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) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.FieldTheory.Minpoly.Field
import Mathlib.Algebra.Polynomial.Module.AEval
import Mathlib.Algebra.Module.Torsion
/-!
# Polynomial modules in finite dimensions
This file is a place to collect results about the `R[X]`-module structure induced on an `R`-module
by an `R`-linear endomorphism, which require the concept of finite-dimensionality.
## Main results:
* `Module.AEval.isTorsion_of_finiteDimensional`: if a vector space `M` with coefficients in a field
`K` carries a natural `K`-linear endomorphism which belongs to a finite-dimensional algebra
over `K`, then the induced `K[X]`-module structure on `M` is pure torsion.
-/
open Polynomial
variable {R K M A : Type*} {a : A}
namespace Module.AEval
| theorem isTorsion_of_aeval_eq_zero [CommSemiring R] [NoZeroDivisors R] [Semiring A] [Algebra R A]
[AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]
{p : R[X]} (h : aeval a p = 0) (h' : p ≠ 0) :
IsTorsion R[X] (AEval R M a) := by
have hp : p ∈ nonZeroDivisors R[X] := fun q hq ↦ Or.resolve_right (mul_eq_zero.mp hq) h'
exact fun x ↦ ⟨⟨p, hp⟩, (of R M a).symm.injective <| by simp [h]⟩
| Mathlib/Algebra/Polynomial/Module/FiniteDimensional.lean | 29 | 34 |
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.NumberTheory.LegendreSymbol.AddCharacter
import Mathlib.NumberTheory.LegendreSymbol.ZModChar
import Mathlib.Algebra.CharP.CharAndCard
/-!
# Gauss sums
We define the Gauss sum associated to a multiplicative and an additive
character of a finite field and prove some results about them.
## Main definition
Let `R` be a finite commutative ring and let `R'` be another commutative ring.
If `χ` is a multiplicative character `R → R'` (type `MulChar R R'`) and `ψ`
is an additive character `R → R'` (type `AddChar R R'`, which abbreviates
`(Multiplicative R) →* R'`), then the *Gauss sum* of `χ` and `ψ` is `∑ a, χ a * ψ a`.
## Main results
Some important results are as follows.
* `gaussSum_mul_gaussSum_eq_card`: The product of the Gauss
sums of `χ` and `ψ` and that of `χ⁻¹` and `ψ⁻¹` is the cardinality
of the source ring `R` (if `χ` is nontrivial, `ψ` is primitive and `R` is a field).
* `gaussSum_sq`: The square of the Gauss sum is `χ(-1)` times
the cardinality of `R` if in addition `χ` is a quadratic character.
* `MulChar.IsQuadratic.gaussSum_frob`: For a quadratic character `χ`, raising
the Gauss sum to the `p`th power (where `p` is the characteristic of
the target ring `R'`) multiplies it by `χ p`.
* `Char.card_pow_card`: When `F` and `F'` are finite fields and `χ : F → F'`
is a nontrivial quadratic character, then `(χ (-1) * #F)^(#F'/2) = χ #F'`.
* `FiniteField.two_pow_card`: For every finite field `F` of odd characteristic,
we have `2^(#F/2) = χ₈ #F` in `F`.
This machinery can be used to derive (a generalization of) the Law of
Quadratic Reciprocity.
## Tags
additive character, multiplicative character, Gauss sum
-/
universe u v
open AddChar MulChar
section GaussSumDef
-- `R` is the domain of the characters
variable {R : Type u} [CommRing R] [Fintype R]
-- `R'` is the target of the characters
variable {R' : Type v} [CommRing R']
/-!
### Definition and first properties
-/
/-- Definition of the Gauss sum associated to a multiplicative and an additive character. -/
def gaussSum (χ : MulChar R R') (ψ : AddChar R R') : R' :=
∑ a, χ a * ψ a
/-- Replacing `ψ` by `mulShift ψ a` and multiplying the Gauss sum by `χ a` does not change it. -/
theorem gaussSum_mulShift (χ : MulChar R R') (ψ : AddChar R R') (a : Rˣ) :
χ a * gaussSum χ (mulShift ψ a) = gaussSum χ ψ := by
simp only [gaussSum, mulShift_apply, Finset.mul_sum]
simp_rw [← mul_assoc, ← map_mul]
exact Fintype.sum_bijective _ a.mulLeft_bijective _ _ fun x ↦ rfl
end GaussSumDef
/-!
### The product of two Gauss sums
-/
section GaussSumProd
open Finset in
/-- A formula for the product of two Gauss sums with the same additive character. -/
lemma gaussSum_mul {R : Type u} [CommRing R] [Fintype R] {R' : Type v} [CommRing R']
(χ φ : MulChar R R') (ψ : AddChar R R') :
gaussSum χ ψ * gaussSum φ ψ = ∑ t : R, ∑ x : R, χ x * φ (t - x) * ψ t := by
rw [gaussSum, gaussSum, sum_mul_sum]
conv => enter [1, 2, x, 2, x_1]; rw [mul_mul_mul_comm]
simp only [← ψ.map_add_eq_mul]
have sum_eq x : ∑ y : R, χ x * φ y * ψ (x + y) = ∑ y : R, χ x * φ (y - x) * ψ y := by
rw [sum_bij (fun a _ ↦ a + x)]
· simp only [mem_univ, forall_true_left, forall_const]
· simp only [mem_univ, add_left_inj, imp_self, forall_const]
· exact fun b _ ↦ ⟨b - x, mem_univ _, by rw [sub_add_cancel]⟩
· exact fun a _ ↦ by rw [add_sub_cancel_right, add_comm]
rw [sum_congr rfl fun x _ ↦ sum_eq x, sum_comm]
-- In the following, we need `R` to be a finite field.
variable {R : Type u} [Field R] [Fintype R] {R' : Type v} [CommRing R']
lemma mul_gaussSum_inv_eq_gaussSum (χ : MulChar R R') (ψ : AddChar R R') :
χ (-1) * gaussSum χ ψ⁻¹ = gaussSum χ ψ := by
rw [ψ.inv_mulShift, ← Units.coe_neg_one]
exact gaussSum_mulShift χ ψ (-1)
variable [IsDomain R'] -- From now on, `R'` needs to be a domain.
-- A helper lemma for `gaussSum_mul_gaussSum_eq_card` below
-- Is this useful enough in other contexts to be public?
private theorem gaussSum_mul_aux {χ : MulChar R R'} (hχ : χ ≠ 1) (ψ : AddChar R R')
(b : R) :
∑ a, χ (a * b⁻¹) * ψ (a - b) = ∑ c, χ c * ψ (b * (c - 1)) := by
rcases eq_or_ne b 0 with hb | hb
· -- case `b = 0`
simp only [hb, inv_zero, mul_zero, MulChar.map_zero, zero_mul,
Finset.sum_const_zero, map_zero_eq_one, mul_one, χ.sum_eq_zero_of_ne_one hχ]
· -- case `b ≠ 0`
refine (Fintype.sum_bijective _ (mulLeft_bijective₀ b hb) _ _ fun x ↦ ?_).symm
rw [mul_assoc, mul_comm x, ← mul_assoc, mul_inv_cancel₀ hb, one_mul, mul_sub, mul_one]
/-- We have `gaussSum χ ψ * gaussSum χ⁻¹ ψ⁻¹ = Fintype.card R`
when `χ` is nontrivial and `ψ` is primitive (and `R` is a field). -/
theorem gaussSum_mul_gaussSum_eq_card {χ : MulChar R R'} (hχ : χ ≠ 1) {ψ : AddChar R R'}
(hψ : IsPrimitive ψ) :
gaussSum χ ψ * gaussSum χ⁻¹ ψ⁻¹ = Fintype.card R := by
simp only [gaussSum, AddChar.inv_apply, Finset.sum_mul, Finset.mul_sum, MulChar.inv_apply']
conv =>
enter [1, 2, x, 2, y]
rw [mul_mul_mul_comm, ← map_mul, ← map_add_eq_mul, ← sub_eq_add_neg]
-- conv in _ * _ * (_ * _) => rw [mul_mul_mul_comm, ← map_mul, ← map_add_eq_mul, ← sub_eq_add_neg]
simp_rw [gaussSum_mul_aux hχ ψ]
rw [Finset.sum_comm]
classical -- to get `[DecidableEq R]` for `sum_mulShift`
simp_rw [← Finset.mul_sum, sum_mulShift _ hψ, sub_eq_zero, apply_ite, Nat.cast_zero, mul_zero]
rw [Finset.sum_ite_eq' Finset.univ (1 : R)]
simp only [Finset.mem_univ, map_one, one_mul, if_true]
/-- If `χ` is a multiplicative character of order `n` on a finite field `F`,
then `g(χ) * g(χ^(n-1)) = χ(-1)*#F` -/
lemma gaussSum_mul_gaussSum_pow_orderOf_sub_one {χ : MulChar R R'} {ψ : AddChar R R'}
(hχ : χ ≠ 1) (hψ : ψ.IsPrimitive) :
gaussSum χ ψ * gaussSum (χ ^ (orderOf χ - 1)) ψ = χ (-1) * Fintype.card R := by
have h : χ ^ (orderOf χ - 1) = χ⁻¹ := by
refine (inv_eq_of_mul_eq_one_right ?_).symm
rw [← pow_succ', Nat.sub_one_add_one_eq_of_pos χ.orderOf_pos, pow_orderOf_eq_one]
rw [h, ← mul_gaussSum_inv_eq_gaussSum χ⁻¹, mul_left_comm, gaussSum_mul_gaussSum_eq_card hχ hψ,
MulChar.inv_apply', inv_neg_one]
/-- The Gauss sum of a nontrivial character on a finite field does not vanish. -/
lemma gaussSum_ne_zero_of_nontrivial (h : (Fintype.card R : R') ≠ 0) {χ : MulChar R R'}
(hχ : χ ≠ 1) {ψ : AddChar R R'} (hψ : ψ.IsPrimitive) :
gaussSum χ ψ ≠ 0 :=
fun H ↦ h.symm <| zero_mul (gaussSum χ⁻¹ _) ▸ H ▸ gaussSum_mul_gaussSum_eq_card hχ hψ
/-- When `χ` is a nontrivial quadratic character, then the square of `gaussSum χ ψ`
is `χ(-1)` times the cardinality of `R`. -/
theorem gaussSum_sq {χ : MulChar R R'} (hχ₁ : χ ≠ 1) (hχ₂ : IsQuadratic χ)
{ψ : AddChar R R'} (hψ : IsPrimitive ψ) :
gaussSum χ ψ ^ 2 = χ (-1) * Fintype.card R := by
rw [pow_two, ← gaussSum_mul_gaussSum_eq_card hχ₁ hψ, hχ₂.inv, mul_rotate']
congr
rw [mul_comm, ← gaussSum_mulShift _ _ (-1 : Rˣ), inv_mulShift]
rfl
end GaussSumProd
/-!
### Gauss sums and Frobenius
-/
section gaussSum_frob
variable {R : Type u} [CommRing R] [Fintype R] {R' : Type v} [CommRing R']
-- We assume that the target ring `R'` has prime characteristic `p`.
variable (p : ℕ) [fp : Fact p.Prime] [hch : CharP R' p]
/-- When `R'` has prime characteristic `p`, then the `p`th power of the Gauss sum
of `χ` and `ψ` is the Gauss sum of `χ^p` and `ψ^p`. -/
theorem gaussSum_frob (χ : MulChar R R') (ψ : AddChar R R') :
gaussSum χ ψ ^ p = gaussSum (χ ^ p) (ψ ^ p) := by
rw [← frobenius_def, gaussSum, gaussSum, map_sum]
simp_rw [pow_apply' χ fp.1.ne_zero, map_mul, frobenius_def]
rfl
/-- For a quadratic character `χ` and when the characteristic `p` of the target ring
is a unit in the source ring, the `p`th power of the Gauss sum of`χ` and `ψ` is
`χ p` times the original Gauss sum. -/
theorem MulChar.IsQuadratic.gaussSum_frob (hp : IsUnit (p : R)) {χ : MulChar R R'}
(hχ : IsQuadratic χ) (ψ : AddChar R R') :
gaussSum χ ψ ^ p = χ p * gaussSum χ ψ := by
rw [_root_.gaussSum_frob, pow_mulShift, hχ.pow_char p, ← gaussSum_mulShift χ ψ hp.unit,
← mul_assoc, hp.unit_spec, ← pow_two, ← pow_apply' _ two_ne_zero, hχ.sq_eq_one, ← hp.unit_spec,
| one_apply_coe, one_mul]
/-- For a quadratic character `χ` and when the characteristic `p` of the target ring
is a unit in the source ring and `n` is a natural number, the `p^n`th power of the Gauss
sum of`χ` and `ψ` is `χ (p^n)` times the original Gauss sum. -/
theorem MulChar.IsQuadratic.gaussSum_frob_iter (n : ℕ) (hp : IsUnit (p : R)) {χ : MulChar R R'}
(hχ : IsQuadratic χ) (ψ : AddChar R R') :
gaussSum χ ψ ^ p ^ n = χ ((p : R) ^ n) * gaussSum χ ψ := by
induction n with
| zero => rw [pow_zero, pow_one, pow_zero, MulChar.map_one, one_mul]
| succ n ih =>
rw [pow_succ, pow_mul, ih, mul_pow, hχ.gaussSum_frob _ hp, ← mul_assoc, pow_succ, map_mul,
← pow_apply' χ fp.1.ne_zero ((p : R) ^ n), hχ.pow_char p]
| Mathlib/NumberTheory/GaussSum.lean | 196 | 208 |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Logic.Relator
import Mathlib.Tactic.Use
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.SimpRw
import Mathlib.Logic.Basic
import Mathlib.Order.Defs.Unbundled
/-!
# Relation closures
This file defines the reflexive, transitive, reflexive transitive and equivalence closures
of relations and proves some basic results on them.
Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For
the bundled version, see `Rel`.
## Definitions
* `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all
`a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`.
* `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related
transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`.
* `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything
`r` related transitively, plus for all `a` it relates `a` with itself. So
`ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as
the reflexive closure of the transitive closure, or the transitive closure of the reflexive
closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of
rewrites.
* `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates,
plus for all related pairs it relates them in the opposite order.
* `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and
`s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to
both.
* `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`,
`g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b`
related by `r`.
* `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In
terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term.
-/
open Function
variable {α β γ δ ε ζ : Type*}
section NeImp
variable {r : α → α → Prop}
theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x
/-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`,
it suffices to show it holds when `x ≠ y`. -/
theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by
by_cases hxy : x = y
· exact hxy ▸ h x
· exact hr hxy
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. -/
theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y :=
⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/
theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y :=
IsRefl.reflexive.ne_imp_iff
protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x :=
⟨fun h ↦ H h, fun h ↦ H h⟩
theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r :=
funext₂ fun _ _ ↦ propext <| h.iff _ _
theorem Symmetric.swap_eq : Symmetric r → swap r = r :=
Symmetric.flip_eq
theorem flip_eq_iff : flip r = r ↔ Symmetric r :=
⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩
theorem swap_eq_iff : swap r = r ↔ Symmetric r :=
flip_eq_iff
end NeImp
section Comap
variable {r : β → β → Prop}
theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a)
theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab
theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) :=
fun _ _ _ hab hbc ↦ h hab hbc
theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) :=
⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩
end Comap
namespace Relation
section Comp
variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop}
/-- The composition of two relations, yielding a new relation. The result
relates a term of `α` and a term of `γ` if there is an intermediate
term of `β` related to both.
-/
def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop :=
∃ b, r a b ∧ p b c
@[inherit_doc]
local infixr:80 " ∘r " => Relation.Comp
@[simp]
theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun ..
@[simp]
theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp ..
@[simp]
theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, eq_comp]
@[simp]
theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, comp_eq]
theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by
funext a d
apply propext
constructor
· exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩
· exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩
theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by
funext c a
apply propext
constructor
· exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩
· exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩
end Comp
section Fibration
variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β)
/-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all
`a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image
of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/
def Fibration :=
∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b
variable {rα rβ}
/-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is
accessible under `rα`, then `f a` is accessible under `rβ`. -/
theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by
induction ha with | intro a _ ih => ?_
refine Acc.intro (f a) fun b hr ↦ ?_
obtain ⟨a', hr', rfl⟩ := fib hr
exact ih a' hr'
theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α)
(ha : Acc (InvImage rβ f) a) : Acc rβ (f a) :=
ha.of_fibration f fun a _ h ↦
let ⟨a', he⟩ := dc h
⟨a', by simp_all [InvImage], he⟩
end Fibration
section Map
variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ}
/-- The map of a relation `r` through a pair of functions pushes the
relation to the codomains of the functions. The resulting relation is
defined by having pairs of terms related if they have preimages
related by `r`.
-/
protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦
∃ a b, r a b ∧ f a = c ∧ g b = d
lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl
@[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) :
Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by
ext a b
simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ]
refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩
rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩
exact ⟨hab, h⟩
@[simp]
lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) :
Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff]
@[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map]
instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) :=
‹Decidable _›
lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) :
Reflexive (Relation.Map r f f) := by
intro x
obtain ⟨y, rfl⟩ := hf x
exact ⟨y, y, hr y, rfl, rfl⟩
lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) :
Symmetric (Relation.Map r f f) := by
rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩
lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β}
(hf : ∀ x y, f x = f y → r x y) :
Transitive (Relation.Map r f f) := by
rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩
exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩
lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β)
(hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) :
Equivalence (Relation.Map r f f) where
refl := map_reflexive hr.reflexive hf
symm := @(map_symmetric hr.symmetric _)
trans := @(map_transitive hr.transitive hf_ker)
-- TODO: state this using `≤`, after adjusting imports.
lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) :
∀ x y, Relation.Map r f g x y → Relation.Map s f g x y :=
fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩
end Map
variable {r : α → α → Prop} {a b c : α}
/-- `ReflTransGen r`: reflexive transitive closure of `r` -/
@[mk_iff ReflTransGen.cases_tail_iff]
inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflTransGen r a a
| tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c
attribute [refl] ReflTransGen.refl
/-- `ReflGen r`: reflexive closure of `r` -/
@[mk_iff]
inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflGen r a a
| single {b} : r a b → ReflGen r a b
variable (r) in
/-- `EqvGen r`: equivalence closure of `r`. -/
@[mk_iff]
inductive EqvGen : α → α → Prop
| rel x y : r x y → EqvGen x y
| refl x : EqvGen x x
| symm x y : EqvGen x y → EqvGen y x
| trans x y z : EqvGen x y → EqvGen y z → EqvGen x z
attribute [mk_iff] TransGen
attribute [refl] ReflGen.refl
namespace ReflGen
theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b
| a, _, refl => by rfl
| _, _, single h => ReflTransGen.tail ReflTransGen.refl h
theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b
| a, _, ReflGen.refl => by rfl
| a, b, single h => single (hp a b h)
instance : IsRefl α (ReflGen r) :=
⟨@refl α r⟩
end ReflGen
namespace ReflTransGen
@[trans]
theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
theorem single (hab : r a b) : ReflTransGen r a b :=
refl.tail hab
theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => exact refl.tail hab
| tail _ hcd hac => exact hac.tail hcd
theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by
intro x y h
induction h with
| refl => rfl
| tail _ b c => apply Relation.ReflTransGen.head (h b) c
theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b :=
(cases_tail_iff r a b).1
@[elab_as_elim]
theorem head_induction_on {P : ∀ a : α, ReflTransGen r a b → Prop} {a : α} (h : ReflTransGen r a b)
(refl : P b refl)
(head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), P c h → P a (h.head h')) : P a h := by
induction h with
| refl => exact refl
| @tail b c _ hbc ih =>
apply ih
· exact head hbc _ refl
· exact fun h1 h2 ↦ head h1 (h2.tail hbc)
@[elab_as_elim]
theorem trans_induction_on {P : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α}
(h : ReflTransGen r a b) (ih₁ : ∀ a, @P a a refl) (ih₂ : ∀ {a b} (h : r a b), P (single h))
(ih₃ : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), P h₁ → P h₂ →
P (h₁.trans h₂)) : P h := by
induction h with
| refl => exact ih₁ a
| tail hab hbc ih => exact ih₃ hab (single hbc) ih (ih₂ hbc)
theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
induction h using Relation.ReflTransGen.head_induction_on
· left
rfl
· right
exact ⟨_, by assumption, by assumption⟩
theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
use cases_head
rintro (rfl | ⟨c, hac, hcb⟩)
· rfl
· exact head hac hcb
theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b)
(ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by
induction ab with
| refl => exact Or.inl ac
| tail _ bd IH =>
rcases IH with (IH | IH)
· rcases cases_head IH with (rfl | ⟨e, be, ec⟩)
· exact Or.inr (single bd)
· cases U bd be
exact Or.inl ec
· exact Or.inr (IH.tail bd)
end ReflTransGen
namespace TransGen
theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by
induction h with
| single h => exact ReflTransGen.single h
| tail _ bc ab => exact ReflTransGen.tail ab bc
theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) :=
⟨trans_left⟩
attribute [trans] trans
instance : Trans (TransGen r) (TransGen r) (TransGen r) :=
⟨trans⟩
theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c :=
trans_left (single hab) hbc
theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by
induction hab generalizing c with
| refl => exact single hbc
| tail _ hdb IH => exact tail (IH hdb) hbc
theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c :=
head' hab hbc.to_reflTransGen
@[elab_as_elim]
theorem head_induction_on {P : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b)
(base : ∀ {a} (h : r a b), P a (single h))
(ih : ∀ {a c} (h' : r a c) (h : TransGen r c b), P c h → P a (h.head h')) : P a h := by
induction h with
| single h => exact base h
| @tail b c _ hbc h_ih =>
apply h_ih
· exact fun h ↦ ih h (single hbc) (base hbc)
· exact fun hab hbc ↦ ih hab _
@[elab_as_elim]
theorem trans_induction_on {P : ∀ {a b : α}, TransGen r a b → Prop} {a b : α} (h : TransGen r a b)
(base : ∀ {a b} (h : r a b), P (single h))
(ih : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) :
P h := by
induction h with
| single h => exact base h
| tail hab hbc h_ih => exact ih hab (single hbc) h_ih (base hbc)
theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by
induction hbc with
| single hbc => exact tail' hab hbc
| tail _ hcd hac => exact hac.tail hcd
instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) :=
⟨trans_right⟩
theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩
cases h with
| single hac => exact ⟨_, by rfl, hac⟩
| tail hab hbc => exact ⟨_, hab.to_reflTransGen, hbc⟩
theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩
induction h with
| single hac => exact ⟨_, hac, by rfl⟩
| tail _ hbc IH =>
rcases IH with ⟨d, had, hdb⟩
exact ⟨_, had, hdb.tail hbc⟩
end TransGen
section reflGen
lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by
ext x y
simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y
lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl
lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α}
(hxy : ReflGen r x y) : r' x y := by
simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy
end reflGen
section TransGen
theorem transGen_eq_self (trans : Transitive r) : TransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| single hc => exact hc
| tail _ hcd hac => exact trans hac hcd, TransGen.single⟩
theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans
instance : IsTrans α (TransGen r) :=
⟨@TransGen.trans α r⟩
theorem transGen_idem : TransGen (TransGen r) = TransGen r :=
transGen_eq_self transitive_transGen
theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b))
(hab : TransGen r a b) : TransGen p (f a) (f b) := by
induction hab with
| single hac => exact TransGen.single (h a _ hac)
| tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd)
theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) :
TransGen p (f a) (f b) := by
simpa [transGen_idem] using hab.lift f h
theorem TransGen.closed {p : α → α → Prop} :
(∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift' id
lemma TransGen.closed' {P : α → Prop} (dc : ∀ {a b}, r a b → P b → P a)
{a b : α} (h : TransGen r a b) : P b → P a :=
h.head_induction_on dc fun hr _ hi ↦ dc hr ∘ hi
theorem TransGen.mono {p : α → α → Prop} :
(∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift id
lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y)
{x y : α} (hxy : TransGen r x y) : r' x y := by
simpa [transGen_eq_self hr'] using TransGen.mono h hxy
theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by
induction h with
| single h => exact TransGen.single h
| tail _ hbc ih => exact ih.head hbc
theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a :=
⟨TransGen.swap, TransGen.swap⟩
end TransGen
section ReflTransGen
open ReflTransGen
theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by
rw [cases_head_iff]; simp [h, eq_comm]
theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· cases h with
| refl => exact Or.inl rfl
| tail hac hcb => exact Or.inr (TransGen.tail' hac hcb)
· rcases h with (rfl | h)
· rfl
· exact h.to_reflTransGen
theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) :=
ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans
theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) →
ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift id
theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| refl => apply refl
| tail _ h₂ IH => exact trans IH h₂, single⟩
lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r')
(h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by
simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy
theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl
theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans
instance : IsRefl α (ReflTransGen r) :=
⟨@ReflTransGen.refl α r⟩
instance : IsTrans α (ReflTransGen r) :=
⟨@ReflTransGen.trans α r⟩
theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r :=
reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen
theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → ReflTransGen p (f a) (f b))
(hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by
simpa [reflTransGen_idem] using hab.lift f h
theorem reflTransGen_closed {p : α → α → Prop} :
(∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift' id
theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by
induction h with
| refl => rfl
| tail _ hbc ih => exact ih.head hbc
theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a :=
⟨ReflTransGen.swap, ReflTransGen.swap⟩
@[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by
ext x y
simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff]
@[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by
ext x y
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simpa [reflTransGen_idem]
using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h
· obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h
· exact .single .refl
· exact TransGen.mono (fun _ _ ↦ .single) h
@[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by
simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen]
@[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by
simp only [← reflGen_transGen, transGen_idem]
lemma reflTransGen_eq_transGen (hr : Reflexive r) :
ReflTransGen r = TransGen r := by
rw [← transGen_reflGen, reflGen_eq_self hr]
lemma reflTransGen_eq_reflGen (hr : Transitive r) :
ReflTransGen r = ReflGen r := by
rw [← reflGen_transGen, transGen_eq_self hr]
end ReflTransGen
namespace EqvGen
variable (r)
theorem is_equivalence : Equivalence (@EqvGen α r) :=
Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _)
/-- `EqvGen.setoid r` is the setoid generated by a relation `r`.
The motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.setoid r)`,
see for example `Quot.eqvGen_exact` and `Quot.eqvGen_sound`. -/
def setoid : Setoid α :=
Setoid.mk _ (EqvGen.is_equivalence r)
theorem mono {r p : α → α → Prop} (hrp : ∀ a b, r a b → p a b) (h : EqvGen r a b) :
EqvGen p a b := by
induction h with
| rel a b h => exact EqvGen.rel _ _ (hrp _ _ h)
| refl => exact EqvGen.refl _
| symm a b _ ih => exact EqvGen.symm _ _ ih
| trans a b c _ _ hab hbc => exact EqvGen.trans _ _ _ hab hbc
end EqvGen
/-- The join of a relation on a single type is a new relation for which
pairs of terms are related if there is a third term they are both
related to. For example, if `r` is a relation representing rewrites
in a term rewriting system, then *confluence* is the property that if
`a` rewrites to both `b` and `c`, then `join r` relates `b` and `c`
(see `Relation.church_rosser`).
-/
def Join (r : α → α → Prop) : α → α → Prop := fun a b ↦ ∃ c, r a c ∧ r b c
section Join
open ReflTransGen ReflGen
/-- A sufficient condition for the Church-Rosser property. -/
theorem church_rosser (h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d)
(hab : ReflTransGen r a b) (hac : ReflTransGen r a c) : Join (ReflTransGen r) b c := by
induction hab with
| refl => exact ⟨c, hac, refl⟩
| @tail d e _ hde ih =>
rcases ih with ⟨b, hdb, hcb⟩
have : ∃ a, ReflTransGen r e a ∧ ReflGen r b a := by
clear hcb
induction hdb with
| refl => exact ⟨e, refl, ReflGen.single hde⟩
| @tail f b _ hfb ih =>
rcases ih with ⟨a, hea, hfa⟩
cases hfa with
| refl => exact ⟨b, hea.tail hfb, ReflGen.refl⟩
| single hfa =>
rcases h _ _ _ hfb hfa with ⟨c, hbc, hac⟩
exact ⟨c, hea.trans hac, hbc⟩
rcases this with ⟨a, hea, hba⟩
cases hba with
| refl => exact ⟨b, hea, hcb⟩
| single hba => exact ⟨a, hea, hcb.tail hba⟩
theorem join_of_single (h : Reflexive r) (hab : r a b) : Join r a b :=
⟨b, hab, h b⟩
theorem symmetric_join : Symmetric (Join r) := fun _ _ ⟨c, hac, hcb⟩ ↦ ⟨c, hcb, hac⟩
theorem reflexive_join (h : Reflexive r) : Reflexive (Join r) := fun a ↦ ⟨a, h a, h a⟩
theorem transitive_join (ht : Transitive r) (h : ∀ a b c, r a b → r a c → Join r b c) :
Transitive (Join r) :=
fun _ b _ ⟨x, hax, hbx⟩ ⟨y, hby, hcy⟩ ↦
let ⟨z, hxz, hyz⟩ := h b x y hbx hby
⟨z, ht hax hxz, ht hcy hyz⟩
theorem equivalence_join (hr : Reflexive r) (ht : Transitive r)
(h : ∀ a b c, r a b → r a c → Join r b c) : Equivalence (Join r) :=
⟨reflexive_join hr, @symmetric_join _ _, @transitive_join _ _ ht h⟩
theorem equivalence_join_reflTransGen
(h : ∀ a b c, r a b → r a c → ∃ d, ReflGen r b d ∧ ReflTransGen r c d) :
Equivalence (Join (ReflTransGen r)) :=
equivalence_join reflexive_reflTransGen transitive_reflTransGen fun _ _ _ ↦ church_rosser h
theorem join_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) (h : ∀ a b, r' a b → r a b) :
Join r' a b → r a b
| ⟨_, hac, hbc⟩ => hr.trans (h _ _ hac) (hr.symm <| h _ _ hbc)
theorem reflTransGen_of_transitive_reflexive {r' : α → α → Prop} (hr : Reflexive r)
(ht : Transitive r) (h : ∀ a b, r' a b → r a b) (h' : ReflTransGen r' a b) : r a b := by
induction h' with
| refl => exact hr _
| tail _ hbc ih => exact ht ih (h _ _ hbc)
theorem reflTransGen_of_equivalence {r' : α → α → Prop} (hr : Equivalence r) :
(∀ a b, r' a b → r a b) → ReflTransGen r' a b → r a b :=
reflTransGen_of_transitive_reflexive hr.1 (fun _ _ _ ↦ hr.trans)
end Join
end Relation
section EqvGen
open Relation
variable {r : α → α → Prop} {a b : α}
theorem Quot.eqvGen_exact (H : Quot.mk r a = Quot.mk r b) : EqvGen r a b :=
@Quotient.exact _ (EqvGen.setoid r) a b (congrArg
(Quot.lift (Quotient.mk (EqvGen.setoid r)) (fun x y h ↦ Quot.sound (EqvGen.rel x y h))) H)
theorem Quot.eqvGen_sound (H : EqvGen r a b) : Quot.mk r a = Quot.mk r b :=
EqvGen.rec
(fun _ _ h ↦ Quot.sound h)
(fun _ ↦ rfl)
(fun _ _ _ IH ↦ Eq.symm IH)
(fun _ _ _ _ _ IH₁ IH₂ ↦ Eq.trans IH₁ IH₂)
H
theorem Equivalence.eqvGen_iff (h : Equivalence r) : EqvGen r a b ↔ r a b :=
Iff.intro
(by
intro h
induction h with
| rel => assumption
| refl => exact h.1 _
| symm => apply h.symm; assumption
| trans _ _ _ _ _ hab hbc => exact h.trans hab hbc)
(EqvGen.rel a b)
theorem Equivalence.eqvGen_eq (h : Equivalence r) : EqvGen r = r :=
funext fun _ ↦ funext fun _ ↦ propext <| h.eqvGen_iff
end EqvGen
| Mathlib/Logic/Relation.lean | 768 | 774 | |
/-
Copyright (c) 2022 Michael Blyth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Blyth
-/
import Mathlib.LinearAlgebra.Projectivization.Basic
/-!
# Subspaces of Projective Space
In this file we define subspaces of a projective space, and show that the subspaces of a projective
space form a complete lattice under inclusion.
## Implementation Details
A subspace of a projective space ℙ K V is defined to be a structure consisting of a subset of
ℙ K V such that if two nonzero vectors in V determine points in ℙ K V which are in the subset, and
the sum of the two vectors is nonzero, then the point determined by the sum of the two vectors is
also in the subset.
## Results
- There is a Galois insertion between the subsets of points of a projective space
and the subspaces of the projective space, which is given by taking the span of the set of points.
- The subspaces of a projective space form a complete lattice under inclusion.
# Future Work
- Show that there is a one-to-one order-preserving correspondence between subspaces of a
projective space and the submodules of the underlying vector space.
-/
variable (K V : Type*) [Field K] [AddCommGroup V] [Module K V]
namespace Projectivization
open scoped LinearAlgebra.Projectivization
/-- A subspace of a projective space is a structure consisting of a set of points such that:
If two nonzero vectors determine points which are in the set, and the sum of the two vectors is
nonzero, then the point determined by the sum is also in the set. -/
@[ext]
structure Subspace where
/-- The set of points. -/
carrier : Set (ℙ K V)
/-- The addition rule. -/
mem_add' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) :
mk K v hv ∈ carrier → mk K w hw ∈ carrier → mk K (v + w) hvw ∈ carrier
namespace Subspace
variable {K V}
instance : SetLike (Subspace K V) (ℙ K V) where
coe := carrier
coe_injective' A B := by
cases A
cases B
simp
@[simp]
theorem mem_carrier_iff (A : Subspace K V) (x : ℙ K V) : x ∈ A.carrier ↔ x ∈ A :=
Iff.refl _
theorem mem_add (T : Subspace K V) (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) :
Projectivization.mk K v hv ∈ T →
Projectivization.mk K w hw ∈ T → Projectivization.mk K (v + w) hvw ∈ T :=
T.mem_add' v w hv hw hvw
/-- The span of a set of points in a projective space is defined inductively to be the set of points
which contains the original set, and contains all points determined by the (nonzero) sum of two
nonzero vectors, each of which determine points in the span. -/
inductive spanCarrier (S : Set (ℙ K V)) : Set (ℙ K V)
| of (x : ℙ K V) (hx : x ∈ S) : spanCarrier S x
| mem_add (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) :
spanCarrier S (Projectivization.mk K v hv) →
spanCarrier S (Projectivization.mk K w hw) → spanCarrier S (Projectivization.mk K (v + w) hvw)
/-- The span of a set of points in projective space is a subspace. -/
def span (S : Set (ℙ K V)) : Subspace K V where
carrier := spanCarrier S
mem_add' v w hv hw hvw := spanCarrier.mem_add v w hv hw hvw
/-- The span of a set of points contains the set of points. -/
theorem subset_span (S : Set (ℙ K V)) : S ⊆ span S := fun _x hx => spanCarrier.of _ hx
/-- The span of a set of points is a Galois insertion between sets of points of a projective space
and subspaces of the projective space. -/
def gi : GaloisInsertion (span : Set (ℙ K V) → Subspace K V) SetLike.coe where
choice S _hS := span S
gc A B :=
⟨fun h => le_trans (subset_span _) h, by
intro h x hx
induction hx with
| of => apply h; assumption
| mem_add => apply B.mem_add; assumption'⟩
le_l_u _ := subset_span _
choice_eq _ _ := rfl
/-- The span of a subspace is the subspace. -/
@[simp]
theorem span_coe (W : Subspace K V) : span ↑W = W :=
GaloisInsertion.l_u_eq gi W
/-- The infimum of two subspaces exists. -/
instance instInf : Min (Subspace K V) :=
⟨fun A B =>
⟨A ⊓ B, fun _v _w hv hw _hvw h1 h2 =>
⟨A.mem_add _ _ hv hw _ h1.1 h2.1, B.mem_add _ _ hv hw _ h1.2 h2.2⟩⟩⟩
/-- Infimums of arbitrary collections of subspaces exist. -/
instance instInfSet : InfSet (Subspace K V) :=
⟨fun A =>
⟨sInf (SetLike.coe '' A), fun v w hv hw hvw h1 h2 t => by
rintro ⟨s, hs, rfl⟩
exact s.mem_add v w hv hw _ (h1 s ⟨s, hs, rfl⟩) (h2 s ⟨s, hs, rfl⟩)⟩⟩
/-- The subspaces of a projective space form a complete lattice. -/
instance : CompleteLattice (Subspace K V) :=
{ __ := completeLatticeOfInf (Subspace K V)
(by
refine fun s => ⟨fun a ha x hx => hx _ ⟨a, ha, rfl⟩, fun a ha x hx E => ?_⟩
rintro ⟨E, hE, rfl⟩
exact ha hE hx)
inf_le_left := fun A B _ hx => (@inf_le_left _ _ A B) hx
inf_le_right := fun A B _ hx => (@inf_le_right _ _ A B) hx
le_inf := fun _ _ _ h1 h2 _ hx => (le_inf h1 h2) hx }
instance subspaceInhabited : Inhabited (Subspace K V) where default := ⊤
/-- The span of the empty set is the bottom of the lattice of subspaces. -/
@[simp]
theorem span_empty : span (∅ : Set (ℙ K V)) = ⊥ := gi.gc.l_bot
/-- The span of the entire projective space is the top of the lattice of subspaces. -/
@[simp]
theorem span_univ : span (Set.univ : Set (ℙ K V)) = ⊤ := by
rw [eq_top_iff, SetLike.le_def]
intro x _hx
exact subset_span _ (Set.mem_univ x)
/-- The span of a set of points is contained in a subspace if and only if the set of points is
contained in the subspace. -/
theorem span_le_subspace_iff {S : Set (ℙ K V)} {W : Subspace K V} : span S ≤ W ↔ S ⊆ W :=
gi.gc S W
/-- If a set of points is a subset of another set of points, then its span will be contained in the
span of that set. -/
@[mono]
theorem monotone_span : Monotone (span : Set (ℙ K V) → Subspace K V) :=
gi.gc.monotone_l
@[gcongr]
lemma span_le_span {s t : Set (ℙ K V)} (hst : s ⊆ t) : span s ≤ span t := monotone_span hst
theorem subset_span_trans {S T U : Set (ℙ K V)} (hST : S ⊆ span T) (hTU : T ⊆ span U) :
S ⊆ span U :=
gi.gc.le_u_l_trans hST hTU
/-- The supremum of two subspaces is equal to the span of their union. -/
theorem span_union (S T : Set (ℙ K V)) : span (S ∪ T) = span S ⊔ span T :=
(@gi K V _ _ _).gc.l_sup
/-- The supremum of a collection of subspaces is equal to the span of the union of the
collection. -/
theorem span_iUnion {ι} (s : ι → Set (ℙ K V)) : span (⋃ i, s i) = ⨆ i, span (s i) :=
(@gi K V _ _ _).gc.l_iSup
/-- The supremum of a subspace and the span of a set of points is equal to the span of the union of
the subspace and the set of points. -/
theorem sup_span {S : Set (ℙ K V)} {W : Subspace K V} : W ⊔ span S = span (W ∪ S) := by
rw [span_union, span_coe]
theorem span_sup {S : Set (ℙ K V)} {W : Subspace K V} : span S ⊔ W = span (S ∪ W) := by
rw [span_union, span_coe]
/-- A point in a projective space is contained in the span of a set of points if and only if the
point is contained in all subspaces of the projective space which contain the set of points. -/
theorem mem_span {S : Set (ℙ K V)} (u : ℙ K V) :
u ∈ span S ↔ ∀ W : Subspace K V, S ⊆ W → u ∈ W := by
simp_rw [← span_le_subspace_iff]
exact ⟨fun hu W hW => hW hu, fun W => W (span S) (le_refl _)⟩
/-- The span of a set of points in a projective space is equal to the infimum of the collection of
subspaces which contain the set. -/
theorem span_eq_sInf {S : Set (ℙ K V)} : span S = sInf { W : Subspace K V| S ⊆ W } := by
ext x
simp_rw [mem_carrier_iff, mem_span x]
refine ⟨fun hx => ?_, fun hx W hW => ?_⟩
· rintro W ⟨T, hT, rfl⟩
exact hx T hT
· exact (@sInf_le _ _ { W : Subspace K V | S ⊆ ↑W } W hW) hx
/-- If a set of points in projective space is contained in a subspace, and that subspace is
contained in the span of the set of points, then the span of the set of points is equal to
the subspace. -/
theorem span_eq_of_le {S : Set (ℙ K V)} {W : Subspace K V} (hS : S ⊆ W) (hW : W ≤ span S) :
span S = W :=
le_antisymm (span_le_subspace_iff.mpr hS) hW
/-- The spans of two sets of points in a projective space are equal if and only if each set of
| points is contained in the span of the other set. -/
theorem span_eq_span_iff {S T : Set (ℙ K V)} : span S = span T ↔ S ⊆ span T ∧ T ⊆ span S :=
⟨fun h => ⟨h ▸ subset_span S, h.symm ▸ subset_span T⟩, fun h =>
le_antisymm (span_le_subspace_iff.2 h.1) (span_le_subspace_iff.2 h.2)⟩
| Mathlib/LinearAlgebra/Projectivization/Subspace.lean | 202 | 205 |
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.HasLimits
import Mathlib.CategoryTheory.Discrete.Basic
/-!
# Categorical (co)products
This file defines (co)products as special cases of (co)limits.
A product is the categorical generalization of the object `Π i, f i` where `f : ι → C`. It is a
limit cone over the diagram formed by `f`, implemented by converting `f` into a functor
`Discrete ι ⥤ C`.
A coproduct is the dual concept.
## Main definitions
* a `Fan` is a cone over a discrete category
* `Fan.mk` constructs a fan from an indexed collection of maps
* a `Pi` is a `limit (Discrete.functor f)`
Each of these has a dual.
## Implementation notes
As with the other special shapes in the limits library, all the definitions here are given as
`abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about
general limits can be used.
-/
noncomputable section
universe w w' w₂ w₃ v v₂ u u₂
open CategoryTheory
namespace CategoryTheory.Limits
variable {β : Type w} {α : Type w₂} {γ : Type w₃}
variable {C : Type u} [Category.{v} C]
-- We don't need an analogue of `Pair` (for binary products), `ParallelPair` (for equalizers),
-- or `(Co)span`, since we already have `Discrete.functor`.
/-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/
abbrev Fan (f : β → C) :=
Cone (Discrete.functor f)
/-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/
abbrev Cofan (f : β → C) :=
Cocone (Discrete.functor f)
/-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/
@[simps! pt π_app]
def Fan.mk {f : β → C} (P : C) (p : ∀ b, P ⟶ f b) : Fan f where
pt := P
π := Discrete.natTrans (fun X => p X.as)
/-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/
@[simps! pt ι_app]
def Cofan.mk {f : β → C} (P : C) (p : ∀ b, f b ⟶ P) : Cofan f where
pt := P
ι := Discrete.natTrans (fun X => p X.as)
/-- Get the `j`th "projection" in the fan.
(Note that the initial letter of `proj` matches the greek letter in `Cone.π`.) -/
def Fan.proj {f : β → C} (p : Fan f) (j : β) : p.pt ⟶ f j :=
p.π.app (Discrete.mk j)
/-- Get the `j`th "injection" in the cofan.
(Note that the initial letter of `inj` matches the greek letter in `Cocone.ι`.) -/
def Cofan.inj {f : β → C} (p : Cofan f) (j : β) : f j ⟶ p.pt :=
p.ι.app (Discrete.mk j)
@[simp]
theorem fan_mk_proj {f : β → C} (P : C) (p : ∀ b, P ⟶ f b) : (Fan.mk P p).proj = p :=
rfl
@[simp]
theorem cofan_mk_inj {f : β → C} (P : C) (p : ∀ b, f b ⟶ P) : (Cofan.mk P p).inj = p :=
rfl
/-- An abbreviation for `HasLimit (Discrete.functor f)`. -/
abbrev HasProduct (f : β → C) :=
HasLimit (Discrete.functor f)
/-- An abbreviation for `HasColimit (Discrete.functor f)`. -/
abbrev HasCoproduct (f : β → C) :=
HasColimit (Discrete.functor f)
lemma hasCoproduct_of_equiv_of_iso (f : α → C) (g : β → C)
[HasCoproduct f] (e : β ≃ α) (iso : ∀ j, g j ≅ f (e j)) : HasCoproduct g := by
have : HasColimit ((Discrete.equivalence e).functor ⋙ Discrete.functor f) :=
hasColimit_equivalence_comp _
have α : Discrete.functor g ≅ (Discrete.equivalence e).functor ⋙ Discrete.functor f :=
Discrete.natIso (fun ⟨j⟩ => iso j)
exact hasColimit_of_iso α
lemma hasProduct_of_equiv_of_iso (f : α → C) (g : β → C)
[HasProduct f] (e : β ≃ α) (iso : ∀ j, g j ≅ f (e j)) : HasProduct g := by
have : HasLimit ((Discrete.equivalence e).functor ⋙ Discrete.functor f) :=
hasLimitEquivalenceComp _
have α : Discrete.functor g ≅ (Discrete.equivalence e).functor ⋙ Discrete.functor f :=
Discrete.natIso (fun ⟨j⟩ => iso j)
exact hasLimit_of_iso α.symm
/-- Make a fan `f` into a limit fan by providing `lift`, `fac`, and `uniq` --
just a convenience lemma to avoid having to go through `Discrete` -/
@[simps]
def mkFanLimit {f : β → C} (t : Fan f) (lift : ∀ s : Fan f, s.pt ⟶ t.pt)
(fac : ∀ (s : Fan f) (j : β), lift s ≫ t.proj j = s.proj j := by aesop_cat)
(uniq : ∀ (s : Fan f) (m : s.pt ⟶ t.pt) (_ : ∀ j : β, m ≫ t.proj j = s.proj j),
m = lift s := by aesop_cat) :
IsLimit t :=
{ lift }
/-- Constructor for morphisms to the point of a limit fan. -/
def Fan.IsLimit.desc {F : β → C} {c : Fan F} (hc : IsLimit c) {A : C}
(f : ∀ i, A ⟶ F i) : A ⟶ c.pt :=
hc.lift (Fan.mk A f)
@[reassoc (attr := simp)]
lemma Fan.IsLimit.fac {F : β → C} {c : Fan F} (hc : IsLimit c) {A : C}
(f : ∀ i, A ⟶ F i) (i : β) :
Fan.IsLimit.desc hc f ≫ c.proj i = f i :=
hc.fac (Fan.mk A f) ⟨i⟩
lemma Fan.IsLimit.hom_ext {I : Type*} {F : I → C} {c : Fan F} (hc : IsLimit c) {A : C}
(f g : A ⟶ c.pt) (h : ∀ i, f ≫ c.proj i = g ≫ c.proj i) : f = g :=
hc.hom_ext (fun ⟨i⟩ => h i)
/-- Make a cofan `f` into a colimit cofan by providing `desc`, `fac`, and `uniq` --
just a convenience lemma to avoid having to go through `Discrete` -/
@[simps]
def mkCofanColimit {f : β → C} (s : Cofan f) (desc : ∀ t : Cofan f, s.pt ⟶ t.pt)
(fac : ∀ (t : Cofan f) (j : β), s.inj j ≫ desc t = t.inj j := by aesop_cat)
(uniq : ∀ (t : Cofan f) (m : s.pt ⟶ t.pt) (_ : ∀ j : β, s.inj j ≫ m = t.inj j),
m = desc t := by aesop_cat) :
IsColimit s :=
{ desc }
/-- Constructor for morphisms from the point of a colimit cofan. -/
def Cofan.IsColimit.desc {F : β → C} {c : Cofan F} (hc : IsColimit c) {A : C}
(f : ∀ i, F i ⟶ A) : c.pt ⟶ A :=
hc.desc (Cofan.mk A f)
@[reassoc (attr := simp)]
lemma Cofan.IsColimit.fac {F : β → C} {c : Cofan F} (hc : IsColimit c) {A : C}
(f : ∀ i, F i ⟶ A) (i : β) :
c.inj i ≫ Cofan.IsColimit.desc hc f = f i :=
hc.fac (Cofan.mk A f) ⟨i⟩
lemma Cofan.IsColimit.hom_ext {I : Type*} {F : I → C} {c : Cofan F} (hc : IsColimit c) {A : C}
(f g : c.pt ⟶ A) (h : ∀ i, c.inj i ≫ f = c.inj i ≫ g) : f = g :=
hc.hom_ext (fun ⟨i⟩ => h i)
section
variable (C)
/-- An abbreviation for `HasLimitsOfShape (Discrete f)`. -/
abbrev HasProductsOfShape (β : Type v) :=
HasLimitsOfShape.{v} (Discrete β)
/-- An abbreviation for `HasColimitsOfShape (Discrete f)`. -/
abbrev HasCoproductsOfShape (β : Type v) :=
HasColimitsOfShape.{v} (Discrete β)
end
/-- `piObj f` computes the product of a family of elements `f`.
(It is defined as an abbreviation for `limit (Discrete.functor f)`,
so for most facts about `piObj f`, you will just use general facts about limits.) -/
abbrev piObj (f : β → C) [HasProduct f] :=
limit (Discrete.functor f)
/-- `sigmaObj f` computes the coproduct of a family of elements `f`.
(It is defined as an abbreviation for `colimit (Discrete.functor f)`,
so for most facts about `sigmaObj f`, you will just use general facts about colimits.) -/
abbrev sigmaObj (f : β → C) [HasCoproduct f] :=
colimit (Discrete.functor f)
/-- notation for categorical products. We need `ᶜ` to avoid conflict with `Finset.prod`. -/
notation "∏ᶜ " f:60 => piObj f
/-- notation for categorical coproducts -/
notation "∐ " f:60 => sigmaObj f
/-- The `b`-th projection from the pi object over `f` has the form `∏ᶜ f ⟶ f b`. -/
abbrev Pi.π (f : β → C) [HasProduct f] (b : β) : ∏ᶜ f ⟶ f b :=
limit.π (Discrete.functor f) (Discrete.mk b)
/-- The `b`-th inclusion into the sigma object over `f` has the form `f b ⟶ ∐ f`. -/
abbrev Sigma.ι (f : β → C) [HasCoproduct f] (b : β) : f b ⟶ ∐ f :=
colimit.ι (Discrete.functor f) (Discrete.mk b)
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10688): added the next two lemmas to ease automation; without these lemmas,
-- `limit.hom_ext` would be applied, but the goal would involve terms
-- in `Discrete β` rather than `β` itself
@[ext 1050]
lemma Pi.hom_ext {f : β → C} [HasProduct f] {X : C} (g₁ g₂ : X ⟶ ∏ᶜ f)
(h : ∀ (b : β), g₁ ≫ Pi.π f b = g₂ ≫ Pi.π f b) : g₁ = g₂ :=
limit.hom_ext (fun ⟨j⟩ => h j)
@[ext 1050]
lemma Sigma.hom_ext {f : β → C} [HasCoproduct f] {X : C} (g₁ g₂ : ∐ f ⟶ X)
(h : ∀ (b : β), Sigma.ι f b ≫ g₁ = Sigma.ι f b ≫ g₂) : g₁ = g₂ :=
colimit.hom_ext (fun ⟨j⟩ => h j)
/-- The fan constructed of the projections from the product is limiting. -/
def productIsProduct (f : β → C) [HasProduct f] : IsLimit (Fan.mk _ (Pi.π f)) :=
IsLimit.ofIsoLimit (limit.isLimit (Discrete.functor f)) (Cones.ext (Iso.refl _))
/-- The cofan constructed of the inclusions from the coproduct is colimiting. -/
def coproductIsCoproduct (f : β → C) [HasCoproduct f] : IsColimit (Cofan.mk _ (Sigma.ι f)) :=
IsColimit.ofIsoColimit (colimit.isColimit (Discrete.functor f)) (Cocones.ext (Iso.refl _))
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `Pi.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem Pi.π_comp_eqToHom {J : Type*} (f : J → C) [HasProduct f] {j j' : J} (w : j = j') :
Pi.π f j ≫ eqToHom (by simp [w]) = Pi.π f j' := by
cases w
simp
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `Sigma.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem Sigma.eqToHom_comp_ι {J : Type*} (f : J → C) [HasCoproduct f] {j j' : J} (w : j = j') :
eqToHom (by simp [w]) ≫ Sigma.ι f j' = Sigma.ι f j := by
cases w
simp
/-- A collection of morphisms `P ⟶ f b` induces a morphism `P ⟶ ∏ᶜ f`. -/
abbrev Pi.lift {f : β → C} [HasProduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ∏ᶜ f :=
limit.lift _ (Fan.mk P p)
theorem Pi.lift_π {β : Type w} {f : β → C} [HasProduct f] {P : C} (p : ∀ b, P ⟶ f b) (b : β) :
Pi.lift p ≫ Pi.π f b = p b := by
simp only [limit.lift_π, Fan.mk_pt, Fan.mk_π_app]
/-- A version of `Cones.ext` for `Fan`s. -/
@[simps!]
def Fan.ext {f : β → C} {c₁ c₂ : Fan f} (e : c₁.pt ≅ c₂.pt)
(w : ∀ (b : β), c₁.proj b = e.hom ≫ c₂.proj b := by aesop_cat) : c₁ ≅ c₂ :=
Cones.ext e (fun ⟨j⟩ => w j)
/-- A collection of morphisms `f b ⟶ P` induces a morphism `∐ f ⟶ P`. -/
abbrev Sigma.desc {f : β → C} [HasCoproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ∐ f ⟶ P :=
colimit.desc _ (Cofan.mk P p)
theorem Sigma.ι_desc {β : Type w} {f : β → C} [HasCoproduct f] {P : C} (p : ∀ b, f b ⟶ P) (b : β) :
Sigma.ι f b ≫ Sigma.desc p = p b := by
simp only [colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app]
instance {f : β → C} [HasCoproduct f] : IsIso (Sigma.desc (fun a ↦ Sigma.ι f a)) := by
convert IsIso.id _
ext
simp
/-- A version of `Cocones.ext` for `Cofan`s. -/
@[simps!]
def Cofan.ext {f : β → C} {c₁ c₂ : Cofan f} (e : c₁.pt ≅ c₂.pt)
(w : ∀ (b : β), c₁.inj b ≫ e.hom = c₂.inj b := by aesop_cat) : c₁ ≅ c₂ :=
Cocones.ext e (fun ⟨j⟩ => w j)
/-- A cofan `c` on `f` such that the induced map `∐ f ⟶ c.pt` is an iso, is a coproduct. -/
def Cofan.isColimitOfIsIsoSigmaDesc {f : β → C} [HasCoproduct f] (c : Cofan f)
[hc : IsIso (Sigma.desc c.inj)] : IsColimit c :=
IsColimit.ofIsoColimit (colimit.isColimit (Discrete.functor f))
(Cofan.ext (@asIso _ _ _ _ _ hc) (fun _ => colimit.ι_desc _ _))
lemma Cofan.isColimit_iff_isIso_sigmaDesc {f : β → C} [HasCoproduct f] (c : Cofan f) :
IsIso (Sigma.desc c.inj) ↔ Nonempty (IsColimit c) := by
refine ⟨fun h ↦ ⟨isColimitOfIsIsoSigmaDesc c⟩, fun ⟨hc⟩ ↦ ?_⟩
have : IsIso (((coproductIsCoproduct f).coconePointUniqueUpToIso hc).hom ≫ hc.desc c) := by
simp; infer_instance
convert this
ext
simp only [colimit.ι_desc, mk_pt, mk_ι_app, IsColimit.coconePointUniqueUpToIso,
coproductIsCoproduct, colimit.cocone_x, Functor.mapIso_hom, IsColimit.uniqueUpToIso_hom,
Cocones.forget_map, IsColimit.descCoconeMorphism_hom, IsColimit.ofIsoColimit_desc,
Cocones.ext_inv_hom, Iso.refl_inv, colimit.isColimit_desc, Category.id_comp,
IsColimit.desc_self, Category.comp_id]
rfl
/-- A coproduct of coproducts is a coproduct -/
def Cofan.isColimitTrans {X : α → C} (c : Cofan X) (hc : IsColimit c)
{β : α → Type*} {Y : (a : α) → β a → C} (π : (a : α) → (b : β a) → Y a b ⟶ X a)
(hs : ∀ a, IsColimit (Cofan.mk (X a) (π a))) :
IsColimit (Cofan.mk (f := fun ⟨a,b⟩ => Y a b) c.pt
(fun (⟨a, b⟩ : Σ a, _) ↦ π a b ≫ c.inj a)) := by
refine mkCofanColimit _ ?_ ?_ ?_
· exact fun t ↦ hc.desc (Cofan.mk _ fun a ↦ (hs a).desc (Cofan.mk t.pt (fun b ↦ t.inj ⟨a, b⟩)))
· intro t ⟨a, b⟩
simp only [mk_pt, cofan_mk_inj, Category.assoc]
erw [hc.fac, (hs a).fac]
rfl
· intro t m h
refine hc.hom_ext fun ⟨a⟩ ↦ (hs a).hom_ext fun ⟨b⟩ ↦ ?_
erw [hc.fac, (hs a).fac]
simpa using h ⟨a, b⟩
/-- Construct a morphism between categorical products (indexed by the same type)
from a family of morphisms between the factors.
-/
abbrev Pi.map {f g : β → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b) : ∏ᶜ f ⟶ ∏ᶜ g :=
limMap (Discrete.natTrans fun X => p X.as)
@[simp]
lemma Pi.map_id {f : α → C} [HasProduct f] : Pi.map (fun a => 𝟙 (f a)) = 𝟙 (∏ᶜ f) := by
ext; simp
lemma Pi.map_comp_map {f g h : α → C} [HasProduct f] [HasProduct g] [HasProduct h]
(q : ∀ (a : α), f a ⟶ g a) (q' : ∀ (a : α), g a ⟶ h a) :
Pi.map q ≫ Pi.map q' = Pi.map (fun a => q a ≫ q' a) := by
ext; simp
instance Pi.map_mono {f g : β → C} [HasProduct f] [HasProduct g] (p : ∀ b, f b ⟶ g b)
[∀ i, Mono (p i)] : Mono <| Pi.map p :=
@Limits.limMap_mono _ _ _ _ (Discrete.functor f) (Discrete.functor g) _ _
(Discrete.natTrans fun X => p X.as) (by dsimp; infer_instance)
/-- Construct a morphism between categorical products from a family of morphisms between the
| factors. -/
def Pi.map' {f : α → C} {g : β → C} [HasProduct f] [HasProduct g] (p : β → α)
(q : ∀ (b : β), f (p b) ⟶ g b) : ∏ᶜ f ⟶ ∏ᶜ g :=
| Mathlib/CategoryTheory/Limits/Shapes/Products.lean | 332 | 334 |
/-
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.Algebra.Order.Ring.Nat
import Mathlib.Data.List.Chain
/-!
# List of booleans
In this file we prove lemmas about the number of `false`s and `true`s in a list of booleans. First
we prove that the number of `false`s plus the number of `true` equals the length of the list. Then
we prove that in a list with alternating `true`s and `false`s, the number of `true`s differs from
the number of `false`s by at most one. We provide several versions of these statements.
-/
namespace List
@[simp]
theorem count_not_add_count (l : List Bool) (b : Bool) : count (!b) l + count b l = length l := by
have := length_eq_countP_add_countP (l := l) (· == !b)
aesop (add simp this)
@[simp]
theorem count_add_count_not (l : List Bool) (b : Bool) : count b l + count (!b) l = length l := by
rw [add_comm, count_not_add_count]
@[simp]
theorem count_false_add_count_true (l : List Bool) : count false l + count true l = length l :=
count_not_add_count l true
|
@[simp]
| Mathlib/Data/Bool/Count.lean | 33 | 34 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.Minpoly.Field
import Mathlib.LinearAlgebra.SModEq
import Mathlib.RingTheory.Ideal.BigOperators
/-!
# Power basis
This file defines a structure `PowerBasis R S`, giving a basis of the
`R`-algebra `S` as a finite list of powers `1, x, ..., x^n`.
For example, if `x` is algebraic over a ring/field, adjoining `x`
gives a `PowerBasis` structure generated by `x`.
## Definitions
* `PowerBasis R A`: a structure containing an `x` and an `n` such that
`1, x, ..., x^n` is a basis for the `R`-algebra `A` (viewed as an `R`-module).
* `finrank (hf : f ≠ 0) : Module.finrank K (AdjoinRoot f) = f.natDegree`,
the dimension of `AdjoinRoot f` equals the degree of `f`
* `PowerBasis.lift (pb : PowerBasis R S)`: if `y : S'` satisfies the same
equations as `pb.gen`, this is the map `S →ₐ[R] S'` sending `pb.gen` to `y`
* `PowerBasis.equiv`: if two power bases satisfy the same equations, they are
equivalent as algebras
## Implementation notes
Throughout this file, `R`, `S`, `A`, `B` ... are `CommRing`s, and `K`, `L`, ... are `Field`s.
`S` is an `R`-algebra, `B` is an `A`-algebra, `L` is a `K`-algebra.
## Tags
power basis, powerbasis
-/
open Polynomial Finsupp
variable {R S T : Type*} [CommRing R] [Ring S] [Algebra R S]
variable {A B : Type*} [CommRing A] [CommRing B] [Algebra A B]
variable {K : Type*} [Field K]
/-- `pb : PowerBasis R S` states that `1, pb.gen, ..., pb.gen ^ (pb.dim - 1)`
is a basis for the `R`-algebra `S` (viewed as `R`-module).
This is a structure, not a class, since the same algebra can have many power bases.
For the common case where `S` is defined by adjoining an integral element to `R`,
the canonical power basis is given by `{Algebra,IntermediateField}.adjoin.powerBasis`.
-/
structure PowerBasis (R S : Type*) [CommRing R] [Ring S] [Algebra R S] where
gen : S
dim : ℕ
basis : Basis (Fin dim) R S
basis_eq_pow : ∀ (i), basis i = gen ^ (i : ℕ)
-- this is usually not needed because of `basis_eq_pow` but can be needed in some cases;
-- in such circumstances, add it manually using `@[simps dim gen basis]`.
initialize_simps_projections PowerBasis (-basis)
namespace PowerBasis
@[simp]
theorem coe_basis (pb : PowerBasis R S) : ⇑pb.basis = fun i : Fin pb.dim => pb.gen ^ (i : ℕ) :=
funext pb.basis_eq_pow
/-- Cannot be an instance because `PowerBasis` cannot be a class. -/
theorem finite (pb : PowerBasis R S) : Module.Finite R S := .of_basis pb.basis
theorem finrank [StrongRankCondition R] (pb : PowerBasis R S) :
Module.finrank R S = pb.dim := by
rw [Module.finrank_eq_card_basis pb.basis, Fintype.card_fin]
theorem mem_span_pow' {x y : S} {d : ℕ} :
y ∈ Submodule.span R (Set.range fun i : Fin d => x ^ (i : ℕ)) ↔
∃ f : R[X], f.degree < d ∧ y = aeval x f := by
have : (Set.range fun i : Fin d => x ^ (i : ℕ)) = (fun i : ℕ => x ^ i) '' ↑(Finset.range d) := by
ext n
simp_rw [Set.mem_range, Set.mem_image, Finset.mem_coe, Finset.mem_range]
exact ⟨fun ⟨⟨i, hi⟩, hy⟩ => ⟨i, hi, hy⟩, fun ⟨i, hi, hy⟩ => ⟨⟨i, hi⟩, hy⟩⟩
simp only [this, mem_span_image_iff_linearCombination, degree_lt_iff_coeff_zero, Finsupp.support,
exists_iff_exists_finsupp, coeff, aeval_def, eval₂RingHom', eval₂_eq_sum, Polynomial.sum,
mem_supported', linearCombination, Finsupp.sum, Algebra.smul_def, eval₂_zero, exists_prop,
LinearMap.id_coe, eval₂_one, id, not_lt, Finsupp.coe_lsum, LinearMap.coe_smulRight,
Finset.mem_range, AlgHom.coe_mks, Finset.mem_coe]
simp_rw [@eq_comm _ y]
exact Iff.rfl
theorem mem_span_pow {x y : S} {d : ℕ} (hd : d ≠ 0) :
y ∈ Submodule.span R (Set.range fun i : Fin d => x ^ (i : ℕ)) ↔
∃ f : R[X], f.natDegree < d ∧ y = aeval x f := by
rw [mem_span_pow']
constructor <;>
· rintro ⟨f, h, hy⟩
refine ⟨f, ?_, hy⟩
by_cases hf : f = 0
· simp only [hf, natDegree_zero, degree_zero] at h ⊢
first | exact lt_of_le_of_ne (Nat.zero_le d) hd.symm | exact WithBot.bot_lt_coe d
simp_all only [degree_eq_natDegree hf]
· first | exact WithBot.coe_lt_coe.1 h | exact WithBot.coe_lt_coe.2 h
theorem dim_ne_zero [Nontrivial S] (pb : PowerBasis R S) : pb.dim ≠ 0 := fun h =>
not_nonempty_iff.mpr (h.symm ▸ Fin.isEmpty : IsEmpty (Fin pb.dim)) pb.basis.index_nonempty
theorem dim_pos [Nontrivial S] (pb : PowerBasis R S) : 0 < pb.dim :=
Nat.pos_of_ne_zero pb.dim_ne_zero
theorem exists_eq_aeval [Nontrivial S] (pb : PowerBasis R S) (y : S) :
∃ f : R[X], f.natDegree < pb.dim ∧ y = aeval pb.gen f :=
(mem_span_pow pb.dim_ne_zero).mp (by simpa using pb.basis.mem_span y)
theorem exists_eq_aeval' (pb : PowerBasis R S) (y : S) : ∃ f : R[X], y = aeval pb.gen f := by
nontriviality S
obtain ⟨f, _, hf⟩ := exists_eq_aeval pb y
exact ⟨f, hf⟩
theorem algHom_ext {S' : Type*} [Semiring S'] [Algebra R S'] (pb : PowerBasis R S)
⦃f g : S →ₐ[R] S'⦄ (h : f pb.gen = g pb.gen) : f = g := by
ext x
obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x
rw [← Polynomial.aeval_algHom_apply, ← Polynomial.aeval_algHom_apply, h]
open Ideal Finset Submodule in
theorem exists_smodEq (pb : PowerBasis A B) (b : B) :
∃ a, SModEq (Ideal.span ({pb.gen})) b (algebraMap A B a) := by
rcases subsingleton_or_nontrivial B
· exact ⟨0, by rw [SModEq, Subsingleton.eq_zero b, map_zero]⟩
refine ⟨pb.basis.repr b ⟨0, pb.dim_pos⟩, ?_⟩
have H := pb.basis.sum_repr b
rw [← insert_erase (mem_univ ⟨0, pb.dim_pos⟩), sum_insert (not_mem_erase _ _)] at H
rw [SModEq, ← add_zero (algebraMap _ _ _), Quotient.mk_add]
nth_rewrite 1 [← H]
rw [Quotient.mk_add]
congr 1
· simp [Algebra.algebraMap_eq_smul_one ((pb.basis.repr b) _)]
· rw [Quotient.mk_zero, Quotient.mk_eq_zero, coe_basis]
refine sum_mem _ (fun i hi ↦ ?_)
rw [Algebra.smul_def']
refine Ideal.mul_mem_left _ _ <| Ideal.pow_mem_of_mem _ (Ideal.subset_span (by simp)) _ <|
Nat.pos_of_ne_zero <| fun h ↦ not_mem_erase i univ <| Fin.eq_mk_iff_val_eq.2 h ▸ hi
open Submodule.Quotient in
theorem exists_gen_dvd_sub (pb : PowerBasis A B) (b : B) : ∃ a, pb.gen ∣ b - algebraMap A B a := by
simpa [← Ideal.mem_span_singleton, ← mk_eq_zero, mk_sub, sub_eq_zero] using pb.exists_smodEq b
section minpoly
variable [Algebra A S]
/-- `pb.minpolyGen` is the minimal polynomial for `pb.gen`. -/
noncomputable def minpolyGen (pb : PowerBasis A S) : A[X] :=
X ^ pb.dim - ∑ i : Fin pb.dim, C (pb.basis.repr (pb.gen ^ pb.dim) i) * X ^ (i : ℕ)
theorem aeval_minpolyGen (pb : PowerBasis A S) : aeval pb.gen (minpolyGen pb) = 0 := by
simp_rw [minpolyGen, map_sub, map_sum, map_mul, map_pow, aeval_C, ← Algebra.smul_def, aeval_X]
refine sub_eq_zero.mpr ((pb.basis.linearCombination_repr (pb.gen ^ pb.dim)).symm.trans ?_)
rw [Finsupp.linearCombination_apply, Finsupp.sum_fintype] <;>
simp only [pb.coe_basis, zero_smul, eq_self_iff_true, imp_true_iff]
theorem minpolyGen_monic (pb : PowerBasis A S) : Monic (minpolyGen pb) := by
nontriviality A
apply (monic_X_pow _).sub_of_left _
rw [degree_X_pow]
exact degree_sum_fin_lt _
theorem dim_le_natDegree_of_root (pb : PowerBasis A S) {p : A[X]} (ne_zero : p ≠ 0)
(root : aeval pb.gen p = 0) : pb.dim ≤ p.natDegree := by
refine le_of_not_lt fun hlt => ne_zero ?_
rw [p.as_sum_range' _ hlt, Finset.sum_range]
refine Fintype.sum_eq_zero _ fun i => ?_
simp_rw [aeval_eq_sum_range' hlt, Finset.sum_range, ← pb.basis_eq_pow] at root
have := Fintype.linearIndependent_iff.1 pb.basis.linearIndependent _ root
| rw [this, monomial_zero_right]
theorem dim_le_degree_of_root (h : PowerBasis A S) {p : A[X]} (ne_zero : p ≠ 0)
(root : aeval h.gen p = 0) : ↑h.dim ≤ p.degree := by
| Mathlib/RingTheory/PowerBasis.lean | 180 | 183 |
/-
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]
| Mathlib/Analysis/InnerProductSpace/TwoDim.lean | 275 | 277 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) :
Real.exp x < 1 / (1 - x) := by
have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc
0 < x ^ 3 := by positivity
_ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring
calc
exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three
_ ≤ 1 + x + x ^ 2 := by
-- Porting note: was `norm_num [Finset.sum] <;> nlinarith`
-- This proof should be restored after the norm_num plugin for big operators is ported.
-- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.)
rw [show 3 = 1 + 1 + 1 from rfl]
repeat rw [Finset.sum_range_succ]
norm_num [Nat.factorial]
nlinarith
_ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith
theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) :
Real.exp x ≤ 1 / (1 - x) := by
rcases eq_or_lt_of_le h1 with (rfl | h1)
· simp
· exact (exp_bound_div_one_sub_of_interval' h1 h2).le
theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by
obtain hx | hx := hx.symm.lt_or_lt
· exact add_one_lt_exp_of_pos hx
obtain h' | h' := le_or_lt 1 (-x)
· linarith [x.exp_pos]
have hx' : 0 < x + 1 := by linarith
simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx']
using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h'
theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by
obtain rfl | hx := eq_or_ne x 0
· simp
· exact (add_one_lt_exp hx).le
lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) :=
(sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx
lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) :=
(sub_eq_neg_add _ _).trans_le <| add_one_le_exp _
theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rwa [Nat.cast_zero] at ht'
calc
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
gcongr
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
· exact one_sub_le_exp_neg _
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by
rw [le_inv_mul_iff₀ hc]
calc c * x
_ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one
_ ≤ _ := Real.add_one_le_exp (c * x)
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.exp $a) =>
assertInstancesCommute
pure (.positive q(Real.exp_pos $a))
| _, _, _ => throwError "not Real.exp"
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by
rw [← ofReal_exp]
exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _))
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal
end Complex
| Mathlib/Data/Complex/Exponential.lean | 721 | 721 | |
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Field.Canonical
import Mathlib.Algebra.Order.Nonneg.Floor
import Mathlib.Data.Real.Pointwise
import Mathlib.Data.NNReal.Defs
import Mathlib.Order.ConditionallyCompleteLattice.Group
/-!
# Basic results on nonnegative real numbers
This file contains all results on `NNReal` that do not directly follow from its basic structure.
As a consequence, it is a bit of a random collection of results, and is a good target for cleanup.
## Notations
This file uses `ℝ≥0` as a localized notation for `NNReal`.
-/
assert_not_exists Star
open Function
open scoped BigOperators
namespace NNReal
noncomputable instance : FloorSemiring ℝ≥0 := Nonneg.floorSemiring
@[simp, norm_cast]
theorem coe_indicator {α} (s : Set α) (f : α → ℝ≥0) (a : α) :
((s.indicator f a : ℝ≥0) : ℝ) = s.indicator (fun x => ↑(f x)) a :=
(toRealHom : ℝ≥0 →+ ℝ).map_indicator _ _ _
@[norm_cast]
theorem coe_list_sum (l : List ℝ≥0) : ((l.sum : ℝ≥0) : ℝ) = (l.map (↑)).sum :=
map_list_sum toRealHom l
@[norm_cast]
theorem coe_list_prod (l : List ℝ≥0) : ((l.prod : ℝ≥0) : ℝ) = (l.map (↑)).prod :=
map_list_prod toRealHom l
@[norm_cast]
theorem coe_multiset_sum (s : Multiset ℝ≥0) : ((s.sum : ℝ≥0) : ℝ) = (s.map (↑)).sum :=
map_multiset_sum toRealHom s
@[norm_cast]
theorem coe_multiset_prod (s : Multiset ℝ≥0) : ((s.prod : ℝ≥0) : ℝ) = (s.map (↑)).prod :=
map_multiset_prod toRealHom s
variable {ι : Type*} {s : Finset ι} {f : ι → ℝ}
@[simp, norm_cast]
theorem coe_sum (s : Finset ι) (f : ι → ℝ≥0) : ∑ i ∈ s, f i = ∑ i ∈ s, (f i : ℝ) :=
map_sum toRealHom _ _
@[simp, norm_cast]
lemma coe_expect (s : Finset ι) (f : ι → ℝ≥0) : 𝔼 i ∈ s, f i = 𝔼 i ∈ s, (f i : ℝ) :=
map_expect toRealHom ..
theorem _root_.Real.toNNReal_sum_of_nonneg (hf : ∀ i ∈ s, 0 ≤ f i) :
Real.toNNReal (∑ a ∈ s, f a) = ∑ a ∈ s, Real.toNNReal (f a) := by
rw [← coe_inj, NNReal.coe_sum, Real.coe_toNNReal _ (Finset.sum_nonneg hf)]
exact Finset.sum_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)]
@[simp, norm_cast]
theorem coe_prod (s : Finset ι) (f : ι → ℝ≥0) : ↑(∏ a ∈ s, f a) = ∏ a ∈ s, (f a : ℝ) :=
map_prod toRealHom _ _
theorem _root_.Real.toNNReal_prod_of_nonneg (hf : ∀ a, a ∈ s → 0 ≤ f a) :
Real.toNNReal (∏ a ∈ s, f a) = ∏ a ∈ s, Real.toNNReal (f a) := by
rw [← coe_inj, NNReal.coe_prod, Real.coe_toNNReal _ (Finset.prod_nonneg hf)]
exact Finset.prod_congr rfl fun x hxs => by rw [Real.coe_toNNReal _ (hf x hxs)]
theorem le_iInf_add_iInf {ι ι' : Sort*} [Nonempty ι] [Nonempty ι'] {f : ι → ℝ≥0} {g : ι' → ℝ≥0}
{a : ℝ≥0} (h : ∀ i j, a ≤ f i + g j) : a ≤ (⨅ i, f i) + ⨅ j, g j := by
rw [← NNReal.coe_le_coe, NNReal.coe_add, coe_iInf, coe_iInf]
exact le_ciInf_add_ciInf h
theorem mul_finset_sup {α} (r : ℝ≥0) (s : Finset α) (f : α → ℝ≥0) :
r * s.sup f = s.sup fun a => r * f a :=
Finset.comp_sup_eq_sup_comp _ (NNReal.mul_sup r) (mul_zero r)
theorem finset_sup_mul {α} (s : Finset α) (f : α → ℝ≥0) (r : ℝ≥0) :
s.sup f * r = s.sup fun a => f a * r :=
Finset.comp_sup_eq_sup_comp (· * r) (fun x y => NNReal.sup_mul x y r) (zero_mul r)
theorem finset_sup_div {α} {f : α → ℝ≥0} {s : Finset α} (r : ℝ≥0) :
s.sup f / r = s.sup fun a => f a / r := by simp only [div_eq_inv_mul, mul_finset_sup]
open Real
section Sub
/-!
### Lemmas about subtraction
In this section we provide a few lemmas about subtraction that do not fit well into any other
typeclass. For lemmas about subtraction and addition see lemmas about `OrderedSub` in the file
`Mathlib.Algebra.Order.Sub.Basic`. See also `mul_tsub` and `tsub_mul`.
-/
theorem sub_div (a b c : ℝ≥0) : (a - b) / c = a / c - b / c :=
tsub_div _ _ _
end Sub
section Csupr
open Set
variable {ι : Sort*} {f : ι → ℝ≥0}
theorem iInf_mul (f : ι → ℝ≥0) (a : ℝ≥0) : iInf f * a = ⨅ i, f i * a := by
rw [← coe_inj, NNReal.coe_mul, coe_iInf, coe_iInf]
exact Real.iInf_mul_of_nonneg (NNReal.coe_nonneg _) _
theorem mul_iInf (f : ι → ℝ≥0) (a : ℝ≥0) : a * iInf f = ⨅ i, a * f i := by
simpa only [mul_comm] using iInf_mul f a
theorem mul_iSup (f : ι → ℝ≥0) (a : ℝ≥0) : (a * ⨆ i, f i) = ⨆ i, a * f i := by
rw [← coe_inj, NNReal.coe_mul, NNReal.coe_iSup, NNReal.coe_iSup]
exact Real.mul_iSup_of_nonneg (NNReal.coe_nonneg _) _
theorem iSup_mul (f : ι → ℝ≥0) (a : ℝ≥0) : (⨆ i, f i) * a = ⨆ i, f i * a := by
rw [mul_comm, mul_iSup]
simp_rw [mul_comm]
theorem iSup_div (f : ι → ℝ≥0) (a : ℝ≥0) : (⨆ i, f i) / a = ⨆ i, f i / a := by
simp only [div_eq_mul_inv, iSup_mul]
theorem mul_iSup_le {a : ℝ≥0} {g : ℝ≥0} {h : ι → ℝ≥0} (H : ∀ j, g * h j ≤ a) : g * iSup h ≤ a := by
rw [mul_iSup]
exact ciSup_le' H
theorem iSup_mul_le {a : ℝ≥0} {g : ι → ℝ≥0} {h : ℝ≥0} (H : ∀ i, g i * h ≤ a) : iSup g * h ≤ a := by
rw [iSup_mul]
exact ciSup_le' H
theorem iSup_mul_iSup_le {a : ℝ≥0} {g h : ι → ℝ≥0} (H : ∀ i j, g i * h j ≤ a) :
iSup g * iSup h ≤ a :=
iSup_mul_le fun _ => mul_iSup_le <| H _
variable [Nonempty ι]
theorem le_mul_iInf {a : ℝ≥0} {g : ℝ≥0} {h : ι → ℝ≥0} (H : ∀ j, a ≤ g * h j) : a ≤ g * iInf h := by
rw [mul_iInf]
exact le_ciInf H
theorem le_iInf_mul {a : ℝ≥0} {g : ι → ℝ≥0} {h : ℝ≥0} (H : ∀ i, a ≤ g i * h) : a ≤ iInf g * h := by
rw [iInf_mul]
exact le_ciInf H
theorem le_iInf_mul_iInf {a : ℝ≥0} {g h : ι → ℝ≥0} (H : ∀ i j, a ≤ g i * h j) :
a ≤ iInf g * iInf h :=
le_iInf_mul fun i => le_mul_iInf <| H i
end Csupr
end NNReal
| Mathlib/Data/NNReal/Basic.lean | 865 | 868 | |
/-
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.SpecialFunctions.Gamma.Basic
import Mathlib.Analysis.SpecialFunctions.PolarCoord
import Mathlib.Analysis.Complex.Convex
import Mathlib.Data.Nat.Factorial.DoubleFactorial
/-!
# Gaussian integral
We prove various versions of the formula for the Gaussian integral:
* `integral_gaussian`: for real `b` we have `∫ x:ℝ, exp (-b * x^2) = √(π / b)`.
* `integral_gaussian_complex`: for complex `b` with `0 < re b` we have
`∫ x:ℝ, exp (-b * x^2) = (π / b) ^ (1 / 2)`.
* `integral_gaussian_Ioi` and `integral_gaussian_complex_Ioi`: variants for integrals over `Ioi 0`.
* `Complex.Gamma_one_half_eq`: the formula `Γ (1 / 2) = √π`.
-/
noncomputable section
open Real Set MeasureTheory Filter Asymptotics
open scoped Real Topology
open Complex hiding exp abs_of_nonneg
theorem exp_neg_mul_rpow_isLittleO_exp_neg {p b : ℝ} (hb : 0 < b) (hp : 1 < p) :
(fun x : ℝ => exp (- b * x ^ p)) =o[atTop] fun x : ℝ => exp (-x) := by
rw [isLittleO_exp_comp_exp_comp]
suffices Tendsto (fun x => x * (b * x ^ (p - 1) + -1)) atTop atTop by
refine Tendsto.congr' ?_ this
refine eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) (fun x hx => ?_)
rw [mem_Ioi] at hx
rw [rpow_sub_one hx.ne']
field_simp [hx.ne']
ring
apply tendsto_id.atTop_mul_atTop₀
refine tendsto_atTop_add_const_right atTop (-1 : ℝ) ?_
exact Tendsto.const_mul_atTop hb (tendsto_rpow_atTop (by linarith))
theorem exp_neg_mul_sq_isLittleO_exp_neg {b : ℝ} (hb : 0 < b) :
(fun x : ℝ => exp (-b * x ^ 2)) =o[atTop] fun x : ℝ => exp (-x) := by
simp_rw [← rpow_two]
exact exp_neg_mul_rpow_isLittleO_exp_neg hb one_lt_two
theorem rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg (s : ℝ) {b p : ℝ} (hp : 1 < p) (hb : 0 < b) :
(fun x : ℝ => x ^ s * exp (- b * x ^ p)) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by
apply ((isBigO_refl (fun x : ℝ => x ^ s) atTop).mul_isLittleO
(exp_neg_mul_rpow_isLittleO_exp_neg hb hp)).trans
simpa only [mul_comm] using Real.Gamma_integrand_isLittleO s
theorem rpow_mul_exp_neg_mul_sq_isLittleO_exp_neg {b : ℝ} (hb : 0 < b) (s : ℝ) :
(fun x : ℝ => x ^ s * exp (-b * x ^ 2)) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by
simp_rw [← rpow_two]
exact rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg s one_lt_two hb
theorem integrableOn_rpow_mul_exp_neg_rpow {p s : ℝ} (hs : -1 < s) (hp : 1 ≤ p) :
IntegrableOn (fun x : ℝ => x ^ s * exp (- x ^ p)) (Ioi 0) := by
obtain hp | hp := le_iff_lt_or_eq.mp hp
· have h_exp : ∀ x, ContinuousAt (fun x => exp (- x)) x := fun x => continuousAt_neg.rexp
rw [← Ioc_union_Ioi_eq_Ioi zero_le_one, integrableOn_union]
constructor
· rw [← integrableOn_Icc_iff_integrableOn_Ioc]
refine IntegrableOn.mul_continuousOn ?_ ?_ isCompact_Icc
· refine (intervalIntegrable_iff_integrableOn_Icc_of_le zero_le_one).mp ?_
exact intervalIntegral.intervalIntegrable_rpow' hs
· intro x _
change ContinuousWithinAt ((fun x => exp (- x)) ∘ (fun x => x ^ p)) (Icc 0 1) x
refine ContinuousAt.comp_continuousWithinAt (h_exp _) ?_
exact continuousWithinAt_id.rpow_const (Or.inr (le_of_lt (lt_trans zero_lt_one hp)))
· have h_rpow : ∀ (x r : ℝ), x ∈ Ici 1 → ContinuousWithinAt (fun x => x ^ r) (Ici 1) x := by
intro _ _ hx
refine continuousWithinAt_id.rpow_const (Or.inl ?_)
exact ne_of_gt (lt_of_lt_of_le zero_lt_one hx)
refine integrable_of_isBigO_exp_neg (by norm_num : (0 : ℝ) < 1 / 2)
(ContinuousOn.mul (fun x hx => h_rpow x s hx) (fun x hx => ?_)) (IsLittleO.isBigO ?_)
· change ContinuousWithinAt ((fun x => exp (- x)) ∘ (fun x => x ^ p)) (Ici 1) x
exact ContinuousAt.comp_continuousWithinAt (h_exp _) (h_rpow x p hx)
· convert rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg s hp (by norm_num : (0 : ℝ) < 1) using 3
rw [neg_mul, one_mul]
· simp_rw [← hp, Real.rpow_one]
convert Real.GammaIntegral_convergent (by linarith : 0 < s + 1) using 2
rw [add_sub_cancel_right, mul_comm]
theorem integrableOn_rpow_mul_exp_neg_mul_rpow {p s b : ℝ} (hs : -1 < s) (hp : 1 ≤ p) (hb : 0 < b) :
IntegrableOn (fun x : ℝ => x ^ s * exp (- b * x ^ p)) (Ioi 0) := by
have hib : 0 < b ^ (-p⁻¹) := rpow_pos_of_pos hb _
suffices IntegrableOn (fun x ↦ (b ^ (-p⁻¹)) ^ s * (x ^ s * exp (-x ^ p))) (Ioi 0) by
rw [show 0 = b ^ (-p⁻¹) * 0 by rw [mul_zero], ← integrableOn_Ioi_comp_mul_left_iff _ _ hib]
refine this.congr_fun (fun _ hx => ?_) measurableSet_Ioi
rw [← mul_assoc, mul_rpow, mul_rpow, ← rpow_mul (z := p), neg_mul, neg_mul, inv_mul_cancel₀,
rpow_neg_one, mul_inv_cancel_left₀]
all_goals linarith [mem_Ioi.mp hx]
refine Integrable.const_mul ?_ _
rw [← IntegrableOn]
exact integrableOn_rpow_mul_exp_neg_rpow hs hp
theorem integrableOn_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) :
IntegrableOn (fun x : ℝ => x ^ s * exp (-b * x ^ 2)) (Ioi 0) := by
simp_rw [← rpow_two]
exact integrableOn_rpow_mul_exp_neg_mul_rpow hs one_le_two hb
theorem integrable_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) :
Integrable fun x : ℝ => x ^ s * exp (-b * x ^ 2) := by
rw [← integrableOn_univ, ← @Iio_union_Ici _ _ (0 : ℝ), integrableOn_union,
integrableOn_Ici_iff_integrableOn_Ioi]
| refine ⟨?_, integrableOn_rpow_mul_exp_neg_mul_sq hb hs⟩
rw [← (Measure.measurePreserving_neg (volume : Measure ℝ)).integrableOn_comp_preimage
(Homeomorph.neg ℝ).measurableEmbedding]
simp only [Function.comp_def, neg_sq, neg_preimage, neg_Iio, neg_neg, neg_zero]
apply Integrable.mono' (integrableOn_rpow_mul_exp_neg_mul_sq hb hs)
· apply Measurable.aestronglyMeasurable
exact (measurable_id'.neg.pow measurable_const).mul
((measurable_id'.pow measurable_const).const_mul (-b)).exp
· have : MeasurableSet (Ioi (0 : ℝ)) := measurableSet_Ioi
filter_upwards [ae_restrict_mem this] with x hx
have h'x : 0 ≤ x := le_of_lt hx
rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (exp_pos _).le]
apply mul_le_mul_of_nonneg_right _ (exp_pos _).le
simpa [abs_of_nonneg h'x] using abs_rpow_le_abs_rpow (-x) s
theorem integrable_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) :
Integrable fun x : ℝ => exp (-b * x ^ 2) := by
simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by norm_num : (-1 : ℝ) < 0)
| Mathlib/Analysis/SpecialFunctions/Gaussian/GaussianIntegral.lean | 110 | 127 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Properties of inner product spaces
This file proves many basic properties of inner product spaces (real or complex).
## Main results
- `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants).
- `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many
variants).
- `inner_eq_sum_norm_sq_div_four`: the polarization identity.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {𝕜 E F : Type*} [RCLike 𝕜]
section BasicProperties_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local postfix:90 "†" => starRingEnd _
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ :=
InnerProductSpace.conj_inner_symm _ _
theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ :=
@inner_conj_symm ℝ _ _ _ _ x y
theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by
rw [← inner_conj_symm]
exact star_eq_zero
@[simp]
theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp
theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
InnerProductSpace.add_left _ _ _
theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by
rw [← inner_conj_symm, inner_add_left, RingHom.map_add]
simp only [inner_conj_symm]
theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]
theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]
section Algebra
variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 𝕜] [Module 𝕝 E]
[IsScalarTower 𝕝 𝕜 E] [StarModule 𝕝 𝕜]
/-- See `inner_smul_left` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r† • ⟪x, y⟫ := by
rw [← algebraMap_smul 𝕜 r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply,
← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul]
/-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star
(eg `ℕ`, `ℤ`, `ℚ≥0`, `ℚ`, `ℝ`). -/
lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial]
/-- See `inner_smul_right` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : ⟪x, r • y⟫ = r • ⟪x, y⟫ := by
rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply,
star_smul, star_star, ← starRingEnd_apply, inner_conj_symm]
end Algebra
/-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/
theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
inner_smul_left_eq_star_smul ..
theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_left _ _ _
theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left, conj_ofReal, Algebra.smul_def]
/-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/
theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
inner_smul_right_eq_smul ..
theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_right _ _ _
theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_right, Algebra.smul_def]
/-- The inner product as a sesquilinear form.
Note that in the case `𝕜 = ℝ` this is a bilinear form. -/
@[simps!]
def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=
LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫)
(fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _)
(fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _
/-- The real inner product as a bilinear form.
Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/
@[simps!]
def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip
/-- An inner product with a sum on the left. -/
theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ :=
map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _
/-- An inner product with a sum on the right. -/
theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ :=
map_sum (LinearMap.flip sesqFormOfInner x) _ _
/-- An inner product with a sum on the left, `Finsupp` version. -/
protected theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by
convert sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]
/-- An inner product with a sum on the right, `Finsupp` version. -/
protected theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by
convert inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]
protected theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by
simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul]
protected theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by
simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul]
@[simp]
theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by
rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul]
theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by
simp only [inner_zero_left, AddMonoidHom.map_zero]
@[simp]
theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by
rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero]
theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by
simp only [inner_zero_right, AddMonoidHom.map_zero]
theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=
PreInnerProductSpace.toCore.re_inner_nonneg x
theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ :=
@inner_self_nonneg ℝ F _ _ _ x
@[simp]
theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im (𝕜 := 𝕜) x)
theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by
rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow]
theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by
conv_rhs => rw [← inner_self_ofReal_re]
symm
exact norm_of_nonneg inner_self_nonneg
theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by
rw [← inner_self_re_eq_norm]
exact inner_self_ofReal_re _
theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ :=
@inner_self_ofReal_norm ℝ F _ _ _ x
theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj]
@[simp]
theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by
rw [← neg_one_smul 𝕜 x, inner_smul_left]
simp
@[simp]
theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by
rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm]
theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp
theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _
theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by
simp [sub_eq_add_neg, inner_add_left]
theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by
simp [sub_eq_add_neg, inner_add_right]
theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by
rw [← inner_conj_symm, mul_comm]
exact re_eq_norm_of_mul_conj (inner y x)
/-- Expand `⟪x + y, x + y⟫` -/
theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_add_left, inner_add_right]; ring
/-- Expand `⟪x + y, x + y⟫_ℝ` -/
theorem real_inner_add_add_self (x y : F) :
⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_add_add_self, this, add_left_inj]
ring
-- Expand `⟪x - y, x - y⟫`
theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `⟪x - y, x - y⟫_ℝ` -/
theorem real_inner_sub_sub_self (x y : F) :
⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_sub_sub_self, this, add_left_inj]
ring
/-- Parallelogram law -/
theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by
simp only [inner_add_add_self, inner_sub_sub_self]
ring
/-- **Cauchy–Schwarz inequality**. -/
theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
letI cd : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
InnerProductSpace.Core.inner_mul_inner_self_le x y
/-- Cauchy–Schwarz inequality for real inner products. -/
theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=
calc
⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by
rw [real_inner_comm y, ← norm_mul]
exact le_abs_self _
_ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y
end BasicProperties_Seminormed
section BasicProperties
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by
rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero]
theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
variable (𝕜)
theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]
theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)]
variable {𝕜}
@[simp]
theorem re_inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by
rw [← norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero]
@[simp]
lemma re_inner_self_pos {x : E} : 0 < re ⟪x, x⟫ ↔ x ≠ 0 := by
simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (𝕜 := 𝕜) (x := x).not
@[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos
@[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos
open scoped InnerProductSpace in
theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := re_inner_self_nonpos (𝕜 := ℝ)
open scoped InnerProductSpace in
theorem real_inner_self_pos {x : F} : 0 < ⟪x, x⟫_ℝ ↔ x ≠ 0 := re_inner_self_pos (𝕜 := ℝ)
/-- A family of vectors is linearly independent if they are nonzero
and orthogonal. -/
theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0)
(ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by
rw [linearIndependent_iff']
intro s g hg i hi
have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by
rw [inner_sum]
symm
convert Finset.sum_eq_single (M := 𝕜) i ?_ ?_
· rw [inner_smul_right]
· intro j _hj hji
rw [inner_smul_right, ho hji.symm, mul_zero]
· exact fun h => False.elim (h hi)
simpa [hg, hz] using h'
end BasicProperties
section Norm_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "IK" => @RCLike.I 𝕜 _
theorem norm_eq_sqrt_re_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) :=
calc
‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm
_ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_re_inner _)
@[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner
theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ :=
@norm_eq_sqrt_re_inner ℝ _ _ _ _ x
theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by
rw [@norm_eq_sqrt_re_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫),
sqrt_mul_self inner_self_nonneg]
theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by
rw [pow_two, inner_self_eq_norm_mul_norm]
theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by
have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x
simpa using h
theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by
rw [pow_two, real_inner_self_eq_norm_mul_norm]
/-- Expand the square -/
theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜]
rw [inner_add_add_self, two_mul]
simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add]
rw [← inner_conj_symm, conj_re]
alias norm_add_pow_two := norm_add_sq
/-- Expand the square -/
theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by
have h := @norm_add_sq ℝ _ _ _ _ x y
simpa using h
alias norm_add_pow_two_real := norm_add_sq_real
/-- Expand the square -/
theorem norm_add_mul_self (x y : E) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_add_sq _ _
/-- Expand the square -/
theorem norm_add_mul_self_real (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_add_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Expand the square -/
theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg,
sub_eq_add_neg]
alias norm_sub_pow_two := norm_sub_sq
/-- Expand the square -/
theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 :=
@norm_sub_sq ℝ _ _ _ _ _ _
alias norm_sub_pow_two_real := norm_sub_sq_real
/-- Expand the square -/
theorem norm_sub_mul_self (x y : E) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_sub_sq _ _
/-- Expand the square -/
theorem norm_sub_mul_self_real (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_sub_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Cauchy–Schwarz inequality with norm -/
theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by
rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜) x, norm_eq_sqrt_re_inner (𝕜 := 𝕜) y]
letI : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
exact InnerProductSpace.Core.norm_inner_le_norm x y
theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ :=
norm_inner_le_norm x y
theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=
le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ :=
(Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=
le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)
lemma inner_eq_zero_of_left {x : E} (y : E) (h : ‖x‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [← norm_eq_zero]
refine le_antisymm ?_ (by positivity)
exact norm_inner_le_norm _ _ |>.trans <| by simp [h]
lemma inner_eq_zero_of_right (x : E) {y : E} (h : ‖y‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h]
variable (𝕜)
include 𝕜 in
theorem parallelogram_law_with_norm (x y : E) :
‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by
simp only [← @inner_self_eq_norm_mul_norm 𝕜]
rw [← re.map_add, parallelogram_law, two_mul, two_mul]
simp only [re.map_add]
include 𝕜 in
theorem parallelogram_law_with_nnnorm (x y : E) :
‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) :=
Subtype.ext <| parallelogram_law_with_norm 𝕜 x y
variable {𝕜}
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := by
rw [@norm_add_mul_self 𝕜]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := by
rw [@norm_sub_mul_self 𝕜]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 := by
rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜]
ring
/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/
theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) :
im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 := by
simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re]
ring
/-- Polarization identity: The inner product, in terms of the norm. -/
theorem inner_eq_sum_norm_sq_div_four (x y : E) :
⟪x, y⟫ = ((‖x + y‖ : 𝕜) ^ 2 - (‖x - y‖ : 𝕜) ^ 2 +
((‖x - IK • y‖ : 𝕜) ^ 2 - (‖x + IK • y‖ : 𝕜) ^ 2) * IK) / 4 := by
rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,
im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four]
push_cast
simp only [sq, ← mul_div_right_comm, ← add_div]
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y
/-- Pythagorean theorem, if-and-only-if vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by
rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_eq_left, mul_eq_zero]
norm_num
/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/
theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x + y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by
rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := by
rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_eq_left, mul_eq_zero]
apply Or.inr
simp only [h, zero_re']
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector
inner product form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by
rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_eq_left, neg_eq_zero,
mul_eq_zero]
norm_num
/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square
roots. -/
theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x - y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by
rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, subtracting vectors, vector inner product
form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- The sum and difference of two vectors are orthogonal if and only
if they have the same norm. -/
theorem real_inner_add_sub_eq_zero_iff (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ := by
conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]
simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x,
sub_eq_zero, re_to_real]
constructor
· intro h
rw [add_comm] at h
linarith
· intro h
linarith
/-- Given two orthogonal vectors, their sum and difference have equal norms. -/
theorem norm_sub_eq_norm_add {v w : E} (h : ⟪v, w⟫ = 0) : ‖w - v‖ = ‖w + v‖ := by
rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]
simp only [h, ← @inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re',
zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm,
zero_add]
/-- The real inner product of two vectors, divided by the product of their
norms, has absolute value at most 1. -/
theorem abs_real_inner_div_norm_mul_norm_le_one (x y : F) : |⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| ≤ 1 := by
rw [abs_div, abs_mul, abs_norm, abs_norm]
exact div_le_one_of_le₀ (abs_real_inner_le_norm x y) (by positivity)
/-- The inner product of a vector with a multiple of itself. -/
theorem real_inner_smul_self_left (x : F) (r : ℝ) : ⟪r • x, x⟫_ℝ = r * (‖x‖ * ‖x‖) := by
rw [real_inner_smul_left, ← real_inner_self_eq_norm_mul_norm]
/-- The inner product of a vector with a multiple of itself. -/
theorem real_inner_smul_self_right (x : F) (r : ℝ) : ⟪x, r • x⟫_ℝ = r * (‖x‖ * ‖x‖) := by
rw [inner_smul_right, ← real_inner_self_eq_norm_mul_norm]
/-- The inner product of two weighted sums, where the weights in each
sum add to 0, in terms of the norms of pairwise differences. -/
theorem inner_sum_smul_sum_smul_of_sum_eq_zero {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ}
(v₁ : ι₁ → F) (h₁ : ∑ i ∈ s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ}
(v₂ : ι₂ → F) (h₂ : ∑ i ∈ s₂, w₂ i = 0) :
⟪∑ i₁ ∈ s₁, w₁ i₁ • v₁ i₁, ∑ i₂ ∈ s₂, w₂ i₂ • v₂ i₂⟫_ℝ =
(-∑ i₁ ∈ s₁, ∑ i₂ ∈ s₂, w₁ i₁ * w₂ i₂ * (‖v₁ i₁ - v₂ i₂‖ * ‖v₁ i₁ - v₂ i₂‖)) / 2 := by
simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, ← div_sub_div_same,
← div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib,
Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul, h₁, h₂, zero_mul,
mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div,
Finset.sum_div, mul_div_assoc, mul_assoc]
end Norm_Seminormed
section Norm
open scoped InnerProductSpace
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
variable {ι : Type*}
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- Formula for the distance between the images of two nonzero points under an inversion with center
zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general
point. -/
theorem dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) :
dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y :=
calc
dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) =
√(‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) := by
rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]
_ = √((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) :=
congr_arg sqrt <| by
field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right,
Real.norm_of_nonneg (mul_self_nonneg _)]
ring
_ = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := by
rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
theorem norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : E} {r : 𝕜} (hx : x ≠ 0)
(hr : r ≠ 0) : ‖⟪x, r • x⟫‖ / (‖x‖ * ‖r • x‖) = 1 := by
have hx' : ‖x‖ ≠ 0 := by simp [hx]
have hr' : ‖r‖ ≠ 0 := by simp [hr]
rw [inner_smul_right, norm_mul, ← inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul]
rw [← mul_assoc, ← div_div, mul_div_cancel_right₀ _ hx', ← div_div, mul_comm,
mul_div_cancel_right₀ _ hr', div_self hx']
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
theorem abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : F} {r : ℝ}
(hx : x ≠ 0) (hr : r ≠ 0) : |⟪x, r • x⟫_ℝ| / (‖x‖ * ‖r • x‖) = 1 :=
norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of a nonzero vector with a positive multiple of
itself, divided by the product of their norms, has value 1. -/
theorem real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul {x : F} {r : ℝ} (hx : x ≠ 0)
(hr : 0 < r) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = 1 := by
rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|,
mul_assoc, abs_of_nonneg hr.le, div_self]
exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
/-- The inner product of a nonzero vector with a negative multiple of
itself, divided by the product of their norms, has value -1. -/
theorem real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul {x : F} {r : ℝ} (hx : x ≠ 0)
(hr : r < 0) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = -1 := by
rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|,
mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self]
exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
theorem norm_inner_eq_norm_tfae (x y : E) :
List.TFAE [‖⟪x, y⟫‖ = ‖x‖ * ‖y‖,
x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫) • x,
x = 0 ∨ ∃ r : 𝕜, y = r • x,
x = 0 ∨ y ∈ 𝕜 ∙ x] := by
tfae_have 1 → 2 := by
refine fun h => or_iff_not_imp_left.2 fun hx₀ => ?_
have : ‖x‖ ^ 2 ≠ 0 := pow_ne_zero _ (norm_ne_zero_iff.2 hx₀)
rw [← sq_eq_sq₀, mul_pow, ← mul_right_inj' this, eq_comm, ← sub_eq_zero, ← mul_sub] at h <;>
try positivity
simp only [@norm_sq_eq_re_inner 𝕜] at h
letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore
erw [← InnerProductSpace.Core.cauchy_schwarz_aux (𝕜 := 𝕜) (F := E)] at h
rw [InnerProductSpace.Core.normSq_eq_zero, sub_eq_zero] at h
rw [div_eq_inv_mul, mul_smul, h, inv_smul_smul₀]
rwa [inner_self_ne_zero]
tfae_have 2 → 3 := fun h => h.imp_right fun h' => ⟨_, h'⟩
tfae_have 3 → 1 := by
rintro (rfl | ⟨r, rfl⟩) <;>
simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm,
sq, mul_left_comm]
tfae_have 3 ↔ 4 := by simp only [Submodule.mem_span_singleton, eq_comm]
tfae_finish
/-- If the inner product of two vectors is equal to the product of their norms, then the two vectors
are multiples of each other. One form of the equality case for Cauchy-Schwarz.
Compare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
theorem norm_inner_eq_norm_iff {x y : E} (hx₀ : x ≠ 0) (hy₀ : y ≠ 0) :
‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :=
calc
‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ x = 0 ∨ ∃ r : 𝕜, y = r • x :=
(@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 2
_ ↔ ∃ r : 𝕜, y = r • x := or_iff_right hx₀
_ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :=
⟨fun ⟨r, h⟩ => ⟨r, fun hr₀ => hy₀ <| h.symm ▸ smul_eq_zero.2 <| Or.inl hr₀, h⟩,
fun ⟨r, _hr₀, h⟩ => ⟨r, h⟩⟩
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
theorem norm_inner_div_norm_mul_norm_eq_one_iff (x y : E) :
‖⟪x, y⟫ / (‖x‖ * ‖y‖)‖ = 1 ↔ x ≠ 0 ∧ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x := by
constructor
· intro h
have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h
have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h
refine ⟨hx₀, (norm_inner_eq_norm_iff hx₀ hy₀).1 <| eq_of_div_eq_one ?_⟩
simpa using h
· rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩
simp only [norm_div, norm_mul, norm_ofReal, abs_norm]
exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
theorem abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
|⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r ≠ 0 ∧ y = r • x :=
@norm_inner_div_norm_mul_norm_eq_one_iff ℝ F _ _ _ x y
theorem inner_eq_norm_mul_iff_div {x y : E} (h₀ : x ≠ 0) :
⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ / ‖x‖ : 𝕜) • x = y := by
have h₀' := h₀
rw [← norm_ne_zero_iff, Ne, ← @ofReal_eq_zero 𝕜] at h₀'
constructor <;> intro h
· have : x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫ : 𝕜) • x :=
((@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 1).1 (by simp [h])
rw [this.resolve_left h₀, h]
simp [norm_smul, inner_self_ofReal_norm, mul_div_cancel_right₀ _ h₀']
· conv_lhs => rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K]
field_simp [sq, mul_left_comm]
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
theorem inner_eq_norm_mul_iff {x y : E} :
⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ : 𝕜) • x = (‖x‖ : 𝕜) • y := by
rcases eq_or_ne x 0 with (rfl | h₀)
· simp
· rw [inner_eq_norm_mul_iff_div h₀, div_eq_inv_mul, mul_smul, inv_smul_eq_iff₀]
rwa [Ne, ofReal_eq_zero, norm_eq_zero]
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
theorem inner_eq_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ = ‖x‖ * ‖y‖ ↔ ‖y‖ • x = ‖x‖ • y :=
inner_eq_norm_mul_iff
/-- The inner product of two vectors, divided by the product of their
norms, has value 1 if and only if they are nonzero and one is
a positive multiple of the other. -/
theorem real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x := by
constructor
· intro h
have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h
have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h
refine ⟨hx₀, ‖y‖ / ‖x‖, div_pos (norm_pos_iff.2 hy₀) (norm_pos_iff.2 hx₀), ?_⟩
exact ((inner_eq_norm_mul_iff_div hx₀).1 (eq_of_div_eq_one h)).symm
· rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩
exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr
/-- The inner product of two vectors, divided by the product of their
norms, has value -1 if and only if they are nonzero and one is
a negative multiple of the other. -/
theorem real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :
⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = -1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x := by
rw [← neg_eq_iff_eq_neg, ← neg_div, ← inner_neg_right, ← norm_neg y,
real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective ℝ _).exists]
refine Iff.rfl.and (exists_congr fun r => ?_)
rw [neg_pos, neg_smul, neg_inj]
/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of
the equality case for Cauchy-Schwarz. -/
theorem inner_eq_one_iff_of_norm_one {x y : E} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :
⟪x, y⟫ = 1 ↔ x = y := by
convert inner_eq_norm_mul_iff (𝕜 := 𝕜) (E := E) using 2 <;> simp [hx, hy]
theorem inner_lt_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ‖y‖ • x ≠ ‖x‖ • y :=
calc
⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ ≠ ‖x‖ * ‖y‖ :=
⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩
_ ↔ ‖y‖ • x ≠ ‖x‖ • y := not_congr inner_eq_norm_mul_iff_real
/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are
distinct. One form of the equality case for Cauchy-Schwarz. -/
theorem inner_lt_one_iff_real_of_norm_one {x y : F} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :
⟪x, y⟫_ℝ < 1 ↔ x ≠ y := by convert inner_lt_norm_mul_iff_real (F := F) <;> simp [hx, hy]
/-- The sphere of radius `r = ‖y‖` is tangent to the plane `⟪x, y⟫ = ‖y‖ ^ 2` at `x = y`. -/
theorem eq_of_norm_le_re_inner_eq_norm_sq {x y : E} (hle : ‖x‖ ≤ ‖y‖) (h : re ⟪x, y⟫ = ‖y‖ ^ 2) :
x = y := by
suffices H : re ⟪x - y, x - y⟫ ≤ 0 by rwa [re_inner_self_nonpos, sub_eq_zero] at H
have H₁ : ‖x‖ ^ 2 ≤ ‖y‖ ^ 2 := by gcongr
have H₂ : re ⟪y, x⟫ = ‖y‖ ^ 2 := by rwa [← inner_conj_symm, conj_re]
simpa [inner_sub_left, inner_sub_right, ← norm_sq_eq_re_inner, h, H₂] using H₁
end Norm
section RCLike
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- A field `𝕜` satisfying `RCLike` is itself a `𝕜`-inner product space. -/
instance RCLike.innerProductSpace : InnerProductSpace 𝕜 𝕜 where
inner x y := y * conj x
norm_sq_eq_re_inner x := by simp only [inner, mul_conj, ← ofReal_pow, ofReal_re]
conj_inner_symm x y := by simp only [mul_comm, map_mul, starRingEnd_self_apply]
add_left x y z := by simp only [mul_add, map_add]
smul_left x y z := by simp only [mul_comm (conj z), mul_assoc, smul_eq_mul, map_mul]
@[simp]
theorem RCLike.inner_apply (x y : 𝕜) : ⟪x, y⟫ = y * conj x :=
rfl
/-- A version of `RCLike.inner_apply` that swaps the order of multiplication. -/
theorem RCLike.inner_apply' (x y : 𝕜) : ⟪x, y⟫ = conj x * y := mul_comm _ _
end RCLike
section RCLikeToReal
open scoped InnerProductSpace
variable {G : Type*}
variable (𝕜 E)
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- A general inner product implies a real inner product. This is not registered as an instance
since `𝕜` does not appear in the return type `Inner ℝ E`. -/
def Inner.rclikeToReal : Inner ℝ E where inner x y := re ⟪x, y⟫
/-- A general inner product space structure implies a real inner product structure.
This is not registered as an instance since
* `𝕜` does not appear in the return type `InnerProductSpace ℝ E`,
* It is likely to create instance diamonds, as it builds upon the diamond-prone
`NormedSpace.restrictScalars`.
However, it can be used in a proof to obtain a real inner product space structure from a given
`𝕜`-inner product space structure. -/
-- See note [reducible non instances]
abbrev InnerProductSpace.rclikeToReal : InnerProductSpace ℝ E :=
{ Inner.rclikeToReal 𝕜 E,
NormedSpace.restrictScalars ℝ 𝕜
E with
norm_sq_eq_re_inner := norm_sq_eq_re_inner
conj_inner_symm := fun _ _ => inner_re_symm _ _
add_left := fun x y z => by
change re ⟪x + y, z⟫ = re ⟪x, z⟫ + re ⟪y, z⟫
simp only [inner_add_left, map_add]
smul_left := fun x y r => by
change re ⟪(r : 𝕜) • x, y⟫ = r * re ⟪x, y⟫
simp only [inner_smul_left, conj_ofReal, re_ofReal_mul] }
variable {E}
theorem real_inner_eq_re_inner (x y : E) :
@Inner.inner ℝ E (Inner.rclikeToReal 𝕜 E) x y = re ⟪x, y⟫ :=
rfl
theorem real_inner_I_smul_self (x : E) :
@Inner.inner ℝ E (Inner.rclikeToReal 𝕜 E) x ((I : 𝕜) • x) = 0 := by
simp [real_inner_eq_re_inner 𝕜, inner_smul_right]
/-- A complex inner product implies a real inner product. This cannot be an instance since it
creates a diamond with `PiLp.innerProductSpace` because `re (sum i, inner (x i) (y i))` and
`sum i, re (inner (x i) (y i))` are not defeq. -/
def InnerProductSpace.complexToReal [SeminormedAddCommGroup G] [InnerProductSpace ℂ G] :
InnerProductSpace ℝ G :=
InnerProductSpace.rclikeToReal ℂ G
instance : InnerProductSpace ℝ ℂ := InnerProductSpace.complexToReal
@[simp]
protected theorem Complex.inner (w z : ℂ) : ⟪w, z⟫_ℝ = (z * conj w).re :=
rfl
end RCLikeToReal
/-- An `RCLike` field is a real inner product space. -/
noncomputable instance RCLike.toInnerProductSpaceReal : InnerProductSpace ℝ 𝕜 where
__ := Inner.rclikeToReal 𝕜 𝕜
norm_sq_eq_re_inner := norm_sq_eq_re_inner
conj_inner_symm x y := inner_re_symm ..
add_left x y z :=
show re (_ * _) = re (_ * _) + re (_ * _) by simp only [map_add, mul_re, conj_re, conj_im]; ring
smul_left x y r :=
show re (_ * _) = _ * re (_ * _) by
simp only [mul_re, conj_re, conj_im, conj_trivial, smul_re, smul_im]; ring
-- The instance above does not create diamonds for concrete `𝕜`:
example : (innerProductSpace : InnerProductSpace ℝ ℝ) = RCLike.toInnerProductSpaceReal := rfl
example :
(instInnerProductSpaceRealComplex : InnerProductSpace ℝ ℂ) = RCLike.toInnerProductSpaceReal := rfl
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 1,893 | 1,909 | |
/-
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.Algebra.Group.TypeTags.Basic
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Finset.Piecewise
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Filter.Curry
import Mathlib.Topology.Constructions.SumProd
import Mathlib.Topology.NhdsSet
/-!
# Constructions of new topological spaces from old ones
This file constructs pi types, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, subspace, quotient space
-/
noncomputable section
open Topology TopologicalSpace Set Filter Function
open scoped Set.Notation
universe u v u' v'
variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*}
section Constructions
instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) :=
coinduced (Quot.mk r) t
instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] :
TopologicalSpace (Quotient s) :=
coinduced Quotient.mk' t
instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] :
TopologicalSpace (Sigma X) :=
⨆ i, coinduced (Sigma.mk i) (t₂ i)
instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] :
TopologicalSpace ((i : ι) → Y i) :=
⨅ i, induced (fun f => f i) (t₂ i)
instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) :=
t.induced ULift.down
/-!
### `Additive`, `Multiplicative`
The topology on those type synonyms is inherited without change.
-/
section
variable [TopologicalSpace X]
open Additive Multiplicative
instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X›
instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X›
instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X›
theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id
theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id
theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id
theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id
theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id
theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id
theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id
theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id
theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id
theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id
theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id
theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id
theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl
theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl
theorem nhds_toMul (x : Additive X) : 𝓝 x.toMul = map toMul (𝓝 x) := rfl
theorem nhds_toAdd (x : Multiplicative X) : 𝓝 x.toAdd = map toAdd (𝓝 x) := rfl
end
/-!
### Order dual
The topology on this type synonym is inherited without change.
-/
section
variable [TopologicalSpace X]
open OrderDual
instance OrderDual.instTopologicalSpace : TopologicalSpace Xᵒᵈ := ‹_›
instance OrderDual.instDiscreteTopology [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹_›
theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id
theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id
theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id
theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id
theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id
theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id
theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl
theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl
variable [Preorder X] {x : X}
instance OrderDual.instNeBotNhdsWithinIoi [(𝓝[<] x).NeBot] : (𝓝[>] toDual x).NeBot := ‹_›
instance OrderDual.instNeBotNhdsWithinIio [(𝓝[>] x).NeBot] : (𝓝[<] toDual x).NeBot := ‹_›
end
theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s}
{x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x :=
preimage_nhds_coinduced hs
/-- The image of a dense set under `Quotient.mk'` is a dense set. -/
theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) :
Dense (Quotient.mk' '' s) :=
Quotient.mk''_surjective.denseRange.dense_image continuous_coinduced_rng H
/-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/
theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) :
DenseRange (Quotient.mk' ∘ f) :=
Quotient.mk''_surjective.denseRange.comp hf continuous_coinduced_rng
theorem continuous_map_of_le {α : Type*} [TopologicalSpace α]
{s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) :=
continuous_coinduced_rng
theorem continuous_map_sInf {α : Type*} [TopologicalSpace α]
{S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) :=
continuous_coinduced_rng
instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) :=
⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩
instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X]
[hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) :=
⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩
instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)]
[h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) :=
⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩
@[simp] lemma comap_nhdsWithin_range {α β} [TopologicalSpace β] (f : α → β) (y : β) :
comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range
section Top
variable [TopologicalSpace X]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t :=
mem_nhds_induced _ x t
theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) :=
nhds_induced _ x
lemma nhds_subtype_eq_comap_nhdsWithin (s : Set X) (x : { x // x ∈ s }) :
𝓝 x = comap (↑) (𝓝[s] (x : X)) := by
rw [nhds_subtype, ← comap_nhdsWithin_range, Subtype.range_val]
theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} :
𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by
rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal,
nhds_induced]
theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} :
𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by
rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton,
Subtype.coe_injective.preimage_image]
theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} :
(𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by
rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff]
theorem discreteTopology_subtype_iff {S : Set X} :
DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by
simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff]
end Top
/-- A type synonym equipped with the topology whose open sets are the empty set and the sets with
finite complements. -/
def CofiniteTopology (X : Type*) := X
namespace CofiniteTopology
/-- The identity equivalence between `` and `CofiniteTopology `. -/
def of : X ≃ CofiniteTopology X :=
Equiv.refl X
instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default
instance : TopologicalSpace (CofiniteTopology X) where
IsOpen s := s.Nonempty → Set.Finite sᶜ
isOpen_univ := by simp
isOpen_inter s t := by
rintro hs ht ⟨x, hxs, hxt⟩
rw [compl_inter]
exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩)
isOpen_sUnion := by
rintro s h ⟨x, t, hts, hzt⟩
rw [compl_sUnion]
exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩)
theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite :=
Iff.rfl
theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by
simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left]
theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by
simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff]
theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by
ext U
rw [mem_nhds_iff]
constructor
· rintro ⟨V, hVU, V_op, haV⟩
exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩
· rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩
exact ⟨U, Subset.rfl, fun _ => hU', hU⟩
theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} :
s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq]
end CofiniteTopology
end Constructions
section Prod
variable [TopologicalSpace X] [TopologicalSpace Y]
theorem MapClusterPt.curry_prodMap {α β : Type*}
{f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y}
(hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) :
MapClusterPt (x, y) (la.curry lb) (.map f g) := by
rw [mapClusterPt_iff_frequently] at hf hg
rw [((𝓝 x).basis_sets.prod_nhds (𝓝 y).basis_sets).mapClusterPt_iff_frequently]
rintro ⟨s, t⟩ ⟨hs, ht⟩
rw [frequently_curry_iff]
exact (hf s hs).mono fun x hx ↦ (hg t ht).mono fun y hy ↦ ⟨hx, hy⟩
theorem MapClusterPt.prodMap {α β : Type*}
{f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y}
(hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) :
MapClusterPt (x, y) (la ×ˢ lb) (.map f g) :=
(hf.curry_prodMap hg).mono <| map_mono curry_le_prod
end Prod
section Bool
lemma continuous_bool_rng [TopologicalSpace X] {f : X → Bool} (b : Bool) :
Continuous f ↔ IsClopen (f ⁻¹' {b}) := by
rw [continuous_discrete_rng, Bool.forall_bool' b, IsClopen, ← isOpen_compl_iff, ← preimage_compl,
Bool.compl_singleton, and_comm]
end Bool
section Subtype
variable [TopologicalSpace X] [TopologicalSpace Y] {p : X → Prop}
lemma Topology.IsInducing.subtypeVal {t : Set Y} : IsInducing ((↑) : t → Y) := ⟨rfl⟩
@[deprecated (since := "2024-10-28")] alias inducing_subtype_val := IsInducing.subtypeVal
lemma Topology.IsInducing.of_codRestrict {f : X → Y} {t : Set Y} (ht : ∀ x, f x ∈ t)
(h : IsInducing (t.codRestrict f ht)) : IsInducing f := subtypeVal.comp h
@[deprecated (since := "2024-10-28")] alias Inducing.of_codRestrict := IsInducing.of_codRestrict
lemma Topology.IsEmbedding.subtypeVal : IsEmbedding ((↑) : Subtype p → X) :=
⟨.subtypeVal, Subtype.coe_injective⟩
@[deprecated (since := "2024-10-26")] alias embedding_subtype_val := IsEmbedding.subtypeVal
theorem Topology.IsClosedEmbedding.subtypeVal (h : IsClosed {a | p a}) :
IsClosedEmbedding ((↑) : Subtype p → X) :=
⟨.subtypeVal, by rwa [Subtype.range_coe_subtype]⟩
@[continuity, fun_prop]
theorem continuous_subtype_val : Continuous (@Subtype.val X p) :=
continuous_induced_dom
theorem Continuous.subtype_val {f : Y → Subtype p} (hf : Continuous f) :
Continuous fun x => (f x : X) :=
continuous_subtype_val.comp hf
theorem IsOpen.isOpenEmbedding_subtypeVal {s : Set X} (hs : IsOpen s) :
IsOpenEmbedding ((↑) : s → X) :=
⟨.subtypeVal, (@Subtype.range_coe _ s).symm ▸ hs⟩
theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s → X) :=
hs.isOpenEmbedding_subtypeVal.isOpenMap
theorem IsOpenMap.restrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} (hs : IsOpen s) :
IsOpenMap (s.restrict f) :=
hf.comp hs.isOpenMap_subtype_val
lemma IsClosed.isClosedEmbedding_subtypeVal {s : Set X} (hs : IsClosed s) :
IsClosedEmbedding ((↑) : s → X) := .subtypeVal hs
theorem IsClosed.isClosedMap_subtype_val {s : Set X} (hs : IsClosed s) :
IsClosedMap ((↑) : s → X) :=
hs.isClosedEmbedding_subtypeVal.isClosedMap
@[continuity, fun_prop]
theorem Continuous.subtype_mk {f : Y → X} (h : Continuous f) (hp : ∀ x, p (f x)) :
Continuous fun x => (⟨f x, hp x⟩ : Subtype p) :=
continuous_induced_rng.2 h
theorem Continuous.subtype_map {f : X → Y} (h : Continuous f) {q : Y → Prop}
(hpq : ∀ x, p x → q (f x)) : Continuous (Subtype.map f hpq) :=
(h.comp continuous_subtype_val).subtype_mk _
theorem continuous_inclusion {s t : Set X} (h : s ⊆ t) : Continuous (inclusion h) :=
continuous_id.subtype_map h
theorem continuousAt_subtype_val {p : X → Prop} {x : Subtype p} :
ContinuousAt ((↑) : Subtype p → X) x :=
continuous_subtype_val.continuousAt
theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s ⊆ closure ((↑) '' t) := by
rw [IsInducing.subtypeVal.dense_iff, SetCoe.forall]
rfl
theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s → X) (𝓝 x) = 𝓝[s] ↑x := by
rw [IsInducing.subtypeVal.map_nhds_eq, Subtype.range_val]
theorem map_nhds_subtype_coe_eq_nhds {x : X} (hx : p x) (h : ∀ᶠ x in 𝓝 x, p x) :
map ((↑) : Subtype p → X) (𝓝 ⟨x, hx⟩) = 𝓝 x :=
map_nhds_induced_of_mem <| by rw [Subtype.range_val]; exact h
theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) :=
nhds_induced _ _
theorem tendsto_subtype_rng {Y : Type*} {p : X → Prop} {l : Filter Y} {f : Y → Subtype p} :
∀ {x : Subtype p}, Tendsto f l (𝓝 x) ↔ Tendsto (fun x => (f x : X)) l (𝓝 (x : X))
| ⟨a, ha⟩ => by rw [nhds_subtype_eq_comap, tendsto_comap_iff]; rfl
theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} :
x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ → X) '' s) :=
closure_induced
@[simp]
theorem continuousAt_codRestrict_iff {f : X → Y} {t : Set Y} (h1 : ∀ x, f x ∈ t) {x : X} :
ContinuousAt (codRestrict f t h1) x ↔ ContinuousAt f x :=
IsInducing.subtypeVal.continuousAt_iff
alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff
theorem ContinuousAt.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) {x : s}
(h2 : ContinuousAt f x) : ContinuousAt (h1.restrict f s t) x :=
(h2.comp continuousAt_subtype_val).codRestrict _
theorem ContinuousAt.restrictPreimage {f : X → Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) :
ContinuousAt (s.restrictPreimage f) x :=
h.restrict _
@[continuity, fun_prop]
theorem Continuous.codRestrict {f : X → Y} {s : Set Y} (hf : Continuous f) (hs : ∀ a, f a ∈ s) :
Continuous (s.codRestrict f hs) :=
hf.subtype_mk hs
@[continuity, fun_prop]
theorem Continuous.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t)
(h2 : Continuous f) : Continuous (h1.restrict f s t) :=
(h2.comp continuous_subtype_val).codRestrict _
@[continuity, fun_prop]
theorem Continuous.restrictPreimage {f : X → Y} {s : Set Y} (h : Continuous f) :
Continuous (s.restrictPreimage f) :=
h.restrict _
lemma Topology.IsEmbedding.restrict {f : X → Y}
(hf : IsEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) :
IsEmbedding H.restrict :=
.of_comp (hf.continuous.restrict H) continuous_subtype_val (hf.comp .subtypeVal)
lemma Topology.IsOpenEmbedding.restrict {f : X → Y}
(hf : IsOpenEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) (hs : IsOpen s) :
IsOpenEmbedding H.restrict :=
⟨hf.isEmbedding.restrict H, (by
rw [MapsTo.range_restrict]
exact continuous_subtype_val.1 _ (hf.isOpenMap _ hs))⟩
theorem Topology.IsInducing.codRestrict {e : X → Y} (he : IsInducing e) {s : Set Y}
(hs : ∀ x, e x ∈ s) : IsInducing (codRestrict e s hs) :=
he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val
@[deprecated (since := "2024-10-28")] alias Inducing.codRestrict := IsInducing.codRestrict
protected lemma Topology.IsEmbedding.codRestrict {e : X → Y} (he : IsEmbedding e) (s : Set Y)
(hs : ∀ x, e x ∈ s) : IsEmbedding (codRestrict e s hs) :=
he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val
@[deprecated (since := "2024-10-26")]
alias Embedding.codRestrict := IsEmbedding.codRestrict
variable {s t : Set X}
protected lemma Topology.IsEmbedding.inclusion (h : s ⊆ t) :
IsEmbedding (inclusion h) := IsEmbedding.subtypeVal.codRestrict _ _
protected lemma Topology.IsOpenEmbedding.inclusion (hst : s ⊆ t) (hs : IsOpen (t ↓∩ s)) :
IsOpenEmbedding (inclusion hst) where
toIsEmbedding := .inclusion _
isOpen_range := by rwa [range_inclusion]
protected lemma Topology.IsClosedEmbedding.inclusion (hst : s ⊆ t) (hs : IsClosed (t ↓∩ s)) :
IsClosedEmbedding (inclusion hst) where
toIsEmbedding := .inclusion _
isClosed_range := by rwa [range_inclusion]
@[deprecated (since := "2024-10-26")]
alias embedding_inclusion := IsEmbedding.inclusion
/-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced
by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/
theorem DiscreteTopology.of_subset {X : Type*} [TopologicalSpace X] {s t : Set X}
(_ : DiscreteTopology s) (ts : t ⊆ s) : DiscreteTopology t :=
(IsEmbedding.inclusion ts).discreteTopology
/-- Let `s` be a discrete subset of a topological space. Then the preimage of `s` by
a continuous injective map is also discrete. -/
theorem DiscreteTopology.preimage_of_continuous_injective {X Y : Type*} [TopologicalSpace X]
[TopologicalSpace Y] (s : Set Y) [DiscreteTopology s] {f : X → Y} (hc : Continuous f)
(hinj : Function.Injective f) : DiscreteTopology (f ⁻¹' s) :=
DiscreteTopology.of_continuous_injective (β := s) (Continuous.restrict
(by exact fun _ x ↦ x) hc) ((MapsTo.restrict_inj _).mpr hinj.injOn)
/-- If `f : X → Y` is a quotient map,
then its restriction to the preimage of an open set is a quotient map too. -/
theorem Topology.IsQuotientMap.restrictPreimage_isOpen {f : X → Y} (hf : IsQuotientMap f)
{s : Set Y} (hs : IsOpen s) : IsQuotientMap (s.restrictPreimage f) := by
refine isQuotientMap_iff.2 ⟨hf.surjective.restrictPreimage _, fun U ↦ ?_⟩
rw [hs.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, ← hf.isOpen_preimage,
(hs.preimage hf.continuous).isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen,
image_val_preimage_restrictPreimage]
@[deprecated (since := "2024-10-22")]
alias QuotientMap.restrictPreimage_isOpen := IsQuotientMap.restrictPreimage_isOpen
open scoped Set.Notation in
lemma isClosed_preimage_val {s t : Set X} : IsClosed (s ↓∩ t) ↔ s ∩ closure (s ∩ t) ⊆ t := by
rw [← closure_eq_iff_isClosed, IsEmbedding.subtypeVal.closure_eq_preimage_closure_image,
← Subtype.val_injective.image_injective.eq_iff, Subtype.image_preimage_coe,
Subtype.image_preimage_coe, subset_antisymm_iff, and_iff_left, Set.subset_inter_iff,
and_iff_right]
exacts [Set.inter_subset_left, Set.subset_inter Set.inter_subset_left subset_closure]
theorem frontier_inter_open_inter {s t : Set X} (ht : IsOpen t) :
frontier (s ∩ t) ∩ t = frontier s ∩ t := by
simp only [Set.inter_comm _ t, ← Subtype.preimage_coe_eq_preimage_coe_iff,
ht.isOpenMap_subtype_val.preimage_frontier_eq_frontier_preimage continuous_subtype_val,
Subtype.preimage_coe_self_inter]
section SetNotation
open scoped Set.Notation
lemma IsOpen.preimage_val {s t : Set X} (ht : IsOpen t) : IsOpen (s ↓∩ t) :=
ht.preimage continuous_subtype_val
lemma IsClosed.preimage_val {s t : Set X} (ht : IsClosed t) : IsClosed (s ↓∩ t) :=
ht.preimage continuous_subtype_val
@[simp] lemma IsOpen.inter_preimage_val_iff {s t : Set X} (hs : IsOpen s) :
IsOpen (s ↓∩ t) ↔ IsOpen (s ∩ t) :=
⟨fun h ↦ by simpa using hs.isOpenMap_subtype_val _ h,
fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩
@[simp] lemma IsClosed.inter_preimage_val_iff {s t : Set X} (hs : IsClosed s) :
IsClosed (s ↓∩ t) ↔ IsClosed (s ∩ t) :=
⟨fun h ↦ by simpa using hs.isClosedMap_subtype_val _ h,
fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩
end SetNotation
end Subtype
section Quotient
variable [TopologicalSpace X] [TopologicalSpace Y]
variable {r : X → X → Prop} {s : Setoid X}
theorem isQuotientMap_quot_mk : IsQuotientMap (@Quot.mk X r) :=
⟨Quot.exists_rep, rfl⟩
@[deprecated (since := "2024-10-22")]
alias quotientMap_quot_mk := isQuotientMap_quot_mk
@[continuity, fun_prop]
theorem continuous_quot_mk : Continuous (@Quot.mk X r) :=
continuous_coinduced_rng
@[continuity, fun_prop]
theorem continuous_quot_lift {f : X → Y} (hr : ∀ a b, r a b → f a = f b) (h : Continuous f) :
Continuous (Quot.lift f hr : Quot r → Y) :=
continuous_coinduced_dom.2 h
theorem isQuotientMap_quotient_mk' : IsQuotientMap (@Quotient.mk' X s) :=
isQuotientMap_quot_mk
@[deprecated (since := "2024-10-22")]
alias quotientMap_quotient_mk' := isQuotientMap_quotient_mk'
theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) :=
continuous_coinduced_rng
theorem Continuous.quotient_lift {f : X → Y} (h : Continuous f) (hs : ∀ a b, a ≈ b → f a = f b) :
Continuous (Quotient.lift f hs : Quotient s → Y) :=
continuous_coinduced_dom.2 h
theorem Continuous.quotient_liftOn' {f : X → Y} (h : Continuous f)
(hs : ∀ a b, s a b → f a = f b) :
Continuous (fun x => Quotient.liftOn' x f hs : Quotient s → Y) :=
h.quotient_lift hs
open scoped Relator in
@[continuity, fun_prop]
theorem Continuous.quotient_map' {t : Setoid Y} {f : X → Y} (hf : Continuous f)
(H : (s.r ⇒ t.r) f f) : Continuous (Quotient.map' f H) :=
(continuous_quotient_mk'.comp hf).quotient_lift _
end Quotient
section Pi
variable {ι : Type*} {π : ι → Type*} {κ : Type*} [TopologicalSpace X]
[T : ∀ i, TopologicalSpace (π i)] {f : X → ∀ i : ι, π i}
theorem continuous_pi_iff : Continuous f ↔ ∀ i, Continuous fun a => f a i := by
simp only [continuous_iInf_rng, continuous_induced_rng, comp_def]
@[continuity, fun_prop]
theorem continuous_pi (h : ∀ i, Continuous fun a => f a i) : Continuous f :=
continuous_pi_iff.2 h
@[continuity, fun_prop]
theorem continuous_apply (i : ι) : Continuous fun p : ∀ i, π i => p i :=
continuous_iInf_dom continuous_induced_dom
@[continuity]
theorem continuous_apply_apply {ρ : κ → ι → Type*} [∀ j i, TopologicalSpace (ρ j i)] (j : κ)
(i : ι) : Continuous fun p : ∀ j, ∀ i, ρ j i => p j i :=
(continuous_apply i).comp (continuous_apply j)
theorem continuousAt_apply (i : ι) (x : ∀ i, π i) : ContinuousAt (fun p : ∀ i, π i => p i) x :=
(continuous_apply i).continuousAt
theorem Filter.Tendsto.apply_nhds {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i}
(h : Tendsto f l (𝓝 x)) (i : ι) : Tendsto (fun a => f a i) l (𝓝 <| x i) :=
(continuousAt_apply i _).tendsto.comp h
@[fun_prop]
protected theorem Continuous.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} (hf : ∀ i, Continuous (f i)) : Continuous (Pi.map f) :=
continuous_pi fun i ↦ (hf i).comp (continuous_apply i)
theorem nhds_pi {a : ∀ i, π i} : 𝓝 a = pi fun i => 𝓝 (a i) := by
simp only [nhds_iInf, nhds_induced, Filter.pi]
protected theorem IsOpenMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i}
(hfo : ∀ i, IsOpenMap (f i)) (hsurj : ∀ᶠ i in cofinite, Surjective (f i)) :
IsOpenMap (Pi.map f) := by
refine IsOpenMap.of_nhds_le fun x ↦ ?_
rw [nhds_pi, nhds_pi, map_piMap_pi hsurj]
exact Filter.pi_mono fun i ↦ (hfo i).nhds_le _
protected theorem IsOpenQuotientMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} (hf : ∀ i, IsOpenQuotientMap (f i)) : IsOpenQuotientMap (Pi.map f) :=
⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2, .piMap (fun i ↦ (hf i).3) <|
.of_forall fun i ↦ (hf i).1⟩
theorem tendsto_pi_nhds {f : Y → ∀ i, π i} {g : ∀ i, π i} {u : Filter Y} :
Tendsto f u (𝓝 g) ↔ ∀ x, Tendsto (fun i => f i x) u (𝓝 (g x)) := by
rw [nhds_pi, Filter.tendsto_pi]
theorem continuousAt_pi {f : X → ∀ i, π i} {x : X} :
ContinuousAt f x ↔ ∀ i, ContinuousAt (fun y => f y i) x :=
tendsto_pi_nhds
@[fun_prop]
theorem continuousAt_pi' {f : X → ∀ i, π i} {x : X} (hf : ∀ i, ContinuousAt (fun y => f y i) x) :
ContinuousAt f x :=
continuousAt_pi.2 hf
@[fun_prop]
protected theorem ContinuousAt.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} {x : ∀ i, π i} (hf : ∀ i, ContinuousAt (f i) (x i)) :
ContinuousAt (Pi.map f) x :=
continuousAt_pi.2 fun i ↦ (hf i).comp (continuousAt_apply i x)
theorem Pi.continuous_precomp' {ι' : Type*} (φ : ι' → ι) :
Continuous (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) :=
continuous_pi fun j ↦ continuous_apply (φ j)
theorem Pi.continuous_precomp {ι' : Type*} (φ : ι' → ι) :
Continuous (· ∘ φ : (ι → X) → (ι' → X)) :=
Pi.continuous_precomp' φ
theorem Pi.continuous_postcomp' {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
{g : ∀ i, π i → X i} (hg : ∀ i, Continuous (g i)) :
Continuous (fun (f : (∀ i, π i)) (i : ι) ↦ g i (f i)) :=
continuous_pi fun i ↦ (hg i).comp <| continuous_apply i
theorem Pi.continuous_postcomp [TopologicalSpace Y] {g : X → Y} (hg : Continuous g) :
Continuous (g ∘ · : (ι → X) → (ι → Y)) :=
Pi.continuous_postcomp' fun _ ↦ hg
lemma Pi.induced_precomp' {ι' : Type*} (φ : ι' → ι) :
induced (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) Pi.topologicalSpace =
⨅ i', induced (eval (φ i')) (T (φ i')) := by
simp [Pi.topologicalSpace, induced_iInf, induced_compose, comp_def]
lemma Pi.induced_precomp [TopologicalSpace Y] {ι' : Type*} (φ : ι' → ι) :
induced (· ∘ φ) Pi.topologicalSpace =
⨅ i', induced (eval (φ i')) ‹TopologicalSpace Y› :=
induced_precomp' φ
@[continuity, fun_prop]
lemma Pi.continuous_restrict (S : Set ι) :
Continuous (S.restrict : (∀ i : ι, π i) → (∀ i : S, π i)) :=
Pi.continuous_precomp' ((↑) : S → ι)
@[continuity, fun_prop]
lemma Pi.continuous_restrict₂ {s t : Set ι} (hst : s ⊆ t) : Continuous (restrict₂ (π := π) hst) :=
continuous_pi fun _ ↦ continuous_apply _
@[continuity, fun_prop]
theorem Finset.continuous_restrict (s : Finset ι) : Continuous (s.restrict (π := π)) :=
continuous_pi fun _ ↦ continuous_apply _
@[continuity, fun_prop]
theorem Finset.continuous_restrict₂ {s t : Finset ι} (hst : s ⊆ t) :
Continuous (Finset.restrict₂ (π := π) hst) :=
continuous_pi fun _ ↦ continuous_apply _
variable [TopologicalSpace Z]
@[continuity, fun_prop]
theorem Pi.continuous_restrict_apply (s : Set X) {f : X → Z} (hf : Continuous f) :
Continuous (s.restrict f) := hf.comp continuous_subtype_val
@[continuity, fun_prop]
theorem Pi.continuous_restrict₂_apply {s t : Set X} (hst : s ⊆ t)
{f : t → Z} (hf : Continuous f) :
Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst)
@[continuity, fun_prop]
theorem Finset.continuous_restrict_apply (s : Finset X) {f : X → Z} (hf : Continuous f) :
Continuous (s.restrict f) := hf.comp continuous_subtype_val
@[continuity, fun_prop]
theorem Finset.continuous_restrict₂_apply {s t : Finset X} (hst : s ⊆ t)
{f : t → Z} (hf : Continuous f) :
Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst)
lemma Pi.induced_restrict (S : Set ι) :
induced (S.restrict) Pi.topologicalSpace =
⨅ i ∈ S, induced (eval i) (T i) := by
simp +unfoldPartialApp [← iInf_subtype'', ← induced_precomp' ((↑) : S → ι),
restrict]
lemma Pi.induced_restrict_sUnion (𝔖 : Set (Set ι)) :
induced (⋃₀ 𝔖).restrict (Pi.topologicalSpace (Y := fun i : (⋃₀ 𝔖) ↦ π i)) =
⨅ S ∈ 𝔖, induced S.restrict Pi.topologicalSpace := by
simp_rw [Pi.induced_restrict, iInf_sUnion]
theorem Filter.Tendsto.update [DecidableEq ι] {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i}
(hf : Tendsto f l (𝓝 x)) (i : ι) {g : Y → π i} {xi : π i} (hg : Tendsto g l (𝓝 xi)) :
Tendsto (fun a => update (f a) i (g a)) l (𝓝 <| update x i xi) :=
tendsto_pi_nhds.2 fun j => by rcases eq_or_ne j i with (rfl | hj) <;> simp [*, hf.apply_nhds]
theorem ContinuousAt.update [DecidableEq ι] {x : X} (hf : ContinuousAt f x) (i : ι) {g : X → π i}
(hg : ContinuousAt g x) : ContinuousAt (fun a => update (f a) i (g a)) x :=
hf.tendsto.update i hg
theorem Continuous.update [DecidableEq ι] (hf : Continuous f) (i : ι) {g : X → π i}
(hg : Continuous g) : Continuous fun a => update (f a) i (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.update i hg.continuousAt
/-- `Function.update f i x` is continuous in `(f, x)`. -/
@[continuity, fun_prop]
theorem continuous_update [DecidableEq ι] (i : ι) :
Continuous fun f : (∀ j, π j) × π i => update f.1 i f.2 :=
continuous_fst.update i continuous_snd
/-- `Pi.mulSingle i x` is continuous in `x`. -/
| @[to_additive (attr := continuity) "`Pi.single i x` is continuous in `x`."]
theorem continuous_mulSingle [∀ i, One (π i)] [DecidableEq ι] (i : ι) :
Continuous fun x => (Pi.mulSingle i x : ∀ i, π i) :=
continuous_const.update _ continuous_id
section Fin
| Mathlib/Topology/Constructions.lean | 744 | 749 |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker, Anne Baanen
-/
import Mathlib.Algebra.BigOperators.Finsupp.Basic
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.Algebra.GroupWithZero.Associated
/-!
# Products of associated, prime, and irreducible elements.
This file contains some theorems relating definitions in `Algebra.Associated`
and products of multisets, finsets, and finsupps.
-/
assert_not_exists Field
variable {α β γ δ : Type*}
-- the same local notation used in `Algebra.Associated`
local infixl:50 " ~ᵤ " => Associated
namespace Prime
variable [CommMonoidWithZero α] {p : α}
theorem exists_mem_multiset_dvd (hp : Prime p) {s : Multiset α} : p ∣ s.prod → ∃ a ∈ s, p ∣ a :=
Multiset.induction_on s (fun h => (hp.not_dvd_one h).elim) fun a s ih h =>
have : p ∣ a * s.prod := by simpa using h
match hp.dvd_or_dvd this with
| Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩
| Or.inr h =>
let ⟨a, has, h⟩ := ih h
⟨a, Multiset.mem_cons_of_mem has, h⟩
theorem exists_mem_multiset_map_dvd (hp : Prime p) {s : Multiset β} {f : β → α} :
p ∣ (s.map f).prod → ∃ a ∈ s, p ∣ f a := fun h => by
simpa only [exists_prop, Multiset.mem_map, exists_exists_and_eq_and] using
hp.exists_mem_multiset_dvd h
theorem exists_mem_finset_dvd (hp : Prime p) {s : Finset β} {f : β → α} :
p ∣ s.prod f → ∃ i ∈ s, p ∣ f i :=
hp.exists_mem_multiset_map_dvd
end Prime
theorem Prod.associated_iff {M N : Type*} [Monoid M] [Monoid N] {x z : M × N} :
x ~ᵤ z ↔ x.1 ~ᵤ z.1 ∧ x.2 ~ᵤ z.2 :=
⟨fun ⟨u, hu⟩ => ⟨⟨(MulEquiv.prodUnits.toFun u).1, (Prod.eq_iff_fst_eq_snd_eq.1 hu).1⟩,
⟨(MulEquiv.prodUnits.toFun u).2, (Prod.eq_iff_fst_eq_snd_eq.1 hu).2⟩⟩,
fun ⟨⟨u₁, h₁⟩, ⟨u₂, h₂⟩⟩ =>
⟨MulEquiv.prodUnits.invFun (u₁, u₂), Prod.eq_iff_fst_eq_snd_eq.2 ⟨h₁, h₂⟩⟩⟩
theorem Associated.prod {M : Type*} [CommMonoid M] {ι : Type*} (s : Finset ι) (f : ι → M)
(g : ι → M) (h : ∀ i, i ∈ s → (f i) ~ᵤ (g i)) : (∏ i ∈ s, f i) ~ᵤ (∏ i ∈ s, g i) := by
induction s using Finset.induction with
| empty =>
simp only [Finset.prod_empty]
rfl
| insert j s hjs IH =>
classical
convert_to (∏ i ∈ insert j s, f i) ~ᵤ (∏ i ∈ insert j s, g i)
rw [Finset.prod_insert hjs, Finset.prod_insert hjs]
exact Associated.mul_mul (h j (Finset.mem_insert_self j s))
(IH (fun i hi ↦ h i (Finset.mem_insert_of_mem hi)))
theorem exists_associated_mem_of_dvd_prod [CancelCommMonoidWithZero α] {p : α} (hp : Prime p)
{s : Multiset α} : (∀ r ∈ s, Prime r) → p ∣ s.prod → ∃ q ∈ s, p ~ᵤ q :=
Multiset.induction_on s (by simp [mt isUnit_iff_dvd_one.2 hp.not_unit]) fun a s ih hs hps => by
rw [Multiset.prod_cons] at hps
rcases hp.dvd_or_dvd hps with h | h
· have hap := hs a (Multiset.mem_cons.2 (Or.inl rfl))
exact ⟨a, Multiset.mem_cons_self a _, hp.associated_of_dvd hap h⟩
· rcases ih (fun r hr => hs _ (Multiset.mem_cons.2 (Or.inr hr))) h with ⟨q, hq₁, hq₂⟩
exact ⟨q, Multiset.mem_cons.2 (Or.inr hq₁), hq₂⟩
open Submonoid in
/-- Let x, y ∈ α. If x * y can be written as a product of units and prime elements, then x can be
written as a product of units and prime elements. -/
theorem divisor_closure_eq_closure [CancelCommMonoidWithZero α]
(x y : α) (hxy : x * y ∈ closure { r : α | IsUnit r ∨ Prime r}) :
x ∈ closure { r : α | IsUnit r ∨ Prime r} := by
obtain ⟨m, hm, hprod⟩ := exists_multiset_of_mem_closure hxy
induction m using Multiset.induction generalizing x y with
| empty =>
apply subset_closure
simp only [Set.mem_setOf]
simp only [Multiset.prod_zero] at hprod
left; exact isUnit_of_mul_eq_one _ _ hprod.symm
| cons c s hind =>
simp only [Multiset.mem_cons, forall_eq_or_imp, Set.mem_setOf] at hm
simp only [Multiset.prod_cons] at hprod
simp only [Set.mem_setOf_eq] at hind
obtain ⟨ha₁ | ha₂, hs⟩ := hm
· rcases ha₁.exists_right_inv with ⟨k, hk⟩
refine hind x (y*k) ?_ hs ?_
· simp only [← mul_assoc, ← hprod, ← Multiset.prod_cons, mul_comm]
refine multiset_prod_mem _ _ (Multiset.forall_mem_cons.2 ⟨subset_closure (Set.mem_def.2 ?_),
Multiset.forall_mem_cons.2 ⟨subset_closure (Set.mem_def.2 ?_), (fun t ht =>
subset_closure (hs t ht))⟩⟩)
· left; exact isUnit_of_mul_eq_one_right _ _ hk
· left; exact ha₁
· rw [← mul_one s.prod, ← hk, ← mul_assoc, ← mul_assoc, mul_eq_mul_right_iff, mul_comm]
left; exact hprod
· rcases ha₂.dvd_mul.1 (Dvd.intro _ hprod) with ⟨c, hc⟩ | ⟨c, hc⟩
· rw [hc]; rw [hc, mul_assoc] at hprod
refine Submonoid.mul_mem _ (subset_closure (Set.mem_def.2 ?_))
(hind _ _ ?_ hs (mul_left_cancel₀ ha₂.ne_zero hprod))
· right; exact ha₂
rw [← mul_left_cancel₀ ha₂.ne_zero hprod]
exact multiset_prod_mem _ _ (fun t ht => subset_closure (hs t ht))
rw [hc, mul_comm x _, mul_assoc, mul_comm c _] at hprod
refine hind x c ?_ hs (mul_left_cancel₀ ha₂.ne_zero hprod)
rw [← mul_left_cancel₀ ha₂.ne_zero hprod]
exact multiset_prod_mem _ _ (fun t ht => subset_closure (hs t ht))
theorem Multiset.prod_primes_dvd [CancelCommMonoidWithZero α]
[∀ a : α, DecidablePred (Associated a)] {s : Multiset α} (n : α) (h : ∀ a ∈ s, Prime a)
(div : ∀ a ∈ s, a ∣ n) (uniq : ∀ a, s.countP (Associated a) ≤ 1) : s.prod ∣ n := by
induction s using Multiset.induction_on generalizing n with
| empty => simp only [Multiset.prod_zero, one_dvd]
| cons a s induct =>
rw [Multiset.prod_cons]
obtain ⟨k, rfl⟩ : a ∣ n := div a (Multiset.mem_cons_self a s)
apply mul_dvd_mul_left a
refine induct _ (fun a ha => h a (Multiset.mem_cons_of_mem ha)) (fun b b_in_s => ?_)
fun a => (Multiset.countP_le_of_le _ (Multiset.le_cons_self _ _)).trans (uniq a)
have b_div_n := div b (Multiset.mem_cons_of_mem b_in_s)
have a_prime := h a (Multiset.mem_cons_self a s)
have b_prime := h b (Multiset.mem_cons_of_mem b_in_s)
refine (b_prime.dvd_or_dvd b_div_n).resolve_left fun b_div_a => ?_
have assoc := b_prime.associated_of_dvd a_prime b_div_a
have := uniq a
rw [Multiset.countP_cons_of_pos _ (Associated.refl _), Nat.succ_le_succ_iff, ← not_lt,
Multiset.countP_pos] at this
exact this ⟨b, b_in_s, assoc.symm⟩
theorem Finset.prod_primes_dvd [CancelCommMonoidWithZero α] [Subsingleton αˣ] {s : Finset α} (n : α)
(h : ∀ a ∈ s, Prime a) (div : ∀ a ∈ s, a ∣ n) : (∏ p ∈ s, p) ∣ n := by
classical
exact
Multiset.prod_primes_dvd n (by simpa only [Multiset.map_id', Finset.mem_def] using h)
(by simpa only [Multiset.map_id', Finset.mem_def] using div)
(by
simp only [Multiset.map_id', associated_eq_eq, Multiset.countP_eq_card_filter,
← s.val.count_eq_card_filter_eq, ← Multiset.nodup_iff_count_le_one, s.nodup])
namespace Associates
section CommMonoid
variable [CommMonoid α]
theorem prod_mk {p : Multiset α} : (p.map Associates.mk).prod = Associates.mk p.prod :=
Multiset.induction_on p (by simp) fun a s ih => by simp [ih, Associates.mk_mul_mk]
theorem finset_prod_mk {p : Finset β} {f : β → α} :
(∏ i ∈ p, Associates.mk (f i)) = Associates.mk (∏ i ∈ p, f i) := by
rw [Finset.prod_eq_multiset_prod, ← Function.comp_def, ← Multiset.map_map, prod_mk,
← Finset.prod_eq_multiset_prod]
theorem rel_associated_iff_map_eq_map {p q : Multiset α} :
Multiset.Rel Associated p q ↔ p.map Associates.mk = q.map Associates.mk := by
rw [← Multiset.rel_eq, Multiset.rel_map]
simp only [mk_eq_mk_iff_associated]
theorem prod_eq_one_iff {p : Multiset (Associates α)} :
p.prod = 1 ↔ ∀ a ∈ p, (a : Associates α) = 1 :=
Multiset.induction_on p (by simp)
(by simp +contextual [mul_eq_one, or_imp, forall_and])
theorem prod_le_prod {p q : Multiset (Associates α)} (h : p ≤ q) : p.prod ≤ q.prod := by
haveI := Classical.decEq (Associates α)
haveI := Classical.decEq α
suffices p.prod ≤ (p + (q - p)).prod by rwa [add_tsub_cancel_of_le h] at this
suffices p.prod * 1 ≤ p.prod * (q - p).prod by simpa
exact mul_mono (le_refl p.prod) one_le
end CommMonoid
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
theorem exists_mem_multiset_le_of_prime {s : Multiset (Associates α)} {p : Associates α}
(hp : Prime p) : p ≤ s.prod → ∃ a ∈ s, p ≤ a :=
Multiset.induction_on s (fun ⟨_, eq⟩ => (hp.ne_one (mul_eq_one.1 eq.symm).1).elim)
fun a s ih h =>
have : p ≤ a * s.prod := by simpa using h
match Prime.le_or_le hp this with
| Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩
| Or.inr h =>
| let ⟨a, has, h⟩ := ih h
⟨a, Multiset.mem_cons_of_mem has, h⟩
| Mathlib/Algebra/BigOperators/Associated.lean | 195 | 197 |
/-
Copyright (c) 2024 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.LinearAlgebra.PiTensorProduct
import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Data.Finset.NoncommProd
/-!
# Tensor product of `R`-algebras and rings
If `(Aᵢ)` is a family of `R`-algebras then the `R`-tensor product `⨂ᵢ Aᵢ` is an `R`-algebra as well
with structure map defined by `r ↦ r • 1`.
In particular if we take `R` to be `ℤ`, then this collapses into the tensor product of rings.
-/
open TensorProduct Function
variable {ι R' R : Type*} {A : ι → Type*}
namespace PiTensorProduct
noncomputable section AddCommMonoidWithOne
variable [CommSemiring R] [∀ i, AddCommMonoidWithOne (A i)] [∀ i, Module R (A i)]
instance instOne : One (⨂[R] i, A i) where
one := tprod R 1
lemma one_def : 1 = tprod R (1 : Π i, A i) := rfl
instance instAddCommMonoidWithOne : AddCommMonoidWithOne (⨂[R] i, A i) where
__ := inferInstanceAs (AddCommMonoid (⨂[R] i, A i))
__ := instOne
end AddCommMonoidWithOne
noncomputable section NonUnitalNonAssocSemiring
variable [CommSemiring R] [∀ i, NonUnitalNonAssocSemiring (A i)]
variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)]
attribute [aesop safe] mul_add mul_smul_comm smul_mul_assoc add_mul in
/--
The multiplication in tensor product of rings is induced by `(xᵢ) * (yᵢ) = (xᵢ * yᵢ)`
-/
def mul : (⨂[R] i, A i) →ₗ[R] (⨂[R] i, A i) →ₗ[R] (⨂[R] i, A i) :=
PiTensorProduct.piTensorHomMap₂ <| tprod R fun _ ↦ LinearMap.mul _ _
@[simp] lemma mul_tprod_tprod (x y : (i : ι) → A i) :
mul (tprod R x) (tprod R y) = tprod R (x * y) := by
simp only [mul, piTensorHomMap₂_tprod_tprod_tprod, LinearMap.mul_apply', Pi.mul_def]
instance instMul : Mul (⨂[R] i, A i) where
mul x y := mul x y
lemma mul_def (x y : ⨂[R] i, A i) : x * y = mul x y := rfl
@[simp] lemma tprod_mul_tprod (x y : (i : ι) → A i) :
tprod R x * tprod R y = tprod R (x * y) :=
mul_tprod_tprod x y
theorem _root_.SemiconjBy.tprod {a₁ a₂ a₃ : Π i, A i}
(ha : SemiconjBy a₁ a₂ a₃) :
SemiconjBy (tprod R a₁) (tprod R a₂) (tprod R a₃) := by
rw [SemiconjBy, tprod_mul_tprod, tprod_mul_tprod, ha]
nonrec theorem _root_.Commute.tprod {a₁ a₂ : Π i, A i} (ha : Commute a₁ a₂) :
Commute (tprod R a₁) (tprod R a₂) :=
ha.tprod
lemma smul_tprod_mul_smul_tprod (r s : R) (x y : Π i, A i) :
(r • tprod R x) * (s • tprod R y) = (r * s) • tprod R (x * y) := by
simp only [mul_def, map_smul, LinearMap.smul_apply, mul_tprod_tprod, mul_comm r s, mul_smul]
instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (⨂[R] i, A i) where
__ := instMul
__ := inferInstanceAs (AddCommMonoid (⨂[R] i, A i))
left_distrib _ _ _ := (mul _).map_add _ _
right_distrib _ _ _ := mul.map_add₂ _ _ _
zero_mul _ := mul.map_zero₂ _
mul_zero _ := map_zero (mul _)
end NonUnitalNonAssocSemiring
noncomputable section NonAssocSemiring
variable [CommSemiring R] [∀ i, NonAssocSemiring (A i)]
variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)]
protected lemma one_mul (x : ⨂[R] i, A i) : mul (tprod R 1) x = x := by
induction x using PiTensorProduct.induction_on with
| smul_tprod => simp
| add _ _ h1 h2 => simp [map_add, h1, h2]
protected lemma mul_one (x : ⨂[R] i, A i) : mul x (tprod R 1) = x := by
induction x using PiTensorProduct.induction_on with
| smul_tprod => simp
| | add _ _ h1 h2 => simp [h1, h2]
instance instNonAssocSemiring : NonAssocSemiring (⨂[R] i, A i) where
__ := instNonUnitalNonAssocSemiring
| Mathlib/RingTheory/PiTensorProduct.lean | 103 | 106 |
/-
Copyright (c) 2023 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.ProbabilityMeasure
import Mathlib.MeasureTheory.Measure.Prod
/-!
# Products of finite measures and probability measures
This file introduces binary products of finite measures and probability measures. The constructions
are obtained from special cases of products of general measures. Taking products nevertheless has
specific properties in the cases of finite measures and probability measures, notably the fact that
the product measures depend continuously on their factors in the topology of weak convergence when
the underlying space is metrizable and separable.
## Main definitions
* `MeasureTheory.FiniteMeasure.prod`: The product of two finite measures.
* `MeasureTheory.ProbabilityMeasure.prod`: The product of two probability measures.
## TODO
* Add continuous dependence of the product measures on the factors.
-/
open MeasureTheory Topology Metric Filter Set ENNReal NNReal
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
section FiniteMeasure_product
namespace FiniteMeasure
variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β]
/-- The binary product of finite measures. -/
noncomputable def prod (μ : FiniteMeasure α) (ν : FiniteMeasure β) : FiniteMeasure (α × β) :=
⟨μ.toMeasure.prod ν.toMeasure, inferInstance⟩
variable (μ : FiniteMeasure α) (ν : FiniteMeasure β)
@[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl
lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by
simp [coeFn_def, Measure.prod_apply s_mble]
lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by
simp [coeFn_def, Measure.prod_apply_symm s_mble]
lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def]
@[simp] lemma mass_prod : (μ.prod ν).mass = μ.mass * ν.mass := by
simp only [coeFn_def, mass, univ_prod_univ.symm, toMeasure_prod]
rw [← ENNReal.toNNReal_mul]
exact congr_arg ENNReal.toNNReal (Measure.prod_prod univ univ)
@[simp] lemma zero_prod : (0 : FiniteMeasure α).prod ν = 0 := by
rw [← mass_zero_iff, mass_prod, zero_mass, zero_mul]
@[simp] lemma prod_zero : μ.prod (0 : FiniteMeasure β) = 0 := by
rw [← mass_zero_iff, mass_prod, zero_mass, mul_zero]
@[simp] lemma map_fst_prod : (μ.prod ν).map Prod.fst = ν univ • μ := by ext; simp
@[simp] lemma map_snd_prod : (μ.prod ν).map Prod.snd = μ univ • ν := by ext; simp
lemma map_prod_map {α' : Type*} [MeasurableSpace α'] {β' : Type*} [MeasurableSpace β']
{f : α → α'} {g : β → β'} (f_mble : Measurable f) (g_mble : Measurable g) :
(μ.map f).prod (ν.map g) = (μ.prod ν).map (Prod.map f g) := by
apply Subtype.ext
simp only [val_eq_toMeasure, toMeasure_prod, toMeasure_map]
rw [Measure.map_prod_map _ _ f_mble g_mble]
lemma prod_swap : (μ.prod ν).map Prod.swap = ν.prod μ := by
apply Subtype.ext
simp [Measure.prod_swap]
end FiniteMeasure -- namespace
end FiniteMeasure_product -- section
section ProbabilityMeasure_product
namespace ProbabilityMeasure
variable {α : Type*} [MeasurableSpace α] {β : Type*} [MeasurableSpace β]
/-- The binary product of probability measures. -/
noncomputable def prod (μ : ProbabilityMeasure α) (ν : ProbabilityMeasure β) :
ProbabilityMeasure (α × β) :=
⟨μ.toMeasure.prod ν.toMeasure, by infer_instance⟩
variable (μ : ProbabilityMeasure α) (ν : ProbabilityMeasure β)
@[simp] lemma toMeasure_prod : (μ.prod ν).toMeasure = μ.toMeasure.prod ν.toMeasure := rfl
lemma prod_apply (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ x, ν.toMeasure (Prod.mk x ⁻¹' s) ∂μ) := by
simp [coeFn_def, Measure.prod_apply s_mble]
lemma prod_apply_symm (s : Set (α × β)) (s_mble : MeasurableSet s) :
μ.prod ν s = ENNReal.toNNReal (∫⁻ y, μ.toMeasure ((fun x ↦ ⟨x, y⟩) ⁻¹' s) ∂ν) := by
simp [coeFn_def, Measure.prod_apply_symm s_mble]
lemma prod_prod (s : Set α) (t : Set β) : μ.prod ν (s ×ˢ t) = μ s * ν t := by simp [coeFn_def]
/-- The first marginal of a product probability measure is the first probability measure. -/
@[simp] lemma map_fst_prod : (μ.prod ν).map measurable_fst.aemeasurable = μ := by
apply Subtype.ext
simp only [val_eq_to_measure, toMeasure_map, toMeasure_prod, Measure.map_fst_prod,
measure_univ, one_smul]
/-- The second marginal of a product probability measure is the second probability measure. -/
@[simp] lemma map_snd_prod : (μ.prod ν).map measurable_snd.aemeasurable = ν := by
apply Subtype.ext
simp only [val_eq_to_measure, toMeasure_map, toMeasure_prod, Measure.map_snd_prod,
measure_univ, one_smul]
lemma map_prod_map {α' : Type*} [MeasurableSpace α'] {β' : Type*} [MeasurableSpace β']
{f : α → α'} {g : β → β'} (f_mble : Measurable f) (g_mble : Measurable g) :
(μ.map f_mble.aemeasurable).prod (ν.map g_mble.aemeasurable)
= (μ.prod ν).map (f_mble.prodMap g_mble).aemeasurable := by
apply Subtype.ext
simp only [val_eq_to_measure, toMeasure_prod, toMeasure_map]
rw [Measure.map_prod_map _ _ f_mble g_mble]
| lemma prod_swap : (μ.prod ν).map measurable_swap.aemeasurable = ν.prod μ := by
apply Subtype.ext
simp [Measure.prod_swap]
| Mathlib/MeasureTheory/Measure/FiniteMeasureProd.lean | 133 | 135 |
/-
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.DivergenceTheorem
import Mathlib.Analysis.BoxIntegral.Integrability
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Equiv
import Mathlib.MeasureTheory.Integral.Prod
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
/-!
# Divergence theorem for Bochner integral
In this file we prove the Divergence theorem for Bochner integral on a box in
`ℝⁿ⁺¹ = Fin (n + 1) → ℝ`. More precisely, we prove the following theorem.
Let `E` be a complete normed space. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is
continuous on a rectangular box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, differentiable on its interior with
derivative `f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹`, and the divergence `fun x ↦ ∑ i, f' x eᵢ i`
is integrable on `[a, b]`, where `eᵢ = Pi.single i 1` is the `i`-th basis vector,
then its integral is equal to the sum of integrals of `f` over the faces of `[a, b]`,
taken with appropriate signs. Moreover, the same
is true if the function is not differentiable at countably many points of the interior of `[a, b]`.
Once we prove the general theorem, we deduce corollaries for functions `ℝ → E` and pairs of
functions `(ℝ × ℝ) → E`.
## Notations
We use the following local notation to make the statement more readable. Note that the documentation
website shows the actual terms, not those abbreviated using local notations.
Porting note (Yury Kudryashov): I disabled some of these notations because I failed to make them
work with Lean 4.
* `ℝⁿ`, `ℝⁿ⁺¹`, `Eⁿ⁺¹`: `Fin n → ℝ`, `Fin (n + 1) → ℝ`, `Fin (n + 1) → E`;
* `face i`: the `i`-th face of the box `[a, b]` as a closed segment in `ℝⁿ`, namely
`[a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]`;
* `e i` : `i`-th basis vector `Pi.single i 1`;
* `frontFace i`, `backFace i`: embeddings `ℝⁿ → ℝⁿ⁺¹` corresponding to the front face
`{x | x i = b i}` and back face `{x | x i = a i}` of the box `[a, b]`, respectively.
They are given by `Fin.insertNth i (b i)` and `Fin.insertNth i (a i)`.
## TODO
* Add a version that assumes existence and integrability of partial derivatives.
* Restore local notations for find another way to make the statements more readable.
## Tags
divergence theorem, Bochner integral
-/
open Set Finset TopologicalSpace Function BoxIntegral MeasureTheory Filter
open scoped Topology Interval
universe u
namespace MeasureTheory
variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E]
section
variable {n : ℕ}
local macro:arg t:term:max noWs "ⁿ" : term => `(Fin n → $t)
local macro:arg t:term:max noWs "ⁿ⁺¹" : term => `(Fin (n + 1) → $t)
local notation "e " i => Pi.single i 1
section
/-!
### Divergence theorem for functions on `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`.
In this section we use the divergence theorem for a Henstock-Kurzweil-like integral
`BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` to prove the divergence
theorem for Bochner integral. The divergence theorem for Bochner integral
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` assumes that the function
itself is continuous on a closed box, differentiable at all but countably many points of its
interior, and the divergence is integrable on the box.
This statement differs from `BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt`
in several aspects.
* We use Bochner integral instead of a Henstock-Kurzweil integral. This modification is done in
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁`. As a side effect
of this change, we need to assume that the divergence is integrable.
* We don't assume differentiability on the boundary of the box. This modification is done in
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂`. To prove it, we
choose an increasing sequence of smaller boxes that cover the interior of the original box, then
apply the previous lemma to these smaller boxes and take the limit of both sides of the equation.
* We assume `a ≤ b` instead of `∀ i, a i < b i`. This is the last step of the proof, and it is done
in the main theorem `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`.
-/
/-- An auxiliary lemma for
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. This is exactly
`BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` reformulated for the
Bochner integral. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (I : Box (Fin (n + 1)))
(f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹) (s : Set ℝⁿ⁺¹)
(hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I))
(Hd : ∀ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x)
(Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Box.Icc I)) :
(∫ x in Box.Icc I, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) -
∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by
wlog hE : CompleteSpace E generalizing
· simp [integral, hE]
simp only [← setIntegral_congr_set (Box.coe_ae_eq_Icc _)]
have A := (Hi.mono_set Box.coe_subset_Icc).hasBoxIntegral ⊥ rfl
have B :=
hasIntegral_GP_divergence_of_forall_hasDerivWithinAt I f f' (s ∩ Box.Icc I)
(hs.mono inter_subset_left) (fun x hx => Hc _ hx.2) fun x hx =>
Hd _ ⟨hx.1, fun h => hx.2 ⟨h, hx.1⟩⟩
rw [continuousOn_pi] at Hc
refine (A.unique B).trans (sum_congr rfl fun i _ => ?_)
refine congr_arg₂ Sub.sub ?_ ?_
· have := Box.continuousOn_face_Icc (Hc i) (Set.right_mem_Icc.2 (I.lower_le_upper i))
have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set
Box.coe_subset_Icc
exact (this.hasBoxIntegral ⊥ rfl).integral_eq
· have := Box.continuousOn_face_Icc (Hc i) (Set.left_mem_Icc.2 (I.lower_le_upper i))
have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set
Box.coe_subset_Icc
exact (this.hasBoxIntegral ⊥ rfl).integral_eq
/-- An auxiliary lemma for
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. Compared to the previous
lemma, here we drop the assumption of differentiability on the boundary of the box. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂ (I : Box (Fin (n + 1)))
| (f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹)
(s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I))
(Hd : ∀ x ∈ Box.Ioo I \ s, HasFDerivAt f (f' x) x)
(Hi : IntegrableOn (∑ i, f' · (e i) i) (Box.Icc I)) :
(∫ x in Box.Icc I, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) -
∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by
/- Choose a monotone sequence `J k` of subboxes that cover the interior of `I` and prove that
these boxes satisfy the assumptions of the previous lemma. -/
rcases I.exists_seq_mono_tendsto with ⟨J, hJ_sub, hJl, hJu⟩
have hJ_sub' : ∀ k, Box.Icc (J k) ⊆ Box.Icc I := fun k => (hJ_sub k).trans I.Ioo_subset_Icc
have hJ_le : ∀ k, J k ≤ I := fun k => Box.le_iff_Icc.2 (hJ_sub' k)
have HcJ : ∀ k, ContinuousOn f (Box.Icc (J k)) := fun k => Hc.mono (hJ_sub' k)
have HdJ : ∀ (k), ∀ x ∈ (Box.Icc (J k)) \ s, HasFDerivWithinAt f (f' x) (Box.Icc (J k)) x :=
fun k x hx => (Hd x ⟨hJ_sub k hx.1, hx.2⟩).hasFDerivWithinAt
have HiJ : ∀ k, IntegrableOn (∑ i, f' · (e i) i) (Box.Icc (J k)) volume := fun k =>
Hi.mono_set (hJ_sub' k)
-- Apply the previous lemma to `J k`.
have HJ_eq := fun k =>
integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (J k) f f' s hs (HcJ k) (HdJ k)
(HiJ k)
-- Note that the LHS of `HJ_eq k` tends to the LHS of the goal as `k → ∞`.
have hI_tendsto :
Tendsto (fun k => ∫ x in Box.Icc (J k), ∑ i, f' x (e i) i) atTop
(𝓝 (∫ x in Box.Icc I, ∑ i, f' x (e i) i)) := by
simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _)] at Hi ⊢
rw [← Box.iUnion_Ioo_of_tendsto J.monotone hJl hJu] at Hi ⊢
exact tendsto_setIntegral_of_monotone (fun k => (J k).measurableSet_Ioo)
(Box.Ioo.comp J).monotone Hi
-- Thus it suffices to prove the same about the RHS.
refine tendsto_nhds_unique_of_eventuallyEq hI_tendsto ?_ (Eventually.of_forall HJ_eq)
clear hI_tendsto
rw [tendsto_pi_nhds] at hJl hJu
/- We'll need to prove a similar statement about the integrals over the front sides and the
integrals over the back sides. In order to avoid repeating ourselves, we formulate a lemma. -/
suffices ∀ (i : Fin (n + 1)) (c : ℕ → ℝ) (d), (∀ k, c k ∈ Icc (I.lower i) (I.upper i)) →
Tendsto c atTop (𝓝 d) →
Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth (c k) x) i) atTop
(𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) by
rw [Box.Icc_eq_pi] at hJ_sub'
refine tendsto_finset_sum _ fun i _ => (this _ _ _ ?_ (hJu _)).sub (this _ _ _ ?_ (hJl _))
exacts [fun k => hJ_sub' k (J k).upper_mem_Icc _ trivial, fun k =>
hJ_sub' k (J k).lower_mem_Icc _ trivial]
intro i c d hc hcd
/- First we prove that the integrals of the restriction of `f` to `{x | x i = d}` over increasing
boxes `((J k).face i).Icc` tend to the desired limit. The proof mostly repeats the one above. -/
have hd : d ∈ Icc (I.lower i) (I.upper i) :=
isClosed_Icc.mem_of_tendsto hcd (Eventually.of_forall hc)
have Hic : ∀ k, IntegrableOn (fun x => f (i.insertNth (c k) x) i) (Box.Icc (I.face i)) := fun k =>
(Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) (hc k)).integrableOn_Icc
have Hid : IntegrableOn (fun x => f (i.insertNth d x) i) (Box.Icc (I.face i)) :=
(Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) hd).integrableOn_Icc
have H :
Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i) atTop
(𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) := by
have hIoo : (⋃ k, Box.Ioo ((J k).face i)) = Box.Ioo (I.face i) :=
Box.iUnion_Ioo_of_tendsto ((Box.monotone_face i).comp J.monotone)
(tendsto_pi_nhds.2 fun _ => hJl _) (tendsto_pi_nhds.2 fun _ => hJu _)
simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _), ← hIoo] at Hid ⊢
exact tendsto_setIntegral_of_monotone (fun k => ((J k).face i).measurableSet_Ioo)
(Box.Ioo.monotone.comp ((Box.monotone_face i).comp J.monotone)) Hid
/- Thus it suffices to show that the distance between the integrals of the restrictions of `f` to
`{x | x i = c k}` and `{x | x i = d}` over `((J k).face i).Icc` tends to zero as `k → ∞`. Choose
`ε > 0`. -/
refine H.congr_dist (Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε εpos => ?_)
have hvol_pos : ∀ J : Box (Fin n), 0 < ∏ j, (J.upper j - J.lower j) := fun J =>
prod_pos fun j hj => sub_pos.2 <| J.lower_lt_upper _
/- Choose `δ > 0` such that for any `x y ∈ I.Icc` at distance at most `δ`, the distance between
`f x` and `f y` is at most `ε / volume (I.face i).Icc`, then the distance between the integrals
is at most `(ε / volume (I.face i).Icc) * volume ((J k).face i).Icc ≤ ε`. -/
rcases Metric.uniformContinuousOn_iff_le.1 (I.isCompact_Icc.uniformContinuousOn_of_continuous Hc)
(ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) (div_pos εpos (hvol_pos (I.face i)))
with ⟨δ, δpos, hδ⟩
refine (hcd.eventually (Metric.ball_mem_nhds _ δpos)).mono fun k hk => ?_
have Hsub : Box.Icc ((J k).face i) ⊆ Box.Icc (I.face i) :=
Box.le_iff_Icc.1 (Box.face_mono (hJ_le _) i)
rw [mem_closedBall_zero_iff, Real.norm_eq_abs, abs_of_nonneg dist_nonneg, dist_eq_norm,
← integral_sub (Hid.mono_set Hsub) ((Hic _).mono_set Hsub)]
calc
‖∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i - f (i.insertNth (c k) x) i‖ ≤
(ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) *
(volume (Box.Icc ((J k).face i))).toReal := by
refine norm_setIntegral_le_of_norm_le_const (((J k).face i).measure_Icc_lt_top _)
fun x hx => ?_
rw [← dist_eq_norm]
calc
dist (f (i.insertNth d x) i) (f (i.insertNth (c k) x) i) ≤
dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) :=
dist_le_pi_dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) i
_ ≤ ε / ∏ j, ((I.face i).upper j - (I.face i).lower j) :=
hδ _ (I.mapsTo_insertNth_face_Icc hd <| Hsub hx) _
(I.mapsTo_insertNth_face_Icc (hc _) <| Hsub hx) ?_
rw [Fin.dist_insertNth_insertNth, dist_self, dist_comm]
exact max_le hk.le δpos.lt.le
_ ≤ ε := by
rw [Box.Icc_def, Real.volume_Icc_pi_toReal ((J k).face i).lower_le_upper,
← le_div_iff₀ (hvol_pos _)]
gcongr
exacts [hvol_pos _, fun _ _ ↦ sub_nonneg.2 (Box.lower_le_upper _ _),
(hJ_sub' _ (J _).upper_mem_Icc).2 _, (hJ_sub' _ (J _).lower_mem_Icc).1 _]
| Mathlib/MeasureTheory/Integral/DivergenceTheorem.lean | 143 | 245 |
/-
Copyright (c) 2021 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.Algebra.Group.Subgroup.Defs
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Star.Pi
import Mathlib.Algebra.Star.Rat
/-!
# Self-adjoint, skew-adjoint and normal elements of a star additive group
This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group,
as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`).
This includes, for instance, (skew-)Hermitian operators on Hilbert spaces.
We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies
`star x * x = x * star x`.
## Implementation notes
* When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural
`Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be
undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)`
and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass
`[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then
add a `[Module R₃ (selfAdjoint R)]` instance whenever we have
`[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define
`[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but
this typeclass would have the disadvantage of taking two type arguments.)
## TODO
* Define `IsSkewAdjoint` to match `IsSelfAdjoint`.
* Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R`
(similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is
invariant under it.
-/
open Function
variable {R A : Type*}
/-- An element is self-adjoint if it is equal to its star. -/
def IsSelfAdjoint [Star R] (x : R) : Prop :=
star x = x
/-- An element of a star monoid is normal if it commutes with its adjoint. -/
@[mk_iff]
class IsStarNormal [Mul R] [Star R] (x : R) : Prop where
/-- A normal element of a star monoid commutes with its adjoint. -/
star_comm_self : Commute (star x) x
export IsStarNormal (star_comm_self)
theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x :=
IsStarNormal.star_comm_self
namespace IsSelfAdjoint
-- named to match `Commute.allₓ`
/-- All elements are self-adjoint when `star` is trivial. -/
theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r :=
star_trivial _
theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x :=
hx
theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x :=
Iff.rfl
@[simp]
theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by
simpa only [IsSelfAdjoint, star_star] using eq_comm
@[simp]
theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by
simp only [IsSelfAdjoint, star_mul, star_star]
@[simp]
theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by
simpa only [star_star] using star_mul_self (star x)
/-- Self-adjoint elements commute if and only if their product is self-adjoint. -/
lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R}
(hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq]
· simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm
/-- Functions in a `StarHomClass` preserve self-adjoint elements. -/
@[aesop 10% apply]
theorem map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S]
{x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) :=
show star (f x) = f x from map_star f x ▸ congr_arg f hx
/- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]`
instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/
theorem _root_.isSelfAdjoint_map {F R S : Type*} [Star R] [Star S] [FunLike F R S]
[StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) :=
(IsSelfAdjoint.all x).map f
section AddMonoid
variable [AddMonoid R] [StarAddMonoid R]
variable (R) in
@[simp] protected theorem zero : IsSelfAdjoint (0 : R) := star_zero R
@[aesop 90% apply]
theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by
simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq]
end AddMonoid
section AddGroup
variable [AddGroup R] [StarAddMonoid R]
@[aesop safe apply]
theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by
simp only [isSelfAdjoint_iff, star_neg, hx.star_eq]
@[aesop 90% apply]
theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by
simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq]
end AddGroup
section AddCommMonoid
variable [AddCommMonoid R] [StarAddMonoid R]
@[simp]
theorem add_star_self (x : R) : IsSelfAdjoint (x + star x) := by
simp only [isSelfAdjoint_iff, add_comm, star_add, star_star]
@[simp]
theorem star_add_self (x : R) : IsSelfAdjoint (star x + x) := by
simp only [isSelfAdjoint_iff, add_comm, star_add, star_star]
end AddCommMonoid
section Semigroup
variable [Semigroup R] [StarMul R]
@[aesop safe apply]
theorem conjugate {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (z * x * star z) := by
simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq]
@[aesop safe apply]
theorem conjugate' {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (star z * x * z) := by
simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq]
@[aesop 90% apply]
theorem conjugate_self {x : R} (hx : IsSelfAdjoint x) {z : R} (hz : IsSelfAdjoint z) :
IsSelfAdjoint (z * x * z) := by nth_rewrite 2 [← hz]; exact conjugate hx z
@[aesop 10% apply]
theorem isStarNormal {x : R} (hx : IsSelfAdjoint x) : IsStarNormal x :=
⟨by simp only [Commute, SemiconjBy, hx.star_eq]⟩
end Semigroup
section MulOneClass
variable [MulOneClass R] [StarMul R]
variable (R)
@[simp] protected theorem one : IsSelfAdjoint (1 : R) :=
star_one R
end MulOneClass
section Monoid
variable [Monoid R] [StarMul R]
@[aesop safe apply]
theorem pow {x : R} (hx : IsSelfAdjoint x) (n : ℕ) : IsSelfAdjoint (x ^ n) := by
simp only [isSelfAdjoint_iff, star_pow, hx.star_eq]
end Monoid
section Semiring
variable [Semiring R] [StarRing R]
@[simp]
protected theorem natCast (n : ℕ) : IsSelfAdjoint (n : R) :=
star_natCast _
@[simp]
protected theorem ofNat (n : ℕ) [n.AtLeastTwo] : IsSelfAdjoint (ofNat(n) : R) :=
.natCast n
end Semiring
section CommSemigroup
variable [CommSemigroup R] [StarMul R]
theorem mul {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x * y) := by
simp only [isSelfAdjoint_iff, star_mul', hx.star_eq, hy.star_eq]
end CommSemigroup
section CommSemiring
variable {α : Type*} [CommSemiring α] [StarRing α] {a : α}
open scoped ComplexConjugate
lemma conj_eq (ha : IsSelfAdjoint a) : conj a = a := ha.star_eq
end CommSemiring
section Ring
variable [Ring R] [StarRing R]
@[simp]
protected theorem intCast (z : ℤ) : IsSelfAdjoint (z : R) :=
star_intCast _
end Ring
section Group
variable [Group R] [StarMul R]
@[aesop safe apply]
theorem inv {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by
simp only [isSelfAdjoint_iff, star_inv, hx.star_eq]
@[aesop safe apply]
theorem zpow {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by
simp only [isSelfAdjoint_iff, star_zpow, hx.star_eq]
end Group
section GroupWithZero
variable [GroupWithZero R] [StarMul R]
@[aesop safe apply]
theorem inv₀ {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by
simp only [isSelfAdjoint_iff, star_inv₀, hx.star_eq]
@[aesop safe apply]
theorem zpow₀ {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by
simp only [isSelfAdjoint_iff, star_zpow₀, hx.star_eq]
end GroupWithZero
@[simp]
protected lemma nnratCast [DivisionSemiring R] [StarRing R] (q : ℚ≥0) :
IsSelfAdjoint (q : R) :=
star_nnratCast _
section DivisionRing
variable [DivisionRing R] [StarRing R]
@[simp]
protected theorem ratCast (x : ℚ) : IsSelfAdjoint (x : R) :=
star_ratCast _
end DivisionRing
section Semifield
variable [Semifield R] [StarRing R]
theorem div {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x / y) := by
simp only [isSelfAdjoint_iff, star_div₀, hx.star_eq, hy.star_eq]
end Semifield
section SMul
@[aesop safe apply]
theorem smul [Star R] [Star A] [SMul R A] [StarModule R A]
{r : R} (hr : IsSelfAdjoint r) {x : A} (hx : IsSelfAdjoint x) :
IsSelfAdjoint (r • x) := by
simp only [isSelfAdjoint_iff, star_smul, hr.star_eq, hx.star_eq]
theorem smul_iff [Monoid R] [StarMul R] [Star A]
[MulAction R A] [StarModule R A] {r : R} (hr : IsSelfAdjoint r) (hu : IsUnit r) {x : A} :
IsSelfAdjoint (r • x) ↔ IsSelfAdjoint x := by
refine ⟨fun hrx ↦ ?_, .smul hr⟩
lift r to Rˣ using hu
rw [← inv_smul_smul r x]
replace hr : IsSelfAdjoint r := Units.ext hr.star_eq
exact hr.inv.smul hrx
end SMul
end IsSelfAdjoint
variable (R)
/-- The self-adjoint elements of a star additive group, as an additive subgroup. -/
def selfAdjoint [AddGroup R] [StarAddMonoid R] : AddSubgroup R where
carrier := { x | IsSelfAdjoint x }
zero_mem' := star_zero R
add_mem' hx := hx.add
neg_mem' hx := hx.neg
/-- The skew-adjoint elements of a star additive group, as an additive subgroup. -/
def skewAdjoint [AddCommGroup R] [StarAddMonoid R] : AddSubgroup R where
carrier := { x | star x = -x }
zero_mem' := show star (0 : R) = -0 by simp only [star_zero, neg_zero]
add_mem' := @fun x y (hx : star x = -x) (hy : star y = -y) =>
show star (x + y) = -(x + y) by rw [star_add x y, hx, hy, neg_add]
neg_mem' := @fun x (hx : star x = -x) => show star (-x) = - -x by simp only [hx, star_neg]
variable {R}
namespace selfAdjoint
section AddGroup
variable [AddGroup R] [StarAddMonoid R]
theorem mem_iff {x : R} : x ∈ selfAdjoint R ↔ star x = x := by
rw [← AddSubgroup.mem_carrier]
exact Iff.rfl
@[simp, norm_cast]
theorem star_val_eq {x : selfAdjoint R} : star (x : R) = x :=
x.prop
instance : Inhabited (selfAdjoint R) :=
⟨0⟩
@[simp]
lemma isSelfAdjoint {x : selfAdjoint R} : IsSelfAdjoint (x : R) := by simp [isSelfAdjoint_iff]
end AddGroup
instance isStarNormal [NonUnitalRing R] [StarRing R] (x : selfAdjoint R) :
IsStarNormal (x : R) :=
x.prop.isStarNormal
section Ring
variable [Ring R] [StarRing R]
instance : One (selfAdjoint R) :=
⟨⟨1, .one R⟩⟩
@[simp, norm_cast]
theorem val_one : ↑(1 : selfAdjoint R) = (1 : R) :=
rfl
instance [Nontrivial R] : Nontrivial (selfAdjoint R) :=
⟨⟨0, 1, ne_of_apply_ne Subtype.val zero_ne_one⟩⟩
instance : NatCast (selfAdjoint R) where
natCast n := ⟨n, .natCast _⟩
instance : IntCast (selfAdjoint R) where
intCast n := ⟨n, .intCast _⟩
instance : Pow (selfAdjoint R) ℕ where
pow x n := ⟨(x : R) ^ n, x.prop.pow n⟩
@[simp, norm_cast]
theorem val_pow (x : selfAdjoint R) (n : ℕ) : ↑(x ^ n) = (x : R) ^ n :=
rfl
end Ring
section NonUnitalCommRing
variable [NonUnitalCommRing R] [StarRing R]
instance : Mul (selfAdjoint R) where
mul x y := ⟨(x : R) * y, x.prop.mul y.prop⟩
@[simp, norm_cast]
theorem val_mul (x y : selfAdjoint R) : ↑(x * y) = (x : R) * y :=
rfl
end NonUnitalCommRing
section CommRing
variable [CommRing R] [StarRing R]
instance : CommRing (selfAdjoint R) :=
Function.Injective.commRing _ Subtype.coe_injective (selfAdjoint R).coe_zero val_one
(selfAdjoint R).coe_add val_mul (selfAdjoint R).coe_neg (selfAdjoint R).coe_sub
(by intros; rfl) (by intros; rfl) val_pow
(fun _ => rfl) fun _ => rfl
end CommRing
section Field
variable [Field R] [StarRing R]
instance : Inv (selfAdjoint R) where
inv x := ⟨x.val⁻¹, x.prop.inv₀⟩
@[simp, norm_cast]
theorem val_inv (x : selfAdjoint R) : ↑x⁻¹ = (x : R)⁻¹ :=
rfl
instance : Div (selfAdjoint R) where
div x y := ⟨x / y, x.prop.div y.prop⟩
@[simp, norm_cast]
theorem val_div (x y : selfAdjoint R) : ↑(x / y) = (x / y : R) :=
rfl
instance : Pow (selfAdjoint R) ℤ where
pow x z := ⟨(x : R) ^ z, x.prop.zpow₀ z⟩
@[simp, norm_cast]
theorem val_zpow (x : selfAdjoint R) (z : ℤ) : ↑(x ^ z) = (x : R) ^ z :=
rfl
instance instNNRatCast : NNRatCast (selfAdjoint R) where
nnratCast q := ⟨q, .nnratCast q⟩
instance instRatCast : RatCast (selfAdjoint R) where
ratCast q := ⟨q, .ratCast q⟩
@[simp, norm_cast] lemma val_nnratCast (q : ℚ≥0) : (q : selfAdjoint R) = (q : R) := rfl
@[simp, norm_cast] lemma val_ratCast (q : ℚ) : (q : selfAdjoint R) = (q : R) := rfl
instance instSMulNNRat : SMul ℚ≥0 (selfAdjoint R) where
smul a x := ⟨a • (x : R), by rw [NNRat.smul_def]; exact .mul (.nnratCast a) x.prop⟩
instance instSMulRat : SMul ℚ (selfAdjoint R) where
smul a x := ⟨a • (x : R), by rw [Rat.smul_def]; exact .mul (.ratCast a) x.prop⟩
@[simp, norm_cast] lemma val_nnqsmul (q : ℚ≥0) (x : selfAdjoint R) : ↑(q • x) = q • (x : R) := rfl
@[simp, norm_cast] lemma val_qsmul (q : ℚ) (x : selfAdjoint R) : ↑(q • x) = q • (x : R) := rfl
instance instField : Field (selfAdjoint R) :=
Subtype.coe_injective.field _ (selfAdjoint R).coe_zero val_one
(selfAdjoint R).coe_add val_mul (selfAdjoint R).coe_neg (selfAdjoint R).coe_sub
val_inv val_div (swap (selfAdjoint R).coe_nsmul) (by intros; rfl) val_nnqsmul
val_qsmul val_pow val_zpow (fun _ => rfl) (fun _ => rfl) val_nnratCast val_ratCast
end Field
section SMul
variable [Star R] [TrivialStar R] [AddGroup A] [StarAddMonoid A]
instance [SMul R A] [StarModule R A] : SMul R (selfAdjoint A) where
smul r x := ⟨r • (x : A), (IsSelfAdjoint.all _).smul x.prop⟩
@[simp, norm_cast]
theorem val_smul [SMul R A] [StarModule R A] (r : R) (x : selfAdjoint A) : ↑(r • x) = r • (x : A) :=
rfl
instance [Monoid R] [MulAction R A] [StarModule R A] : MulAction R (selfAdjoint A) :=
Function.Injective.mulAction Subtype.val Subtype.coe_injective val_smul
instance [Monoid R] [DistribMulAction R A] [StarModule R A] : DistribMulAction R (selfAdjoint A) :=
Function.Injective.distribMulAction (selfAdjoint A).subtype Subtype.coe_injective val_smul
end SMul
section Module
variable [Star R] [TrivialStar R] [AddCommGroup A] [StarAddMonoid A]
instance [Semiring R] [Module R A] [StarModule R A] : Module R (selfAdjoint A) :=
Function.Injective.module R (selfAdjoint A).subtype Subtype.coe_injective val_smul
end Module
end selfAdjoint
namespace skewAdjoint
section AddGroup
variable [AddCommGroup R] [StarAddMonoid R]
theorem mem_iff {x : R} : x ∈ skewAdjoint R ↔ star x = -x := by
rw [← AddSubgroup.mem_carrier]
exact Iff.rfl
@[simp, norm_cast]
theorem star_val_eq {x : skewAdjoint R} : star (x : R) = -x :=
x.prop
instance : Inhabited (skewAdjoint R) :=
⟨0⟩
end AddGroup
section Ring
variable [Ring R] [StarRing R]
theorem conjugate {x : R} (hx : x ∈ skewAdjoint R) (z : R) : z * x * star z ∈ skewAdjoint R := by
simp only [mem_iff, star_mul, star_star, mem_iff.mp hx, neg_mul, mul_neg, mul_assoc]
| theorem conjugate' {x : R} (hx : x ∈ skewAdjoint R) (z : R) : star z * x * z ∈ skewAdjoint R := by
simp only [mem_iff, star_mul, star_star, mem_iff.mp hx, neg_mul, mul_neg, mul_assoc]
| Mathlib/Algebra/Star/SelfAdjoint.lean | 509 | 511 |
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel
-/
import Mathlib.Topology.MetricSpace.Pseudo.Basic
import Mathlib.Topology.MetricSpace.Pseudo.Lemmas
import Mathlib.Topology.MetricSpace.Pseudo.Pi
import Mathlib.Topology.MetricSpace.Defs
/-!
# Basic properties of metric spaces, and instances.
-/
open Set Filter Bornology Topology
open scoped NNReal Uniformity
universe u v w
variable {α : Type u} {β : Type v} {X : Type*}
variable [PseudoMetricSpace α]
variable {γ : Type w} [MetricSpace γ]
namespace Metric
variable {x : γ} {s : Set γ}
-- see Note [lower instance priority]
instance (priority := 100) _root_.MetricSpace.instT0Space : T0Space γ where
t0 _ _ h := eq_of_dist_eq_zero <| Metric.inseparable_iff.1 h
/-- A map between metric spaces is a uniform embedding if and only if the distance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem isUniformEmbedding_iff' [PseudoMetricSpace β] {f : γ → β} :
IsUniformEmbedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, dist a b < δ → dist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, dist (f a) (f b) < ε → dist a b < δ := by
rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff]
/-- If a `PseudoMetricSpace` is a T₀ space, then it is a `MetricSpace`. -/
abbrev _root_.MetricSpace.ofT0PseudoMetricSpace (α : Type*) [PseudoMetricSpace α] [T0Space α] :
MetricSpace α where
toPseudoMetricSpace := ‹_›
| eq_of_dist_eq_zero hdist := (Metric.inseparable_iff.2 hdist).eq
-- see Note [lower instance priority]
| Mathlib/Topology/MetricSpace/Basic.lean | 45 | 47 |
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Geißer, Michael Stoll
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.DiophantineApproximation.Basic
import Mathlib.NumberTheory.Zsqrtd.Basic
import Mathlib.Tactic.Qify
/-!
# Pell's Equation
*Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer
that is not a square, and one is interested in solutions in integers $x$ and $y$.
In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$
(as opposed to the contents of `NumberTheory.PellMatiyasevic`, which is specific to the case
$d = a^2 - 1$ for some $a > 1$).
We begin by defining a type `Pell.Solution₁ d` for solutions of the equation,
show that it has a natural structure as an abelian group, and prove some basic
properties.
We then prove the following
**Theorem.** Let $d$ be a positive integer that is not a square. Then the equation
$x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers.
See `Pell.exists_of_not_isSquare` and `Pell.Solution₁.exists_nontrivial_of_not_isSquare`.
We then define the *fundamental solution* to be the solution
with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$.
We show that every solution is a power (in the sense of the group structure mentioned above)
of the fundamental solution up to a (common) sign,
see `Pell.IsFundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property
if and only if it is fundamental, see `Pell.pos_generator_iff_fundamental`.
## References
* [K. Ireland, M. Rosen, *A classical introduction to modern number theory*
(Section 17.5)][IrelandRosen1990]
## Tags
Pell's equation
## TODO
* Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations.
* Connect solutions to the continued fraction expansion of `√d`.
-/
namespace Pell
/-!
### Group structure of the solution set
We define a structure of a commutative multiplicative group with distributive negation
on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`.
The type of such solutions is `Pell.Solution₁ d`. It corresponds to a pair of integers `x` and `y`
and a proof that `(x, y)` is indeed a solution.
The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`.
This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results.
In fact, we define `Pell.Solution₁ d` to be `↥(unitary (ℤ√d))` and transport
the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`.
We then set up an API for `Pell.Solution₁ d`.
-/
open CharZero Zsqrtd
/-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if
it is contained in the submonoid of unitary elements.
TODO: merge this result with `Pell.isPell_iff_mem_unitary`. -/
theorem is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} :
a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by
rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc]
-- We use `solution₁ d` to allow for a more general structure `solution d m` that
-- encodes solutions to `x^2 - d*y^2 = m` to be added later.
/-- `Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`.
We define this in terms of elements of `ℤ√d` of norm one.
-/
def Solution₁ (d : ℤ) : Type :=
↥(unitary (ℤ√d))
namespace Solution₁
variable {d : ℤ}
instance instCommGroup : CommGroup (Solution₁ d) :=
inferInstanceAs (CommGroup (unitary (ℤ√d)))
instance instHasDistribNeg : HasDistribNeg (Solution₁ d) :=
inferInstanceAs (HasDistribNeg (unitary (ℤ√d)))
instance instInhabited : Inhabited (Solution₁ d) :=
inferInstanceAs (Inhabited (unitary (ℤ√d)))
instance : Coe (Solution₁ d) (ℤ√d) where coe := Subtype.val
/-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def x (a : Solution₁ d) : ℤ :=
(a : ℤ√d).re
/-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def y (a : Solution₁ d) : ℤ :=
(a : ℤ√d).im
/-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/
theorem prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 :=
is_pell_solution_iff_mem_unitary.mpr a.property
/-- An alternative form of the equation, suitable for rewriting `x^2`. -/
theorem prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring
/-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/
theorem prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring
/-- Two solutions are equal if their `x` and `y` components are equal. -/
@[ext]
theorem ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b :=
Subtype.ext <| Zsqrtd.ext hx hy
/-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/
def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where
val := ⟨x, y⟩
property := is_pell_solution_iff_mem_unitary.mp prop
@[simp]
theorem x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x :=
rfl
@[simp]
theorem y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y :=
rfl
@[simp]
theorem coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ :=
Zsqrtd.ext (x_mk x y prop) (y_mk x y prop)
@[simp]
theorem x_one : (1 : Solution₁ d).x = 1 :=
rfl
@[simp]
theorem y_one : (1 : Solution₁ d).y = 0 :=
rfl
@[simp]
theorem x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by
rw [← mul_assoc]
rfl
@[simp]
theorem y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x :=
rfl
@[simp]
theorem x_inv (a : Solution₁ d) : a⁻¹.x = a.x :=
rfl
@[simp]
theorem y_inv (a : Solution₁ d) : a⁻¹.y = -a.y :=
rfl
@[simp]
theorem x_neg (a : Solution₁ d) : (-a).x = -a.x :=
rfl
@[simp]
theorem y_neg (a : Solution₁ d) : (-a).y = -a.y :=
rfl
/-- When `d` is negative, then `x` or `y` must be zero in a solution. -/
theorem eq_zero_of_d_neg (h₀ : d < 0) (a : Solution₁ d) : a.x = 0 ∨ a.y = 0 := by
have h := a.prop
contrapose! h
have h1 := sq_pos_of_ne_zero h.1
have h2 := sq_pos_of_ne_zero h.2
nlinarith
/-- A solution has `x ≠ 0`. -/
theorem x_ne_zero (h₀ : 0 ≤ d) (a : Solution₁ d) : a.x ≠ 0 := by
intro hx
have h : 0 ≤ d * a.y ^ 2 := mul_nonneg h₀ (sq_nonneg _)
rw [a.prop_y, hx, sq, zero_mul, zero_sub] at h
exact not_le.mpr (neg_one_lt_zero : (-1 : ℤ) < 0) h
/-- A solution with `x > 1` must have `y ≠ 0`. -/
theorem y_ne_zero_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : a.y ≠ 0 := by
intro hy
have prop := a.prop
rw [hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero] at prop
exact lt_irrefl _ (((one_lt_sq_iff₀ <| zero_le_one.trans ha.le).mpr ha).trans_eq prop)
/-- If a solution has `x > 1`, then `d` is positive. -/
theorem d_pos_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : 0 < d := by
refine pos_of_mul_pos_left ?_ (sq_nonneg a.y)
rw [a.prop_y, sub_pos]
exact one_lt_pow₀ ha two_ne_zero
/-- If a solution has `x > 1`, then `d` is not a square. -/
theorem d_nonsquare_of_one_lt_x {a : Solution₁ d} (ha : 1 < a.x) : ¬IsSquare d := by
have hp := a.prop
rintro ⟨b, rfl⟩
simp_rw [← sq, ← mul_pow, sq_sub_sq, Int.mul_eq_one_iff_eq_one_or_neg_one] at hp
omega
/-- A solution with `x = 1` is trivial. -/
theorem eq_one_of_x_eq_one (h₀ : d ≠ 0) {a : Solution₁ d} (ha : a.x = 1) : a = 1 := by
have prop := a.prop_y
rw [ha, one_pow, sub_self, mul_eq_zero, or_iff_right h₀, sq_eq_zero_iff] at prop
exact ext ha prop
/-- A solution is `1` or `-1` if and only if `y = 0`. -/
theorem eq_one_or_neg_one_iff_y_eq_zero {a : Solution₁ d} : a = 1 ∨ a = -1 ↔ a.y = 0 := by
refine ⟨fun H => H.elim (fun h => by simp [h]) fun h => by simp [h], fun H => ?_⟩
have prop := a.prop
rw [H, sq (0 : ℤ), mul_zero, mul_zero, sub_zero, sq_eq_one_iff] at prop
exact prop.imp (fun h => ext h H) fun h => ext h H
/-- The set of solutions with `x > 0` is closed under multiplication. -/
theorem x_mul_pos {a b : Solution₁ d} (ha : 0 < a.x) (hb : 0 < b.x) : 0 < (a * b).x := by
simp only [x_mul]
refine neg_lt_iff_pos_add'.mp (abs_lt.mp ?_).1
rw [← abs_of_pos ha, ← abs_of_pos hb, ← abs_mul, ← sq_lt_sq, mul_pow a.x, a.prop_x, b.prop_x, ←
sub_pos]
ring_nf
rcases le_or_lt 0 d with h | h
· positivity
· rw [(eq_zero_of_d_neg h a).resolve_left ha.ne', (eq_zero_of_d_neg h b).resolve_left hb.ne']
simp
/-- The set of solutions with `x` and `y` positive is closed under multiplication. -/
theorem y_mul_pos {a b : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (hbx : 0 < b.x)
(hby : 0 < b.y) : 0 < (a * b).y := by
simp only [y_mul]
positivity
/-- If `(x, y)` is a solution with `x` positive, then all its powers with natural exponents
have positive `x`. -/
theorem x_pow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℕ) : 0 < (a ^ n).x := by
induction n with
| zero => simp only [pow_zero, x_one, zero_lt_one]
| succ n ih => rw [pow_succ]; exact x_mul_pos ih hax
/-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive
natural exponents have positive `y`. -/
theorem y_pow_succ_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) (n : ℕ) :
0 < (a ^ n.succ).y := by
induction n with
| zero => simp only [pow_one, hay]
| succ n ih => rw [pow_succ']; exact y_mul_pos hax hay (x_pow_pos hax _) ih
/-- If `(x, y)` is a solution with `x` and `y` positive, then all its powers with positive
exponents have positive `y`. -/
theorem y_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y) {n : ℤ} (hn : 0 < n) :
0 < (a ^ n).y := by
lift n to ℕ using hn.le
norm_cast at hn ⊢
rw [← Nat.succ_pred_eq_of_pos hn]
exact y_pow_succ_pos hax hay _
/-- If `(x, y)` is a solution with `x` positive, then all its powers have positive `x`. -/
theorem x_zpow_pos {a : Solution₁ d} (hax : 0 < a.x) (n : ℤ) : 0 < (a ^ n).x := by
cases n with
| ofNat n =>
rw [Int.ofNat_eq_coe, zpow_natCast]
exact x_pow_pos hax n
| negSucc n =>
rw [zpow_negSucc]
exact x_pow_pos hax (n + 1)
/-- If `(x, y)` is a solution with `x` and `y` positive, then the `y` component of any power
has the same sign as the exponent. -/
theorem sign_y_zpow_eq_sign_of_x_pos_of_y_pos {a : Solution₁ d} (hax : 0 < a.x) (hay : 0 < a.y)
(n : ℤ) : (a ^ n).y.sign = n.sign := by
rcases n with ((_ | n) | n)
· rfl
· rw [Int.ofNat_eq_coe, zpow_natCast]
exact Int.sign_eq_one_of_pos (y_pow_succ_pos hax hay n)
· rw [zpow_negSucc]
exact Int.sign_eq_neg_one_of_neg (neg_neg_of_pos (y_pow_succ_pos hax hay n))
/-- If `a` is any solution, then one of `a`, `a⁻¹`, `-a`, `-a⁻¹` has
positive `x` and nonnegative `y`. -/
theorem exists_pos_variant (h₀ : 0 < d) (a : Solution₁ d) :
∃ b : Solution₁ d, 0 < b.x ∧ 0 ≤ b.y ∧ a ∈ ({b, b⁻¹, -b, -b⁻¹} : Set (Solution₁ d)) := by
refine
(lt_or_gt_of_ne (a.x_ne_zero h₀.le)).elim
((le_total 0 a.y).elim (fun hy hx => ⟨-a⁻¹, ?_, ?_, ?_⟩) fun hy hx => ⟨-a, ?_, ?_, ?_⟩)
((le_total 0 a.y).elim (fun hy hx => ⟨a, hx, hy, ?_⟩) fun hy hx => ⟨a⁻¹, hx, ?_, ?_⟩) <;>
simp only [neg_neg, inv_inv, neg_inv, Set.mem_insert_iff, Set.mem_singleton_iff, true_or,
eq_self_iff_true, x_neg, x_inv, y_neg, y_inv, neg_pos, neg_nonneg, or_true] <;>
assumption
end Solution₁
section Existence
/-!
### Existence of nontrivial solutions
-/
variable {d : ℤ}
open Set Real
/-- If `d` is a positive integer that is not a square, then there is a nontrivial solution
to the Pell equation `x^2 - d*y^2 = 1`. -/
theorem exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) :
∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0 := by
let ξ : ℝ := √d
have hξ : Irrational ξ := by
refine irrational_nrt_of_notint_nrt 2 d (sq_sqrt <| Int.cast_nonneg.mpr h₀.le) ?_ two_pos
rintro ⟨x, hx⟩
refine hd ⟨x, @Int.cast_injective ℝ _ _ d (x * x) ?_⟩
rw [← sq_sqrt <| Int.cast_nonneg.mpr h₀.le, Int.cast_mul, ← hx, sq]
obtain ⟨M, hM₁⟩ := exists_int_gt (2 * |ξ| + 1)
have hM : {q : ℚ | |q.1 ^ 2 - d * (q.2 : ℤ) ^ 2| < M}.Infinite := by
refine Infinite.mono (fun q h => ?_) (infinite_rat_abs_sub_lt_one_div_den_sq_of_irrational hξ)
have h0 : 0 < (q.2 : ℝ) ^ 2 := pow_pos (Nat.cast_pos.mpr q.pos) 2
have h1 : (q.num : ℝ) / (q.den : ℝ) = q := mod_cast q.num_div_den
rw [mem_setOf, abs_sub_comm, ← @Int.cast_lt ℝ,
← div_lt_div_iff_of_pos_right (abs_pos_of_pos h0)]
push_cast
rw [← abs_div, abs_sq, sub_div, mul_div_cancel_right₀ _ h0.ne', ← div_pow, h1, ←
sq_sqrt (Int.cast_pos.mpr h₀).le, sq_sub_sq, abs_mul, ← mul_one_div]
refine mul_lt_mul'' (((abs_add ξ q).trans ?_).trans_lt hM₁) h (abs_nonneg _) (abs_nonneg _)
rw [two_mul, add_assoc, add_le_add_iff_left, ← sub_le_iff_le_add']
rw [mem_setOf, abs_sub_comm] at h
refine (abs_sub_abs_le_abs_sub (q : ℝ) ξ).trans (h.le.trans ?_)
rw [div_le_one h0, one_le_sq_iff_one_le_abs, Nat.abs_cast, Nat.one_le_cast]
exact q.pos
obtain ⟨m, hm⟩ : ∃ m : ℤ, {q : ℚ | q.1 ^ 2 - d * (q.den : ℤ) ^ 2 = m}.Infinite := by
contrapose! hM
simp only [not_infinite] at hM ⊢
refine (congr_arg _ (ext fun x => ?_)).mp (Finite.biUnion (finite_Ioo (-M) M) fun m _ => hM m)
simp only [abs_lt, mem_setOf, mem_Ioo, mem_iUnion, exists_prop, exists_eq_right']
have hm₀ : m ≠ 0 := by
rintro rfl
obtain ⟨q, hq⟩ := hm.nonempty
rw [mem_setOf, sub_eq_zero, mul_comm] at hq
obtain ⟨a, ha⟩ := (Int.pow_dvd_pow_iff two_ne_zero).mp ⟨d, hq⟩
rw [ha, mul_pow, mul_right_inj' (pow_pos (Int.natCast_pos.mpr q.pos) 2).ne'] at hq
exact hd ⟨a, sq a ▸ hq.symm⟩
haveI := neZero_iff.mpr (Int.natAbs_ne_zero.mpr hm₀)
let f : ℚ → ZMod m.natAbs × ZMod m.natAbs := fun q => (q.num, q.den)
obtain ⟨q₁, h₁ : q₁.num ^ 2 - d * (q₁.den : ℤ) ^ 2 = m,
q₂, h₂ : q₂.num ^ 2 - d * (q₂.den : ℤ) ^ 2 = m, hne, hqf⟩ :=
hm.exists_ne_map_eq_of_mapsTo (mapsTo_univ f _) finite_univ
obtain ⟨hq1 : (q₁.num : ZMod m.natAbs) = q₂.num, hq2 : (q₁.den : ZMod m.natAbs) = q₂.den⟩ :=
Prod.ext_iff.mp hqf
have hd₁ : m ∣ q₁.num * q₂.num - d * (q₁.den * q₂.den) := by
rw [← Int.natAbs_dvd, ← ZMod.intCast_zmod_eq_zero_iff_dvd]
push_cast
rw [hq1, hq2, ← sq, ← sq]
norm_cast
rw [ZMod.intCast_zmod_eq_zero_iff_dvd, Int.natAbs_dvd, Nat.cast_pow, ← h₂]
have hd₂ : m ∣ q₁.num * q₂.den - q₂.num * q₁.den := by
rw [← Int.natAbs_dvd, ← ZMod.intCast_eq_intCast_iff_dvd_sub]
push_cast
rw [hq1, hq2]
replace hm₀ : (m : ℚ) ≠ 0 := Int.cast_ne_zero.mpr hm₀
refine ⟨(q₁.num * q₂.num - d * (q₁.den * q₂.den)) / m, (q₁.num * q₂.den - q₂.num * q₁.den) / m,
?_, ?_⟩
· qify [hd₁, hd₂]
field_simp [hm₀]
norm_cast
conv_rhs =>
rw [sq]
congr
· rw [← h₁]
· rw [← h₂]
push_cast
ring
· qify [hd₂]
refine div_ne_zero_iff.mpr ⟨?_, hm₀⟩
exact mod_cast mt sub_eq_zero.mp (mt Rat.eq_iff_mul_eq_mul.mpr hne)
/-- If `d` is a positive integer, then there is a nontrivial solution
to the Pell equation `x^2 - d*y^2 = 1` if and only if `d` is not a square. -/
theorem exists_iff_not_isSquare (h₀ : 0 < d) :
(∃ x y : ℤ, x ^ 2 - d * y ^ 2 = 1 ∧ y ≠ 0) ↔ ¬IsSquare d := by
refine ⟨?_, exists_of_not_isSquare h₀⟩
rintro ⟨x, y, hxy, hy⟩ ⟨a, rfl⟩
rw [← sq, ← mul_pow, sq_sub_sq] at hxy
simpa [hy, mul_self_pos.mp h₀, sub_eq_add_neg, eq_neg_self_iff] using Int.eq_of_mul_eq_one hxy
namespace Solution₁
/-- If `d` is a positive integer that is not a square, then there exists a nontrivial solution
to the Pell equation `x^2 - d*y^2 = 1`. -/
theorem exists_nontrivial_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) :
∃ a : Solution₁ d, a ≠ 1 ∧ a ≠ -1 := by
obtain ⟨x, y, prop, hy⟩ := exists_of_not_isSquare h₀ hd
refine ⟨mk x y prop, fun H => ?_, fun H => ?_⟩ <;> apply_fun Solution₁.y at H <;>
simp [hy] at H
/-- If `d` is a positive integer that is not a square, then there exists a solution
to the Pell equation `x^2 - d*y^2 = 1` with `x > 1` and `y > 0`. -/
theorem exists_pos_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) :
∃ a : Solution₁ d, 1 < a.x ∧ 0 < a.y := by
obtain ⟨x, y, h, hy⟩ := exists_of_not_isSquare h₀ hd
refine ⟨mk |x| |y| (by rwa [sq_abs, sq_abs]), ?_, abs_pos.mpr hy⟩
rw [x_mk, ← one_lt_sq_iff_one_lt_abs, eq_add_of_sub_eq h, lt_add_iff_pos_right]
exact mul_pos h₀ (sq_pos_of_ne_zero hy)
end Solution₁
end Existence
/-! ### Fundamental solutions
We define the notion of a *fundamental solution* of Pell's equation and
show that it exists and is unique (when `d` is positive and non-square)
and generates the group of solutions up to sign.
-/
variable {d : ℤ}
/-- We define a solution to be *fundamental* if it has `x > 1` and `y > 0`
and its `x` is the smallest possible among solutions with `x > 1`. -/
def IsFundamental (a : Solution₁ d) : Prop :=
1 < a.x ∧ 0 < a.y ∧ ∀ {b : Solution₁ d}, 1 < b.x → a.x ≤ b.x
namespace IsFundamental
open Solution₁
/-- A fundamental solution has positive `x`. -/
theorem x_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < a.x :=
zero_lt_one.trans h.1
/-- If a fundamental solution exists, then `d` must be positive. -/
theorem d_pos {a : Solution₁ d} (h : IsFundamental a) : 0 < d :=
d_pos_of_one_lt_x h.1
/-- If a fundamental solution exists, then `d` must be a non-square. -/
theorem d_nonsquare {a : Solution₁ d} (h : IsFundamental a) : ¬IsSquare d :=
d_nonsquare_of_one_lt_x h.1
/-- If there is a fundamental solution, it is unique. -/
theorem subsingleton {a b : Solution₁ d} (ha : IsFundamental a) (hb : IsFundamental b) : a = b := by
have hx := le_antisymm (ha.2.2 hb.1) (hb.2.2 ha.1)
refine Solution₁.ext hx ?_
have : d * a.y ^ 2 = d * b.y ^ 2 := by rw [a.prop_y, b.prop_y, hx]
exact (sq_eq_sq₀ ha.2.1.le hb.2.1.le).mp (Int.eq_of_mul_eq_mul_left ha.d_pos.ne' this)
/-- If `d` is positive and not a square, then a fundamental solution exists. -/
theorem exists_of_not_isSquare (h₀ : 0 < d) (hd : ¬IsSquare d) :
∃ a : Solution₁ d, IsFundamental a := by
obtain ⟨a, ha₁, ha₂⟩ := exists_pos_of_not_isSquare h₀ hd
-- convert to `x : ℕ` to be able to use `Nat.find`
have P : ∃ x' : ℕ, 1 < x' ∧ ∃ y' : ℤ, 0 < y' ∧ (x' : ℤ) ^ 2 - d * y' ^ 2 = 1 := by
have hax := a.prop
lift a.x to ℕ using by positivity with ax
norm_cast at ha₁
exact ⟨ax, ha₁, a.y, ha₂, hax⟩
classical
-- to avoid having to show that the predicate is decidable
let x₁ := Nat.find P
obtain ⟨hx, y₁, hy₀, hy₁⟩ := Nat.find_spec P
refine ⟨mk x₁ y₁ hy₁, by rw [x_mk]; exact mod_cast hx, hy₀, fun {b} hb => ?_⟩
rw [x_mk]
have hb' := (Int.toNat_of_nonneg <| zero_le_one.trans hb.le).symm
have hb'' := hb
rw [hb'] at hb ⊢
norm_cast at hb ⊢
refine Nat.find_min' P ⟨hb, |b.y|, abs_pos.mpr <| y_ne_zero_of_one_lt_x hb'', ?_⟩
rw [← hb', sq_abs]
exact b.prop
/-- The map sending an integer `n` to the `y`-coordinate of `a^n` for a fundamental
solution `a` is stritcly increasing. -/
theorem y_strictMono {a : Solution₁ d} (h : IsFundamental a) :
StrictMono fun n : ℤ => (a ^ n).y := by
have H : ∀ n : ℤ, 0 ≤ n → (a ^ n).y < (a ^ (n + 1)).y := by
intro n hn
rw [← sub_pos, zpow_add, zpow_one, y_mul, add_sub_assoc]
rw [show (a ^ n).y * a.x - (a ^ n).y = (a ^ n).y * (a.x - 1) by ring]
refine
add_pos_of_pos_of_nonneg (mul_pos (x_zpow_pos h.x_pos _) h.2.1)
(mul_nonneg ?_ (by rw [sub_nonneg]; exact h.1.le))
rcases hn.eq_or_lt with (rfl | hn)
· simp only [zpow_zero, y_one, le_refl]
· exact (y_zpow_pos h.x_pos h.2.1 hn).le
refine strictMono_int_of_lt_succ fun n => ?_
rcases le_or_lt 0 n with hn | hn
· exact H n hn
· let m : ℤ := -n - 1
have hm : n = -m - 1 := by simp only [m, neg_sub, sub_neg_eq_add, add_tsub_cancel_left]
rw [hm, sub_add_cancel, ← neg_add', zpow_neg, zpow_neg, y_inv, y_inv, neg_lt_neg_iff]
exact H _ (by omega)
/-- If `a` is a fundamental solution, then `(a^m).y < (a^n).y` if and only if `m < n`. -/
theorem zpow_y_lt_iff_lt {a : Solution₁ d} (h : IsFundamental a) (m n : ℤ) :
(a ^ m).y < (a ^ n).y ↔ m < n := by
refine ⟨fun H => ?_, fun H => h.y_strictMono H⟩
contrapose! H
exact h.y_strictMono.monotone H
/-- The `n`th power of a fundamental solution is trivial if and only if `n = 0`. -/
theorem zpow_eq_one_iff {a : Solution₁ d} (h : IsFundamental a) (n : ℤ) : a ^ n = 1 ↔ n = 0 := by
rw [← zpow_zero a]
exact ⟨fun H => h.y_strictMono.injective (congr_arg Solution₁.y H), fun H => H ▸ rfl⟩
/-- A power of a fundamental solution is never equal to the negative of a power of this
fundamental solution. -/
theorem zpow_ne_neg_zpow {a : Solution₁ d} (h : IsFundamental a) {n n' : ℤ} : a ^ n ≠ -a ^ n' := by
intro hf
apply_fun Solution₁.x at hf
have H := x_zpow_pos h.x_pos n
rw [hf, x_neg, lt_neg, neg_zero] at H
exact lt_irrefl _ ((x_zpow_pos h.x_pos n').trans H)
/-- The `x`-coordinate of a fundamental solution is a lower bound for the `x`-coordinate
of any positive solution. -/
theorem x_le_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x) :
a₁.x ≤ a.x :=
h.2.2 hax
/-- The `y`-coordinate of a fundamental solution is a lower bound for the `y`-coordinate
of any positive solution. -/
theorem y_le_y {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x)
(hay : 0 < a.y) : a₁.y ≤ a.y := by
have H : d * (a₁.y ^ 2 - a.y ^ 2) = a₁.x ^ 2 - a.x ^ 2 := by rw [a.prop_x, a₁.prop_x]; ring
rw [← abs_of_pos hay, ← abs_of_pos h.2.1, ← sq_le_sq, ← mul_le_mul_left h.d_pos, ← sub_nonpos, ←
mul_sub, H, sub_nonpos, sq_le_sq, abs_of_pos (zero_lt_one.trans h.1),
abs_of_pos (zero_lt_one.trans hax)]
exact h.x_le_x hax
-- helper lemma for the next three results
theorem x_mul_y_le_y_mul_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d}
(hax : 1 < a.x) (hay : 0 < a.y) : a.x * a₁.y ≤ a.y * a₁.x := by
rw [← abs_of_pos <| zero_lt_one.trans hax, ← abs_of_pos hay, ← abs_of_pos h.x_pos, ←
abs_of_pos h.2.1, ← abs_mul, ← abs_mul, ← sq_le_sq, mul_pow, mul_pow, a.prop_x, a₁.prop_x, ←
sub_nonneg]
ring_nf
rw [sub_nonneg, sq_le_sq, abs_of_pos hay, abs_of_pos h.2.1]
exact h.y_le_y hax hay
/-- If we multiply a positive solution with the inverse of a fundamental solution,
the `y`-coordinate remains nonnegative. -/
theorem mul_inv_y_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x)
(hay : 0 < a.y) : 0 ≤ (a * a₁⁻¹).y := by
simpa only [y_inv, mul_neg, y_mul, le_neg_add_iff_add_le, add_zero] using
h.x_mul_y_le_y_mul_x hax hay
/-- If we multiply a positive solution with the inverse of a fundamental solution,
the `x`-coordinate stays positive. -/
theorem mul_inv_x_pos {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x)
(hay : 0 < a.y) : 0 < (a * a₁⁻¹).x := by
simp only [x_mul, x_inv, y_inv, mul_neg, lt_add_neg_iff_add_lt, zero_add]
refine (mul_lt_mul_left <| zero_lt_one.trans hax).mp ?_
rw [(by ring : a.x * (d * (a.y * a₁.y)) = d * a.y * (a.x * a₁.y))]
refine ((mul_le_mul_left <| mul_pos h.d_pos hay).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_
rw [← mul_assoc, mul_assoc d, ← sq, a.prop_y, ← sub_pos]
ring_nf
exact zero_lt_one.trans h.1
/-- If we multiply a positive solution with the inverse of a fundamental solution,
the `x`-coordinate decreases. -/
theorem mul_inv_x_lt_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x)
(hay : 0 < a.y) : (a * a₁⁻¹).x < a.x := by
simp only [x_mul, x_inv, y_inv, mul_neg, add_neg_lt_iff_le_add']
refine (mul_lt_mul_left h.2.1).mp ?_
rw [(by ring : a₁.y * (a.x * a₁.x) = a.x * a₁.y * a₁.x)]
refine
((mul_le_mul_right <| zero_lt_one.trans h.1).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_
rw [mul_assoc, ← sq, a₁.prop_x, ← sub_neg]
suffices a.y - a.x * a₁.y < 0 by convert this using 1; ring
rw [sub_neg, ← abs_of_pos hay, ← abs_of_pos h.2.1, ← abs_of_pos <| zero_lt_one.trans hax, ←
abs_mul, ← sq_lt_sq, mul_pow, a.prop_x]
calc
a.y ^ 2 = 1 * a.y ^ 2 := (one_mul _).symm
_ ≤ d * a.y ^ 2 := (mul_le_mul_right <| sq_pos_of_pos hay).mpr h.d_pos
_ < d * a.y ^ 2 + 1 := lt_add_one _
_ = (1 + d * a.y ^ 2) * 1 := by rw [add_comm, mul_one]
_ ≤ (1 + d * a.y ^ 2) * a₁.y ^ 2 :=
(mul_le_mul_left (by have := h.d_pos; positivity)).mpr (sq_pos_of_pos h.2.1)
/-- Any nonnegative solution is a power with nonnegative exponent of a fundamental solution. -/
theorem eq_pow_of_nonneg {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 0 < a.x)
(hay : 0 ≤ a.y) : ∃ n : ℕ, a = a₁ ^ n := by
lift a.x to ℕ using hax.le with ax hax'
induction ax using Nat.strong_induction_on generalizing a with | h x ih =>
rcases hay.eq_or_lt with hy | hy
· -- case 1: `a = 1`
refine ⟨0, ?_⟩
simp only [pow_zero]
ext <;> simp only [x_one, y_one]
· have prop := a.prop
rw [← hy, sq (0 : ℤ), zero_mul, mul_zero, sub_zero,
sq_eq_one_iff] at prop
refine prop.resolve_right fun hf => ?_
have := (hax.trans_eq hax').le.trans_eq hf
norm_num at this
· exact hy.symm
· -- case 2: `a ≥ a₁`
have hx₁ : 1 < a.x := by nlinarith [a.prop, h.d_pos]
have hxx₁ := h.mul_inv_x_pos hx₁ hy
have hxx₂ := h.mul_inv_x_lt_x hx₁ hy
have hyy := h.mul_inv_y_nonneg hx₁ hy
lift (a * a₁⁻¹).x to ℕ using hxx₁.le with x' hx'
obtain ⟨n, hn⟩ := ih x' (mod_cast hxx₂.trans_eq hax'.symm) hyy hx' hxx₁
exact ⟨n + 1, by rw [pow_succ', ← hn, mul_comm a, ← mul_assoc, mul_inv_cancel, one_mul]⟩
/-- Every solution is, up to a sign, a power of a given fundamental solution. -/
theorem eq_zpow_or_neg_zpow {a₁ : Solution₁ d} (h : IsFundamental a₁) (a : Solution₁ d) :
∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by
obtain ⟨b, hbx, hby, hb⟩ := exists_pos_variant h.d_pos a
obtain ⟨n, hn⟩ := h.eq_pow_of_nonneg hbx hby
rcases hb with (rfl | rfl | rfl | hb)
· exact ⟨n, Or.inl (mod_cast hn)⟩
· exact ⟨-n, Or.inl (by simp [hn])⟩
· exact ⟨n, Or.inr (by simp [hn])⟩
· rw [Set.mem_singleton_iff] at hb
rw [hb]
exact ⟨-n, Or.inr (by simp [hn])⟩
end IsFundamental
open Solution₁ IsFundamental
/-- When `d` is positive and not a square, then the group of solutions to the Pell equation
`x^2 - d*y^2 = 1` has a unique positive generator (up to sign). -/
theorem existsUnique_pos_generator (h₀ : 0 < d) (hd : ¬IsSquare d) :
∃! a₁ : Solution₁ d,
| 1 < a₁.x ∧ 0 < a₁.y ∧ ∀ a : Solution₁ d, ∃ n : ℤ, a = a₁ ^ n ∨ a = -a₁ ^ n := by
obtain ⟨a₁, ha₁⟩ := IsFundamental.exists_of_not_isSquare h₀ hd
refine ⟨a₁, ⟨ha₁.1, ha₁.2.1, ha₁.eq_zpow_or_neg_zpow⟩, fun a (H : 1 < _ ∧ _) => ?_⟩
obtain ⟨Hx, Hy, H⟩ := H
obtain ⟨n₁, hn₁⟩ := H a₁
obtain ⟨n₂, hn₂⟩ := ha₁.eq_zpow_or_neg_zpow a
rcases hn₂ with (rfl | rfl)
· rw [← zpow_mul, eq_comm, @eq_comm _ a₁, ← mul_inv_eq_one, ← @mul_inv_eq_one _ _ _ a₁, ←
zpow_neg_one, neg_mul, ← zpow_add, ← sub_eq_add_neg] at hn₁
rcases hn₁ with hn₁ | hn₁
· rcases Int.isUnit_iff.mp
(isUnit_of_mul_eq_one _ _ <|
sub_eq_zero.mp <| (ha₁.zpow_eq_one_iff (n₂ * n₁ - 1)).mp hn₁) with
(rfl | rfl)
· rw [zpow_one]
· rw [zpow_neg_one, y_inv, lt_neg, neg_zero] at Hy
exact False.elim (lt_irrefl _ <| ha₁.2.1.trans Hy)
· rw [← zpow_zero a₁, eq_comm] at hn₁
exact False.elim (ha₁.zpow_ne_neg_zpow hn₁)
| Mathlib/NumberTheory/Pell.lean | 639 | 657 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Algebra.Field.NegOnePow
import Mathlib.Algebra.Field.Periodic
import Mathlib.Algebra.QuadraticDiscriminant
import Mathlib.Analysis.SpecialFunctions.Exp
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and
`Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Complex.Arg` and
`Analysis.SpecialFunctions.Complex.Log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`Analysis.SpecialFunctions.Trigonometric.Complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open Topology Filter Set
namespace Complex
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin := by
change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2
fun_prop
@[fun_prop]
theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos := by
change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2
fun_prop
@[fun_prop]
theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh := by
change Continuous fun z => (exp z - exp (-z)) / 2
fun_prop
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh := by
change Continuous fun z => (exp z + exp (-z)) / 2
fun_prop
end Complex
namespace Real
variable {x y z : ℝ}
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin :=
Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_sin {s} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos :=
Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_cos {s} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh :=
Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal)
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh :=
Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal)
end Real
namespace Real
theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuousOn_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`.
Denoted `π`, once the `Real` namespace is opened. -/
protected noncomputable def pi : ℝ :=
2 * Classical.choose exists_cos_eq_zero
@[inherit_doc]
scoped notation "π" => Real.pi
@[simp]
theorem cos_pi_div_two : cos (π / 2) = 0 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).2
theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.1
theorem pi_div_two_le_two : π / 2 ≤ 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.2
theorem two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1
(by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two)
theorem pi_le_four : π ≤ 4 :=
(div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1
(calc
π / 2 ≤ 2 := pi_div_two_le_two
_ = 4 / 2 := by norm_num)
@[bound]
theorem pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
@[bound]
theorem pi_nonneg : 0 ≤ π :=
pi_pos.le
theorem pi_ne_zero : π ≠ 0 :=
pi_pos.ne'
theorem pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos]
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `π` is always positive. -/
@[positivity Real.pi]
def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.pi) =>
assertInstancesCommute
pure (.positive q(Real.pi_pos))
| _, _, _ => throwError "not Real.pi"
end Mathlib.Meta.Positivity
namespace NNReal
open Real
open Real NNReal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 :=
⟨π, Real.pi_pos.le⟩
@[simp]
theorem coe_real_pi : (pi : ℝ) = π :=
rfl
theorem pi_pos : 0 < pi := mod_cast Real.pi_pos
theorem pi_ne_zero : pi ≠ 0 :=
pi_pos.ne'
end NNReal
namespace Real
@[simp]
theorem sin_pi : sin π = 0 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp
@[simp]
theorem cos_pi : cos π = -1 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two]
norm_num
@[simp]
theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add]
@[simp]
theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add]
theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add]
theorem sin_periodic : Function.Periodic sin (2 * π) :=
sin_antiperiodic.periodic_two_mul
@[simp]
theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
@[simp]
theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
@[simp]
theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp]
theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
@[simp]
theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
@[simp]
theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
@[simp]
theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
@[simp]
theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
@[simp]
theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp]
theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp]
theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
@[simp]
theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x :=
n.cast_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n
theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.add_nat_mul_eq n
theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x :=
n.cast_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n
theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.sub_nat_mul_eq n
theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n
theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add]
theorem cos_periodic : Function.Periodic cos (2 * π) :=
cos_antiperiodic.periodic_two_mul
@[simp]
theorem abs_cos_int_mul_pi (k : ℤ) : |cos (k * π)| = 1 := by
simp [abs_cos_eq_sqrt_one_sub_sin_sq]
@[simp]
theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
@[simp]
theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
@[simp]
theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp]
theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
@[simp]
theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
@[simp]
theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
@[simp]
theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp]
theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp]
theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
@[simp]
theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
@[simp]
theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp]
theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp]
theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
@[simp]
theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x :=
n.cast_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n
theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.add_nat_mul_eq n
theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x :=
n.cast_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n
theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.sub_nat_mul_eq n
theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x :=
n.cast_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n
theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x :=
cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n
theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have : (2 : ℝ) + 2 = 4 := by norm_num
have : π - x ≤ 2 :=
sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _))
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by
rw [← closure_Ioo pi_ne_zero.symm] at hx
exact
closure_lt_subset_le continuous_const continuous_sin
(closure_mono (fun y => sin_pos_of_mem_Ioo) hx)
theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp]
theorem sin_pi_div_two : sin (π / 2) = 1 :=
have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by
simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2)
this.resolve_right fun h =>
show ¬(0 : ℝ) < -1 by norm_num <|
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)
theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add]
theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add]
theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by
rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) :
cos x < 0 :=
neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = √(1 - cos x ^ 2) := by
rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = √(1 - sin x ^ 2) := by
rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by
have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith
rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves]
lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by
rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div]
lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) :
sin (x / 2) = sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonneg]
apply sin_nonneg_of_nonneg_of_le_pi <;> linarith
lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) :
sin (x / 2) = -sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonpos, neg_neg]
apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith
theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 :=
⟨fun h => by
contrapose! h
cases h.lt_or_lt with
| inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne
| inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne',
fun h => by simp [h]⟩
theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨fun h =>
⟨⌊x / π⌋,
le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 <|
le_of_not_gt fun h₃ =>
(sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩
theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self]
exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩
theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨fun h =>
let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h))
⟨n / 2,
(Int.emod_two_eq_zero_or_one n).elim
(fun hn0 => by
rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul,
Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)])
fun hn1 => by
rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm,
mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn
rw [← hn, cos_int_mul_two_pi_add_pi] at h
exact absurd h (by norm_num)⟩,
fun ⟨_, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩
theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨fun h => by
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁
norm_cast at hx₁ hx₂
obtain rfl : n = 0 := le_antisymm (by omega) (by omega)
simp, fun h => by simp [h]⟩
theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : sin x < sin y := by
rw [← sub_pos, sin_sub_sin]
have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith
have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
positivity
theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy =>
sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x := by
rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub]
apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith
| theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : cos y < cos x :=
cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean | 549 | 551 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Shing Tak Lam, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Log
import Mathlib.Data.List.Palindrome
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
/-!
# Digits of a natural number
This provides a basic API for extracting the digits of a natural number in a given base,
and reconstructing numbers from their digits.
We also prove some divisibility tests based on digits, in particular completing
Theorem #85 from https://www.cs.ru.nl/~freek/100/.
Also included is a bound on the length of `Nat.toDigits` from core.
## TODO
A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b`
are numerals is not yet ported.
-/
namespace Nat
variable {n : ℕ}
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux0 : ℕ → List ℕ
| 0 => []
| n + 1 => [n + 1]
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux1 (n : ℕ) : List ℕ :=
List.replicate n 1
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ
| 0 => []
| n + 1 =>
((n + 1) % b) :: digitsAux b h ((n + 1) / b)
decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h
@[simp]
theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux]
theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) :
digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by
cases n
· cases w
· rw [digitsAux]
/-- `digits b n` gives the digits, in little-endian order,
of a natural number `n` in a specified base `b`.
In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`.
* For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`,
and the last digit is not zero.
This uniquely specifies the behaviour of `digits b`.
* For `b = 1`, we define `digits 1 n = List.replicate n 1`.
* For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`.
Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals.
In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`.
-/
def digits : ℕ → ℕ → List ℕ
| 0 => digitsAux0
| 1 => digitsAux1
| b + 2 => digitsAux (b + 2) (by norm_num)
@[simp]
theorem digits_zero (b : ℕ) : digits b 0 = [] := by
rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1]
theorem digits_zero_zero : digits 0 0 = [] :=
rfl
@[simp]
theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] :=
rfl
theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n]
| 0, h => (h rfl).elim
| _ + 1, _ => rfl
@[simp]
theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 :=
rfl
-- no `@[simp]`: dsimp can prove this
theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n :=
rfl
theorem digits_add_two_add_one (b n : ℕ) :
digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by
simp [digits, digitsAux_def]
@[simp]
lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) :
Nat.digits b n = n % b :: Nat.digits b (n / b) := by
rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one]
theorem digits_def' :
∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b)
| 0, h => absurd h (by decide)
| 1, h => absurd h (by decide)
| b + 2, _ => digitsAux_def _ (by simp) _
@[simp]
theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by
rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩
rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩
rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb]
theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) :
digits b (x + b * y) = x :: digits b y := by
rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩
cases y
· simp [hxb, hxy.resolve_right (absurd rfl)]
dsimp [digits]
rw [digitsAux_def]
· congr
· simp [Nat.add_mod, mod_eq_of_lt hxb]
· simp [add_mul_div_left, div_eq_of_lt hxb]
· apply Nat.succ_pos
-- If we had a function converting a list into a polynomial,
-- and appropriate lemmas about that function,
-- we could rewrite this in terms of that.
/-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them
as a number in semiring, as the little-endian digits in base `b`.
-/
def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α
| [] => 0
| h :: t => h + b * ofDigits b t
theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) :
ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by
induction' L with d L ih
· rfl
· dsimp [ofDigits]
rw [ih]
theorem ofDigits_eq_sum_mapIdx_aux (b : ℕ) (l : List ℕ) :
(l.zipWith ((fun a i : ℕ => a * b ^ (i + 1))) (List.range l.length)).sum =
b * (l.zipWith (fun a i => a * b ^ i) (List.range l.length)).sum := by
suffices
l.zipWith (fun a i : ℕ => a * b ^ (i + 1)) (List.range l.length) =
l.zipWith (fun a i=> b * (a * b ^ i)) (List.range l.length)
by simp [this]
congr; ext; simp [pow_succ]; ring
theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) :
ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by
rw [List.mapIdx_eq_zipIdx_map, List.zipIdx_eq_zip_range', List.map_zip_eq_zipWith,
ofDigits_eq_foldr, ← List.range_eq_range']
induction' L with hd tl hl
· simp
· simpa [List.range_succ_eq_map, List.zipWith_map_right, ofDigits_eq_sum_mapIdx_aux] using
Or.inl hl
@[simp]
theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl
@[simp]
theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits]
@[simp]
theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) :
ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits]
theorem ofDigits_cons {b hd} {tl : List ℕ} :
ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl
theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} :
ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by
induction' l1 with hd tl IH
· simp [ofDigits]
· rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ']
ring
@[norm_cast]
theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) :
((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by
induction' L with d L ih
· simp [ofDigits]
· dsimp [ofDigits]; push_cast; rw [ih]
@[norm_cast]
theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by
induction' L with d L _
· rfl
· dsimp [ofDigits]; push_cast; simp only
theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) :
∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0
| _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0
| _ :: _, h0, _, List.Mem.tail _ hL =>
digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL
theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b)
(w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by
induction' L with d L ih
· dsimp [ofDigits]
simp
· dsimp [ofDigits]
replace w₂ := w₂ (by simp)
rw [digits_add b h]
· rw [ih]
· intro l m
apply w₁
exact List.mem_cons_of_mem _ m
· intro h
rw [List.getLast_cons h] at w₂
convert w₂
· exact w₁ d List.mem_cons_self
· by_cases h' : L = []
· rcases h' with rfl
left
simpa using w₂
· right
contrapose! w₂
refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_
rw [List.getLast_cons h']
exact List.getLast_mem h'
theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by
rcases b with - | b
· rcases n with - | n
· rfl
· simp
· rcases b with - | b
· induction' n with n ih
· rfl
· rw [Nat.zero_add] at ih ⊢
simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ]
· induction n using Nat.strongRecOn with | ind n h => ?_
cases n
· rw [digits_zero]
rfl
· simp only [Nat.succ_eq_add_one, digits_add_two_add_one]
dsimp [ofDigits]
rw [h _ (Nat.div_lt_self' _ b)]
rw [Nat.mod_add_div]
theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by
induction L with
| nil => rfl
| cons _ _ ih => simp [ofDigits, List.sum_cons, ih]
/-!
### Properties
This section contains various lemmas of properties relating to `digits` and `ofDigits`.
-/
theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by
constructor
· intro h
have : ofDigits b (digits b n) = ofDigits b [] := by rw [h]
convert this
rw [ofDigits_digits]
· rintro rfl
simp
theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 :=
not_congr digits_eq_nil_iff_eq_zero
theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) :
digits b n = (n % b) :: digits b (n / b) := by
rcases b with (_ | _ | b)
· rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero]
· norm_num at h
rcases n with (_ | n)
· norm_num at w
· simp only [digits_add_two_add_one, ne_eq]
theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) :
(digits b m).getLast p = (digits b (m / b)).getLast q := by
by_cases hm : m = 0
· simp [hm]
simp only [digits_eq_cons_digits_div h hm]
rw [List.getLast_cons]
theorem digits.injective (b : ℕ) : Function.Injective b.digits :=
Function.LeftInverse.injective (ofDigits_digits b)
@[simp]
theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m :=
(digits.injective b).eq_iff
theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by
induction' n using Nat.strong_induction_on with n IH
rw [digits_eq_cons_digits_div hb hn, List.length]
by_cases h : n / b = 0
· simp [IH, h]
aesop
· have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb
rw [IH _ this h, log_div_base, tsub_add_cancel_of_le]
refine Nat.succ_le_of_lt (log_pos hb ?_)
contrapose! h
exact div_eq_of_lt h
theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) :
(digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by
rcases b with (_ | _ | b)
· cases m
· cases hm rfl
· simp
· cases m
· cases hm rfl
rename ℕ => m
simp only [zero_add, digits_one, List.getLast_replicate_succ m 1]
exact Nat.one_ne_zero
revert hm
induction m using Nat.strongRecOn with | ind n IH => ?_
intro hn
by_cases hnb : n < b + 2
· simpa only [digits_of_lt (b + 2) n hn hnb]
· rw [digits_getLast n (le_add_left 2 b)]
refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_
rw [← pos_iff_ne_zero]
exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b))
theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} :
n * ofDigits b l = ofDigits b (l.map (n * ·)) := by
induction l with
| nil => rfl
| cons hd tl ih =>
rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih]
ring
lemma ofDigits_inj_of_len_eq {b : ℕ} (hb : 1 < b) {L1 L2 : List ℕ}
(len : L1.length = L2.length) (w1 : ∀ l ∈ L1, l < b) (w2 : ∀ l ∈ L2, l < b)
(h : ofDigits b L1 = ofDigits b L2) : L1 = L2 := by
induction' L1 with D L ih generalizing L2
· simp only [List.length_nil] at len
exact (List.length_eq_zero_iff.mp len.symm).symm
obtain ⟨d, l, rfl⟩ := List.exists_cons_of_length_eq_add_one len.symm
simp only [List.length_cons, add_left_inj] at len
simp only [ofDigits_cons] at h
have eqd : D = d := by
have H : (D + b * ofDigits b L) % b = (d + b * ofDigits b l) % b := by rw [h]
simpa [mod_eq_of_lt (w2 d List.mem_cons_self),
mod_eq_of_lt (w1 D List.mem_cons_self)] using H
simp only [eqd, add_right_inj, mul_left_cancel_iff_of_pos (zero_lt_of_lt hb)] at h
have := ih len (fun a ha ↦ w1 a <| List.mem_cons_of_mem D ha)
(fun a ha ↦ w2 a <| List.mem_cons_of_mem d ha) h
rw [eqd, this]
/-- The addition of ofDigits of two lists is equal to ofDigits of digit-wise addition of them -/
theorem ofDigits_add_ofDigits_eq_ofDigits_zipWith_of_length_eq {b : ℕ} {l1 l2 : List ℕ}
(h : l1.length = l2.length) :
ofDigits b l1 + ofDigits b l2 = ofDigits b (l1.zipWith (· + ·) l2) := by
induction l1 generalizing l2 with
| nil => simp_all [eq_comm, List.length_eq_zero_iff, ofDigits]
| cons hd₁ tl₁ ih₁ =>
induction l2 generalizing tl₁ with
| nil => simp_all
| cons hd₂ tl₂ ih₂ =>
simp_all only [List.length_cons, succ_eq_add_one, ofDigits_cons, add_left_inj,
eq_comm, List.zipWith_cons_cons, add_eq]
rw [← ih₁ h.symm, mul_add]
ac_rfl
/-- The digits in the base b+2 expansion of n are all less than b+2 -/
theorem digits_lt_base' {b m : ℕ} : ∀ {d}, d ∈ digits (b + 2) m → d < b + 2 := by
induction m using Nat.strongRecOn with | ind n IH => ?_
intro d hd
rcases n with - | n
· rw [digits_zero] at hd
cases hd
-- base b+2 expansion of 0 has no digits
rw [digits_add_two_add_one] at hd
cases hd
· exact n.succ.mod_lt (by linarith)
· apply IH ((n + 1) / (b + 2))
| · apply Nat.div_lt_self <;> omega
· assumption
/-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/
theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by
rcases b with (_ | _ | b) <;> try simp_all
exact digits_lt_base' hd
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
ofDigits (b + 2) l < (b + 2) ^ l.length := by
induction' l with hd tl IH
· simp [ofDigits]
| Mathlib/Data/Nat/Digits.lean | 388 | 400 |
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.NumberTheory.Cyclotomic.PrimitiveRoots
import Mathlib.FieldTheory.Finite.Trace
import Mathlib.Algebra.Group.AddChar
import Mathlib.Data.ZMod.Units
import Mathlib.Analysis.Complex.Polynomial.Basic
/-!
# Additive characters of finite rings and fields
This file collects some results on additive characters whose domain is (the additive group of)
a finite ring or field.
## Main definitions and results
We define an additive character `ψ` to be *primitive* if `mulShift ψ a` is trivial only when
`a = 0`.
We show that when `ψ` is primitive, then the map `a ↦ mulShift ψ a` is injective
(`AddChar.to_mulShift_inj_of_isPrimitive`) and that `ψ` is primitive when `R` is a field
and `ψ` is nontrivial (`AddChar.IsNontrivial.isPrimitive`).
We also show that there are primitive additive characters on `R` (with suitable
target `R'`) when `R` is a field or `R = ZMod n` (`AddChar.primitiveCharFiniteField`
and `AddChar.primitiveZModChar`).
Finally, we show that the sum of all character values is zero when the character
is nontrivial (and the target is a domain); see `AddChar.sum_eq_zero_of_isNontrivial`.
## Tags
additive character
-/
universe u v
namespace AddChar
section Additive
-- The domain and target of our additive characters. Now we restrict to a ring in the domain.
variable {R : Type u} [CommRing R] {R' : Type v} [CommMonoid R']
/-- The values of an additive character on a ring of positive characteristic are roots of unity. -/
lemma val_mem_rootsOfUnity (φ : AddChar R R') (a : R) (h : 0 < ringChar R) :
(φ.val_isUnit a).unit ∈ rootsOfUnity (ringChar R).toPNat' R' := by
simp only [mem_rootsOfUnity', IsUnit.unit_spec, Nat.toPNat'_coe, h, ↓reduceIte,
← map_nsmul_eq_pow, nsmul_eq_mul, CharP.cast_eq_zero, zero_mul, map_zero_eq_one]
/-- An additive character is *primitive* iff all its multiplicative shifts by nonzero
elements are nontrivial. -/
def IsPrimitive (ψ : AddChar R R') : Prop := ∀ ⦃a : R⦄, a ≠ 0 → mulShift ψ a ≠ 1
/-- The composition of a primitive additive character with an injective mooid homomorphism
is also primitive. -/
lemma IsPrimitive.compMulHom_of_isPrimitive {R'' : Type*} [CommMonoid R''] {φ : AddChar R R'}
{f : R' →* R''} (hφ : φ.IsPrimitive) (hf : Function.Injective f) :
(f.compAddChar φ).IsPrimitive := fun a ha ↦ by
simpa [DFunLike.ext_iff] using (MonoidHom.compAddChar_injective_right f hf).ne (hφ ha)
/-- The map associating to `a : R` the multiplicative shift of `ψ` by `a`
is injective when `ψ` is primitive. -/
theorem to_mulShift_inj_of_isPrimitive {ψ : AddChar R R'} (hψ : IsPrimitive ψ) :
Function.Injective ψ.mulShift := by
intro a b h
apply_fun fun x => x * mulShift ψ (-b) at h
simp only [mulShift_mul, mulShift_zero, add_neg_cancel, mulShift_apply] at h
simpa [← sub_eq_add_neg, sub_eq_zero] using (hψ · h)
-- `AddCommGroup.equiv_direct_sum_zmod_of_fintype`
-- gives the structure theorem for finite abelian groups.
-- This could be used to show that the map above is a bijection.
-- We leave this for a later occasion.
/-- When `R` is a field `F`, then a nontrivial additive character is primitive -/
theorem IsPrimitive.of_ne_one {F : Type u} [Field F] {ψ : AddChar F R'} (hψ : ψ ≠ 1) :
IsPrimitive ψ :=
fun a ha h ↦ hψ <| by simpa [mulShift_mulShift, ha] using congr_arg (mulShift · a⁻¹) h
/-- If `r` is not a unit, then `e.mulShift r` is not primitive. -/
lemma not_isPrimitive_mulShift [Finite R] (e : AddChar R R') {r : R}
(hr : ¬ IsUnit r) : ¬ IsPrimitive (e.mulShift r) := by
simp only [IsPrimitive, not_forall]
simp only [isUnit_iff_mem_nonZeroDivisors_of_finite, mem_nonZeroDivisors_iff, not_forall] at hr
rcases hr with ⟨x, h, h'⟩
exact ⟨x, h', by simp only [mulShift_mulShift, mul_comm r, h, mulShift_zero, not_ne_iff]⟩
/-- Definition for a primitive additive character on a finite ring `R` into a cyclotomic extension
of a field `R'`. It records which cyclotomic extension it is, the character, and the
fact that the character is primitive. -/
structure PrimitiveAddChar (R : Type u) [CommRing R] (R' : Type v) [Field R'] where
/-- The first projection from `PrimitiveAddChar`, giving the cyclotomic field. -/
n : ℕ+
/-- The second projection from `PrimitiveAddChar`, giving the character. -/
char : AddChar R (CyclotomicField n R')
/-- The third projection from `PrimitiveAddChar`, showing that `χ.char` is primitive. -/
prim : IsPrimitive char
/-!
### Additive characters on `ZMod n`
-/
section ZMod
variable {N : ℕ} [NeZero N] {R : Type*} [CommRing R] (e : AddChar (ZMod N) R)
/-- If `e` is not primitive, then `e.mulShift d = 1` for some proper divisor `d` of `N`. -/
lemma exists_divisor_of_not_isPrimitive (he : ¬e.IsPrimitive) :
∃ d : ℕ, d ∣ N ∧ d < N ∧ e.mulShift d = 1 := by
simp_rw [IsPrimitive, not_forall, not_ne_iff] at he
rcases he with ⟨b, hb_ne, hb⟩
-- We have `AddChar.mulShift e b = 1`, but `b ≠ 0`.
obtain ⟨d, hd, u, hu, rfl⟩ := b.eq_unit_mul_divisor
refine ⟨d, hd, lt_of_le_of_ne (Nat.le_of_dvd (NeZero.pos _) hd) ?_, ?_⟩
· exact fun h ↦ by simp only [h, ZMod.natCast_self, mul_zero, ne_eq, not_true_eq_false] at hb_ne
· rw [← mulShift_unit_eq_one_iff _ hu, ← hb, mul_comm]
ext1 y
rw [mulShift_apply, mulShift_apply, mulShift_apply, mul_assoc]
end ZMod
section ZModChar
variable {C : Type v} [CommMonoid C]
section ZModCharDef
/-- We can define an additive character on `ZMod n` when we have an `n`th root of unity `ζ : C`. -/
def zmodChar (n : ℕ) [NeZero n] {ζ : C} (hζ : ζ ^ n = 1) : AddChar (ZMod n) C where
toFun a := ζ ^ a.val
map_zero_eq_one' := by simp only [ZMod.val_zero, pow_zero]
map_add_eq_mul' x y := by simp only [ZMod.val_add, ← pow_eq_pow_mod _ hζ, ← pow_add]
/-- The additive character on `ZMod n` defined using `ζ` sends `a` to `ζ^a`. -/
theorem zmodChar_apply {n : ℕ} [NeZero n] {ζ : C} (hζ : ζ ^ n = 1) (a : ZMod n) :
zmodChar n hζ a = ζ ^ a.val :=
rfl
theorem zmodChar_apply' {n : ℕ} [NeZero n] {ζ : C} (hζ : ζ ^ n = 1) (a : ℕ) :
zmodChar n hζ a = ζ ^ a := by
rw [pow_eq_pow_mod a hζ, zmodChar_apply, ZMod.val_natCast]
end ZModCharDef
/-- An additive character on `ZMod n` is nontrivial iff it takes a value `≠ 1` on `1`. -/
theorem zmod_char_ne_one_iff (n : ℕ) [NeZero n] (ψ : AddChar (ZMod n) C) : ψ ≠ 1 ↔ ψ 1 ≠ 1 := by
rw [ne_one_iff]
refine ⟨?_, fun h => ⟨_, h⟩⟩
contrapose!
rintro h₁ a
have ha₁ : a = a.val • (1 : ZMod ↑n) := by
rw [nsmul_eq_mul, mul_one]; exact (ZMod.natCast_zmod_val a).symm
rw [ha₁, map_nsmul_eq_pow, h₁, one_pow]
/-- A primitive additive character on `ZMod n` takes the value `1` only at `0`. -/
theorem IsPrimitive.zmod_char_eq_one_iff (n : ℕ) [NeZero n]
{ψ : AddChar (ZMod n) C} (hψ : IsPrimitive ψ) (a : ZMod n) :
ψ a = 1 ↔ a = 0 := by
refine ⟨fun h => not_imp_comm.mp (@hψ a) ?_, fun ha => by rw [ha, map_zero_eq_one]⟩
rw [zmod_char_ne_one_iff n (mulShift ψ a), mulShift_apply, mul_one, h, Classical.not_not]
/-- The converse: if the additive character takes the value `1` only at `0`,
then it is primitive. -/
theorem zmod_char_primitive_of_eq_one_only_at_zero (n : ℕ) (ψ : AddChar (ZMod n) C)
(hψ : ∀ a, ψ a = 1 → a = 0) : IsPrimitive ψ := by
refine fun a ha hf => ?_
have h : mulShift ψ a 1 = (1 : AddChar (ZMod n) C) (1 : ZMod n) :=
congr_fun (congr_arg (↑) hf) 1
rw [mulShift_apply, mul_one] at h; norm_cast at h
exact ha (hψ a h)
/-- The additive character on `ZMod n` associated to a primitive `n`th root of unity
is primitive -/
theorem zmodChar_primitive_of_primitive_root (n : ℕ) [NeZero n] {ζ : C} (h : IsPrimitiveRoot ζ n) :
IsPrimitive (zmodChar n ((IsPrimitiveRoot.iff_def ζ n).mp h).left) := by
apply zmod_char_primitive_of_eq_one_only_at_zero
intro a ha
rw [zmodChar_apply, ← pow_zero ζ] at ha
exact (ZMod.val_eq_zero a).mp (IsPrimitiveRoot.pow_inj h (ZMod.val_lt a) (NeZero.pos _) ha)
/-- There is a primitive additive character on `ZMod n` if the characteristic of the target
does not divide `n` -/
noncomputable def primitiveZModChar (n : ℕ+) (F' : Type v) [Field F'] (h : (n : F') ≠ 0) :
PrimitiveAddChar (ZMod n) F' :=
have : NeZero (n : F') := ⟨h⟩
⟨n, zmodChar n (IsCyclotomicExtension.zeta_pow n F' _),
zmodChar_primitive_of_primitive_root n (IsCyclotomicExtension.zeta_spec n F' _)⟩
end ZModChar
end Additive
/-!
### Existence of a primitive additive character on a finite field
-/
/-- There is a primitive additive character on the finite field `F` if the characteristic
of the target is different from that of `F`.
We obtain it as the composition of the trace from `F` to `ZMod p` with a primitive
additive character on `ZMod p`, where `p` is the characteristic of `F`. -/
noncomputable def FiniteField.primitiveChar (F F' : Type*) [Field F] [Finite F] [Field F']
(h : ringChar F' ≠ ringChar F) : PrimitiveAddChar F F' := by
let p := ringChar F
haveI hp : Fact p.Prime := ⟨CharP.char_is_prime F _⟩
let pp := p.toPNat hp.1.pos
have hp₂ : ¬ringChar F' ∣ p := by
rcases CharP.char_is_prime_or_zero F' (ringChar F') with hq | hq
· exact mt (Nat.Prime.dvd_iff_eq hp.1 (Nat.Prime.ne_one hq)).mp h.symm
· rw [hq]
exact fun hf => Nat.Prime.ne_zero hp.1 (zero_dvd_iff.mp hf)
let ψ := primitiveZModChar pp F' (neZero_iff.mp (NeZero.of_not_dvd F' hp₂))
letI : Algebra (ZMod p) F := ZMod.algebra _ _
let ψ' := ψ.char.compAddMonoidHom (Algebra.trace (ZMod p) F).toAddMonoidHom
have hψ' : ψ' ≠ 1 := by
obtain ⟨a, ha⟩ := FiniteField.trace_to_zmod_nondegenerate F one_ne_zero
rw [one_mul] at ha
exact ne_one_iff.2
⟨a, fun hf => ha <| (ψ.prim.zmod_char_eq_one_iff pp <| Algebra.trace (ZMod p) F a).mp hf⟩
exact ⟨ψ.n, ψ', IsPrimitive.of_ne_one hψ'⟩
/-!
### The sum of all character values
-/
section sum
variable {R : Type*} [AddGroup R] [Fintype R] {R' : Type*} [CommRing R']
/-- The sum over the values of a nontrivial additive character vanishes if the target ring
is a domain. -/
theorem sum_eq_zero_of_ne_one [IsDomain R'] {ψ : AddChar R R'} (hψ : ψ ≠ 1) : ∑ a, ψ a = 0 := by
rcases ne_one_iff.1 hψ with ⟨b, hb⟩
have h₁ : ∑ a : R, ψ (b + a) = ∑ a : R, ψ a :=
Fintype.sum_bijective _ (AddGroup.addLeft_bijective b) _ _ fun x => rfl
simp_rw [map_add_eq_mul] at h₁
have h₂ : ∑ a : R, ψ a = Finset.univ.sum ↑ψ := rfl
rw [← Finset.mul_sum, h₂] at h₁
exact eq_zero_of_mul_eq_self_left hb h₁
/-- The sum over the values of the trivial additive character is the cardinality of the source. -/
theorem sum_eq_card_of_eq_one {ψ : AddChar R R'} (hψ : ψ = 1) :
∑ a, ψ a = Fintype.card R := by simp [hψ]
end sum
/-- The sum over the values of `mulShift ψ b` for `ψ` primitive is zero when `b ≠ 0`
and `#R` otherwise. -/
theorem sum_mulShift {R : Type*} [CommRing R] [Fintype R] [DecidableEq R]
{R' : Type*} [CommRing R'] [IsDomain R'] {ψ : AddChar R R'} (b : R)
(hψ : IsPrimitive ψ) : ∑ x : R, ψ (x * b) = if b = 0 then Fintype.card R else 0 := by
split_ifs with h
· -- case `b = 0`
simp only [h, mul_zero, map_zero_eq_one, Finset.sum_const, Nat.smul_one_eq_cast]
rfl
· -- case `b ≠ 0`
simp_rw [mul_comm]
exact mod_cast sum_eq_zero_of_ne_one (hψ h)
/-!
### Complex-valued additive characters
-/
section Ring
variable {R : Type*} [CommRing R]
/-- Post-composing an additive character to `ℂ` with complex conjugation gives the inverse
character. -/
lemma starComp_eq_inv (hR : 0 < ringChar R) {φ : AddChar R ℂ} :
(starRingEnd ℂ).compAddChar φ = φ⁻¹ := by
ext1 a
simp only [RingHom.toMonoidHom_eq_coe, MonoidHom.coe_compAddChar, MonoidHom.coe_coe,
Function.comp_apply, inv_apply']
have H := Complex.norm_eq_one_of_mem_rootsOfUnity <| φ.val_mem_rootsOfUnity a hR
exact (Complex.inv_eq_conj H).symm
lemma starComp_apply (hR : 0 < ringChar R) {φ : AddChar R ℂ} (a : R) :
(starRingEnd ℂ) (φ a) = φ⁻¹ a := by
rw [← starComp_eq_inv hR]
rfl
end Ring
section Field
variable (F : Type*) [Field F] [Finite F]
private lemma ringChar_ne : ringChar ℂ ≠ ringChar F := by
simpa only [ringChar.eq_zero] using (CharP.ringChar_ne_zero_of_finite F).symm
/-- A primitive additive character on the finite field `F` with values in `ℂ`. -/
noncomputable def FiniteField.primitiveChar_to_Complex : AddChar F ℂ := by
refine MonoidHom.compAddChar ?_ (primitiveChar F ℂ <| ringChar_ne F).char
exact (IsCyclotomicExtension.algEquiv ?n ℂ (CyclotomicField ?n ℂ) ℂ : CyclotomicField ?n ℂ →* ℂ)
lemma FiniteField.primitiveChar_to_Complex_isPrimitive :
(primitiveChar_to_Complex F).IsPrimitive := by
refine IsPrimitive.compMulHom_of_isPrimitive (PrimitiveAddChar.prim _) ?_
let nn := (primitiveChar F ℂ <| ringChar_ne F).n
exact (IsCyclotomicExtension.algEquiv nn ℂ (CyclotomicField nn ℂ) ℂ).injective
end Field
|
end AddChar
| Mathlib/NumberTheory/LegendreSymbol/AddCharacter.lean | 308 | 311 |
/-
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.Analysis.Complex.Basic
import Mathlib.Topology.FiberBundle.IsHomeomorphicTrivialBundle
/-!
# Closure, interior, and frontier of preimages under `re` and `im`
In this fact we use the fact that `ℂ` is naturally homeomorphic to `ℝ × ℝ` to deduce some
topological properties of `Complex.re` and `Complex.im`.
## Main statements
Each statement about `Complex.re` listed below has a counterpart about `Complex.im`.
* `Complex.isHomeomorphicTrivialFiberBundle_re`: `Complex.re` turns `ℂ` into a trivial
topological fiber bundle over `ℝ`;
* `Complex.isOpenMap_re`, `Complex.isQuotientMap_re`: in particular, `Complex.re` is an open map
and is a quotient map;
* `Complex.interior_preimage_re`, `Complex.closure_preimage_re`, `Complex.frontier_preimage_re`:
formulas for `interior (Complex.re ⁻¹' s)` etc;
* `Complex.interior_setOf_re_le` etc: particular cases of the above formulas in the cases when `s`
is one of the infinite intervals `Set.Ioi a`, `Set.Ici a`, `Set.Iio a`, and `Set.Iic a`,
formulated as `interior {z : ℂ | z.re ≤ a} = {z | z.re < a}` etc.
## Tags
complex, real part, imaginary part, closure, interior, frontier
-/
open Set Topology
noncomputable section
namespace Complex
/-- `Complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/
theorem isHomeomorphicTrivialFiberBundle_re : IsHomeomorphicTrivialFiberBundle ℝ re :=
⟨equivRealProdCLM.toHomeomorph, fun _ => rfl⟩
/-- `Complex.im` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/
theorem isHomeomorphicTrivialFiberBundle_im : IsHomeomorphicTrivialFiberBundle ℝ im :=
⟨equivRealProdCLM.toHomeomorph.trans (Homeomorph.prodComm ℝ ℝ), fun _ => rfl⟩
theorem isOpenMap_re : IsOpenMap re :=
isHomeomorphicTrivialFiberBundle_re.isOpenMap_proj
theorem isOpenMap_im : IsOpenMap im :=
isHomeomorphicTrivialFiberBundle_im.isOpenMap_proj
theorem isQuotientMap_re : IsQuotientMap re :=
isHomeomorphicTrivialFiberBundle_re.isQuotientMap_proj
@[deprecated (since := "2024-10-22")]
alias quotientMap_re := isQuotientMap_re
theorem isQuotientMap_im : IsQuotientMap im :=
isHomeomorphicTrivialFiberBundle_im.isQuotientMap_proj
@[deprecated (since := "2024-10-22")]
alias quotientMap_im := isQuotientMap_im
theorem interior_preimage_re (s : Set ℝ) : interior (re ⁻¹' s) = re ⁻¹' interior s :=
(isOpenMap_re.preimage_interior_eq_interior_preimage continuous_re _).symm
theorem interior_preimage_im (s : Set ℝ) : interior (im ⁻¹' s) = im ⁻¹' interior s :=
(isOpenMap_im.preimage_interior_eq_interior_preimage continuous_im _).symm
theorem closure_preimage_re (s : Set ℝ) : closure (re ⁻¹' s) = re ⁻¹' closure s :=
(isOpenMap_re.preimage_closure_eq_closure_preimage continuous_re _).symm
theorem closure_preimage_im (s : Set ℝ) : closure (im ⁻¹' s) = im ⁻¹' closure s :=
(isOpenMap_im.preimage_closure_eq_closure_preimage continuous_im _).symm
theorem frontier_preimage_re (s : Set ℝ) : frontier (re ⁻¹' s) = re ⁻¹' frontier s :=
(isOpenMap_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm
theorem frontier_preimage_im (s : Set ℝ) : frontier (im ⁻¹' s) = im ⁻¹' frontier s :=
(isOpenMap_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm
@[simp]
theorem interior_setOf_re_le (a : ℝ) : interior { z : ℂ | z.re ≤ a } = { z | z.re < a } := by
simpa only [interior_Iic] using interior_preimage_re (Iic a)
@[simp]
theorem interior_setOf_im_le (a : ℝ) : interior { z : ℂ | z.im ≤ a } = { z | z.im < a } := by
simpa only [interior_Iic] using interior_preimage_im (Iic a)
@[simp]
theorem interior_setOf_le_re (a : ℝ) : interior { z : ℂ | a ≤ z.re } = { z | a < z.re } := by
simpa only [interior_Ici] using interior_preimage_re (Ici a)
@[simp]
theorem interior_setOf_le_im (a : ℝ) : interior { z : ℂ | a ≤ z.im } = { z | a < z.im } := by
simpa only [interior_Ici] using interior_preimage_im (Ici a)
@[simp]
theorem closure_setOf_re_lt (a : ℝ) : closure { z : ℂ | z.re < a } = { z | z.re ≤ a } := by
simpa only [closure_Iio] using closure_preimage_re (Iio a)
@[simp]
theorem closure_setOf_im_lt (a : ℝ) : closure { z : ℂ | z.im < a } = { z | z.im ≤ a } := by
simpa only [closure_Iio] using closure_preimage_im (Iio a)
@[simp]
| theorem closure_setOf_lt_re (a : ℝ) : closure { z : ℂ | a < z.re } = { z | a ≤ z.re } := by
simpa only [closure_Ioi] using closure_preimage_re (Ioi a)
| Mathlib/Analysis/Complex/ReImTopology.lean | 109 | 110 |
/-
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
-/
import Mathlib.Analysis.Complex.Asymptotics
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Data.Complex.Trigonometric
/-!
# Complex and real exponential
In this file we prove continuity of `Complex.exp` and `Real.exp`. We also prove a few facts about
limits of `Real.exp` at infinity.
## Tags
exp
-/
noncomputable section
open Asymptotics Bornology Finset Filter Function Metric Set Topology
open scoped Nat
namespace Complex
variable {z y x : ℝ}
theorem exp_bound_sq (x z : ℂ) (hz : ‖z‖ ≤ 1) :
‖exp (x + z) - exp x - z • exp x‖ ≤ ‖exp x‖ * ‖z‖ ^ 2 :=
calc
‖exp (x + z) - exp x - z * exp x‖ = ‖exp x * (exp z - 1 - z)‖ := by
congr
rw [exp_add]
ring
_ = ‖exp x‖ * ‖exp z - 1 - z‖ := norm_mul _ _
_ ≤ ‖exp x‖ * ‖z‖ ^ 2 :=
mul_le_mul_of_nonneg_left (norm_exp_sub_one_sub_id_le hz) (norm_nonneg _)
theorem locally_lipschitz_exp {r : ℝ} (hr_nonneg : 0 ≤ r) (hr_le : r ≤ 1) (x y : ℂ)
(hyx : ‖y - x‖ < r) : ‖exp y - exp x‖ ≤ (1 + r) * ‖exp x‖ * ‖y - x‖ := by
have hy_eq : y = x + (y - x) := by abel
have hyx_sq_le : ‖y - x‖ ^ 2 ≤ r * ‖y - x‖ := by
rw [pow_two]
exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg
have h_sq : ∀ z, ‖z‖ ≤ 1 → ‖exp (x + z) - exp x‖ ≤ ‖z‖ * ‖exp x‖ + ‖exp x‖ * ‖z‖ ^ 2 := by
intro z hz
have : ‖exp (x + z) - exp x - z • exp x‖ ≤ ‖exp x‖ * ‖z‖ ^ 2 := exp_bound_sq x z hz
rw [← sub_le_iff_le_add', ← norm_smul z]
exact (norm_sub_norm_le _ _).trans this
calc
‖exp y - exp x‖ = ‖exp (x + (y - x)) - exp x‖ := by nth_rw 1 [hy_eq]
_ ≤ ‖y - x‖ * ‖exp x‖ + ‖exp x‖ * ‖y - x‖ ^ 2 := h_sq (y - x) (hyx.le.trans hr_le)
_ ≤ ‖y - x‖ * ‖exp x‖ + ‖exp x‖ * (r * ‖y - x‖) :=
(add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _)
_ = (1 + r) * ‖exp x‖ * ‖y - x‖ := by ring
-- Porting note: proof by term mode `locally_lipschitz_exp zero_le_one le_rfl x`
-- doesn't work because `‖y - x‖` and `dist y x` don't unify
@[continuity]
theorem continuous_exp : Continuous exp :=
continuous_iff_continuousAt.mpr fun x =>
continuousAt_of_locally_lipschitz zero_lt_one (2 * ‖exp x‖)
(fun y ↦ by
convert locally_lipschitz_exp zero_le_one le_rfl x y using 2
congr
ring)
theorem continuousOn_exp {s : Set ℂ} : ContinuousOn exp s :=
continuous_exp.continuousOn
lemma exp_sub_sum_range_isBigO_pow (n : ℕ) :
(fun x ↦ exp x - ∑ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (· ^ n) := by
rcases (zero_le n).eq_or_lt with rfl | hn
· simpa using continuous_exp.continuousAt.norm.isBoundedUnder_le
· refine .of_bound (n.succ / (n ! * n)) ?_
rw [NormedAddCommGroup.nhds_zero_basis_norm_lt.eventually_iff]
refine ⟨1, one_pos, fun x hx ↦ ?_⟩
convert exp_bound hx.out.le hn using 1
field_simp [mul_comm]
lemma exp_sub_sum_range_succ_isLittleO_pow (n : ℕ) :
(fun x ↦ exp x - ∑ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (· ^ n) :=
(exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self
end Complex
section ComplexContinuousExpComp
variable {α : Type*}
open Complex
theorem Filter.Tendsto.cexp {l : Filter α} {f : α → ℂ} {z : ℂ} (hf : Tendsto f l (𝓝 z)) :
Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) :=
(continuous_exp.tendsto _).comp hf
variable [TopologicalSpace α] {f : α → ℂ} {s : Set α} {x : α}
nonrec
theorem ContinuousWithinAt.cexp (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (fun y => exp (f y)) s x :=
h.cexp
@[fun_prop]
nonrec
theorem ContinuousAt.cexp (h : ContinuousAt f x) : ContinuousAt (fun y => exp (f y)) x :=
h.cexp
@[fun_prop]
theorem ContinuousOn.cexp (h : ContinuousOn f s) : ContinuousOn (fun y => exp (f y)) s :=
fun x hx => (h x hx).cexp
@[fun_prop]
theorem Continuous.cexp (h : Continuous f) : Continuous fun y => exp (f y) :=
continuous_iff_continuousAt.2 fun _ => h.continuousAt.cexp
/-- The complex exponential function is uniformly continuous on left half planes. -/
lemma UniformContinuousOn.cexp (a : ℝ) : UniformContinuousOn exp {x : ℂ | x.re ≤ a} := by
have : Continuous (cexp - 1) := Continuous.sub (Continuous.cexp continuous_id') continuous_one
rw [Metric.uniformContinuousOn_iff, Metric.continuous_iff'] at *
intro ε hε
simp only [gt_iff_lt, Pi.sub_apply, Pi.one_apply, dist_sub_eq_dist_add_right,
sub_add_cancel] at this
have ha : 0 < ε / (2 * Real.exp a) := by positivity
have H := this 0 (ε / (2 * Real.exp a)) ha
rw [Metric.eventually_nhds_iff] at H
obtain ⟨δ, hδ⟩ := H
refine ⟨δ, hδ.1, ?_⟩
intros x _ y hy hxy
have h3 := hδ.2 (y := x - y) (by simpa only [dist_zero_right] using hxy)
rw [dist_eq_norm, exp_zero] at *
have : cexp x - cexp y = cexp y * (cexp (x - y) - 1) := by
rw [mul_sub_one, ← exp_add]
ring_nf
rw [this, mul_comm]
have hya : ‖cexp y‖ ≤ Real.exp a := by
simp only [norm_exp, Real.exp_le_exp]
exact hy
simp only [gt_iff_lt, dist_zero_right, Set.mem_setOf_eq, norm_mul, Complex.norm_exp] at *
apply lt_of_le_of_lt (mul_le_mul h3.le hya (Real.exp_nonneg y.re) (le_of_lt ha))
have hrr : ε / (2 * a.exp) * a.exp = ε / 2 := by
nth_rw 2 [mul_comm]
field_simp [mul_assoc]
rw [hrr]
exact div_two_lt_of_pos hε
@[deprecated (since := "2025-02-11")] alias UniformlyContinuousOn.cexp := UniformContinuousOn.cexp
end ComplexContinuousExpComp
namespace Real
@[continuity]
theorem continuous_exp : Continuous exp :=
Complex.continuous_re.comp Complex.continuous_ofReal.cexp
theorem continuousOn_exp {s : Set ℝ} : ContinuousOn exp s :=
continuous_exp.continuousOn
lemma exp_sub_sum_range_isBigO_pow (n : ℕ) :
(fun x ↦ exp x - ∑ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (· ^ n) := by
have := (Complex.exp_sub_sum_range_isBigO_pow n).comp_tendsto
(Complex.continuous_ofReal.tendsto' 0 0 rfl)
simp only [Function.comp_def] at this
norm_cast at this
lemma exp_sub_sum_range_succ_isLittleO_pow (n : ℕ) :
(fun x ↦ exp x - ∑ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (· ^ n) :=
(exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self
end Real
section RealContinuousExpComp
variable {α : Type*}
open Real
theorem Filter.Tendsto.rexp {l : Filter α} {f : α → ℝ} {z : ℝ} (hf : Tendsto f l (𝓝 z)) :
Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) :=
(continuous_exp.tendsto _).comp hf
variable [TopologicalSpace α] {f : α → ℝ} {s : Set α} {x : α}
nonrec
theorem ContinuousWithinAt.rexp (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (fun y ↦ exp (f y)) s x :=
h.rexp
@[fun_prop]
nonrec
theorem ContinuousAt.rexp (h : ContinuousAt f x) : ContinuousAt (fun y ↦ exp (f y)) x :=
h.rexp
@[fun_prop]
theorem ContinuousOn.rexp (h : ContinuousOn f s) :
ContinuousOn (fun y ↦ exp (f y)) s :=
fun x hx ↦ (h x hx).rexp
@[fun_prop]
theorem Continuous.rexp (h : Continuous f) : Continuous fun y ↦ exp (f y) :=
continuous_iff_continuousAt.2 fun _ ↦ h.continuousAt.rexp
end RealContinuousExpComp
namespace Real
variable {α : Type*} {x y z : ℝ} {l : Filter α}
theorem exp_half (x : ℝ) : exp (x / 2) = √(exp x) := by
rw [eq_comm, sqrt_eq_iff_eq_sq, sq, ← exp_add, add_halves] <;> exact (exp_pos _).le
/-- The real exponential function tends to `+∞` at `+∞`. -/
theorem tendsto_exp_atTop : Tendsto exp atTop atTop := by
have A : Tendsto (fun x : ℝ => x + 1) atTop atTop :=
tendsto_atTop_add_const_right atTop 1 tendsto_id
have B : ∀ᶠ x in atTop, x + 1 ≤ exp x := eventually_atTop.2 ⟨0, fun x _ => add_one_le_exp x⟩
exact tendsto_atTop_mono' atTop B A
/-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0`
at `+∞` -/
theorem tendsto_exp_neg_atTop_nhds_zero : Tendsto (fun x => exp (-x)) atTop (𝓝 0) :=
(tendsto_inv_atTop_zero.comp tendsto_exp_atTop).congr fun x => (exp_neg x).symm
/-- The real exponential function tends to `1` at `0`. -/
theorem tendsto_exp_nhds_zero_nhds_one : Tendsto exp (𝓝 0) (𝓝 1) := by
convert continuous_exp.tendsto 0
simp
theorem tendsto_exp_atBot : Tendsto exp atBot (𝓝 0) :=
(tendsto_exp_neg_atTop_nhds_zero.comp tendsto_neg_atBot_atTop).congr fun x =>
congr_arg exp <| neg_neg x
theorem tendsto_exp_atBot_nhdsGT : Tendsto exp atBot (𝓝[>] 0) :=
tendsto_inf.2 ⟨tendsto_exp_atBot, tendsto_principal.2 <| Eventually.of_forall exp_pos⟩
@[deprecated (since := "2024-12-22")]
alias tendsto_exp_atBot_nhdsWithin := tendsto_exp_atBot_nhdsGT
@[simp]
theorem isBoundedUnder_ge_exp_comp (l : Filter α) (f : α → ℝ) :
IsBoundedUnder (· ≥ ·) l fun x => exp (f x) :=
isBoundedUnder_of ⟨0, fun _ => (exp_pos _).le⟩
@[simp]
theorem isBoundedUnder_le_exp_comp {f : α → ℝ} :
(IsBoundedUnder (· ≤ ·) l fun x => exp (f x)) ↔ IsBoundedUnder (· ≤ ·) l f :=
exp_monotone.isBoundedUnder_le_comp_iff tendsto_exp_atTop
/-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/
theorem tendsto_exp_div_pow_atTop (n : ℕ) : Tendsto (fun x => exp x / x ^ n) atTop atTop := by
refine (atTop_basis_Ioi.tendsto_iff (atTop_basis' 1)).2 fun C hC₁ => ?_
have hC₀ : 0 < C := zero_lt_one.trans_le hC₁
have : 0 < (exp 1 * C)⁻¹ := inv_pos.2 (mul_pos (exp_pos _) hC₀)
| obtain ⟨N, hN⟩ : ∃ N : ℕ, ∀ k ≥ N, (↑k : ℝ) ^ n / exp 1 ^ k < (exp 1 * C)⁻¹ :=
eventually_atTop.1
((tendsto_pow_const_div_const_pow_of_one_lt n (one_lt_exp_iff.2 zero_lt_one)).eventually
(gt_mem_nhds this))
simp only [← exp_nat_mul, mul_one, div_lt_iff₀, exp_pos, ← div_eq_inv_mul] at hN
refine ⟨N, trivial, fun x hx => ?_⟩
rw [Set.mem_Ioi] at hx
have hx₀ : 0 < x := (Nat.cast_nonneg N).trans_lt hx
rw [Set.mem_Ici, le_div_iff₀ (pow_pos hx₀ _), ← le_div_iff₀' hC₀]
calc
x ^ n ≤ ⌈x⌉₊ ^ n := by gcongr; exact Nat.le_ceil _
_ ≤ exp ⌈x⌉₊ / (exp 1 * C) := mod_cast (hN _ (Nat.lt_ceil.2 hx).le).le
_ ≤ exp (x + 1) / (exp 1 * C) := by gcongr; exact (Nat.ceil_lt_add_one hx₀.le).le
_ = exp x / C := by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne']
/-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/
theorem tendsto_pow_mul_exp_neg_atTop_nhds_zero (n : ℕ) :
Tendsto (fun x => x ^ n * exp (-x)) atTop (𝓝 0) :=
| Mathlib/Analysis/SpecialFunctions/Exp.lean | 254 | 271 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) :
Real.exp x < 1 / (1 - x) := by
have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc
0 < x ^ 3 := by positivity
_ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring
calc
exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three
_ ≤ 1 + x + x ^ 2 := by
-- Porting note: was `norm_num [Finset.sum] <;> nlinarith`
-- This proof should be restored after the norm_num plugin for big operators is ported.
-- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.)
rw [show 3 = 1 + 1 + 1 from rfl]
repeat rw [Finset.sum_range_succ]
norm_num [Nat.factorial]
nlinarith
_ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith
theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) :
Real.exp x ≤ 1 / (1 - x) := by
rcases eq_or_lt_of_le h1 with (rfl | h1)
· simp
· exact (exp_bound_div_one_sub_of_interval' h1 h2).le
theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by
obtain hx | hx := hx.symm.lt_or_lt
· exact add_one_lt_exp_of_pos hx
obtain h' | h' := le_or_lt 1 (-x)
· linarith [x.exp_pos]
have hx' : 0 < x + 1 := by linarith
simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx']
using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h'
theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by
obtain rfl | hx := eq_or_ne x 0
· simp
· exact (add_one_lt_exp hx).le
lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) :=
(sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx
lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) :=
(sub_eq_neg_add _ _).trans_le <| add_one_le_exp _
theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rwa [Nat.cast_zero] at ht'
calc
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
gcongr
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
· exact one_sub_le_exp_neg _
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by
rw [le_inv_mul_iff₀ hc]
calc c * x
_ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one
_ ≤ _ := Real.add_one_le_exp (c * x)
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.exp $a) =>
assertInstancesCommute
pure (.positive q(Real.exp_pos $a))
| _, _, _ => throwError "not Real.exp"
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by
rw [← ofReal_exp]
exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _))
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal
end Complex
| Mathlib/Data/Complex/Exponential.lean | 862 | 863 | |
/-
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.Localization.Opposite
/-!
# Calculus of fractions
Following the definitions by [Gabriel and Zisman][gabriel-zisman-1967],
given a morphism property `W : MorphismProperty C` on a category `C`,
we introduce the class `W.HasLeftCalculusOfFractions`. The main
result `Localization.exists_leftFraction` is that if `L : C ⥤ D`
is a localization functor for `W`, then for any morphism `L.obj X ⟶ L.obj Y` in `D`,
there exists an auxiliary object `Y' : C` and morphisms `g : X ⟶ Y'` and `s : Y ⟶ Y'`,
with `W s`, such that the given morphism is a sort of fraction `g / s`,
or more precisely of the form `L.map g ≫ (Localization.isoOfHom L W s hs).inv`.
We also show that the functor `L.mapArrow : Arrow C ⥤ Arrow D` is essentially surjective.
Similar results are obtained when `W` has a right calculus of fractions.
## References
* [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967]
-/
namespace CategoryTheory
variable {C D : Type*} [Category C] [Category D]
open Category
namespace MorphismProperty
/-- A left fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the
datum of an object `Y' : C` and maps `f : X ⟶ Y'` and `s : Y ⟶ Y'` such that `W s`. -/
structure LeftFraction (W : MorphismProperty C) (X Y : C) where
/-- the auxiliary object of a left fraction -/
{Y' : C}
/-- the numerator of a left fraction -/
f : X ⟶ Y'
/-- the denominator of a left fraction -/
s : Y ⟶ Y'
/-- the condition that the denominator belongs to the given morphism property -/
hs : W s
namespace LeftFraction
variable (W : MorphismProperty C) {X Y : C}
/-- The left fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/
@[simps]
def ofHom (f : X ⟶ Y) [W.ContainsIdentities] :
W.LeftFraction X Y := mk f (𝟙 Y) (W.id_mem Y)
variable {W}
/-- The left fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/
@[simps]
def ofInv (s : Y ⟶ X) (hs : W s) :
W.LeftFraction X Y := mk (𝟙 X) s hs
/-- If `φ : W.LeftFraction X Y` and `L` is a functor which inverts `W`, this is the
induced morphism `L.obj X ⟶ L.obj Y` -/
noncomputable def map (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.obj X ⟶ L.obj Y :=
have := hL _ φ.hs
L.map φ.f ≫ inv (L.map φ.s)
@[reassoc (attr := simp)]
lemma map_comp_map_s (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
φ.map L hL ≫ L.map φ.s = L.map φ.f := by
letI := hL _ φ.hs
simp [map]
variable (W)
lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] :
(ofHom W f).map L hL = L.map f := by
simp [map]
@[reassoc (attr := simp)]
lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by
letI := hL _ hs
simp [map]
| @[reassoc (attr := simp)]
lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by
letI := hL _ hs
simp [map]
| Mathlib/CategoryTheory/Localization/CalculusOfFractions.lean | 90 | 94 |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Multiset.Bind
/-!
# Sections of a multiset
-/
assert_not_exists Ring
namespace Multiset
variable {α : Type*}
section Sections
/-- The sections of a multiset of multisets `s` consists of all those multisets
which can be put in bijection with `s`, so each element is a member of the corresponding multiset.
-/
def Sections (s : Multiset (Multiset α)) : Multiset (Multiset α) :=
Multiset.recOn s {0} (fun s _ c => s.bind fun a => c.map (Multiset.cons a)) fun a₀ a₁ _ pi => by
simp [map_bind, bind_bind a₀ a₁, cons_swap]
@[simp]
theorem sections_zero : Sections (0 : Multiset (Multiset α)) = {0} :=
rfl
@[simp]
theorem sections_cons (s : Multiset (Multiset α)) (m : Multiset α) :
Sections (m ::ₘ s) = m.bind fun a => (Sections s).map (Multiset.cons a) :=
recOn_cons m s
theorem coe_sections :
∀ l : List (List α),
Sections (l.map fun l : List α => (l : Multiset α) : Multiset (Multiset α)) =
(l.sections.map fun l : List α => (l : Multiset α) : Multiset (Multiset α))
| [] => rfl
| | a :: l => by
simp only [List.map_cons, List.sections]
rw [← cons_coe, sections_cons, bind_map_comm, coe_sections l]
simp [List.sections, Function.comp_def, List.flatMap]
@[simp]
theorem sections_add (s t : Multiset (Multiset α)) :
Sections (s + t) = (Sections s).bind fun m => (Sections t).map (m + ·) :=
Multiset.induction_on s (by simp) fun a s ih => by
| Mathlib/Data/Multiset/Sections.lean | 42 | 50 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Data.Ordering.Lemmas
import Mathlib.Data.PNat.Basic
import Mathlib.SetTheory.Ordinal.Principal
import Mathlib.Tactic.NormNum
/-!
# Ordinal notation
Constructive ordinal arithmetic for ordinals below `ε₀`.
We define a type `ONote`, with constructors `0 : ONote` and `ONote.oadd e n a` representing
`ω ^ e * n + a`.
We say that `o` is in Cantor normal form - `ONote.NF o` - if either `o = 0` or
`o = ω ^ e * n + a` with `a < ω ^ e` and `a` in Cantor normal form.
The type `NONote` is the type of ordinals below `ε₀` in Cantor normal form.
Various operations (addition, subtraction, multiplication, exponentiation)
are defined on `ONote` and `NONote`.
-/
open Ordinal Order
-- The generated theorem `ONote.zero.sizeOf_spec` is flagged by `simpNF`,
-- and we don't otherwise need it.
set_option genSizeOfSpec false in
/-- Recursive definition of an ordinal notation. `zero` denotes the ordinal 0, and `oadd e n a` is
intended to refer to `ω ^ e * n + a`. For this to be a valid Cantor normal form, we must have the
exponents decrease to the right, but we can't state this condition until we've defined `repr`, so we
make it a separate definition `NF`. -/
inductive ONote : Type
| zero : ONote
| oadd : ONote → ℕ+ → ONote → ONote
deriving DecidableEq
compile_inductive% ONote
namespace ONote
/-- Notation for 0 -/
instance : Zero ONote :=
⟨zero⟩
@[simp]
theorem zero_def : zero = 0 :=
rfl
instance : Inhabited ONote :=
⟨0⟩
/-- Notation for 1 -/
instance : One ONote :=
⟨oadd 0 1 0⟩
/-- Notation for ω -/
def omega : ONote :=
oadd 1 1 0
/-- The ordinal denoted by a notation -/
noncomputable def repr : ONote → Ordinal.{0}
| 0 => 0
| oadd e n a => ω ^ repr e * n + repr a
@[simp] theorem repr_zero : repr 0 = 0 := rfl
attribute [simp] repr.eq_1 repr.eq_2
/-- Print `ω^s*n`, omitting `s` if `e = 0` or `e = 1`, and omitting `n` if `n = 1` -/
private def toString_aux (e : ONote) (n : ℕ) (s : String) : String :=
if e = 0 then toString n
else (if e = 1 then "ω" else "ω^(" ++ s ++ ")") ++ if n = 1 then "" else "*" ++ toString n
/-- Print an ordinal notation -/
def toString : ONote → String
| zero => "0"
| oadd e n 0 => toString_aux e n (toString e)
| oadd e n a => toString_aux e n (toString e) ++ " + " ++ toString a
open Lean in
/-- Print an ordinal notation -/
def repr' (prec : ℕ) : ONote → Format
| zero => "0"
| oadd e n a =>
Repr.addAppParen
("oadd " ++ (repr' max_prec e) ++ " " ++ Nat.repr (n : ℕ) ++ " " ++ (repr' max_prec a))
prec
instance : ToString ONote :=
⟨toString⟩
instance : Repr ONote where
reprPrec o prec := repr' prec o
instance : Preorder ONote where
le x y := repr x ≤ repr y
lt x y := repr x < repr y
le_refl _ := @le_refl Ordinal _ _
le_trans _ _ _ := @le_trans Ordinal _ _ _ _
lt_iff_le_not_le _ _ := @lt_iff_le_not_le Ordinal _ _ _
theorem lt_def {x y : ONote} : x < y ↔ repr x < repr y :=
Iff.rfl
theorem le_def {x y : ONote} : x ≤ y ↔ repr x ≤ repr y :=
Iff.rfl
instance : WellFoundedRelation ONote :=
⟨(· < ·), InvImage.wf repr Ordinal.lt_wf⟩
/-- Convert a `Nat` into an ordinal -/
@[coe] def ofNat : ℕ → ONote
| 0 => 0
| Nat.succ n => oadd 0 n.succPNat 0
-- Porting note (https://github.com/leanprover-community/mathlib4/pull/11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
@[simp] theorem ofNat_zero : ofNat 0 = 0 :=
rfl
@[simp] theorem ofNat_succ (n) : ofNat (Nat.succ n) = oadd 0 n.succPNat 0 :=
rfl
instance (priority := low) nat (n : ℕ) : OfNat ONote n where
ofNat := ofNat n
@[simp 1200] theorem ofNat_one : ofNat 1 = 1 := rfl
@[simp] theorem repr_ofNat (n : ℕ) : repr (ofNat n) = n := by cases n <;> simp
@[simp] theorem repr_one : repr 1 = (1 : ℕ) := repr_ofNat 1
theorem omega0_le_oadd (e n a) : ω ^ repr e ≤ repr (oadd e n a) := by
refine le_trans ?_ (le_add_right _ _)
simpa using (Ordinal.mul_le_mul_iff_left <| opow_pos (repr e) omega0_pos).2 (Nat.cast_le.2 n.2)
theorem oadd_pos (e n a) : 0 < oadd e n a :=
@lt_of_lt_of_le _ _ _ (ω ^ repr e) _ (opow_pos (repr e) omega0_pos) (omega0_le_oadd e n a)
/-- Comparison of ordinal notations:
`ω ^ e₁ * n₁ + a₁` is less than `ω ^ e₂ * n₂ + a₂` when either `e₁ < e₂`, or `e₁ = e₂` and
`n₁ < n₂`, or `e₁ = e₂`, `n₁ = n₂`, and `a₁ < a₂`. -/
def cmp : ONote → ONote → Ordering
| 0, 0 => Ordering.eq
| _, 0 => Ordering.gt
| 0, _ => Ordering.lt
| _o₁@(oadd e₁ n₁ a₁), _o₂@(oadd e₂ n₂ a₂) =>
(cmp e₁ e₂).then <| (_root_.cmp (n₁ : ℕ) n₂).then (cmp a₁ a₂)
theorem eq_of_cmp_eq : ∀ {o₁ o₂}, cmp o₁ o₂ = Ordering.eq → o₁ = o₂
| 0, 0, _ => rfl
| oadd e n a, 0, h => by injection h
| 0, oadd e n a, h => by injection h
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, h => by
revert h; simp only [cmp]
cases h₁ : cmp e₁ e₂ <;> intro h <;> try cases h
obtain rfl := eq_of_cmp_eq h₁
revert h; cases h₂ : _root_.cmp (n₁ : ℕ) n₂ <;> intro h <;> try cases h
obtain rfl := eq_of_cmp_eq h
rw [_root_.cmp, cmpUsing_eq_eq, not_lt, not_lt, ← le_antisymm_iff] at h₂
obtain rfl := Subtype.eq h₂
simp
protected theorem zero_lt_one : (0 : ONote) < 1 := by
simp only [lt_def, repr_zero, repr_one, Nat.cast_one, zero_lt_one]
/-- `NFBelow o b` says that `o` is a normal form ordinal notation satisfying `repr o < ω ^ b`. -/
inductive NFBelow : ONote → Ordinal.{0} → Prop
| zero {b} : NFBelow 0 b
| oadd' {e n a eb b} : NFBelow e eb → NFBelow a (repr e) → repr e < b → NFBelow (oadd e n a) b
/-- A normal form ordinal notation has the form
`ω ^ a₁ * n₁ + ω ^ a₂ * n₂ + ⋯ + ω ^ aₖ * nₖ`
where `a₁ > a₂ > ⋯ > aₖ` and all the `aᵢ` are also in normal form.
We will essentially only be interested in normal form ordinal notations, but to avoid complicating
the algorithms, we define everything over general ordinal notations and only prove correctness with
normal form as an invariant. -/
class NF (o : ONote) : Prop where
out : Exists (NFBelow o)
instance NF.zero : NF 0 :=
⟨⟨0, NFBelow.zero⟩⟩
theorem NFBelow.oadd {e n a b} : NF e → NFBelow a (repr e) → repr e < b → NFBelow (oadd e n a) b
| ⟨⟨_, h⟩⟩ => NFBelow.oadd' h
theorem NFBelow.fst {e n a b} (h : NFBelow (ONote.oadd e n a) b) : NF e := by
obtain - | ⟨h₁, h₂, h₃⟩ := h; exact ⟨⟨_, h₁⟩⟩
theorem NF.fst {e n a} : NF (oadd e n a) → NF e
| ⟨⟨_, h⟩⟩ => h.fst
theorem NFBelow.snd {e n a b} (h : NFBelow (ONote.oadd e n a) b) : NFBelow a (repr e) := by
obtain - | ⟨h₁, h₂, h₃⟩ := h; exact h₂
theorem NF.snd' {e n a} : NF (oadd e n a) → NFBelow a (repr e)
| ⟨⟨_, h⟩⟩ => h.snd
theorem NF.snd {e n a} (h : NF (oadd e n a)) : NF a :=
⟨⟨_, h.snd'⟩⟩
theorem NF.oadd {e a} (h₁ : NF e) (n) (h₂ : NFBelow a (repr e)) : NF (oadd e n a) :=
⟨⟨_, NFBelow.oadd h₁ h₂ (lt_succ _)⟩⟩
instance NF.oadd_zero (e n) [h : NF e] : NF (ONote.oadd e n 0) :=
h.oadd _ NFBelow.zero
theorem NFBelow.lt {e n a b} (h : NFBelow (ONote.oadd e n a) b) : repr e < b := by
obtain - | ⟨h₁, h₂, h₃⟩ := h; exact h₃
theorem NFBelow_zero : ∀ {o}, NFBelow o 0 ↔ o = 0
| 0 => ⟨fun _ => rfl, fun _ => NFBelow.zero⟩
| oadd _ _ _ =>
⟨fun h => (not_le_of_lt h.lt).elim (Ordinal.zero_le _), fun e => e.symm ▸ NFBelow.zero⟩
theorem NF.zero_of_zero {e n a} (h : NF (ONote.oadd e n a)) (e0 : e = 0) : a = 0 := by
simpa [e0, NFBelow_zero] using h.snd'
theorem NFBelow.repr_lt {o b} (h : NFBelow o b) : repr o < ω ^ b := by
induction h with
| zero => exact opow_pos _ omega0_pos
| oadd' _ _ h₃ _ IH =>
rw [repr]
apply ((add_lt_add_iff_left _).2 IH).trans_le
rw [← mul_succ]
apply (mul_le_mul_left' (succ_le_of_lt (nat_lt_omega0 _)) _).trans
rw [← opow_succ]
exact opow_le_opow_right omega0_pos (succ_le_of_lt h₃)
theorem NFBelow.mono {o b₁ b₂} (bb : b₁ ≤ b₂) (h : NFBelow o b₁) : NFBelow o b₂ := by
induction h with
| zero => exact zero
| oadd' h₁ h₂ h₃ _ _ => constructor; exacts [h₁, h₂, lt_of_lt_of_le h₃ bb]
theorem NF.below_of_lt {e n a b} (H : repr e < b) :
NF (ONote.oadd e n a) → NFBelow (ONote.oadd e n a) b
| ⟨⟨b', h⟩⟩ => by (obtain - | ⟨h₁, h₂, h₃⟩ := h; exact NFBelow.oadd' h₁ h₂ H)
theorem NF.below_of_lt' : ∀ {o b}, repr o < ω ^ b → NF o → NFBelow o b
| 0, _, _, _ => NFBelow.zero
| ONote.oadd _ _ _, _, H, h =>
h.below_of_lt <|
(opow_lt_opow_iff_right one_lt_omega0).1 <| lt_of_le_of_lt (omega0_le_oadd _ _ _) H
theorem nfBelow_ofNat : ∀ n, NFBelow (ofNat n) 1
| 0 => NFBelow.zero
| Nat.succ _ => NFBelow.oadd NF.zero NFBelow.zero zero_lt_one
instance nf_ofNat (n) : NF (ofNat n) :=
⟨⟨_, nfBelow_ofNat n⟩⟩
instance nf_one : NF 1 := by rw [← ofNat_one]; infer_instance
theorem oadd_lt_oadd_1 {e₁ n₁ o₁ e₂ n₂ o₂} (h₁ : NF (oadd e₁ n₁ o₁)) (h : e₁ < e₂) :
oadd e₁ n₁ o₁ < oadd e₂ n₂ o₂ :=
@lt_of_lt_of_le _ _ (repr (oadd e₁ n₁ o₁)) _ _
(NF.below_of_lt h h₁).repr_lt (omega0_le_oadd e₂ n₂ o₂)
theorem oadd_lt_oadd_2 {e o₁ o₂ : ONote} {n₁ n₂ : ℕ+} (h₁ : NF (oadd e n₁ o₁)) (h : (n₁ : ℕ) < n₂) :
oadd e n₁ o₁ < oadd e n₂ o₂ := by
simp only [lt_def, repr]
refine lt_of_lt_of_le ((add_lt_add_iff_left _).2 h₁.snd'.repr_lt) (le_trans ?_ (le_add_right _ _))
rwa [← mul_succ,Ordinal.mul_le_mul_iff_left (opow_pos _ omega0_pos), succ_le_iff, Nat.cast_lt]
theorem oadd_lt_oadd_3 {e n a₁ a₂} (h : a₁ < a₂) : oadd e n a₁ < oadd e n a₂ := by
rw [lt_def]; unfold repr
exact @add_lt_add_left _ _ _ _ (repr a₁) _ h _
theorem cmp_compares : ∀ (a b : ONote) [NF a] [NF b], (cmp a b).Compares a b
| 0, 0, _, _ => rfl
| oadd _ _ _, 0, _, _ => oadd_pos _ _ _
| 0, oadd _ _ _, _, _ => oadd_pos _ _ _
| o₁@(oadd e₁ n₁ a₁), o₂@(oadd e₂ n₂ a₂), h₁, h₂ => by -- TODO: golf
rw [cmp]
have IHe := @cmp_compares _ _ h₁.fst h₂.fst
simp only [Ordering.Compares, gt_iff_lt] at IHe; revert IHe
cases cmp e₁ e₂
case lt => intro IHe; exact oadd_lt_oadd_1 h₁ IHe
case gt => intro IHe; exact oadd_lt_oadd_1 h₂ IHe
case eq =>
intro IHe; dsimp at IHe; subst IHe
unfold _root_.cmp; cases nh : cmpUsing (· < ·) (n₁ : ℕ) n₂ <;>
rw [cmpUsing, ite_eq_iff, not_lt] at nh
case lt =>
rcases nh with nh | nh
· exact oadd_lt_oadd_2 h₁ nh.left
· rw [ite_eq_iff] at nh; rcases nh.right with nh | nh <;> cases nh <;> contradiction
case gt =>
rcases nh with nh | nh
· cases nh; contradiction
· obtain ⟨_, nh⟩ := nh
rw [ite_eq_iff] at nh; rcases nh with nh | nh
· exact oadd_lt_oadd_2 h₂ nh.left
· cases nh; contradiction
rcases nh with nh | nh
· cases nh; contradiction
obtain ⟨nhl, nhr⟩ := nh
rw [ite_eq_iff] at nhr
rcases nhr with nhr | nhr
· cases nhr; contradiction
obtain rfl := Subtype.eq (nhl.eq_of_not_lt nhr.1)
have IHa := @cmp_compares _ _ h₁.snd h₂.snd
revert IHa; cases cmp a₁ a₂ <;> intro IHa <;> dsimp at IHa
case lt => exact oadd_lt_oadd_3 IHa
case gt => exact oadd_lt_oadd_3 IHa
subst IHa; exact rfl
theorem repr_inj {a b} [NF a] [NF b] : repr a = repr b ↔ a = b :=
⟨fun e => match cmp a b, cmp_compares a b with
| Ordering.lt, (h : repr a < repr b) => (ne_of_lt h e).elim
| Ordering.gt, (h : repr a > repr b)=> (ne_of_gt h e).elim
| Ordering.eq, h => h,
congr_arg _⟩
theorem NF.of_dvd_omega0_opow {b e n a} (h : NF (ONote.oadd e n a))
(d : ω ^ b ∣ repr (ONote.oadd e n a)) :
b ≤ repr e ∧ ω ^ b ∣ repr a := by
have := mt repr_inj.1 (fun h => by injection h : ONote.oadd e n a ≠ 0)
have L := le_of_not_lt fun l => not_le_of_lt (h.below_of_lt l).repr_lt (le_of_dvd this d)
simp only [repr] at d
exact ⟨L, (dvd_add_iff <| (opow_dvd_opow _ L).mul_right _).1 d⟩
theorem NF.of_dvd_omega0 {e n a} (h : NF (ONote.oadd e n a)) :
ω ∣ repr (ONote.oadd e n a) → repr e ≠ 0 ∧ ω ∣ repr a := by
(rw [← opow_one ω, ← one_le_iff_ne_zero]; exact h.of_dvd_omega0_opow)
/-- `TopBelow b o` asserts that the largest exponent in `o`, if it exists, is less than `b`. This is
an auxiliary definition for decidability of `NF`. -/
def TopBelow (b : ONote) : ONote → Prop
| 0 => True
| oadd e _ _ => cmp e b = Ordering.lt
instance decidableTopBelow : DecidableRel TopBelow := by
intro b o
cases o <;> delta TopBelow <;> infer_instance
theorem nfBelow_iff_topBelow {b} [NF b] : ∀ {o}, NFBelow o (repr b) ↔ NF o ∧ TopBelow b o
| 0 => ⟨fun h => ⟨⟨⟨_, h⟩⟩, trivial⟩, fun _ => NFBelow.zero⟩
| oadd _ _ _ =>
⟨fun h => ⟨⟨⟨_, h⟩⟩, (@cmp_compares _ b h.fst _).eq_lt.2 h.lt⟩, fun ⟨h₁, h₂⟩ =>
h₁.below_of_lt <| (@cmp_compares _ b h₁.fst _).eq_lt.1 h₂⟩
instance decidableNF : DecidablePred NF
| 0 => isTrue NF.zero
| oadd e n a => by
have := decidableNF e
have := decidableNF a
apply decidable_of_iff (NF e ∧ NF a ∧ TopBelow e a)
rw [← and_congr_right fun h => @nfBelow_iff_topBelow _ h _]
exact ⟨fun ⟨h₁, h₂⟩ => NF.oadd h₁ n h₂, fun h => ⟨h.fst, h.snd'⟩⟩
/-- Auxiliary definition for `add` -/
def addAux (e : ONote) (n : ℕ+) (o : ONote) : ONote :=
match o with
| 0 => oadd e n 0
| o'@(oadd e' n' a') =>
match cmp e e' with
| Ordering.lt => o'
| Ordering.eq => oadd e (n + n') a'
| Ordering.gt => oadd e n o'
/-- Addition of ordinal notations (correct only for normal input) -/
def add : ONote → ONote → ONote
| 0, o => o
| oadd e n a, o => addAux e n (add a o)
instance : Add ONote :=
⟨add⟩
@[simp]
theorem zero_add (o : ONote) : 0 + o = o :=
rfl
theorem oadd_add (e n a o) : oadd e n a + o = addAux e n (a + o) :=
rfl
/-- Subtraction of ordinal notations (correct only for normal input) -/
def sub : ONote → ONote → ONote
| 0, _ => 0
| o, 0 => o
| o₁@(oadd e₁ n₁ a₁), oadd e₂ n₂ a₂ =>
match cmp e₁ e₂ with
| Ordering.lt => 0
| Ordering.gt => o₁
| Ordering.eq =>
match (n₁ : ℕ) - n₂ with
| 0 => if n₁ = n₂ then sub a₁ a₂ else 0
| Nat.succ k => oadd e₁ k.succPNat a₁
instance : Sub ONote :=
⟨sub⟩
theorem add_nfBelow {b} : ∀ {o₁ o₂}, NFBelow o₁ b → NFBelow o₂ b → NFBelow (o₁ + o₂) b
| 0, _, _, h₂ => h₂
| oadd e n a, o, h₁, h₂ => by
have h' := add_nfBelow (h₁.snd.mono <| le_of_lt h₁.lt) h₂
simp only [oadd_add]; revert h'; obtain - | ⟨e', n', a'⟩ := a + o <;> intro h'
· exact NFBelow.oadd h₁.fst NFBelow.zero h₁.lt
have : ((e.cmp e').Compares e e') := @cmp_compares _ _ h₁.fst h'.fst
cases h : cmp e e' <;> dsimp [addAux] <;> simp only [h]
· exact h'
· simp only [h] at this
subst e'
exact NFBelow.oadd h'.fst h'.snd h'.lt
· simp only [h] at this
exact NFBelow.oadd h₁.fst (NF.below_of_lt this ⟨⟨_, h'⟩⟩) h₁.lt
instance add_nf (o₁ o₂) : ∀ [NF o₁] [NF o₂], NF (o₁ + o₂)
| ⟨⟨b₁, h₁⟩⟩, ⟨⟨b₂, h₂⟩⟩ =>
⟨(le_total b₁ b₂).elim (fun h => ⟨b₂, add_nfBelow (h₁.mono h) h₂⟩) fun h =>
⟨b₁, add_nfBelow h₁ (h₂.mono h)⟩⟩
@[simp]
theorem repr_add : ∀ (o₁ o₂) [NF o₁] [NF o₂], repr (o₁ + o₂) = repr o₁ + repr o₂
| 0, o, _, _ => by simp
| oadd e n a, o, h₁, h₂ => by
haveI := h₁.snd; have h' := repr_add a o
conv_lhs at h' => simp [HAdd.hAdd, Add.add]
have nf := ONote.add_nf a o
conv at nf => simp [HAdd.hAdd, Add.add]
conv in _ + o => simp [HAdd.hAdd, Add.add]
rcases h : add a o with - | ⟨e', n', a'⟩ <;>
simp only [Add.add, add, addAux, h'.symm, h, add_assoc, repr_zero, repr] at nf h₁ ⊢
have := h₁.fst; haveI := nf.fst; have ee := cmp_compares e e'
cases he : cmp e e' <;> simp only [he, Ordering.compares_gt, Ordering.compares_lt,
Ordering.compares_eq, repr, gt_iff_lt, PNat.add_coe, Nat.cast_add] at ee ⊢
· rw [← add_assoc, @add_absorp _ (repr e') (ω ^ repr e' * (n' : ℕ))]
· have := (h₁.below_of_lt ee).repr_lt
unfold repr at this
cases he' : e' <;> simp only [he', zero_def, opow_zero, repr, gt_iff_lt] at this ⊢ <;>
exact lt_of_le_of_lt (le_add_right _ _) this
· simpa using (Ordinal.mul_le_mul_iff_left <| opow_pos (repr e') omega0_pos).2
(Nat.cast_le.2 n'.pos)
· rw [ee, ← add_assoc, ← mul_add]
theorem sub_nfBelow : ∀ {o₁ o₂ b}, NFBelow o₁ b → NF o₂ → NFBelow (o₁ - o₂) b
| 0, o, b, _, h₂ => by cases o <;> exact NFBelow.zero
| oadd _ _ _, 0, _, h₁, _ => h₁
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, b, h₁, h₂ => by
have h' := sub_nfBelow h₁.snd h₂.snd
simp only [HSub.hSub, Sub.sub, sub] at h' ⊢
have := @cmp_compares _ _ h₁.fst h₂.fst
cases h : cmp e₁ e₂
· apply NFBelow.zero
· rw [Nat.sub_eq]
simp only [h, Ordering.compares_eq] at this
subst e₂
cases (n₁ : ℕ) - n₂
· by_cases en : n₁ = n₂ <;> simp only [en, ↓reduceIte]
· exact h'.mono (le_of_lt h₁.lt)
· exact NFBelow.zero
· exact NFBelow.oadd h₁.fst h₁.snd h₁.lt
· exact h₁
instance sub_nf (o₁ o₂) : ∀ [NF o₁] [NF o₂], NF (o₁ - o₂)
| ⟨⟨b₁, h₁⟩⟩, h₂ => ⟨⟨b₁, sub_nfBelow h₁ h₂⟩⟩
@[simp]
theorem repr_sub : ∀ (o₁ o₂) [NF o₁] [NF o₂], repr (o₁ - o₂) = repr o₁ - repr o₂
| 0, o, _, h₂ => by cases o <;> exact (Ordinal.zero_sub _).symm
| oadd _ _ _, 0, _, _ => (Ordinal.sub_zero _).symm
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, h₁, h₂ => by
haveI := h₁.snd; haveI := h₂.snd; have h' := repr_sub a₁ a₂
conv_lhs at h' => dsimp [HSub.hSub, Sub.sub, sub]
conv_lhs => dsimp only [HSub.hSub, Sub.sub]; dsimp only [sub]
have ee := @cmp_compares _ _ h₁.fst h₂.fst
cases h : cmp e₁ e₂ <;> simp only [h] at ee
· rw [Ordinal.sub_eq_zero_iff_le.2]
· rfl
exact le_of_lt (oadd_lt_oadd_1 h₁ ee)
· change e₁ = e₂ at ee
subst e₂
dsimp only
cases mn : (n₁ : ℕ) - n₂ <;> dsimp only
· by_cases en : n₁ = n₂
· simpa [en]
· simp only [en, ite_false]
exact
(Ordinal.sub_eq_zero_iff_le.2 <|
le_of_lt <|
oadd_lt_oadd_2 h₁ <|
lt_of_le_of_ne (tsub_eq_zero_iff_le.1 mn) (mt PNat.eq en)).symm
· simp [Nat.succPNat]
rw [(tsub_eq_iff_eq_add_of_le <| le_of_lt <| Nat.lt_of_sub_eq_succ mn).1 mn, add_comm,
Nat.cast_add, mul_add, add_assoc, add_sub_add_cancel]
refine
(Ordinal.sub_eq_of_add_eq <|
add_absorp h₂.snd'.repr_lt <| le_trans ?_ (le_add_right _ _)).symm
exact Ordinal.le_mul_left _ (Nat.cast_lt.2 <| Nat.succ_pos _)
· exact
(Ordinal.sub_eq_of_add_eq <|
add_absorp (h₂.below_of_lt ee).repr_lt <| omega0_le_oadd _ _ _).symm
/-- Multiplication of ordinal notations (correct only for normal input) -/
def mul : ONote → ONote → ONote
| 0, _ => 0
| _, 0 => 0
| o₁@(oadd e₁ n₁ a₁), oadd e₂ n₂ a₂ =>
if e₂ = 0 then oadd e₁ (n₁ * n₂) a₁ else oadd (e₁ + e₂) n₂ (mul o₁ a₂)
instance : Mul ONote :=
⟨mul⟩
instance : MulZeroClass ONote where
mul := (· * ·)
zero := 0
zero_mul o := by cases o <;> rfl
mul_zero o := by cases o <;> rfl
theorem oadd_mul (e₁ n₁ a₁ e₂ n₂ a₂) :
oadd e₁ n₁ a₁ * oadd e₂ n₂ a₂ =
if e₂ = 0 then oadd e₁ (n₁ * n₂) a₁ else oadd (e₁ + e₂) n₂ (oadd e₁ n₁ a₁ * a₂) :=
rfl
theorem oadd_mul_nfBelow {e₁ n₁ a₁ b₁} (h₁ : NFBelow (oadd e₁ n₁ a₁) b₁) :
∀ {o₂ b₂}, NFBelow o₂ b₂ → NFBelow (oadd e₁ n₁ a₁ * o₂) (repr e₁ + b₂)
| 0, _, _ => NFBelow.zero
| oadd e₂ n₂ a₂, b₂, h₂ => by
have IH := oadd_mul_nfBelow h₁ h₂.snd
by_cases e0 : e₂ = 0 <;> simp only [e0, oadd_mul, ↓reduceIte]
· apply NFBelow.oadd h₁.fst h₁.snd
simpa using (add_lt_add_iff_left (repr e₁)).2 (lt_of_le_of_lt (Ordinal.zero_le _) h₂.lt)
· haveI := h₁.fst
haveI := h₂.fst
apply NFBelow.oadd
· infer_instance
· rwa [repr_add]
· rw [repr_add, add_lt_add_iff_left]
exact h₂.lt
instance mul_nf : ∀ (o₁ o₂) [NF o₁] [NF o₂], NF (o₁ * o₂)
| 0, o, _, h₂ => by cases o <;> exact NF.zero
| oadd _ _ _, _, ⟨⟨_, hb₁⟩⟩, ⟨⟨_, hb₂⟩⟩ => ⟨⟨_, oadd_mul_nfBelow hb₁ hb₂⟩⟩
@[simp]
theorem repr_mul : ∀ (o₁ o₂) [NF o₁] [NF o₂], repr (o₁ * o₂) = repr o₁ * repr o₂
| 0, o, _, h₂ => by cases o <;> exact (zero_mul _).symm
| oadd _ _ _, 0, _, _ => (mul_zero _).symm
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, h₁, h₂ => by
have IH : repr (mul _ _) = _ := @repr_mul _ _ h₁ h₂.snd
conv =>
lhs
simp [(· * ·)]
have ao : repr a₁ + ω ^ repr e₁ * (n₁ : ℕ) = ω ^ repr e₁ * (n₁ : ℕ) := by
apply add_absorp h₁.snd'.repr_lt
simpa using (Ordinal.mul_le_mul_iff_left <| opow_pos _ omega0_pos).2 (Nat.cast_le.2 n₁.2)
by_cases e0 : e₂ = 0
· obtain ⟨x, xe⟩ := Nat.exists_eq_succ_of_ne_zero n₂.ne_zero
simp only [Mul.mul, mul, e0, ↓reduceIte, repr, PNat.mul_coe, natCast_mul, opow_zero, one_mul]
simp only [xe, h₂.zero_of_zero e0, repr, add_zero]
rw [natCast_succ x, add_mul_succ _ ao, mul_assoc]
· simp only [repr]
haveI := h₁.fst
haveI := h₂.fst
simp only [Mul.mul, mul, e0, ite_false, repr.eq_2, repr_add, opow_add, IH, repr, mul_add]
rw [← mul_assoc]
congr 2
have := mt repr_inj.1 e0
rw [add_mul_limit ao (isLimit_opow_left isLimit_omega0 this), mul_assoc,
mul_omega0_dvd (Nat.cast_pos'.2 n₁.pos) (nat_lt_omega0 _)]
simpa using opow_dvd_opow ω (one_le_iff_ne_zero.2 this)
/-- Calculate division and remainder of `o` mod `ω`:
`split' o = (a, n)` means `o = ω * a + n`. -/
def split' : ONote → ONote × ℕ
| 0 => (0, 0)
| oadd e n a =>
if e = 0 then (0, n)
else
let (a', m) := split' a
(oadd (e - 1) n a', m)
/-- Calculate division and remainder of `o` mod `ω`:
`split o = (a, n)` means `o = a + n`, where `ω ∣ a`. -/
def split : ONote → ONote × ℕ
| 0 => (0, 0)
| oadd e n a =>
if e = 0 then (0, n)
else
let (a', m) := split a
(oadd e n a', m)
/-- `scale x o` is the ordinal notation for `ω ^ x * o`. -/
def scale (x : ONote) : ONote → ONote
| 0 => 0
| oadd e n a => oadd (x + e) n (scale x a)
/-- `mulNat o n` is the ordinal notation for `o * n`. -/
def mulNat : ONote → ℕ → ONote
| 0, _ => 0
| _, 0 => 0
| oadd e n a, m + 1 => oadd e (n * m.succPNat) a
/-- Auxiliary definition to compute the ordinal notation for the ordinal exponentiation in `opow` -/
def opowAux (e a0 a : ONote) : ℕ → ℕ → ONote
| _, 0 => 0
| 0, m + 1 => oadd e m.succPNat 0
| k + 1, m => scale (e + mulNat a0 k) a + (opowAux e a0 a k m)
/-- Auxiliary definition to compute the ordinal notation for the ordinal exponentiation in `opow` -/
def opowAux2 (o₂ : ONote) (o₁ : ONote × ℕ) : ONote :=
match o₁ with
| (0, 0) => if o₂ = 0 then 1 else 0
| (0, 1) => 1
| (0, m + 1) =>
let (b', k) := split' o₂
oadd b' (m.succPNat ^ k) 0
| (a@(oadd a0 _ _), m) =>
match split o₂ with
| (b, 0) => oadd (a0 * b) 1 0
| (b, k + 1) =>
let eb := a0 * b
scale (eb + mulNat a0 k) a + opowAux eb a0 (mulNat a m) k m
/-- `opow o₁ o₂` calculates the ordinal notation for the ordinal exponential `o₁ ^ o₂`. -/
def opow (o₁ o₂ : ONote) : ONote := opowAux2 o₂ (split o₁)
instance : Pow ONote ONote :=
⟨opow⟩
theorem opow_def (o₁ o₂ : ONote) : o₁ ^ o₂ = opowAux2 o₂ (split o₁) :=
rfl
theorem split_eq_scale_split' : ∀ {o o' m} [NF o], split' o = (o', m) → split o = (scale 1 o', m)
| 0, o', m, _, p => by injection p; substs o' m; rfl
| oadd e n a, o', m, h, p => by
by_cases e0 : e = 0 <;> simp only [split', e0, ↓reduceIte, Prod.mk.injEq, split] at p ⊢
· rcases p with ⟨rfl, rfl⟩
exact ⟨rfl, rfl⟩
· revert p
rcases h' : split' a with ⟨a', m'⟩
haveI := h.fst
haveI := h.snd
simp only [split_eq_scale_split' h', and_imp]
have : 1 + (e - 1) = e := by
refine repr_inj.1 ?_
simp only [repr_add, repr_one, Nat.cast_one, repr_sub]
have := mt repr_inj.1 e0
exact Ordinal.add_sub_cancel_of_le <| one_le_iff_ne_zero.2 this
intros
substs o' m
simp [scale, this]
theorem nf_repr_split' : ∀ {o o' m} [NF o], split' o = (o', m) → NF o' ∧ repr o = ω * repr o' + m
| 0, o', m, _, p => by injection p; substs o' m; simp [NF.zero]
| oadd e n a, o', m, h, p => by
by_cases e0 : e = 0 <;> simp [e0, split, split'] at p ⊢
· rcases p with ⟨rfl, rfl⟩
simp [h.zero_of_zero e0, NF.zero]
· revert p
rcases h' : split' a with ⟨a', m'⟩
haveI := h.fst
haveI := h.snd
obtain ⟨IH₁, IH₂⟩ := nf_repr_split' h'
simp only [IH₂, and_imp]
intros
substs o' m
have : (ω : Ordinal.{0}) ^ repr e = ω ^ (1 : Ordinal.{0}) * ω ^ (repr e - 1) := by
have := mt repr_inj.1 e0
rw [← opow_add, Ordinal.add_sub_cancel_of_le (one_le_iff_ne_zero.2 this)]
refine ⟨NF.oadd (by infer_instance) _ ?_, ?_⟩
· simp only [opow_one, repr_sub, repr_one, Nat.cast_one] at this ⊢
refine IH₁.below_of_lt'
((Ordinal.mul_lt_mul_iff_left omega0_pos).1 <| lt_of_le_of_lt (le_add_right _ m') ?_)
rw [← this, ← IH₂]
exact h.snd'.repr_lt
· rw [this]
simp [mul_add, mul_assoc, add_assoc]
theorem scale_eq_mul (x) [NF x] : ∀ (o) [NF o], scale x o = oadd x 1 0 * o
| 0, _ => rfl
| oadd e n a, h => by
simp only [HMul.hMul]; simp only [scale]
haveI := h.snd
by_cases e0 : e = 0
· simp_rw [scale_eq_mul]
simp [Mul.mul, mul, scale_eq_mul, e0, h.zero_of_zero,
show x + 0 = x from repr_inj.1 (by simp)]
· simp [e0, Mul.mul, mul, scale_eq_mul, (· * ·)]
instance nf_scale (x) [NF x] (o) [NF o] : NF (scale x o) := by
rw [scale_eq_mul]
infer_instance
@[simp]
theorem repr_scale (x) [NF x] (o) [NF o] : repr (scale x o) = ω ^ repr x * repr o := by
simp only [scale_eq_mul, repr_mul, repr, PNat.one_coe, Nat.cast_one, mul_one, add_zero]
theorem nf_repr_split {o o' m} [NF o] (h : split o = (o', m)) : NF o' ∧ repr o = repr o' + m := by
rcases e : split' o with ⟨a, n⟩
obtain ⟨s₁, s₂⟩ := nf_repr_split' e
rw [split_eq_scale_split' e] at h
injection h; substs o' n
simp only [repr_scale, repr_one, Nat.cast_one, opow_one, ← s₂, and_true]
infer_instance
theorem split_dvd {o o' m} [NF o] (h : split o = (o', m)) : ω ∣ repr o' := by
rcases e : split' o with ⟨a, n⟩
rw [split_eq_scale_split' e] at h
injection h; subst o'
cases nf_repr_split' e; simp
theorem split_add_lt {o e n a m} [NF o] (h : split o = (oadd e n a, m)) :
repr a + m < ω ^ repr e := by
obtain ⟨h₁, h₂⟩ := nf_repr_split h
obtain ⟨e0, d⟩ := h₁.of_dvd_omega0 (split_dvd h)
apply principal_add_omega0_opow _ h₁.snd'.repr_lt (lt_of_lt_of_le (nat_lt_omega0 _) _)
simpa using opow_le_opow_right omega0_pos (one_le_iff_ne_zero.2 e0)
@[simp]
theorem mulNat_eq_mul (n o) : mulNat o n = o * ofNat n := by cases o <;> cases n <;> rfl
instance nf_mulNat (o) [NF o] (n) : NF (mulNat o n) := by simpa using ONote.mul_nf o (ofNat n)
instance nf_opowAux (e a0 a) [NF e] [NF a0] [NF a] : ∀ k m, NF (opowAux e a0 a k m) := by
intro k m
unfold opowAux
cases m with
| zero => cases k <;> exact NF.zero
| succ m =>
cases k with
| zero => exact NF.oadd_zero _ _
| succ k =>
haveI := nf_opowAux e a0 a k
simp only [Nat.succ_ne_zero m, IsEmpty.forall_iff, mulNat_eq_mul]; infer_instance
instance nf_opow (o₁ o₂) [NF o₁] [NF o₂] : NF (o₁ ^ o₂) := by
rcases e₁ : split o₁ with ⟨a, m⟩
have na := (nf_repr_split e₁).1
rcases e₂ : split' o₂ with ⟨b', k⟩
haveI := (nf_repr_split' e₂).1
obtain - | ⟨a0, n, a'⟩ := a
· rcases m with - | m
· by_cases o₂ = 0 <;> simp only [(· ^ ·), Pow.pow, opow, opowAux2, *] <;> decide
· by_cases m = 0
· simp only [(· ^ ·), Pow.pow, opow, opowAux2, *, zero_def]
decide
· simp only [(· ^ ·), Pow.pow, opow, opowAux2, mulNat_eq_mul, ofNat, *]
infer_instance
· simp only [(· ^ ·), Pow.pow, opow, opowAux2, e₁, split_eq_scale_split' e₂, mulNat_eq_mul]
have := na.fst
rcases k with - | k
· infer_instance
· cases k <;> cases m <;> infer_instance
theorem scale_opowAux (e a0 a : ONote) [NF e] [NF a0] [NF a] :
∀ k m, repr (opowAux e a0 a k m) = ω ^ repr e * repr (opowAux 0 a0 a k m)
| 0, m => by cases m <;> simp [opowAux]
| k + 1, m => by
by_cases h : m = 0
· simp [h, opowAux, mul_add, opow_add, mul_assoc, scale_opowAux _ _ _ k]
· -- Porting note: rewrote proof
rw [opowAux]; swap
· assumption
rw [opowAux]; swap
· assumption
rw [repr_add, repr_scale, scale_opowAux _ _ _ k]
simp only [repr_add, repr_scale, opow_add, mul_assoc, zero_add, mul_add]
theorem repr_opow_aux₁ {e a} [Ne : NF e] [Na : NF a] {a' : Ordinal} (e0 : repr e ≠ 0)
(h : a' < (ω : Ordinal.{0}) ^ repr e) (aa : repr a = a') (n : ℕ+) :
((ω : Ordinal.{0}) ^ repr e * (n : ℕ) + a') ^ (ω : Ordinal.{0}) =
(ω ^ repr e) ^ (ω : Ordinal.{0}) := by
subst aa
have No := Ne.oadd n (Na.below_of_lt' h)
have := omega0_le_oadd e n a
rw [repr] at this
refine le_antisymm ?_ (opow_le_opow_left _ this)
apply (opow_le_of_limit ((opow_pos _ omega0_pos).trans_le this).ne' isLimit_omega0).2
intro b l
have := (No.below_of_lt (lt_succ _)).repr_lt
rw [repr] at this
apply (opow_le_opow_left b <| this.le).trans
rw [← opow_mul, ← opow_mul]
apply opow_le_opow_right omega0_pos
rcases le_or_lt ω (repr e) with h | h
· apply (mul_le_mul_left' (le_succ b) _).trans
rw [← add_one_eq_succ, add_mul_succ _ (one_add_of_omega0_le h), add_one_eq_succ, succ_le_iff,
Ordinal.mul_lt_mul_iff_left (Ordinal.pos_iff_ne_zero.2 e0)]
exact isLimit_omega0.succ_lt l
· apply (principal_mul_omega0 (isLimit_omega0.succ_lt h) l).le.trans
simpa using mul_le_mul_right' (one_le_iff_ne_zero.2 e0) ω
section
-- Porting note: `R'` is used in the proof but marked as an unused variable.
set_option linter.unusedVariables false in
theorem repr_opow_aux₂ {a0 a'} [N0 : NF a0] [Na' : NF a'] (m : ℕ) (d : ω ∣ repr a')
(e0 : repr a0 ≠ 0) (h : repr a' + m < (ω ^ repr a0)) (n : ℕ+) (k : ℕ) :
let R := repr (opowAux 0 a0 (oadd a0 n a' * ofNat m) k m)
(k ≠ 0 → R < ((ω ^ repr a0) ^ succ (k : Ordinal))) ∧
((ω ^ repr a0) ^ (k : Ordinal)) * ((ω ^ repr a0) * (n : ℕ) + repr a') + R =
((ω ^ repr a0) * (n : ℕ) + repr a' + m) ^ succ (k : Ordinal) := by
intro R'
haveI No : NF (oadd a0 n a') :=
N0.oadd n (Na'.below_of_lt' <| lt_of_le_of_lt (le_add_right _ _) h)
induction' k with k IH
· cases m <;> simp [R', opowAux]
-- rename R => R'
let R := repr (opowAux 0 a0 (oadd a0 n a' * ofNat m) k m)
let ω0 := ω ^ repr a0
let α' := ω0 * n + repr a'
change (k ≠ 0 → R < (ω0 ^ succ (k : Ordinal))) ∧ (ω0 ^ (k : Ordinal)) * α' + R
= (α' + m) ^ (succ ↑k : Ordinal) at IH
have RR : R' = ω0 ^ (k : Ordinal) * (α' * m) + R := by
by_cases h : m = 0
· simp only [R, R', h, ONote.ofNat, Nat.cast_zero, zero_add, ONote.repr, mul_zero,
ONote.opowAux, add_zero]
· simp only [α', ω0, R, R', ONote.repr_scale, ONote.repr, ONote.mulNat_eq_mul, ONote.opowAux,
ONote.repr_ofNat, ONote.repr_mul, ONote.repr_add, Ordinal.opow_mul, ONote.zero_add]
have α0 : 0 < α' := by simpa [lt_def, repr] using oadd_pos a0 n a'
have ω00 : 0 < ω0 ^ (k : Ordinal) := opow_pos _ (opow_pos _ omega0_pos)
have Rl : R < ω ^ (repr a0 * succ ↑k) := by
by_cases k0 : k = 0
· simp only [k0, Nat.cast_zero, succ_zero, mul_one, R]
refine lt_of_lt_of_le ?_ (opow_le_opow_right omega0_pos (one_le_iff_ne_zero.2 e0))
rcases m with - | m <;> simp [opowAux, omega0_pos]
rw [← add_one_eq_succ, ← Nat.cast_succ]
apply nat_lt_omega0
· rw [opow_mul]
exact IH.1 k0
refine ⟨fun _ => ?_, ?_⟩
· rw [RR, ← opow_mul _ _ (succ k.succ)]
have e0 := Ordinal.pos_iff_ne_zero.2 e0
have rr0 : 0 < repr a0 + repr a0 := lt_of_lt_of_le e0 (le_add_left _ _)
apply principal_add_omega0_opow
· simp only [Nat.succ_eq_add_one, Nat.cast_add, Nat.cast_one, add_one_eq_succ,
opow_mul, opow_succ, mul_assoc]
rw [Ordinal.mul_lt_mul_iff_left ω00, ← Ordinal.opow_add]
have : _ < ω ^ (repr a0 + repr a0) := (No.below_of_lt ?_).repr_lt
· exact mul_lt_omega0_opow rr0 this (nat_lt_omega0 _)
· simpa using (add_lt_add_iff_left (repr a0)).2 e0
· exact
lt_of_lt_of_le Rl
(opow_le_opow_right omega0_pos <|
mul_le_mul_left' (succ_le_succ_iff.2 (Nat.cast_le.2 (le_of_lt k.lt_succ_self))) _)
calc
(ω0 ^ (k.succ : Ordinal)) * α' + R'
_ = (ω0 ^ succ (k : Ordinal)) * α' + ((ω0 ^ (k : Ordinal)) * α' * m + R) := by
rw [natCast_succ, RR, ← mul_assoc]
_ = ((ω0 ^ (k : Ordinal)) * α' + R) * α' + ((ω0 ^ (k : Ordinal)) * α' + R) * m := ?_
_ = (α' + m) ^ succ (k.succ : Ordinal) := by rw [← mul_add, natCast_succ, opow_succ, IH.2]
congr 1
· have αd : ω ∣ α' :=
dvd_add (dvd_mul_of_dvd_left (by simpa using opow_dvd_opow ω (one_le_iff_ne_zero.2 e0)) _) d
rw [mul_add (ω0 ^ (k : Ordinal)), add_assoc, ← mul_assoc, ← opow_succ,
add_mul_limit _ (isLimit_iff_omega0_dvd.2 ⟨ne_of_gt α0, αd⟩), mul_assoc,
@mul_omega0_dvd n (Nat.cast_pos'.2 n.pos) (nat_lt_omega0 _) _ αd]
apply @add_absorp _ (repr a0 * succ ↑k)
· refine principal_add_omega0_opow _ ?_ Rl
rw [opow_mul, opow_succ, Ordinal.mul_lt_mul_iff_left ω00]
exact No.snd'.repr_lt
· have := mul_le_mul_left' (one_le_iff_pos.2 <| Nat.cast_pos'.2 n.pos) (ω0 ^ succ (k : Ordinal))
rw [opow_mul]
simpa [-opow_succ]
· cases m
· have : R = 0 := by cases k <;> simp [R, opowAux]
simp [this]
· rw [natCast_succ, add_mul_succ]
apply add_absorp Rl
rw [opow_mul, opow_succ]
apply mul_le_mul_left'
simpa [repr] using omega0_le_oadd a0 n a'
end
theorem repr_opow (o₁ o₂) [NF o₁] [NF o₂] : repr (o₁ ^ o₂) = repr o₁ ^ repr o₂ := by
rcases e₁ : split o₁ with ⟨a, m⟩
obtain ⟨N₁, r₁⟩ := nf_repr_split e₁
obtain - | ⟨a0, n, a'⟩ := a
· rcases m with - | m
· by_cases h : o₂ = 0 <;> simp [opow_def, opowAux2, opow, e₁, h, r₁]
have := mt repr_inj.1 h
rw [zero_opow this]
· rcases e₂ : split' o₂ with ⟨b', k⟩
obtain ⟨_, r₂⟩ := nf_repr_split' e₂
by_cases h : m = 0
· simp [opowAux2, opow_def, opow, e₁, h, r₁, e₂, r₂]
simp only [opow_def, opowAux2, opow, e₁, h, r₁, e₂, r₂, repr,
opow_zero, Nat.succPNat_coe, Nat.cast_succ, Nat.cast_zero, _root_.zero_add, mul_one,
add_zero, one_opow, npow_eq_pow]
rw [opow_add, opow_mul, opow_omega0, add_one_eq_succ]
· congr
conv_lhs =>
dsimp [(· ^ ·)]
simp [Pow.pow, opow, Ordinal.succ_ne_zero]
rw [opow_natCast]
· simpa [Nat.one_le_iff_ne_zero]
· rw [← Nat.cast_succ, lt_omega0]
exact ⟨_, rfl⟩
· haveI := N₁.fst
haveI := N₁.snd
obtain ⟨a00, ad⟩ := N₁.of_dvd_omega0 (split_dvd e₁)
have al := split_add_lt e₁
have aa : repr (a' + ofNat m) = repr a' + m := by
simp only [eq_self_iff_true, ONote.repr_ofNat, ONote.repr_add]
rcases e₂ : split' o₂ with ⟨b', k⟩
obtain ⟨_, r₂⟩ := nf_repr_split' e₂
simp only [opow_def, opow, e₁, r₁, split_eq_scale_split' e₂, opowAux2, repr]
rcases k with - | k
· simp [r₂, opow_mul, repr_opow_aux₁ a00 al aa, add_assoc]
· simp [opow, opowAux2, r₂, opow_add, opow_mul, mul_assoc, add_assoc]
rw [repr_opow_aux₁ a00 al aa, scale_opowAux]
simp only [repr_mul, repr_scale, repr, opow_zero, PNat.val_ofNat, Nat.cast_one, mul_one,
add_zero, opow_one, opow_mul]
rw [← mul_add, ← add_assoc ((ω : Ordinal.{0}) ^ repr a0 * (n : ℕ))]
congr 1
rw [← pow_succ, ← opow_natCast, ← opow_natCast]
exact (repr_opow_aux₂ _ ad a00 al _ _).2
/-- Given an ordinal, returns:
* `inl none` for `0`
* `inl (some a)` for `a + 1`
* `inr f` for a limit ordinal `a`, where `f i` is a sequence converging to `a` -/
def fundamentalSequence : ONote → (Option ONote) ⊕ (ℕ → ONote)
| zero => Sum.inl none
| oadd a m b =>
match fundamentalSequence b with
| Sum.inr f => Sum.inr fun i => oadd a m (f i)
| Sum.inl (some b') => Sum.inl (some (oadd a m b'))
| Sum.inl none =>
match fundamentalSequence a, m.natPred with
| Sum.inl none, 0 => Sum.inl (some zero)
| Sum.inl none, m + 1 => Sum.inl (some (oadd zero m.succPNat zero))
| Sum.inl (some a'), 0 => Sum.inr fun i => oadd a' i.succPNat zero
| Sum.inl (some a'), m + 1 => Sum.inr fun i => oadd a m.succPNat (oadd a' i.succPNat zero)
| Sum.inr f, 0 => Sum.inr fun i => oadd (f i) 1 zero
| Sum.inr f, m + 1 => Sum.inr fun i => oadd a m.succPNat (oadd (f i) 1 zero)
private theorem exists_lt_add {α} [hα : Nonempty α] {o : Ordinal} {f : α → Ordinal}
(H : ∀ ⦃a⦄, a < o → ∃ i, a < f i) {b : Ordinal} ⦃a⦄ (h : a < b + o) : ∃ i, a < b + f i := by
rcases lt_or_le a b with h | h'
· obtain ⟨i⟩ := id hα
exact ⟨i, h.trans_le (le_add_right _ _)⟩
· rw [← Ordinal.add_sub_cancel_of_le h', add_lt_add_iff_left] at h
refine (H h).imp fun i H => ?_
rwa [← Ordinal.add_sub_cancel_of_le h', add_lt_add_iff_left]
private theorem exists_lt_mul_omega0' {o : Ordinal} ⦃a⦄ (h : a < o * ω) :
∃ i : ℕ, a < o * ↑i + o := by
obtain ⟨i, hi, h'⟩ := (lt_mul_of_limit isLimit_omega0).1 h
obtain ⟨i, rfl⟩ := lt_omega0.1 hi
exact ⟨i, h'.trans_le (le_add_right _ _)⟩
private theorem exists_lt_omega0_opow' {α} {o b : Ordinal} (hb : 1 < b) (ho : o.IsLimit)
{f : α → Ordinal} (H : ∀ ⦃a⦄, a < o → ∃ i, a < f i) ⦃a⦄ (h : a < b ^ o) :
∃ i, a < b ^ f i := by
obtain ⟨d, hd, h'⟩ := (lt_opow_of_limit (zero_lt_one.trans hb).ne' ho).1 h
exact (H hd).imp fun i hi => h'.trans <| (opow_lt_opow_iff_right hb).2 hi
/-- The property satisfied by `fundamentalSequence o`:
* `inl none` means `o = 0`
* `inl (some a)` means `o = succ a`
* `inr f` means `o` is a limit ordinal and `f` is a strictly increasing sequence which converges to
`o` -/
def FundamentalSequenceProp (o : ONote) : (Option ONote) ⊕ (ℕ → ONote) → Prop
| Sum.inl none => o = 0
| Sum.inl (some a) => o.repr = succ a.repr ∧ (o.NF → a.NF)
| Sum.inr f =>
o.repr.IsLimit ∧
(∀ i, f i < f (i + 1) ∧ f i < o ∧ (o.NF → (f i).NF)) ∧ ∀ a, a < o.repr → ∃ i, a < (f i).repr
theorem fundamentalSequenceProp_inl_none (o) :
FundamentalSequenceProp o (Sum.inl none) ↔ o = 0 :=
Iff.rfl
theorem fundamentalSequenceProp_inl_some (o a) :
FundamentalSequenceProp o (Sum.inl (some a)) ↔ o.repr = succ a.repr ∧ (o.NF → a.NF) :=
Iff.rfl
theorem fundamentalSequenceProp_inr (o f) :
FundamentalSequenceProp o (Sum.inr f) ↔
o.repr.IsLimit ∧
(∀ i, f i < f (i + 1) ∧ f i < o ∧ (o.NF → (f i).NF)) ∧
∀ a, a < o.repr → ∃ i, a < (f i).repr :=
Iff.rfl
theorem fundamentalSequence_has_prop (o) : FundamentalSequenceProp o (fundamentalSequence o) := by
induction' o with a m b iha ihb; · exact rfl
rw [fundamentalSequence]
rcases e : b.fundamentalSequence with (⟨_ | b'⟩ | f) <;>
simp only [FundamentalSequenceProp] <;>
rw [e, FundamentalSequenceProp] at ihb
· rcases e : a.fundamentalSequence with (⟨_ | a'⟩ | f) <;> rcases e' : m.natPred with - | m' <;>
simp only [FundamentalSequenceProp] <;>
rw [e, FundamentalSequenceProp] at iha <;>
(try rw [show m = 1 by
have := PNat.natPred_add_one m; rw [e'] at this; exact PNat.coe_inj.1 this.symm]) <;>
(try rw [show m = (m' + 1).succPNat by
rw [← e', ← PNat.coe_inj, Nat.succPNat_coe, ← Nat.add_one, PNat.natPred_add_one]]) <;>
simp only [repr, iha, ihb, opow_lt_opow_iff_right one_lt_omega0, add_lt_add_iff_left,
add_zero, eq_self_iff_true, lt_add_iff_pos_right, lt_def, mul_one, Nat.cast_zero,
Nat.cast_succ, Nat.succPNat_coe, opow_succ, opow_zero, mul_add_one, PNat.one_coe, succ_zero,
_root_.zero_add, zero_def]
· decide
· exact ⟨rfl, inferInstance⟩
· have := opow_pos (repr a') omega0_pos
refine
⟨isLimit_mul this isLimit_omega0, fun i =>
⟨this, ?_, fun H => @NF.oadd_zero _ _ (iha.2 H.fst)⟩, exists_lt_mul_omega0'⟩
rw [← mul_succ, ← natCast_succ, Ordinal.mul_lt_mul_iff_left this]
apply nat_lt_omega0
· have := opow_pos (repr a') omega0_pos
refine
⟨isLimit_add _ (isLimit_mul this isLimit_omega0), fun i => ⟨this, ?_, ?_⟩,
exists_lt_add exists_lt_mul_omega0'⟩
· rw [← mul_succ, ← natCast_succ, Ordinal.mul_lt_mul_iff_left this]
apply nat_lt_omega0
· refine fun H => H.fst.oadd _ (NF.below_of_lt' ?_ (@NF.oadd_zero _ _ (iha.2 H.fst)))
rw [repr, ← zero_def, repr, add_zero, iha.1, opow_succ, Ordinal.mul_lt_mul_iff_left this]
apply nat_lt_omega0
· rcases iha with ⟨h1, h2, h3⟩
refine ⟨isLimit_opow one_lt_omega0 h1, fun i => ?_,
exists_lt_omega0_opow' one_lt_omega0 h1 h3⟩
obtain ⟨h4, h5, h6⟩ := h2 i
exact ⟨h4, h5, fun H => @NF.oadd_zero _ _ (h6 H.fst)⟩
· rcases iha with ⟨h1, h2, h3⟩
refine
⟨isLimit_add _ (isLimit_opow one_lt_omega0 h1), fun i => ?_,
exists_lt_add (exists_lt_omega0_opow' one_lt_omega0 h1 h3)⟩
obtain ⟨h4, h5, h6⟩ := h2 i
refine ⟨h4, h5, fun H => H.fst.oadd _ (NF.below_of_lt' ?_ (@NF.oadd_zero _ _ (h6 H.fst)))⟩
rwa [repr, ← zero_def, repr, add_zero, PNat.one_coe, Nat.cast_one, mul_one,
opow_lt_opow_iff_right one_lt_omega0]
· refine ⟨by
rw [repr, ihb.1, add_succ, repr], fun H => H.fst.oadd _ (NF.below_of_lt' ?_ (ihb.2 H.snd))⟩
have := H.snd'.repr_lt
rw [ihb.1] at this
exact (lt_succ _).trans this
· rcases ihb with ⟨h1, h2, h3⟩
simp only [repr]
exact
⟨Ordinal.isLimit_add _ h1, fun i =>
⟨oadd_lt_oadd_3 (h2 i).1, oadd_lt_oadd_3 (h2 i).2.1, fun H =>
H.fst.oadd _ (NF.below_of_lt' (lt_trans (h2 i).2.1 H.snd'.repr_lt) ((h2 i).2.2 H.snd))⟩,
exists_lt_add h3⟩
/-- The fast growing hierarchy for ordinal notations `< ε₀`. This is a sequence of functions `ℕ → ℕ`
indexed by ordinals, with the definition:
* `f_0(n) = n + 1`
* `f_(α + 1)(n) = f_α^[n](n)`
* `f_α(n) = f_(α[n])(n)` where `α` is a limit ordinal and `α[i]` is the fundamental sequence
converging to `α` -/
def fastGrowing : ONote → ℕ → ℕ
| o =>
match fundamentalSequence o, fundamentalSequence_has_prop o with
| Sum.inl none, _ => Nat.succ
| Sum.inl (some a), h =>
have : a < o := by rw [lt_def, h.1]; apply lt_succ
fun i => (fastGrowing a)^[i] i
| Sum.inr f, h => fun i =>
have : f i < o := (h.2.1 i).2.1
fastGrowing (f i) i
termination_by o => o
-- Porting note: the linter bug should be fixed.
@[nolint unusedHavesSuffices]
theorem fastGrowing_def {o : ONote} {x} (e : fundamentalSequence o = x) :
fastGrowing o =
match
(motive := (x : Option ONote ⊕ (ℕ → ONote)) → FundamentalSequenceProp o x → ℕ → ℕ)
x, e ▸ fundamentalSequence_has_prop o with
| Sum.inl none, _ => Nat.succ
| Sum.inl (some a), _ =>
fun i => (fastGrowing a)^[i] i
| Sum.inr f, _ => fun i =>
fastGrowing (f i) i := by
subst x
rw [fastGrowing]
theorem fastGrowing_zero' (o : ONote) (h : fundamentalSequence o = Sum.inl none) :
fastGrowing o = Nat.succ := by
rw [fastGrowing_def h]
theorem fastGrowing_succ (o) {a} (h : fundamentalSequence o = Sum.inl (some a)) :
fastGrowing o = fun i => (fastGrowing a)^[i] i := by
rw [fastGrowing_def h]
theorem fastGrowing_limit (o) {f} (h : fundamentalSequence o = Sum.inr f) :
fastGrowing o = fun i => fastGrowing (f i) i := by
rw [fastGrowing_def h]
@[simp]
theorem fastGrowing_zero : fastGrowing 0 = Nat.succ :=
fastGrowing_zero' _ rfl
@[simp]
theorem fastGrowing_one : fastGrowing 1 = fun n => 2 * n := by
rw [@fastGrowing_succ 1 0 rfl]; funext i; rw [two_mul, fastGrowing_zero]
suffices ∀ a b, Nat.succ^[a] b = b + a from this _ _
intro a b; induction a <;> simp [*, Function.iterate_succ', Nat.add_assoc, -Function.iterate_succ]
@[simp]
theorem fastGrowing_two : fastGrowing 2 = fun n => (2 ^ n) * n := by
rw [@fastGrowing_succ 2 1 rfl]; funext i; rw [fastGrowing_one]
suffices ∀ a b, (fun n : ℕ => 2 * n)^[a] b = (2 ^ a) * b from this _ _
intro a b; induction a <;>
simp [*, Function.iterate_succ, pow_succ, mul_assoc, -Function.iterate_succ]
/-- We can extend the fast growing hierarchy one more step to `ε₀` itself, using `ω ^ (ω ^ (⋯ ^ ω))`
as the fundamental sequence converging to `ε₀` (which is not an `ONote`). Extending the fast
growing hierarchy beyond this requires a definition of fundamental sequence for larger ordinals. -/
def fastGrowingε₀ (i : ℕ) : ℕ :=
fastGrowing ((fun a => a.oadd 1 0)^[i] 0) i
theorem fastGrowingε₀_zero : fastGrowingε₀ 0 = 1 := by simp [fastGrowingε₀]
theorem fastGrowingε₀_one : fastGrowingε₀ 1 = 2 := by
simp [fastGrowingε₀, show oadd 0 1 0 = 1 from rfl]
theorem fastGrowingε₀_two : fastGrowingε₀ 2 = 2048 := by
norm_num [fastGrowingε₀, show oadd 0 1 0 = 1 from rfl, @fastGrowing_limit (oadd 1 1 0) _ rfl,
show oadd 0 (2 : Nat).succPNat 0 = 3 from rfl, @fastGrowing_succ 3 2 rfl]
end ONote
/-- The type of normal ordinal notations.
It would have been nicer to define this right in the inductive type, but `NF o` requires `repr`
which requires `ONote`, so all these things would have to be defined at once, which messes up the VM
representation. -/
def NONote :=
{ o : ONote // o.NF }
instance : DecidableEq NONote := by unfold NONote; infer_instance
namespace NONote
open ONote
instance NF (o : NONote) : NF o.1 :=
o.2
/-- Construct a `NONote` from an ordinal notation (and infer normality) -/
def mk (o : ONote) [h : ONote.NF o] : NONote :=
⟨o, h⟩
/-- The ordinal represented by an ordinal notation.
This function is noncomputable because ordinal arithmetic is noncomputable. In computational
applications `NONote` can be used exclusively without reference to `Ordinal`, but this function
allows for correctness results to be stated. -/
noncomputable def repr (o : NONote) : Ordinal :=
o.1.repr
instance : ToString NONote :=
⟨fun x => x.1.toString⟩
instance : Repr NONote :=
⟨fun x prec => x.1.repr' prec⟩
instance : Preorder NONote where
le x y := repr x ≤ repr y
lt x y := repr x < repr y
le_refl _ := @le_refl Ordinal _ _
le_trans _ _ _ := @le_trans Ordinal _ _ _ _
lt_iff_le_not_le _ _ := @lt_iff_le_not_le Ordinal _ _ _
instance : Zero NONote :=
⟨⟨0, NF.zero⟩⟩
instance : Inhabited NONote :=
⟨0⟩
theorem lt_wf : @WellFounded NONote (· < ·) :=
InvImage.wf repr Ordinal.lt_wf
instance : WellFoundedLT NONote :=
⟨lt_wf⟩
instance : WellFoundedRelation NONote :=
⟨(· < ·), lt_wf⟩
/-- Convert a natural number to an ordinal notation -/
def ofNat (n : ℕ) : NONote :=
⟨ONote.ofNat n, ⟨⟨_, nfBelow_ofNat _⟩⟩⟩
/-- Compare ordinal notations -/
def cmp (a b : NONote) : Ordering :=
ONote.cmp a.1 b.1
theorem cmp_compares : ∀ a b : NONote, (cmp a b).Compares a b
| | ⟨a, ha⟩, ⟨b, hb⟩ => by
dsimp [cmp]
have := ONote.cmp_compares a b
| Mathlib/SetTheory/Ordinal/Notation.lean | 1,197 | 1,199 |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.LocallyConvex.Basic
/-!
# Balanced Core and Balanced Hull
## Main definitions
* `balancedCore`: The largest balanced subset of a set `s`.
* `balancedHull`: The smallest balanced superset of a set `s`.
## Main statements
* `balancedCore_eq_iInter`: Characterization of the balanced core as an intersection over subsets.
* `nhds_basis_closed_balanced`: The closed balanced sets form a basis of the neighborhood filter.
## Implementation details
The balanced core and hull are implemented differently: for the core we take the obvious definition
of the union over all balanced sets that are contained in `s`, whereas for the hull, we take the
union over `r • s`, for `r` the scalars with `‖r‖ ≤ 1`. We show that `balancedHull` has the
defining properties of a hull in `Balanced.balancedHull_subset_of_subset` and `subset_balancedHull`.
For the core we need slightly stronger assumptions to obtain a characterization as an intersection,
this is `balancedCore_eq_iInter`.
## References
* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]
## Tags
balanced
-/
open Set Pointwise Topology Filter
variable {𝕜 E ι : Type*}
section balancedHull
section SeminormedRing
variable [SeminormedRing 𝕜]
section SMul
variable (𝕜) [SMul 𝕜 E] {s t : Set E} {x : E}
/-- The largest balanced subset of `s`. -/
def balancedCore (s : Set E) :=
⋃₀ { t : Set E | Balanced 𝕜 t ∧ t ⊆ s }
/-- Helper definition to prove `balanced_core_eq_iInter` -/
def balancedCoreAux (s : Set E) :=
⋂ (r : 𝕜) (_ : 1 ≤ ‖r‖), r • s
/-- The smallest balanced superset of `s`. -/
def balancedHull (s : Set E) :=
⋃ (r : 𝕜) (_ : ‖r‖ ≤ 1), r • s
variable {𝕜}
theorem balancedCore_subset (s : Set E) : balancedCore 𝕜 s ⊆ s :=
sUnion_subset fun _ ht => ht.2
theorem balancedCore_empty : balancedCore 𝕜 (∅ : Set E) = ∅ :=
eq_empty_of_subset_empty (balancedCore_subset _)
theorem mem_balancedCore_iff : x ∈ balancedCore 𝕜 s ↔ ∃ t, Balanced 𝕜 t ∧ t ⊆ s ∧ x ∈ t := by
simp_rw [balancedCore, mem_sUnion, mem_setOf_eq, and_assoc]
theorem smul_balancedCore_subset (s : Set E) {a : 𝕜} (ha : ‖a‖ ≤ 1) :
a • balancedCore 𝕜 s ⊆ balancedCore 𝕜 s := by
rintro x ⟨y, hy, rfl⟩
rw [mem_balancedCore_iff] at hy
rcases hy with ⟨t, ht1, ht2, hy⟩
exact ⟨t, ⟨ht1, ht2⟩, ht1 a ha (smul_mem_smul_set hy)⟩
theorem balancedCore_balanced (s : Set E) : Balanced 𝕜 (balancedCore 𝕜 s) := fun _ =>
smul_balancedCore_subset s
/-- The balanced core of `t` is maximal in the sense that it contains any balanced subset
`s` of `t`. -/
theorem Balanced.subset_balancedCore_of_subset (hs : Balanced 𝕜 s) (h : s ⊆ t) :
s ⊆ balancedCore 𝕜 t :=
subset_sUnion_of_mem ⟨hs, h⟩
lemma Balanced.balancedCore_eq (h : Balanced 𝕜 s) : balancedCore 𝕜 s = s :=
le_antisymm (balancedCore_subset _) (h.subset_balancedCore_of_subset (subset_refl _))
theorem mem_balancedCoreAux_iff : x ∈ balancedCoreAux 𝕜 s ↔ ∀ r : 𝕜, 1 ≤ ‖r‖ → x ∈ r • s :=
mem_iInter₂
theorem mem_balancedHull_iff : x ∈ balancedHull 𝕜 s ↔ ∃ r : 𝕜, ‖r‖ ≤ 1 ∧ x ∈ r • s := by
simp [balancedHull]
/-- The balanced hull of `s` is minimal in the sense that it is contained in any balanced superset
`t` of `s`. -/
theorem Balanced.balancedHull_subset_of_subset (ht : Balanced 𝕜 t) (h : s ⊆ t) :
balancedHull 𝕜 s ⊆ t := by
intros x hx
obtain ⟨r, hr, y, hy, rfl⟩ := mem_balancedHull_iff.1 hx
exact ht.smul_mem hr (h hy)
@[mono, gcongr]
theorem balancedHull_mono (hst : s ⊆ t) : balancedHull 𝕜 s ⊆ balancedHull 𝕜 t := by
intro x hx
rw [mem_balancedHull_iff] at *
| obtain ⟨r, hr₁, hr₂⟩ := hx
use r
exact ⟨hr₁, smul_set_mono hst hr₂⟩
end SMul
| Mathlib/Analysis/LocallyConvex/BalancedCoreHull.lean | 114 | 118 |
/-
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.Algebra.Group.Indicator
import Mathlib.Tactic.FinCases
import Mathlib.Topology.Connected.LocallyConnected
import Mathlib.Topology.Sets.Closeds
/-!
# Locally constant functions
This file sets up the theory of locally constant function from a topological space to a type.
## Main definitions and constructions
* `IsLocallyConstant f` : a map `f : X → Y` where `X` is a topological space is locally
constant if every set in `Y` has an open preimage.
* `LocallyConstant X Y` : the type of locally constant maps from `X` to `Y`
* `LocallyConstant.map` : push-forward of locally constant maps
* `LocallyConstant.comap` : pull-back of locally constant maps
-/
variable {X Y Z α : Type*} [TopologicalSpace X]
open Set Filter
open scoped Topology
/-- A function between topological spaces is locally constant if the preimage of any set is open. -/
def IsLocallyConstant (f : X → Y) : Prop :=
∀ s : Set Y, IsOpen (f ⁻¹' s)
namespace IsLocallyConstant
open List in
protected theorem tfae (f : X → Y) :
TFAE [IsLocallyConstant f,
∀ x, ∀ᶠ x' in 𝓝 x, f x' = f x,
∀ x, IsOpen { x' | f x' = f x },
∀ y, IsOpen (f ⁻¹' {y}),
∀ x, ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ ∀ x' ∈ U, f x' = f x] := by
tfae_have 1 → 4 := fun h y => h {y}
tfae_have 4 → 3 := fun h x => h (f x)
tfae_have 3 → 2 := fun h x => IsOpen.mem_nhds (h x) rfl
tfae_have 2 → 5
| h, x => by
rcases mem_nhds_iff.1 (h x) with ⟨U, eq, hU, hx⟩
exact ⟨U, hU, hx, eq⟩
tfae_have 5 → 1
| h, s => by
refine isOpen_iff_forall_mem_open.2 fun x hx ↦ ?_
rcases h x with ⟨U, hU, hxU, eq⟩
exact ⟨U, fun x' hx' => mem_preimage.2 <| (eq x' hx').symm ▸ hx, hU, hxU⟩
tfae_finish
@[nontriviality]
theorem of_discrete [DiscreteTopology X] (f : X → Y) : IsLocallyConstant f := fun _ =>
isOpen_discrete _
theorem isOpen_fiber {f : X → Y} (hf : IsLocallyConstant f) (y : Y) : IsOpen { x | f x = y } :=
hf {y}
theorem isClosed_fiber {f : X → Y} (hf : IsLocallyConstant f) (y : Y) : IsClosed { x | f x = y } :=
⟨hf {y}ᶜ⟩
theorem isClopen_fiber {f : X → Y} (hf : IsLocallyConstant f) (y : Y) : IsClopen { x | f x = y } :=
⟨isClosed_fiber hf _, isOpen_fiber hf _⟩
theorem iff_exists_open (f : X → Y) :
IsLocallyConstant f ↔ ∀ x, ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ ∀ x' ∈ U, f x' = f x :=
(IsLocallyConstant.tfae f).out 0 4
theorem iff_eventually_eq (f : X → Y) : IsLocallyConstant f ↔ ∀ x, ∀ᶠ y in 𝓝 x, f y = f x :=
(IsLocallyConstant.tfae f).out 0 1
theorem exists_open {f : X → Y} (hf : IsLocallyConstant f) (x : X) :
∃ U : Set X, IsOpen U ∧ x ∈ U ∧ ∀ x' ∈ U, f x' = f x :=
(iff_exists_open f).1 hf x
protected theorem eventually_eq {f : X → Y} (hf : IsLocallyConstant f) (x : X) :
∀ᶠ y in 𝓝 x, f y = f x :=
(iff_eventually_eq f).1 hf x
theorem iff_isOpen_fiber_apply {f : X → Y} : IsLocallyConstant f ↔ ∀ x, IsOpen (f ⁻¹' {f x}) :=
(IsLocallyConstant.tfae f).out 0 2
theorem iff_isOpen_fiber {f : X → Y} : IsLocallyConstant f ↔ ∀ y, IsOpen (f ⁻¹' {y}) :=
(IsLocallyConstant.tfae f).out 0 3
protected theorem continuous [TopologicalSpace Y] {f : X → Y} (hf : IsLocallyConstant f) :
Continuous f :=
⟨fun _ _ => hf _⟩
theorem iff_continuous {_ : TopologicalSpace Y} [DiscreteTopology Y] (f : X → Y) :
IsLocallyConstant f ↔ Continuous f :=
⟨IsLocallyConstant.continuous, fun h s => h.isOpen_preimage s (isOpen_discrete _)⟩
theorem of_constant (f : X → Y) (h : ∀ x y, f x = f y) : IsLocallyConstant f :=
(iff_eventually_eq f).2 fun _ => Eventually.of_forall fun _ => h _ _
protected theorem const (y : Y) : IsLocallyConstant (Function.const X y) :=
of_constant _ fun _ _ => rfl
protected theorem comp {f : X → Y} (hf : IsLocallyConstant f) (g : Y → Z) :
IsLocallyConstant (g ∘ f) := fun s => by
rw [Set.preimage_comp]
exact hf _
theorem prodMk {Y'} {f : X → Y} {f' : X → Y'} (hf : IsLocallyConstant f)
(hf' : IsLocallyConstant f') : IsLocallyConstant fun x => (f x, f' x) :=
(iff_eventually_eq _).2 fun x =>
(hf.eventually_eq x).mp <| (hf'.eventually_eq x).mono fun _ hf' hf => Prod.ext hf hf'
@[deprecated (since := "2025-03-10")]
alias prod_mk := prodMk
theorem comp₂ {Y₁ Y₂ Z : Type*} {f : X → Y₁} {g : X → Y₂} (hf : IsLocallyConstant f)
(hg : IsLocallyConstant g) (h : Y₁ → Y₂ → Z) : IsLocallyConstant fun x => h (f x) (g x) :=
(hf.prodMk hg).comp fun x : Y₁ × Y₂ => h x.1 x.2
theorem comp_continuous [TopologicalSpace Y] {g : Y → Z} {f : X → Y} (hg : IsLocallyConstant g)
(hf : Continuous f) : IsLocallyConstant (g ∘ f) := fun s => by
rw [Set.preimage_comp]
exact hf.isOpen_preimage _ (hg _)
/-- A locally constant function is constant on any preconnected set. -/
theorem apply_eq_of_isPreconnected {f : X → Y} (hf : IsLocallyConstant f) {s : Set X}
(hs : IsPreconnected s) {x y : X} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by
let U := f ⁻¹' {f y}
suffices x ∉ Uᶜ from Classical.not_not.1 this
intro hxV
specialize hs U Uᶜ (hf {f y}) (hf {f y}ᶜ) _ ⟨y, ⟨hy, rfl⟩⟩ ⟨x, ⟨hx, hxV⟩⟩
· simp only [union_compl_self, subset_univ]
· simp only [inter_empty, Set.not_nonempty_empty, inter_compl_self] at hs
theorem apply_eq_of_preconnectedSpace [PreconnectedSpace X] {f : X → Y} (hf : IsLocallyConstant f)
(x y : X) : f x = f y :=
hf.apply_eq_of_isPreconnected isPreconnected_univ trivial trivial
theorem eq_const [PreconnectedSpace X] {f : X → Y} (hf : IsLocallyConstant f) (x : X) :
f = Function.const X (f x) :=
funext fun y => hf.apply_eq_of_preconnectedSpace y x
theorem exists_eq_const [PreconnectedSpace X] [Nonempty Y] {f : X → Y} (hf : IsLocallyConstant f) :
∃ y, f = Function.const X y := by
rcases isEmpty_or_nonempty X with h | h
· exact ⟨Classical.arbitrary Y, funext <| h.elim⟩
· exact ⟨f (Classical.arbitrary X), hf.eq_const _⟩
theorem iff_is_const [PreconnectedSpace X] {f : X → Y} : IsLocallyConstant f ↔ ∀ x y, f x = f y :=
⟨fun h _ _ => h.apply_eq_of_isPreconnected isPreconnected_univ trivial trivial, of_constant _⟩
theorem range_finite [CompactSpace X] {f : X → Y} (hf : IsLocallyConstant f) :
(Set.range f).Finite := by
letI : TopologicalSpace Y := ⊥; haveI := discreteTopology_bot Y
exact (isCompact_range hf.continuous).finite_of_discrete
@[to_additive]
theorem one [One Y] : IsLocallyConstant (1 : X → Y) := IsLocallyConstant.const 1
@[to_additive]
theorem inv [Inv Y] ⦃f : X → Y⦄ (hf : IsLocallyConstant f) : IsLocallyConstant f⁻¹ :=
hf.comp fun x => x⁻¹
@[to_additive]
theorem mul [Mul Y] ⦃f g : X → Y⦄ (hf : IsLocallyConstant f) (hg : IsLocallyConstant g) :
IsLocallyConstant (f * g) :=
hf.comp₂ hg (· * ·)
@[to_additive]
theorem div [Div Y] ⦃f g : X → Y⦄ (hf : IsLocallyConstant f) (hg : IsLocallyConstant g) :
IsLocallyConstant (f / g) :=
hf.comp₂ hg (· / ·)
/-- If a composition of a function `f` followed by an injection `g` is locally
constant, then the locally constant property descends to `f`. -/
theorem desc {α β : Type*} (f : X → α) (g : α → β) (h : IsLocallyConstant (g ∘ f))
(inj : Function.Injective g) : IsLocallyConstant f := fun s => by
rw [← preimage_image_eq s inj, preimage_preimage]
exact h (g '' s)
theorem of_constant_on_connected_components [LocallyConnectedSpace X] {f : X → Y}
(h : ∀ x, ∀ y ∈ connectedComponent x, f y = f x) : IsLocallyConstant f :=
(iff_exists_open _).2 fun x =>
⟨connectedComponent x, isOpen_connectedComponent, mem_connectedComponent, h x⟩
theorem of_constant_on_connected_clopens [LocallyConnectedSpace X] {f : X → Y}
(h : ∀ U : Set X, IsConnected U → IsClopen U → ∀ x ∈ U, ∀ y ∈ U, f y = f x) :
IsLocallyConstant f :=
of_constant_on_connected_components fun x =>
h (connectedComponent x) isConnected_connectedComponent isClopen_connectedComponent x
mem_connectedComponent
theorem of_constant_on_preconnected_clopens [LocallyConnectedSpace X] {f : X → Y}
(h : ∀ U : Set X, IsPreconnected U → IsClopen U → ∀ x ∈ U, ∀ y ∈ U, f y = f x) :
IsLocallyConstant f :=
of_constant_on_connected_clopens fun U hU ↦ h U hU.isPreconnected
end IsLocallyConstant
/-- A (bundled) locally constant function from a topological space `X` to a type `Y`. -/
structure LocallyConstant (X Y : Type*) [TopologicalSpace X] where
/-- The underlying function. -/
protected toFun : X → Y
/-- The map is locally constant. -/
protected isLocallyConstant : IsLocallyConstant toFun
namespace LocallyConstant
instance [Inhabited Y] : Inhabited (LocallyConstant X Y) :=
⟨⟨_, IsLocallyConstant.const default⟩⟩
instance : FunLike (LocallyConstant X Y) X Y where
coe := LocallyConstant.toFun
coe_injective' := by rintro ⟨_, _⟩ ⟨_, _⟩ _; congr
/-- See Note [custom simps projections]. -/
def Simps.apply (f : LocallyConstant X Y) : X → Y := f
initialize_simps_projections LocallyConstant (toFun → apply)
@[simp]
theorem toFun_eq_coe (f : LocallyConstant X Y) : f.toFun = f :=
rfl
@[simp]
theorem coe_mk (f : X → Y) (h) : ⇑(⟨f, h⟩ : LocallyConstant X Y) = f :=
rfl
protected theorem congr_fun {f g : LocallyConstant X Y} (h : f = g) (x : X) : f x = g x :=
DFunLike.congr_fun h x
protected theorem congr_arg (f : LocallyConstant X Y) {x y : X} (h : x = y) : f x = f y :=
DFunLike.congr_arg f h
theorem coe_injective : @Function.Injective (LocallyConstant X Y) (X → Y) (↑) := fun _ _ =>
DFunLike.ext'
@[norm_cast]
theorem coe_inj {f g : LocallyConstant X Y} : (f : X → Y) = g ↔ f = g :=
coe_injective.eq_iff
@[ext]
theorem ext ⦃f g : LocallyConstant X Y⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext _ _ h
section CodomainTopologicalSpace
variable [TopologicalSpace Y] (f : LocallyConstant X Y)
protected theorem continuous : Continuous f :=
f.isLocallyConstant.continuous
/-- We can turn a locally-constant function into a bundled `ContinuousMap`. -/
@[coe] def toContinuousMap : C(X, Y) :=
⟨f, f.continuous⟩
/-- As a shorthand, `LocallyConstant.toContinuousMap` is available as a coercion -/
instance : Coe (LocallyConstant X Y) C(X, Y) := ⟨toContinuousMap⟩
-- Porting note: became a syntactic `rfl`
@[simp] theorem coe_continuousMap : ((f : C(X, Y)) : X → Y) = (f : X → Y) := rfl
theorem toContinuousMap_injective :
Function.Injective (toContinuousMap : LocallyConstant X Y → C(X, Y)) := fun _ _ h =>
ext (ContinuousMap.congr_fun h)
end CodomainTopologicalSpace
/-- The constant locally constant function on `X` with value `y : Y`. -/
def const (X : Type*) {Y : Type*} [TopologicalSpace X] (y : Y) : LocallyConstant X Y :=
⟨Function.const X y, IsLocallyConstant.const _⟩
@[simp]
theorem coe_const (y : Y) : (const X y : X → Y) = Function.const X y :=
rfl
/-- Evaluation/projection as a locally constant function. -/
@[simps]
def eval {ι : Type*} {X : ι → Type*}
[∀ i, TopologicalSpace (X i)] (i : ι) [DiscreteTopology (X i)] :
LocallyConstant (Π i, X i) (X i) where
toFun := fun f ↦ f i
isLocallyConstant := (IsLocallyConstant.iff_continuous _).mpr <| continuous_apply i
/-- The locally constant function to `Fin 2` associated to a clopen set. -/
def ofIsClopen {X : Type*} [TopologicalSpace X] {U : Set X} [∀ x, Decidable (x ∈ U)]
(hU : IsClopen U) : LocallyConstant X (Fin 2) where
toFun x := if x ∈ U then 0 else 1
isLocallyConstant := by
refine IsLocallyConstant.iff_isOpen_fiber.2 <| Fin.forall_fin_two.2 ⟨?_, ?_⟩
· convert hU.2 using 1
ext
simp only [mem_singleton_iff, Fin.one_eq_zero_iff, mem_preimage, ite_eq_left_iff,
Nat.succ_succ_ne_one]
tauto
· rw [← isClosed_compl_iff]
convert hU.1
ext
simp
@[simp]
theorem ofIsClopen_fiber_zero {X : Type*} [TopologicalSpace X] {U : Set X} [∀ x, Decidable (x ∈ U)]
(hU : IsClopen U) : ofIsClopen hU ⁻¹' ({0} : Set (Fin 2)) = U := by
ext
simp only [ofIsClopen, mem_singleton_iff, Fin.one_eq_zero_iff, coe_mk, mem_preimage,
ite_eq_left_iff, Nat.succ_succ_ne_one]
tauto
@[simp]
theorem ofIsClopen_fiber_one {X : Type*} [TopologicalSpace X] {U : Set X} [∀ x, Decidable (x ∈ U)]
(hU : IsClopen U) : ofIsClopen hU ⁻¹' ({1} : Set (Fin 2)) = Uᶜ := by
ext
simp only [ofIsClopen, mem_singleton_iff, coe_mk, Fin.zero_eq_one_iff, mem_preimage,
ite_eq_right_iff, mem_compl_iff, Nat.succ_succ_ne_one]
theorem locallyConstant_eq_of_fiber_zero_eq {X : Type*} [TopologicalSpace X]
(f g : LocallyConstant X (Fin 2)) (h : f ⁻¹' ({0} : Set (Fin 2)) = g ⁻¹' {0}) : f = g := by
simp only [Set.ext_iff, mem_singleton_iff, mem_preimage] at h
ext1 x
exact Fin.fin_two_eq_of_eq_zero_iff (h x)
theorem range_finite [CompactSpace X] (f : LocallyConstant X Y) : (Set.range f).Finite :=
f.isLocallyConstant.range_finite
theorem apply_eq_of_isPreconnected (f : LocallyConstant X Y) {s : Set X} (hs : IsPreconnected s)
{x y : X} (hx : x ∈ s) (hy : y ∈ s) : f x = f y :=
f.isLocallyConstant.apply_eq_of_isPreconnected hs hx hy
theorem apply_eq_of_preconnectedSpace [PreconnectedSpace X] (f : LocallyConstant X Y) (x y : X) :
f x = f y :=
f.isLocallyConstant.apply_eq_of_isPreconnected isPreconnected_univ trivial trivial
theorem eq_const [PreconnectedSpace X] (f : LocallyConstant X Y) (x : X) : f = const X (f x) :=
ext fun _ => apply_eq_of_preconnectedSpace f _ _
theorem exists_eq_const [PreconnectedSpace X] [Nonempty Y] (f : LocallyConstant X Y) :
∃ y, f = const X y := by
rcases Classical.em (Nonempty X) with (⟨⟨x⟩⟩ | hX)
· exact ⟨f x, f.eq_const x⟩
· exact ⟨Classical.arbitrary Y, ext fun x => (hX ⟨x⟩).elim⟩
/-- Push forward of locally constant maps under any map, by post-composition. -/
def map (f : Y → Z) (g : LocallyConstant X Y) : LocallyConstant X Z :=
⟨f ∘ g, g.isLocallyConstant.comp f⟩
@[simp]
theorem map_apply (f : Y → Z) (g : LocallyConstant X Y) : ⇑(map f g) = f ∘ g :=
rfl
@[simp]
theorem map_id : @map X Y Y _ id = id := rfl
@[simp]
theorem map_comp {Y₁ Y₂ Y₃ : Type*} (g : Y₂ → Y₃) (f : Y₁ → Y₂) :
@map X _ _ _ g ∘ map f = map (g ∘ f) := rfl
/-- Given a locally constant function to `α → β`, construct a family of locally constant
functions with values in β indexed by α. -/
def flip {X α β : Type*} [TopologicalSpace X] (f : LocallyConstant X (α → β)) (a : α) :
LocallyConstant X β :=
f.map fun f => f a
/-- If α is finite, this constructs a locally constant function to `α → β` given a
family of locally constant functions with values in β indexed by α. -/
def unflip {X α β : Type*} [Finite α] [TopologicalSpace X] (f : α → LocallyConstant X β) :
LocallyConstant X (α → β) where
toFun x a := f a x
isLocallyConstant := IsLocallyConstant.iff_isOpen_fiber.2 fun g => by
have : (fun (x : X) (a : α) => f a x) ⁻¹' {g} = ⋂ a : α, f a ⁻¹' {g a} := by
ext; simp [funext_iff]
rw [this]
exact isOpen_iInter_of_finite fun a => (f a).isLocallyConstant _
@[simp]
theorem unflip_flip {X α β : Type*} [Finite α] [TopologicalSpace X]
(f : LocallyConstant X (α → β)) : unflip f.flip = f := rfl
@[simp]
theorem flip_unflip {X α β : Type*} [Finite α] [TopologicalSpace X]
(f : α → LocallyConstant X β) : (unflip f).flip = f := rfl
section Comap
variable [TopologicalSpace Y]
/-- Pull back of locally constant maps under a continuous map, by pre-composition. -/
def comap (f : C(X, Y)) (g : LocallyConstant Y Z) : LocallyConstant X Z :=
⟨g ∘ f, g.isLocallyConstant.comp_continuous f.continuous⟩
@[simp]
theorem coe_comap (f : C(X, Y)) (g : LocallyConstant Y Z) :
(comap f g) = g ∘ f := rfl
|
theorem coe_comap_apply (f : C(X, Y)) (g : LocallyConstant Y Z) (x : X) :
comap f g x = g (f x) := rfl
@[simp]
| Mathlib/Topology/LocallyConstant/Basic.lean | 396 | 400 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Kim Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
/-!
# Specific subobjects
We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects
represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions
for `P.factors f`, where `P` is one of these special subobjects.
TODO: Add conditions for when `P` is a pullback subobject.
TODO: an iff characterisation of `(imageSubobject f).Factors h`
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace CategoryTheory
namespace Limits
section Equalizer
variable (f g : X ⟶ Y) [HasEqualizer f g]
/-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/
abbrev equalizerSubobject : Subobject X :=
Subobject.mk (equalizer.ι f g)
/-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!)
the same as the chosen object `equalizer f g`. -/
def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g :=
Subobject.underlyingIso (equalizer.ι f g)
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow :
(equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by
simp [equalizerSubobjectIso]
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow' :
(equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by
simp [equalizerSubobjectIso]
@[reassoc]
theorem equalizerSubobject_arrow_comp :
(equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by
rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition]
theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) :
(equalizerSubobject f g).Factors h :=
⟨equalizer.lift h w, by simp⟩
theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) :
(equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp,
Category.assoc],
equalizerSubobject_factors f g h⟩
end Equalizer
section Kernel
variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f]
/-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/
abbrev kernelSubobject : Subobject X :=
Subobject.mk (kernel.ι f)
/-- The underlying object of `kernelSubobject f` is (up to isomorphism!)
the same as the chosen object `kernel f`. -/
def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f :=
Subobject.underlyingIso (kernel.ι f)
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow :
(kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by
simp [kernelSubobjectIso]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow' :
(kernelSubobjectIso f).inv ≫ (kernelSubobject f).arrow = kernel.ι f := by
simp [kernelSubobjectIso]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow_comp : (kernelSubobject f).arrow ≫ f = 0 := by
rw [← kernelSubobject_arrow]
simp only [Category.assoc, kernel.condition, comp_zero]
theorem kernelSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
(kernelSubobject f).Factors h :=
⟨kernel.lift _ h w, by simp⟩
theorem kernelSubobject_factors_iff {W : C} (h : W ⟶ X) :
(kernelSubobject f).Factors h ↔ h ≫ f = 0 :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp,
comp_zero],
kernelSubobject_factors f h⟩
/-- A factorisation of `h : W ⟶ X` through `kernelSubobject f`, assuming `h ≫ f = 0`. -/
def factorThruKernelSubobject {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : W ⟶ kernelSubobject f :=
(kernelSubobject f).factorThru h (kernelSubobject_factors f h w)
@[simp]
theorem factorThruKernelSubobject_comp_arrow {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobject f).arrow = h := by
dsimp [factorThruKernelSubobject]
simp
@[simp]
theorem factorThruKernelSubobject_comp_kernelSubobjectIso {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom = kernel.lift f h w :=
(cancel_mono (kernel.ι f)).1 <| by simp
section
variable {f} {X' Y' : C} {f' : X' ⟶ Y'} [HasKernel f']
/-- A commuting square induces a morphism between the kernel subobjects. -/
def kernelSubobjectMap (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobject f : C) ⟶ (kernelSubobject f' : C) :=
Subobject.factorThru _ ((kernelSubobject f).arrow ≫ sq.left)
(kernelSubobject_factors _ _ (by simp [sq.w]))
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobjectMap_arrow (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernelSubobjectMap sq ≫ (kernelSubobject f').arrow = (kernelSubobject f).arrow ≫ sq.left := by
simp [kernelSubobjectMap]
@[simp]
theorem kernelSubobjectMap_id : kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 _ := by aesop_cat
@[simp]
theorem kernelSubobjectMap_comp {X'' Y'' : C} {f'' : X'' ⟶ Y''} [HasKernel f'']
(sq : Arrow.mk f ⟶ Arrow.mk f') (sq' : Arrow.mk f' ⟶ Arrow.mk f'') :
kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' := by
aesop_cat
@[reassoc]
theorem kernel_map_comp_kernelSubobjectIso_inv (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernel.map f f' sq.1 sq.2 sq.3.symm ≫ (kernelSubobjectIso _).inv =
(kernelSubobjectIso _).inv ≫ kernelSubobjectMap sq := by aesop_cat
@[reassoc]
theorem kernelSubobjectIso_comp_kernel_map (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobjectIso _).hom ≫ kernel.map f f' sq.1 sq.2 sq.3.symm =
kernelSubobjectMap sq ≫ (kernelSubobjectIso _).hom := by
simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv]
end
@[simp]
theorem kernelSubobject_zero {A B : C} : kernelSubobject (0 : A ⟶ B) = ⊤ :=
(isIso_iff_mk_eq_top _).mp (by infer_instance)
instance isIso_kernelSubobject_zero_arrow : IsIso (kernelSubobject (0 : X ⟶ Y)).arrow :=
(isIso_arrow_iff_eq_top _).mpr kernelSubobject_zero
theorem le_kernelSubobject (A : Subobject X) (h : A.arrow ≫ f = 0) : A ≤ kernelSubobject f :=
Subobject.le_mk_of_comm (kernel.lift f A.arrow h) (by simp)
/-- The isomorphism between the kernel of `f ≫ g` and the kernel of `g`,
| when `f` is an isomorphism.
-/
def kernelSubobjectIsoComp {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
| Mathlib/CategoryTheory/Subobject/Limits.lean | 175 | 177 |
/-
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.Order.Ring.Defs
import Mathlib.Algebra.Field.Defs
/-!
# Linear ordered (semi)fields
A linear ordered (semi)field is a (semi)field equipped with a linear order such that
* addition respects the order: `a ≤ b → c + a ≤ c + b`;
* multiplication of positives is positive: `0 < a → 0 < b → 0 < a * b`;
* `0 < 1`.
## Main Definitions
* `LinearOrderedSemifield`: Typeclass for linear order semifields.
* `LinearOrderedField`: Typeclass for linear ordered fields.
-/
-- Guard against import creep.
assert_not_exists MonoidHom
set_option linter.deprecated false in
/-- A linear ordered semifield is a field with a linear order respecting the operations. -/
@[deprecated "Use `[Semifield K] [LinearOrder K] [IsStrictOrderedRing K]` instead."
(since := "2025-04-10")]
structure LinearOrderedSemifield (K : Type*) extends LinearOrderedCommSemiring K, Semifield K
set_option linter.deprecated false in
/-- A linear ordered field is a field with a linear order respecting the operations. -/
@[deprecated "Use `[Field K] [LinearOrder K] [IsStrictOrderedRing K]` instead."
(since := "2025-04-10")]
structure LinearOrderedField (K : Type*) extends LinearOrderedCommRing K, Field K
attribute [nolint docBlame] LinearOrderedSemifield.toSemifield LinearOrderedField.toField
| Mathlib/Algebra/Order/Field/Defs.lean | 91 | 92 | |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Tactic.Attr.Register
import Mathlib.Tactic.Basic
import Batteries.Logic
import Batteries.Tactic.Trans
import Batteries.Util.LibraryNote
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Int.Notation
/-!
# Basic logic properties
This file is one of the earliest imports in mathlib.
## Implementation notes
Theorems that require decidability hypotheses are in the namespace `Decidable`.
Classical versions are in the namespace `Classical`.
-/
open Function
section Miscellany
-- attribute [refl] HEq.refl -- FIXME This is still rejected after https://github.com/leanprover-community/mathlib4/pull/857
attribute [trans] Iff.trans HEq.trans heq_of_eq_of_heq
attribute [simp] cast_heq
/-- An identity function with its main argument implicit. This will be printed as `hidden` even
if it is applied to a large term, so it can be used for elision,
as done in the `elide` and `unelide` tactics. -/
abbrev hidden {α : Sort*} {a : α} := a
variable {α : Sort*}
instance (priority := 10) decidableEq_of_subsingleton [Subsingleton α] : DecidableEq α :=
fun a b ↦ isTrue (Subsingleton.elim a b)
instance [Subsingleton α] (p : α → Prop) : Subsingleton (Subtype p) :=
⟨fun ⟨x, _⟩ ⟨y, _⟩ ↦ by cases Subsingleton.elim x y; rfl⟩
theorem congr_heq {α β γ : Sort _} {f : α → γ} {g : β → γ} {x : α} {y : β}
(h₁ : HEq f g) (h₂ : HEq x y) : f x = g y := by
cases h₂; cases h₁; rfl
theorem congr_arg_heq {β : α → Sort*} (f : ∀ a, β a) :
∀ {a₁ a₂ : α}, a₁ = a₂ → HEq (f a₁) (f a₂)
| _, _, rfl => HEq.rfl
@[simp] theorem eq_iff_eq_cancel_left {b c : α} : (∀ {a}, a = b ↔ a = c) ↔ b = c :=
⟨fun h ↦ by rw [← h], fun h a ↦ by rw [h]⟩
@[simp] theorem eq_iff_eq_cancel_right {a b : α} : (∀ {c}, a = c ↔ b = c) ↔ a = b :=
⟨fun h ↦ by rw [h], fun h a ↦ by rw [h]⟩
lemma ne_and_eq_iff_right {a b c : α} (h : b ≠ c) : a ≠ b ∧ a = c ↔ a = c :=
and_iff_right_of_imp (fun h2 => h2.symm ▸ h.symm)
/-- Wrapper for adding elementary propositions to the type class systems.
Warning: this can easily be abused. See the rest of this docstring for details.
Certain propositions should not be treated as a class globally,
but sometimes it is very convenient to be able to use the type class system
in specific circumstances.
For example, `ZMod p` is a field if and only if `p` is a prime number.
In order to be able to find this field instance automatically by type class search,
we have to turn `p.prime` into an instance implicit assumption.
On the other hand, making `Nat.prime` a class would require a major refactoring of the library,
and it is questionable whether making `Nat.prime` a class is desirable at all.
The compromise is to add the assumption `[Fact p.prime]` to `ZMod.field`.
In particular, this class is not intended for turning the type class system
into an automated theorem prover for first order logic. -/
class Fact (p : Prop) : Prop where
/-- `Fact.out` contains the unwrapped witness for the fact represented by the instance of
`Fact p`. -/
out : p
library_note "fact non-instances"/--
In most cases, we should not have global instances of `Fact`; typeclass search only reads the head
symbol and then tries any instances, which means that adding any such instance will cause slowdowns
everywhere. We instead make them as lemmata and make them local instances as required.
-/
theorem Fact.elim {p : Prop} (h : Fact p) : p := h.1
theorem fact_iff {p : Prop} : Fact p ↔ p := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩
instance {p : Prop} [Decidable p] : Decidable (Fact p) :=
decidable_of_iff _ fact_iff.symm
/-- Swaps two pairs of arguments to a function. -/
abbrev Function.swap₂ {ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*}
{φ : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Sort*} (f : ∀ i₁ j₁ i₂ j₂, φ i₁ j₁ i₂ j₂)
(i₂ j₂ i₁ j₁) : φ i₁ j₁ i₂ j₂ := f i₁ j₁ i₂ j₂
end Miscellany
open Function
/-!
### Declarations about propositional connectives
-/
section Propositional
/-! ### Declarations about `implies` -/
alias Iff.imp := imp_congr
-- This is a duplicate of `Classical.imp_iff_right_iff`. Deprecate?
theorem imp_iff_right_iff {a b : Prop} : (a → b ↔ b) ↔ a ∨ b :=
open scoped Classical in Decidable.imp_iff_right_iff
-- This is a duplicate of `Classical.and_or_imp`. Deprecate?
theorem and_or_imp {a b c : Prop} : a ∧ b ∨ (a → c) ↔ a → b ∨ c :=
open scoped Classical in Decidable.and_or_imp
/-- Provide modus tollens (`mt`) as dot notation for implications. -/
protected theorem Function.mt {a b : Prop} : (a → b) → ¬b → ¬a := mt
/-! ### Declarations about `not` -/
alias dec_em := Decidable.em
theorem dec_em' (p : Prop) [Decidable p] : ¬p ∨ p := (dec_em p).symm
alias em := Classical.em
theorem em' (p : Prop) : ¬p ∨ p := (em p).symm
theorem or_not {p : Prop} : p ∨ ¬p := em _
theorem Decidable.eq_or_ne {α : Sort*} (x y : α) [Decidable (x = y)] : x = y ∨ x ≠ y :=
dec_em <| x = y
theorem Decidable.ne_or_eq {α : Sort*} (x y : α) [Decidable (x = y)] : x ≠ y ∨ x = y :=
dec_em' <| x = y
theorem eq_or_ne {α : Sort*} (x y : α) : x = y ∨ x ≠ y := em <| x = y
theorem ne_or_eq {α : Sort*} (x y : α) : x ≠ y ∨ x = y := em' <| x = y
theorem by_contradiction {p : Prop} : (¬p → False) → p :=
open scoped Classical in Decidable.byContradiction
theorem by_cases {p q : Prop} (hpq : p → q) (hnpq : ¬p → q) : q :=
open scoped Classical in if hp : p then hpq hp else hnpq hp
alias by_contra := by_contradiction
library_note "decidable namespace"/--
In most of mathlib, we use the law of excluded middle (LEM) and the axiom of choice (AC) freely.
The `Decidable` namespace contains versions of lemmas from the root namespace that explicitly
attempt to avoid the axiom of choice, usually by adding decidability assumptions on the inputs.
You can check if a lemma uses the axiom of choice by using `#print axioms foo` and seeing if
`Classical.choice` appears in the list.
-/
library_note "decidable arguments"/--
As mathlib is primarily classical,
if the type signature of a `def` or `lemma` does not require any `Decidable` instances to state,
it is preferable not to introduce any `Decidable` instances that are needed in the proof
as arguments, but rather to use the `classical` tactic as needed.
In the other direction, when `Decidable` instances do appear in the type signature,
it is better to use explicitly introduced ones rather than allowing Lean to automatically infer
classical ones, as these may cause instance mismatch errors later.
-/
export Classical (not_not)
attribute [simp] not_not
variable {a b : Prop}
theorem of_not_not {a : Prop} : ¬¬a → a := by_contra
theorem not_ne_iff {α : Sort*} {a b : α} : ¬a ≠ b ↔ a = b := not_not
theorem of_not_imp : ¬(a → b) → a := open scoped Classical in Decidable.of_not_imp
alias Not.decidable_imp_symm := Decidable.not_imp_symm
theorem Not.imp_symm : (¬a → b) → ¬b → a := open scoped Classical in Not.decidable_imp_symm
theorem not_imp_comm : ¬a → b ↔ ¬b → a := open scoped Classical in Decidable.not_imp_comm
@[simp] theorem not_imp_self : ¬a → a ↔ a := open scoped Classical in Decidable.not_imp_self
theorem Imp.swap {a b : Sort*} {c : Prop} : a → b → c ↔ b → a → c :=
⟨fun h x y ↦ h y x, fun h x y ↦ h y x⟩
alias Iff.not := not_congr
theorem Iff.not_left (h : a ↔ ¬b) : ¬a ↔ b := h.not.trans not_not
theorem Iff.not_right (h : ¬a ↔ b) : a ↔ ¬b := not_not.symm.trans h.not
protected lemma Iff.ne {α β : Sort*} {a b : α} {c d : β} : (a = b ↔ c = d) → (a ≠ b ↔ c ≠ d) :=
Iff.not
lemma Iff.ne_left {α β : Sort*} {a b : α} {c d : β} : (a = b ↔ c ≠ d) → (a ≠ b ↔ c = d) :=
Iff.not_left
lemma Iff.ne_right {α β : Sort*} {a b : α} {c d : β} : (a ≠ b ↔ c = d) → (a = b ↔ c ≠ d) :=
Iff.not_right
/-! ### Declarations about `Xor'` -/
/-- `Xor' a b` is the exclusive-or of propositions. -/
def Xor' (a b : Prop) := (a ∧ ¬b) ∨ (b ∧ ¬a)
instance [Decidable a] [Decidable b] : Decidable (Xor' a b) := inferInstanceAs (Decidable (Or ..))
@[simp] theorem xor_true : Xor' True = Not := by
simp +unfoldPartialApp [Xor']
@[simp] theorem xor_false : Xor' False = id := by ext; simp [Xor']
theorem xor_comm (a b : Prop) : Xor' a b = Xor' b a := by simp [Xor', and_comm, or_comm]
instance : Std.Commutative Xor' := ⟨xor_comm⟩
@[simp] theorem xor_self (a : Prop) : Xor' a a = False := by simp [Xor']
@[simp] theorem xor_not_left : Xor' (¬a) b ↔ (a ↔ b) := by by_cases a <;> simp [*]
@[simp] theorem xor_not_right : Xor' a (¬b) ↔ (a ↔ b) := by by_cases a <;> simp [*]
theorem xor_not_not : Xor' (¬a) (¬b) ↔ Xor' a b := by simp [Xor', or_comm, and_comm]
protected theorem Xor'.or (h : Xor' a b) : a ∨ b := h.imp And.left And.left
/-! ### Declarations about `and` -/
alias Iff.and := and_congr
alias ⟨And.rotate, _⟩ := and_rotate
theorem and_symm_right {α : Sort*} (a b : α) (p : Prop) : p ∧ a = b ↔ p ∧ b = a := by simp [eq_comm]
theorem and_symm_left {α : Sort*} (a b : α) (p : Prop) : a = b ∧ p ↔ b = a ∧ p := by simp [eq_comm]
/-! ### Declarations about `or` -/
alias Iff.or := or_congr
alias ⟨Or.rotate, _⟩ := or_rotate
theorem Or.elim3 {c d : Prop} (h : a ∨ b ∨ c) (ha : a → d) (hb : b → d) (hc : c → d) : d :=
Or.elim h ha fun h₂ ↦ Or.elim h₂ hb hc
theorem Or.imp3 {d e c f : Prop} (had : a → d) (hbe : b → e) (hcf : c → f) :
a ∨ b ∨ c → d ∨ e ∨ f :=
Or.imp had <| Or.imp hbe hcf
export Classical (or_iff_not_imp_left or_iff_not_imp_right)
theorem not_or_of_imp : (a → b) → ¬a ∨ b := open scoped Classical in Decidable.not_or_of_imp
-- See Note [decidable namespace]
protected theorem Decidable.or_not_of_imp [Decidable a] (h : a → b) : b ∨ ¬a :=
dite _ (Or.inl ∘ h) Or.inr
theorem or_not_of_imp : (a → b) → b ∨ ¬a := open scoped Classical in Decidable.or_not_of_imp
theorem imp_iff_not_or : a → b ↔ ¬a ∨ b := open scoped Classical in Decidable.imp_iff_not_or
theorem imp_iff_or_not {b a : Prop} : b → a ↔ a ∨ ¬b :=
open scoped Classical in Decidable.imp_iff_or_not
theorem not_imp_not : ¬a → ¬b ↔ b → a := open scoped Classical in Decidable.not_imp_not
theorem imp_and_neg_imp_iff (p q : Prop) : (p → q) ∧ (¬p → q) ↔ q := by simp
/-- Provide the reverse of modus tollens (`mt`) as dot notation for implications. -/
protected theorem Function.mtr : (¬a → ¬b) → b → a := not_imp_not.mp
theorem or_congr_left' {c a b : Prop} (h : ¬c → (a ↔ b)) : a ∨ c ↔ b ∨ c :=
open scoped Classical in Decidable.or_congr_left' h
theorem or_congr_right' {c : Prop} (h : ¬a → (b ↔ c)) : a ∨ b ↔ a ∨ c :=
open scoped Classical in Decidable.or_congr_right' h
/-! ### Declarations about distributivity -/
/-! Declarations about `iff` -/
alias Iff.iff := iff_congr
-- @[simp] -- FIXME simp ignores proof rewrites
theorem iff_mpr_iff_true_intro {P : Prop} (h : P) : Iff.mpr (iff_true_intro h) True.intro = h := rfl
theorem imp_or {a b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) :=
open scoped Classical in Decidable.imp_or
theorem imp_or' {a : Sort*} {b c : Prop} : a → b ∨ c ↔ (a → b) ∨ (a → c) :=
open scoped Classical in Decidable.imp_or'
theorem not_imp : ¬(a → b) ↔ a ∧ ¬b := open scoped Classical in Decidable.not_imp_iff_and_not
theorem peirce (a b : Prop) : ((a → b) → a) → a := open scoped Classical in Decidable.peirce _ _
theorem not_iff_not : (¬a ↔ ¬b) ↔ (a ↔ b) := open scoped Classical in Decidable.not_iff_not
theorem not_iff_comm : (¬a ↔ b) ↔ (¬b ↔ a) := open scoped Classical in Decidable.not_iff_comm
theorem not_iff : ¬(a ↔ b) ↔ (¬a ↔ b) := open scoped Classical in Decidable.not_iff
theorem iff_not_comm : (a ↔ ¬b) ↔ (b ↔ ¬a) := open scoped Classical in Decidable.iff_not_comm
theorem iff_iff_and_or_not_and_not : (a ↔ b) ↔ a ∧ b ∨ ¬a ∧ ¬b :=
open scoped Classical in Decidable.iff_iff_and_or_not_and_not
theorem iff_iff_not_or_and_or_not : (a ↔ b) ↔ (¬a ∨ b) ∧ (a ∨ ¬b) :=
open scoped Classical in Decidable.iff_iff_not_or_and_or_not
theorem not_and_not_right : ¬(a ∧ ¬b) ↔ a → b :=
open scoped Classical in Decidable.not_and_not_right
/-! ### De Morgan's laws -/
/-- One of **de Morgan's laws**: the negation of a conjunction is logically equivalent to the
disjunction of the negations. -/
theorem not_and_or : ¬(a ∧ b) ↔ ¬a ∨ ¬b := open scoped Classical in Decidable.not_and_iff_not_or_not
theorem or_iff_not_and_not : a ∨ b ↔ ¬(¬a ∧ ¬b) :=
open scoped Classical in Decidable.or_iff_not_not_and_not
theorem and_iff_not_or_not : a ∧ b ↔ ¬(¬a ∨ ¬b) :=
open scoped Classical in Decidable.and_iff_not_not_or_not
@[simp] theorem not_xor (P Q : Prop) : ¬Xor' P Q ↔ (P ↔ Q) := by
simp only [not_and, Xor', not_or, not_not, ← iff_iff_implies_and_implies]
theorem xor_iff_not_iff (P Q : Prop) : Xor' P Q ↔ ¬ (P ↔ Q) := (not_xor P Q).not_right
theorem xor_iff_iff_not : Xor' a b ↔ (a ↔ ¬b) := by simp only [← @xor_not_right a, not_not]
theorem xor_iff_not_iff' : Xor' a b ↔ (¬a ↔ b) := by simp only [← @xor_not_left _ b, not_not]
theorem xor_iff_or_and_not_and (a b : Prop) : Xor' a b ↔ (a ∨ b) ∧ (¬ (a ∧ b)) := by
rw [Xor', or_and_right, not_and_or, and_or_left, and_not_self_iff, false_or,
and_or_left, and_not_self_iff, or_false]
end Propositional
/-! ### Membership -/
alias Membership.mem.ne_of_not_mem := ne_of_mem_of_not_mem
alias Membership.mem.ne_of_not_mem' := ne_of_mem_of_not_mem'
section Membership
variable {α β : Type*} [Membership α β] {p : Prop} [Decidable p]
theorem mem_dite {a : α} {s : p → β} {t : ¬p → β} :
(a ∈ if h : p then s h else t h) ↔ (∀ h, a ∈ s h) ∧ (∀ h, a ∈ t h) := by
by_cases h : p <;> simp [h]
theorem dite_mem {a : p → α} {b : ¬p → α} {s : β} :
(if h : p then a h else b h) ∈ s ↔ (∀ h, a h ∈ s) ∧ (∀ h, b h ∈ s) := by
by_cases h : p <;> simp [h]
theorem mem_ite {a : α} {s t : β} : (a ∈ if p then s else t) ↔ (p → a ∈ s) ∧ (¬p → a ∈ t) :=
mem_dite
theorem ite_mem {a b : α} {s : β} : (if p then a else b) ∈ s ↔ (p → a ∈ s) ∧ (¬p → b ∈ s) :=
dite_mem
end Membership
/-! ### Declarations about equality -/
section Equality
-- todo: change name
theorem forall_cond_comm {α} {s : α → Prop} {p : α → α → Prop} :
(∀ a, s a → ∀ b, s b → p a b) ↔ ∀ a b, s a → s b → p a b :=
⟨fun h a b ha hb ↦ h a ha b hb, fun h a ha b hb ↦ h a b ha hb⟩
theorem forall_mem_comm {α β} [Membership α β] {s : β} {p : α → α → Prop} :
(∀ a (_ : a ∈ s) b (_ : b ∈ s), p a b) ↔ ∀ a b, a ∈ s → b ∈ s → p a b :=
forall_cond_comm
lemma ne_of_eq_of_ne {α : Sort*} {a b c : α} (h₁ : a = b) (h₂ : b ≠ c) : a ≠ c := h₁.symm ▸ h₂
lemma ne_of_ne_of_eq {α : Sort*} {a b c : α} (h₁ : a ≠ b) (h₂ : b = c) : a ≠ c := h₂ ▸ h₁
alias Eq.trans_ne := ne_of_eq_of_ne
alias Ne.trans_eq := ne_of_ne_of_eq
theorem eq_equivalence {α : Sort*} : Equivalence (@Eq α) :=
⟨Eq.refl, @Eq.symm _, @Eq.trans _⟩
-- These were migrated to Batteries but the `@[simp]` attributes were (mysteriously?) removed.
attribute [simp] eq_mp_eq_cast eq_mpr_eq_cast
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_refl_left {α β : Sort*} (f : α → β) {a b : α} (h : a = b) :
congr (Eq.refl f) h = congr_arg f h := rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_refl_right {α β : Sort*} {f g : α → β} (h : f = g) (a : α) :
congr h (Eq.refl a) = congr_fun h a := rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_arg_refl {α β : Sort*} (f : α → β) (a : α) :
congr_arg f (Eq.refl a) = Eq.refl (f a) :=
rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_fun_rfl {α β : Sort*} (f : α → β) (a : α) : congr_fun (Eq.refl f) a = Eq.refl (f a) :=
rfl
-- @[simp] -- FIXME simp ignores proof rewrites
theorem congr_fun_congr_arg {α β γ : Sort*} (f : α → β → γ) {a a' : α} (p : a = a') (b : β) :
congr_fun (congr_arg f p) b = congr_arg (fun a ↦ f a b) p := rfl
theorem Eq.rec_eq_cast {α : Sort _} {P : α → Sort _} {x y : α} (h : x = y) (z : P x) :
h ▸ z = cast (congr_arg P h) z := by induction h; rfl
theorem eqRec_heq' {α : Sort*} {a' : α} {motive : (a : α) → a' = a → Sort*}
(p : motive a' (rfl : a' = a')) {a : α} (t : a' = a) :
HEq (@Eq.rec α a' motive p a t) p := by
subst t; rfl
theorem rec_heq_of_heq {α β : Sort _} {a b : α} {C : α → Sort*} {x : C a} {y : β}
(e : a = b) (h : HEq x y) : HEq (e ▸ x) y := by subst e; exact h
theorem rec_heq_iff_heq {α β : Sort _} {a b : α} {C : α → Sort*} {x : C a} {y : β} {e : a = b} :
HEq (e ▸ x) y ↔ HEq x y := by subst e; rfl
theorem heq_rec_iff_heq {α β : Sort _} {a b : α} {C : α → Sort*} {x : β} {y : C a} {e : a = b} :
HEq x (e ▸ y) ↔ HEq x y := by subst e; rfl
@[simp]
theorem cast_heq_iff_heq {α β γ : Sort _} (e : α = β) (a : α) (c : γ) :
HEq (cast e a) c ↔ HEq a c := by subst e; rfl
@[simp]
theorem heq_cast_iff_heq {α β γ : Sort _} (e : β = γ) (a : α) (b : β) :
HEq a (cast e b) ↔ HEq a b := by subst e; rfl
universe u
variable {α β : Sort u} {e : β = α} {a : α} {b : β}
lemma heq_of_eq_cast (e : β = α) : a = cast e b → HEq a b := by rintro rfl; simp
lemma eq_cast_iff_heq : a = cast e b ↔ HEq a b := ⟨heq_of_eq_cast _, fun h ↦ by cases h; rfl⟩
end Equality
/-! ### Declarations about quantifiers -/
section Quantifiers
section Dependent
variable {α : Sort*} {β : α → Sort*} {γ : ∀ a, β a → Sort*}
theorem forall₂_imp {p q : ∀ a, β a → Prop} (h : ∀ a b, p a b → q a b) :
(∀ a b, p a b) → ∀ a b, q a b :=
forall_imp fun i ↦ forall_imp <| h i
theorem forall₃_imp {p q : ∀ a b, γ a b → Prop} (h : ∀ a b c, p a b c → q a b c) :
(∀ a b c, p a b c) → ∀ a b c, q a b c :=
forall_imp fun a ↦ forall₂_imp <| h a
theorem Exists₂.imp {p q : ∀ a, β a → Prop} (h : ∀ a b, p a b → q a b) :
(∃ a b, p a b) → ∃ a b, q a b :=
Exists.imp fun a ↦ Exists.imp <| h a
theorem Exists₃.imp {p q : ∀ a b, γ a b → Prop} (h : ∀ a b c, p a b c → q a b c) :
(∃ a b c, p a b c) → ∃ a b c, q a b c :=
Exists.imp fun a ↦ Exists₂.imp <| h a
end Dependent
variable {α β : Sort*} {p : α → Prop}
theorem forall_swap {p : α → β → Prop} : (∀ x y, p x y) ↔ ∀ y x, p x y :=
⟨fun f x y ↦ f y x, fun f x y ↦ f y x⟩
theorem forall₂_swap
{ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} {p : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Prop} :
(∀ i₁ j₁ i₂ j₂, p i₁ j₁ i₂ j₂) ↔ ∀ i₂ j₂ i₁ j₁, p i₁ j₁ i₂ j₂ := ⟨swap₂, swap₂⟩
/-- We intentionally restrict the type of `α` in this lemma so that this is a safer to use in simp
than `forall_swap`. -/
theorem imp_forall_iff {α : Type*} {p : Prop} {q : α → Prop} : (p → ∀ x, q x) ↔ ∀ x, p → q x :=
forall_swap
lemma imp_forall_iff_forall (A : Prop) (B : A → Prop) :
(A → ∀ h : A, B h) ↔ ∀ h : A, B h := by by_cases h : A <;> simp [h]
theorem exists_swap {p : α → β → Prop} : (∃ x y, p x y) ↔ ∃ y x, p x y :=
⟨fun ⟨x, y, h⟩ ↦ ⟨y, x, h⟩, fun ⟨y, x, h⟩ ↦ ⟨x, y, h⟩⟩
theorem exists_and_exists_comm {P : α → Prop} {Q : β → Prop} :
(∃ a, P a) ∧ (∃ b, Q b) ↔ ∃ a b, P a ∧ Q b :=
⟨fun ⟨⟨a, ha⟩, ⟨b, hb⟩⟩ ↦ ⟨a, b, ⟨ha, hb⟩⟩, fun ⟨a, b, ⟨ha, hb⟩⟩ ↦ ⟨⟨a, ha⟩, ⟨b, hb⟩⟩⟩
export Classical (not_forall)
theorem not_forall_not : (¬∀ x, ¬p x) ↔ ∃ x, p x :=
open scoped Classical in Decidable.not_forall_not
export Classical (not_exists_not)
lemma forall_or_exists_not (P : α → Prop) : (∀ a, P a) ∨ ∃ a, ¬ P a := by
rw [← not_forall]; exact em _
lemma exists_or_forall_not (P : α → Prop) : (∃ a, P a) ∨ ∀ a, ¬ P a := by
rw [← not_exists]; exact em _
theorem forall_imp_iff_exists_imp {α : Sort*} {p : α → Prop} {b : Prop} [ha : Nonempty α] :
(∀ x, p x) → b ↔ ∃ x, p x → b := by
classical
let ⟨a⟩ := ha
refine ⟨fun h ↦ not_forall_not.1 fun h' ↦ ?_, fun ⟨x, hx⟩ h ↦ hx (h x)⟩
exact if hb : b then h' a fun _ ↦ hb else hb <| h fun x ↦ (_root_.not_imp.1 (h' x)).1
@[mfld_simps]
theorem forall_true_iff : (α → True) ↔ True := imp_true_iff _
-- Unfortunately this causes simp to loop sometimes, so we
-- add the 2 and 3 cases as simp lemmas instead
theorem forall_true_iff' (h : ∀ a, p a ↔ True) : (∀ a, p a) ↔ True :=
iff_true_intro fun _ ↦ of_iff_true (h _)
-- This is not marked `@[simp]` because `implies_true : (α → True) = True` works
theorem forall₂_true_iff {β : α → Sort*} : (∀ a, β a → True) ↔ True := by simp
-- This is not marked `@[simp]` because `implies_true : (α → True) = True` works
theorem forall₃_true_iff {β : α → Sort*} {γ : ∀ a, β a → Sort*} :
(∀ (a) (b : β a), γ a b → True) ↔ True := by simp
theorem Decidable.and_forall_ne [DecidableEq α] (a : α) {p : α → Prop} :
(p a ∧ ∀ b, b ≠ a → p b) ↔ ∀ b, p b := by
simp only [← @forall_eq _ p a, ← forall_and, ← or_imp, Decidable.em, forall_const]
theorem and_forall_ne (a : α) : (p a ∧ ∀ b, b ≠ a → p b) ↔ ∀ b, p b :=
open scoped Classical in Decidable.and_forall_ne a
theorem Ne.ne_or_ne {x y : α} (z : α) (h : x ≠ y) : x ≠ z ∨ y ≠ z :=
not_and_or.1 <| mt (and_imp.2 (· ▸ ·)) h.symm
@[simp]
theorem exists_apply_eq_apply' (f : α → β) (a' : α) : ∃ a, f a' = f a := ⟨a', rfl⟩
@[simp]
lemma exists_apply_eq_apply2 {α β γ} {f : α → β → γ} {a : α} {b : β} : ∃ x y, f x y = f a b :=
⟨a, b, rfl⟩
@[simp]
lemma exists_apply_eq_apply2' {α β γ} {f : α → β → γ} {a : α} {b : β} : ∃ x y, f a b = f x y :=
⟨a, b, rfl⟩
@[simp]
lemma exists_apply_eq_apply3 {α β γ δ} {f : α → β → γ → δ} {a : α} {b : β} {c : γ} :
∃ x y z, f x y z = f a b c :=
⟨a, b, c, rfl⟩
@[simp]
lemma exists_apply_eq_apply3' {α β γ δ} {f : α → β → γ → δ} {a : α} {b : β} {c : γ} :
∃ x y z, f a b c = f x y z :=
⟨a, b, c, rfl⟩
/--
The constant function witnesses that
there exists a function sending a given term to a given term.
This is sometimes useful in `simp` to discharge side conditions.
-/
theorem exists_apply_eq (a : α) (b : β) : ∃ f : α → β, f a = b := ⟨fun _ ↦ b, rfl⟩
@[simp] theorem exists_exists_and_eq_and {f : α → β} {p : α → Prop} {q : β → Prop} :
(∃ b, (∃ a, p a ∧ f a = b) ∧ q b) ↔ ∃ a, p a ∧ q (f a) :=
⟨fun ⟨_, ⟨a, ha, hab⟩, hb⟩ ↦ ⟨a, ha, hab.symm ▸ hb⟩, fun ⟨a, hp, hq⟩ ↦ ⟨f a, ⟨a, hp, rfl⟩, hq⟩⟩
@[simp] theorem exists_exists_eq_and {f : α → β} {p : β → Prop} :
(∃ b, (∃ a, f a = b) ∧ p b) ↔ ∃ a, p (f a) :=
⟨fun ⟨_, ⟨a, ha⟩, hb⟩ ↦ ⟨a, ha.symm ▸ hb⟩, fun ⟨a, ha⟩ ↦ ⟨f a, ⟨a, rfl⟩, ha⟩⟩
@[simp] theorem exists_exists_and_exists_and_eq_and {α β γ : Type*}
{f : α → β → γ} {p : α → Prop} {q : β → Prop} {r : γ → Prop} :
(∃ c, (∃ a, p a ∧ ∃ b, q b ∧ f a b = c) ∧ r c) ↔ ∃ a, p a ∧ ∃ b, q b ∧ r (f a b) :=
⟨fun ⟨_, ⟨a, ha, b, hb, hab⟩, hc⟩ ↦ ⟨a, ha, b, hb, hab.symm ▸ hc⟩,
fun ⟨a, ha, b, hb, hab⟩ ↦ ⟨f a b, ⟨a, ha, b, hb, rfl⟩, hab⟩⟩
@[simp] theorem exists_exists_exists_and_eq {α β γ : Type*}
{f : α → β → γ} {p : γ → Prop} :
(∃ c, (∃ a, ∃ b, f a b = c) ∧ p c) ↔ ∃ a, ∃ b, p (f a b) :=
⟨fun ⟨_, ⟨a, b, hab⟩, hc⟩ ↦ ⟨a, b, hab.symm ▸ hc⟩,
fun ⟨a, b, hab⟩ ↦ ⟨f a b, ⟨a, b, rfl⟩, hab⟩⟩
theorem forall_apply_eq_imp_iff' {f : α → β} {p : β → Prop} :
(∀ a b, f a = b → p b) ↔ ∀ a, p (f a) := by simp
theorem forall_eq_apply_imp_iff' {f : α → β} {p : β → Prop} :
(∀ a b, b = f a → p b) ↔ ∀ a, p (f a) := by simp
theorem exists₂_comm
{ι₁ ι₂ : Sort*} {κ₁ : ι₁ → Sort*} {κ₂ : ι₂ → Sort*} {p : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Prop} :
(∃ i₁ j₁ i₂ j₂, p i₁ j₁ i₂ j₂) ↔ ∃ i₂ j₂ i₁ j₁, p i₁ j₁ i₂ j₂ := by
simp only [@exists_comm (κ₁ _), @exists_comm ι₁]
theorem And.exists {p q : Prop} {f : p ∧ q → Prop} : (∃ h, f h) ↔ ∃ hp hq, f ⟨hp, hq⟩ :=
⟨fun ⟨h, H⟩ ↦ ⟨h.1, h.2, H⟩, fun ⟨hp, hq, H⟩ ↦ ⟨⟨hp, hq⟩, H⟩⟩
theorem forall_or_of_or_forall {α : Sort*} {p : α → Prop} {b : Prop} (h : b ∨ ∀ x, p x) (x : α) :
b ∨ p x :=
h.imp_right fun h₂ ↦ h₂ x
-- See Note [decidable namespace]
protected theorem Decidable.forall_or_left {q : Prop} {p : α → Prop} [Decidable q] :
(∀ x, q ∨ p x) ↔ q ∨ ∀ x, p x :=
⟨fun h ↦ if hq : q then Or.inl hq else
Or.inr fun x ↦ (h x).resolve_left hq, forall_or_of_or_forall⟩
theorem forall_or_left {q} {p : α → Prop} : (∀ x, q ∨ p x) ↔ q ∨ ∀ x, p x :=
open scoped Classical in Decidable.forall_or_left
-- See Note [decidable namespace]
protected theorem Decidable.forall_or_right {q} {p : α → Prop} [Decidable q] :
(∀ x, p x ∨ q) ↔ (∀ x, p x) ∨ q := by simp [or_comm, Decidable.forall_or_left]
theorem forall_or_right {q} {p : α → Prop} : (∀ x, p x ∨ q) ↔ (∀ x, p x) ∨ q :=
open scoped Classical in Decidable.forall_or_right
theorem Exists.fst {b : Prop} {p : b → Prop} : Exists p → b
| ⟨h, _⟩ => h
theorem Exists.snd {b : Prop} {p : b → Prop} : ∀ h : Exists p, p h.fst
| ⟨_, h⟩ => h
theorem Prop.exists_iff {p : Prop → Prop} : (∃ h, p h) ↔ p False ∨ p True :=
⟨fun ⟨h₁, h₂⟩ ↦ by_cases (fun H : h₁ ↦ .inr <| by simpa only [H] using h₂)
(fun H ↦ .inl <| by simpa only [H] using h₂), fun h ↦ h.elim (.intro _) (.intro _)⟩
theorem Prop.forall_iff {p : Prop → Prop} : (∀ h, p h) ↔ p False ∧ p True :=
⟨fun H ↦ ⟨H _, H _⟩, fun ⟨h₁, h₂⟩ h ↦ by by_cases H : h <;> simpa only [H]⟩
theorem exists_iff_of_forall {p : Prop} {q : p → Prop} (h : ∀ h, q h) : (∃ h, q h) ↔ p :=
⟨Exists.fst, fun H ↦ ⟨H, h H⟩⟩
theorem exists_prop_of_false {p : Prop} {q : p → Prop} : ¬p → ¬∃ h' : p, q h' :=
mt Exists.fst
/- See `IsEmpty.exists_iff` for the `False` version of `exists_true_left`. -/
theorem forall_prop_congr {p p' : Prop} {q q' : p → Prop} (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') :
(∀ h, q h) ↔ ∀ h : p', q' (hp.2 h) :=
⟨fun h1 h2 ↦ (hq _).1 (h1 (hp.2 h2)), fun h1 h2 ↦ (hq _).2 (h1 (hp.1 h2))⟩
theorem forall_prop_congr' {p p' : Prop} {q q' : p → Prop} (hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') :
(∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
propext (forall_prop_congr hq hp)
lemma imp_congr_eq {a b c d : Prop} (h₁ : a = c) (h₂ : b = d) : (a → b) = (c → d) :=
propext (imp_congr h₁.to_iff h₂.to_iff)
lemma imp_congr_ctx_eq {a b c d : Prop} (h₁ : a = c) (h₂ : c → b = d) : (a → b) = (c → d) :=
propext (imp_congr_ctx h₁.to_iff fun hc ↦ (h₂ hc).to_iff)
lemma eq_true_intro {a : Prop} (h : a) : a = True := propext (iff_true_intro h)
lemma eq_false_intro {a : Prop} (h : ¬a) : a = False := propext (iff_false_intro h)
-- FIXME: `alias` creates `def Iff.eq := propext` instead of `lemma Iff.eq := propext`
@[nolint defLemma] alias Iff.eq := propext
lemma iff_eq_eq {a b : Prop} : (a ↔ b) = (a = b) := propext ⟨propext, Eq.to_iff⟩
-- They were not used in Lean 3 and there are already lemmas with those names in Lean 4
/-- See `IsEmpty.forall_iff` for the `False` version. -/
@[simp] theorem forall_true_left (p : True → Prop) : (∀ x, p x) ↔ p True.intro :=
forall_prop_of_true _
end Quantifiers
/-! ### Classical lemmas -/
namespace Classical
-- use shortened names to avoid conflict when classical namespace is open.
/-- Any prop `p` is decidable classically. A shorthand for `Classical.propDecidable`. -/
noncomputable def dec (p : Prop) : Decidable p := by infer_instance
variable {α : Sort*}
/-- Any predicate `p` is decidable classically. -/
noncomputable def decPred (p : α → Prop) : DecidablePred p := by infer_instance
/-- Any relation `p` is decidable classically. -/
noncomputable def decRel (p : α → α → Prop) : DecidableRel p := by infer_instance
/-- Any type `α` has decidable equality classically. -/
noncomputable def decEq (α : Sort*) : DecidableEq α := by infer_instance
/-- Construct a function from a default value `H0`, and a function to use if there exists a value
satisfying the predicate. -/
noncomputable def existsCases {α C : Sort*} {p : α → Prop} (H0 : C) (H : ∀ a, p a → C) : C :=
if h : ∃ a, p a then H (Classical.choose h) (Classical.choose_spec h) else H0
theorem some_spec₂ {α : Sort*} {p : α → Prop} {h : ∃ a, p a} (q : α → Prop)
(hpq : ∀ a, p a → q a) : q (choose h) := hpq _ <| choose_spec _
/-- A version of `byContradiction` that uses types instead of propositions. -/
protected noncomputable def byContradiction' {α : Sort*} (H : ¬(α → False)) : α :=
Classical.choice <| (peirce _ False) fun h ↦ (H fun a ↦ h ⟨a⟩).elim
/-- `Classical.byContradiction'` is equivalent to lean's axiom `Classical.choice`. -/
def choice_of_byContradiction' {α : Sort*} (contra : ¬(α → False) → α) : Nonempty α → α :=
fun H ↦ contra H.elim
@[simp] lemma choose_eq (a : α) : @Exists.choose _ (· = a) ⟨a, rfl⟩ = a := @choose_spec _ (· = a) _
@[simp]
lemma choose_eq' (a : α) : @Exists.choose _ (a = ·) ⟨a, rfl⟩ = a :=
(@choose_spec _ (a = ·) _).symm
alias axiom_of_choice := axiomOfChoice -- TODO: remove? rename in core?
alias by_cases := byCases -- TODO: remove? rename in core?
alias by_contradiction := byContradiction -- TODO: remove? rename in core?
-- The remaining theorems in this section were ported from Lean 3,
-- but are currently unused in Mathlib, so have been deprecated.
-- If any are being used downstream, please remove the deprecation.
alias prop_complete := propComplete -- TODO: remove? rename in core?
end Classical
/-- This function has the same type as `Exists.recOn`, and can be used to case on an equality,
but `Exists.recOn` can only eliminate into Prop, while this version eliminates into any universe
using the axiom of choice. -/
noncomputable def Exists.classicalRecOn {α : Sort*} {p : α → Prop} (h : ∃ a, p a)
{C : Sort*} (H : ∀ a, p a → C) : C :=
H (Classical.choose h) (Classical.choose_spec h)
/-! ### Declarations about bounded quantifiers -/
section BoundedQuantifiers
variable {α : Sort*} {r p q : α → Prop} {P Q : ∀ x, p x → Prop}
theorem bex_def : (∃ (x : _) (_ : p x), q x) ↔ ∃ x, p x ∧ q x :=
⟨fun ⟨x, px, qx⟩ ↦ ⟨x, px, qx⟩, fun ⟨x, px, qx⟩ ↦ ⟨x, px, qx⟩⟩
theorem BEx.elim {b : Prop} : (∃ x h, P x h) → (∀ a h, P a h → b) → b
| ⟨a, h₁, h₂⟩, h' => h' a h₁ h₂
theorem BEx.intro (a : α) (h₁ : p a) (h₂ : P a h₁) : ∃ (x : _) (h : p x), P x h :=
⟨a, h₁, h₂⟩
theorem BAll.imp_right (H : ∀ x h, P x h → Q x h) (h₁ : ∀ x h, P x h) (x h) : Q x h :=
H _ _ <| h₁ _ _
theorem BEx.imp_right (H : ∀ x h, P x h → Q x h) : (∃ x h, P x h) → ∃ x h, Q x h
| ⟨_, _, h'⟩ => ⟨_, _, H _ _ h'⟩
theorem BAll.imp_left (H : ∀ x, p x → q x) (h₁ : ∀ x, q x → r x) (x) (h : p x) : r x :=
h₁ _ <| H _ h
theorem BEx.imp_left (H : ∀ x, p x → q x) : (∃ (x : _) (_ : p x), r x) → ∃ (x : _) (_ : q x), r x
| ⟨x, hp, hr⟩ => ⟨x, H _ hp, hr⟩
theorem exists_mem_of_exists (H : ∀ x, p x) : (∃ x, q x) → ∃ (x : _) (_ : p x), q x
| ⟨x, hq⟩ => ⟨x, H x, hq⟩
theorem exists_of_exists_mem : (∃ (x : _) (_ : p x), q x) → ∃ x, q x
| ⟨x, _, hq⟩ => ⟨x, hq⟩
theorem not_exists_mem : (¬∃ x h, P x h) ↔ ∀ x h, ¬P x h := exists₂_imp
theorem not_forall₂_of_exists₂_not : (∃ x h, ¬P x h) → ¬∀ x h, P x h
| ⟨x, h, hp⟩, al => hp <| al x h
-- See Note [decidable namespace]
protected theorem Decidable.not_forall₂ [Decidable (∃ x h, ¬P x h)] [∀ x h, Decidable (P x h)] :
(¬∀ x h, P x h) ↔ ∃ x h, ¬P x h :=
⟨Not.decidable_imp_symm fun nx x h ↦ nx.decidable_imp_symm
fun h' ↦ ⟨x, h, h'⟩, not_forall₂_of_exists₂_not⟩
theorem not_forall₂ : (¬∀ x h, P x h) ↔ ∃ x h, ¬P x h :=
open scoped Classical in Decidable.not_forall₂
theorem forall₂_and : (∀ x h, P x h ∧ Q x h) ↔ (∀ x h, P x h) ∧ ∀ x h, Q x h :=
Iff.trans (forall_congr' fun _ ↦ forall_and) forall_and
theorem forall_and_left [Nonempty α] (q : Prop) (p : α → Prop) :
(∀ x, q ∧ p x) ↔ (q ∧ ∀ x, p x) := by rw [forall_and, forall_const]
theorem forall_and_right [Nonempty α] (p : α → Prop) (q : Prop) :
(∀ x, p x ∧ q) ↔ (∀ x, p x) ∧ q := by rw [forall_and, forall_const]
theorem exists_mem_or : (∃ x h, P x h ∨ Q x h) ↔ (∃ x h, P x h) ∨ ∃ x h, Q x h :=
Iff.trans (exists_congr fun _ ↦ exists_or) exists_or
theorem forall₂_or_left : (∀ x, p x ∨ q x → r x) ↔ (∀ x, p x → r x) ∧ ∀ x, q x → r x :=
Iff.trans (forall_congr' fun _ ↦ or_imp) forall_and
theorem exists_mem_or_left :
(∃ (x : _) (_ : p x ∨ q x), r x) ↔ (∃ (x : _) (_ : p x), r x) ∨ ∃ (x : _) (_ : q x), r x := by
simp only [exists_prop]
exact Iff.trans (exists_congr fun x ↦ or_and_right) exists_or
end BoundedQuantifiers
section ite
variable {α : Sort*} {σ : α → Sort*} {P Q R : Prop} [Decidable P]
{a b c : α} {A : P → α} {B : ¬P → α}
theorem dite_eq_iff : dite P A B = c ↔ (∃ h, A h = c) ∨ ∃ h, B h = c := by
by_cases P <;> simp [*, exists_prop_of_true, exists_prop_of_false]
theorem ite_eq_iff : ite P a b = c ↔ P ∧ a = c ∨ ¬P ∧ b = c :=
dite_eq_iff.trans <| by rw [exists_prop, exists_prop]
theorem eq_ite_iff : a = ite P b c ↔ P ∧ a = b ∨ ¬P ∧ a = c :=
eq_comm.trans <| ite_eq_iff.trans <| (Iff.rfl.and eq_comm).or (Iff.rfl.and eq_comm)
theorem dite_eq_iff' : dite P A B = c ↔ (∀ h, A h = c) ∧ ∀ h, B h = c :=
⟨fun he ↦ ⟨fun h ↦ (dif_pos h).symm.trans he, fun h ↦ (dif_neg h).symm.trans he⟩, fun he ↦
(em P).elim (fun h ↦ (dif_pos h).trans <| he.1 h) fun h ↦ (dif_neg h).trans <| he.2 h⟩
theorem ite_eq_iff' : ite P a b = c ↔ (P → a = c) ∧ (¬P → b = c) := dite_eq_iff'
theorem dite_ne_left_iff : dite P (fun _ ↦ a) B ≠ a ↔ ∃ h, a ≠ B h := by
rw [Ne, dite_eq_left_iff, not_forall]
exact exists_congr fun h ↦ by rw [ne_comm]
theorem dite_ne_right_iff : (dite P A fun _ ↦ b) ≠ b ↔ ∃ h, A h ≠ b := by
simp only [Ne, dite_eq_right_iff, not_forall]
theorem ite_ne_left_iff : ite P a b ≠ a ↔ ¬P ∧ a ≠ b :=
dite_ne_left_iff.trans <| by rw [exists_prop]
theorem ite_ne_right_iff : ite P a b ≠ b ↔ P ∧ a ≠ b :=
dite_ne_right_iff.trans <| by rw [exists_prop]
protected theorem Ne.dite_eq_left_iff (h : ∀ h, a ≠ B h) : dite P (fun _ ↦ a) B = a ↔ P :=
dite_eq_left_iff.trans ⟨fun H ↦ of_not_not fun h' ↦ h h' (H h').symm, fun h H ↦ (H h).elim⟩
protected theorem Ne.dite_eq_right_iff (h : ∀ h, A h ≠ b) : (dite P A fun _ ↦ b) = b ↔ ¬P :=
dite_eq_right_iff.trans ⟨fun H h' ↦ h h' (H h'), fun h' H ↦ (h' H).elim⟩
protected theorem Ne.ite_eq_left_iff (h : a ≠ b) : ite P a b = a ↔ P :=
Ne.dite_eq_left_iff fun _ ↦ h
protected theorem Ne.ite_eq_right_iff (h : a ≠ b) : ite P a b = b ↔ ¬P :=
Ne.dite_eq_right_iff fun _ ↦ h
protected theorem Ne.dite_ne_left_iff (h : ∀ h, a ≠ B h) : dite P (fun _ ↦ a) B ≠ a ↔ ¬P :=
dite_ne_left_iff.trans <| exists_iff_of_forall h
protected theorem Ne.dite_ne_right_iff (h : ∀ h, A h ≠ b) : (dite P A fun _ ↦ b) ≠ b ↔ P :=
dite_ne_right_iff.trans <| exists_iff_of_forall h
protected theorem Ne.ite_ne_left_iff (h : a ≠ b) : ite P a b ≠ a ↔ ¬P :=
Ne.dite_ne_left_iff fun _ ↦ h
protected theorem Ne.ite_ne_right_iff (h : a ≠ b) : ite P a b ≠ b ↔ P :=
Ne.dite_ne_right_iff fun _ ↦ h
variable (P Q a b)
theorem dite_eq_or_eq : (∃ h, dite P A B = A h) ∨ ∃ h, dite P A B = B h :=
if h : _ then .inl ⟨h, dif_pos h⟩ else .inr ⟨h, dif_neg h⟩
theorem ite_eq_or_eq : ite P a b = a ∨ ite P a b = b :=
if h : _ then .inl (if_pos h) else .inr (if_neg h)
/-- A two-argument function applied to two `dite`s is a `dite` of that two-argument function
applied to each of the branches. -/
theorem apply_dite₂ {α β γ : Sort*} (f : α → β → γ) (P : Prop) [Decidable P]
(a : P → α) (b : ¬P → α) (c : P → β) (d : ¬P → β) :
f (dite P a b) (dite P c d) = dite P (fun h ↦ f (a h) (c h)) fun h ↦ f (b h) (d h) := by
by_cases h : P <;> simp [h]
/-- A two-argument function applied to two `ite`s is a `ite` of that two-argument function
applied to each of the branches. -/
theorem apply_ite₂ {α β γ : Sort*} (f : α → β → γ) (P : Prop) [Decidable P] (a b : α) (c d : β) :
f (ite P a b) (ite P c d) = ite P (f a c) (f b d) :=
apply_dite₂ f P (fun _ ↦ a) (fun _ ↦ b) (fun _ ↦ c) fun _ ↦ d
/-- A 'dite' producing a `Pi` type `Π a, σ a`, applied to a value `a : α` is a `dite` that applies
either branch to `a`. -/
theorem dite_apply (f : P → ∀ a, σ a) (g : ¬P → ∀ a, σ a) (a : α) :
(dite P f g) a = dite P (fun h ↦ f h a) fun h ↦ g h a := by by_cases h : P <;> simp [h]
/-- A 'ite' producing a `Pi` type `Π a, σ a`, applied to a value `a : α` is a `ite` that applies
either branch to `a`. -/
theorem ite_apply (f g : ∀ a, σ a) (a : α) : (ite P f g) a = ite P (f a) (g a) :=
dite_apply P (fun _ ↦ f) (fun _ ↦ g) a
section
variable [Decidable Q]
theorem ite_and : ite (P ∧ Q) a b = ite P (ite Q a b) b := by
by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
theorem ite_or : ite (P ∨ Q) a b = ite P a (ite Q a b) := by
by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
theorem dite_dite_comm {B : Q → α} {C : ¬P → ¬Q → α} (h : P → ¬Q) :
(if p : P then A p else if q : Q then B q else C p q) =
if q : Q then B q else if p : P then A p else C p q :=
dite_eq_iff'.2 ⟨
fun p ↦ by rw [dif_neg (h p), dif_pos p],
fun np ↦ by congr; funext _; rw [dif_neg np]⟩
theorem ite_ite_comm (h : P → ¬Q) :
(if P then a else if Q then b else c) =
if Q then b else if P then a else c :=
dite_dite_comm P Q h
end
variable {P Q}
theorem ite_prop_iff_or : (if P then Q else R) ↔ (P ∧ Q ∨ ¬ P ∧ R) := by
by_cases p : P <;> simp [p]
theorem dite_prop_iff_or {Q : P → Prop} {R : ¬P → Prop} :
dite P Q R ↔ (∃ p, Q p) ∨ (∃ p, R p) := by
by_cases h : P <;> simp [h, exists_prop_of_false, exists_prop_of_true]
-- TODO make this a simp lemma in a future PR
theorem ite_prop_iff_and : (if P then Q else R) ↔ ((P → Q) ∧ (¬ P → R)) := by
by_cases p : P <;> simp [p]
theorem dite_prop_iff_and {Q : P → Prop} {R : ¬P → Prop} :
dite P Q R ↔ (∀ h, Q h) ∧ (∀ h, R h) := by
by_cases h : P <;> simp [h, forall_prop_of_false, forall_prop_of_true]
section congr
variable [Decidable Q] {x y u v : α}
theorem if_ctx_congr (h_c : P ↔ Q) (h_t : Q → x = u) (h_e : ¬Q → y = v) : ite P x y = ite Q u v :=
ite_congr h_c.eq h_t h_e
theorem if_congr (h_c : P ↔ Q) (h_t : x = u) (h_e : y = v) : ite P x y = ite Q u v :=
if_ctx_congr h_c (fun _ ↦ h_t) (fun _ ↦ h_e)
end congr
end ite
theorem not_beq_of_ne {α : Type*} [BEq α] [LawfulBEq α] {a b : α} (ne : a ≠ b) : ¬(a == b) :=
fun h => ne (eq_of_beq h)
alias beq_eq_decide := Bool.beq_eq_decide_eq
@[simp] lemma beq_eq_beq {α β : Type*} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] {a₁ a₂ : α}
{b₁ b₂ : β} : (a₁ == a₂) = (b₁ == b₂) ↔ (a₁ = a₂ ↔ b₁ = b₂) := by rw [Bool.eq_iff_iff]; simp
@[ext]
theorem beq_ext {α : Type*} (inst1 : BEq α) (inst2 : BEq α)
(h : ∀ x y, @BEq.beq _ inst1 x y = @BEq.beq _ inst2 x y) :
inst1 = inst2 := by
have ⟨beq1⟩ := inst1
have ⟨beq2⟩ := inst2
congr
funext x y
exact h x y
theorem lawful_beq_subsingleton {α : Type*} (inst1 : BEq α) (inst2 : BEq α)
[@LawfulBEq α inst1] [@LawfulBEq α inst2] :
inst1 = inst2 := by
apply beq_ext
intro x y
classical
simp only [beq_eq_decide]
| Mathlib/Logic/Basic.lean | 1,322 | 1,324 | |
/-
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
-/
import Mathlib.RingTheory.Valuation.Basic
import Mathlib.NumberTheory.Padics.PadicNorm
import Mathlib.Analysis.Normed.Field.Lemmas
import Mathlib.Tactic.Peel
import Mathlib.Topology.MetricSpace.Ultra.Basic
/-!
# p-adic numbers
This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as
the completion of `ℚ` with respect to the `p`-adic norm.
We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`,
and that `ℚ_[p]` is Cauchy complete.
## Important definitions
* `Padic` : the type of `p`-adic numbers
* `padicNormE` : the rational valued `p`-adic norm on `ℚ_[p]`
* `Padic.addValuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `WithTop ℤ`
## Notation
We introduce the notation `ℚ_[p]` for the `p`-adic numbers.
## 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.
We use the same concrete Cauchy sequence construction that is used to construct `ℝ`.
`ℚ_[p]` inherits a field structure from this construction.
The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to
`ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete.
`padicNormE` is the rational-valued `p`-adic norm on `ℚ_[p]`.
To instantiate `ℚ_[p]` as a normed field, we must cast this into an `ℝ`-valued norm.
The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces,
is the canonical representation of this norm.
`simp` prefers `padicNorm` to `padicNormE` when possible.
Since `padicNormE` and `‖ ‖` have different types, `simp` does not rewrite one to the other.
Coercions from `ℚ` to `ℚ_[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, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable section
open Nat padicNorm CauSeq CauSeq.Completion Metric
/-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/
abbrev PadicSeq (p : ℕ) :=
CauSeq _ (padicNorm p)
namespace PadicSeq
section
variable {p : ℕ} [Fact p.Prime]
/-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually
constant. -/
theorem stationary {f : CauSeq ℚ (padicNorm p)} (hf : ¬f ≈ 0) :
∃ N, ∀ m n, N ≤ m → N ≤ n → padicNorm p (f n) = padicNorm p (f m) :=
have : ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padicNorm p (f j) :=
CauSeq.abv_pos_of_not_limZero <| not_limZero_of_not_congr_zero hf
let ⟨ε, hε, N1, hN1⟩ := this
let ⟨N2, hN2⟩ := CauSeq.cauchy₂ f hε
⟨max N1 N2, fun n m hn hm ↦ by
have : padicNorm p (f n - f m) < ε := hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2
have : padicNorm p (f n - f m) < padicNorm p (f n) :=
lt_of_lt_of_le this <| hN1 _ (max_le_iff.1 hn).1
have : padicNorm p (f n - f m) < max (padicNorm p (f n)) (padicNorm p (f m)) :=
lt_max_iff.2 (Or.inl this)
by_contra hne
rw [← padicNorm.neg (f m)] at hne
have hnam := add_eq_max_of_ne hne
rw [padicNorm.neg, max_comm] at hnam
rw [← hnam, sub_eq_add_neg, add_comm] at this
apply _root_.lt_irrefl _ this⟩
/-- For all `n ≥ stationaryPoint f hf`, the `p`-adic norm of `f n` is the same. -/
def stationaryPoint {f : PadicSeq p} (hf : ¬f ≈ 0) : ℕ :=
Classical.choose <| stationary hf
theorem stationaryPoint_spec {f : PadicSeq p} (hf : ¬f ≈ 0) :
∀ {m n},
stationaryPoint hf ≤ m → stationaryPoint hf ≤ n → padicNorm p (f n) = padicNorm p (f m) :=
@(Classical.choose_spec <| stationary hf)
open Classical in
/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,
we can lift the norm to sequences. -/
def norm (f : PadicSeq p) : ℚ :=
if hf : f ≈ 0 then 0 else padicNorm p (f (stationaryPoint hf))
theorem norm_zero_iff (f : PadicSeq p) : f.norm = 0 ↔ f ≈ 0 := by
constructor
· intro h
by_contra hf
unfold norm at h
split_ifs at h
apply hf
intro ε hε
exists stationaryPoint hf
intro j hj
have heq := stationaryPoint_spec hf le_rfl hj
simpa [h, heq]
· intro h
simp [norm, h]
end
section Embedding
open CauSeq
variable {p : ℕ} [Fact p.Prime]
theorem equiv_zero_of_val_eq_of_equiv_zero {f g : PadicSeq p}
(h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) (hf : f ≈ 0) : g ≈ 0 := fun ε hε ↦
let ⟨i, hi⟩ := hf _ hε
⟨i, fun j hj ↦ by simpa [h] using hi _ hj⟩
theorem norm_nonzero_of_not_equiv_zero {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm ≠ 0 :=
hf ∘ f.norm_zero_iff.1
theorem norm_eq_norm_app_of_nonzero {f : PadicSeq p} (hf : ¬f ≈ 0) :
∃ k, f.norm = padicNorm p k ∧ k ≠ 0 :=
have heq : f.norm = padicNorm p (f <| stationaryPoint hf) := by simp [norm, hf]
⟨f <| stationaryPoint hf, heq, fun h ↦
norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩
theorem not_limZero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬LimZero (const (padicNorm p) q) :=
fun h' ↦ hq <| const_limZero.1 h'
theorem not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬const (padicNorm p) q ≈ 0 :=
fun h : LimZero (const (padicNorm p) q - 0) ↦
not_limZero_const_of_nonzero (p := p) hq <| by simpa using h
theorem norm_nonneg (f : PadicSeq p) : 0 ≤ f.norm := by
classical exact if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padicNorm.nonneg]
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_left_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v2 v3 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max (stationaryPoint hf) (max v2 v3))) := by
apply stationaryPoint_spec hf
· apply le_max_left
· exact le_rfl
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v3 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max v1 (max (stationaryPoint hf) v3))) := by
apply stationaryPoint_spec hf
· apply le_trans
· apply le_max_left _ v3
· apply le_max_right
· exact le_rfl
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_right {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v2 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max v1 (max v2 (stationaryPoint hf)))) := by
apply stationaryPoint_spec hf
· apply le_trans
· apply le_max_right v2
· apply le_max_right
· exact le_rfl
end Embedding
section Valuation
open CauSeq
variable {p : ℕ} [Fact p.Prime]
/-! ### Valuation on `PadicSeq` -/
open Classical in
/-- The `p`-adic valuation on `ℚ` lifts to `PadicSeq p`.
`Valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/
def valuation (f : PadicSeq p) : ℤ :=
if hf : f ≈ 0 then 0 else padicValRat p (f (stationaryPoint hf))
theorem norm_eq_zpow_neg_valuation {f : PadicSeq p} (hf : ¬f ≈ 0) :
f.norm = (p : ℚ) ^ (-f.valuation : ℤ) := by
rw [norm, valuation, dif_neg hf, dif_neg hf, padicNorm, if_neg]
intro H
apply CauSeq.not_limZero_of_not_congr_zero hf
intro ε hε
use stationaryPoint hf
intro n hn
rw [stationaryPoint_spec hf le_rfl hn]
simpa [H] using hε
@[deprecated (since := "2024-12-10")] alias norm_eq_pow_val := norm_eq_zpow_neg_valuation
theorem val_eq_iff_norm_eq {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) :
f.valuation = g.valuation ↔ f.norm = g.norm := by
rw [norm_eq_zpow_neg_valuation hf, norm_eq_zpow_neg_valuation hg, ← neg_inj, zpow_right_inj₀]
· exact mod_cast (Fact.out : p.Prime).pos
· exact mod_cast (Fact.out : p.Prime).ne_one
end Valuation
end PadicSeq
section
open PadicSeq
-- Porting note: Commented out `padic_index_simp` tactic
/-
private unsafe def index_simp_core (hh hf hg : expr)
(at_ : Interactive.Loc := Interactive.Loc.ns [none]) : tactic Unit := do
let [v1, v2, v3] ← [hh, hf, hg].mapM fun n => tactic.mk_app `` stationary_point [n] <|> return n
let e1 ← tactic.mk_app `` lift_index_left_left [hh, v2, v3] <|> return q(True)
let e2 ← tactic.mk_app `` lift_index_left [hf, v1, v3] <|> return q(True)
let e3 ← tactic.mk_app `` lift_index_right [hg, v1, v2] <|> return q(True)
let sl ← [e1, e2, e3].foldlM (fun s e => simp_lemmas.add s e) simp_lemmas.mk
when at_ (tactic.simp_target sl >> tactic.skip)
let hs ← at_.get_locals
hs (tactic.simp_hyp sl [])
/-- This is a special-purpose tactic that lifts `padicNorm (f (stationary_point f))` to
`padicNorm (f (max _ _ _))`. -/
unsafe def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)
(at_ : interactive.parse interactive.types.location) : tactic Unit := do
let [h, f, g] ← l.mapM tactic.i_to_expr
index_simp_core h f g at_
-/
end
namespace PadicSeq
section Embedding
open CauSeq
variable {p : ℕ} [hp : Fact p.Prime]
theorem norm_mul (f g : PadicSeq p) : (f * g).norm = f.norm * g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : f * g ≈ 0 := mul_equiv_zero' _ hf
simp only [hf, hg, norm, dif_pos, zero_mul]
else
if hg : g ≈ 0 then by
have hf : f * g ≈ 0 := mul_equiv_zero _ hg
simp only [hf, hg, norm, dif_pos, mul_zero]
else by
unfold norm
have hfg := mul_not_equiv_zero hf hg
simp only [hfg, hf, hg, dite_false]
-- Porting note: originally `padic_index_simp [hfg, hf, hg]`
rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
apply padicNorm.mul
theorem eq_zero_iff_equiv_zero (f : PadicSeq p) : mk f = 0 ↔ f ≈ 0 :=
mk_eq
theorem ne_zero_iff_nequiv_zero (f : PadicSeq p) : mk f ≠ 0 ↔ ¬f ≈ 0 :=
eq_zero_iff_equiv_zero _ |>.not
theorem norm_const (q : ℚ) : norm (const (padicNorm p) q) = padicNorm p q := by
obtain rfl | hq := eq_or_ne q 0
· simp [norm]
· simp [norm, not_equiv_zero_const_of_nonzero hq]
theorem norm_values_discrete (a : PadicSeq p) (ha : ¬a ≈ 0) : ∃ z : ℤ, a.norm = (p : ℚ) ^ (-z) := by
let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha
simpa [hk] using padicNorm.values_discrete hk'
theorem norm_one : norm (1 : PadicSeq p) = 1 := by
have h1 : ¬(1 : PadicSeq p) ≈ 0 := one_not_equiv_zero _
simp [h1, norm, hp.1.one_lt]
private theorem norm_eq_of_equiv_aux {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g)
(h : padicNorm p (f (stationaryPoint hf)) ≠ padicNorm p (g (stationaryPoint hg)))
(hlt : padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) :
False := by
have hpn : 0 < padicNorm p (f (stationaryPoint hf)) - padicNorm p (g (stationaryPoint hg)) :=
sub_pos_of_lt hlt
obtain ⟨N, hN⟩ := hfg _ hpn
let i := max N (max (stationaryPoint hf) (stationaryPoint hg))
have hi : N ≤ i := le_max_left _ _
have hN' := hN _ hi
-- Porting note: originally `padic_index_simp [N, hf, hg] at hN' h hlt`
rw [lift_index_left hf N (stationaryPoint hg), lift_index_right hg N (stationaryPoint hf)]
at hN' h hlt
have hpne : padicNorm p (f i) ≠ padicNorm p (-g i) := by rwa [← padicNorm.neg (g i)] at h
rw [CauSeq.sub_apply, sub_eq_add_neg, add_eq_max_of_ne hpne, padicNorm.neg, max_eq_left_of_lt hlt]
at hN'
have : padicNorm p (f i) < padicNorm p (f i) := by
apply lt_of_lt_of_le hN'
apply sub_le_self
apply padicNorm.nonneg
exact lt_irrefl _ this
private theorem norm_eq_of_equiv {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) :
padicNorm p (f (stationaryPoint hf)) = padicNorm p (g (stationaryPoint hg)) := by
by_contra h
cases lt_or_le (padicNorm p (g (stationaryPoint hg))) (padicNorm p (f (stationaryPoint hf))) with
| inl hlt =>
exact norm_eq_of_equiv_aux hf hg hfg h hlt
| inr hle =>
apply norm_eq_of_equiv_aux hg hf (Setoid.symm hfg) (Ne.symm h)
exact lt_of_le_of_ne hle h
theorem norm_equiv {f g : PadicSeq p} (hfg : f ≈ g) : f.norm = g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : g ≈ 0 := Setoid.trans (Setoid.symm hfg) hf
simp [norm, hf, hg]
else by
have hg : ¬g ≈ 0 := hf ∘ Setoid.trans hfg
unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg
private theorem norm_nonarchimedean_aux {f g : PadicSeq p} (hfg : ¬f + g ≈ 0) (hf : ¬f ≈ 0)
(hg : ¬g ≈ 0) : (f + g).norm ≤ max f.norm g.norm := by
unfold norm; split_ifs
-- Porting note: originally `padic_index_simp [hfg, hf, hg]`
rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
apply padicNorm.nonarchimedean
theorem norm_nonarchimedean (f g : PadicSeq p) : (f + g).norm ≤ max f.norm g.norm := by
classical
exact if hfg : f + g ≈ 0 then by
have : 0 ≤ max f.norm g.norm := le_max_of_le_left (norm_nonneg _)
simpa only [hfg, norm]
else
if hf : f ≈ 0 then by
have hfg' : f + g ≈ g := by
change LimZero (f - 0) at hf
show LimZero (f + g - g); · simpa only [sub_zero, add_sub_cancel_right] using hf
have hcfg : (f + g).norm = g.norm := norm_equiv hfg'
have hcl : f.norm = 0 := (norm_zero_iff f).2 hf
have : max f.norm g.norm = g.norm := by rw [hcl]; exact max_eq_right (norm_nonneg _)
rw [this, hcfg]
else
if hg : g ≈ 0 then by
have hfg' : f + g ≈ f := by
change LimZero (g - 0) at hg
show LimZero (f + g - f); · simpa only [add_sub_cancel_left, sub_zero] using hg
have hcfg : (f + g).norm = f.norm := norm_equiv hfg'
have hcl : g.norm = 0 := (norm_zero_iff g).2 hg
have : max f.norm g.norm = f.norm := by rw [hcl]; exact max_eq_left (norm_nonneg _)
rw [this, hcfg]
else norm_nonarchimedean_aux hfg hf hg
theorem norm_eq {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) :
f.norm = g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : g ≈ 0 := equiv_zero_of_val_eq_of_equiv_zero h hf
simp only [hf, hg, norm, dif_pos]
else by
have hg : ¬g ≈ 0 := fun hg ↦
hf <| equiv_zero_of_val_eq_of_equiv_zero (by simp only [h, forall_const, eq_self_iff_true]) hg
simp only [hg, hf, norm, dif_neg, not_false_iff]
let i := max (stationaryPoint hf) (stationaryPoint hg)
have hpf : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f i) := by
apply stationaryPoint_spec
· apply le_max_left
· exact le_rfl
have hpg : padicNorm p (g (stationaryPoint hg)) = padicNorm p (g i) := by
apply stationaryPoint_spec
· apply le_max_right
· exact le_rfl
rw [hpf, hpg, h]
theorem norm_neg (a : PadicSeq p) : (-a).norm = a.norm :=
norm_eq <| by simp
theorem norm_eq_of_add_equiv_zero {f g : PadicSeq p} (h : f + g ≈ 0) : f.norm = g.norm := by
have : LimZero (f + g - 0) := h
have : f ≈ -g := show LimZero (f - -g) by simpa only [sub_zero, sub_neg_eq_add]
have : f.norm = (-g).norm := norm_equiv this
simpa only [norm_neg] using this
theorem add_eq_max_of_ne {f g : PadicSeq p} (hfgne : f.norm ≠ g.norm) :
(f + g).norm = max f.norm g.norm := by
classical
have hfg : ¬f + g ≈ 0 := mt norm_eq_of_add_equiv_zero hfgne
exact if hf : f ≈ 0 then by
have : LimZero (f - 0) := hf
have : f + g ≈ g := show LimZero (f + g - g) by simpa only [sub_zero, add_sub_cancel_right]
have h1 : (f + g).norm = g.norm := norm_equiv this
have h2 : f.norm = 0 := (norm_zero_iff _).2 hf
rw [h1, h2, max_eq_right (norm_nonneg _)]
else
if hg : g ≈ 0 then by
have : LimZero (g - 0) := hg
have : f + g ≈ f := show LimZero (f + g - f) by simpa only [add_sub_cancel_left, sub_zero]
have h1 : (f + g).norm = f.norm := norm_equiv this
have h2 : g.norm = 0 := (norm_zero_iff _).2 hg
rw [h1, h2, max_eq_left (norm_nonneg _)]
else by
unfold norm at hfgne ⊢; split_ifs at hfgne ⊢
-- Porting note: originally `padic_index_simp [hfg, hf, hg] at hfgne ⊢`
rw [lift_index_left hf, lift_index_right hg] at hfgne
· rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
exact padicNorm.add_eq_max_of_ne hfgne
end Embedding
end PadicSeq
/-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm.
-/
def Padic (p : ℕ) [Fact p.Prime] :=
CauSeq.Completion.Cauchy (padicNorm p)
/-- notation for p-padic rationals -/
notation "ℚ_[" p "]" => Padic p
namespace Padic
section Completion
variable {p : ℕ} [Fact p.Prime]
instance field : Field ℚ_[p] :=
Cauchy.field
instance : Inhabited ℚ_[p] :=
⟨0⟩
-- short circuits
instance : CommRing ℚ_[p] :=
Cauchy.commRing
instance : Ring ℚ_[p] :=
Cauchy.ring
instance : Zero ℚ_[p] := by infer_instance
instance : One ℚ_[p] := by infer_instance
instance : Add ℚ_[p] := by infer_instance
instance : Mul ℚ_[p] := by infer_instance
instance : Sub ℚ_[p] := by infer_instance
instance : Neg ℚ_[p] := by infer_instance
instance : Div ℚ_[p] := by infer_instance
instance : AddCommGroup ℚ_[p] := by infer_instance
/-- Builds the equivalence class of a Cauchy sequence of rationals. -/
def mk : PadicSeq p → ℚ_[p] :=
Quotient.mk'
variable (p)
theorem zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl
theorem mk_eq {f g : PadicSeq p} : mk f = mk g ↔ f ≈ g :=
Quotient.eq'
theorem const_equiv {q r : ℚ} : const (padicNorm p) q ≈ const (padicNorm p) r ↔ q = r :=
⟨fun heq ↦ eq_of_sub_eq_zero <| const_limZero.1 heq, fun heq ↦ by
rw [heq]⟩
@[norm_cast]
theorem coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r :=
⟨(const_equiv p).1 ∘ Quotient.eq'.1, fun h ↦ by rw [h]⟩
instance : CharZero ℚ_[p] :=
⟨fun m n ↦ by
rw [← Rat.cast_natCast]
norm_cast
exact id⟩
@[norm_cast]
theorem coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y :=
Rat.cast_add _ _
@[norm_cast]
theorem coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x :=
Rat.cast_neg _
@[norm_cast]
theorem coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y :=
Rat.cast_mul _ _
@[norm_cast]
theorem coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y :=
Rat.cast_sub _ _
@[norm_cast]
theorem coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y :=
Rat.cast_div _ _
@[norm_cast]
theorem coe_one : (↑(1 : ℚ) : ℚ_[p]) = 1 := rfl
@[norm_cast]
theorem coe_zero : (↑(0 : ℚ) : ℚ_[p]) = 0 := rfl
end Completion
end Padic
/-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The
canonical form of this function is the normed space instance, with notation `‖ ‖`. -/
def padicNormE {p : ℕ} [hp : Fact p.Prime] : AbsoluteValue ℚ_[p] ℚ where
toFun := Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _
map_mul' q r := Quotient.inductionOn₂ q r <| PadicSeq.norm_mul
nonneg' q := Quotient.inductionOn q <| PadicSeq.norm_nonneg
eq_zero' q := Quotient.inductionOn q fun r ↦ by
rw [Padic.zero_def, Quotient.eq]
exact PadicSeq.norm_zero_iff r
add_le' q r := by
trans
max ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) q)
((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) r)
· exact Quotient.inductionOn₂ q r <| PadicSeq.norm_nonarchimedean
refine max_le_add_of_nonneg (Quotient.inductionOn q <| PadicSeq.norm_nonneg) ?_
exact Quotient.inductionOn r <| PadicSeq.norm_nonneg
namespace padicNormE
section Embedding
open PadicSeq
variable {p : ℕ} [Fact p.Prime]
theorem defn (f : PadicSeq p) {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padicNormE (Padic.mk f - f i : ℚ_[p]) < ε := by
dsimp [padicNormE]
-- `change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε` also works, but is very slow
suffices hyp : ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε by peel hyp with N; use N
by_contra! h
obtain ⟨N, hN⟩ := cauchy₂ f hε
rcases h N with ⟨i, hi, hge⟩
have hne : ¬f - const (padicNorm p) (f i) ≈ 0 := fun h ↦ by
rw [PadicSeq.norm, dif_pos h] at hge
exact not_lt_of_ge hge hε
unfold PadicSeq.norm at hge; split_ifs at hge
apply not_le_of_gt _ hge
cases _root_.le_total N (stationaryPoint hne) with
| inl hgen =>
exact hN _ hgen _ hi
| inr hngen =>
have := stationaryPoint_spec hne le_rfl hngen
rw [← this]
exact hN _ le_rfl _ hi
/-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem nonarchimedean' (q r : ℚ_[p]) :
padicNormE (q + r : ℚ_[p]) ≤ max (padicNormE q) (padicNormE r) :=
Quotient.inductionOn₂ q r <| norm_nonarchimedean
/-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem add_eq_max_of_ne' {q r : ℚ_[p]} :
padicNormE q ≠ padicNormE r → padicNormE (q + r : ℚ_[p]) = max (padicNormE q) (padicNormE r) :=
Quotient.inductionOn₂ q r fun _ _ ↦ PadicSeq.add_eq_max_of_ne
@[simp]
theorem eq_padic_norm' (q : ℚ) : padicNormE (q : ℚ_[p]) = padicNorm p q :=
norm_const _
protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padicNormE q = (p : ℚ) ^ (-n) :=
Quotient.inductionOn q fun f hf ↦
have : ¬f ≈ 0 := (ne_zero_iff_nequiv_zero f).1 hf
norm_values_discrete f this
end Embedding
end padicNormE
namespace Padic
section Complete
open PadicSeq Padic
variable {p : ℕ} [Fact p.Prime] (f : CauSeq _ (@padicNormE p _))
theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) : ∃ r : ℚ, padicNormE (q - r : ℚ_[p]) < ε :=
Quotient.inductionOn q fun q' ↦
have : ∃ N, ∀ m ≥ N, ∀ n ≥ N, padicNorm p (q' m - q' n) < ε := cauchy₂ _ hε
let ⟨N, hN⟩ := this
⟨q' N, by
classical
dsimp [padicNormE]
-- Porting note: this used to be `change`, but that times out.
convert_to PadicSeq.norm (q' - const _ (q' N)) < ε
rcases Decidable.em (q' - const (padicNorm p) (q' N) ≈ 0) with heq | hne'
· simpa only [heq, PadicSeq.norm, dif_pos]
· simp only [PadicSeq.norm, dif_neg hne']
change padicNorm p (q' _ - q' _) < ε
rcases Decidable.em (stationaryPoint hne' ≤ N) with hle | hle
· have := (stationaryPoint_spec hne' le_rfl hle).symm
simp only [const_apply, sub_apply, padicNorm.zero, sub_self] at this
simpa only [this]
· exact hN _ (lt_of_not_ge hle).le _ le_rfl⟩
private theorem div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) :=
div_pos zero_lt_one (mod_cast succ_pos _)
/-- `limSeq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the
same limit point as `f`. -/
def limSeq : ℕ → ℚ :=
fun n ↦ Classical.choose (rat_dense' (f n) (div_nat_pos n))
theorem exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padicNormE (f i - (limSeq f i : ℚ_[p]) : ℚ_[p]) < ε := by
refine (exists_nat_gt (1 / ε)).imp fun N hN i hi ↦ ?_
have h := Classical.choose_spec (rat_dense' (f i) (div_nat_pos i))
refine lt_of_lt_of_le h ((div_le_iff₀' <| mod_cast succ_pos _).mpr ?_)
rw [right_distrib]
apply le_add_of_le_of_nonneg
· exact (div_le_iff₀ hε).mp (le_trans (le_of_lt hN) (mod_cast hi))
· apply le_of_lt
simpa
theorem exi_rat_seq_conv_cauchy : IsCauSeq (padicNorm p) (limSeq f) := fun ε hε ↦ by
have hε3 : 0 < ε / 3 := div_pos hε (by norm_num)
let ⟨N, hN⟩ := exi_rat_seq_conv f hε3
let ⟨N2, hN2⟩ := f.cauchy₂ hε3
exists max N N2
intro j hj
suffices
padicNormE (limSeq f j - f (max N N2) + (f (max N N2) - limSeq f (max N N2)) : ℚ_[p]) < ε by
ring_nf at this ⊢
rw [← padicNormE.eq_padic_norm']
exact mod_cast this
apply lt_of_le_of_lt
· apply padicNormE.add_le
· rw [← add_thirds ε]
apply _root_.add_lt_add
· suffices padicNormE (limSeq f j - f j + (f j - f (max N N2)) : ℚ_[p]) < ε / 3 + ε / 3 by
simpa only [sub_add_sub_cancel]
apply lt_of_le_of_lt
· apply padicNormE.add_le
· apply _root_.add_lt_add
· rw [padicNormE.map_sub]
apply mod_cast hN j
exact le_of_max_le_left hj
· exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _)
· apply mod_cast hN (max N N2)
apply le_max_left
private def lim' : PadicSeq p :=
⟨_, exi_rat_seq_conv_cauchy f⟩
private def lim : ℚ_[p] :=
⟦lim' f⟧
theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (q - f i : ℚ_[p]) < ε :=
⟨lim f, fun ε hε ↦ by
obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε)
obtain ⟨N2, hN2⟩ := padicNormE.defn (lim' f) (half_pos hε)
refine ⟨max N N2, fun i hi ↦ ?_⟩
rw [← sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _]
refine (padicNormE.add_le _ _).trans_lt ?_
rw [← add_halves ε]
apply _root_.add_lt_add
· apply hN2 _ (le_of_max_le_right hi)
· rw [padicNormE.map_sub]
exact hN _ (le_of_max_le_left hi)⟩
theorem complete'' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (f i - q : ℚ_[p]) < ε := by
obtain ⟨x, hx⟩ := complete' f
refine ⟨x, fun ε hε => ?_⟩
obtain ⟨N, hN⟩ := hx ε hε
refine ⟨N, fun i hi => ?_⟩
rw [padicNormE.map_sub]
exact hN i hi
end Complete
section NormedSpace
variable (p : ℕ) [Fact p.Prime]
instance : Dist ℚ_[p] :=
⟨fun x y ↦ padicNormE (x - y : ℚ_[p])⟩
instance : IsUltrametricDist ℚ_[p] :=
⟨fun x y z ↦ by simpa [dist] using padicNormE.nonarchimedean' (x - y) (y - z)⟩
instance metricSpace : MetricSpace ℚ_[p] where
dist_self := by simp [dist]
dist := dist
dist_comm x y := by simp [dist, ← padicNormE.map_neg (x - y : ℚ_[p])]
dist_triangle x y z := by
dsimp [dist]
exact mod_cast padicNormE.sub_le x y z
eq_of_dist_eq_zero := by
dsimp [dist]; intro _ _ h
apply eq_of_sub_eq_zero
apply padicNormE.eq_zero.1
exact mod_cast h
instance : Norm ℚ_[p] :=
⟨fun x ↦ padicNormE x⟩
instance normedField : NormedField ℚ_[p] :=
{ Padic.field,
Padic.metricSpace p with
dist_eq := fun _ _ ↦ rfl
norm_mul := by simp [Norm.norm, map_mul]
norm := norm }
instance isAbsoluteValue : IsAbsoluteValue fun a : ℚ_[p] ↦ ‖a‖ where
abv_nonneg' := norm_nonneg
abv_eq_zero' := norm_eq_zero
abv_add' := norm_add_le
abv_mul' := by simp [Norm.norm, map_mul]
theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε :=
let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε
let ⟨r, hr⟩ := rat_dense' q (ε := ε') (by simpa using hε'l)
⟨r, lt_trans (by simpa [Norm.norm] using hr) hε'r⟩
end NormedSpace
end Padic
namespace padicNormE
section NormedSpace
variable {p : ℕ} [hp : Fact p.Prime]
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
protected theorem mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ := by simp [Norm.norm, map_mul]
protected theorem is_norm (q : ℚ_[p]) : ↑(padicNormE q) = ‖q‖ := rfl
theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := by
dsimp [norm]
exact mod_cast nonarchimedean' _ _
theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max ‖q‖ ‖r‖ := by
dsimp [norm] at h ⊢
have : padicNormE q ≠ padicNormE r := mod_cast h
exact mod_cast add_eq_max_of_ne' this
@[simp]
theorem eq_padicNorm (q : ℚ) : ‖(q : ℚ_[p])‖ = padicNorm p q := by
dsimp [norm]
rw [← padicNormE.eq_padic_norm']
@[simp]
theorem norm_p : ‖(p : ℚ_[p])‖ = (p : ℝ)⁻¹ := by
rw [← @Rat.cast_natCast ℝ _ p]
rw [← @Rat.cast_natCast ℚ_[p] _ p]
simp [hp.1.ne_zero, hp.1.ne_one, norm, padicNorm, padicValRat, padicValInt, zpow_neg,
-Rat.cast_natCast]
theorem norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 := by
rw [norm_p]
exact inv_lt_one_of_one_lt₀ <| mod_cast hp.1.one_lt
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
theorem norm_p_zpow (n : ℤ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n) := by
rw [norm_zpow, norm_p, zpow_neg, inv_zpow]
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
theorem norm_p_pow (n : ℕ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by
rw [← norm_p_zpow, zpow_natCast]
instance : NontriviallyNormedField ℚ_[p] :=
{ Padic.normedField p with
non_trivial :=
⟨p⁻¹, by
rw [norm_inv, norm_p, inv_inv]
exact mod_cast hp.1.one_lt⟩ }
protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ (-n)) :=
Quotient.inductionOn q fun f hf ↦
have : ¬f ≈ 0 := (PadicSeq.ne_zero_iff_nequiv_zero f).1 hf
let ⟨n, hn⟩ := PadicSeq.norm_values_discrete f this
⟨n, by rw [← hn]; rfl⟩
protected theorem is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' := by
classical
exact if h : q = 0 then ⟨0, by simp [h]⟩
else
let ⟨n, hn⟩ := padicNormE.image h
⟨_, hn⟩
/-- `ratNorm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.
| The lemma `padicNormE.eq_ratNorm` asserts `‖q‖ = ratNorm q`. -/
| Mathlib/NumberTheory/Padics/PadicNumbers.lean | 813 | 813 |
/-
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.Composition.MapComap
import Mathlib.Probability.Martingale.Convergence
import Mathlib.Probability.Process.PartitionFiltration
/-!
# Kernel density
Let `κ : Kernel α (γ × β)` and `ν : Kernel α γ` be two finite kernels with `Kernel.fst κ ≤ ν`,
where `γ` has a countably generated σ-algebra (true in particular for standard Borel spaces).
We build a function `density κ ν : α → γ → Set β → ℝ` jointly measurable in the first two arguments
such that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`,
`∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)`.
There are two main applications of this construction.
* Disintegration of kernels: for `κ : Kernel α (γ × β)`, we want to build a kernel
`η : Kernel (α × γ) β` such that `κ = fst κ ⊗ₖ η`. For `β = ℝ`, we can use the density of `κ`
with respect to `fst κ` for intervals to build a kernel cumulative distribution function for `η`.
The construction can then be extended to `β` standard Borel.
* Radon-Nikodym theorem for kernels: for `κ ν : Kernel α γ`, we can use the density to build a
Radon-Nikodym derivative of `κ` with respect to `ν`. We don't need `β` here but we can apply the
density construction to `β = Unit`. The derivative construction will use `density` but will not
be exactly equal to it because we will want to remove the `fst κ ≤ ν` assumption.
## Main definitions
* `ProbabilityTheory.Kernel.density`: for `κ : Kernel α (γ × β)` and `ν : Kernel α γ` two finite
kernels, `Kernel.density κ ν` is a function `α → γ → Set β → ℝ`.
## Main statements
* `ProbabilityTheory.Kernel.setIntegral_density`: for all measurable sets `A : Set γ` and
`s : Set β`, `∫ x in A, Kernel.density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)`.
* `ProbabilityTheory.Kernel.measurable_density`: the function
`p : α × γ ↦ Kernel.density κ ν p.1 p.2 s` is measurable.
## Construction of the density
If we were interested only in a fixed `a : α`, then we could use the Radon-Nikodym derivative to
build the density function `density κ ν`, as follows.
```
def density' (κ : Kernel α (γ × β)) (ν : kernel a γ) (a : α) (x : γ) (s : Set β) : ℝ :=
(((κ a).restrict (univ ×ˢ s)).fst.rnDeriv (ν a) x).toReal
```
However, we can't turn those functions for each `a` into a measurable function of the pair `(a, x)`.
In order to obtain measurability through countability, we use the fact that the measurable space `γ`
is countably generated. For each `n : ℕ`, we define (in the file
`Mathlib.Probability.Process.PartitionFiltration`) a finite partition of `γ`, such that those
partitions are finer as `n` grows, and the σ-algebra generated by the union of all partitions is the
σ-algebra of `γ`. For `x : γ`, `countablePartitionSet n x` denotes the set in the partition such
that `x ∈ countablePartitionSet n x`.
For a given `n`, the function `densityProcess κ ν n : α → γ → Set β → ℝ` defined by
`fun a x s ↦ (κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal` has
the desired property that `∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a (A ×ˢ s)).toReal` for
all `A` in the σ-algebra generated by the partition at scale `n` and is measurable in `(a, x)`.
`countableFiltration γ` is the filtration of those σ-algebras for all `n : ℕ`.
The functions `densityProcess κ ν n` described here are a bounded `ν`-martingale for the filtration
`countableFiltration γ`. By Doob's martingale L1 convergence theorem, that martingale converges to
a limit, which has a product-measurable version and satisfies the integral equality for all `A` in
`⨆ n, countableFiltration γ n`. Finally, the partitions were chosen such that that supremum is equal
to the σ-algebra on `γ`, hence the equality holds for all measurable sets.
We have obtained the desired density function.
## References
The construction of the density process in this file follows the proof of Theorem 9.27 in
[O. Kallenberg, Foundations of modern probability][kallenberg2021], adapted to use a countably
generated hypothesis instead of specializing to `ℝ`.
-/
open MeasureTheory Set Filter MeasurableSpace
open scoped NNReal ENNReal MeasureTheory Topology ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {α β γ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
[CountablyGenerated γ] {κ : Kernel α (γ × β)} {ν : Kernel α γ}
section DensityProcess
/-- An `ℕ`-indexed martingale that is a density for `κ` with respect to `ν` on the sets in
`countablePartition γ n`. Used to define its limit `ProbabilityTheory.Kernel.density`, which is
a density for those kernels for all measurable sets. -/
noncomputable
def densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) (s : Set β) :
ℝ :=
(κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x)).toReal
lemma densityProcess_def (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (s : Set β) :
(fun t ↦ densityProcess κ ν n a t s)
= fun t ↦ (κ a (countablePartitionSet n t ×ˢ s) / ν a (countablePartitionSet n t)).toReal :=
rfl
lemma measurable_densityProcess_countableFiltration_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ)
(n : ℕ) {s : Set β} (hs : MeasurableSet s) :
Measurable[mα.prod (countableFiltration γ n)] (fun (p : α × γ) ↦
κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by
change Measurable[mα.prod (countableFiltration γ n)]
((fun (p : α × countablePartition γ n) ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2)
∘ (fun (p : α × γ) ↦ (p.1, ⟨countablePartitionSet n p.2, countablePartitionSet_mem n p.2⟩)))
have h1 : @Measurable _ _ (mα.prod ⊤) _
(fun p : α × countablePartition γ n ↦ κ p.1 (↑p.2 ×ˢ s) / ν p.1 p.2) := by
refine Measurable.div ?_ ?_
· refine measurable_from_prod_countable (fun t ↦ ?_)
exact Kernel.measurable_coe _ ((measurableSet_countablePartition _ t.prop).prod hs)
· refine measurable_from_prod_countable ?_
rintro ⟨t, ht⟩
exact Kernel.measurable_coe _ (measurableSet_countablePartition _ ht)
refine h1.comp (measurable_fst.prodMk ?_)
change @Measurable (α × γ) (countablePartition γ n) (mα.prod (countableFiltration γ n)) ⊤
((fun c ↦ ⟨countablePartitionSet n c, countablePartitionSet_mem n c⟩) ∘ (fun p : α × γ ↦ p.2))
exact (measurable_countablePartitionSet_subtype n ⊤).comp measurable_snd
lemma measurable_densityProcess_aux (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦
κ p.1 (countablePartitionSet n p.2 ×ˢ s) / ν p.1 (countablePartitionSet n p.2)) := by
refine Measurable.mono (measurable_densityProcess_countableFiltration_aux κ ν n hs) ?_ le_rfl
exact sup_le_sup le_rfl (comap_mono ((countableFiltration γ).le _))
lemma measurable_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦ densityProcess κ ν n p.1 p.2 s) :=
(measurable_densityProcess_aux κ ν n hs).ennreal_toReal
-- The following two lemmas also work without the `( :)`, but they are slow.
lemma measurable_densityProcess_left (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
(x : γ) {s : Set β} (hs : MeasurableSet s) :
Measurable (fun a ↦ densityProcess κ ν n a x s) :=
((measurable_densityProcess κ ν n hs).comp (measurable_id.prodMk measurable_const):)
lemma measurable_densityProcess_right (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
{s : Set β} (a : α) (hs : MeasurableSet s) :
Measurable (fun x ↦ densityProcess κ ν n a x s) :=
((measurable_densityProcess κ ν n hs).comp (measurable_const.prodMk measurable_id):)
lemma measurable_countableFiltration_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
(a : α) {s : Set β} (hs : MeasurableSet s) :
Measurable[countableFiltration γ n] (fun x ↦ densityProcess κ ν n a x s) := by
refine @Measurable.ennreal_toReal _ (countableFiltration γ n) _ ?_
exact (measurable_densityProcess_countableFiltration_aux κ ν n hs).comp measurable_prodMk_left
lemma stronglyMeasurable_countableFiltration_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ)
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) :
StronglyMeasurable[countableFiltration γ n] (fun x ↦ densityProcess κ ν n a x s) :=
(measurable_countableFiltration_densityProcess κ ν n a hs).stronglyMeasurable
lemma adapted_densityProcess (κ : Kernel α (γ × β)) (ν : Kernel α γ) (a : α)
{s : Set β} (hs : MeasurableSet s) :
Adapted (countableFiltration γ) (fun n x ↦ densityProcess κ ν n a x s) :=
fun n ↦ stronglyMeasurable_countableFiltration_densityProcess κ ν n a hs
lemma densityProcess_nonneg (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ)
(a : α) (x : γ) (s : Set β) :
0 ≤ densityProcess κ ν n a x s :=
ENNReal.toReal_nonneg
lemma meas_countablePartitionSet_le_of_fst_le (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ)
(s : Set β) :
κ a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) := by
calc κ a (countablePartitionSet n x ×ˢ s)
≤ fst κ a (countablePartitionSet n x) := by
rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)]
refine measure_mono (fun x ↦ ?_)
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
_ ≤ ν a (countablePartitionSet n x) := hκν a _
lemma densityProcess_le_one (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) :
densityProcess κ ν n a x s ≤ 1 := by
refine ENNReal.toReal_le_of_le_ofReal zero_le_one (ENNReal.div_le_of_le_mul ?_)
rw [ENNReal.ofReal_one, one_mul]
exact meas_countablePartitionSet_le_of_fst_le hκν n a x s
lemma eLpNorm_densityProcess_le (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (s : Set β) :
eLpNorm (fun x ↦ densityProcess κ ν n a x s) 1 (ν a) ≤ ν a univ := by
refine (eLpNorm_le_of_ae_bound (C := 1) (ae_of_all _ (fun x ↦ ?_))).trans ?_
· simp only [Real.norm_eq_abs, abs_of_nonneg (densityProcess_nonneg κ ν n a x s),
densityProcess_le_one hκν n a x s]
· simp
lemma integrable_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (n : ℕ)
(a : α) {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x ↦ densityProcess κ ν n a x s) (ν a) := by
rw [← memLp_one_iff_integrable]
refine ⟨Measurable.aestronglyMeasurable ?_, ?_⟩
· exact measurable_densityProcess_right κ ν n a hs
· exact (eLpNorm_densityProcess_le hκν n a s).trans_lt (measure_lt_top _ _)
lemma setIntegral_densityProcess_of_mem (hκν : fst κ ≤ ν) [hν : IsFiniteKernel ν]
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {u : Set γ}
(hu : u ∈ countablePartition γ n) :
∫ x in u, densityProcess κ ν n a x s ∂(ν a) = (κ a).real (u ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
have hu_meas : MeasurableSet u := measurableSet_countablePartition n hu
simp_rw [densityProcess]
rw [integral_toReal]
rotate_left
· refine Measurable.aemeasurable ?_
change Measurable ((fun (p : α × _) ↦ κ p.1 (countablePartitionSet n p.2 ×ˢ s)
/ ν p.1 (countablePartitionSet n p.2)) ∘ (fun x ↦ (a, x)))
exact (measurable_densityProcess_aux κ ν n hs).comp measurable_prodMk_left
· refine ae_of_all _ (fun x ↦ ?_)
by_cases h0 : ν a (countablePartitionSet n x) = 0
· suffices κ a (countablePartitionSet n x ×ˢ s) = 0 by simp [h0, this]
have h0' : fst κ a (countablePartitionSet n x) = 0 :=
le_antisymm ((hκν a _).trans h0.le) zero_le'
rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h0'
refine measure_mono_null (fun x ↦ ?_) h0'
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
· exact ENNReal.div_lt_top (measure_ne_top _ _) h0
congr
have : ∫⁻ x in u, κ a (countablePartitionSet n x ×ˢ s) / ν a (countablePartitionSet n x) ∂(ν a)
= ∫⁻ _ in u, κ a (u ×ˢ s) / ν a u ∂(ν a) := by
refine setLIntegral_congr_fun hu_meas (ae_of_all _ (fun t ht ↦ ?_))
rw [countablePartitionSet_of_mem hu ht]
rw [this]
simp only [MeasureTheory.lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter]
by_cases h0 : ν a u = 0
· simp only [h0, mul_zero]
have h0' : fst κ a u = 0 := le_antisymm ((hκν a _).trans h0.le) zero_le'
rw [fst_apply' _ _ hu_meas] at h0'
refine (measure_mono_null ?_ h0').symm
intro p
simp only [mem_prod, mem_setOf_eq, and_imp]
exact fun h _ ↦ h
rw [div_eq_mul_inv, mul_assoc, ENNReal.inv_mul_cancel h0, mul_one]
exact measure_ne_top _ _
open scoped Function in -- required for scoped `on` notation
lemma setIntegral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ}
(hA : MeasurableSet[countableFiltration γ n] A) :
∫ x in A, densityProcess κ ν n a x s ∂(ν a) = (κ a).real (A ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
obtain ⟨S, hS_subset, rfl⟩ := (measurableSet_generateFrom_countablePartition_iff _ _).mp hA
simp_rw [sUnion_eq_iUnion]
have h_disj : Pairwise (Disjoint on fun i : S ↦ (i : Set γ)) := by
intro u v huv
#adaptation_note /-- nightly-2024-03-16
Previously `Function.onFun` unfolded in the following `simp only`,
but now needs a `rw`.
This may be a bug: a no import minimization may be required.
simp only [Finset.coe_sort_coe, Function.onFun] -/
rw [Function.onFun]
refine disjoint_countablePartition (hS_subset (by simp)) (hS_subset (by simp)) ?_
rwa [ne_eq, ← Subtype.ext_iff]
rw [integral_iUnion, iUnion_prod_const, measureReal_def, measure_iUnion,
ENNReal.tsum_toReal_eq (fun _ ↦ measure_ne_top _ _)]
· congr with u
rw [setIntegral_densityProcess_of_mem hκν _ _ hs (hS_subset (by simp))]
rfl
· intro u v huv
simp only [Finset.coe_sort_coe, Set.disjoint_prod, disjoint_self, bot_eq_empty]
exact Or.inl (h_disj huv)
· exact fun _ ↦ (measurableSet_countablePartition n (hS_subset (by simp))).prod hs
· exact fun _ ↦ measurableSet_countablePartition n (hS_subset (by simp))
· exact h_disj
· exact (integrable_densityProcess hκν _ _ hs).integrableOn
lemma integral_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) :
∫ x, densityProcess κ ν n a x s ∂(ν a) = (κ a).real (univ ×ˢ s) := by
rw [← setIntegral_univ, setIntegral_densityProcess hκν _ _ hs MeasurableSet.univ]
lemma setIntegral_densityProcess_of_le (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] {n m : ℕ} (hnm : n ≤ m) (a : α) {s : Set β} (hs : MeasurableSet s)
{A : Set γ} (hA : MeasurableSet[countableFiltration γ n] A) :
∫ x in A, densityProcess κ ν m a x s ∂(ν a) = (κ a).real (A ×ˢ s) :=
setIntegral_densityProcess hκν m a hs ((countableFiltration γ).mono hnm A hA)
lemma condExp_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
{i j : ℕ} (hij : i ≤ j) (a : α) {s : Set β} (hs : MeasurableSet s) :
(ν a)[fun x ↦ densityProcess κ ν j a x s | countableFiltration γ i]
=ᵐ[ν a] fun x ↦ densityProcess κ ν i a x s := by
refine (ae_eq_condExp_of_forall_setIntegral_eq ?_ ?_ ?_ ?_ ?_).symm
· exact integrable_densityProcess hκν j a hs
· exact fun _ _ _ ↦ (integrable_densityProcess hκν _ _ hs).integrableOn
· intro x hx _
rw [setIntegral_densityProcess hκν i a hs hx,
setIntegral_densityProcess_of_le hκν hij a hs hx]
· exact StronglyMeasurable.aestronglyMeasurable
(stronglyMeasurable_countableFiltration_densityProcess κ ν i a hs)
@[deprecated (since := "2025-01-21")] alias condexp_densityProcess := condExp_densityProcess
lemma martingale_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
Martingale (fun n x ↦ densityProcess κ ν n a x s) (countableFiltration γ) (ν a) :=
⟨adapted_densityProcess κ ν a hs, fun _ _ h ↦ condExp_densityProcess hκν h a hs⟩
lemma densityProcess_mono_set (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ)
{s s' : Set β} (h : s ⊆ s') :
densityProcess κ ν n a x s ≤ densityProcess κ ν n a x s' := by
unfold densityProcess
obtain h₀ | h₀ := eq_or_ne (ν a (countablePartitionSet n x)) 0
· simp [h₀]
· gcongr
simp only [ne_eq, ENNReal.div_eq_top, h₀, and_false, false_or, not_and, not_not]
exact eq_top_mono (meas_countablePartitionSet_le_of_fst_le hκν n a x s')
lemma densityProcess_mono_kernel_left {κ' : Kernel α (γ × β)} (hκκ' : κ ≤ κ')
(hκ'ν : fst κ' ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) :
densityProcess κ ν n a x s ≤ densityProcess κ' ν n a x s := by
unfold densityProcess
by_cases h0 : ν a (countablePartitionSet n x) = 0
· rw [h0, ENNReal.toReal_div, ENNReal.toReal_div]
simp
have h_le : κ' a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) :=
meas_countablePartitionSet_le_of_fst_le hκ'ν n a x s
gcongr
· simp only [ne_eq, ENNReal.div_eq_top, h0, and_false, false_or, not_and, not_not]
exact fun h_top ↦ eq_top_mono h_le h_top
· apply hκκ'
lemma densityProcess_antitone_kernel_right {ν' : Kernel α γ}
(hνν' : ν ≤ ν') (hκν : fst κ ≤ ν) (n : ℕ) (a : α) (x : γ) (s : Set β) :
densityProcess κ ν' n a x s ≤ densityProcess κ ν n a x s := by
unfold densityProcess
have h_le : κ a (countablePartitionSet n x ×ˢ s) ≤ ν a (countablePartitionSet n x) :=
meas_countablePartitionSet_le_of_fst_le hκν n a x s
by_cases h0 : ν a (countablePartitionSet n x) = 0
· simp [le_antisymm (h_le.trans h0.le) zero_le', h0]
gcongr
· simp only [ne_eq, ENNReal.div_eq_top, h0, and_false, false_or, not_and, not_not]
exact fun h_top ↦ eq_top_mono h_le h_top
· apply hνν'
@[simp]
lemma densityProcess_empty (κ : Kernel α (γ × β)) (ν : Kernel α γ) (n : ℕ) (a : α) (x : γ) :
densityProcess κ ν n a x ∅ = 0 := by
simp [densityProcess]
lemma tendsto_densityProcess_atTop_empty_of_antitone (κ : Kernel α (γ × β)) (ν : Kernel α γ)
[IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ densityProcess κ ν n a x (seq m)) atTop
(𝓝 (densityProcess κ ν n a x ∅)) := by
simp_rw [densityProcess]
by_cases h0 : ν a (countablePartitionSet n x) = 0
· simp_rw [h0, ENNReal.toReal_div]
simp
refine (ENNReal.tendsto_toReal ?_).comp ?_
· rw [ne_eq, ENNReal.div_eq_top]
push_neg
simp
refine ENNReal.Tendsto.div_const ?_ (.inr h0)
have : Tendsto (fun m ↦ κ a (countablePartitionSet n x ×ˢ seq m)) atTop
(𝓝 ((κ a) (⋂ n_1, countablePartitionSet n x ×ˢ seq n_1))) := by
apply tendsto_measure_iInter_atTop
· measurability
· exact fun _ _ h ↦ prod_mono_right <| hseq h
· exact ⟨0, measure_ne_top _ _⟩
simpa only [← prod_iInter, hseq_iInter] using this
lemma tendsto_densityProcess_atTop_of_antitone (κ : Kernel α (γ × β)) (ν : Kernel α γ)
[IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ densityProcess κ ν n a x (seq m)) atTop (𝓝 0) := by
rw [← densityProcess_empty κ ν n a x]
exact tendsto_densityProcess_atTop_empty_of_antitone κ ν n a x seq hseq hseq_iInter hseq_meas
lemma tendsto_densityProcess_limitProcess (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) :
∀ᵐ x ∂(ν a), Tendsto (fun n ↦ densityProcess κ ν n a x s) atTop
(𝓝 ((countableFiltration γ).limitProcess
(fun n x ↦ densityProcess κ ν n a x s) (ν a) x)) := by
refine Submartingale.ae_tendsto_limitProcess (martingale_densityProcess hκν a hs).submartingale
(R := (ν a univ).toNNReal) (fun n ↦ ?_)
refine (eLpNorm_densityProcess_le hκν n a s).trans_eq ?_
rw [ENNReal.coe_toNNReal]
exact measure_ne_top _ _
lemma memL1_limitProcess_densityProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
MemLp ((countableFiltration γ).limitProcess
(fun n x ↦ densityProcess κ ν n a x s) (ν a)) 1 (ν a) := by
refine Submartingale.memLp_limitProcess (martingale_densityProcess hκν a hs).submartingale
(R := (ν a univ).toNNReal) (fun n ↦ ?_)
refine (eLpNorm_densityProcess_le hκν n a s).trans_eq ?_
rw [ENNReal.coe_toNNReal]
exact measure_ne_top _ _
lemma tendsto_eLpNorm_one_densityProcess_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
Tendsto (fun n ↦ eLpNorm ((fun x ↦ densityProcess κ ν n a x s)
- (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a))
1 (ν a)) atTop (𝓝 0) := by
refine Submartingale.tendsto_eLpNorm_one_limitProcess ?_ ?_
· exact (martingale_densityProcess hκν a hs).submartingale
· refine uniformIntegrable_of le_rfl ENNReal.one_ne_top ?_ ?_
· exact fun n ↦ (measurable_densityProcess_right κ ν n a hs).aestronglyMeasurable
· refine fun ε _ ↦ ⟨2, fun n ↦ le_of_eq_of_le ?_ (?_ : 0 ≤ ENNReal.ofReal ε)⟩
· suffices {x | 2 ≤ ‖densityProcess κ ν n a x s‖₊} = ∅ by simp [this]
ext x
simp only [mem_setOf_eq, mem_empty_iff_false, iff_false, not_le]
refine (?_ : _ ≤ (1 : ℝ≥0)).trans_lt one_lt_two
rw [Real.nnnorm_of_nonneg (densityProcess_nonneg _ _ _ _ _ _)]
exact mod_cast (densityProcess_le_one hκν _ _ _ _)
· simp
lemma tendsto_eLpNorm_one_restrict_densityProcess_limitProcess [IsFiniteKernel ν]
(hκν : fst κ ≤ ν) (a : α) {s : Set β} (hs : MeasurableSet s) (A : Set γ) :
Tendsto (fun n ↦ eLpNorm ((fun x ↦ densityProcess κ ν n a x s)
- (countableFiltration γ).limitProcess (fun n x ↦ densityProcess κ ν n a x s) (ν a))
1 ((ν a).restrict A)) atTop (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds
(tendsto_eLpNorm_one_densityProcess_limitProcess hκν a hs) (fun _ ↦ zero_le')
(fun _ ↦ eLpNorm_restrict_le _ _ _ _)
end DensityProcess
section Density
/-- Density of the kernel `κ` with respect to `ν`. This is a function `α → γ → Set β → ℝ` which
is measurable on `α × γ` for all measurable sets `s : Set β` and satisfies that
`∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s)` for all measurable `A : Set γ`. -/
noncomputable
def density (κ : Kernel α (γ × β)) (ν : Kernel α γ) (a : α) (x : γ) (s : Set β) : ℝ :=
limsup (fun n ↦ densityProcess κ ν n a x s) atTop
lemma density_ae_eq_limitProcess (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
(fun x ↦ density κ ν a x s)
=ᵐ[ν a] (countableFiltration γ).limitProcess
(fun n x ↦ densityProcess κ ν n a x s) (ν a) := by
filter_upwards [tendsto_densityProcess_limitProcess hκν a hs] with t ht using ht.limsup_eq
lemma tendsto_m_density (hκν : fst κ ≤ ν) (a : α) [IsFiniteKernel ν]
{s : Set β} (hs : MeasurableSet s) :
∀ᵐ x ∂(ν a),
Tendsto (fun n ↦ densityProcess κ ν n a x s) atTop (𝓝 (density κ ν a x s)) := by
filter_upwards [tendsto_densityProcess_limitProcess hκν a hs, density_ae_eq_limitProcess hκν a hs]
with t h1 h2 using h2 ▸ h1
lemma measurable_density (κ : Kernel α (γ × β)) (ν : Kernel α γ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun (p : α × γ) ↦ density κ ν p.1 p.2 s) :=
.limsup (fun n ↦ measurable_densityProcess κ ν n hs)
lemma measurable_density_left (κ : Kernel α (γ × β)) (ν : Kernel α γ) (x : γ)
{s : Set β} (hs : MeasurableSet s) :
Measurable (fun a ↦ density κ ν a x s) := by
change Measurable ((fun (p : α × γ) ↦ density κ ν p.1 p.2 s) ∘ (fun a ↦ (a, x)))
exact (measurable_density κ ν hs).comp measurable_prodMk_right
lemma measurable_density_right (κ : Kernel α (γ × β)) (ν : Kernel α γ)
{s : Set β} (hs : MeasurableSet s) (a : α) :
Measurable (fun x ↦ density κ ν a x s) := by
change Measurable ((fun (p : α × γ) ↦ density κ ν p.1 p.2 s) ∘ (fun x ↦ (a, x)))
exact (measurable_density κ ν hs).comp measurable_prodMk_left
lemma density_mono_set (hκν : fst κ ≤ ν) (a : α) (x : γ) {s s' : Set β} (h : s ⊆ s') :
density κ ν a x s ≤ density κ ν a x s' := by
refine limsup_le_limsup ?_ ?_ ?_
· exact Eventually.of_forall (fun n ↦ densityProcess_mono_set hκν n a x h)
· exact isCoboundedUnder_le_of_le atTop (fun i ↦ densityProcess_nonneg _ _ _ _ _ _)
· exact isBoundedUnder_of ⟨1, fun n ↦ densityProcess_le_one hκν _ _ _ _⟩
lemma density_nonneg (hκν : fst κ ≤ ν) (a : α) (x : γ) (s : Set β) :
0 ≤ density κ ν a x s := by
refine le_limsup_of_frequently_le ?_ ?_
· exact Frequently.of_forall (fun n ↦ densityProcess_nonneg _ _ _ _ _ _)
· exact isBoundedUnder_of ⟨1, fun n ↦ densityProcess_le_one hκν _ _ _ _⟩
lemma density_le_one (hκν : fst κ ≤ ν) (a : α) (x : γ) (s : Set β) :
density κ ν a x s ≤ 1 := by
refine limsup_le_of_le ?_ ?_
· exact isCoboundedUnder_le_of_le atTop (fun i ↦ densityProcess_nonneg _ _ _ _ _ _)
· exact Eventually.of_forall (fun n ↦ densityProcess_le_one hκν _ _ _ _)
section Integral
lemma eLpNorm_density_le (hκν : fst κ ≤ ν) (a : α) (s : Set β) :
eLpNorm (fun x ↦ density κ ν a x s) 1 (ν a) ≤ ν a univ := by
refine (eLpNorm_le_of_ae_bound (C := 1) (ae_of_all _ (fun t ↦ ?_))).trans ?_
· simp only [Real.norm_eq_abs, abs_of_nonneg (density_nonneg hκν a t s),
density_le_one hκν a t s]
· simp
lemma integrable_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
Integrable (fun x ↦ density κ ν a x s) (ν a) := by
rw [← memLp_one_iff_integrable]
refine ⟨Measurable.aestronglyMeasurable ?_, ?_⟩
· exact measurable_density_right κ ν hs a
· exact (eLpNorm_density_le hκν a s).trans_lt (measure_lt_top _ _)
lemma tendsto_setIntegral_densityProcess (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] (a : α) {s : Set β} (hs : MeasurableSet s) (A : Set γ) :
Tendsto (fun i ↦ ∫ x in A, densityProcess κ ν i a x s ∂(ν a)) atTop
(𝓝 (∫ x in A, density κ ν a x s ∂(ν a))) := by
refine tendsto_setIntegral_of_L1' (μ := ν a) (fun x ↦ density κ ν a x s)
(integrable_density hκν a hs) (F := fun i x ↦ densityProcess κ ν i a x s) (l := atTop)
(Eventually.of_forall (fun n ↦ integrable_densityProcess hκν _ _ hs)) ?_ A
refine (tendsto_congr fun n ↦ ?_).mp (tendsto_eLpNorm_one_densityProcess_limitProcess hκν a hs)
refine eLpNorm_congr_ae ?_
exact EventuallyEq.rfl.sub (density_ae_eq_limitProcess hκν a hs).symm
/-- Auxiliary lemma for `setIntegral_density`. -/
lemma setIntegral_density_of_measurableSet (hκν : fst κ ≤ ν)
[IsFiniteKernel ν] (n : ℕ) (a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ}
(hA : MeasurableSet[countableFiltration γ n] A) :
∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s) := by
suffices ∫ x in A, density κ ν a x s ∂(ν a) = ∫ x in A, densityProcess κ ν n a x s ∂(ν a) by
exact this ▸ setIntegral_densityProcess hκν _ _ hs hA
suffices ∫ x in A, density κ ν a x s ∂(ν a)
= limsup (fun i ↦ ∫ x in A, densityProcess κ ν i a x s ∂(ν a)) atTop by
rw [this, ← limsup_const (α := ℕ) (f := atTop) (∫ x in A, densityProcess κ ν n a x s ∂(ν a)),
limsup_congr]
simp only [eventually_atTop]
refine ⟨n, fun m hnm ↦ ?_⟩
rw [setIntegral_densityProcess_of_le hκν hnm _ hs hA,
setIntegral_densityProcess hκν _ _ hs hA]
-- use L1 convergence
have h := tendsto_setIntegral_densityProcess hκν a hs A
rw [h.limsup_eq]
lemma integral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
∫ x, density κ ν a x s ∂(ν a) = (κ a).real (univ ×ˢ s) := by
rw [← setIntegral_univ, setIntegral_density_of_measurableSet hκν 0 a hs MeasurableSet.univ]
lemma setIntegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet A) :
∫ x in A, density κ ν a x s ∂(ν a) = (κ a).real (A ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
have hgen : ‹MeasurableSpace γ› =
.generateFrom {s | ∃ n, MeasurableSet[countableFiltration γ n] s} := by
rw [setOf_exists, generateFrom_iUnion_measurableSet (countableFiltration γ),
iSup_countableFiltration]
have hpi : IsPiSystem {s | ∃ n, MeasurableSet[countableFiltration γ n] s} := by
rw [setOf_exists]
exact isPiSystem_iUnion_of_monotone _
(fun n ↦ @isPiSystem_measurableSet _ (countableFiltration γ n))
fun _ _ ↦ (countableFiltration γ).mono
induction A, hA using induction_on_inter hgen hpi with
| empty => simp
| basic s hs =>
rcases hs with ⟨n, hn⟩
exact setIntegral_density_of_measurableSet hκν n a hs hn
| compl A hA hA_eq =>
have h := integral_add_compl hA (integrable_density hκν a hs)
rw [hA_eq, integral_density hκν a hs] at h
have : Aᶜ ×ˢ s = univ ×ˢ s \ A ×ˢ s := by
rw [prod_diff_prod, compl_eq_univ_diff]
simp
rw [this, measureReal_def,
measure_diff (by intro; simp) (hA.prod hs).nullMeasurableSet (measure_ne_top (κ a) _),
ENNReal.toReal_sub_of_le (measure_mono (by intro x; simp)) (measure_ne_top _ _)]
rw [eq_tsub_iff_add_eq_of_le, add_comm]
· exact h
· gcongr <;> simp
| iUnion f hf_disj hf h_eq =>
rw [integral_iUnion hf hf_disj (integrable_density hκν _ hs).integrableOn]
simp_rw [h_eq, measureReal_def]
rw [← ENNReal.tsum_toReal_eq (fun _ ↦ measure_ne_top _ _)]
congr
rw [iUnion_prod_const, measure_iUnion]
· exact hf_disj.mono fun _ _ h ↦ h.set_prod_left _ _
· exact fun i ↦ (hf i).prod hs
lemma setLIntegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) {A : Set γ} (hA : MeasurableSet A) :
∫⁻ x in A, ENNReal.ofReal (density κ ν a x s) ∂(ν a) = κ a (A ×ˢ s) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
rw [← ofReal_integral_eq_lintegral_ofReal]
· rw [setIntegral_density hκν a hs hA, measureReal_def,
ENNReal.ofReal_toReal (measure_ne_top _ _)]
· exact (integrable_density hκν a hs).restrict
· exact ae_of_all _ (fun _ ↦ density_nonneg hκν _ _ _)
lemma lintegral_density (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) {s : Set β} (hs : MeasurableSet s) :
∫⁻ x, ENNReal.ofReal (density κ ν a x s) ∂(ν a) = κ a (univ ×ˢ s) := by
rw [← setLIntegral_univ]
exact setLIntegral_density hκν a hs MeasurableSet.univ
end Integral
lemma tendsto_integral_density_of_monotone (hκν : fst κ ≤ ν) [IsFiniteKernel ν]
(a : α) (seq : ℕ → Set β) (hseq : Monotone seq) (hseq_iUnion : ⋃ i, seq i = univ)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ ∫ x, density κ ν a x (seq m) ∂(ν a)) atTop (𝓝 ((κ a).real univ)) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
simp_rw [integral_density hκν a (hseq_meas _)]
have h_cont := ENNReal.continuousOn_toReal.continuousAt (x := κ a univ) ?_
swap
· rw [mem_nhds_iff]
refine ⟨Iio (κ a univ + 1), fun x hx ↦ ne_top_of_lt (?_ : x < κ a univ + 1), isOpen_Iio, ?_⟩
· simpa using hx
· simp only [mem_Iio]
exact ENNReal.lt_add_right (measure_ne_top _ _) one_ne_zero
refine h_cont.tendsto.comp ?_
convert tendsto_measure_iUnion_atTop (monotone_const.set_prod hseq)
rw [← prod_iUnion, hseq_iUnion, univ_prod_univ]
lemma tendsto_integral_density_of_antitone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
Tendsto (fun m ↦ ∫ x, density κ ν a x (seq m) ∂(ν a)) atTop (𝓝 0) := by
have : IsFiniteKernel κ := isFiniteKernel_of_isFiniteKernel_fst (h := isFiniteKernel_of_le hκν)
simp_rw [integral_density hκν a (hseq_meas _)]
rw [← ENNReal.toReal_zero]
have h_cont := ENNReal.continuousAt_toReal ENNReal.zero_ne_top
refine h_cont.tendsto.comp ?_
have h : Tendsto (fun m ↦ κ a (univ ×ˢ seq m)) atTop
(𝓝 ((κ a) (⋂ n, (fun m ↦ univ ×ˢ seq m) n))) := by
apply tendsto_measure_iInter_atTop
· measurability
· exact antitone_const.set_prod hseq
· exact ⟨0, measure_ne_top _ _⟩
simpa [← prod_iInter, hseq_iInter] using h
lemma tendsto_density_atTop_ae_of_antitone (hκν : fst κ ≤ ν) [IsFiniteKernel ν] (a : α)
(seq : ℕ → Set β) (hseq : Antitone seq) (hseq_iInter : ⋂ i, seq i = ∅)
(hseq_meas : ∀ m, MeasurableSet (seq m)) :
∀ᵐ x ∂(ν a), Tendsto (fun m ↦ density κ ν a x (seq m)) atTop (𝓝 0) := by
refine tendsto_of_integral_tendsto_of_antitone ?_ (integrable_const _) ?_ ?_ ?_
· exact fun m ↦ integrable_density hκν _ (hseq_meas m)
· rw [integral_zero]
exact tendsto_integral_density_of_antitone hκν a seq hseq hseq_iInter hseq_meas
· exact ae_of_all _ (fun c n m hnm ↦ density_mono_set hκν a c (hseq hnm))
· exact ae_of_all _ (fun x m ↦ density_nonneg hκν a x (seq m))
section UnivFst
/-! We specialize to `ν = fst κ`, for which `density κ (fst κ) a t univ = 1` almost everywhere. -/
lemma densityProcess_fst_univ [IsFiniteKernel κ] (n : ℕ) (a : α) (x : γ) :
densityProcess κ (fst κ) n a x univ
= if fst κ a (countablePartitionSet n x) = 0 then 0 else 1 := by
rw [densityProcess]
split_ifs with h
· simp only [h]
by_cases h' : κ a (countablePartitionSet n x ×ˢ univ) = 0
· simp [h']
· rw [ENNReal.div_zero h']
simp
· rw [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)]
have : countablePartitionSet n x ×ˢ univ = {p : γ × β | p.1 ∈ countablePartitionSet n x} := by
ext x
simp
rw [this, ENNReal.div_self]
· simp
· rwa [fst_apply' _ _ (measurableSet_countablePartitionSet _ _)] at h
· exact measure_ne_top _ _
lemma densityProcess_fst_univ_ae (κ : Kernel α (γ × β)) [IsFiniteKernel κ] (n : ℕ) (a : α) :
∀ᵐ x ∂(fst κ a), densityProcess κ (fst κ) n a x univ = 1 := by
rw [ae_iff]
have : {x | ¬ densityProcess κ (fst κ) n a x univ = 1}
⊆ {x | fst κ a (countablePartitionSet n x) = 0} := by
intro x hx
simp only [mem_setOf_eq] at hx ⊢
rw [densityProcess_fst_univ] at hx
simpa using hx
refine measure_mono_null this ?_
have : {x | fst κ a (countablePartitionSet n x) = 0}
⊆ ⋃ (u) (_ : u ∈ countablePartition γ n) (_ : fst κ a u = 0), u := by
intro t ht
simp only [mem_setOf_eq, mem_iUnion, exists_prop] at ht ⊢
| exact ⟨countablePartitionSet n t, countablePartitionSet_mem _ _, ht,
mem_countablePartitionSet _ _⟩
refine measure_mono_null this ?_
rw [measure_biUnion]
· simp
· exact (finite_countablePartition _ _).countable
· intro s hs t ht hst
simp only [disjoint_iUnion_right, disjoint_iUnion_left]
exact fun _ _ ↦ disjoint_countablePartition hs ht hst
· intro s hs
| Mathlib/Probability/Kernel/Disintegration/Density.lean | 674 | 683 |
/-
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.LinearAlgebra.FreeModule.StrongRankCondition
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## 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.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
/-- The determinant of an endomorphism given a basis.
See `LinearMap.det` for a version that populates the basis non-computably.
Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s
type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma,
or avoid mentioning a basis at all using `LinearMap.det`.
-/
irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A :=
Trunc.lift
(fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A))
fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c
/-- Unfold lemma for `detAux`.
See also `detAux_def''` which allows you to vary the basis.
-/
theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) :
LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by
rw [detAux]
rfl
theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M)
(b' : Basis ι' A M) (f : M →ₗ[A] M) :
LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by
induction tb using Trunc.induction_on with
| h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b']
@[simp]
theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 :=
(LinearMap.detAux b).map_one
@[simp]
theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) :
LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g :=
(LinearMap.detAux b).map_mul f g
section
open scoped Classical in
-- Discourage the elaborator from unfolding `det` and producing a huge term by marking it
-- as irreducible.
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected irreducible_def det : (M →ₗ[A] M) →* A :=
if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1
open scoped Classical in
theorem coe_det [DecidableEq M] :
⇑(LinearMap.det : (M →ₗ[A] M) →* A) =
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1 := by
ext
rw [LinearMap.det_def]
split_ifs
· congr -- use the correct `DecidableEq` instance
rfl
end
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `LinearMap.det_toMatrix`)
theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M)
(f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩
rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption
@[simp]
theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) :
Matrix.det (toMatrix b b f) = LinearMap.det f := by
haveI := Classical.decEq M
rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange,
det_toMatrix_eq_det_toMatrix b b.reindexFinsetRange]
@[simp]
theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) :
Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix']
@[simp]
theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) :
LinearMap.det (Matrix.toLin b b f) = f.det := by
rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin]
@[simp]
theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by
simp only [← toLin_eq_toLin', det_toLin]
/-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and
`P 1`. -/
@[elab_as_elim]
theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) :
P (LinearMap.det f) := by
classical
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
obtain ⟨s, ⟨b⟩⟩ := H
rw [← det_toMatrix b]
exact hb s b
else
rwa [LinearMap.det_def, dif_neg H]
@[simp]
theorem det_comp (f g : M →ₗ[A] M) :
LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g :=
LinearMap.det.map_mul f g
@[simp]
theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 :=
LinearMap.det.map_one
/-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/
@[simp]
theorem det_smul [Module.Free A M] (c : A) (f : M →ₗ[A] M) :
LinearMap.det (c • f) = c ^ Module.finrank A M * LinearMap.det f := by
nontriviality A
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· have : Module.Finite A M := by
rcases H with ⟨s, ⟨hs⟩⟩
exact Module.Finite.of_basis hs
simp only [← det_toMatrix (Module.finBasis A M), LinearEquiv.map_smul,
Fintype.card_fin, Matrix.det_smul]
· classical
have : Module.finrank A M = 0 := finrank_eq_zero_of_not_exists_basis H
simp [coe_det, H, this]
theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) :
LinearMap.det (0 : M →ₗ[A] M) = 0 := by
haveI := Classical.decEq ι
cases nonempty_fintype ι
rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero]
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
the determinant to be `1`. -/
@[simp]
theorem det_zero [Module.Free A M] :
LinearMap.det (0 : M →ₗ[A] M) = (0 : A) ^ Module.finrank A M := by
simp only [← zero_smul A (1 : M →ₗ[A] M), det_smul, mul_one, MonoidHom.map_one]
theorem det_eq_one_of_not_module_finite (h : ¬Module.Finite R M) (f : M →ₗ[R] M) : f.det = 1 := by
rw [LinearMap.det, dif_neg, MonoidHom.one_apply]
exact fun ⟨_, ⟨b⟩⟩ ↦ h (Module.Finite.of_basis b)
theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) :
LinearMap.det (f : M →ₗ[R] M) = 1 := by
have b : Basis (Fin 0) R M := Basis.empty M
rw [← f.det_toMatrix b]
exact Matrix.det_isEmpty
theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M]
[Module 𝕜 M] (h : Module.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) :
LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by
classical
refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl
intro s b
have : IsEmpty s := by
rw [← Fintype.card_eq_zero_iff]
exact (Module.finrank_eq_card_basis b).symm.trans h
exact Matrix.det_isEmpty
/-- Conjugating a linear map by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) :
LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· rcases H with ⟨s, ⟨b⟩⟩
rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e),
toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by
contrapose! H
rcases H with ⟨s, ⟨b⟩⟩
exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩
simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true]
/-- If a linear map is invertible, so is its determinant. -/
theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) :
IsUnit (LinearMap.det f) := by
obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv
have : LinearMap.det f * LinearMap.det g = 1 := by
simp only [← LinearMap.det_comp, hg, MonoidHom.map_one]
exact isUnit_of_mul_eq_one _ _ this
/-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/
theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M)
(hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
· classical simp [LinearMap.coe_det, H] at hf
/-- If the determinant of a map vanishes, then the map is not onto. -/
theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- If the determinant of a map vanishes, then the map is not injective. -/
theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
/-- When the function is over the base ring, the determinant is the evaluation at `1`. -/
@[simp] lemma det_ring (f : R →ₗ[R] R) : f.det = f 1 := by
simp [← det_toMatrix (Basis.singleton Unit R)]
lemma det_mulLeft (a : R) : (mulLeft R a).det = a := by simp
lemma det_mulRight (a : R) : (mulRight R a).det = a := by simp
theorem det_prodMap [Module.Free R M] [Module.Free R M'] [Module.Finite R M] [Module.Finite R M']
(f : Module.End R M) (f' : Module.End R M') :
(prodMap f f').det = f.det * f'.det := by
let b := Module.Free.chooseBasis R M
let b' := Module.Free.chooseBasis R M'
rw [← det_toMatrix (b.prod b'), ← det_toMatrix b, ← det_toMatrix b', toMatrix_prodMap,
det_fromBlocks_zero₂₁, det_toMatrix]
omit [DecidableEq ι] in
theorem det_pi [Module.Free R M] [Module.Finite R M] (f : ι → M →ₗ[R] M) :
(LinearMap.pi (fun i ↦ (f i).comp (LinearMap.proj i))).det = ∏ i, (f i).det := by
classical
let b := Module.Free.chooseBasis R M
let B := (Pi.basis (fun _ : ι ↦ b)).reindex <|
(Equiv.sigmaEquivProd _ _).trans (Equiv.prodComm _ _)
simp_rw [← LinearMap.det_toMatrix B, ← LinearMap.det_toMatrix b]
have : ((LinearMap.toMatrix B B) (LinearMap.pi fun i ↦ f i ∘ₗ LinearMap.proj i)) =
Matrix.blockDiagonal (fun i ↦ LinearMap.toMatrix b b (f i)) := by
ext ⟨i₁, i₂⟩ ⟨j₁, j₂⟩
unfold B
simp_rw [LinearMap.toMatrix_apply', Matrix.blockDiagonal_apply, Basis.coe_reindex,
Function.comp_apply, Basis.repr_reindex_apply, Equiv.symm_trans_apply, Equiv.prodComm_symm,
Equiv.prodComm_apply, Equiv.sigmaEquivProd_symm_apply, Prod.swap_prod_mk, Pi.basis_apply,
Pi.basis_repr, LinearMap.pi_apply, LinearMap.coe_comp, Function.comp_apply,
LinearMap.toMatrix_apply', LinearMap.coe_proj, Function.eval, Pi.single_apply]
split_ifs with h
· rw [h]
· simp only [map_zero, Finsupp.coe_zero, Pi.zero_apply]
rw [this, Matrix.det_blockDiagonal]
end LinearMap
namespace LinearEquiv
/-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/
protected def det : (M ≃ₗ[R] M) →* Rˣ :=
(Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp
(LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom
@[simp]
theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) :=
rfl
@[simp]
theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) :=
rfl
@[simp]
theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 :=
Units.ext <| LinearMap.det_id
@[simp]
theorem det_trans (f g : M ≃ₗ[R] M) :
LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f :=
map_mul _ g f
@[simp]
theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ :=
map_inv _ f
/-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') :
LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by
rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj]
attribute [irreducible] LinearEquiv.det
end LinearEquiv
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
-- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') :
IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse
simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
/-- Specialization of `LinearEquiv.isUnit_det` -/
theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
IsUnit (LinearMap.det (f : M →ₗ[A] M)) :=
isUnit_of_mul_eq_one _ _ f.det_mul_det_symm
/-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/
theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) :
LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by
field_simp [IsUnit.ne_zero f.isUnit_det']
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where
toFun := f
map_add' := f.map_add
map_smul' := f.map_smul
invFun := toLin v' v (toMatrix v v' f)⁻¹
left_inv x :=
calc toLin v' v (toMatrix v v' f)⁻¹ (f x)
_ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by
rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply]
_ = x := by simp [h]
right_inv x :=
calc f (toLin v' v (toMatrix v v' f)⁻¹ x)
_ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by
rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v']
_ = x := by simp [h]
@[simp]
theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) :
(LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by
ext x
rfl
| /-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose
determinant is nonzero. -/
abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M]
[FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M :=
have : IsUnit (LinearMap.toMatrix (Module.finBasis 𝕜 M)
| Mathlib/LinearAlgebra/Determinant.lean | 463 | 467 |
/-
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]
[hφ : QuasiIsoAt φ i] :
QuasiIsoAt (φ ≫ φ') i ↔ QuasiIsoAt φ' i := by
constructor
· intro
exact quasiIsoAt_of_comp_left φ φ' i
· intro
infer_instance
lemma quasiIso_iff_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i]
[∀ i, L.HasHomology i] [∀ i, M.HasHomology i]
[hφ : QuasiIso φ] :
QuasiIso (φ ≫ φ') ↔ QuasiIso φ' := by
simp only [quasiIso_iff, quasiIsoAt_iff_comp_left φ φ']
lemma quasiIso_of_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i]
[∀ i, L.HasHomology i] [∀ i, M.HasHomology i]
[hφ : QuasiIso φ] [hφφ' : QuasiIso (φ ≫ φ')] :
QuasiIso φ' := by
rw [← quasiIso_iff_comp_left φ φ']
infer_instance
lemma quasiIsoAt_of_comp_right (φ : 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_right (homologyMap φ i) (homologyMap φ' i)
lemma quasiIsoAt_iff_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i]
[L.HasHomology i] [M.HasHomology i]
[hφ' : QuasiIsoAt φ' i] :
QuasiIsoAt (φ ≫ φ') i ↔ QuasiIsoAt φ i := by
constructor
· intro
exact quasiIsoAt_of_comp_right φ φ' i
· intro
infer_instance
lemma quasiIso_iff_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i]
[∀ i, L.HasHomology i] [∀ i, M.HasHomology i]
[hφ' : QuasiIso φ'] :
QuasiIso (φ ≫ φ') ↔ QuasiIso φ := by
simp only [quasiIso_iff, quasiIsoAt_iff_comp_right φ φ']
lemma quasiIso_of_comp_right (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i]
[∀ i, L.HasHomology i] [∀ i, M.HasHomology i]
[hφ : QuasiIso φ'] [hφφ' : QuasiIso (φ ≫ φ')] :
QuasiIso φ := by
rw [← quasiIso_iff_comp_right φ φ']
infer_instance
lemma quasiIso_iff_of_arrow_mk_iso (φ : K ⟶ L) (φ' : K' ⟶ L') (e : Arrow.mk φ ≅ Arrow.mk φ')
[∀ i, K.HasHomology i] [∀ i, L.HasHomology i]
[∀ i, K'.HasHomology i] [∀ i, L'.HasHomology i] :
QuasiIso φ ↔ QuasiIso φ' := by
simp [← quasiIso_iff_comp_left (show K' ⟶ K from e.inv.left) φ,
← quasiIso_iff_comp_right φ' (show L' ⟶ L from e.inv.right)]
lemma quasiIso_of_arrow_mk_iso (φ : K ⟶ L) (φ' : K' ⟶ L') (e : Arrow.mk φ ≅ Arrow.mk φ')
[∀ i, K.HasHomology i] [∀ i, L.HasHomology i]
[∀ i, K'.HasHomology i] [∀ i, L'.HasHomology i]
[hφ : QuasiIso φ] : QuasiIso φ' := by
simpa only [← quasiIso_iff_of_arrow_mk_iso φ φ' e]
lemma quasiIso_of_retractArrow {f : K ⟶ L} {f' : K' ⟶ L'}
(h : RetractArrow f f') [∀ i, K.HasHomology i] [∀ i, L.HasHomology i]
[∀ i, K'.HasHomology i] [∀ i, L'.HasHomology i] [QuasiIso f'] :
QuasiIso f where
quasiIsoAt i := quasiIsoAt_of_retract h i
namespace HomologicalComplex
section PreservesHomology
variable {C₁ C₂ : Type*} [Category C₁] [Category C₂] [Preadditive C₁] [Preadditive C₂]
{K L : HomologicalComplex C₁ c} (φ : K ⟶ L) (F : C₁ ⥤ C₂) [F.Additive]
[F.PreservesHomology]
section
| variable (i : ι) [K.HasHomology i] [L.HasHomology i]
[((F.mapHomologicalComplex c).obj K).HasHomology i]
[((F.mapHomologicalComplex c).obj L).HasHomology i]
instance quasiIsoAt_map_of_preservesHomology [hφ : QuasiIsoAt φ i] :
| Mathlib/Algebra/Homology/QuasiIso.lean | 253 | 257 |
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Satisfiability
/-!
# Type Spaces
This file defines the space of complete types over a first-order theory.
(Note that types in model theory are different from types in type theory.)
## Main Definitions
- `FirstOrder.Language.Theory.CompleteType`:
`T.CompleteType α` consists of complete types over the theory `T` with variables `α`.
- `FirstOrder.Language.Theory.typeOf` is the type of a given tuple.
- `FirstOrder.Language.Theory.realizedTypes`: `T.realizedTypes M α` is the set of
types in `T.CompleteType α` that are realized in `M` - that is, the type of some tuple in `M`.
## Main Results
- `FirstOrder.Language.Theory.CompleteType.nonempty_iff`:
The space `T.CompleteType α` is nonempty exactly when `T` is satisfiable.
- `FirstOrder.Language.Theory.CompleteType.exists_modelType_is_realized_in`: Every type is realized
in some model.
## Implementation Notes
- Complete types are implemented as maximal consistent theories in an expanded language.
More frequently they are described as maximal consistent sets of formulas, but this is equivalent.
## TODO
- Connect `T.CompleteType α` to sets of formulas `L.Formula α`.
-/
universe u v w w'
open Cardinal Set FirstOrder
namespace FirstOrder
namespace Language
namespace Theory
variable {L : Language.{u, v}} (T : L.Theory) (α : Type w)
/-- A complete type over a given theory in a certain type of variables is a maximally
consistent (with the theory) set of formulas in that type. -/
structure CompleteType where
/-- The underlying theory -/
toTheory : L[[α]].Theory
subset' : (L.lhomWithConstants α).onTheory T ⊆ toTheory
isMaximal' : toTheory.IsMaximal
variable {T α}
namespace CompleteType
attribute [coe] CompleteType.toTheory
instance Sentence.instSetLike : SetLike (T.CompleteType α) (L[[α]].Sentence) :=
⟨fun p => p.toTheory, fun p q h => by
cases p
cases q
congr ⟩
theorem isMaximal (p : T.CompleteType α) : IsMaximal (p : L[[α]].Theory) :=
p.isMaximal'
theorem subset (p : T.CompleteType α) : (L.lhomWithConstants α).onTheory T ⊆ (p : L[[α]].Theory) :=
p.subset'
theorem mem_or_not_mem (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ ∈ p ∨ φ.not ∈ p :=
p.isMaximal.mem_or_not_mem φ
theorem mem_of_models (p : T.CompleteType α) {φ : L[[α]].Sentence}
(h : (L.lhomWithConstants α).onTheory T ⊨ᵇ φ) : φ ∈ p :=
(p.mem_or_not_mem φ).resolve_right fun con =>
((models_iff_not_satisfiable _).1 h)
(p.isMaximal.1.mono (union_subset p.subset (singleton_subset_iff.2 con)))
theorem not_mem_iff (p : T.CompleteType α) (φ : L[[α]].Sentence) : φ.not ∈ p ↔ ¬φ ∈ p :=
⟨fun hf ht => by
have h : ¬IsSatisfiable ({φ, φ.not} : L[[α]].Theory) := by
rintro ⟨@⟨_, _, h, _⟩⟩
simp only [model_iff, mem_insert_iff, mem_singleton_iff, forall_eq_or_imp, forall_eq] at h
exact h.2 h.1
refine h (p.isMaximal.1.mono ?_)
rw [insert_subset_iff, singleton_subset_iff]
exact ⟨ht, hf⟩, (p.mem_or_not_mem φ).resolve_left⟩
@[simp]
theorem compl_setOf_mem {φ : L[[α]].Sentence} :
{ p : T.CompleteType α | φ ∈ p }ᶜ = { p : T.CompleteType α | φ.not ∈ p } :=
ext fun _ => (not_mem_iff _ _).symm
theorem setOf_subset_eq_empty_iff (S : L[[α]].Theory) :
{ p : T.CompleteType α | S ⊆ ↑p } = ∅ ↔
¬((L.lhomWithConstants α).onTheory T ∪ S).IsSatisfiable := by
rw [iff_not_comm, ← not_nonempty_iff_eq_empty, Classical.not_not, Set.Nonempty]
refine
⟨fun h =>
⟨⟨L[[α]].completeTheory h.some, (subset_union_left (t := S)).trans completeTheory.subset,
completeTheory.isMaximal (L[[α]]) h.some⟩,
(((L.lhomWithConstants α).onTheory T).subset_union_right).trans completeTheory.subset⟩,
?_⟩
rintro ⟨p, hp⟩
exact p.isMaximal.1.mono (union_subset p.subset hp)
|
theorem setOf_mem_eq_univ_iff (φ : L[[α]].Sentence) :
{ p : T.CompleteType α | φ ∈ p } = Set.univ ↔ (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by
rw [models_iff_not_satisfiable, ← compl_empty_iff, compl_setOf_mem, ← setOf_subset_eq_empty_iff]
simp
theorem setOf_subset_eq_univ_iff (S : L[[α]].Theory) :
{ p : T.CompleteType α | S ⊆ ↑p } = Set.univ ↔
∀ φ, φ ∈ S → (L.lhomWithConstants α).onTheory T ⊨ᵇ φ := by
have h : { p : T.CompleteType α | S ⊆ ↑p } = ⋂₀ ((fun φ => { p | φ ∈ p }) '' S) := by
ext
simp [subset_def]
| Mathlib/ModelTheory/Types.lean | 115 | 126 |
/-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
import Mathlib.Data.Fintype.Sigma
/-!
# Darts in graphs
A `Dart` or half-edge or bond in a graph is an ordered pair of adjacent vertices, regarded as an
oriented edge. This file defines darts and proves some of their basic properties.
-/
namespace SimpleGraph
variable {V : Type*} (G : SimpleGraph V)
/-- A `Dart` is an oriented edge, implemented as an ordered pair of adjacent vertices.
This terminology comes from combinatorial maps, and they are also known as "half-edges"
or "bonds." -/
structure Dart extends V × V where
adj : G.Adj fst snd
deriving DecidableEq
initialize_simps_projections Dart (+toProd, -fst, -snd)
attribute [simp] Dart.adj
variable {G}
theorem Dart.ext_iff (d₁ d₂ : G.Dart) : d₁ = d₂ ↔ d₁.toProd = d₂.toProd := by
cases d₁; cases d₂; simp
@[ext]
theorem Dart.ext (d₁ d₂ : G.Dart) (h : d₁.toProd = d₂.toProd) : d₁ = d₂ :=
(Dart.ext_iff d₁ d₂).mpr h
@[simp]
theorem Dart.fst_ne_snd (d : G.Dart) : d.fst ≠ d.snd :=
fun h ↦ G.irrefl (h ▸ d.adj)
@[simp]
theorem Dart.snd_ne_fst (d : G.Dart) : d.snd ≠ d.fst :=
fun h ↦ G.irrefl (h ▸ d.adj)
theorem Dart.toProd_injective : Function.Injective (Dart.toProd : G.Dart → V × V) :=
Dart.ext
instance Dart.fintype [Fintype V] [DecidableRel G.Adj] : Fintype G.Dart :=
Fintype.ofEquiv (Σ v, G.neighborSet v)
{ toFun := fun s => ⟨(s.fst, s.snd), s.snd.property⟩
invFun := fun d => ⟨d.fst, d.snd, d.adj⟩
left_inv := fun s => by ext <;> simp
right_inv := fun d => by ext <;> simp }
/-- The edge associated to the dart. -/
def Dart.edge (d : G.Dart) : Sym2 V :=
Sym2.mk d.toProd
@[simp]
theorem Dart.edge_mk {p : V × V} (h : G.Adj p.1 p.2) : (Dart.mk p h).edge = Sym2.mk p :=
rfl
@[simp]
theorem Dart.edge_mem (d : G.Dart) : d.edge ∈ G.edgeSet :=
d.adj
/-- The dart with reversed orientation from a given dart. -/
@[simps]
def Dart.symm (d : G.Dart) : G.Dart :=
⟨d.toProd.swap, G.symm d.adj⟩
@[simp]
theorem Dart.symm_mk {p : V × V} (h : G.Adj p.1 p.2) : (Dart.mk p h).symm = Dart.mk p.swap h.symm :=
rfl
@[simp]
theorem Dart.edge_symm (d : G.Dart) : d.symm.edge = d.edge :=
Sym2.mk_prod_swap_eq
@[simp]
theorem Dart.edge_comp_symm : Dart.edge ∘ Dart.symm = (Dart.edge : G.Dart → Sym2 V) :=
funext Dart.edge_symm
@[simp]
theorem Dart.symm_symm (d : G.Dart) : d.symm.symm = d :=
Dart.ext _ _ <| Prod.swap_swap _
@[simp]
theorem Dart.symm_involutive : Function.Involutive (Dart.symm : G.Dart → G.Dart) :=
Dart.symm_symm
theorem Dart.symm_ne (d : G.Dart) : d.symm ≠ d :=
ne_of_apply_ne (Prod.snd ∘ Dart.toProd) d.adj.ne
theorem dart_edge_eq_iff : ∀ d₁ d₂ : G.Dart, d₁.edge = d₂.edge ↔ d₁ = d₂ ∨ d₁ = d₂.symm := by
rintro ⟨p, hp⟩ ⟨q, hq⟩
simp
theorem dart_edge_eq_mk'_iff :
∀ {d : G.Dart} {p : V × V}, d.edge = Sym2.mk p ↔ d.toProd = p ∨ d.toProd = p.swap := by
rintro ⟨p, h⟩
apply Sym2.mk_eq_mk_iff
theorem dart_edge_eq_mk'_iff' :
∀ {d : G.Dart} {u v : V},
d.edge = s(u, v) ↔ d.fst = u ∧ d.snd = v ∨ d.fst = v ∧ d.snd = u := by
rintro ⟨⟨a, b⟩, h⟩ u v
rw [dart_edge_eq_mk'_iff]
simp
variable (G)
/-- Two darts are said to be adjacent if they could be consecutive
darts in a walk -- that is, the first dart's second vertex is equal to
the second dart's first vertex. -/
def DartAdj (d d' : G.Dart) : Prop :=
d.snd = d'.fst
/-- For a given vertex `v`, this is the bijective map from the neighbor set at `v`
to the darts `d` with `d.fst = v`. -/
@[simps]
def dartOfNeighborSet (v : V) (w : G.neighborSet v) : G.Dart :=
⟨(v, w), w.property⟩
theorem dartOfNeighborSet_injective (v : V) : Function.Injective (G.dartOfNeighborSet v) :=
fun e₁ e₂ h =>
Subtype.ext <| by
injection h with h'
convert congr_arg Prod.snd h'
instance nonempty_dart_top [Nontrivial V] : Nonempty (⊤ : SimpleGraph V).Dart := by
obtain ⟨v, w, h⟩ := exists_pair_ne V
exact ⟨⟨(v, w), h⟩⟩
end SimpleGraph
| Mathlib/Combinatorics/SimpleGraph/Dart.lean | 142 | 146 | |
/-
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, Kim Morrison
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Tactic.FastInstance
import Mathlib.Algebra.Group.Equiv.Defs
/-!
# Type of functions with finite support
For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`)
of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere
on `α` except on a finite set.
Functions with finite support are used (at least) in the following parts of the library:
* `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`;
* polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use
`Finsupp` under the hood;
* the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to
define linearly independent family `LinearIndependent`) is defined as a map
`Finsupp.linearCombination : (ι → M) → (ι →₀ R) →ₗ[R] M`.
Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined
in a different way in the library:
* `Multiset α ≃+ α →₀ ℕ`;
* `FreeAbelianGroup α ≃+ α →₀ ℤ`.
Most of the theory assumes that the range is a commutative additive monoid. This gives us the big
sum operator as a powerful way to construct `Finsupp` elements, which is defined in
`Mathlib.Algebra.BigOperators.Finsupp.Basic`.
Many constructions based on `α →₀ M` are `def`s rather than `abbrev`s to avoid reusing unwanted type
class instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have
non-pointwise multiplication.
## Main declarations
* `Finsupp`: The type of finitely supported functions from `α` to `β`.
* `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`.
* `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`.
* `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding.
* `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`.
## Notations
This file adds `α →₀ M` as a global notation for `Finsupp α M`.
We also use the following convention for `Type*` variables in this file
* `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp`
somewhere in the statement;
* `ι` : an auxiliary index type;
* `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used
for a (semi)module over a (semi)ring.
* `G`, `H`: groups (commutative or not, multiplicative or additive);
* `R`, `S`: (semi)rings.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* Expand the list of definitions and important lemmas to the module docstring.
-/
assert_not_exists CompleteLattice Submonoid
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
/-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that
`f x = 0` for all but finitely many `x`. -/
structure Finsupp (α : Type*) (M : Type*) [Zero M] where
/-- The support of a finitely supported function (aka `Finsupp`). -/
support : Finset α
/-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/
toFun : α → M
/-- The witness that the support of a `Finsupp` is indeed the exact locus where its
underlying function is nonzero. -/
mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0
@[inherit_doc]
infixr:25 " →₀ " => Finsupp
namespace Finsupp
/-! ### Basic declarations about `Finsupp` -/
section Basic
variable [Zero M]
instance instFunLike : FunLike (α →₀ M) α M :=
⟨toFun, by
rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g)
congr
ext a
exact (hf _).trans (hg _).symm⟩
@[ext]
theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext _ _ h
lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff
@[simp, norm_cast]
theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f :=
rfl
instance instZero : Zero (α →₀ M) :=
⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩
@[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl
theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 :=
rfl
@[simp]
theorem support_zero : (0 : α →₀ M).support = ∅ :=
rfl
instance instInhabited : Inhabited (α →₀ M) :=
⟨0⟩
@[simp]
theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 :=
@(f.mem_support_toFun)
@[simp, norm_cast]
theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support :=
Set.ext fun _x => mem_support_iff.symm
theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 :=
not_iff_comm.1 mem_support_iff.symm
@[simp, norm_cast]
theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq]
theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ =>
ext fun a => by
classical
exact if h : a ∈ f.support then h₂ a h else by
have hf : f a = 0 := not_mem_support_iff.1 h
have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h
rw [hf, hg]⟩
@[simp]
theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
mod_cast @Function.support_eq_empty_iff _ _ _ f
theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by
simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne]
theorem card_support_eq_zero {f : α →₀ M} : #f.support = 0 ↔ f = 0 := by simp
instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g =>
decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm
theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) :=
f.fun_support_eq.symm ▸ f.support.finite_toSet
theorem support_subset_iff {s : Set α} {f : α →₀ M} :
↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by
simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm
/-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
@[simps]
def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where
toFun := (⇑)
invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _
left_inv _f := ext fun _x => rfl
right_inv _f := rfl
@[simp]
theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f :=
equivFunOnFinite.symm_apply_apply f
@[simp]
lemma coe_equivFunOnFinite_symm {α} [Finite α] (f : α → M) : ⇑(equivFunOnFinite.symm f) = f := rfl
/--
If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`.
-/
@[simps!]
noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M :=
Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M)
@[ext]
theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g :=
ext fun a => by rwa [Unique.eq_default a]
end Basic
/-! ### Declarations about `onFinset` -/
section OnFinset
variable [Zero M]
/-- `Finsupp.onFinset s f hf` is the finsupp function representing `f` restricted to the finset `s`.
The function must be `0` outside of `s`. Use this when the set needs to be filtered anyways,
otherwise a better set representation is often available. -/
def onFinset (s : Finset α) (f : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) : α →₀ M where
support :=
haveI := Classical.decEq M
{a ∈ s | f a ≠ 0}
toFun := f
mem_support_toFun := by classical simpa
@[simp, norm_cast] lemma coe_onFinset (s : Finset α) (f : α → M) (hf) : onFinset s f hf = f := rfl
@[simp]
theorem onFinset_apply {s : Finset α} {f : α → M} {hf a} : (onFinset s f hf : α →₀ M) a = f a :=
rfl
@[simp]
theorem support_onFinset_subset {s : Finset α} {f : α → M} {hf} :
(onFinset s f hf).support ⊆ s := by
classical convert filter_subset (f · ≠ 0) s
theorem mem_support_onFinset {s : Finset α} {f : α → M} (hf : ∀ a : α, f a ≠ 0 → a ∈ s) {a : α} :
a ∈ (Finsupp.onFinset s f hf).support ↔ f a ≠ 0 := by
rw [Finsupp.mem_support_iff, Finsupp.onFinset_apply]
theorem support_onFinset [DecidableEq M] {s : Finset α} {f : α → M}
(hf : ∀ a : α, f a ≠ 0 → a ∈ s) :
(Finsupp.onFinset s f hf).support = {a ∈ s | f a ≠ 0} := by
dsimp [onFinset]; congr
end OnFinset
section OfSupportFinite
variable [Zero M]
/-- The natural `Finsupp` induced by the function `f` given that it has finite support. -/
noncomputable def ofSupportFinite (f : α → M) (hf : (Function.support f).Finite) : α →₀ M where
support := hf.toFinset
toFun := f
mem_support_toFun _ := hf.mem_toFinset
theorem ofSupportFinite_coe {f : α → M} {hf : (Function.support f).Finite} :
(ofSupportFinite f hf : α → M) = f :=
rfl
instance instCanLift : CanLift (α → M) (α →₀ M) (⇑) fun f => (Function.support f).Finite where
prf f hf := ⟨ofSupportFinite f hf, rfl⟩
end OfSupportFinite
/-! ### Declarations about `mapRange` -/
section MapRange
variable [Zero M] [Zero N] [Zero P]
/-- The composition of `f : M → N` and `g : α →₀ M` is `mapRange f hf g : α →₀ N`,
which is well-defined when `f 0 = 0`.
This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself
bundled (defined in `Mathlib/Data/Finsupp/Basic.lean`):
* `Finsupp.mapRange.equiv`
* `Finsupp.mapRange.zeroHom`
* `Finsupp.mapRange.addMonoidHom`
* `Finsupp.mapRange.addEquiv`
* `Finsupp.mapRange.linearMap`
* `Finsupp.mapRange.linearEquiv`
-/
def mapRange (f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N :=
| onFinset g.support (f ∘ g) fun a => by
rw [mem_support_iff, not_imp_not]; exact fun H => (congr_arg f H).trans hf
| Mathlib/Data/Finsupp/Defs.lean | 293 | 294 |
/-
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.Calculus.ContDiff.Operations
import Mathlib.Analysis.Calculus.UniformLimitsDeriv
import Mathlib.Topology.Algebra.InfiniteSum.Module
import Mathlib.Analysis.NormedSpace.FunctionSeries
/-!
# Smoothness of series
We show that series of functions are differentiable, or smooth, when each individual
function in the series is and additionally suitable uniform summable bounds are satisfied.
More specifically,
* `differentiable_tsum` ensures that a series of differentiable functions is differentiable.
* `contDiff_tsum` ensures that a series of `C^n` functions is `C^n`.
We also give versions of these statements which are localized to a set.
-/
open Set Metric TopologicalSpace Function Asymptotics Filter
open scoped Topology NNReal
variable {α β 𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜]
[NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [CompleteSpace F] {u : α → ℝ}
/-! ### Differentiability -/
variable [NormedSpace 𝕜 F]
variable {f : α → E → F} {f' : α → E → E →L[𝕜] F} {g : α → 𝕜 → F} {g' : α → 𝕜 → F} {v : ℕ → α → ℝ}
{s : Set E} {t : Set 𝕜} {x₀ x : E} {y₀ y : 𝕜} {N : ℕ∞}
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series converges everywhere on the set. -/
theorem summable_of_summable_hasFDerivAt_of_isPreconnected (hu : Summable u) (hs : IsOpen s)
(h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable (f · x₀))
(hx : x ∈ s) : Summable fun n => f n x := by
haveI := Classical.decEq α
rw [summable_iff_cauchySeq_finset] at hf0 ⊢
have A : UniformCauchySeqOn (fun t : Finset α => fun x => ∑ i ∈ t, f' i x) atTop s :=
(tendstoUniformlyOn_tsum hu hf').uniformCauchySeqOn
refine cauchy_map_of_uniformCauchySeqOn_fderiv (f := fun t x ↦ ∑ i ∈ t, f i x)
hs h's A (fun t y hy => ?_) hx₀ hx hf0
exact HasFDerivAt.sum fun i _ => hf i y hy
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series converges everywhere on the set. -/
theorem summable_of_summable_hasDerivAt_of_isPreconnected (hu : Summable u) (ht : IsOpen t)
(h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable (g · y₀))
(hy : y ∈ t) : Summable fun n => g n y := by
simp_rw [hasDerivAt_iff_hasFDerivAt] at hg
refine summable_of_summable_hasFDerivAt_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy
simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul]
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series is differentiable on the set and its derivative is the sum of the
derivatives. -/
theorem hasFDerivAt_tsum_of_isPreconnected (hu : Summable u) (hs : IsOpen s)
(h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable fun n => f n x₀)
(hx : x ∈ s) : HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by
classical
have A :
∀ x : E, x ∈ s → Tendsto (fun t : Finset α => ∑ n ∈ t, f n x) atTop (𝓝 (∑' n, f n x)) := by
intro y hy
apply Summable.hasSum
exact summable_of_summable_hasFDerivAt_of_isPreconnected hu hs h's hf hf' hx₀ hf0 hy
refine hasFDerivAt_of_tendstoUniformlyOn hs (tendstoUniformlyOn_tsum hu hf')
(fun t y hy => ?_) A hx
exact HasFDerivAt.sum fun n _ => hf n y hy
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series is differentiable on the set and its derivative is the sum of the
derivatives. -/
theorem hasDerivAt_tsum_of_isPreconnected (hu : Summable u) (ht : IsOpen t)
(h't : IsPreconnected t) (hg : ∀ n y, y ∈ t → HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, y ∈ t → ‖g' n y‖ ≤ u n) (hy₀ : y₀ ∈ t) (hg0 : Summable fun n => g n y₀)
(hy : y ∈ t) : HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by
simp_rw [hasDerivAt_iff_hasFDerivAt] at hg ⊢
convert hasFDerivAt_tsum_of_isPreconnected hu ht h't hg ?_ hy₀ hg0 hy
· exact (ContinuousLinearMap.smulRightL 𝕜 𝕜 F 1).map_tsum <|
.of_norm_bounded u hu fun n ↦ hg' n y hy
· simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul]
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series converges everywhere. -/
theorem summable_of_summable_hasFDerivAt (hu : Summable u)
(hf : ∀ n x, HasFDerivAt (f n) (f' n x) x) (hf' : ∀ n x, ‖f' n x‖ ≤ u n)
(hf0 : Summable fun n => f n x₀) (x : E) : Summable fun n => f n x := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let _ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _
exact summable_of_summable_hasFDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series converges everywhere. -/
theorem summable_of_summable_hasDerivAt (hu : Summable u)
(hg : ∀ n y, HasDerivAt (g n) (g' n y) y) (hg' : ∀ n y, ‖g' n y‖ ≤ u n)
(hg0 : Summable fun n => g n y₀) (y : 𝕜) : Summable fun n => g n y := by
exact summable_of_summable_hasDerivAt_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n x _ => hg n x) (fun n x _ => hg' n x) (mem_univ _) hg0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series is differentiable and its derivative is the sum of the derivatives. -/
theorem hasFDerivAt_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, ‖f' n x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) :
HasFDerivAt (fun y => ∑' n, f n y) (∑' n, f' n x) x := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let A : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 _
exact hasFDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n x _ => hf n x) (fun n x _ => hf' n x) (mem_univ _) hf0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If the series converges at a
point, and all functions in the series are differentiable with a summable bound on the derivatives,
then the series is differentiable and its derivative is the sum of the derivatives. -/
theorem hasDerivAt_tsum (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, ‖g' n y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) :
HasDerivAt (fun z => ∑' n, g n z) (∑' n, g' n y) y := by
exact hasDerivAt_tsum_of_isPreconnected hu isOpen_univ isPreconnected_univ
(fun n y _ => hg n y) (fun n y _ => hg' n y) (mem_univ _) hg0 (mem_univ _)
/-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable
with a summable bound on the derivatives, then the series is differentiable.
Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise
convergence then the series is zero everywhere so the result still holds. -/
theorem differentiable_tsum (hu : Summable u) (hf : ∀ n x, HasFDerivAt (f n) (f' n x) x)
(hf' : ∀ n x, ‖f' n x‖ ≤ u n) : Differentiable 𝕜 fun y => ∑' n, f n y := by
by_cases h : ∃ x₀, Summable fun n => f n x₀
· rcases h with ⟨x₀, hf0⟩
intro x
exact (hasFDerivAt_tsum hu hf hf' hf0 x).differentiableAt
· push_neg at h
have : (fun x => ∑' n, f n x) = 0 := by ext1 x; exact tsum_eq_zero_of_not_summable (h x)
rw [this]
exact differentiable_const 0
/-- Consider a series of functions `∑' n, f n x`. If all functions in the series are differentiable
with a summable bound on the derivatives, then the series is differentiable.
Note that our assumptions do not ensure the pointwise convergence, but if there is no pointwise
convergence then the series is zero everywhere so the result still holds. -/
theorem differentiable_tsum' (hu : Summable u) (hg : ∀ n y, HasDerivAt (g n) (g' n y) y)
(hg' : ∀ n y, ‖g' n y‖ ≤ u n) : Differentiable 𝕜 fun z => ∑' n, g n z := by
simp_rw [hasDerivAt_iff_hasFDerivAt] at hg
refine differentiable_tsum hu hg ?_
simpa? says simpa only [ContinuousLinearMap.norm_smulRight_apply, norm_one, one_mul]
theorem fderiv_tsum_apply (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n))
(hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) (x : E) :
fderiv 𝕜 (fun y => ∑' n, f n y) x = ∑' n, fderiv 𝕜 (f n) x :=
(hasFDerivAt_tsum hu (fun n x => (hf n x).hasFDerivAt) hf' hf0 _).fderiv
theorem deriv_tsum_apply (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n))
(hg' : ∀ n y, ‖deriv (g n) y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) (y : 𝕜) :
deriv (fun z => ∑' n, g n z) y = ∑' n, deriv (g n) y :=
(hasDerivAt_tsum hu (fun n y => (hg n y).hasDerivAt) hg' hg0 _).deriv
theorem fderiv_tsum (hu : Summable u) (hf : ∀ n, Differentiable 𝕜 (f n))
(hf' : ∀ n x, ‖fderiv 𝕜 (f n) x‖ ≤ u n) (hf0 : Summable fun n => f n x₀) :
(fderiv 𝕜 fun y => ∑' n, f n y) = fun x => ∑' n, fderiv 𝕜 (f n) x := by
ext1 x
exact fderiv_tsum_apply hu hf hf' hf0 x
theorem deriv_tsum (hu : Summable u) (hg : ∀ n, Differentiable 𝕜 (g n))
(hg' : ∀ n y, ‖deriv (g n) y‖ ≤ u n) (hg0 : Summable fun n => g n y₀) :
(deriv fun y => ∑' n, g n y) = fun y => ∑' n, deriv (g n) y := by
ext1 x
exact deriv_tsum_apply hu hg hg' hg0 x
/-! ### Higher smoothness -/
/-- Consider a series of `C^n` functions, with summable uniform bounds on the successive
derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/
theorem iteratedFDeriv_tsum (hf : ∀ i, ContDiff 𝕜 N (f i))
(hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k))
(h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) {k : ℕ}
(hk : (k : ℕ∞) ≤ N) :
(iteratedFDeriv 𝕜 k fun y => ∑' n, f n y) = fun x => ∑' n, iteratedFDeriv 𝕜 k (f n) x := by
induction' k with k IH
· ext1 x
simp_rw [iteratedFDeriv_zero_eq_comp]
exact (continuousMultilinearCurryFin0 𝕜 E F).symm.toContinuousLinearEquiv.map_tsum
· have h'k : (k : ℕ∞) < N := lt_of_lt_of_le (WithTop.coe_lt_coe.2 (Nat.lt_succ_self _)) hk
have A : Summable fun n => iteratedFDeriv 𝕜 k (f n) 0 :=
.of_norm_bounded (v k) (hv k h'k.le) fun n => h'f k n 0 h'k.le
simp_rw [iteratedFDeriv_succ_eq_comp_left, IH h'k.le]
rw [fderiv_tsum (hv _ hk) (fun n => (hf n).differentiable_iteratedFDeriv
(mod_cast h'k)) _ A]
· ext1 x
exact (continuousMultilinearCurryLeftEquiv 𝕜
(fun _ : Fin (k + 1) => E) F).symm.toContinuousLinearEquiv.map_tsum
· intro n x
simpa only [iteratedFDeriv_succ_eq_comp_left, LinearIsometryEquiv.norm_map, comp_apply]
using h'f k.succ n x hk
/-- Consider a series of smooth functions, with summable uniform bounds on the successive
derivatives. Then the iterated derivative of the sum is the sum of the iterated derivative. -/
theorem iteratedFDeriv_tsum_apply (hf : ∀ i, ContDiff 𝕜 N (f i))
(hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k))
(h'f : ∀ (k : ℕ) (i : α) (x : E), (k : ℕ∞) ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) {k : ℕ}
(hk : (k : ℕ∞) ≤ N) (x : E) :
iteratedFDeriv 𝕜 k (fun y => ∑' n, f n y) x = ∑' n, iteratedFDeriv 𝕜 k (f n) x := by
rw [iteratedFDeriv_tsum hf hv h'f hk]
/-- Consider a series of functions `∑' i, f i x`. Assume that each individual function `f i` is of
class `C^N`, and moreover there is a uniform summable upper bound on the `k`-th derivative
for each `k ≤ N`. Then the series is also `C^N`. -/
theorem contDiff_tsum (hf : ∀ i, ContDiff 𝕜 N (f i)) (hv : ∀ k : ℕ, (k : ℕ∞) ≤ N → Summable (v k))
(h'f : ∀ (k : ℕ) (i : α) (x : E), k ≤ N → ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) :
ContDiff 𝕜 N fun x => ∑' i, f i x := by
rw [contDiff_iff_continuous_differentiable]
constructor
· intro m hm
rw [iteratedFDeriv_tsum hf hv h'f hm]
refine continuous_tsum ?_ (hv m hm) ?_
· intro i
| exact ContDiff.continuous_iteratedFDeriv (mod_cast hm) (hf i)
· intro n x
exact h'f _ _ _ hm
· intro m hm
have h'm : ((m + 1 : ℕ) : ℕ∞) ≤ N := by
simpa only [ENat.coe_add, ENat.coe_one] using Order.add_one_le_of_lt hm
rw [iteratedFDeriv_tsum hf hv h'f hm.le]
have A n x : HasFDerivAt (iteratedFDeriv 𝕜 m (f n)) (fderiv 𝕜 (iteratedFDeriv 𝕜 m (f n)) x) x :=
(ContDiff.differentiable_iteratedFDeriv (mod_cast hm)
(hf n)).differentiableAt.hasFDerivAt
refine differentiable_tsum (hv _ h'm) A fun n x => ?_
rw [fderiv_iteratedFDeriv, comp_apply, LinearIsometryEquiv.norm_map]
exact h'f _ _ _ h'm
/-- Consider a series of functions `∑' i, f i x`. Assume that each individual function `f i` is of
class `C^N`, and moreover there is a uniform summable upper bound on the `k`-th derivative
for each `k ≤ N` (except maybe for finitely many `i`s). Then the series is also `C^N`. -/
theorem contDiff_tsum_of_eventually (hf : ∀ i, ContDiff 𝕜 N (f i))
(hv : ∀ k : ℕ, k ≤ N → Summable (v k))
(h'f : ∀ k : ℕ, k ≤ N →
∀ᶠ i in (Filter.cofinite : Filter α), ∀ x : E, ‖iteratedFDeriv 𝕜 k (f i) x‖ ≤ v k i) :
ContDiff 𝕜 N fun x => ∑' i, f i x := by
| Mathlib/Analysis/Calculus/SmoothSeries.lean | 230 | 251 |
/-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Lie.Engel
import Mathlib.Algebra.Lie.Normalizer
import Mathlib.Algebra.Lie.OfAssociative
import Mathlib.Algebra.Lie.Subalgebra
import Mathlib.Data.Finset.NatAntidiagonal
/-!
# Engel subalgebras
This file defines Engel subalgebras of a Lie algebra and provides basic related properties.
The Engel subalgebra `LieSubalgebra.Engel R x` consists of
all `y : L` such that `(ad R L x)^n` kills `y` for some `n`.
## Main results
Engel subalgebras are self-normalizing (`LieSubalgebra.normalizer_engel`),
and minimal ones are nilpotent (TODO), hence Cartan subalgebras.
* `LieSubalgebra.normalizer_eq_self_of_engel_le`:
Lie subalgebras containing an Engel subalgebra are self-normalizing,
provided the ambient Lie algebra is Artinian.
* `LieSubalgebra.isNilpotent_of_forall_le_engel`:
A Lie subalgebra of a Noetherian Lie algebra is nilpotent
if it is contained in the Engel subalgebra of all its elements.
-/
open LieAlgebra LieModule
variable {R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L]
[AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
namespace LieSubalgebra
variable (R)
/-- The Engel subalgebra `Engel R x` consists of
all `y : L` such that `(ad R L x)^n` kills `y` for some `n`.
Engel subalgebras are self-normalizing (`LieSubalgebra.normalizer_engel`),
and minimal ones are nilpotent, hence Cartan subalgebras. -/
@[simps!]
def engel (x : L) : LieSubalgebra R L :=
{ (ad R L x).maxGenEigenspace 0 with
lie_mem' := by
simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup,
Submodule.mem_toAddSubmonoid, Module.End.mem_maxGenEigenspace, zero_smul,
sub_zero, forall_exists_index]
intro y z m hm n hn
refine ⟨m + n, ?_⟩
rw [ad_pow_lie]
apply Finset.sum_eq_zero
intro ij hij
obtain (h|h) : m ≤ ij.1 ∨ n ≤ ij.2 := by rw [Finset.mem_antidiagonal] at hij; omega
all_goals simp [Module.End.pow_map_zero_of_le h, hm, hn] }
lemma mem_engel_iff (x y : L) :
y ∈ engel R x ↔ ∃ n : ℕ, ((ad R L x) ^ n) y = 0 :=
(Module.End.mem_maxGenEigenspace _ _ _).trans <| by simp only [zero_smul, sub_zero]
lemma self_mem_engel (x : L) : x ∈ engel R x := by
simp only [mem_engel_iff]
exact ⟨1, by simp⟩
@[simp]
lemma engel_zero : engel R (0 : L) = ⊤ := by
rw [eq_top_iff]
rintro x -
rw [mem_engel_iff, LieHom.map_zero]
use 1
simp only [pow_one, LinearMap.zero_apply]
/-- Engel subalgebras are self-normalizing.
See `LieSubalgebra.normalizer_eq_self_of_engel_le` for a proof that Lie-subalgebras
containing an Engel subalgebra are also self-normalizing,
provided that the ambient Lie algebra is artinina. -/
@[simp]
lemma normalizer_engel (x : L) : normalizer (engel R x) = engel R x := by
apply le_antisymm _ (le_normalizer _)
intro y hy
rw [mem_normalizer_iff] at hy
specialize hy x (self_mem_engel R x)
rw [← lie_skew, neg_mem_iff (G := L), mem_engel_iff] at hy
rcases hy with ⟨n, hn⟩
rw [mem_engel_iff]
use n+1
rw [pow_succ, Module.End.mul_apply]
exact hn
variable {R}
open Filter in
| /-- A Lie-subalgebra of an Artinian Lie algebra is self-normalizing
if it contains an Engel subalgebra.
See `LieSubalgebra.normalizer_engel` for a proof that Engel subalgebras are self-normalizing,
avoiding the Artinian condition. -/
lemma normalizer_eq_self_of_engel_le [IsArtinian R L]
(H : LieSubalgebra R L) (x : L) (h : engel R x ≤ H) :
normalizer H = H := by
set N := normalizer H
apply le_antisymm _ (le_normalizer H)
calc N.toSubmodule ≤ (engel R x).toSubmodule ⊔ H.toSubmodule := ?_
_ = H := by rwa [sup_eq_right]
have aux₁ : ∀ n ∈ N, ⁅x, n⁆ ∈ H := by
intro n hn
rw [mem_normalizer_iff] at hn
specialize hn x (h (self_mem_engel R x))
rwa [← lie_skew, neg_mem_iff (G := L)]
have aux₂ : ∀ n ∈ N, ⁅x, n⁆ ∈ N := fun n hn ↦ le_normalizer H (aux₁ _ hn)
let dx : N →ₗ[R] N := (ad R L x).restrict aux₂
obtain ⟨k, hk⟩ : ∃ a, ∀ b ≥ a, Codisjoint (LinearMap.ker (dx ^ b)) (LinearMap.range (dx ^ b)) :=
eventually_atTop.mp <| dx.eventually_codisjoint_ker_pow_range_pow
specialize hk (k+1) (Nat.le_add_right k 1)
rw [← Submodule.map_subtype_top N.toSubmodule, Submodule.map_le_iff_le_comap]
apply hk
· rw [← Submodule.map_le_iff_le_comap]
apply le_sup_of_le_left
rw [Submodule.map_le_iff_le_comap]
intro y hy
simp only [Submodule.mem_comap, mem_engel_iff, mem_toSubmodule]
use k+1
clear hk; revert hy
generalize k+1 = k
induction k generalizing y with
| zero =>
cases y; intro hy; simp only [pow_zero, Module.End.one_apply]
exact (AddSubmonoid.mk_eq_zero N.toAddSubmonoid).mp hy
| succ k ih => simp only [pow_succ, LinearMap.mem_ker, Module.End.mul_apply] at ih ⊢; apply ih
· rw [← Submodule.map_le_iff_le_comap]
apply le_sup_of_le_right
rw [Submodule.map_le_iff_le_comap]
rintro _ ⟨y, rfl⟩
simp only [pow_succ', Module.End.mul_apply, Submodule.mem_comap, mem_toSubmodule]
| Mathlib/Algebra/Lie/EngelSubalgebra.lean | 98 | 138 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.BooleanAlgebra
/-!
# The set lattice
This file is a collection of results on the complete atomic boolean algebra structure of `Set α`.
Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`.
## Main declarations
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and
`⋃₀ s = ⋃ x ∈ s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`,
`< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference.
See `Set.instBooleanAlgebra`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `⋃ i, s i` is called `iUnion`
* `⋂ i, s i` is called `iInter`
* `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`.
* `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`.
* `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂`
where `j : i ∈ s`.
* `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂`
where `j : i ∈ s`.
## Notation
* `⋃`: `Set.iUnion`
* `⋂`: `Set.iInter`
* `⋃₀`: `Set.sUnion`
* `⋂₀`: `Set.sInter`
-/
open Function Set
universe u
variable {α β γ δ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by
simp_rw [mem_iUnion]
theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by
simp_rw [mem_iInter]
theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i :=
mem_iUnion.2 ⟨i, ha⟩
theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) :
a ∈ ⋃ (i) (j), s i j :=
mem_iUnion₂.2 ⟨i, j, ha⟩
theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i :=
mem_iInter.2 h
theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) :
a ∈ ⋂ (i) (j), s i j :=
mem_iInter₂.2 h
/-! ### Union and intersection over an indexed family of sets -/
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ :=
iSup_congr_Prop pq f
@[congr]
theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ :=
iInf_congr_Prop pq f
theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i :=
iSup_plift_up _
theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i :=
iSup_plift_down _
theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i :=
iInf_plift_up _
theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i :=
iInf_plift_down _
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ :=
iSup_eq_if _
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋃ h : p, s h = if h : p then s h else ∅ :=
iSup_eq_dif _
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ :=
iInf_eq_if _
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋂ h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β)
(w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by
have p : x ∈ ⊤ := Set.mem_univ x
rw [← w, Set.mem_iUnion] at p
simpa using p
theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α)
(H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by
obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some
exact ⟨x, m⟩
theorem nonempty_of_nonempty_iUnion
{s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by
obtain ⟨x, hx⟩ := h_Union
exact ⟨Classical.choose <| mem_iUnion.mp hx⟩
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } :=
ext fun _ => mem_iInter.symm
theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t :=
iSup_le h
theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) :
⋃ (i) (j), s i j ⊆ t :=
iUnion_subset fun x => iUnion_subset (h x)
theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
le_iInf h
theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) :
s ⊆ ⋂ (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
@[simp]
theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t :=
⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩
theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} :
⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff]
@[simp]
theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i :=
le_iInf_iff
theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} :
(s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff]
theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i :=
le_iSup
theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i :=
iInf_le
lemma iInter_subset_iUnion [Nonempty ι] {s : ι → Set α} : ⋂ i, s i ⊆ ⋃ i, s i := iInf_le_iSup
theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' :=
le_iSup₂ i j
theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j :=
iInf₂_le i j
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i :=
le_iSup_of_le i h
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) :
⋂ i, s i ⊆ t :=
iInf_le_of_le i h
/-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i)
(h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j :=
le_iSup₂_of_le i j h
/-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i)
(h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t :=
iInf₂_le_of_le i j h
theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono h
@[gcongr]
theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t :=
iSup_mono h
theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j :=
iSup₂_mono h
theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i :=
iInf_mono h
@[gcongr]
theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t :=
iInf_mono h
theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j :=
iInf₂_mono h
theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) :
⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono' h
theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' :=
iSup₂_mono' h
theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) :
⋂ i, s i ⊆ ⋂ j, t j :=
Set.subset_iInter fun j =>
let ⟨i, hi⟩ := h j
iInter_subset_of_subset i hi
theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' :=
subset_iInter₂_iff.2 fun i' j' =>
let ⟨_, _, hst⟩ := h i' j'
(iInter₂_subset _ _).trans hst
theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) :
⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) :
⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by
ext
exact mem_iUnion
theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by
ext
exact mem_iInter
theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y :=
h1.iSup_congr h h2
theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y :=
h1.iInf_congr h h2
lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h
lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h
lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋃ (i) (j), s i j = ⋃ (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋂ (i) (j), s i j = ⋂ (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
section Nonempty
variable [Nonempty ι] {f : ι → Set α} {s : Set α}
lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const
lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const
lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
end Nonempty
@[simp]
theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ :=
compl_iSup
theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iUnion]
@[simp]
theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ :=
compl_iInf
theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iInter]
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by
simp only [compl_iInter, compl_compl]
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by
simp only [compl_iUnion, compl_compl]
theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i :=
inf_iSup_eq _ _
theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
iSup_inf_eq _ _
theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) :
⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i :=
iSup_sup_eq
theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) :
⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i :=
iInf_inf_eq
theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i :=
sup_iSup
theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
iSup_sup
theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i :=
inf_iInf
theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
iInf_inf
theorem insert_iUnion [Nonempty ι] (x : β) (t : ι → Set β) :
insert x (⋃ i, t i) = ⋃ i, insert x (t i) := by
simp_rw [← union_singleton, iUnion_union]
-- classical
theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i :=
sup_iInf_eq _ _
theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
theorem insert_iInter (x : β) (t : ι → Set β) : insert x (⋂ i, t i) = ⋂ i, insert x (t i) := by
simp_rw [← union_singleton, iInter_union]
theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s :=
iUnion_inter _ _
theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i :=
le_iSup_inf_iSup s t
theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_monotone hs ht
theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_antitone hs ht
theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_monotone hs ht
theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_antitone hs ht
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) :=
iSup_option s
theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) :=
iInf_option s
section
variable (p : ι → Prop) [DecidablePred p]
theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h :=
iSup_dite _ _ _
theorem iUnion_ite (f g : ι → Set α) :
⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i :=
iUnion_dite _ _ _
theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h :=
iInf_dite _ _ _
theorem iInter_ite (f g : ι → Set α) :
⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i :=
iInter_dite _ _ _
end
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False → Set α} : iInter s = univ :=
iInf_false
theorem iUnion_false {s : False → Set α} : iUnion s = ∅ :=
iSup_false
@[simp]
theorem iInter_true {s : True → Set α} : iInter s = s trivial :=
iInf_true
@[simp]
theorem iUnion_true {s : True → Set α} : iUnion s = s trivial :=
iSup_true
@[simp]
theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} :
⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ :=
iInf_exists
@[simp]
theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} :
⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ :=
iSup_exists
@[simp]
theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ :=
iSup_bot
@[simp]
theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ :=
iInf_top
section
variable {s : ι → Set α}
@[simp]
theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ :=
iSup_eq_bot
@[simp]
theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ :=
iInf_eq_top
@[simp]
theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
theorem nonempty_biUnion {t : Set α} {s : α → Set β} :
(⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp
theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) :
⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ :=
iSup_exists
end
@[simp]
theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋂ (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋂ (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋃ (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋃ (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) :
⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) :=
iInf_or
theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) :
⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) :=
iSup_or
theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ :=
iSup_and
theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ :=
iInf_and
theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' :=
iSup_comm
theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' :=
iInf_comm
theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_sigma
theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_sigma
theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 :=
iInf_sigma' _
theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iSup₂_comm _
theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iInf₂_comm _
@[simp]
theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι']
@[simp]
theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι]
@[simp]
theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iInter_and, @iInter_comm _ ι']
@[simp]
theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iInter_and, @iInter_comm _ ι]
@[simp]
theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
@[simp]
theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
lemma iUnion_sum {s : α ⊕ β → Set γ} : ⋃ x, s x = (⋃ x, s (.inl x)) ∪ ⋃ x, s (.inr x) := iSup_sum
lemma iInter_sum {s : α ⊕ β → Set γ} : ⋂ x, s x = (⋂ x, s (.inl x)) ∩ ⋂ x, s (.inr x) := iInf_sum
theorem iUnion_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_psigma _
/-- A reversed version of `iUnion_psigma` with a curried map. -/
theorem iUnion_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : PSigma γ, s ia.1 ia.2 :=
iSup_psigma' _
theorem iInter_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_psigma _
/-- A reversed version of `iInter_psigma` with a curried map. -/
theorem iInter_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : PSigma γ, s ia.1 ia.2 :=
iInf_psigma' _
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnion₂`. -/
theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
mem_iUnion₂_of_mem xs ytx
/-- A specialization of `mem_iInter₂`. -/
theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
mem_iInter₂_of_mem h
/-- A specialization of `subset_iUnion₂`. -/
theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) :
u x ⊆ ⋃ x ∈ s, u x :=
subset_iUnion₂ (s := fun i _ => u i) x xs
/-- A specialization of `iInter₂_subset`. -/
theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) :
⋂ x ∈ s, t x ⊆ t x :=
iInter₂_subset x xs
lemma biInter_subset_biUnion {s : Set α} (hs : s.Nonempty) {t : α → Set β} :
⋂ x ∈ s, t x ⊆ ⋃ x ∈ s, t x := biInf_le_biSup hs
theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') :
⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x :=
iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx
theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) :
⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x :=
subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx
theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) :
⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h
theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) :
⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInter₂_mono h
theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) :
⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 :=
iSup_subtype'
theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) :
⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 :=
iInf_subtype'
@[simp] lemma biUnion_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋃ a ∈ s, t = t :=
biSup_const hs
@[simp] lemma biInter_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋂ a ∈ s, t = t :=
biInf_const hs
theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ :=
iSup_subtype
theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ :=
iInf_subtype
theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ :=
iInf_emptyset
theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x :=
iInf_univ
@[simp]
theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s :=
Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
@[simp]
theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a :=
iInf_singleton
theorem biInter_union (s t : Set α) (u : α → Set β) :
⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x :=
iInf_union
theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) :
⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp
theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by
rw [biInter_insert, biInter_singleton]
theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, ← iInter_inter]
theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by
rw [inter_comm, ← biInter_inter hs]
simp [inter_comm]
theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ :=
iSup_emptyset
theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x :=
iSup_univ
theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a :=
iSup_singleton
@[simp]
theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s :=
ext <| by simp
theorem biUnion_union (s t : Set α) (u : α → Set β) :
⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x :=
iSup_union
@[simp]
theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iUnion_subtype _ _
@[simp]
theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iInter_subtype _ _
theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) :
⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp
theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by
simp
theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion]
theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter]
theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter]
theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union]
theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀ S :=
⟨t, ht, hx⟩
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀ S)
(ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩
theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
sInf_le tS
theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀ S :=
le_sSup tS
theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀ t :=
Subset.trans h₁ (subset_sUnion_of_mem h₂)
theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀ S ⊆ t :=
sSup_le h
@[simp]
theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀ s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t :=
sSup_le_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) :
⋃₀ s ⊆ ⋃₀ (f '' s) :=
fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) :
⋃₀ (f '' s) ⊆ ⋃₀ s :=
-- If t ∈ f '' s is arbitrary; t = f u for some u : Set α.
fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩
theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S :=
le_sInf h
@[simp]
theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' :=
le_sInf_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
@[simp]
theorem sUnion_empty : ⋃₀ ∅ = (∅ : Set α) :=
sSup_empty
@[simp]
theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) :=
sInf_empty
@[simp]
theorem sUnion_singleton (s : Set α) : ⋃₀ {s} = s :=
sSup_singleton
@[simp]
theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s :=
sInf_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀ S = ∅ ↔ ∀ s ∈ S, s = ∅ :=
sSup_eq_bot
@[simp]
theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ :=
sInf_eq_top
theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t :=
sUnion_subset_iff.symm
/-- `⋃₀` and `𝒫` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gc_sSup_Iic
/-- `⋃₀` and `𝒫` form a Galois insertion. -/
def sUnionPowersetGI :
GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gi_sSup_Iic
@[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI
/-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) :
⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro ⟨s, hs, hne⟩
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀ S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀ s).Nonempty) : s.Nonempty :=
let ⟨s, hs, _⟩ := nonempty_sUnion.1 h
⟨s, hs⟩
theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀ s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm ▸ univ_nonempty
theorem sUnion_union (S T : Set (Set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T :=
sSup_union
theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T :=
sInf_union
@[simp]
theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀ insert s T = s ∪ ⋃₀ T :=
sSup_insert
@[simp]
theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T :=
sInf_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀ (s \ {∅}) = ⋃₀ s :=
sSup_diff_singleton_bot s
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s :=
sInf_diff_singleton_top s
theorem sUnion_pair (s t : Set α) : ⋃₀ {s, t} = s ∪ t :=
sSup_pair
theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t :=
sInf_pair
@[simp]
theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀ (f '' s) = ⋃ a ∈ s, f a :=
sSup_image
@[simp]
theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ a ∈ s, f a :=
sInf_image
@[simp]
lemma sUnion_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) :
⋃₀ (image2 f s t) = ⋃ (a ∈ s) (b ∈ t), f a b := sSup_image2
@[simp]
lemma sInter_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) :
⋂₀ (image2 f s t) = ⋂ (a ∈ s) (b ∈ t), f a b := sInf_image2
@[simp]
theorem sUnion_range (f : ι → Set β) : ⋃₀ range f = ⋃ x, f x :=
rfl
@[simp]
theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x :=
rfl
theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} :
⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀ c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by
simp only [eq_univ_iff_forall, mem_sUnion]
-- classical
theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} :
⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
-- classical
theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
@[simp]
theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
-- classical
theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} :
(⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by
simp
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
-- classical
theorem compl_sUnion (S : Set (Set α)) : (⋃₀ S)ᶜ = ⋂₀ (compl '' S) :=
ext fun x => by simp
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀ S = (⋂₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋃₀ S), compl_sUnion]
-- classical
theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀ (compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋂₀ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀ S = ∅) : s ∩ t = ∅ :=
eq_empty_of_subset_empty <| by
rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) :
range f = ⋃ a, range fun b => f ⟨a, b⟩ :=
Set.ext <| by simp
theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) :
⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
· rintro ⟨i, a, h, rfl⟩
exact h
· intro h
obtain ⟨i, a⟩ := x
exact ⟨i, a, h, rfl⟩
theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩
alias sUnion_mono := sUnion_subset_sUnion
alias sInter_mono := sInter_subset_sInter
theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s :=
iSup_const_mono (α := Set α) h
@[simp]
theorem iUnion_singleton_eq_range (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x
simp [@eq_comm _ x]
theorem iUnion_insert_eq_range_union_iUnion {ι : Type*} (x : ι → β) (t : ι → Set β) :
⋃ i, insert (x i) (t i) = range x ∪ ⋃ i, t i := by
simp_rw [← union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range]
theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff]
theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp
theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀ s = ⋃ (i : Set α) (_ : i ∈ s), i := by
rw [← sUnion_image, image_id']
theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by
rw [← sInter_image, image_id']
theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀ s = ⋃ i : s, i := by
simp only [← sUnion_range, Subtype.range_coe]
theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by
simp only [← sInter_range, Subtype.range_coe]
@[simp]
theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ :=
iSup_of_empty _
@[simp]
theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ :=
iInf_of_empty _
theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ :=
sup_eq_iSup s₁ s₂
theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ :=
inf_eq_iInf s₁ s₂
theorem sInter_union_sInter {S T : Set (Set α)} :
⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 :=
sInf_sup_sInf
theorem sUnion_inter_sUnion {s t : Set (Set α)} :
⋃₀ s ∩ ⋃₀ t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 :=
sSup_inf_sSup
theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) :
⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι]
theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) :
⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι]
theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀ ⋃ i, s i = ⋃ i, ⋃₀ s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)}
(hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀ C := by
ext x; constructor
· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩
refine ⟨_, hs, ?_⟩
exact (f ⟨s, hs⟩ y).2
· rintro ⟨s, hs, hx⟩
obtain ⟨y, hy⟩ := hf ⟨s, hs⟩ ⟨x, hx⟩
refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩
exact congr_arg Subtype.val hy
theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x}
(hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
· rintro ⟨y, i, rfl⟩
exact ⟨i, (f i y).2⟩
· rintro ⟨i, hx⟩
obtain ⟨y, hy⟩ := hf i ⟨x, hx⟩
exact ⟨y, i, congr_arg Subtype.val hy⟩
theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i :=
sup_iInf_eq _ _
theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left]
theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right]
lemma biUnion_lt_eq_iUnion [LT α] [NoMaxOrder α] {s : α → Set β} :
⋃ (n) (m < n), s m = ⋃ n, s n := biSup_lt_eq_iSup
lemma biUnion_le_eq_iUnion [Preorder α] {s : α → Set β} :
⋃ (n) (m ≤ n), s m = ⋃ n, s n := biSup_le_eq_iSup
lemma biInter_lt_eq_iInter [LT α] [NoMaxOrder α] {s : α → Set β} :
⋂ (n) (m < n), s m = ⋂ (n), s n := biInf_lt_eq_iInf
lemma biInter_le_eq_iInter [Preorder α] {s : α → Set β} :
⋂ (n) (m ≤ n), s m = ⋂ (n), s n := biInf_le_eq_iInf
lemma biUnion_gt_eq_iUnion [LT α] [NoMinOrder α] {s : α → Set β} :
⋃ (n) (m > n), s m = ⋃ n, s n := biSup_gt_eq_iSup
lemma biUnion_ge_eq_iUnion [Preorder α] {s : α → Set β} :
⋃ (n) (m ≥ n), s m = ⋃ n, s n := biSup_ge_eq_iSup
lemma biInter_gt_eq_iInf [LT α] [NoMinOrder α] {s : α → Set β} :
⋂ (n) (m > n), s m = ⋂ n, s n := biInf_gt_eq_iInf
lemma biInter_ge_eq_iInf [Preorder α] {s : α → Set β} :
⋂ (n) (m ≥ n), s m = ⋂ n, s n := biInf_ge_eq_iInf
section le
variable {ι : Type*} [PartialOrder ι] (s : ι → Set α) (i : ι)
theorem biUnion_le : (⋃ j ≤ i, s j) = (⋃ j < i, s j) ∪ s i :=
biSup_le_eq_sup s i
theorem biInter_le : (⋂ j ≤ i, s j) = (⋂ j < i, s j) ∩ s i :=
biInf_le_eq_inf s i
theorem biUnion_ge : (⋃ j ≥ i, s j) = s i ∪ ⋃ j > i, s j :=
biSup_ge_eq_sup s i
theorem biInter_ge : (⋂ j ≥ i, s j) = s i ∩ ⋂ j > i, s j :=
biInf_ge_eq_inf s i
end le
section Pi
variable {π : α → Type*}
theorem pi_def (i : Set α) (s : ∀ a, Set (π a)) : pi i s = ⋂ a ∈ i, eval a ⁻¹' s a := by
ext
simp
theorem univ_pi_eq_iInter (t : ∀ i, Set (π i)) : pi univ t = ⋂ i, eval i ⁻¹' t i := by
simp only [pi_def, iInter_true, mem_univ]
theorem pi_diff_pi_subset (i : Set α) (s t : ∀ a, Set (π a)) :
pi i s \ pi i t ⊆ ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by
refine diff_subset_comm.2 fun x hx a ha => ?_
simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not,
eval_apply] at hx
exact hx.2 _ ha (hx.1 _ ha)
theorem iUnion_univ_pi {ι : α → Type*} (t : (a : α) → ι a → Set (π a)) :
⋃ x : (a : α) → ι a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ι a, t a j := by
ext
simp [Classical.skolem]
end Pi
section Directed
theorem directedOn_iUnion {r} {f : ι → Set α} (hd : Directed (· ⊆ ·) f)
(h : ∀ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by
simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp]
exact fun a₁ b₁ fb₁ a₂ b₂ fb₂ =>
let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂
let ⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂)
⟨x, ⟨z, xf⟩, xa₁, xa₂⟩
theorem directedOn_sUnion {r} {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S)
(h : ∀ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by
rw [sUnion_eq_iUnion]
exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2)
theorem pairwise_iUnion₂ {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S)
(r : α → α → Prop) (h : ∀ s ∈ S, s.Pairwise r) : (⋃ s ∈ S, s).Pairwise r := by
simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp]
intro x S hS hx y T hT hy hne
obtain ⟨U, hU, hSU, hTU⟩ := hd S hS T hT
exact h U hU (hSU hx) (hTU hy) hne
end Directed
end Set
namespace Function
namespace Surjective
theorem iUnion_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋃ x, g (f x) = ⋃ y, g y :=
hf.iSup_comp g
theorem iInter_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋂ x, g (f x) = ⋂ y, g y :=
hf.iInf_comp g
end Surjective
end Function
/-!
### Disjoint sets
-/
section Disjoint
variable {s t : Set α}
namespace Set
@[simp]
theorem disjoint_iUnion_left {ι : Sort*} {s : ι → Set α} :
Disjoint (⋃ i, s i) t ↔ ∀ i, Disjoint (s i) t :=
iSup_disjoint_iff
@[simp]
theorem disjoint_iUnion_right {ι : Sort*} {s : ι → Set α} :
Disjoint t (⋃ i, s i) ↔ ∀ i, Disjoint t (s i) :=
disjoint_iSup_iff
theorem disjoint_iUnion₂_left {s : ∀ i, κ i → Set α} {t : Set α} :
Disjoint (⋃ (i) (j), s i j) t ↔ ∀ i j, Disjoint (s i j) t :=
iSup₂_disjoint_iff
theorem disjoint_iUnion₂_right {s : Set α} {t : ∀ i, κ i → Set α} :
Disjoint s (⋃ (i) (j), t i j) ↔ ∀ i j, Disjoint s (t i j) :=
disjoint_iSup₂_iff
@[simp]
theorem disjoint_sUnion_left {S : Set (Set α)} {t : Set α} :
Disjoint (⋃₀ S) t ↔ ∀ s ∈ S, Disjoint s t :=
sSup_disjoint_iff
@[simp]
theorem disjoint_sUnion_right {s : Set α} {S : Set (Set α)} :
Disjoint s (⋃₀ S) ↔ ∀ t ∈ S, Disjoint s t :=
disjoint_sSup_iff
lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ι : Type*} {Es : ι → Set α}
(Es_union : ⋃ i, Es i = univ) (Es_disj : Pairwise fun i j ↦ Disjoint (Es i) (Es j))
(I : Set ι) :
(⋃ i ∈ I, Es i)ᶜ = ⋃ i ∈ Iᶜ, Es i := by
ext x
obtain ⟨i, hix⟩ : ∃ i, x ∈ Es i := by simp [← mem_iUnion, Es_union]
have obs : ∀ (J : Set ι), x ∈ ⋃ j ∈ J, Es j ↔ i ∈ J := by
refine fun J ↦ ⟨?_, fun i_in_J ↦ by simpa only [mem_iUnion, exists_prop] using ⟨i, i_in_J, hix⟩⟩
intro x_in_U
simp only [mem_iUnion, exists_prop] at x_in_U
obtain ⟨j, j_in_J, hjx⟩ := x_in_U
rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl]
have obs' : ∀ (J : Set ι), x ∈ (⋃ j ∈ J, Es j)ᶜ ↔ i ∉ J :=
fun J ↦ by simpa only [mem_compl_iff, not_iff_not] using obs J
rw [obs, obs', mem_compl_iff]
end Set
end Disjoint
/-! ### Intervals -/
namespace Set
lemma nonempty_iInter_Iic_iff [Preorder α] {f : ι → α} :
(⋂ i, Iic (f i)).Nonempty ↔ BddBelow (range f) := by
have : (⋂ (i : ι), Iic (f i)) = lowerBounds (range f) := by
ext c; simp [lowerBounds]
simp [this, BddBelow]
lemma nonempty_iInter_Ici_iff [Preorder α] {f : ι → α} :
(⋂ i, Ici (f i)).Nonempty ↔ BddAbove (range f) :=
nonempty_iInter_Iic_iff (α := αᵒᵈ)
variable [CompleteLattice α]
theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) :=
ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter]
theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⋂ i, Iic (f i) :=
ext fun _ => by simp only [mem_Iic, le_iInf_iff, mem_iInter]
theorem Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⋂ (i) (j), Ici (f i j) := by
simp_rw [Ici_iSup]
theorem Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⋂ (i) (j), Iic (f i j) := by
simp_rw [Iic_iInf]
theorem Ici_sSup (s : Set α) : Ici (sSup s) = ⋂ a ∈ s, Ici a := by rw [sSup_eq_iSup, Ici_iSup₂]
theorem Iic_sInf (s : Set α) : Iic (sInf s) = ⋂ a ∈ s, Iic a := by rw [sInf_eq_iInf, Iic_iInf₂]
end Set
namespace Set
variable (t : α → Set β)
theorem biUnion_diff_biUnion_subset (s₁ s₂ : Set α) :
((⋃ x ∈ s₁, t x) \ ⋃ x ∈ s₂, t x) ⊆ ⋃ x ∈ s₁ \ s₂, t x := by
simp only [diff_subset_iff, ← biUnion_union]
apply biUnion_subset_biUnion_left
rw [union_diff_self]
apply subset_union_right
/-- If `t` is an indexed family of sets, then there is a natural map from `Σ i, t i` to `⋃ i, t i`
sending `⟨i, x⟩` to `x`. -/
def sigmaToiUnion (x : Σi, t i) : ⋃ i, t i :=
⟨x.2, mem_iUnion.2 ⟨x.1, x.2.2⟩⟩
theorem sigmaToiUnion_surjective : Surjective (sigmaToiUnion t)
| ⟨b, hb⟩ =>
have : ∃ a, b ∈ t a := by simpa using hb
let ⟨a, hb⟩ := this
⟨⟨a, b, hb⟩, rfl⟩
theorem sigmaToiUnion_injective (h : Pairwise (Disjoint on t)) :
Injective (sigmaToiUnion t)
| ⟨a₁, b₁, h₁⟩, ⟨a₂, b₂, h₂⟩, eq =>
have b_eq : b₁ = b₂ := congr_arg Subtype.val eq
have a_eq : a₁ = a₂ :=
by_contradiction fun ne =>
have : b₁ ∈ t a₁ ∩ t a₂ := ⟨h₁, b_eq.symm ▸ h₂⟩
(h ne).le_bot this
Sigma.eq a_eq <| Subtype.eq <| by subst b_eq; subst a_eq; rfl
theorem sigmaToiUnion_bijective (h : Pairwise (Disjoint on t)) :
Bijective (sigmaToiUnion t) :=
⟨sigmaToiUnion_injective t h, sigmaToiUnion_surjective t⟩
/-- Equivalence from the disjoint union of a family of sets forming a partition of `β`, to `β`
itself. -/
noncomputable def sigmaEquiv (s : α → Set β) (hs : ∀ b, ∃! i, b ∈ s i) :
(Σ i, s i) ≃ β where
toFun | ⟨_, b⟩ => b
invFun b := ⟨(hs b).choose, b, (hs b).choose_spec.1⟩
left_inv | ⟨i, b, hb⟩ => Sigma.subtype_ext ((hs b).choose_spec.2 i hb).symm rfl
right_inv _ := rfl
/-- Equivalence between a disjoint union and a dependent sum. -/
noncomputable def unionEqSigmaOfDisjoint {t : α → Set β}
(h : Pairwise (Disjoint on t)) :
(⋃ i, t i) ≃ Σi, t i :=
(Equiv.ofBijective _ <| sigmaToiUnion_bijective t h).symm
theorem iUnion_ge_eq_iUnion_nat_add (u : ℕ → Set α) (n : ℕ) : ⋃ i ≥ n, u i = ⋃ i, u (i + n) :=
iSup_ge_eq_iSup_nat_add u n
theorem iInter_ge_eq_iInter_nat_add (u : ℕ → Set α) (n : ℕ) : ⋂ i ≥ n, u i = ⋂ i, u (i + n) :=
iInf_ge_eq_iInf_nat_add u n
theorem _root_.Monotone.iUnion_nat_add {f : ℕ → Set α} (hf : Monotone f) (k : ℕ) :
⋃ n, f (n + k) = ⋃ n, f n :=
hf.iSup_nat_add k
theorem _root_.Antitone.iInter_nat_add {f : ℕ → Set α} (hf : Antitone f) (k : ℕ) :
⋂ n, f (n + k) = ⋂ n, f n :=
hf.iInf_nat_add k
@[simp]
theorem iUnion_iInter_ge_nat_add (f : ℕ → Set α) (k : ℕ) :
⋃ n, ⋂ i ≥ n, f (i + k) = ⋃ n, ⋂ i ≥ n, f i :=
iSup_iInf_ge_nat_add f k
theorem union_iUnion_nat_succ (u : ℕ → Set α) : (u 0 ∪ ⋃ i, u (i + 1)) = ⋃ i, u i :=
sup_iSup_nat_succ u
theorem inter_iInter_nat_succ (u : ℕ → Set α) : (u 0 ∩ ⋂ i, u (i + 1)) = ⋂ i, u i :=
inf_iInf_nat_succ u
end Set
open Set
variable [CompleteLattice β]
theorem iSup_iUnion (s : ι → Set α) (f : α → β) : ⨆ a ∈ ⋃ i, s i, f a = ⨆ (i) (a ∈ s i), f a := by
rw [iSup_comm]
simp_rw [mem_iUnion, iSup_exists]
theorem iInf_iUnion (s : ι → Set α) (f : α → β) : ⨅ a ∈ ⋃ i, s i, f a = ⨅ (i) (a ∈ s i), f a :=
iSup_iUnion (β := βᵒᵈ) s f
theorem sSup_iUnion (t : ι → Set β) : sSup (⋃ i, t i) = ⨆ i, sSup (t i) := by
simp_rw [sSup_eq_iSup, iSup_iUnion]
theorem sSup_sUnion (s : Set (Set β)) : sSup (⋃₀ s) = ⨆ t ∈ s, sSup t := by
simp only [sUnion_eq_biUnion, sSup_eq_iSup, iSup_iUnion]
theorem sInf_sUnion (s : Set (Set β)) : sInf (⋃₀ s) = ⨅ t ∈ s, sInf t :=
sSup_sUnion (β := βᵒᵈ) s
lemma iSup_sUnion (S : Set (Set α)) (f : α → β) :
(⨆ x ∈ ⋃₀ S, f x) = ⨆ (s ∈ S) (x ∈ s), f x := by
rw [sUnion_eq_iUnion, iSup_iUnion, ← iSup_subtype'']
lemma iInf_sUnion (S : Set (Set α)) (f : α → β) :
(⨅ x ∈ ⋃₀ S, f x) = ⨅ (s ∈ S) (x ∈ s), f x := by
rw [sUnion_eq_iUnion, iInf_iUnion, ← iInf_subtype'']
lemma forall_sUnion {S : Set (Set α)} {p : α → Prop} :
(∀ x ∈ ⋃₀ S, p x) ↔ ∀ s ∈ S, ∀ x ∈ s, p x := by
simp_rw [← iInf_Prop_eq, iInf_sUnion]
lemma exists_sUnion {S : Set (Set α)} {p : α → Prop} :
(∃ x ∈ ⋃₀ S, p x) ↔ ∃ s ∈ S, ∃ x ∈ s, p x := by
simp_rw [← exists_prop, ← iSup_Prop_eq, iSup_sUnion]
| Mathlib/Data/Set/Lattice.lean | 1,820 | 1,826 | |
/-
Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Judith Ludwig, Christian Merten
-/
import Mathlib.Algebra.Module.Torsion
import Mathlib.Algebra.Algebra.Pi
import Mathlib.RingTheory.AdicCompletion.Basic
/-!
# Algebra instance on adic completion
In this file we provide an algebra instance on the adic completion of a ring. Then the adic
completion of any module is a module over the adic completion of the ring.
## Implementation details
We do not make a separate adic completion type in algebra case, to not duplicate all module
theoretic results on adic completions. This choice does cause some trouble though,
since `I ^ n • ⊤` is not defeq to `I ^ n`. We try to work around most of the trouble by
providing as much API as possible.
-/
suppress_compilation
open Submodule
variable {R S : Type*} [CommRing R] [CommRing S] (I : Ideal R)
variable {M : Type*} [AddCommGroup M] [Module R M]
namespace AdicCompletion
attribute [-simp] smul_eq_mul Algebra.id.smul_eq_mul
@[local simp]
theorem transitionMap_ideal_mk {m n : ℕ} (hmn : m ≤ n) (x : R) :
transitionMap I R hmn (Ideal.Quotient.mk (I ^ n • ⊤ : Ideal R) x) =
Ideal.Quotient.mk (I ^ m • ⊤ : Ideal R) x :=
rfl
@[local simp]
theorem transitionMap_map_one {m n : ℕ} (hmn : m ≤ n) : transitionMap I R hmn 1 = 1 :=
rfl
@[local simp]
theorem transitionMap_map_mul {m n : ℕ} (hmn : m ≤ n) (x y : R ⧸ (I ^ n • ⊤ : Ideal R)) :
transitionMap I R hmn (x * y) = transitionMap I R hmn x * transitionMap I R hmn y :=
Quotient.inductionOn₂' x y (fun _ _ ↦ rfl)
@[local simp]
theorem transitionMap_map_pow {m n a : ℕ} (hmn : m ≤ n) (x : R ⧸ (I ^ n • ⊤ : Ideal R)) :
transitionMap I R hmn (x ^ a) = transitionMap I R hmn x ^ a :=
Quotient.inductionOn' x (fun _ ↦ rfl)
/-- `AdicCompletion.transitionMap` as an algebra homomorphism. -/
def transitionMapₐ {m n : ℕ} (hmn : m ≤ n) :
R ⧸ (I ^ n • ⊤ : Ideal R) →ₐ[R] R ⧸ (I ^ m • ⊤ : Ideal R) :=
AlgHom.ofLinearMap (transitionMap I R hmn) rfl (transitionMap_map_mul I hmn)
/-- `AdicCompletion I R` is an `R`-subalgebra of `∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)`. -/
def subalgebra : Subalgebra R (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) :=
Submodule.toSubalgebra (submodule I R) (fun _ ↦ by simp [transitionMap_map_one I])
(fun x y hx hy m n hmn ↦ by simp [hx hmn, hy hmn, transitionMap_map_mul I hmn])
/-- `AdicCompletion I R` is a subring of `∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)`. -/
def subring : Subring (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) :=
Subalgebra.toSubring (subalgebra I)
instance : Mul (AdicCompletion I R) where
mul x y := ⟨x.val * y.val, fun hmn ↦ by
simp [x.property, y.property, transitionMap_map_mul I hmn]⟩
instance : One (AdicCompletion I R) where
one := ⟨1, by simp [transitionMap_map_one I]⟩
instance : NatCast (AdicCompletion I R) where
natCast n := ⟨n, fun _ ↦ rfl⟩
instance : IntCast (AdicCompletion I R) where
intCast n := ⟨n, fun _ ↦ rfl⟩
instance : Pow (AdicCompletion I R) ℕ where
pow x n := ⟨x.val ^ n, fun hmn ↦ by simp [x.property, transitionMap_map_pow I hmn]⟩
instance : CommRing (AdicCompletion I R) :=
let f : AdicCompletion I R → ∀ n, R ⧸ (I ^ n • ⊤ : Ideal R) := Subtype.val
Subtype.val_injective.commRing f rfl rfl
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl)
instance [Algebra S R] : Algebra S (AdicCompletion I R) where
algebraMap :=
{ toFun r := ⟨algebraMap S (∀ n, R ⧸ (I ^ n • ⊤ : Ideal R)) r, fun hmn ↦ by
simp only [Pi.algebraMap_apply,
IsScalarTower.algebraMap_apply S R (R ⧸ (I ^ _ • ⊤ : Ideal R)),
Ideal.Quotient.algebraMap_eq, mapQ_eq_factor]
rfl⟩
map_one' := Subtype.ext <| map_one _
map_mul' x y := Subtype.ext <| map_mul _ x y
map_zero' := Subtype.ext <| map_zero _
map_add' x y := Subtype.ext <| map_add _ x y }
commutes' r x := Subtype.ext <| Algebra.commutes' r x.val
smul_def' r x := Subtype.ext <| Algebra.smul_def' r x.val
@[simp]
theorem val_one (n : ℕ) : (1 : AdicCompletion I R).val n = 1 :=
rfl
@[simp]
theorem val_mul (n : ℕ) (x y : AdicCompletion I R) : (x * y).val n = x.val n * y.val n :=
rfl
/-- The canonical algebra map from the adic completion to `R ⧸ I ^ n`.
This is `AdicCompletion.eval` postcomposed with the algebra isomorphism
`R ⧸ (I ^ n • ⊤) ≃ₐ[R] R ⧸ I ^ n`. -/
def evalₐ (n : ℕ) : AdicCompletion I R →ₐ[R] R ⧸ I ^ n :=
have h : (I ^ n • ⊤ : Ideal R) = I ^ n := by ext x; simp
AlgHom.comp
(Ideal.quotientEquivAlgOfEq R h)
(AlgHom.ofLinearMap (eval I R n) rfl (fun _ _ ↦ rfl))
@[simp]
theorem evalₐ_mk (n : ℕ) (x : AdicCauchySequence I R) :
evalₐ I n (mk I R x) = Ideal.Quotient.mk (I ^ n) (x.val n) := by
simp [evalₐ]
/-- `AdicCauchySequence I R` is an `R`-subalgebra of `ℕ → R`. -/
def AdicCauchySequence.subalgebra : Subalgebra R (ℕ → R) :=
Submodule.toSubalgebra (AdicCauchySequence.submodule I R)
(fun {m n} _ ↦ by simp; rfl)
(fun x y hx hy {m n} hmn ↦ by
simp only [Pi.mul_apply]
exact SModEq.mul (hx hmn) (hy hmn))
/-- `AdicCauchySequence I R` is a subring of `ℕ → R`. -/
def AdicCauchySequence.subring : Subring (ℕ → R) :=
Subalgebra.toSubring (AdicCauchySequence.subalgebra I)
instance : Mul (AdicCauchySequence I R) where
mul x y := ⟨x.val * y.val, fun hmn ↦ SModEq.mul (x.property hmn) (y.property hmn)⟩
instance : One (AdicCauchySequence I R) where
one := ⟨1, fun _ ↦ rfl⟩
instance : NatCast (AdicCauchySequence I R) where
natCast n := ⟨n, fun _ ↦ rfl⟩
instance : IntCast (AdicCauchySequence I R) where
intCast n := ⟨n, fun _ ↦ rfl⟩
instance : Pow (AdicCauchySequence I R) ℕ where
pow x n := ⟨x.val ^ n, fun hmn ↦ SModEq.pow n (x.property hmn)⟩
instance : CommRing (AdicCauchySequence I R) :=
let f : AdicCauchySequence I R → (ℕ → R) := Subtype.val
Subtype.val_injective.commRing f rfl rfl
| (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
(fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ ↦ rfl)
instance : Algebra R (AdicCauchySequence I R) where
| Mathlib/RingTheory/AdicCompletion/Algebra.lean | 159 | 162 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Subalgebra
import Mathlib.LinearAlgebra.Finsupp.Span
/-!
# Lie submodules of a Lie algebra
In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we
use it to define various important operations, notably the Lie span of a subset of a Lie module.
## Main definitions
* `LieSubmodule`
* `LieSubmodule.wellFounded_of_noetherian`
* `LieSubmodule.lieSpan`
* `LieSubmodule.map`
* `LieSubmodule.comap`
## Tags
lie algebra, lie submodule, lie ideal, lattice structure
-/
universe u v w w₁ w₂
section LieSubmodule
variable (R : Type u) (L : Type v) (M : Type w)
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
/-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie module. -/
structure LieSubmodule extends Submodule R M where
lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier
attribute [nolint docBlame] LieSubmodule.toSubmodule
attribute [coe] LieSubmodule.toSubmodule
namespace LieSubmodule
variable {R L M}
variable (N N' : LieSubmodule R L M)
instance : SetLike (LieSubmodule R L M) M where
coe s := s.carrier
coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h
instance : AddSubgroupClass (LieSubmodule R L M) M where
add_mem {N} _ _ := N.add_mem'
zero_mem N := N.zero_mem'
neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx
instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where
smul_mem {s} c _ h := s.smul_mem' c h
/-- The zero module is a Lie submodule of any Lie module. -/
instance : Zero (LieSubmodule R L M) :=
⟨{ (0 : Submodule R M) with
lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩
instance : Inhabited (LieSubmodule R L M) :=
⟨0⟩
instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where
coe N := { x : M // x ∈ N }
instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) :=
⟨toSubmodule⟩
instance : CanLift (Submodule R M) (LieSubmodule R L M) (·)
(fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where
prf N hN := ⟨⟨N, hN⟩, rfl⟩
@[norm_cast]
theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N :=
rfl
theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) :=
Iff.rfl
theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} :
x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} :
x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p :=
Iff.rfl
@[simp]
theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N :=
Iff.rfl
@[deprecated (since := "2024-12-30")] alias mem_coeSubmodule := mem_toSubmodule
theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N :=
Iff.rfl
@[simp]
protected theorem zero_mem : (0 : M) ∈ N :=
zero_mem N
@[simp]
theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 :=
Subtype.ext_iff_val
@[simp]
theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) :
((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S :=
rfl
theorem toSubmodule_mk (p : Submodule R M) (h) :
(({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl
@[deprecated (since := "2024-12-30")] alias coe_toSubmodule_mk := toSubmodule_mk
theorem toSubmodule_injective :
Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by
cases x; cases y; congr
@[deprecated (since := "2024-12-30")] alias coeSubmodule_injective := toSubmodule_injective
@[ext]
theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' :=
SetLike.ext h
@[simp]
theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' :=
toSubmodule_injective.eq_iff
@[deprecated (since := "2024-12-30")] alias coe_toSubmodule_inj := toSubmodule_inj
@[deprecated (since := "2024-12-29")] alias toSubmodule_eq_iff := toSubmodule_inj
/-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where
carrier := s
zero_mem' := by simp [hs]
add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y
smul_mem' := by exact hs.symm ▸ N.smul_mem'
lie_mem := by exact hs.symm ▸ N.lie_mem
@[simp]
theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s :=
rfl
theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
instance : LieRingModule L N where
bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩
add_lie := by intro x y m; apply SetCoe.ext; apply add_lie
lie_add := by intro x m n; apply SetCoe.ext; apply lie_add
leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie
@[simp, norm_cast]
theorem coe_zero : ((0 : N) : M) = (0 : M) :=
rfl
@[simp, norm_cast]
theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) :=
rfl
@[simp, norm_cast]
theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) :=
rfl
@[simp, norm_cast]
theorem coe_bracket (x : L) (m : N) :
(↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ :=
rfl
-- Copying instances from `Submodule` for correct discrimination keys
instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N :=
inferInstanceAs <| IsNoetherian R N.toSubmodule
instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N :=
inferInstanceAs <| IsArtinian R N.toSubmodule
instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N :=
inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule
variable [LieAlgebra R L] [LieModule R L M]
instance instLieModule : LieModule R L N where
lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul
smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie
instance [Subsingleton M] : Unique (LieSubmodule R L M) :=
⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩
end LieSubmodule
variable {R M}
theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) :
(∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by
constructor
· rintro ⟨N, rfl⟩ _ _; exact N.lie_mem
· intro h; use { p with lie_mem := @h }
namespace LieSubalgebra
variable {L}
variable [LieAlgebra R L]
variable (K : LieSubalgebra R L)
/-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains
a distinguished Lie submodule for the action of `K`, namely `K` itself. -/
def toLieSubmodule : LieSubmodule R K L :=
{ (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy }
@[simp]
theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl
variable {K}
@[simp]
theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K :=
Iff.rfl
end LieSubalgebra
end LieSubmodule
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w}
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
variable (N N' : LieSubmodule R L M)
section LatticeStructure
open Set
theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) :=
SetLike.coe_injective
@[simp, norm_cast]
theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' :=
Iff.rfl
@[deprecated (since := "2024-12-30")]
alias coeSubmodule_le_coeSubmodule := toSubmodule_le_toSubmodule
instance : Bot (LieSubmodule R L M) :=
⟨0⟩
instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) :=
inferInstanceAs <| Unique (⊥ : Submodule R M)
@[simp]
theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} :=
rfl
@[simp]
theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ :=
rfl
@[deprecated (since := "2024-12-30")] alias bot_coeSubmodule := bot_toSubmodule
@[simp]
theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_bot_iff := toSubmodule_eq_bot
@[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[simp]
theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 :=
mem_singleton_iff
instance : Top (LieSubmodule R L M) :=
⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩
@[simp]
theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ :=
rfl
@[simp]
theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ :=
rfl
@[deprecated (since := "2024-12-30")] alias top_coeSubmodule := top_toSubmodule
@[simp]
theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_top_iff := toSubmodule_eq_top
@[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) :=
mem_univ x
instance : Min (LieSubmodule R L M) :=
⟨fun N N' ↦
{ (N ⊓ N' : Submodule R M) with
lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩
instance : InfSet (LieSubmodule R L M) :=
⟨fun S ↦
{ toSubmodule := sInf {(s : Submodule R M) | s ∈ S}
lie_mem := fun {x m} h ↦ by
simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq,
forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢
intro N hN; apply N.lie_mem (h N hN) }⟩
@[simp]
theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' :=
rfl
@[norm_cast, simp]
theorem inf_toSubmodule :
(↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) :=
rfl
@[deprecated (since := "2024-12-30")] alias inf_coe_toSubmodule := inf_toSubmodule
@[simp]
theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} :=
rfl
@[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule := sInf_toSubmodule
theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by
rw [sInf_toSubmodule, ← Set.image, sInf_image]
@[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule' := sInf_toSubmodule_eq_iInf
@[simp]
theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by
rw [iInf, sInf_toSubmodule]; ext; simp
@[deprecated (since := "2024-12-30")] alias iInf_coe_toSubmodule := iInf_toSubmodule
@[simp]
theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by
rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe]
ext m
simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp,
and_imp, SetLike.mem_coe, mem_toSubmodule]
@[simp]
theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by
rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq']
@[simp]
theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by
rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl
instance : Max (LieSubmodule R L M) where
max N N' :=
{ toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M)
lie_mem := by
rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M))
change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)
rw [Submodule.mem_sup] at hm ⊢
obtain ⟨y, hy, z, hz, rfl⟩ := hm
exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ }
instance : SupSet (LieSubmodule R L M) where
sSup S :=
{ toSubmodule := sSup {(p : Submodule R M) | p ∈ S}
lie_mem := by
intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S})
change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S}
obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm
clear hm
classical
induction s using Finset.induction_on generalizing m with
| empty =>
replace hsm : m = 0 := by simpa using hsm
simp [hsm]
| insert q t hqt ih =>
rw [Finset.iSup_insert] at hsm
obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm
rw [lie_add]
refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu)
obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t)
suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm')
exact le_sSup ⟨p, hp, rfl⟩ }
@[norm_cast, simp]
theorem sup_toSubmodule :
(↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by
rfl
@[deprecated (since := "2024-12-30")] alias sup_coe_toSubmodule := sup_toSubmodule
@[simp]
theorem sSup_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} :=
rfl
@[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule := sSup_toSubmodule
theorem sSup_toSubmodule_eq_iSup (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by
rw [sSup_toSubmodule, ← Set.image, sSup_image]
@[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule' := sSup_toSubmodule_eq_iSup
@[simp]
theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by
rw [iSup, sSup_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup]
@[deprecated (since := "2024-12-30")] alias iSup_coe_toSubmodule := iSup_toSubmodule
/-- The set of Lie submodules of a Lie module form a complete lattice. -/
instance : CompleteLattice (LieSubmodule R L M) :=
{ toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule
sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with
toPartialOrder := SetLike.instPartialOrder }
theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) :
b ∈ ⨆ i, N i :=
(le_iSup N i) h
@[elab_as_elim]
lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {motive : M → Prop} {x : M}
(hx : x ∈ ⨆ i, N i) (mem : ∀ i, ∀ y ∈ N i, motive y) (zero : motive 0)
(add : ∀ y z, motive y → motive z → motive (y + z)) : motive x := by
rw [← LieSubmodule.mem_toSubmodule, LieSubmodule.iSup_toSubmodule] at hx
exact Submodule.iSup_induction (motive := motive) (fun i ↦ (N i : Submodule R M)) hx mem zero add
@[elab_as_elim]
theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {motive : (x : M) → (x ∈ ⨆ i, N i) → Prop}
(mem : ∀ (i) (x) (hx : x ∈ N i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, N i) : motive x hx := by
refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : motive x hx) => hc
refine iSup_induction N (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), motive x hx) hx
(fun i x hx => ?_) ?_ fun x y => ?_
· exact ⟨_, mem _ _ hx⟩
· exact ⟨_, zero⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, add _ _ _ _ Cx Cy⟩
variable {N N'}
@[simp] lemma disjoint_toSubmodule :
Disjoint (N : Submodule R M) (N' : Submodule R M) ↔ Disjoint N N' := by
rw [disjoint_iff, disjoint_iff, ← toSubmodule_inj, inf_toSubmodule, bot_toSubmodule,
← disjoint_iff]
@[deprecated disjoint_toSubmodule (since := "2025-04-03")]
theorem disjoint_iff_toSubmodule :
Disjoint N N' ↔ Disjoint (N : Submodule R M) (N' : Submodule R M) := disjoint_toSubmodule.symm
@[deprecated (since := "2024-12-30")] alias disjoint_iff_coe_toSubmodule := disjoint_iff_toSubmodule
@[simp] lemma codisjoint_toSubmodule :
Codisjoint (N : Submodule R M) (N' : Submodule R M) ↔ Codisjoint N N' := by
rw [codisjoint_iff, codisjoint_iff, ← toSubmodule_inj, sup_toSubmodule,
top_toSubmodule, ← codisjoint_iff]
@[deprecated codisjoint_toSubmodule (since := "2025-04-03")]
theorem codisjoint_iff_toSubmodule :
Codisjoint N N' ↔ Codisjoint (N : Submodule R M) (N' : Submodule R M) :=
codisjoint_toSubmodule.symm
@[deprecated (since := "2024-12-30")]
alias codisjoint_iff_coe_toSubmodule := codisjoint_iff_toSubmodule
@[simp] lemma isCompl_toSubmodule :
IsCompl (N : Submodule R M) (N' : Submodule R M) ↔ IsCompl N N' := by
simp [isCompl_iff]
@[deprecated isCompl_toSubmodule (since := "2025-04-03")]
theorem isCompl_iff_toSubmodule :
IsCompl N N' ↔ IsCompl (N : Submodule R M) (N' : Submodule R M) := isCompl_toSubmodule.symm
@[deprecated (since := "2024-12-30")] alias isCompl_iff_coe_toSubmodule := isCompl_iff_toSubmodule
@[simp] lemma iSupIndep_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep (fun i ↦ (N i : Submodule R M)) ↔ iSupIndep N := by
simp [iSupIndep_def, ← disjoint_toSubmodule]
@[deprecated iSupIndep_toSubmodule (since := "2025-04-03")]
theorem iSupIndep_iff_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep N ↔ iSupIndep fun i ↦ (N i : Submodule R M) := iSupIndep_toSubmodule.symm
@[deprecated (since := "2024-12-30")]
alias iSupIndep_iff_coe_toSubmodule := iSupIndep_iff_toSubmodule
@[deprecated (since := "2024-11-24")]
alias independent_iff_toSubmodule := iSupIndep_iff_toSubmodule
@[deprecated (since := "2024-12-30")]
alias independent_iff_coe_toSubmodule := independent_iff_toSubmodule
@[simp] lemma iSup_toSubmodule_eq_top {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, (N i : Submodule R M) = ⊤ ↔ ⨆ i, N i = ⊤ := by
rw [← iSup_toSubmodule, ← top_toSubmodule (L := L), toSubmodule_inj]
@[deprecated iSup_toSubmodule_eq_top (since := "2025-04-03")]
theorem iSup_eq_top_iff_toSubmodule {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, N i = ⊤ ↔ ⨆ i, (N i : Submodule R M) = ⊤ := iSup_toSubmodule_eq_top.symm
@[deprecated (since := "2024-12-30")]
alias iSup_eq_top_iff_coe_toSubmodule := iSup_eq_top_iff_toSubmodule
instance : Add (LieSubmodule R L M) where add := max
instance : Zero (LieSubmodule R L M) where zero := ⊥
instance : AddCommMonoid (LieSubmodule R L M) where
add_assoc := sup_assoc
zero_add := bot_sup_eq
add_zero := sup_bot_eq
add_comm := sup_comm
nsmul := nsmulRec
variable (N N')
@[simp]
theorem add_eq_sup : N + N' = N ⊔ N' :=
rfl
@[simp]
theorem mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' := by
rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule,
Submodule.mem_inf]
theorem mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ y ∈ N, ∃ z ∈ N', y + z = x := by
rw [← mem_toSubmodule, sup_toSubmodule, Submodule.mem_sup]; exact Iff.rfl
nonrec theorem eq_bot_iff : N = ⊥ ↔ ∀ m : M, m ∈ N → m = 0 := by rw [eq_bot_iff]; exact Iff.rfl
instance subsingleton_of_bot : Subsingleton (LieSubmodule R L (⊥ : LieSubmodule R L M)) := by
apply subsingleton_of_bot_eq_top
ext ⟨_, hx⟩
simp only [mem_bot, mk_eq_zero, mem_top, iff_true]
exact hx
instance : IsModularLattice (LieSubmodule R L M) where
sup_inf_le_assoc_of_le _ _ := by
simp only [← toSubmodule_le_toSubmodule, sup_toSubmodule, inf_toSubmodule]
exact IsModularLattice.sup_inf_le_assoc_of_le _
variable (R L M)
/-- The natural functor that forgets the action of `L` as an order embedding. -/
@[simps] def toSubmodule_orderEmbedding : LieSubmodule R L M ↪o Submodule R M :=
{ toFun := (↑)
inj' := toSubmodule_injective
map_rel_iff' := Iff.rfl }
instance wellFoundedGT_of_noetherian [IsNoetherian R M] : WellFoundedGT (LieSubmodule R L M) :=
RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).dual.ltEmbedding
theorem wellFoundedLT_of_isArtinian [IsArtinian R M] : WellFoundedLT (LieSubmodule R L M) :=
RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).ltEmbedding
instance [IsArtinian R M] : IsAtomic (LieSubmodule R L M) :=
isAtomic_of_orderBot_wellFounded_lt <| (wellFoundedLT_of_isArtinian R L M).wf
@[simp]
theorem subsingleton_iff : Subsingleton (LieSubmodule R L M) ↔ Subsingleton M :=
have h : Subsingleton (LieSubmodule R L M) ↔ Subsingleton (Submodule R M) := by
rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← toSubmodule_inj,
top_toSubmodule, bot_toSubmodule]
h.trans <| Submodule.subsingleton_iff R
@[simp]
theorem nontrivial_iff : Nontrivial (LieSubmodule R L M) ↔ Nontrivial M :=
not_iff_not.mp
((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R L M).trans
not_nontrivial_iff_subsingleton.symm)
instance [Nontrivial M] : Nontrivial (LieSubmodule R L M) :=
(nontrivial_iff R L M).mpr ‹_›
theorem nontrivial_iff_ne_bot {N : LieSubmodule R L M} : Nontrivial N ↔ N ≠ ⊥ := by
constructor <;> contrapose!
· rintro rfl
⟨⟨m₁, h₁ : m₁ ∈ (⊥ : LieSubmodule R L M)⟩, ⟨m₂, h₂ : m₂ ∈ (⊥ : LieSubmodule R L M)⟩, h₁₂⟩
simp [(LieSubmodule.mem_bot _).mp h₁, (LieSubmodule.mem_bot _).mp h₂] at h₁₂
· rw [not_nontrivial_iff_subsingleton, LieSubmodule.eq_bot_iff]
rintro ⟨h⟩ m hm
simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩
variable {R L M}
section InclusionMaps
/-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/
def incl : N →ₗ⁅R,L⁆ M :=
{ Submodule.subtype (N : Submodule R M) with map_lie' := fun {_ _} ↦ rfl }
@[simp]
theorem incl_coe : (N.incl : N →ₗ[R] M) = (N : Submodule R M).subtype :=
rfl
@[simp]
theorem incl_apply (m : N) : N.incl m = m :=
rfl
theorem incl_eq_val : (N.incl : N → M) = Subtype.val :=
rfl
theorem injective_incl : Function.Injective N.incl := Subtype.coe_injective
variable {N N'}
variable (h : N ≤ N')
/-- Given two nested Lie submodules `N ⊆ N'`,
the inclusion `N ↪ N'` is a morphism of Lie modules. -/
def inclusion : N →ₗ⁅R,L⁆ N' where
__ := Submodule.inclusion (show N.toSubmodule ≤ N'.toSubmodule from h)
map_lie' := rfl
@[simp]
theorem coe_inclusion (m : N) : (inclusion h m : M) = m :=
rfl
theorem inclusion_apply (m : N) : inclusion h m = ⟨m.1, h m.2⟩ :=
rfl
theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by
simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe]
end InclusionMaps
section LieSpan
variable (R L) (s : Set M)
/-- The `lieSpan` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/
def lieSpan : LieSubmodule R L M :=
sInf { N | s ⊆ N }
variable {R L s}
theorem mem_lieSpan {x : M} : x ∈ lieSpan R L s ↔ ∀ N : LieSubmodule R L M, s ⊆ N → x ∈ N := by
rw [← SetLike.mem_coe, lieSpan, sInf_coe]
exact mem_iInter₂
theorem subset_lieSpan : s ⊆ lieSpan R L s := by
intro m hm
rw [SetLike.mem_coe, mem_lieSpan]
intro N hN
exact hN hm
theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by
rw [Submodule.span_le]
apply subset_lieSpan
@[simp]
theorem lieSpan_le {N} : lieSpan R L s ≤ N ↔ s ⊆ N := by
constructor
· exact Subset.trans subset_lieSpan
· intro hs m hm; rw [mem_lieSpan] at hm; exact hm _ hs
theorem lieSpan_mono {t : Set M} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by
rw [lieSpan_le]
exact Subset.trans h subset_lieSpan
theorem lieSpan_eq (N : LieSubmodule R L M) : lieSpan R L (N : Set M) = N :=
le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan
theorem coe_lieSpan_submodule_eq_iff {p : Submodule R M} :
(lieSpan R L (p : Set M) : Submodule R M) = p ↔ ∃ N : LieSubmodule R L M, ↑N = p := by
rw [p.exists_lieSubmodule_coe_eq_iff L]; constructor <;> intro h
· intro x m hm; rw [← h, mem_toSubmodule]; exact lie_mem _ (subset_lieSpan hm)
· rw [← toSubmodule_mk p @h, coe_toSubmodule, toSubmodule_inj, lieSpan_eq]
variable (R L M)
/-- `lieSpan` forms a Galois insertion with the coercion from `LieSubmodule` to `Set`. -/
protected def gi : GaloisInsertion (lieSpan R L : Set M → LieSubmodule R L M) (↑) where
choice s _ := lieSpan R L s
gc _ _ := lieSpan_le
le_l_u _ := subset_lieSpan
| choice_eq _ _ := rfl
| Mathlib/Algebra/Lie/Submodule.lean | 703 | 704 |
/-
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]
theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl
theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by
simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le,
not_imp_comm, Nat.cast_withBot]
theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by
simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff,
WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not]
theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le
end Semiring
section NontrivialSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ)
@[simp]
theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by
rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]
@[simp]
theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_X_pow n)
end NontrivialSemiring
section Ring
variable [Ring R] {p q : R[X]}
theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by
simpa only [degree_neg q] using degree_add_le p (-q)
theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p - q) ≤ max a b :=
(p.degree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by
simpa only [← natDegree_neg q] using natDegree_add_le p (-q)
theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p - q) ≤ max m n :=
(p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0)
(hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p :=
have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p :=
monomial_add_erase _ _
have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q :=
monomial_add_erase _ _
have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd]
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0)
calc
degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by
conv =>
lhs
rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]
_ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) :=
(degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _)
_ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 :=
(degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))
theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 :=
natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r
end Ring
end Polynomial
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 1,027 | 1,031 | |
/-
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
-/
import Mathlib.Analysis.Convex.Combination
import Mathlib.Analysis.Convex.Function
import Mathlib.Tactic.FieldSimp
/-!
# Jensen's inequality and maximum principle for convex functions
In this file, we prove the finite Jensen inequality and the finite maximum principle for convex
functions. The integral versions are to be found in `Analysis.Convex.Integral`.
## Main declarations
Jensen's inequalities:
* `ConvexOn.map_centerMass_le`, `ConvexOn.map_sum_le`: Convex Jensen's inequality. The image of a
convex combination of points under a convex function is less than the convex combination of the
images.
* `ConcaveOn.le_map_centerMass`, `ConcaveOn.le_map_sum`: Concave Jensen's inequality.
* `StrictConvexOn.map_sum_lt`: Convex strict Jensen inequality.
* `StrictConcaveOn.lt_map_sum`: Concave strict Jensen inequality.
As corollaries, we get:
* `StrictConvexOn.map_sum_eq_iff`: Equality case of the convex Jensen inequality.
* `StrictConcaveOn.map_sum_eq_iff`: Equality case of the concave Jensen inequality.
* `ConvexOn.exists_ge_of_mem_convexHull`: Maximum principle for convex functions.
* `ConcaveOn.exists_le_of_mem_convexHull`: Minimum principle for concave functions.
-/
open Finset LinearMap Set Convex Pointwise
variable {𝕜 E F β ι : Type*}
/-! ### Jensen's inequality -/
section Jensen
variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E]
[AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [Module 𝕜 E] [Module 𝕜 β]
[OrderedSMul 𝕜 β] {s : Set E} {f : E → β} {t : Finset ι} {w : ι → 𝕜} {p : ι → E} {v : 𝕜} {q : E}
/-- Convex **Jensen's inequality**, `Finset.centerMass` version. -/
theorem ConvexOn.map_centerMass_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i)
(h₁ : 0 < ∑ i ∈ t, w i) (hmem : ∀ i ∈ t, p i ∈ s) :
f (t.centerMass w p) ≤ t.centerMass w (f ∘ p) := by
have hmem' : ∀ i ∈ t, (p i, (f ∘ p) i) ∈ { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := fun i hi =>
⟨hmem i hi, le_rfl⟩
convert (hf.convex_epigraph.centerMass_mem h₀ h₁ hmem').2 <;>
simp only [centerMass, Function.comp, Prod.smul_fst, Prod.fst_sum, Prod.smul_snd, Prod.snd_sum]
/-- Concave **Jensen's inequality**, `Finset.centerMass` version. -/
theorem ConcaveOn.le_map_centerMass (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i)
(h₁ : 0 < ∑ i ∈ t, w i) (hmem : ∀ i ∈ t, p i ∈ s) :
t.centerMass w (f ∘ p) ≤ f (t.centerMass w p) :=
ConvexOn.map_centerMass_le (β := βᵒᵈ) hf h₀ h₁ hmem
/-- Convex **Jensen's inequality**, `Finset.sum` version. -/
theorem ConvexOn.map_sum_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1)
(hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) ≤ ∑ i ∈ t, w i • f (p i) := by
simpa only [centerMass, h₁, inv_one, one_smul] using
hf.map_centerMass_le h₀ (h₁.symm ▸ zero_lt_one) hmem
/-- Concave **Jensen's inequality**, `Finset.sum` version. -/
theorem ConcaveOn.le_map_sum (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) :
(∑ i ∈ t, w i • f (p i)) ≤ f (∑ i ∈ t, w i • p i) :=
ConvexOn.map_sum_le (β := βᵒᵈ) hf h₀ h₁ hmem
/-- Convex **Jensen's inequality** where an element plays a distinguished role. -/
lemma ConvexOn.map_add_sum_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i)
(h₁ : v + ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hv : 0 ≤ v) (hq : q ∈ s) :
f (v • q + ∑ i ∈ t, w i • p i) ≤ v • f q + ∑ i ∈ t, w i • f (p i) := by
let W j := Option.elim j v w
let P j := Option.elim j q p
have : f (∑ j ∈ insertNone t, W j • P j) ≤ ∑ j ∈ insertNone t, W j • f (P j) :=
hf.map_sum_le (forall_mem_insertNone.2 ⟨hv, h₀⟩) (by simpa using h₁)
(forall_mem_insertNone.2 ⟨hq, hmem⟩)
simpa using this
/-- Concave **Jensen's inequality** where an element plays a distinguished role. -/
lemma ConcaveOn.map_add_sum_le (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i)
(h₁ : v + ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hv : 0 ≤ v) (hq : q ∈ s) :
v • f q + ∑ i ∈ t, w i • f (p i) ≤ f (v • q + ∑ i ∈ t, w i • p i) :=
hf.dual.map_add_sum_le h₀ h₁ hmem hv hq
/-! ### Strict Jensen inequality -/
/-- Convex **strict Jensen inequality**.
If the function is strictly convex, the weights are strictly positive and the indexed family of
points is non-constant, then Jensen's inequality is strict.
See also `StrictConvexOn.map_sum_eq_iff`. -/
lemma StrictConvexOn.map_sum_lt (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hp : ∃ j ∈ t, ∃ k ∈ t, p j ≠ p k) :
f (∑ i ∈ t, w i • p i) < ∑ i ∈ t, w i • f (p i) := by
classical
obtain ⟨j, hj, k, hk, hjk⟩ := hp
-- We replace `t` by `t \ {j, k}`
have : k ∈ t.erase j := mem_erase.2 ⟨ne_of_apply_ne _ hjk.symm, hk⟩
let u := (t.erase j).erase k
have hj : j ∉ u := by simp [u]
have hk : k ∉ u := by simp [u]
have ht :
t = (u.cons k hk).cons j (mem_cons.not.2 <| not_or_intro (ne_of_apply_ne _ hjk) hj) := by
simp [u, insert_erase this, insert_erase ‹j ∈ t›, *]
clear_value u
subst ht
simp only [sum_cons]
have := h₀ j <| by simp
have := h₀ k <| by simp
let c := w j + w k
have hc : w j / c + w k / c = 1 := by field_simp [c]
calc f (w j • p j + (w k • p k + ∑ x ∈ u, w x • p x))
_ = f (c • ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • p x) := by
congrm f ?_
match_scalars <;> field_simp
_ ≤ c • f ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • f (p x) :=
-- apply the usual Jensen's inequality wrt the weighted average of the two distinguished
-- points and all the other points
hf.convexOn.map_add_sum_le (fun i hi ↦ (h₀ _ <| by simp [hi]).le)
(by simpa [-cons_eq_insert, ← add_assoc] using h₁)
(forall_of_forall_cons <| forall_of_forall_cons hmem) (by positivity) <| by
refine hf.1 (hmem _ <| by simp) (hmem _ <| by simp) ?_ ?_ hc <;> positivity
_ < c • ((w j / c) • f (p j) + (w k / c) • f (p k)) + ∑ x ∈ u, w x • f (p x) := by
-- then apply the definition of strict convexity for the two distinguished points
gcongr; refine hf.2 (hmem _ <| by simp) (hmem _ <| by simp) hjk ?_ ?_ hc <;> positivity
_ = (w j • f (p j) + w k • f (p k)) + ∑ x ∈ u, w x • f (p x) := by
match_scalars <;> field_simp
_ = w j • f (p j) + (w k • f (p k) + ∑ x ∈ u, w x • f (p x)) := by abel_nf
/-- Concave **strict Jensen inequality**.
If the function is strictly concave, the weights are strictly positive and the indexed family of
points is non-constant, then Jensen's inequality is strict.
See also `StrictConcaveOn.map_sum_eq_iff`. -/
lemma StrictConcaveOn.lt_map_sum (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hp : ∃ j ∈ t, ∃ k ∈ t, p j ≠ p k) :
∑ i ∈ t, w i • f (p i) < f (∑ i ∈ t, w i • p i) := hf.dual.map_sum_lt h₀ h₁ hmem hp
/-! ### Equality case of Jensen's inequality -/
/-- A form of the **equality case of Jensen's equality**.
For a strictly convex function `f` and positive weights `w`, if
`f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)`, then the points `p` are all equal.
See also `StrictConvexOn.map_sum_eq_iff`. -/
lemma StrictConvexOn.eq_of_le_map_sum (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s)
(h_eq : ∑ i ∈ t, w i • f (p i) ≤ f (∑ i ∈ t, w i • p i)) :
∀ ⦃j⦄, j ∈ t → ∀ ⦃k⦄, k ∈ t → p j = p k := by
by_contra!; exact h_eq.not_lt <| hf.map_sum_lt h₀ h₁ hmem this
/-- A form of the **equality case of Jensen's equality**.
For a strictly concave function `f` and positive weights `w`, if
`f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)`, then the points `p` are all equal.
See also `StrictConcaveOn.map_sum_eq_iff`. -/
lemma StrictConcaveOn.eq_of_map_sum_eq (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s)
(h_eq : f (∑ i ∈ t, w i • p i) ≤ ∑ i ∈ t, w i • f (p i)) :
∀ ⦃j⦄, j ∈ t → ∀ ⦃k⦄, k ∈ t → p j = p k := by
by_contra!; exact h_eq.not_lt <| hf.lt_map_sum h₀ h₁ hmem this
/-- Canonical form of the **equality case of Jensen's equality**.
For a strictly convex function `f` and positive weights `w`, we have
`f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` are all equal
(and in fact all equal to their center of mass wrt `w`). -/
lemma StrictConvexOn.map_sum_eq_iff {w : ι → 𝕜} {p : ι → E} (hf : StrictConvexOn 𝕜 s f)
(h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) :
f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔ ∀ j ∈ t, p j = ∑ i ∈ t, w i • p i := by
constructor
· obtain rfl | ⟨i₀, hi₀⟩ := t.eq_empty_or_nonempty
· simp
intro h_eq i hi
have H : ∀ j ∈ t, p j = p i₀ := by
intro j hj
apply hf.eq_of_le_map_sum h₀ h₁ hmem h_eq.ge hj hi₀
calc p i = p i₀ := by rw [H _ hi]
_ = (1 : 𝕜) • p i₀ := by simp
_ = (∑ j ∈ t, w j) • p i₀ := by rw [h₁]
_ = ∑ j ∈ t, (w j • p i₀) := by rw [sum_smul]
_ = ∑ j ∈ t, (w j • p j) := by congr! 2 with j hj; rw [← H _ hj]
· intro h
have H : ∀ j ∈ t, w j • f (p j) = w j • f (∑ i ∈ t, w i • p i) := by
intro j hj
simp [h j hj]
rw [sum_congr rfl H, ← sum_smul, h₁, one_smul]
/-- Canonical form of the **equality case of Jensen's equality**.
For a strictly concave function `f` and positive weights `w`, we have
`f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` are all equal
(and in fact all equal to their center of mass wrt `w`). -/
lemma StrictConcaveOn.map_sum_eq_iff (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) :
f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔ ∀ j ∈ t, p j = ∑ i ∈ t, w i • p i := by
simpa using hf.neg.map_sum_eq_iff h₀ h₁ hmem
|
/-- Canonical form of the **equality case of Jensen's equality**.
For a strictly convex function `f` and nonnegative weights `w`, we have
`f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` with nonzero
weight are all equal (and in fact all equal to their center of mass wrt `w`). -/
lemma StrictConvexOn.map_sum_eq_iff' (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i)
(h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) :
f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔
| Mathlib/Analysis/Convex/Jensen.lean | 208 | 216 |
/-
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
| Mathlib/Computability/AkraBazzi/AkraBazzi.lean | 175 | 189 |
/-
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.HomotopyCategory.HomComplex
import Mathlib.Algebra.Homology.HomotopyCofiber
/-! # The mapping cone of a morphism of cochain complexes
In this file, we study the homotopy cofiber `HomologicalComplex.homotopyCofiber`
of a morphism `φ : F ⟶ G` of cochain complexes indexed by `ℤ`. In this case,
we redefine it as `CochainComplex.mappingCone φ`. The API involves definitions
- `mappingCone.inl φ : Cochain F (mappingCone φ) (-1)`,
- `mappingCone.inr φ : G ⟶ mappingCone φ`,
- `mappingCone.fst φ : Cocycle (mappingCone φ) F 1` and
- `mappingCone.snd φ : Cochain (mappingCone φ) G 0`.
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Limits
variable {C D : Type*} [Category C] [Category D] [Preadditive C] [Preadditive D]
namespace CochainComplex
open HomologicalComplex
section
variable {ι : Type*} [AddRightCancelSemigroup ι] [One ι]
{F G : CochainComplex C ι} (φ : F ⟶ G)
instance [∀ p, HasBinaryBiproduct (F.X (p + 1)) (G.X p)] :
HasHomotopyCofiber φ where
hasBinaryBiproduct := by
rintro i _ rfl
infer_instance
end
variable {F G : CochainComplex C ℤ} (φ : F ⟶ G)
variable [HasHomotopyCofiber φ]
/-- The mapping cone of a morphism of cochain complexes indexed by `ℤ`. -/
noncomputable def mappingCone := homotopyCofiber φ
namespace mappingCone
open HomComplex
/-- The left inclusion in the mapping cone, as a cochain of degree `-1`. -/
noncomputable def inl : Cochain F (mappingCone φ) (-1) :=
Cochain.mk (fun p q hpq => homotopyCofiber.inlX φ p q (by dsimp; omega))
/-- The right inclusion in the mapping cone. -/
noncomputable def inr : G ⟶ mappingCone φ := homotopyCofiber.inr φ
/-- The first projection from the mapping cone, as a cocyle of degree `1`. -/
noncomputable def fst : Cocycle (mappingCone φ) F 1 :=
Cocycle.mk (Cochain.mk (fun p q hpq => homotopyCofiber.fstX φ p q hpq)) 2 (by omega) (by
ext p _ rfl
simp [δ_v 1 2 (by omega) _ p (p + 2) (by omega) (p + 1) (p + 1) (by omega) rfl,
homotopyCofiber.d_fstX φ p (p + 1) (p + 2) rfl, mappingCone,
show Int.negOnePow 2 = 1 by rfl])
/-- The second projection from the mapping cone, as a cochain of degree `0`. -/
noncomputable def snd : Cochain (mappingCone φ) G 0 :=
Cochain.ofHoms (homotopyCofiber.sndX φ)
@[reassoc (attr := simp)]
lemma inl_v_fst_v (p q : ℤ) (hpq : q + 1 = p) :
(inl φ).v p q (by rw [← hpq, add_neg_cancel_right]) ≫
(fst φ : Cochain (mappingCone φ) F 1).v q p hpq = 𝟙 _ := by
simp [inl, fst]
@[reassoc (attr := simp)]
lemma inl_v_snd_v (p q : ℤ) (hpq : p + (-1) = q) :
(inl φ).v p q hpq ≫ (snd φ).v q q (add_zero q) = 0 := by
simp [inl, snd]
@[reassoc (attr := simp)]
lemma inr_f_fst_v (p q : ℤ) (hpq : p + 1 = q) :
(inr φ).f p ≫ (fst φ).1.v p q hpq = 0 := by
simp [inr, fst]
@[reassoc (attr := simp)]
lemma inr_f_snd_v (p : ℤ) :
(inr φ).f p ≫ (snd φ).v p p (add_zero p) = 𝟙 _ := by
simp [inr, snd]
@[simp]
lemma inl_fst :
(inl φ).comp (fst φ).1 (neg_add_cancel 1) = Cochain.ofHom (𝟙 F) := by
ext p
simp [Cochain.comp_v _ _ (neg_add_cancel 1) p (p-1) p rfl (by omega)]
@[simp]
lemma inl_snd :
(inl φ).comp (snd φ) (add_zero (-1)) = 0 := by
ext p q hpq
simp [Cochain.comp_v _ _ (add_zero (-1)) p q q (by omega) (by omega)]
@[simp]
lemma inr_fst :
(Cochain.ofHom (inr φ)).comp (fst φ).1 (zero_add 1) = 0 := by
ext p q hpq
simp [Cochain.comp_v _ _ (zero_add 1) p p q (by omega) (by omega)]
@[simp]
lemma inr_snd :
(Cochain.ofHom (inr φ)).comp (snd φ) (zero_add 0) = Cochain.ofHom (𝟙 G) := by aesop_cat
/-! In order to obtain identities of cochains involving `inl`, `inr`, `fst` and `snd`,
it is often convenient to use an `ext` lemma, and use simp lemmas like `inl_v_f_fst_v`,
but it is sometimes possible to get identities of cochains by using rewrites of
identities of cochains like `inl_fst`. Then, similarly as in category theory,
if we associate the compositions of cochains to the right as much as possible,
it is also interesting to have `reassoc` variants of lemmas, like `inl_fst_assoc`. -/
@[simp]
lemma inl_fst_assoc {K : CochainComplex C ℤ} {d e : ℤ} (γ : Cochain F K d) (he : 1 + d = e) :
(inl φ).comp ((fst φ).1.comp γ he) (by rw [← he, neg_add_cancel_left]) = γ := by
rw [← Cochain.comp_assoc _ _ _ (neg_add_cancel 1) (by omega) (by omega), inl_fst,
Cochain.id_comp]
@[simp]
lemma inl_snd_assoc {K : CochainComplex C ℤ} {d e f : ℤ} (γ : Cochain G K d)
(he : 0 + d = e) (hf : -1 + e = f) :
(inl φ).comp ((snd φ).comp γ he) hf = 0 := by
obtain rfl : e = d := by omega
rw [← Cochain.comp_assoc_of_second_is_zero_cochain, inl_snd, Cochain.zero_comp]
@[simp]
lemma inr_fst_assoc {K : CochainComplex C ℤ} {d e f : ℤ} (γ : Cochain F K d)
(he : 1 + d = e) (hf : 0 + e = f) :
(Cochain.ofHom (inr φ)).comp ((fst φ).1.comp γ he) hf = 0 := by
obtain rfl : e = f := by omega
rw [← Cochain.comp_assoc_of_first_is_zero_cochain, inr_fst, Cochain.zero_comp]
@[simp]
lemma inr_snd_assoc {K : CochainComplex C ℤ} {d e : ℤ} (γ : Cochain G K d) (he : 0 + d = e) :
(Cochain.ofHom (inr φ)).comp ((snd φ).comp γ he) (by simp only [← he, zero_add]) = γ := by
obtain rfl : d = e := by omega
rw [← Cochain.comp_assoc_of_first_is_zero_cochain, inr_snd, Cochain.id_comp]
lemma ext_to (i j : ℤ) (hij : i + 1 = j) {A : C} {f g : A ⟶ (mappingCone φ).X i}
(h₁ : f ≫ (fst φ).1.v i j hij = g ≫ (fst φ).1.v i j hij)
(h₂ : f ≫ (snd φ).v i i (add_zero i) = g ≫ (snd φ).v i i (add_zero i)) :
f = g :=
homotopyCofiber.ext_to_X φ i j hij h₁ (by simpa [snd] using h₂)
lemma ext_to_iff (i j : ℤ) (hij : i + 1 = j) {A : C} (f g : A ⟶ (mappingCone φ).X i) :
f = g ↔ f ≫ (fst φ).1.v i j hij = g ≫ (fst φ).1.v i j hij ∧
f ≫ (snd φ).v i i (add_zero i) = g ≫ (snd φ).v i i (add_zero i) := by
constructor
· rintro rfl
tauto
· rintro ⟨h₁, h₂⟩
exact ext_to φ i j hij h₁ h₂
lemma ext_from (i j : ℤ) (hij : j + 1 = i) {A : C} {f g : (mappingCone φ).X j ⟶ A}
(h₁ : (inl φ).v i j (by omega) ≫ f = (inl φ).v i j (by omega) ≫ g)
(h₂ : (inr φ).f j ≫ f = (inr φ).f j ≫ g) :
f = g :=
homotopyCofiber.ext_from_X φ i j hij h₁ h₂
lemma ext_from_iff (i j : ℤ) (hij : j + 1 = i) {A : C} (f g : (mappingCone φ).X j ⟶ A) :
f = g ↔ (inl φ).v i j (by omega) ≫ f = (inl φ).v i j (by omega) ≫ g ∧
(inr φ).f j ≫ f = (inr φ).f j ≫ g := by
constructor
· rintro rfl
tauto
· rintro ⟨h₁, h₂⟩
exact ext_from φ i j hij h₁ h₂
lemma decomp_to {i : ℤ} {A : C} (f : A ⟶ (mappingCone φ).X i) (j : ℤ) (hij : i + 1 = j) :
∃ (a : A ⟶ F.X j) (b : A ⟶ G.X i), f = a ≫ (inl φ).v j i (by omega) + b ≫ (inr φ).f i :=
⟨f ≫ (fst φ).1.v i j hij, f ≫ (snd φ).v i i (add_zero i),
by apply ext_to φ i j hij <;> simp⟩
lemma decomp_from {j : ℤ} {A : C} (f : (mappingCone φ).X j ⟶ A) (i : ℤ) (hij : j + 1 = i) :
∃ (a : F.X i ⟶ A) (b : G.X j ⟶ A),
f = (fst φ).1.v j i hij ≫ a + (snd φ).v j j (add_zero j) ≫ b :=
⟨(inl φ).v i j (by omega) ≫ f, (inr φ).f j ≫ f,
by apply ext_from φ i j hij <;> simp⟩
lemma ext_cochain_to_iff (i j : ℤ) (hij : i + 1 = j)
{K : CochainComplex C ℤ} {γ₁ γ₂ : Cochain K (mappingCone φ) i} :
γ₁ = γ₂ ↔ γ₁.comp (fst φ).1 hij = γ₂.comp (fst φ).1 hij ∧
γ₁.comp (snd φ) (add_zero i) = γ₂.comp (snd φ) (add_zero i) := by
constructor
· rintro rfl
tauto
· rintro ⟨h₁, h₂⟩
ext p q hpq
rw [ext_to_iff φ q (q + 1) rfl]
replace h₁ := Cochain.congr_v h₁ p (q + 1) (by omega)
replace h₂ := Cochain.congr_v h₂ p q hpq
simp only [Cochain.comp_v _ _ _ p q (q + 1) hpq rfl] at h₁
simp only [Cochain.comp_zero_cochain_v] at h₂
exact ⟨h₁, h₂⟩
lemma ext_cochain_from_iff (i j : ℤ) (hij : i + 1 = j)
{K : CochainComplex C ℤ} {γ₁ γ₂ : Cochain (mappingCone φ) K j} :
γ₁ = γ₂ ↔
(inl φ).comp γ₁ (show _ = i by omega) = (inl φ).comp γ₂ (by omega) ∧
(Cochain.ofHom (inr φ)).comp γ₁ (zero_add j) =
(Cochain.ofHom (inr φ)).comp γ₂ (zero_add j) := by
constructor
· rintro rfl
tauto
· rintro ⟨h₁, h₂⟩
ext p q hpq
rw [ext_from_iff φ (p + 1) p rfl]
replace h₁ := Cochain.congr_v h₁ (p + 1) q (by omega)
replace h₂ := Cochain.congr_v h₂ p q (by omega)
simp only [Cochain.comp_v (inl φ) _ _ (p + 1) p q (by omega) hpq] at h₁
simp only [Cochain.zero_cochain_comp_v, Cochain.ofHom_v] at h₂
exact ⟨h₁, h₂⟩
lemma id :
(fst φ).1.comp (inl φ) (add_neg_cancel 1) +
(snd φ).comp (Cochain.ofHom (inr φ)) (add_zero 0) = Cochain.ofHom (𝟙 _) := by
| simp [ext_cochain_from_iff φ (-1) 0 (neg_add_cancel 1)]
lemma id_X (p q : ℤ) (hpq : p + 1 = q) :
(fst φ).1.v p q hpq ≫ (inl φ).v q p (by omega) +
(snd φ).v p p (add_zero p) ≫ (inr φ).f p = 𝟙 ((mappingCone φ).X p) := by
simpa only [Cochain.add_v, Cochain.comp_zero_cochain_v, Cochain.ofHom_v, id_f,
| Mathlib/Algebra/Homology/HomotopyCategory/MappingCone.lean | 227 | 232 |
/-
Copyright (c) 2017 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Mario Carneiro
-/
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Algebra.Star.Basic
import Mathlib.Data.Real.Basic
import Mathlib.Order.Interval.Set.UnorderedInterval
import Mathlib.Tactic.Ring
/-!
# The complex numbers
The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field
of characteristic zero. The result that the complex numbers are algebraically closed, see
`FieldTheory.AlgebraicClosure`.
-/
assert_not_exists Multiset Algebra
open Set Function
/-! ### Definition and basic arithmetic -/
/-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/
structure Complex : Type where
/-- The real part of a complex number. -/
re : ℝ
/-- The imaginary part of a complex number. -/
im : ℝ
@[inherit_doc] notation "ℂ" => Complex
namespace Complex
open ComplexConjugate
noncomputable instance : DecidableEq ℂ :=
Classical.decEq _
/-- The equivalence between the complex numbers and `ℝ × ℝ`. -/
@[simps apply]
def equivRealProd : ℂ ≃ ℝ × ℝ where
toFun z := ⟨z.re, z.im⟩
invFun p := ⟨p.1, p.2⟩
left_inv := fun ⟨_, _⟩ => rfl
right_inv := fun ⟨_, _⟩ => rfl
@[simp]
theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z
| ⟨_, _⟩ => rfl
-- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear.
theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w
| ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl
attribute [local ext] Complex.ext
lemma «forall» {p : ℂ → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ := by aesop
lemma «exists» {p : ℂ → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ := by aesop
theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩
theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩
@[simp]
theorem range_re : range re = univ :=
re_surjective.range_eq
@[simp]
theorem range_im : range im = univ :=
im_surjective.range_eq
/-- The natural inclusion of the real numbers into the complex numbers. -/
@[coe]
def ofReal (r : ℝ) : ℂ :=
⟨r, 0⟩
instance : Coe ℝ ℂ :=
⟨ofReal⟩
@[simp, norm_cast]
theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r :=
rfl
@[simp, norm_cast]
theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 :=
rfl
theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ :=
rfl
@[simp, norm_cast]
theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w :=
⟨congrArg re, by apply congrArg⟩
theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re
instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where
prf z hz := ⟨z.re, ext rfl hz.symm⟩
/-- The product of a set on the real axis and a set on the imaginary axis of the complex plane,
denoted by `s ×ℂ t`. -/
def reProdIm (s t : Set ℝ) : Set ℂ :=
re ⁻¹' s ∩ im ⁻¹' t
@[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm
@[inherit_doc]
infixl:72 " ×ℂ " => reProdIm
theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t :=
Iff.rfl
instance : Zero ℂ :=
⟨(0 : ℝ)⟩
instance : Inhabited ℂ :=
⟨0⟩
@[simp]
theorem zero_re : (0 : ℂ).re = 0 :=
rfl
@[simp]
theorem zero_im : (0 : ℂ).im = 0 :=
rfl
@[simp, norm_cast]
theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 :=
rfl
@[simp]
theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 :=
ofReal_inj
theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 :=
not_congr ofReal_eq_zero
instance : One ℂ :=
⟨(1 : ℝ)⟩
@[simp]
theorem one_re : (1 : ℂ).re = 1 :=
rfl
@[simp]
theorem one_im : (1 : ℂ).im = 0 :=
rfl
@[simp, norm_cast]
theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 :=
rfl
@[simp]
theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 :=
ofReal_inj
theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 :=
not_congr ofReal_eq_one
instance : Add ℂ :=
⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩
@[simp]
theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re :=
rfl
@[simp]
theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im :=
rfl
-- replaced by `re_ofNat`
-- replaced by `im_ofNat`
@[simp, norm_cast]
theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s :=
Complex.ext_iff.2 <| by simp [ofReal]
-- replaced by `Complex.ofReal_ofNat`
instance : Neg ℂ :=
⟨fun z => ⟨-z.re, -z.im⟩⟩
@[simp]
theorem neg_re (z : ℂ) : (-z).re = -z.re :=
rfl
@[simp]
theorem neg_im (z : ℂ) : (-z).im = -z.im :=
rfl
@[simp, norm_cast]
theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r :=
Complex.ext_iff.2 <| by simp [ofReal]
instance : Sub ℂ :=
⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩
instance : Mul ℂ :=
⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩
@[simp]
theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im :=
rfl
@[simp]
theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
@[simp, norm_cast]
theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s :=
Complex.ext_iff.2 <| by simp [ofReal]
theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal]
theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by simp [ofReal]
lemma re_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal]
lemma im_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal]
theorem ofReal_mul' (r : ℝ) (z : ℂ) : ↑r * z = ⟨r * z.re, r * z.im⟩ :=
ext (re_ofReal_mul _ _) (im_ofReal_mul _ _)
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
def I : ℂ :=
⟨0, 1⟩
@[simp]
theorem I_re : I.re = 0 :=
rfl
@[simp]
theorem I_im : I.im = 1 :=
rfl
@[simp]
theorem I_mul_I : I * I = -1 :=
Complex.ext_iff.2 <| by simp
theorem I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ :=
Complex.ext_iff.2 <| by simp
@[simp] lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm
theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I :=
Complex.ext_iff.2 <| by simp [ofReal]
@[simp]
theorem re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=
Complex.ext_iff.2 <| by simp [ofReal]
theorem mul_I_re (z : ℂ) : (z * I).re = -z.im := by simp
theorem mul_I_im (z : ℂ) : (z * I).im = z.re := by simp
theorem I_mul_re (z : ℂ) : (I * z).re = -z.im := by simp
theorem I_mul_im (z : ℂ) : (I * z).im = z.re := by simp
@[simp]
theorem equivRealProd_symm_apply (p : ℝ × ℝ) : equivRealProd.symm p = p.1 + p.2 * I := by
ext <;> simp [Complex.equivRealProd, ofReal]
/-- The natural `AddEquiv` from `ℂ` to `ℝ × ℝ`. -/
@[simps! +simpRhs apply symm_apply_re symm_apply_im]
def equivRealProdAddHom : ℂ ≃+ ℝ × ℝ :=
{ equivRealProd with map_add' := by simp }
theorem equivRealProdAddHom_symm_apply (p : ℝ × ℝ) :
equivRealProdAddHom.symm p = p.1 + p.2 * I := equivRealProd_symm_apply p
/-! ### Commutative ring instance and lemmas -/
/- We use a nonstandard formula for the `ℕ` and `ℤ` actions to make sure there is no
diamond from the other actions they inherit through the `ℝ`-action on `ℂ` and action transitivity
defined in `Data.Complex.Module`. -/
instance : Nontrivial ℂ :=
domain_nontrivial re rfl rfl
namespace SMul
-- The useless `0` multiplication in `smul` is to make sure that
-- `RestrictScalars.module ℝ ℂ ℂ = Complex.module` definitionally.
-- instance made scoped to avoid situations like instance synthesis
-- of `SMul ℂ ℂ` trying to proceed via `SMul ℂ ℝ`.
/-- Scalar multiplication by `R` on `ℝ` extends to `ℂ`. This is used here and in
`Matlib.Data.Complex.Module` to transfer instances from `ℝ` to `ℂ`, but is not
needed outside, so we make it scoped. -/
scoped instance instSMulRealComplex {R : Type*} [SMul R ℝ] : SMul R ℂ where
smul r x := ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩
end SMul
open scoped SMul
section SMul
variable {R : Type*} [SMul R ℝ]
theorem smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(· • ·), SMul.smul]
theorem smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(· • ·), SMul.smul]
@[simp]
theorem real_smul {x : ℝ} {z : ℂ} : x • z = x * z :=
rfl
end SMul
instance addCommGroup : AddCommGroup ℂ :=
{ zero := (0 : ℂ)
add := (· + ·)
neg := Neg.neg
sub := Sub.sub
nsmul := fun n z => n • z
zsmul := fun n z => n • z
zsmul_zero' := by intros; ext <;> simp [smul_re, smul_im]
nsmul_zero := by intros; ext <;> simp [smul_re, smul_im]
nsmul_succ := by intros; ext <;> simp [smul_re, smul_im] <;> ring
zsmul_succ' := by intros; ext <;> simp [smul_re, smul_im] <;> ring
zsmul_neg' := by intros; ext <;> simp [smul_re, smul_im] <;> ring
add_assoc := by intros; ext <;> simp <;> ring
zero_add := by intros; ext <;> simp
add_zero := by intros; ext <;> simp
add_comm := by intros; ext <;> simp <;> ring
neg_add_cancel := by intros; ext <;> simp }
instance addGroupWithOne : AddGroupWithOne ℂ :=
{ Complex.addCommGroup with
natCast := fun n => ⟨n, 0⟩
natCast_zero := by
ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_zero]
natCast_succ := fun _ => by ext <;> simp [Nat.cast, AddMonoidWithOne.natCast_succ]
intCast := fun n => ⟨n, 0⟩
intCast_ofNat := fun _ => by ext <;> rfl
intCast_negSucc := fun n => by
ext
· simp [AddGroupWithOne.intCast_negSucc]
show -(1 : ℝ) + (-n) = -(↑(n + 1))
simp [Nat.cast_add, add_comm]
· simp [AddGroupWithOne.intCast_negSucc]
show im ⟨n, 0⟩ = 0
rfl
one := 1 }
instance commRing : CommRing ℂ :=
{ addGroupWithOne with
mul := (· * ·)
npow := @npowRec _ ⟨(1 : ℂ)⟩ ⟨(· * ·)⟩
add_comm := by intros; ext <;> simp <;> ring
left_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring
right_distrib := by intros; ext <;> simp [mul_re, mul_im] <;> ring
zero_mul := by intros; ext <;> simp
mul_zero := by intros; ext <;> simp
mul_assoc := by intros; ext <;> simp <;> ring
one_mul := by intros; ext <;> simp
mul_one := by intros; ext <;> simp
mul_comm := by intros; ext <;> simp <;> ring }
/-- This shortcut instance ensures we do not find `Ring` via the noncomputable `Complex.field`
instance. -/
instance : Ring ℂ := by infer_instance
/-- This shortcut instance ensures we do not find `CommSemiring` via the noncomputable
`Complex.field` instance. -/
instance : CommSemiring ℂ :=
inferInstance
/-- This shortcut instance ensures we do not find `Semiring` via the noncomputable
`Complex.field` instance. -/
instance : Semiring ℂ :=
inferInstance
/-- The "real part" map, considered as an additive group homomorphism. -/
def reAddGroupHom : ℂ →+ ℝ where
toFun := re
map_zero' := zero_re
map_add' := add_re
@[simp]
theorem coe_reAddGroupHom : (reAddGroupHom : ℂ → ℝ) = re :=
rfl
/-- The "imaginary part" map, considered as an additive group homomorphism. -/
def imAddGroupHom : ℂ →+ ℝ where
toFun := im
map_zero' := zero_im
map_add' := add_im
@[simp]
theorem coe_imAddGroupHom : (imAddGroupHom : ℂ → ℝ) = im :=
rfl
/-! ### Cast lemmas -/
instance instNNRatCast : NNRatCast ℂ where nnratCast q := ofReal q
instance instRatCast : RatCast ℂ where ratCast q := ofReal q
@[simp, norm_cast] lemma ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ofReal ofNat(n) = ofNat(n) := rfl
@[simp, norm_cast] lemma ofReal_natCast (n : ℕ) : ofReal n = n := rfl
@[simp, norm_cast] lemma ofReal_intCast (n : ℤ) : ofReal n = n := rfl
@[simp, norm_cast] lemma ofReal_nnratCast (q : ℚ≥0) : ofReal q = q := rfl
@[simp, norm_cast] lemma ofReal_ratCast (q : ℚ) : ofReal q = q := rfl
@[simp]
lemma re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).re = ofNat(n) := rfl
@[simp] lemma im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma natCast_re (n : ℕ) : (n : ℂ).re = n := rfl
@[simp, norm_cast] lemma natCast_im (n : ℕ) : (n : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma intCast_re (n : ℤ) : (n : ℂ).re = n := rfl
@[simp, norm_cast] lemma intCast_im (n : ℤ) : (n : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma re_nnratCast (q : ℚ≥0) : (q : ℂ).re = q := rfl
@[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℂ).im = 0 := rfl
@[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℂ).re = q := rfl
@[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℂ).im = 0 := rfl
lemma re_nsmul (n : ℕ) (z : ℂ) : (n • z).re = n • z.re := smul_re ..
lemma im_nsmul (n : ℕ) (z : ℂ) : (n • z).im = n • z.im := smul_im ..
lemma re_zsmul (n : ℤ) (z : ℂ) : (n • z).re = n • z.re := smul_re ..
lemma im_zsmul (n : ℤ) (z : ℂ) : (n • z).im = n • z.im := smul_im ..
@[simp] lemma re_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).re = q • z.re := smul_re ..
@[simp] lemma im_nnqsmul (q : ℚ≥0) (z : ℂ) : (q • z).im = q • z.im := smul_im ..
@[simp] lemma re_qsmul (q : ℚ) (z : ℂ) : (q • z).re = q • z.re := smul_re ..
@[simp] lemma im_qsmul (q : ℚ) (z : ℂ) : (q • z).im = q • z.im := smul_im ..
@[norm_cast] lemma ofReal_nsmul (n : ℕ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp
@[norm_cast] lemma ofReal_zsmul (n : ℤ) (r : ℝ) : ↑(n • r) = n • (r : ℂ) := by simp
/-! ### Complex conjugation -/
/-- This defines the complex conjugate as the `star` operation of the `StarRing ℂ`. It
is recommended to use the ring endomorphism version `starRingEnd`, available under the
notation `conj` in the locale `ComplexConjugate`. -/
instance : StarRing ℂ where
star z := ⟨z.re, -z.im⟩
star_involutive x := by simp only [eta, neg_neg]
star_mul a b := by ext <;> simp [add_comm] <;> ring
star_add a b := by ext <;> simp [add_comm]
@[simp]
theorem conj_re (z : ℂ) : (conj z).re = z.re :=
rfl
@[simp]
theorem conj_im (z : ℂ) : (conj z).im = -z.im :=
rfl
@[simp]
theorem conj_ofReal (r : ℝ) : conj (r : ℂ) = r :=
Complex.ext_iff.2 <| by simp [star]
@[simp]
theorem conj_I : conj I = -I :=
Complex.ext_iff.2 <| by simp
theorem conj_natCast (n : ℕ) : conj (n : ℂ) = n := map_natCast _ _
theorem conj_ofNat (n : ℕ) [n.AtLeastTwo] : conj (ofNat(n) : ℂ) = ofNat(n) :=
map_ofNat _ _
theorem conj_neg_I : conj (-I) = I := by simp
theorem conj_eq_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=
⟨fun h => ⟨z.re, ext rfl <| eq_zero_of_neg_eq (congr_arg im h)⟩, fun ⟨h, e⟩ => by
rw [e, conj_ofReal]⟩
theorem conj_eq_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=
conj_eq_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp [ofReal], fun h => ⟨_, h.symm⟩⟩
theorem conj_eq_iff_im {z : ℂ} : conj z = z ↔ z.im = 0 :=
⟨fun h => add_self_eq_zero.mp (neg_eq_iff_add_eq_zero.mp (congr_arg im h)), fun h =>
ext rfl (neg_eq_iff_add_eq_zero.mpr (add_self_eq_zero.mpr h))⟩
@[simp]
theorem star_def : (Star.star : ℂ → ℂ) = conj :=
rfl
/-! ### Norm squared -/
/-- The norm squared function. -/
@[pp_nodot]
def normSq : ℂ →*₀ ℝ where
toFun z := z.re * z.re + z.im * z.im
map_zero' := by simp
map_one' := by simp
map_mul' z w := by
dsimp
ring
theorem normSq_apply (z : ℂ) : normSq z = z.re * z.re + z.im * z.im :=
rfl
@[simp]
theorem normSq_ofReal (r : ℝ) : normSq r = r * r := by
simp [normSq, ofReal]
@[simp]
theorem normSq_natCast (n : ℕ) : normSq n = n * n := normSq_ofReal _
@[simp]
theorem normSq_intCast (z : ℤ) : normSq z = z * z := normSq_ofReal _
@[simp]
theorem normSq_ratCast (q : ℚ) : normSq q = q * q := normSq_ofReal _
@[simp]
theorem normSq_ofNat (n : ℕ) [n.AtLeastTwo] :
normSq (ofNat(n) : ℂ) = ofNat(n) * ofNat(n) :=
normSq_natCast _
@[simp]
theorem normSq_mk (x y : ℝ) : normSq ⟨x, y⟩ = x * x + y * y :=
rfl
theorem normSq_add_mul_I (x y : ℝ) : normSq (x + y * I) = x ^ 2 + y ^ 2 := by
rw [← mk_eq_add_mul_I, normSq_mk, sq, sq]
theorem normSq_eq_conj_mul_self {z : ℂ} : (normSq z : ℂ) = conj z * z := by
ext <;> simp [normSq, mul_comm, ofReal]
theorem normSq_zero : normSq 0 = 0 := by simp
theorem normSq_one : normSq 1 = 1 := by simp
@[simp]
theorem normSq_I : normSq I = 1 := by simp [normSq]
theorem normSq_nonneg (z : ℂ) : 0 ≤ normSq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
theorem normSq_eq_zero {z : ℂ} : normSq z = 0 ↔ z = 0 :=
⟨fun h =>
ext (eq_zero_of_mul_self_add_mul_self_eq_zero h)
(eq_zero_of_mul_self_add_mul_self_eq_zero <| (add_comm _ _).trans h),
fun h => h.symm ▸ normSq_zero⟩
@[simp]
theorem normSq_pos {z : ℂ} : 0 < normSq z ↔ z ≠ 0 :=
(normSq_nonneg z).lt_iff_ne.trans <| not_congr (eq_comm.trans normSq_eq_zero)
@[simp]
theorem normSq_neg (z : ℂ) : normSq (-z) = normSq z := by simp [normSq]
@[simp]
theorem normSq_conj (z : ℂ) : normSq (conj z) = normSq z := by simp [normSq]
theorem normSq_mul (z w : ℂ) : normSq (z * w) = normSq z * normSq w :=
normSq.map_mul z w
theorem normSq_add (z w : ℂ) : normSq (z + w) = normSq z + normSq w + 2 * (z * conj w).re := by
dsimp [normSq]; ring
theorem re_sq_le_normSq (z : ℂ) : z.re * z.re ≤ normSq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
theorem im_sq_le_normSq (z : ℂ) : z.im * z.im ≤ normSq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : ℂ) : z * conj z = normSq z :=
Complex.ext_iff.2 <| by simp [normSq, mul_comm, sub_eq_neg_add, add_comm, ofReal]
theorem add_conj (z : ℂ) : z + conj z = (2 * z.re : ℝ) :=
Complex.ext_iff.2 <| by simp [two_mul, ofReal]
/-- The coercion `ℝ → ℂ` as a `RingHom`. -/
def ofRealHom : ℝ →+* ℂ where
toFun x := (x : ℂ)
| map_one' := ofReal_one
map_zero' := ofReal_zero
| Mathlib/Data/Complex/Basic.lean | 577 | 578 |
/-
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.Geometry.Manifold.Algebra.Structures
import Mathlib.Geometry.Manifold.BumpFunction
import Mathlib.Topology.MetricSpace.PartitionOfUnity
import Mathlib.Topology.ShrinkingLemma
/-!
# Smooth partition of unity
In this file we define two structures, `SmoothBumpCovering` and `SmoothPartitionOfUnity`. Both
structures describe coverings of a set by a locally finite family of supports of smooth functions
with some additional properties. The former structure is mostly useful as an intermediate step in
the construction of a smooth partition of unity but some proofs that traditionally deal with a
partition of unity can use a `SmoothBumpCovering` as well.
Given a real manifold `M` and its subset `s`, a `SmoothBumpCovering ι I M s` is a collection of
`SmoothBumpFunction`s `f i` indexed by `i : ι` such that
* the center of each `f i` belongs to `s`;
* the family of sets `support (f i)` is locally finite;
* for each `x ∈ s`, there exists `i : ι` such that `f i =ᶠ[𝓝 x] 1`.
In the same settings, a `SmoothPartitionOfUnity ι I M s` is a collection of smooth nonnegative
functions `f i : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯`, `i : ι`, such that
* the family of sets `support (f i)` is locally finite;
* for each `x ∈ s`, the sum `∑ᶠ i, f i x` equals one;
* for each `x`, the sum `∑ᶠ i, f i x` is less than or equal to one.
We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each
index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than
being subordinate to an open covering of `M`, because we make no assumption about the way `U x`
depends on `x`.
We prove that on a smooth finitely dimensional real manifold with `σ`-compact Hausdorff topology,
for any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s`
subordinate to `U`. Then we use this fact to prove a similar statement about smooth partitions of
unity, see `SmoothPartitionOfUnity.exists_isSubordinate`.
Finally, we use existence of a partition of unity to prove lemma
`exists_smooth_forall_mem_convex_of_local` that allows us to construct a globally defined smooth
function from local functions.
## TODO
* Build a framework for to transfer local definitions to global using partition of unity and use it
to define, e.g., the integral of a differential form over a manifold. Lemma
`exists_smooth_forall_mem_convex_of_local` is a first step in this direction.
## Tags
smooth bump function, partition of unity
-/
universe uι uE uH uM uF
open Function Filter Module Set
open scoped Topology Manifold ContDiff
noncomputable section
variable {ι : Type uι} {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E]
{F : Type uF} [NormedAddCommGroup F] [NormedSpace ℝ F] {H : Type uH}
[TopologicalSpace H] (I : ModelWithCorners ℝ E H) {M : Type uM} [TopologicalSpace M]
[ChartedSpace H M]
/-!
### Covering by supports of smooth bump functions
In this section we define `SmoothBumpCovering ι I M s` to be a collection of
`SmoothBumpFunction`s such that their supports is a locally finite family of sets and for each
`x ∈ s` some function `f i` from the collection is equal to `1` in a neighborhood of `x`. A covering
of this type is useful to construct a smooth partition of unity and can be used instead of a
partition of unity in some proofs.
We prove that on a smooth finite dimensional real manifold with `σ`-compact Hausdorff topology, for
any `U : M → Set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `SmoothBumpCovering ι I M s`
subordinate to `U`. -/
variable (ι M)
/-- We say that a collection of `SmoothBumpFunction`s is a `SmoothBumpCovering` of a set `s` if
* `(f i).c ∈ s` for all `i`;
* the family `fun i ↦ support (f i)` is locally finite;
* for each point `x ∈ s` there exists `i` such that `f i =ᶠ[𝓝 x] 1`;
in other words, `x` belongs to the interior of `{y | f i y = 1}`;
If `M` is a finite dimensional real manifold which is a `σ`-compact Hausdorff topological space,
then for every covering `U : M → Set M`, `∀ x, U x ∈ 𝓝 x`, there exists a `SmoothBumpCovering`
subordinate to `U`, see `SmoothBumpCovering.exists_isSubordinate`.
This covering can be used, e.g., to construct a partition of unity and to prove the weak
Whitney embedding theorem. -/
structure SmoothBumpCovering [FiniteDimensional ℝ E] (s : Set M := univ) where
/-- The center point of each bump in the smooth covering. -/
c : ι → M
/-- A smooth bump function around `c i`. -/
toFun : ∀ i, SmoothBumpFunction I (c i)
/-- All the bump functions in the covering are centered at points in `s`. -/
c_mem' : ∀ i, c i ∈ s
/-- Around each point, there are only finitely many nonzero bump functions in the family. -/
locallyFinite' : LocallyFinite fun i => support (toFun i)
/-- Around each point in `s`, one of the bump functions is equal to `1`. -/
eventuallyEq_one' : ∀ x ∈ s, ∃ i, toFun i =ᶠ[𝓝 x] 1
/-- We say that a collection of functions form a smooth partition of unity on a set `s` if
* all functions are infinitely smooth and nonnegative;
* the family `fun i ↦ support (f i)` is locally finite;
* for all `x ∈ s` the sum `∑ᶠ i, f i x` equals one;
* for all `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. -/
structure SmoothPartitionOfUnity (s : Set M := univ) where
/-- The family of functions forming the partition of unity. -/
toFun : ι → C^∞⟮I, M; 𝓘(ℝ), ℝ⟯
/-- Around each point, there are only finitely many nonzero functions in the family. -/
locallyFinite' : LocallyFinite fun i => support (toFun i)
/-- All the functions in the partition of unity are nonnegative. -/
nonneg' : ∀ i x, 0 ≤ toFun i x
/-- The functions in the partition of unity add up to `1` at any point of `s`. -/
sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, toFun i x = 1
/-- The functions in the partition of unity add up to at most `1` everywhere. -/
sum_le_one' : ∀ x, ∑ᶠ i, toFun i x ≤ 1
variable {ι I M}
namespace SmoothPartitionOfUnity
variable {s : Set M} (f : SmoothPartitionOfUnity ι I M s) {n : ℕ∞}
instance {s : Set M} : FunLike (SmoothPartitionOfUnity ι I M s) ι C^∞⟮I, M; 𝓘(ℝ), ℝ⟯ where
coe := toFun
coe_injective' f g h := by cases f; cases g; congr
protected theorem locallyFinite : LocallyFinite fun i => support (f i) :=
f.locallyFinite'
theorem nonneg (i : ι) (x : M) : 0 ≤ f i x :=
f.nonneg' i x
theorem sum_eq_one {x} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 :=
f.sum_eq_one' x hx
theorem exists_pos_of_mem {x} (hx : x ∈ s) : ∃ i, 0 < f i x := by
by_contra! h
have H : ∀ i, f i x = 0 := fun i ↦ le_antisymm (h i) (f.nonneg i x)
have := f.sum_eq_one hx
simp_rw [H] at this
simpa
theorem sum_le_one (x : M) : ∑ᶠ i, f i x ≤ 1 :=
f.sum_le_one' x
/-- Reinterpret a smooth partition of unity as a continuous partition of unity. -/
@[simps]
def toPartitionOfUnity : PartitionOfUnity ι M s :=
{ f with toFun := fun i => f i }
theorem contMDiff_sum : ContMDiff I 𝓘(ℝ) ∞ fun x => ∑ᶠ i, f i x :=
contMDiff_finsum (fun i => (f i).contMDiff) f.locallyFinite
@[deprecated (since := "2024-11-21")] alias smooth_sum := contMDiff_sum
theorem le_one (i : ι) (x : M) : f i x ≤ 1 :=
f.toPartitionOfUnity.le_one i x
theorem sum_nonneg (x : M) : 0 ≤ ∑ᶠ i, f i x :=
f.toPartitionOfUnity.sum_nonneg x
theorem finsum_smul_mem_convex {g : ι → M → F} {t : Set F} {x : M} (hx : x ∈ s)
(hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : Convex ℝ t) : ∑ᶠ i, f i x • g i x ∈ t :=
ht.finsum_mem (fun _ => f.nonneg _ _) (f.sum_eq_one hx) hg
theorem contMDiff_smul {g : M → F} {i} (hg : ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n g x) :
ContMDiff I 𝓘(ℝ, F) n fun x => f i x • g x :=
contMDiff_of_tsupport fun x hx =>
((f i).contMDiff.contMDiffAt.of_le (mod_cast le_top)).smul <| hg x
<| tsupport_smul_subset_left _ _ hx
@[deprecated (since := "2024-11-21")] alias smooth_smul := contMDiff_smul
/-- If `f` is a smooth partition of unity on a set `s : Set M` and `g : ι → M → F` is a family of
functions such that `g i` is $C^n$ smooth at every point of the topological support of `f i`, then
the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/
theorem contMDiff_finsum_smul {g : ι → M → F}
(hg : ∀ (i), ∀ x ∈ tsupport (f i), ContMDiffAt I 𝓘(ℝ, F) n (g i) x) :
ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x :=
(contMDiff_finsum fun i => f.contMDiff_smul (hg i)) <|
f.locallyFinite.subset fun _ => support_smul_subset_left _ _
@[deprecated (since := "2024-11-21")] alias smooth_finsum_smul := contMDiff_finsum_smul
theorem contMDiffAt_finsum {x₀ : M} {g : ι → M → F}
(hφ : ∀ i, x₀ ∈ tsupport (f i) → ContMDiffAt I 𝓘(ℝ, F) n (g i) x₀) :
ContMDiffAt I 𝓘(ℝ, F) n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by
refine _root_.contMDiffAt_finsum (f.locallyFinite.smul_left _) fun i ↦ ?_
by_cases hx : x₀ ∈ tsupport (f i)
· exact ContMDiffAt.smul ((f i).contMDiff.of_le (mod_cast le_top)).contMDiffAt (hφ i hx)
· exact contMDiffAt_of_not_mem (compl_subset_compl.mpr
(tsupport_smul_subset_left (f i) (g i)) hx) n
theorem contDiffAt_finsum {s : Set E} (f : SmoothPartitionOfUnity ι 𝓘(ℝ, E) E s) {x₀ : E}
{g : ι → E → F} (hφ : ∀ i, x₀ ∈ tsupport (f i) → ContDiffAt ℝ n (g i) x₀) :
ContDiffAt ℝ n (fun x ↦ ∑ᶠ i, f i x • g i x) x₀ := by
simp only [← contMDiffAt_iff_contDiffAt] at *
exact f.contMDiffAt_finsum hφ
section finsupport
variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M)
/-- The support of a smooth partition of unity at a point `x₀` as a `Finset`.
This is the set of `i : ι` such that `x₀ ∈ support f i`, i.e. `f i ≠ x₀`. -/
def finsupport : Finset ι := ρ.toPartitionOfUnity.finsupport x₀
@[simp]
theorem mem_finsupport {i : ι} : i ∈ ρ.finsupport x₀ ↔ i ∈ support fun i ↦ ρ i x₀ :=
ρ.toPartitionOfUnity.mem_finsupport x₀
@[simp]
theorem coe_finsupport : (ρ.finsupport x₀ : Set ι) = support fun i ↦ ρ i x₀ :=
ρ.toPartitionOfUnity.coe_finsupport x₀
theorem sum_finsupport (hx₀ : x₀ ∈ s) : ∑ i ∈ ρ.finsupport x₀, ρ i x₀ = 1 :=
ρ.toPartitionOfUnity.sum_finsupport hx₀
theorem sum_finsupport' (hx₀ : x₀ ∈ s) {I : Finset ι} (hI : ρ.finsupport x₀ ⊆ I) :
∑ i ∈ I, ρ i x₀ = 1 :=
ρ.toPartitionOfUnity.sum_finsupport' hx₀ hI
theorem sum_finsupport_smul_eq_finsum {A : Type*} [AddCommGroup A] [Module ℝ A] (φ : ι → M → A) :
∑ i ∈ ρ.finsupport x₀, ρ i x₀ • φ i x₀ = ∑ᶠ i, ρ i x₀ • φ i x₀ :=
ρ.toPartitionOfUnity.sum_finsupport_smul_eq_finsum φ
end finsupport
section fintsupport -- smooth partitions of unity have locally finite `tsupport`
variable {s : Set M} (ρ : SmoothPartitionOfUnity ι I M s) (x₀ : M)
/-- The `tsupport`s of a smooth partition of unity are locally finite. -/
theorem finite_tsupport : {i | x₀ ∈ tsupport (ρ i)}.Finite :=
ρ.toPartitionOfUnity.finite_tsupport _
/-- The tsupport of a partition of unity at a point `x₀` as a `Finset`.
This is the set of `i : ι` such that `x₀ ∈ tsupport f i`. -/
def fintsupport (x : M) : Finset ι :=
(ρ.finite_tsupport x).toFinset
theorem mem_fintsupport_iff (i : ι) : i ∈ ρ.fintsupport x₀ ↔ x₀ ∈ tsupport (ρ i) :=
Finite.mem_toFinset _
theorem eventually_fintsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.fintsupport y ⊆ ρ.fintsupport x₀ :=
ρ.toPartitionOfUnity.eventually_fintsupport_subset _
theorem finsupport_subset_fintsupport : ρ.finsupport x₀ ⊆ ρ.fintsupport x₀ :=
ρ.toPartitionOfUnity.finsupport_subset_fintsupport x₀
theorem eventually_finsupport_subset : ∀ᶠ y in 𝓝 x₀, ρ.finsupport y ⊆ ρ.fintsupport x₀ :=
ρ.toPartitionOfUnity.eventually_finsupport_subset x₀
end fintsupport
section IsSubordinate
/-- A smooth partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same
type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/
def IsSubordinate (f : SmoothPartitionOfUnity ι I M s) (U : ι → Set M) :=
∀ i, tsupport (f i) ⊆ U i
variable {f}
variable {U : ι → Set M}
@[simp]
theorem isSubordinate_toPartitionOfUnity :
f.toPartitionOfUnity.IsSubordinate U ↔ f.IsSubordinate U :=
Iff.rfl
alias ⟨_, IsSubordinate.toPartitionOfUnity⟩ := isSubordinate_toPartitionOfUnity
/-- If `f` is a smooth partition of unity on a set `s : Set M` subordinate to a family of open sets
`U : ι → Set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth on
`U i`, then the sum `fun x ↦ ∑ᶠ i, f i x • g i x` is $C^n$ smooth on the whole manifold. -/
theorem IsSubordinate.contMDiff_finsum_smul {g : ι → M → F} (hf : f.IsSubordinate U)
(ho : ∀ i, IsOpen (U i)) (hg : ∀ i, ContMDiffOn I 𝓘(ℝ, F) n (g i) (U i)) :
ContMDiff I 𝓘(ℝ, F) n fun x => ∑ᶠ i, f i x • g i x :=
f.contMDiff_finsum_smul fun i _ hx => (hg i).contMDiffAt <| (ho i).mem_nhds (hf i hx)
@[deprecated (since := "2024-11-21")]
alias IsSubordinate.smooth_finsum_smul := IsSubordinate.contMDiff_finsum_smul
end IsSubordinate
end SmoothPartitionOfUnity
namespace BumpCovering
-- Repeat variables to drop `[FiniteDimensional ℝ E]` and `[IsManifold I ∞ M]`
theorem contMDiff_toPartitionOfUnity {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E]
{H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM}
[TopologicalSpace M] [ChartedSpace H M] {s : Set M} (f : BumpCovering ι M s)
(hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) (i : ι) : ContMDiff I 𝓘(ℝ) ∞ (f.toPartitionOfUnity i) :=
(hf i).mul <| (contMDiff_finprod_cond fun j _ => contMDiff_const.sub (hf j)) <| by
simp only [Pi.sub_def, mulSupport_one_sub]
exact f.locallyFinite
@[deprecated (since := "2024-11-21")]
alias smooth_toPartitionOfUnity := contMDiff_toPartitionOfUnity
variable {s : Set M}
/-- A `BumpCovering` such that all functions in this covering are smooth generates a smooth
partition of unity.
In our formalization, not every `f : BumpCovering ι M s` with smooth functions `f i` is a
`SmoothBumpCovering`; instead, a `SmoothBumpCovering` is a covering by supports of
`SmoothBumpFunction`s. So, we define `BumpCovering.toSmoothPartitionOfUnity`, then reuse it
in `SmoothBumpCovering.toSmoothPartitionOfUnity`. -/
def toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) :
SmoothPartitionOfUnity ι I M s :=
{ f.toPartitionOfUnity with
toFun := fun i => ⟨f.toPartitionOfUnity i, f.contMDiff_toPartitionOfUnity hf i⟩ }
@[simp]
theorem toSmoothPartitionOfUnity_toPartitionOfUnity (f : BumpCovering ι M s)
(hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) :
(f.toSmoothPartitionOfUnity hf).toPartitionOfUnity = f.toPartitionOfUnity :=
rfl
@[simp]
theorem coe_toSmoothPartitionOfUnity (f : BumpCovering ι M s) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i))
(i : ι) : ⇑(f.toSmoothPartitionOfUnity hf i) = f.toPartitionOfUnity i :=
rfl
theorem IsSubordinate.toSmoothPartitionOfUnity {f : BumpCovering ι M s} {U : ι → Set M}
(h : f.IsSubordinate U) (hf : ∀ i, ContMDiff I 𝓘(ℝ) ∞ (f i)) :
(f.toSmoothPartitionOfUnity hf).IsSubordinate U :=
h.toPartitionOfUnity
end BumpCovering
namespace SmoothBumpCovering
variable [FiniteDimensional ℝ E]
variable {s : Set M} {U : M → Set M} (fs : SmoothBumpCovering ι I M s)
instance : CoeFun (SmoothBumpCovering ι I M s) fun x => ∀ i : ι, SmoothBumpFunction I (x.c i) :=
⟨toFun⟩
/--
We say that `f : SmoothBumpCovering ι I M s` is *subordinate* to a map `U : M → Set M` if for each
index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than
being subordinate to an open covering of `M`, because we make no assumption about the way `U x`
depends on `x`.
-/
def IsSubordinate {s : Set M} (f : SmoothBumpCovering ι I M s) (U : M → Set M) :=
∀ i, tsupport (f i) ⊆ U (f.c i)
theorem IsSubordinate.support_subset {fs : SmoothBumpCovering ι I M s} {U : M → Set M}
(h : fs.IsSubordinate U) (i : ι) : support (fs i) ⊆ U (fs.c i) :=
Subset.trans subset_closure (h i)
variable (I) in
/-- Let `M` be a smooth manifold modelled on a finite dimensional real vector space.
Suppose also that `M` is a Hausdorff `σ`-compact topological space. Let `s` be a closed set
in `M` and `U : M → Set M` be a collection of sets such that `U x ∈ 𝓝 x` for every `x ∈ s`.
Then there exists a smooth bump covering of `s` that is subordinate to `U`. -/
theorem exists_isSubordinate [T2Space M] [SigmaCompactSpace M] (hs : IsClosed s)
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ (ι : Type uM) (f : SmoothBumpCovering ι I M s), f.IsSubordinate U := by
-- First we deduce some missing instances
haveI : LocallyCompactSpace H := I.locallyCompactSpace
haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M
-- Next we choose a covering by supports of smooth bump functions
have hB := fun x hx => SmoothBumpFunction.nhds_basis_support (I := I) (hU x hx)
rcases refinement_of_locallyCompact_sigmaCompact_of_nhds_basis_set hs hB with
⟨ι, c, f, hf, hsub', hfin⟩
choose hcs hfU using hf
-- Then we use the shrinking lemma to get a covering by smaller open
rcases exists_subset_iUnion_closed_subset hs (fun i => (f i).isOpen_support)
(fun x _ => hfin.point_finite x) hsub' with ⟨V, hsV, hVc, hVf⟩
choose r hrR hr using fun i => (f i).exists_r_pos_lt_subset_ball (hVc i) (hVf i)
refine ⟨ι, ⟨c, fun i => (f i).updateRIn (r i) (hrR i), hcs, ?_, fun x hx => ?_⟩, fun i => ?_⟩
· simpa only [SmoothBumpFunction.support_updateRIn]
· refine (mem_iUnion.1 <| hsV hx).imp fun i hi => ?_
exact ((f i).updateRIn _ _).eventuallyEq_one_of_dist_lt
((f i).support_subset_source <| hVf _ hi) (hr i hi).2
· simpa only [SmoothBumpFunction.support_updateRIn, tsupport] using hfU i
protected theorem locallyFinite : LocallyFinite fun i => support (fs i) :=
fs.locallyFinite'
protected theorem point_finite (x : M) : {i | fs i x ≠ 0}.Finite :=
fs.locallyFinite.point_finite x
/-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/
def ind (x : M) (hx : x ∈ s) : ι :=
(fs.eventuallyEq_one' x hx).choose
theorem eventuallyEq_one (x : M) (hx : x ∈ s) : fs (fs.ind x hx) =ᶠ[𝓝 x] 1 :=
(fs.eventuallyEq_one' x hx).choose_spec
theorem apply_ind (x : M) (hx : x ∈ s) : fs (fs.ind x hx) x = 1 :=
(fs.eventuallyEq_one x hx).eq_of_nhds
theorem mem_support_ind (x : M) (hx : x ∈ s) : x ∈ support (fs <| fs.ind x hx) := by
simp [fs.apply_ind x hx]
theorem mem_chartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) :
x ∈ (chartAt H (fs.c i)).source :=
(fs i).support_subset_source <| by simp [h]
theorem mem_extChartAt_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) :
x ∈ (extChartAt I (fs.c i)).source := by
rw [extChartAt_source]; exact fs.mem_chartAt_source_of_eq_one h
theorem mem_chartAt_ind_source (x : M) (hx : x ∈ s) : x ∈ (chartAt H (fs.c (fs.ind x hx))).source :=
fs.mem_chartAt_source_of_eq_one (fs.apply_ind x hx)
theorem mem_extChartAt_ind_source (x : M) (hx : x ∈ s) :
x ∈ (extChartAt I (fs.c (fs.ind x hx))).source :=
fs.mem_extChartAt_source_of_eq_one (fs.apply_ind x hx)
/-- The index type of a `SmoothBumpCovering` of a compact manifold is finite. -/
protected def fintype [CompactSpace M] : Fintype ι :=
fs.locallyFinite.fintypeOfCompact fun i => (fs i).nonempty_support
variable [T2Space M]
variable [IsManifold I ∞ M]
/-- Reinterpret a `SmoothBumpCovering` as a continuous `BumpCovering`. Note that not every
`f : BumpCovering ι M s` with smooth functions `f i` is a `SmoothBumpCovering`. -/
def toBumpCovering : BumpCovering ι M s where
toFun i := ⟨fs i, (fs i).continuous⟩
locallyFinite' := fs.locallyFinite
nonneg' i _ := (fs i).nonneg
le_one' i _ := (fs i).le_one
eventuallyEq_one' := fs.eventuallyEq_one'
@[simp]
theorem isSubordinate_toBumpCovering {f : SmoothBumpCovering ι I M s} {U : M → Set M} :
(f.toBumpCovering.IsSubordinate fun i => U (f.c i)) ↔ f.IsSubordinate U :=
Iff.rfl
alias ⟨_, IsSubordinate.toBumpCovering⟩ := isSubordinate_toBumpCovering
/-- Every `SmoothBumpCovering` defines a smooth partition of unity. -/
def toSmoothPartitionOfUnity : SmoothPartitionOfUnity ι I M s :=
fs.toBumpCovering.toSmoothPartitionOfUnity fun i => (fs i).contMDiff
theorem toSmoothPartitionOfUnity_apply (i : ι) (x : M) :
fs.toSmoothPartitionOfUnity i x = fs i x * ∏ᶠ (j) (_ : WellOrderingRel j i), (1 - fs j x) :=
rfl
open Classical in
theorem toSmoothPartitionOfUnity_eq_mul_prod (i : ι) (x : M) (t : Finset ι)
(ht : ∀ j, WellOrderingRel j i → fs j x ≠ 0 → j ∈ t) :
fs.toSmoothPartitionOfUnity i x = fs i x * ∏ j ∈ t with WellOrderingRel j i, (1 - fs j x) :=
fs.toBumpCovering.toPartitionOfUnity_eq_mul_prod i x t ht
open Classical in
theorem exists_finset_toSmoothPartitionOfUnity_eventuallyEq (i : ι) (x : M) :
∃ t : Finset ι,
fs.toSmoothPartitionOfUnity i =ᶠ[𝓝 x]
fs i * ∏ j ∈ t with WellOrderingRel j i, ((1 : M → ℝ) - fs j) := by
-- Porting note: was defeq, now the continuous lemma uses bundled homs
simpa using fs.toBumpCovering.exists_finset_toPartitionOfUnity_eventuallyEq i x
theorem toSmoothPartitionOfUnity_zero_of_zero {i : ι} {x : M} (h : fs i x = 0) :
fs.toSmoothPartitionOfUnity i x = 0 :=
fs.toBumpCovering.toPartitionOfUnity_zero_of_zero h
theorem support_toSmoothPartitionOfUnity_subset (i : ι) :
support (fs.toSmoothPartitionOfUnity i) ⊆ support (fs i) :=
fs.toBumpCovering.support_toPartitionOfUnity_subset i
theorem IsSubordinate.toSmoothPartitionOfUnity {f : SmoothBumpCovering ι I M s} {U : M → Set M}
(h : f.IsSubordinate U) : f.toSmoothPartitionOfUnity.IsSubordinate fun i => U (f.c i) :=
h.toBumpCovering.toPartitionOfUnity
theorem sum_toSmoothPartitionOfUnity_eq (x : M) :
∑ᶠ i, fs.toSmoothPartitionOfUnity i x = 1 - ∏ᶠ i, (1 - fs i x) :=
fs.toBumpCovering.sum_toPartitionOfUnity_eq x
end SmoothBumpCovering
variable (I)
variable [FiniteDimensional ℝ E]
variable [IsManifold I ∞ M]
/-- Given two disjoint closed sets `s, t` in a Hausdorff σ-compact finite dimensional manifold,
there exists an infinitely smooth function that is equal to `0` on `s` and to `1` on `t`.
See also `exists_msmooth_zero_iff_one_iff_of_isClosed`, which ensures additionally that
`f` is equal to `0` exactly on `s` and to `1` exactly on `t`. -/
theorem exists_smooth_zero_one_of_isClosed [T2Space M] [SigmaCompactSpace M] {s t : Set M}
(hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) :
∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, EqOn f 0 s ∧ EqOn f 1 t ∧ ∀ x, f x ∈ Icc 0 1 := by
have : ∀ x ∈ t, sᶜ ∈ 𝓝 x := fun x hx => hs.isOpen_compl.mem_nhds (disjoint_right.1 hd hx)
rcases SmoothBumpCovering.exists_isSubordinate I ht this with ⟨ι, f, hf⟩
set g := f.toSmoothPartitionOfUnity
refine
⟨⟨_, g.contMDiff_sum⟩, fun x hx => ?_, fun x => g.sum_eq_one, fun x =>
⟨g.sum_nonneg x, g.sum_le_one x⟩⟩
suffices ∀ i, g i x = 0 by simp only [this, ContMDiffMap.coeFn_mk, finsum_zero, Pi.zero_apply]
refine fun i => f.toSmoothPartitionOfUnity_zero_of_zero ?_
exact nmem_support.1 (subset_compl_comm.1 (hf.support_subset i) hx)
/-- Given two disjoint closed sets `s, t` in a Hausdorff normal σ-compact finite dimensional
manifold `M`, there exists a smooth function `f : M → [0,1]` that vanishes in a neighbourhood of `s`
and is equal to `1` in a neighbourhood of `t`. -/
theorem exists_smooth_zero_one_nhds_of_isClosed [T2Space M] [NormalSpace M] [SigmaCompactSpace M]
{s t : Set M} (hs : IsClosed s) (ht : IsClosed t) (hd : Disjoint s t) :
∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 0) ∧ (∀ᶠ x in 𝓝ˢ t, f x = 1) ∧
∀ x, f x ∈ Icc 0 1 := by
obtain ⟨u, u_op, hsu, hut⟩ := normal_exists_closure_subset hs ht.isOpen_compl
(subset_compl_iff_disjoint_left.mpr hd.symm)
obtain ⟨v, v_op, htv, hvu⟩ := normal_exists_closure_subset ht isClosed_closure.isOpen_compl
(subset_compl_comm.mp hut)
obtain ⟨f, hfu, hfv, hf⟩ := exists_smooth_zero_one_of_isClosed I isClosed_closure isClosed_closure
(subset_compl_iff_disjoint_left.mp hvu)
refine ⟨f, ?_, ?_, hf⟩
· exact eventually_of_mem (mem_of_superset (u_op.mem_nhdsSet.mpr hsu) subset_closure) hfu
· exact eventually_of_mem (mem_of_superset (v_op.mem_nhdsSet.mpr htv) subset_closure) hfv
/-- Given two sets `s, t` in a Hausdorff normal σ-compact finite-dimensional manifold `M`
with `s` open and `s ⊆ interior t`, there is a smooth function `f : M → [0,1]` which is equal to `s`
in a neighbourhood of `s` and has support contained in `t`. -/
theorem exists_smooth_one_nhds_of_subset_interior [T2Space M] [NormalSpace M] [SigmaCompactSpace M]
{s t : Set M} (hs : IsClosed s) (hd : s ⊆ interior t) :
∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, (∀ᶠ x in 𝓝ˢ s, f x = 1) ∧ (∀ x ∉ t, f x = 0) ∧
∀ x, f x ∈ Icc 0 1 := by
rcases exists_smooth_zero_one_nhds_of_isClosed I isOpen_interior.isClosed_compl hs
(by rwa [← subset_compl_iff_disjoint_left, compl_compl]) with ⟨f, h0, h1, hf⟩
refine ⟨f, h1, fun x hx ↦ ?_, hf⟩
exact h0.self_of_nhdsSet _ fun hx' ↦ hx <| interior_subset hx'
namespace SmoothPartitionOfUnity
/-- A `SmoothPartitionOfUnity` that consists of a single function, uniformly equal to one,
defined as an example for `Inhabited` instance. -/
def single (i : ι) (s : Set M) : SmoothPartitionOfUnity ι I M s :=
(BumpCovering.single i s).toSmoothPartitionOfUnity fun j => by
classical
rcases eq_or_ne j i with (rfl | h)
· simp only [contMDiff_one, ContinuousMap.coe_one, BumpCovering.coe_single, Pi.single_eq_same]
· simp only [contMDiff_zero, BumpCovering.coe_single, Pi.single_eq_of_ne h,
ContinuousMap.coe_zero]
instance [Inhabited ι] (s : Set M) : Inhabited (SmoothPartitionOfUnity ι I M s) :=
⟨single I default s⟩
variable [T2Space M] [SigmaCompactSpace M]
/-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set
`s`, then there exists a `SmoothPartitionOfUnity ι M s` that is subordinate to `U`. -/
theorem exists_isSubordinate {s : Set M} (hs : IsClosed s) (U : ι → Set M) (ho : ∀ i, IsOpen (U i))
(hU : s ⊆ ⋃ i, U i) : ∃ f : SmoothPartitionOfUnity ι I M s, f.IsSubordinate U := by
haveI : LocallyCompactSpace H := I.locallyCompactSpace
haveI : LocallyCompactSpace M := ChartedSpace.locallyCompactSpace H M
-- porting note(https://github.com/leanprover/std4/issues/116):
-- split `rcases` into `have` + `rcases`
have := BumpCovering.exists_isSubordinate_of_prop (ContMDiff I 𝓘(ℝ) ∞) ?_ hs U ho hU
· rcases this with ⟨f, hf, hfU⟩
exact ⟨f.toSmoothPartitionOfUnity hf, hfU.toSmoothPartitionOfUnity hf⟩
· intro s t hs ht hd
rcases exists_smooth_zero_one_of_isClosed I hs ht hd with ⟨f, hf⟩
exact ⟨f, f.contMDiff, hf⟩
theorem exists_isSubordinate_chartAt_source_of_isClosed {s : Set M} (hs : IsClosed s) :
∃ f : SmoothPartitionOfUnity s I M s,
f.IsSubordinate (fun x ↦ (chartAt H (x : M)).source) := by
apply exists_isSubordinate _ hs _ (fun i ↦ (chartAt H _).open_source) (fun x hx ↦ ?_)
exact mem_iUnion_of_mem ⟨x, hx⟩ (mem_chart_source H x)
variable (M)
theorem exists_isSubordinate_chartAt_source :
∃ f : SmoothPartitionOfUnity M I M univ, f.IsSubordinate (fun x ↦ (chartAt H x).source) := by
apply exists_isSubordinate _ isClosed_univ _ (fun i ↦ (chartAt H _).open_source) (fun x _ ↦ ?_)
exact mem_iUnion_of_mem x (mem_chart_source H x)
end SmoothPartitionOfUnity
variable [SigmaCompactSpace M] [T2Space M] {t : M → Set F} {n : ℕ∞}
/-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F`
be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood
`U ∈ 𝓝 x` and a function `g : M → F` such that `g` is $C^n$ smooth on `U` and `g y ∈ t y` for all
`y ∈ U`. Then there exists a $C^n$ smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x`
for all `x`. See also `exists_smooth_forall_mem_convex_of_local` and
`exists_smooth_forall_mem_convex_of_local_const`. -/
theorem exists_contMDiffOn_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x))
(Hloc : ∀ x : M, ∃ U ∈ 𝓝 x, ∃ g : M → F, ContMDiffOn I 𝓘(ℝ, F) n g U ∧ ∀ y ∈ U, g y ∈ t y) :
∃ g : C^n⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x := by
choose U hU g hgs hgt using Hloc
obtain ⟨f, hf⟩ :=
SmoothPartitionOfUnity.exists_isSubordinate I isClosed_univ (fun x => interior (U x))
(fun x => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩
refine ⟨⟨fun x => ∑ᶠ i, f i x • g i x,
hf.contMDiff_finsum_smul (fun i => isOpen_interior) fun i => (hgs i).mono interior_subset⟩,
fun x => f.finsum_smul_mem_convex (mem_univ x) (fun i hi => hgt _ _ ?_) (ht _)⟩
exact interior_subset (hf _ <| subset_closure hi)
/-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F`
be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood
`U ∈ 𝓝 x` and a function `g : M → F` such that `g` is smooth on `U` and `g y ∈ t y` for all `y ∈ U`.
Then there exists a smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`.
See also `exists_contMDiffOn_forall_mem_convex_of_local` and
`exists_smooth_forall_mem_convex_of_local_const`. -/
theorem exists_smooth_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x))
(Hloc : ∀ x : M, ∃ U ∈ 𝓝 x, ∃ g : M → F, ContMDiffOn I 𝓘(ℝ, F) ∞ g U ∧ ∀ y ∈ U, g y ∈ t y) :
∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x :=
exists_contMDiffOn_forall_mem_convex_of_local I ht Hloc
/-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → Set F` be
a family of convex sets. Suppose that for each point `x : M` there exists a vector `c : F` such that
for all `y` in a neighborhood of `x` we have `c ∈ t y`. Then there exists a smooth function
`g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. See also
`exists_contMDiffOn_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local`. -/
theorem exists_smooth_forall_mem_convex_of_local_const (ht : ∀ x, Convex ℝ (t x))
(Hloc : ∀ x : M, ∃ c : F, ∀ᶠ y in 𝓝 x, c ∈ t y) : ∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x :=
exists_smooth_forall_mem_convex_of_local I ht fun x =>
let ⟨c, hc⟩ := Hloc x
⟨_, hc, fun _ => c, contMDiffOn_const, fun _ => id⟩
/-- Let `M` be a smooth σ-compact manifold with extended distance. Let `K : ι → Set M` be a locally
finite family of closed sets, let `U : ι → Set M` be a family of open sets such that `K i ⊆ U i` for
all `i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and
`x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/
theorem Emetric.exists_smooth_forall_closedBall_subset {M} [EMetricSpace M] [ChartedSpace H M]
[IsManifold I ∞ M] [SigmaCompactSpace M] {K : ι → Set M} {U : ι → Set M}
(hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i)
(hfin : LocallyFinite K) :
∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯,
(∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, EMetric.closedBall x (ENNReal.ofReal (δ x)) ⊆ U i := by
simpa only [mem_inter_iff, forall_and, mem_preimage, mem_iInter, @forall_swap ι M]
using exists_smooth_forall_mem_convex_of_local_const I
EMetric.exists_forall_closedBall_subset_aux₂
(EMetric.exists_forall_closedBall_subset_aux₁ hK hU hKU hfin)
/-- Let `M` be a smooth σ-compact manifold with a metric. Let `K : ι → Set M` be a locally finite
family of closed sets, let `U : ι → Set M` be a family of open sets such that `K i ⊆ U i` for all
`i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and `x ∈ K i`,
we have `Metric.closedBall x (δ x) ⊆ U i`. -/
theorem Metric.exists_smooth_forall_closedBall_subset {M} [MetricSpace M] [ChartedSpace H M]
[IsManifold I ∞ M] [SigmaCompactSpace M] {K : ι → Set M} {U : ι → Set M}
(hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i)
(hfin : LocallyFinite K) :
∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯,
(∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, Metric.closedBall x (δ x) ⊆ U i := by
rcases Emetric.exists_smooth_forall_closedBall_subset I hK hU hKU hfin with ⟨δ, hδ0, hδ⟩
refine ⟨δ, hδ0, fun i x hx => ?_⟩
rw [← Metric.emetric_closedBall (hδ0 _).le]
exact hδ i x hx
lemma IsOpen.exists_msmooth_support_eq_aux {s : Set H} (hs : IsOpen s) :
∃ f : H → ℝ, f.support = s ∧ ContMDiff I 𝓘(ℝ) ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := by
have h's : IsOpen (I.symm ⁻¹' s) := I.continuous_symm.isOpen_preimage _ hs
rcases h's.exists_smooth_support_eq with ⟨f, f_supp, f_diff, f_range⟩
refine ⟨f ∘ I, ?_, ?_, ?_⟩
· rw [support_comp_eq_preimage, f_supp, ← preimage_comp]
simp only [ModelWithCorners.symm_comp_self, preimage_id_eq, id_eq]
· exact f_diff.comp_contMDiff contMDiff_model
· exact Subset.trans (range_comp_subset_range _ _) f_range
/-- Given an open set in a finite-dimensional real manifold, there exists a nonnegative smooth
function with support equal to `s`. -/
theorem IsOpen.exists_msmooth_support_eq {s : Set M} (hs : IsOpen s) :
∃ f : M → ℝ, f.support = s ∧ ContMDiff I 𝓘(ℝ) ∞ f ∧ ∀ x, 0 ≤ f x := by
rcases SmoothPartitionOfUnity.exists_isSubordinate_chartAt_source I M with ⟨f, hf⟩
have A : ∀ (c : M), ∃ g : H → ℝ,
g.support = (chartAt H c).target ∩ (chartAt H c).symm ⁻¹' s ∧
ContMDiff I 𝓘(ℝ) ∞ g ∧ Set.range g ⊆ Set.Icc 0 1 := by
intro i
apply IsOpen.exists_msmooth_support_eq_aux
exact PartialHomeomorph.isOpen_inter_preimage_symm _ hs
choose g g_supp g_diff hg using A
have h'g : ∀ c x, 0 ≤ g c x := fun c x ↦ (hg c (mem_range_self (f := g c) x)).1
have h''g : ∀ c x, 0 ≤ f c x * g c (chartAt H c x) :=
fun c x ↦ mul_nonneg (f.nonneg c x) (h'g c _)
refine ⟨fun x ↦ ∑ᶠ c, f c x * g c (chartAt H c x), ?_, ?_, ?_⟩
· refine support_eq_iff.2 ⟨fun x hx ↦ ?_, fun x hx ↦ ?_⟩
· apply ne_of_gt
have B : ∃ c, 0 < f c x * g c (chartAt H c x) := by
obtain ⟨c, hc⟩ : ∃ c, 0 < f c x := f.exists_pos_of_mem (mem_univ x)
refine ⟨c, mul_pos hc ?_⟩
apply lt_of_le_of_ne (h'g _ _) (Ne.symm _)
rw [← mem_support, g_supp, ← mem_preimage, preimage_inter]
have Hx : x ∈ tsupport (f c) := subset_tsupport _ (ne_of_gt hc)
simp [(chartAt H c).left_inv (hf c Hx), hx, (chartAt H c).map_source (hf c Hx)]
apply finsum_pos' (fun c ↦ h''g c x) B
apply (f.locallyFinite.point_finite x).subset
apply compl_subset_compl.2
rintro c (hc : f c x = 0)
simpa only [mul_eq_zero] using Or.inl hc
| · apply finsum_eq_zero_of_forall_eq_zero
intro c
by_cases Hx : x ∈ tsupport (f c)
· suffices g c (chartAt H c x) = 0 by simp only [this, mul_zero]
rw [← nmem_support, g_supp, ← mem_preimage, preimage_inter]
contrapose! hx
simp only [mem_inter_iff, mem_preimage, (chartAt H c).left_inv (hf c Hx)] at hx
exact hx.2
· have : x ∉ support (f c) := by contrapose! Hx; exact subset_tsupport _ Hx
rw [nmem_support] at this
| Mathlib/Geometry/Manifold/PartitionOfUnity.lean | 697 | 706 |
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Continuity
import Mathlib.Topology.Algebra.IsUniformGroup.Basic
import Mathlib.Topology.MetricSpace.Algebra
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Normed groups are uniform groups
This file proves lipschitzness of normed group operations and shows that normed groups are uniform
groups.
-/
variable {𝓕 E F : Type*}
open Filter Function Metric Bornology
open scoped ENNReal NNReal Uniformity Pointwise Topology
section SeminormedGroup
variable [SeminormedGroup E] [SeminormedGroup F] {s : Set E} {a b : E} {r : ℝ}
@[to_additive]
instance NormedGroup.to_isIsometricSMul_right : IsIsometricSMul Eᵐᵒᵖ E :=
⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩
@[to_additive]
theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) :
‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right]
@[to_additive (attr := simp)]
theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by
rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul]
@[to_additive (attr := simp)]
theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by
rw [dist_comm, dist_mul_self_right]
@[to_additive (attr := simp)]
theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by
rw [← dist_mul_right _ _ b, div_mul_cancel]
@[to_additive (attr := simp)]
theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by
rw [← dist_mul_right _ _ c, div_mul_cancel]
open Finset
variable [FunLike 𝓕 E F]
/-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that
for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of
(semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/
@[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant
`C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of
(semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."]
theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f :=
LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive]
theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} :
LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by
simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div]
alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le
attribute [to_additive] LipschitzOnWith.norm_div_le
@[to_additive]
theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s)
(ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r :=
(h.norm_div_le ha hb).trans <| by gcongr
@[to_additive]
theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} :
LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by
simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div]
alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le
attribute [to_additive] LipschitzWith.norm_div_le
@[to_additive]
theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f)
(hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r :=
(h.norm_div_le _ _).trans <| by gcongr
/-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that
for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/
@[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C`
such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"]
theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f :=
(MonoidHomClass.lipschitz_of_bound f C h).continuous
@[to_additive]
theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f :=
(MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous
@[to_additive]
theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) :
Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by
simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div]
refine ⟨fun h x => ?_, fun h x y => h _⟩
simpa using h x 1
alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm
attribute [to_additive] MonoidHomClass.isometry_of_norm
section NNNorm
@[to_additive]
theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0)
(h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f :=
@Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h
@[to_additive]
theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0}
(h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f :=
AntilipschitzWith.of_le_mul_dist fun x y => by
simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive LipschitzWith.norm_le_mul]
theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1)
(x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1
@[to_additive LipschitzWith.nnorm_le_mul]
theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1)
(x) : ‖f x‖₊ ≤ K * ‖x‖₊ :=
h.norm_le_mul' hf x
@[to_additive AntilipschitzWith.le_mul_norm]
theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f)
(hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by
simpa only [dist_one_right, hf] using h.le_mul_dist x 1
@[to_additive AntilipschitzWith.le_mul_nnnorm]
theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f)
(hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ :=
h.le_mul_norm' hf x
@[to_additive]
theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0}
(h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ :=
h.le_mul_nnnorm' (map_one f) x
@[to_additive]
theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) :
‖f x‖₊ = ‖x‖₊ :=
Subtype.ext <| hi.norm_map_of_map_one h₁ x
end NNNorm
@[to_additive lipschitzWith_one_norm]
theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by
simpa using LipschitzWith.dist_right (1 : E)
@[to_additive lipschitzWith_one_nnnorm]
theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) :=
lipschitzWith_one_norm'
@[to_additive uniformContinuous_norm]
theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) :=
lipschitzWith_one_norm'.uniformContinuous
@[to_additive uniformContinuous_nnnorm]
theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ :=
uniformContinuous_norm'.subtype_mk _
end SeminormedGroup
section SeminormedCommGroup
variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a₁ a₂ b₁ b₂ : E} {r₁ r₂ : ℝ}
@[to_additive]
instance NormedGroup.to_isIsometricSMul_left : IsIsometricSMul E E :=
⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩
@[to_additive (attr := simp)]
theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by
rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one]
@[to_additive (attr := simp)]
theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by
rw [dist_comm, dist_self_mul_right]
@[to_additive (attr := simp 1001)] -- Increase priority because `simp` can prove this
theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by
rw [div_eq_mul_inv, dist_self_mul_right, norm_inv']
@[to_additive (attr := simp 1001)] -- Increase priority because `simp` can prove this
theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by
rw [dist_comm, dist_self_div_right]
@[to_additive]
theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by
simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂)
@[to_additive]
theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) :
dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ :=
(dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂
@[to_additive]
theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by
simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹
@[to_additive]
theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) :
dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ :=
(dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂
@[to_additive]
theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) :
|dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by
simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using
abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂)
open Finset
@[to_additive]
theorem nndist_mul_mul_le (a₁ a₂ b₁ b₂ : E) :
nndist (a₁ * a₂) (b₁ * b₂) ≤ nndist a₁ b₁ + nndist a₂ b₂ :=
NNReal.coe_le_coe.1 <| dist_mul_mul_le a₁ a₂ b₁ b₂
@[to_additive]
theorem edist_mul_mul_le (a₁ a₂ b₁ b₂ : E) :
edist (a₁ * a₂) (b₁ * b₂) ≤ edist a₁ b₁ + edist a₂ b₂ := by
simp only [edist_nndist]
norm_cast
apply nndist_mul_mul_le
section PseudoEMetricSpace
variable {α E : Type*} [SeminormedCommGroup E] [PseudoEMetricSpace α] {K Kf Kg : ℝ≥0}
{f g : α → E} {s : Set α}
@[to_additive (attr := simp)]
lemma lipschitzWith_inv_iff : LipschitzWith K f⁻¹ ↔ LipschitzWith K f := by simp [LipschitzWith]
@[to_additive (attr := simp)]
lemma antilipschitzWith_inv_iff : AntilipschitzWith K f⁻¹ ↔ AntilipschitzWith K f := by
simp [AntilipschitzWith]
@[to_additive (attr := simp)]
lemma lipschitzOnWith_inv_iff : LipschitzOnWith K f⁻¹ s ↔ LipschitzOnWith K f s := by
simp [LipschitzOnWith]
@[to_additive (attr := simp)]
lemma locallyLipschitz_inv_iff : LocallyLipschitz f⁻¹ ↔ LocallyLipschitz f := by
simp [LocallyLipschitz]
@[to_additive (attr := simp)]
lemma locallyLipschitzOn_inv_iff : LocallyLipschitzOn s f⁻¹ ↔ LocallyLipschitzOn s f := by
simp [LocallyLipschitzOn]
@[to_additive] alias ⟨LipschitzWith.of_inv, LipschitzWith.inv⟩ := lipschitzWith_inv_iff
@[to_additive] alias ⟨AntilipschitzWith.of_inv, AntilipschitzWith.inv⟩ := antilipschitzWith_inv_iff
@[to_additive] alias ⟨LipschitzOnWith.of_inv, LipschitzOnWith.inv⟩ := lipschitzOnWith_inv_iff
@[to_additive] alias ⟨LocallyLipschitz.of_inv, LocallyLipschitz.inv⟩ := locallyLipschitz_inv_iff
@[to_additive]
alias ⟨LocallyLipschitzOn.of_inv, LocallyLipschitzOn.inv⟩ := locallyLipschitzOn_inv_iff
@[to_additive]
lemma LipschitzOnWith.mul (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) :
LipschitzOnWith (Kf + Kg) (fun x ↦ f x * g x) s := fun x hx y hy ↦
calc
edist (f x * g x) (f y * g y) ≤ edist (f x) (f y) + edist (g x) (g y) :=
edist_mul_mul_le _ _ _ _
_ ≤ Kf * edist x y + Kg * edist x y := add_le_add (hf hx hy) (hg hx hy)
_ = (Kf + Kg) * edist x y := (add_mul _ _ _).symm
@[to_additive]
lemma LipschitzWith.mul (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (Kf + Kg) fun x ↦ f x * g x := by
simpa [← lipschitzOnWith_univ] using hf.lipschitzOnWith.mul hg.lipschitzOnWith
@[to_additive]
lemma LocallyLipschitzOn.mul (hf : LocallyLipschitzOn s f) (hg : LocallyLipschitzOn s g) :
LocallyLipschitzOn s fun x ↦ f x * g x := fun x hx ↦ by
obtain ⟨Kf, t, ht, hKf⟩ := hf hx
obtain ⟨Kg, u, hu, hKg⟩ := hg hx
exact ⟨Kf + Kg, t ∩ u, inter_mem ht hu,
(hKf.mono Set.inter_subset_left).mul (hKg.mono Set.inter_subset_right)⟩
@[to_additive]
lemma LocallyLipschitz.mul (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz fun x ↦ f x * g x := by
simpa [← locallyLipschitzOn_univ] using hf.locallyLipschitzOn.mul hg.locallyLipschitzOn
@[to_additive]
lemma LipschitzOnWith.div (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) :
LipschitzOnWith (Kf + Kg) (fun x ↦ f x / g x) s := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
theorem LipschitzWith.div (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (Kf + Kg) fun x => f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
lemma LocallyLipschitzOn.div (hf : LocallyLipschitzOn s f) (hg : LocallyLipschitzOn s g) :
LocallyLipschitzOn s fun x ↦ f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
lemma LocallyLipschitz.div (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz fun x ↦ f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
namespace AntilipschitzWith
@[to_additive]
theorem mul_lipschitzWith (hf : AntilipschitzWith Kf f) (hg : LipschitzWith Kg g) (hK : Kg < Kf⁻¹) :
AntilipschitzWith (Kf⁻¹ - Kg)⁻¹ fun x => f x * g x := by
letI : PseudoMetricSpace α := PseudoEMetricSpace.toPseudoMetricSpace hf.edist_ne_top
refine AntilipschitzWith.of_le_mul_dist fun x y => ?_
rw [NNReal.coe_inv, ← _root_.div_eq_inv_mul]
rw [le_div_iff₀ (NNReal.coe_pos.2 <| tsub_pos_iff_lt.2 hK)]
rw [mul_comm, NNReal.coe_sub hK.le, sub_mul]
calc
↑Kf⁻¹ * dist x y - Kg * dist x y ≤ dist (f x) (f y) - dist (g x) (g y) :=
sub_le_sub (hf.mul_le_dist x y) (hg.dist_le_mul x y)
_ ≤ _ := le_trans (le_abs_self _) (abs_dist_sub_le_dist_mul_mul _ _ _ _)
@[to_additive]
theorem mul_div_lipschitzWith (hf : AntilipschitzWith Kf f) (hg : LipschitzWith Kg (g / f))
(hK : Kg < Kf⁻¹) : AntilipschitzWith (Kf⁻¹ - Kg)⁻¹ g := by
simpa only [Pi.div_apply, mul_div_cancel] using hf.mul_lipschitzWith hg hK
|
@[to_additive le_mul_norm_sub]
theorem le_mul_norm_div {f : E → F} (hf : AntilipschitzWith K f) (x y : E) :
| Mathlib/Analysis/Normed/Group/Uniform.lean | 336 | 338 |
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Data.Set.Finite.Powerset
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = ENat.card α := by
rw [encard, ENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
@[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl
theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl
@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]
@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
@[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
simp [encard, ENat.card_congr (Equiv.Set.union h)]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
induction s, h using Set.Finite.induction_on with
| empty => simp
| insert hat _ ht' =>
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
@[simp]
theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by
simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)]
section Lattice
theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
@[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_encard
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_inj h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts
theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le)
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_encard inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
| rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
| Mathlib/Data/Set/Card.lean | 263 | 271 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import Mathlib.Algebra.Field.IsField
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.LinearAlgebra.Finsupp.LinearCombination
import Mathlib.RingTheory.Ideal.Maximal
import Mathlib.Tactic.FinCases
/-!
# Ideals over a ring
This file contains an assortment of definitions and results for `Ideal R`,
the type of (left) ideals over a ring `R`.
Note that over commutative rings, left ideals and two-sided ideals are equivalent.
## Implementation notes
`Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
variable {ι α β F : Type*}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable {α : ι → Type*} [Π i, Semiring (α i)] (I : Π i, Ideal (α i))
section Pi
/-- `Πᵢ Iᵢ` as an ideal of `Πᵢ Rᵢ`. -/
def pi : Ideal (Π i, α i) where
carrier := { x | ∀ i, x i ∈ I i }
zero_mem' i := (I i).zero_mem
add_mem' ha hb i := (I i).add_mem (ha i) (hb i)
smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i)
theorem mem_pi (x : Π i, α i) : x ∈ pi I ↔ ∀ i, x i ∈ I i :=
Iff.rfl
instance (priority := low) [∀ i, (I i).IsTwoSided] : (pi I).IsTwoSided :=
⟨fun _b hb i ↦ mul_mem_right _ _ (hb i)⟩
end Pi
section Commute
variable {α : Type*} [Semiring α] (I : Ideal α) {a b : α}
theorem add_pow_mem_of_pow_mem_of_le_of_commute {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1)
(hab : Commute a b) :
(a + b) ^ k ∈ I := by
simp_rw [hab.add_pow, ← Nat.cast_comm]
apply I.sum_mem
intro c _
apply mul_mem_left
by_cases h : m ≤ c
· rw [hab.pow_pow]
exact I.mul_mem_left _ (I.pow_mem_of_pow_mem ha h)
· refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_)
omega
theorem add_pow_add_pred_mem_of_pow_mem_of_commute {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hab : Commute a b) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb (by rw [← Nat.sub_le_iff_le_add]) hab
end Commute
end Ideal
end Semiring
section CommSemiring
variable {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different
-- order.
namespace Ideal
variable [CommSemiring α] (I : Ideal α)
theorem add_pow_mem_of_pow_mem_of_le {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1) :
(a + b) ^ k ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb hk (Commute.all ..)
theorem add_pow_add_pred_mem_of_pow_mem {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_add_pred_mem_of_pow_mem_of_commute ha hb (Commute.all ..)
theorem pow_multiset_sum_mem_span_pow [DecidableEq α] (s : Multiset α) (n : ℕ) :
s.sum ^ (Multiset.card s * n + 1) ∈
span ((s.map fun (x : α) ↦ x ^ (n + 1)).toFinset : Set α) := by
induction' s using Multiset.induction_on with a s hs
· simp
simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons,
Multiset.card_cons, add_pow]
refine Submodule.sum_mem _ ?_
intro c _hc
rw [mem_span_insert]
by_cases h : n + 1 ≤ c
· refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) *
((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩
rw [mul_comm _ (a ^ (n + 1))]
simp_rw [← mul_assoc]
rw [← pow_add, add_zero, add_tsub_cancel_of_le h]
· use 0
simp_rw [zero_mul, zero_add]
refine ⟨_, ?_, rfl⟩
replace h : c ≤ n := Nat.lt_succ_iff.mp (not_le.mp h)
have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by
rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h]
rw [this, pow_add]
simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc]
exact mul_mem_left _ _ hs
theorem sum_pow_mem_span_pow {ι} (s : Finset ι) (f : ι → α) (n : ℕ) :
(∑ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by
classical
simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map,
Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n
theorem span_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : ℕ) :
span ((fun (x : α) => x ^ n) '' s) = ⊤ := by
rw [eq_top_iff_one]
rcases n with - | n
· obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s
· rw [Set.image_empty, hs]
trivial
· exact subset_span ⟨_, hx, pow_zero _⟩
rw [eq_top_iff_one, span, Finsupp.mem_span_iff_linearCombination] at hs
rcases hs with ⟨f, hf⟩
have hf : (f.support.sum fun a => f a * a) = 1 := hf -- Porting note: was `change ... at hf`
have := sum_pow_mem_span_pow f.support (fun a => f a * a) n
rw [hf, one_pow] at this
refine span_le.mpr ?_ this
rintro _ hx
simp_rw [Set.mem_image] at hx
rcases hx with ⟨x, _, rfl⟩
have : span ({(x : α) ^ (n + 1)} : Set α) ≤ span ((fun x : α => x ^ (n + 1)) '' s) := by
rw [span_le, Set.singleton_subset_iff]
exact subset_span ⟨x, x.prop, rfl⟩
refine this ?_
rw [mul_pow, mem_span_singleton]
exact ⟨f x ^ (n + 1), mul_comm _ _⟩
theorem span_range_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : s → ℕ) :
span (Set.range fun x ↦ x.1 ^ n x) = ⊤ := by
have ⟨t, hts, mem⟩ := Submodule.mem_span_finite_of_mem_span ((eq_top_iff_one _).mp hs)
refine top_unique ((span_pow_eq_top _ ((eq_top_iff_one _).mpr mem) <|
t.attach.sup fun x ↦ n ⟨x, hts x.2⟩).ge.trans <| span_le.mpr ?_)
rintro _ ⟨x, hxt, rfl⟩
rw [← Nat.sub_add_cancel (Finset.le_sup <| t.mem_attach ⟨x, hxt⟩)]
simp_rw [pow_add]
exact mul_mem_left _ _ (subset_span ⟨_, rfl⟩)
theorem prod_mem {ι : Type*} {f : ι → α} {s : Finset ι}
(I : Ideal α) {i : ι} (hi : i ∈ s) (hfi : f i ∈ I) :
∏ i ∈ s, f i ∈ I := by
classical
rw [Finset.prod_eq_prod_diff_singleton_mul hi]
exact Ideal.mul_mem_left _ _ hfi
end Ideal
end CommSemiring
section DivisionSemiring
variable {K : Type*} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
variable (K) in
/-- A bijection between (left) ideals of a division ring and `{0, 1}`, sending `⊥` to `0`
and `⊤` to `1`. -/
def equivFinTwo [DecidableEq (Ideal K)] : Ideal K ≃ Fin 2 where
toFun := fun I ↦ if I = ⊥ then 0 else 1
invFun := ![⊥, ⊤]
left_inv := fun I ↦ by rcases eq_bot_or_top I with rfl | rfl <;> simp
right_inv := fun i ↦ by fin_cases i <;> simp
instance : Finite (Ideal K) := let _i := Classical.decEq (Ideal K); ⟨equivFinTwo K⟩
/-- Ideals of a `DivisionSemiring` are a simple order. Thanks to the way abbreviations work,
this automatically gives an `IsSimpleModule K` instance. -/
instance isSimpleOrder : IsSimpleOrder (Ideal K) :=
⟨eq_bot_or_top⟩
end Ideal
end DivisionSemiring
-- TODO: consider moving the lemmas below out of the `Ring` namespace since they are
-- about `CommSemiring`s.
namespace Ring
variable {R : Type*} [CommSemiring R]
theorem exists_not_isUnit_of_not_isField [Nontrivial R] (hf : ¬IsField R) :
∃ (x : R) (_hx : x ≠ (0 : R)), ¬IsUnit x := by
have : ¬_ := fun h => hf ⟨exists_pair_ne R, mul_comm, h⟩
simp_rw [isUnit_iff_exists_inv]
push_neg at this ⊢
obtain ⟨x, hx, not_unit⟩ := this
exact ⟨x, hx, not_unit⟩
theorem not_isField_iff_exists_ideal_bot_lt_and_lt_top [Nontrivial R] :
¬IsField R ↔ ∃ I : Ideal R, ⊥ < I ∧ I < ⊤ := by
constructor
· intro h
obtain ⟨x, nz, nu⟩ := exists_not_isUnit_of_not_isField h
use Ideal.span {x}
rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top]
exact ⟨mt Ideal.span_singleton_eq_bot.mp nz, mt Ideal.span_singleton_eq_top.mp nu⟩
· rintro ⟨I, bot_lt, lt_top⟩ hf
obtain ⟨x, mem, ne_zero⟩ := SetLike.exists_of_lt bot_lt
rw [Submodule.mem_bot] at ne_zero
obtain ⟨y, hy⟩ := hf.mul_inv_cancel ne_zero
rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, ← hy] at lt_top
exact lt_top (I.mul_mem_right _ mem)
theorem not_isField_iff_exists_prime [Nontrivial R] :
¬IsField R ↔ ∃ p : Ideal R, p ≠ ⊥ ∧ p.IsPrime :=
not_isField_iff_exists_ideal_bot_lt_and_lt_top.trans
⟨fun ⟨I, bot_lt, lt_top⟩ =>
let ⟨p, hp, le_p⟩ := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top)
⟨p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.isPrime⟩,
fun ⟨p, ne_bot, Prime⟩ => ⟨p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr Prime.1⟩⟩
/-- Also see `Ideal.isSimpleOrder` for the forward direction as an instance when `R` is a
division (semi)ring.
This result actually holds for all division semirings, but we lack the predicate to state it. -/
theorem isField_iff_isSimpleOrder_ideal : IsField R ↔ IsSimpleOrder (Ideal R) := by
cases subsingleton_or_nontrivial R
· exact
⟨fun h => (not_isField_of_subsingleton _ h).elim, fun h =>
(false_of_nontrivial_of_subsingleton <| Ideal R).elim⟩
rw [← not_iff_not, Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top, ← not_iff_not]
push_neg
simp_rw [lt_top_iff_ne_top, bot_lt_iff_ne_bot, ← or_iff_not_imp_left, not_ne_iff]
exact ⟨fun h => ⟨h⟩, fun h => h.2⟩
/-- When a ring is not a field, the maximal ideals are nontrivial. -/
theorem ne_bot_of_isMaximal_of_not_isField [Nontrivial R] {M : Ideal R} (max : M.IsMaximal)
(not_field : ¬IsField R) : M ≠ ⊥ := by
rintro h
rw [h] at max
rcases max with ⟨⟨_h1, h2⟩⟩
obtain ⟨I, hIbot, hItop⟩ := not_isField_iff_exists_ideal_bot_lt_and_lt_top.mp not_field
exact ne_of_lt hItop (h2 I hIbot)
end Ring
namespace Ideal
variable {R : Type*} [CommSemiring R] [Nontrivial R]
theorem bot_lt_of_maximal (M : Ideal R) [hm : M.IsMaximal] (non_field : ¬IsField R) : ⊥ < M := by
rcases Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top.1 non_field with ⟨I, Ibot, Itop⟩
constructor; · simp
intro mle
apply lt_irrefl (⊤ : Ideal R)
have : M = ⊥ := eq_bot_iff.mpr mle
rw [← this] at Ibot
rwa [hm.1.2 I Ibot] at Itop
end Ideal
| Mathlib/RingTheory/Ideal/Basic.lean | 561 | 566 | |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.GramSchmidtOrtho
import Mathlib.LinearAlgebra.Orientation
/-!
# Orientations of real inner product spaces.
This file provides definitions and proves lemmas about orientations of real inner product spaces.
## Main definitions
* `OrthonormalBasis.adjustToOrientation` takes an orthonormal basis and an orientation, and
returns an orthonormal basis with that orientation: either the original orthonormal basis, or one
constructed by negating a single (arbitrary) basis vector.
* `Orientation.finOrthonormalBasis` is an orthonormal basis, indexed by `Fin n`, with the given
orientation.
* `Orientation.volumeForm` is a nonvanishing top-dimensional alternating form on an oriented real
inner product space, uniquely defined by compatibility with the orientation and inner product
structure.
## Main theorems
* `Orientation.volumeForm_apply_le` states that the result of applying the volume form to a set of
`n` vectors, where `n` is the dimension the inner product space, is bounded by the product of the
lengths of the vectors.
* `Orientation.abs_volumeForm_apply_of_pairwise_orthogonal` states that the result of applying the
volume form to a set of `n` orthogonal vectors, where `n` is the dimension the inner product
space, is equal up to sign to the product of the lengths of the vectors.
-/
noncomputable section
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]
open Module
open scoped RealInnerProductSpace
namespace OrthonormalBasis
variable {ι : Type*} [Fintype ι] [DecidableEq ι] (e f : OrthonormalBasis ι ℝ E)
(x : Orientation ℝ E ι)
/-- The change-of-basis matrix between two orthonormal bases with the same orientation has
determinant 1. -/
theorem det_to_matrix_orthonormalBasis_of_same_orientation
(h : e.toBasis.orientation = f.toBasis.orientation) : e.toBasis.det f = 1 := by
apply (e.det_to_matrix_orthonormalBasis_real f).resolve_right
have : 0 < e.toBasis.det f := by
rw [e.toBasis.orientation_eq_iff_det_pos] at h
simpa using h
linarith
/-- The change-of-basis matrix between two orthonormal bases with the opposite orientations has
determinant -1. -/
theorem det_to_matrix_orthonormalBasis_of_opposite_orientation
(h : e.toBasis.orientation ≠ f.toBasis.orientation) : e.toBasis.det f = -1 := by
contrapose! h
simp [e.toBasis.orientation_eq_iff_det_pos,
(e.det_to_matrix_orthonormalBasis_real f).resolve_right h]
variable {e f}
/-- Two orthonormal bases with the same orientation determine the same "determinant" top-dimensional
form on `E`, and conversely. -/
theorem same_orientation_iff_det_eq_det :
e.toBasis.det = f.toBasis.det ↔ e.toBasis.orientation = f.toBasis.orientation := by
constructor
· intro h
dsimp [Basis.orientation]
congr
· intro h
rw [e.toBasis.det.eq_smul_basis_det f.toBasis]
simp [e.det_to_matrix_orthonormalBasis_of_same_orientation f h]
variable (e f)
/-- Two orthonormal bases with opposite orientations determine opposite "determinant"
top-dimensional forms on `E`. -/
theorem det_eq_neg_det_of_opposite_orientation (h : e.toBasis.orientation ≠ f.toBasis.orientation) :
e.toBasis.det = -f.toBasis.det := by
rw [e.toBasis.det.eq_smul_basis_det f.toBasis]
simp [e.det_to_matrix_orthonormalBasis_of_opposite_orientation f h, neg_one_smul]
variable [Nonempty ι]
section AdjustToOrientation
/-- `OrthonormalBasis.adjustToOrientation`, applied to an orthonormal basis, preserves the
property of orthonormality. -/
theorem orthonormal_adjustToOrientation : Orthonormal ℝ (e.toBasis.adjustToOrientation x) := by
apply e.orthonormal.orthonormal_of_forall_eq_or_eq_neg
simpa using e.toBasis.adjustToOrientation_apply_eq_or_eq_neg x
/-- Given an orthonormal basis and an orientation, return an orthonormal basis giving that
orientation: either the original basis, or one constructed by negating a single (arbitrary) basis
vector. -/
def adjustToOrientation : OrthonormalBasis ι ℝ E :=
(e.toBasis.adjustToOrientation x).toOrthonormalBasis (e.orthonormal_adjustToOrientation x)
theorem toBasis_adjustToOrientation :
(e.adjustToOrientation x).toBasis = e.toBasis.adjustToOrientation x :=
(e.toBasis.adjustToOrientation x).toBasis_toOrthonormalBasis _
/-- `adjustToOrientation` gives an orthonormal basis with the required orientation. -/
@[simp]
theorem orientation_adjustToOrientation : (e.adjustToOrientation x).toBasis.orientation = x := by
rw [e.toBasis_adjustToOrientation]
exact e.toBasis.orientation_adjustToOrientation x
/-- Every basis vector from `adjustToOrientation` is either that from the original basis or its
negation. -/
theorem adjustToOrientation_apply_eq_or_eq_neg (i : ι) :
e.adjustToOrientation x i = e i ∨ e.adjustToOrientation x i = -e i := by
simpa [← e.toBasis_adjustToOrientation] using
e.toBasis.adjustToOrientation_apply_eq_or_eq_neg x i
theorem det_adjustToOrientation :
(e.adjustToOrientation x).toBasis.det = e.toBasis.det ∨
(e.adjustToOrientation x).toBasis.det = -e.toBasis.det := by
simpa using e.toBasis.det_adjustToOrientation x
theorem abs_det_adjustToOrientation (v : ι → E) :
|(e.adjustToOrientation x).toBasis.det v| = |e.toBasis.det v| := by
simp [toBasis_adjustToOrientation]
end AdjustToOrientation
end OrthonormalBasis
namespace Orientation
variable {n : ℕ}
open OrthonormalBasis
/-- An orthonormal basis, indexed by `Fin n`, with the given orientation. -/
protected def finOrthonormalBasis (hn : 0 < n) (h : finrank ℝ E = n) (x : Orientation ℝ E (Fin n)) :
OrthonormalBasis (Fin n) ℝ E := by
haveI := Fin.pos_iff_nonempty.1 hn
haveI : FiniteDimensional ℝ E := .of_finrank_pos <| h.symm ▸ hn
exact ((@stdOrthonormalBasis _ _ _ _ _ this).reindex <| finCongr h).adjustToOrientation x
/-- `Orientation.finOrthonormalBasis` gives a basis with the required orientation. -/
@[simp]
theorem finOrthonormalBasis_orientation (hn : 0 < n) (h : finrank ℝ E = n)
(x : Orientation ℝ E (Fin n)) : (x.finOrthonormalBasis hn h).toBasis.orientation = x := by
haveI := Fin.pos_iff_nonempty.1 hn
haveI : FiniteDimensional ℝ E := .of_finrank_pos <| h.symm ▸ hn
exact ((@stdOrthonormalBasis _ _ _ _ _ this).reindex <|
finCongr h).orientation_adjustToOrientation x
section VolumeForm
variable [_i : Fact (finrank ℝ E = n)] (o : Orientation ℝ E (Fin n))
/-- The volume form on an oriented real inner product space, a nonvanishing top-dimensional
alternating form uniquely defined by compatibility with the orientation and inner product structure.
-/
irreducible_def volumeForm : E [⋀^Fin n]→ₗ[ℝ] ℝ := by
classical
cases n with
| zero =>
let opos : E [⋀^Fin 0]→ₗ[ℝ] ℝ := .constOfIsEmpty ℝ E (Fin 0) (1 : ℝ)
exact o.eq_or_eq_neg_of_isEmpty.by_cases (fun _ => opos) fun _ => -opos
| succ n => exact (o.finOrthonormalBasis n.succ_pos _i.out).toBasis.det
@[simp]
theorem volumeForm_zero_pos [_i : Fact (finrank ℝ E = 0)] :
Orientation.volumeForm (positiveOrientation : Orientation ℝ E (Fin 0)) =
AlternatingMap.constLinearEquivOfIsEmpty 1 := by
simp [volumeForm, Or.by_cases, if_pos]
theorem volumeForm_zero_neg [_i : Fact (finrank ℝ E = 0)] :
Orientation.volumeForm (-positiveOrientation : Orientation ℝ E (Fin 0)) =
-AlternatingMap.constLinearEquivOfIsEmpty 1 := by
simp_rw [volumeForm, Or.by_cases, positiveOrientation]
apply if_neg
simp only [neg_rayOfNeZero]
rw [ray_eq_iff, SameRay.sameRay_comm]
intro h
simpa using
congr_arg AlternatingMap.constLinearEquivOfIsEmpty.symm (eq_zero_of_sameRay_self_neg h)
/-- The volume form on an oriented real inner product space can be evaluated as the determinant with
respect to any orthonormal basis of the space compatible with the orientation. -/
theorem volumeForm_robust (b : OrthonormalBasis (Fin n) ℝ E) (hb : b.toBasis.orientation = o) :
o.volumeForm = b.toBasis.det := by
cases n
| · classical
have : o = positiveOrientation := hb.symm.trans b.toBasis.orientation_isEmpty
simp_rw [volumeForm, Or.by_cases, dif_pos this, Nat.rec_zero, Basis.det_isEmpty]
· simp_rw [volumeForm]
rw [same_orientation_iff_det_eq_det, hb]
exact o.finOrthonormalBasis_orientation _ _
/-- The volume form on an oriented real inner product space can be evaluated as the determinant with
respect to any orthonormal basis of the space compatible with the orientation. -/
theorem volumeForm_robust_neg (b : OrthonormalBasis (Fin n) ℝ E) (hb : b.toBasis.orientation ≠ o) :
| Mathlib/Analysis/InnerProductSpace/Orientation.lean | 196 | 205 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Set.Function
import Mathlib.Logic.Pairwise
import Mathlib.Logic.Relation
/-!
# Relations holding pairwise
This file develops pairwise relations and defines pairwise disjoint indexed sets.
We also prove many basic facts about `Pairwise`. It is possible that an intermediate file,
with more imports than `Logic.Pairwise` but not importing `Data.Set.Function` would be appropriate
to hold many of these basic facts.
## Main declarations
* `Set.PairwiseDisjoint`: `s.PairwiseDisjoint f` states that images under `f` of distinct elements
of `s` are either equal or `Disjoint`.
## Notes
The spelling `s.PairwiseDisjoint id` is preferred over `s.Pairwise Disjoint` to permit dot notation
on `Set.PairwiseDisjoint`, even though the latter unfolds to something nicer.
-/
open Function Order Set
variable {α β γ ι ι' : Type*} {r p : α → α → Prop}
section Pairwise
variable {f g : ι → α} {s t : Set α} {a b : α}
theorem pairwise_on_bool (hr : Symmetric r) {a b : α} :
Pairwise (r on fun c => cond c a b) ↔ r a b := by simpa [Pairwise, Function.onFun] using @hr a b
theorem pairwise_disjoint_on_bool [PartialOrder α] [OrderBot α] {a b : α} :
Pairwise (Disjoint on fun c => cond c a b) ↔ Disjoint a b :=
pairwise_on_bool Disjoint.symm
theorem Symmetric.pairwise_on [LinearOrder ι] (hr : Symmetric r) (f : ι → α) :
Pairwise (r on f) ↔ ∀ ⦃m n⦄, m < n → r (f m) (f n) :=
⟨fun h _m _n hmn => h hmn.ne, fun h _m _n hmn => hmn.lt_or_lt.elim (@h _ _) fun h' => hr (h h')⟩
theorem pairwise_disjoint_on [PartialOrder α] [OrderBot α] [LinearOrder ι] (f : ι → α) :
Pairwise (Disjoint on f) ↔ ∀ ⦃m n⦄, m < n → Disjoint (f m) (f n) :=
Symmetric.pairwise_on Disjoint.symm f
theorem pairwise_disjoint_mono [PartialOrder α] [OrderBot α] (hs : Pairwise (Disjoint on f))
(h : g ≤ f) : Pairwise (Disjoint on g) :=
hs.mono fun i j hij => Disjoint.mono (h i) (h j) hij
theorem Pairwise.disjoint_extend_bot [PartialOrder γ] [OrderBot γ]
{e : α → β} {f : α → γ} (hf : Pairwise (Disjoint on f)) (he : FactorsThrough f e) :
Pairwise (Disjoint on extend e f ⊥) := by
intro b₁ b₂ hne
rcases em (∃ a₁, e a₁ = b₁) with ⟨a₁, rfl⟩ | hb₁
· rcases em (∃ a₂, e a₂ = b₂) with ⟨a₂, rfl⟩ | hb₂
· simpa only [onFun, he.extend_apply] using hf (ne_of_apply_ne e hne)
· simpa only [onFun, extend_apply' _ _ _ hb₂] using disjoint_bot_right
· simpa only [onFun, extend_apply' _ _ _ hb₁] using disjoint_bot_left
namespace Set
theorem Pairwise.mono (h : t ⊆ s) (hs : s.Pairwise r) : t.Pairwise r :=
fun _x xt _y yt => hs (h xt) (h yt)
theorem Pairwise.mono' (H : r ≤ p) (hr : s.Pairwise r) : s.Pairwise p :=
hr.imp H
theorem pairwise_top (s : Set α) : s.Pairwise ⊤ :=
pairwise_of_forall s _ fun _ _ => trivial
protected theorem Subsingleton.pairwise (h : s.Subsingleton) (r : α → α → Prop) : s.Pairwise r :=
fun _x hx _y hy hne => (hne (h hx hy)).elim
@[simp]
theorem pairwise_empty (r : α → α → Prop) : (∅ : Set α).Pairwise r :=
subsingleton_empty.pairwise r
@[simp]
theorem pairwise_singleton (a : α) (r : α → α → Prop) : Set.Pairwise {a} r :=
subsingleton_singleton.pairwise r
theorem pairwise_iff_of_refl [IsRefl α r] : s.Pairwise r ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b :=
forall₄_congr fun _ _ _ _ => or_iff_not_imp_left.symm.trans <| or_iff_right_of_imp of_eq
alias ⟨Pairwise.of_refl, _⟩ := pairwise_iff_of_refl
theorem Nonempty.pairwise_iff_exists_forall [IsEquiv α r] {s : Set ι} (hs : s.Nonempty) :
s.Pairwise (r on f) ↔ ∃ z, ∀ x ∈ s, r (f x) z := by
constructor
· rcases hs with ⟨y, hy⟩
refine fun H => ⟨f y, fun x hx => ?_⟩
rcases eq_or_ne x y with (rfl | hne)
· apply IsRefl.refl
· exact H hx hy hne
· rintro ⟨z, hz⟩ x hx y hy _
exact @IsTrans.trans α r _ (f x) z (f y) (hz _ hx) (IsSymm.symm _ _ <| hz _ hy)
/-- For a nonempty set `s`, a function `f` takes pairwise equal values on `s` if and only if
for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also
`Set.pairwise_eq_iff_exists_eq` for a version that assumes `[Nonempty ι]` instead of
`Set.Nonempty s`. -/
theorem Nonempty.pairwise_eq_iff_exists_eq {s : Set α} (hs : s.Nonempty) {f : α → ι} :
(s.Pairwise fun x y => f x = f y) ↔ ∃ z, ∀ x ∈ s, f x = z :=
hs.pairwise_iff_exists_forall
theorem pairwise_iff_exists_forall [Nonempty ι] (s : Set α) (f : α → ι) {r : ι → ι → Prop}
[IsEquiv ι r] : s.Pairwise (r on f) ↔ ∃ z, ∀ x ∈ s, r (f x) z := by
rcases s.eq_empty_or_nonempty with (rfl | hne)
· simp
· exact hne.pairwise_iff_exists_forall
/-- A function `f : α → ι` with nonempty codomain takes pairwise equal values on a set `s` if and
only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also
`Set.Nonempty.pairwise_eq_iff_exists_eq` for a version that assumes `Set.Nonempty s` instead of
`[Nonempty ι]`. -/
theorem pairwise_eq_iff_exists_eq [Nonempty ι] (s : Set α) (f : α → ι) :
(s.Pairwise fun x y => f x = f y) ↔ ∃ z, ∀ x ∈ s, f x = z :=
pairwise_iff_exists_forall s f
theorem pairwise_union :
(s ∪ t).Pairwise r ↔
s.Pairwise r ∧ t.Pairwise r ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b ∧ r b a := by
simp only [Set.Pairwise, mem_union, or_imp, forall_and]
aesop
theorem pairwise_union_of_symmetric (hr : Symmetric r) :
(s ∪ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b :=
pairwise_union.trans <| by simp only [hr.iff, and_self_iff]
theorem pairwise_insert :
(insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b ∧ r b a := by
simp only [insert_eq, pairwise_union, pairwise_singleton, true_and, mem_singleton_iff, forall_eq]
theorem pairwise_insert_of_not_mem (ha : a ∉ s) :
(insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, r a b ∧ r b a :=
pairwise_insert.trans <|
and_congr_right' <| forall₂_congr fun b hb => by simp [(ne_of_mem_of_not_mem hb ha).symm]
protected theorem Pairwise.insert (hs : s.Pairwise r) (h : ∀ b ∈ s, a ≠ b → r a b ∧ r b a) :
(insert a s).Pairwise r :=
pairwise_insert.2 ⟨hs, h⟩
theorem Pairwise.insert_of_not_mem (ha : a ∉ s) (hs : s.Pairwise r) (h : ∀ b ∈ s, r a b ∧ r b a) :
(insert a s).Pairwise r :=
(pairwise_insert_of_not_mem ha).2 ⟨hs, h⟩
theorem pairwise_insert_of_symmetric (hr : Symmetric r) :
(insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b := by
simp only [pairwise_insert, hr.iff a, and_self_iff]
theorem pairwise_insert_of_symmetric_of_not_mem (hr : Symmetric r) (ha : a ∉ s) :
(insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, r a b := by
simp only [pairwise_insert_of_not_mem ha, hr.iff a, and_self_iff]
theorem Pairwise.insert_of_symmetric (hs : s.Pairwise r) (hr : Symmetric r)
(h : ∀ b ∈ s, a ≠ b → r a b) : (insert a s).Pairwise r :=
(pairwise_insert_of_symmetric hr).2 ⟨hs, h⟩
@[deprecated Pairwise.insert_of_symmetric (since := "2025-03-19")]
theorem Pairwise.insert_of_symmetric_of_not_mem (hs : s.Pairwise r) (hr : Symmetric r) (ha : a ∉ s)
(h : ∀ b ∈ s, r a b) : (insert a s).Pairwise r :=
(pairwise_insert_of_symmetric_of_not_mem hr ha).2 ⟨hs, h⟩
theorem pairwise_pair : Set.Pairwise {a, b} r ↔ a ≠ b → r a b ∧ r b a := by simp [pairwise_insert]
theorem pairwise_pair_of_symmetric (hr : Symmetric r) : Set.Pairwise {a, b} r ↔ a ≠ b → r a b := by
simp [pairwise_insert_of_symmetric hr]
theorem pairwise_univ : (univ : Set α).Pairwise r ↔ Pairwise r := by
simp only [Set.Pairwise, Pairwise, mem_univ, forall_const]
@[simp]
theorem pairwise_bot_iff : s.Pairwise (⊥ : α → α → Prop) ↔ (s : Set α).Subsingleton :=
⟨fun h _a ha _b hb => h.eq ha hb id, fun h => h.pairwise _⟩
alias ⟨Pairwise.subsingleton, _⟩ := pairwise_bot_iff
/-- See also `Function.injective_iff_pairwise_ne` -/
lemma injOn_iff_pairwise_ne {s : Set ι} : InjOn f s ↔ s.Pairwise (f · ≠ f ·) := by
simp only [InjOn, Set.Pairwise, not_imp_not]
alias ⟨InjOn.pairwise_ne, _⟩ := injOn_iff_pairwise_ne
protected theorem Pairwise.image {s : Set ι} (h : s.Pairwise (r on f)) : (f '' s).Pairwise r :=
forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy hne ↦ h hx hy <| ne_of_apply_ne _ hne
/-- See also `Set.Pairwise.image`. -/
theorem InjOn.pairwise_image {s : Set ι} (h : s.InjOn f) :
(f '' s).Pairwise r ↔ s.Pairwise (r on f) := by
simp +contextual [h.eq_iff, Set.Pairwise]
lemma _root_.Pairwise.range_pairwise (hr : Pairwise (r on f)) : (Set.range f).Pairwise r :=
image_univ ▸ (pairwise_univ.mpr hr).image
end Set
end Pairwise
theorem pairwise_subtype_iff_pairwise_set (s : Set α) (r : α → α → Prop) :
(Pairwise fun (x : s) (y : s) => r x y) ↔ s.Pairwise r := by
simp only [Pairwise, Set.Pairwise, SetCoe.forall, Ne, Subtype.ext_iff, Subtype.coe_mk]
alias ⟨Pairwise.set_of_subtype, Set.Pairwise.subtype⟩ := pairwise_subtype_iff_pairwise_set
namespace Set
section PartialOrderBot
variable [PartialOrder α] [OrderBot α] {s t : Set ι} {f g : ι → α}
/-- A set is `PairwiseDisjoint` under `f`, if the images of any distinct two elements under `f`
are disjoint.
| `s.Pairwise Disjoint` is (definitionally) the same as `s.PairwiseDisjoint id`. We prefer the latter
in order to allow dot notation on `Set.PairwiseDisjoint`, even though the former unfolds more
nicely. -/
| Mathlib/Data/Set/Pairwise/Basic.lean | 222 | 224 |
/-
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]
| Mathlib/NumberTheory/Bernoulli.lean | 116 | 118 |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Reduced
import Mathlib.FieldTheory.KummerPolynomial
import Mathlib.FieldTheory.Separable
/-!
# Perfect fields and rings
In this file we define perfect fields, together with a generalisation to (commutative) rings in
prime characteristic.
## Main definitions / statements:
* `PerfectRing`: a ring of characteristic `p` (prime) is said to be perfect in the sense of Serre,
if its absolute Frobenius map `x ↦ xᵖ` is bijective.
* `PerfectField`: a field `K` is said to be perfect if every irreducible polynomial over `K` is
separable.
* `PerfectRing.toPerfectField`: a field that is perfect in the sense of Serre is a perfect field.
* `PerfectField.toPerfectRing`: a perfect field of characteristic `p` (prime) is perfect in the
sense of Serre.
* `PerfectField.ofCharZero`: all fields of characteristic zero are perfect.
* `PerfectField.ofFinite`: all finite fields are perfect.
* `PerfectField.separable_iff_squarefree`: a polynomial over a perfect field is separable iff
it is square-free.
* `Algebra.IsAlgebraic.isSeparable_of_perfectField`, `Algebra.IsAlgebraic.perfectField`:
if `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable,
and `L` is also a perfect field.
-/
open Function Polynomial
/-- A perfect ring of characteristic `p` (prime) in the sense of Serre.
NB: This is not related to the concept with the same name introduced by Bass (related to projective
covers of modules). -/
class PerfectRing (R : Type*) (p : ℕ) [CommSemiring R] [ExpChar R p] : Prop where
/-- A ring is perfect if the Frobenius map is bijective. -/
bijective_frobenius : Bijective <| frobenius R p
section PerfectRing
variable (R : Type*) (p m n : ℕ) [CommSemiring R] [ExpChar R p]
/-- For a reduced ring, surjectivity of the Frobenius map is a sufficient condition for perfection.
-/
lemma PerfectRing.ofSurjective (R : Type*) (p : ℕ) [CommRing R] [ExpChar R p]
[IsReduced R] (h : Surjective <| frobenius R p) : PerfectRing R p :=
⟨frobenius_inj R p, h⟩
instance PerfectRing.ofFiniteOfIsReduced (R : Type*) [CommRing R] [ExpChar R p]
[Finite R] [IsReduced R] : PerfectRing R p :=
ofSurjective _ _ <| Finite.surjective_of_injective (frobenius_inj R p)
variable [PerfectRing R p]
@[simp]
theorem bijective_frobenius : Bijective (frobenius R p) := PerfectRing.bijective_frobenius
theorem bijective_iterateFrobenius : Bijective (iterateFrobenius R p n) :=
coe_iterateFrobenius R p n ▸ (bijective_frobenius R p).iterate n
@[simp]
theorem injective_frobenius : Injective (frobenius R p) := (bijective_frobenius R p).1
@[simp]
theorem surjective_frobenius : Surjective (frobenius R p) := (bijective_frobenius R p).2
/-- The Frobenius automorphism for a perfect ring. -/
@[simps! apply]
noncomputable def frobeniusEquiv : R ≃+* R :=
RingEquiv.ofBijective (frobenius R p) PerfectRing.bijective_frobenius
@[simp]
theorem coe_frobeniusEquiv : ⇑(frobeniusEquiv R p) = frobenius R p := rfl
theorem frobeniusEquiv_def (x : R) : frobeniusEquiv R p x = x ^ p := rfl
/-- The iterated Frobenius automorphism for a perfect ring. -/
@[simps! apply]
noncomputable def iterateFrobeniusEquiv : R ≃+* R :=
RingEquiv.ofBijective (iterateFrobenius R p n) (bijective_iterateFrobenius R p n)
@[simp]
theorem coe_iterateFrobeniusEquiv : ⇑(iterateFrobeniusEquiv R p n) = iterateFrobenius R p n := rfl
theorem iterateFrobeniusEquiv_def (x : R) : iterateFrobeniusEquiv R p n x = x ^ p ^ n := rfl
theorem iterateFrobeniusEquiv_add_apply (x : R) : iterateFrobeniusEquiv R p (m + n) x =
iterateFrobeniusEquiv R p m (iterateFrobeniusEquiv R p n x) :=
iterateFrobenius_add_apply R p m n x
theorem iterateFrobeniusEquiv_add : iterateFrobeniusEquiv R p (m + n) =
(iterateFrobeniusEquiv R p n).trans (iterateFrobeniusEquiv R p m) :=
RingEquiv.ext (iterateFrobeniusEquiv_add_apply R p m n)
theorem iterateFrobeniusEquiv_symm_add_apply (x : R) : (iterateFrobeniusEquiv R p (m + n)).symm x =
(iterateFrobeniusEquiv R p m).symm ((iterateFrobeniusEquiv R p n).symm x) :=
(iterateFrobeniusEquiv R p (m + n)).injective <| by rw [RingEquiv.apply_symm_apply, add_comm,
iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply, RingEquiv.apply_symm_apply]
theorem iterateFrobeniusEquiv_symm_add : (iterateFrobeniusEquiv R p (m + n)).symm =
(iterateFrobeniusEquiv R p n).symm.trans (iterateFrobeniusEquiv R p m).symm :=
RingEquiv.ext (iterateFrobeniusEquiv_symm_add_apply R p m n)
theorem iterateFrobeniusEquiv_zero_apply (x : R) : iterateFrobeniusEquiv R p 0 x = x := by
rw [iterateFrobeniusEquiv_def, pow_zero, pow_one]
theorem iterateFrobeniusEquiv_one_apply (x : R) : iterateFrobeniusEquiv R p 1 x = x ^ p := by
rw [iterateFrobeniusEquiv_def, pow_one]
@[simp]
theorem iterateFrobeniusEquiv_zero : iterateFrobeniusEquiv R p 0 = RingEquiv.refl R :=
RingEquiv.ext (iterateFrobeniusEquiv_zero_apply R p)
@[simp]
theorem iterateFrobeniusEquiv_one : iterateFrobeniusEquiv R p 1 = frobeniusEquiv R p :=
RingEquiv.ext (iterateFrobeniusEquiv_one_apply R p)
theorem iterateFrobeniusEquiv_eq_pow : iterateFrobeniusEquiv R p n = frobeniusEquiv R p ^ n :=
DFunLike.ext' <| show _ = ⇑(RingAut.toPerm _ _) by
rw [map_pow, Equiv.Perm.coe_pow]; exact (pow_iterate p n).symm
theorem iterateFrobeniusEquiv_symm :
(iterateFrobeniusEquiv R p n).symm = (frobeniusEquiv R p).symm ^ n := by
rw [iterateFrobeniusEquiv_eq_pow]; exact (inv_pow _ _).symm
@[simp]
theorem frobeniusEquiv_symm_apply_frobenius (x : R) :
(frobeniusEquiv R p).symm (frobenius R p x) = x :=
leftInverse_surjInv PerfectRing.bijective_frobenius x
@[simp]
theorem frobenius_apply_frobeniusEquiv_symm (x : R) :
frobenius R p ((frobeniusEquiv R p).symm x) = x :=
surjInv_eq _ _
@[simp]
theorem frobenius_comp_frobeniusEquiv_symm :
(frobenius R p).comp (frobeniusEquiv R p).symm = RingHom.id R := by
ext; simp
@[simp]
theorem frobeniusEquiv_symm_comp_frobenius :
((frobeniusEquiv R p).symm : R →+* R).comp (frobenius R p) = RingHom.id R := by
ext; simp
@[simp]
theorem frobeniusEquiv_symm_pow_p (x : R) : ((frobeniusEquiv R p).symm x) ^ p = x :=
frobenius_apply_frobeniusEquiv_symm R p x
theorem injective_pow_p {x y : R} (h : x ^ p = y ^ p) : x = y := (frobeniusEquiv R p).injective h
lemma polynomial_expand_eq (f : R[X]) :
expand R p f = (f.map (frobeniusEquiv R p).symm) ^ p := by
rw [← (f.map (S := R) (frobeniusEquiv R p).symm).expand_char p, map_expand, map_map,
frobenius_comp_frobeniusEquiv_symm, map_id]
@[simp]
theorem not_irreducible_expand (R p) [CommSemiring R] [Fact p.Prime] [CharP R p] [PerfectRing R p]
(f : R[X]) : ¬ Irreducible (expand R p f) := by
rw [polynomial_expand_eq]
exact not_irreducible_pow (Fact.out : p.Prime).ne_one
instance instPerfectRingProd (S : Type*) [CommSemiring S] [ExpChar S p] [PerfectRing S p] :
PerfectRing (R × S) p where
bijective_frobenius := (bijective_frobenius R p).prodMap (bijective_frobenius S p)
end PerfectRing
/-- A perfect field.
See also `PerfectRing` for a generalisation in positive characteristic. -/
class PerfectField (K : Type*) [Field K] : Prop where
/-- A field is perfect if every irreducible polynomial is separable. -/
separable_of_irreducible : ∀ {f : K[X]}, Irreducible f → f.Separable
lemma PerfectRing.toPerfectField (K : Type*) (p : ℕ)
[Field K] [ExpChar K p] [PerfectRing K p] : PerfectField K := by
obtain hp | ⟨hp⟩ := ‹ExpChar K p›
· exact ⟨Irreducible.separable⟩
refine PerfectField.mk fun hf ↦ ?_
rcases separable_or p hf with h | ⟨-, g, -, rfl⟩
· assumption
· exfalso; revert hf; haveI := Fact.mk hp; simp
namespace PerfectField
variable {K : Type*} [Field K]
instance ofCharZero [CharZero K] : PerfectField K := ⟨Irreducible.separable⟩
instance ofFinite [Finite K] : PerfectField K := by
obtain ⟨p, _instP⟩ := CharP.exists K
have : Fact p.Prime := ⟨CharP.char_is_prime K p⟩
exact PerfectRing.toPerfectField K p
variable [PerfectField K]
/-- A perfect field of characteristic `p` (prime) is a perfect ring. -/
instance toPerfectRing (p : ℕ) [hp : ExpChar K p] : PerfectRing K p := by
refine PerfectRing.ofSurjective _ _ fun y ↦ ?_
rcases hp with _ | hp
· simp [frobenius]
rw [← not_forall_not]
apply mt (X_pow_sub_C_irreducible_of_prime hp)
apply mt separable_of_irreducible
simp [separable_def, isCoprime_zero_right, isUnit_iff_degree_eq_zero,
derivative_X_pow, degree_X_pow_sub_C hp.pos, hp.ne_zero]
theorem separable_iff_squarefree {g : K[X]} : g.Separable ↔ Squarefree g := by
refine ⟨Separable.squarefree, fun sqf ↦ isCoprime_of_irreducible_dvd (sqf.ne_zero ·.1) ?_⟩
rintro p (h : Irreducible p) ⟨q, rfl⟩ (dvd : p ∣ derivative (p * q))
replace dvd : p ∣ q := by
rw [derivative_mul, dvd_add_left (dvd_mul_right p _)] at dvd
exact (separable_of_irreducible h).dvd_of_dvd_mul_left dvd
exact (h.1 : ¬ IsUnit p) (sqf _ <| mul_dvd_mul_left _ dvd)
end PerfectField
/-- If `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable. -/
instance Algebra.IsAlgebraic.isSeparable_of_perfectField {K L : Type*} [Field K] [Field L]
[Algebra K L] [Algebra.IsAlgebraic K L] [PerfectField K] : Algebra.IsSeparable K L :=
⟨fun x ↦ PerfectField.separable_of_irreducible <|
minpoly.irreducible (Algebra.IsIntegral.isIntegral x)⟩
/-- If `L / K` is an algebraic extension, `K` is a perfect field, then so is `L`. -/
theorem Algebra.IsAlgebraic.perfectField {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsAlgebraic K L] [PerfectField K] : PerfectField L := ⟨fun {f} hf ↦ by
obtain ⟨_, _, hi, h⟩ := hf.exists_dvd_monic_irreducible_of_isIntegral (K := K)
exact (PerfectField.separable_of_irreducible hi).map |>.of_dvd h⟩
namespace Polynomial
variable {R : Type*} [CommRing R] [IsDomain R] (p n : ℕ) [ExpChar R p] (f : R[X])
open Multiset
theorem roots_expand_pow_map_iterateFrobenius_le :
(expand R (p ^ n) f).roots.map (iterateFrobenius R p n) ≤ p ^ n • f.roots := by
classical
refine le_iff_count.2 fun r ↦ ?_
by_cases h : ∃ s, r = s ^ p ^ n
· obtain ⟨s, rfl⟩ := h
simp_rw [count_nsmul, count_roots, ← rootMultiplicity_expand_pow, ← count_roots, count_map,
count_eq_card_filter_eq]
exact card_le_card (monotone_filter_right _ fun _ h ↦ iterateFrobenius_inj R p n h)
convert Nat.zero_le _
simp_rw [count_map, card_eq_zero]
exact ext' fun t ↦ count_zero t ▸ count_filter_of_neg fun h' ↦ h ⟨t, h'⟩
theorem roots_expand_map_frobenius_le :
(expand R p f).roots.map (frobenius R p) ≤ p • f.roots := by
rw [← iterateFrobenius_one]
convert ← roots_expand_pow_map_iterateFrobenius_le p 1 f <;> apply pow_one
theorem roots_expand_pow_image_iterateFrobenius_subset [DecidableEq R] :
(expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) ⊆ f.roots.toFinset := by
rw [Finset.image_toFinset, ← (roots f).toFinset_nsmul _ (expChar_pow_pos R p n).ne',
toFinset_subset]
exact subset_of_le (roots_expand_pow_map_iterateFrobenius_le p n f)
theorem roots_expand_image_frobenius_subset [DecidableEq R] :
(expand R p f).roots.toFinset.image (frobenius R p) ⊆ f.roots.toFinset := by
rw [← iterateFrobenius_one]
convert ← roots_expand_pow_image_iterateFrobenius_subset p 1 f
apply pow_one
section PerfectRing
variable {p n f}
variable [PerfectRing R p]
theorem roots_expand_pow :
(expand R (p ^ n) f).roots = p ^ n • f.roots.map (iterateFrobeniusEquiv R p n).symm := by
| classical
refine ext' fun r ↦ ?_
rw [count_roots, rootMultiplicity_expand_pow, ← count_roots, count_nsmul, count_map,
count_eq_card_filter_eq]; congr; ext
| Mathlib/FieldTheory/Perfect.lean | 280 | 283 |
/-
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
theorem edist_lt_top (hf : LipschitzWith K f) {x y : α} (h : edist x y ≠ ⊤) :
edist (f x) (f y) < ⊤ :=
(hf x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_lt_top h.lt_top
theorem mul_edist_le (h : LipschitzWith K f) (x y : α) :
(K⁻¹ : ℝ≥0∞) * edist (f x) (f y) ≤ edist x y := by
rw [mul_comm, ← div_eq_mul_inv]
exact ENNReal.div_le_of_le_mul' (h x y)
protected theorem of_edist_le (h : ∀ x y, edist (f x) (f y) ≤ edist x y) : LipschitzWith 1 f :=
fun x y => by simp only [ENNReal.coe_one, one_mul, h]
protected theorem weaken (hf : LipschitzWith K f) {K' : ℝ≥0} (h : K ≤ K') : LipschitzWith K' f :=
fun x y => le_trans (hf x y) <| mul_right_mono (ENNReal.coe_le_coe.2 h)
theorem ediam_image_le (hf : LipschitzWith K f) (s : Set α) :
EMetric.diam (f '' s) ≤ K * EMetric.diam s := by
apply EMetric.diam_le
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩
exact hf.edist_le_mul_of_le (EMetric.edist_le_diam_of_mem hx hy)
theorem edist_lt_of_edist_lt_div (hf : LipschitzWith K f) {x y : α} {d : ℝ≥0∞}
(h : edist x y < d / K) : edist (f x) (f y) < d :=
calc
edist (f x) (f y) ≤ K * edist x y := hf x y
_ < d := ENNReal.mul_lt_of_lt_div' h
/-- A Lipschitz function is uniformly continuous. -/
protected theorem uniformContinuous (hf : LipschitzWith K f) : UniformContinuous f :=
EMetric.uniformContinuous_iff.2 fun ε εpos =>
⟨ε / K, ENNReal.div_pos_iff.2 ⟨ne_of_gt εpos, ENNReal.coe_ne_top⟩, hf.edist_lt_of_edist_lt_div⟩
/-- A Lipschitz function is continuous. -/
protected theorem continuous (hf : LipschitzWith K f) : Continuous f :=
hf.uniformContinuous.continuous
|
/-- Constant functions are Lipschitz (with any constant). -/
| Mathlib/Topology/EMetricSpace/Lipschitz.lean | 185 | 186 |
/-
Copyright (c) 2021 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.Algebra.Group.Subgroup.Defs
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Star.Pi
import Mathlib.Algebra.Star.Rat
/-!
# Self-adjoint, skew-adjoint and normal elements of a star additive group
This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group,
as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`).
This includes, for instance, (skew-)Hermitian operators on Hilbert spaces.
We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies
`star x * x = x * star x`.
## Implementation notes
* When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural
`Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be
undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)`
and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass
`[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then
add a `[Module R₃ (selfAdjoint R)]` instance whenever we have
`[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define
`[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but
this typeclass would have the disadvantage of taking two type arguments.)
## TODO
* Define `IsSkewAdjoint` to match `IsSelfAdjoint`.
* Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R`
(similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is
invariant under it.
-/
open Function
variable {R A : Type*}
/-- An element is self-adjoint if it is equal to its star. -/
def IsSelfAdjoint [Star R] (x : R) : Prop :=
star x = x
/-- An element of a star monoid is normal if it commutes with its adjoint. -/
@[mk_iff]
class IsStarNormal [Mul R] [Star R] (x : R) : Prop where
/-- A normal element of a star monoid commutes with its adjoint. -/
star_comm_self : Commute (star x) x
export IsStarNormal (star_comm_self)
theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x :=
IsStarNormal.star_comm_self
namespace IsSelfAdjoint
-- named to match `Commute.allₓ`
/-- All elements are self-adjoint when `star` is trivial. -/
theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r :=
star_trivial _
theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x :=
hx
theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x :=
Iff.rfl
@[simp]
theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by
simpa only [IsSelfAdjoint, star_star] using eq_comm
@[simp]
theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by
simp only [IsSelfAdjoint, star_mul, star_star]
@[simp]
| theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by
simpa only [star_star] using star_mul_self (star x)
| Mathlib/Algebra/Star/SelfAdjoint.lean | 83 | 84 |
/-
Copyright (c) 2020 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard
-/
import Mathlib.RingTheory.AdicCompletion.Basic
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
import Mathlib.RingTheory.LocalRing.RingHom.Basic
import Mathlib.RingTheory.UniqueFactorizationDomain.Basic
import Mathlib.RingTheory.Valuation.PrimeMultiplicity
import Mathlib.RingTheory.Valuation.ValuationRing
/-!
# Discrete valuation rings
This file defines discrete valuation rings (DVRs) and develops a basic interface
for them.
## Important definitions
There are various definitions of a DVR in the literature; we define a DVR to be a local PID
which is not a field (the first definition in Wikipedia) and prove that this is equivalent
to being a PID with a unique non-zero prime ideal (the definition in Serre's
book "Local Fields").
Let R be an integral domain, assumed to be a principal ideal ring and a local ring.
* `IsDiscreteValuationRing R` : a predicate expressing that R is a DVR.
### Definitions
* `addVal R : AddValuation R PartENat` : the additive valuation on a DVR.
## Implementation notes
It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible.
We do not hence define `Uniformizer` at all, because we can use `Irreducible` instead.
## Tags
discrete valuation ring
-/
universe u
open Ideal IsLocalRing
/-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which
is not a field. -/
class IsDiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] : Prop
extends IsPrincipalIdealRing R, IsLocalRing R where
not_a_field' : maximalIdeal R ≠ ⊥
namespace IsDiscreteValuationRing
variable (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R]
theorem not_a_field : maximalIdeal R ≠ ⊥ :=
not_a_field'
/-- A discrete valuation ring `R` is not a field. -/
theorem not_isField : ¬IsField R :=
IsLocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R)
variable {R}
open PrincipalIdealRing
theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommSemiring R] [IsLocalRing R]
[IsDomain R] (ϖ : R) (hϖ : ϖ ≠ 0) (h : maximalIdeal R = Ideal.span {ϖ}) : Irreducible ϖ := by
have h2 : ¬IsUnit ϖ := show ϖ ∈ maximalIdeal R from h.symm ▸ Submodule.mem_span_singleton_self ϖ
refine ⟨h2, ?_⟩
intro a b hab
by_contra! h
obtain ⟨ha : a ∈ maximalIdeal R, hb : b ∈ maximalIdeal R⟩ := h
rw [h, mem_span_singleton'] at ha hb
rcases ha with ⟨a, rfl⟩
rcases hb with ⟨b, rfl⟩
rw [show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)) by ring] at hab
apply hϖ
apply eq_zero_of_mul_eq_self_right _ hab.symm
exact fun hh => h2 (isUnit_of_dvd_one ⟨_, hh.symm⟩)
/-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the
maximal ideal of `R`. -/
theorem irreducible_iff_uniformizer (ϖ : R) : Irreducible ϖ ↔ maximalIdeal R = Ideal.span {ϖ} :=
⟨fun hϖ => (eq_maximalIdeal (isMaximal_of_irreducible hϖ)).symm,
fun h => irreducible_of_span_eq_maximalIdeal ϖ
(fun e => not_a_field R <| by rwa [h, span_singleton_eq_bot]) h⟩
theorem _root_.Irreducible.maximalIdeal_eq {ϖ : R} (h : Irreducible ϖ) :
maximalIdeal R = Ideal.span {ϖ} :=
(irreducible_iff_uniformizer _).mp h
variable (R)
/-- Uniformizers exist in a DVR. -/
theorem exists_irreducible : ∃ ϖ : R, Irreducible ϖ := by
simp_rw [irreducible_iff_uniformizer]
exact (IsPrincipalIdealRing.principal <| maximalIdeal R).principal
/-- Uniformizers exist in a DVR. -/
theorem exists_prime : ∃ ϖ : R, Prime ϖ :=
(exists_irreducible R).imp fun _ => irreducible_iff_prime.1
/-- An integral domain is a DVR iff it's a PID with a unique non-zero prime ideal. -/
| theorem iff_pid_with_one_nonzero_prime (R : Type u) [CommRing R] [IsDomain R] :
IsDiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by
constructor
| Mathlib/RingTheory/DiscreteValuationRing/Basic.lean | 107 | 109 |
/-
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
· rw [← ofReal_one, ← ofReal_neg, Ne, ofReal_inj]
exact ht
end RpowCpow
open Nat
/-! ### Integral of `sin x ^ n` -/
theorem integral_sin_pow_aux :
(∫ x in a..b, sin x ^ (n + 2)) =
(sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b + (↑n + 1) * ∫ x in a..b, sin x ^ n) -
(↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by
let C := sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b
have h : ∀ α β γ : ℝ, β * α * γ * α = β * (α * α * γ) := fun α β γ => by ring
have hu : ∀ x ∈ [[a, b]],
HasDerivAt (fun y => sin y ^ (n + 1)) ((n + 1 : ℕ) * cos x * sin x ^ n) x :=
fun x _ => by simpa only [mul_right_comm] using (hasDerivAt_sin x).pow (n + 1)
have hv : ∀ x ∈ [[a, b]], HasDerivAt (-cos) (sin x) x := fun x _ => by
simpa only [neg_neg] using (hasDerivAt_cos x).neg
have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_
· calc
(∫ x in a..b, sin x ^ (n + 2)) = ∫ x in a..b, sin x ^ (n + 1) * sin x := by
simp only [_root_.pow_succ]
_ = C + (↑n + 1) * ∫ x in a..b, cos x ^ 2 * sin x ^ n := by simp [H, h, sq]; ring
_ = C + (↑n + 1) * ∫ x in a..b, sin x ^ n - sin x ^ (n + 2) := by
simp [cos_sq', sub_mul, ← pow_add, add_comm]
_ = (C + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by
rw [integral_sub, mul_sub, add_sub_assoc] <;>
apply Continuous.intervalIntegrable <;> fun_prop
all_goals apply Continuous.intervalIntegrable; fun_prop
/-- The reduction formula for the integral of `sin x ^ n` for any natural `n ≥ 2`. -/
theorem integral_sin_pow :
(∫ x in a..b, sin x ^ (n + 2)) =
(sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b) / (n + 2) +
(n + 1) / (n + 2) * ∫ x in a..b, sin x ^ n := by
field_simp
convert eq_sub_iff_add_eq.mp (integral_sin_pow_aux n) using 1
ring
@[simp]
theorem integral_sin_sq : ∫ x in a..b, sin x ^ 2 = (sin a * cos a - sin b * cos b + b - a) / 2 := by
field_simp [integral_sin_pow, add_sub_assoc]
theorem integral_sin_pow_odd :
(∫ x in (0)..π, sin x ^ (2 * n + 1)) = 2 * ∏ i ∈ range n, (2 * (i : ℝ) + 2) / (2 * i + 3) := by
induction' n with k ih; · norm_num
rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow]
norm_cast
simp [-cast_add, field_simps]
theorem integral_sin_pow_even :
(∫ x in (0)..π, sin x ^ (2 * n)) = π * ∏ i ∈ range n, (2 * (i : ℝ) + 1) / (2 * i + 2) := by
induction' n with k ih; · simp
rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow]
norm_cast
simp [-cast_add, field_simps]
theorem integral_sin_pow_pos : 0 < ∫ x in (0)..π, sin x ^ n := by
rcases even_or_odd' n with ⟨k, rfl | rfl⟩ <;>
simp only [integral_sin_pow_even, integral_sin_pow_odd] <;>
refine mul_pos (by norm_num [pi_pos]) (prod_pos fun n _ => div_pos ?_ ?_) <;>
norm_cast <;>
omega
theorem integral_sin_pow_succ_le : (∫ x in (0)..π, sin x ^ (n + 1)) ≤ ∫ x in (0)..π, sin x ^ n := by
let H x h := pow_le_pow_of_le_one (sin_nonneg_of_mem_Icc h) (sin_le_one x) (n.le_add_right 1)
refine integral_mono_on pi_pos.le ?_ ?_ H <;> exact (continuous_sin.pow _).intervalIntegrable 0 π
theorem integral_sin_pow_antitone : Antitone fun n : ℕ => ∫ x in (0)..π, sin x ^ n :=
antitone_nat_of_succ_le integral_sin_pow_succ_le
/-! ### Integral of `cos x ^ n` -/
theorem integral_cos_pow_aux :
(∫ x in a..b, cos x ^ (n + 2)) =
(cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a + (n + 1) * ∫ x in a..b, cos x ^ n) -
(n + 1) * ∫ x in a..b, cos x ^ (n + 2) := by
let C := cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a
have h : ∀ α β γ : ℝ, β * α * γ * α = β * (α * α * γ) := fun α β γ => by ring
have hu : ∀ x ∈ [[a, b]],
HasDerivAt (fun y => cos y ^ (n + 1)) (-(n + 1 : ℕ) * sin x * cos x ^ n) x :=
fun x _ => by
simpa only [mul_right_comm, neg_mul, mul_neg] using (hasDerivAt_cos x).pow (n + 1)
have hv : ∀ x ∈ [[a, b]], HasDerivAt sin (cos x) x := fun x _ => hasDerivAt_sin x
have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_
· calc
(∫ x in a..b, cos x ^ (n + 2)) = ∫ x in a..b, cos x ^ (n + 1) * cos x := by
simp only [_root_.pow_succ]
_ = C + (n + 1) * ∫ x in a..b, sin x ^ 2 * cos x ^ n := by simp [C, H, h, sq, -neg_add_rev]
_ = C + (n + 1) * ∫ x in a..b, cos x ^ n - cos x ^ (n + 2) := by
simp [sin_sq, sub_mul, ← pow_add, add_comm]
_ = (C + (n + 1) * ∫ x in a..b, cos x ^ n) - (n + 1) * ∫ x in a..b, cos x ^ (n + 2) := by
rw [integral_sub, mul_sub, add_sub_assoc] <;>
apply Continuous.intervalIntegrable <;> fun_prop
all_goals apply Continuous.intervalIntegrable; fun_prop
/-- The reduction formula for the integral of `cos x ^ n` for any natural `n ≥ 2`. -/
theorem integral_cos_pow :
(∫ x in a..b, cos x ^ (n + 2)) =
(cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a) / (n + 2) +
(n + 1) / (n + 2) * ∫ x in a..b, cos x ^ n := by
field_simp
convert eq_sub_iff_add_eq.mp (integral_cos_pow_aux n) using 1
ring
@[simp]
theorem integral_cos_sq : ∫ x in a..b, cos x ^ 2 = (cos b * sin b - cos a * sin a + b - a) / 2 := by
field_simp [integral_cos_pow, add_sub_assoc]
/-! ### Integral of `sin x ^ m * cos x ^ n` -/
/-- Simplification of the integral of `sin x ^ m * cos x ^ n`, case `n` is odd. -/
theorem integral_sin_pow_mul_cos_pow_odd (m n : ℕ) :
(∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)) = ∫ u in sin a..sin b, u^m * (↑1 - u ^ 2) ^ n :=
have hc : Continuous fun u : ℝ => u ^ m * (↑1 - u ^ 2) ^ n := by fun_prop
calc
(∫ x in a..b, sin x ^ m * cos x ^ (2 * n + 1)) =
∫ x in a..b, sin x ^ m * (↑1 - sin x ^ 2) ^ n * cos x := by
simp only [_root_.pow_zero, _root_.pow_succ, mul_assoc, pow_mul, one_mul]
congr! 5
rw [← sq, ← sq, cos_sq']
_ = ∫ u in sin a..sin b, u ^ m * (1 - u ^ 2) ^ n := by
| -- Note(kmill): Didn't need `by exact`, but elaboration order seems to matter here.
exact integral_comp_mul_deriv (fun x _ => hasDerivAt_sin x) continuousOn_cos hc
/-- The integral of `sin x * cos x`, given in terms of sin².
See `integral_sin_mul_cos₂` below for the integral given in terms of cos². -/
@[simp]
theorem integral_sin_mul_cos₁ : ∫ x in a..b, sin x * cos x = (sin b ^ 2 - sin a ^ 2) / 2 := by
| Mathlib/Analysis/SpecialFunctions/Integrals.lean | 742 | 748 |
/-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang, Yury Kudryashov
-/
import Mathlib.Data.Fintype.Option
import Mathlib.Topology.Homeomorph.Lemmas
import Mathlib.Topology.Sets.Opens
/-!
# The OnePoint Compactification
We construct the OnePoint compactification (the one-point compactification) of an arbitrary
topological space `X` and prove some properties inherited from `X`.
## Main definitions
* `OnePoint`: the OnePoint compactification, we use coercion for the canonical embedding
`X → OnePoint X`; when `X` is already compact, the compactification adds an isolated point
to the space.
* `OnePoint.infty`: the extra point
## Main results
* The topological structure of `OnePoint X`
* The connectedness of `OnePoint X` for a noncompact, preconnected `X`
* `OnePoint X` is `T₀` for a T₀ space `X`
* `OnePoint X` is `T₁` for a T₁ space `X`
* `OnePoint X` is normal if `X` is a locally compact Hausdorff space
## Tags
one-point compactification, Alexandroff compactification, compactness
-/
open Set Filter Topology
/-!
### Definition and basic properties
In this section we define `OnePoint X` to be the disjoint union of `X` and `∞`, implemented as
`Option X`. Then we restate some lemmas about `Option X` for `OnePoint X`.
-/
variable {X Y : Type*}
/-- The OnePoint extension of an arbitrary topological space `X` -/
def OnePoint (X : Type*) :=
Option X
/-- The repr uses the notation from the `OnePoint` locale. -/
instance [Repr X] : Repr (OnePoint X) :=
⟨fun o _ =>
match o with
| none => "∞"
| some a => "↑" ++ repr a⟩
namespace OnePoint
/-- The point at infinity -/
@[match_pattern] def infty : OnePoint X := none
@[inherit_doc]
scoped notation "∞" => OnePoint.infty
/-- Coercion from `X` to `OnePoint X`. -/
@[coe, match_pattern] def some : X → OnePoint X := Option.some
@[simp]
lemma some_eq_iff (x₁ x₂ : X) : (some x₁ = some x₂) ↔ (x₁ = x₂) := by
rw [iff_eq_eq]
exact Option.some.injEq x₁ x₂
instance : CoeTC X (OnePoint X) := ⟨some⟩
instance : Inhabited (OnePoint X) := ⟨∞⟩
protected lemma «forall» {p : OnePoint X → Prop} :
(∀ (x : OnePoint X), p x) ↔ p ∞ ∧ ∀ (x : X), p x :=
Option.forall
protected lemma «exists» {p : OnePoint X → Prop} :
(∃ x, p x) ↔ p ∞ ∨ ∃ (x : X), p x :=
Option.exists
instance [Fintype X] : Fintype (OnePoint X) :=
inferInstanceAs (Fintype (Option X))
instance infinite [Infinite X] : Infinite (OnePoint X) :=
inferInstanceAs (Infinite (Option X))
theorem coe_injective : Function.Injective ((↑) : X → OnePoint X) :=
Option.some_injective X
@[norm_cast]
theorem coe_eq_coe {x y : X} : (x : OnePoint X) = y ↔ x = y :=
coe_injective.eq_iff
@[simp]
theorem coe_ne_infty (x : X) : (x : OnePoint X) ≠ ∞ :=
nofun
@[simp]
theorem infty_ne_coe (x : X) : ∞ ≠ (x : OnePoint X) :=
nofun
/-- Recursor for `OnePoint` using the preferred forms `∞` and `↑x`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
protected def rec {C : OnePoint X → Sort*} (infty : C ∞) (coe : ∀ x : X, C x) :
∀ z : OnePoint X, C z
| ∞ => infty
| (x : X) => coe x
/-- An elimination principle for `OnePoint`. -/
@[inline] protected def elim : OnePoint X → Y → (X → Y) → Y := Option.elim
@[simp] theorem elim_infty (y : Y) (f : X → Y) : ∞.elim y f = y := rfl
@[simp] theorem elim_some (y : Y) (f : X → Y) (x : X) : (some x).elim y f = f x := rfl
theorem isCompl_range_coe_infty : IsCompl (range ((↑) : X → OnePoint X)) {∞} :=
isCompl_range_some_none X
theorem range_coe_union_infty : range ((↑) : X → OnePoint X) ∪ {∞} = univ :=
range_some_union_none X
@[simp]
theorem insert_infty_range_coe : insert ∞ (range (@some X)) = univ :=
insert_none_range_some _
@[simp]
theorem range_coe_inter_infty : range ((↑) : X → OnePoint X) ∩ {∞} = ∅ :=
range_some_inter_none X
@[simp]
theorem compl_range_coe : (range ((↑) : X → OnePoint X))ᶜ = {∞} :=
compl_range_some X
theorem compl_infty : ({∞}ᶜ : Set (OnePoint X)) = range ((↑) : X → OnePoint X) :=
(@isCompl_range_coe_infty X).symm.compl_eq
theorem compl_image_coe (s : Set X) : ((↑) '' s : Set (OnePoint X))ᶜ = (↑) '' sᶜ ∪ {∞} := by
rw [coe_injective.compl_image_eq, compl_range_coe]
theorem ne_infty_iff_exists {x : OnePoint X} : x ≠ ∞ ↔ ∃ y : X, (y : OnePoint X) = x := by
induction x using OnePoint.rec <;> simp
instance canLift : CanLift (OnePoint X) X (↑) fun x => x ≠ ∞ :=
WithTop.canLift
theorem not_mem_range_coe_iff {x : OnePoint X} : x ∉ range some ↔ x = ∞ := by
rw [← mem_compl_iff, compl_range_coe, mem_singleton_iff]
theorem infty_not_mem_range_coe : ∞ ∉ range ((↑) : X → OnePoint X) :=
not_mem_range_coe_iff.2 rfl
theorem infty_not_mem_image_coe {s : Set X} : ∞ ∉ ((↑) : X → OnePoint X) '' s :=
not_mem_subset (image_subset_range _ _) infty_not_mem_range_coe
@[simp]
theorem coe_preimage_infty : ((↑) : X → OnePoint X) ⁻¹' {∞} = ∅ := by
ext
simp
/-- Extend a map `f : X → Y` to a map `OnePoint X → OnePoint Y`
by sending infinity to infinity. -/
protected def map (f : X → Y) : OnePoint X → OnePoint Y :=
Option.map f
@[simp] theorem map_infty (f : X → Y) : OnePoint.map f ∞ = ∞ := rfl
@[simp] theorem map_some (f : X → Y) (x : X) : (x : OnePoint X).map f = f x := rfl
@[simp] theorem map_id : OnePoint.map (id : X → X) = id := Option.map_id
theorem map_comp {Z : Type*} (f : Y → Z) (g : X → Y) :
OnePoint.map (f ∘ g) = OnePoint.map f ∘ OnePoint.map g :=
(Option.map_comp_map _ _).symm
/-!
### Topological space structure on `OnePoint X`
We define a topological space structure on `OnePoint X` so that `s` is open if and only if
* `(↑) ⁻¹' s` is open in `X`;
* if `∞ ∈ s`, then `((↑) ⁻¹' s)ᶜ` is compact.
Then we reformulate this definition in a few different ways, and prove that
`(↑) : X → OnePoint X` is an open embedding. If `X` is not a compact space, then we also prove
that `(↑)` has dense range, so it is a dense embedding.
-/
variable [TopologicalSpace X]
instance : TopologicalSpace (OnePoint X) where
IsOpen s := (∞ ∈ s → IsCompact (((↑) : X → OnePoint X) ⁻¹' s)ᶜ) ∧
IsOpen (((↑) : X → OnePoint X) ⁻¹' s)
isOpen_univ := by simp
isOpen_inter s t := by
rintro ⟨hms, hs⟩ ⟨hmt, ht⟩
refine ⟨?_, hs.inter ht⟩
rintro ⟨hms', hmt'⟩
simpa [compl_inter] using (hms hms').union (hmt hmt')
isOpen_sUnion S ho := by
suffices IsOpen ((↑) ⁻¹' ⋃₀ S : Set X) by
refine ⟨?_, this⟩
rintro ⟨s, hsS : s ∈ S, hs : ∞ ∈ s⟩
refine IsCompact.of_isClosed_subset ((ho s hsS).1 hs) this.isClosed_compl ?_
exact compl_subset_compl.mpr (preimage_mono <| subset_sUnion_of_mem hsS)
rw [preimage_sUnion]
exact isOpen_biUnion fun s hs => (ho s hs).2
variable {s : Set (OnePoint X)}
theorem isOpen_def :
IsOpen s ↔ (∞ ∈ s → IsCompact ((↑) ⁻¹' s : Set X)ᶜ) ∧ IsOpen ((↑) ⁻¹' s : Set X) :=
Iff.rfl
theorem isOpen_iff_of_mem' (h : ∞ ∈ s) :
IsOpen s ↔ IsCompact ((↑) ⁻¹' s : Set X)ᶜ ∧ IsOpen ((↑) ⁻¹' s : Set X) := by
simp [isOpen_def, h]
theorem isOpen_iff_of_mem (h : ∞ ∈ s) :
IsOpen s ↔ IsClosed ((↑) ⁻¹' s : Set X)ᶜ ∧ IsCompact ((↑) ⁻¹' s : Set X)ᶜ := by
simp only [isOpen_iff_of_mem' h, isClosed_compl_iff, and_comm]
theorem isOpen_iff_of_not_mem (h : ∞ ∉ s) : IsOpen s ↔ IsOpen ((↑) ⁻¹' s : Set X) := by
simp [isOpen_def, h]
theorem isClosed_iff_of_mem (h : ∞ ∈ s) : IsClosed s ↔ IsClosed ((↑) ⁻¹' s : Set X) := by
have : ∞ ∉ sᶜ := fun H => H h
rw [← isOpen_compl_iff, isOpen_iff_of_not_mem this, ← isOpen_compl_iff, preimage_compl]
theorem isClosed_iff_of_not_mem (h : ∞ ∉ s) :
IsClosed s ↔ IsClosed ((↑) ⁻¹' s : Set X) ∧ IsCompact ((↑) ⁻¹' s : Set X) := by
rw [← isOpen_compl_iff, isOpen_iff_of_mem (mem_compl h), ← preimage_compl, compl_compl]
@[simp]
theorem isOpen_image_coe {s : Set X} : IsOpen ((↑) '' s : Set (OnePoint X)) ↔ IsOpen s := by
rw [isOpen_iff_of_not_mem infty_not_mem_image_coe, preimage_image_eq _ coe_injective]
theorem isOpen_compl_image_coe {s : Set X} :
IsOpen ((↑) '' s : Set (OnePoint X))ᶜ ↔ IsClosed s ∧ IsCompact s := by
rw [isOpen_iff_of_mem, ← preimage_compl, compl_compl, preimage_image_eq _ coe_injective]
exact infty_not_mem_image_coe
@[simp]
theorem isClosed_image_coe {s : Set X} :
IsClosed ((↑) '' s : Set (OnePoint X)) ↔ IsClosed s ∧ IsCompact s := by
rw [← isOpen_compl_iff, isOpen_compl_image_coe]
/-- An open set in `OnePoint X` constructed from a closed compact set in `X` -/
def opensOfCompl (s : Set X) (h₁ : IsClosed s) (h₂ : IsCompact s) :
| TopologicalSpace.Opens (OnePoint X) :=
⟨((↑) '' s)ᶜ, isOpen_compl_image_coe.2 ⟨h₁, h₂⟩⟩
| Mathlib/Topology/Compactification/OnePoint.lean | 255 | 257 |
/-
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, Chris Hughes, Anne Baanen, Junyan Xu
-/
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.RankNullity
/-!
# Dimension of vector spaces
In this file we provide results about `Module.rank` and `Module.finrank` of vector spaces
over division rings.
## Main statements
For vector spaces (i.e. modules over a field), we have
* `rank_quotient_add_rank_of_divisionRing`: if `V₁` is a submodule of `V`, then
`Module.rank (V/V₁) + Module.rank V₁ = Module.rank V`.
* `rank_range_add_rank_ker`: the rank-nullity theorem.
See also `Mathlib.LinearAlgebra.Dimension.ErdosKaplansky` for the Erdős-Kaplansky theorem.
-/
noncomputable section
universe u₀ u v v' v'' u₁' w w'
variable {K R : Type u} {V V₁ V₂ V₃ : Type v} {V' V'₁ : Type v'} {V'' : Type v''}
variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*}
open Cardinal Basis Submodule Function Set
section Module
section DivisionRing
variable [DivisionRing K]
variable [AddCommGroup V] [Module K V]
variable [AddCommGroup V'] [Module K V']
variable [AddCommGroup V₁] [Module K V₁]
/-- If a vector space has a finite dimension, the index set of `Basis.ofVectorSpace` is finite. -/
theorem Basis.finite_ofVectorSpaceIndex_of_rank_lt_aleph0 (h : Module.rank K V < ℵ₀) :
(Basis.ofVectorSpaceIndex K V).Finite :=
finite_def.2 <| (Basis.ofVectorSpace K V).nonempty_fintype_index_of_rank_lt_aleph0 h
/-- Also see `rank_quotient_add_rank`. -/
theorem rank_quotient_add_rank_of_divisionRing (p : Submodule K V) :
Module.rank K (V ⧸ p) + Module.rank K p = Module.rank K V := by
classical
let ⟨f⟩ := quotient_prod_linearEquiv p
exact rank_prod'.symm.trans f.rank_eq
instance DivisionRing.hasRankNullity : HasRankNullity.{u₀} K where
rank_quotient_add_rank := rank_quotient_add_rank_of_divisionRing
exists_set_linearIndependent V _ _ := by
let b := Module.Free.chooseBasis K V
refine ⟨range b, ?_, b.linearIndependent.linearIndepOn_id⟩
rw [← lift_injective.eq_iff, mk_range_eq_of_injective b.injective,
Module.Free.rank_eq_card_chooseBasisIndex]
section
variable [AddCommGroup V₂] [Module K V₂]
variable [AddCommGroup V₃] [Module K V₃]
open LinearMap
/-- This is mostly an auxiliary lemma for `Submodule.rank_sup_add_rank_inf_eq`. -/
theorem rank_add_rank_split (db : V₂ →ₗ[K] V) (eb : V₃ →ₗ[K] V) (cd : V₁ →ₗ[K] V₂)
(ce : V₁ →ₗ[K] V₃) (hde : ⊤ ≤ LinearMap.range db ⊔ LinearMap.range eb) (hgd : ker cd = ⊥)
(eq : db.comp cd = eb.comp ce) (eq₂ : ∀ d e, db d = eb e → ∃ c, cd c = d ∧ ce c = e) :
Module.rank K V + Module.rank K V₁ = Module.rank K V₂ + Module.rank K V₃ := by
have hf : Surjective (coprod db eb) := by
rwa [← range_eq_top, range_coprod, eq_top_iff]
conv =>
rhs
rw [← rank_prod', rank_eq_of_surjective hf]
congr 1
apply LinearEquiv.rank_eq
let L : V₁ →ₗ[K] ker (coprod db eb) :=
LinearMap.codRestrict _ (prod cd (-ce)) <| by
simpa [add_eq_zero_iff_eq_neg] using LinearMap.ext_iff.1 eq
refine LinearEquiv.ofBijective L ⟨?_, ?_⟩
· rw [← ker_eq_bot, ker_codRestrict, ker_prod, hgd, bot_inf_eq]
· rw [← range_eq_top, eq_top_iff, range_codRestrict, ← map_le_iff_le_comap,
Submodule.map_top, range_subtype]
rintro ⟨d, e⟩
have h := eq₂ d (-e)
simp only [add_eq_zero_iff_eq_neg, LinearMap.prod_apply, mem_ker, SetLike.mem_coe,
Prod.mk_inj, coprod_apply, map_neg, neg_apply, LinearMap.mem_range, Pi.prod] at h ⊢
intro hde
rcases h hde with ⟨c, h₁, h₂⟩
refine ⟨c, h₁, ?_⟩
rw [h₂, _root_.neg_neg]
end
end DivisionRing
end Module
section Basis
open Module
variable [DivisionRing K] [AddCommGroup V] [Module K V]
theorem linearIndependent_of_top_le_span_of_card_eq_finrank {ι : Type*} [Fintype ι] {b : ι → V}
(spans : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
LinearIndependent K b :=
linearIndependent_iff'.mpr fun s g dependent i i_mem_s => by
classical
by_contra gx_ne_zero
-- We'll derive a contradiction by showing `b '' (univ \ {i})` of cardinality `n - 1`
-- spans a vector space of dimension `n`.
refine not_le_of_gt (span_lt_top_of_card_lt_finrank
(show (b '' (Set.univ \ {i})).toFinset.card < finrank K V from ?_)) ?_
· calc
(b '' (Set.univ \ {i})).toFinset.card = ((Set.univ \ {i}).toFinset.image b).card := by
rw [Set.toFinset_card, Fintype.card_ofFinset]
_ ≤ (Set.univ \ {i}).toFinset.card := Finset.card_image_le
_ = (Finset.univ.erase i).card := (congr_arg Finset.card (Finset.ext (by simp [and_comm])))
_ < Finset.univ.card := Finset.card_erase_lt_of_mem (Finset.mem_univ i)
_ = finrank K V := card_eq
-- We already have that `b '' univ` spans the whole space,
-- so we only need to show that the span of `b '' (univ \ {i})` contains each `b j`.
refine spans.trans (span_le.mpr ?_)
rintro _ ⟨j, rfl, rfl⟩
-- The case that `j ≠ i` is easy because `b j ∈ b '' (univ \ {i})`.
by_cases j_eq : j = i
swap
· refine subset_span ⟨j, (Set.mem_diff _).mpr ⟨Set.mem_univ _, ?_⟩, rfl⟩
exact mt Set.mem_singleton_iff.mp j_eq
-- To show `b i ∈ span (b '' (univ \ {i}))`, we use that it's a weighted sum
-- of the other `b j`s.
rw [j_eq, SetLike.mem_coe, show b i = -((g i)⁻¹ • (s.erase i).sum fun j => g j • b j) from _]
· refine neg_mem (smul_mem _ _ (sum_mem fun k hk => ?_))
obtain ⟨k_ne_i, _⟩ := Finset.mem_erase.mp hk
refine smul_mem _ _ (subset_span ⟨k, ?_, rfl⟩)
simp_all only [Set.mem_univ, Set.mem_diff, Set.mem_singleton_iff, and_self, not_false_eq_true]
-- To show `b i` is a weighted sum of the other `b j`s, we'll rewrite this sum
-- to have the form of the assumption `dependent`.
apply eq_neg_of_add_eq_zero_left
calc
(b i + (g i)⁻¹ • (s.erase i).sum fun j => g j • b j) =
(g i)⁻¹ • (g i • b i + (s.erase i).sum fun j => g j • b j) := by
rw [smul_add, ← mul_smul, inv_mul_cancel₀ gx_ne_zero, one_smul]
_ = (g i)⁻¹ • (0 : V) := congr_arg _ ?_
_ = 0 := smul_zero _
-- And then it's just a bit of manipulation with finite sums.
rwa [← Finset.insert_erase i_mem_s, Finset.sum_insert (Finset.not_mem_erase _ _)] at dependent
/-- A finite family of vectors is linearly independent if and only if
its cardinality equals the dimension of its span. -/
theorem linearIndependent_iff_card_eq_finrank_span {ι : Type*} [Fintype ι] {b : ι → V} :
LinearIndependent K b ↔ Fintype.card ι = (Set.range b).finrank K := by
constructor
· intro h
exact (finrank_span_eq_card h).symm
· intro hc
let f := Submodule.subtype (span K (Set.range b))
let b' : ι → span K (Set.range b) := fun i =>
⟨b i, mem_span.2 fun p hp => hp (Set.mem_range_self _)⟩
have hs : ⊤ ≤ span K (Set.range b') := by
intro x
have h : span K (f '' Set.range b') = map f (span K (Set.range b')) := span_image f
have hf : f '' Set.range b' = Set.range b := by
ext x
simp [f, b', Set.mem_image, Set.mem_range]
rw [hf] at h
have hx : (x : V) ∈ span K (Set.range b) := x.property
simp_rw [h] at hx
simpa [f, mem_map] using hx
have hi : LinearMap.ker f = ⊥ := ker_subtype _
convert (linearIndependent_of_top_le_span_of_card_eq_finrank hs hc).map' _ hi
theorem linearIndependent_iff_card_le_finrank_span {ι : Type*} [Fintype ι] {b : ι → V} :
LinearIndependent K b ↔ Fintype.card ι ≤ (Set.range b).finrank K := by
rw [linearIndependent_iff_card_eq_finrank_span, (finrank_range_le_card _).le_iff_eq]
/-- A family of `finrank K V` vectors forms a basis if they span the whole space. -/
noncomputable def basisOfTopLeSpanOfCardEqFinrank {ι : Type*} [Fintype ι] (b : ι → V)
(le_span : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) : Basis ι K V :=
Basis.mk (linearIndependent_of_top_le_span_of_card_eq_finrank le_span card_eq) le_span
@[simp]
theorem coe_basisOfTopLeSpanOfCardEqFinrank {ι : Type*} [Fintype ι] (b : ι → V)
(le_span : ⊤ ≤ span K (Set.range b)) (card_eq : Fintype.card ι = finrank K V) :
⇑(basisOfTopLeSpanOfCardEqFinrank b le_span card_eq) = b :=
Basis.coe_mk _ _
/-- A finset of `finrank K V` vectors forms a basis if they span the whole space. -/
@[simps! repr_apply]
noncomputable def finsetBasisOfTopLeSpanOfCardEqFinrank {s : Finset V}
(le_span : ⊤ ≤ span K (s : Set V)) (card_eq : s.card = finrank K V) : Basis {x // x ∈ s} K V :=
basisOfTopLeSpanOfCardEqFinrank ((↑) : ↥(s : Set V) → V)
((@Subtype.range_coe_subtype _ fun x => x ∈ s).symm ▸ le_span)
(_root_.trans (Fintype.card_coe _) card_eq)
/-- A set of `finrank K V` vectors forms a basis if they span the whole space. -/
@[simps! repr_apply]
noncomputable def setBasisOfTopLeSpanOfCardEqFinrank {s : Set V} [Fintype s]
(le_span : ⊤ ≤ span K s) (card_eq : s.toFinset.card = finrank K V) : Basis s K V :=
basisOfTopLeSpanOfCardEqFinrank ((↑) : s → V) ((@Subtype.range_coe_subtype _ s).symm ▸ le_span)
(_root_.trans s.toFinset_card.symm card_eq)
end Basis
| Mathlib/LinearAlgebra/Dimension/DivisionRing.lean | 332 | 336 | |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot, Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/IntervalIntegral.lean | 1,154 | 1,157 | |
/-
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.Data.Vector.Defs
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.Scan
import Mathlib.Control.Applicative
import Mathlib.Control.Traversable.Basic
import Mathlib.Algebra.BigOperators.Group.List.Basic
/-!
# Additional theorems and definitions about the `Vector` type
This file introduces the infix notation `::ᵥ` for `Vector.cons`.
-/
universe u
variable {α β γ σ φ : Type*} {m n : ℕ}
namespace List.Vector
@[inherit_doc]
infixr:67 " ::ᵥ " => Vector.cons
attribute [simp] head_cons tail_cons
instance [Inhabited α] : Inhabited (Vector α n) :=
⟨ofFn default⟩
theorem toList_injective : Function.Injective (@toList α n) :=
Subtype.val_injective
/-- Two `v w : Vector α n` are equal iff they are equal at every single index. -/
@[ext]
theorem ext : ∀ {v w : Vector α n} (_ : ∀ m : Fin n, Vector.get v m = Vector.get w m), v = w
| ⟨v, hv⟩, ⟨w, hw⟩, h =>
Subtype.eq (List.ext_get (by rw [hv, hw]) fun m hm _ => h ⟨m, hv ▸ hm⟩)
/-- The empty `Vector` is a `Subsingleton`. -/
instance zero_subsingleton : Subsingleton (Vector α 0) :=
⟨fun _ _ => Vector.ext fun m => Fin.elim0 m⟩
@[simp]
theorem cons_val (a : α) : ∀ v : Vector α n, (a ::ᵥ v).val = a :: v.val
| ⟨_, _⟩ => rfl
theorem eq_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) :
v = a ::ᵥ v' ↔ v.head = a ∧ v.tail = v' :=
⟨fun h => h.symm ▸ ⟨head_cons a v', tail_cons a v'⟩, fun h =>
_root_.trans (cons_head_tail v).symm (by rw [h.1, h.2])⟩
theorem ne_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) :
v ≠ a ::ᵥ v' ↔ v.head ≠ a ∨ v.tail ≠ v' := by rw [Ne, eq_cons_iff a v v', not_and_or]
theorem exists_eq_cons (v : Vector α n.succ) : ∃ (a : α) (as : Vector α n), v = a ::ᵥ as :=
⟨v.head, v.tail, (eq_cons_iff v.head v v.tail).2 ⟨rfl, rfl⟩⟩
@[simp]
theorem toList_ofFn : ∀ {n} (f : Fin n → α), toList (ofFn f) = List.ofFn f
| 0, f => by rw [ofFn, List.ofFn_zero, toList, nil]
| n + 1, f => by rw [ofFn, List.ofFn_succ, toList_cons, toList_ofFn]
@[simp]
theorem mk_toList : ∀ (v : Vector α n) (h), (⟨toList v, h⟩ : Vector α n) = v
| ⟨_, _⟩, _ => rfl
@[simp] theorem length_val (v : Vector α n) : v.val.length = n := v.2
@[simp]
theorem pmap_cons {p : α → Prop} (f : (a : α) → p a → β) (a : α) (v : Vector α n)
(hp : ∀ x ∈ (cons a v).toList, p x) :
(cons a v).pmap f hp = cons (f a (by
simp only [Nat.succ_eq_add_one, toList_cons, List.mem_cons, forall_eq_or_imp] at hp
exact hp.1))
(v.pmap f (by
simp only [Nat.succ_eq_add_one, toList_cons, List.mem_cons, forall_eq_or_imp] at hp
exact hp.2)) := rfl
/-- Opposite direction of `Vector.pmap_cons` -/
theorem pmap_cons' {p : α → Prop} (f : (a : α) → p a → β) (a : α) (v : Vector α n)
(ha : p a) (hp : ∀ x ∈ v.toList, p x) :
cons (f a ha) (v.pmap f hp) = (cons a v).pmap f (by simpa [ha]) := rfl
@[simp]
theorem toList_map {β : Type*} (v : Vector α n) (f : α → β) :
(v.map f).toList = v.toList.map f := by cases v; rfl
@[simp]
theorem head_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).head = f v.head := by
obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v
rw [h, map_cons, head_cons, head_cons]
@[simp]
theorem tail_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) :
(v.map f).tail = v.tail.map f := by
obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v
rw [h, map_cons, tail_cons, tail_cons]
@[simp]
theorem getElem_map {β : Type*} (v : Vector α n) (f : α → β) {i : ℕ} (hi : i < n) :
(v.map f)[i] = f v[i] := by
simp only [getElem_def, toList_map, List.getElem_map]
@[simp]
theorem toList_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α n)
(hp : ∀ x ∈ v.toList, p x) :
(v.pmap f hp).toList = v.toList.pmap f hp := by cases v; rfl
@[simp]
theorem head_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α (n + 1))
(hp : ∀ x ∈ v.toList, p x) :
(v.pmap f hp).head = f v.head (hp _ <| by
rw [← cons_head_tail v, toList_cons, head_cons, List.mem_cons]; exact .inl rfl) := by
obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v
simp_rw [h, pmap_cons, head_cons]
@[simp]
theorem tail_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α (n + 1))
(hp : ∀ x ∈ v.toList, p x) :
(v.pmap f hp).tail = v.tail.pmap f (fun x hx ↦ hp _ <| by
rw [← cons_head_tail v, toList_cons, List.mem_cons]; exact .inr hx) := by
obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v
simp_rw [h, pmap_cons, tail_cons]
@[simp]
theorem getElem_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α n)
(hp : ∀ x ∈ v.toList, p x) {i : ℕ} (hi : i < n) :
(v.pmap f hp)[i] = f v[i] (hp _ (by simp [getElem_def, List.getElem_mem])) := by
simp only [getElem_def, toList_pmap, List.getElem_pmap]
theorem get_eq_get_toList (v : Vector α n) (i : Fin n) :
v.get i = v.toList.get (Fin.cast v.toList_length.symm i) :=
rfl
@[deprecated (since := "2024-12-20")]
alias get_eq_get := get_eq_get_toList
@[simp]
| theorem get_replicate (a : α) (i : Fin n) : (Vector.replicate n a).get i = a := by
apply List.getElem_replicate
@[simp]
| Mathlib/Data/Vector/Basic.lean | 144 | 147 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.PartialHomeomorph
import Mathlib.Topology.Connected.LocPathConnected
/-!
# Charted spaces
A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean
half-space for manifolds with boundaries, or an infinite dimensional vector space for more general
notions of manifolds), i.e., the manifold is covered by open subsets on which there are local
homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth
maps.
In this file, we introduce a general framework describing these notions, where the model space is an
arbitrary topological space. We avoid the word *manifold*, which should be reserved for the
situation where the model space is a (subset of a) vector space, and use the terminology
*charted space* instead.
If the changes of charts satisfy some additional property (for instance if they are smooth), then
`M` inherits additional structure (it makes sense to talk about smooth manifolds). There are
therefore two different ingredients in a charted space:
* the set of charts, which is data
* the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop.
We separate these two parts in the definition: the charted space structure is just the set of
charts, and then the different smoothness requirements (smooth manifold, orientable manifold,
contact manifold, and so on) are additional properties of these charts. These properties are
formalized through the notion of structure groupoid, i.e., a set of partial homeomorphisms stable
under composition and inverse, to which the change of coordinates should belong.
## Main definitions
* `StructureGroupoid H` : a subset of partial homeomorphisms of `H` stable under composition,
inverse and restriction (ex: partial diffeomorphisms).
* `continuousGroupoid H` : the groupoid of all partial homeomorphisms of `H`.
* `ChartedSpace H M` : charted space structure on `M` modelled on `H`, given by an atlas of
partial homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class.
* `HasGroupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space
modelled on `H`, require that all coordinate changes belong to `G`. This is a type class.
* `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted
space structure, i.e., the set of charts.
* `G.maximalAtlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a
structure groupoid, one can consider all the partial homeomorphisms from `M` to `H` such that
changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the
maximal atlas (for the groupoid `G`).
* `Structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for
the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category.
As a basic example, we give the instance
`instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H`
saying that a topological space is a charted space over itself, with the identity as unique chart.
This charted space structure is compatible with any groupoid.
Additional useful definitions:
* `Pregroupoid H` : a subset of partial maps of `H` stable under composition and
restriction, but not inverse (ex: smooth maps)
* `Pregroupoid.groupoid` : construct a groupoid from a pregroupoid, by requiring that a map and
its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps)
* `chartAt H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on
`H`.
* `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition
of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid.
* `G.compatible_of_mem_maximalAtlas he he'` states that, for any two charts `e` and `e'` in the
maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the
`G` if `M` admits `G` as a structure groupoid.
* `ChartedSpaceCore.toChartedSpace`: consider a space without a topology, but endowed with a set
of charts (which are partial equivs) for which the change of coordinates are partial homeos.
Then one can construct a topology on the space for which the charts become partial homeos,
defining a genuine charted space structure.
## Implementation notes
The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends
on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current
formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas
defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms
between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the
definition is only that, read in charts, the structomorphism locally belongs to the groupoid under
consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas).
A consequence is that the invariance under structomorphisms of properties defined in terms of the
atlas is not obvious in general, and could require some work in theory (amounting to the fact
that these properties only depend on the maximal atlas, for instance). In practice, this does not
create any real difficulty.
We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the
model space is a half space.
Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and
sometimes as spaces with an atlas from which a topology is deduced. We use the former approach:
otherwise, there would be an instance from manifolds to topological spaces, which means that any
instance search for topological spaces would try to find manifold structures involving a yet
unknown model space, leading to problems. However, we also introduce the latter approach,
through a structure `ChartedSpaceCore` making it possible to construct a topology out of a set of
partial equivs with compatibility conditions (but we do not register it as an instance).
In the definition of a charted space, the model space is written as an explicit parameter as there
can be several model spaces for a given topological space. For instance, a complex manifold
(modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`.
## Notations
In the locale `Manifold`, we denote the composition of partial homeomorphisms with `≫ₕ`, and the
composition of partial equivs with `≫`.
-/
noncomputable section
open TopologicalSpace Topology
universe u
variable {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*}
/- Notational shortcut for the composition of partial homeomorphisms and partial equivs, i.e.,
`PartialHomeomorph.trans` and `PartialEquiv.trans`.
Note that, as is usual for equivs, the composition is from left to right, hence the direction of
the arrow. -/
@[inherit_doc] scoped[Manifold] infixr:100 " ≫ₕ " => PartialHomeomorph.trans
@[inherit_doc] scoped[Manifold] infixr:100 " ≫ " => PartialEquiv.trans
open Set PartialHomeomorph Manifold -- Porting note: Added `Manifold`
/-! ### Structure groupoids -/
section Groupoid
/-! One could add to the definition of a structure groupoid the fact that the restriction of an
element of the groupoid to any open set still belongs to the groupoid.
(This is in Kobayashi-Nomizu.)
I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is
made of functions respecting the fibers and linear in the fibers (so that a charted space over this
groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always
defined on sets of the form `s × E`. There is a typeclass `ClosedUnderRestriction` for groupoids
which have the restriction property.
The only nontrivial requirement is locality: if a partial homeomorphism belongs to the groupoid
around each point in its domain of definition, then it belongs to the groupoid. Without this
requirement, the composition of structomorphisms does not have to be a structomorphism. Note that
this implies that a partial homeomorphism with empty source belongs to any structure groupoid, as
it trivially satisfies this condition.
There is also a technical point, related to the fact that a partial homeomorphism is by definition a
global map which is a homeomorphism when restricted to its source subset (and its values outside
of the source are not relevant). Therefore, we also require that being a member of the groupoid only
depends on the values on the source.
We use primes in the structure names as we will reformulate them below (without primes) using a
`Membership` instance, writing `e ∈ G` instead of `e ∈ G.members`.
-/
/-- A structure groupoid is a set of partial homeomorphisms of a topological space stable under
composition and inverse. They appear in the definition of the smoothness class of a manifold. -/
structure StructureGroupoid (H : Type u) [TopologicalSpace H] where
/-- Members of the structure groupoid are partial homeomorphisms. -/
members : Set (PartialHomeomorph H H)
/-- Structure groupoids are stable under composition. -/
trans' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members
/-- Structure groupoids are stable under inverse. -/
symm' : ∀ e : PartialHomeomorph H H, e ∈ members → e.symm ∈ members
/-- The identity morphism lies in the structure groupoid. -/
id_mem' : PartialHomeomorph.refl H ∈ members
/-- Let `e` be a partial homeomorphism. If for every `x ∈ e.source`, the restriction of e to some
open set around `x` lies in the groupoid, then `e` lies in the groupoid. -/
locality' : ∀ e : PartialHomeomorph H H,
(∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ members) → e ∈ members
/-- Membership in a structure groupoid respects the equivalence of partial homeomorphisms. -/
mem_of_eqOnSource' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ≈ e → e' ∈ members
variable [TopologicalSpace H]
instance : Membership (PartialHomeomorph H H) (StructureGroupoid H) :=
⟨fun (G : StructureGroupoid H) (e : PartialHomeomorph H H) ↦ e ∈ G.members⟩
instance (H : Type u) [TopologicalSpace H] :
SetLike (StructureGroupoid H) (PartialHomeomorph H H) where
coe s := s.members
coe_injective' N O h := by cases N; cases O; congr
instance : Min (StructureGroupoid H) :=
⟨fun G G' => StructureGroupoid.mk
(members := G.members ∩ G'.members)
(trans' := fun e e' he he' =>
⟨G.trans' e e' he.left he'.left, G'.trans' e e' he.right he'.right⟩)
(symm' := fun e he => ⟨G.symm' e he.left, G'.symm' e he.right⟩)
(id_mem' := ⟨G.id_mem', G'.id_mem'⟩)
(locality' := by
intro e hx
apply (mem_inter_iff e G.members G'.members).mpr
refine And.intro (G.locality' e ?_) (G'.locality' e ?_)
all_goals
intro x hex
rcases hx x hex with ⟨s, hs⟩
use s
refine And.intro hs.left (And.intro hs.right.left ?_)
· exact hs.right.right.left
· exact hs.right.right.right)
(mem_of_eqOnSource' := fun e e' he hee' =>
⟨G.mem_of_eqOnSource' e e' he.left hee', G'.mem_of_eqOnSource' e e' he.right hee'⟩)⟩
instance : InfSet (StructureGroupoid H) :=
⟨fun S => StructureGroupoid.mk
(members := ⋂ s ∈ S, s.members)
(trans' := by
simp only [mem_iInter]
intro e e' he he' i hi
exact i.trans' e e' (he i hi) (he' i hi))
(symm' := by
simp only [mem_iInter]
intro e he i hi
exact i.symm' e (he i hi))
(id_mem' := by
simp only [mem_iInter]
intro i _
exact i.id_mem')
(locality' := by
simp only [mem_iInter]
intro e he i hi
refine i.locality' e ?_
intro x hex
rcases he x hex with ⟨s, hs⟩
exact ⟨s, ⟨hs.left, ⟨hs.right.left, hs.right.right i hi⟩⟩⟩)
(mem_of_eqOnSource' := by
simp only [mem_iInter]
intro e e' he he'e
exact fun i hi => i.mem_of_eqOnSource' e e' (he i hi) he'e)⟩
theorem StructureGroupoid.trans (G : StructureGroupoid H) {e e' : PartialHomeomorph H H}
(he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G :=
G.trans' e e' he he'
theorem StructureGroupoid.symm (G : StructureGroupoid H) {e : PartialHomeomorph H H} (he : e ∈ G) :
e.symm ∈ G :=
G.symm' e he
theorem StructureGroupoid.id_mem (G : StructureGroupoid H) : PartialHomeomorph.refl H ∈ G :=
G.id_mem'
theorem StructureGroupoid.locality (G : StructureGroupoid H) {e : PartialHomeomorph H H}
(h : ∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ G) : e ∈ G :=
G.locality' e h
theorem StructureGroupoid.mem_of_eqOnSource (G : StructureGroupoid H) {e e' : PartialHomeomorph H H}
(he : e ∈ G) (h : e' ≈ e) : e' ∈ G :=
G.mem_of_eqOnSource' e e' he h
theorem StructureGroupoid.mem_iff_of_eqOnSource {G : StructureGroupoid H}
{e e' : PartialHomeomorph H H} (h : e ≈ e') : e ∈ G ↔ e' ∈ G :=
⟨fun he ↦ G.mem_of_eqOnSource he (Setoid.symm h), fun he' ↦ G.mem_of_eqOnSource he' h⟩
/-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid. -/
instance StructureGroupoid.partialOrder : PartialOrder (StructureGroupoid H) :=
PartialOrder.lift StructureGroupoid.members fun a b h ↦ by
cases a
cases b
dsimp at h
induction h
rfl
theorem StructureGroupoid.le_iff {G₁ G₂ : StructureGroupoid H} : G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ :=
Iff.rfl
/-- The trivial groupoid, containing only the identity (and maps with empty source, as this is
necessary from the definition). -/
def idGroupoid (H : Type u) [TopologicalSpace H] : StructureGroupoid H where
members := {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ }
trans' e e' he he' := by
rcases he with he | he
· simpa only [mem_singleton_iff.1 he, refl_trans]
· have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _
rw [he] at this
have : e ≫ₕ e' ∈ { e : PartialHomeomorph H H | e.source = ∅ } := eq_bot_iff.2 this
exact (mem_union _ _ _).2 (Or.inr this)
symm' e he := by
rcases (mem_union _ _ _).1 he with E | E
· simp [mem_singleton_iff.mp E]
· right
simpa only [e.toPartialEquiv.image_source_eq_target.symm, mfld_simps] using E
id_mem' := mem_union_left _ rfl
locality' e he := by
rcases e.source.eq_empty_or_nonempty with h | h
· right
exact h
· left
rcases h with ⟨x, hx⟩
rcases he x hx with ⟨s, open_s, xs, hs⟩
have x's : x ∈ (e.restr s).source := by
rw [restr_source, open_s.interior_eq]
exact ⟨hx, xs⟩
rcases hs with hs | hs
· replace hs : PartialHomeomorph.restr e s = PartialHomeomorph.refl H := by
simpa only using hs
have : (e.restr s).source = univ := by
rw [hs]
simp
have : e.toPartialEquiv.source ∩ interior s = univ := this
have : univ ⊆ interior s := by
rw [← this]
exact inter_subset_right
have : s = univ := by rwa [open_s.interior_eq, univ_subset_iff] at this
simpa only [this, restr_univ] using hs
· exfalso
rw [mem_setOf_eq] at hs
rwa [hs] at x's
mem_of_eqOnSource' e e' he he'e := by
rcases he with he | he
· left
have : e = e' := by
refine eq_of_eqOnSource_univ (Setoid.symm he'e) ?_ ?_ <;>
rw [Set.mem_singleton_iff.1 he] <;> rfl
rwa [← this]
· right
have he : e.toPartialEquiv.source = ∅ := he
rwa [Set.mem_setOf_eq, EqOnSource.source_eq he'e]
/-- Every structure groupoid contains the identity groupoid. -/
instance instStructureGroupoidOrderBot : OrderBot (StructureGroupoid H) where
bot := idGroupoid H
bot_le := by
intro u f hf
have hf : f ∈ {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ } := hf
simp only [singleton_union, mem_setOf_eq, mem_insert_iff] at hf
rcases hf with hf | hf
· rw [hf]
apply u.id_mem
· apply u.locality
intro x hx
rw [hf, mem_empty_iff_false] at hx
exact hx.elim
instance : Inhabited (StructureGroupoid H) := ⟨idGroupoid H⟩
/-- To construct a groupoid, one may consider classes of partial homeomorphisms such that
both the function and its inverse have some property. If this property is stable under composition,
one gets a groupoid. `Pregroupoid` bundles the properties needed for this construction, with the
groupoid of smooth functions with smooth inverses as an application. -/
structure Pregroupoid (H : Type*) [TopologicalSpace H] where
/-- Property describing membership in this groupoid: the pregroupoid "contains"
all functions `H → H` having the pregroupoid property on some `s : Set H` -/
property : (H → H) → Set H → Prop
/-- The pregroupoid property is stable under composition -/
comp : ∀ {f g u v}, property f u → property g v →
IsOpen u → IsOpen v → IsOpen (u ∩ f ⁻¹' v) → property (g ∘ f) (u ∩ f ⁻¹' v)
/-- Pregroupoids contain the identity map (on `univ`) -/
id_mem : property id univ
/-- The pregroupoid property is "local", in the sense that `f` has the pregroupoid property on `u`
iff its restriction to each open subset of `u` has it -/
locality :
∀ {f u}, IsOpen u → (∀ x ∈ u, ∃ v, IsOpen v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u
/-- If `f = g` on `u` and `property f u`, then `property g u` -/
congr : ∀ {f g : H → H} {u}, IsOpen u → (∀ x ∈ u, g x = f x) → property f u → property g u
/-- Construct a groupoid of partial homeos for which the map and its inverse have some property,
from a pregroupoid asserting that this property is stable under composition. -/
def Pregroupoid.groupoid (PG : Pregroupoid H) : StructureGroupoid H where
members := { e : PartialHomeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target }
trans' e e' he he' := by
constructor
· apply PG.comp he.1 he'.1 e.open_source e'.open_source
apply e.continuousOn_toFun.isOpen_inter_preimage e.open_source e'.open_source
· apply PG.comp he'.2 he.2 e'.open_target e.open_target
apply e'.continuousOn_invFun.isOpen_inter_preimage e'.open_target e.open_target
symm' _ he := ⟨he.2, he.1⟩
id_mem' := ⟨PG.id_mem, PG.id_mem⟩
locality' e he := by
constructor
· refine PG.locality e.open_source fun x xu ↦ ?_
rcases he x xu with ⟨s, s_open, xs, hs⟩
refine ⟨s, s_open, xs, ?_⟩
convert hs.1 using 1
dsimp [PartialHomeomorph.restr]
rw [s_open.interior_eq]
· refine PG.locality e.open_target fun x xu ↦ ?_
rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩
refine ⟨e.target ∩ e.symm ⁻¹' s, ?_, ⟨xu, xs⟩, ?_⟩
· exact ContinuousOn.isOpen_inter_preimage e.continuousOn_invFun e.open_target s_open
· rw [← inter_assoc, inter_self]
convert hs.2 using 1
dsimp [PartialHomeomorph.restr]
rw [s_open.interior_eq]
mem_of_eqOnSource' e e' he ee' := by
constructor
· apply PG.congr e'.open_source ee'.2
simp only [ee'.1, he.1]
· have A := EqOnSource.symm' ee'
apply PG.congr e'.symm.open_source A.2
-- Porting note: was
-- convert he.2
-- rw [A.1]
-- rfl
rw [A.1, symm_toPartialEquiv, PartialEquiv.symm_source]
exact he.2
theorem mem_groupoid_of_pregroupoid {PG : Pregroupoid H} {e : PartialHomeomorph H H} :
e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target :=
Iff.rfl
theorem groupoid_of_pregroupoid_le (PG₁ PG₂ : Pregroupoid H)
(h : ∀ f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid := by
refine StructureGroupoid.le_iff.2 fun e he ↦ ?_
rw [mem_groupoid_of_pregroupoid] at he ⊢
exact ⟨h _ _ he.1, h _ _ he.2⟩
theorem mem_pregroupoid_of_eqOnSource (PG : Pregroupoid H) {e e' : PartialHomeomorph H H}
(he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source := by
rw [← he'.1]
exact PG.congr e.open_source he'.eqOn.symm he
/-- The pregroupoid of all partial maps on a topological space `H`. -/
abbrev continuousPregroupoid (H : Type*) [TopologicalSpace H] : Pregroupoid H where
property _ _ := True
comp _ _ _ _ _ := trivial
id_mem := trivial
locality _ _ := trivial
congr _ _ _ := trivial
instance (H : Type*) [TopologicalSpace H] : Inhabited (Pregroupoid H) :=
⟨continuousPregroupoid H⟩
/-- The groupoid of all partial homeomorphisms on a topological space `H`. -/
def continuousGroupoid (H : Type*) [TopologicalSpace H] : StructureGroupoid H :=
Pregroupoid.groupoid (continuousPregroupoid H)
/-- Every structure groupoid is contained in the groupoid of all partial homeomorphisms. -/
instance instStructureGroupoidOrderTop : OrderTop (StructureGroupoid H) where
top := continuousGroupoid H
le_top _ _ _ := ⟨trivial, trivial⟩
instance : CompleteLattice (StructureGroupoid H) :=
{ SetLike.instPartialOrder,
completeLatticeOfInf _ (by
exact fun s =>
⟨fun S Ss F hF => mem_iInter₂.mp hF S Ss,
fun T Tl F fT => mem_iInter₂.mpr (fun i his => Tl his fT)⟩) with
le := (· ≤ ·)
lt := (· < ·)
bot := instStructureGroupoidOrderBot.bot
bot_le := instStructureGroupoidOrderBot.bot_le
top := instStructureGroupoidOrderTop.top
le_top := instStructureGroupoidOrderTop.le_top
inf := (· ⊓ ·)
le_inf := fun _ _ _ h₁₂ h₁₃ _ hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩
inf_le_left := fun _ _ _ ↦ And.left
inf_le_right := fun _ _ _ ↦ And.right }
/-- A groupoid is closed under restriction if it contains all restrictions of its element local
homeomorphisms to open subsets of the source. -/
class ClosedUnderRestriction (G : StructureGroupoid H) : Prop where
closedUnderRestriction :
∀ {e : PartialHomeomorph H H}, e ∈ G → ∀ s : Set H, IsOpen s → e.restr s ∈ G
theorem closedUnderRestriction' {G : StructureGroupoid H} [ClosedUnderRestriction G]
{e : PartialHomeomorph H H} (he : e ∈ G) {s : Set H} (hs : IsOpen s) : e.restr s ∈ G :=
ClosedUnderRestriction.closedUnderRestriction he s hs
/-- The trivial restriction-closed groupoid, containing only partial homeomorphisms equivalent
to the restriction of the identity to the various open subsets. -/
def idRestrGroupoid : StructureGroupoid H where
members := { e | ∃ (s : Set H) (h : IsOpen s), e ≈ PartialHomeomorph.ofSet s h }
trans' := by
rintro e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩
refine ⟨s ∩ s', hs.inter hs', ?_⟩
have := PartialHomeomorph.EqOnSource.trans' hse hse'
rwa [PartialHomeomorph.ofSet_trans_ofSet] at this
symm' := by
rintro e ⟨s, hs, hse⟩
refine ⟨s, hs, ?_⟩
rw [← ofSet_symm]
exact PartialHomeomorph.EqOnSource.symm' hse
id_mem' := ⟨univ, isOpen_univ, by simp only [mfld_simps, refl]⟩
locality' := by
intro e h
refine ⟨e.source, e.open_source, by simp only [mfld_simps], ?_⟩
intro x hx
rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩
have hes : x ∈ (e.restr s).source := by
rw [e.restr_source]
refine ⟨hx, ?_⟩
rw [hs.interior_eq]
exact hxs
simpa only [mfld_simps] using PartialHomeomorph.EqOnSource.eqOn hes' hes
mem_of_eqOnSource' := by
rintro e e' ⟨s, hs, hse⟩ hee'
exact ⟨s, hs, Setoid.trans hee' hse⟩
theorem idRestrGroupoid_mem {s : Set H} (hs : IsOpen s) : ofSet s hs ∈ @idRestrGroupoid H _ :=
⟨s, hs, refl _⟩
/-- The trivial restriction-closed groupoid is indeed `ClosedUnderRestriction`. -/
instance closedUnderRestriction_idRestrGroupoid : ClosedUnderRestriction (@idRestrGroupoid H _) :=
⟨by
rintro e ⟨s', hs', he⟩ s hs
use s' ∩ s, hs'.inter hs
refine Setoid.trans (PartialHomeomorph.EqOnSource.restr he s) ?_
exact ⟨by simp only [hs.interior_eq, mfld_simps], by simp only [mfld_simps, eqOn_refl]⟩⟩
/-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed
groupoid. -/
theorem closedUnderRestriction_iff_id_le (G : StructureGroupoid H) :
ClosedUnderRestriction G ↔ idRestrGroupoid ≤ G := by
constructor
· intro _i
rw [StructureGroupoid.le_iff]
rintro e ⟨s, hs, hes⟩
refine G.mem_of_eqOnSource ?_ hes
convert closedUnderRestriction' G.id_mem hs
-- Porting note: was
-- change s = _ ∩ _
-- rw [hs.interior_eq]
-- simp only [mfld_simps]
ext
· rw [PartialHomeomorph.restr_apply, PartialHomeomorph.refl_apply, id, ofSet_apply, id_eq]
· simp [hs]
· simp [hs.interior_eq]
· intro h
constructor
intro e he s hs
rw [← ofSet_trans (e : PartialHomeomorph H H) hs]
refine G.trans ?_ he
apply StructureGroupoid.le_iff.mp h
exact idRestrGroupoid_mem hs
/-- The groupoid of all partial homeomorphisms on a topological space `H`
is closed under restriction. -/
instance : ClosedUnderRestriction (continuousGroupoid H) :=
(closedUnderRestriction_iff_id_le _).mpr le_top
end Groupoid
/-! ### Charted spaces -/
/-- A charted space is a topological space endowed with an atlas, i.e., a set of local
homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts
cover the whole space. We express the covering property by choosing for each `x` a member
`chartAt x` of the atlas containing `x` in its source: in the smooth case, this is convenient to
construct the tangent bundle in an efficient way.
The model space is written as an explicit parameter as there can be several model spaces for a
given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen
sometimes as a real manifold over `ℝ^(2n)`.
-/
@[ext]
class ChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] where
/-- The atlas of charts in the `ChartedSpace`. -/
protected atlas : Set (PartialHomeomorph M H)
/-- The preferred chart at each point in the charted space. -/
protected chartAt : M → PartialHomeomorph M H
protected mem_chart_source : ∀ x, x ∈ (chartAt x).source
protected chart_mem_atlas : ∀ x, chartAt x ∈ atlas
/-- The atlas of charts in a `ChartedSpace`. -/
abbrev atlas (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M]
[ChartedSpace H M] : Set (PartialHomeomorph M H) :=
ChartedSpace.atlas
/-- The preferred chart at a point `x` in a charted space `M`. -/
abbrev chartAt (H : Type*) [TopologicalSpace H] {M : Type*} [TopologicalSpace M]
[ChartedSpace H M] (x : M) : PartialHomeomorph M H :=
ChartedSpace.chartAt x
@[simp, mfld_simps]
lemma mem_chart_source (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] (x : M) : x ∈ (chartAt H x).source :=
ChartedSpace.mem_chart_source x
@[simp, mfld_simps]
lemma chart_mem_atlas (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] (x : M) : chartAt H x ∈ atlas H M :=
ChartedSpace.chart_mem_atlas x
lemma nonempty_of_chartedSpace {H : Type*} {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] (x : M) : Nonempty H :=
⟨chartAt H x x⟩
lemma isEmpty_of_chartedSpace (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M]
[ChartedSpace H M] [IsEmpty H] : IsEmpty M := by
rcases isEmpty_or_nonempty M with hM | ⟨⟨x⟩⟩
· exact hM
· exact (IsEmpty.false (chartAt H x x)).elim
section ChartedSpace
section
variable (H) [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M]
-- Porting note: Added `(H := H)` to avoid typeclass instance problem.
theorem mem_chart_target (x : M) : chartAt H x x ∈ (chartAt H x).target :=
(chartAt H x).map_source (mem_chart_source _ _)
theorem chart_source_mem_nhds (x : M) : (chartAt H x).source ∈ 𝓝 x :=
(chartAt H x).open_source.mem_nhds <| mem_chart_source H x
theorem chart_target_mem_nhds (x : M) : (chartAt H x).target ∈ 𝓝 (chartAt H x x) :=
(chartAt H x).open_target.mem_nhds <| mem_chart_target H x
variable (M) in
@[simp]
theorem iUnion_source_chartAt : (⋃ x : M, (chartAt H x).source) = (univ : Set M) :=
eq_univ_iff_forall.mpr fun x ↦ mem_iUnion.mpr ⟨x, mem_chart_source H x⟩
theorem ChartedSpace.isOpen_iff (s : Set M) :
IsOpen s ↔ ∀ x : M, IsOpen <| chartAt H x '' ((chartAt H x).source ∩ s) := by
rw [isOpen_iff_of_cover (fun i ↦ (chartAt H i).open_source) (iUnion_source_chartAt H M)]
simp only [(chartAt H _).isOpen_image_iff_of_subset_source inter_subset_left]
/-- `achart H x` is the chart at `x`, considered as an element of the atlas.
Especially useful for working with `BasicContMDiffVectorBundleCore`. -/
def achart (x : M) : atlas H M :=
⟨chartAt H x, chart_mem_atlas H x⟩
theorem achart_def (x : M) : achart H x = ⟨chartAt H x, chart_mem_atlas H x⟩ :=
rfl
@[simp, mfld_simps]
theorem coe_achart (x : M) : (achart H x : PartialHomeomorph M H) = chartAt H x :=
rfl
@[simp, mfld_simps]
theorem achart_val (x : M) : (achart H x).1 = chartAt H x :=
rfl
theorem mem_achart_source (x : M) : x ∈ (achart H x).1.source :=
mem_chart_source H x
open TopologicalSpace
theorem ChartedSpace.secondCountable_of_countable_cover [SecondCountableTopology H] {s : Set M}
(hs : ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ) (hsc : s.Countable) :
SecondCountableTopology M := by
haveI : ∀ x : M, SecondCountableTopology (chartAt H x).source :=
fun x ↦ (chartAt (H := H) x).secondCountableTopology_source
haveI := hsc.toEncodable
rw [biUnion_eq_iUnion] at hs
exact secondCountableTopology_of_countable_cover (fun x : s ↦ (chartAt H (x : M)).open_source) hs
variable (M)
theorem ChartedSpace.secondCountable_of_sigmaCompact [SecondCountableTopology H]
[SigmaCompactSpace M] : SecondCountableTopology M := by
obtain ⟨s, hsc, hsU⟩ : ∃ s, Set.Countable s ∧ ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ :=
countable_cover_nhds_of_sigmaCompact fun x : M ↦ chart_source_mem_nhds H x
| exact ChartedSpace.secondCountable_of_countable_cover H hsU hsc
@[deprecated (since := "2024-11-13")] alias
ChartedSpace.secondCountable_of_sigma_compact := ChartedSpace.secondCountable_of_sigmaCompact
| Mathlib/Geometry/Manifold/ChartedSpace.lean | 648 | 651 |
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Analysis.Convex.Hull
import Mathlib.LinearAlgebra.AffineSpace.Basis
/-!
# Convex combinations
This file defines convex combinations of points in a vector space.
## Main declarations
* `Finset.centerMass`: Center of mass of a finite family of points.
## Implementation notes
We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way
mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few
lemmas unconditional on the sum of the weights being `1`.
-/
open Set Function Pointwise
universe u u'
section
variable {R R' E F ι ι' α : Type*} [Field R] [Field R'] [AddCommGroup E] [AddCommGroup F]
[AddCommGroup α] [LinearOrder α] [Module R E] [Module R F] [Module R α] {s : Set E}
/-- Center of mass of a finite collection of points with prescribed weights.
Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/
def Finset.centerMass (t : Finset ι) (w : ι → R) (z : ι → E) : E :=
(∑ i ∈ t, w i)⁻¹ • ∑ i ∈ t, w i • z i
variable (i j : ι) (c : R) (t : Finset ι) (w : ι → R) (z : ι → E)
open Finset
theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by
simp only [centerMass, sum_empty, smul_zero]
theorem Finset.centerMass_pair [DecidableEq ι] (hne : i ≠ j) :
({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by
simp only [centerMass, sum_pair hne]
module
variable {w}
theorem Finset.centerMass_insert [DecidableEq ι] (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) :
(insert i t).centerMass w z =
(w i / (w i + ∑ j ∈ t, w j)) • z i +
((∑ j ∈ t, w j) / (w i + ∑ j ∈ t, w j)) • t.centerMass w z := by
simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul]
congr 2
rw [div_mul_eq_mul_div, mul_inv_cancel₀ hw, one_div]
theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by
rw [centerMass, sum_singleton, sum_singleton]
match_scalars
field_simp
@[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by
simp [centerMass, inv_neg]
lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R]
[IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c ≠ 0) :
t.centerMass (c • w) z = t.centerMass w z := by
simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_inv₀, smul_smul_smul_comm, hc]
theorem Finset.centerMass_eq_of_sum_1 (hw : ∑ i ∈ t, w i = 1) :
t.centerMass w z = ∑ i ∈ t, w i • z i := by
simp only [Finset.centerMass, hw, inv_one, one_smul]
theorem Finset.centerMass_smul : (t.centerMass w fun i => c • z i) = c • t.centerMass w z := by
simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]
/-- A convex combination of two centers of mass is a center of mass as well. This version
deals with two different index types. -/
theorem Finset.centerMass_segment' (s : Finset ι) (t : Finset ι') (ws : ι → R) (zs : ι → E)
(wt : ι' → R) (zt : ι' → E) (hws : ∑ i ∈ s, ws i = 1) (hwt : ∑ i ∈ t, wt i = 1) (a b : R)
(hab : a + b = 1) : a • s.centerMass ws zs + b • t.centerMass wt zt = (s.disjSum t).centerMass
(Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by
rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ←
Finset.sum_sumElim, Finset.centerMass_eq_of_sum_1]
· congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul]
· rw [sum_sumElim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab]
/-- A convex combination of two centers of mass is a center of mass as well. This version
works if two centers of mass share the set of original points. -/
theorem Finset.centerMass_segment (s : Finset ι) (w₁ w₂ : ι → R) (z : ι → E)
(hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (a b : R) (hab : a + b = 1) :
a • s.centerMass w₁ z + b • s.centerMass w₂ z =
s.centerMass (fun i => a * w₁ i + b * w₂ i) z := by
have hw : (∑ i ∈ s, (a * w₁ i + b * w₂ i)) = 1 := by
simp only [← mul_sum, sum_add_distrib, mul_one, *]
simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw,
smul_sum, sum_add_distrib, add_smul, mul_smul, *]
theorem Finset.centerMass_ite_eq [DecidableEq ι] (hi : i ∈ t) :
t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by
rw [Finset.centerMass_eq_of_sum_1]
· trans ∑ j ∈ t, if i = j then z i else 0
· congr with i
split_ifs with h
exacts [h ▸ one_smul _ _, zero_smul _ _]
· rw [sum_ite_eq, if_pos hi]
· rw [sum_ite_eq, if_pos hi]
variable {t}
theorem Finset.centerMass_subset {t' : Finset ι} (ht : t ⊆ t') (h : ∀ i ∈ t', i ∉ t → w i = 0) :
t.centerMass w z = t'.centerMass w z := by
rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum]
apply sum_subset ht
intro i hit' hit
rw [h i hit' hit, zero_smul, smul_zero]
theorem Finset.centerMass_filter_ne_zero [∀ i, Decidable (w i ≠ 0)] :
{i ∈ t | w i ≠ 0}.centerMass w z = t.centerMass w z :=
Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by
simpa only [hit, mem_filter, true_and, Ne, Classical.not_not] using hit'
namespace Finset
variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid α] [OrderedSMul R α]
theorem centerMass_le_sup {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i)
(hw₁ : 0 < ∑ i ∈ s, w i) :
s.centerMass w f ≤ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f := by
rw [centerMass, inv_smul_le_iff_of_pos hw₁, sum_smul]
exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hw₀ i hi
theorem inf_le_centerMass {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i)
(hw₁ : 0 < ∑ i ∈ s, w i) :
s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f ≤ s.centerMass w f :=
centerMass_le_sup (α := αᵒᵈ) hw₀ hw₁
end Finset
variable {z}
lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ι}
(hw : ∑ i ∈ s, w i + ∑ i ∈ t, w i = 0) (hz : ∑ i ∈ s, w i • z i + ∑ i ∈ t, w i • z i = 0) :
s.centerMass w z = t.centerMass w z := by
simp [centerMass, eq_neg_of_add_eq_zero_right hw, eq_neg_of_add_eq_zero_left hz, ← neg_inv]
variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid α] [OrderedSMul R α]
/-- The center of mass of a finite subset of a convex set belongs to the set
provided that all weights are non-negative, and the total weight is positive. -/
theorem Convex.centerMass_mem (hs : Convex R s) :
(∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i ∈ t, w i) → (∀ i ∈ t, z i ∈ s) → t.centerMass w z ∈ s := by
classical
induction' t using Finset.induction with i t hi ht
· simp [lt_irrefl]
intro h₀ hpos hmem
have zi : z i ∈ s := hmem _ (mem_insert_self _ _)
have hs₀ : ∀ j ∈ t, 0 ≤ w j := fun j hj => h₀ j <| mem_insert_of_mem hj
rw [sum_insert hi] at hpos
by_cases hsum_t : ∑ j ∈ t, w j = 0
· have ws : ∀ j ∈ t, w j = 0 := (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t
have wz : ∑ j ∈ t, w j • z j = 0 := sum_eq_zero fun i hi => by simp [ws i hi]
| simp only [centerMass, sum_insert hi, wz, hsum_t, add_zero]
simp only [hsum_t, add_zero] at hpos
rw [← mul_smul, inv_mul_cancel₀ (ne_of_gt hpos), one_smul]
exact zi
· rw [Finset.centerMass_insert _ _ _ hi hsum_t]
refine convex_iff_div.1 hs zi (ht hs₀ ?_ ?_) ?_ (sum_nonneg hs₀) hpos
· exact lt_of_le_of_ne (sum_nonneg hs₀) (Ne.symm hsum_t)
· intro j hj
exact hmem j (mem_insert_of_mem hj)
· exact h₀ _ (mem_insert_self _ _)
theorem Convex.sum_mem (hs : Convex R s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1)
(hz : ∀ i ∈ t, z i ∈ s) : (∑ i ∈ t, w i • z i) ∈ s := by
simpa only [h₁, centerMass, inv_one, one_smul] using
hs.centerMass_mem h₀ (h₁.symm ▸ zero_lt_one) hz
/-- A version of `Convex.sum_mem` for `finsum`s. If `s` is a convex set, `w : ι → R` is a family of
nonnegative weights with sum one and `z : ι → E` is a family of elements of a module over `R` such
that `z i ∈ s` whenever `w i ≠ 0`, then the sum `∑ᶠ i, w i • z i` belongs to `s`. See also
`PartitionOfUnity.finsum_smul_mem_convex`. -/
theorem Convex.finsum_mem {ι : Sort*} {w : ι → R} {z : ι → E} {s : Set E} (hs : Convex R s)
| Mathlib/Analysis/Convex/Combination.lean | 168 | 188 |
/-
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.Geometry.RingedSpace.PresheafedSpace.Gluing
import Mathlib.AlgebraicGeometry.Cover.Open
/-!
# Gluing Schemes
Given a family of gluing data of schemes, we may glue them together.
## Main definitions
* `AlgebraicGeometry.Scheme.GlueData`: A structure containing the family of gluing data.
* `AlgebraicGeometry.Scheme.GlueData.glued`: The glued scheme.
This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API
can be used.
* `AlgebraicGeometry.Scheme.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`.
* `AlgebraicGeometry.Scheme.GlueData.isoCarrier`: The isomorphism between the underlying space
of the glued scheme and the gluing of the underlying topological spaces.
* `AlgebraicGeometry.Scheme.OpenCover.gluedCover`: The glue data associated with an open cover.
* `AlgebraicGeometry.Scheme.OpenCover.fromGlued`: The canonical morphism
`𝒰.gluedCover.glued ⟶ X`. This has an `is_iso` instance.
* `AlgebraicGeometry.Scheme.OpenCover.glueMorphisms`: We may glue a family of compatible
morphisms defined on an open cover of a scheme.
## Main results
* `AlgebraicGeometry.Scheme.GlueData.ι_isOpenImmersion`: The map `ι i : U i ⟶ glued`
is an open immersion for each `i : J`.
* `AlgebraicGeometry.Scheme.GlueData.ι_jointly_surjective` : The underlying maps of
`ι i : U i ⟶ glued` are jointly surjective.
* `AlgebraicGeometry.Scheme.GlueData.vPullbackConeIsLimit` : `V i j` is the pullback
(intersection) of `U i` and `U j` over the glued space.
* `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff` : `ι i x = ι j y` if and only if they coincide
when restricted to `V i i`.
* `AlgebraicGeometry.Scheme.GlueData.isOpen_iff` : A subset of the glued scheme is open iff
all its preimages in `U i` are open.
## Implementation details
All the hard work is done in `AlgebraicGeometry/PresheafedSpace/Gluing.lean` where we glue
presheafed spaces, sheafed spaces, and locally ringed spaces.
-/
noncomputable section
universe u
open TopologicalSpace CategoryTheory Opposite Topology
open CategoryTheory.Limits AlgebraicGeometry.PresheafedSpace
open CategoryTheory.GlueData
namespace AlgebraicGeometry
namespace Scheme
/-- A family of gluing data consists of
1. An index type `J`
2. A scheme `U i` for each `i : J`.
3. A scheme `V i j` for each `i j : J`.
(Note that this is `J × J → Scheme` rather than `J → J → Scheme` to connect to the
limits library easier.)
4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`.
5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`.
such that
6. `f i i` is an isomorphism.
7. `t i i` is the identity.
8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some
`t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`.
9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`.
We can then glue the schemes `U i` together by identifying `V i j` with `V j i`, such
that the `U i`'s are open subschemes of the glued space.
-/
structure GlueData extends CategoryTheory.GlueData Scheme where
f_open : ∀ i j, IsOpenImmersion (f i j)
attribute [instance] GlueData.f_open
namespace GlueData
variable (D : GlueData.{u})
local notation "𝖣" => D.toGlueData
/-- The glue data of locally ringed spaces associated to a family of glue data of schemes. -/
abbrev toLocallyRingedSpaceGlueData : LocallyRingedSpace.GlueData :=
{ f_open := D.f_open
toGlueData := 𝖣.mapGlueData forgetToLocallyRingedSpace }
instance (i j : 𝖣.J) :
LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.f i j) := by
apply GlueData.f_open
instance (i j : 𝖣.J) :
SheafedSpace.IsOpenImmersion
(D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toGlueData.f i j) := by
apply GlueData.f_open
instance (i j : 𝖣.J) :
PresheafedSpace.IsOpenImmersion
(D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toGlueData.f
i j) := by
apply GlueData.f_open
instance (i : 𝖣.J) :
LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.ι i) := by
apply LocallyRingedSpace.GlueData.ι_isOpenImmersion
/-- (Implementation). The glued scheme of a glue data.
This should not be used outside this file. Use `AlgebraicGeometry.Scheme.GlueData.glued` instead. -/
def gluedScheme : Scheme := by
apply LocallyRingedSpace.IsOpenImmersion.scheme
D.toLocallyRingedSpaceGlueData.toGlueData.glued
intro x
obtain ⟨i, y, rfl⟩ := D.toLocallyRingedSpaceGlueData.ι_jointly_surjective x
refine ⟨_, ((D.U i).affineCover.map y).toLRSHom ≫
D.toLocallyRingedSpaceGlueData.toGlueData.ι i, ?_⟩
constructor
· simp only [LocallyRingedSpace.comp_toShHom, SheafedSpace.comp_base, TopCat.hom_comp,
ContinuousMap.coe_comp, Set.range_comp]
refine Set.mem_image_of_mem _ ?_
exact (D.U i).affineCover.covers y
· infer_instance
instance : CreatesColimit 𝖣.diagram.multispan forgetToLocallyRingedSpace :=
createsColimitOfFullyFaithfulOfIso D.gluedScheme
(HasColimit.isoOfNatIso (𝖣.diagramIso forgetToLocallyRingedSpace).symm)
instance : PreservesColimit (𝖣.diagram.multispan) forgetToTop :=
inferInstanceAs (PreservesColimit (𝖣.diagram).multispan (forgetToLocallyRingedSpace ⋙
LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget CommRingCat))
instance : HasMulticoequalizer 𝖣.diagram :=
hasColimit_of_created _ forgetToLocallyRingedSpace
/-- The glued scheme of a glued space. -/
abbrev glued : Scheme :=
𝖣.glued
/-- The immersion from `D.U i` into the glued space. -/
abbrev ι (i : D.J) : D.U i ⟶ D.glued :=
𝖣.ι i
/-- The gluing as sheafed spaces is isomorphic to the gluing as presheafed spaces. -/
abbrev isoLocallyRingedSpace :
D.glued.toLocallyRingedSpace ≅ D.toLocallyRingedSpaceGlueData.toGlueData.glued :=
𝖣.gluedIso forgetToLocallyRingedSpace
theorem ι_isoLocallyRingedSpace_inv (i : D.J) :
D.toLocallyRingedSpaceGlueData.toGlueData.ι i ≫
D.isoLocallyRingedSpace.inv = (𝖣.ι i).toLRSHom :=
𝖣.ι_gluedIso_inv forgetToLocallyRingedSpace i
instance ι_isOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) := by
rw [IsOpenImmersion, ← D.ι_isoLocallyRingedSpace_inv]; infer_instance
theorem ι_jointly_surjective (x : 𝖣.glued.carrier) :
∃ (i : D.J) (y : (D.U i).carrier), (D.ι i).base y = x :=
𝖣.ι_jointly_surjective (forgetToTop ⋙ forget TopCat) x
/-- Promoted to higher priority to short circuit simplifier. -/
@[simp (high), reassoc]
theorem glue_condition (i j : D.J) : D.t i j ≫ D.f j i ≫ D.ι j = D.f i j ≫ D.ι i :=
𝖣.glue_condition i j
/-- The pullback cone spanned by `V i j ⟶ U i` and `V i j ⟶ U j`.
This is a pullback diagram (`vPullbackConeIsLimit`). -/
def vPullbackCone (i j : D.J) : PullbackCone (D.ι i) (D.ι j) :=
PullbackCone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp)
/-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`.
```
Vᵢⱼ ⟶ Uᵢ
| |
↓ ↓
Uⱼ ⟶ X
```
-/
def vPullbackConeIsLimit (i j : D.J) : IsLimit (D.vPullbackCone i j) :=
𝖣.vPullbackConeIsLimitOfMap forgetToLocallyRingedSpace i j
(D.toLocallyRingedSpaceGlueData.vPullbackConeIsLimit _ _)
local notation "D_" => TopCat.GlueData.toGlueData <|
D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData
/-- The underlying topological space of the glued scheme is isomorphic to the gluing of the
underlying spaces -/
def isoCarrier :
D.glued.carrier ≅ (D_).glued := by
refine (PresheafedSpace.forget _).mapIso ?_ ≪≫
GlueData.gluedIso _ (PresheafedSpace.forget.{_, _, u} _)
refine SheafedSpace.forgetToPresheafedSpace.mapIso ?_ ≪≫
SheafedSpace.GlueData.isoPresheafedSpace _
refine LocallyRingedSpace.forgetToSheafedSpace.mapIso ?_ ≪≫
LocallyRingedSpace.GlueData.isoSheafedSpace _
exact Scheme.GlueData.isoLocallyRingedSpace _
@[simp]
theorem ι_isoCarrier_inv (i : D.J) :
(D_).ι i ≫ D.isoCarrier.inv = (D.ι i).base := by
delta isoCarrier
rw [Iso.trans_inv, GlueData.ι_gluedIso_inv_assoc, Functor.mapIso_inv, Iso.trans_inv,
Functor.mapIso_inv, Iso.trans_inv, SheafedSpace.forgetToPresheafedSpace_map, forget_map,
forget_map, ← PresheafedSpace.comp_base, ← Category.assoc,
D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.ι_isoPresheafedSpace_inv i]
erw [← Category.assoc, D.toLocallyRingedSpaceGlueData.ι_isoSheafedSpace_inv i]
change (_ ≫ D.isoLocallyRingedSpace.inv).base = _
rw [D.ι_isoLocallyRingedSpace_inv i]
/-- An equivalence relation on `Σ i, D.U i` that holds iff `𝖣.ι i x = 𝖣.ι j y`.
See `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff`. -/
def Rel (a b : Σ i, ((D.U i).carrier : Type _)) : Prop :=
∃ x : (D.V (a.1, b.1)).carrier, (D.f _ _).base x = a.2 ∧ (D.t _ _ ≫ D.f _ _).base x = b.2
theorem ι_eq_iff (i j : D.J) (x : (D.U i).carrier) (y : (D.U j).carrier) :
(𝖣.ι i).base x = (𝖣.ι j).base y ↔ D.Rel ⟨i, x⟩ ⟨j, y⟩ := by
refine Iff.trans ?_
(TopCat.GlueData.ι_eq_iff_rel
D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData
i j x y)
rw [← ((TopCat.mono_iff_injective D.isoCarrier.inv).mp _).eq_iff, ← ConcreteCategory.comp_apply]
· simp_rw [← D.ι_isoCarrier_inv]
rfl -- `rfl` was not needed before https://github.com/leanprover-community/mathlib4/pull/13170
· infer_instance
theorem isOpen_iff (U : Set D.glued.carrier) : IsOpen U ↔ ∀ i, IsOpen ((D.ι i).base ⁻¹' U) := by
rw [← (TopCat.homeoOfIso D.isoCarrier.symm).isOpen_preimage, TopCat.GlueData.isOpen_iff]
apply forall_congr'
intro i
rw [← Set.preimage_comp, ← ι_isoCarrier_inv]
rfl
/-- The open cover of the glued space given by the glue data. -/
@[simps -isSimp]
def openCover (D : Scheme.GlueData) : OpenCover D.glued where
J := D.J
obj := D.U
map := D.ι
f x := (D.ι_jointly_surjective x).choose
covers x := ⟨_, (D.ι_jointly_surjective x).choose_spec.choose_spec⟩
end GlueData
namespace Cover
variable {X : Scheme.{u}} (𝒰 : OpenCover.{u} X)
/-- (Implementation) the transition maps in the glue data associated with an open cover. -/
def gluedCoverT' (x y z : 𝒰.J) :
pullback (pullback.fst (𝒰.map x) (𝒰.map y)) (pullback.fst (𝒰.map x) (𝒰.map z)) ⟶
pullback (pullback.fst (𝒰.map y) (𝒰.map z)) (pullback.fst (𝒰.map y) (𝒰.map x)) := by
refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_
refine ?_ ≫ (pullbackSymmetry _ _).hom
refine ?_ ≫ (pullbackRightPullbackFstIso _ _ _).inv
refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_
· simp [pullback.condition]
· simp
@[simp, reassoc]
theorem gluedCoverT'_fst_fst (x y z : 𝒰.J) :
𝒰.gluedCoverT' x y z ≫ pullback.fst _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ ≫ pullback.snd _ _ := by
delta gluedCoverT'; simp
@[simp, reassoc]
theorem gluedCoverT'_fst_snd (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ pullback.fst _ _ ≫ pullback.snd _ _ =
pullback.snd _ _ ≫ pullback.snd _ _ := by
delta gluedCoverT'; simp
@[simp, reassoc]
theorem gluedCoverT'_snd_fst (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ ≫ pullback.snd _ _ := by
delta gluedCoverT'; simp
@[simp, reassoc]
theorem gluedCoverT'_snd_snd (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.snd _ _ =
pullback.fst _ _ ≫ pullback.fst _ _ := by
delta gluedCoverT'; simp
theorem glued_cover_cocycle_fst (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.fst _ _ =
pullback.fst _ _ := by
apply pullback.hom_ext <;> simp
theorem glued_cover_cocycle_snd (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.snd _ _ =
pullback.snd _ _ := by
apply pullback.hom_ext <;> simp [pullback.condition]
theorem glued_cover_cocycle (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y = 𝟙 _ := by
apply pullback.hom_ext <;> simp_rw [Category.id_comp, Category.assoc]
· apply glued_cover_cocycle_fst
· apply glued_cover_cocycle_snd
/-- The glue data associated with an open cover.
The canonical isomorphism `𝒰.gluedCover.glued ⟶ X` is provided by `𝒰.fromGlued`. -/
@[simps]
def gluedCover : Scheme.GlueData.{u} where
J := 𝒰.J
U := 𝒰.obj
V := fun ⟨x, y⟩ => pullback (𝒰.map x) (𝒰.map y)
f _ _ := pullback.fst _ _
f_id _ := inferInstance
t _ _ := (pullbackSymmetry _ _).hom
t_id x := by simp
t' x y z := gluedCoverT' 𝒰 x y z
t_fac x y z := by apply pullback.hom_ext <;> simp
-- The `cocycle` field could have been `by tidy` but lean timeouts.
cocycle x y z := glued_cover_cocycle 𝒰 x y z
f_open _ := inferInstance
/-- The canonical morphism from the gluing of an open cover of `X` into `X`.
This is an isomorphism, as witnessed by an `IsIso` instance. -/
def fromGlued : 𝒰.gluedCover.glued ⟶ X := by
fapply Multicoequalizer.desc
· exact fun x => 𝒰.map x
rintro ⟨x, y⟩
change pullback.fst _ _ ≫ _ = ((pullbackSymmetry _ _).hom ≫ pullback.fst _ _) ≫ _
simpa using pullback.condition
@[simp, reassoc]
theorem ι_fromGlued (x : 𝒰.J) : 𝒰.gluedCover.ι x ≫ 𝒰.fromGlued = 𝒰.map x :=
Multicoequalizer.π_desc _ _ _ _ _
theorem fromGlued_injective : Function.Injective 𝒰.fromGlued.base := by
intro x y h
obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x
obtain ⟨j, y, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective y
rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] at h
simp_rw [← Scheme.comp_base] at h
rw [ι_fromGlued, ι_fromGlued] at h
let e :=
(TopCat.pullbackConeIsLimit _ _).conePointUniqueUpToIso
(isLimitOfHasPullbackOfPreservesLimit Scheme.forgetToTop (𝒰.map i) (𝒰.map j))
rw [𝒰.gluedCover.ι_eq_iff]
use e.hom ⟨⟨x, y⟩, h⟩
constructor
· erw [← ConcreteCategory.comp_apply e.hom,
IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left]
rfl
· erw [← ConcreteCategory.comp_apply e.hom, pullbackSymmetry_hom_comp_fst,
IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right]
rfl
instance fromGlued_stalk_iso (x : 𝒰.gluedCover.glued.carrier) :
IsIso (𝒰.fromGlued.stalkMap x) := by
obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x
have := stalkMap_congr_hom _ _ (𝒰.ι_fromGlued i) x
rw [stalkMap_comp, ← IsIso.eq_comp_inv] at this
rw [this]
infer_instance
theorem fromGlued_open_map : IsOpenMap 𝒰.fromGlued.base := by
intro U hU
rw [isOpen_iff_forall_mem_open]
intro x hx
rw [𝒰.gluedCover.isOpen_iff] at hU
use 𝒰.fromGlued.base '' U ∩ Set.range (𝒰.map (𝒰.f x)).base
use Set.inter_subset_left
constructor
· rw [← Set.image_preimage_eq_inter_range]
apply (show IsOpenImmersion (𝒰.map (𝒰.f x)) from inferInstance).base_open.isOpenMap
convert hU (𝒰.f x) using 1
simp only [← ι_fromGlued, gluedCover_U, comp_coeBase, TopCat.hom_comp, ContinuousMap.coe_comp,
Set.preimage_comp]
congr! 1
exact Set.preimage_image_eq _ 𝒰.fromGlued_injective
· exact ⟨hx, 𝒰.covers x⟩
theorem fromGlued_isOpenEmbedding : IsOpenEmbedding 𝒰.fromGlued.base :=
.of_continuous_injective_isOpenMap (by fun_prop) 𝒰.fromGlued_injective 𝒰.fromGlued_open_map
instance : Epi 𝒰.fromGlued.base := by
rw [TopCat.epi_iff_surjective]
intro x
obtain ⟨y, h⟩ := 𝒰.covers x
use (𝒰.gluedCover.ι (𝒰.f x)).base y
rw [← ConcreteCategory.comp_apply]
rw [← 𝒰.ι_fromGlued (𝒰.f x)] at h
exact h
instance fromGlued_open_immersion : IsOpenImmersion 𝒰.fromGlued :=
IsOpenImmersion.of_stalk_iso _ 𝒰.fromGlued_isOpenEmbedding
instance : IsIso 𝒰.fromGlued :=
let F := Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙
SheafedSpace.forgetToPresheafedSpace
have : IsIso (F.map (fromGlued 𝒰)) := by
change IsIso 𝒰.fromGlued.toPshHom
apply PresheafedSpace.IsOpenImmersion.to_iso
isIso_of_reflects_iso _ F
/-- Given an open cover of `X`, and a morphism `𝒰.obj x ⟶ Y` for each open subscheme in the cover,
such that these morphisms are compatible in the intersection (pullback), we may glue the morphisms
together into a morphism `X ⟶ Y`.
Note:
If `X` is exactly (defeq to) the gluing of `U i`, then using `Multicoequalizer.desc` suffices.
-/
def glueMorphisms {Y : Scheme} (f : ∀ x, 𝒰.obj x ⟶ Y)
(hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y) :
X ⟶ Y := by
refine inv 𝒰.fromGlued ≫ ?_
fapply Multicoequalizer.desc
· exact f
rintro ⟨i, j⟩
change pullback.fst _ _ ≫ f i = (_ ≫ _) ≫ f j
simp [pullbackSymmetry_hom_comp_fst]
exact hf i j
@[simp, reassoc]
theorem ι_glueMorphisms {Y : Scheme} (f : ∀ x, 𝒰.obj x ⟶ Y)
(hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y)
(x : 𝒰.J) : 𝒰.map x ≫ 𝒰.glueMorphisms f hf = f x := by
rw [← ι_fromGlued, Category.assoc, glueMorphisms, IsIso.hom_inv_id_assoc]
erw [Multicoequalizer.π_desc]
theorem hom_ext {Y : Scheme} (f₁ f₂ : X ⟶ Y) (h : ∀ x, 𝒰.map x ≫ f₁ = 𝒰.map x ≫ f₂) : f₁ = f₂ := by
rw [← cancel_epi 𝒰.fromGlued]
apply Multicoequalizer.hom_ext
intro x
rw [fromGlued, Multicoequalizer.π_desc_assoc, Multicoequalizer.π_desc_assoc]
exact h x
end Cover
end Scheme
end AlgebraicGeometry
| Mathlib/AlgebraicGeometry/Gluing.lean | 473 | 479 | |
/-
Copyright (c) 2021 Praneeth Kolichala. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Praneeth Kolichala
-/
import Mathlib.Topology.Constructions
import Mathlib.Topology.Homotopy.Path
/-!
# Product of homotopies
In this file, we introduce definitions for the product of
homotopies. We show that the products of relative homotopies
are still relative homotopies. Finally, we specialize to the case
of path homotopies, and provide the definition for the product of path classes.
We show various lemmas associated with these products, such as the fact that
path products commute with path composition, and that projection is the inverse
of products.
## Definitions
### General homotopies
- `ContinuousMap.Homotopy.pi homotopies`: Let f and g be a family of functions
indexed on I, such that for each i ∈ I, fᵢ and gᵢ are maps from A to Xᵢ.
Let `homotopies` be a family of homotopies from fᵢ to gᵢ for each i.
Then `Homotopy.pi homotopies` is the canonical homotopy
from ∏ f to ∏ g, where ∏ f is the product map from A to Πi, Xᵢ,
and similarly for ∏ g.
- `ContinuousMap.HomotopyRel.pi homotopies`: Same as `ContinuousMap.Homotopy.pi`, but
all homotopies are done relative to some set S ⊆ A.
- `ContinuousMap.Homotopy.prod F G` is the product of homotopies F and G,
where F is a homotopy between f₀ and f₁, G is a homotopy between g₀ and g₁.
The result F × G is a homotopy between (f₀ × g₀) and (f₁ × g₁).
Again, all homotopies are done relative to S.
- `ContinuousMap.HomotopyRel.prod F G`: Same as `ContinuousMap.Homotopy.prod`, but
all homotopies are done relative to some set S ⊆ A.
### Path products
- `Path.Homotopic.pi` The product of a family of path classes, where a path class is an equivalence
class of paths up to path homotopy.
- `Path.Homotopic.prod` The product of two path classes.
-/
noncomputable section
namespace ContinuousMap
open ContinuousMap
section Pi
variable {I A : Type*} {X : I → Type*} [∀ i, TopologicalSpace (X i)] [TopologicalSpace A]
{f g : ∀ i, C(A, X i)} {S : Set A}
/-- The relative product homotopy of `homotopies` between functions `f` and `g` -/
@[simps!]
def HomotopyRel.pi (homotopies : ∀ i : I, HomotopyRel (f i) (g i) S) :
HomotopyRel (pi f) (pi g) S :=
{ Homotopy.pi fun i => (homotopies i).toHomotopy with
prop' := by
intro t x hx
dsimp only [coe_mk, pi_eval, toFun_eq_coe, HomotopyWith.coe_toContinuousMap]
simp only [funext_iff, ← forall_and]
intro i
exact (homotopies i).prop' t x hx }
end Pi
section Prod
variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {A : Type*} [TopologicalSpace A]
{f₀ f₁ : C(A, α)} {g₀ g₁ : C(A, β)} {S : Set A}
/-- The product of homotopies `F` and `G`,
where `F` takes `f₀` to `f₁` and `G` takes `g₀` to `g₁` -/
@[simps]
def Homotopy.prod (F : Homotopy f₀ f₁) (G : Homotopy g₀ g₁) :
Homotopy (ContinuousMap.prodMk f₀ g₀) (ContinuousMap.prodMk f₁ g₁) where
toFun t := (F t, G t)
map_zero_left x := by simp only [prod_eval, Homotopy.apply_zero]
map_one_left x := by simp only [prod_eval, Homotopy.apply_one]
/-- The relative product of homotopies `F` and `G`,
where `F` takes `f₀` to `f₁` and `G` takes `g₀` to `g₁` -/
@[simps!]
def HomotopyRel.prod (F : HomotopyRel f₀ f₁ S) (G : HomotopyRel g₀ g₁ S) :
HomotopyRel (prodMk f₀ g₀) (prodMk f₁ g₁) S where
toHomotopy := Homotopy.prod F.toHomotopy G.toHomotopy
prop' t x hx := Prod.ext (F.prop' t x hx) (G.prop' t x hx)
end Prod
end ContinuousMap
namespace Path.Homotopic
attribute [local instance] Path.Homotopic.setoid
local infixl:70 " ⬝ " => Quotient.comp
section Pi
variable {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {as bs cs : ∀ i, X i}
/-- The product of a family of path homotopies. This is just a specialization of `HomotopyRel`. -/
def piHomotopy (γ₀ γ₁ : ∀ i, Path (as i) (bs i)) (H : ∀ i, Path.Homotopy (γ₀ i) (γ₁ i)) :
Path.Homotopy (Path.pi γ₀) (Path.pi γ₁) :=
ContinuousMap.HomotopyRel.pi H
/-- The product of a family of path homotopy classes. -/
def pi (γ : ∀ i, Path.Homotopic.Quotient (as i) (bs i)) : Path.Homotopic.Quotient as bs :=
(Quotient.map Path.pi fun x y hxy =>
Nonempty.map (piHomotopy x y) (Classical.nonempty_pi.mpr hxy)) (Quotient.choice γ)
theorem pi_lift (γ : ∀ i, Path (as i) (bs i)) :
(Path.Homotopic.pi fun i => ⟦γ i⟧) = ⟦Path.pi γ⟧ := by unfold pi; simp
/-- Composition and products commute.
This is `Path.trans_pi_eq_pi_trans` descended to path homotopy classes. -/
theorem comp_pi_eq_pi_comp (γ₀ : ∀ i, Path.Homotopic.Quotient (as i) (bs i))
(γ₁ : ∀ i, Path.Homotopic.Quotient (bs i) (cs i)) : pi γ₀ ⬝ pi γ₁ = pi fun i ↦ γ₀ i ⬝ γ₁ i := by
induction γ₁ using Quotient.induction_on_pi with | _ a =>
induction γ₀ using Quotient.induction_on_pi
simp only [pi_lift]
rw [← Path.Homotopic.comp_lift, Path.trans_pi_eq_pi_trans, ← pi_lift]
rfl
/-- Abbreviation for projection onto the ith coordinate. -/
abbrev proj (i : ι) (p : Path.Homotopic.Quotient as bs) : Path.Homotopic.Quotient (as i) (bs i) :=
p.mapFn ⟨_, continuous_apply i⟩
/-- Lemmas showing projection is the inverse of pi. -/
@[simp]
theorem proj_pi (i : ι) (paths : ∀ i, Path.Homotopic.Quotient (as i) (bs i)) :
proj i (pi paths) = paths i := by
induction paths using Quotient.induction_on_pi
rw [proj, pi_lift, ← Path.Homotopic.map_lift]
congr
@[simp]
theorem pi_proj (p : Path.Homotopic.Quotient as bs) : (pi fun i => proj i p) = p := by
induction p using Quotient.inductionOn
simp_rw [proj, ← Path.Homotopic.map_lift]
erw [pi_lift]
congr
end Pi
section Prod
variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {a₁ a₂ a₃ : α} {b₁ b₂ b₃ : β}
{p₁ p₁' : Path a₁ a₂} {p₂ p₂' : Path b₁ b₂} (q₁ : Path.Homotopic.Quotient a₁ a₂)
(q₂ : Path.Homotopic.Quotient b₁ b₂)
/-- The product of homotopies h₁ and h₂.
This is `HomotopyRel.prod` specialized for path homotopies. -/
def prodHomotopy (h₁ : Path.Homotopy p₁ p₁') (h₂ : Path.Homotopy p₂ p₂') :
Path.Homotopy (p₁.prod p₂) (p₁'.prod p₂') :=
ContinuousMap.HomotopyRel.prod h₁ h₂
/-- The product of path classes q₁ and q₂. This is `Path.prod` descended to the quotient. -/
def prod (q₁ : Path.Homotopic.Quotient a₁ a₂) (q₂ : Path.Homotopic.Quotient b₁ b₂) :
Path.Homotopic.Quotient (a₁, b₁) (a₂, b₂) :=
Quotient.map₂ Path.prod (fun _ _ h₁ _ _ h₂ => Nonempty.map2 prodHomotopy h₁ h₂) q₁ q₂
variable (p₁ p₁' p₂ p₂')
theorem prod_lift : prod ⟦p₁⟧ ⟦p₂⟧ = ⟦p₁.prod p₂⟧ :=
rfl
variable (r₁ : Path.Homotopic.Quotient a₂ a₃) (r₂ : Path.Homotopic.Quotient b₂ b₃)
/-- Products commute with path composition.
This is `trans_prod_eq_prod_trans` descended to the quotient. -/
theorem comp_prod_eq_prod_comp : prod q₁ q₂ ⬝ prod r₁ r₂ = prod (q₁ ⬝ r₁) (q₂ ⬝ r₂) := by
induction q₁, q₂ using Quotient.inductionOn₂
induction r₁, r₂ using Quotient.inductionOn₂
simp only [prod_lift, ← Path.Homotopic.comp_lift, Path.trans_prod_eq_prod_trans]
variable {c₁ c₂ : α × β}
/-- Abbreviation for projection onto the left coordinate of a path class. -/
abbrev projLeft (p : Path.Homotopic.Quotient c₁ c₂) : Path.Homotopic.Quotient c₁.1 c₂.1 :=
p.mapFn ⟨_, continuous_fst⟩
/-- Abbreviation for projection onto the right coordinate of a path class. -/
abbrev projRight (p : Path.Homotopic.Quotient c₁ c₂) : Path.Homotopic.Quotient c₁.2 c₂.2 :=
p.mapFn ⟨_, continuous_snd⟩
/-- Lemmas showing projection is the inverse of product. -/
@[simp]
theorem projLeft_prod : projLeft (prod q₁ q₂) = q₁ := by
induction q₁, q₂ using Quotient.inductionOn₂
rw [projLeft, prod_lift, ← Path.Homotopic.map_lift]
congr
@[simp]
theorem projRight_prod : projRight (prod q₁ q₂) = q₂ := by
induction q₁, q₂ using Quotient.inductionOn₂
rw [projRight, prod_lift, ← Path.Homotopic.map_lift]
congr
| @[simp]
theorem prod_projLeft_projRight (p : Path.Homotopic.Quotient (a₁, b₁) (a₂, b₂)) :
prod (projLeft p) (projRight p) = p := by
induction p using Quotient.inductionOn
simp only [projLeft, projRight, ← Path.Homotopic.map_lift, prod_lift]
congr
| Mathlib/Topology/Homotopy/Product.lean | 207 | 212 |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Group.GeometryOfNumbers
import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
/-!
# Convex Bodies
The file contains the definitions of several convex bodies lying in the mixed space `ℝ^r₁ × ℂ^r₂`
associated to a number field of signature `K` and proves several existence theorems by applying
*Minkowski Convex Body Theorem* to those.
## Main definitions and results
* `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all
infinite places `w` with `f : InfinitePlace K → ℝ≥0`.
* `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`.
Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a
nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`.
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal
of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see
`convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic
number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.mixedEmbedding
open NumberField NumberField.InfinitePlace Module
section convexBodyLT
open Metric NNReal
variable (f : InfinitePlace K → ℝ≥0)
/-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all
infinite places `w`. -/
abbrev convexBodyLT : Set (mixedSpace K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w)))
theorem convexBodyLT_mem {x : K} :
mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real,
embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em,
| forall_true_left, norm_embedding_eq]
theorem convexBodyLT_neg_mem (x : mixedSpace K) (hx : x ∈ (convexBodyLT K f)) :
-x ∈ (convexBodyLT K f) := by
simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean | 63 | 68 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.Trim
import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. This property, called `AEMeasurable f μ`, is defined in the file `MeasureSpaceDef`.
We discuss several of its properties that are analogous to properties of measurable functions.
-/
open MeasureTheory MeasureTheory.Measure Filter Set Function ENNReal
variable {ι α β γ δ R : Type*} {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ] {f g : α → β} {μ ν : Measure α}
section
@[nontriviality, measurability]
theorem Subsingleton.aemeasurable [Subsingleton α] : AEMeasurable f μ :=
Subsingleton.measurable.aemeasurable
@[nontriviality, measurability]
theorem aemeasurable_of_subsingleton_codomain [Subsingleton β] : AEMeasurable f μ :=
(measurable_of_subsingleton_codomain f).aemeasurable
@[simp, measurability]
theorem aemeasurable_zero_measure : AEMeasurable f (0 : Measure α) := by
nontriviality α; inhabit α
exact ⟨fun _ => f default, measurable_const, rfl⟩
@[fun_prop]
theorem aemeasurable_id'' (μ : Measure α) {m : MeasurableSpace α} (hm : m ≤ m0) :
@AEMeasurable α α m m0 id μ :=
@Measurable.aemeasurable α α m0 m id μ (measurable_id'' hm)
lemma aemeasurable_of_map_neZero {μ : Measure α}
{f : α → β} (h : NeZero (μ.map f)) :
AEMeasurable f μ := by
by_contra h'
simp [h'] at h
namespace AEMeasurable
lemma mono_ac (hf : AEMeasurable f ν) (hμν : μ ≪ ν) : AEMeasurable f μ :=
⟨hf.mk f, hf.measurable_mk, hμν.ae_le hf.ae_eq_mk⟩
theorem mono_measure (h : AEMeasurable f μ) (h' : ν ≤ μ) : AEMeasurable f ν :=
mono_ac h h'.absolutelyContinuous
theorem mono_set {s t} (h : s ⊆ t) (ht : AEMeasurable f (μ.restrict t)) :
AEMeasurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
@[fun_prop]
protected theorem mono' (h : AEMeasurable f μ) (h' : ν ≪ μ) : AEMeasurable f ν :=
⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩
theorem ae_mem_imp_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
theorem ae_inf_principal_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) : f =ᶠ[ae μ ⊓ 𝓟 s] h.mk f :=
le_ae_restrict h.ae_eq_mk
@[measurability]
theorem sum_measure [Countable ι] {μ : ι → Measure α} (h : ∀ i, AEMeasurable f (μ i)) :
AEMeasurable f (sum μ) := by
classical
nontriviality β
inhabit β
set s : ι → Set α := fun i => toMeasurable (μ i) { x | f x ≠ (h i).mk f x }
have hsμ : ∀ i, μ i (s i) = 0 := by
intro i
rw [measure_toMeasurable]
exact (h i).ae_eq_mk
have hsm : MeasurableSet (⋂ i, s i) :=
MeasurableSet.iInter fun i => measurableSet_toMeasurable _ _
have hs : ∀ i x, x ∉ s i → f x = (h i).mk f x := by
intro i x hx
contrapose! hx
exact subset_toMeasurable _ _ hx
set g : α → β := (⋂ i, s i).piecewise (const α default) f
refine ⟨g, measurable_of_restrict_of_restrict_compl hsm ?_ ?_, ae_sum_iff.mpr fun i => ?_⟩
· rw [restrict_piecewise]
simp only [s, Set.restrict, const]
exact measurable_const
· rw [restrict_piecewise_compl, compl_iInter]
intro t ht
refine ⟨⋃ i, (h i).mk f ⁻¹' t ∩ (s i)ᶜ, MeasurableSet.iUnion fun i ↦
(measurable_mk _ ht).inter (measurableSet_toMeasurable _ _).compl, ?_⟩
ext ⟨x, hx⟩
simp only [mem_preimage, mem_iUnion, Subtype.coe_mk, Set.restrict, mem_inter_iff,
mem_compl_iff] at hx ⊢
constructor
· rintro ⟨i, hxt, hxs⟩
rwa [hs _ _ hxs]
· rcases hx with ⟨i, hi⟩
rw [hs _ _ hi]
exact fun h => ⟨i, h, hi⟩
· refine measure_mono_null (fun x (hx : f x ≠ g x) => ?_) (hsμ i)
contrapose! hx
refine (piecewise_eq_of_not_mem _ _ _ ?_).symm
exact fun h => hx (mem_iInter.1 h i)
@[simp]
theorem _root_.aemeasurable_sum_measure_iff [Countable ι] {μ : ι → Measure α} :
AEMeasurable f (sum μ) ↔ ∀ i, AEMeasurable f (μ i) :=
⟨fun h _ => h.mono_measure (le_sum _ _), sum_measure⟩
@[simp]
theorem _root_.aemeasurable_add_measure_iff :
AEMeasurable f (μ + ν) ↔ AEMeasurable f μ ∧ AEMeasurable f ν := by
rw [← sum_cond, aemeasurable_sum_measure_iff, Bool.forall_bool, and_comm]
rfl
@[measurability]
theorem add_measure {f : α → β} (hμ : AEMeasurable f μ) (hν : AEMeasurable f ν) :
AEMeasurable f (μ + ν) :=
aemeasurable_add_measure_iff.2 ⟨hμ, hν⟩
@[measurability]
protected theorem iUnion [Countable ι] {s : ι → Set α}
(h : ∀ i, AEMeasurable f (μ.restrict (s i))) : AEMeasurable f (μ.restrict (⋃ i, s i)) :=
(sum_measure h).mono_measure <| restrict_iUnion_le
@[simp]
theorem _root_.aemeasurable_iUnion_iff [Countable ι] {s : ι → Set α} :
AEMeasurable f (μ.restrict (⋃ i, s i)) ↔ ∀ i, AEMeasurable f (μ.restrict (s i)) :=
⟨fun h _ => h.mono_measure <| restrict_mono (subset_iUnion _ _) le_rfl, AEMeasurable.iUnion⟩
@[simp]
theorem _root_.aemeasurable_union_iff {s t : Set α} :
AEMeasurable f (μ.restrict (s ∪ t)) ↔
AEMeasurable f (μ.restrict s) ∧ AEMeasurable f (μ.restrict t) := by
simp only [union_eq_iUnion, aemeasurable_iUnion_iff, Bool.forall_bool, cond, and_comm]
@[measurability]
theorem smul_measure [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : AEMeasurable f μ) (c : R) : AEMeasurable f (c • μ) :=
⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
theorem comp_aemeasurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (g ∘ f) μ :=
⟨hg.mk g ∘ hf.mk f, hg.measurable_mk.comp hf.measurable_mk,
(ae_eq_comp hf hg.ae_eq_mk).trans (hf.ae_eq_mk.fun_comp (mk g hg))⟩
@[fun_prop]
theorem comp_aemeasurable' {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (fun x ↦ g (f x)) μ := comp_aemeasurable hg hf
theorem comp_measurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : Measurable f) : AEMeasurable (g ∘ f) μ :=
hg.comp_aemeasurable hf.aemeasurable
theorem comp_quasiMeasurePreserving {ν : Measure δ} {f : α → δ} {g : δ → β} (hg : AEMeasurable g ν)
(hf : QuasiMeasurePreserving f μ ν) : AEMeasurable (g ∘ f) μ :=
(hg.mono' hf.absolutelyContinuous).comp_measurable hf.measurable
theorem map_map_of_aemeasurable {g : β → γ} {f : α → β} (hg : AEMeasurable g (Measure.map f μ))
(hf : AEMeasurable f μ) : (μ.map f).map g = μ.map (g ∘ f) := by
ext1 s hs
rw [map_apply_of_aemeasurable hg hs, map_apply₀ hf (hg.nullMeasurable hs),
map_apply_of_aemeasurable (hg.comp_aemeasurable hf) hs, preimage_comp]
@[fun_prop, measurability]
theorem prodMk {f : α → β} {g : α → γ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (fun x => (f x, g x)) μ :=
⟨fun a => (hf.mk f a, hg.mk g a), hf.measurable_mk.prodMk hg.measurable_mk,
hf.ae_eq_mk.prodMk hg.ae_eq_mk⟩
@[deprecated (since := "2025-03-05")]
alias prod_mk := prodMk
theorem exists_ae_eq_range_subset (H : AEMeasurable f μ) {t : Set β} (ht : ∀ᵐ x ∂μ, f x ∈ t)
(h₀ : t.Nonempty) : ∃ g, Measurable g ∧ range g ⊆ t ∧ f =ᵐ[μ] g := by
classical
let s : Set α := toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ
let g : α → β := piecewise s (fun _ => h₀.some) (H.mk f)
refine ⟨g, ?_, ?_, ?_⟩
· exact Measurable.piecewise (measurableSet_toMeasurable _ _) measurable_const H.measurable_mk
· rintro _ ⟨x, rfl⟩
by_cases hx : x ∈ s
· simpa [g, hx] using h₀.some_mem
· simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp +contextual only [hx, mem_compl_iff, mem_setOf_eq, not_and,
not_false_iff, imp_true_iff]
· have A : μ (toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ) = 0 := by
rw [measure_toMeasurable, ← compl_mem_ae_iff, compl_compl]
exact H.ae_eq_mk.and ht
filter_upwards [compl_mem_ae_iff.2 A] with x hx
rw [mem_compl_iff] at hx
simp only [s, g, hx, piecewise_eq_of_not_mem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp only [hx, mem_compl_iff, mem_setOf_eq, false_and, not_false_iff]
theorem exists_measurable_nonneg {β} [Preorder β] [Zero β] {mβ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (f_nn : ∀ᵐ t ∂μ, 0 ≤ f t) : ∃ g, Measurable g ∧ 0 ≤ g ∧ f =ᵐ[μ] g := by
obtain ⟨G, hG_meas, hG_mem, hG_ae_eq⟩ := hf.exists_ae_eq_range_subset f_nn ⟨0, le_rfl⟩
exact ⟨G, hG_meas, fun x => hG_mem (mem_range_self x), hG_ae_eq⟩
theorem subtype_mk (h : AEMeasurable f μ) {s : Set β} {hfs : ∀ x, f x ∈ s} :
AEMeasurable (codRestrict f s hfs) μ := by
nontriviality α; inhabit α
obtain ⟨g, g_meas, hg, fg⟩ : ∃ g : α → β, Measurable g ∧ range g ⊆ s ∧ f =ᵐ[μ] g :=
h.exists_ae_eq_range_subset (Eventually.of_forall hfs) ⟨_, hfs default⟩
refine ⟨codRestrict g s fun x => hg (mem_range_self _), Measurable.subtype_mk g_meas, ?_⟩
filter_upwards [fg] with x hx
simpa [Subtype.ext_iff]
end AEMeasurable
theorem aemeasurable_const' (h : ∀ᵐ (x) (y) ∂μ, f x = f y) : AEMeasurable f μ := by
rcases eq_or_ne μ 0 with (rfl | hμ)
· exact aemeasurable_zero_measure
· haveI := ae_neBot.2 hμ
rcases h.exists with ⟨x, hx⟩
exact ⟨const α (f x), measurable_const, EventuallyEq.symm hx⟩
open scoped Interval in
theorem aemeasurable_uIoc_iff [LinearOrder α] {f : α → β} {a b : α} :
(AEMeasurable f <| μ.restrict <| Ι a b) ↔
(AEMeasurable f <| μ.restrict <| Ioc a b) ∧ (AEMeasurable f <| μ.restrict <| Ioc b a) := by
rw [uIoc_eq_union, aemeasurable_union_iff]
theorem aemeasurable_iff_measurable [μ.IsComplete] : AEMeasurable f μ ↔ Measurable f :=
⟨fun h => h.nullMeasurable.measurable_of_complete, fun h => h.aemeasurable⟩
theorem MeasurableEmbedding.aemeasurable_map_iff {g : β → γ} (hf : MeasurableEmbedding f) :
AEMeasurable g (μ.map f) ↔ AEMeasurable (g ∘ f) μ := by
refine ⟨fun H => H.comp_measurable hf.measurable, ?_⟩
rintro ⟨g₁, hgm₁, heq⟩
rcases hf.exists_measurable_extend hgm₁ fun x => ⟨g x⟩ with ⟨g₂, hgm₂, rfl⟩
exact ⟨g₂, hgm₂, hf.ae_map_iff.2 heq⟩
theorem MeasurableEmbedding.aemeasurable_comp_iff {g : β → γ} (hg : MeasurableEmbedding g)
{μ : Measure α} : AEMeasurable (g ∘ f) μ ↔ AEMeasurable f μ := by
refine ⟨fun H => ?_, hg.measurable.comp_aemeasurable⟩
suffices AEMeasurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) μ by
rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this
exact hg.measurable_rangeSplitting.comp_aemeasurable H.subtype_mk
theorem aemeasurable_restrict_iff_comap_subtype {s : Set α} (hs : MeasurableSet s) {μ : Measure α}
{f : α → β} : AEMeasurable f (μ.restrict s) ↔ AEMeasurable (f ∘ (↑) : s → β) (comap (↑) μ) := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).aemeasurable_map_iff]
@[to_additive]
theorem aemeasurable_one [One β] : AEMeasurable (fun _ : α => (1 : β)) μ :=
measurable_one.aemeasurable
@[simp]
theorem aemeasurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :
AEMeasurable f (c • μ) ↔ AEMeasurable f μ :=
⟨fun h => ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩, fun h =>
⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩
theorem aemeasurable_of_aemeasurable_trim {α} {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) {f : α → β} (hf : AEMeasurable f (μ.trim hm)) : AEMeasurable f μ :=
⟨hf.mk f, Measurable.mono hf.measurable_mk hm le_rfl, ae_eq_of_ae_eq_trim hf.ae_eq_mk⟩
theorem aemeasurable_restrict_of_measurable_subtype {s : Set α} (hs : MeasurableSet s)
(hf : Measurable fun x : s => f x) : AEMeasurable f (μ.restrict s) :=
(aemeasurable_restrict_iff_comap_subtype hs).2 hf.aemeasurable
theorem aemeasurable_map_equiv_iff (e : α ≃ᵐ β) {f : β → γ} :
AEMeasurable f (μ.map e) ↔ AEMeasurable (f ∘ e) μ :=
e.measurableEmbedding.aemeasurable_map_iff
end
theorem AEMeasurable.restrict (hfm : AEMeasurable f μ) {s} : AEMeasurable f (μ.restrict s) :=
⟨AEMeasurable.mk f hfm, hfm.measurable_mk, ae_restrict_of_ae hfm.ae_eq_mk⟩
theorem aemeasurable_Ioi_of_forall_Ioc {β} {mβ : MeasurableSpace β} [LinearOrder α]
[(atTop : Filter α).IsCountablyGenerated] {x : α} {g : α → β}
(g_meas : ∀ t > x, AEMeasurable g (μ.restrict (Ioc x t))) :
AEMeasurable g (μ.restrict (Ioi x)) := by
haveI : Nonempty α := ⟨x⟩
obtain ⟨u, hu_tendsto⟩ := exists_seq_tendsto (atTop : Filter α)
have Ioi_eq_iUnion : Ioi x = ⋃ n : ℕ, Ioc x (u n) := by
rw [iUnion_Ioc_eq_Ioi_self_iff.mpr _]
exact fun y _ => (hu_tendsto.eventually (eventually_ge_atTop y)).exists
rw [Ioi_eq_iUnion, aemeasurable_iUnion_iff]
intro n
rcases lt_or_le x (u n) with h | h
· exact g_meas (u n) h
· rw [Ioc_eq_empty (not_lt.mpr h), Measure.restrict_empty]
exact aemeasurable_zero_measure
section Zero
variable [Zero β]
theorem aemeasurable_indicator_iff {s} (hs : MeasurableSet s) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
constructor
· intro h
exact (h.mono_measure Measure.restrict_le_self).congr (indicator_ae_eq_restrict hs)
· intro h
refine ⟨indicator s (h.mk f), h.measurable_mk.indicator hs, ?_⟩
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans <| (indicator_ae_eq_restrict hs).symm)
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm
exact ae_of_ae_restrict_of_ae_restrict_compl _ A B
theorem aemeasurable_indicator_iff₀ {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
rcases hs with ⟨t, ht, hst⟩
rw [← aemeasurable_congr (indicator_ae_eq_of_ae_eq_set hst.symm), aemeasurable_indicator_iff ht,
restrict_congr_set hst]
/-- A characterization of the a.e.-measurability of the indicator function which takes a constant
value `b` on a set `A` and `0` elsewhere. -/
lemma aemeasurable_indicator_const_iff {s} [MeasurableSingletonClass β] (b : β) [NeZero b] :
AEMeasurable (s.indicator (fun _ ↦ b)) μ ↔ NullMeasurableSet s μ := by
classical
constructor <;> intro h
· convert h.nullMeasurable (MeasurableSet.singleton (0 : β)).compl
rw [indicator_const_preimage_eq_union s {0}ᶜ b]
simp [NeZero.ne b]
· exact (aemeasurable_indicator_iff₀ h).mpr aemeasurable_const
@[measurability]
theorem AEMeasurable.indicator (hfm : AEMeasurable f μ) {s} (hs : MeasurableSet s) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff hs).mpr hfm.restrict
theorem AEMeasurable.indicator₀ (hfm : AEMeasurable f μ) {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff₀ hs).mpr hfm.restrict
end Zero
theorem MeasureTheory.Measure.restrict_map_of_aemeasurable {f : α → δ} (hf : AEMeasurable f μ)
{s : Set δ} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
calc
(μ.map f).restrict s = (μ.map (hf.mk f)).restrict s := by
congr 1
apply Measure.map_congr hf.ae_eq_mk
_ = (μ.restrict <| hf.mk f ⁻¹' s).map (hf.mk f) := Measure.restrict_map hf.measurable_mk hs
_ = (μ.restrict <| hf.mk f ⁻¹' s).map f :=
(Measure.map_congr (ae_restrict_of_ae hf.ae_eq_mk.symm))
_ = (μ.restrict <| f ⁻¹' s).map f := by
apply congr_arg
ext1 t ht
simp only [ht, Measure.restrict_apply]
apply measure_congr
apply (EventuallyEq.refl _ _).inter (hf.ae_eq_mk.symm.preimage s)
theorem MeasureTheory.Measure.map_mono_of_aemeasurable {f : α → δ} (h : μ ≤ ν)
(hf : AEMeasurable f ν) : μ.map f ≤ ν.map f :=
le_iff.2 fun s hs ↦ by simpa [hf, hs, hf.mono_measure h] using h (f ⁻¹' s)
/-- If the `σ`-algebra of the codomain of a null measurable function is countably generated,
then the function is a.e.-measurable. -/
lemma MeasureTheory.NullMeasurable.aemeasurable {f : α → β}
[hc : MeasurableSpace.CountablyGenerated β] (h : NullMeasurable f μ) : AEMeasurable f μ := by
classical
nontriviality β; inhabit β
rcases hc.1 with ⟨S, hSc, rfl⟩
choose! T hTf hTm hTeq using fun s hs ↦ (h <| .basic s hs).exists_measurable_subset_ae_eq
choose! U hUf hUm hUeq using fun s hs ↦ (h <| .basic s hs).exists_measurable_superset_ae_eq
set v := ⋃ s ∈ S, U s \ T s
have hvm : MeasurableSet v := .biUnion hSc fun s hs ↦ (hUm s hs).diff (hTm s hs)
have hvμ : μ v = 0 := (measure_biUnion_null_iff hSc).2 fun s hs ↦ ae_le_set.1 <|
((hUeq s hs).trans (hTeq s hs).symm).le
refine ⟨v.piecewise (fun _ ↦ default) f, ?_, measure_mono_null (fun x ↦
not_imp_comm.2 fun hxv ↦ (piecewise_eq_of_not_mem _ _ _ hxv).symm) hvμ⟩
refine measurable_of_restrict_of_restrict_compl hvm ?_ ?_
· rw [restrict_piecewise]
apply measurable_const
· rw [restrict_piecewise_compl, restrict_eq]
refine measurable_generateFrom fun s hs ↦ .of_subtype_image ?_
rw [preimage_comp, Subtype.image_preimage_coe]
convert (hTm s hs).diff hvm using 1
rw [inter_comm]
refine Set.ext fun x ↦ and_congr_left fun hxv ↦ ⟨fun hx ↦ ?_, fun hx ↦ hTf s hs hx⟩
exact by_contra fun hx' ↦ hxv <| mem_biUnion hs ⟨hUf s hs hx, hx'⟩
/-- Let `f : α → β` be a null measurable function
such that a.e. all values of `f` belong to a set `t`
such that the restriction of the `σ`-algebra in the codomain to `t` is countably generated,
then `f` is a.e.-measurable. -/
lemma MeasureTheory.NullMeasurable.aemeasurable_of_aerange {f : α → β} {t : Set β}
[MeasurableSpace.CountablyGenerated t] (h : NullMeasurable f μ) (hft : ∀ᵐ x ∂μ, f x ∈ t) :
AEMeasurable f μ := by
rcases eq_empty_or_nonempty t with rfl | hne
| · obtain rfl : μ = 0 := by simpa using hft
apply aemeasurable_zero_measure
· rw [← μ.ae_completion] at hft
| Mathlib/MeasureTheory/Measure/AEMeasurable.lean | 397 | 399 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes,
angles modulo `π` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `π` can be represented
modulo `2 * π` as equalities of `(2 : ℤ) • θ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V']
variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2))
local notation "ω" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, ← ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π))
apply arg_ofReal_of_nonneg
positivity
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by
rintro rfl; simp at h
/-- If the angle between two vectors is `π`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
/-- Negating the first vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle (-x) y = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the second vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x (-y) = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_left hx hy]
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_right hx hy]
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [← neg_neg y, oangle_neg_neg, neg_neg]
/-- The angle between the negation of a nonzero vector and that vector is `π`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by
simp [oangle_neg_left, hx]
/-- The angle between a nonzero vector and its negation is `π`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by
simp [oangle_neg_right, hx]
/-- Twice the angle between the negation of a vector and that vector is 0. -/
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Twice the angle between a vector and its negation is 0. -/
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel]
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel]
/-- Multiplying the first vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :
o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the second vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :
o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
o.oangle (r • x) y = o.oangle (-x) y := by
rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)]
/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
o.oangle x (r • y) = o.oangle x (-y) := by
rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)]
/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/
@[simp]
theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by
rcases hr.lt_or_eq with (h | h)
· simp [h]
· simp [h.symm]
/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/
@[simp]
theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by
rcases hr.lt_or_eq with (h | h)
· simp [h]
· simp [h.symm]
/-- The angle between two nonnegative multiples of the same vector is 0. -/
@[simp]
theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) :
o.oangle (r₁ • x) (r₂ • x) = 0 := by
rcases hr₁.lt_or_eq with (h | h)
· simp [h, hr₂]
· simp [h.symm]
/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) :
(2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) :
(2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
/-- Twice the angle between a multiple of a vector and that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between a vector and a multiple of that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
/-- Twice the angle between two multiples of a vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} :
(2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h]
/-- If the spans of two vectors are equal, twice angles with those vectors on the left are
equal. -/
theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) :
(2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with ⟨r, rfl⟩
exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two vectors are equal, twice angles with those vectors on the right are
equal. -/
theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) :
(2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with ⟨r, rfl⟩
exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm
/-- If the spans of two pairs of vectors are equal, twice angles between those vectors are
equal. -/
theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x)
(hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by
rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz]
/-- The oriented angle between two vectors is zero if and only if the angle with the vectors
swapped is zero. -/
theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by
rw [oangle_rev, neg_eq_zero]
/-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/
theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by
rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero,
Complex.arg_eq_zero_iff]
simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y
/-- The oriented angle between two vectors is `π` if and only if the angle with the vectors
swapped is `π`. -/
theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by
rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi]
/-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is
on the same ray as the negation of the second. -/
theorem oangle_eq_pi_iff_sameRay_neg {x y : V} :
o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by
rw [← o.oangle_eq_zero_iff_sameRay]
constructor
· intro h
by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h
by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h
refine ⟨hx, hy, ?_⟩
rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi]
· rintro ⟨hx, hy, h⟩
rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h
/-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are
not linearly independent. -/
theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} :
o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg,
| sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent]
/-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero
or the second is a multiple of the first. -/
theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} :
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 380 | 384 |
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.RatFunc.Defs
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Content
/-!
# The field structure of rational functions
## Main definitions
Working with rational functions as polynomials:
- `RatFunc.instField` provides a field structure
You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials:
* `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions
* `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`,
in particular:
* `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of
fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change
the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`.
Working with rational functions as fractions:
- `RatFunc.num` and `RatFunc.denom` give the numerator and denominator.
These values are chosen to be coprime and such that `RatFunc.denom` is monic.
Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long
as the homomorphism retains the non-zero-divisor property:
- `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to
a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]`
- `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`,
where `[CommRing K] [Field L]`
- `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`,
where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]`
This is satisfied by injective homs.
We also have lifting homomorphisms of polynomials to other polynomials,
with the same condition on retaining the non-zero-divisor property across the map:
- `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when
`[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]`
-/
universe u v
noncomputable section
open scoped nonZeroDivisors Polynomial
variable {K : Type u}
namespace RatFunc
section Field
variable [CommRing K]
/-- The zero rational function. -/
protected irreducible_def zero : RatFunc K :=
⟨0⟩
instance : Zero (RatFunc K) :=
⟨RatFunc.zero⟩
theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 :=
zero_def.symm
/-- Addition of rational functions. -/
protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p + q⟩
instance : Add (RatFunc K) :=
⟨RatFunc.add⟩
theorem ofFractionRing_add (p q : FractionRing K[X]) :
ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q :=
(add_def _ _).symm
/-- Subtraction of rational functions. -/
protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p - q⟩
instance : Sub (RatFunc K) :=
⟨RatFunc.sub⟩
theorem ofFractionRing_sub (p q : FractionRing K[X]) :
ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q :=
(sub_def _ _).symm
/-- Additive inverse of a rational function. -/
protected irreducible_def neg : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨-p⟩
instance : Neg (RatFunc K) :=
⟨RatFunc.neg⟩
theorem ofFractionRing_neg (p : FractionRing K[X]) :
ofFractionRing (-p) = -ofFractionRing p :=
(neg_def _).symm
/-- The multiplicative unit of rational functions. -/
protected irreducible_def one : RatFunc K :=
⟨1⟩
instance : One (RatFunc K) :=
⟨RatFunc.one⟩
theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 :=
one_def.symm
/-- Multiplication of rational functions. -/
protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p * q⟩
instance : Mul (RatFunc K) :=
⟨RatFunc.mul⟩
theorem ofFractionRing_mul (p q : FractionRing K[X]) :
ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q :=
(mul_def _ _).symm
section IsDomain
variable [IsDomain K]
/-- Division of rational functions. -/
protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p / q⟩
instance : Div (RatFunc K) :=
⟨RatFunc.div⟩
theorem ofFractionRing_div (p q : FractionRing K[X]) :
ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q :=
(div_def _ _).symm
/-- Multiplicative inverse of a rational function. -/
protected irreducible_def inv : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨p⁻¹⟩
instance : Inv (RatFunc K) :=
⟨RatFunc.inv⟩
theorem ofFractionRing_inv (p : FractionRing K[X]) :
ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ :=
(inv_def _).symm
-- Auxiliary lemma for the `Field` instance
theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1
| ⟨p⟩, h => by
have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero]
simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one,
ofFractionRing.injEq] using
mul_inv_cancel₀ this
end IsDomain
section SMul
variable {R : Type*}
/-- Scalar multiplication of rational functions. -/
protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K
| r, ⟨p⟩ => ⟨r • p⟩
instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) :=
⟨RatFunc.smul⟩
theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) :
ofFractionRing (c • p) = c • ofFractionRing p :=
(smul_def _ _).symm
theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) :
toFractionRing (c • p) = c • toFractionRing p := by
cases p
rw [← ofFractionRing_smul]
theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by
obtain ⟨x⟩ := x
induction x using Localization.induction_on
rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk,
Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul]
section IsDomain
variable [IsDomain K]
variable [Monoid R] [DistribMulAction R K[X]]
variable [IsScalarTower R K[X] K[X]]
theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by
letI : SMulZeroClass R (FractionRing K[X]) := inferInstance
by_cases hq : q = 0
· rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero]
· rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ←
ofFractionRing_smul]
instance : IsScalarTower R K[X] (RatFunc K) :=
⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩
end IsDomain
end SMul
variable (K)
instance [Subsingleton K] : Subsingleton (RatFunc K) :=
toFractionRing_injective.subsingleton
instance : Inhabited (RatFunc K) :=
⟨0⟩
instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) :=
ofFractionRing_injective.nontrivial
/-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings.
This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`.
-/
@[simps apply]
def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where
toFun := toFractionRing
invFun := ofFractionRing
left_inv := fun ⟨_⟩ => rfl
right_inv _ := rfl
map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add]
map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul]
end Field
section TacticInterlude
/-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/
macro "frac_tac" : tactic => `(tactic|
· repeat (rintro (⟨⟩ : RatFunc _))
try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub,
← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div,
← ofFractionRing_inv,
add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero,
add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv,
add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_neg_cancel])
/-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/
macro "smul_tac" : tactic => `(tactic|
repeat
(first
| rintro (⟨⟩ : RatFunc _)
| intro) <;>
simp_rw [← ofFractionRing_smul] <;>
simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero,
neg_add, mul_neg,
Int.cast_zero, Int.cast_add, Int.cast_one,
Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ,
Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk,
ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg])
end TacticInterlude
section CommRing
variable (K) [CommRing K]
/-- `RatFunc K` is a commutative monoid.
This is an intermediate step on the way to the full instance `RatFunc.instCommRing`.
-/
def instCommMonoid : CommMonoid (RatFunc K) where
mul := (· * ·)
mul_assoc := by frac_tac
mul_comm := by frac_tac
one := 1
one_mul := by frac_tac
mul_one := by frac_tac
npow := npowRec
/-- `RatFunc K` is an additive commutative group.
This is an intermediate step on the way to the full instance `RatFunc.instCommRing`.
-/
def instAddCommGroup : AddCommGroup (RatFunc K) where
add := (· + ·)
add_assoc := by frac_tac
add_comm := by frac_tac
zero := 0
zero_add := by frac_tac
add_zero := by frac_tac
neg := Neg.neg
neg_add_cancel := by frac_tac
sub := Sub.sub
sub_eq_add_neg := by frac_tac
nsmul := (· • ·)
nsmul_zero := by smul_tac
nsmul_succ _ := by smul_tac
zsmul := (· • ·)
zsmul_zero' := by smul_tac
zsmul_succ' _ := by smul_tac
zsmul_neg' _ := by smul_tac
instance instCommRing : CommRing (RatFunc K) :=
{ instCommMonoid K, instAddCommGroup K with
zero := 0
sub := Sub.sub
zero_mul := by frac_tac
mul_zero := by frac_tac
left_distrib := by frac_tac
right_distrib := by frac_tac
one := 1
nsmul := (· • ·)
zsmul := (· • ·)
npow := npowRec }
variable {K}
section LiftHom
open RatFunc
variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S]
variable [FunLike F R[X] S[X]]
open scoped Classical in
/-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]`
to a `RatFunc R →* RatFunc S`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
RatFunc R →* RatFunc S where
toFun f :=
RatFunc.liftOn f
(fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0)
fun {p q p' q'} hq hq' h => by
simp only [Submonoid.mem_comap.mp (hφ hq), Submonoid.mem_comap.mp (hφ hq'),
dif_pos, ofFractionRing.injEq, Localization.mk_eq_mk_iff]
refine Localization.r_of_eq ?_
simpa only [map_mul] using congr_arg φ h
map_one' := by
simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk,
OneMemClass.coe_one, map_one, OneMemClass.one_mem, dite_true, ofFractionRing.injEq,
Localization.mk_one, Localization.mk_eq_monoidOf_mk', Submonoid.LocalizationMap.mk'_self]
map_mul' x y := by
obtain ⟨x⟩ := x; obtain ⟨y⟩ := y
induction' x using Localization.induction_on with pq
induction' y using Localization.induction_on with p'q'
obtain ⟨p, q⟩ := pq
obtain ⟨p', q'⟩ := p'q'
have hq : φ q ∈ S[X]⁰ := hφ q.prop
have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop
have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq'
simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq,
dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul,
Localization.mk_mul, Submonoid.mk_mul_mk]
theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F)
(hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) :
map φ hφ (ofFractionRing (Localization.mk n d)) =
ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by
simp only [map, MonoidHom.coe_mk, OneHom.coe_mk, liftOn_ofFractionRing_mk,
Submonoid.mem_comap.mp (hφ d.2), ↓reduceDIte]
theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ)
(hf : Function.Injective φ) : Function.Injective (map φ hφ) := by
rintro ⟨x⟩ ⟨y⟩ h
induction x using Localization.induction_on
induction y using Localization.induction_on
simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff,
Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors,
exists_const, ← map_mul, hf.eq_iff] using h
/-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]`
to a `RatFunc R →+* RatFunc S`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
RatFunc R →+* RatFunc S :=
{ map φ hφ with
map_zero' := by
simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰),
← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero,
Localization.mk_eq_mk', IsLocalization.mk'_zero]
map_add' := by
rintro ⟨x⟩ ⟨y⟩
induction x using Localization.induction_on
induction y using Localization.induction_on
· simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul,
MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul,
-- We have to specify `S[X]⁰` to `mk_mul_mk`, otherwise it will try to rewrite
-- the wrong occurrence.
Submonoid.mk_mul_mk S[X]⁰] }
theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
(mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ :=
rfl
-- TODO: Generalize to `FunLike` classes,
/-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀`
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where
toFun f :=
RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q]
rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;>
exact nonZeroDivisors.ne_zero (hφ ‹_›)
map_one' := by
simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk,
OneMemClass.coe_one, map_one, div_one]
map_mul' x y := by
obtain ⟨x⟩ := x
obtain ⟨y⟩ := y
induction' x using Localization.induction_on with p q
induction' y using Localization.induction_on with p' q'
rw [← ofFractionRing_mul, Localization.mk_mul]
simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul]
map_zero' := by
simp_rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk,
map_zero, zero_div]
theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ)
(n : R[X]) (d : R[X]⁰) :
liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftOn_ofFractionRing_mk _ _ _ _
theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ)
(hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftMonoidWithZeroHom φ hφ') := by
rintro ⟨x⟩ ⟨y⟩
induction' x using Localization.induction_on with a
induction' y using Localization.induction_on with a'
simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk]
intro h
congr 1
refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_)
have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h
· rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this
all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _)
/-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L`
by mapping both the numerator and denominator and quotienting them. -/
def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L :=
{ liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with
map_add' := fun x y => by
simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe]
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add]
obtain ⟨x⟩ := x
obtain ⟨y⟩ := y
induction' x using Localization.induction_on with pq
induction' y using Localization.induction_on with p'q'
obtain ⟨p, q⟩ := pq
obtain ⟨p', q'⟩ := p'q'
rw [← ofFractionRing_add, Localization.add_mk]
simp only [RingHom.toMonoidWithZeroHom_eq_coe,
liftMonoidWithZeroHom_apply_ofFractionRing_mk]
rw [div_add_div, div_eq_div_iff]
· rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm]
simp only [map_add, map_mul, Submonoid.coe_mul]
all_goals
try simp only [← map_mul, ← Submonoid.coe_mul]
exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _)) }
theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X])
(d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _
theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ)
(hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftRingHom φ hφ') :=
liftMonoidWithZeroHom_injective _ hφ
end LiftHom
variable (K)
@[stacks 09FK]
instance instField [IsDomain K] : Field (RatFunc K) where
inv_zero := by frac_tac
div := (· / ·)
div_eq_mul_inv := by frac_tac
mul_inv_cancel _ := mul_inv_cancel
zpow := zpowRec
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
section IsFractionRing
/-! ### `RatFunc` as field of fractions of `Polynomial` -/
section IsDomain
variable [IsDomain K]
instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where
algebraMap :=
{ toFun x := RatFunc.mk (algebraMap _ _ x) 1
map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add]
map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul]
map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one]
map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero] }
smul := (· • ·)
smul_def' c x := by
induction' x using RatFunc.induction_on' with p q hq
rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, mk_one', ← mk_smul,
mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ← ofFractionRing_mul,
IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def]
commutes' _ _ := mul_comm _ _
variable {K}
/-- The coercion from polynomials to rational functions, implemented as the algebra map from a
domain to its field of fractions -/
@[coe]
def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P
instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩
theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x :=
rfl
theorem ofFractionRing_algebraMap (x : K[X]) :
ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by
rw [← mk_one, mk_one']
@[simp]
theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by
simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap]
@[simp]
theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R)
(p q : K[X]) :
algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q =
c • (algebraMap _ _ p / algebraMap _ _ q) := by
rw [← mk_eq_div, mk_smul, mk_eq_div]
theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) :
algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by
rw [← mk_eq_div]
rfl
theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]]
(φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) :
map φ hφ (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by
have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq))
simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk,
mk_eq_localization_mk _ hq']
@[simp]
theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]]
(φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) :
map φ hφ (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by
rcases eq_or_ne q 0 with (rfl | hq)
· have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp
rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one,
map_one, div_one, map_zero, map_zero]
exact one_ne_zero
exact map_apply_div_ne_zero _ _ _ _ hq
theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L]
(φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) :
liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by
rcases eq_or_ne q 0 with (rfl | hq)
· simp only [div_zero, map_zero]
simp only [← mk_eq_div, mk_eq_localization_mk _ hq,
liftMonoidWithZeroHom_apply_ofFractionRing_mk]
@[simp]
theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L]
(φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) :
liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) =
φ p / φ q := by
rw [← map_div₀, liftMonoidWithZeroHom_apply_div]
theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div _ hφ _ _
@[simp]
theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) =
φ p / φ q :=
liftMonoidWithZeroHom_apply_div' _ hφ _ _
variable (K)
theorem ofFractionRing_comp_algebraMap :
ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ :=
funext ofFractionRing_algebraMap
theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by
rw [← ofFractionRing_comp_algebraMap]
exact ofFractionRing_injective.comp (IsFractionRing.injective _ _)
variable {K}
section LiftAlgHom
variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]]
[Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
/-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]`
to a `RatFunc K →ₐ[S] RatFunc R`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R :=
{ mapRingHom φ hφ with
commutes' := fun r => by
simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div,
map_one, AlgHom.commutes] }
theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) :
(mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ :=
rfl
/-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`
by mapping both the numerator and denominator and quotienting them. -/
def liftAlgHom : RatFunc K →ₐ[S] L :=
{ liftRingHom φ.toRingHom hφ with
commutes' := fun r => by
simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r,
liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] }
theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) :
liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _
theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ)
(hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftAlgHom φ hφ') :=
liftMonoidWithZeroHom_injective _ hφ
@[simp]
theorem liftAlgHom_apply_div' (p q : K[X]) :
liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div' _ hφ _ _
theorem liftAlgHom_apply_div (p q : K[X]) :
liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div _ hφ _ _
end LiftAlgHom
variable (K)
/-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/
instance : IsFractionRing K[X] (RatFunc K) where
map_units' y := by
rw [← ofFractionRing_algebraMap]
exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y)
exists_of_eq {x y} := by
rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap]
exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h)
surj' := by
rintro ⟨z⟩
convert IsLocalization.surj K[X]⁰ z
simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul,
ofFractionRing.injEq]
variable {K}
theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 := by
simpa
@[simp]
theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q')
(H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' :=
fun {_ _ _ _} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) :
(RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by
rw [← mk_eq_div, liftOn_mk _ _ f f0 @H']
@[simp]
theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H) :
(RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by
rw [RatFunc.liftOn', liftOn_div _ _ _ f0]
apply liftOn_condition_of_liftOn'_condition H
/-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`,
then `P` holds on all elements of `RatFunc K`.
See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`.
-/
protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K)
(f : ∀ (p q : K[X]) (_ : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x :=
x.induction_on' fun p q hq => by simpa using f p q hq
theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) :
ofFractionRing (IsLocalization.mk' _ x y) =
IsLocalization.mk' (RatFunc K) x y := by
rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div]
theorem mk_eq_mk' (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) :
RatFunc.mk f g = IsLocalization.mk' (RatFunc K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 hg⟩ :=
by simp only [mk_eq_div, IsFractionRing.mk'_eq_div]
@[simp]
theorem ofFractionRing_eq :
(ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ :=
funext fun x =>
Localization.induction_on x fun x => by
simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply,
IsLocalization.map_mk', RingHom.id_apply]
@[simp]
theorem toFractionRing_eq :
(toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ :=
funext fun ⟨x⟩ =>
Localization.induction_on x fun x => by
simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply,
IsLocalization.map_mk', RingHom.id_apply]
@[simp]
theorem toFractionRingRingEquiv_symm_eq :
(toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by
ext x
simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv']
end IsDomain
end IsFractionRing
end CommRing
section NumDenom
/-! ### Numerator and denominator -/
open GCDMonoid Polynomial
variable [Field K]
open scoped Classical in
/-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field,
normalized such that the denominator is monic. -/
def numDenom (x : RatFunc K) : K[X] × K[X] :=
x.liftOn'
(fun p q =>
if q = 0 then ⟨0, 1⟩
else
let r := gcd p q
⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r),
Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩)
(by
intros p q a hq ha
dsimp
rw [if_neg hq, if_neg (mul_ne_zero ha hq)]
have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha
have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha'
simp only [Prod.ext_iff, gcd_mul_left, normalize_apply a, Polynomial.coe_normUnit, mul_assoc,
CommGroupWithZero.coe_normUnit _ ha']
have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq
have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by
rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add]
exact hdeg
have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p :=
(C_mul_dvd hainv).mpr (gcd_dvd_left p q)
have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q :=
(C_mul_dvd hainv).mpr (gcd_dvd_right p q)
rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq,
leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul,
Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ←
mul_assoc, ← Polynomial.C_mul]
constructor <;> congr <;>
rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, mul_inv_cancel₀ ha',
one_mul, inv_div])
open scoped Classical in
@[simp]
theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
numDenom (algebraMap _ _ p / algebraMap _ _ q) =
(Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q),
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by
rw [numDenom, liftOn'_div, if_neg hq]
intro p
rw [if_pos rfl, if_neg (one_ne_zero' K[X])]
simp
/-- `RatFunc.num` is the numerator of a rational function,
normalized such that the denominator is monic. -/
def num (x : RatFunc K) : K[X] :=
x.numDenom.1
open scoped Classical in
private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
num (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by
rw [num, numDenom_div _ hq]
@[simp]
theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp
open scoped Classical in
@[simp]
theorem num_div (p q : K[X]) :
num (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by
by_cases hq : q = 0
· simp [hq]
· exact num_div' p hq
@[simp]
theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp
@[simp]
theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp
theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by
classical
rw [num_div _ q, C_mul_dvd]
· exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q)
· simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq
open scoped Classical in
/-- A version of `num_div_dvd` with the LHS in simp normal form -/
@[simp]
theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq
/-- `RatFunc.denom` is the denominator of a rational function,
normalized such that it is monic. -/
def denom (x : RatFunc K) : K[X] :=
x.numDenom.2
open scoped Classical in
@[simp]
theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
denom (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by
rw [denom, numDenom_div _ hq]
theorem monic_denom (x : RatFunc K) : (denom x).Monic := by
classical
induction x using RatFunc.induction_on with
| f p q hq =>
rw [denom_div p hq, mul_comm]
exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq)
theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 :=
(monic_denom x).ne_zero
@[simp]
theorem denom_zero : denom (0 : RatFunc K) = 1 := by
convert denom_div (0 : K[X]) one_ne_zero <;> simp
@[simp]
theorem denom_one : denom (1 : RatFunc K) = 1 := by
convert denom_div (1 : K[X]) one_ne_zero <;> simp
@[simp]
theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by
convert denom_div p one_ne_zero <;> simp
@[simp]
theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by
classical
by_cases hq : q = 0
· simp [hq]
rw [denom_div _ hq, C_mul_dvd]
· exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q)
· simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq
@[simp]
theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by
classical
induction' x using RatFunc.induction_on with p q hq
have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq
rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left,
div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ←
EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm]
· apply gcd_dvd_right
· apply gcd_dvd_left
· exact algebraMap_ne_zero q_div_ne_zero
· exact algebraMap_ne_zero hq
· refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_)
exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero)
theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by
classical
induction' x using RatFunc.induction_on with p q hq
rw [num_div, denom_div _ hq]
exact (isCoprime_mul_unit_left
((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2
(isCoprime_div_gcd_div_gcd hq)
@[simp]
theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 :=
⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩
theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 :=
mt num_eq_zero_iff.mp hx
theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) :
x.num * q = p * x.denom ↔ x = algebraMap _ _ p / algebraMap _ _ q := by
rw [← (algebraMap_injective K).eq_iff, eq_div_iff (algebraMap_ne_zero hq)]
conv_rhs => rw [← num_div_denom x]
rw [RingHom.map_mul, RingHom.map_mul, div_eq_mul_inv, mul_assoc, mul_comm (Inv.inv _), ←
mul_assoc, ← div_eq_mul_inv, div_eq_iff]
exact algebraMap_ne_zero (denom_ne_zero x)
theorem num_denom_add (x y : RatFunc K) :
(x + y).num * (x.denom * y.denom) = (x.num * y.denom + x.denom * y.num) * (x + y).denom :=
(num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by
conv_lhs => rw [← num_div_denom x, ← num_div_denom y]
rw [div_add_div, RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul]
· exact algebraMap_ne_zero (denom_ne_zero x)
· exact algebraMap_ne_zero (denom_ne_zero y)
theorem num_denom_neg (x : RatFunc K) : (-x).num * x.denom = -x.num * (-x).denom := by
rw [num_mul_eq_mul_denom_iff (denom_ne_zero x), map_neg, neg_div, num_div_denom]
theorem num_denom_mul (x y : RatFunc K) :
(x * y).num * (x.denom * y.denom) = x.num * y.num * (x * y).denom :=
(num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by
conv_lhs =>
rw [← num_div_denom x, ← num_div_denom y, div_mul_div_comm, ← RingHom.map_mul, ←
RingHom.map_mul]
theorem num_dvd {x : RatFunc K} {p : K[X]} (hp : p ≠ 0) :
num x ∣ p ↔ ∃ q : K[X], q ≠ 0 ∧ x = algebraMap _ _ p / algebraMap _ _ q := by
constructor
· rintro ⟨q, rfl⟩
obtain ⟨_hx, hq⟩ := mul_ne_zero_iff.mp hp
use denom x * q
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom]
· exact ⟨mul_ne_zero (denom_ne_zero x) hq, rfl⟩
· exact algebraMap_ne_zero hq
· rintro ⟨q, hq, rfl⟩
exact num_div_dvd p hq
theorem denom_dvd {x : RatFunc K} {q : K[X]} (hq : q ≠ 0) :
denom x ∣ q ↔ ∃ p : K[X], x = algebraMap _ _ p / algebraMap _ _ q := by
constructor
· rintro ⟨p, rfl⟩
obtain ⟨_hx, hp⟩ := mul_ne_zero_iff.mp hq
use num x * p
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom]
exact algebraMap_ne_zero hp
· rintro ⟨p, rfl⟩
exact denom_div_dvd p q
theorem num_mul_dvd (x y : RatFunc K) : num (x * y) ∣ num x * num y := by
by_cases hx : x = 0
· simp [hx]
by_cases hy : y = 0
· simp [hy]
rw [num_dvd (mul_ne_zero (num_ne_zero hx) (num_ne_zero hy))]
refine ⟨x.denom * y.denom, mul_ne_zero (denom_ne_zero x) (denom_ne_zero y), ?_⟩
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom]
theorem denom_mul_dvd (x y : RatFunc K) : denom (x * y) ∣ denom x * denom y := by
rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))]
refine ⟨x.num * y.num, ?_⟩
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom]
theorem denom_add_dvd (x y : RatFunc K) : denom (x + y) ∣ denom x * denom y := by
rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))]
refine ⟨x.num * y.denom + x.denom * y.num, ?_⟩
rw [RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul, ← div_add_div,
num_div_denom, num_div_denom]
· exact algebraMap_ne_zero (denom_ne_zero x)
· exact algebraMap_ne_zero (denom_ne_zero y)
theorem map_denom_ne_zero {L F : Type*} [Zero L] [FunLike F K[X] L] [ZeroHomClass F K[X] L]
(φ : F) (hφ : Function.Injective φ) (f : RatFunc K) : φ f.denom ≠ 0 := fun H =>
(denom_ne_zero f) ((map_eq_zero_iff φ hφ).mp H)
theorem map_apply {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F)
(hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (f : RatFunc K) :
map φ hφ f = algebraMap _ _ (φ f.num) / algebraMap _ _ (φ f.denom) := by
rw [← num_div_denom f, map_apply_div_ne_zero, num_div_denom f]
exact denom_ne_zero _
theorem liftMonoidWithZeroHom_apply {L : Type*} [CommGroupWithZero L] (φ : K[X] →*₀ L)
(hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) :
liftMonoidWithZeroHom φ hφ f = φ f.num / φ f.denom := by
rw [← num_div_denom f, liftMonoidWithZeroHom_apply_div, num_div_denom]
theorem liftRingHom_apply {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(f : RatFunc K) : liftRingHom φ hφ f = φ f.num / φ f.denom :=
liftMonoidWithZeroHom_apply _ hφ _
theorem liftAlgHom_apply {L S : Type*} [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]
(φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) :
liftAlgHom φ hφ f = φ f.num / φ f.denom :=
liftMonoidWithZeroHom_apply _ hφ _
theorem num_mul_denom_add_denom_mul_num_ne_zero {x y : RatFunc K} (hxy : x + y ≠ 0) :
x.num * y.denom + x.denom * y.num ≠ 0 := by
intro h_zero
have h := num_denom_add x y
rw [h_zero, zero_mul] at h
exact (mul_ne_zero (num_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)) h
end NumDenom
end RatFunc
| Mathlib/FieldTheory/RatFunc/Basic.lean | 1,073 | 1,082 | |
/-
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.Algebra.Order.Group.Indicator
import Mathlib.MeasureTheory.OuterMeasure.Basic
/-!
# Operations on outer measures
In this file we define algebraic operations (addition, scalar multiplication)
on the type of outer measures on a type.
We also show that outer measures on a type `α` form a complete lattice.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
## Tags
outer measure
-/
noncomputable section
open Set Function Filter
open scoped NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section Basic
variable {α β : Type*} {m : OuterMeasure α}
instance instZero : Zero (OuterMeasure α) :=
⟨{ measureOf := fun _ => 0
empty := rfl
mono := by intro _ _ _; exact le_refl 0
iUnion_nat := fun _ _ => zero_le _ }⟩
@[simp]
theorem coe_zero : ⇑(0 : OuterMeasure α) = 0 :=
rfl
instance instInhabited : Inhabited (OuterMeasure α) :=
⟨0⟩
instance instAdd : Add (OuterMeasure α) :=
⟨fun m₁ m₂ =>
{ measureOf := fun s => m₁ s + m₂ s
empty := show m₁ ∅ + m₂ ∅ = 0 by simp [OuterMeasure.empty]
mono := fun {_ _} h => add_le_add (m₁.mono h) (m₂.mono h)
iUnion_nat := fun s _ =>
calc
m₁ (⋃ i, s i) + m₂ (⋃ i, s i) ≤ (∑' i, m₁ (s i)) + ∑' i, m₂ (s i) :=
add_le_add (measure_iUnion_le s) (measure_iUnion_le s)
_ = _ := ENNReal.tsum_add.symm }⟩
@[simp]
theorem coe_add (m₁ m₂ : OuterMeasure α) : ⇑(m₁ + m₂) = m₁ + m₂ :=
rfl
theorem add_apply (m₁ m₂ : OuterMeasure α) (s : Set α) : (m₁ + m₂) s = m₁ s + m₂ s :=
rfl
section SMul
variable {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
variable {R' : Type*} [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞]
instance instSMul : SMul R (OuterMeasure α) :=
⟨fun c m =>
{ measureOf := fun s => c • m s
empty := by simp only [measure_empty]; rw [← smul_one_mul c]; simp
mono := fun {s t} h => by
rw [← smul_one_mul c, ← smul_one_mul c (m t)]
exact mul_left_mono (m.mono h)
iUnion_nat := fun s _ => by
simp_rw [← smul_one_mul c (m _), ENNReal.tsum_mul_left]
exact mul_left_mono (measure_iUnion_le _) }⟩
@[simp]
theorem coe_smul (c : R) (m : OuterMeasure α) : ⇑(c • m) = c • ⇑m :=
rfl
theorem smul_apply (c : R) (m : OuterMeasure α) (s : Set α) : (c • m) s = c • m s :=
rfl
instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] : SMulCommClass R R' (OuterMeasure α) :=
⟨fun _ _ _ => ext fun _ => smul_comm _ _ _⟩
instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] :
IsScalarTower R R' (OuterMeasure α) :=
⟨fun _ _ _ => ext fun _ => smul_assoc _ _ _⟩
instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] :
IsCentralScalar R (OuterMeasure α) :=
⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩
end SMul
instance instMulAction {R : Type*} [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] :
MulAction R (OuterMeasure α) :=
Injective.mulAction _ coe_fn_injective coe_smul
instance addCommMonoid : AddCommMonoid (OuterMeasure α) :=
Injective.addCommMonoid (show OuterMeasure α → Set α → ℝ≥0∞ from _) coe_fn_injective rfl
(fun _ _ => rfl) fun _ _ => rfl
/-- `(⇑)` as an `AddMonoidHom`. -/
@[simps]
def coeFnAddMonoidHom : OuterMeasure α →+ Set α → ℝ≥0∞ where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
instance instDistribMulAction {R : Type*} [Monoid R] [DistribMulAction R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] :
DistribMulAction R (OuterMeasure α) :=
Injective.distribMulAction coeFnAddMonoidHom coe_fn_injective coe_smul
instance instModule {R : Type*} [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] :
Module R (OuterMeasure α) :=
Injective.module R coeFnAddMonoidHom coe_fn_injective coe_smul
instance instBot : Bot (OuterMeasure α) :=
⟨0⟩
@[simp]
theorem coe_bot : (⊥ : OuterMeasure α) = 0 :=
rfl
instance instPartialOrder : PartialOrder (OuterMeasure α) where
le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s
le_refl _ _ := le_rfl
le_trans _ _ _ hab hbc s := le_trans (hab s) (hbc s)
le_antisymm _ _ hab hba := ext fun s => le_antisymm (hab s) (hba s)
instance orderBot : OrderBot (OuterMeasure α) :=
{ bot := 0,
bot_le := fun a s => by simp only [coe_zero, Pi.zero_apply, coe_bot, zero_le] }
theorem univ_eq_zero_iff (m : OuterMeasure α) : m univ = 0 ↔ m = 0 :=
⟨fun h => bot_unique fun s => (measure_mono <| subset_univ s).trans_eq h, fun h => h.symm ▸ rfl⟩
section Supremum
instance instSupSet : SupSet (OuterMeasure α) :=
⟨fun ms =>
{ measureOf := fun s => ⨆ m ∈ ms, (m : OuterMeasure α) s
empty := nonpos_iff_eq_zero.1 <| iSup₂_le fun m _ => le_of_eq m.empty
mono := fun {_ _} hs => iSup₂_mono fun m _ => m.mono hs
iUnion_nat := fun f _ =>
iSup₂_le fun m hm =>
calc
m (⋃ i, f i) ≤ ∑' i : ℕ, m (f i) := measure_iUnion_le _
_ ≤ ∑' i, ⨆ m ∈ ms, (m : OuterMeasure α) (f i) :=
ENNReal.tsum_le_tsum fun i => by apply le_iSup₂ m hm
}⟩
instance instCompleteLattice : CompleteLattice (OuterMeasure α) :=
{ OuterMeasure.orderBot,
completeLatticeOfSup (OuterMeasure α) fun ms =>
⟨fun m hm s => by apply le_iSup₂ m hm, fun _ hm s => iSup₂_le fun _ hm' => hm hm' s⟩ with }
@[simp]
theorem sSup_apply (ms : Set (OuterMeasure α)) (s : Set α) :
(sSup ms) s = ⨆ m ∈ ms, (m : OuterMeasure α) s :=
rfl
@[simp]
theorem iSup_apply {ι} (f : ι → OuterMeasure α) (s : Set α) : (⨆ i : ι, f i) s = ⨆ i, f i s := by
rw [iSup, sSup_apply, iSup_range]
@[norm_cast]
theorem coe_iSup {ι} (f : ι → OuterMeasure α) : ⇑(⨆ i, f i) = ⨆ i, ⇑(f i) :=
funext fun s => by simp
@[simp]
theorem sup_apply (m₁ m₂ : OuterMeasure α) (s : Set α) : (m₁ ⊔ m₂) s = m₁ s ⊔ m₂ s := by
have := iSup_apply (fun b => cond b m₁ m₂) s; rwa [iSup_bool_eq, iSup_bool_eq] at this
theorem smul_iSup {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{ι : Sort*} (f : ι → OuterMeasure α) (c : R) :
(c • ⨆ i, f i) = ⨆ i, c • f i :=
ext fun s => by simp only [smul_apply, iSup_apply, ENNReal.smul_iSup]
end Supremum
@[mono, gcongr]
theorem mono'' {m₁ m₂ : OuterMeasure α} {s₁ s₂ : Set α} (hm : m₁ ≤ m₂) (hs : s₁ ⊆ s₂) :
m₁ s₁ ≤ m₂ s₂ :=
(hm s₁).trans (m₂.mono hs)
/-- The pushforward of `m` along `f`. The outer measure on `s` is defined to be `m (f ⁻¹' s)`. -/
def map {β} (f : α → β) : OuterMeasure α →ₗ[ℝ≥0∞] OuterMeasure β where
toFun m :=
{ measureOf := fun s => m (f ⁻¹' s)
empty := m.empty
mono := fun {_ _} h => m.mono (preimage_mono h)
iUnion_nat := fun s _ => by simpa using measure_iUnion_le fun i => f ⁻¹' s i }
map_add' _ _ := coe_fn_injective rfl
map_smul' _ _ := coe_fn_injective rfl
@[simp]
theorem map_apply {β} (f : α → β) (m : OuterMeasure α) (s : Set β) : map f m s = m (f ⁻¹' s) :=
rfl
@[simp]
theorem map_id (m : OuterMeasure α) : map id m = m :=
ext fun _ => rfl
@[simp]
theorem map_map {β γ} (f : α → β) (g : β → γ) (m : OuterMeasure α) :
map g (map f m) = map (g ∘ f) m :=
ext fun _ => rfl
@[mono]
theorem map_mono {β} (f : α → β) : Monotone (map f) := fun _ _ h _ => h _
@[simp]
theorem map_sup {β} (f : α → β) (m m' : OuterMeasure α) : map f (m ⊔ m') = map f m ⊔ map f m' :=
ext fun s => by simp only [map_apply, sup_apply]
@[simp]
theorem map_iSup {β ι} (f : α → β) (m : ι → OuterMeasure α) : map f (⨆ i, m i) = ⨆ i, map f (m i) :=
ext fun s => by simp only [map_apply, iSup_apply]
instance instFunctor : Functor OuterMeasure where map {_ _} f := map f
instance instLawfulFunctor : LawfulFunctor OuterMeasure := by constructor <;> intros <;> rfl
/-- The dirac outer measure. -/
def dirac (a : α) : OuterMeasure α where
measureOf s := indicator s (fun _ => 1) a
empty := by simp
mono {_ _} h := indicator_le_indicator_of_subset h (fun _ => zero_le _) a
iUnion_nat s _ := calc
indicator (⋃ n, s n) 1 a = ⨆ n, indicator (s n) 1 a :=
indicator_iUnion_apply (M := ℝ≥0∞) rfl _ _ _
_ ≤ ∑' n, indicator (s n) 1 a := iSup_le fun _ ↦ ENNReal.le_tsum _
@[simp]
theorem dirac_apply (a : α) (s : Set α) : dirac a s = indicator s (fun _ => 1) a :=
rfl
/-- The sum of an (arbitrary) collection of outer measures. -/
def sum {ι} (f : ι → OuterMeasure α) : OuterMeasure α where
measureOf s := ∑' i, f i s
empty := by simp
mono {_ _} h := ENNReal.tsum_le_tsum fun _ => measure_mono h
iUnion_nat s _ := by
rw [ENNReal.tsum_comm]; exact ENNReal.tsum_le_tsum fun i => measure_iUnion_le _
@[simp]
theorem sum_apply {ι} (f : ι → OuterMeasure α) (s : Set α) : sum f s = ∑' i, f i s :=
rfl
theorem smul_dirac_apply (a : ℝ≥0∞) (b : α) (s : Set α) :
(a • dirac b) s = indicator s (fun _ => a) b := by
simp only [smul_apply, smul_eq_mul, dirac_apply, ← indicator_mul_right _ fun _ => a, mul_one]
| /-- Pullback of an `OuterMeasure`: `comap f μ s = μ (f '' s)`. -/
def comap {β} (f : α → β) : OuterMeasure β →ₗ[ℝ≥0∞] OuterMeasure α where
| Mathlib/MeasureTheory/OuterMeasure/Operations.lean | 266 | 267 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex
/-!
# The `arctan` function.
Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)`
and the whole line.
The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or
`arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of
`arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to
`π / 4 = arctan 1`), including John Machin's original one at
`four_mul_arctan_inv_5_sub_arctan_inv_239`.
-/
noncomputable section
namespace Real
open Set Filter
open scoped Topology Real
theorem tan_add {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by
simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div,
Complex.ofReal_mul, Complex.ofReal_tan] using
@Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast)
theorem tan_add' {x y : ℝ}
(h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (Or.inl h)
theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by
have := @Complex.tan_two_mul x
norm_cast at *
theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by
suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by
have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos]
rwa [h_eq] at this
exact continuousOn_sin.div continuousOn_cos fun x => id
@[continuity]
theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x :=
continuousOn_iff_continuous_restrict.1 continuousOn_tan
theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by
refine ContinuousOn.mono continuousOn_tan fun x => ?_
simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne]
rw [cos_eq_zero_iff]
rintro hx_gt hx_lt ⟨r, hxr_eq⟩
rcases le_or_lt 0 r with h | h
· rw [lt_iff_not_ge] at hx_lt
refine hx_lt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)]
simp [h]
· rw [lt_iff_not_ge] at hx_gt
refine hx_gt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul,
mul_le_mul_right (half_pos pi_pos)]
have hr_le : r ≤ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h
rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff₀]
· norm_num
rw [← Int.cast_one, ← Int.cast_neg]; norm_cast
· exact zero_lt_two
theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ :=
have := neg_lt_self pi_div_two_pos
continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this)
(by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two)
(by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two)
theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial
theorem image_tan_Ioo : tan '' Ioo (-(π / 2)) (π / 2) = univ :=
univ_subset_iff.1 surjOn_tan
/-- `Real.tan` as an `OrderIso` between `(-(π / 2), π / 2)` and `ℝ`. -/
def tanOrderIso : Ioo (-(π / 2)) (π / 2) ≃o ℝ :=
(strictMonoOn_tan.orderIso _ _).trans <|
(OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and
`arctan x < π / 2` -/
@[pp_nodot]
noncomputable def arctan (x : ℝ) : ℝ :=
tanOrderIso.symm x
@[simp]
theorem tan_arctan (x : ℝ) : tan (arctan x) = x :=
tanOrderIso.apply_symm_apply x
theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arctan : range arctan = Ioo (-(π / 2)) (π / 2) :=
((EquivLike.surjective _).range_comp _).trans Subtype.range_coe
theorem arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hx₂⟩
theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) :=
cos_pos_of_mem_Ioo <| arctan_mem_Ioo x
theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]
theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by
rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
(arctan_mem_Ioo x).2
theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
(arctan_mem_Ioo x).1
theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) :=
Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x)
theorem arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1 : ℝ)) 1) :
arcsin x = arctan (x / √(1 - x ^ 2)) := by
rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul,
mul_div_cancel₀, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2]
@[simp]
theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin]
@[mono]
theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono
@[gcongr]
lemma arctan_lt_arctan {x y : ℝ} (hxy : x < y) : arctan x < arctan y := arctan_strictMono hxy
@[gcongr]
lemma arctan_le_arctan {x y : ℝ} (hxy : x ≤ y) : arctan x ≤ arctan y :=
arctan_strictMono.monotone hxy
theorem arctan_injective : arctan.Injective := arctan_strictMono.injective
@[simp]
theorem arctan_eq_zero_iff {x : ℝ} : arctan x = 0 ↔ x = 0 :=
.trans (by rw [arctan_zero]) arctan_injective.eq_iff
theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (π / 2)) :=
tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop
theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(π / 2))) :=
tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot
theorem arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) :
arctan y = x :=
injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])
@[simp]
theorem arctan_one : arctan 1 = π / 4 :=
arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos]
@[simp]
theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div]
theorem arctan_eq_arccos {x : ℝ} (h : 0 ≤ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by
rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; · exact inv_nonneg.2 (sqrt_nonneg _)
congr 1
rw_mod_cast [← sqrt_inv, sq_sqrt, ← one_div, one_sub_div, add_sub_cancel_left, sqrt_div,
sqrt_sq h]
all_goals positivity
-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.
theorem arccos_eq_arctan {x : ℝ} (h : 0 < x) : arccos x = arctan (√(1 - x ^ 2) / x) := by
rw [arccos, eq_comm]
refine arctan_eq_of_tan_eq ?_ ⟨?_, ?_⟩
· rw_mod_cast [tan_pi_div_two_sub, tan_arcsin, inv_div]
· linarith only [arcsin_le_pi_div_two x, pi_pos]
· linarith only [arcsin_pos.2 h]
theorem arctan_inv_of_pos {x : ℝ} (h : 0 < x) : arctan x⁻¹ = π / 2 - arctan x := by
rw [← arctan_tan (x := _ - _), tan_pi_div_two_sub, tan_arctan]
· norm_num
exact (arctan_lt_pi_div_two x).trans (half_lt_self_iff.mpr pi_pos)
· rw [sub_lt_self_iff, ← arctan_zero]
exact tanOrderIso.symm.strictMono h
theorem arctan_inv_of_neg {x : ℝ} (h : x < 0) : arctan x⁻¹ = -(π / 2) - arctan x := by
have := arctan_inv_of_pos (neg_pos.mpr h)
rwa [inv_neg, arctan_neg, neg_eq_iff_eq_neg, neg_sub', arctan_neg, neg_neg] at this
section ArctanAdd
lemma arctan_ne_mul_pi_div_two {x : ℝ} : ∀ (k : ℤ), arctan x ≠ (2 * k + 1) * π / 2 := by
by_contra!
obtain ⟨k, h⟩ := this
obtain ⟨lb, ub⟩ := arctan_mem_Ioo x
rw [h, neg_eq_neg_one_mul, mul_div_assoc, mul_lt_mul_right (by positivity)] at lb
rw [h, ← one_mul (π / 2), mul_div_assoc, mul_lt_mul_right (by positivity)] at ub
norm_cast at lb ub; change -1 < _ at lb; omega
lemma arctan_add_arctan_lt_pi_div_two {x y : ℝ} (h : x * y < 1) : arctan x + arctan y < π / 2 := by
rcases le_or_lt y 0 with hy | hy
· rw [← add_zero (π / 2), ← arctan_zero]
exact add_lt_add_of_lt_of_le (arctan_lt_pi_div_two _) (tanOrderIso.symm.monotone hy)
· rw [← lt_div_iff₀ hy, ← inv_eq_one_div] at h
replace h : arctan x < arctan y⁻¹ := tanOrderIso.symm.strictMono h
rwa [arctan_inv_of_pos hy, lt_tsub_iff_right] at h
theorem arctan_add {x y : ℝ} (h : x * y < 1) :
arctan x + arctan y = arctan ((x + y) / (1 - x * y)) := by
rw [← arctan_tan (x := _ + _)]
· congr
conv_rhs => rw [← tan_arctan x, ← tan_arctan y]
exact tan_add' ⟨arctan_ne_mul_pi_div_two, arctan_ne_mul_pi_div_two⟩
· rw [neg_lt, neg_add, ← arctan_neg, ← arctan_neg]
rw [← neg_mul_neg] at h
exact arctan_add_arctan_lt_pi_div_two h
· exact arctan_add_arctan_lt_pi_div_two h
theorem arctan_add_eq_add_pi {x y : ℝ} (h : 1 < x * y) (hx : 0 < x) :
arctan x + arctan y = arctan ((x + y) / (1 - x * y)) + π := by
have hy : 0 < y := by
have := mul_pos_iff.mp (zero_lt_one.trans h)
simpa [hx, hx.asymm]
have k := arctan_add (mul_inv x y ▸ inv_lt_one_of_one_lt₀ h)
rw [arctan_inv_of_pos hx, arctan_inv_of_pos hy, show _ + _ = π - (arctan x + arctan y) by ring,
sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', sub_eq_add_neg, ← arctan_neg, add_comm] at k
convert k.symm using 3
field_simp
rw [show -x + -y = -(x + y) by ring, show x * y - 1 = -(1 - x * y) by ring, neg_div_neg_eq]
theorem arctan_add_eq_sub_pi {x y : ℝ} (h : 1 < x * y) (hx : x < 0) :
arctan x + arctan y = arctan ((x + y) / (1 - x * y)) - π := by
rw [← neg_mul_neg] at h
have k := arctan_add_eq_add_pi h (neg_pos.mpr hx)
rw [show _ / _ = -((x + y) / (1 - x * y)) by ring, ← neg_inj] at k
simp only [arctan_neg, neg_add, neg_neg, ← sub_eq_add_neg _ π] at k
exact k
theorem two_mul_arctan {x : ℝ} (h₁ : -1 < x) (h₂ : x < 1) :
2 * arctan x = arctan (2 * x / (1 - x ^ 2)) := by
rw [two_mul, arctan_add (by nlinarith)]; congr 1; ring
theorem two_mul_arctan_add_pi {x : ℝ} (h : 1 < x) :
2 * arctan x = arctan (2 * x / (1 - x ^ 2)) + π := by
rw [two_mul, arctan_add_eq_add_pi (by nlinarith) (by linarith)]; congr 2; ring
theorem two_mul_arctan_sub_pi {x : ℝ} (h : x < -1) :
2 * arctan x = arctan (2 * x / (1 - x ^ 2)) - π := by
rw [two_mul, arctan_add_eq_sub_pi (by nlinarith) (by linarith)]; congr 2; ring
theorem arctan_inv_2_add_arctan_inv_3 : arctan 2⁻¹ + arctan 3⁻¹ = π / 4 := by
rw [arctan_add] <;> norm_num
theorem two_mul_arctan_inv_2_sub_arctan_inv_7 : 2 * arctan 2⁻¹ - arctan 7⁻¹ = π / 4 := by
rw [two_mul_arctan, ← arctan_one, sub_eq_iff_eq_add, arctan_add] <;> norm_num
theorem two_mul_arctan_inv_3_add_arctan_inv_7 : 2 * arctan 3⁻¹ + arctan 7⁻¹ = π / 4 := by
rw [two_mul_arctan, arctan_add] <;> norm_num
/-- **John Machin's 1706 formula**, which he used to compute π to 100 decimal places. -/
theorem four_mul_arctan_inv_5_sub_arctan_inv_239 : 4 * arctan 5⁻¹ - arctan 239⁻¹ = π / 4 := by
rw [show 4 * arctan _ = 2 * (2 * _) by ring, two_mul_arctan, two_mul_arctan, ← arctan_one,
sub_eq_iff_eq_add, arctan_add] <;> norm_num
end ArctanAdd
@[continuity]
theorem continuous_arctan : Continuous arctan :=
continuous_subtype_val.comp tanOrderIso.toHomeomorph.continuous_invFun
theorem continuousAt_arctan {x : ℝ} : ContinuousAt arctan x :=
| continuous_arctan.continuousAt
/-- `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)` and the whole line. -/
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean | 286 | 288 |
/-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import Mathlib.Topology.Bases
import Mathlib.Topology.DenseEmbedding
import Mathlib.Topology.Connected.TotallyDisconnected
/-! # Stone-Čech compactification
Construction of the Stone-Čech compactification using ultrafilters.
For any topological space `α`, we build a compact Hausdorff space `StoneCech α` and a continuous
map `stoneCechUnit : α → StoneCech α` which is minimal in the sense of the following universal
property: for any compact Hausdorff space `β` and every map `f : α → β` such that
`hf : Continuous f`, there is a unique map `stoneCechExtend hf : StoneCech α → β` such that
`stoneCechExtend_extends : stoneCechExtend hf ∘ stoneCechUnit = f`.
Continuity of this extension is asserted by `continuous_stoneCechExtend` and uniqueness by
`stoneCech_hom_ext`.
Beware that the terminology “extend” is slightly misleading since `stoneCechUnit` is not always
injective, so one cannot always think of `α` as being “inside” its compactification `StoneCech α`.
## Implementation notes
Parts of the formalization are based on “Ultrafilters and Topology”
by Marius Stekelenburg, particularly section 5. However the construction in the general
case is different because the equivalence relation on spaces of ultrafilters described
by Stekelenburg causes issues with universes since it involves a condition
on all compact Hausdorff spaces. We replace it by a two steps construction.
The first step called `PreStoneCech` guarantees the expected universal property but
not the Hausdorff condition. We then define `StoneCech α` as `t2Quotient (PreStoneCech α)`.
-/
noncomputable section
open Filter Set
open Topology
universe u v
section Ultrafilter
/- The set of ultrafilters on α carries a natural topology which makes
it the Stone-Čech compactification of α (viewed as a discrete space). -/
/-- Basis for the topology on `Ultrafilter α`. -/
def ultrafilterBasis (α : Type u) : Set (Set (Ultrafilter α)) :=
range fun s : Set α ↦ { u | s ∈ u }
variable {α : Type u}
instance Ultrafilter.topologicalSpace : TopologicalSpace (Ultrafilter α) :=
TopologicalSpace.generateFrom (ultrafilterBasis α)
theorem ultrafilterBasis_is_basis : TopologicalSpace.IsTopologicalBasis (ultrafilterBasis α) :=
⟨by
rintro _ ⟨a, rfl⟩ _ ⟨b, rfl⟩ u ⟨ua, ub⟩
refine ⟨_, ⟨a ∩ b, rfl⟩, inter_mem ua ub, fun v hv ↦ ⟨?_, ?_⟩⟩ <;> apply mem_of_superset hv <;>
simp [inter_subset_right],
eq_univ_of_univ_subset <| subset_sUnion_of_mem <| ⟨univ, eq_univ_of_forall fun _ ↦ univ_mem⟩,
rfl⟩
/-- The basic open sets for the topology on ultrafilters are open. -/
theorem ultrafilter_isOpen_basic (s : Set α) : IsOpen { u : Ultrafilter α | s ∈ u } :=
ultrafilterBasis_is_basis.isOpen ⟨s, rfl⟩
/-- The basic open sets for the topology on ultrafilters are also closed. -/
theorem ultrafilter_isClosed_basic (s : Set α) : IsClosed { u : Ultrafilter α | s ∈ u } := by
rw [← isOpen_compl_iff]
convert ultrafilter_isOpen_basic sᶜ using 1
ext u
exact Ultrafilter.compl_mem_iff_not_mem.symm
/-- Every ultrafilter `u` on `Ultrafilter α` converges to a unique
point of `Ultrafilter α`, namely `joinM u`. -/
theorem ultrafilter_converges_iff {u : Ultrafilter (Ultrafilter α)} {x : Ultrafilter α} :
↑u ≤ 𝓝 x ↔ x = joinM u := by
rw [eq_comm, ← Ultrafilter.coe_le_coe]
change ↑u ≤ 𝓝 x ↔ ∀ s ∈ x, { v : Ultrafilter α | s ∈ v } ∈ u
simp only [TopologicalSpace.nhds_generateFrom, le_iInf_iff, ultrafilterBasis, le_principal_iff,
mem_setOf_eq]
constructor
· intro h a ha
exact h _ ⟨ha, a, rfl⟩
· rintro h a ⟨xi, a, rfl⟩
exact h _ xi
instance ultrafilter_compact : CompactSpace (Ultrafilter α) :=
⟨isCompact_iff_ultrafilter_le_nhds.mpr fun f _ ↦
⟨joinM f, trivial, ultrafilter_converges_iff.mpr rfl⟩⟩
instance Ultrafilter.t2Space : T2Space (Ultrafilter α) :=
t2_iff_ultrafilter.mpr fun {x y} f fx fy ↦
have hx : x = joinM f := ultrafilter_converges_iff.mp fx
have hy : y = joinM f := ultrafilter_converges_iff.mp fy
hx.trans hy.symm
instance : TotallyDisconnectedSpace (Ultrafilter α) := by
rw [totallyDisconnectedSpace_iff_connectedComponent_singleton]
intro A
simp only [Set.eq_singleton_iff_unique_mem, mem_connectedComponent, true_and]
intro B hB
rw [← Ultrafilter.coe_le_coe]
intro s hs
rw [connectedComponent_eq_iInter_isClopen, Set.mem_iInter] at hB
let Z := { F : Ultrafilter α | s ∈ F }
have hZ : IsClopen Z := ⟨ultrafilter_isClosed_basic s, ultrafilter_isOpen_basic s⟩
exact hB ⟨Z, hZ, hs⟩
@[simp] theorem Ultrafilter.tendsto_pure_self (b : Ultrafilter α) : Tendsto pure b (𝓝 b) := by
rw [Tendsto, ← coe_map, ultrafilter_converges_iff]
ext s
change s ∈ b ↔ {t | s ∈ t} ∈ map pure b
simp_rw [mem_map, preimage_setOf_eq, mem_pure, setOf_mem_eq]
theorem ultrafilter_comap_pure_nhds (b : Ultrafilter α) : comap pure (𝓝 b) ≤ b := by
rw [TopologicalSpace.nhds_generateFrom]
simp only [comap_iInf, comap_principal]
intro s hs
rw [← le_principal_iff]
refine iInf_le_of_le { u | s ∈ u } ?_
refine iInf_le_of_le ⟨hs, ⟨s, rfl⟩⟩ ?_
exact principal_mono.2 fun _ ↦ id
section Embedding
theorem ultrafilter_pure_injective : Function.Injective (pure : α → Ultrafilter α) := by
intro x y h
have : {x} ∈ (pure x : Ultrafilter α) := singleton_mem_pure
rw [h] at this
exact (mem_singleton_iff.mp (mem_pure.mp this)).symm
open TopologicalSpace
/-- The range of `pure : α → Ultrafilter α` is dense in `Ultrafilter α`. -/
theorem denseRange_pure : DenseRange (pure : α → Ultrafilter α) :=
fun x ↦ mem_closure_iff_ultrafilter.mpr
⟨x.map pure, range_mem_map, ultrafilter_converges_iff.mpr (bind_pure x).symm⟩
/-- The map `pure : α → Ultrafilter α` induces on `α` the discrete topology. -/
theorem induced_topology_pure :
TopologicalSpace.induced (pure : α → Ultrafilter α) Ultrafilter.topologicalSpace = ⊥ := by
apply eq_bot_of_singletons_open
intro x
use { u : Ultrafilter α | {x} ∈ u }, ultrafilter_isOpen_basic _
simp
/-- `pure : α → Ultrafilter α` defines a dense inducing of `α` in `Ultrafilter α`. -/
theorem isDenseInducing_pure : @IsDenseInducing _ _ ⊥ _ (pure : α → Ultrafilter α) :=
letI : TopologicalSpace α := ⊥
⟨⟨induced_topology_pure.symm⟩, denseRange_pure⟩
-- The following refined version will never be used
/-- `pure : α → Ultrafilter α` defines a dense embedding of `α` in `Ultrafilter α`. -/
theorem isDenseEmbedding_pure : @IsDenseEmbedding _ _ ⊥ _ (pure : α → Ultrafilter α) :=
letI : TopologicalSpace α := ⊥
{ isDenseInducing_pure with injective := ultrafilter_pure_injective }
end Embedding
section Extension
/- Goal: Any function `α → γ` to a compact Hausdorff space `γ` has a
unique extension to a continuous function `Ultrafilter α → γ`. We
already know it must be unique because `α → Ultrafilter α` is a
dense embedding and `γ` is Hausdorff. For existence, we will invoke
`IsDenseInducing.continuous_extend`. -/
variable {γ : Type*} [TopologicalSpace γ]
/-- The extension of a function `α → γ` to a function `Ultrafilter α → γ`.
When `γ` is a compact Hausdorff space it will be continuous. -/
def Ultrafilter.extend (f : α → γ) : Ultrafilter α → γ :=
letI : TopologicalSpace α := ⊥
isDenseInducing_pure.extend f
variable [T2Space γ]
theorem ultrafilter_extend_extends (f : α → γ) : Ultrafilter.extend f ∘ pure = f := by
letI : TopologicalSpace α := ⊥
haveI : DiscreteTopology α := ⟨rfl⟩
exact funext (isDenseInducing_pure.extend_eq continuous_of_discreteTopology)
variable [CompactSpace γ]
theorem continuous_ultrafilter_extend (f : α → γ) : Continuous (Ultrafilter.extend f) := by
have h (b : Ultrafilter α) : ∃ c, Tendsto f (comap pure (𝓝 b)) (𝓝 c) :=
-- b.map f is an ultrafilter on γ, which is compact, so it converges to some c in γ.
let ⟨c, _, h'⟩ :=
isCompact_univ.ultrafilter_le_nhds (b.map f) (by rw [le_principal_iff]; exact univ_mem)
⟨c, le_trans (map_mono (ultrafilter_comap_pure_nhds _)) h'⟩
let _ : TopologicalSpace α := ⊥
exact isDenseInducing_pure.continuous_extend h
/-- The value of `Ultrafilter.extend f` on an ultrafilter `b` is the
unique limit of the ultrafilter `b.map f` in `γ`. -/
theorem ultrafilter_extend_eq_iff {f : α → γ} {b : Ultrafilter α} {c : γ} :
Ultrafilter.extend f b = c ↔ ↑(b.map f) ≤ 𝓝 c :=
⟨fun h ↦ by
-- Write b as an ultrafilter limit of pure ultrafilters, and use
-- the facts that ultrafilter.extend is a continuous extension of f.
let b' : Ultrafilter (Ultrafilter α) := b.map pure
have t : ↑b' ≤ 𝓝 b := ultrafilter_converges_iff.mpr (bind_pure _).symm
rw [← h]
have := (continuous_ultrafilter_extend f).tendsto b
refine le_trans ?_ (le_trans (map_mono t) this)
change _ ≤ map (Ultrafilter.extend f ∘ pure) ↑b
rw [ultrafilter_extend_extends]
exact le_rfl,
fun h ↦
let _ : TopologicalSpace α := ⊥
isDenseInducing_pure.extend_eq_of_tendsto
(le_trans (map_mono (ultrafilter_comap_pure_nhds _)) h)⟩
end Extension
end Ultrafilter
section PreStoneCech
variable (α : Type u) [TopologicalSpace α]
/-- Auxiliary construction towards the Stone-Čech compactification of a topological space.
It should not be used after the Stone-Čech compactification is constructed. -/
def PreStoneCech : Type u :=
Quot fun F G : Ultrafilter α ↦ ∃ x, (F : Filter α) ≤ 𝓝 x ∧ (G : Filter α) ≤ 𝓝 x
variable {α}
instance : TopologicalSpace (PreStoneCech α) :=
inferInstanceAs (TopologicalSpace <| Quot _)
instance : CompactSpace (PreStoneCech α) :=
Quot.compactSpace
instance [Inhabited α] : Inhabited (PreStoneCech α) :=
inferInstanceAs (Inhabited <| Quot _)
/-- The natural map from α to its pre-Stone-Čech compactification. -/
def preStoneCechUnit (x : α) : PreStoneCech α :=
Quot.mk _ (pure x : Ultrafilter α)
theorem continuous_preStoneCechUnit : Continuous (preStoneCechUnit : α → PreStoneCech α) :=
continuous_iff_ultrafilter.mpr fun x g gx ↦ by
have : (g.map pure).toFilter ≤ 𝓝 g := by
rw [ultrafilter_converges_iff, ← bind_pure g]
rfl
have : (map preStoneCechUnit g : Filter (PreStoneCech α)) ≤ 𝓝 (Quot.mk _ g) :=
(map_mono this).trans (continuous_quot_mk.tendsto _)
convert this
exact Quot.sound ⟨x, pure_le_nhds x, gx⟩
theorem denseRange_preStoneCechUnit : DenseRange (preStoneCechUnit : α → PreStoneCech α) :=
Quot.mk_surjective.denseRange.comp denseRange_pure continuous_coinduced_rng
section Extension
variable {β : Type v} [TopologicalSpace β] [T2Space β]
theorem preStoneCech_hom_ext {g₁ g₂ : PreStoneCech α → β} (h₁ : Continuous g₁) (h₂ : Continuous g₂)
(h : g₁ ∘ preStoneCechUnit = g₂ ∘ preStoneCechUnit) : g₁ = g₂ := by
apply Continuous.ext_on denseRange_preStoneCechUnit h₁ h₂
rintro x ⟨x, rfl⟩
apply congr_fun h x
variable [CompactSpace β]
variable {g : α → β} (hg : Continuous g)
include hg
lemma preStoneCechCompat {F G : Ultrafilter α} {x : α} (hF : ↑F ≤ 𝓝 x) (hG : ↑G ≤ 𝓝 x) :
Ultrafilter.extend g F = Ultrafilter.extend g G := by
replace hF := (map_mono hF).trans hg.continuousAt
replace hG := (map_mono hG).trans hg.continuousAt
rwa [show Ultrafilter.extend g G = g x by rwa [ultrafilter_extend_eq_iff, G.coe_map],
ultrafilter_extend_eq_iff, F.coe_map]
/-- The extension of a continuous function from `α` to a compact
Hausdorff space `β` to the pre-Stone-Čech compactification of `α`. -/
def preStoneCechExtend : PreStoneCech α → β :=
Quot.lift (Ultrafilter.extend g) fun _ _ ⟨_, hF, hG⟩ ↦ preStoneCechCompat hg hF hG
theorem preStoneCechExtend_extends : preStoneCechExtend hg ∘ preStoneCechUnit = g :=
ultrafilter_extend_extends g
lemma eq_if_preStoneCechUnit_eq {a b : α} (h : preStoneCechUnit a = preStoneCechUnit b) :
g a = g b := by
have e := ultrafilter_extend_extends g
rw [← congrFun e a, ← congrFun e b, Function.comp_apply, Function.comp_apply]
rw [preStoneCechUnit, preStoneCechUnit, Quot.eq] at h
generalize (pure a : Ultrafilter α) = F at h
generalize (pure b : Ultrafilter α) = G at h
induction h with
| rel x y a => exact let ⟨a, hx, hy⟩ := a; preStoneCechCompat hg hx hy
| refl x => rfl
| symm x y _ h => rw [h]
| trans x y z _ _ h h' => exact h.trans h'
theorem continuous_preStoneCechExtend : Continuous (preStoneCechExtend hg) :=
continuous_quot_lift _ (continuous_ultrafilter_extend g)
end Extension
end PreStoneCech
section StoneCech
variable (α : Type u) [TopologicalSpace α]
/-- The Stone-Čech compactification of a topological space. -/
def StoneCech : Type u :=
t2Quotient (PreStoneCech α)
variable {α}
instance : TopologicalSpace (StoneCech α) :=
inferInstanceAs <| TopologicalSpace <| t2Quotient _
instance : T2Space (StoneCech α) :=
inferInstanceAs <| T2Space <| t2Quotient _
instance : CompactSpace (StoneCech α) :=
Quot.compactSpace
instance [Inhabited α] : Inhabited (StoneCech α) :=
inferInstanceAs <| Inhabited <| Quotient _
/-- The natural map from α to its Stone-Čech compactification. -/
def stoneCechUnit (x : α) : StoneCech α :=
t2Quotient.mk (preStoneCechUnit x)
theorem continuous_stoneCechUnit : Continuous (stoneCechUnit : α → StoneCech α) :=
(t2Quotient.continuous_mk _).comp continuous_preStoneCechUnit
/-- The image of `stoneCechUnit` is dense. (But `stoneCechUnit` need
not be an embedding, for example if the original space is not Hausdorff.) -/
theorem denseRange_stoneCechUnit : DenseRange (stoneCechUnit : α → StoneCech α) := by
unfold stoneCechUnit t2Quotient.mk
have : Function.Surjective (t2Quotient.mk : PreStoneCech α → StoneCech α) := by
exact Quot.mk_surjective
exact this.denseRange.comp denseRange_preStoneCechUnit continuous_coinduced_rng
section Extension
variable {β : Type v} [TopologicalSpace β] [T2Space β]
variable {g : α → β} (hg : Continuous g)
theorem stoneCech_hom_ext {g₁ g₂ : StoneCech α → β} (h₁ : Continuous g₁) (h₂ : Continuous g₂)
(h : g₁ ∘ stoneCechUnit = g₂ ∘ stoneCechUnit) : g₁ = g₂ := by
apply h₁.ext_on denseRange_stoneCechUnit h₂
rintro _ ⟨x, rfl⟩
exact congr_fun h x
variable [CompactSpace β]
/-- The extension of a continuous function from `α` to a compact
Hausdorff space `β` to the Stone-Čech compactification of `α`.
This extension implements the universal property of this compactification. -/
def stoneCechExtend : StoneCech α → β :=
t2Quotient.lift (continuous_preStoneCechExtend hg)
theorem stoneCechExtend_extends : stoneCechExtend hg ∘ stoneCechUnit = g := by
ext x
rw [stoneCechExtend, Function.comp_apply, stoneCechUnit, t2Quotient.lift_mk]
apply congrFun (preStoneCechExtend_extends hg)
theorem continuous_stoneCechExtend : Continuous (stoneCechExtend hg) :=
continuous_coinduced_dom.mpr (continuous_preStoneCechExtend hg)
lemma eq_if_stoneCechUnit_eq {a b : α} {f : α → β} (hcf : Continuous f)
(h : stoneCechUnit a = stoneCechUnit b) : f a = f b := by
rw [← congrFun (stoneCechExtend_extends hcf), ← congrFun (stoneCechExtend_extends hcf)]
exact congrArg (stoneCechExtend hcf) h
|
end Extension
end StoneCech
| Mathlib/Topology/StoneCech.lean | 375 | 378 |
/-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Yuyang Zhao
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Comp
import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars
/-!
# One-dimensional derivatives of compositions of functions
In this file we prove the chain rule for the following cases:
* `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`;
* `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`;
* `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`;
Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra
over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`).
We also give versions with the `of_eq` suffix, which require an equality proof instead
of definitional equality of the different points used in the composition. These versions are
often more flexible to use.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, chain rule
-/
universe u v w
open scoped Topology Filter ENNReal
open Filter Asymptotics Set
open ContinuousLinearMap (smulRight smulRight_one_eq_iff)
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {f : 𝕜 → F}
variable {f' : F}
variable {x : 𝕜}
variable {s : Set 𝕜}
variable {L : Filter 𝕜}
section Composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F]
[IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'}
{g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x)
theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter
theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L')
(hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
rw [hy] at hg; exact hg.scomp x hh hL
theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x))
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩
theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y)
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs
nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp x hh hst
/-- The chain rule. -/
nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh hh.continuousAt
/-- The chain rule. -/
theorem HasDerivAt.scomp_of_eq
(hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt
theorem HasStrictDerivAt.scomp_of_eq
(hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _)
theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh
theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x))
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y)
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t')
(hy : y = h x) :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
rw [hy] at hg; exact derivWithin.scomp x hg hh hs
theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) :=
(HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv
theorem deriv.scomp_of_eq
(hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by
rw [hy] at hg; exact deriv.scomp x hg hh
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
convert (hh₂.restrictScalars 𝕜).comp x hf hL
ext x
simp [mul_comm]
theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq
{f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL
theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [HasStrictDerivAt] at hh
convert (hh.restrictScalars 𝕜).comp x hf
ext x
simp [mul_comm]
theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousAt
theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) :
HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt
theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf
theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t)
(hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst
/-! ### Derivative of the composition of two scalar functions -/
theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [mul_comm]
exact hh₂.scomp x hh hL
theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [hy] at hh₂; exact hh₂.comp x hh hL
theorem HasDerivWithinAt.comp (hh₂ : HasDerivWithinAt h₂ h₂' s' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [mul_comm]
exact hh₂.scomp x hh hst
theorem HasDerivWithinAt.comp_of_eq (hh₂ : HasDerivWithinAt h₂ h₂' s' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') (hy : y = h x) :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [hy] at hh₂; exact hh₂.comp x hh hst
/-- The chain rule.
Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule
with `h₂` taking values in a vector space, use `HasDerivAt.scomp`. -/
nonrec theorem HasDerivAt.comp (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x :=
hh₂.comp x hh hh.continuousAt
/-- The chain rule.
Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule
with `h₂` taking values in a vector space, use `HasDerivAt.scomp_of_eq`. -/
theorem HasDerivAt.comp_of_eq
(hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [hy] at hh₂; exact hh₂.comp x hh
theorem HasStrictDerivAt.comp (hh₂ : HasStrictDerivAt h₂ h₂' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [mul_comm]
exact hh₂.scomp x hh
theorem HasStrictDerivAt.comp_of_eq
(hh₂ : HasStrictDerivAt h₂ h₂' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [hy] at hh₂; exact hh₂.comp x hh
theorem HasDerivAt.comp_hasDerivWithinAt (hh₂ : HasDerivAt h₂ h₂' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x :=
hh₂.hasDerivWithinAt.comp x hh (mapsTo_univ _ _)
theorem HasDerivAt.comp_hasDerivWithinAt_of_eq (hh₂ : HasDerivAt h₂ h₂' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [hy] at hh₂; exact hh₂.comp_hasDerivWithinAt x hh
theorem derivWithin_comp (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' (h x))
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') :
derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (hh₂.hasDerivWithinAt.comp x hh.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
@[deprecated (since := "2024-10-31")] alias derivWithin.comp := derivWithin_comp
theorem derivWithin_comp_of_eq (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' y)
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s')
(hy : h x = y) :
derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by
subst hy; exact derivWithin_comp x hh₂ hh hs
@[deprecated (since := "2024-10-31")] alias derivWithin.comp_of_eq := derivWithin_comp_of_eq
theorem deriv_comp (hh₂ : DifferentiableAt 𝕜' h₂ (h x)) (hh : DifferentiableAt 𝕜 h x) :
deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x :=
(hh₂.hasDerivAt.comp x hh.hasDerivAt).deriv
@[deprecated (since := "2024-10-31")] alias deriv.comp := deriv_comp
theorem deriv_comp_of_eq (hh₂ : DifferentiableAt 𝕜' h₂ y) (hh : DifferentiableAt 𝕜 h x)
(hy : h x = y) :
deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := by
subst hy; exact deriv_comp x hh₂ hh
@[deprecated (since := "2024-10-31")] alias deriv.comp_of_eq := deriv_comp_of_eq
protected nonrec theorem HasDerivAtFilter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : HasDerivAtFilter f f' x L) (hL : Tendsto f L L) (hx : f x = x) (n : ℕ) :
HasDerivAtFilter f^[n] (f' ^ n) x L := by
have := hf.iterate hL hx n
rwa [ContinuousLinearMap.smulRight_one_pow] at this
protected nonrec theorem HasDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAt f f' x)
(hx : f x = x) (n : ℕ) : HasDerivAt f^[n] (f' ^ n) x :=
hf.iterate _ (have := hf.tendsto_nhds le_rfl; by rwa [hx] at this) hx n
protected theorem HasDerivWithinAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivWithinAt f f' s x)
(hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : HasDerivWithinAt f^[n] (f' ^ n) s x := by
have := HasFDerivWithinAt.iterate hf hx hs n
rwa [ContinuousLinearMap.smulRight_one_pow] at this
protected nonrec theorem HasStrictDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : HasStrictDerivAt f f' x) (hx : f x = x) (n : ℕ) :
HasStrictDerivAt f^[n] (f' ^ n) x := by
| have := hf.iterate hx n
rwa [ContinuousLinearMap.smulRight_one_pow] at this
| Mathlib/Analysis/Calculus/Deriv/Comp.lean | 317 | 319 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Batteries.Data.List.Pairwise
import Mathlib.Logic.Pairwise
import Mathlib.Logic.Relation
/-!
# Pairwise relations on a list
This file provides basic results about `List.Pairwise` and `List.pwFilter` (definitions are in
`Data.List.Defs`).
`Pairwise r [a 0, ..., a (n - 1)]` means `∀ i j, i < j → r (a i) (a j)`. For example,
`Pairwise (≠) l` means that all elements of `l` are distinct, and `Pairwise (<) l` means that `l`
is strictly increasing.
`pwFilter r l` is the list obtained by iteratively adding each element of `l` that doesn't break
the pairwiseness of the list we have so far. It thus yields `l'` a maximal sublist of `l` such that
`Pairwise r l'`.
## Tags
sorted, nodup
-/
open Nat Function
namespace List
variable {α β : Type*} {R : α → α → Prop} {l : List α} {a : α}
mk_iff_of_inductive_prop List.Pairwise List.pairwise_iff
/-! ### Pairwise -/
theorem Pairwise.forall_of_forall (H : Symmetric R) (H₁ : ∀ x ∈ l, R x x) (H₂ : l.Pairwise R) :
∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y :=
H₂.forall_of_forall_of_flip H₁ <| by rwa [H.flip_eq]
theorem Pairwise.forall (hR : Symmetric R) (hl : l.Pairwise R) :
∀ ⦃a⦄, a ∈ l → ∀ ⦃b⦄, b ∈ l → a ≠ b → R a b := by
apply Pairwise.forall_of_forall
· exact fun a b h hne => hR (h hne.symm)
· exact fun _ _ hx => (hx rfl).elim
· exact hl.imp (@fun a b h _ => by exact h)
theorem Pairwise.set_pairwise (hl : Pairwise R l) (hr : Symmetric R) : { x | x ∈ l }.Pairwise R :=
hl.forall hr
theorem pairwise_of_reflexive_of_forall_ne (hr : Reflexive R)
(h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → R a b) : l.Pairwise R := by
rw [pairwise_iff_forall_sublist]
intro a b hab
if heq : a = b then
cases heq; apply hr
else
apply h <;> try (apply hab.subset; simp)
exact heq
theorem Pairwise.rel_head_tail (h₁ : l.Pairwise R) (ha : a ∈ l.tail) :
R (l.head <| ne_nil_of_mem <| mem_of_mem_tail ha) a := by
cases l with
| nil => simp at ha
| cons b l => exact (pairwise_cons.1 h₁).1 a ha
theorem Pairwise.rel_head_of_rel_head_head (h₁ : l.Pairwise R) (ha : a ∈ l)
(hhead : R (l.head <| ne_nil_of_mem ha) (l.head <| ne_nil_of_mem ha)) :
R (l.head <| ne_nil_of_mem ha) a := by
cases l with
| nil => simp at ha
| cons b l => exact (mem_cons.mp ha).elim (· ▸ hhead) ((pairwise_cons.1 h₁).1 _)
theorem Pairwise.rel_head [IsRefl α R] (h₁ : l.Pairwise R) (ha : a ∈ l) :
R (l.head <| ne_nil_of_mem ha) a :=
h₁.rel_head_of_rel_head_head ha (refl_of ..)
theorem Pairwise.rel_dropLast_getLast (h : l.Pairwise R) (ha : a ∈ l.dropLast) :
R a (l.getLast <| ne_nil_of_mem <| dropLast_subset _ ha) := by
rw [← pairwise_reverse] at h
rw [getLast_eq_head_reverse]
exact h.rel_head_tail (by rwa [tail_reverse, mem_reverse])
theorem Pairwise.rel_getLast_of_rel_getLast_getLast (h₁ : l.Pairwise R) (ha : a ∈ l)
(hlast : R (l.getLast <| ne_nil_of_mem ha) (l.getLast <| ne_nil_of_mem ha)) :
R a (l.getLast <| ne_nil_of_mem ha) := by
rw [← dropLast_concat_getLast (ne_nil_of_mem ha), mem_append, List.mem_singleton] at ha
exact ha.elim h₁.rel_dropLast_getLast (· ▸ hlast)
theorem Pairwise.rel_getLast [IsRefl α R] (h₁ : l.Pairwise R) (ha : a ∈ l) :
R a (l.getLast <| ne_nil_of_mem ha) :=
h₁.rel_getLast_of_rel_getLast_getLast ha (refl_of ..)
protected alias ⟨Pairwise.of_reverse, Pairwise.reverse⟩ := pairwise_reverse
/-! ### Pairwise filtering -/
protected alias ⟨_, Pairwise.pwFilter⟩ := pwFilter_eq_self
end List
| Mathlib/Data/List/Pairwise.lean | 124 | 133 | |
/-
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.Data.ENat.Lattice
import Mathlib.Order.OrderIsoNat
import Mathlib.Tactic.TFAE
/-!
# Maximal length of chains
This file contains lemmas to work with the maximal length of strictly descending finite
sequences (chains) in a partial order.
## Main definition
- `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`.
- `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order.
This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`.
## Main results
- `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there
exists `s.subchain` of length `n`.
- `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`.
- `Set.chainHeight_image`: If `f` is an order embedding, then
`(f '' s).chainHeight = s.chainHeight`.
- `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then
`(insert x s).chainHeight = s.chainHeight + 1`.
- `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then
`(insert x s).chainHeight = s.chainHeight + 1`.
- `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then
`(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`.
- `Set.wellFoundedGT_of_chainHeight_ne_top`:
If `s` has finite height, then `>` is well-founded on `s`.
- `Set.wellFoundedLT_of_chainHeight_ne_top`:
If `s` has finite height, then `<` is well-founded on `s`.
-/
assert_not_exists Field
open List hiding le_antisymm
open OrderDual
universe u v
variable {α β : Type*}
namespace Set
section LT
variable [LT α] [LT β] (s t : Set α)
/-- The set of strictly ascending lists of `α` contained in a `Set α`. -/
def subchain : Set (List α) :=
{ l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s }
@[simp]
theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩
variable {s} {l : List α} {a : α}
theorem cons_mem_subchain_iff :
(a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by
simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm,
and_assoc]
@[simp]
theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff]
instance : Nonempty s.subchain :=
⟨⟨[], s.nil_mem_subchain⟩⟩
variable (s)
/-- The maximal length of a strictly ascending sequence in a partial order. -/
noncomputable def chainHeight : ℕ∞ :=
⨆ l ∈ s.subchain, length l
theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length :=
iSup_subtype'
theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) :
∃ l ∈ s.subchain, length l = n := by
rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;>
rw [chainHeight_eq_iSup_subtype] at ha
· obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ :=
not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n
exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
(l.length_take).trans <| min_eq_left <| le_of_not_ge h₃⟩
· rw [ENat.iSup_coe_lt_top] at ha
obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha
refine
⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
(l.length_take).trans <| min_eq_left <| ?_⟩
rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype]
theorem le_chainHeight_TFAE (n : ℕ) :
TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
tfae_have 1 → 2 := s.exists_chain_of_le_chainHeight
tfae_have 2 → 3 := fun ⟨l, hls, he⟩ ↦ ⟨l, hls, he.ge⟩
tfae_have 3 → 1 := fun ⟨l, hs, hn⟩ ↦ le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn)
tfae_finish
variable {s t}
theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n :=
(le_chainHeight_TFAE s n).out 0 1
theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight :=
le_chainHeight_iff.mpr ⟨l, hl, rfl⟩
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩
contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h
exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <|
(length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩
@[simp]
theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by
rw [← Nat.cast_one, Set.le_chainHeight_iff]
simp only [length_eq_one_iff, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and,
singleton_mem_subchain_iff, Set.Nonempty]
@[simp]
theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by
rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff,
nonempty_iff_ne_empty]
@[simp]
theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 :=
chainHeight_eq_zero_iff.2 rfl
@[simp]
theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 :=
chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _)
theorem le_chainHeight_add_nat_iff {n m : ℕ} :
↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by
simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2]
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
s.chainHeight + n ≤ t.chainHeight + m ↔
∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
refine
⟨fun e l h ↦
le_chainHeight_add_nat_iff.1
((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
fun H ↦ ?_⟩
by_cases h : s.chainHeight = ⊤
· suffices t.chainHeight = ⊤ by
rw [this, top_add]
exact le_top
rw [chainHeight_eq_top_iff] at h ⊢
intro k
have := (le_chainHeight_TFAE t k).out 1 2
rw [this]
obtain ⟨l, hs, hl⟩ := h (k + m)
obtain ⟨l', ht, hl'⟩ := H l hs
exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩
· obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h
obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le
rw [← hk, ← hl]
exact le_chainHeight_add_nat_iff.2 (H l hs)
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
tfae_have 1 ↔ 3 := by
convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero
tfae_have 2 ↔ 3 := by
refine forall₂_congr fun l _ ↦ ?_
simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm]
tfae_finish
theorem chainHeight_le_chainHeight_iff {t : Set β} :
s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l' :=
(chainHeight_le_chainHeight_TFAE s t).out 0 1
theorem chainHeight_le_chainHeight_iff_le {t : Set β} :
s.chainHeight ≤ t.chainHeight ↔ ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l' :=
(chainHeight_le_chainHeight_TFAE s t).out 0 2
theorem chainHeight_mono (h : s ⊆ t) : s.chainHeight ≤ t.chainHeight :=
chainHeight_le_chainHeight_iff.2 fun l hl ↦ ⟨l, ⟨hl.1, fun i hi ↦ h <| hl.2 i hi⟩, rfl⟩
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
(f '' s).chainHeight = s.chainHeight := by
apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
· suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
intro l hl
obtain ⟨l', h₁, rfl⟩ := this l hl
exact ⟨l', h₁, length_map _⟩
intro l
induction' l with x xs hx
· exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil h).elim⟩, rfl⟩
· intro h
rw [cons_mem_subchain_iff] at h
obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
obtain ⟨l', h₃, rfl⟩ := hx h₁
refine ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, ?_⟩, rfl⟩
cases l'
· simp
· simpa [← hf] using h₂
· intro l hl
refine ⟨l.map f, ⟨?_, ?_⟩, ?_⟩
· simp_rw [chain'_map, ← hf]
exact hl.1
· intro _ e
obtain ⟨a, ha, rfl⟩ := mem_map.mp e
exact Set.mem_image_of_mem _ (hl.2 _ ha)
· rw [length_map]
variable (s)
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
apply le_antisymm <;>
· rw [chainHeight_le_chainHeight_iff]
rintro l ⟨h₁, h₂⟩
exact ⟨l.reverse, ⟨chain'_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩,
length_reverse.symm⟩
end LT
section Preorder
variable (s t : Set α) [Preorder α]
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
apply le_antisymm
· refine iSup₂_le ?_
rintro (_ | ⟨x, xs⟩) h
· exact zero_le _
· apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
apply length_le_chainHeight_of_mem_subchain
refine ⟨h.1, fun i hi ↦ ⟨h.2 i hi, ?_⟩⟩
cases hi
· exact left_mem_Ici
rename_i hi
obtain - | h' := chain'_iff_pairwise.mp h.1
exact (h' _ hi).le
· exact iSup₂_le fun i _ ↦ chainHeight_mono Set.inter_subset_left
theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by
simp_rw [← chainHeight_dual (_ ∩ _)]
rw [← chainHeight_dual, chainHeight_eq_iSup_Ici]
rfl
variable {s t}
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
| (insert a s).chainHeight = s.chainHeight + 1 := by
rw [← add_zero (insert a s).chainHeight]
change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
· rintro (_ | ⟨y, ys⟩) h
· exact ⟨[], nil_mem_subchain _, zero_le _⟩
· have h' := cons_mem_subchain_iff.mp h
refine ⟨ys, ⟨h'.2.1.1, fun i hi ↦ ?_⟩, by simp⟩
apply (h'.2.1.2 i hi).resolve_left
rintro rfl
obtain - | hy := chain'_iff_pairwise.mp h.1
rcases h'.1 with h' | h'
exacts [(hy _ hi).ne h', not_le_of_gt (hy _ hi) (hx _ h').le]
· intro l hl
| Mathlib/Order/Height.lean | 257 | 270 |
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Eval.Subring
import Mathlib.Algebra.Polynomial.Monic
/-!
# Polynomials that lift
Given semirings `R` and `S` with a morphism `f : R →+* S`, we define a subsemiring `lifts` of
`S[X]` by the image of `RingHom.of (map f)`.
Then, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree
and that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree).
## Main definition
* `lifts (f : R →+* S)` : the subsemiring of polynomials that lift.
## Main results
* `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial
of the same degree.
* `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a
monic polynomial of the same degree.
* `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of
`mapAlg`, where `mapAlg : R[X] →ₐ[R] S[X]` is the only `R`-algebra map
that sends `X` to `X`.
## Implementation details
In general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see
`lifts_iff_lifts_ring`.
Since we do not assume `R` to be commutative, we cannot say in general that the set of polynomials
that lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.)
-/
open Polynomial
noncomputable section
namespace Polynomial
universe u v w
section Semiring
variable {R : Type u} [Semiring R] {S : Type v} [Semiring S] {f : R →+* S}
/-- We define the subsemiring of polynomials that lifts as the image of `RingHom.of (map f)`. -/
def lifts (f : R →+* S) : Subsemiring S[X] :=
RingHom.rangeS (mapRingHom f)
theorem mem_lifts (p : S[X]) : p ∈ lifts f ↔ ∃ q : R[X], map f q = p := by
simp only [coe_mapRingHom, lifts, RingHom.mem_rangeS]
theorem lifts_iff_set_range (p : S[X]) : p ∈ lifts f ↔ p ∈ Set.range (map f) := by
simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS]
theorem lifts_iff_ringHom_rangeS (p : S[X]) : p ∈ lifts f ↔ p ∈ (mapRingHom f).rangeS := by
simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS]
theorem lifts_iff_coeff_lifts (p : S[X]) : p ∈ lifts f ↔ ∀ n : ℕ, p.coeff n ∈ Set.range f := by
rw [lifts_iff_ringHom_rangeS, mem_map_rangeS f]
rfl
theorem lifts_iff_coeffs_subset_range (p : S[X]) :
p ∈ lifts f ↔ (p.coeffs : Set S) ⊆ Set.range f := by
rw [lifts_iff_coeff_lifts]
constructor
· intro h _ hc
obtain ⟨n, ⟨-, hn⟩⟩ := mem_coeffs_iff.mp hc
exact hn ▸ h n
· intro h n
by_cases hn : p.coeff n = 0
· exact ⟨0, by simp [hn]⟩
· exact h <| coeff_mem_coeffs _ _ hn
/-- If `(r : R)`, then `C (f r)` lifts. -/
theorem C_mem_lifts (f : R →+* S) (r : R) : C (f r) ∈ lifts f :=
⟨C r, by
simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true,
and_self_iff]⟩
/-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/
theorem C'_mem_lifts {f : R →+* S} {s : S} (h : s ∈ Set.range f) : C s ∈ lifts f := by
obtain ⟨r, rfl⟩ := Set.mem_range.1 h
use C r
simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true,
and_self_iff]
/-- The polynomial `X` lifts. -/
theorem X_mem_lifts (f : R →+* S) : (X : S[X]) ∈ lifts f :=
⟨X, by
simp only [coe_mapRingHom, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, map_X,
and_self_iff]⟩
/-- The polynomial `X ^ n` lifts. -/
theorem X_pow_mem_lifts (f : R →+* S) (n : ℕ) : (X ^ n : S[X]) ∈ lifts f :=
⟨X ^ n, by
simp only [coe_mapRingHom, map_pow, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true,
map_X, and_self_iff]⟩
/-- If `p` lifts and `(r : R)` then `r * p` lifts. -/
theorem base_mul_mem_lifts {p : S[X]} (r : R) (hp : p ∈ lifts f) : C (f r) * p ∈ lifts f := by
simp only [lifts, RingHom.mem_rangeS] at hp ⊢
obtain ⟨p₁, rfl⟩ := hp
use C r * p₁
simp only [coe_mapRingHom, map_C, map_mul]
/-- If `(s : S)` is in the image of `f`, then `monomial n s` lifts. -/
theorem monomial_mem_lifts {s : S} (n : ℕ) (h : s ∈ Set.range f) : monomial n s ∈ lifts f := by
obtain ⟨r, rfl⟩ := Set.mem_range.1 h
use monomial n r
| simp only [coe_mapRingHom, Set.mem_univ, map_monomial, Subsemiring.coe_top, eq_self_iff_true,
and_self_iff]
/-- If `p` lifts then `p.erase n` lifts. -/
theorem erase_mem_lifts {p : S[X]} (n : ℕ) (h : p ∈ lifts f) : p.erase n ∈ lifts f := by
| Mathlib/Algebra/Polynomial/Lifts.lean | 120 | 124 |
/-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Algebra.Polynomial.Reverse
/-!
# "Mirror" of a univariate polynomial
In this file we define `Polynomial.mirror`, a variant of `Polynomial.reverse`. The difference
between `reverse` and `mirror` is that `reverse` will decrease the degree if the polynomial is
divisible by `X`.
## Main definitions
- `Polynomial.mirror`
## Main results
- `Polynomial.mirror_mul_of_domain`: `mirror` preserves multiplication.
- `Polynomial.irreducible_of_mirror`: an irreducibility criterion involving `mirror`
-/
namespace Polynomial
section Semiring
variable {R : Type*} [Semiring R] (p q : R[X])
/-- mirror of a polynomial: reverses the coefficients while preserving `Polynomial.natDegree` -/
noncomputable def mirror :=
p.reverse * X ^ p.natTrailingDegree
@[simp]
theorem mirror_zero : (0 : R[X]).mirror = 0 := by simp [mirror]
theorem mirror_monomial (n : ℕ) (a : R) : (monomial n a).mirror = monomial n a := by
classical
by_cases ha : a = 0
· rw [ha, monomial_zero_right, mirror_zero]
· rw [mirror, reverse, natDegree_monomial n a, if_neg ha, natTrailingDegree_monomial ha, ←
C_mul_X_pow_eq_monomial, reflect_C_mul_X_pow, revAt_le (le_refl n), tsub_self, pow_zero,
mul_one]
theorem mirror_C (a : R) : (C a).mirror = C a :=
mirror_monomial 0 a
theorem mirror_X : X.mirror = (X : R[X]) :=
mirror_monomial 1 (1 : R)
theorem mirror_natDegree : p.mirror.natDegree = p.natDegree := by
by_cases hp : p = 0
· rw [hp, mirror_zero]
nontriviality R
rw [mirror, natDegree_mul', reverse_natDegree, natDegree_X_pow,
tsub_add_cancel_of_le p.natTrailingDegree_le_natDegree]
rwa [leadingCoeff_X_pow, mul_one, reverse_leadingCoeff, Ne, trailingCoeff_eq_zero]
theorem mirror_natTrailingDegree : p.mirror.natTrailingDegree = p.natTrailingDegree := by
by_cases hp : p = 0
· rw [hp, mirror_zero]
· rw [mirror, natTrailingDegree_mul_X_pow ((mt reverse_eq_zero.mp) hp),
natTrailingDegree_reverse, zero_add]
theorem coeff_mirror (n : ℕ) :
p.mirror.coeff n = p.coeff (revAt (p.natDegree + p.natTrailingDegree) n) := by
by_cases h2 : p.natDegree < n
· rw [coeff_eq_zero_of_natDegree_lt (by rwa [mirror_natDegree])]
by_cases h1 : n ≤ p.natDegree + p.natTrailingDegree
· rw [revAt_le h1, coeff_eq_zero_of_lt_natTrailingDegree]
| exact (tsub_lt_iff_left h1).mpr (Nat.add_lt_add_right h2 _)
· rw [← revAtFun_eq, revAtFun, if_neg h1, coeff_eq_zero_of_natDegree_lt h2]
rw [not_lt] at h2
rw [revAt_le (h2.trans (Nat.le_add_right _ _))]
by_cases h3 : p.natTrailingDegree ≤ n
| Mathlib/Algebra/Polynomial/Mirror.lean | 75 | 79 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Comap
import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono, gcongr]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
@[gcongr]
theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) :
μ.restrict s ≤ ν.restrict s :=
restrict_mono subset_rfl h
@[gcongr]
theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) :
μ.restrict s ≤ μ.restrict t :=
restrict_mono h le_rfl
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s := by
simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
@[simp]
theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by
rw [← measure_univ_eq_zero, restrict_apply_univ]
/-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) :=
⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩
theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 :=
restrict_eq_zero.2 h
@[simp]
theorem restrict_empty : μ.restrict ∅ = 0 :=
restrict_zero_set measure_empty
@[simp]
theorem restrict_univ : μ.restrict univ = μ :=
ext fun s hs => by simp [hs]
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq]
exact measure_inter_add_diff₀ (u ∩ s) ht
theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s :=
restrict_inter_add_diff₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
restrict_union_add_inter₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h]
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
restrict_union₀ h.aedisjoint ht.nullMeasurableSet
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
μ.restrict s + μ.restrict sᶜ = μ := by
rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self,
restrict_univ]
@[simp]
theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by
rw [add_comm, restrict_add_restrict_compl hs]
theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
le_iff.2 fun t ht ↦ by
simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s')
theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by
simp only [restrict_apply, ht, inter_iUnion]
exact
measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right)
fun i => ht.nullMeasurableSet.inter (hm i)
theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht
theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s)
{t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion]
rw [Directed.measure_iUnion]
exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _]
/-- The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/
theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
ext fun t ht => by simp [*, hf ht]
theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h,
inter_comm]
theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄
(hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ :=
calc
μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs)
_ = μ := restrict_univ
theorem restrict_congr_meas (hs : MeasurableSet s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t :=
⟨fun H t hts ht => by
rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H =>
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩
theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s := by
rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
theorem restrict_union_congr :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by
refine ⟨fun h ↦ ⟨restrict_congr_mono subset_union_left h,
restrict_congr_mono subset_union_right h⟩, ?_⟩
rintro ⟨hs, ht⟩
ext1 u hu
simp only [restrict_apply hu, inter_union_distrib_left]
rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩
calc
μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) :=
measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl
_ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm.nullMeasurableSet _).symm
_ = restrict μ s u + restrict μ t (u \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc]
_ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht]
_ = ν US + ν ((u ∩ t) \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc]
_ = ν (US ∪ u ∩ t) := measure_add_diff hm.nullMeasurableSet _
_ = ν (u ∩ s ∪ u ∩ t) := .symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl
theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
classical
induction' s using Finset.induction_on with i s _ hs; · simp
simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert]
rw [restrict_union_congr, ← hs]
theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩
ext1 t ht
have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i :=
Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht
rw [iUnion_eq_iUnion_finset]
simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i]
theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr]
theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by
rw [sUnion_eq_biUnion, restrict_biUnion_congr hc]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)}
(hm : m.Nonempty) (ht : MeasurableSet t) :
(sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by
ext1 s hs
simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht),
Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ←
Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _),
OuterMeasure.restrict_apply]
theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop}
(hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by
rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs
exact (hs.and_eventually hp).exists
/-- If a quasi measure preserving map `f` maps a set `s` to a set `t`,
then it is quasi measure preserving with respect to the restrictions of the measures. -/
theorem QuasiMeasurePreserving.restrict {ν : Measure β} {f : α → β}
(hf : QuasiMeasurePreserving f μ ν) {t : Set β} (hmaps : MapsTo f s t) :
QuasiMeasurePreserving f (μ.restrict s) (ν.restrict t) where
measurable := hf.measurable
absolutelyContinuous := by
refine AbsolutelyContinuous.mk fun u hum ↦ ?_
suffices ν (u ∩ t) = 0 → μ (f ⁻¹' u ∩ s) = 0 by simpa [hum, hf.measurable, hf.measurable hum]
refine fun hu ↦ measure_mono_null ?_ (hf.preimage_null hu)
rw [preimage_inter]
gcongr
assumption
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `biUnion`). -/
theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable)
(hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion]
alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ
theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞)
(ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by
refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_
ext1 u hu
simp only [restrict_apply hu]
induction u, hu using induction_on_inter h_gen h_inter with
| empty => simp only [Set.empty_inter, measure_empty]
| basic u hu => exact ST_eq _ ht _ hu
| compl u hu ihu =>
have := T_eq t ht
rw [Set.inter_comm] at ihu ⊢
rwa [← measure_inter_add_diff t hu, ← measure_inter_add_diff t hu, ← ihu,
ENNReal.add_right_inj] at this
exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left)
| iUnion f hfd hfm ihf =>
simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at ihf ⊢
simp only [measure_iUnion hfd hfm, ihf]
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ)
(htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht)
intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H
· simp only [H, measure_empty]
· exact h_eq _ (h_inter _ hs _ (h_sub ht) H)
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `iUnion`.
`FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/
theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞)
(h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq
· rintro _ ⟨i, rfl⟩
apply h2B
· rintro _ ⟨i, rfl⟩
apply hμB
@[simp]
theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
(sum μ).restrict s = sum fun i => (μ i).restrict s :=
ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
@[simp]
theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) :
(sum μ).restrict s = sum fun i => (μ i).restrict s := by
ext t ht
simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable]
lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by
refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_)
rw [restrict_apply ht] at htν ⊢
exact h htν
theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht]
theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet
theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) :=
le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·)
end Measure
@[simp]
theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) :
ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) :=
le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <|
iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl
@[simp]
theorem ae_restrict_union_eq (s t : Set α) :
ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by
simp [union_eq_iUnion, iSup_bool_eq]
theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype'']
theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) :=
ae_restrict_biUnion_eq s t.countable_toSet
theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp
theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp
theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup]
@[simp]
theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup]
theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup]
theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup]
theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g :=
ae_eq_restrict_biUnion_iff s t.countable_toSet f g
open scoped Interval in
theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) :
ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by
simp only [uIoc_eq_union, ae_restrict_union_eq]
open scoped Interval in
/-- See also `MeasureTheory.ae_uIoc_iff`. -/
theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔
(∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by
rw [ae_restrict_uIoc_eq, eventually_sup]
theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff₀ hp.nullMeasurableSet
theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) :
∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff] at h ⊢
simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h
theorem ae_restrict_iff'₀ {p : α → Prop} (hs : NullMeasurableSet s μ) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, restrict_apply₀' hs]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff' {p : α → Prop} (hs : MeasurableSet s) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff'₀ hs.nullMeasurableSet
theorem _root_.Filter.EventuallyEq.restrict {f g : α → δ} {s : Set α} (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.restrict s] g := by
-- note that we cannot use `ae_restrict_iff` since we do not require measurability
refine hfg.filter_mono ?_
rw [Measure.ae_le_iff_absolutelyContinuous]
exact Measure.absolutelyContinuous_of_le Measure.restrict_le_self
theorem ae_restrict_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
(ae_restrict_iff'₀ hs).2 (Filter.Eventually.of_forall fun _ => id)
theorem ae_restrict_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
ae_restrict_mem₀ hs.nullMeasurableSet
theorem ae_restrict_of_forall_mem {μ : Measure α} {s : Set α}
(hs : MeasurableSet s) {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᵐ (x : α) ∂μ.restrict s, p x :=
(ae_restrict_mem hs).mono h
theorem ae_restrict_of_ae {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono Measure.restrict_le_self)
theorem ae_restrict_of_ae_restrict_of_subset {s t : Set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂μ.restrict t, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono <| Measure.restrict_mono hst (le_refl μ))
theorem ae_of_ae_restrict_of_ae_restrict_compl (t : Set α) {p : α → Prop}
(ht : ∀ᵐ x ∂μ.restrict t, p x) (htc : ∀ᵐ x ∂μ.restrict tᶜ, p x) : ∀ᵐ x ∂μ, p x :=
nonpos_iff_eq_zero.1 <|
calc
μ { x | ¬p x } ≤ μ ({ x | ¬p x } ∩ t) + μ ({ x | ¬p x } ∩ tᶜ) :=
measure_le_inter_add_diff _ _ _
_ ≤ μ.restrict t { x | ¬p x } + μ.restrict tᶜ { x | ¬p x } :=
add_le_add (le_restrict_apply _ _) (le_restrict_apply _ _)
_ = 0 := by rw [ae_iff.1 ht, ae_iff.1 htc, zero_add]
theorem mem_map_restrict_ae_iff {β} {s : Set α} {t : Set β} {f : α → β} (hs : MeasurableSet s) :
t ∈ Filter.map f (ae (μ.restrict s)) ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0 := by
rw [mem_map, mem_ae_iff, Measure.restrict_apply' hs]
theorem ae_add_measure_iff {p : α → Prop} {ν} :
(∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero
theorem ae_eq_comp' {ν : Measure β} {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ)
(h : g =ᵐ[ν] g') (h2 : μ.map f ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=
(tendsto_ae_map hf).mono_right h2.ae_le h
theorem Measure.QuasiMeasurePreserving.ae_eq_comp {ν : Measure β} {f : α → β} {g g' : β → δ}
(hf : QuasiMeasurePreserving f μ ν) (h : g =ᵐ[ν] g') : g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf.aemeasurable h hf.absolutelyContinuous
theorem ae_eq_comp {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ) (h : g =ᵐ[μ.map f] g') :
g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf h AbsolutelyContinuous.rfl
@[to_additive]
theorem div_ae_eq_one {β} [Group β] (f g : α → β) : f / g =ᵐ[μ] 1 ↔ f =ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun x hx ↦ ?_, fun h ↦ h.mono fun x hx ↦ ?_⟩
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one] at hx
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one]
@[to_additive sub_nonneg_ae]
lemma one_le_div_ae {β : Type*} [Group β] [LE β] [MulRightMono β] (f g : α → β) :
1 ≤ᵐ[μ] g / f ↔ f ≤ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun a ha ↦ ?_, fun h ↦ h.mono fun a ha ↦ ?_⟩
· rwa [Pi.one_apply, Pi.div_apply, one_le_div'] at ha
· rwa [Pi.one_apply, Pi.div_apply, one_le_div']
theorem le_ae_restrict : ae μ ⊓ 𝓟 s ≤ ae (μ.restrict s) := fun _s hs =>
eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)
@[simp]
theorem ae_restrict_eq (hs : MeasurableSet s) : ae (μ.restrict s) = ae μ ⊓ 𝓟 s := by
ext t
simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_setOf,
Classical.not_imp, fun a => and_comm (a := a ∈ s) (b := ¬a ∈ t)]
rfl
lemma ae_restrict_le : ae (μ.restrict s) ≤ ae μ :=
ae_mono restrict_le_self
theorem ae_restrict_eq_bot {s} : ae (μ.restrict s) = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans restrict_eq_zero
theorem ae_restrict_neBot {s} : (ae <| μ.restrict s).NeBot ↔ μ s ≠ 0 :=
neBot_iff.trans ae_restrict_eq_bot.not
theorem self_mem_ae_restrict {s} (hs : MeasurableSet s) : s ∈ ae (μ.restrict s) := by
simp only [ae_restrict_eq hs, exists_prop, mem_principal, mem_inf_iff]
exact ⟨_, univ_mem, s, Subset.rfl, (univ_inter s).symm⟩
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_of_ae_eq_of_ae_restrict {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) → ∀ᵐ x ∂μ.restrict t, p x := by simp [Measure.restrict_congr_set hst]
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_congr_set {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ.restrict t, p x :=
⟨ae_restrict_of_ae_eq_of_ae_restrict hst, ae_restrict_of_ae_eq_of_ae_restrict hst.symm⟩
lemma NullMeasurable.measure_preimage_eq_measure_restrict_preimage_of_ae_compl_eq_const
{β : Type*} [MeasurableSpace β] {b : β} {f : α → β} {s : Set α}
(f_mble : NullMeasurable f (μ.restrict s)) (hs : f =ᵐ[Measure.restrict μ sᶜ] (fun _ ↦ b))
{t : Set β} (t_mble : MeasurableSet t) (ht : b ∉ t) :
μ (f ⁻¹' t) = μ.restrict s (f ⁻¹' t) := by
rw [Measure.restrict_apply₀ (f_mble t_mble)]
rw [EventuallyEq, ae_iff, Measure.restrict_apply₀] at hs
· apply le_antisymm _ (measure_mono inter_subset_left)
apply (measure_mono (Eq.symm (inter_union_compl (f ⁻¹' t) s)).le).trans
apply (measure_union_le _ _).trans
have obs : μ ((f ⁻¹' t) ∩ sᶜ) = 0 := by
apply le_antisymm _ (zero_le _)
rw [← hs]
apply measure_mono (inter_subset_inter_left _ _)
intro x hx hfx
simp only [mem_preimage, mem_setOf_eq] at hx hfx
exact ht (hfx ▸ hx)
simp only [obs, add_zero, le_refl]
· exact NullMeasurableSet.of_null hs
namespace Measure
section Subtype
/-! ### Subtype of a measure space -/
section ComapAnyMeasure
theorem MeasurableSet.nullMeasurableSet_subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : MeasurableSet t) : NullMeasurableSet ((↑) '' t) μ := by
rw [Subtype.instMeasurableSpace, comap_eq_generateFrom] at ht
induction t, ht using generateFrom_induction with
| hC t' ht' =>
obtain ⟨s', hs', rfl⟩ := ht'
rw [Subtype.image_preimage_coe]
exact hs.inter (hs'.nullMeasurableSet)
| empty => simp only [image_empty, nullMeasurableSet_empty]
| compl t' _ ht' =>
simp only [← range_diff_image Subtype.coe_injective, Subtype.range_coe_subtype, setOf_mem_eq]
exact hs.diff ht'
| iUnion f _ hf =>
dsimp only []
rw [image_iUnion]
exact .iUnion hf
theorem NullMeasurableSet.subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : NullMeasurableSet t (μ.comap Subtype.val)) : NullMeasurableSet (((↑) : s → α) '' t) μ :=
NullMeasurableSet.image _ μ Subtype.coe_injective
(fun _ => MeasurableSet.nullMeasurableSet_subtype_coe hs) ht
theorem measure_subtype_coe_le_comap (hs : NullMeasurableSet s μ) (t : Set s) :
μ (((↑) : s → α) '' t) ≤ μ.comap Subtype.val t :=
le_comap_apply _ _ Subtype.coe_injective (fun _ =>
MeasurableSet.nullMeasurableSet_subtype_coe hs) _
theorem measure_subtype_coe_eq_zero_of_comap_eq_zero (hs : NullMeasurableSet s μ) {t : Set s}
(ht : μ.comap Subtype.val t = 0) : μ (((↑) : s → α) '' t) = 0 :=
eq_bot_iff.mpr <| (measure_subtype_coe_le_comap hs t).trans ht.le
end ComapAnyMeasure
section MeasureSpace
variable {u : Set δ} [MeasureSpace δ] {p : δ → Prop}
/-- In a measure space, one can restrict the measure to a subtype to get a new measure space.
Not registered as an instance, as there are other natural choices such as the normalized restriction
for a probability measure, or the subspace measure when restricting to a vector subspace. Enable
locally if needed with `attribute [local instance] Measure.Subtype.measureSpace`. -/
noncomputable def Subtype.measureSpace : MeasureSpace (Subtype p) where
volume := Measure.comap Subtype.val volume
attribute [local instance] Subtype.measureSpace
theorem Subtype.volume_def : (volume : Measure u) = volume.comap Subtype.val :=
rfl
theorem Subtype.volume_univ (hu : NullMeasurableSet u) : volume (univ : Set u) = volume u := by
rw [Subtype.volume_def, comap_apply₀ _ _ _ _ MeasurableSet.univ.nullMeasurableSet]
· congr
simp only [image_univ, Subtype.range_coe_subtype, setOf_mem_eq]
· exact Subtype.coe_injective
· exact fun t => MeasurableSet.nullMeasurableSet_subtype_coe hu
theorem volume_subtype_coe_le_volume (hu : NullMeasurableSet u) (t : Set u) :
volume (((↑) : u → δ) '' t) ≤ volume t :=
measure_subtype_coe_le_comap hu t
theorem volume_subtype_coe_eq_zero_of_volume_eq_zero (hu : NullMeasurableSet u) {t : Set u}
(ht : volume t = 0) : volume (((↑) : u → δ) '' t) = 0 :=
measure_subtype_coe_eq_zero_of_comap_eq_zero hu ht
end MeasureSpace
end Subtype
end Measure
end MeasureTheory
open MeasureTheory Measure
namespace MeasurableEmbedding
variable {m0 : MeasurableSpace α} {m1 : MeasurableSpace β} {f : α → β}
section
variable (hf : MeasurableEmbedding f)
include hf
theorem map_comap (μ : Measure β) : (comap f μ).map f = μ.restrict (range f) := by
ext1 t ht
rw [hf.map_apply, comap_apply f hf.injective hf.measurableSet_image' _ (hf.measurable ht),
image_preimage_eq_inter_range, Measure.restrict_apply ht]
theorem comap_apply (μ : Measure β) (s : Set α) : comap f μ s = μ (f '' s) :=
calc
comap f μ s = comap f μ (f ⁻¹' (f '' s)) := by rw [hf.injective.preimage_image]
_ = (comap f μ).map f (f '' s) := (hf.map_apply _ _).symm
_ = μ (f '' s) := by
rw [hf.map_comap, restrict_apply' hf.measurableSet_range,
inter_eq_self_of_subset_left (image_subset_range _ _)]
theorem comap_map (μ : Measure α) : (map f μ).comap f = μ := by
ext t _
rw [hf.comap_apply, hf.map_apply, preimage_image_eq _ hf.injective]
theorem ae_map_iff {p : β → Prop} {μ : Measure α} : (∀ᵐ x ∂μ.map f, p x) ↔ ∀ᵐ x ∂μ, p (f x) := by
simp only [ae_iff, hf.map_apply, preimage_setOf_eq]
theorem restrict_map (μ : Measure α) (s : Set β) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
Measure.ext fun t ht => by simp [hf.map_apply, ht, hf.measurable ht]
protected theorem comap_preimage (μ : Measure β) (s : Set β) :
μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by
rw [← hf.map_apply, hf.map_comap, restrict_apply' hf.measurableSet_range]
lemma comap_restrict (μ : Measure β) (s : Set β) :
(μ.restrict s).comap f = (μ.comap f).restrict (f ⁻¹' s) := by
ext t ht
rw [Measure.restrict_apply ht, comap_apply hf, comap_apply hf,
Measure.restrict_apply (hf.measurableSet_image.2 ht), image_inter_preimage]
lemma restrict_comap (μ : Measure β) (s : Set α) :
(μ.comap f).restrict s = (μ.restrict (f '' s)).comap f := by
rw [comap_restrict hf, preimage_image_eq _ hf.injective]
end
theorem _root_.MeasurableEquiv.restrict_map (e : α ≃ᵐ β) (μ : Measure α) (s : Set β) :
(μ.map e).restrict s = (μ.restrict <| e ⁻¹' s).map e :=
e.measurableEmbedding.restrict_map _ _
end MeasurableEmbedding
section Subtype
theorem comap_subtype_coe_apply {_m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s)
(μ : Measure α) (t : Set s) : comap (↑) μ t = μ ((↑) '' t) :=
(MeasurableEmbedding.subtype_coe hs).comap_apply _ _
theorem map_comap_subtype_coe {m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s)
(μ : Measure α) : (comap (↑) μ).map ((↑) : s → α) = μ.restrict s := by
rw [(MeasurableEmbedding.subtype_coe hs).map_comap, Subtype.range_coe]
theorem ae_restrict_iff_subtype {m0 : MeasurableSpace α} {μ : Measure α} {s : Set α}
(hs : MeasurableSet s) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ (x : s) ∂comap ((↑) : s → α) μ, p x := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).ae_map_iff]
variable [MeasureSpace α] {s t : Set α}
/-!
### Volume on `s : Set α`
Note the instance is provided earlier as `Subtype.measureSpace`.
-/
attribute [local instance] Subtype.measureSpace
theorem volume_set_coe_def (s : Set α) : (volume : Measure s) = comap ((↑) : s → α) volume :=
rfl
theorem MeasurableSet.map_coe_volume {s : Set α} (hs : MeasurableSet s) :
volume.map ((↑) : s → α) = restrict volume s := by
rw [volume_set_coe_def, (MeasurableEmbedding.subtype_coe hs).map_comap volume, Subtype.range_coe]
theorem volume_image_subtype_coe {s : Set α} (hs : MeasurableSet s) (t : Set s) :
volume ((↑) '' t : Set α) = volume t :=
(comap_subtype_coe_apply hs volume t).symm
@[simp]
theorem volume_preimage_coe (hs : NullMeasurableSet s) (ht : MeasurableSet t) :
volume (((↑) : s → α) ⁻¹' t) = volume (t ∩ s) := by
rw [volume_set_coe_def,
comap_apply₀ _ _ Subtype.coe_injective
(fun h => MeasurableSet.nullMeasurableSet_subtype_coe hs)
(measurable_subtype_coe ht).nullMeasurableSet,
image_preimage_eq_inter_range, Subtype.range_coe]
end Subtype
section Piecewise
variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f g : α → β}
theorem piecewise_ae_eq_restrict [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
piecewise s f g =ᵐ[μ.restrict s] f := by
rw [ae_restrict_eq hs]
exact (piecewise_eqOn s f g).eventuallyEq.filter_mono inf_le_right
theorem piecewise_ae_eq_restrict_compl [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
piecewise s f g =ᵐ[μ.restrict sᶜ] g := by
rw [ae_restrict_eq hs.compl]
exact (piecewise_eqOn_compl s f g).eventuallyEq.filter_mono inf_le_right
theorem piecewise_ae_eq_of_ae_eq_set [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)]
(hst : s =ᵐ[μ] t) : s.piecewise f g =ᵐ[μ] t.piecewise f g :=
hst.mem_iff.mono fun x hx => by simp [piecewise, hx]
end Piecewise
section IndicatorFunction
variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f : α → β}
theorem mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem [Zero β] {t : Set β}
(ht : (0 : β) ∈ t) (hs : MeasurableSet s) :
t ∈ Filter.map (s.indicator f) (ae μ) ↔ t ∈ Filter.map f (ae <| μ.restrict s) := by
classical
simp_rw [mem_map, mem_ae_iff]
rw [Measure.restrict_apply' hs, Set.indicator_preimage, Set.ite]
simp_rw [Set.compl_union, Set.compl_inter]
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((fun _ => (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0
simp only [ht, ← Set.compl_eq_univ_diff, compl_compl, Set.compl_union, if_true,
Set.preimage_const]
simp_rw [Set.union_inter_distrib_right, Set.compl_inter_self s, Set.union_empty]
theorem mem_map_indicator_ae_iff_of_zero_nmem [Zero β] {t : Set β} (ht : (0 : β) ∉ t) :
t ∈ Filter.map (s.indicator f) (ae μ) ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0 := by
classical
rw [mem_map, mem_ae_iff, Set.indicator_preimage, Set.ite, Set.compl_union, Set.compl_inter]
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((fun _ => (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0
simp only [ht, if_false, Set.compl_empty, Set.empty_diff, Set.inter_univ, Set.preimage_const]
theorem map_restrict_ae_le_map_indicator_ae [Zero β] (hs : MeasurableSet s) :
Filter.map f (ae <| μ.restrict s) ≤ Filter.map (s.indicator f) (ae μ) := by
intro t
| by_cases ht : (0 : β) ∈ t
· rw [mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem ht hs]
exact id
rw [mem_map_indicator_ae_iff_of_zero_nmem ht, mem_map_restrict_ae_iff hs]
exact fun h => measure_mono_null (Set.inter_subset_left.trans Set.subset_union_left) h
| Mathlib/MeasureTheory/Measure/Restrict.lean | 926 | 930 |
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Convex.Gauge
import Mathlib.Analysis.Normed.Module.Convex
/-!
# "Gauge rescale" homeomorphism between convex sets
Given two convex von Neumann bounded neighbourhoods of the origin
in a real topological vector space,
we construct a homeomorphism `gaugeRescaleHomeomorph`
that sends the interior, the closure, and the frontier of one set
to the interior, the closure, and the frontier of the other set.
-/
open Metric Bornology Filter Set
open scoped NNReal Topology Pointwise
noncomputable section
section Module
variable {E : Type*} [AddCommGroup E] [Module ℝ E]
/-- The gauge rescale map `gaugeRescale s t` sends each point `x` to the point `y` on the same ray
that has the same gauge w.r.t. `t` as `x` has w.r.t. `s`.
The characteristic property is satisfied if `gauge t x ≠ 0`, see `gauge_gaugeRescale'`.
In particular, it is satisfied for all `x`,
provided that `t` is absorbent and von Neumann bounded. -/
def gaugeRescale (s t : Set E) (x : E) : E := (gauge s x / gauge t x) • x
theorem gaugeRescale_def (s t : Set E) (x : E) :
gaugeRescale s t x = (gauge s x / gauge t x) • x :=
rfl
@[simp] theorem gaugeRescale_zero (s t : Set E) : gaugeRescale s t 0 = 0 := smul_zero _
theorem gaugeRescale_smul (s t : Set E) {c : ℝ} (hc : 0 ≤ c) (x : E) :
gaugeRescale s t (c • x) = c • gaugeRescale s t x := by
simp only [gaugeRescale, gauge_smul_of_nonneg hc, smul_smul, smul_eq_mul]
rw [mul_div_mul_comm, mul_right_comm, div_self_mul_self]
theorem gauge_gaugeRescale' (s : Set E) {t : Set E} {x : E} (hx : gauge t x ≠ 0) :
gauge t (gaugeRescale s t x) = gauge s x := by
rw [gaugeRescale, gauge_smul_of_nonneg (div_nonneg (gauge_nonneg _) (gauge_nonneg _)),
smul_eq_mul, div_mul_cancel₀ _ hx]
theorem gauge_gaugeRescale_le (s t : Set E) (x : E) :
gauge t (gaugeRescale s t x) ≤ gauge s x := by
by_cases hx : gauge t x = 0
· simp [gaugeRescale, hx, gauge_nonneg]
· exact (gauge_gaugeRescale' s hx).le
variable [TopologicalSpace E]
section
variable [T1Space E]
theorem gaugeRescale_self_apply {s : Set E} (hsa : Absorbent ℝ s) (hsb : IsVonNBounded ℝ s)
(x : E) : gaugeRescale s s x = x := by
rcases eq_or_ne x 0 with rfl | hx; · simp
rw [gaugeRescale, div_self, one_smul]
exact ((gauge_pos hsa hsb).2 hx).ne'
theorem gaugeRescale_self {s : Set E} (hsa : Absorbent ℝ s) (hsb : IsVonNBounded ℝ s) :
gaugeRescale s s = id :=
funext <| gaugeRescale_self_apply hsa hsb
theorem gauge_gaugeRescale (s : Set E) {t : Set E} (hta : Absorbent ℝ t) (htb : IsVonNBounded ℝ t)
(x : E) : gauge t (gaugeRescale s t x) = gauge s x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· exact gauge_gaugeRescale' s ((gauge_pos hta htb).2 hx).ne'
theorem gaugeRescale_gaugeRescale {s t u : Set E} (hta : Absorbent ℝ t) (htb : IsVonNBounded ℝ t)
(x : E) : gaugeRescale t u (gaugeRescale s t x) = gaugeRescale s u x := by
rcases eq_or_ne x 0 with rfl | hx; · simp
rw [gaugeRescale_def s t x, gaugeRescale_smul, gaugeRescale, gaugeRescale, smul_smul,
div_mul_div_cancel₀]
exacts [((gauge_pos hta htb).2 hx).ne', div_nonneg (gauge_nonneg _) (gauge_nonneg _)]
/-- `gaugeRescale` bundled as an `Equiv`. -/
def gaugeRescaleEquiv (s t : Set E) (hsa : Absorbent ℝ s) (hsb : IsVonNBounded ℝ s)
(hta : Absorbent ℝ t) (htb : IsVonNBounded ℝ t) : E ≃ E where
toFun := gaugeRescale s t
invFun := gaugeRescale t s
left_inv x := by rw [gaugeRescale_gaugeRescale, gaugeRescale_self_apply] <;> assumption
right_inv x := by rw [gaugeRescale_gaugeRescale, gaugeRescale_self_apply] <;> assumption
end
variable [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] {s t : Set E}
theorem mapsTo_gaugeRescale_interior (h₀ : t ∈ 𝓝 0) (hc : Convex ℝ t) :
MapsTo (gaugeRescale s t) (interior s) (interior t) := fun x hx ↦ by
rw [← gauge_lt_one_iff_mem_interior] <;> try assumption
exact (gauge_gaugeRescale_le _ _ _).trans_lt (interior_subset_gauge_lt_one _ hx)
theorem mapsTo_gaugeRescale_closure {s t : Set E} (hsc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0)
| (htc : Convex ℝ t) (ht₀ : 0 ∈ t) (hta : Absorbent ℝ t) :
MapsTo (gaugeRescale s t) (closure s) (closure t) := fun _x hx ↦
mem_closure_of_gauge_le_one htc ht₀ hta <| (gauge_gaugeRescale_le _ _ _).trans <|
(gauge_le_one_iff_mem_closure hsc hs₀).2 hx
variable [T1Space E]
theorem continuous_gaugeRescale {s t : Set E} (hs : Convex ℝ s) (hs₀ : s ∈ 𝓝 0)
(ht : Convex ℝ t) (ht₀ : t ∈ 𝓝 0) (htb : IsVonNBounded ℝ t) :
Continuous (gaugeRescale s t) := by
have hta : Absorbent ℝ t := absorbent_nhds_zero ht₀
refine continuous_iff_continuousAt.2 fun x ↦ ?_
| Mathlib/Analysis/Convex/GaugeRescale.lean | 103 | 114 |
/-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Cast
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Tactic.DeriveFintype
/-!
# Sign function
This file defines the sign function for types with zero and a decidable less-than relation, and
proves some basic theorems about it.
-/
-- Don't generate unnecessary `sizeOf_spec` lemmas which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- The type of signs. -/
inductive SignType
| zero
| neg
| pos
deriving DecidableEq, Inhabited, Fintype
namespace SignType
instance : Zero SignType :=
⟨zero⟩
instance : One SignType :=
⟨pos⟩
instance : Neg SignType :=
⟨fun s =>
match s with
| neg => pos
| zero => zero
| pos => neg⟩
@[simp]
theorem zero_eq_zero : zero = 0 :=
rfl
@[simp]
theorem neg_eq_neg_one : neg = -1 :=
rfl
@[simp]
theorem pos_eq_one : pos = 1 :=
rfl
instance : Mul SignType :=
⟨fun x y =>
match x with
| neg => -y
| zero => zero
| pos => y⟩
/-- The less-than-or-equal relation on signs. -/
protected inductive LE : SignType → SignType → Prop
| of_neg (a) : SignType.LE neg a
| zero : SignType.LE zero zero
| of_pos (a) : SignType.LE a pos
instance : LE SignType :=
⟨SignType.LE⟩
instance LE.decidableRel : DecidableRel SignType.LE := fun a b => by
cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩)
instance decidableEq : DecidableEq SignType := fun a b => by
cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩)
private lemma mul_comm : ∀ (a b : SignType), a * b = b * a := by rintro ⟨⟩ ⟨⟩ <;> rfl
private lemma mul_assoc : ∀ (a b c : SignType), (a * b) * c = a * (b * c) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩ <;> rfl
/- We can define a `Field` instance on `SignType`, but it's not mathematically sensible,
so we only define the `CommGroupWithZero`. -/
instance : CommGroupWithZero SignType where
zero := 0
one := 1
mul := (· * ·)
inv := id
mul_zero a := by cases a <;> rfl
zero_mul a := by cases a <;> rfl
mul_one a := by cases a <;> rfl
one_mul a := by cases a <;> rfl
mul_inv_cancel a ha := by cases a <;> trivial
mul_comm := mul_comm
mul_assoc := mul_assoc
exists_pair_ne := ⟨0, 1, by rintro ⟨_⟩⟩
inv_zero := rfl
private lemma le_antisymm (a b : SignType) (_ : a ≤ b) (_ : b ≤ a) : a = b := by
cases a <;> cases b <;> trivial
private lemma le_trans (a b c : SignType) (_ : a ≤ b) (_ : b ≤ c) : a ≤ c := by
cases a <;> cases b <;> cases c <;> tauto
instance : LinearOrder SignType where
le := (· ≤ ·)
le_refl a := by cases a <;> constructor
le_total a b := by cases a <;> cases b <;> first | left; constructor | right; constructor
le_antisymm := le_antisymm
le_trans := le_trans
toDecidableLE := LE.decidableRel
toDecidableEq := SignType.decidableEq
instance : BoundedOrder SignType where
top := 1
le_top := LE.of_pos
bot := -1
bot_le :=
#adaptation_note /-- https://github.com/leanprover/lean4/pull/6053
Added `by exact`, but don't understand why it was needed. -/
by exact LE.of_neg
instance : HasDistribNeg SignType :=
{ neg_neg := fun x => by cases x <;> rfl
neg_mul := fun x y => by cases x <;> cases y <;> rfl
mul_neg := fun x y => by cases x <;> cases y <;> rfl }
/-- `SignType` is equivalent to `Fin 3`. -/
def fin3Equiv : SignType ≃* Fin 3 where
toFun a :=
match a with
| 0 => ⟨0, by simp⟩
| 1 => ⟨1, by simp⟩
| -1 => ⟨2, by simp⟩
invFun a :=
match a with
| ⟨0, _⟩ => 0
| ⟨1, _⟩ => 1
| ⟨2, _⟩ => -1
left_inv a := by cases a <;> rfl
right_inv a :=
match a with
| ⟨0, _⟩ => by simp
| ⟨1, _⟩ => by simp
| ⟨2, _⟩ => by simp
map_mul' a b := by
cases a <;> cases b <;> rfl
section CaseBashing
theorem nonneg_iff {a : SignType} : 0 ≤ a ↔ a = 0 ∨ a = 1 := by decide +revert
theorem nonneg_iff_ne_neg_one {a : SignType} : 0 ≤ a ↔ a ≠ -1 := by decide +revert
theorem neg_one_lt_iff {a : SignType} : -1 < a ↔ 0 ≤ a := by decide +revert
theorem nonpos_iff {a : SignType} : a ≤ 0 ↔ a = -1 ∨ a = 0 := by decide +revert
theorem nonpos_iff_ne_one {a : SignType} : a ≤ 0 ↔ a ≠ 1 := by decide +revert
theorem lt_one_iff {a : SignType} : a < 1 ↔ a ≤ 0 := by decide +revert
@[simp]
theorem neg_iff {a : SignType} : a < 0 ↔ a = -1 := by decide +revert
@[simp]
theorem le_neg_one_iff {a : SignType} : a ≤ -1 ↔ a = -1 :=
le_bot_iff
@[simp]
theorem pos_iff {a : SignType} : 0 < a ↔ a = 1 := by decide +revert
@[simp]
theorem one_le_iff {a : SignType} : 1 ≤ a ↔ a = 1 :=
top_le_iff
@[simp]
theorem neg_one_le (a : SignType) : -1 ≤ a :=
bot_le
@[simp]
theorem le_one (a : SignType) : a ≤ 1 :=
le_top
@[simp]
theorem not_lt_neg_one (a : SignType) : ¬a < -1 :=
not_lt_bot
@[simp]
theorem not_one_lt (a : SignType) : ¬1 < a :=
not_top_lt
@[simp]
theorem self_eq_neg_iff (a : SignType) : a = -a ↔ a = 0 := by decide +revert
@[simp]
theorem neg_eq_self_iff (a : SignType) : -a = a ↔ a = 0 := by decide +revert
@[simp]
theorem neg_one_lt_one : (-1 : SignType) < 1 :=
bot_lt_top
end CaseBashing
section cast
variable {α : Type*} [Zero α] [One α] [Neg α]
/-- Turn a `SignType` into zero, one, or minus one. This is a coercion instance. -/
@[coe]
def cast : SignType → α
| zero => 0
| pos => 1
| neg => -1
/-- This is a `CoeTail` since the type on the right (trivially) determines the type on the left.
`outParam`-wise it could be a `Coe`, but we don't want to try applying this instance for a
coercion to any `α`.
-/
instance : CoeTail SignType α :=
⟨cast⟩
/-- Casting out of `SignType` respects composition with functions preserving `0, 1, -1`. -/
lemma map_cast' {β : Type*} [One β] [Neg β] [Zero β]
(f : α → β) (h₁ : f 1 = 1) (h₂ : f 0 = 0) (h₃ : f (-1) = -1) (s : SignType) :
f s = s := by
cases s <;> simp only [SignType.cast, h₁, h₂, h₃]
/-- Casting out of `SignType` respects composition with suitable bundled homomorphism types. -/
lemma map_cast {α β F : Type*} [AddGroupWithOne α] [One β] [SubtractionMonoid β]
[FunLike F α β] [AddMonoidHomClass F α β] [OneHomClass F α β] (f : F) (s : SignType) :
f s = s := by
apply map_cast' <;> simp
@[simp]
theorem coe_zero : ↑(0 : SignType) = (0 : α) :=
rfl
@[simp]
theorem coe_one : ↑(1 : SignType) = (1 : α) :=
rfl
@[simp]
theorem coe_neg_one : ↑(-1 : SignType) = (-1 : α) :=
rfl
@[simp, norm_cast]
lemma coe_neg {α : Type*} [One α] [SubtractionMonoid α] (s : SignType) :
(↑(-s) : α) = -↑s := by
cases s <;> simp
/-- Casting `SignType → ℤ → α` is the same as casting directly `SignType → α`. -/
@[simp, norm_cast]
lemma intCast_cast {α : Type*} [AddGroupWithOne α] (s : SignType) : ((s : ℤ) : α) = s :=
map_cast' _ Int.cast_one Int.cast_zero (@Int.cast_one α _ ▸ Int.cast_neg 1) _
end cast
/-- `SignType.cast` as a `MulWithZeroHom`. -/
@[simps]
def castHom {α} [MulZeroOneClass α] [HasDistribNeg α] : SignType →*₀ α where
toFun := cast
map_zero' := rfl
map_one' := rfl
map_mul' x y := by cases x <;> cases y <;> simp [zero_eq_zero, pos_eq_one, neg_eq_neg_one]
theorem univ_eq : (Finset.univ : Finset SignType) = {0, -1, 1} := by
decide
theorem range_eq {α} (f : SignType → α) : Set.range f = {f zero, f neg, f pos} := by
classical rw [← Fintype.coe_image_univ, univ_eq]
classical simp [Finset.coe_insert]
@[simp, norm_cast] lemma coe_mul {α} [MulZeroOneClass α] [HasDistribNeg α] (a b : SignType) :
↑(a * b) = (a : α) * b :=
map_mul SignType.castHom _ _
@[simp, norm_cast] lemma coe_pow {α} [MonoidWithZero α] [HasDistribNeg α] (a : SignType) (k : ℕ) :
↑(a ^ k) = (a : α) ^ k :=
map_pow SignType.castHom _ _
@[simp, norm_cast] lemma coe_zpow {α} [GroupWithZero α] [HasDistribNeg α] (a : SignType) (k : ℤ) :
↑(a ^ k) = (a : α) ^ k :=
map_zpow₀ SignType.castHom _ _
end SignType
-- The lemma `exists_signed_sum` needs explicit universe handling in its statement.
universe u
variable {α : Type u}
open SignType
section Preorder
variable [Zero α] [Preorder α] [DecidableLT α] {a : α}
/-- The sign of an element is 1 if it's positive, -1 if negative, 0 otherwise. -/
def SignType.sign : α →o SignType :=
⟨fun a => if 0 < a then 1 else if a < 0 then -1 else 0, fun a b h => by
dsimp
split_ifs with h₁ h₂ h₃ h₄ _ _ h₂ h₃ <;> try constructor
· cases lt_irrefl 0 (h₁.trans <| h.trans_lt h₃)
· cases h₂ (h₁.trans_le h)
· cases h₄ (h.trans_lt h₃)⟩
theorem sign_apply : sign a = ite (0 < a) 1 (ite (a < 0) (-1) 0) :=
rfl
@[simp]
theorem sign_zero : sign (0 : α) = 0 := by simp [sign_apply]
@[simp]
theorem sign_pos (ha : 0 < a) : sign a = 1 := by rwa [sign_apply, if_pos]
@[simp]
theorem sign_neg (ha : a < 0) : sign a = -1 := by rwa [sign_apply, if_neg <| asymm ha, if_pos]
theorem sign_eq_one_iff : sign a = 1 ↔ 0 < a := by
refine ⟨fun h => ?_, fun h => sign_pos h⟩
by_contra hn
rw [sign_apply, if_neg hn] at h
split_ifs at h
theorem sign_eq_neg_one_iff : sign a = -1 ↔ a < 0 := by
refine ⟨fun h => ?_, fun h => sign_neg h⟩
rw [sign_apply] at h
split_ifs at h
assumption
end Preorder
section LinearOrder
variable [Zero α] [LinearOrder α] {a : α}
/-- `SignType.sign` respects strictly monotone zero-preserving maps. -/
lemma StrictMono.sign_comp {β F : Type*} [Zero β] [Preorder β] [DecidableLT β]
[FunLike F α β] [ZeroHomClass F α β] {f : F} (hf : StrictMono f) (a : α) :
sign (f a) = sign a := by
simp only [sign_apply, ← map_zero f, hf.lt_iff_lt]
@[simp]
theorem sign_eq_zero_iff : sign a = 0 ↔ a = 0 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ sign_zero⟩
rw [sign_apply] at h
split_ifs at h with h_1 h_2
cases h
| exact (le_of_not_lt h_1).eq_of_not_lt h_2
| Mathlib/Data/Sign.lean | 350 | 350 |
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Data.Set.Finite.Powerset
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = ENat.card α := by
rw [encard, ENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
@[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl
theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl
@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]
@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
@[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
simp [encard, ENat.card_congr (Equiv.Set.union h)]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
induction s, h using Set.Finite.induction_on with
| empty => simp
| insert hat _ ht' =>
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
@[simp]
theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by
simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)]
section Lattice
theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
@[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_encard
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_inj h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts
theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le)
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_encard inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_inj WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by
rw [encard_le_one_iff, Set.Subsingleton]
tauto
theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by
rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
theorem encard_eq_three {α : Type u_1} {s : Set α} :
encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩
· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h
obtain ⟨y, z, hne, hs⟩ := h
refine ⟨x, y, z, ?_, ?_, hne, ?_⟩
· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
· rw [Finset.coe_range, Iio_def]
rw [Finset.card_range]
end SmallSets
theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
(hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne,
encard_eq_one] at hst
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
revert hk
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
simp only [Nat.cast_succ] at *
have hne : t₀ ≠ s := by
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
simp only [top_le_iff, encard_eq_top_iff]
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq {k : ℕ∞}
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
obtain (hs | hs) := eq_or_ne s.encard ⊤
· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
have hk : k ≤ encard (t \ s) := by
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
exact WithTop.le_of_add_le_add_right hs hkt
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
section Function
variable {s : Set α} {t : Set β} {f : α → β}
theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
rw [encard, ENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e]
theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
(f '' s).encard = s.encard :=
hf.injOn.encard_image
theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by
rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
exact encard_mono (by simp)
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
obtain (h | h) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image]
apply encard_le_encard
exact f.invFunOn_image_image_subset s
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
InjOn f s := by
obtain (h' | hne) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image] at h
rw [injOn_iff_invFunOn_image_image_eq_self]
exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le
theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) :
(f ⁻¹' t).encard = t.encard := by
rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard :=
encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq])
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
s.encard ≤ t.encard := by
rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx
theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
(hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
classical
obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
· simp
· exact (encard_ne_top_iff.mpr hs h).elim
obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by
rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle'
simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
use Function.update f₀ a b
rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
· rintro x hx; split_ifs with h
· assumption
· exact (hf₀s x hx h).1
exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne])
termination_by encard s
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
∃ (f : α → β), BijOn f s t := by
obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
convert hinj.bijOn_image
rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf)
(h.symm.trans hinj.encard_image.symm).le]
end Function
section ncard
open Nat
| /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite`
term. -/
syntax "toFinite_tac" : tactic
macro_rules
| `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite)
| Mathlib/Data/Set/Card.lean | 482 | 488 |
/-
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
-/
| Mathlib/Topology/UniformSpace/Basic.lean | 160 | 161 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl, Damiano Testa,
Yuyang Zhao
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Defs
import Mathlib.Data.Ordering.Basic
import Mathlib.Order.MinMax
import Mathlib.Tactic.Contrapose
import Mathlib.Tactic.Use
/-!
# Ordered monoids
This file develops the basics of ordered monoids.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
## Remark
Almost no monoid is actually present in this file: most assumptions have been generalized to
`Mul` or `MulOneClass`.
-/
-- TODO: If possible, uniformize lemma names, taking special care of `'`,
-- after the `ordered`-refactor is done.
open Function
section Nat
instance Nat.instMulLeftMono : MulLeftMono ℕ where
elim := fun _ _ _ h => mul_le_mul_left _ h
end Nat
section Int
instance Int.instAddLeftMono : AddLeftMono ℤ where
elim := fun _ _ _ h => Int.add_le_add_left h _
end Int
variable {α β : Type*}
section Mul
variable [Mul α]
section LE
variable [LE α]
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
@[to_additive (attr := gcongr) add_le_add_left]
theorem mul_le_mul_left' [MulLeftMono α] {b c : α} (bc : b ≤ c) (a : α) :
a * b ≤ a * c :=
CovariantClass.elim _ bc
@[to_additive le_of_add_le_add_left]
theorem le_of_mul_le_mul_left' [MulLeftReflectLE α] {a b c : α}
(bc : a * b ≤ a * c) :
b ≤ c :=
ContravariantClass.elim _ bc
/- The prime on this lemma is present only on the multiplicative version. The unprimed version
is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/
@[to_additive (attr := gcongr) add_le_add_right]
theorem mul_le_mul_right' [i : MulRightMono α] {b c : α} (bc : b ≤ c)
(a : α) :
b * a ≤ c * a :=
i.elim a bc
@[to_additive le_of_add_le_add_right]
theorem le_of_mul_le_mul_right' [i : MulRightReflectLE α] {a b c : α}
(bc : b * a ≤ c * a) :
b ≤ c :=
i.elim a bc
@[to_additive (attr := simp)]
theorem mul_le_mul_iff_left [MulLeftMono α]
[MulLeftReflectLE α] (a : α) {b c : α} :
a * b ≤ a * c ↔ b ≤ c :=
rel_iff_cov α α (· * ·) (· ≤ ·) a
@[to_additive (attr := simp)]
theorem mul_le_mul_iff_right [MulRightMono α]
[MulRightReflectLE α] (a : α) {b c : α} :
b * a ≤ c * a ↔ b ≤ c :=
rel_iff_cov α α (swap (· * ·)) (· ≤ ·) a
end LE
section LT
variable [LT α]
@[to_additive (attr := simp)]
theorem mul_lt_mul_iff_left [MulLeftStrictMono α]
[MulLeftReflectLT α] (a : α) {b c : α} :
a * b < a * c ↔ b < c :=
rel_iff_cov α α (· * ·) (· < ·) a
@[to_additive (attr := simp)]
theorem mul_lt_mul_iff_right [MulRightStrictMono α]
[MulRightReflectLT α] (a : α) {b c : α} :
b * a < c * a ↔ b < c :=
rel_iff_cov α α (swap (· * ·)) (· < ·) a
@[to_additive (attr := gcongr) add_lt_add_left]
theorem mul_lt_mul_left' [MulLeftStrictMono α] {b c : α} (bc : b < c) (a : α) :
a * b < a * c :=
CovariantClass.elim _ bc
@[to_additive lt_of_add_lt_add_left]
theorem lt_of_mul_lt_mul_left' [MulLeftReflectLT α] {a b c : α}
(bc : a * b < a * c) :
b < c :=
ContravariantClass.elim _ bc
@[to_additive (attr := gcongr) add_lt_add_right]
theorem mul_lt_mul_right' [i : MulRightStrictMono α] {b c : α} (bc : b < c)
(a : α) :
b * a < c * a :=
i.elim a bc
@[to_additive lt_of_add_lt_add_right]
theorem lt_of_mul_lt_mul_right' [i : MulRightReflectLT α] {a b c : α}
(bc : b * a < c * a) :
b < c :=
i.elim a bc
end LT
section Preorder
variable [Preorder α]
@[to_additive]
lemma mul_left_mono [MulLeftMono α] {a : α} : Monotone (a * ·) :=
fun _ _ h ↦ mul_le_mul_left' h _
@[to_additive]
lemma mul_right_mono [MulRightMono α] {a : α} : Monotone (· * a) :=
fun _ _ h ↦ mul_le_mul_right' h _
@[to_additive]
lemma mul_left_strictMono [MulLeftStrictMono α] {a : α} : StrictMono (a * ·) :=
fun _ _ h ↦ mul_lt_mul_left' h _
@[to_additive]
lemma mul_right_strictMono [MulRightStrictMono α] {a : α} : StrictMono (· * a) :=
fun _ _ h ↦ mul_lt_mul_right' h _
@[to_additive (attr := gcongr)]
theorem mul_lt_mul_of_lt_of_lt [MulLeftStrictMono α]
[MulRightStrictMono α]
{a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d :=
calc
a * c < a * d := mul_lt_mul_left' h₂ a
_ < b * d := mul_lt_mul_right' h₁ d
alias add_lt_add := add_lt_add_of_lt_of_lt
@[to_additive]
theorem mul_lt_mul_of_le_of_lt [MulLeftStrictMono α]
[MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c < d) :
a * c < b * d :=
(mul_le_mul_right' h₁ _).trans_lt (mul_lt_mul_left' h₂ b)
@[to_additive]
theorem mul_lt_mul_of_lt_of_le [MulLeftMono α]
[MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c ≤ d) :
a * c < b * d :=
(mul_le_mul_left' h₂ _).trans_lt (mul_lt_mul_right' h₁ d)
/-- Only assumes left strict covariance. -/
@[to_additive "Only assumes left strict covariance"]
theorem Left.mul_lt_mul [MulLeftStrictMono α]
[MulRightMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) :
a * c < b * d :=
mul_lt_mul_of_le_of_lt h₁.le h₂
/-- Only assumes right strict covariance. -/
@[to_additive "Only assumes right strict covariance"]
theorem Right.mul_lt_mul [MulLeftMono α]
[MulRightStrictMono α] {a b c d : α}
(h₁ : a < b) (h₂ : c < d) :
a * c < b * d :=
mul_lt_mul_of_lt_of_le h₁ h₂.le
@[to_additive (attr := gcongr) add_le_add]
theorem mul_le_mul' [MulLeftMono α] [MulRightMono α]
{a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) :
a * c ≤ b * d :=
(mul_le_mul_left' h₂ _).trans (mul_le_mul_right' h₁ d)
@[to_additive]
theorem mul_le_mul_three [MulLeftMono α]
[MulRightMono α] {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e)
(h₃ : c ≤ f) :
a * b * c ≤ d * e * f :=
mul_le_mul' (mul_le_mul' h₁ h₂) h₃
@[to_additive]
theorem mul_lt_of_mul_lt_left [MulLeftMono α] {a b c d : α} (h : a * b < c)
(hle : d ≤ b) :
a * d < c :=
(mul_le_mul_left' hle a).trans_lt h
@[to_additive]
theorem mul_le_of_mul_le_left [MulLeftMono α] {a b c d : α} (h : a * b ≤ c)
(hle : d ≤ b) :
a * d ≤ c :=
@act_rel_of_rel_of_act_rel _ _ _ (· ≤ ·) _ _ a _ _ _ hle h
@[to_additive]
theorem mul_lt_of_mul_lt_right [MulRightMono α] {a b c d : α}
(h : a * b < c) (hle : d ≤ a) :
d * b < c :=
(mul_le_mul_right' hle b).trans_lt h
@[to_additive]
theorem mul_le_of_mul_le_right [MulRightMono α] {a b c d : α}
(h : a * b ≤ c) (hle : d ≤ a) :
d * b ≤ c :=
(mul_le_mul_right' hle b).trans h
@[to_additive]
theorem lt_mul_of_lt_mul_left [MulLeftMono α] {a b c d : α} (h : a < b * c)
(hle : c ≤ d) :
a < b * d :=
h.trans_le (mul_le_mul_left' hle b)
@[to_additive]
theorem le_mul_of_le_mul_left [MulLeftMono α] {a b c d : α} (h : a ≤ b * c)
(hle : c ≤ d) :
a ≤ b * d :=
@rel_act_of_rel_of_rel_act _ _ _ (· ≤ ·) _ _ b _ _ _ hle h
@[to_additive]
theorem lt_mul_of_lt_mul_right [MulRightMono α] {a b c d : α}
(h : a < b * c) (hle : b ≤ d) :
a < d * c :=
h.trans_le (mul_le_mul_right' hle c)
@[to_additive]
theorem le_mul_of_le_mul_right [MulRightMono α] {a b c d : α}
(h : a ≤ b * c) (hle : b ≤ d) :
a ≤ d * c :=
h.trans (mul_le_mul_right' hle c)
end Preorder
section PartialOrder
variable [PartialOrder α]
@[to_additive]
theorem mul_left_cancel'' [MulLeftReflectLE α] {a b c : α} (h : a * b = a * c) :
b = c :=
(le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge)
@[to_additive]
theorem mul_right_cancel'' [MulRightReflectLE α] {a b c : α}
(h : a * b = c * b) :
a = c :=
(le_of_mul_le_mul_right' h.le).antisymm (le_of_mul_le_mul_right' h.ge)
@[to_additive] lemma mul_le_mul_iff_of_ge [MulLeftStrictMono α]
[MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) :
a₂ * b₂ ≤ a₁ * b₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
haveI := mulLeftMono_of_mulLeftStrictMono α
haveI := mulRightMono_of_mulRightStrictMono α
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩
exacts [mul_lt_mul_of_lt_of_le ha hb, mul_lt_mul_of_le_of_lt ha hb]
@[to_additive] theorem mul_eq_mul_iff_eq_and_eq [MulLeftStrictMono α]
[MulRightStrictMono α] {a b c d : α} (hac : a ≤ c) (hbd : b ≤ d) :
a * b = c * d ↔ a = c ∧ b = d := by
haveI := mulLeftMono_of_mulLeftStrictMono α
haveI := mulRightMono_of_mulRightStrictMono α
rw [le_antisymm_iff, eq_true (mul_le_mul' hac hbd), true_and, mul_le_mul_iff_of_ge hac hbd]
@[to_additive]
lemma mul_left_inj_of_comparable [MulRightStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) :
c * a = b * a ↔ c = b := by
refine ⟨fun h' => ?_, (· ▸ rfl)⟩
contrapose h'
obtain h | h := h
· exact mul_lt_mul_right' (h.lt_of_ne' h') a |>.ne'
· exact mul_lt_mul_right' (h.lt_of_ne h') a |>.ne
@[to_additive]
lemma mul_right_inj_of_comparable [MulLeftStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) :
a * c = a * b ↔ c = b := by
refine ⟨fun h' => ?_, (· ▸ rfl)⟩
contrapose h'
obtain h | h := h
· exact mul_lt_mul_left' (h.lt_of_ne' h') a |>.ne'
· exact mul_lt_mul_left' (h.lt_of_ne h') a |>.ne
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b c d : α}
@[to_additive]
theorem trichotomy_of_mul_eq_mul
[MulLeftStrictMono α] [MulRightStrictMono α]
(h : a * b = c * d) : (a = c ∧ b = d) ∨ a < c ∨ b < d := by
obtain hac | rfl | hca := lt_trichotomy a c
· right; left; exact hac
· left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b)|>.1 h
· obtain hbd | rfl | hdb := lt_trichotomy b d
· right; right; exact hbd
· exact False.elim <| ne_of_lt (mul_lt_mul_right' hca b) h.symm
· exact False.elim <| ne_of_lt (mul_lt_mul_of_lt_of_lt hca hdb) h.symm
@[to_additive]
lemma mul_max [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :
a * max b c = max (a * b) (a * c) := mul_left_mono.map_max
@[to_additive]
lemma max_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
max a b * c = max (a * c) (b * c) := mul_right_mono.map_max
@[to_additive]
lemma mul_min [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) :
a * min b c = min (a * b) (a * c) := mul_left_mono.map_min
@[to_additive]
lemma min_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) :
min a b * c = min (a * c) (b * c) := mul_right_mono.map_min
@[to_additive] lemma min_lt_max_of_mul_lt_mul
[MulLeftMono α] [MulRightMono α]
(h : a * b < c * d) : min a b < max c d := by
simp_rw [min_lt_iff, lt_max_iff]; contrapose! h; exact mul_le_mul' h.1.1 h.2.2
@[to_additive] lemma Left.min_le_max_of_mul_le_mul
[MulLeftStrictMono α] [MulRightMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d := by
simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_le_of_lt h.1.1.le h.2.2
@[to_additive] lemma Right.min_le_max_of_mul_le_mul
[MulLeftMono α] [MulRightStrictMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d := by
simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_lt_of_le h.1.1 h.2.2.le
@[to_additive] lemma min_le_max_of_mul_le_mul
[MulLeftStrictMono α] [MulRightStrictMono α]
(h : a * b ≤ c * d) : min a b ≤ max c d :=
haveI := mulRightMono_of_mulRightStrictMono α
Left.min_le_max_of_mul_le_mul h
/-- Not an instance, to avoid loops with `IsLeftCancelMul.mulLeftStrictMono_of_mulLeftMono`. -/
@[to_additive]
theorem MulLeftStrictMono.toIsLeftCancelMul [MulLeftStrictMono α] : IsLeftCancelMul α where
mul_left_cancel _ _ _ h := mul_left_strictMono.injective h
/-- Not an instance, to avoid loops with `IsRightCancelMul.mulRightStrictMono_of_mulRightMono`. -/
@[to_additive]
theorem MulRightStrictMono.toIsRightCancelMul [MulRightStrictMono α] : IsRightCancelMul α where
mul_right_cancel _ _ _ h := mul_right_strictMono.injective h
end LinearOrder
section LinearOrder
variable [LinearOrder α] [MulLeftMono α] [MulRightMono α] {a b c d : α}
@[to_additive max_add_add_le_max_add_max]
theorem max_mul_mul_le_max_mul_max' : max (a * b) (c * d) ≤ max a c * max b d :=
max_le (mul_le_mul' (le_max_left _ _) <| le_max_left _ _) <|
mul_le_mul' (le_max_right _ _) <| le_max_right _ _
@[to_additive min_add_min_le_min_add_add]
theorem min_mul_min_le_min_mul_mul' : min a c * min b d ≤ min (a * b) (c * d) :=
le_min (mul_le_mul' (min_le_left _ _) <| min_le_left _ _) <|
mul_le_mul' (min_le_right _ _) <| min_le_right _ _
end LinearOrder
end Mul
-- using one
section MulOneClass
variable [MulOneClass α]
section LE
variable [LE α]
@[to_additive le_add_of_nonneg_right]
theorem le_mul_of_one_le_right' [MulLeftMono α] {a b : α} (h : 1 ≤ b) :
a ≤ a * b :=
calc
a = a * 1 := (mul_one a).symm
_ ≤ a * b := mul_le_mul_left' h a
@[to_additive add_le_of_nonpos_right]
theorem mul_le_of_le_one_right' [MulLeftMono α] {a b : α} (h : b ≤ 1) :
a * b ≤ a :=
calc
a * b ≤ a * 1 := mul_le_mul_left' h a
_ = a := mul_one a
@[to_additive le_add_of_nonneg_left]
theorem le_mul_of_one_le_left' [MulRightMono α] {a b : α} (h : 1 ≤ b) :
a ≤ b * a :=
calc
a = 1 * a := (one_mul a).symm
_ ≤ b * a := mul_le_mul_right' h a
@[to_additive add_le_of_nonpos_left]
theorem mul_le_of_le_one_left' [MulRightMono α] {a b : α} (h : b ≤ 1) :
b * a ≤ a :=
calc
| b * a ≤ 1 * a := mul_le_mul_right' h a
_ = a := one_mul a
| Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean | 428 | 430 |
/-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang, Yury Kudryashov
-/
import Mathlib.Data.Fintype.Option
import Mathlib.Topology.Homeomorph.Lemmas
import Mathlib.Topology.Sets.Opens
/-!
# The OnePoint Compactification
We construct the OnePoint compactification (the one-point compactification) of an arbitrary
topological space `X` and prove some properties inherited from `X`.
## Main definitions
* `OnePoint`: the OnePoint compactification, we use coercion for the canonical embedding
`X → OnePoint X`; when `X` is already compact, the compactification adds an isolated point
to the space.
* `OnePoint.infty`: the extra point
## Main results
* The topological structure of `OnePoint X`
* The connectedness of `OnePoint X` for a noncompact, preconnected `X`
* `OnePoint X` is `T₀` for a T₀ space `X`
* `OnePoint X` is `T₁` for a T₁ space `X`
* `OnePoint X` is normal if `X` is a locally compact Hausdorff space
## Tags
one-point compactification, Alexandroff compactification, compactness
-/
open Set Filter Topology
/-!
### Definition and basic properties
In this section we define `OnePoint X` to be the disjoint union of `X` and `∞`, implemented as
`Option X`. Then we restate some lemmas about `Option X` for `OnePoint X`.
-/
variable {X Y : Type*}
/-- The OnePoint extension of an arbitrary topological space `X` -/
def OnePoint (X : Type*) :=
Option X
/-- The repr uses the notation from the `OnePoint` locale. -/
instance [Repr X] : Repr (OnePoint X) :=
⟨fun o _ =>
match o with
| none => "∞"
| some a => "↑" ++ repr a⟩
namespace OnePoint
/-- The point at infinity -/
@[match_pattern] def infty : OnePoint X := none
@[inherit_doc]
scoped notation "∞" => OnePoint.infty
/-- Coercion from `X` to `OnePoint X`. -/
@[coe, match_pattern] def some : X → OnePoint X := Option.some
@[simp]
lemma some_eq_iff (x₁ x₂ : X) : (some x₁ = some x₂) ↔ (x₁ = x₂) := by
rw [iff_eq_eq]
exact Option.some.injEq x₁ x₂
instance : CoeTC X (OnePoint X) := ⟨some⟩
instance : Inhabited (OnePoint X) := ⟨∞⟩
protected lemma «forall» {p : OnePoint X → Prop} :
(∀ (x : OnePoint X), p x) ↔ p ∞ ∧ ∀ (x : X), p x :=
Option.forall
protected lemma «exists» {p : OnePoint X → Prop} :
(∃ x, p x) ↔ p ∞ ∨ ∃ (x : X), p x :=
Option.exists
instance [Fintype X] : Fintype (OnePoint X) :=
inferInstanceAs (Fintype (Option X))
instance infinite [Infinite X] : Infinite (OnePoint X) :=
inferInstanceAs (Infinite (Option X))
theorem coe_injective : Function.Injective ((↑) : X → OnePoint X) :=
Option.some_injective X
@[norm_cast]
theorem coe_eq_coe {x y : X} : (x : OnePoint X) = y ↔ x = y :=
coe_injective.eq_iff
@[simp]
theorem coe_ne_infty (x : X) : (x : OnePoint X) ≠ ∞ :=
nofun
@[simp]
theorem infty_ne_coe (x : X) : ∞ ≠ (x : OnePoint X) :=
nofun
/-- Recursor for `OnePoint` using the preferred forms `∞` and `↑x`. -/
@[elab_as_elim, induction_eliminator, cases_eliminator]
protected def rec {C : OnePoint X → Sort*} (infty : C ∞) (coe : ∀ x : X, C x) :
∀ z : OnePoint X, C z
| ∞ => infty
| (x : X) => coe x
/-- An elimination principle for `OnePoint`. -/
@[inline] protected def elim : OnePoint X → Y → (X → Y) → Y := Option.elim
@[simp] theorem elim_infty (y : Y) (f : X → Y) : ∞.elim y f = y := rfl
@[simp] theorem elim_some (y : Y) (f : X → Y) (x : X) : (some x).elim y f = f x := rfl
theorem isCompl_range_coe_infty : IsCompl (range ((↑) : X → OnePoint X)) {∞} :=
isCompl_range_some_none X
theorem range_coe_union_infty : range ((↑) : X → OnePoint X) ∪ {∞} = univ :=
range_some_union_none X
@[simp]
theorem insert_infty_range_coe : insert ∞ (range (@some X)) = univ :=
insert_none_range_some _
@[simp]
theorem range_coe_inter_infty : range ((↑) : X → OnePoint X) ∩ {∞} = ∅ :=
range_some_inter_none X
@[simp]
theorem compl_range_coe : (range ((↑) : X → OnePoint X))ᶜ = {∞} :=
compl_range_some X
theorem compl_infty : ({∞}ᶜ : Set (OnePoint X)) = range ((↑) : X → OnePoint X) :=
(@isCompl_range_coe_infty X).symm.compl_eq
theorem compl_image_coe (s : Set X) : ((↑) '' s : Set (OnePoint X))ᶜ = (↑) '' sᶜ ∪ {∞} := by
rw [coe_injective.compl_image_eq, compl_range_coe]
theorem ne_infty_iff_exists {x : OnePoint X} : x ≠ ∞ ↔ ∃ y : X, (y : OnePoint X) = x := by
induction x using OnePoint.rec <;> simp
instance canLift : CanLift (OnePoint X) X (↑) fun x => x ≠ ∞ :=
WithTop.canLift
theorem not_mem_range_coe_iff {x : OnePoint X} : x ∉ range some ↔ x = ∞ := by
rw [← mem_compl_iff, compl_range_coe, mem_singleton_iff]
theorem infty_not_mem_range_coe : ∞ ∉ range ((↑) : X → OnePoint X) :=
not_mem_range_coe_iff.2 rfl
theorem infty_not_mem_image_coe {s : Set X} : ∞ ∉ ((↑) : X → OnePoint X) '' s :=
not_mem_subset (image_subset_range _ _) infty_not_mem_range_coe
@[simp]
theorem coe_preimage_infty : ((↑) : X → OnePoint X) ⁻¹' {∞} = ∅ := by
ext
simp
/-- Extend a map `f : X → Y` to a map `OnePoint X → OnePoint Y`
by sending infinity to infinity. -/
protected def map (f : X → Y) : OnePoint X → OnePoint Y :=
Option.map f
@[simp] theorem map_infty (f : X → Y) : OnePoint.map f ∞ = ∞ := rfl
@[simp] theorem map_some (f : X → Y) (x : X) : (x : OnePoint X).map f = f x := rfl
@[simp] theorem map_id : OnePoint.map (id : X → X) = id := Option.map_id
theorem map_comp {Z : Type*} (f : Y → Z) (g : X → Y) :
OnePoint.map (f ∘ g) = OnePoint.map f ∘ OnePoint.map g :=
(Option.map_comp_map _ _).symm
/-!
### Topological space structure on `OnePoint X`
We define a topological space structure on `OnePoint X` so that `s` is open if and only if
* `(↑) ⁻¹' s` is open in `X`;
* if `∞ ∈ s`, then `((↑) ⁻¹' s)ᶜ` is compact.
Then we reformulate this definition in a few different ways, and prove that
`(↑) : X → OnePoint X` is an open embedding. If `X` is not a compact space, then we also prove
that `(↑)` has dense range, so it is a dense embedding.
-/
variable [TopologicalSpace X]
instance : TopologicalSpace (OnePoint X) where
IsOpen s := (∞ ∈ s → IsCompact (((↑) : X → OnePoint X) ⁻¹' s)ᶜ) ∧
IsOpen (((↑) : X → OnePoint X) ⁻¹' s)
isOpen_univ := by simp
isOpen_inter s t := by
rintro ⟨hms, hs⟩ ⟨hmt, ht⟩
refine ⟨?_, hs.inter ht⟩
rintro ⟨hms', hmt'⟩
simpa [compl_inter] using (hms hms').union (hmt hmt')
isOpen_sUnion S ho := by
suffices IsOpen ((↑) ⁻¹' ⋃₀ S : Set X) by
refine ⟨?_, this⟩
rintro ⟨s, hsS : s ∈ S, hs : ∞ ∈ s⟩
refine IsCompact.of_isClosed_subset ((ho s hsS).1 hs) this.isClosed_compl ?_
exact compl_subset_compl.mpr (preimage_mono <| subset_sUnion_of_mem hsS)
rw [preimage_sUnion]
exact isOpen_biUnion fun s hs => (ho s hs).2
variable {s : Set (OnePoint X)}
theorem isOpen_def :
IsOpen s ↔ (∞ ∈ s → IsCompact ((↑) ⁻¹' s : Set X)ᶜ) ∧ IsOpen ((↑) ⁻¹' s : Set X) :=
Iff.rfl
theorem isOpen_iff_of_mem' (h : ∞ ∈ s) :
IsOpen s ↔ IsCompact ((↑) ⁻¹' s : Set X)ᶜ ∧ IsOpen ((↑) ⁻¹' s : Set X) := by
simp [isOpen_def, h]
theorem isOpen_iff_of_mem (h : ∞ ∈ s) :
IsOpen s ↔ IsClosed ((↑) ⁻¹' s : Set X)ᶜ ∧ IsCompact ((↑) ⁻¹' s : Set X)ᶜ := by
simp only [isOpen_iff_of_mem' h, isClosed_compl_iff, and_comm]
theorem isOpen_iff_of_not_mem (h : ∞ ∉ s) : IsOpen s ↔ IsOpen ((↑) ⁻¹' s : Set X) := by
simp [isOpen_def, h]
theorem isClosed_iff_of_mem (h : ∞ ∈ s) : IsClosed s ↔ IsClosed ((↑) ⁻¹' s : Set X) := by
have : ∞ ∉ sᶜ := fun H => H h
rw [← isOpen_compl_iff, isOpen_iff_of_not_mem this, ← isOpen_compl_iff, preimage_compl]
theorem isClosed_iff_of_not_mem (h : ∞ ∉ s) :
IsClosed s ↔ IsClosed ((↑) ⁻¹' s : Set X) ∧ IsCompact ((↑) ⁻¹' s : Set X) := by
rw [← isOpen_compl_iff, isOpen_iff_of_mem (mem_compl h), ← preimage_compl, compl_compl]
@[simp]
theorem isOpen_image_coe {s : Set X} : IsOpen ((↑) '' s : Set (OnePoint X)) ↔ IsOpen s := by
rw [isOpen_iff_of_not_mem infty_not_mem_image_coe, preimage_image_eq _ coe_injective]
theorem isOpen_compl_image_coe {s : Set X} :
IsOpen ((↑) '' s : Set (OnePoint X))ᶜ ↔ IsClosed s ∧ IsCompact s := by
rw [isOpen_iff_of_mem, ← preimage_compl, compl_compl, preimage_image_eq _ coe_injective]
exact infty_not_mem_image_coe
@[simp]
theorem isClosed_image_coe {s : Set X} :
IsClosed ((↑) '' s : Set (OnePoint X)) ↔ IsClosed s ∧ IsCompact s := by
rw [← isOpen_compl_iff, isOpen_compl_image_coe]
/-- An open set in `OnePoint X` constructed from a closed compact set in `X` -/
def opensOfCompl (s : Set X) (h₁ : IsClosed s) (h₂ : IsCompact s) :
TopologicalSpace.Opens (OnePoint X) :=
⟨((↑) '' s)ᶜ, isOpen_compl_image_coe.2 ⟨h₁, h₂⟩⟩
theorem infty_mem_opensOfCompl {s : Set X} (h₁ : IsClosed s) (h₂ : IsCompact s) :
∞ ∈ opensOfCompl s h₁ h₂ :=
mem_compl infty_not_mem_image_coe
@[continuity]
theorem continuous_coe : Continuous ((↑) : X → OnePoint X) :=
continuous_def.mpr fun _s hs => hs.right
theorem isOpenMap_coe : IsOpenMap ((↑) : X → OnePoint X) := fun _ => isOpen_image_coe.2
theorem isOpenEmbedding_coe : IsOpenEmbedding ((↑) : X → OnePoint X) :=
.of_continuous_injective_isOpenMap continuous_coe coe_injective isOpenMap_coe
theorem isOpen_range_coe : IsOpen (range ((↑) : X → OnePoint X)) :=
isOpenEmbedding_coe.isOpen_range
theorem isClosed_infty : IsClosed ({∞} : Set (OnePoint X)) := by
rw [← compl_range_coe, isClosed_compl_iff]
exact isOpen_range_coe
theorem nhds_coe_eq (x : X) : 𝓝 ↑x = map ((↑) : X → OnePoint X) (𝓝 x) :=
(isOpenEmbedding_coe.map_nhds_eq x).symm
theorem nhdsWithin_coe_image (s : Set X) (x : X) :
𝓝[(↑) '' s] (x : OnePoint X) = map (↑) (𝓝[s] x) :=
(isOpenEmbedding_coe.isEmbedding.map_nhdsWithin_eq _ _).symm
theorem nhdsWithin_coe (s : Set (OnePoint X)) (x : X) : 𝓝[s] ↑x = map (↑) (𝓝[(↑) ⁻¹' s] x) :=
(isOpenEmbedding_coe.map_nhdsWithin_preimage_eq _ _).symm
theorem comap_coe_nhds (x : X) : comap ((↑) : X → OnePoint X) (𝓝 x) = 𝓝 x :=
(isOpenEmbedding_coe.isInducing.nhds_eq_comap x).symm
/-- If `x` is not an isolated point of `X`, then `x : OnePoint X` is not an isolated point
of `OnePoint X`. -/
instance nhdsNE_coe_neBot (x : X) [h : NeBot (𝓝[≠] x)] : NeBot (𝓝[≠] (x : OnePoint X)) := by
simpa [nhdsWithin_coe, preimage, coe_eq_coe] using h.map some
@[deprecated (since := "2025-03-02")]
alias nhdsWithin_compl_coe_neBot := nhdsNE_coe_neBot
theorem nhdsNE_infty_eq : 𝓝[≠] (∞ : OnePoint X) = map (↑) (coclosedCompact X) := by
refine (nhdsWithin_basis_open ∞ _).ext (hasBasis_coclosedCompact.map _) ?_ ?_
· rintro s ⟨hs, hso⟩
refine ⟨_, (isOpen_iff_of_mem hs).mp hso, ?_⟩
simp [Subset.rfl]
· rintro s ⟨h₁, h₂⟩
refine ⟨_, ⟨mem_compl infty_not_mem_image_coe, isOpen_compl_image_coe.2 ⟨h₁, h₂⟩⟩, ?_⟩
simp [compl_image_coe, ← diff_eq, subset_preimage_image]
@[deprecated (since := "2025-03-02")]
alias nhdsWithin_compl_infty_eq := nhdsNE_infty_eq
/-- If `X` is a non-compact space, then `∞` is not an isolated point of `OnePoint X`. -/
instance nhdsNE_infty_neBot [NoncompactSpace X] : NeBot (𝓝[≠] (∞ : OnePoint X)) := by
rw [nhdsNE_infty_eq]
infer_instance
@[deprecated (since := "2025-03-02")]
alias nhdsWithin_compl_infty_neBot := nhdsNE_infty_neBot
instance (priority := 900) nhdsNE_neBot [∀ x : X, NeBot (𝓝[≠] x)] [NoncompactSpace X]
(x : OnePoint X) : NeBot (𝓝[≠] x) :=
OnePoint.rec OnePoint.nhdsNE_infty_neBot (fun y => OnePoint.nhdsNE_coe_neBot y) x
@[deprecated (since := "2025-03-02")]
alias nhdsWithin_compl_neBot := nhdsNE_neBot
theorem nhds_infty_eq : 𝓝 (∞ : OnePoint X) = map (↑) (coclosedCompact X) ⊔ pure ∞ := by
rw [← nhdsNE_infty_eq, nhdsNE_sup_pure]
theorem tendsto_coe_infty : Tendsto (↑) (coclosedCompact X) (𝓝 (∞ : OnePoint X)) := by
rw [nhds_infty_eq]
exact Filter.Tendsto.mono_right tendsto_map le_sup_left
theorem hasBasis_nhds_infty :
(𝓝 (∞ : OnePoint X)).HasBasis (fun s : Set X => IsClosed s ∧ IsCompact s) fun s =>
(↑) '' sᶜ ∪ {∞} := by
rw [nhds_infty_eq]
exact (hasBasis_coclosedCompact.map _).sup_pure _
@[simp]
theorem comap_coe_nhds_infty : comap ((↑) : X → OnePoint X) (𝓝 ∞) = coclosedCompact X := by
simp [nhds_infty_eq, comap_sup, comap_map coe_injective]
theorem le_nhds_infty {f : Filter (OnePoint X)} :
f ≤ 𝓝 ∞ ↔ ∀ s : Set X, IsClosed s → IsCompact s → (↑) '' sᶜ ∪ {∞} ∈ f := by
simp only [hasBasis_nhds_infty.ge_iff, and_imp]
theorem ultrafilter_le_nhds_infty {f : Ultrafilter (OnePoint X)} :
(f : Filter (OnePoint X)) ≤ 𝓝 ∞ ↔ ∀ s : Set X, IsClosed s → IsCompact s → (↑) '' s ∉ f := by
simp only [le_nhds_infty, ← compl_image_coe, Ultrafilter.mem_coe,
Ultrafilter.compl_mem_iff_not_mem]
theorem tendsto_nhds_infty' {α : Type*} {f : OnePoint X → α} {l : Filter α} :
Tendsto f (𝓝 ∞) l ↔ Tendsto f (pure ∞) l ∧ Tendsto (f ∘ (↑)) (coclosedCompact X) l := by
simp [nhds_infty_eq, and_comm]
theorem tendsto_nhds_infty {α : Type*} {f : OnePoint X → α} {l : Filter α} :
Tendsto f (𝓝 ∞) l ↔
∀ s ∈ l, f ∞ ∈ s ∧ ∃ t : Set X, IsClosed t ∧ IsCompact t ∧ MapsTo (f ∘ (↑)) tᶜ s :=
tendsto_nhds_infty'.trans <| by
simp only [tendsto_pure_left, hasBasis_coclosedCompact.tendsto_left_iff, forall_and,
and_assoc, exists_prop]
theorem continuousAt_infty' {Y : Type*} [TopologicalSpace Y] {f : OnePoint X → Y} :
ContinuousAt f ∞ ↔ Tendsto (f ∘ (↑)) (coclosedCompact X) (𝓝 (f ∞)) :=
tendsto_nhds_infty'.trans <| and_iff_right (tendsto_pure_nhds _ _)
theorem continuousAt_infty {Y : Type*} [TopologicalSpace Y] {f : OnePoint X → Y} :
ContinuousAt f ∞ ↔
∀ s ∈ 𝓝 (f ∞), ∃ t : Set X, IsClosed t ∧ IsCompact t ∧ MapsTo (f ∘ (↑)) tᶜ s :=
continuousAt_infty'.trans <| by simp only [hasBasis_coclosedCompact.tendsto_left_iff, and_assoc]
theorem continuousAt_coe {Y : Type*} [TopologicalSpace Y] {f : OnePoint X → Y} {x : X} :
ContinuousAt f x ↔ ContinuousAt (f ∘ (↑)) x := by
rw [ContinuousAt, nhds_coe_eq, tendsto_map'_iff, ContinuousAt]; rfl
lemma continuous_iff {Y : Type*} [TopologicalSpace Y] (f : OnePoint X → Y) : Continuous f ↔
Tendsto (fun x : X ↦ f x) (coclosedCompact X) (𝓝 (f ∞)) ∧ Continuous (fun x : X ↦ f x) := by
simp only [continuous_iff_continuousAt, OnePoint.forall, continuousAt_coe, continuousAt_infty',
Function.comp_def]
/--
A constructor for continuous maps out of a one point compactification, given a continuous map from
the underlying space and a limit value at infinity.
-/
def continuousMapMk {Y : Type*} [TopologicalSpace Y] (f : C(X, Y)) (y : Y)
(h : Tendsto f (coclosedCompact X) (𝓝 y)) : C(OnePoint X, Y) where
toFun x := x.elim y f
continuous_toFun := by
rw [continuous_iff]
refine ⟨h, f.continuous⟩
lemma continuous_iff_from_discrete {Y : Type*} [TopologicalSpace Y]
[DiscreteTopology X] (f : OnePoint X → Y) :
Continuous f ↔ Tendsto (fun x : X ↦ f x) cofinite (𝓝 (f ∞)) := by
simp [continuous_iff, cocompact_eq_cofinite, continuous_of_discreteTopology]
/--
A constructor for continuous maps out of a one point compactification of a discrete space, given a
map from the underlying space and a limit value at infinity.
-/
def continuousMapMkDiscrete {Y : Type*} [TopologicalSpace Y]
[DiscreteTopology X] (f : X → Y) (y : Y) (h : Tendsto f cofinite (𝓝 y)) :
C(OnePoint X, Y) :=
continuousMapMk ⟨f, continuous_of_discreteTopology⟩ y (by simpa [cocompact_eq_cofinite])
variable (X) in
/--
Continuous maps out of the one point compactification of an infinite discrete space to a Hausdorff
space correspond bijectively to "convergent" maps out of the discrete space.
-/
noncomputable def continuousMapDiscreteEquiv (Y : Type*) [DiscreteTopology X] [TopologicalSpace Y]
[T2Space Y] [Infinite X] :
C(OnePoint X, Y) ≃ { f : X → Y // ∃ L, Tendsto (fun x : X ↦ f x) cofinite (𝓝 L) } where
toFun f := ⟨(f ·), ⟨f ∞, continuous_iff_from_discrete _ |>.mp (map_continuous f)⟩⟩
invFun f :=
{ toFun := fun x => match x with
| ∞ => Classical.choose f.2
| some x => f.1 x
continuous_toFun := continuous_iff_from_discrete _ |>.mpr <| Classical.choose_spec f.2 }
left_inv f := by
ext x
refine OnePoint.rec ?_ ?_ x
· refine tendsto_nhds_unique ?_ (continuous_iff_from_discrete _ |>.mp <| map_continuous f)
let f' : { f : X → Y // ∃ L, Tendsto (fun x : X ↦ f x) cofinite (𝓝 L) } :=
⟨fun x ↦ f x, ⟨f ∞, continuous_iff_from_discrete f |>.mp <| map_continuous f⟩⟩
exact Classical.choose_spec f'.property
· simp
right_inv _ := rfl
lemma continuous_iff_from_nat {Y : Type*} [TopologicalSpace Y] (f : OnePoint ℕ → Y) :
Continuous f ↔ Tendsto (fun x : ℕ ↦ f x) atTop (𝓝 (f ∞)) := by
rw [continuous_iff_from_discrete, Nat.cofinite_eq_atTop]
/--
A constructor for continuous maps out of the one point compactification of `ℕ`, given a
sequence and a limit value at infinity.
-/
def continuousMapMkNat {Y : Type*} [TopologicalSpace Y]
(f : ℕ → Y) (y : Y) (h : Tendsto f atTop (𝓝 y)) :
C(OnePoint ℕ, Y) :=
continuousMapMkDiscrete f y (by rwa [Nat.cofinite_eq_atTop])
/--
Continuous maps out of the one point compactification of `ℕ` to a Hausdorff space `Y` correspond
bijectively to convergent sequences in `Y`.
-/
noncomputable def continuousMapNatEquiv (Y : Type*) [TopologicalSpace Y] [T2Space Y] :
C(OnePoint ℕ, Y) ≃ { f : ℕ → Y // ∃ L, Tendsto (f ·) atTop (𝓝 L) } := by
refine (continuousMapDiscreteEquiv ℕ Y).trans {
toFun := fun ⟨f, hf⟩ ↦ ⟨f, by rwa [← Nat.cofinite_eq_atTop]⟩
invFun := fun ⟨f, hf⟩ ↦ ⟨f, by rwa [Nat.cofinite_eq_atTop]⟩
left_inv := fun _ ↦ rfl
right_inv := fun _ ↦ rfl }
/-- If `X` is not a compact space, then the natural embedding `X → OnePoint X` has dense range.
-/
theorem denseRange_coe [NoncompactSpace X] : DenseRange ((↑) : X → OnePoint X) := by
rw [DenseRange, ← compl_infty]
exact dense_compl_singleton _
theorem isDenseEmbedding_coe [NoncompactSpace X] : IsDenseEmbedding ((↑) : X → OnePoint X) :=
{ isOpenEmbedding_coe with dense := denseRange_coe }
@[simp, norm_cast]
theorem specializes_coe {x y : X} : (x : OnePoint X) ⤳ y ↔ x ⤳ y :=
isOpenEmbedding_coe.isInducing.specializes_iff
@[simp, norm_cast]
theorem inseparable_coe {x y : X} : Inseparable (x : OnePoint X) y ↔ Inseparable x y :=
isOpenEmbedding_coe.isInducing.inseparable_iff
theorem not_specializes_infty_coe {x : X} : ¬Specializes ∞ (x : OnePoint X) :=
isClosed_infty.not_specializes rfl (coe_ne_infty x)
theorem not_inseparable_infty_coe {x : X} : ¬Inseparable ∞ (x : OnePoint X) := fun h =>
not_specializes_infty_coe h.specializes
|
theorem not_inseparable_coe_infty {x : X} : ¬Inseparable (x : OnePoint X) ∞ := fun h =>
not_specializes_infty_coe h.specializes'
| Mathlib/Topology/Compactification/OnePoint.lean | 477 | 479 |
/-
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, Jeremy Avigad
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Notation.Pi
import Mathlib.Data.Set.Lattice
import Mathlib.Order.Filter.Defs
/-!
# Theory of filters on sets
A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`,
is upwards-closed, and is stable under intersection. They are mostly used to
abstract two related kinds of ideas:
* *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions
at a point or at infinity, etc...
* *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough
a point `x`, or for close enough pairs of points, or things happening almost everywhere in the
sense of measure theory. Dually, filters can also express the idea of *things happening often*:
for arbitrarily large `n`, or at a point in any neighborhood of given a point etc...
## Main definitions
In this file, we endow `Filter α` it with a complete lattice structure.
This structure is lifted from the lattice structure on `Set (Set X)` using the Galois
insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to
the smallest filter containing it in the other direction.
We also prove `Filter` is a monadic functor, with a push-forward operation
`Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the
order on filters.
The examples of filters appearing in the description of the two motivating ideas are:
* `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N`
* `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic)
* `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces
defined in `Mathlib/Topology/UniformSpace/Basic.lean`)
* `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ`
(defined in `Mathlib/MeasureTheory/OuterMeasure/AE`)
The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is
`Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come
rather late in this file in order to immediately relate them to the lattice structure).
## Notations
* `∀ᶠ x in f, p x` : `f.Eventually p`;
* `∃ᶠ x in f, p x` : `f.Frequently p`;
* `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`;
* `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`;
* `𝓟 s` : `Filter.Principal s`, localized in `Filter`.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which
we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element
`⊥` for its lattice structure, at the cost of including the assumption
`[NeBot f]` in a number of lemmas and definitions.
-/
assert_not_exists OrderedSemiring Fintype
open Function Set Order
open scoped symmDiff
universe u v w x y
namespace Filter
variable {α : Type u} {f g : Filter α} {s t : Set α}
instance inhabitedMem : Inhabited { s : Set α // s ∈ f } :=
⟨⟨univ, f.univ_sets⟩⟩
theorem filter_eq_iff : f = g ↔ f.sets = g.sets :=
⟨congr_arg _, filter_eq⟩
@[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl
@[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl
/-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g.,
`Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/
protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g :=
Filter.ext <| compl_surjective.forall.2 h
instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where
trans h₁ h₂ := mem_of_superset h₂ h₁
instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where
trans h₁ h₂ := mem_of_superset h₁ h₂
@[simp]
theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f :=
⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩,
and_imp.2 inter_mem⟩
theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f :=
inter_mem hs ht
theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f :=
⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs =>
mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩
lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem
/-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/
theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) :
(⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by
apply Subsingleton.induction_on hf <;> simp
/-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/
theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] :
(⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by
rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range]
theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f :=
⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩
theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h =>
mem_of_superset h hst
theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P)
(hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by
constructor
· rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩
exact
⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩
· rintro ⟨u, huf, hPu, hQu⟩
exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩
theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} :
(∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b :=
Set.forall_in_swap
end Filter
namespace Filter
variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x}
theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl
section Lattice
variable {f g : Filter α} {s t : Set α}
protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop]
/-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/
inductive GenerateSets (g : Set (Set α)) : Set α → Prop
| basic {s : Set α} : s ∈ g → GenerateSets g s
| univ : GenerateSets g univ
| superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t
| inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t)
/-- `generate g` is the largest filter containing the sets `g`. -/
def generate (g : Set (Set α)) : Filter α where
sets := {s | GenerateSets g s}
univ_sets := GenerateSets.univ
sets_of_superset := GenerateSets.superset
inter_sets := GenerateSets.inter
lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) :
U ∈ generate s := GenerateSets.basic h
theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets :=
Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu =>
hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy =>
inter_mem hx hy
@[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s :=
le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <|
le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl
/-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly
`s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/
protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where
sets := s
univ_sets := hs ▸ univ_mem
sets_of_superset := hs ▸ mem_of_superset
inter_sets := hs ▸ inter_mem
theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} :
Filter.mkOfClosure s hs = generate s :=
Filter.ext fun u =>
show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl
/-- Galois insertion from sets of sets into filters. -/
def giGenerate (α : Type*) :
@GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where
gc _ _ := le_generate_iff
le_l_u _ _ h := GenerateSets.basic h
choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ :=
Iff.rfl
theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g :=
⟨s, h, univ, univ_mem, (inter_univ s).symm⟩
theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g :=
⟨univ, univ_mem, s, h, (univ_inter s).symm⟩
theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) :
s ∩ t ∈ f ⊓ g :=
⟨s, hs, t, ht, rfl⟩
theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g)
(h : s ∩ t ⊆ u) : u ∈ f ⊓ g :=
mem_of_superset (inter_mem_inf hs ht) h
theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} :
s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s :=
⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ =>
mem_inf_of_inter h₁ h₂ sub⟩
section CompleteLattice
/-- Complete lattice structure on `Filter α`. -/
instance instCompleteLatticeFilter : CompleteLattice (Filter α) where
inf a b := min a b
sup a b := max a b
le_sup_left _ _ _ h := h.1
le_sup_right _ _ _ h := h.2
sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩
inf_le_left _ _ _ := mem_inf_of_left
inf_le_right _ _ _ := mem_inf_of_right
le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb)
le_sSup _ _ h₁ _ h₂ := h₂ h₁
sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂
sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂
le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁
le_top _ _ := univ_mem'
bot_le _ _ _ := trivial
instance : Inhabited (Filter α) := ⟨⊥⟩
end CompleteLattice
theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne'
@[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left
theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g :=
⟨ne_bot_of_le_ne_bot hf.1 hg⟩
theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g :=
hf.mono hg
@[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by
simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff]
theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff]
theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl
/-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot`
as the second alternative, to be used as an instance. -/
theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk
theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets :=
(giGenerate α).gc.u_inf
theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets :=
(giGenerate α).gc.u_sInf
theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets :=
(giGenerate α).gc.u_iInf
theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) :=
(giGenerate α).gc.l_bot
theorem generate_univ : Filter.generate univ = (⊥ : Filter α) :=
bot_unique fun _ _ => GenerateSets.basic (mem_univ _)
theorem generate_union {s t : Set (Set α)} :
Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t :=
(giGenerate α).gc.l_sup
theorem generate_iUnion {s : ι → Set (Set α)} :
Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) :=
(giGenerate α).gc.l_iSup
@[simp]
theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g :=
Iff.rfl
theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g :=
⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩
@[simp]
theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by
simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter]
@[simp]
theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by
simp [neBot_iff]
theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) :=
eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff]
theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i :=
iInf_le f i hs
@[simp]
theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f :=
⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩
theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } :=
Set.ext fun _ => le_principal_iff
theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by
simp only [le_principal_iff, mem_principal]
@[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono
@[mono]
theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2
@[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by
simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl
@[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl
@[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ :=
top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true]
@[simp]
theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ :=
bot_unique fun _ _ => empty_subset _
theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s :=
eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def]
/-! ### Lattice equations -/
theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ :=
⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩
theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty :=
s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id
theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty :=
@Filter.nonempty_of_mem α f hf s hs
@[simp]
theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl
theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α :=
nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f)
theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc =>
(nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s
theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ :=
empty_mem_iff_bot.mp <| univ_mem' isEmptyElim
protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by
simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty,
@eq_comm _ ∅]
theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f)
(ht : t ∈ g) : Disjoint f g :=
Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩
theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h =>
not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩
theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by
simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty]
/-- There is exactly one filter on an empty type. -/
instance unique [IsEmpty α] : Unique (Filter α) where
default := ⊥
uniq := filter_eq_bot_of_isEmpty
theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α :=
not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _)
/-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are
equal. -/
theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by
refine top_unique fun s hs => ?_
obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs)
exact univ_mem
theorem forall_mem_nonempty_iff_neBot {f : Filter α} :
(∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f :=
⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩
instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) :=
forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]
instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) :=
⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩
theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α :=
⟨fun _ =>
by_contra fun h' =>
haveI := not_nonempty_iff.1 h'
not_subsingleton (Filter α) inferInstance,
@Filter.instNontrivialFilter α⟩
theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S :=
le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩)
fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs
theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f :=
eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm
theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α}
(h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by
rw [iInf_subtype']
exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop]
theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] :
(iInf f).sets = ⋃ i, (f i).sets :=
let ⟨i⟩ := ne
let u :=
{ sets := ⋃ i, (f i).sets
univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩
sets_of_superset := by
simp only [mem_iUnion, exists_imp]
exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩
inter_sets := by
simp only [mem_iUnion, exists_imp]
intro x y a hx b hy
rcases h a b with ⟨c, ha, hb⟩
exact ⟨c, inter_mem (ha hx) (hb hy)⟩ }
have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion
congr_arg Filter.sets this.symm
theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) :
s ∈ iInf f ↔ ∃ i, s ∈ f i := by
simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion]
theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by
haveI := ne.to_subtype
simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop]
theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s)
(ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets :=
ext fun t => by simp [mem_biInf_of_directed h ne]
@[simp]
theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) :=
Filter.ext fun x => by simp only [mem_sup, mem_join]
@[simp]
theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) :=
Filter.ext fun x => by simp only [mem_iSup, mem_join]
instance : DistribLattice (Filter α) :=
{ Filter.instCompleteLatticeFilter with
le_sup_inf := by
intro x y z s
simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp]
rintro hs t₁ ht₁ t₂ ht₂ rfl
exact
⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂,
x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ }
/-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/
theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
(∀ i, NeBot (f i)) → NeBot (iInf f) :=
not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot,
mem_iInf_of_directed hd] using id
/-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`.
See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/
theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f)
(hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by
cases isEmpty_or_nonempty ι
· constructor
simp [iInf_of_empty f, top_ne_bot]
· exact iInf_neBot_of_directed' hd hb
theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
@iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ =>
⟨ne_of_mem_of_not_mem hf hbot⟩
theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s)
(hbot : ⊥ ∉ s) : NeBot (sInf s) :=
(sInf_eq_iInf' s).symm ▸
iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩
theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩
theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) :
NeBot (iInf f) ↔ ∀ i, NeBot (f i) :=
⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩
/-! #### `principal` equations -/
@[simp]
theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) :=
le_antisymm
(by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩)
(by simp [le_inf_iff, inter_subset_left, inter_subset_right])
@[simp]
theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) :=
Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal]
@[simp]
theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) :=
Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff]
@[simp]
theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ :=
empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff
@[simp]
theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty :=
neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm
alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff
theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) :=
IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by
rw [sup_principal, union_compl_self, principal_univ]
theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by
simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal,
← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl]
lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by
simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq]
lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by
ext
simp only [mem_iSup, mem_inf_principal]
theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by
rw [← empty_mem_iff_bot, mem_inf_principal]
simp only [mem_empty_iff_false, imp_false, compl_def]
theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by
rwa [inf_principal_eq_bot, compl_compl] at h
theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) :
s \ t ∈ f ⊓ 𝓟 tᶜ :=
inter_mem_inf hs <| mem_principal_self tᶜ
theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by
simp_rw [le_def, mem_principal]
end Lattice
@[mono, gcongr]
theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs
/-! ### Eventually -/
theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f :=
Iff.rfl
@[simp]
theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l :=
Iff.rfl
protected theorem ext' {f₁ f₂ : Filter α}
(h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ :=
Filter.ext h
theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop}
(hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x :=
h hp
theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f)
(h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x :=
mem_of_superset hU h
protected theorem Eventually.and {p q : α → Prop} {f : Filter α} :
f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x :=
inter_mem
@[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem
theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x :=
univ_mem' hp
@[simp]
theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ :=
empty_mem_iff_bot
@[simp]
theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by
by_cases h : p <;> simp [h, t.ne]
theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y :=
exists_mem_subset_iff.symm
theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) :
∃ v ∈ f, ∀ y ∈ v, p y :=
eventually_iff_exists_mem.1 hp
theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x :=
mp_mem hp hq
theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x :=
hp.mp (Eventually.of_forall hq)
theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop}
(h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y :=
fun y => h.mono fun _ h => h y
@[simp]
theorem eventually_and {p q : α → Prop} {f : Filter α} :
(∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x :=
inter_mem_iff
theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x)
(h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x :=
h'.mp (h.mono fun _ hx => hx.mp)
theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) :
(∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x :=
⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩
@[simp]
theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x :=
by_cases (fun h : p => by simp [h]) fun h => by simp [h]
@[simp]
theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by
simp only [@or_comm _ q, eventually_or_distrib_left]
theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by
simp only [imp_iff_not_or, eventually_or_distrib_left]
@[simp]
theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x :=
⟨⟩
@[simp]
theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x :=
Iff.rfl
@[simp]
theorem eventually_sup {p : α → Prop} {f g : Filter α} :
(∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x :=
Iff.rfl
@[simp]
theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x :=
Iff.rfl
@[simp]
theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} :
(∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x :=
mem_iSup
@[simp]
theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x :=
Iff.rfl
theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop}
(hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x :=
Filter.eventually_principal.mp (hP.filter_mono hf)
theorem eventually_inf {f g : Filter α} {p : α → Prop} :
(∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x :=
mem_inf_iff_superset
theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} :
(∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x :=
mem_inf_principal
theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} :
(∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where
mp h _ := by filter_upwards [h] with _ pa _ using pa
mpr h := by filter_upwards [h univ] with _ pa using pa (by simp)
/-! ### Frequently -/
theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) :
∃ᶠ x in f, p x :=
compl_not_mem h
theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) :
∃ᶠ x in f, p x :=
Eventually.frequently (Eventually.of_forall h)
theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x :=
mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h
lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) :
(∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x :=
⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩
theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) :
∃ᶠ x in g, p x :=
mt (fun h' => h'.filter_mono hle) h
theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x)
(hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x :=
h.mp (Eventually.of_forall hpq)
theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x)
(hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
refine mt (fun h => hq.mp <| h.mono ?_) hp
exact fun x hpq hq hp => hpq ⟨hp, hq⟩
theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x)
(hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by
simpa only [and_comm] using hq.and_eventually hp
theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by
by_contra H
replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H)
exact hp H
theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) :
∃ x, p x :=
hp.frequently.exists
lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} :
(∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by
rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl
lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) :=
frequently_iff_neBot
theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} :
(∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x :=
⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by
simpa only [and_not_self_iff, exists_false] using H hp⟩
theorem frequently_iff {f : Filter α} {P : α → Prop} :
(∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by
simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)]
rfl
@[simp]
theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by
simp [Filter.Frequently]
@[simp]
theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by
simp only [Filter.Frequently, not_not]
@[simp]
theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by
simp [frequently_iff_neBot]
@[simp]
theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp
@[simp]
theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by
by_cases p <;> simp [*]
@[simp]
theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and]
theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp
theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp
theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} :
(∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by
simp [imp_iff_not_or]
theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib]
theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by
simp only [frequently_imp_distrib, frequently_const]
theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by
simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently]
@[simp]
theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} :
(∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by
simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp]
@[simp]
theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} :
(∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by
simp only [@and_comm _ q, frequently_and_distrib_left]
@[simp]
theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp
@[simp]
theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently]
@[simp]
theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by
simp [Filter.Frequently, not_forall]
theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by
simp only [Filter.Frequently, eventually_inf_principal, not_and]
alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal
theorem frequently_sup {p : α → Prop} {f g : Filter α} :
(∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by
simp only [Filter.Frequently, eventually_sup, not_and_or]
@[simp]
theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} :
(∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by
simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop]
@[simp]
theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} :
(∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by
simp only [Filter.Frequently, eventually_iSup, not_forall]
theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) :
∃ f : α → β, ∀ᶠ x in l, r x (f x) := by
haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty
choose! f hf using fun x (hx : ∃ y, r x y) => hx
exact ⟨f, h.mono hf⟩
lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)]
{P : ∀ i : ι, α i → Prop} {F : Filter ι} :
(∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by
classical
refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩
refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩
filter_upwards [H] with i hi
exact dif_pos hi ▸ hi.choose_spec
/-!
### Relation “eventually equal”
-/
section EventuallyEq
variable {l : Filter α} {f g : α → β}
theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h
@[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff]
theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop)
(hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) :=
hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl
theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t :=
eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff
alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set
@[simp]
theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by
simp [eventuallyEq_set]
theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) :
∃ s ∈ l, EqOn f g s :=
Eventually.exists_mem h
theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) :
f =ᶠ[l] g :=
eventually_of_mem hs h
theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} :
f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s :=
eventually_iff_exists_mem
theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) :
f =ᶠ[l'] g :=
h₂ h₁
@[refl, simp]
theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f :=
Eventually.of_forall fun _ => rfl
protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f :=
EventuallyEq.refl l f
theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl
alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq
@[symm]
theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f :=
H.mono fun _ => Eq.symm
lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩
@[trans]
theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) :
f =ᶠ[l] h :=
H₂.rw (fun x y => f x = y) H₁
theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) :
f =ᶠ[l] h ↔ g =ᶠ[l] h :=
⟨H.symm.trans, H.trans⟩
theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) :
f =ᶠ[l] g ↔ f =ᶠ[l] h :=
⟨(·.trans H), (·.trans H.symm)⟩
instance {l : Filter α} :
Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where
trans := EventuallyEq.trans
theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') :
(fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) :=
hf.mp <|
hg.mono <| by
intros
simp only [*]
@[deprecated (since := "2025-03-10")]
alias EventuallyEq.prod_mk := EventuallyEq.prodMk
-- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t.
-- composition on the right.
theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) :
h ∘ f =ᶠ[l] h ∘ g :=
H.mono fun _ hx => congr_arg h hx
theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ)
(Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) :=
(Hf.prodMk Hg).fun_comp (uncurry h)
@[to_additive]
theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x :=
h.comp₂ (· * ·) h'
@[to_additive const_smul]
theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) :
(fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c :=
h.fun_comp (· ^ c)
@[to_additive]
theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
(fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ :=
h.fun_comp Inv.inv
@[to_additive]
theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g)
(h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x :=
h.comp₂ (· / ·) h'
attribute [to_additive] EventuallyEq.const_smul
@[to_additive]
theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β}
(hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x :=
hf.comp₂ (· • ·) hg
theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x :=
hf.comp₂ (· ⊔ ·) hg
theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f')
(hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x :=
hf.comp₂ (· ⊓ ·) hg
theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) :
f ⁻¹' s =ᶠ[l] g ⁻¹' s :=
h.fun_comp s
theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) :=
h.comp₂ (· ∧ ·) h'
theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) :=
h.comp₂ (· ∨ ·) h'
theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) :
(sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) :=
h.fun_comp Not
theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') :
(s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) :=
h.inter h'.compl
protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α}
(h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) :=
(h.diff h').union (h'.diff h)
theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s :=
eventuallyEq_set.trans <| by simp
theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by
simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp]
theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} :
(s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by
rw [inter_comm, inter_eventuallyEq_left]
@[simp]
theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s :=
Iff.rfl
theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} :
f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x :=
eventually_inf_principal
theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) :
f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm
theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} :
f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 :=
⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩
theorem eventuallyEq_iff_all_subsets {f g : α → β} {l : Filter α} :
f =ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x = g x :=
eventually_iff_all_subsets
section LE
variable [LE β] {l : Filter α}
theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f' ≤ᶠ[l] g' :=
H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H
theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') :
f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' :=
⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩
theorem eventuallyLE_iff_all_subsets {f g : α → β} {l : Filter α} :
f ≤ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x ≤ g x :=
| eventually_iff_all_subsets
| Mathlib/Order/Filter/Basic.lean | 1,051 | 1,052 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Order.ConditionallyCompleteLattice.Group
import Mathlib.Topology.MetricSpace.Isometry
/-!
# Metric space gluing
Gluing two metric spaces along a common subset. Formally, we are given
```
Φ
Z ---> X
|
|Ψ
v
Y
```
where `hΦ : Isometry Φ` and `hΨ : Isometry Ψ`.
We want to complete the square by a space `GlueSpacescan hΦ hΨ` and two isometries
`toGlueL hΦ hΨ` and `toGlueR hΦ hΨ` that make the square commute.
We start by defining a predistance on the disjoint union `X ⊕ Y`, for which
points `Φ p` and `Ψ p` are at distance 0. The (quotient) metric space associated
to this predistance is the desired space.
This is an instance of a more general construction, where `Φ` and `Ψ` do not have to be isometries,
but the distances in the image almost coincide, up to `2ε` say. Then one can almost glue the two
spaces so that the images of a point under `Φ` and `Ψ` are `ε`-close. If `ε > 0`, this yields a
metric space structure on `X ⊕ Y`, without the need to take a quotient. In particular,
this gives a natural metric space structure on `X ⊕ Y`, where the basepoints
are at distance 1, say, and the distances between other points are obtained by going through the two
basepoints.
(We also register the same metric space structure on a general disjoint union `Σ i, E i`).
We also define the inductive limit of metric spaces. Given
```
f 0 f 1 f 2 f 3
X 0 -----> X 1 -----> X 2 -----> X 3 -----> ...
```
where the `X n` are metric spaces and `f n` isometric embeddings, we define the inductive
limit of the `X n`, also known as the increasing union of the `X n` in this context, if we
identify `X n` and `X (n+1)` through `f n`. This is a metric space in which all `X n` embed
isometrically and in a way compatible with `f n`.
-/
noncomputable section
universe u v w
open Function Set Uniformity Topology
namespace Metric
section ApproxGluing
variable {X : Type u} {Y : Type v} {Z : Type w}
variable [MetricSpace X] [MetricSpace Y] {Φ : Z → X} {Ψ : Z → Y} {ε : ℝ}
/-- Define a predistance on `X ⊕ Y`, for which `Φ p` and `Ψ p` are at distance `ε` -/
def glueDist (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : X ⊕ Y → X ⊕ Y → ℝ
| .inl x, .inl y => dist x y
| .inr x, .inr y => dist x y
| .inl x, .inr y => (⨅ p, dist x (Φ p) + dist y (Ψ p)) + ε
| .inr x, .inl y => (⨅ p, dist y (Φ p) + dist x (Ψ p)) + ε
private theorem glueDist_self (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) : ∀ x, glueDist Φ Ψ ε x x = 0
| .inl _ => dist_self _
| .inr _ => dist_self _
theorem glueDist_glued_points [Nonempty Z] (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (p : Z) :
glueDist Φ Ψ ε (.inl (Φ p)) (.inr (Ψ p)) = ε := by
have : ⨅ q, dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) = 0 := by
have A : ∀ q, 0 ≤ dist (Φ p) (Φ q) + dist (Ψ p) (Ψ q) := fun _ =>
add_nonneg dist_nonneg dist_nonneg
refine le_antisymm ?_ (le_ciInf A)
have : 0 = dist (Φ p) (Φ p) + dist (Ψ p) (Ψ p) := by simp
rw [this]
exact ciInf_le ⟨0, forall_mem_range.2 A⟩ p
simp only [glueDist, this, zero_add]
private theorem glueDist_comm (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) :
∀ x y, glueDist Φ Ψ ε x y = glueDist Φ Ψ ε y x
| .inl _, .inl _ => dist_comm _ _
| .inr _, .inr _ => dist_comm _ _
| .inl _, .inr _ => rfl
| .inr _, .inl _ => rfl
theorem glueDist_swap (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) :
∀ x y, glueDist Ψ Φ ε x.swap y.swap = glueDist Φ Ψ ε x y
| .inl _, .inl _ => rfl
| .inr _, .inr _ => rfl
| .inl _, .inr _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, dist_comm, add_comm]
| .inr _, .inl _ => by simp only [glueDist, Sum.swap_inl, Sum.swap_inr, dist_comm, add_comm]
theorem le_glueDist_inl_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) :
ε ≤ glueDist Φ Ψ ε (.inl x) (.inr y) :=
le_add_of_nonneg_left <| Real.iInf_nonneg fun _ => add_nonneg dist_nonneg dist_nonneg
theorem le_glueDist_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x y) :
ε ≤ glueDist Φ Ψ ε (.inr x) (.inl y) := by
rw [glueDist_comm]; apply le_glueDist_inl_inr
section
variable [Nonempty Z]
private theorem glueDist_triangle_inl_inr_inr (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ) (x : X) (y z : Y) :
glueDist Φ Ψ ε (.inl x) (.inr z) ≤
glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inr z) := by
simp only [glueDist]
rw [add_right_comm, add_le_add_iff_right]
refine le_ciInf_add fun p => ciInf_le_of_le ⟨0, ?_⟩ p ?_
· exact forall_mem_range.2 fun _ => add_nonneg dist_nonneg dist_nonneg
· linarith [dist_triangle_left z (Ψ p) y]
private theorem glueDist_triangle_inl_inr_inl (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ)
(H : ∀ p q, |dist (Φ p) (Φ q) - dist (Ψ p) (Ψ q)| ≤ 2 * ε) (x : X) (y : Y) (z : X) :
| glueDist Φ Ψ ε (.inl x) (.inl z) ≤
glueDist Φ Ψ ε (.inl x) (.inr y) + glueDist Φ Ψ ε (.inr y) (.inl z) := by
simp_rw [glueDist, add_add_add_comm _ ε, add_assoc]
refine le_ciInf_add fun p => ?_
rw [add_left_comm, add_assoc, ← two_mul]
refine le_ciInf_add fun q => ?_
rw [dist_comm z]
linarith [dist_triangle4 x (Φ p) (Φ q) z, dist_triangle_left (Ψ p) (Ψ q) y, (abs_le.1 (H p q)).2]
private theorem glueDist_triangle (Φ : Z → X) (Ψ : Z → Y) (ε : ℝ)
| Mathlib/Topology/MetricSpace/Gluing.lean | 121 | 130 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Topology.Order.ProjIcc
/-!
# Inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function.
(This is delayed as it is easier to set up after developing complex trigonometric functions.)
Basic inequalities on trigonometric functions.
-/
noncomputable section
open Topology Filter Set Filter Real
namespace Real
variable {x y : ℝ}
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.
It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/
@[pp_nodot]
noncomputable def arcsin : ℝ → ℝ :=
Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm
theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by
rw [arcsin, range_comp Subtype.val]
simp [Icc]
theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 :=
(arcsin_mem_Icc x).2
theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x :=
(arcsin_mem_Icc x).1
theorem arcsin_projIcc (x : ℝ) :
arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by
rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend,
Function.comp_apply]
theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by
simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using
Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩)
theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
sin_arcsin' ⟨hx₁, hx₂⟩
theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x :=
injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]
theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
arcsin_sin' ⟨hx₁, hx₂⟩
theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) :=
(Subtype.strictMono_coe _).comp_strictMonoOn <|
sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _
@[gcongr]
theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) :
arcsin x < arcsin y :=
strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt
theorem monotone_arcsin : Monotone arcsin :=
(Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _
@[gcongr]
theorem arcsin_le_arcsin {x y : ℝ} (h : x ≤ y) : arcsin x ≤ arcsin y := monotone_arcsin h
theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) :=
strictMonoOn_arcsin.injOn
theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arcsin x = arcsin y ↔ x = y :=
injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[continuity, fun_prop]
theorem continuous_arcsin : Continuous arcsin :=
continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend'
@[fun_prop]
theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x :=
continuous_arcsin.continuousAt
theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :
arcsin y = x := by
subst y
exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))
@[simp]
theorem arcsin_zero : arcsin 0 = 0 :=
arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩
@[simp]
theorem arcsin_one : arcsin 1 = π / 2 :=
arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by
rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one]
theorem arcsin_neg_one : arcsin (-1) = -(π / 2) :=
arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <|
left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by
rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one]
@[simp]
theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by
rcases le_total x (-1) with hx₁ | hx₁
· rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)]
rcases le_total 1 x with hx₂ | hx₂
· rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)]
refine arcsin_eq_of_sin_eq ?_ ?_
· rw [sin_neg, sin_arcsin hx₁ hx₂]
· exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩
theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y := by
rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]
theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y := by
rcases le_total x (-1) with hx₁ | hx₁
· simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)]
rcases lt_or_le 1 x with hx₂ | hx₂
· simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂]
exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)
theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg,
arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg,
neg_le_neg_iff]
theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :
x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le
theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le
theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le
theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le
theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :
arcsin x = y ↔ x = sin y := by
simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),
le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]
@[simp]
theorem arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=
(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by
rw [sin_zero]
@[simp]
theorem arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=
neg_nonneg.symm.trans <| arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg
@[simp]
theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff]
@[simp]
theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=
eq_comm.trans arcsin_eq_zero_iff
@[simp]
theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le arcsin_nonpos
@[simp]
theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=
lt_iff_lt_of_le_iff_le arcsin_nonneg
@[simp]
theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 :=
(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by
rw [sin_pi_div_two]
@[simp]
theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x :=
(lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by
rw [sin_neg, sin_pi_div_two]
@[simp]
theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=
⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩
@[simp]
theorem pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=
eq_comm.trans arcsin_eq_pi_div_two
@[simp]
theorem pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x :=
(arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin
@[simp]
theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=
⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩
@[simp]
theorem neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=
eq_comm.trans arcsin_eq_neg_pi_div_two
@[simp]
theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=
(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two
@[simp]
theorem pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ √2 / 2 ≤ x := by
rw [← sin_pi_div_four, le_arcsin_iff_sin_le']
have := pi_pos
constructor <;> linarith
theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := fun x h => by
rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le]
/-- `Real.sin` as a `PartialHomeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/
@[simp]
def sinPartialHomeomorph : PartialHomeomorph ℝ ℝ where
toFun := sin
invFun := arcsin
source := Ioo (-(π / 2)) (π / 2)
target := Ioo (-1) 1
map_source' := mapsTo_sin_Ioo
map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩
left_inv' _ hx := arcsin_sin hx.1.le hx.2.le
right_inv' _ hy := sin_arcsin hy.1.le hy.2.le
open_source := isOpen_Ioo
open_target := isOpen_Ioo
continuousOn_toFun := continuous_sin.continuousOn
continuousOn_invFun := continuous_arcsin.continuousOn
theorem cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.
theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by
by_cases hx₁ : -1 ≤ x; swap
· rw [not_le] at hx₁
rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos]
nlinarith
by_cases hx₂ : x ≤ 1; swap
· rw [not_le] at hx₂
rw [arcsin_of_one_le hx₂.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos]
nlinarith
have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x)
rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq,
sqrt_mul_self (cos_arcsin_nonneg _)] at this
rw [this, sin_arcsin hx₁ hx₂]
-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.
theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by
rw [tan_eq_sin_div_cos, cos_arcsin]
by_cases hx₁ : -1 ≤ x; swap
· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)
rw [h]
simp
by_cases hx₂ : x ≤ 1; swap
· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)
rw [h]
simp
rw [sin_arcsin hx₁ hx₂]
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/
@[pp_nodot]
noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x :=
rfl
theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos]
theorem arccos_le_pi (x : ℝ) : arccos x ≤ π := by
unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
theorem arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by
unfold arccos; linarith [arcsin_le_pi_div_two x]
@[simp]
theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos]
theorem cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by
rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
theorem arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by
rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith
lemma arccos_eq_of_eq_cos (hy₀ : 0 ≤ y) (hy₁ : y ≤ π) (hxy : x = cos y) : arccos x = y := by
rw [hxy, arccos_cos hy₀ hy₁]
theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h =>
sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _
@[gcongr]
lemma arccos_lt_arccos {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) :
arccos y < arccos x := by
unfold arccos; gcongr <;> assumption
@[gcongr]
lemma arccos_le_arccos {x y : ℝ} (hlt : x ≤ y) : arccos y ≤ arccos x := by unfold arccos; gcongr
theorem antitone_arccos : Antitone arccos := fun _ _ ↦ arccos_le_arccos
theorem arccos_injOn : InjOn arccos (Icc (-1) 1) :=
strictAntiOn_arccos.injOn
theorem arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arccos x = arccos y ↔ x = y :=
arccos_injOn.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[simp]
theorem arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp]
theorem arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp]
theorem arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
@[simp]
theorem arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero]
@[simp]
theorem arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by simp [arccos]
@[simp]
theorem arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 := by
rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]
theorem arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by
rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]
theorem arccos_of_one_le {x : ℝ} (hx : 1 ≤ x) : arccos x = 0 := by
rw [arccos, arcsin_of_one_le hx, sub_self]
theorem arccos_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arccos x = π := by
rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves]
-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.
theorem sin_arccos (x : ℝ) : sin (arccos x) = √(1 - x ^ 2) := by
by_cases hx₁ : -1 ≤ x; swap
· rw [not_le] at hx₁
rw [arccos_of_le_neg_one hx₁.le, sin_pi, sqrt_eq_zero_of_nonpos]
nlinarith
by_cases hx₂ : x ≤ 1; swap
· rw [not_le] at hx₂
rw [arccos_of_one_le hx₂.le, sin_zero, sqrt_eq_zero_of_nonpos]
nlinarith
rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin]
@[simp]
theorem arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos]
@[simp]
theorem arccos_lt_pi_div_two {x : ℝ} : arccos x < π / 2 ↔ 0 < x := by simp [arccos]
@[simp]
theorem arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ √2 / 2 ≤ x := by
rw [arccos, ← pi_div_four_le_arcsin]
constructor <;>
· intro
linarith
@[continuity, fun_prop]
theorem continuous_arccos : Continuous arccos :=
continuous_const.sub continuous_arcsin
-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.
theorem tan_arccos (x : ℝ) : tan (arccos x) = √(1 - x ^ 2) / x := by
rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div]
-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.
theorem arccos_eq_arcsin {x : ℝ} (h : 0 ≤ x) : arccos x = arcsin (√(1 - x ^ 2)) :=
(arcsin_eq_of_sin_eq (sin_arccos _)
⟨(Left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by norm_num))).trans (arccos_nonneg _),
arccos_le_pi_div_two.2 h⟩).symm
-- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`.
theorem arcsin_eq_arccos {x : ℝ} (h : 0 ≤ x) : arcsin x = arccos (√(1 - x ^ 2)) := by
rw [eq_comm, ← cos_arcsin]
exact
arccos_cos (arcsin_nonneg.2 h)
((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two))
end Real
open Real
/-!
### Convenience dot notation lemmas
| -/
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean | 414 | 415 |
/-
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
| Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean | 825 | 852 |
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Sébastien Gouëzel
-/
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Measure.Doubling
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
/-!
# Relationship between the Haar and Lebesgue measures
We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in
`MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`.
We deduce basic properties of any Haar measure on a finite dimensional real vector space:
* `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the
absolute value of its determinant.
* `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure
of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the
determinant of `f`.
* `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the
measure of `s` multiplied by the absolute value of the determinant of `f`.
* `addHaar_submodule` : a strict submodule has measure `0`.
* `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`.
* `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_sphere`: spheres have zero measure.
This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`.
This measure is called `AlternatingMap.measure`. Its main property is
`ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned
by vectors `v₁, ..., vₙ` is given by `|ω v|`.
We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has
density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in
`tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for
small `r`, see `eventually_nonempty_inter_smul_of_density_one`.
Statements on integrals of functions with respect to an additive Haar measure can be found in
`MeasureTheory.Measure.Haar.NormedSpace`.
-/
assert_not_exists MeasureTheory.integral
open TopologicalSpace Set Filter Metric Bornology
open scoped ENNReal Pointwise Topology NNReal
/-- The interval `[0,1]` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where
carrier := Icc 0 1
isCompact' := isCompact_Icc
interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]
universe u
/-- The set `[0,1]^ι` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] :
PositiveCompacts (ι → ℝ) where
carrier := pi univ fun _ => Icc 0 1
isCompact' := isCompact_univ_pi fun _ => isCompact_Icc
interior_nonempty' := by
simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,
imp_true_iff, zero_lt_one]
/-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/
theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] :
(Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι :=
SetLike.coe_injective <| by
refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm)
· classical convert parallelepiped_single (ι := ι) 1
· exact zero_le_one
/-- A parallelepiped can be expressed on the standard basis. -/
theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E]
[NormedSpace ℝ E] (b : Basis ι ℝ E) :
b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm
b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by
classical
rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map]
congr with x
simp [Pi.single_apply]
open MeasureTheory MeasureTheory.Measure
theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F]
[NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E]
[BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F]
(b : Basis ι ℝ E) (f : E ≃L[ℝ] F) :
map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by
have : IsAddHaarMeasure (map f b.addHaar) :=
AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous
rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable
(PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map]
erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self]
namespace MeasureTheory
open Measure TopologicalSpace.PositiveCompacts Module
/-!
### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`.
-/
/-- The Haar measure equals the Lebesgue measure on `ℝ`. -/
theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by
convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01]
/-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/
theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] :
addHaarMeasure (piIcc01 ι) = volume := by
convert (addHaarMeasure_unique volume (piIcc01 ι)).symm
simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk,
Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero]
theorem isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] :
IsAddHaarMeasure (volume : Measure (ι → ℝ)) :=
inferInstance
namespace Measure
/-!
### Strict subspaces have zero measure
-/
open scoped Function -- required for scoped `on` notation
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/
theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
by_contra h
apply lt_irrefl ∞
calc
∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm
_ = ∑' n : ℕ, μ ({u n} + s) := by
congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add]
_ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by
simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's
_ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range]
_ < ∞ := (hu.add sb).measure_lt_top
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. -/
theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by
apply le_antisymm _ (zero_le _)
calc
μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by
conv_lhs => rw [← iUnion_inter_closedBall_nat s 0]
exact measure_iUnion_le _
_ = 0 := by simp only [H, tsum_zero]
intro R
apply addHaar_eq_zero_of_disjoint_translates_aux μ u
(isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall)
refine pairwise_disjoint_mono hs fun n => ?_
exact add_subset_add Subset.rfl inter_subset_left
/-- A strict vector subspace has measure zero. -/
theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E]
[BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E)
(hs : s ≠ ⊤) : μ s = 0 := by
obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by
simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs
obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩
have A : IsBounded (range fun n : ℕ => c ^ n • x) :=
have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) :=
(tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x
isBounded_range_of_tendsto _ this
apply addHaar_eq_zero_of_disjoint_translates μ _ A _
(Submodule.closed_of_finiteDimensional s).measurableSet
intro m n hmn
simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage,
SetLike.mem_coe]
intro y hym hyn
have A : (c ^ n - c ^ m) • x ∈ s := by
convert s.sub_mem hym hyn using 1
simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub]
have H : c ^ n - c ^ m ≠ 0 := by
simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti₀ cpos cone).injective.ne hmn.symm
have : x ∈ s := by
convert s.smul_mem (c ^ n - c ^ m)⁻¹ A
rw [smul_smul, inv_mul_cancel₀ H, one_smul]
exact hx this
/-- A strict affine subspace has measure zero. -/
theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
(s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by
rcases s.eq_bot_or_nonempty with (rfl | hne)
· rw [AffineSubspace.bot_coe, measure_empty]
rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs
rcases hne with ⟨x, hx : x ∈ s⟩
simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg,
image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs
/-!
### Applying a linear map rescales Haar measure by the determinant
We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue
measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real
vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a
linear equiv maps Haar measure to Haar measure.
-/
theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ}
(hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] :
Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by
cases nonempty_fintype ι
/- We have already proved the result for the Lebesgue product measure, using matrices.
We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/
have := addHaarMeasure_unique μ (piIcc01 ι)
rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul,
Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) :
Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by
-- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using
-- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`.
let ι := Fin (finrank ℝ E)
haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance
have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι]
have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this
-- next line is to avoid `g` getting reduced by `simp`.
obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩
have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e
rw [← gdet] at hf ⊢
have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by
ext x
simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp,
LinearEquiv.symm_apply_apply, hg]
simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp]
have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional
have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g
have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional
rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable]
haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm
have ecomp : e.symm ∘ e = id := by
ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply]
rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul,
map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id]
/-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s :=
calc
μ (f ⁻¹' s) = Measure.map f μ s :=
((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply
s).symm
_ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl
/-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E}
(hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s :=
addHaar_preimage_linearMap μ hf s
/-- The preimage of a set `s` under a linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by
have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero
convert addHaar_preimage_linearMap μ A s
simp only [LinearEquiv.det_coe_symm]
/-- The preimage of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s :=
addHaar_preimage_linearEquiv μ _ s
/-- The image of a set `s` under a linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by
rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf)
· let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv
change μ (g '' s) = _
rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv]
congr
· simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero]
have : μ (LinearMap.range f) = 0 :=
addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne
exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _)
/-- The image of a set `s` under a continuous linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
addHaar_image_linearMap μ _ s
/-- The image of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s
theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) :
QuasiMeasurePreserving f μ μ := by
refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]
exact smul_absolutelyContinuous
theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) :
QuasiMeasurePreserving f μ μ :=
LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf
/-!
### Basic properties of Haar measures on real vector spaces
-/
theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) :
Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by
let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E)
change Measure.map f μ = _
have hf : LinearMap.det f ≠ 0 := by
simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one]
intro h
exact hr (pow_eq_zero h)
simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one]
theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) :
QuasiMeasurePreserving (r • ·) μ μ := by
refine ⟨measurable_const_smul r, ?_⟩
rw [map_addHaar_smul μ hr]
exact smul_absolutelyContinuous
@[simp]
theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) :
μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s :=
calc
μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s :=
((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by
rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul]
/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/
@[simp]
theorem addHaar_smul (r : ℝ) (s : Set E) :
μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
rcases ne_or_eq r 0 with (h | rfl)
· rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv]
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp only [measure_empty, mul_zero, smul_set_empty]
rw [zero_smul_set hs, ← singleton_zero]
by_cases h : finrank ℝ E = 0
· haveI : Subsingleton E := finrank_zero_iff.1 h
simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs,
pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))]
· haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h)
simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff,
zero_pow, measure_singleton]
theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) :
μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by
rw [addHaar_smul, abs_pow, abs_of_nonneg hr]
variable {μ} {s : Set E}
-- Note: We might want to rename this once we acquire the lemma corresponding to
-- `MeasurableSet.const_smul`
theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) :
NullMeasurableSet (r • s) μ := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simp
obtain rfl | hr := eq_or_ne r 0
· simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _
obtain ⟨t, ht, hst⟩ := hs
refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩
rw [← measure_symmDiff_eq_zero_iff] at hst ⊢
rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero]
variable (μ)
@[simp]
theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) :
μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s :=
calc
μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by
simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
simp only [image_add_right, measure_preimage_add_right, addHaar_smul]
/-! We don't need to state `map_addHaar_neg` here, because it has already been proved for
general Haar measures on general commutative groups. -/
/-! ### Measure of balls -/
theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E]
(μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by
have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball]
rw [this, measure_preimage_add]
theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ.real (ball x r) = μ.real (ball (0 : E) r) := by
simp [measureReal_def, addHaar_ball_center]
theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (closedBall (0 : E) r) := by
have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall]
rw [this, measure_preimage_add]
theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ.real (closedBall x r) = μ.real (closedBall (0 : E) r) := by
simp [measureReal_def, addHaar_closedBall_center]
theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
have : ball (0 : E) (r * s) = r • ball (0 : E) s := by
simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow]
theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul_of_pos μ x hr, mul_one]
theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
rcases hr.eq_or_lt with (rfl | h)
· simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul,
ENNReal.ofReal_zero, ball_zero]
· exact addHaar_ball_mul_of_pos μ x h s
theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul μ x hr, mul_one]
theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow]
theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr]
simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow]
/-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball.
Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard
form. -/
theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by
rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one]
theorem addHaar_real_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (closedBall 0 1) := by
simp only [measureReal_def, addHaar_closedBall' μ x hr, ENNReal.toReal_mul, mul_eq_mul_right_iff,
ENNReal.toReal_ofReal_eq_iff]
left
positivity
theorem addHaar_unitClosedBall_eq_addHaar_unitBall :
μ (closedBall (0 : E) 1) = μ (ball 0 1) := by
apply le_antisymm _ (measure_mono ball_subset_closedBall)
have A : Tendsto
(fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall (0 : E) 1)) (𝓝[<] 1)
(𝓝 (ENNReal.ofReal ((1 : ℝ) ^ finrank ℝ E) * μ (closedBall (0 : E) 1))) := by
refine ENNReal.Tendsto.mul ?_ (by simp) tendsto_const_nhds (by simp)
exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _)
simp only [one_pow, one_mul, ENNReal.ofReal_one] at A
refine le_of_tendsto A ?_
filter_upwards [Ioo_mem_nhdsLT zero_lt_one] with r hr
rw [← addHaar_closedBall' μ (0 : E) hr.1.le]
exact measure_mono (closedBall_subset_ball hr.2)
@[deprecated (since := "2024-12-01")]
alias addHaar_closed_unit_ball_eq_addHaar_unit_ball := addHaar_unitClosedBall_eq_addHaar_unitBall
theorem addHaar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [addHaar_closedBall' μ x hr, addHaar_unitClosedBall_eq_addHaar_unitBall]
theorem addHaar_real_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (ball 0 1) := by
simp [addHaar_real_closedBall' μ x hr, measureReal_def,
addHaar_unitClosedBall_eq_addHaar_unitBall]
theorem addHaar_closedBall_eq_addHaar_ball [Nontrivial E] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (ball x r) := by
by_cases h : r < 0
· rw [Metric.closedBall_eq_empty.mpr h, Metric.ball_eq_empty.mpr h.le]
push_neg at h
rw [addHaar_closedBall μ x h, addHaar_ball μ x h]
theorem addHaar_real_closedBall_eq_addHaar_real_ball [Nontrivial E] (x : E) (r : ℝ) :
μ.real (closedBall x r) = μ.real (ball x r) := by
simp [measureReal_def, addHaar_closedBall_eq_addHaar_ball μ x r]
theorem addHaar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 := by
rcases hr.lt_or_lt with (h | h)
· simp only [empty_diff, measure_empty, ← closedBall_diff_ball, closedBall_eq_empty.2 h]
· rw [← closedBall_diff_ball,
measure_diff ball_subset_closedBall measurableSet_ball.nullMeasurableSet
measure_ball_lt_top.ne,
addHaar_ball_of_pos μ _ h, addHaar_closedBall μ _ h.le, tsub_self]
theorem addHaar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 := by
rcases eq_or_ne r 0 with (rfl | h)
· rw [sphere_zero, measure_singleton]
· exact addHaar_sphere_of_ne_zero μ x h
theorem addHaar_singleton_add_smul_div_singleton_add_smul {r : ℝ} (hr : r ≠ 0) (x y : E)
(s t : Set E) : μ ({x} + r • s) / μ ({y} + r • t) = μ s / μ t :=
calc
μ ({x} + r • s) / μ ({y} + r • t) = ENNReal.ofReal (|r| ^ finrank ℝ E) * μ s *
(ENNReal.ofReal (|r| ^ finrank ℝ E) * μ t)⁻¹ := by
simp only [div_eq_mul_inv, addHaar_smul, image_add_left, measure_preimage_add, abs_pow,
singleton_add]
_ = ENNReal.ofReal (|r| ^ finrank ℝ E) * (ENNReal.ofReal (|r| ^ finrank ℝ E))⁻¹ *
(μ s * (μ t)⁻¹) := by
rw [ENNReal.mul_inv]
· ring
· simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne, true_or]
· simp only [ENNReal.ofReal_ne_top, true_or, Ne, not_false_iff]
_ = μ s / μ t := by
rw [ENNReal.mul_inv_cancel, one_mul, div_eq_mul_inv]
· simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne]
· simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff]
instance (priority := 100) isUnifLocDoublingMeasureOfIsAddHaarMeasure :
IsUnifLocDoublingMeasure μ := by
refine ⟨⟨(2 : ℝ≥0) ^ finrank ℝ E, ?_⟩⟩
filter_upwards [self_mem_nhdsWithin] with r hr x
rw [addHaar_closedBall_mul μ x zero_le_two (le_of_lt hr), addHaar_closedBall_center μ x,
ENNReal.ofReal, Real.toNNReal_pow zero_le_two]
simp only [Real.toNNReal_ofNat, le_refl]
section
/-!
### The Lebesgue measure associated to an alternating map
-/
variable {ι G : Type*} [Fintype ι] [DecidableEq ι] [NormedAddCommGroup G] [NormedSpace ℝ G]
[MeasurableSpace G] [BorelSpace G]
theorem addHaar_parallelepiped (b : Basis ι ℝ G) (v : ι → G) :
b.addHaar (parallelepiped v) = ENNReal.ofReal |b.det v| := by
have : FiniteDimensional ℝ G := FiniteDimensional.of_fintype_basis b
have A : parallelepiped v = b.constr ℕ v '' parallelepiped b := by
rw [image_parallelepiped]
exact congr_arg _ <| funext fun i ↦ (b.constr_basis ℕ v i).symm
rw [A, addHaar_image_linearMap, b.addHaar_self, mul_one, ← LinearMap.det_toMatrix b,
← Basis.toMatrix_eq_toMatrix_constr, Basis.det_apply]
variable [FiniteDimensional ℝ G] {n : ℕ} [_i : Fact (finrank ℝ G = n)]
/-- The Lebesgue measure associated to an alternating map. It gives measure `|ω v|` to the
parallelepiped spanned by the vectors `v₁, ..., vₙ`. Note that it is not always a Haar measure,
as it can be zero, but it is always locally finite and translation invariant. -/
noncomputable irreducible_def _root_.AlternatingMap.measure (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) :
| Measure G :=
‖ω (finBasisOfFinrankEq ℝ G _i.out)‖₊ • (finBasisOfFinrankEq ℝ G _i.out).addHaar
theorem _root_.AlternatingMap.measure_parallelepiped (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ)
(v : Fin n → G) : ω.measure (parallelepiped v) = ENNReal.ofReal |ω v| := by
conv_rhs => rw [ω.eq_smul_basis_det (finBasisOfFinrankEq ℝ G _i.out)]
simp only [addHaar_parallelepiped, AlternatingMap.measure, coe_nnreal_smul_apply,
AlternatingMap.smul_apply, Algebra.id.smul_eq_mul, abs_mul, ENNReal.ofReal_mul (abs_nonneg _),
← Real.enorm_eq_ofReal_abs, enorm]
| Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean | 581 | 590 |
/-
Copyright (c) 2024 Yaël Dillies, Kin Yau James Wong. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Kin Yau James Wong, Rémy Degenne
-/
import Mathlib.MeasureTheory.Function.AEEqOfLIntegral
import Mathlib.Probability.Kernel.Composition.MeasureCompProd
/-!
# Disintegration of measures and kernels
This file defines predicates for a kernel to "disintegrate" a measure or a kernel. This kernel is
also called the "conditional kernel" of the measure or kernel.
A measure `ρ : Measure (α × Ω)` is disintegrated by a kernel `ρCond : Kernel α Ω` if
`ρ.fst ⊗ₘ ρCond = ρ`.
A kernel `ρ : Kernel α (β × Ω)` is disintegrated by a kernel `κCond : Kernel (α × β) Ω` if
`κ.fst ⊗ₖ κCond = κ`.
## Main definitions
* `MeasureTheory.Measure.IsCondKernel ρ ρCond`: Predicate for the kernel `ρCond` to disintegrate the
measure `ρ`.
* `ProbabilityTheory.Kernel.IsCondKernel κ κCond`: Predicate for the kernel `κ Cond` to disintegrate
the kernel `κ`.
Further, if `κ` is an s-finite kernel from a countable `α` such that each measure `κ a` is
disintegrated by some kernel, then `κ` itself is disintegrated by a kernel, namely
`ProbabilityTheory.Kernel.condKernelCountable`.
## See also
`Mathlib.Probability.Kernel.Disintegration.StandardBorel` for a **construction** of disintegrating
kernels.
-/
open MeasureTheory Set Filter MeasurableSpace ProbabilityTheory
open scoped ENNReal MeasureTheory Topology
variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β} {mΩ : MeasurableSpace Ω}
/-!
### Disintegration of measures
This section provides a predicate for a kernel to disintegrate a measure.
-/
namespace MeasureTheory.Measure
variable (ρ : Measure (α × Ω)) (ρCond : Kernel α Ω)
/-- A kernel `ρCond` is a conditional kernel for a measure `ρ` if it disintegrates it in the sense
that `ρ.fst ⊗ₘ ρCond = ρ`. -/
class IsCondKernel : Prop where
disintegrate : ρ.fst ⊗ₘ ρCond = ρ
variable [ρ.IsCondKernel ρCond]
lemma disintegrate : ρ.fst ⊗ₘ ρCond = ρ := IsCondKernel.disintegrate
lemma IsCondKernel.isSFiniteKernel (hρ : ρ ≠ 0) : IsSFiniteKernel ρCond := by
contrapose! hρ; rwa [← ρ.disintegrate ρCond, Measure.compProd_of_not_isSFiniteKernel]
variable [IsFiniteMeasure ρ]
/-- Auxiliary lemma for `IsCondKernel.apply_of_ne_zero`. -/
private lemma IsCondKernel.apply_of_ne_zero_of_measurableSet [MeasurableSingletonClass α] {x : α}
(hx : ρ.fst {x} ≠ 0) {s : Set Ω} (hs : MeasurableSet s) :
ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := by
have := isSFiniteKernel ρ ρCond (by rintro rfl; simp at hx)
nth_rewrite 2 [← ρ.disintegrate ρCond]
rw [Measure.compProd_apply (measurableSet_prod.mpr (Or.inl ⟨measurableSet_singleton x, hs⟩))]
classical
have (a) : ρCond a (Prod.mk a ⁻¹' {x} ×ˢ s) = ({x} : Set α).indicator (ρCond · s) a := by
obtain rfl | hax := eq_or_ne a x
· simp only [singleton_prod, mem_singleton_iff, indicator_of_mem]
congr with y
simp
· simp only [singleton_prod, mem_singleton_iff, hax, not_false_eq_true, indicator_of_not_mem]
have : Prod.mk a ⁻¹' (Prod.mk x '' s) = ∅ := by ext y; simp [Ne.symm hax]
simp only [this, measure_empty]
simp_rw [this]
rw [MeasureTheory.lintegral_indicator (measurableSet_singleton x)]
simp only [Measure.restrict_singleton, lintegral_smul_measure, lintegral_dirac, smul_eq_mul]
rw [← mul_assoc, ENNReal.inv_mul_cancel hx (measure_ne_top _ _), one_mul]
/-- If the singleton `{x}` has non-zero mass for `ρ.fst`, then for all `s : Set Ω`,
`ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s)` . -/
lemma IsCondKernel.apply_of_ne_zero [MeasurableSingletonClass α] {x : α}
(hx : ρ.fst {x} ≠ 0) (s : Set Ω) : ρCond x s = (ρ.fst {x})⁻¹ * ρ ({x} ×ˢ s) := by
have : ρCond x s = ((ρ.fst {x})⁻¹ • ρ).comap (fun (y : Ω) ↦ (x, y)) s := by
congr 2 with s hs
simp [IsCondKernel.apply_of_ne_zero_of_measurableSet _ _ hx hs,
(measurableEmbedding_prodMk_left x).comap_apply, Set.singleton_prod]
simp [this, (measurableEmbedding_prodMk_left x).comap_apply, hx, Set.singleton_prod]
lemma IsCondKernel.isProbabilityMeasure [MeasurableSingletonClass α] {a : α} (ha : ρ.fst {a} ≠ 0) :
IsProbabilityMeasure (ρCond a) := by
constructor
rw [IsCondKernel.apply_of_ne_zero _ _ ha, prod_univ, ← Measure.fst_apply
(measurableSet_singleton _), ENNReal.inv_mul_cancel ha (measure_ne_top _ _)]
lemma IsCondKernel.isMarkovKernel [MeasurableSingletonClass α] (hρ : ∀ a, ρ.fst {a} ≠ 0) :
IsMarkovKernel ρCond := ⟨fun _ ↦ isProbabilityMeasure _ _ (hρ _)⟩
end MeasureTheory.Measure
/-!
### Disintegration of kernels
This section provides a predicate for a kernel to disintegrate a kernel. It also proves that if `κ`
is an s-finite kernel from a countable `α` such that each measure `κ a` is disintegrated by some
kernel, then `κ` itself is disintegrated by a kernel, namely
`ProbabilityTheory.Kernel.condKernelCountable`.
-/
namespace ProbabilityTheory.Kernel
variable (κ : Kernel α (β × Ω)) (κCond : Kernel (α × β) Ω)
/-! #### Predicate for a kernel to disintegrate a kernel -/
/-- A kernel `κCond` is a conditional kernel for a kernel `κ` if it disintegrates it in the sense
that `κ.fst ⊗ₖ κCond = κ`. -/
class IsCondKernel : Prop where
protected disintegrate : κ.fst ⊗ₖ κCond = κ
instance instIsCondKernel_zero (κCond : Kernel (α × β) Ω) : IsCondKernel 0 κCond where
disintegrate := by simp
lemma disintegrate [κ.IsCondKernel κCond] : κ.fst ⊗ₖ κCond = κ := IsCondKernel.disintegrate
/-- A conditional kernel is almost everywhere a probability measure. -/
lemma IsCondKernel.isProbabilityMeasure_ae [IsFiniteKernel κ.fst] [κ.IsCondKernel κCond] (a : α) :
∀ᵐ b ∂(κ.fst a), IsProbabilityMeasure (κCond (a, b)) := by
have h := disintegrate κ κCond
by_cases h_sfin : IsSFiniteKernel κCond
swap; · rw [Kernel.compProd_of_not_isSFiniteKernel_right _ _ h_sfin] at h; simp [h.symm]
suffices ∀ᵐ b ∂(κ.fst a), κCond (a, b) Set.univ = 1 by
convert this with b
exact ⟨fun _ ↦ measure_univ, fun h ↦ ⟨h⟩⟩
suffices (∀ᵐ b ∂(κ.fst a), κCond (a, b) Set.univ ≤ 1)
∧ (∀ᵐ b ∂(κ.fst a), 1 ≤ κCond (a, b) Set.univ) by
filter_upwards [this.1, this.2] with b h1 h2 using le_antisymm h1 h2
have h_eq s (hs : MeasurableSet s) :
∫⁻ b, s.indicator (fun b ↦ κCond (a, b) Set.univ) b ∂κ.fst a = κ.fst a s := by
conv_rhs => rw [← h]
rw [fst_compProd_apply _ _ _ hs]
have h_meas : Measurable fun b ↦ κCond (a, b) Set.univ :=
(κCond.measurable_coe MeasurableSet.univ).comp measurable_prodMk_left
constructor
· rw [ae_le_const_iff_forall_gt_measure_zero]
intro r hr
let s := {b | r ≤ κCond (a, b) Set.univ}
have hs : MeasurableSet s := h_meas measurableSet_Ici
have h_2_le : s.indicator (fun _ ↦ r) ≤ s.indicator (fun b ↦ (κCond (a, b)) Set.univ) := by
intro b
by_cases hbs : b ∈ s
· simpa [hbs]
· simp [hbs]
have : ∫⁻ b, s.indicator (fun _ ↦ r) b ∂(κ.fst a) ≤ κ.fst a s :=
(lintegral_mono h_2_le).trans_eq (h_eq s hs)
rw [lintegral_indicator_const hs] at this
contrapose! this with h_ne_zero
conv_lhs => rw [← one_mul (κ.fst a s)]
exact ENNReal.mul_lt_mul_right' h_ne_zero (measure_ne_top _ _) hr
· rw [ae_const_le_iff_forall_lt_measure_zero]
intro r hr
let s := {b | κCond (a, b) Set.univ ≤ r}
have hs : MeasurableSet s := h_meas measurableSet_Iic
have h_2_le : s.indicator (fun b ↦ (κCond (a, b)) Set.univ) ≤ s.indicator (fun _ ↦ r) := by
intro b
by_cases hbs : b ∈ s
· simpa [hbs]
· simp [hbs]
have : κ.fst a s ≤ ∫⁻ b, s.indicator (fun _ ↦ r) b ∂(κ.fst a) :=
(h_eq s hs).symm.trans_le (lintegral_mono h_2_le)
rw [lintegral_indicator_const hs] at this
contrapose! this with h_ne_zero
conv_rhs => rw [← one_mul (κ.fst a s)]
exact ENNReal.mul_lt_mul_right' h_ne_zero (measure_ne_top _ _) hr
/-! #### Existence of a disintegrating kernel in a countable space -/
section Countable
variable [Countable α] (κCond : α → Kernel β Ω)
/-- Auxiliary definition for `ProbabilityTheory.Kernel.condKernel`.
A conditional kernel for `κ : Kernel α (β × Ω)` where `α` is countable and `Ω` is a measurable
space. -/
noncomputable def condKernelCountable (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) :
Kernel (α × β) Ω where
toFun p := κCond p.1 p.2
measurable' := by
change Measurable ((fun q : β × α ↦ (κCond q.2) q.1) ∘ Prod.swap)
refine (measurable_from_prod_countable' (fun a ↦ (κCond a).measurable) ?_).comp measurable_swap
· intro x y hx hy
simpa using DFunLike.congr (h_atom _ _ hy) rfl
lemma condKernelCountable_apply (h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y)
(p : α × β) : condKernelCountable κCond h_atom p = κCond p.1 p.2 := rfl
instance condKernelCountable.instIsMarkovKernel [∀ a, IsMarkovKernel (κCond a)]
(h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) :
IsMarkovKernel (condKernelCountable κCond h_atom) where
isProbabilityMeasure p := (‹∀ a, IsMarkovKernel (κCond a)› p.1).isProbabilityMeasure p.2
instance condKernelCountable.instIsCondKernel [∀ a, IsMarkovKernel (κCond a)]
(h_atom : ∀ x y, x ∈ measurableAtom y → κCond x = κCond y) (κ : Kernel α (β × Ω))
[IsSFiniteKernel κ] [∀ a, (κ a).IsCondKernel (κCond a)] :
κ.IsCondKernel (condKernelCountable κCond h_atom) := by
constructor
ext a s hs
conv_rhs => rw [← (κ a).disintegrate (κCond a)]
simp_rw [compProd_apply hs, condKernelCountable_apply, Measure.compProd_apply hs]
congr
end Countable
end ProbabilityTheory.Kernel
| Mathlib/Probability/Kernel/Disintegration/Basic.lean | 439 | 448 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Data.Fintype.Card
import Mathlib.Algebra.Order.BigOperators.Group.Multiset
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Data.Multiset.OrderedMonoid
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Algebra.BigOperators.Group.Finset.Sigma
import Mathlib.Data.Multiset.Powerset
/-!
# Big operators on a finset in ordered groups
This file contains the results concerning the interaction of multiset big operators with ordered
groups/monoids.
-/
assert_not_exists Ring
open Function
variable {ι α β M N G k R : Type*}
namespace Finset
section OrderedCommMonoid
variable [CommMonoid M] [CommMonoid N] [PartialOrder N] [IsOrderedMonoid N]
/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map
submultiplicative on `{x | p x}`, i.e., `p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be
a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then
`f (∏ x ∈ s, g x) ≤ ∏ x ∈ s, f (g x)`. -/
@[to_additive le_sum_nonempty_of_subadditive_on_pred]
theorem le_prod_nonempty_of_submultiplicative_on_pred (f : M → N) (p : M → Prop)
(h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))
(g : ι → M) (s : Finset ι) (hs_nonempty : s.Nonempty) (hs : ∀ i ∈ s, p (g i)) :
f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
refine le_trans
(Multiset.le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul _ ?_ ?_) ?_
· simp [hs_nonempty.ne_empty]
· exact Multiset.forall_mem_map_iff.mpr hs
rw [Multiset.map_map]
rfl
/-- Let `{x | p x}` be an additive subsemigroup of an additive commutative monoid `M`. Let
`f : M → N` be a map subadditive on `{x | p x}`, i.e., `p x → p y → f (x + y) ≤ f x + f y`. Let
`g i`, `i ∈ s`, be a nonempty finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then
`f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/
add_decl_doc le_sum_nonempty_of_subadditive_on_pred
/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y` and `g i`, `i ∈ s`, is a
nonempty finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/
@[to_additive le_sum_nonempty_of_subadditive]
theorem le_prod_nonempty_of_submultiplicative (f : M → N) (h_mul : ∀ x y, f (x * y) ≤ f x * f y)
{s : Finset ι} (hs : s.Nonempty) (g : ι → M) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) :=
le_prod_nonempty_of_submultiplicative_on_pred f (fun _ ↦ True) (fun x y _ _ ↦ h_mul x y)
(fun _ _ _ _ ↦ trivial) g s hs fun _ _ ↦ trivial
/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y` and `g i`, `i ∈ s`, is a
nonempty finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/
add_decl_doc le_sum_nonempty_of_subadditive
/-- Let `{x | p x}` be a subsemigroup of a commutative monoid `M`. Let `f : M → N` be a map
such that `f 1 = 1` and `f` is submultiplicative on `{x | p x}`, i.e.,
`p x → p y → f (x * y) ≤ f x * f y`. Let `g i`, `i ∈ s`, be a finite family of elements of `M` such
that `∀ i ∈ s, p (g i)`. Then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/
@[to_additive le_sum_of_subadditive_on_pred]
theorem le_prod_of_submultiplicative_on_pred (f : M → N) (p : M → Prop) (h_one : f 1 = 1)
(h_mul : ∀ x y, p x → p y → f (x * y) ≤ f x * f y) (hp_mul : ∀ x y, p x → p y → p (x * y))
(g : ι → M) {s : Finset ι} (hs : ∀ i ∈ s, p (g i)) : f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
rcases eq_empty_or_nonempty s with (rfl | hs_nonempty)
· simp [h_one]
· exact le_prod_nonempty_of_submultiplicative_on_pred f p h_mul hp_mul g s hs_nonempty hs
/-- Let `{x | p x}` be a subsemigroup of a commutative additive monoid `M`. Let `f : M → N` be a map
such that `f 0 = 0` and `f` is subadditive on `{x | p x}`, i.e. `p x → p y → f (x + y) ≤ f x + f y`.
Let `g i`, `i ∈ s`, be a finite family of elements of `M` such that `∀ i ∈ s, p (g i)`. Then
`f (∑ x ∈ s, g x) ≤ ∑ x ∈ s, f (g x)`. -/
add_decl_doc le_sum_of_subadditive_on_pred
/-- If `f : M → N` is a submultiplicative function, `f (x * y) ≤ f x * f y`, `f 1 = 1`, and `g i`,
`i ∈ s`, is a finite family of elements of `M`, then `f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i)`. -/
@[to_additive le_sum_of_subadditive]
theorem le_prod_of_submultiplicative (f : M → N) (h_one : f 1 = 1)
(h_mul : ∀ x y, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :
f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
refine le_trans (Multiset.le_prod_of_submultiplicative f h_one h_mul _) ?_
rw [Multiset.map_map]
rfl
/-- If `f : M → N` is a subadditive function, `f (x + y) ≤ f x + f y`, `f 0 = 0`, and `g i`,
`i ∈ s`, is a finite family of elements of `M`, then `f (∑ i ∈ s, g i) ≤ ∑ i ∈ s, f (g i)`. -/
add_decl_doc le_sum_of_subadditive
variable {f g : ι → N} {s t : Finset ι}
/-- In an ordered commutative monoid, if each factor `f i` of one finite product is less than or
equal to the corresponding factor `g i` of another finite product, then
`∏ i ∈ s, f i ≤ ∏ i ∈ s, g i`. -/
@[to_additive (attr := gcongr) sum_le_sum]
theorem prod_le_prod' (h : ∀ i ∈ s, f i ≤ g i) : ∏ i ∈ s, f i ≤ ∏ i ∈ s, g i :=
Multiset.prod_map_le_prod_map f g h
attribute [bound] sum_le_sum
/-- In an ordered additive commutative monoid, if each summand `f i` of one finite sum is less than
or equal to the corresponding summand `g i` of another finite sum, then
`∑ i ∈ s, f i ≤ ∑ i ∈ s, g i`. -/
add_decl_doc sum_le_sum
@[to_additive sum_nonneg]
theorem one_le_prod' (h : ∀ i ∈ s, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i :=
le_trans (by rw [prod_const_one]) (prod_le_prod' h)
@[to_additive Finset.sum_nonneg']
theorem one_le_prod'' (h : ∀ i : ι, 1 ≤ f i) : 1 ≤ ∏ i ∈ s, f i :=
Finset.one_le_prod' fun i _ ↦ h i
@[to_additive sum_nonpos]
theorem prod_le_one' (h : ∀ i ∈ s, f i ≤ 1) : ∏ i ∈ s, f i ≤ 1 :=
(prod_le_prod' h).trans_eq (by rw [prod_const_one])
@[to_additive (attr := gcongr) sum_le_sum_of_subset_of_nonneg]
theorem prod_le_prod_of_subset_of_one_le' (h : s ⊆ t) (hf : ∀ i ∈ t, i ∉ s → 1 ≤ f i) :
∏ i ∈ s, f i ≤ ∏ i ∈ t, f i := by
classical calc
∏ i ∈ s, f i ≤ (∏ i ∈ t \ s, f i) * ∏ i ∈ s, f i :=
le_mul_of_one_le_left' <| one_le_prod' <| by simpa only [mem_sdiff, and_imp]
_ = ∏ i ∈ t \ s ∪ s, f i := (prod_union sdiff_disjoint).symm
_ = ∏ i ∈ t, f i := by rw [sdiff_union_of_subset h]
@[to_additive sum_mono_set_of_nonneg]
theorem prod_mono_set_of_one_le' (hf : ∀ x, 1 ≤ f x) : Monotone fun s ↦ ∏ x ∈ s, f x :=
fun _ _ hst ↦ prod_le_prod_of_subset_of_one_le' hst fun x _ _ ↦ hf x
@[to_additive sum_le_univ_sum_of_nonneg]
theorem prod_le_univ_prod_of_one_le' [Fintype ι] {s : Finset ι} (w : ∀ x, 1 ≤ f x) :
∏ x ∈ s, f x ≤ ∏ x, f x :=
prod_le_prod_of_subset_of_one_le' (subset_univ s) fun a _ _ ↦ w a
@[to_additive sum_eq_zero_iff_of_nonneg]
theorem prod_eq_one_iff_of_one_le' :
(∀ i ∈ s, 1 ≤ f i) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) := by
classical
refine Finset.induction_on s
(fun _ ↦ ⟨fun _ _ h ↦ False.elim (Finset.not_mem_empty _ h), fun _ ↦ rfl⟩) ?_
intro a s ha ih H
have : ∀ i ∈ s, 1 ≤ f i := fun _ ↦ H _ ∘ mem_insert_of_mem
rw [prod_insert ha, mul_eq_one_iff_of_one_le (H _ <| mem_insert_self _ _) (one_le_prod' this),
forall_mem_insert, ih this]
@[to_additive sum_eq_zero_iff_of_nonpos]
theorem prod_eq_one_iff_of_le_one' :
(∀ i ∈ s, f i ≤ 1) → ((∏ i ∈ s, f i) = 1 ↔ ∀ i ∈ s, f i = 1) :=
prod_eq_one_iff_of_one_le' (N := Nᵒᵈ)
@[to_additive single_le_sum]
theorem single_le_prod' (hf : ∀ i ∈ s, 1 ≤ f i) {a} (h : a ∈ s) : f a ≤ ∏ x ∈ s, f x :=
calc
f a = ∏ i ∈ {a}, f i := (prod_singleton _ _).symm
_ ≤ ∏ i ∈ s, f i :=
prod_le_prod_of_subset_of_one_le' (singleton_subset_iff.2 h) fun i hi _ ↦ hf i hi
@[to_additive]
lemma mul_le_prod {i j : ι} (hf : ∀ i ∈ s, 1 ≤ f i) (hi : i ∈ s) (hj : j ∈ s) (hne : i ≠ j) :
f i * f j ≤ ∏ k ∈ s, f k :=
calc
f i * f j = ∏ k ∈ .cons i {j} (by simpa), f k := by rw [prod_cons, prod_singleton]
_ ≤ ∏ k ∈ s, f k := by
refine prod_le_prod_of_subset_of_one_le' ?_ fun k hk _ ↦ hf k hk
simp [cons_subset, *]
@[to_additive sum_le_card_nsmul]
theorem prod_le_pow_card (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, f x ≤ n) :
s.prod f ≤ n ^ #s := by
refine (Multiset.prod_le_pow_card (s.val.map f) n ?_).trans ?_
· simpa using h
· simp
@[to_additive card_nsmul_le_sum]
theorem pow_card_le_prod (s : Finset ι) (f : ι → N) (n : N) (h : ∀ x ∈ s, n ≤ f x) :
n ^ #s ≤ s.prod f := Finset.prod_le_pow_card (N := Nᵒᵈ) _ _ _ h
theorem card_biUnion_le_card_mul [DecidableEq β] (s : Finset ι) (f : ι → Finset β) (n : ℕ)
(h : ∀ a ∈ s, #(f a) ≤ n) : #(s.biUnion f) ≤ #s * n :=
card_biUnion_le.trans <| sum_le_card_nsmul _ _ _ h
variable {ι' : Type*} [DecidableEq ι']
@[to_additive sum_fiberwise_le_sum_of_sum_fiber_nonneg]
theorem prod_fiberwise_le_prod_of_one_le_prod_fiber' {t : Finset ι'} {g : ι → ι'} {f : ι → N}
(h : ∀ y ∉ t, (1 : N) ≤ ∏ x ∈ s with g x = y, f x) :
(∏ y ∈ t, ∏ x ∈ s with g x = y, f x) ≤ ∏ x ∈ s, f x :=
calc
(∏ y ∈ t, ∏ x ∈ s with g x = y, f x) ≤
∏ y ∈ t ∪ s.image g, ∏ x ∈ s with g x = y, f x :=
prod_le_prod_of_subset_of_one_le' subset_union_left fun y _ ↦ h y
_ = ∏ x ∈ s, f x :=
prod_fiberwise_of_maps_to (fun _ hx ↦ mem_union.2 <| Or.inr <| mem_image_of_mem _ hx) _
@[to_additive sum_le_sum_fiberwise_of_sum_fiber_nonpos]
theorem prod_le_prod_fiberwise_of_prod_fiber_le_one' {t : Finset ι'} {g : ι → ι'} {f : ι → N}
(h : ∀ y ∉ t, ∏ x ∈ s with g x = y, f x ≤ 1) :
∏ x ∈ s, f x ≤ ∏ y ∈ t, ∏ x ∈ s with g x = y, f x :=
prod_fiberwise_le_prod_of_one_le_prod_fiber' (N := Nᵒᵈ) h
@[to_additive]
lemma prod_image_le_of_one_le
{g : ι → ι'} {f : ι' → N} (hf : ∀ u ∈ s.image g, 1 ≤ f u) :
∏ u ∈ s.image g, f u ≤ ∏ u ∈ s, f (g u) := by
rw [prod_comp f g]
refine prod_le_prod' fun a hag ↦ ?_
obtain ⟨i, hi, hig⟩ := Finset.mem_image.mp hag
apply le_self_pow (hf a hag)
rw [← Nat.pos_iff_ne_zero, card_pos]
exact ⟨i, mem_filter.mpr ⟨hi, hig⟩⟩
end OrderedCommMonoid
@[to_additive]
lemma max_prod_le [CommMonoid M] [LinearOrder M] [IsOrderedMonoid M] {f g : ι → M} {s : Finset ι} :
max (s.prod f) (s.prod g) ≤ s.prod (fun i ↦ max (f i) (g i)) :=
Multiset.max_prod_le
@[to_additive]
lemma prod_min_le [CommMonoid M] [LinearOrder M] [IsOrderedMonoid M] {f g : ι → M} {s : Finset ι} :
s.prod (fun i ↦ min (f i) (g i)) ≤ min (s.prod f) (s.prod g) :=
Multiset.prod_min_le
theorem abs_sum_le_sum_abs {G : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G]
(f : ι → G) (s : Finset ι) :
|∑ i ∈ s, f i| ≤ ∑ i ∈ s, |f i| := le_sum_of_subadditive _ abs_zero abs_add s f
theorem abs_sum_of_nonneg {G : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G]
{f : ι → G} {s : Finset ι}
(hf : ∀ i ∈ s, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by
rw [abs_of_nonneg (Finset.sum_nonneg hf)]
theorem abs_sum_of_nonneg' {G : Type*} [AddCommGroup G] [LinearOrder G] [IsOrderedAddMonoid G]
{f : ι → G} {s : Finset ι}
(hf : ∀ i, 0 ≤ f i) : |∑ i ∈ s, f i| = ∑ i ∈ s, f i := by
rw [abs_of_nonneg (Finset.sum_nonneg' hf)]
section CommMonoid
variable [CommMonoid α] [LE α] [MulLeftMono α] {s : Finset ι} {f : ι → α}
@[to_additive (attr := simp)]
lemma mulLECancellable_prod :
MulLECancellable (∏ i ∈ s, f i) ↔ ∀ ⦃i⦄, i ∈ s → MulLECancellable (f i) := by
induction' s using Finset.cons_induction with i s hi ih <;> simp [*]
end CommMonoid
section Pigeonhole
variable [DecidableEq β]
theorem card_le_mul_card_image_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}
(Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ b ∈ t, #{a ∈ s | f a = b} ≤ n) : #s ≤ n * #t :=
calc
#s = ∑ b ∈ t, #{a ∈ s | f a = b} := card_eq_sum_card_fiberwise Hf
_ ≤ ∑ _b ∈ t, n := sum_le_sum hn
_ = _ := by simp [mul_comm]
theorem card_le_mul_card_image {f : α → β} (s : Finset α) (n : ℕ)
(hn : ∀ b ∈ s.image f, #{a ∈ s | f a = b} ≤ n) : #s ≤ n * #(s.image f) :=
card_le_mul_card_image_of_maps_to (fun _ ↦ mem_image_of_mem _) n hn
|
theorem mul_card_image_le_card_of_maps_to {f : α → β} {s : Finset α} {t : Finset β}
(Hf : ∀ a ∈ s, f a ∈ t) (n : ℕ) (hn : ∀ b ∈ t, n ≤ #{a ∈ s | f a = b}) :
| Mathlib/Algebra/Order/BigOperators/Group/Finset.lean | 272 | 274 |
/-
Copyright (c) 2020 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard
-/
import Mathlib.RingTheory.AdicCompletion.Basic
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
import Mathlib.RingTheory.LocalRing.RingHom.Basic
import Mathlib.RingTheory.UniqueFactorizationDomain.Basic
import Mathlib.RingTheory.Valuation.PrimeMultiplicity
import Mathlib.RingTheory.Valuation.ValuationRing
/-!
# Discrete valuation rings
This file defines discrete valuation rings (DVRs) and develops a basic interface
for them.
## Important definitions
There are various definitions of a DVR in the literature; we define a DVR to be a local PID
which is not a field (the first definition in Wikipedia) and prove that this is equivalent
to being a PID with a unique non-zero prime ideal (the definition in Serre's
book "Local Fields").
Let R be an integral domain, assumed to be a principal ideal ring and a local ring.
* `IsDiscreteValuationRing R` : a predicate expressing that R is a DVR.
### Definitions
* `addVal R : AddValuation R PartENat` : the additive valuation on a DVR.
## Implementation notes
It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible.
We do not hence define `Uniformizer` at all, because we can use `Irreducible` instead.
## Tags
discrete valuation ring
-/
universe u
open Ideal IsLocalRing
/-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which
is not a field. -/
class IsDiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] : Prop
extends IsPrincipalIdealRing R, IsLocalRing R where
not_a_field' : maximalIdeal R ≠ ⊥
namespace IsDiscreteValuationRing
variable (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R]
theorem not_a_field : maximalIdeal R ≠ ⊥ :=
not_a_field'
/-- A discrete valuation ring `R` is not a field. -/
theorem not_isField : ¬IsField R :=
IsLocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R)
variable {R}
open PrincipalIdealRing
theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommSemiring R] [IsLocalRing R]
[IsDomain R] (ϖ : R) (hϖ : ϖ ≠ 0) (h : maximalIdeal R = Ideal.span {ϖ}) : Irreducible ϖ := by
have h2 : ¬IsUnit ϖ := show ϖ ∈ maximalIdeal R from h.symm ▸ Submodule.mem_span_singleton_self ϖ
refine ⟨h2, ?_⟩
intro a b hab
by_contra! h
obtain ⟨ha : a ∈ maximalIdeal R, hb : b ∈ maximalIdeal R⟩ := h
rw [h, mem_span_singleton'] at ha hb
rcases ha with ⟨a, rfl⟩
rcases hb with ⟨b, rfl⟩
rw [show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)) by ring] at hab
apply hϖ
apply eq_zero_of_mul_eq_self_right _ hab.symm
exact fun hh => h2 (isUnit_of_dvd_one ⟨_, hh.symm⟩)
/-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the
maximal ideal of `R`. -/
theorem irreducible_iff_uniformizer (ϖ : R) : Irreducible ϖ ↔ maximalIdeal R = Ideal.span {ϖ} :=
⟨fun hϖ => (eq_maximalIdeal (isMaximal_of_irreducible hϖ)).symm,
fun h => irreducible_of_span_eq_maximalIdeal ϖ
(fun e => not_a_field R <| by rwa [h, span_singleton_eq_bot]) h⟩
theorem _root_.Irreducible.maximalIdeal_eq {ϖ : R} (h : Irreducible ϖ) :
maximalIdeal R = Ideal.span {ϖ} :=
(irreducible_iff_uniformizer _).mp h
variable (R)
/-- Uniformizers exist in a DVR. -/
theorem exists_irreducible : ∃ ϖ : R, Irreducible ϖ := by
simp_rw [irreducible_iff_uniformizer]
exact (IsPrincipalIdealRing.principal <| maximalIdeal R).principal
/-- Uniformizers exist in a DVR. -/
theorem exists_prime : ∃ ϖ : R, Prime ϖ :=
(exists_irreducible R).imp fun _ => irreducible_iff_prime.1
/-- An integral domain is a DVR iff it's a PID with a unique non-zero prime ideal. -/
theorem iff_pid_with_one_nonzero_prime (R : Type u) [CommRing R] [IsDomain R] :
IsDiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by
constructor
· intro RDVR
rcases id RDVR with ⟨Rlocal⟩
constructor
· assumption
use IsLocalRing.maximalIdeal R
constructor
· exact ⟨Rlocal, inferInstance⟩
· rintro Q ⟨hQ1, hQ2⟩
obtain ⟨q, rfl⟩ := (IsPrincipalIdealRing.principal Q).1
have hq : q ≠ 0 := by
rintro rfl
apply hQ1
simp
rw [submodule_span_eq, span_singleton_prime hq] at hQ2
replace hQ2 := hQ2.irreducible
rw [irreducible_iff_uniformizer] at hQ2
exact hQ2.symm
· rintro ⟨RPID, Punique⟩
haveI : IsLocalRing R := IsLocalRing.of_unique_nonzero_prime Punique
refine { not_a_field' := ?_ }
rcases Punique with ⟨P, ⟨hP1, hP2⟩, _⟩
have hPM : P ≤ maximalIdeal R := le_maximalIdeal hP2.1
intro h
rw [h, le_bot_iff] at hPM
exact hP1 hPM
theorem associated_of_irreducible {a b : R} (ha : Irreducible a) (hb : Irreducible b) :
Associated a b := by
rw [irreducible_iff_uniformizer] at ha hb
rw [← span_singleton_eq_span_singleton, ← ha, hb]
variable (R : Type*)
/-- Alternative characterisation of discrete valuation rings. -/
def HasUnitMulPowIrreducibleFactorization [CommRing R] : Prop :=
∃ p : R, Irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ n : ℕ, Associated (p ^ n) x
namespace HasUnitMulPowIrreducibleFactorization
variable {R} [CommRing R]
theorem unique_irreducible (hR : HasUnitMulPowIrreducibleFactorization R)
⦃p q : R⦄ (hp : Irreducible p) (hq : Irreducible q) :
Associated p q := by
rcases hR with ⟨ϖ, hϖ, hR⟩
suffices ∀ {p : R} (_ : Irreducible p), Associated p ϖ by
apply Associated.trans (this hp) (this hq).symm
clear hp hq p q
intro p hp
obtain ⟨n, hn⟩ := hR hp.ne_zero
have : Irreducible (ϖ ^ n) := hn.symm.irreducible hp
rcases lt_trichotomy n 1 with (H | rfl | H)
· obtain rfl : n = 0 := by
clear hn this
revert H n
decide
simp [not_irreducible_one, pow_zero] at this
· simpa only [pow_one] using hn.symm
· obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := Nat.exists_eq_add_of_lt H
rw [pow_succ'] at this
rcases this.isUnit_or_isUnit rfl with (H0 | H0)
· exact (hϖ.not_isUnit H0).elim
· rw [add_comm, pow_succ'] at H0
exact (hϖ.not_isUnit (isUnit_of_mul_isUnit_left H0)).elim
variable [IsDomain R]
/-- An integral domain in which there is an irreducible element `p`
such that every nonzero element is associated to a power of `p` is a unique factorization domain.
See `IsDiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization`. -/
theorem toUniqueFactorizationMonoid (hR : HasUnitMulPowIrreducibleFactorization R) :
UniqueFactorizationMonoid R :=
let p := Classical.choose hR
let spec := Classical.choose_spec hR
UniqueFactorizationMonoid.of_exists_prime_factors fun x hx => by
use Multiset.replicate (Classical.choose (spec.2 hx)) p
constructor
· intro q hq
have hpq := Multiset.eq_of_mem_replicate hq
rw [hpq]
refine ⟨spec.1.ne_zero, spec.1.not_isUnit, ?_⟩
intro a b h
by_cases ha : a = 0
· rw [ha]
simp only [true_or, dvd_zero]
obtain ⟨m, u, rfl⟩ := spec.2 ha
rw [mul_assoc, mul_left_comm, Units.dvd_mul_left] at h
rw [Units.dvd_mul_right]
by_cases hm : m = 0
· simp only [hm, one_mul, pow_zero] at h ⊢
right
exact h
left
obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hm
rw [pow_succ']
apply dvd_mul_of_dvd_left dvd_rfl _
· rw [Multiset.prod_replicate]
exact Classical.choose_spec (spec.2 hx)
theorem of_ufd_of_unique_irreducible [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p)
(h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) :
HasUnitMulPowIrreducibleFactorization R := by
obtain ⟨p, hp⟩ := h₁
refine ⟨p, hp, ?_⟩
intro x hx
obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx
refine ⟨Multiset.card fx, ?_⟩
have H := hfx.2
rw [← Associates.mk_eq_mk_iff_associated] at H ⊢
rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate]
congr 1
symm
rw [Multiset.eq_replicate]
simp only [true_and, and_imp, Multiset.card_map, eq_self_iff_true, Multiset.mem_map, exists_imp]
rintro _ q hq rfl
rw [Associates.mk_eq_mk_iff_associated]
apply h₂ (hfx.1 _ hq) hp
end HasUnitMulPowIrreducibleFactorization
theorem aux_pid_of_ufd_of_unique_irreducible (R : Type u) [CommRing R] [IsDomain R]
[UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p)
(h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) :
IsPrincipalIdealRing R := by
classical
constructor
intro I
by_cases I0 : I = ⊥
· rw [I0]
use 0
simp only [Set.singleton_zero, Submodule.span_zero]
obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0 : R) := I.ne_bot_iff.mp I0
obtain ⟨p, _, H⟩ := HasUnitMulPowIrreducibleFactorization.of_ufd_of_unique_irreducible h₁ h₂
have ex : ∃ n : ℕ, p ^ n ∈ I := by
obtain ⟨n, u, rfl⟩ := H hx0
refine ⟨n, ?_⟩
simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hxI
constructor
use p ^ Nat.find ex
show I = Ideal.span _
apply le_antisymm
· intro r hr
by_cases hr0 : r = 0
· simp only [hr0, Submodule.zero_mem]
obtain ⟨n, u, rfl⟩ := H hr0
simp only [mem_span_singleton, Units.isUnit, IsUnit.dvd_mul_right]
apply pow_dvd_pow
apply Nat.find_min'
simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hr
· rw [span_singleton_le_iff_mem]
exact Nat.find_spec ex
/-- A unique factorization domain with at least one irreducible element
in which all irreducible elements are associated
is a discrete valuation ring.
-/
theorem of_ufd_of_unique_irreducible {R : Type u} [CommRing R] [IsDomain R]
[UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p)
(h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) :
IsDiscreteValuationRing R := by
rw [iff_pid_with_one_nonzero_prime]
haveI PID : IsPrincipalIdealRing R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂
obtain ⟨p, hp⟩ := h₁
refine ⟨PID, ⟨Ideal.span {p}, ⟨?_, ?_⟩, ?_⟩⟩
· rw [Submodule.ne_bot_iff]
exact ⟨p, Ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩
· rwa [Ideal.span_singleton_prime hp.ne_zero, ← UniqueFactorizationMonoid.irreducible_iff_prime]
· intro I
rw [← Submodule.IsPrincipal.span_singleton_generator I]
rintro ⟨I0, hI⟩
apply span_singleton_eq_span_singleton.mpr
apply h₂ _ hp
rw [Ne, Submodule.span_singleton_eq_bot] at I0
rwa [UniqueFactorizationMonoid.irreducible_iff_prime, ← Ideal.span_singleton_prime I0]
/-- An integral domain in which there is an irreducible element `p`
such that every nonzero element is associated to a power of `p`
is a discrete valuation ring.
-/
theorem ofHasUnitMulPowIrreducibleFactorization {R : Type u} [CommRing R] [IsDomain R]
(hR : HasUnitMulPowIrreducibleFactorization R) : IsDiscreteValuationRing R := by
letI : UniqueFactorizationMonoid R := hR.toUniqueFactorizationMonoid
apply of_ufd_of_unique_irreducible _ hR.unique_irreducible
obtain ⟨p, hp, H⟩ := hR
exact ⟨p, hp⟩
/- If a ring is equivalent to a DVR, it is itself a DVR. -/
theorem RingEquivClass.isDiscreteValuationRing {A B E : Type*} [CommRing A] [IsDomain A]
[CommRing B] [IsDomain B] [IsDiscreteValuationRing A] [EquivLike E A B] [RingEquivClass E A B]
(e : E) : IsDiscreteValuationRing B where
principal := (isPrincipalIdealRing_iff _).1 <|
IsPrincipalIdealRing.of_surjective _ (e : A ≃+* B).surjective
__ : IsLocalRing B := (e : A ≃+* B).isLocalRing
not_a_field' := by
obtain ⟨a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr
<| IsDiscreteValuationRing.not_a_field A)
rw [Submodule.ne_bot_iff]
refine ⟨e a, ⟨?_, by simp only [ne_eq, EmbeddingLike.map_eq_zero_iff, ZeroMemClass.coe_eq_zero,
ha, not_false_eq_true]⟩⟩
rw [IsLocalRing.mem_maximalIdeal, map_mem_nonunits_iff e, ← IsLocalRing.mem_maximalIdeal]
exact a.2
section
variable [CommRing R] [IsDomain R] [IsDiscreteValuationRing R]
variable {R}
theorem associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) :
∃ n : ℕ, Associated x (ϖ ^ n) := by
have : WfDvdMonoid R := IsNoetherianRing.wfDvdMonoid
obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx
use Multiset.card fx
have H := hfx.2
rw [← Associates.mk_eq_mk_iff_associated] at H ⊢
rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate]
congr 1
rw [Multiset.eq_replicate]
simp only [true_and, and_imp, Multiset.card_map, eq_self_iff_true, Multiset.mem_map, exists_imp]
rintro _ _ _ rfl
rw [Associates.mk_eq_mk_iff_associated]
refine associated_of_irreducible _ ?_ hirr
apply hfx.1
assumption
theorem eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) :
∃ (n : ℕ) (u : Rˣ), x = u * ϖ ^ n := by
obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr
obtain ⟨u, rfl⟩ := hn.symm
use n, u
apply mul_comm
open Submodule.IsPrincipal
theorem ideal_eq_span_pow_irreducible {s : Ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : Irreducible ϖ) :
∃ n : ℕ, s = Ideal.span {ϖ ^ n} := by
have gen_ne_zero : generator s ≠ 0 := by
rw [Ne, ← eq_bot_iff_generator_eq_zero]
assumption
rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩
use n
have : span _ = _ := Ideal.span_singleton_generator s
rw [← this, ← hnu, span_singleton_eq_span_singleton]
use u
theorem unit_mul_pow_congr_pow {p q : R} (hp : Irreducible p) (hq : Irreducible q) (u v : Rˣ)
(m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) : m = n := by
have key : Associated (Multiset.replicate m p).prod (Multiset.replicate n q).prod := by
rw [Multiset.prod_replicate, Multiset.prod_replicate, Associated]
refine ⟨u * v⁻¹, ?_⟩
simp only [Units.val_mul]
rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, Units.mul_inv, one_mul]
have := by
refine Multiset.card_eq_card_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ key)
all_goals
| intro x hx
obtain rfl := Multiset.eq_of_mem_replicate hx
assumption
simpa only [Multiset.card_replicate]
theorem unit_mul_pow_congr_unit {ϖ : R} (hirr : Irreducible ϖ) (u v : Rˣ) (m n : ℕ)
(h : ↑u * ϖ ^ m = v * ϖ ^ n) : u = v := by
obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h
rw [← sub_eq_zero] at h
rw [← sub_mul, mul_eq_zero] at h
rcases h with h | h
· rw [sub_eq_zero] at h
exact mod_cast h
· apply (hirr.ne_zero (pow_eq_zero h)).elim
| Mathlib/RingTheory/DiscreteValuationRing/Basic.lean | 364 | 377 |
/-
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)
(h : S.pOpcycles ≫ f₁ = S.pOpcycles ≫ f₂) : f₁ = f₂ := by
simpa only [opcycles_ext_iff]
lemma isIso_pOpcycles (hf : S.f = 0) : IsIso S.pOpcycles :=
RightHomologyData.isIso_p _ hf
/-- When `S.f = 0`, this is the canonical isomorphism `S.opcycles ≅ S.X₂`
induced by `S.pOpcycles`. -/
@[simps! inv]
noncomputable def opcyclesIsoX₂ (hf : S.f = 0) : S.opcycles ≅ S.X₂ := by
have := S.isIso_pOpcycles hf
exact (asIso S.pOpcycles).symm
@[reassoc (attr := simp)]
lemma opcyclesIsoX₂_inv_hom_id (hf : S.f = 0) :
S.pOpcycles ≫ (S.opcyclesIsoX₂ hf).hom = 𝟙 _ := (S.opcyclesIsoX₂ hf).inv_hom_id
@[reassoc (attr := simp)]
lemma opcyclesIsoX₂_hom_inv_id (hf : S.f = 0) :
(S.opcyclesIsoX₂ hf).hom ≫ S.pOpcycles = 𝟙 _ := (S.opcyclesIsoX₂ hf).hom_inv_id
lemma isIso_rightHomologyι (hg : S.g = 0) : IsIso S.rightHomologyι :=
RightHomologyData.isIso_ι _ hg
/-- When `S.g = 0`, this is the canonical isomorphism `S.opcycles ≅ S.rightHomology` induced
by `S.rightHomologyι`. -/
@[simps! inv]
noncomputable def opcyclesIsoRightHomology (hg : S.g = 0) : S.opcycles ≅ S.rightHomology := by
have := S.isIso_rightHomologyι hg
exact (asIso S.rightHomologyι).symm
@[reassoc (attr := simp)]
lemma opcyclesIsoRightHomology_inv_hom_id (hg : S.g = 0) :
S.rightHomologyι ≫ (S.opcyclesIsoRightHomology hg).hom = 𝟙 _ :=
(S.opcyclesIsoRightHomology hg).inv_hom_id
@[reassoc (attr := simp)]
lemma opcyclesIsoRightHomology_hom_inv_id (hg : S.g = 0) :
(S.opcyclesIsoRightHomology hg).hom ≫ S.rightHomologyι = 𝟙 _ :=
(S.opcyclesIsoRightHomology hg).hom_inv_id
end
section
variable (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData)
/-- The (unique) right homology map data associated to a morphism of short complexes that
are both equipped with right homology data. -/
def rightHomologyMapData : RightHomologyMapData φ h₁ h₂ := default
/-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and right homology data `h₁` and `h₂`
for `S₁` and `S₂` respectively, this is the induced right homology map `h₁.H ⟶ h₁.H`. -/
def rightHomologyMap' : h₁.H ⟶ h₂.H := (rightHomologyMapData φ _ _).φH
/-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and right homology data `h₁` and `h₂`
for `S₁` and `S₂` respectively, this is the induced morphism `h₁.K ⟶ h₁.K` on opcycles. -/
def opcyclesMap' : h₁.Q ⟶ h₂.Q := (rightHomologyMapData φ _ _).φQ
@[reassoc (attr := simp)]
lemma p_opcyclesMap' : h₁.p ≫ opcyclesMap' φ h₁ h₂ = φ.τ₂ ≫ h₂.p :=
RightHomologyMapData.commp _
@[reassoc (attr := simp)]
lemma opcyclesMap'_g' : opcyclesMap' φ h₁ h₂ ≫ h₂.g' = h₁.g' ≫ φ.τ₃ := by
simp only [← cancel_epi h₁.p, assoc, φ.comm₂₃, p_opcyclesMap'_assoc,
RightHomologyData.p_g'_assoc, RightHomologyData.p_g']
@[reassoc (attr := simp)]
lemma rightHomologyι_naturality' :
rightHomologyMap' φ h₁ h₂ ≫ h₂.ι = h₁.ι ≫ opcyclesMap' φ h₁ h₂ :=
RightHomologyMapData.commι _
end
section
variable [HasRightHomology S₁] [HasRightHomology S₂] (φ : S₁ ⟶ S₂)
/-- The (right) homology map `S₁.rightHomology ⟶ S₂.rightHomology` induced by a morphism
`S₁ ⟶ S₂` of short complexes. -/
noncomputable def rightHomologyMap : S₁.rightHomology ⟶ S₂.rightHomology :=
rightHomologyMap' φ _ _
/-- The morphism `S₁.opcycles ⟶ S₂.opcycles` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/
noncomputable def opcyclesMap : S₁.opcycles ⟶ S₂.opcycles :=
opcyclesMap' φ _ _
@[reassoc (attr := simp)]
lemma p_opcyclesMap : S₁.pOpcycles ≫ opcyclesMap φ = φ.τ₂ ≫ S₂.pOpcycles :=
p_opcyclesMap' _ _ _
@[reassoc (attr := simp)]
lemma fromOpcycles_naturality : opcyclesMap φ ≫ S₂.fromOpcycles = S₁.fromOpcycles ≫ φ.τ₃ :=
opcyclesMap'_g' _ _ _
@[reassoc (attr := simp)]
lemma rightHomologyι_naturality :
rightHomologyMap φ ≫ S₂.rightHomologyι = S₁.rightHomologyι ≫ opcyclesMap φ :=
rightHomologyι_naturality' _ _ _
end
namespace RightHomologyMapData
variable {φ : S₁ ⟶ S₂} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData}
(γ : RightHomologyMapData φ h₁ h₂)
lemma rightHomologyMap'_eq : rightHomologyMap' φ h₁ h₂ = γ.φH :=
RightHomologyMapData.congr_φH (Subsingleton.elim _ _)
lemma opcyclesMap'_eq : opcyclesMap' φ h₁ h₂ = γ.φQ :=
RightHomologyMapData.congr_φQ (Subsingleton.elim _ _)
end RightHomologyMapData
@[simp]
lemma rightHomologyMap'_id (h : S.RightHomologyData) :
rightHomologyMap' (𝟙 S) h h = 𝟙 _ :=
(RightHomologyMapData.id h).rightHomologyMap'_eq
@[simp]
lemma opcyclesMap'_id (h : S.RightHomologyData) :
opcyclesMap' (𝟙 S) h h = 𝟙 _ :=
(RightHomologyMapData.id h).opcyclesMap'_eq
variable (S)
@[simp]
lemma rightHomologyMap_id [HasRightHomology S] :
rightHomologyMap (𝟙 S) = 𝟙 _ :=
rightHomologyMap'_id _
@[simp]
lemma opcyclesMap_id [HasRightHomology S] :
opcyclesMap (𝟙 S) = 𝟙 _ :=
opcyclesMap'_id _
@[simp]
lemma rightHomologyMap'_zero (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) :
rightHomologyMap' 0 h₁ h₂ = 0 :=
(RightHomologyMapData.zero h₁ h₂).rightHomologyMap'_eq
@[simp]
lemma opcyclesMap'_zero (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) :
opcyclesMap' 0 h₁ h₂ = 0 :=
(RightHomologyMapData.zero h₁ h₂).opcyclesMap'_eq
variable (S₁ S₂)
@[simp]
lemma rightHomologyMap_zero [HasRightHomology S₁] [HasRightHomology S₂] :
rightHomologyMap (0 : S₁ ⟶ S₂) = 0 :=
rightHomologyMap'_zero _ _
@[simp]
lemma opcyclesMap_zero [HasRightHomology S₁] [HasRightHomology S₂] :
opcyclesMap (0 : S₁ ⟶ S₂) = 0 :=
opcyclesMap'_zero _ _
| variable {S₁ S₂}
@[reassoc]
lemma rightHomologyMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃)
(h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) (h₃ : S₃.RightHomologyData) :
rightHomologyMap' (φ₁ ≫ φ₂) h₁ h₃ = rightHomologyMap' φ₁ h₁ h₂ ≫
rightHomologyMap' φ₂ h₂ h₃ := by
let γ₁ := rightHomologyMapData φ₁ h₁ h₂
let γ₂ := rightHomologyMapData φ₂ h₂ h₃
| Mathlib/Algebra/Homology/ShortComplex/RightHomology.lean | 691 | 699 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Order.Atoms
import Mathlib.Order.OrderIsoNat
import Mathlib.Order.RelIso.Set
import Mathlib.Order.SupClosed
import Mathlib.Order.SupIndep
import Mathlib.Order.Zorn
import Mathlib.Data.Finset.Order
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Data.Finite.Set
import Mathlib.Tactic.TFAE
/-!
# Compactness properties for complete lattices
For complete lattices, there are numerous equivalent ways to express the fact that the relation `>`
is well-founded. In this file we define three especially-useful characterisations and provide
proofs that they are indeed equivalent to well-foundedness.
## Main definitions
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `CompleteLattice.IsCompactElement`
* `IsCompactlyGenerated`
## Main results
The main result is that the following four conditions are equivalent for a complete lattice:
* `well_founded (>)`
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `∀ k, CompleteLattice.IsCompactElement k`
This is demonstrated by means of the following four lemmas:
* `CompleteLattice.WellFounded.isSupFiniteCompact`
* `CompleteLattice.IsSupFiniteCompact.isSupClosedCompact`
* `CompleteLattice.IsSupClosedCompact.wellFounded`
* `CompleteLattice.isSupFiniteCompact_iff_all_elements_compact`
We also show well-founded lattices are compactly generated
(`CompleteLattice.isCompactlyGenerated_of_wellFounded`).
## References
- [G. Călugăreanu, *Lattice Concepts of Module Theory*][calugareanu]
## Tags
complete lattice, well-founded, compact
-/
open Set
variable {ι : Sort*} {α : Type*} [CompleteLattice α] {f : ι → α}
namespace CompleteLattice
variable (α)
/-- A compactness property for a complete lattice is that any `sup`-closed non-empty subset
contains its `sSup`. -/
def IsSupClosedCompact : Prop :=
∀ (s : Set α) (_ : s.Nonempty), SupClosed s → sSup s ∈ s
/-- A compactness property for a complete lattice is that any subset has a finite subset with the
same `sSup`. -/
def IsSupFiniteCompact : Prop :=
∀ s : Set α, ∃ t : Finset α, ↑t ⊆ s ∧ sSup s = t.sup id
/-- An element `k` of a complete lattice is said to be compact if any set with `sSup`
above `k` has a finite subset with `sSup` above `k`. Such an element is also called
"finite" or "S-compact". -/
def IsCompactElement {α : Type*} [CompleteLattice α] (k : α) :=
∀ s : Set α, k ≤ sSup s → ∃ t : Finset α, ↑t ⊆ s ∧ k ≤ t.sup id
theorem isCompactElement_iff.{u} {α : Type u} [CompleteLattice α] (k : α) :
CompleteLattice.IsCompactElement k ↔
∀ (ι : Type u) (s : ι → α), k ≤ iSup s → ∃ t : Finset ι, k ≤ t.sup s := by
classical
constructor
· intro H ι s hs
obtain ⟨t, ht, ht'⟩ := H (Set.range s) hs
have : ∀ x : t, ∃ i, s i = x := fun x => ht x.prop
choose f hf using this
refine ⟨Finset.univ.image f, ht'.trans ?_⟩
rw [Finset.sup_le_iff]
intro b hb
rw [← show s (f ⟨b, hb⟩) = id b from hf _]
exact Finset.le_sup (Finset.mem_image_of_mem f <| Finset.mem_univ (Subtype.mk b hb))
· intro H s hs
obtain ⟨t, ht⟩ :=
H s Subtype.val
(by
delta iSup
rwa [Subtype.range_coe])
refine ⟨t.image Subtype.val, by simp, ht.trans ?_⟩
rw [Finset.sup_le_iff]
exact fun x hx => @Finset.le_sup _ _ _ _ _ id _ (Finset.mem_image_of_mem Subtype.val hx)
/-- An element `k` is compact if and only if any directed set with `sSup` above
`k` already got above `k` at some point in the set. -/
theorem isCompactElement_iff_le_of_directed_sSup_le (k : α) :
IsCompactElement k ↔
∀ s : Set α, s.Nonempty → DirectedOn (· ≤ ·) s → k ≤ sSup s → ∃ x : α, x ∈ s ∧ k ≤ x := by
classical
constructor
· intro hk s hne hdir hsup
obtain ⟨t, ht⟩ := hk s hsup
-- certainly every element of t is below something in s, since ↑t ⊆ s.
have t_below_s : ∀ x ∈ t, ∃ y ∈ s, x ≤ y := fun x hxt => ⟨x, ht.left hxt, le_rfl⟩
obtain ⟨x, ⟨hxs, hsupx⟩⟩ := Finset.sup_le_of_le_directed s hne hdir t t_below_s
exact ⟨x, ⟨hxs, le_trans ht.right hsupx⟩⟩
· intro hk s hsup
-- Consider the set of finite joins of elements of the (plain) set s.
let S : Set α := { x | ∃ t : Finset α, ↑t ⊆ s ∧ x = t.sup id }
-- S is directed, nonempty, and still has sup above k.
have dir_US : DirectedOn (· ≤ ·) S := by
rintro x ⟨c, hc⟩ y ⟨d, hd⟩
use x ⊔ y
constructor
· use c ∪ d
constructor
· simp only [hc.left, hd.left, Set.union_subset_iff, Finset.coe_union, and_self_iff]
· simp only [hc.right, hd.right, Finset.sup_union]
simp only [and_self_iff, le_sup_left, le_sup_right]
have sup_S : sSup s ≤ sSup S := by
apply sSup_le_sSup
intro x hx
use {x}
simpa only [and_true, id, Finset.coe_singleton, eq_self_iff_true,
Finset.sup_singleton, Set.singleton_subset_iff]
have Sne : S.Nonempty := by
suffices ⊥ ∈ S from Set.nonempty_of_mem this
use ∅
simp only [Set.empty_subset, Finset.coe_empty, Finset.sup_empty, eq_self_iff_true,
and_self_iff]
-- Now apply the defn of compact and finish.
obtain ⟨j, ⟨hjS, hjk⟩⟩ := hk S Sne dir_US (le_trans hsup sup_S)
obtain ⟨t, ⟨htS, htsup⟩⟩ := hjS
use t
exact ⟨htS, by rwa [← htsup]⟩
theorem IsCompactElement.exists_finset_of_le_iSup {k : α} (hk : IsCompactElement k) {ι : Type*}
(f : ι → α) (h : k ≤ ⨆ i, f i) : ∃ s : Finset ι, k ≤ ⨆ i ∈ s, f i := by
classical
let g : Finset ι → α := fun s => ⨆ i ∈ s, f i
have h1 : DirectedOn (· ≤ ·) (Set.range g) := by
rintro - ⟨s, rfl⟩ - ⟨t, rfl⟩
exact
⟨g (s ∪ t), ⟨s ∪ t, rfl⟩, iSup_le_iSup_of_subset Finset.subset_union_left,
iSup_le_iSup_of_subset Finset.subset_union_right⟩
have h2 : k ≤ sSup (Set.range g) :=
h.trans
(iSup_le fun i =>
le_sSup_of_le ⟨{i}, rfl⟩
(le_iSup_of_le i (le_iSup_of_le (Finset.mem_singleton_self i) le_rfl)))
obtain ⟨-, ⟨s, rfl⟩, hs⟩ :=
(isCompactElement_iff_le_of_directed_sSup_le α k).mp hk (Set.range g) (Set.range_nonempty g)
h1 h2
exact ⟨s, hs⟩
/-- A compact element `k` has the property that any directed set lying strictly below `k` has
its `sSup` strictly below `k`. -/
theorem IsCompactElement.directed_sSup_lt_of_lt {α : Type*} [CompleteLattice α] {k : α}
(hk : IsCompactElement k) {s : Set α} (hemp : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s)
(hbelow : ∀ x ∈ s, x < k) : sSup s < k := by
rw [isCompactElement_iff_le_of_directed_sSup_le] at hk
by_contra h
have sSup' : sSup s ≤ k := sSup_le s k fun s hs => (hbelow s hs).le
replace sSup : sSup s = k := eq_iff_le_not_lt.mpr ⟨sSup', h⟩
obtain ⟨x, hxs, hkx⟩ := hk s hemp hdir sSup.symm.le
obtain hxk := hbelow x hxs
exact hxk.ne (hxk.le.antisymm hkx)
theorem isCompactElement_finsetSup {α β : Type*} [CompleteLattice α] {f : β → α} (s : Finset β)
(h : ∀ x ∈ s, IsCompactElement (f x)) : IsCompactElement (s.sup f) := by
classical
rw [isCompactElement_iff_le_of_directed_sSup_le]
intro d hemp hdir hsup
rw [← Function.id_comp f]
rw [← Finset.sup_image]
apply Finset.sup_le_of_le_directed d hemp hdir
rintro x hx
obtain ⟨p, ⟨hps, rfl⟩⟩ := Finset.mem_image.mp hx
specialize h p hps
rw [isCompactElement_iff_le_of_directed_sSup_le] at h
specialize h d hemp hdir (le_trans (Finset.le_sup hps) hsup)
simpa only [exists_prop]
theorem WellFoundedGT.isSupFiniteCompact [WellFoundedGT α] :
IsSupFiniteCompact α := fun s => by
let S := { x | ∃ t : Finset α, ↑t ⊆ s ∧ t.sup id = x }
obtain ⟨m, ⟨t, ⟨ht₁, rfl⟩⟩, hm⟩ := wellFounded_gt.has_min S ⟨⊥, ∅, by simp⟩
refine ⟨t, ht₁, (sSup_le _ _ fun y hy => ?_).antisymm ?_⟩
· classical
rw [eq_of_le_of_not_lt (Finset.sup_mono (t.subset_insert y))
(hm _ ⟨insert y t, by simp [Set.insert_subset_iff, hy, ht₁]⟩)]
simp
· rw [Finset.sup_id_eq_sSup]
exact sSup_le_sSup ht₁
theorem IsSupFiniteCompact.isSupClosedCompact (h : IsSupFiniteCompact α) :
IsSupClosedCompact α := by
intro s hne hsc; obtain ⟨t, ht₁, ht₂⟩ := h s; clear h
rcases t.eq_empty_or_nonempty with h | h
· subst h
rw [Finset.sup_empty] at ht₂
rw [ht₂]
simp [eq_singleton_bot_of_sSup_eq_bot_of_nonempty ht₂ hne]
· rw [ht₂]
exact hsc.finsetSup_mem h ht₁
theorem IsSupClosedCompact.wellFoundedGT (h : IsSupClosedCompact α) :
WellFoundedGT α where
wf := by
refine RelEmbedding.wellFounded_iff_no_descending_seq.mpr ⟨fun a => ?_⟩
suffices sSup (Set.range a) ∈ Set.range a by
obtain ⟨n, hn⟩ := Set.mem_range.mp this
have h' : sSup (Set.range a) < a (n + 1) := by
change _ > _
simp [← hn, a.map_rel_iff]
apply lt_irrefl (a (n + 1))
apply lt_of_le_of_lt _ h'
apply le_sSup
apply Set.mem_range_self
apply h (Set.range a)
· use a 37
apply Set.mem_range_self
· rintro x ⟨m, hm⟩ y ⟨n, hn⟩
use m ⊔ n
rw [← hm, ← hn]
apply RelHomClass.map_sup a
theorem isSupFiniteCompact_iff_all_elements_compact :
IsSupFiniteCompact α ↔ ∀ k : α, IsCompactElement k := by
refine ⟨fun h k s hs => ?_, fun h s => ?_⟩
· obtain ⟨t, ⟨hts, htsup⟩⟩ := h s
use t, hts
rwa [← htsup]
· obtain ⟨t, ⟨hts, htsup⟩⟩ := h (sSup s) s (by rfl)
have : sSup s = t.sup id := by
suffices t.sup id ≤ sSup s by apply le_antisymm <;> assumption
simp only [id, Finset.sup_le_iff]
intro x hx
exact le_sSup _ _ (hts hx)
exact ⟨t, hts, this⟩
open List in
theorem wellFoundedGT_characterisations : List.TFAE
[WellFoundedGT α, IsSupFiniteCompact α, IsSupClosedCompact α, ∀ k : α, IsCompactElement k] := by
tfae_have 1 → 2 := @WellFoundedGT.isSupFiniteCompact α _
tfae_have 2 → 3 := IsSupFiniteCompact.isSupClosedCompact α
tfae_have 3 → 1 := IsSupClosedCompact.wellFoundedGT α
tfae_have 2 ↔ 4 := isSupFiniteCompact_iff_all_elements_compact α
tfae_finish
theorem wellFoundedGT_iff_isSupFiniteCompact :
WellFoundedGT α ↔ IsSupFiniteCompact α :=
(wellFoundedGT_characterisations α).out 0 1
theorem isSupFiniteCompact_iff_isSupClosedCompact : IsSupFiniteCompact α ↔ IsSupClosedCompact α :=
(wellFoundedGT_characterisations α).out 1 2
theorem isSupClosedCompact_iff_wellFoundedGT :
IsSupClosedCompact α ↔ WellFoundedGT α :=
(wellFoundedGT_characterisations α).out 2 0
alias ⟨_, IsSupFiniteCompact.wellFoundedGT⟩ := wellFoundedGT_iff_isSupFiniteCompact
alias ⟨_, IsSupClosedCompact.isSupFiniteCompact⟩ := isSupFiniteCompact_iff_isSupClosedCompact
alias ⟨_, WellFoundedGT.isSupClosedCompact⟩ := isSupClosedCompact_iff_wellFoundedGT
end CompleteLattice
theorem WellFoundedGT.finite_of_sSupIndep [WellFoundedGT α] {s : Set α}
(hs : sSupIndep s) : s.Finite := by
classical
refine Set.not_infinite.mp fun contra => ?_
obtain ⟨t, ht₁, ht₂⟩ := CompleteLattice.WellFoundedGT.isSupFiniteCompact α s
replace contra : ∃ x : α, x ∈ s ∧ x ≠ ⊥ ∧ x ∉ t := by
have : (s \ (insert ⊥ t : Finset α)).Infinite := contra.diff (Finset.finite_toSet _)
obtain ⟨x, hx₁, hx₂⟩ := this.nonempty
exact ⟨x, hx₁, by simpa [not_or] using hx₂⟩
obtain ⟨x, hx₀, hx₁, hx₂⟩ := contra
replace hs : x ⊓ sSup s = ⊥ := by
have := hs.mono (by simp [ht₁, hx₀, -Set.union_singleton] : ↑t ∪ {x} ≤ s) (by simp : x ∈ _)
simpa [Disjoint, hx₂, ← t.sup_id_eq_sSup, ← ht₂] using this.eq_bot
apply hx₁
rw [← hs, eq_comm, inf_eq_left]
exact le_sSup hx₀
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedGT.finite_of_setIndependent := WellFoundedGT.finite_of_sSupIndep
theorem WellFoundedGT.finite_ne_bot_of_iSupIndep [WellFoundedGT α]
{ι : Type*} {t : ι → α} (ht : iSupIndep t) : Set.Finite {i | t i ≠ ⊥} := by
refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn
exact WellFoundedGT.finite_of_sSupIndep ht.sSupIndep_range
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedGT.finite_ne_bot_of_independent :=
WellFoundedGT.finite_ne_bot_of_iSupIndep
theorem WellFoundedGT.finite_of_iSupIndep [WellFoundedGT α] {ι : Type*}
{t : ι → α} (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι :=
haveI := (WellFoundedGT.finite_of_sSupIndep ht.sSupIndep_range).to_subtype
Finite.of_injective_finite_range (ht.injective h_ne_bot)
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedGT.finite_of_independent := WellFoundedGT.finite_of_iSupIndep
theorem WellFoundedLT.finite_of_sSupIndep [WellFoundedLT α] {s : Set α}
(hs : sSupIndep s) : s.Finite := by
by_contra inf
let e := (Infinite.diff inf <| finite_singleton ⊥).to_subtype.natEmbedding
let a n := ⨆ i ≥ n, (e i).1
have sup_le n : (e n).1 ⊔ a (n + 1) ≤ a n := sup_le_iff.mpr ⟨le_iSup₂_of_le n le_rfl le_rfl,
iSup₂_le fun i hi ↦ le_iSup₂_of_le i (n.le_succ.trans hi) le_rfl⟩
have lt n : a (n + 1) < a n := (Disjoint.right_lt_sup_of_left_ne_bot
((hs (e n).2.1).mono_right <| iSup₂_le fun i hi ↦ le_sSup ?_) (e n).2.2).trans_le (sup_le n)
· exact (RelEmbedding.natGT a lt).not_wellFounded_of_decreasing_seq wellFounded_lt
exact ⟨(e i).2.1, fun h ↦ n.lt_succ_self.not_le <| hi.trans_eq <| e.2 <| Subtype.val_injective h⟩
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedLT.finite_of_setIndependent := WellFoundedLT.finite_of_sSupIndep
theorem WellFoundedLT.finite_ne_bot_of_iSupIndep [WellFoundedLT α]
{ι : Type*} {t : ι → α} (ht : iSupIndep t) : Set.Finite {i | t i ≠ ⊥} := by
refine Finite.of_finite_image (Finite.subset ?_ (image_subset_range t _)) ht.injOn
exact WellFoundedLT.finite_of_sSupIndep ht.sSupIndep_range
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedLT.finite_ne_bot_of_independent :=
WellFoundedLT.finite_ne_bot_of_iSupIndep
theorem WellFoundedLT.finite_of_iSupIndep [WellFoundedLT α] {ι : Type*}
{t : ι → α} (ht : iSupIndep t) (h_ne_bot : ∀ i, t i ≠ ⊥) : Finite ι :=
haveI := (WellFoundedLT.finite_of_sSupIndep ht.sSupIndep_range).to_subtype
Finite.of_injective_finite_range (ht.injective h_ne_bot)
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.WellFoundedLT.finite_of_independent := WellFoundedLT.finite_of_iSupIndep
/-- A complete lattice is said to be compactly generated if any
element is the `sSup` of compact elements. -/
class IsCompactlyGenerated (α : Type*) [CompleteLattice α] : Prop where
/-- In a compactly generated complete lattice,
every element is the `sSup` of some set of compact elements. -/
exists_sSup_eq : ∀ x : α, ∃ s : Set α, (∀ x ∈ s, CompleteLattice.IsCompactElement x) ∧ sSup s = x
section
variable [IsCompactlyGenerated α] {a : α} {s : Set α}
@[simp]
theorem sSup_compact_le_eq (b) :
sSup { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } = b := by
rcases IsCompactlyGenerated.exists_sSup_eq b with ⟨s, hs, rfl⟩
exact le_antisymm (sSup_le fun c hc => hc.2) (sSup_le_sSup fun c cs => ⟨hs c cs, le_sSup cs⟩)
@[simp]
theorem sSup_compact_eq_top : sSup { a : α | CompleteLattice.IsCompactElement a } = ⊤ := by
refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_compact_le_eq ⊤)
exact (and_iff_left le_top).symm
theorem le_iff_compact_le_imp {a b : α} :
a ≤ b ↔ ∀ c : α, CompleteLattice.IsCompactElement c → c ≤ a → c ≤ b :=
⟨fun ab _ _ ca => le_trans ca ab, fun h => by
rw [← sSup_compact_le_eq a, ← sSup_compact_le_eq b]
exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩
/-- This property is sometimes referred to as `α` being upper continuous. -/
theorem DirectedOn.inf_sSup_eq (h : DirectedOn (· ≤ ·) s) : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b :=
le_antisymm
(by
rw [le_iff_compact_le_imp]
by_cases hs : s.Nonempty
· intro c hc hcinf
rw [le_inf_iff] at hcinf
rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] at hc
rcases hc s hs h hcinf.2 with ⟨d, ds, cd⟩
refine (le_inf hcinf.1 cd).trans (le_trans ?_ (le_iSup₂ d ds))
rfl
· rw [Set.not_nonempty_iff_eq_empty] at hs
simp [hs])
iSup_inf_le_inf_sSup
/-- This property is sometimes referred to as `α` being upper continuous. -/
protected theorem DirectedOn.sSup_inf_eq (h : DirectedOn (· ≤ ·) s) :
sSup s ⊓ a = ⨆ b ∈ s, b ⊓ a := by
simp_rw [inf_comm _ a, h.inf_sSup_eq]
protected theorem Directed.inf_iSup_eq (h : Directed (· ≤ ·) f) :
(a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by
rw [iSup, h.directedOn_range.inf_sSup_eq, iSup_range]
protected theorem Directed.iSup_inf_eq (h : Directed (· ≤ ·) f) :
(⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by
rw [iSup, h.directedOn_range.sSup_inf_eq, iSup_range]
protected theorem DirectedOn.disjoint_sSup_right (h : DirectedOn (· ≤ ·) s) :
Disjoint a (sSup s) ↔ ∀ ⦃b⦄, b ∈ s → Disjoint a b := by
simp_rw [disjoint_iff, h.inf_sSup_eq, iSup_eq_bot]
protected theorem DirectedOn.disjoint_sSup_left (h : DirectedOn (· ≤ ·) s) :
Disjoint (sSup s) a ↔ ∀ ⦃b⦄, b ∈ s → Disjoint b a := by
simp_rw [disjoint_iff, h.sSup_inf_eq, iSup_eq_bot]
protected theorem Directed.disjoint_iSup_right (h : Directed (· ≤ ·) f) :
Disjoint a (⨆ i, f i) ↔ ∀ i, Disjoint a (f i) := by
simp_rw [disjoint_iff, h.inf_iSup_eq, iSup_eq_bot]
protected theorem Directed.disjoint_iSup_left (h : Directed (· ≤ ·) f) :
Disjoint (⨆ i, f i) a ↔ ∀ i, Disjoint (f i) a := by
simp_rw [disjoint_iff, h.iSup_inf_eq, iSup_eq_bot]
/-- This property is equivalent to `α` being upper continuous. -/
theorem inf_sSup_eq_iSup_inf_sup_finset :
a ⊓ sSup s = ⨆ (t : Finset α) (_ : ↑t ⊆ s), a ⊓ t.sup id :=
le_antisymm
(by
rw [le_iff_compact_le_imp]
intro c hc hcinf
rw [le_inf_iff] at hcinf
rcases hc s hcinf.2 with ⟨t, ht1, ht2⟩
refine (le_inf hcinf.1 ht2).trans (le_trans ?_ (le_iSup₂ t ht1))
rfl)
(iSup_le fun t =>
iSup_le fun h => inf_le_inf_left _ ((Finset.sup_id_eq_sSup t).symm ▸ sSup_le_sSup h))
theorem sSupIndep_iff_finite {s : Set α} :
sSupIndep s ↔
∀ t : Finset α, ↑t ⊆ s → sSupIndep (↑t : Set α) :=
⟨fun hs _ ht => hs.mono ht, fun h a ha => by
rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot]
intro t
rw [iSup_eq_bot, Finset.sup_id_eq_sSup]
intro ht
classical
have h' := (h (insert a t) ?_ (t.mem_insert_self a)).eq_bot
· rwa [Finset.coe_insert, Set.insert_diff_self_of_not_mem] at h'
exact fun con => ((Set.mem_diff a).1 (ht con)).2 (Set.mem_singleton a)
· rw [Finset.coe_insert, Set.insert_subset_iff]
exact ⟨ha, Set.Subset.trans ht diff_subset⟩⟩
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.setIndependent_iff_finite := sSupIndep_iff_finite
lemma iSupIndep_iff_supIndep_of_injOn {ι : Type*} {f : ι → α}
(hf : InjOn f {i | f i ≠ ⊥}) :
iSupIndep f ↔ ∀ (s : Finset ι), s.SupIndep f := by
refine ⟨fun h ↦ h.supIndep', fun h ↦ iSupIndep_def'.mpr fun i ↦ ?_⟩
simp_rw [disjoint_iff, inf_sSup_eq_iSup_inf_sup_finset, iSup_eq_bot, ← disjoint_iff]
intro s hs
classical
rw [← Finset.sup_erase_bot]
set t := s.erase ⊥
replace hf : InjOn f (f ⁻¹' t) := fun i hi j _ hij ↦ by
refine hf ?_ ?_ hij <;> aesop (add norm simp [t])
have : (Finset.erase (insert i (t.preimage _ hf)) i).image f = t := by
ext a
simp only [Finset.mem_preimage, Finset.mem_erase, ne_eq, Finset.mem_insert, true_or, not_true,
Finset.erase_insert_eq_erase, not_and, Finset.mem_image, t]
refine ⟨by aesop, fun ⟨ha, has⟩ ↦ ?_⟩
obtain ⟨j, hj, rfl⟩ := hs has
exact ⟨j, ⟨hj, ha, has⟩, rfl⟩
rw [← this, Finset.sup_image]
specialize h (insert i (t.preimage _ hf))
rw [Finset.supIndep_iff_disjoint_erase] at h
exact h i (Finset.mem_insert_self i _)
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.independent_iff_supIndep_of_injOn := iSupIndep_iff_supIndep_of_injOn
theorem sSupIndep_iUnion_of_directed {η : Type*} {s : η → Set α}
(hs : Directed (· ⊆ ·) s) (h : ∀ i, sSupIndep (s i)) :
sSupIndep (⋃ i, s i) := by
by_cases hη : Nonempty η
· rw [sSupIndep_iff_finite]
intro t ht
obtain ⟨I, fi, hI⟩ := Set.finite_subset_iUnion t.finite_toSet ht
obtain ⟨i, hi⟩ := hs.finset_le fi.toFinset
exact (h i).mono
(Set.Subset.trans hI <| Set.iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj))
· rintro a ⟨_, ⟨i, _⟩, _⟩
exfalso
exact hη ⟨i⟩
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.setIndependent_iUnion_of_directed := sSupIndep_iUnion_of_directed
theorem iSupIndep_sUnion_of_directed {s : Set (Set α)} (hs : DirectedOn (· ⊆ ·) s)
(h : ∀ a ∈ s, sSupIndep a) : sSupIndep (⋃₀ s) := by
rw [Set.sUnion_eq_iUnion]
exact sSupIndep_iUnion_of_directed hs.directed_val (by simpa using h)
@[deprecated (since := "2024-11-24")]
alias CompleteLattice.independent_sUnion_of_directed := iSupIndep_sUnion_of_directed
end
namespace CompleteLattice
theorem isCompactlyGenerated_of_wellFoundedGT [h : WellFoundedGT α] :
IsCompactlyGenerated α := by
rw [wellFoundedGT_iff_isSupFiniteCompact, isSupFiniteCompact_iff_all_elements_compact] at h
-- x is the join of the set of compact elements {x}
exact ⟨fun x => ⟨{x}, ⟨fun x _ => h x, sSup_singleton⟩⟩⟩
/-- A compact element `k` has the property that any `b < k` lies below a "maximal element below
`k`", which is to say `[⊥, k]` is coatomic. -/
theorem Iic_coatomic_of_compact_element {k : α} (h : IsCompactElement k) :
IsCoatomic (Set.Iic k) := by
constructor
rintro ⟨b, hbk⟩
obtain rfl | H := eq_or_ne b k
· left; ext; simp only [Set.Iic.coe_top, Subtype.coe_mk]
right
have ⟨a, ba, h⟩ := zorn_le_nonempty₀ (Set.Iio k) ?_ b (lt_of_le_of_ne hbk H)
· refine ⟨⟨a, le_of_lt h.prop⟩, ⟨ne_of_lt h.prop, fun c hck => by_contradiction fun c₀ => ?_⟩, ba⟩
cases h.eq_of_le (y := c.1) (lt_of_le_of_ne c.2 fun con ↦ c₀ (Subtype.ext con)) hck.le
exact lt_irrefl _ hck
· intro S SC cC I _
by_cases hS : S.Nonempty
· refine ⟨sSup S, h.directed_sSup_lt_of_lt hS cC.directedOn SC, ?_⟩
intro; apply le_sSup
exact
⟨b, lt_of_le_of_ne hbk H, by
simp only [Set.not_nonempty_iff_eq_empty.mp hS, Set.mem_empty_iff_false, forall_const,
forall_prop_of_false, not_false_iff]⟩
theorem coatomic_of_top_compact (h : IsCompactElement (⊤ : α)) : IsCoatomic α :=
(@OrderIso.IicTop α _ _).isCoatomic_iff.mp (Iic_coatomic_of_compact_element h)
end CompleteLattice
section
variable [IsModularLattice α] [IsCompactlyGenerated α]
instance (priority := 100) isAtomic_of_complementedLattice [ComplementedLattice α] : IsAtomic α :=
⟨fun b => by
by_cases h : { c : α | CompleteLattice.IsCompactElement c ∧ c ≤ b } ⊆ {⊥}
· left
rw [← sSup_compact_le_eq b, sSup_eq_bot]
exact h
· rcases Set.not_subset.1 h with ⟨c, ⟨hc, hcb⟩, hcbot⟩
right
have hc' := CompleteLattice.Iic_coatomic_of_compact_element hc
rw [← isAtomic_iff_isCoatomic] at hc'
haveI := hc'
obtain con | ⟨a, ha, hac⟩ := eq_bot_or_exists_atom_le (⟨c, le_refl c⟩ : Set.Iic c)
· exfalso
apply hcbot
simp only [Subtype.ext_iff, Set.Iic.coe_bot, Subtype.coe_mk] at con
exact con
rw [← Subtype.coe_le_coe, Subtype.coe_mk] at hac
exact ⟨a, ha.of_isAtom_coe_Iic, hac.trans hcb⟩⟩
/-- See [Lemma 5.1][calugareanu]. -/
instance (priority := 100) isAtomistic_of_complementedLattice [ComplementedLattice α] :
IsAtomistic α :=
CompleteLattice.isAtomistic_iff.2 fun b =>
⟨{ a | IsAtom a ∧ a ≤ b }, by
symm
have hle : sSup { a : α | IsAtom a ∧ a ≤ b } ≤ b := sSup_le fun _ => And.right
apply (lt_or_eq_of_le hle).resolve_left _
intro con
obtain ⟨c, hc⟩ := exists_isCompl (⟨sSup { a : α | IsAtom a ∧ a ≤ b }, hle⟩ : Set.Iic b)
obtain rfl | ⟨a, ha, hac⟩ := eq_bot_or_exists_atom_le c
· exact ne_of_lt con (Subtype.ext_iff.1 (eq_top_of_isCompl_bot hc))
· apply ha.1
rw [eq_bot_iff]
apply le_trans (le_inf _ hac) hc.disjoint.le_bot
rw [← Subtype.coe_le_coe, Subtype.coe_mk]
exact le_sSup ⟨ha.of_isAtom_coe_Iic, a.2⟩, fun _ => And.left⟩
/-!
Now we will prove that a compactly generated modular atomistic lattice is a complemented lattice.
Most explicitly, every element is the complement of a supremum of indepedendent atoms.
-/
/-- In an atomic lattice, every element `b` has a complement of the form `sSup s`, where each
element of `s` is an atom. See also `complementedLattice_of_sSup_atoms_eq_top`. -/
theorem exists_sSupIndep_isCompl_sSup_atoms (h : sSup { a : α | IsAtom a } = ⊤) (b : α) :
∃ s : Set α, sSupIndep s ∧
IsCompl b (sSup s) ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a := by
-- porting note(https://github.com/leanprover-community/mathlib4/issues/5732):
-- `obtain` chokes on the placeholder.
have zorn := zorn_subset
(S := {s : Set α | sSupIndep s ∧ Disjoint b (sSup s) ∧ ∀ a ∈ s, IsAtom a})
fun c hc1 hc2 =>
⟨⋃₀ c,
⟨iSupIndep_sUnion_of_directed hc2.directedOn fun s hs => (hc1 hs).1, ?_,
fun a ⟨s, sc, as⟩ => (hc1 sc).2.2 a as⟩,
fun _ => Set.subset_sUnion_of_mem⟩
swap
· rw [sSup_sUnion, ← sSup_image, DirectedOn.disjoint_sSup_right]
· rintro _ ⟨s, hs, rfl⟩
exact (hc1 hs).2.1
· rw [directedOn_image]
exact hc2.directedOn.mono @fun s t => sSup_le_sSup
simp_rw [maximal_subset_iff] at zorn
obtain ⟨s, ⟨s_ind, b_inf_Sup_s, s_atoms⟩, s_max⟩ := zorn
refine ⟨s, s_ind, ⟨b_inf_Sup_s, ?_⟩, s_atoms⟩
rw [codisjoint_iff_le_sup, ← h, sSup_le_iff]
intro a ha
rw [← inf_eq_left]
refine (ha.le_iff.mp inf_le_left).resolve_left fun con => ha.1 ?_
rw [← con, eq_comm, inf_eq_left]
refine (le_sSup ?_).trans le_sup_right
rw [← disjoint_iff] at con
have a_dis_Sup_s : Disjoint a (sSup s) := con.mono_right le_sup_right
rw [s_max ⟨fun x hx => ?_, ?_, fun x hx => ?_⟩ Set.subset_union_left]
· exact Set.mem_union_right _ (Set.mem_singleton _)
· rw [sSup_union, sSup_singleton]
exact b_inf_Sup_s.disjoint_sup_right_of_disjoint_sup_left con.symm
· rw [Set.mem_union, Set.mem_singleton_iff] at hx
obtain rfl | xa := eq_or_ne x a
· simp only [Set.mem_singleton, Set.insert_diff_of_mem, Set.union_singleton]
exact con.mono_right ((sSup_le_sSup Set.diff_subset).trans le_sup_right)
· have h : (s ∪ {a}) \ {x} = s \ {x} ∪ {a} := by
simp only [Set.union_singleton]
rw [Set.insert_diff_of_not_mem]
rw [Set.mem_singleton_iff]
exact Ne.symm xa
rw [h, sSup_union, sSup_singleton]
apply
(s_ind (hx.resolve_right xa)).disjoint_sup_right_of_disjoint_sup_left
(a_dis_Sup_s.mono_right _).symm
rw [← sSup_insert, Set.insert_diff_singleton, Set.insert_eq_of_mem (hx.resolve_right xa)]
· rw [Set.mem_union, Set.mem_singleton_iff] at hx
obtain hx | rfl := hx
· exact s_atoms x hx
· exact ha
@[deprecated (since := "2024-11-24")]
alias exists_setIndependent_isCompl_sSup_atoms := exists_sSupIndep_isCompl_sSup_atoms
theorem exists_sSupIndep_of_sSup_atoms_eq_top (h : sSup { a : α | IsAtom a } = ⊤) :
∃ s : Set α, sSupIndep s ∧ sSup s = ⊤ ∧ ∀ ⦃a⦄, a ∈ s → IsAtom a :=
let ⟨s, s_ind, s_top, s_atoms⟩ := exists_sSupIndep_isCompl_sSup_atoms h ⊥
⟨s, s_ind, eq_top_of_isCompl_bot s_top.symm, s_atoms⟩
@[deprecated (since := "2024-11-24")]
alias exists_setIndependent_of_sSup_atoms_eq_top := exists_sSupIndep_of_sSup_atoms_eq_top
/-- See [Theorem 6.6][calugareanu]. -/
theorem complementedLattice_of_sSup_atoms_eq_top (h : sSup { a : α | IsAtom a } = ⊤) :
ComplementedLattice α :=
⟨fun b =>
let ⟨s, _, s_top, _⟩ := exists_sSupIndep_isCompl_sSup_atoms h b
⟨sSup s, s_top⟩⟩
|
/-- See [Theorem 6.6][calugareanu]. -/
theorem complementedLattice_of_isAtomistic [IsAtomistic α] : ComplementedLattice α :=
complementedLattice_of_sSup_atoms_eq_top sSup_atoms_eq_top
| Mathlib/Order/CompactlyGenerated/Basic.lean | 658 | 661 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.