Context stringlengths 227 76.5k | target stringlengths 0 11.6k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 16 3.69k |
|---|---|---|---|---|
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll, Anatole Dedecker
-/
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.Seminorm
import Mathlib.Data.Real.Sqrt
import Mathlib.Topology.Algebra.Equicontinuity
import Mathlib.Topology.MetricSpace.Equicontinuity
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.Module.LocallyConvex
/-!
# Topology induced by a family of seminorms
## Main definitions
* `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms.
* `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls.
* `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be
bounded by a finite number of seminorms in `E`.
## Main statements
* `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally
convex.
* `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a
countable family of seminorms.
## Continuity of semilinear maps
If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then
we have a direct method to prove that a linear map is continuous:
* `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous.
If the topology of a space `E` is induced by a family of seminorms, then we can characterize von
Neumann boundedness in terms of that seminorm family. Together with
`LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity.
* `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.isVonNBounded_iff_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded`
## Tags
seminorm, locally convex
-/
open NormedField Set Seminorm TopologicalSpace Filter List
open NNReal Pointwise Topology Uniformity
variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*}
section FilterBasis
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable (𝕜 E ι)
/-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/
abbrev SeminormFamily :=
ι → Seminorm 𝕜 E
variable {𝕜 E ι}
namespace SeminormFamily
/-- The sets of a filter basis for the neighborhood filter of 0. -/
def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) :=
⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r)
variable (p : SeminormFamily 𝕜 E ι)
theorem basisSets_iff {U : Set E} :
U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by
simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff]
theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets :=
(basisSets_iff _).mpr ⟨i, _, hr, rfl⟩
theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets :=
(basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩
theorem basisSets_nonempty [Nonempty ι] : p.basisSets.Nonempty := by
let i := Classical.arbitrary ι
refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩
exact p.basisSets_singleton_mem i zero_lt_one
theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) :
∃ z ∈ p.basisSets, z ⊆ U ∩ V := by
classical
rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩
rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩
use ((s ∪ t).sup p).ball 0 (min r₁ r₂)
refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩
rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩),
ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂]
exact
Set.subset_inter
(Set.iInter₂_mono' fun i hi =>
⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩)
(Set.iInter₂_mono' fun i hi =>
⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩)
theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by
rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩
rw [hU, mem_ball_zero, map_zero]
exact hr
theorem basisSets_add (U) (hU : U ∈ p.basisSets) :
∃ V ∈ p.basisSets, V + V ⊆ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
use (s.sup p).ball 0 (r / 2)
refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩
refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_
rw [hU, add_zero, add_halves]
theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) :
∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by
rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩
rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero]
exact ⟨U, hU', Eq.subset hU⟩
/-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
protected def addGroupFilterBasis [Nonempty ι] : AddGroupFilterBasis E :=
addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero
p.basisSets_add p.basisSets_neg
theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) :
∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
rw [hU, Filter.eventually_iff]
simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul]
by_cases h : 0 < (s.sup p) v
· simp_rw [(lt_div_iff₀ h).symm]
rw [← _root_.ball_zero_eq]
exact Metric.ball_mem_nhds 0 (div_pos hr h)
simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr]
exact IsOpen.mem_nhds isOpen_univ (mem_univ 0)
variable [Nonempty ι]
theorem basisSets_smul (U) (hU : U ∈ p.basisSets) :
∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩
refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩
refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_
rw [hU, Real.mul_self_sqrt (le_of_lt hr)]
theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) :
∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
rw [hU]
by_cases h : x ≠ 0
· rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero]
use (s.sup p).ball 0 (r / ‖x‖)
exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩
refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩
simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff,
preimage_const_of_mem, zero_smul]
/-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
protected def moduleFilterBasis : ModuleFilterBasis 𝕜 E where
toAddGroupFilterBasis := p.addGroupFilterBasis
smul' := p.basisSets_smul _
smul_left' := p.basisSets_smul_left
smul_right' := p.basisSets_smul_right
theorem filter_eq_iInf (p : SeminormFamily 𝕜 E ι) :
p.moduleFilterBasis.toFilterBasis.filter = ⨅ i, (𝓝 0).comap (p i) := by
refine le_antisymm (le_iInf fun i => ?_) ?_
· rw [p.moduleFilterBasis.toFilterBasis.hasBasis.le_basis_iff
(Metric.nhds_basis_ball.comap _)]
intro ε hε
refine ⟨(p i).ball 0 ε, ?_, ?_⟩
· rw [← (Finset.sup_singleton : _ = p i)]
exact p.basisSets_mem {i} hε
· rw [id, (p i).ball_zero_eq_preimage_ball]
· rw [p.moduleFilterBasis.toFilterBasis.hasBasis.ge_iff]
rintro U (hU : U ∈ p.basisSets)
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, rfl⟩
rw [id, Seminorm.ball_finset_sup_eq_iInter _ _ _ hr, s.iInter_mem_sets]
exact fun i _ =>
Filter.mem_iInf_of_mem i
⟨Metric.ball 0 r, Metric.ball_mem_nhds 0 hr,
Eq.subset (p i).ball_zero_eq_preimage_ball.symm⟩
/-- If a family of seminorms is continuous, then their basis sets are neighborhoods of zero. -/
lemma basisSets_mem_nhds {𝕜 E ι : Type*} [NormedField 𝕜]
[AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] (p : SeminormFamily 𝕜 E ι)
(hp : ∀ i, Continuous (p i)) (U : Set E) (hU : U ∈ p.basisSets) : U ∈ 𝓝 (0 : E) := by
obtain ⟨s, r, hr, rfl⟩ := p.basisSets_iff.mp hU
clear hU
refine Seminorm.ball_mem_nhds ?_ hr
classical
induction s using Finset.induction_on
case empty => simpa using continuous_zero
case insert a s _ hs =>
simp only [Finset.sup_insert, coe_sup]
exact Continuous.max (hp a) hs
end SeminormFamily
end FilterBasis
section Bounded
namespace Seminorm
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
-- Todo: This should be phrased entirely in terms of the von Neumann bornology.
/-- The proposition that a linear map is bounded between spaces with families of seminorms. -/
def IsBounded (p : ι → Seminorm 𝕜 E) (q : ι' → Seminorm 𝕜₂ F) (f : E →ₛₗ[σ₁₂] F) : Prop :=
∀ i, ∃ s : Finset ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • s.sup p
theorem isBounded_const (ι' : Type*) [Nonempty ι'] {p : ι → Seminorm 𝕜 E} {q : Seminorm 𝕜₂ F}
(f : E →ₛₗ[σ₁₂] F) :
IsBounded p (fun _ : ι' => q) f ↔ ∃ (s : Finset ι) (C : ℝ≥0), q.comp f ≤ C • s.sup p := by
simp only [IsBounded, forall_const]
theorem const_isBounded (ι : Type*) [Nonempty ι] {p : Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F}
(f : E →ₛₗ[σ₁₂] F) : IsBounded (fun _ : ι => p) q f ↔ ∀ i, ∃ C : ℝ≥0, (q i).comp f ≤ C • p := by
constructor <;> intro h i
· rcases h i with ⟨s, C, h⟩
exact ⟨C, le_trans h (smul_le_smul (Finset.sup_le fun _ _ => le_rfl) le_rfl)⟩
use {Classical.arbitrary ι}
simp only [h, Finset.sup_singleton]
theorem isBounded_sup {p : ι → Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} {f : E →ₛₗ[σ₁₂] F}
(hf : IsBounded p q f) (s' : Finset ι') :
∃ (C : ℝ≥0) (s : Finset ι), (s'.sup q).comp f ≤ C • s.sup p := by
classical
obtain rfl | _ := s'.eq_empty_or_nonempty
· exact ⟨1, ∅, by simp [Seminorm.bot_eq_zero]⟩
choose fₛ fC hf using hf
use s'.card • s'.sup fC, Finset.biUnion s' fₛ
have hs : ∀ i : ι', i ∈ s' → (q i).comp f ≤ s'.sup fC • (Finset.biUnion s' fₛ).sup p := by
intro i hi
refine (hf i).trans (smul_le_smul ?_ (Finset.le_sup hi))
exact Finset.sup_mono (Finset.subset_biUnion_of_mem fₛ hi)
refine (comp_mono f (finset_sup_le_sum q s')).trans ?_
simp_rw [← pullback_apply, map_sum, pullback_apply]
refine (Finset.sum_le_sum hs).trans ?_
rw [Finset.sum_const, smul_assoc]
end Seminorm
end Bounded
section Topology
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Nonempty ι]
/-- The proposition that the topology of `E` is induced by a family of seminorms `p`. -/
structure WithSeminorms (p : SeminormFamily 𝕜 E ι) [topology : TopologicalSpace E] : Prop where
topology_eq_withSeminorms : topology = p.moduleFilterBasis.topology
theorem WithSeminorms.withSeminorms_eq {p : SeminormFamily 𝕜 E ι} [t : TopologicalSpace E]
(hp : WithSeminorms p) : t = p.moduleFilterBasis.topology :=
hp.1
variable [TopologicalSpace E]
variable {p : SeminormFamily 𝕜 E ι}
theorem WithSeminorms.topologicalAddGroup (hp : WithSeminorms p) : IsTopologicalAddGroup E := by
rw [hp.withSeminorms_eq]
exact AddGroupFilterBasis.isTopologicalAddGroup _
theorem WithSeminorms.continuousSMul (hp : WithSeminorms p) : ContinuousSMul 𝕜 E := by
rw [hp.withSeminorms_eq]
exact ModuleFilterBasis.continuousSMul _
theorem WithSeminorms.hasBasis (hp : WithSeminorms p) :
(𝓝 (0 : E)).HasBasis (fun s : Set E => s ∈ p.basisSets) id := by
rw [congr_fun (congr_arg (@nhds E) hp.1) 0]
exact AddGroupFilterBasis.nhds_zero_hasBasis _
theorem WithSeminorms.hasBasis_zero_ball (hp : WithSeminorms p) :
(𝓝 (0 : E)).HasBasis
(fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball 0 sr.2 := by
refine ⟨fun V => ?_⟩
simp only [hp.hasBasis.mem_iff, SeminormFamily.basisSets_iff, Prod.exists]
constructor
· rintro ⟨-, ⟨s, r, hr, rfl⟩, hV⟩
exact ⟨s, r, hr, hV⟩
· rintro ⟨s, r, hr, hV⟩
exact ⟨_, ⟨s, r, hr, rfl⟩, hV⟩
theorem WithSeminorms.hasBasis_ball (hp : WithSeminorms p) {x : E} :
(𝓝 (x : E)).HasBasis
(fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball x sr.2 := by
have : IsTopologicalAddGroup E := hp.topologicalAddGroup
rw [← map_add_left_nhds_zero]
convert hp.hasBasis_zero_ball.map (x + ·) using 1
ext sr : 1
-- Porting note: extra type ascriptions needed on `0`
have : (sr.fst.sup p).ball (x +ᵥ (0 : E)) sr.snd = x +ᵥ (sr.fst.sup p).ball 0 sr.snd :=
Eq.symm (Seminorm.vadd_ball (sr.fst.sup p))
rwa [vadd_eq_add, add_zero] at this
/-- The `x`-neighbourhoods of a space whose topology is induced by a family of seminorms
are exactly the sets which contain seminorm balls around `x`. -/
theorem WithSeminorms.mem_nhds_iff (hp : WithSeminorms p) (x : E) (U : Set E) :
U ∈ 𝓝 x ↔ ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by
rw [hp.hasBasis_ball.mem_iff, Prod.exists]
/-- The open sets of a space whose topology is induced by a family of seminorms
are exactly the sets which contain seminorm balls around all of their points. -/
theorem WithSeminorms.isOpen_iff_mem_balls (hp : WithSeminorms p) (U : Set E) :
IsOpen U ↔ ∀ x ∈ U, ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by
simp_rw [← WithSeminorms.mem_nhds_iff hp _ U, isOpen_iff_mem_nhds]
/- Note that through the following lemmas, one also immediately has that separating families
of seminorms induce T₂ and T₃ topologies by `IsTopologicalAddGroup.t2Space`
and `IsTopologicalAddGroup.t3Space` -/
/-- A separating family of seminorms induces a T₁ topology. -/
theorem WithSeminorms.T1_of_separating (hp : WithSeminorms p)
(h : ∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) : T1Space E := by
have := hp.topologicalAddGroup
refine IsTopologicalAddGroup.t1Space _ ?_
rw [← isOpen_compl_iff, hp.isOpen_iff_mem_balls]
rintro x (hx : x ≠ 0)
obtain ⟨i, pi_nonzero⟩ := h x hx
| refine ⟨{i}, p i x, by positivity, subset_compl_singleton_iff.mpr ?_⟩
rw [Finset.sup_singleton, mem_ball, zero_sub, map_neg_eq_map, not_lt]
| Mathlib/Analysis/LocallyConvex/WithSeminorms.lean | 331 | 333 |
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.Sheaf
/-!
# The plus construction for presheaves.
This file contains the construction of `P⁺`, for a presheaf `P : Cᵒᵖ ⥤ D`
where `C` is endowed with a grothendieck topology `J`.
See <https://stacks.math.columbia.edu/tag/00W1> for details.
-/
namespace CategoryTheory.GrothendieckTopology
open CategoryTheory
open CategoryTheory.Limits
open Opposite
universe w v u
variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C)
variable {D : Type w} [Category.{max v u} D]
noncomputable section
variable [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.Cover X), HasMultiequalizer (S.index P)]
variable (P : Cᵒᵖ ⥤ D)
/-- The diagram whose colimit defines the values of `plus`. -/
@[simps]
def diagram (X : C) : (J.Cover X)ᵒᵖ ⥤ D where
obj S := multiequalizer (S.unop.index P)
map {S _} f :=
Multiequalizer.lift _ _ (fun I => Multiequalizer.ι (S.unop.index P) (I.map f.unop))
(fun I => Multiequalizer.condition (S.unop.index P) (Cover.Relation.mk' (I.r.map f.unop)))
/-- A helper definition used to define the morphisms for `plus`. -/
@[simps]
def diagramPullback {X Y : C} (f : X ⟶ Y) : J.diagram P Y ⟶ (J.pullback f).op ⋙ J.diagram P X where
app S :=
Multiequalizer.lift _ _ (fun I => Multiequalizer.ι (S.unop.index P) I.base) fun I =>
Multiequalizer.condition (S.unop.index P) (Cover.Relation.mk' I.r.base)
naturality S T f := Multiequalizer.hom_ext _ _ _ (fun I => by dsimp; simp; rfl)
/-- A natural transformation `P ⟶ Q` induces a natural transformation
between diagrams whose colimits define the values of `plus`. -/
@[simps]
def diagramNatTrans {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (X : C) : J.diagram P X ⟶ J.diagram Q X where
app W :=
Multiequalizer.lift _ _ (fun _ => Multiequalizer.ι _ _ ≫ η.app _) (fun i => by
dsimp only
erw [Category.assoc, Category.assoc, ← η.naturality, ← η.naturality,
Multiequalizer.condition_assoc]
rfl)
@[simp]
theorem diagramNatTrans_id (X : C) (P : Cᵒᵖ ⥤ D) :
J.diagramNatTrans (𝟙 P) X = 𝟙 (J.diagram P X) := by
ext : 2
refine Multiequalizer.hom_ext _ _ _ (fun i => ?_)
simp
@[simp]
theorem diagramNatTrans_zero [Preadditive D] (X : C) (P Q : Cᵒᵖ ⥤ D) :
J.diagramNatTrans (0 : P ⟶ Q) X = 0 := by
ext : 2
refine Multiequalizer.hom_ext _ _ _ (fun i => ?_)
simp
@[simp]
theorem diagramNatTrans_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) (X : C) :
J.diagramNatTrans (η ≫ γ) X = J.diagramNatTrans η X ≫ J.diagramNatTrans γ X := by
ext : 2
refine Multiequalizer.hom_ext _ _ _ (fun i => ?_)
simp
variable (D) in
/-- `J.diagram P`, as a functor in `P`. -/
@[simps]
def diagramFunctor (X : C) : (Cᵒᵖ ⥤ D) ⥤ (J.Cover X)ᵒᵖ ⥤ D where
obj P := J.diagram P X
map η := J.diagramNatTrans η X
variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D]
/-- The plus construction, associating a presheaf to any presheaf.
See `plusFunctor` below for a functorial version. -/
def plusObj : Cᵒᵖ ⥤ D where
obj X := colimit (J.diagram P X.unop)
map f := colimMap (J.diagramPullback P f.unop) ≫ colimit.pre _ _
map_id := by
intro X
refine colimit.hom_ext (fun S => ?_)
dsimp
simp only [diagramPullback_app, colimit.ι_pre, ι_colimMap_assoc, Category.comp_id]
let e := S.unop.pullbackId
dsimp only [Functor.op, pullback_obj]
rw [← colimit.w _ e.inv.op, ← Category.assoc]
convert Category.id_comp (colimit.ι (diagram J P (unop X)) S)
refine Multiequalizer.hom_ext _ _ _ (fun I => ?_)
dsimp
simp only [Multiequalizer.lift_ι, Category.id_comp, Category.assoc]
dsimp [Cover.Arrow.map, Cover.Arrow.base]
cases I
congr
simp
map_comp := by
intro X Y Z f g
refine colimit.hom_ext (fun S => ?_)
dsimp
simp only [diagramPullback_app, colimit.ι_pre_assoc, colimit.ι_pre, ι_colimMap_assoc,
Category.assoc]
let e := S.unop.pullbackComp g.unop f.unop
dsimp only [Functor.op, pullback_obj]
rw [← colimit.w _ e.inv.op, ← Category.assoc, ← Category.assoc]
congr 1
refine Multiequalizer.hom_ext _ _ _ (fun I => ?_)
dsimp
simp only [Multiequalizer.lift_ι, Category.assoc]
cases I
dsimp only [Cover.Arrow.base, Cover.Arrow.map]
congr 2
simp
/-- An auxiliary definition used in `plus` below. -/
def plusMap {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : J.plusObj P ⟶ J.plusObj Q where
app X := colimMap (J.diagramNatTrans η X.unop)
naturality := by
intro X Y f
dsimp [plusObj]
ext
simp only [diagramPullback_app, ι_colimMap, colimit.ι_pre_assoc, colimit.ι_pre,
ι_colimMap_assoc, Category.assoc]
simp_rw [← Category.assoc]
congr 1
exact Multiequalizer.hom_ext _ _ _ (fun I => by dsimp; simp)
@[simp]
theorem plusMap_id (P : Cᵒᵖ ⥤ D) : J.plusMap (𝟙 P) = 𝟙 _ := by
ext : 2
dsimp only [plusMap, plusObj]
rw [J.diagramNatTrans_id, NatTrans.id_app]
ext
dsimp
simp
@[simp]
theorem plusMap_zero [Preadditive D] (P Q : Cᵒᵖ ⥤ D) : J.plusMap (0 : P ⟶ Q) = 0 := by
ext : 2
refine colimit.hom_ext (fun S => ?_)
erw [comp_zero, colimit.ι_map, J.diagramNatTrans_zero, zero_comp]
@[simp, reassoc]
theorem plusMap_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) :
J.plusMap (η ≫ γ) = J.plusMap η ≫ J.plusMap γ := by
| ext : 2
refine colimit.hom_ext (fun S => ?_)
simp [plusMap, J.diagramNatTrans_comp]
variable (D) in
/-- The plus construction, a functor sending `P` to `J.plusObj P`. -/
@[simps]
| Mathlib/CategoryTheory/Sites/Plus.lean | 165 | 171 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.Order.Filter.AtTopBot.Field
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.LinearCombination
import Mathlib.Tactic.Linarith.Frontend
/-!
# Quadratic discriminants and roots of a quadratic
This file defines the discriminant of a quadratic and gives the solution to a quadratic equation.
## Main definition
- `discrim a b c`: the discriminant of a quadratic `a * (x * x) + b * x + c` is `b * b - 4 * a * c`.
## Main statements
- `quadratic_eq_zero_iff`: roots of a quadratic can be written as
`(-b + s) / (2 * a)` or `(-b - s) / (2 * a)`, where `s` is a square root of the discriminant.
- `quadratic_ne_zero_of_discrim_ne_sq`: if the discriminant has no square root,
then the corresponding quadratic has no root.
- `discrim_le_zero`: if a quadratic is always non-negative, then its discriminant is non-positive.
- `discrim_le_zero_of_nonpos`, `discrim_lt_zero`, `discrim_lt_zero_of_neg`: versions of this
statement with other inequalities.
## Tags
polynomial, quadratic, discriminant, root
-/
assert_not_exists Finite Finset
open Filter
section Ring
variable {R : Type*}
/-- Discriminant of a quadratic -/
def discrim [Ring R] (a b c : R) : R :=
b ^ 2 - 4 * a * c
@[simp] lemma discrim_neg [Ring R] (a b c : R) : discrim (-a) (-b) (-c) = discrim a b c := by
simp [discrim]
variable [CommRing R] {a b c : R}
lemma discrim_eq_sq_of_quadratic_eq_zero {x : R} (h : a * (x * x) + b * x + c = 0) :
discrim a b c = (2 * a * x + b) ^ 2 := by
rw [discrim]
linear_combination -4 * a * h
/-- A quadratic has roots if and only if its discriminant equals some square.
-/
theorem quadratic_eq_zero_iff_discrim_eq_sq [NeZero (2 : R)] [NoZeroDivisors R]
(ha : a ≠ 0) (x : R) :
a * (x * x) + b * x + c = 0 ↔ discrim a b c = (2 * a * x + b) ^ 2 := by
refine ⟨discrim_eq_sq_of_quadratic_eq_zero, fun h ↦ ?_⟩
rw [discrim] at h
have ha : 2 * 2 * a ≠ 0 := mul_ne_zero (mul_ne_zero (NeZero.ne _) (NeZero.ne _)) ha
apply mul_left_cancel₀ ha
linear_combination -h
/-- A quadratic has no root if its discriminant has no square root. -/
theorem quadratic_ne_zero_of_discrim_ne_sq (h : ∀ s : R, discrim a b c ≠ s^2) (x : R) :
a * (x * x) + b * x + c ≠ 0 :=
mt discrim_eq_sq_of_quadratic_eq_zero (h _)
end Ring
section Field
variable {K : Type*} [Field K] [NeZero (2 : K)] {a b c : K}
/-- Roots of a quadratic equation. -/
theorem quadratic_eq_zero_iff (ha : a ≠ 0) {s : K} (h : discrim a b c = s * s) (x : K) :
a * (x * x) + b * x + c = 0 ↔ x = (-b + s) / (2 * a) ∨ x = (-b - s) / (2 * a) := by
rw [quadratic_eq_zero_iff_discrim_eq_sq ha, h, sq, mul_self_eq_mul_self_iff]
field_simp
apply or_congr
· constructor <;> intro h' <;> linear_combination -h'
· constructor <;> intro h' <;> linear_combination h'
/-- A quadratic has roots if its discriminant has square roots -/
theorem exists_quadratic_eq_zero (ha : a ≠ 0) (h : ∃ s, discrim a b c = s * s) :
∃ x, a * (x * x) + b * x + c = 0 := by
rcases h with ⟨s, hs⟩
use (-b + s) / (2 * a)
rw [quadratic_eq_zero_iff ha hs]
simp
| /-- Root of a quadratic when its discriminant equals zero -/
theorem quadratic_eq_zero_iff_of_discrim_eq_zero (ha : a ≠ 0) (h : discrim a b c = 0) (x : K) :
a * (x * x) + b * x + c = 0 ↔ x = -b / (2 * a) := by
have : discrim a b c = 0 * 0 := by rw [h, mul_zero]
rw [quadratic_eq_zero_iff ha this, add_zero, sub_zero, or_self_iff]
| Mathlib/Algebra/QuadraticDiscriminant.lean | 96 | 101 |
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn, Joachim Breitner
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.GroupTheory.Congruence.Basic
import Mathlib.GroupTheory.FreeGroup.IsFreeGroup
import Mathlib.SetTheory.Cardinal.Basic
/-!
# The coproduct (a.k.a. the free product) of groups or monoids
Given an `ι`-indexed family `M` of monoids,
we define their coproduct (a.k.a. free product) `Monoid.CoprodI M`.
As usual, we use the suffix `I` for an indexed (co)product,
leaving `Coprod` for the coproduct of two monoids.
When `ι` and all `M i` have decidable equality,
the free product bijects with the type `Monoid.CoprodI.Word M` of reduced words.
This bijection is constructed
by defining an action of `Monoid.CoprodI M` on `Monoid.CoprodI.Word M`.
When `M i` are all groups, `Monoid.CoprodI M` is also a group
(and the coproduct in the category of groups).
## Main definitions
- `Monoid.CoprodI M`: the free product, defined as a quotient of a free monoid.
- `Monoid.CoprodI.of {i} : M i →* Monoid.CoprodI M`.
- `Monoid.CoprodI.lift : (∀ {i}, M i →* N) ≃ (Monoid.CoprodI M →* N)`: the universal property.
- `Monoid.CoprodI.Word M`: the type of reduced words.
- `Monoid.CoprodI.Word.equiv M : Monoid.CoprodI M ≃ word M`.
- `Monoid.CoprodI.NeWord M i j`: an inductive description of non-empty words
with first letter from `M i` and last letter from `M j`,
together with an API (`singleton`, `append`, `head`, `tail`, `to_word`, `Prod`, `inv`).
Used in the proof of the Ping-Pong-lemma.
- `Monoid.CoprodI.lift_injective_of_ping_pong`: The Ping-Pong-lemma,
proving injectivity of the `lift`. See the documentation of that theorem for more information.
## Remarks
There are many answers to the question "what is the coproduct of a family `M` of monoids?",
and they are all equivalent but not obviously equivalent.
We provide two answers.
The first, almost tautological answer is given by `Monoid.CoprodI M`,
which is a quotient of the type of words in the alphabet `Σ i, M i`.
It's straightforward to define and easy to prove its universal property.
But this answer is not completely satisfactory,
because it's difficult to tell when two elements `x y : Monoid.CoprodI M` are distinct
since `Monoid.CoprodI M` is defined as a quotient.
The second, maximally efficient answer is given by `Monoid.CoprodI.Word M`.
An element of `Monoid.CoprodI.Word M` is a word in the alphabet `Σ i, M i`,
where the letter `⟨i, 1⟩` doesn't occur and no adjacent letters share an index `i`.
Since we only work with reduced words, there is no need for quotienting,
and it is easy to tell when two elements are distinct.
However it's not obvious that this is even a monoid!
We prove that every element of `Monoid.CoprodI M` can be represented by a unique reduced word,
i.e. `Monoid.CoprodI M` and `Monoid.CoprodI.Word M` are equivalent types.
This means that `Monoid.CoprodI.Word M` can be given a monoid structure,
and it lets us tell when two elements of `Monoid.CoprodI M` are distinct.
There is also a completely tautological, maximally inefficient answer
given by `MonCat.Colimits.ColimitType`.
Whereas `Monoid.CoprodI M` at least ensures that
(any instance of) associativity holds by reflexivity,
in this answer associativity holds because of quotienting.
Yet another answer, which is constructively more satisfying,
could be obtained by showing that `Monoid.CoprodI.Rel` is confluent.
## References
[van der Waerden, *Free products of groups*][MR25465]
-/
open Set
variable {ι : Type*} (M : ι → Type*) [∀ i, Monoid (M i)]
/-- A relation on the free monoid on alphabet `Σ i, M i`,
relating `⟨i, 1⟩` with `1` and `⟨i, x⟩ * ⟨i, y⟩` with `⟨i, x * y⟩`. -/
inductive Monoid.CoprodI.Rel : FreeMonoid (Σ i, M i) → FreeMonoid (Σ i, M i) → Prop
| of_one (i : ι) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, 1⟩) 1
| of_mul {i : ι} (x y : M i) :
Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, x⟩ * FreeMonoid.of ⟨i, y⟩) (FreeMonoid.of ⟨i, x * y⟩)
/-- The free product (categorical coproduct) of an indexed family of monoids. -/
def Monoid.CoprodI : Type _ := (conGen (Monoid.CoprodI.Rel M)).Quotient
-- The `Monoid` instance should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : Monoid (Monoid.CoprodI M) := by
delta Monoid.CoprodI; infer_instance
instance : Inhabited (Monoid.CoprodI M) :=
⟨1⟩
namespace Monoid.CoprodI
/-- The type of reduced words. A reduced word cannot contain a letter `1`, and no two adjacent
letters can come from the same summand. -/
@[ext]
structure Word where
/-- A `Word` is a `List (Σ i, M i)`, such that `1` is not in the list, and no
two adjacent letters are from the same summand -/
toList : List (Σi, M i)
/-- A reduced word does not contain `1` -/
ne_one : ∀ l ∈ toList, Sigma.snd l ≠ 1
/-- Adjacent letters are not from the same summand. -/
chain_ne : toList.Chain' fun l l' => Sigma.fst l ≠ Sigma.fst l'
variable {M}
/-- The inclusion of a summand into the free product. -/
def of {i : ι} : M i →* CoprodI M where
toFun x := Con.mk' _ (FreeMonoid.of <| Sigma.mk i x)
map_one' := (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_one i))
map_mul' x y := Eq.symm <| (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_mul x y))
theorem of_apply {i} (m : M i) : of m = Con.mk' _ (FreeMonoid.of <| Sigma.mk i m) :=
rfl
variable {N : Type*} [Monoid N]
/-- See note [partially-applied ext lemmas]. -/
-- Porting note: higher `ext` priority
@[ext 1100]
theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
FreeMonoid.hom_eq fun ⟨i, x⟩ => by
rw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply]
unfold CoprodI
rw [← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h]
/-- A map out of the free product corresponds to a family of maps out of the summands. This is the
universal property of the free product, characterizing it as a categorical coproduct. -/
@[simps symm_apply]
def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where
toFun fi :=
Con.lift _ (FreeMonoid.lift fun p : Σi, M i => fi p.fst p.snd) <|
Con.conGen_le <| by
simp_rw [Con.ker_rel]
rintro _ _ (i | ⟨x, y⟩) <;> simp
invFun f _ := f.comp of
left_inv := by
intro fi
ext i x
rfl
right_inv := by
intro f
ext i x
rfl
@[simp]
theorem lift_comp_of {N} [Monoid N] (fi : ∀ i, M i →* N) i : (lift fi).comp of = fi i :=
congr_fun (lift.symm_apply_apply fi) i
@[simp]
theorem lift_of {N} [Monoid N] (fi : ∀ i, M i →* N) {i} (m : M i) : lift fi (of m) = fi i m :=
DFunLike.congr_fun (lift_comp_of ..) m
@[simp]
theorem lift_comp_of' {N} [Monoid N] (f : CoprodI M →* N) :
lift (fun i ↦ f.comp (of (i := i))) = f :=
lift.apply_symm_apply f
@[simp]
theorem lift_of' : lift (fun i ↦ (of : M i →* CoprodI M)) = .id (CoprodI M) :=
lift_comp_of' (.id _)
theorem of_leftInverse [DecidableEq ι] (i : ι) :
Function.LeftInverse (lift <| Pi.mulSingle i (MonoidHom.id (M i))) of := fun x => by
simp only [lift_of, Pi.mulSingle_eq_same, MonoidHom.id_apply]
theorem of_injective (i : ι) : Function.Injective (of : M i →* _) := by
classical exact (of_leftInverse i).injective
theorem mrange_eq_iSup {N} [Monoid N] (f : ∀ i, M i →* N) :
MonoidHom.mrange (lift f) = ⨆ i, MonoidHom.mrange (f i) := by
rw [lift, Equiv.coe_fn_mk, Con.lift_range, FreeMonoid.mrange_lift,
range_sigma_eq_iUnion_range, Submonoid.closure_iUnion]
simp only [MonoidHom.mclosure_range]
theorem lift_mrange_le {N} [Monoid N] (f : ∀ i, M i →* N) {s : Submonoid N} :
MonoidHom.mrange (lift f) ≤ s ↔ ∀ i, MonoidHom.mrange (f i) ≤ s := by
simp [mrange_eq_iSup]
@[simp]
theorem iSup_mrange_of : ⨆ i, MonoidHom.mrange (of : M i →* CoprodI M) = ⊤ := by
simp [← mrange_eq_iSup]
@[simp]
theorem mclosure_iUnion_range_of :
Submonoid.closure (⋃ i, Set.range (of : M i →* CoprodI M)) = ⊤ := by
simp [Submonoid.closure_iUnion]
@[elab_as_elim]
theorem induction_left {motive : CoprodI M → Prop} (m : CoprodI M) (one : motive 1)
(mul : ∀ {i} (m : M i) x, motive x → motive (of m * x)) : motive m := by
induction m using Submonoid.induction_of_closure_eq_top_left mclosure_iUnion_range_of with
| one => exact one
| mul x hx y ihy =>
obtain ⟨i, m, rfl⟩ : ∃ (i : ι) (m : M i), of m = x := by simpa using hx
exact mul m y ihy
@[elab_as_elim]
theorem induction_on {motive : CoprodI M → Prop} (m : CoprodI M) (one : motive 1)
(of : ∀ (i) (m : M i), motive (of m))
(mul : ∀ x y, motive x → motive y → motive (x * y)) : motive m := by
induction m using CoprodI.induction_left with
| one => exact one
| mul m x hx => exact mul _ _ (of _ _) hx
section Group
variable (G : ι → Type*) [∀ i, Group (G i)]
instance : Inv (CoprodI G) where
| inv :=
MulOpposite.unop ∘ lift fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom
theorem inv_def (x : CoprodI G) :
x⁻¹ =
MulOpposite.unop
(lift (fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom) x) :=
| Mathlib/GroupTheory/CoprodI.lean | 225 | 231 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.Continuous
import Mathlib.Topology.Defs.Induced
/-!
# Ordering on topologies and (co)induced topologies
Topologies on a fixed type `α` are ordered, by reverse inclusion. That is, for topologies `t₁` and
`t₂` on `α`, we write `t₁ ≤ t₂` if every set open in `t₂` is also open in `t₁`. (One also calls
`t₁` *finer* than `t₂`, and `t₂` *coarser* than `t₁`.)
Any function `f : α → β` induces
* `TopologicalSpace.induced f : TopologicalSpace β → TopologicalSpace α`;
* `TopologicalSpace.coinduced f : TopologicalSpace α → TopologicalSpace β`.
Continuity, the ordering on topologies and (co)induced topologies are related as follows:
* The identity map `(α, t₁) → (α, t₂)` is continuous iff `t₁ ≤ t₂`.
* A map `f : (α, t) → (β, u)` is continuous
* iff `t ≤ TopologicalSpace.induced f u` (`continuous_iff_le_induced`)
* iff `TopologicalSpace.coinduced f t ≤ u` (`continuous_iff_coinduced_le`).
Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete
topology.
For a function `f : α → β`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois
connection between topologies on `α` and topologies on `β`.
## Implementation notes
There is a Galois insertion between topologies on `α` (with the inclusion ordering) and all
collections of sets in `α`. The complete lattice structure on topologies on `α` is defined as the
reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding
Galois coinsertion between topologies on `α` (with the reversed inclusion ordering) and collections
of sets in `α` (with the reversed inclusion ordering).
## Tags
finer, coarser, induced topology, coinduced topology
-/
open Function Set Filter Topology
universe u v w
namespace TopologicalSpace
variable {α : Type u}
/-- The open sets of the least topology containing a collection of basic sets. -/
inductive GenerateOpen (g : Set (Set α)) : Set α → Prop
| basic : ∀ s ∈ g, GenerateOpen g s
| univ : GenerateOpen g univ
| inter : ∀ s t, GenerateOpen g s → GenerateOpen g t → GenerateOpen g (s ∩ t)
| sUnion : ∀ S : Set (Set α), (∀ s ∈ S, GenerateOpen g s) → GenerateOpen g (⋃₀ S)
/-- The smallest topological space containing the collection `g` of basic sets -/
def generateFrom (g : Set (Set α)) : TopologicalSpace α where
IsOpen := GenerateOpen g
isOpen_univ := GenerateOpen.univ
isOpen_inter := GenerateOpen.inter
isOpen_sUnion := GenerateOpen.sUnion
theorem isOpen_generateFrom_of_mem {g : Set (Set α)} {s : Set α} (hs : s ∈ g) :
IsOpen[generateFrom g] s :=
GenerateOpen.basic s hs
theorem nhds_generateFrom {g : Set (Set α)} {a : α} :
@nhds α (generateFrom g) a = ⨅ s ∈ { s | a ∈ s ∧ s ∈ g }, 𝓟 s := by
letI := generateFrom g
rw [nhds_def]
refine le_antisymm (biInf_mono fun s ⟨as, sg⟩ => ⟨as, .basic _ sg⟩) <| le_iInf₂ ?_
rintro s ⟨ha, hs⟩
induction hs with
| basic _ hs => exact iInf₂_le _ ⟨ha, hs⟩
| univ => exact le_top.trans_eq principal_univ.symm
| inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal
| sUnion _ _ hS =>
let ⟨t, htS, hat⟩ := ha
exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS)
lemma tendsto_nhds_generateFrom_iff {β : Type*} {m : α → β} {f : Filter α} {g : Set (Set β)}
{b : β} : Tendsto m f (@nhds β (generateFrom g) b) ↔ ∀ s ∈ g, b ∈ s → m ⁻¹' s ∈ f := by
simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp,
tendsto_principal]; rfl
/-- Construct a topology on α given the filter of neighborhoods of each point of α. -/
protected def mkOfNhds (n : α → Filter α) : TopologicalSpace α where
IsOpen s := ∀ a ∈ s, s ∈ n a
isOpen_univ _ _ := univ_mem
isOpen_inter := fun _s _t hs ht x ⟨hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt)
isOpen_sUnion := fun _s hs _a ⟨x, hx, hxa⟩ =>
mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx)
theorem nhds_mkOfNhds_of_hasBasis {n : α → Filter α} {ι : α → Sort*} {p : ∀ a, ι a → Prop}
{s : ∀ a, ι a → Set α} (hb : ∀ a, (n a).HasBasis (p a) (s a))
(hpure : ∀ a i, p a i → a ∈ s a i) (hopen : ∀ a i, p a i → ∀ᶠ x in n a, s a i ∈ n x) (a : α) :
@nhds α (.mkOfNhds n) a = n a := by
let t : TopologicalSpace α := .mkOfNhds n
apply le_antisymm
· intro U hU
replace hpure : pure ≤ n := fun x ↦ (hb x).ge_iff.2 (hpure x)
refine mem_nhds_iff.2 ⟨{x | U ∈ n x}, fun x hx ↦ hpure x hx, fun x hx ↦ ?_, hU⟩
rcases (hb x).mem_iff.1 hx with ⟨i, hpi, hi⟩
exact (hopen x i hpi).mono fun y hy ↦ mem_of_superset hy hi
· exact (nhds_basis_opens a).ge_iff.2 fun U ⟨haU, hUo⟩ ↦ hUo a haU
theorem nhds_mkOfNhds (n : α → Filter α) (a : α) (h₀ : pure ≤ n)
(h₁ : ∀ a, ∀ s ∈ n a, ∀ᶠ y in n a, s ∈ n y) :
@nhds α (TopologicalSpace.mkOfNhds n) a = n a :=
nhds_mkOfNhds_of_hasBasis (fun a ↦ (n a).basis_sets) h₀ h₁ _
theorem nhds_mkOfNhds_single [DecidableEq α] {a₀ : α} {l : Filter α} (h : pure a₀ ≤ l) (b : α) :
@nhds α (TopologicalSpace.mkOfNhds (update pure a₀ l)) b =
(update pure a₀ l : α → Filter α) b := by
refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟨h, fun _ _ => le_rfl⟩) fun a s hs => ?_
rcases eq_or_ne a a₀ with (rfl | ha)
· filter_upwards [hs] with b hb
rcases eq_or_ne b a with (rfl | hb)
· exact hs
· rwa [update_of_ne hb]
· simpa only [update_of_ne ha, mem_pure, eventually_pure] using hs
theorem nhds_mkOfNhds_filterBasis (B : α → FilterBasis α) (a : α) (h₀ : ∀ x, ∀ n ∈ B x, x ∈ n)
(h₁ : ∀ x, ∀ n ∈ B x, ∃ n₁ ∈ B x, ∀ x' ∈ n₁, ∃ n₂ ∈ B x', n₂ ⊆ n) :
@nhds α (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter :=
nhds_mkOfNhds_of_hasBasis (fun a ↦ (B a).hasBasis) h₀ h₁ a
section Lattice
variable {α : Type u} {β : Type v}
/-- The ordering on topologies on the type `α`. `t ≤ s` if every set open in `s` is also open in `t`
(`t` is finer than `s`). -/
instance : PartialOrder (TopologicalSpace α) :=
{ PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with
le := fun s t => ∀ U, IsOpen[t] U → IsOpen[s] U }
protected theorem le_def {α} {t s : TopologicalSpace α} : t ≤ s ↔ IsOpen[s] ≤ IsOpen[t] :=
Iff.rfl
theorem le_generateFrom_iff_subset_isOpen {g : Set (Set α)} {t : TopologicalSpace α} :
t ≤ generateFrom g ↔ g ⊆ { s | IsOpen[t] s } :=
⟨fun ht s hs => ht _ <| .basic s hs, fun hg _s hs =>
hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩
/-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a
topology. -/
protected def mkOfClosure (s : Set (Set α)) (hs : { u | GenerateOpen s u } = s) :
TopologicalSpace α where
IsOpen u := u ∈ s
isOpen_univ := hs ▸ TopologicalSpace.GenerateOpen.univ
isOpen_inter := hs ▸ TopologicalSpace.GenerateOpen.inter
isOpen_sUnion := hs ▸ TopologicalSpace.GenerateOpen.sUnion
theorem mkOfClosure_sets {s : Set (Set α)} {hs : { u | GenerateOpen s u } = s} :
TopologicalSpace.mkOfClosure s hs = generateFrom s :=
TopologicalSpace.ext hs.symm
theorem gc_generateFrom (α) :
GaloisConnection (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s })
(generateFrom ∘ OrderDual.ofDual) := fun _ _ =>
le_generateFrom_iff_subset_isOpen.symm
/-- The Galois coinsertion between `TopologicalSpace α` and `(Set (Set α))ᵒᵈ` whose lower part sends
a topology to its collection of open subsets, and whose upper part sends a collection of subsets
of `α` to the topology they generate. -/
def gciGenerateFrom (α : Type*) :
GaloisCoinsertion (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s })
(generateFrom ∘ OrderDual.ofDual) where
gc := gc_generateFrom α
u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs
choice g hg := TopologicalSpace.mkOfClosure g
(Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
/-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology
and `⊤` the indiscrete topology. The infimum of a collection of topologies
is the topology generated by all their open sets, while the supremum is the
topology whose open sets are those sets open in every member of the collection. -/
instance : CompleteLattice (TopologicalSpace α) := (gciGenerateFrom α).liftCompleteLattice
@[mono, gcongr]
theorem generateFrom_anti {α} {g₁ g₂ : Set (Set α)} (h : g₁ ⊆ g₂) :
generateFrom g₂ ≤ generateFrom g₁ :=
(gc_generateFrom _).monotone_u h
theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) :
generateFrom { s | IsOpen[t] s } = t :=
(gciGenerateFrom α).u_l_eq t
theorem leftInverse_generateFrom :
LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } :=
(gciGenerateFrom α).u_l_leftInverse
theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) :=
(gciGenerateFrom α).u_surjective
theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace α => { s | IsOpen[t] s } :=
(gciGenerateFrom α).l_injective
end Lattice
end TopologicalSpace
section Lattice
variable {α : Type*} {t t₁ t₂ : TopologicalSpace α} {s : Set α}
theorem IsOpen.mono (hs : IsOpen[t₂] s) (h : t₁ ≤ t₂) : IsOpen[t₁] s := h s hs
theorem IsClosed.mono (hs : IsClosed[t₂] s) (h : t₁ ≤ t₂) : IsClosed[t₁] s :=
(@isOpen_compl_iff α s t₁).mp <| hs.isOpen_compl.mono h
theorem closure.mono (h : t₁ ≤ t₂) : closure[t₁] s ⊆ closure[t₂] s :=
@closure_minimal _ t₁ s (@closure _ t₂ s) subset_closure (IsClosed.mono isClosed_closure h)
theorem isOpen_implies_isOpen_iff : (∀ s, IsOpen[t₁] s → IsOpen[t₂] s) ↔ t₂ ≤ t₁ :=
Iff.rfl
/-- The only open sets in the indiscrete topology are the empty set and the whole space. -/
theorem TopologicalSpace.isOpen_top_iff {α} (U : Set α) : IsOpen[⊤] U ↔ U = ∅ ∨ U = univ :=
⟨fun h => by
induction h with
| basic _ h => exact False.elim h
| univ => exact .inr rfl
| inter _ _ _ _ h₁ h₂ =>
rcases h₁ with (rfl | rfl) <;> rcases h₂ with (rfl | rfl) <;> simp
| sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by
rintro (rfl | rfl)
exacts [@isOpen_empty _ ⊤, @isOpen_univ _ ⊤]⟩
/-- A topological space is discrete if every set is open, that is,
its topology equals the discrete topology `⊥`. -/
class DiscreteTopology (α : Type*) [t : TopologicalSpace α] : Prop where
/-- The `TopologicalSpace` structure on a type with discrete topology is equal to `⊥`. -/
eq_bot : t = ⊥
theorem discreteTopology_bot (α : Type*) : @DiscreteTopology α ⊥ :=
@DiscreteTopology.mk α ⊥ rfl
section DiscreteTopology
variable [TopologicalSpace α] [DiscreteTopology α] {β : Type*}
@[simp]
theorem isOpen_discrete (s : Set α) : IsOpen s := (@DiscreteTopology.eq_bot α _).symm ▸ trivial
@[simp] theorem isClosed_discrete (s : Set α) : IsClosed s := ⟨isOpen_discrete _⟩
theorem closure_discrete (s : Set α) : closure s = s := (isClosed_discrete _).closure_eq
@[simp] theorem dense_discrete {s : Set α} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq]
@[simp]
theorem denseRange_discrete {ι : Type*} {f : ι → α} : DenseRange f ↔ Surjective f := by
rw [DenseRange, dense_discrete, range_eq_univ]
@[nontriviality, continuity, fun_prop]
theorem continuous_of_discreteTopology [TopologicalSpace β] {f : α → β} : Continuous f :=
continuous_def.2 fun _ _ => isOpen_discrete _
/-- A function to a discrete topological space is continuous if and only if the preimage of every
singleton is open. -/
theorem continuous_discrete_rng {α} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β]
{f : α → β} : Continuous f ↔ ∀ b : β, IsOpen (f ⁻¹' {b}) :=
⟨fun h _ => (isOpen_discrete _).preimage h, fun h => ⟨fun s _ => by
rw [← biUnion_of_singleton s, preimage_iUnion₂]
exact isOpen_biUnion fun _ _ => h _⟩⟩
@[simp]
theorem nhds_discrete (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : @nhds α _ = pure :=
le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds
theorem mem_nhds_discrete {x : α} {s : Set α} :
s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure]
end DiscreteTopology
theorem le_of_nhds_le_nhds (h : ∀ x, @nhds α t₁ x ≤ @nhds α t₂ x) : t₁ ≤ t₂ := fun s => by
rw [@isOpen_iff_mem_nhds _ t₁, @isOpen_iff_mem_nhds _ t₂]
exact fun hs a ha => h _ (hs _ ha)
theorem eq_bot_of_singletons_open {t : TopologicalSpace α} (h : ∀ x, IsOpen[t] {x}) : t = ⊥ :=
bot_unique fun s _ => biUnion_of_singleton s ▸ isOpen_biUnion fun x _ => h x
theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] :
(∀ s : Set X, IsOpen s) ↔ DiscreteTopology X :=
⟨fun h => ⟨eq_bot_of_singletons_open fun _ => h _⟩, @isOpen_discrete _ _⟩
theorem discreteTopology_iff_forall_isClosed [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ s : Set α, IsClosed s :=
forall_open_iff_discrete.symm.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↦
isOpen_compl_iff
theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] :
(∀ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X :=
⟨fun h => ⟨eq_bot_of_singletons_open h⟩, fun a _ => @isOpen_discrete _ _ a _⟩
theorem DiscreteTopology.of_finite_of_isClosed_singleton [TopologicalSpace α] [Finite α]
(h : ∀ a : α, IsClosed {a}) : DiscreteTopology α :=
discreteTopology_iff_forall_isClosed.mpr fun s ↦
s.iUnion_of_singleton_coe ▸ isClosed_iUnion_of_finite fun _ ↦ h _
theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ x : α, {x} ∈ 𝓝 x := by
simp only [← singletons_open_iff_discrete, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq]
/-- This lemma characterizes discrete topological spaces as those whose singletons are
neighbourhoods. -/
theorem discreteTopology_iff_nhds [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ x : α, 𝓝 x = pure x := by
simp [discreteTopology_iff_singleton_mem_nhds, le_pure_iff]
apply forall_congr' (fun x ↦ ?_)
simp [le_antisymm_iff, pure_le_nhds x]
theorem discreteTopology_iff_nhds_ne [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ x : α, 𝓝[≠] x = ⊥ := by
simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl]
/-- If the codomain of a continuous injective function has discrete topology,
then so does the domain.
See also `Embedding.discreteTopology` for an important special case. -/
theorem DiscreteTopology.of_continuous_injective
{β : Type*} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β}
(hc : Continuous f) (hinj : Injective f) : DiscreteTopology α :=
forall_open_iff_discrete.1 fun s ↦ hinj.preimage_image s ▸ (isOpen_discrete _).preimage hc
end Lattice
section GaloisConnection
variable {α β γ : Type*}
theorem isOpen_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} :
IsOpen[t.induced f] s ↔ ∃ t, IsOpen t ∧ f ⁻¹' t = s :=
Iff.rfl
theorem isClosed_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} :
IsClosed[t.induced f] s ↔ ∃ t, IsClosed t ∧ f ⁻¹' t = s := by
letI := t.induced f
simp only [← isOpen_compl_iff, isOpen_induced_iff]
exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff])
theorem isOpen_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} :
IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) :=
Iff.rfl
theorem isClosed_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} :
IsClosed[t.coinduced f] s ↔ IsClosed (f ⁻¹' s) := by
simp only [← isOpen_compl_iff, isOpen_coinduced (f := f), preimage_compl]
theorem preimage_nhds_coinduced [TopologicalSpace α] {π : α → β} {s : Set β} {a : α}
(hs : s ∈ @nhds β (TopologicalSpace.coinduced π ‹_›) (π a)) : π ⁻¹' s ∈ 𝓝 a := by
letI := TopologicalSpace.coinduced π ‹_›
rcases mem_nhds_iff.mp hs with ⟨V, hVs, V_op, mem_V⟩
exact mem_nhds_iff.mpr ⟨π ⁻¹' V, Set.preimage_mono hVs, V_op, mem_V⟩
variable {t t₁ t₂ : TopologicalSpace α} {t' : TopologicalSpace β} {f : α → β} {g : β → α}
theorem Continuous.coinduced_le (h : Continuous[t, t'] f) : t.coinduced f ≤ t' :=
(@continuous_def α β t t').1 h
theorem coinduced_le_iff_le_induced {f : α → β} {tα : TopologicalSpace α}
{tβ : TopologicalSpace β} : tα.coinduced f ≤ tβ ↔ tα ≤ tβ.induced f :=
⟨fun h _s ⟨_t, ht, hst⟩ => hst ▸ h _ ht, fun h s hs => h _ ⟨s, hs, rfl⟩⟩
theorem Continuous.le_induced (h : Continuous[t, t'] f) : t ≤ t'.induced f :=
coinduced_le_iff_le_induced.1 h.coinduced_le
theorem gc_coinduced_induced (f : α → β) :
GaloisConnection (TopologicalSpace.coinduced f) (TopologicalSpace.induced f) := fun _ _ =>
coinduced_le_iff_le_induced
theorem induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g :=
(gc_coinduced_induced g).monotone_u h
theorem coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f :=
(gc_coinduced_induced f).monotone_l h
@[simp]
theorem induced_top : (⊤ : TopologicalSpace α).induced g = ⊤ :=
(gc_coinduced_induced g).u_top
@[simp]
theorem induced_inf : (t₁ ⊓ t₂).induced g = t₁.induced g ⊓ t₂.induced g :=
(gc_coinduced_induced g).u_inf
@[simp]
theorem induced_iInf {ι : Sort w} {t : ι → TopologicalSpace α} :
(⨅ i, t i).induced g = ⨅ i, (t i).induced g :=
(gc_coinduced_induced g).u_iInf
@[simp]
theorem induced_sInf {s : Set (TopologicalSpace α)} :
TopologicalSpace.induced g (sInf s) = sInf (TopologicalSpace.induced g '' s) := by
rw [sInf_eq_iInf', sInf_image', induced_iInf]
@[simp]
theorem coinduced_bot : (⊥ : TopologicalSpace α).coinduced f = ⊥ :=
(gc_coinduced_induced f).l_bot
@[simp]
theorem coinduced_sup : (t₁ ⊔ t₂).coinduced f = t₁.coinduced f ⊔ t₂.coinduced f :=
(gc_coinduced_induced f).l_sup
@[simp]
theorem coinduced_iSup {ι : Sort w} {t : ι → TopologicalSpace α} :
(⨆ i, t i).coinduced f = ⨆ i, (t i).coinduced f :=
(gc_coinduced_induced f).l_iSup
@[simp]
theorem coinduced_sSup {s : Set (TopologicalSpace α)} :
TopologicalSpace.coinduced f (sSup s) = sSup ((TopologicalSpace.coinduced f) '' s) := by
rw [sSup_eq_iSup', sSup_image', coinduced_iSup]
theorem induced_id [t : TopologicalSpace α] : t.induced id = t :=
TopologicalSpace.ext <|
funext fun s => propext <| ⟨fun ⟨_, hs, h⟩ => h ▸ hs, fun hs => ⟨s, hs, rfl⟩⟩
theorem induced_compose {tγ : TopologicalSpace γ} {f : α → β} {g : β → γ} :
(tγ.induced g).induced f = tγ.induced (g ∘ f) :=
TopologicalSpace.ext <|
funext fun _ => propext
⟨fun ⟨_, ⟨s, hs, h₂⟩, h₁⟩ => h₁ ▸ h₂ ▸ ⟨s, hs, rfl⟩,
fun ⟨s, hs, h⟩ => ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩
theorem induced_const [t : TopologicalSpace α] {x : α} : (t.induced fun _ : β => x) = ⊤ :=
le_antisymm le_top (@continuous_const β α ⊤ t x).le_induced
theorem coinduced_id [t : TopologicalSpace α] : t.coinduced id = t :=
TopologicalSpace.ext rfl
theorem coinduced_compose [tα : TopologicalSpace α] {f : α → β} {g : β → γ} :
(tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) :=
TopologicalSpace.ext rfl
theorem Equiv.induced_symm {α β : Type*} (e : α ≃ β) :
TopologicalSpace.induced e.symm = TopologicalSpace.coinduced e := by
ext t U
rw [isOpen_induced_iff, isOpen_coinduced]
simp only [e.symm.preimage_eq_iff_eq_image, exists_eq_right, ← preimage_equiv_eq_image_symm]
theorem Equiv.coinduced_symm {α β : Type*} (e : α ≃ β) :
TopologicalSpace.coinduced e.symm = TopologicalSpace.induced e :=
e.symm.induced_symm.symm
end GaloisConnection
-- constructions using the complete lattice structure
section Constructions
open TopologicalSpace
variable {α : Type u} {β : Type v}
instance inhabitedTopologicalSpace {α : Type u} : Inhabited (TopologicalSpace α) :=
⟨⊥⟩
instance (priority := 100) Subsingleton.uniqueTopologicalSpace [Subsingleton α] :
Unique (TopologicalSpace α) where
default := ⊥
uniq t :=
eq_bot_of_singletons_open fun x =>
Subsingleton.set_cases (@isOpen_empty _ t) (@isOpen_univ _ t) ({x} : Set α)
instance (priority := 100) Subsingleton.discreteTopology [t : TopologicalSpace α] [Subsingleton α] :
DiscreteTopology α :=
⟨Unique.eq_default t⟩
instance : TopologicalSpace Empty := ⊥
instance : DiscreteTopology Empty := ⟨rfl⟩
instance : TopologicalSpace PEmpty := ⊥
instance : DiscreteTopology PEmpty := ⟨rfl⟩
instance : TopologicalSpace PUnit := ⊥
instance : DiscreteTopology PUnit := ⟨rfl⟩
instance : TopologicalSpace Bool := ⊥
instance : DiscreteTopology Bool := ⟨rfl⟩
instance : TopologicalSpace ℕ := ⊥
instance : DiscreteTopology ℕ := ⟨rfl⟩
instance : TopologicalSpace ℤ := ⊥
instance : DiscreteTopology ℤ := ⟨rfl⟩
instance {n} : TopologicalSpace (Fin n) := ⊥
instance {n} : DiscreteTopology (Fin n) := ⟨rfl⟩
instance sierpinskiSpace : TopologicalSpace Prop :=
generateFrom {{True}}
/-- See also `continuous_of_discreteTopology`, which works for `IsEmpty α`. -/
theorem continuous_empty_function [TopologicalSpace α] [TopologicalSpace β] [IsEmpty β]
(f : α → β) : Continuous f :=
letI := Function.isEmpty f
continuous_of_discreteTopology
theorem le_generateFrom {t : TopologicalSpace α} {g : Set (Set α)} (h : ∀ s ∈ g, IsOpen s) :
t ≤ generateFrom g :=
le_generateFrom_iff_subset_isOpen.2 h
theorem induced_generateFrom_eq {α β} {b : Set (Set β)} {f : α → β} :
(generateFrom b).induced f = generateFrom (preimage f '' b) :=
le_antisymm (le_generateFrom <| forall_mem_image.2 fun s hs => ⟨s, GenerateOpen.basic _ hs, rfl⟩)
(coinduced_le_iff_le_induced.1 <| le_generateFrom fun _s hs => .basic _ (mem_image_of_mem _ hs))
theorem le_induced_generateFrom {α β} [t : TopologicalSpace α] {b : Set (Set β)} {f : α → β}
(h : ∀ a : Set β, a ∈ b → IsOpen (f ⁻¹' a)) : t ≤ induced f (generateFrom b) := by
rw [induced_generateFrom_eq]
apply le_generateFrom
simp only [mem_image, and_imp, forall_apply_eq_imp_iff₂, exists_imp]
exact h
lemma generateFrom_insert_of_generateOpen {α : Type*} {s : Set (Set α)} {t : Set α}
(ht : GenerateOpen s t) : generateFrom (insert t s) = generateFrom s := by
refine le_antisymm (generateFrom_anti <| subset_insert t s) (le_generateFrom ?_)
rintro t (rfl | h)
· exact ht
· exact isOpen_generateFrom_of_mem h
@[simp]
lemma generateFrom_insert_univ {α : Type*} {s : Set (Set α)} :
generateFrom (insert univ s) = generateFrom s :=
generateFrom_insert_of_generateOpen .univ
@[simp]
lemma generateFrom_insert_empty {α : Type*} {s : Set (Set α)} :
generateFrom (insert ∅ s) = generateFrom s := by
rw [← sUnion_empty]
exact generateFrom_insert_of_generateOpen (.sUnion ∅ (fun s_1 a ↦ False.elim a))
/-- This construction is left adjoint to the operation sending a topology on `α`
to its neighborhood filter at a fixed point `a : α`. -/
def nhdsAdjoint (a : α) (f : Filter α) : TopologicalSpace α where
IsOpen s := a ∈ s → s ∈ f
isOpen_univ _ := univ_mem
isOpen_inter := fun _s _t hs ht ⟨has, hat⟩ => inter_mem (hs has) (ht hat)
isOpen_sUnion := fun _k hk ⟨u, hu, hau⟩ => mem_of_superset (hk u hu hau) (subset_sUnion_of_mem hu)
theorem gc_nhds (a : α) : GaloisConnection (nhdsAdjoint a) fun t => @nhds α t a := fun f t => by
rw [le_nhds_iff]
exact ⟨fun H s hs has => H _ has hs, fun H s has hs => H _ hs has⟩
theorem nhds_mono {t₁ t₂ : TopologicalSpace α} {a : α} (h : t₁ ≤ t₂) :
@nhds α t₁ a ≤ @nhds α t₂ a :=
(gc_nhds a).monotone_u h
theorem le_iff_nhds {α : Type*} (t t' : TopologicalSpace α) :
t ≤ t' ↔ ∀ x, @nhds α t x ≤ @nhds α t' x :=
⟨fun h _ => nhds_mono h, le_of_nhds_le_nhds⟩
theorem isOpen_singleton_nhdsAdjoint {α : Type*} {a b : α} (f : Filter α) (hb : b ≠ a) :
IsOpen[nhdsAdjoint a f] {b} := fun h ↦
absurd h hb.symm
theorem nhds_nhdsAdjoint_same (a : α) (f : Filter α) :
@nhds α (nhdsAdjoint a f) a = pure a ⊔ f := by
let _ := nhdsAdjoint a f
apply le_antisymm
· rintro t ⟨hat : a ∈ t, htf : t ∈ f⟩
exact IsOpen.mem_nhds (fun _ ↦ htf) hat
· exact sup_le (pure_le_nhds _) ((gc_nhds a).le_u_l f)
theorem nhds_nhdsAdjoint_of_ne {a b : α} (f : Filter α) (h : b ≠ a) :
@nhds α (nhdsAdjoint a f) b = pure b :=
let _ := nhdsAdjoint a f
(isOpen_singleton_iff_nhds_eq_pure _).1 <| isOpen_singleton_nhdsAdjoint f h
theorem nhds_nhdsAdjoint [DecidableEq α] (a : α) (f : Filter α) :
@nhds α (nhdsAdjoint a f) = update pure a (pure a ⊔ f) :=
eq_update_iff.2 ⟨nhds_nhdsAdjoint_same .., fun _ ↦ nhds_nhdsAdjoint_of_ne _⟩
theorem le_nhdsAdjoint_iff' {a : α} {f : Filter α} {t : TopologicalSpace α} :
t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, @nhds α t b = pure b := by
classical
simp_rw [le_iff_nhds, nhds_nhdsAdjoint, forall_update_iff, (pure_le_nhds _).le_iff_eq]
theorem le_nhdsAdjoint_iff {α : Type*} (a : α) (f : Filter α) (t : TopologicalSpace α) :
t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, IsOpen[t] {b} := by
simp only [le_nhdsAdjoint_iff', @isOpen_singleton_iff_nhds_eq_pure α t]
theorem nhds_iInf {ι : Sort*} {t : ι → TopologicalSpace α} {a : α} :
@nhds α (iInf t) a = ⨅ i, @nhds α (t i) a :=
(gc_nhds a).u_iInf
theorem nhds_sInf {s : Set (TopologicalSpace α)} {a : α} :
@nhds α (sInf s) a = ⨅ t ∈ s, @nhds α t a :=
(gc_nhds a).u_sInf
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: timeouts without `b₁ := t₁`
theorem nhds_inf {t₁ t₂ : TopologicalSpace α} {a : α} :
@nhds α (t₁ ⊓ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a :=
(gc_nhds a).u_inf (b₁ := t₁)
theorem nhds_top {a : α} : @nhds α ⊤ a = ⊤ :=
(gc_nhds a).u_top
theorem isOpen_sup {t₁ t₂ : TopologicalSpace α} {s : Set α} :
IsOpen[t₁ ⊔ t₂] s ↔ IsOpen[t₁] s ∧ IsOpen[t₂] s :=
Iff.rfl
open TopologicalSpace
variable {γ : Type*} {f : α → β} {ι : Sort*}
theorem continuous_iff_coinduced_le {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} :
Continuous[t₁, t₂] f ↔ coinduced f t₁ ≤ t₂ :=
continuous_def
theorem continuous_iff_le_induced {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} :
Continuous[t₁, t₂] f ↔ t₁ ≤ induced f t₂ :=
Iff.trans continuous_iff_coinduced_le (gc_coinduced_induced f _ _)
lemma continuous_generateFrom_iff {t : TopologicalSpace α} {b : Set (Set β)} :
Continuous[t, generateFrom b] f ↔ ∀ s ∈ b, IsOpen (f ⁻¹' s) := by
rw [continuous_iff_coinduced_le, le_generateFrom_iff_subset_isOpen]
simp only [isOpen_coinduced, preimage_id', subset_def, mem_setOf]
@[continuity, fun_prop]
theorem continuous_induced_dom {t : TopologicalSpace β} : Continuous[induced f t, t] f :=
continuous_iff_le_induced.2 le_rfl
theorem continuous_induced_rng {g : γ → α} {t₂ : TopologicalSpace β} {t₁ : TopologicalSpace γ} :
Continuous[t₁, induced f t₂] g ↔ Continuous[t₁, t₂] (f ∘ g) := by
simp only [continuous_iff_le_induced, induced_compose]
theorem continuous_coinduced_rng {t : TopologicalSpace α} :
Continuous[t, coinduced f t] f :=
continuous_iff_coinduced_le.2 le_rfl
theorem continuous_coinduced_dom {g : β → γ} {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace γ} :
Continuous[coinduced f t₁, t₂] g ↔ Continuous[t₁, t₂] (g ∘ f) := by
simp only [continuous_iff_coinduced_le, coinduced_compose]
theorem continuous_le_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁)
(h₂ : Continuous[t₁, t₃] f) : Continuous[t₂, t₃] f := by
rw [continuous_iff_le_induced] at h₂ ⊢
exact le_trans h₁ h₂
theorem continuous_le_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃)
(h₂ : Continuous[t₁, t₂] f) : Continuous[t₁, t₃] f := by
rw [continuous_iff_coinduced_le] at h₂ ⊢
exact le_trans h₂ h₁
theorem continuous_sup_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} :
Continuous[t₁ ⊔ t₂, t₃] f ↔ Continuous[t₁, t₃] f ∧ Continuous[t₂, t₃] f := by
simp only [continuous_iff_le_induced, sup_le_iff]
theorem continuous_sup_rng_left {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} :
Continuous[t₁, t₂] f → Continuous[t₁, t₂ ⊔ t₃] f :=
continuous_le_rng le_sup_left
theorem continuous_sup_rng_right {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} :
Continuous[t₁, t₃] f → Continuous[t₁, t₂ ⊔ t₃] f :=
continuous_le_rng le_sup_right
theorem continuous_sSup_dom {T : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β} :
Continuous[sSup T, t₂] f ↔ ∀ t ∈ T, Continuous[t, t₂] f := by
simp only [continuous_iff_le_induced, sSup_le_iff]
theorem continuous_sSup_rng {t₁ : TopologicalSpace α} {t₂ : Set (TopologicalSpace β)}
{t : TopologicalSpace β} (h₁ : t ∈ t₂) (hf : Continuous[t₁, t] f) :
Continuous[t₁, sSup t₂] f :=
continuous_iff_coinduced_le.2 <| le_sSup_of_le h₁ <| continuous_iff_coinduced_le.1 hf
theorem continuous_iSup_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} :
Continuous[iSup t₁, t₂] f ↔ ∀ i, Continuous[t₁ i, t₂] f := by
simp only [continuous_iff_le_induced, iSup_le_iff]
theorem continuous_iSup_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} {i : ι}
(h : Continuous[t₁, t₂ i] f) : Continuous[t₁, iSup t₂] f :=
continuous_sSup_rng ⟨i, rfl⟩ h
theorem continuous_inf_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} :
Continuous[t₁, t₂ ⊓ t₃] f ↔ Continuous[t₁, t₂] f ∧ Continuous[t₁, t₃] f := by
simp only [continuous_iff_coinduced_le, le_inf_iff]
theorem continuous_inf_dom_left {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} :
Continuous[t₁, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f :=
continuous_le_dom inf_le_left
theorem continuous_inf_dom_right {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} :
Continuous[t₂, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f :=
continuous_le_dom inf_le_right
theorem continuous_sInf_dom {t₁ : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β}
{t : TopologicalSpace α} (h₁ : t ∈ t₁) :
Continuous[t, t₂] f → Continuous[sInf t₁, t₂] f :=
continuous_le_dom <| sInf_le h₁
theorem continuous_sInf_rng {t₁ : TopologicalSpace α} {T : Set (TopologicalSpace β)} :
Continuous[t₁, sInf T] f ↔ ∀ t ∈ T, Continuous[t₁, t] f := by
simp only [continuous_iff_coinduced_le, le_sInf_iff]
theorem continuous_iInf_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} {i : ι} :
Continuous[t₁ i, t₂] f → Continuous[iInf t₁, t₂] f :=
continuous_le_dom <| iInf_le _ _
theorem continuous_iInf_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} :
Continuous[t₁, iInf t₂] f ↔ ∀ i, Continuous[t₁, t₂ i] f := by
simp only [continuous_iff_coinduced_le, le_iInf_iff]
@[continuity, fun_prop]
theorem continuous_bot {t : TopologicalSpace β} : Continuous[⊥, t] f :=
continuous_iff_le_induced.2 bot_le
@[continuity, fun_prop]
theorem continuous_top {t : TopologicalSpace α} : Continuous[t, ⊤] f :=
continuous_iff_coinduced_le.2 le_top
theorem continuous_id_iff_le {t t' : TopologicalSpace α} : Continuous[t, t'] id ↔ t ≤ t' :=
@continuous_def _ _ t t' id
| theorem continuous_id_of_le {t t' : TopologicalSpace α} (h : t ≤ t') : Continuous[t, t'] id :=
continuous_id_iff_le.2 h
-- 𝓝 in the induced topology
| Mathlib/Topology/Order.lean | 723 | 726 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine
import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle
/-!
# Oriented angles in right-angled triangles.
This file proves basic geometrical results about distances and oriented angles in (possibly
degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces.
-/
noncomputable section
open scoped EuclideanGeometry
open scoped Real
open scoped RealInnerProductSpace
namespace Orientation
open Module
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side. -/
theorem norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle x (x + y)) = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side. -/
theorem norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle (x + y) y) = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arccos (‖y‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arccos (‖x‖ / ‖x - y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arcsin (‖x‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arcsin (‖y‖ / ‖x - y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arctan (‖x‖ / ‖y‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arctan (‖y‖ / ‖x‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle y (y - x)) = ‖y‖ / ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x - y) x) = ‖x‖ / ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).cos_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle y (y - x)) = ‖x‖ / ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x - y) x) = ‖y‖ / ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).sin_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle y (y - x)) = ‖x‖ / ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x - y) x) = ‖y‖ / ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).tan_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side, version subtracting vectors. -/
theorem cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) * ‖y - x‖ = ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side, version subtracting vectors. -/
theorem cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) * ‖x - y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side, version subtracting vectors. -/
theorem sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) * ‖y - x‖ = ‖x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side, version subtracting vectors. -/
theorem sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) * ‖x - y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side, version subtracting vectors. -/
theorem tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) * ‖y‖ = ‖x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side, version subtracting vectors. -/
theorem tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) * ‖x‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle y (y - x)) = ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle (x - y) x) = ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle y (y - x)) = ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle (x - y) x) = ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side, version subtracting vectors. -/
theorem norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle y (y - x)) = ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side, version subtracting vectors. -/
theorem norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle (x - y) x) = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`. -/
theorem oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle x (x + r • o.rotation (π / 2 : ℝ) x) = Real.arctan r := by
rcases lt_trichotomy r 0 with (hr | rfl | hr)
· have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = -(π / 2 : ℝ) := by
rw [o.oangle_smul_right_of_neg _ _ hr, o.oangle_neg_right h, o.oangle_rotation_self_right h, ←
sub_eq_zero, add_comm, sub_neg_eq_add, ← Real.Angle.coe_add, ← Real.Angle.coe_add,
add_assoc, add_halves, ← two_mul, Real.Angle.coe_two_pi]
simpa using h
-- Porting note: if the type is not given in `neg_neg` then Lean "forgets" about the instance
-- `Neg (Orientation ℝ V (Fin 2))`
rw [← neg_inj, ← oangle_neg_orientation_eq_neg, @neg_neg Real.Angle] at ha
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, oangle_rev,
(-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul,
LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one,
Real.norm_eq_abs, abs_of_neg hr, Real.arctan_neg, Real.Angle.coe_neg, neg_neg]
· rw [zero_smul, add_zero, oangle_self, Real.arctan_zero, Real.Angle.coe_zero]
· have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = (π / 2 : ℝ) := by
rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right h]
rw [o.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul,
LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one,
Real.norm_eq_abs, abs_of_pos hr]
| /-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`. -/
theorem oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)
| Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean | 468 | 471 |
/-
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.Order.Group.Finset
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $R[X]$
-/
noncomputable section
open Polynomial
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R]
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero
(p : R[X]) (t : R) (hnezero : derivative p ≠ 0) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t :=
(le_rootMultiplicity_iff hnezero).2 <|
pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t)
theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors
{p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t)
(hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) :
(derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· simp only [h, map_zero, rootMultiplicity_zero]
obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t
set m := p.rootMultiplicity t
have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt
have hndvd : ¬(X - C t) ^ m ∣ derivative p := by
rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _),
derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc,
dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)]
rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢
rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd]
have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _)
exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm])
(rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero)
theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ}
(hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t :=
dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans
(pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t)
open Finset in
theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} :
(derivative^[p.rootMultiplicity t] p).eval t =
(p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by
set m := p.rootMultiplicity t with hm
conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm]
rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)]
· rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self,
eval_natCast, nsmul_eq_mul]; rfl
· intro b hb hb0
rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow,
Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self,
zero_pow hb0, smul_zero, zero_mul, smul_zero]
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
by_contra! h'
replace hroot := hroot _ h'
simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot
obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h'
rw [hq, mul_mem_nonZeroDivisors] at hnzd
rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot
exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot
clear hroot
induction n with
| zero =>
simp only [Nat.factorial_zero, Nat.cast_one]
exact Submonoid.one_mem _
| succ n ih =>
rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors]
exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩
theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t :=
lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h
(by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _)
theorem one_lt_rootMultiplicity_iff_isRoot
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by
rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h]
refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩
obtain (_|_|m) := m
exacts [h0, h1, by omega]
end CommRing
section IsDomain
variable [CommRing R] [IsDomain R]
theorem one_lt_rootMultiplicity_iff_isRoot_gcd
[GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by
simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff]
theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) :
p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· rw [h, map_zero, rootMultiplicity_zero]
exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne'
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by
by_cases h : p.IsRoot t
· exact (derivative_rootMultiplicity_of_root h).symm.le
· rw [rootMultiplicity_eq_zero h, zero_tsub]
exact zero_le _
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) :
n < p.rootMultiplicity t :=
lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩
/-- A sufficient condition for the set of roots of a nonzero polynomial `f` to be a subset of the
set of roots of `g` is that `f` divides `f.derivative * g`. Over an algebraically closed field of
characteristic zero, this is also a necessary condition.
See `isRoot_of_isRoot_iff_dvd_derivative_mul` -/
theorem isRoot_of_isRoot_of_dvd_derivative_mul [CharZero R] {f g : R[X]} (hf0 : f ≠ 0)
(hfd : f ∣ f.derivative * g) {a : R} (haf : f.IsRoot a) : g.IsRoot a := by
rcases hfd with ⟨r, hr⟩
have hdf0 : derivative f ≠ 0 := by
contrapose! haf
rw [eq_C_of_derivative_eq_zero haf] at hf0 ⊢
exact not_isRoot_C _ _ <| C_ne_zero.mp hf0
by_contra hg
have hdfg0 : f.derivative * g ≠ 0 := mul_ne_zero hdf0 (by rintro rfl; simp at hg)
have hr' := congr_arg (rootMultiplicity a) hr
rw [rootMultiplicity_mul hdfg0, derivative_rootMultiplicity_of_root haf,
rootMultiplicity_eq_zero hg, add_zero, rootMultiplicity_mul (hr ▸ hdfg0), add_comm,
Nat.sub_eq_iff_eq_add (Nat.succ_le_iff.2 ((rootMultiplicity_pos hf0).2 haf))] at hr'
omega
section NormalizationMonoid
variable [NormalizationMonoid R]
instance instNormalizationMonoid : NormalizationMonoid R[X] where
normUnit p :=
⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by
rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩
normUnit_zero := Units.ext (by simp)
normUnit_mul hp0 hq0 :=
Units.ext
(by
dsimp
rw [Ne, ← leadingCoeff_eq_zero] at *
rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul])
normUnit_coe_units u :=
Units.ext
(by
dsimp
rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq]
rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩
rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1]
rfl)
@[simp]
theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by
simp [normUnit]
@[simp]
theorem leadingCoeff_normalize (p : R[X]) :
leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp [normalize_apply]
theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by
simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one,
Units.val_one, Polynomial.C.map_one, mul_one]
theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by
rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero]
theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by
have := coe_normUnit (R := R) (p := X)
rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this
theorem X_eq_normalize : (X : Polynomial R) = normalize X := by
simp only [normalize_apply, normUnit_X, Units.val_one, mul_one]
end NormalizationMonoid
end IsDomain
section DivisionRing
variable [DivisionRing R] {p q : R[X]}
theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p :=
lt_of_not_ge fun h => by
rw [eq_C_of_degree_le_zero h] at hp0 hp
exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))
@[simp]
protected theorem map_eq_zero [Semiring S] [Nontrivial S] (f : R →+* S) : p.map f = 0 ↔ p = 0 := by
simp only [Polynomial.ext_iff]
congr!
simp [map_eq_zero, coeff_map, coeff_zero]
theorem map_ne_zero [Semiring S] [Nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 :=
mt (Polynomial.map_eq_zero f).1 hp
@[simp]
theorem degree_map [Semiring S] [Nontrivial S] (p : R[X]) (f : R →+* S) :
degree (p.map f) = degree p :=
p.degree_map_eq_of_injective f.injective
@[simp]
theorem natDegree_map [Semiring S] [Nontrivial S] (f : R →+* S) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map _ f)
@[simp]
theorem leadingCoeff_map [Semiring S] [Nontrivial S] (f : R →+* S) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
simp only [← coeff_natDegree, coeff_map f, natDegree_map]
theorem monic_map_iff [Semiring S] [Nontrivial S] {f : R →+* S} {p : R[X]} :
(p.map f).Monic ↔ p.Monic := by
rw [Monic, leadingCoeff_map, ← f.map_one, Function.Injective.eq_iff f.injective, Monic]
end DivisionRing
section Field
variable [Field R] {p q : R[X]}
theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_isUnit, fun h =>
have : degree p ≤ 0 := by simp [*, le_refl]
have hc : coeff p 0 ≠ 0 := fun hc => by
rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction
isUnit_iff_dvd_one.2
⟨C (coeff p 0)⁻¹, by
conv in p => rw [eq_C_of_degree_le_zero this]
rw [← C_mul, mul_inv_cancel₀ hc, C_1]⟩⟩
/-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/
def div (p q : R[X]) :=
C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹))
/-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/
def mod (p q : R[X]) :=
p %ₘ (q * C (leadingCoeff q)⁻¹)
private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by
by_cases h : q = 0
· simp only [h, zero_mul, mod, modByMonic_zero, zero_add]
· conv =>
rhs
rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)]
rw [div, mod, add_comm, mul_assoc]
private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by
rw [← degree_mul_leadingCoeff_inv q hq]
exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq)
instance : Div R[X] :=
⟨div⟩
instance : Mod R[X] :=
⟨mod⟩
theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) :=
rfl
theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl
theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by
simp only [Monic.def.1 hq, inv_one, mul_one, C_1]
theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by
simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) :=
modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _
theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a :=
divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot
instance instEuclideanDomain : EuclideanDomain R[X] :=
{ Polynomial.commRing,
Polynomial.nontrivial with
quotient := (· / ·)
quotient_zero := by simp [div_def]
remainder := (· % ·)
r := _
r_wellFounded := degree_lt_wf
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux
remainder_lt := fun _ _ hq => remainder_lt_aux _ hq
mul_left_not_lt := fun _ _ hq => not_lt_of_ge (degree_le_mul_left _ hq) }
theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by
classical
have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p :=
not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0]
rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)]
unfold divModByMonicAux
dsimp
simp only [this, false_and, if_false]⟩
theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨fun h => by
have := EuclideanDomain.div_add_mod p q
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
fun h => by
have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by
rwa [degree_mul_leadingCoeff_inv q hq0]
have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0
rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩
theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p := by
have : degree (p % q) < degree (q * (p / q)) :=
calc
degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0
_ ≤ _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq))
conv_rhs =>
rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul]
theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by
by_cases hq : q = 0
· simp [hq]
· rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _
theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by
have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq
rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0]
exact degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp
(by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq)
theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by
simp_rw [isUnit_iff_degree_eq_zero, degree_map]
theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by
if hq0 : q = 0 then simp [hq0]
else
rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0),
Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀]
theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by
by_cases hq0 : q = 0
· simp [hq0]
· rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f,
map_modByMonic f (monic_mul_leadingCoeff_inv hq0)]
lemma natDegree_mod_lt [Field k] (p : k[X]) {q : k[X]} (hq : q.natDegree ≠ 0) :
(p % q).natDegree < q.natDegree := by
have hq' : q.leadingCoeff ≠ 0 := by
rw [leadingCoeff_ne_zero]
contrapose! hq
simp [hq]
rw [mod_def]
refine (natDegree_modByMonic_lt p ?_ ?_).trans_le ?_
· refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_
rw [mul_inv_eq_one₀ hq']
· contrapose! hq
rw [← natDegree_mul_C_eq_of_mul_eq_one ((inv_mul_eq_one₀ hq').mpr rfl)]
simp [hq]
· exact natDegree_mul_C_le q q.leadingCoeff⁻¹
section
open EuclideanDomain
theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) :
gcd (p.map f) (q.map f) = (gcd p q).map f :=
GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left])
fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val]
end
theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0)
(hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by
rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul,
Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add]
theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R}
(hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 :=
eval₂_gcd_eq_zero hf hg
theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_left f g
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_right f g
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} :
(EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 :=
⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩
theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} :
(EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α :=
root_gcd_iff_root_left_right
theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by
classical
rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map]
theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) :
x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map]
theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by
classical
rw [rootSet, aroots_monomial ha,
Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton]
theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by
rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha]
theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) :
(X ^ n : R[X]).rootSet S = {0} := by
rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn]
exact one_ne_zero
theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X])
(s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by
classical
simp only [rootSet, aroots, ← Finset.mem_coe]
rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion]
rwa [← Polynomial.map_prod, Ne, Polynomial.map_eq_zero]
theorem roots_C_mul_X_sub_C (b : R) (ha : a ≠ 0) : (C a * X - C b).roots = {a⁻¹ * b} := by
simp [roots_C_mul_X_sub_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩]
theorem roots_C_mul_X_add_C (b : R) (ha : a ≠ 0) : (C a * X + C b).roots = {-(a⁻¹ * b)} := by
simp [roots_C_mul_X_add_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩]
theorem roots_degree_eq_one (h : degree p = 1) : p.roots = {-((p.coeff 1)⁻¹ * p.coeff 0)} := by
rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1 by rw [h])]
have : p.coeff 1 ≠ 0 := coeff_ne_zero_of_eq_degree h
simp [roots_C_mul_X_add_C _ this]
theorem exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, IsRoot p x :=
⟨-((p.coeff 1)⁻¹ * p.coeff 0), by
rw [← mem_roots (by simp [← zero_le_degree_iff, h])]
simp [roots_degree_eq_one h]⟩
theorem coeff_inv_units (u : R[X]ˣ) (n : ℕ) : ((↑u : R[X]).coeff n)⁻¹ = (↑u⁻¹ : R[X]).coeff n := by
rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹),
coeff_C, coeff_C, inv_eq_one_div]
split_ifs
· rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,
coeff_zero_eq_eval_zero, ← eval_mul, ← Units.val_mul, inv_mul_cancel]
simp
· simp
theorem monic_normalize [DecidableEq R] (hp0 : p ≠ 0) : Monic (normalize p) := by
rw [Ne, ← leadingCoeff_eq_zero, ← Ne, ← isUnit_iff_ne_zero] at hp0
rw [Monic, leadingCoeff_normalize, normalize_eq_one]
apply hp0
theorem leadingCoeff_div (hpq : q.degree ≤ p.degree) :
(p / q).leadingCoeff = p.leadingCoeff / q.leadingCoeff := by
by_cases hq : q = 0
· simp [hq]
rw [div_def, leadingCoeff_mul, leadingCoeff_C,
leadingCoeff_divByMonic_of_monic (monic_mul_leadingCoeff_inv hq) _, mul_comm,
div_eq_mul_inv]
rwa [degree_mul_leadingCoeff_inv q hq]
theorem div_C_mul : p / (C a * q) = C a⁻¹ * (p / q) := by
by_cases ha : a = 0
· simp [ha]
simp only [div_def, leadingCoeff_mul, mul_inv, leadingCoeff_C, C.map_mul, mul_assoc]
congr 3
rw [mul_left_comm q, ← mul_assoc, ← C.map_mul, mul_inv_cancel₀ ha, C.map_one, one_mul]
theorem C_mul_dvd (ha : a ≠ 0) : C a * p ∣ q ↔ p ∣ q :=
⟨fun h => dvd_trans (dvd_mul_left _ _) h, fun ⟨r, hr⟩ =>
⟨C a⁻¹ * r, by
rw [mul_assoc, mul_left_comm p, ← mul_assoc, ← C.map_mul, mul_inv_cancel₀ ha, C.map_one,
one_mul, hr]⟩⟩
theorem dvd_C_mul (ha : a ≠ 0) : p ∣ Polynomial.C a * q ↔ p ∣ q :=
⟨fun ⟨r, hr⟩ =>
⟨C a⁻¹ * r, by
rw [mul_left_comm p, ← hr, ← mul_assoc, ← C.map_mul, inv_mul_cancel₀ ha, C.map_one,
one_mul]⟩,
fun h => dvd_trans h (dvd_mul_left _ _)⟩
theorem coe_normUnit_of_ne_zero [DecidableEq R] (hp : p ≠ 0) :
(normUnit p : R[X]) = C p.leadingCoeff⁻¹ := by
have : p.leadingCoeff ≠ 0 := mt leadingCoeff_eq_zero.mp hp
simp [CommGroupWithZero.coe_normUnit _ this]
theorem map_dvd_map' [Field k] (f : R →+* k) {x y : R[X]} : x.map f ∣ y.map f ↔ x ∣ y := by
by_cases H : x = 0
· rw [H, Polynomial.map_zero, zero_dvd_iff, zero_dvd_iff, Polynomial.map_eq_zero]
· classical
rw [← normalize_dvd_iff, ← @normalize_dvd_iff R[X], normalize_apply, normalize_apply,
coe_normUnit_of_ne_zero H, coe_normUnit_of_ne_zero (mt (Polynomial.map_eq_zero f).1 H),
leadingCoeff_map, ← map_inv₀ f, ← map_C, ← Polynomial.map_mul,
map_dvd_map _ f.injective (monic_mul_leadingCoeff_inv H)]
@[simp]
theorem degree_normalize [DecidableEq R] : degree (normalize p) = degree p := by
simp [normalize_apply]
theorem prime_of_degree_eq_one (hp1 : degree p = 1) : Prime p := by
classical
have : Prime (normalize p) :=
Monic.prime_of_degree_eq_one (hp1 ▸ degree_normalize)
(monic_normalize fun hp0 => absurd hp1 (hp0.symm ▸ by simp [degree_zero]))
exact (normalize_associated _).prime this
theorem irreducible_of_degree_eq_one (hp1 : degree p = 1) : Irreducible p :=
(prime_of_degree_eq_one hp1).irreducible
theorem not_irreducible_C (x : R) : ¬Irreducible (C x) := by
by_cases H : x = 0
· rw [H, C_0]
exact not_irreducible_zero
· exact fun hx => hx.not_isUnit <| isUnit_C.2 <| isUnit_iff_ne_zero.2 H
theorem degree_pos_of_irreducible (hp : Irreducible p) : 0 < p.degree :=
lt_of_not_ge fun hp0 =>
have := eq_C_of_degree_le_zero hp0
not_irreducible_C (p.coeff 0) <| this ▸ hp
theorem X_sub_C_mul_divByMonic_eq_sub_modByMonic {K : Type*} [Ring K] (f : K[X]) (a : K) :
(X - C a) * (f /ₘ (X - C a)) = f - f %ₘ (X - C a) := by
rw [eq_sub_iff_add_eq, ← eq_sub_iff_add_eq', modByMonic_eq_sub_mul_div]
exact monic_X_sub_C a
theorem divByMonic_add_X_sub_C_mul_derivate_divByMonic_eq_derivative
{K : Type*} [CommRing K] (f : K[X]) (a : K) :
f /ₘ (X - C a) + (X - C a) * derivative (f /ₘ (X - C a)) = derivative f := by
have key := by apply congrArg derivative <| X_sub_C_mul_divByMonic_eq_sub_modByMonic f a
simpa only [derivative_mul, derivative_sub, derivative_X, derivative_C, sub_zero, one_mul,
modByMonic_X_sub_C_eq_C_eval] using key
theorem X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic {K : Type*} [Field K] (f : K[X]) {a : K}
(hf : (X - C a) ∣ f /ₘ (X - C a)) : X - C a ∣ derivative f := by
have key := divByMonic_add_X_sub_C_mul_derivate_divByMonic_eq_derivative f a
have ⟨u,hu⟩ := hf
rw [← key, hu, ← mul_add (X - C a) u _]
use (u + derivative ((X - C a) * u))
/-- If `f` is a polynomial over a field, and `a : K` satisfies `f' a ≠ 0`,
then `f / (X - a)` is coprime with `X - a`.
Note that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/
theorem isCoprime_of_is_root_of_eval_derivative_ne_zero {K : Type*} [Field K] (f : K[X]) (a : K)
(hf' : f.derivative.eval a ≠ 0) : IsCoprime (X - C a : K[X]) (f /ₘ (X - C a)) := by
classical
refine Or.resolve_left
(EuclideanDomain.dvd_or_coprime (X - C a) (f /ₘ (X - C a))
(irreducible_of_degree_eq_one (Polynomial.degree_X_sub_C a))) ?_
contrapose! hf' with h
have : X - C a ∣ derivative f := X_sub_C_dvd_derivative_of_X_sub_C_dvd_divByMonic f h
rw [← modByMonic_eq_zero_iff_dvd (monic_X_sub_C _), modByMonic_X_sub_C_eq_C_eval] at this
rwa [← C_inj, C_0]
/-- To check a polynomial over a field is irreducible, it suffices to check only for
divisors that have smaller degree.
See also: `Polynomial.Monic.irreducible_iff_natDegree`.
-/
theorem irreducible_iff_degree_lt (p : R[X]) (hp0 : p ≠ 0) (hpu : ¬ IsUnit p) :
Irreducible p ↔ ∀ q, q.degree ≤ ↑(natDegree p / 2) → q ∣ p → IsUnit q := by
rw [← irreducible_mul_leadingCoeff_inv,
(monic_mul_leadingCoeff_inv hp0).irreducible_iff_degree_lt]
· simp [hp0, natDegree_mul_leadingCoeff_inv]
· contrapose! hpu
exact isUnit_of_mul_eq_one _ _ hpu
/-- To check a polynomial `p` over a field is irreducible, it suffices to check there are no
divisors of degree `0 < d ≤ degree p / 2`.
See also: `Polynomial.Monic.irreducible_iff_natDegree'`.
-/
theorem irreducible_iff_lt_natDegree_lt {p : R[X]} (hp0 : p ≠ 0) (hpu : ¬ IsUnit p) :
Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by
have : p * C (leadingCoeff p)⁻¹ ≠ 1 := by
contrapose! hpu
exact isUnit_of_mul_eq_one _ _ hpu
rw [← irreducible_mul_leadingCoeff_inv,
(monic_mul_leadingCoeff_inv hp0).irreducible_iff_lt_natDegree_lt this,
natDegree_mul_leadingCoeff_inv _ hp0]
simp only [IsUnit.dvd_mul_right
(isUnit_C.mpr (IsUnit.mk0 (leadingCoeff p)⁻¹ (inv_ne_zero (leadingCoeff_ne_zero.mpr hp0))))]
open UniqueFactorizationMonoid in
/--
The normalized factors of a polynomial over a field times its leading coefficient give
the polynomial.
-/
theorem leadingCoeff_mul_prod_normalizedFactors [DecidableEq R] (a : R[X]) :
C a.leadingCoeff * (normalizedFactors a).prod = a := by
| by_cases ha : a = 0
· simp [ha]
rw [prod_normalizedFactors_eq, normalize_apply, coe_normUnit, CommGroupWithZero.coe_normUnit,
mul_comm, mul_assoc, ← map_mul, inv_mul_cancel₀] <;>
simp_all
end Field
| Mathlib/Algebra/Polynomial/FieldDivision.lean | 660 | 666 |
/-
Copyright (c) 2020 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Devon Tuma
-/
import Mathlib.Probability.ProbabilityMassFunction.Basic
/-!
# Monad Operations for Probability Mass Functions
This file constructs two operations on `PMF` that give it a monad structure.
`pure a` is the distribution where a single value `a` has probability `1`.
`bind pa pb : PMF β` is the distribution given by sampling `a : α` from `pa : PMF α`,
and then sampling from `pb a : PMF β` to get a final result `b : β`.
`bindOnSupport` generalizes `bind` to allow binding to a partial function,
so that the second argument only needs to be defined on the support of the first argument.
-/
noncomputable section
variable {α β γ : Type*}
open NNReal ENNReal
open MeasureTheory
namespace PMF
section Pure
open scoped Classical in
/-- The pure `PMF` is the `PMF` where all the mass lies in one point.
The value of `pure a` is `1` at `a` and `0` elsewhere. -/
def pure (a : α) : PMF α :=
⟨fun a' => if a' = a then 1 else 0, hasSum_ite_eq _ _⟩
variable (a a' : α)
open scoped Classical in
@[simp]
theorem pure_apply : pure a a' = if a' = a then 1 else 0 := rfl
@[simp]
theorem support_pure : (pure a).support = {a} :=
Set.ext fun a' => by simp [mem_support_iff]
theorem mem_support_pure_iff : a' ∈ (pure a).support ↔ a' = a := by simp
theorem pure_apply_self : pure a a = 1 :=
if_pos rfl
theorem pure_apply_of_ne (h : a' ≠ a) : pure a a' = 0 :=
if_neg h
instance [Inhabited α] : Inhabited (PMF α) :=
⟨pure default⟩
section Measure
variable (s : Set α)
open scoped Classical in
@[simp]
theorem toOuterMeasure_pure_apply : (pure a).toOuterMeasure s = if a ∈ s then 1 else 0 := by
refine (toOuterMeasure_apply (pure a) s).trans ?_
split_ifs with ha
· refine (tsum_congr fun b => ?_).trans (tsum_ite_eq a 1)
exact ite_eq_left_iff.2 fun hb =>
symm (ite_eq_right_iff.2 fun h => (hb <| h.symm ▸ ha).elim)
· refine (tsum_congr fun b => ?_).trans tsum_zero
exact ite_eq_right_iff.2 fun hb =>
ite_eq_right_iff.2 fun h => (ha <| h ▸ hb).elim
variable [MeasurableSpace α]
open scoped Classical in
/-- The measure of a set under `pure a` is `1` for sets containing `a` and `0` otherwise. -/
@[simp]
theorem toMeasure_pure_apply (hs : MeasurableSet s) :
(pure a).toMeasure s = if a ∈ s then 1 else 0 :=
(toMeasure_apply_eq_toOuterMeasure_apply (pure a) s hs).trans (toOuterMeasure_pure_apply a s)
theorem toMeasure_pure : (pure a).toMeasure = Measure.dirac a :=
Measure.ext fun s hs => by rw [toMeasure_pure_apply a s hs, Measure.dirac_apply' a hs]; rfl
@[simp]
theorem toPMF_dirac [Countable α] [h : MeasurableSingletonClass α] :
(Measure.dirac a).toPMF = pure a := by
rw [toPMF_eq_iff_toMeasure_eq, toMeasure_pure]
end Measure
end Pure
section Bind
/-- The monadic bind operation for `PMF`. -/
def bind (p : PMF α) (f : α → PMF β) : PMF β :=
⟨fun b => ∑' a, p a * f a b,
ENNReal.summable.hasSum_iff.2
(ENNReal.tsum_comm.trans <| by simp only [ENNReal.tsum_mul_left, tsum_coe, mul_one])⟩
variable (p : PMF α) (f : α → PMF β) (g : β → PMF γ)
@[simp]
theorem bind_apply (b : β) : p.bind f b = ∑' a, p a * f a b := rfl
@[simp]
theorem support_bind : (p.bind f).support = ⋃ a ∈ p.support, (f a).support :=
Set.ext fun b => by simp [mem_support_iff, ENNReal.tsum_eq_zero, not_or]
theorem mem_support_bind_iff (b : β) :
b ∈ (p.bind f).support ↔ ∃ a ∈ p.support, b ∈ (f a).support := by
simp only [support_bind, Set.mem_iUnion, Set.mem_setOf_eq, exists_prop]
@[simp]
theorem pure_bind (a : α) (f : α → PMF β) : (pure a).bind f = f a := by
classical
have : ∀ b a', ite (a' = a) (f a' b) 0 = ite (a' = a) (f a b) 0 := fun b a' => by
split_ifs with h <;> simp [h]
ext b
simp [this]
@[simp]
theorem bind_pure : p.bind pure = p :=
PMF.ext fun x => (bind_apply _ _ _).trans (_root_.trans
(tsum_eq_single x fun y hy => by rw [pure_apply_of_ne _ _ hy.symm, mul_zero]) <|
by rw [pure_apply_self, mul_one])
@[simp]
theorem bind_const (p : PMF α) (q : PMF β) : (p.bind fun _ => q) = q :=
PMF.ext fun x => by rw [bind_apply, ENNReal.tsum_mul_right, tsum_coe, one_mul]
@[simp]
theorem bind_bind : (p.bind f).bind g = p.bind fun a => (f a).bind g :=
PMF.ext fun b => by
simpa only [ENNReal.coe_inj.symm, bind_apply, ENNReal.tsum_mul_left.symm,
ENNReal.tsum_mul_right.symm, mul_assoc, mul_left_comm, mul_comm] using ENNReal.tsum_comm
theorem bind_comm (p : PMF α) (q : PMF β) (f : α → β → PMF γ) :
(p.bind fun a => q.bind (f a)) = q.bind fun b => p.bind fun a => f a b :=
PMF.ext fun b => by
simpa only [ENNReal.coe_inj.symm, bind_apply, ENNReal.tsum_mul_left.symm,
ENNReal.tsum_mul_right.symm, mul_assoc, mul_left_comm, mul_comm] using ENNReal.tsum_comm
section Measure
variable (s : Set β)
@[simp]
theorem toOuterMeasure_bind_apply :
(p.bind f).toOuterMeasure s = ∑' a, p a * (f a).toOuterMeasure s := by
classical
calc
(p.bind f).toOuterMeasure s = ∑' b, if b ∈ s then ∑' a, p a * f a b else 0 := by
simp [toOuterMeasure_apply, Set.indicator_apply]
_ = ∑' (b) (a), p a * if b ∈ s then f a b else 0 := tsum_congr fun b => by split_ifs <;> simp
_ = ∑' (a) (b), p a * if b ∈ s then f a b else 0 := ENNReal.tsum_comm
_ = ∑' a, p a * ∑' b, if b ∈ s then f a b else 0 := tsum_congr fun _ => ENNReal.tsum_mul_left
_ = ∑' a, p a * ∑' b, if b ∈ s then f a b else 0 :=
(tsum_congr fun a => (congr_arg fun x => p a * x) <| tsum_congr fun b => by split_ifs <;> rfl)
_ = ∑' a, p a * (f a).toOuterMeasure s :=
tsum_congr fun a => by simp only [toOuterMeasure_apply, Set.indicator_apply]
/-- The measure of a set under `p.bind f` is the sum over `a : α`
of the probability of `a` under `p` times the measure of the set under `f a`. -/
@[simp]
theorem toMeasure_bind_apply [MeasurableSpace β] (hs : MeasurableSet s) :
(p.bind f).toMeasure s = ∑' a, p a * (f a).toMeasure s :=
(toMeasure_apply_eq_toOuterMeasure_apply (p.bind f) s hs).trans
((toOuterMeasure_bind_apply p f s).trans
(tsum_congr fun a =>
congr_arg (fun x => p a * x) (toMeasure_apply_eq_toOuterMeasure_apply (f a) s hs).symm))
end Measure
end Bind
instance : Monad PMF where
pure a := pure a
bind pa pb := pa.bind pb
section BindOnSupport
/-- Generalized version of `bind` allowing `f` to only be defined on the support of `p`.
`p.bind f` is equivalent to `p.bindOnSupport (fun a _ ↦ f a)`, see `bindOnSupport_eq_bind`. -/
def bindOnSupport (p : PMF α) (f : ∀ a ∈ p.support, PMF β) : PMF β :=
⟨fun b => ∑' a, p a * if h : p a = 0 then 0 else f a h b, ENNReal.summable.hasSum_iff.2 (by
refine ENNReal.tsum_comm.trans (_root_.trans (tsum_congr fun a => ?_) p.tsum_coe)
simp_rw [ENNReal.tsum_mul_left]
split_ifs with h
· simp only [h, zero_mul]
· rw [(f a h).tsum_coe, mul_one])⟩
variable {p : PMF α} (f : ∀ a ∈ p.support, PMF β)
@[simp]
theorem bindOnSupport_apply (b : β) :
p.bindOnSupport f b = ∑' a, p a * if h : p a = 0 then 0 else f a h b := rfl
@[simp]
theorem support_bindOnSupport :
(p.bindOnSupport f).support = ⋃ (a : α) (h : a ∈ p.support), (f a h).support := by
refine Set.ext fun b => ?_
simp only [ENNReal.tsum_eq_zero, not_or, mem_support_iff, bindOnSupport_apply, Ne, not_forall,
mul_eq_zero, Set.mem_iUnion]
exact
⟨fun hb =>
let ⟨a, ⟨ha, ha'⟩⟩ := hb
⟨a, ha, by simpa [ha] using ha'⟩,
fun hb =>
let ⟨a, ha, ha'⟩ := hb
⟨a, ⟨ha, by simpa [(mem_support_iff _ a).1 ha] using ha'⟩⟩⟩
theorem mem_support_bindOnSupport_iff (b : β) :
b ∈ (p.bindOnSupport f).support ↔ ∃ (a : α) (h : a ∈ p.support), b ∈ (f a h).support := by
simp only [support_bindOnSupport, Set.mem_setOf_eq, Set.mem_iUnion]
/-- `bindOnSupport` reduces to `bind` if `f` doesn't depend on the additional hypothesis. -/
@[simp]
theorem bindOnSupport_eq_bind (p : PMF α) (f : α → PMF β) :
(p.bindOnSupport fun a _ => f a) = p.bind f := by
ext b
have : ∀ a, ite (p a = 0) 0 (p a * f a b) = p a * f a b :=
fun a => ite_eq_right_iff.2 fun h => h.symm ▸ symm (zero_mul <| f a b)
simp only [bindOnSupport_apply fun a _ => f a, p.bind_apply f, dite_eq_ite, mul_ite,
mul_zero, this]
theorem bindOnSupport_eq_zero_iff (b : β) :
p.bindOnSupport f b = 0 ↔ ∀ (a) (ha : p a ≠ 0), f a ha b = 0 := by
simp only [bindOnSupport_apply, ENNReal.tsum_eq_zero, mul_eq_zero, or_iff_not_imp_left]
exact ⟨fun h a ha => Trans.trans (dif_neg ha).symm (h a ha),
fun h a ha => Trans.trans (dif_neg ha) (h a ha)⟩
@[simp]
theorem pure_bindOnSupport (a : α) (f : ∀ (a' : α) (_ : a' ∈ (pure a).support), PMF β) :
(pure a).bindOnSupport f = f a ((mem_support_pure_iff a a).mpr rfl) := by
refine PMF.ext fun b => ?_
simp only [bindOnSupport_apply, pure_apply]
classical
refine _root_.trans (tsum_congr fun a' => ?_) (tsum_ite_eq a _)
by_cases h : a' = a <;> simp [h]
theorem bindOnSupport_pure (p : PMF α) : (p.bindOnSupport fun a _ => pure a) = p := by
simp only [PMF.bind_pure, PMF.bindOnSupport_eq_bind]
@[simp]
theorem bindOnSupport_bindOnSupport (p : PMF α) (f : ∀ a ∈ p.support, PMF β)
(g : ∀ b ∈ (p.bindOnSupport f).support, PMF γ) :
(p.bindOnSupport f).bindOnSupport g =
p.bindOnSupport fun a ha =>
(f a ha).bindOnSupport fun b hb =>
g b ((mem_support_bindOnSupport_iff f b).mpr ⟨a, ha, hb⟩) := by
refine PMF.ext fun a => ?_
dsimp only [bindOnSupport_apply]
simp only [← tsum_dite_right, ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm]
classical
simp only [ENNReal.tsum_eq_zero, dite_eq_left_iff]
refine ENNReal.tsum_comm.trans (tsum_congr fun a' => tsum_congr fun b => ?_)
split_ifs with h _ h_1 _ h_2
any_goals ring1
· have := h_1 a'
simp? [h] at this says simp only [h, ↓reduceDIte, mul_eq_zero, false_or] at this
contradiction
· simp [h_2]
theorem bindOnSupport_comm (p : PMF α) (q : PMF β) (f : ∀ a ∈ p.support, ∀ b ∈ q.support, PMF γ) :
(p.bindOnSupport fun a ha => q.bindOnSupport (f a ha)) =
q.bindOnSupport fun b hb => p.bindOnSupport fun a ha => f a ha b hb := by
apply PMF.ext; rintro c
simp only [ENNReal.coe_inj.symm, bindOnSupport_apply, ← tsum_dite_right,
ENNReal.tsum_mul_left.symm, ENNReal.tsum_mul_right.symm]
refine _root_.trans ENNReal.tsum_comm (tsum_congr fun b => tsum_congr fun a => ?_)
split_ifs with h1 h2 h2 <;> ring
section Measure
variable (s : Set β)
@[simp]
theorem toOuterMeasure_bindOnSupport_apply :
(p.bindOnSupport f).toOuterMeasure s =
∑' a, p a * if h : p a = 0 then 0 else (f a h).toOuterMeasure s := by
simp only [toOuterMeasure_apply, Set.indicator_apply, bindOnSupport_apply]
classical
calc
(∑' b, ite (b ∈ s) (∑' a, p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0) =
∑' (b) (a), ite (b ∈ s) (p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0 :=
tsum_congr fun b => by split_ifs with hbs <;> simp only [eq_self_iff_true, tsum_zero]
_ = ∑' (a) (b), ite (b ∈ s) (p a * dite (p a = 0) (fun h => 0) fun h => f a h b) 0 :=
ENNReal.tsum_comm
| _ = ∑' a, p a * ∑' b, ite (b ∈ s) (dite (p a = 0) (fun h => 0) fun h => f a h b) 0 :=
(tsum_congr fun a => by simp only [← ENNReal.tsum_mul_left, mul_ite, mul_zero])
_ = ∑' a, p a * dite (p a = 0) (fun h => 0) fun h => ∑' b, ite (b ∈ s) (f a h b) 0 :=
tsum_congr fun a => by split_ifs with ha <;> simp only [ite_self, tsum_zero, eq_self_iff_true]
/-- The measure of a set under `p.bindOnSupport f` is the sum over `a : α`
of the probability of `a` under `p` times the measure of the set under `f a _`.
The additional if statement is needed since `f` is only a partial function. -/
| Mathlib/Probability/ProbabilityMassFunction/Monad.lean | 295 | 302 |
/-
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
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Data.Set.Function
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Images of intervals under `(+ d)`
The lemmas in this file state that addition maps intervals bijectively. The typeclass
`ExistsAddOfLE` is defined specifically to make them work when combined with
`OrderedCancelAddCommMonoid`; the lemmas below therefore apply to all
`OrderedAddCommGroup`, but also to `ℕ` and `ℝ≥0`, which are not groups.
-/
namespace Set
variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedCancelAddMonoid M]
[ExistsAddOfLE M] (a b c d : M)
theorem Ici_add_bij : BijOn (· + d) (Ici a) (Ici (a + d)) := by
refine
⟨fun x h => add_le_add_right (mem_Ici.mp h) _, (add_left_injective d).injOn, fun _ h => ?_⟩
obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ici.mp h)
rw [mem_Ici, add_right_comm, add_le_add_iff_right] at h
exact ⟨a + c, h, by rw [add_right_comm]⟩
theorem Ioi_add_bij : BijOn (· + d) (Ioi a) (Ioi (a + d)) := by
refine
⟨fun x h => add_lt_add_right (mem_Ioi.mp h) _, fun _ _ _ _ h => add_right_cancel h, fun _ h =>
?_⟩
obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ioi.mp h).le
rw [mem_Ioi, add_right_comm, add_lt_add_iff_right] at h
exact ⟨a + c, h, by rw [add_right_comm]⟩
theorem Icc_add_bij : BijOn (· + d) (Icc a b) (Icc (a + d) (b + d)) := by
rw [← Ici_inter_Iic, ← Ici_inter_Iic]
exact
(Ici_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx =>
le_of_add_le_add_right hx.2
theorem Ioo_add_bij : BijOn (· + d) (Ioo a b) (Ioo (a + d) (b + d)) := by
rw [← Ioi_inter_Iio, ← Ioi_inter_Iio]
exact
(Ioi_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx =>
lt_of_add_lt_add_right hx.2
theorem Ioc_add_bij : BijOn (· + d) (Ioc a b) (Ioc (a + d) (b + d)) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic]
exact
(Ioi_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx =>
le_of_add_le_add_right hx.2
theorem Ico_add_bij : BijOn (· + d) (Ico a b) (Ico (a + d) (b + d)) := by
rw [← Ici_inter_Iio, ← Ici_inter_Iio]
exact
(Ici_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx =>
lt_of_add_lt_add_right hx.2
/-!
### Images under `x ↦ x + a`
-/
@[simp]
theorem image_add_const_Ici : (fun x => x + a) '' Ici b = Ici (b + a) :=
(Ici_add_bij _ _).image_eq
@[simp]
theorem image_add_const_Ioi : (fun x => x + a) '' Ioi b = Ioi (b + a) :=
(Ioi_add_bij _ _).image_eq
@[simp]
theorem image_add_const_Icc : (fun x => x + a) '' Icc b c = Icc (b + a) (c + a) :=
(Icc_add_bij _ _ _).image_eq
@[simp]
theorem image_add_const_Ico : (fun x => x + a) '' Ico b c = Ico (b + a) (c + a) :=
(Ico_add_bij _ _ _).image_eq
@[simp]
theorem image_add_const_Ioc : (fun x => x + a) '' Ioc b c = Ioc (b + a) (c + a) :=
(Ioc_add_bij _ _ _).image_eq
@[simp]
theorem image_add_const_Ioo : (fun x => x + a) '' Ioo b c = Ioo (b + a) (c + a) :=
(Ioo_add_bij _ _ _).image_eq
/-!
### Images under `x ↦ a + x`
-/
@[simp]
theorem image_const_add_Ici : (fun x => a + x) '' Ici b = Ici (a + b) := by
simp only [add_comm a, image_add_const_Ici]
@[simp]
theorem image_const_add_Ioi : (fun x => a + x) '' Ioi b = Ioi (a + b) := by
simp only [add_comm a, image_add_const_Ioi]
@[simp]
theorem image_const_add_Icc : (fun x => a + x) '' Icc b c = Icc (a + b) (a + c) := by
simp only [add_comm a, image_add_const_Icc]
@[simp]
theorem image_const_add_Ico : (fun x => a + x) '' Ico b c = Ico (a + b) (a + c) := by
simp only [add_comm a, image_add_const_Ico]
@[simp]
theorem image_const_add_Ioc : (fun x => a + x) '' Ioc b c = Ioc (a + b) (a + c) := by
| simp only [add_comm a, image_add_const_Ioc]
| Mathlib/Algebra/Order/Interval/Set/Monoid.lean | 118 | 119 |
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Order.ToIntervalMod
import Mathlib.Algebra.Ring.AddAut
import Mathlib.Data.Nat.Totient
import Mathlib.GroupTheory.Divisible
import Mathlib.Topology.Connected.PathConnected
import Mathlib.Topology.IsLocalHomeomorph
import Mathlib.Topology.Instances.ZMultiples
/-!
# The additive circle
We define the additive circle `AddCircle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`.
See also `Circle` and `Real.angle`. For the normed group structure on `AddCircle`, see
`AddCircle.NormedAddCommGroup` in a later file.
## Main definitions and results:
* `AddCircle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`
* `UnitAddCircle`: the special case `ℝ ⧸ ℤ`
* `AddCircle.equivAddCircle`: the rescaling equivalence `AddCircle p ≃+ AddCircle q`
* `AddCircle.equivIco`: the natural equivalence `AddCircle p ≃ Ico a (a + p)`
* `AddCircle.addOrderOf_div_of_gcd_eq_one`: rational points have finite order
* `AddCircle.exists_gcd_eq_one_of_isOfFinAddOrder`: finite-order points are rational
* `AddCircle.homeoIccQuot`: the natural topological equivalence between `AddCircle p` and
`Icc a (a + p)` with its endpoints identified.
* `AddCircle.liftIco_continuous`: if `f : ℝ → B` is continuous, and `f a = f (a + p)` for
some `a`, then there is a continuous function `AddCircle p → B` which agrees with `f` on
`Icc a (a + p)`.
## Implementation notes:
Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as
the rational circle `AddCircle (1 : ℚ)`, and so we set things up more generally.
## TODO
* Link with periodicity
* Lie group structure
* Exponential equivalence to `Circle`
-/
noncomputable section
open AddCommGroup Set Function AddSubgroup TopologicalSpace
open Topology
variable {𝕜 B : Type*}
section Continuity
variable [AddCommGroup 𝕜] [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜]
{p : 𝕜} (hp : 0 < p) (a x : 𝕜)
theorem continuous_right_toIcoMod : ContinuousWithinAt (toIcoMod hp a) (Ici x) x := by
intro s h
rw [Filter.mem_map, mem_nhdsWithin_iff_exists_mem_nhds_inter]
haveI : Nontrivial 𝕜 := ⟨⟨0, p, hp.ne⟩⟩
simp_rw [mem_nhds_iff_exists_Ioo_subset] at h ⊢
obtain ⟨l, u, hxI, hIs⟩ := h
let d := toIcoDiv hp a x • p
have hd := toIcoMod_mem_Ico hp a x
simp_rw [subset_def, mem_inter_iff]
refine ⟨_, ⟨l + d, min (a + p) u + d, ?_, fun x => id⟩, fun y => ?_⟩ <;>
simp_rw [← sub_mem_Ioo_iff_left, mem_Ioo, lt_min_iff]
· exact ⟨hxI.1, hd.2, hxI.2⟩
· rintro ⟨h, h'⟩
apply hIs
rw [← toIcoMod_sub_zsmul, (toIcoMod_eq_self _).2]
exacts [⟨h.1, h.2.2⟩, ⟨hd.1.trans (sub_le_sub_right h' _), h.2.1⟩]
theorem continuous_left_toIocMod : ContinuousWithinAt (toIocMod hp a) (Iic x) x := by
rw [(funext fun y => Eq.trans (by rw [neg_neg]) <| toIocMod_neg _ _ _ :
toIocMod hp a = (fun x => p - x) ∘ toIcoMod hp (-a) ∘ Neg.neg)]
exact
(continuous_sub_left _).continuousAt.comp_continuousWithinAt <|
(continuous_right_toIcoMod _ _ _).comp continuous_neg.continuousWithinAt fun y => neg_le_neg
variable {x}
theorem toIcoMod_eventuallyEq_toIocMod (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) :
toIcoMod hp a =ᶠ[𝓝 x] toIocMod hp a :=
IsOpen.mem_nhds
(by
rw [Ico_eq_locus_Ioc_eq_iUnion_Ioo]
exact isOpen_iUnion fun i => isOpen_Ioo) <|
(not_modEq_iff_toIcoMod_eq_toIocMod hp).1 <| not_modEq_iff_ne_mod_zmultiples.2 hx
theorem continuousAt_toIcoMod (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) : ContinuousAt (toIcoMod hp a) x :=
let h := toIcoMod_eventuallyEq_toIocMod hp a hx
continuousAt_iff_continuous_left_right.2 <|
⟨(continuous_left_toIocMod hp a x).congr_of_eventuallyEq (h.filter_mono nhdsWithin_le_nhds)
h.eq_of_nhds,
continuous_right_toIcoMod hp a x⟩
theorem continuousAt_toIocMod (hx : (x : 𝕜 ⧸ zmultiples p) ≠ a) : ContinuousAt (toIocMod hp a) x :=
let h := toIcoMod_eventuallyEq_toIocMod hp a hx
continuousAt_iff_continuous_left_right.2 <|
⟨continuous_left_toIocMod hp a x,
(continuous_right_toIcoMod hp a x).congr_of_eventuallyEq
(h.symm.filter_mono nhdsWithin_le_nhds) h.symm.eq_of_nhds⟩
end Continuity
/-- The "additive circle": `𝕜 ⧸ (ℤ ∙ p)`. See also `Circle` and `Real.angle`. -/
abbrev AddCircle [AddCommGroup 𝕜] (p : 𝕜) :=
𝕜 ⧸ zmultiples p
namespace AddCircle
section LinearOrderedAddCommGroup
variable [AddCommGroup 𝕜] (p : 𝕜)
theorem coe_nsmul {n : ℕ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) :=
rfl
theorem coe_zsmul {n : ℤ} {x : 𝕜} : (↑(n • x) : AddCircle p) = n • (x : AddCircle p) :=
rfl
theorem coe_add (x y : 𝕜) : (↑(x + y) : AddCircle p) = (x : AddCircle p) + (y : AddCircle p) :=
rfl
theorem coe_sub (x y : 𝕜) : (↑(x - y) : AddCircle p) = (x : AddCircle p) - (y : AddCircle p) :=
rfl
theorem coe_neg {x : 𝕜} : (↑(-x) : AddCircle p) = -(x : AddCircle p) :=
rfl
@[norm_cast]
theorem coe_zero : ↑(0 : 𝕜) = (0 : AddCircle p) :=
rfl
theorem coe_eq_zero_iff {x : 𝕜} : (x : AddCircle p) = 0 ↔ ∃ n : ℤ, n • p = x := by
simp [AddSubgroup.mem_zmultiples_iff]
theorem coe_period : (p : AddCircle p) = 0 :=
(QuotientAddGroup.eq_zero_iff p).2 <| mem_zmultiples p
theorem coe_add_period (x : 𝕜) : ((x + p : 𝕜) : AddCircle p) = x := by
rw [coe_add, ← eq_sub_iff_add_eq', sub_self, coe_period]
@[continuity, nolint unusedArguments]
protected theorem continuous_mk' [TopologicalSpace 𝕜] :
Continuous (QuotientAddGroup.mk' (zmultiples p) : 𝕜 → AddCircle p) :=
continuous_coinduced_rng
variable [LinearOrder 𝕜] [IsOrderedAddMonoid 𝕜]
theorem coe_eq_zero_of_pos_iff (hp : 0 < p) {x : 𝕜} (hx : 0 < x) :
(x : AddCircle p) = 0 ↔ ∃ n : ℕ, n • p = x := by
rw [coe_eq_zero_iff]
constructor <;> rintro ⟨n, rfl⟩
· replace hx : 0 < n := by
contrapose! hx
simpa only [← neg_nonneg, ← zsmul_neg, zsmul_neg'] using zsmul_nonneg hp.le (neg_nonneg.2 hx)
exact ⟨n.toNat, by rw [← natCast_zsmul, Int.toNat_of_nonneg hx.le]⟩
· exact ⟨(n : ℤ), by simp⟩
variable [hp : Fact (0 < p)] (a : 𝕜) [Archimedean 𝕜]
/-- The equivalence between `AddCircle p` and the half-open interval `[a, a + p)`, whose inverse
is the natural quotient map. -/
def equivIco : AddCircle p ≃ Ico a (a + p) :=
QuotientAddGroup.equivIcoMod hp.out a
/-- The equivalence between `AddCircle p` and the half-open interval `(a, a + p]`, whose inverse
is the natural quotient map. -/
def equivIoc : AddCircle p ≃ Ioc a (a + p) :=
QuotientAddGroup.equivIocMod hp.out a
/-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on
`[a, a + p)`. -/
def liftIco (f : 𝕜 → B) : AddCircle p → B :=
restrict _ f ∘ AddCircle.equivIco p a
/-- Given a function on `𝕜`, return the unique function on `AddCircle p` agreeing with `f` on
`(a, a + p]`. -/
def liftIoc (f : 𝕜 → B) : AddCircle p → B :=
restrict _ f ∘ AddCircle.equivIoc p a
variable {p a}
theorem coe_eq_coe_iff_of_mem_Ico {x y : 𝕜} (hx : x ∈ Ico a (a + p)) (hy : y ∈ Ico a (a + p)) :
(x : AddCircle p) = y ↔ x = y := by
refine ⟨fun h => ?_, by tauto⟩
suffices (⟨x, hx⟩ : Ico a (a + p)) = ⟨y, hy⟩ by exact Subtype.mk.inj this
apply_fun equivIco p a at h
rw [← (equivIco p a).right_inv ⟨x, hx⟩, ← (equivIco p a).right_inv ⟨y, hy⟩]
exact h
theorem liftIco_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ico a (a + p)) :
liftIco p a f ↑x = f x := by
have : (equivIco p a) x = ⟨x, hx⟩ := by
rw [Equiv.apply_eq_iff_eq_symm_apply]
rfl
rw [liftIco, comp_apply, this]
rfl
theorem liftIoc_coe_apply {f : 𝕜 → B} {x : 𝕜} (hx : x ∈ Ioc a (a + p)) :
liftIoc p a f ↑x = f x := by
have : (equivIoc p a) x = ⟨x, hx⟩ := by
rw [Equiv.apply_eq_iff_eq_symm_apply]
rfl
rw [liftIoc, comp_apply, this]
rfl
lemma eq_coe_Ico (a : AddCircle p) : ∃ b, b ∈ Ico 0 p ∧ ↑b = a := by
let b := QuotientAddGroup.equivIcoMod hp.out 0 a
exact ⟨b.1, by simpa only [zero_add] using b.2,
(QuotientAddGroup.equivIcoMod hp.out 0).symm_apply_apply a⟩
lemma coe_eq_zero_iff_of_mem_Ico (ha : a ∈ Ico 0 p) :
(a : AddCircle p) = 0 ↔ a = 0 := by
have h0 : 0 ∈ Ico 0 (0 + p) := by simpa [zero_add, left_mem_Ico] using hp.out
have ha' : a ∈ Ico 0 (0 + p) := by rwa [zero_add]
rw [← AddCircle.coe_eq_coe_iff_of_mem_Ico ha' h0, QuotientAddGroup.mk_zero]
variable (p a)
section Continuity
variable [TopologicalSpace 𝕜]
@[continuity]
theorem continuous_equivIco_symm : Continuous (equivIco p a).symm :=
continuous_quotient_mk'.comp continuous_subtype_val
@[continuity]
theorem continuous_equivIoc_symm : Continuous (equivIoc p a).symm :=
continuous_quotient_mk'.comp continuous_subtype_val
variable [OrderTopology 𝕜] {x : AddCircle p}
theorem continuousAt_equivIco (hx : x ≠ a) : ContinuousAt (equivIco p a) x := by
induction x using QuotientAddGroup.induction_on
rw [ContinuousAt, Filter.Tendsto, QuotientAddGroup.nhds_eq, Filter.map_map]
exact (continuousAt_toIcoMod hp.out a hx).codRestrict _
theorem continuousAt_equivIoc (hx : x ≠ a) : ContinuousAt (equivIoc p a) x := by
induction x using QuotientAddGroup.induction_on
rw [ContinuousAt, Filter.Tendsto, QuotientAddGroup.nhds_eq, Filter.map_map]
exact (continuousAt_toIocMod hp.out a hx).codRestrict _
/-- The quotient map `𝕜 → AddCircle p` as a partial homeomorphism. -/
@[simps] def partialHomeomorphCoe [DiscreteTopology (zmultiples p)] :
PartialHomeomorph 𝕜 (AddCircle p) where
toFun := (↑)
invFun := fun x ↦ equivIco p a x
source := Ioo a (a + p)
target := {↑a}ᶜ
map_source' := by
intro x hx hx'
exact hx.1.ne' ((coe_eq_coe_iff_of_mem_Ico (Ioo_subset_Ico_self hx)
(left_mem_Ico.mpr (lt_add_of_pos_right a hp.out))).mp hx')
map_target' := by
intro x hx
exact (eq_left_or_mem_Ioo_of_mem_Ico (equivIco p a x).2).resolve_left
(hx ∘ ((equivIco p a).symm_apply_apply x).symm.trans ∘ congrArg _)
left_inv' :=
fun x hx ↦ congrArg _ ((equivIco p a).apply_symm_apply ⟨x, Ioo_subset_Ico_self hx⟩)
right_inv' := fun x _ ↦ (equivIco p a).symm_apply_apply x
open_source := isOpen_Ioo
open_target := isOpen_compl_singleton
continuousOn_toFun := (AddCircle.continuous_mk' p).continuousOn
continuousOn_invFun := by
exact continuousOn_of_forall_continuousAt
(fun _ ↦ continuousAt_subtype_val.comp ∘ continuousAt_equivIco p a)
lemma isLocalHomeomorph_coe [DiscreteTopology (zmultiples p)] [DenselyOrdered 𝕜] :
IsLocalHomeomorph ((↑) : 𝕜 → AddCircle p) := by
intro a
obtain ⟨b, hb1, hb2⟩ := exists_between (sub_lt_self a hp.out)
exact ⟨partialHomeomorphCoe p b, ⟨hb2, lt_add_of_sub_right_lt hb1⟩, rfl⟩
end Continuity
/-- The image of the closed-open interval `[a, a + p)` under the quotient map `𝕜 → AddCircle p` is
the entire space. -/
@[simp]
theorem coe_image_Ico_eq : ((↑) : 𝕜 → AddCircle p) '' Ico a (a + p) = univ := by
rw [image_eq_range]
exact (equivIco p a).symm.range_eq_univ
/-- The image of the closed-open interval `[a, a + p)` under the quotient map `𝕜 → AddCircle p` is
the entire space. -/
@[simp]
theorem coe_image_Ioc_eq : ((↑) : 𝕜 → AddCircle p) '' Ioc a (a + p) = univ := by
rw [image_eq_range]
exact (equivIoc p a).symm.range_eq_univ
/-- The image of the closed interval `[0, p]` under the quotient map `𝕜 → AddCircle p` is the
entire space. -/
@[simp]
theorem coe_image_Icc_eq : ((↑) : 𝕜 → AddCircle p) '' Icc a (a + p) = univ :=
eq_top_mono (image_subset _ Ico_subset_Icc_self) <| coe_image_Ico_eq _ _
end LinearOrderedAddCommGroup
section LinearOrderedField
variable [Field 𝕜] (p q : 𝕜)
/-- The rescaling equivalence between additive circles with different periods. -/
def equivAddCircle (hp : p ≠ 0) (hq : q ≠ 0) : AddCircle p ≃+ AddCircle q :=
QuotientAddGroup.congr _ _ (AddAut.mulRight <| (Units.mk0 p hp)⁻¹ * Units.mk0 q hq) <| by
rw [AddMonoidHom.map_zmultiples, AddMonoidHom.coe_coe, AddAut.mulRight_apply, Units.val_mul,
Units.val_mk0, Units.val_inv_eq_inv_val, Units.val_mk0, mul_inv_cancel_left₀ hp]
@[simp]
theorem equivAddCircle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) :
equivAddCircle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) :=
rfl
@[simp]
theorem equivAddCircle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) :
(equivAddCircle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) :=
rfl
section
variable [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜]
/-- The rescaling homeomorphism between additive circles with different periods. -/
def homeomorphAddCircle (hp : p ≠ 0) (hq : q ≠ 0) : AddCircle p ≃ₜ AddCircle q :=
⟨equivAddCircle p q hp hq,
(continuous_quotient_mk'.comp (continuous_mul_right (p⁻¹ * q))).quotient_lift _,
(continuous_quotient_mk'.comp (continuous_mul_right (q⁻¹ * p))).quotient_lift _⟩
@[simp]
theorem homeomorphAddCircle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) :
homeomorphAddCircle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) :=
rfl
@[simp]
theorem homeomorphAddCircle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) :
(homeomorphAddCircle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) :=
rfl
end
variable [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [hp : Fact (0 < p)]
section FloorRing
variable [FloorRing 𝕜]
@[simp]
theorem coe_equivIco_mk_apply (x : 𝕜) :
(equivIco p 0 <| QuotientAddGroup.mk x : 𝕜) = Int.fract (x / p) * p :=
toIcoMod_eq_fract_mul _ x
instance : DivisibleBy (AddCircle p) ℤ where
div x n := (↑((n : 𝕜)⁻¹ * (equivIco p 0 x : 𝕜)) : AddCircle p)
div_zero x := by
simp only [algebraMap.coe_zero, Int.cast_zero, inv_zero, zero_mul, QuotientAddGroup.mk_zero]
div_cancel {n} x hn := by
replace hn : (n : 𝕜) ≠ 0 := by norm_cast
change n • QuotientAddGroup.mk' _ ((n : 𝕜)⁻¹ * ↑(equivIco p 0 x)) = x
rw [← map_zsmul, ← smul_mul_assoc, zsmul_eq_mul, mul_inv_cancel₀ hn, one_mul]
exact (equivIco p 0).symm_apply_apply x
end FloorRing
section FiniteOrderPoints
variable {p}
theorem addOrderOf_period_div {n : ℕ} (h : 0 < n) : addOrderOf ((p / n : 𝕜) : AddCircle p) = n := by
rw [addOrderOf_eq_iff h]
replace h : 0 < (n : 𝕜) := Nat.cast_pos.2 h
refine ⟨?_, fun m hn h0 => ?_⟩ <;> simp only [Ne, ← coe_nsmul, nsmul_eq_mul]
· rw [mul_div_cancel₀ _ h.ne', coe_period]
rw [coe_eq_zero_of_pos_iff p hp.out (mul_pos (Nat.cast_pos.2 h0) <| div_pos hp.out h)]
rintro ⟨k, hk⟩
rw [mul_div, eq_div_iff h.ne', nsmul_eq_mul, mul_right_comm, ← Nat.cast_mul,
(mul_left_injective₀ hp.out.ne').eq_iff, Nat.cast_inj, mul_comm] at hk
exact (Nat.le_of_dvd h0 ⟨_, hk.symm⟩).not_lt hn
variable (p) in
theorem gcd_mul_addOrderOf_div_eq {n : ℕ} (m : ℕ) (hn : 0 < n) :
m.gcd n * addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by
rw [mul_comm_div, ← nsmul_eq_mul, coe_nsmul, IsOfFinAddOrder.addOrderOf_nsmul]
· rw [addOrderOf_period_div hn, Nat.gcd_comm, Nat.mul_div_cancel']
exact n.gcd_dvd_left m
· rwa [← addOrderOf_pos_iff, addOrderOf_period_div hn]
theorem addOrderOf_div_of_gcd_eq_one {m n : ℕ} (hn : 0 < n) (h : m.gcd n = 1) :
addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by
convert gcd_mul_addOrderOf_div_eq p m hn
rw [h, one_mul]
theorem addOrderOf_div_of_gcd_eq_one' {m : ℤ} {n : ℕ} (hn : 0 < n) (h : m.natAbs.gcd n = 1) :
addOrderOf (↑(↑m / ↑n * p) : AddCircle p) = n := by
cases m
· simp only [Int.ofNat_eq_coe, Int.cast_natCast, Int.natAbs_natCast] at h ⊢
exact addOrderOf_div_of_gcd_eq_one hn h
· simp only [Int.cast_negSucc, neg_div, neg_mul, coe_neg, addOrderOf_neg]
exact addOrderOf_div_of_gcd_eq_one hn h
theorem addOrderOf_coe_rat {q : ℚ} : addOrderOf (↑(↑q * p) : AddCircle p) = q.den := by
have : (↑(q.den : ℤ) : 𝕜) ≠ 0 := by
norm_cast
exact q.pos.ne.symm
rw [← q.num_divInt_den, Rat.cast_divInt_of_ne_zero _ this, Int.cast_natCast, Rat.num_divInt_den,
addOrderOf_div_of_gcd_eq_one' q.pos q.reduced]
theorem addOrderOf_eq_pos_iff {u : AddCircle p} {n : ℕ} (h : 0 < n) :
addOrderOf u = n ↔ ∃ m < n, m.gcd n = 1 ∧ ↑(↑m / ↑n * p) = u := by
refine ⟨QuotientAddGroup.induction_on u fun k hk => ?_, ?_⟩
| · rintro ⟨m, _, h₁, rfl⟩
exact addOrderOf_div_of_gcd_eq_one h h₁
have h0 := addOrderOf_nsmul_eq_zero (k : AddCircle p)
rw [hk, ← coe_nsmul, coe_eq_zero_iff] at h0
obtain ⟨a, ha⟩ := h0
have h0 : (_ : 𝕜) ≠ 0 := Nat.cast_ne_zero.2 h.ne'
| Mathlib/Topology/Instances/AddCircle.lean | 418 | 423 |
/-
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.Basic
import Mathlib.Algebra.Lie.Subalgebra
import Mathlib.Algebra.Lie.Submodule
import Mathlib.Algebra.Algebra.Subalgebra.Basic
/-!
# Lie algebras of associative algebras
This file defines the Lie algebra structure that arises on an associative algebra via the ring
commutator.
Since the linear endomorphisms of a Lie algebra form an associative algebra, one can define the
adjoint action as a morphism of Lie algebras from a Lie algebra to its linear endomorphisms. We
make such a definition in this file.
## Main definitions
* `LieAlgebra.ofAssociativeAlgebra`
* `LieAlgebra.ofAssociativeAlgebraHom`
* `LieModule.toEnd`
* `LieAlgebra.ad`
* `LinearEquiv.lieConj`
* `AlgEquiv.toLieEquiv`
## Tags
lie algebra, ring commutator, adjoint action
-/
universe u v w w₁ w₂
section OfAssociative
variable {A : Type v} [Ring A]
namespace LieRing
/-- An associative ring gives rise to a Lie ring by taking the bracket to be the ring commutator. -/
instance (priority := 100) ofAssociativeRing : LieRing A where
add_lie _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel
lie_add _ _ _ := by simp only [Ring.lie_def, right_distrib, left_distrib]; abel
lie_self := by simp only [Ring.lie_def, forall_const, sub_self]
leibniz_lie _ _ _ := by
simp only [Ring.lie_def, mul_sub_left_distrib, mul_sub_right_distrib, mul_assoc]; abel
theorem of_associative_ring_bracket (x y : A) : ⁅x, y⁆ = x * y - y * x :=
rfl
@[simp]
theorem lie_apply {α : Type*} (f g : α → A) (a : α) : ⁅f, g⁆ a = ⁅f a, g a⁆ :=
rfl
end LieRing
section AssociativeModule
variable {M : Type w} [AddCommGroup M] [Module A M]
/-- We can regard a module over an associative ring `A` as a Lie ring module over `A` with Lie
bracket equal to its ring commutator.
Note that this cannot be a global instance because it would create a diamond when `M = A`,
specifically we can build two mathematically-different `bracket A A`s:
1. `@Ring.bracket A _` which says `⁅a, b⁆ = a * b - b * a`
2. `(@LieRingModule.ofAssociativeModule A _ A _ _).toBracket` which says `⁅a, b⁆ = a • b`
(and thus `⁅a, b⁆ = a * b`)
See note [reducible non-instances] -/
abbrev LieRingModule.ofAssociativeModule : LieRingModule A M where
bracket := (· • ·)
add_lie := add_smul
lie_add := smul_add
leibniz_lie := by simp [LieRing.of_associative_ring_bracket, sub_smul, mul_smul, sub_add_cancel]
attribute [local instance] LieRingModule.ofAssociativeModule
theorem lie_eq_smul (a : A) (m : M) : ⁅a, m⁆ = a • m :=
rfl
end AssociativeModule
section LieAlgebra
variable {R : Type u} [CommRing R] [Algebra R A]
/-- An associative algebra gives rise to a Lie algebra by taking the bracket to be the ring
commutator. -/
instance (priority := 100) LieAlgebra.ofAssociativeAlgebra : LieAlgebra R A where
lie_smul t x y := by
rw [LieRing.of_associative_ring_bracket, LieRing.of_associative_ring_bracket,
Algebra.mul_smul_comm, Algebra.smul_mul_assoc, smul_sub]
attribute [local instance] LieRingModule.ofAssociativeModule
section AssociativeRepresentation
variable {M : Type w} [AddCommGroup M] [Module R M] [Module A M] [IsScalarTower R A M]
/-- A representation of an associative algebra `A` is also a representation of `A`, regarded as a
Lie algebra via the ring commutator.
See the comment at `LieRingModule.ofAssociativeModule` for why the possibility `M = A` means
this cannot be a global instance. -/
theorem LieModule.ofAssociativeModule : LieModule R A M where
smul_lie := smul_assoc
lie_smul := smul_algebra_smul_comm
instance Module.End.instLieRingModule : LieRingModule (Module.End R M) M :=
LieRingModule.ofAssociativeModule
instance Module.End.instLieModule : LieModule R (Module.End R M) M :=
LieModule.ofAssociativeModule
@[simp] lemma Module.End.lie_apply (f : Module.End R M) (m : M) : ⁅f, m⁆ = f m := rfl
end AssociativeRepresentation
namespace AlgHom
variable {B : Type w} {C : Type w₁} [Ring B] [Ring C] [Algebra R B] [Algebra R C]
variable (f : A →ₐ[R] B) (g : B →ₐ[R] C)
/-- The map `ofAssociativeAlgebra` associating a Lie algebra to an associative algebra is
functorial. -/
def toLieHom : A →ₗ⁅R⁆ B :=
{ f.toLinearMap with
map_lie' := fun {_ _} => by simp [LieRing.of_associative_ring_bracket] }
instance : Coe (A →ₐ[R] B) (A →ₗ⁅R⁆ B) :=
⟨toLieHom⟩
@[simp]
theorem coe_toLieHom : ((f : A →ₗ⁅R⁆ B) : A → B) = f :=
rfl
theorem toLieHom_apply (x : A) : f.toLieHom x = f x :=
rfl
@[simp]
theorem toLieHom_id : (AlgHom.id R A : A →ₗ⁅R⁆ A) = LieHom.id :=
rfl
@[simp]
theorem toLieHom_comp : (g.comp f : A →ₗ⁅R⁆ C) = (g : B →ₗ⁅R⁆ C).comp (f : A →ₗ⁅R⁆ B) :=
rfl
theorem toLieHom_injective {f g : A →ₐ[R] B} (h : (f : A →ₗ⁅R⁆ B) = (g : A →ₗ⁅R⁆ B)) : f = g := by
ext a; exact LieHom.congr_fun h a
end AlgHom
end LieAlgebra
end OfAssociative
section AdjointAction
variable (R : Type u) (L : Type v) (M : Type w)
variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M] [LieModule R L M]
/-- A Lie module yields a Lie algebra morphism into the linear endomorphisms of the module.
See also `LieModule.toModuleHom`. -/
@[simps]
def LieModule.toEnd : L →ₗ⁅R⁆ Module.End R M where
toFun x :=
{ toFun := fun m => ⁅x, m⁆
map_add' := lie_add x
map_smul' := fun t => lie_smul t x }
map_add' x y := by ext m; apply add_lie
map_smul' t x := by ext m; apply smul_lie
map_lie' {x y} := by ext m; apply lie_lie
/-- The adjoint action of a Lie algebra on itself. -/
def LieAlgebra.ad : L →ₗ⁅R⁆ Module.End R L :=
LieModule.toEnd R L L
@[simp]
theorem LieAlgebra.ad_apply (x y : L) : LieAlgebra.ad R L x y = ⁅x, y⁆ :=
rfl
@[simp]
theorem LieModule.toEnd_module_end :
LieModule.toEnd R (Module.End R M) M = LieHom.id := by ext g m; simp [lie_eq_smul]
theorem LieSubalgebra.toEnd_eq (K : LieSubalgebra R L) {x : K} :
LieModule.toEnd R K M x = LieModule.toEnd R L M x :=
rfl
@[simp]
theorem LieSubalgebra.toEnd_mk (K : LieSubalgebra R L) {x : L} (hx : x ∈ K) :
LieModule.toEnd R K M ⟨x, hx⟩ = LieModule.toEnd R L M x :=
rfl
section IsFaithful
open Function
namespace LieModule
/-- A Lie module is *faithful* if the associated map `L → End M` is injective. -/
@[mk_iff]
class IsFaithful : Prop where
injective_toEnd : Injective <| toEnd R L M
@[simp]
lemma toEnd_eq_iff [IsFaithful R L M] {x y : L} :
toEnd R L M x = toEnd R L M y ↔ x = y :=
IsFaithful.injective_toEnd.eq_iff
variable {R L} in
lemma ext_of_isFaithful [IsFaithful R L M] {x y : L} (h : ∀ m : M, ⁅x, m⁆ = ⁅y, m⁆) :
x = y :=
(toEnd_eq_iff R L M).mp <| LinearMap.ext h
@[simp]
lemma toEnd_eq_zero_iff [IsFaithful R L M] {x : L} :
toEnd R L M x = 0 ↔ x = 0 := by
simp [- LieHom.map_zero, ← (toEnd R L M).map_zero]
lemma isFaithful_iff' : IsFaithful R L M ↔ ∀ x : L, (∀ m : M, ⁅x, m⁆ = 0) → x = 0 := by
refine ⟨fun h x hx ↦ ?_, fun h ↦ ⟨fun x y hxy ↦ ?_⟩⟩
· replace hx : toEnd R L M x = 0 := by ext m; simpa using hx m
simpa using hx
· rw [← sub_eq_zero]
refine h _ fun m ↦ ?_
rw [sub_lie, sub_eq_zero, ← toEnd_apply_apply R, ← toEnd_apply_apply R, hxy]
end LieModule
end IsFaithful
section
open LieAlgebra LieModule
lemma LieSubmodule.coe_toEnd (N : LieSubmodule R L M) (x : L) (y : N) :
(toEnd R L N x y : M) = toEnd R L M x y := rfl
lemma LieSubmodule.coe_toEnd_pow (N : LieSubmodule R L M) (x : L) (y : N) (n : ℕ) :
((toEnd R L N x ^ n) y : M) = (toEnd R L M x ^ n) y := by
induction n generalizing y with
| zero => rfl
| succ n ih => simp only [pow_succ', Module.End.mul_apply, ih, LieSubmodule.coe_toEnd]
lemma LieSubalgebra.coe_ad (H : LieSubalgebra R L) (x y : H) :
(ad R H x y : L) = ad R L x y := rfl
lemma LieSubalgebra.coe_ad_pow (H : LieSubalgebra R L) (x y : H) (n : ℕ) :
((ad R H x ^ n) y : L) = (ad R L x ^ n) y :=
LieSubmodule.coe_toEnd_pow R H L H.toLieSubmodule x y n
variable {L M}
local notation "φ" => LieModule.toEnd R L M
lemma LieModule.toEnd_lie (x y : L) (z : M) :
(φ x) ⁅y, z⁆ = ⁅ad R L x y, z⁆ + ⁅y, φ x z⁆ := by
simp
lemma LieAlgebra.ad_lie (x y z : L) :
(ad R L x) ⁅y, z⁆ = ⁅ad R L x y, z⁆ + ⁅y, ad R L x z⁆ :=
toEnd_lie _ x y z
open Finset in
lemma LieModule.toEnd_pow_lie (x y : L) (z : M) (n : ℕ) :
((φ x) ^ n) ⁅y, z⁆ =
∑ ij ∈ antidiagonal n, n.choose ij.1 • ⁅((ad R L x) ^ ij.1) y, ((φ x) ^ ij.2) z⁆ := by
induction n with
| zero => simp
| succ n ih =>
rw [Finset.sum_antidiagonal_choose_succ_nsmul
(fun i j ↦ ⁅((ad R L x) ^ i) y, ((φ x) ^ j) z⁆) n]
simp only [pow_succ', Module.End.mul_apply, ih, map_sum, map_nsmul,
toEnd_lie, nsmul_add, sum_add_distrib]
rw [add_comm, add_left_cancel_iff, sum_congr rfl]
rintro ⟨i, j⟩ hij
rw [mem_antidiagonal] at hij
rw [Nat.choose_symm_of_eq_add hij.symm]
open Finset in
lemma LieAlgebra.ad_pow_lie (x y z : L) (n : ℕ) :
((ad R L x) ^ n) ⁅y, z⁆ =
∑ ij ∈ antidiagonal n, n.choose ij.1 • ⁅((ad R L x) ^ ij.1) y, ((ad R L x) ^ ij.2) z⁆ :=
toEnd_pow_lie _ x y z n
| end
variable {R L M}
namespace LieModule
| Mathlib/Algebra/Lie/OfAssociative.lean | 295 | 299 |
/-
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)
| Mathlib/SetTheory/Ordinal/Notation.lean | 848 | 860 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Operations
/-!
# Results about division in extended non-negative reals
This file establishes basic properties related to the inversion and division operations on `ℝ≥0∞`.
For instance, as a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation
with integer exponent.
## Main results
A few order isomorphisms are worthy of mention:
- `OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ`: The map `x ↦ x⁻¹` as an order isomorphism to the dual.
- `orderIsoIicOneBirational : ℝ≥0∞ ≃o Iic (1 : ℝ≥0∞)`: The birational order isomorphism between
`ℝ≥0∞` and the unit interval `Set.Iic (1 : ℝ≥0∞)` given by `x ↦ (x⁻¹ + 1)⁻¹` with inverse
`x ↦ (x⁻¹ - 1)⁻¹`
- `orderIsoIicCoe (a : ℝ≥0) : Iic (a : ℝ≥0∞) ≃o Iic a`: Order isomorphism between an initial
interval in `ℝ≥0∞` and an initial interval in `ℝ≥0` given by the identity map.
- `orderIsoUnitIntervalBirational : ℝ≥0∞ ≃o Icc (0 : ℝ) 1`: An order isomorphism between
the extended nonnegative real numbers and the unit interval. This is `orderIsoIicOneBirational`
composed with the identity order isomorphism between `Iic (1 : ℝ≥0∞)` and `Icc (0 : ℝ) 1`.
-/
assert_not_exists Finset
open Set NNReal
namespace ENNReal
noncomputable section Inv
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
protected theorem div_eq_inv_mul : a / b = b⁻¹ * a := by rw [div_eq_mul_inv, mul_comm]
@[simp] theorem inv_zero : (0 : ℝ≥0∞)⁻¹ = ∞ :=
show sInf { b : ℝ≥0∞ | 1 ≤ 0 * b } = ∞ by simp
@[simp] theorem inv_top : ∞⁻¹ = 0 :=
bot_unique <| le_of_forall_gt_imp_ge_of_dense fun a (h : 0 < a) => sInf_le <| by
simp [*, h.ne', top_mul]
theorem coe_inv_le : (↑r⁻¹ : ℝ≥0∞) ≤ (↑r)⁻¹ :=
le_sInf fun b (hb : 1 ≤ ↑r * b) =>
coe_le_iff.2 <| by
rintro b rfl
apply NNReal.inv_le_of_le_mul
rwa [← coe_mul, ← coe_one, coe_le_coe] at hb
@[simp, norm_cast]
theorem coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ℝ≥0∞) = (↑r)⁻¹ :=
coe_inv_le.antisymm <| sInf_le <| mem_setOf.2 <| by rw [← coe_mul, mul_inv_cancel₀ hr, coe_one]
@[norm_cast]
theorem coe_inv_two : ((2⁻¹ : ℝ≥0) : ℝ≥0∞) = 2⁻¹ := by rw [coe_inv _root_.two_ne_zero, coe_two]
@[simp, norm_cast]
theorem coe_div (hr : r ≠ 0) : (↑(p / r) : ℝ≥0∞) = p / r := by
rw [div_eq_mul_inv, div_eq_mul_inv, coe_mul, coe_inv hr]
lemma coe_div_le : ↑(p / r) ≤ (p / r : ℝ≥0∞) := by
simpa only [div_eq_mul_inv, coe_mul] using mul_le_mul_left' coe_inv_le _
theorem div_zero (h : a ≠ 0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h]
instance : DivInvOneMonoid ℝ≥0∞ :=
{ inferInstanceAs (DivInvMonoid ℝ≥0∞) with
inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one }
protected theorem inv_pow : ∀ {a : ℝ≥0∞} {n : ℕ}, (a ^ n)⁻¹ = a⁻¹ ^ n
| _, 0 => by simp only [pow_zero, inv_one]
| ⊤, n + 1 => by simp [top_pow]
| (a : ℝ≥0), n + 1 => by
rcases eq_or_ne a 0 with (rfl | ha)
· simp [top_pow]
· have := pow_ne_zero (n + 1) ha
norm_cast
rw [inv_pow]
protected theorem mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 := by
lift a to ℝ≥0 using ht
norm_cast at h0; norm_cast
exact mul_inv_cancel₀ h0
protected theorem inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 :=
mul_comm a a⁻¹ ▸ ENNReal.mul_inv_cancel h0 ht
/-- See `ENNReal.inv_mul_cancel_left` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma inv_mul_cancel_left' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) :
a⁻¹ * (a * b) = b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
obtain rfl | ha := eq_or_ne a ⊤
· simp_all
· simp [← mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_left'` for a stronger version. -/
protected lemma inv_mul_cancel_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a⁻¹ * (a * b) = b :=
ENNReal.inv_mul_cancel_left' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_left` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma mul_inv_cancel_left' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) :
a * (a⁻¹ * b) = b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
obtain rfl | ha := eq_or_ne a ⊤
· simp_all
· simp [← mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_left'` for a stronger version. -/
protected lemma mul_inv_cancel_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * (a⁻¹ * b) = b :=
ENNReal.mul_inv_cancel_left' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_inv_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma mul_inv_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b * b⁻¹ = a := by
obtain rfl | hb₀ := eq_or_ne b 0
· simp_all
obtain rfl | hb := eq_or_ne b ⊤
· simp_all
· simp [mul_assoc, ENNReal.mul_inv_cancel, *]
/-- See `ENNReal.mul_inv_cancel_right'` for a stronger version. -/
protected lemma mul_inv_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b * b⁻¹ = a :=
ENNReal.mul_inv_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.inv_mul_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma inv_mul_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b⁻¹ * b = a := by
obtain rfl | hb₀ := eq_or_ne b 0
· simp_all
obtain rfl | hb := eq_or_ne b ⊤
· simp_all
· simp [mul_assoc, ENNReal.inv_mul_cancel, *]
/-- See `ENNReal.inv_mul_cancel_right'` for a stronger version. -/
protected lemma inv_mul_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b⁻¹ * b = a :=
ENNReal.inv_mul_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.mul_div_cancel_right` for a simpler version assuming `b ≠ 0`, `b ≠ ∞`. -/
protected lemma mul_div_cancel_right' (hb₀ : b = 0 → a = 0) (hb : b = ∞ → a = 0) :
a * b / b = a := ENNReal.mul_inv_cancel_right' hb₀ hb
/-- See `ENNReal.mul_div_cancel_right'` for a stronger version. -/
protected lemma mul_div_cancel_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b / b = a :=
ENNReal.mul_div_cancel_right' (by simp [hb₀]) (by simp [hb])
/-- See `ENNReal.div_mul_cancel` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma div_mul_cancel' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) : b / a * a = b :=
ENNReal.inv_mul_cancel_right' ha₀ ha
/-- See `ENNReal.div_mul_cancel'` for a stronger version. -/
protected lemma div_mul_cancel (ha₀ : a ≠ 0) (ha : a ≠ ∞) : b / a * a = b :=
ENNReal.div_mul_cancel' (by simp [ha₀]) (by simp [ha])
/-- See `ENNReal.mul_div_cancel` for a simpler version assuming `a ≠ 0`, `a ≠ ∞`. -/
protected lemma mul_div_cancel' (ha₀ : a = 0 → b = 0) (ha : a = ∞ → b = 0) : a * (b / a) = b := by
rw [mul_comm, ENNReal.div_mul_cancel' ha₀ ha]
/-- See `ENNReal.mul_div_cancel'` for a stronger version. -/
protected lemma mul_div_cancel (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * (b / a) = b :=
ENNReal.mul_div_cancel' (by simp [ha₀]) (by simp [ha])
protected theorem mul_comm_div : a / b * c = a * (c / b) := by
simp only [div_eq_mul_inv, mul_left_comm, mul_comm, mul_assoc]
protected theorem mul_div_right_comm : a * b / c = a / c * b := by
simp only [div_eq_mul_inv, mul_right_comm]
instance : InvolutiveInv ℝ≥0∞ where
inv_inv a := by
by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm]
@[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one]
@[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_inj
theorem inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp
@[aesop (rule_sets := [finiteness]) safe apply]
protected alias ⟨_, Finiteness.inv_ne_top⟩ := ENNReal.inv_ne_top
@[simp]
theorem inv_lt_top {x : ℝ≥0∞} : x⁻¹ < ∞ ↔ 0 < x := by
simp only [lt_top_iff_ne_top, inv_ne_top, pos_iff_ne_zero]
theorem div_lt_top {x y : ℝ≥0∞} (h1 : x ≠ ∞) (h2 : y ≠ 0) : x / y < ∞ :=
mul_lt_top h1.lt_top (inv_ne_top.mpr h2).lt_top
@[simp]
protected theorem inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ :=
inv_top ▸ inv_inj
protected theorem inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp
protected theorem div_pos (ha : a ≠ 0) (hb : b ≠ ∞) : 0 < a / b :=
ENNReal.mul_pos ha <| ENNReal.inv_ne_zero.2 hb
protected theorem inv_mul_le_iff {x y z : ℝ≥0∞} (h1 : x ≠ 0) (h2 : x ≠ ∞) :
x⁻¹ * y ≤ z ↔ y ≤ x * z := by
rw [← mul_le_mul_left h1 h2, ← mul_assoc, ENNReal.mul_inv_cancel h1 h2, one_mul]
protected theorem mul_inv_le_iff {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x * y⁻¹ ≤ z ↔ x ≤ z * y := by
rw [mul_comm, ENNReal.inv_mul_le_iff h1 h2, mul_comm]
protected theorem div_le_iff {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x / y ≤ z ↔ x ≤ z * y := by
rw [div_eq_mul_inv, ENNReal.mul_inv_le_iff h1 h2]
protected theorem div_le_iff' {x y z : ℝ≥0∞} (h1 : y ≠ 0) (h2 : y ≠ ∞) :
x / y ≤ z ↔ x ≤ y * z := by
rw [mul_comm, ENNReal.div_le_iff h1 h2]
protected theorem mul_inv {a b : ℝ≥0∞} (ha : a ≠ 0 ∨ b ≠ ∞) (hb : a ≠ ∞ ∨ b ≠ 0) :
(a * b)⁻¹ = a⁻¹ * b⁻¹ := by
induction' b with b
· replace ha : a ≠ 0 := ha.neg_resolve_right rfl
simp [ha]
induction' a with a
· replace hb : b ≠ 0 := coe_ne_zero.1 (hb.neg_resolve_left rfl)
simp [hb]
by_cases h'a : a = 0
· simp only [h'a, top_mul, ENNReal.inv_zero, ENNReal.coe_ne_top, zero_mul, Ne,
not_false_iff, ENNReal.coe_zero, ENNReal.inv_eq_zero]
by_cases h'b : b = 0
· simp only [h'b, ENNReal.inv_zero, ENNReal.coe_ne_top, mul_top, Ne, not_false_iff,
mul_zero, ENNReal.coe_zero, ENNReal.inv_eq_zero]
rw [← ENNReal.coe_mul, ← ENNReal.coe_inv, ← ENNReal.coe_inv h'a, ← ENNReal.coe_inv h'b, ←
ENNReal.coe_mul, mul_inv_rev, mul_comm]
simp [h'a, h'b]
protected theorem inv_div {a b : ℝ≥0∞} (htop : b ≠ ∞ ∨ a ≠ ∞) (hzero : b ≠ 0 ∨ a ≠ 0) :
(a / b)⁻¹ = b / a := by
rw [← ENNReal.inv_ne_zero] at htop
rw [← ENNReal.inv_ne_top] at hzero
rw [ENNReal.div_eq_inv_mul, ENNReal.div_eq_inv_mul, ENNReal.mul_inv htop hzero, mul_comm, inv_inv]
protected theorem mul_div_mul_left (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) :
c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inl hc) (Or.inl hc'), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', one_mul]
protected theorem mul_div_mul_right (a b : ℝ≥0∞) (hc : c ≠ 0) (hc' : c ≠ ⊤) :
a * c / (b * c) = a / b := by
rw [div_eq_mul_inv, div_eq_mul_inv, ENNReal.mul_inv (Or.inr hc') (Or.inr hc), mul_mul_mul_comm,
ENNReal.mul_inv_cancel hc hc', mul_one]
protected theorem sub_div (h : 0 < b → b < a → c ≠ 0) : (a - b) / c = a / c - b / c := by
simp_rw [div_eq_mul_inv]
exact ENNReal.sub_mul (by simpa using h)
@[simp]
protected theorem inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ :=
pos_iff_ne_zero.trans ENNReal.inv_ne_zero
theorem inv_strictAnti : StrictAnti (Inv.inv : ℝ≥0∞ → ℝ≥0∞) := by
intro a b h
lift a to ℝ≥0 using h.ne_top
induction b; · simp
rw [coe_lt_coe] at h
rcases eq_or_ne a 0 with (rfl | ha); · simp [h]
rw [← coe_inv h.ne_bot, ← coe_inv ha, coe_lt_coe]
exact NNReal.inv_lt_inv ha h
@[simp]
protected theorem inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a :=
inv_strictAnti.lt_iff_lt
theorem inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by
simpa only [inv_inv] using @ENNReal.inv_lt_inv a b⁻¹
theorem lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by
simpa only [inv_inv] using @ENNReal.inv_lt_inv a⁻¹ b
@[simp]
protected theorem inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a :=
inv_strictAnti.le_iff_le
theorem inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by
simpa only [inv_inv] using @ENNReal.inv_le_inv a b⁻¹
theorem le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by
simpa only [inv_inv] using @ENNReal.inv_le_inv a⁻¹ b
@[gcongr] protected theorem inv_le_inv' (h : a ≤ b) : b⁻¹ ≤ a⁻¹ :=
ENNReal.inv_strictAnti.antitone h
@[gcongr] protected theorem inv_lt_inv' (h : a < b) : b⁻¹ < a⁻¹ := ENNReal.inv_strictAnti h
@[simp]
protected theorem inv_le_one : a⁻¹ ≤ 1 ↔ 1 ≤ a := by rw [inv_le_iff_inv_le, inv_one]
protected theorem one_le_inv : 1 ≤ a⁻¹ ↔ a ≤ 1 := by rw [le_inv_iff_le_inv, inv_one]
@[simp]
protected theorem inv_lt_one : a⁻¹ < 1 ↔ 1 < a := by rw [inv_lt_iff_inv_lt, inv_one]
@[simp]
protected theorem one_lt_inv : 1 < a⁻¹ ↔ a < 1 := by rw [lt_inv_iff_lt_inv, inv_one]
/-- The inverse map `fun x ↦ x⁻¹` is an order isomorphism between `ℝ≥0∞` and its `OrderDual` -/
@[simps! apply]
def _root_.OrderIso.invENNReal : ℝ≥0∞ ≃o ℝ≥0∞ᵒᵈ where
map_rel_iff' := ENNReal.inv_le_inv
toEquiv := (Equiv.inv ℝ≥0∞).trans OrderDual.toDual
@[simp]
theorem _root_.OrderIso.invENNReal_symm_apply (a : ℝ≥0∞ᵒᵈ) :
OrderIso.invENNReal.symm a = (OrderDual.ofDual a)⁻¹ :=
rfl
@[simp] theorem div_top : a / ∞ = 0 := by rw [div_eq_mul_inv, inv_top, mul_zero]
theorem top_div : ∞ / a = if a = ∞ then 0 else ∞ := by simp [div_eq_mul_inv, top_mul']
theorem top_div_of_ne_top (h : a ≠ ∞) : ∞ / a = ∞ := by simp [top_div, h]
@[simp] theorem top_div_coe : ∞ / p = ∞ := top_div_of_ne_top coe_ne_top
theorem top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ := top_div_of_ne_top h.ne
@[simp] protected theorem zero_div : 0 / a = 0 := zero_mul a⁻¹
theorem div_eq_top : a / b = ∞ ↔ a ≠ 0 ∧ b = 0 ∨ a = ∞ ∧ b ≠ ∞ := by
simp [div_eq_mul_inv, ENNReal.mul_eq_top]
protected theorem le_div_iff_mul_le (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) :
a ≤ c / b ↔ a * b ≤ c := by
induction' b with b
· lift c to ℝ≥0 using ht.neg_resolve_left rfl
rw [div_top, nonpos_iff_eq_zero]
rcases eq_or_ne a 0 with (rfl | ha) <;> simp [*]
rcases eq_or_ne b 0 with (rfl | hb)
· have hc : c ≠ 0 := h0.neg_resolve_left rfl
simp [div_zero hc]
· rw [← coe_ne_zero] at hb
rw [← ENNReal.mul_le_mul_right hb coe_ne_top, ENNReal.div_mul_cancel hb coe_ne_top]
protected theorem div_le_iff_le_mul (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) :
a / b ≤ c ↔ a ≤ c * b := by
suffices a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹ by simpa [div_eq_mul_inv]
refine (ENNReal.le_div_iff_mul_le ?_ ?_).symm <;> simpa
protected theorem lt_div_iff_mul_lt (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) :
c < a / b ↔ c * b < a :=
lt_iff_lt_of_le_iff_le (ENNReal.div_le_iff_le_mul hb0 hbt)
theorem div_le_of_le_mul (h : a ≤ b * c) : a / c ≤ b := by
by_cases h0 : c = 0
· have : a = 0 := by simpa [h0] using h
simp [*]
by_cases hinf : c = ∞; · simp [hinf]
exact (ENNReal.div_le_iff_le_mul (Or.inl h0) (Or.inl hinf)).2 h
theorem div_le_of_le_mul' (h : a ≤ b * c) : a / b ≤ c :=
div_le_of_le_mul <| mul_comm b c ▸ h
@[simp] protected theorem div_self_le_one : a / a ≤ 1 := div_le_of_le_mul <| by rw [one_mul]
@[simp] protected lemma mul_inv_le_one (a : ℝ≥0∞) : a * a⁻¹ ≤ 1 := ENNReal.div_self_le_one
@[simp] protected lemma inv_mul_le_one (a : ℝ≥0∞) : a⁻¹ * a ≤ 1 := by simp [mul_comm]
@[simp] lemma mul_inv_ne_top (a : ℝ≥0∞) : a * a⁻¹ ≠ ⊤ :=
ne_top_of_le_ne_top one_ne_top a.mul_inv_le_one
@[simp] lemma inv_mul_ne_top (a : ℝ≥0∞) : a⁻¹ * a ≠ ⊤ := by simp [mul_comm]
theorem mul_le_of_le_div (h : a ≤ b / c) : a * c ≤ b := by
rw [← inv_inv c]
exact div_le_of_le_mul h
theorem mul_le_of_le_div' (h : a ≤ b / c) : c * a ≤ b :=
mul_comm a c ▸ mul_le_of_le_div h
protected theorem div_lt_iff (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) : c / b < a ↔ c < a * b :=
lt_iff_lt_of_le_iff_le <| ENNReal.le_div_iff_mul_le h0 ht
theorem mul_lt_of_lt_div (h : a < b / c) : a * c < b := by
contrapose! h
exact ENNReal.div_le_of_le_mul h
theorem mul_lt_of_lt_div' (h : a < b / c) : c * a < b :=
mul_comm a c ▸ mul_lt_of_lt_div h
theorem div_lt_of_lt_mul (h : a < b * c) : a / c < b :=
mul_lt_of_lt_div <| by rwa [div_eq_mul_inv, inv_inv]
theorem div_lt_of_lt_mul' (h : a < b * c) : a / b < c :=
div_lt_of_lt_mul <| by rwa [mul_comm]
theorem inv_le_iff_le_mul (h₁ : b = ∞ → a ≠ 0) (h₂ : a = ∞ → b ≠ 0) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by
rw [← one_div, ENNReal.div_le_iff_le_mul, mul_comm]
exacts [or_not_of_imp h₁, not_or_of_imp h₂]
@[simp 900]
theorem le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 := by
rw [← one_div, ENNReal.le_div_iff_mul_le] <;>
· right
simp
@[gcongr] protected theorem div_le_div (hab : a ≤ b) (hdc : d ≤ c) : a / c ≤ b / d :=
div_eq_mul_inv b d ▸ div_eq_mul_inv a c ▸ mul_le_mul' hab (ENNReal.inv_le_inv.mpr hdc)
@[gcongr] protected theorem div_le_div_left (h : a ≤ b) (c : ℝ≥0∞) : c / b ≤ c / a :=
ENNReal.div_le_div le_rfl h
@[gcongr] protected theorem div_le_div_right (h : a ≤ b) (c : ℝ≥0∞) : a / c ≤ b / c :=
ENNReal.div_le_div h le_rfl
protected theorem eq_inv_of_mul_eq_one_left (h : a * b = 1) : a = b⁻¹ := by
rw [← mul_one a, ← ENNReal.mul_inv_cancel (right_ne_zero_of_mul_eq_one h), ← mul_assoc, h,
one_mul]
rintro rfl
simp [left_ne_zero_of_mul_eq_one h] at h
theorem mul_le_iff_le_inv {a b r : ℝ≥0∞} (hr₀ : r ≠ 0) (hr₁ : r ≠ ∞) : r * a ≤ b ↔ a ≤ r⁻¹ * b := by
rw [← @ENNReal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, ENNReal.mul_inv_cancel hr₀ hr₁,
one_mul]
theorem le_of_forall_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r < x → ↑r ≤ y) : x ≤ y := by
refine le_of_forall_lt_imp_le_of_dense fun r hr => ?_
lift r to ℝ≥0 using ne_top_of_lt hr
exact h r hr
lemma eq_of_forall_nnreal_iff {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r ≤ x ↔ ↑r ≤ y) : x = y :=
le_antisymm (le_of_forall_nnreal_lt fun _r hr ↦ (h _).1 hr.le)
(le_of_forall_nnreal_lt fun _r hr ↦ (h _).2 hr.le)
theorem le_of_forall_pos_nnreal_lt {x y : ℝ≥0∞} (h : ∀ r : ℝ≥0, 0 < r → ↑r < x → ↑r ≤ y) : x ≤ y :=
le_of_forall_nnreal_lt fun r hr =>
(zero_le r).eq_or_lt.elim (fun h => h ▸ zero_le _) fun h0 => h r h0 hr
theorem eq_top_of_forall_nnreal_le {x : ℝ≥0∞} (h : ∀ r : ℝ≥0, ↑r ≤ x) : x = ∞ :=
top_unique <| le_of_forall_nnreal_lt fun r _ => h r
protected theorem add_div : (a + b) / c = a / c + b / c :=
right_distrib a b c⁻¹
protected theorem div_add_div_same {a b c : ℝ≥0∞} : a / c + b / c = (a + b) / c :=
ENNReal.add_div.symm
protected theorem div_self (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 :=
ENNReal.mul_inv_cancel h0 hI
theorem mul_div_le : a * (b / a) ≤ b :=
mul_le_of_le_div' le_rfl
theorem eq_div_iff (ha : a ≠ 0) (ha' : a ≠ ∞) : b = c / a ↔ a * b = c :=
⟨fun h => by rw [h, ENNReal.mul_div_cancel ha ha'], fun h => by
rw [← h, mul_div_assoc, ENNReal.mul_div_cancel ha ha']⟩
protected theorem div_eq_div_iff (ha : a ≠ 0) (ha' : a ≠ ∞) (hb : b ≠ 0) (hb' : b ≠ ∞) :
c / b = d / a ↔ a * c = b * d := by
rw [eq_div_iff ha ha']
conv_rhs => rw [eq_comm]
rw [← eq_div_iff hb hb', mul_div_assoc, eq_comm]
theorem div_eq_one_iff {a b : ℝ≥0∞} (hb₀ : b ≠ 0) (hb₁ : b ≠ ∞) : a / b = 1 ↔ a = b :=
⟨fun h => by rw [← (eq_div_iff hb₀ hb₁).mp h.symm, mul_one], fun h =>
h.symm ▸ ENNReal.div_self hb₀ hb₁⟩
theorem inv_two_add_inv_two : (2 : ℝ≥0∞)⁻¹ + 2⁻¹ = 1 := by
rw [← two_mul, ← div_eq_mul_inv, ENNReal.div_self two_ne_zero ofNat_ne_top]
theorem inv_three_add_inv_three : (3 : ℝ≥0∞)⁻¹ + 3⁻¹ + 3⁻¹ = 1 := by
rw [← ENNReal.mul_inv_cancel three_ne_zero ofNat_ne_top]
ring
@[simp]
protected theorem add_halves (a : ℝ≥0∞) : a / 2 + a / 2 = a := by
rw [div_eq_mul_inv, ← mul_add, inv_two_add_inv_two, mul_one]
@[simp]
theorem add_thirds (a : ℝ≥0∞) : a / 3 + a / 3 + a / 3 = a := by
rw [div_eq_mul_inv, ← mul_add, ← mul_add, inv_three_add_inv_three, mul_one]
@[simp] theorem div_eq_zero_iff : a / b = 0 ↔ a = 0 ∨ b = ∞ := by simp [div_eq_mul_inv]
@[simp] theorem div_pos_iff : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ∞ := by simp [pos_iff_ne_zero, not_or]
protected lemma div_ne_zero : a / b ≠ 0 ↔ a ≠ 0 ∧ b ≠ ∞ := by
rw [← pos_iff_ne_zero, div_pos_iff]
protected lemma div_mul (a : ℝ≥0∞) (h0 : b ≠ 0 ∨ c ≠ 0) (htop : b ≠ ∞ ∨ c ≠ ∞) :
a / b * c = a / (b / c) := by
simp only [div_eq_mul_inv]
rw [ENNReal.mul_inv, inv_inv]
· ring
· simpa
· simpa
protected lemma mul_div_mul_comm (hc : c ≠ 0 ∨ d ≠ ∞) (hd : c ≠ ∞ ∨ d ≠ 0) :
a * b / (c * d) = a / c * (b / d) := by
simp only [div_eq_mul_inv, ENNReal.mul_inv hc hd]
ring
protected theorem half_pos (h : a ≠ 0) : 0 < a / 2 :=
ENNReal.div_pos h ofNat_ne_top
protected theorem one_half_lt_one : (2⁻¹ : ℝ≥0∞) < 1 :=
| ENNReal.inv_lt_one.2 <| one_lt_two
protected theorem half_lt_self (hz : a ≠ 0) (ht : a ≠ ∞) : a / 2 < a := by
| Mathlib/Data/ENNReal/Inv.lean | 511 | 513 |
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.AffineScheme
import Mathlib.RingTheory.LocalProperties.Reduced
/-!
# Basic properties of schemes
We provide some basic properties of schemes
## Main definition
* `AlgebraicGeometry.IsIntegral`: A scheme is integral if it is nontrivial and all nontrivial
components of the structure sheaf are integral domains.
* `AlgebraicGeometry.IsReduced`: A scheme is reduced if all the components of the structure sheaf
are reduced.
-/
-- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737
universe u
open TopologicalSpace Opposite CategoryTheory CategoryTheory.Limits TopCat Topology
namespace AlgebraicGeometry
variable (X : Scheme)
instance : T0Space X :=
T0Space.of_open_cover fun x => ⟨_, X.affineCover.covers x,
(X.affineCover.map x).opensRange.2, IsEmbedding.t0Space (Y := PrimeSpectrum _)
(isAffineOpen_opensRange (X.affineCover.map x)).isoSpec.schemeIsoToHomeo.isEmbedding⟩
instance : QuasiSober X := by
apply (config := { allowSynthFailures := true })
quasiSober_of_open_cover (Set.range fun x => Set.range <| (X.affineCover.map x).base)
· rintro ⟨_, i, rfl⟩; exact (X.affineCover.map_prop i).base_open.isOpen_range
· rintro ⟨_, i, rfl⟩
exact @IsOpenEmbedding.quasiSober _ _ _ _ _
(X.affineCover.map_prop i).base_open.isEmbedding.toHomeomorph.symm.isOpenEmbedding
PrimeSpectrum.quasiSober
· rw [Set.top_eq_univ, Set.sUnion_range, Set.eq_univ_iff_forall]
intro x; exact ⟨_, ⟨_, rfl⟩, X.affineCover.covers x⟩
instance {X : Scheme.{u}} : PrespectralSpace X :=
have (Y : Scheme.{u}) (_ : IsAffine Y) : PrespectralSpace Y :=
.of_isClosedEmbedding (Y := PrimeSpectrum _) _
Y.isoSpec.hom.homeomorph.isClosedEmbedding
have (i) : PrespectralSpace (X.affineCover.map i).opensRange.1 :=
this (X.affineCover.map i).opensRange (isAffineOpen_opensRange (X.affineCover.map i))
.of_isOpenCover X.affineCover.isOpenCover_opensRange
/-- A scheme `X` is reduced if all `𝒪ₓ(U)` are reduced. -/
class IsReduced : Prop where
component_reduced : ∀ U, _root_.IsReduced Γ(X, U) := by infer_instance
attribute [instance] IsReduced.component_reduced
theorem isReduced_of_isReduced_stalk [∀ x : X, _root_.IsReduced (X.presheaf.stalk x)] :
IsReduced X := by
refine ⟨fun U => ⟨fun s hs => ?_⟩⟩
apply Presheaf.section_ext X.sheaf U s 0
intro x hx
show (X.sheaf.presheaf.germ U x hx) s = (X.sheaf.presheaf.germ U x hx) 0
rw [RingHom.map_zero]
change X.presheaf.germ U x hx s = 0
exact (hs.map _).eq_zero
instance isReduced_stalk_of_isReduced [IsReduced X] (x : X) :
_root_.IsReduced (X.presheaf.stalk x) := by
constructor
rintro g ⟨n, e⟩
obtain ⟨U, hxU, s, (rfl : (X.presheaf.germ U x hxU) s = g)⟩ := X.presheaf.germ_exist x g
rw [← map_pow, ← map_zero (X.presheaf.germ _ x hxU).hom] at e
obtain ⟨V, hxV, iU, iV, (e' : (X.presheaf.map iU.op) (s ^ n) = (X.presheaf.map iV.op) 0)⟩ :=
X.presheaf.germ_eq x hxU hxU _ 0 e
rw [map_pow, map_zero] at e'
replace e' := (IsNilpotent.mk _ _ e').eq_zero (R := Γ(X, V))
rw [← X.presheaf.germ_res iU x hxV, CommRingCat.comp_apply, e', map_zero]
theorem isReduced_of_isOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f]
[IsReduced Y] : IsReduced X := by
constructor
intro U
have : U = f ⁻¹ᵁ f ''ᵁ U := by
ext1; exact (Set.preimage_image_eq _ H.base_open.injective).symm
rw [this]
exact isReduced_of_injective (inv <| f.app (f ''ᵁ U)).hom
(asIso <| f.app (f ''ᵁ U) : Γ(Y, f ''ᵁ U) ≅ _).symm.commRingCatIsoToRingEquiv.injective
instance {R : CommRingCat.{u}} [H : _root_.IsReduced R] : IsReduced (Spec R) := by
apply (config := { allowSynthFailures := true }) isReduced_of_isReduced_stalk
intro x; dsimp
have : _root_.IsReduced (CommRingCat.of <| Localization.AtPrime (PrimeSpectrum.asIdeal x)) := by
dsimp; infer_instance
exact isReduced_of_injective (StructureSheaf.stalkIso R x).hom.hom
(StructureSheaf.stalkIso R x).commRingCatIsoToRingEquiv.injective
theorem affine_isReduced_iff (R : CommRingCat) :
IsReduced (Spec R) ↔ _root_.IsReduced R := by
refine ⟨?_, fun h => inferInstance⟩
intro h
exact isReduced_of_injective (Scheme.ΓSpecIso R).inv.hom
(Scheme.ΓSpecIso R).symm.commRingCatIsoToRingEquiv.injective
theorem isReduced_of_isAffine_isReduced [IsAffine X] [_root_.IsReduced Γ(X, ⊤)] :
IsReduced X :=
isReduced_of_isOpenImmersion X.isoSpec.hom
/-- To show that a statement `P` holds for all open subsets of all schemes, it suffices to show that
1. In any scheme `X`, if `P` holds for an open cover of `U`, then `P` holds for `U`.
2. For an open immerison `f : X ⟶ Y`, if `P` holds for the entire space of `X`, then `P` holds for
the image of `f`.
3. `P` holds for the entire space of an affine scheme.
-/
@[elab_as_elim]
theorem reduce_to_affine_global (P : ∀ {X : Scheme} (_ : X.Opens), Prop)
{X : Scheme} (U : X.Opens)
(h₁ : ∀ (X : Scheme) (U : X.Opens),
(∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (_ : V ⟶ U), P V) → P U)
(h₂ : ∀ (X Y) (f : X ⟶ Y) [IsOpenImmersion f],
∃ (U : X.Opens) (V : Y.Opens), U = ⊤ ∧ V = f.opensRange ∧ (P U → P V))
(h₃ : ∀ R : CommRingCat, P (X := Spec R) ⊤) : P U := by
apply h₁
intro x
obtain ⟨_, ⟨j, rfl⟩, hx, i⟩ :=
X.affineBasisCover_is_basis.exists_subset_of_mem_open (SetLike.mem_coe.2 x.prop) U.isOpen
let U' : Opens _ := ⟨_, (X.affineBasisCover.map_prop j).base_open.isOpen_range⟩
let i' : U' ⟶ U := homOfLE i
refine ⟨U', hx, i', ?_⟩
obtain ⟨_, _, rfl, rfl, h₂'⟩ := h₂ _ _ (X.affineBasisCover.map j)
apply h₂'
apply h₃
theorem reduce_to_affine_nbhd (P : ∀ (X : Scheme) (_ : X), Prop)
(h₁ : ∀ R x, P (Spec R) x)
(h₂ : ∀ {X Y} (f : X ⟶ Y) [IsOpenImmersion f] (x : X), P X x → P Y (f.base x)) :
∀ (X : Scheme) (x : X), P X x := by
intro X x
obtain ⟨y, e⟩ := X.affineCover.covers x
convert h₂ (X.affineCover.map (X.affineCover.f x)) y _
· rw [e]
apply h₁
theorem eq_zero_of_basicOpen_eq_bot {X : Scheme} [hX : IsReduced X] {U : X.Opens}
(s : Γ(X, U)) (hs : X.basicOpen s = ⊥) : s = 0 := by
apply TopCat.Presheaf.section_ext X.sheaf U
intro x hx
show (X.sheaf.presheaf.germ U x hx) s = (X.sheaf.presheaf.germ U x hx) 0
rw [RingHom.map_zero]
induction U using reduce_to_affine_global generalizing hX with
| h₁ X U H =>
obtain ⟨V, hx, i, H⟩ := H ⟨x, hx⟩
specialize H (X.presheaf.map i.op s)
rw [Scheme.basicOpen_res, hs] at H
specialize H (inf_bot_eq _) x hx
rw [← X.sheaf.presheaf.germ_res_apply i x hx s]
exact H
| h₂ X Y f =>
refine ⟨f ⁻¹ᵁ f.opensRange, f.opensRange, by ext1; simp, rfl, ?_⟩
rintro H hX s hs _ ⟨x, rfl⟩
haveI := isReduced_of_isOpenImmersion f
specialize H (f.app _ s) _ x ⟨x, rfl⟩
· rw [← Scheme.preimage_basicOpen, hs]; ext1; simp [Opens.map]
· have H : (X.presheaf.germ _ x _).hom _ = 0 := H
rw [← Scheme.stalkMap_germ_apply f ⟨_, _⟩ x] at H
apply_fun inv <| f.stalkMap x at H
rw [← CommRingCat.comp_apply, CategoryTheory.IsIso.hom_inv_id, map_zero] at H
exact H
| h₃ R =>
rw [basicOpen_eq_of_affine', PrimeSpectrum.basicOpen_eq_bot_iff] at hs
replace hs := (hs.map (Scheme.ΓSpecIso R).inv.hom).eq_zero
rw [← CommRingCat.comp_apply, Iso.hom_inv_id, CommRingCat.id_apply] at hs
rw [hs, map_zero]
@[simp]
theorem basicOpen_eq_bot_iff {X : Scheme} [IsReduced X] {U : X.Opens}
(s : Γ(X, U)) : X.basicOpen s = ⊥ ↔ s = 0 := by
refine ⟨eq_zero_of_basicOpen_eq_bot s, ?_⟩
rintro rfl
simp
/-- A scheme `X` is integral if its is nonempty,
and `𝒪ₓ(U)` is an integral domain for each `U ≠ ∅`. -/
class IsIntegral : Prop where
nonempty : Nonempty X := by infer_instance
component_integral : ∀ (U : X.Opens) [Nonempty U], IsDomain Γ(X, U) := by infer_instance
attribute [instance] IsIntegral.component_integral IsIntegral.nonempty
instance [IsIntegral X] : IsDomain Γ(X, ⊤) :=
@IsIntegral.component_integral _ _ _ ⟨Nonempty.some inferInstance, trivial⟩
instance (priority := 900) isReduced_of_isIntegral [IsIntegral X] : IsReduced X := by
constructor
intro U
rcases U.1.eq_empty_or_nonempty with h | h
· have : U = ⊥ := SetLike.ext' h
haveI : Subsingleton Γ(X, U) :=
CommRingCat.subsingleton_of_isTerminal (X.sheaf.isTerminalOfEqEmpty this)
infer_instance
· haveI : Nonempty U := by simpa
infer_instance
instance Scheme.component_nontrivial (X : Scheme.{u}) (U : X.Opens) [Nonempty U] :
Nontrivial Γ(X, U) :=
LocallyRingedSpace.component_nontrivial (hU := ‹_›)
instance irreducibleSpace_of_isIntegral [IsIntegral X] : IrreducibleSpace X := by
by_contra H
replace H : ¬IsPreirreducible (⊤ : Set X) := fun h =>
H { toPreirreducibleSpace := ⟨h⟩
toNonempty := inferInstance }
simp_rw [isPreirreducible_iff_isClosed_union_isClosed, not_forall, not_or] at H
rcases H with ⟨S, T, hS, hT, h₁, h₂, h₃⟩
rw [Set.not_top_subset] at h₂ h₃
haveI : Nonempty (⟨Sᶜ, hS.1⟩ : X.Opens) := ⟨⟨_, h₂.choose_spec⟩⟩
haveI : Nonempty (⟨Tᶜ, hT.1⟩ : X.Opens) := ⟨⟨_, h₃.choose_spec⟩⟩
haveI : Nonempty (⟨Sᶜ, hS.1⟩ ⊔ ⟨Tᶜ, hT.1⟩ : X.Opens) := ⟨⟨_, Or.inl h₂.choose_spec⟩⟩
let e : Γ(X, _) ≅ CommRingCat.of _ :=
(X.sheaf.isProductOfDisjoint ⟨_, hS.1⟩ ⟨_, hT.1⟩ ?_).conePointUniqueUpToIso
(CommRingCat.prodFanIsLimit _ _)
· have : IsDomain (Γ(X, ⟨Sᶜ, hS.1⟩) × Γ(X, ⟨Tᶜ, hT.1⟩)) :=
e.symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
exact false_of_nontrivial_of_product_domain Γ(X, ⟨Sᶜ, hS.1⟩) Γ(X, ⟨Tᶜ, hT.1⟩)
· ext x
constructor
· rintro ⟨hS, hT⟩
rcases h₁ (show x ∈ ⊤ by trivial) with h | h
exacts [hS h, hT h]
· simp
theorem isIntegral_of_irreducibleSpace_of_isReduced [IsReduced X] [H : IrreducibleSpace X] :
IsIntegral X := by
constructor; · infer_instance
intro U hU
haveI := (@LocallyRingedSpace.component_nontrivial X.toLocallyRingedSpace U hU).1
have : NoZeroDivisors
(X.toLocallyRingedSpace.toSheafedSpace.toPresheafedSpace.presheaf.obj (op U)) := by
refine ⟨fun {a b} e => ?_⟩
simp_rw [← basicOpen_eq_bot_iff, ← Opens.not_nonempty_iff_eq_bot]
by_contra! h
obtain ⟨x, ⟨hxU, hx₁⟩, _, hx₂⟩ :=
nonempty_preirreducible_inter (X.basicOpen a).2 (X.basicOpen b).2 h.1 h.2
replace e := congr_arg (X.presheaf.germ U x hxU) e
rw [RingHom.map_mul, RingHom.map_zero] at e
refine zero_ne_one' (X.presheaf.stalk x) (isUnit_zero_iff.1 ?_)
convert hx₁.mul hx₂
exact e.symm
exact NoZeroDivisors.to_isDomain _
theorem isIntegral_iff_irreducibleSpace_and_isReduced :
IsIntegral X ↔ IrreducibleSpace X ∧ IsReduced X :=
⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ =>
isIntegral_of_irreducibleSpace_of_isReduced X⟩
theorem isIntegral_of_isOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f]
[IsIntegral Y] [Nonempty X] : IsIntegral X := by
constructor; · infer_instance
intro U hU
have : U = f ⁻¹ᵁ f ''ᵁ U := by ext1; exact (Set.preimage_image_eq _ H.base_open.injective).symm
rw [this]
have : IsDomain Γ(Y, f ''ᵁ U) := by
apply (config := { allowSynthFailures := true }) IsIntegral.component_integral
exact ⟨⟨_, _, hU.some.prop, rfl⟩⟩
exact (asIso <| f.app (f ''ᵁ U) :
Γ(Y, f ''ᵁ U) ≅ _).symm.commRingCatIsoToRingEquiv.toMulEquiv.isDomain _
instance {R : CommRingCat} [IsDomain R] : IrreducibleSpace (Spec R) := by
convert PrimeSpectrum.irreducibleSpace (R := R)
instance {R : CommRingCat} [IsDomain R] : IsIntegral (Spec R) :=
isIntegral_of_irreducibleSpace_of_isReduced _
theorem affine_isIntegral_iff (R : CommRingCat) :
IsIntegral (Spec R) ↔ IsDomain R :=
⟨fun _ => MulEquiv.isDomain Γ(Spec R, ⊤)
(Scheme.ΓSpecIso R).symm.commRingCatIsoToRingEquiv.toMulEquiv, fun _ => inferInstance⟩
theorem isIntegral_of_isAffine_of_isDomain [IsAffine X] [Nonempty X] [IsDomain Γ(X, ⊤)] :
IsIntegral X :=
isIntegral_of_isOpenImmersion X.isoSpec.hom
theorem map_injective_of_isIntegral [IsIntegral X] {U V : X.Opens} (i : U ⟶ V)
[H : Nonempty U] : Function.Injective (X.presheaf.map i.op) := by
rw [injective_iff_map_eq_zero]
intro x hx
rw [← basicOpen_eq_bot_iff] at hx ⊢
rw [Scheme.basicOpen_res] at hx
revert hx
contrapose!
simp_rw [Ne, ← Opens.not_nonempty_iff_eq_bot, Classical.not_not]
apply nonempty_preirreducible_inter U.isOpen (RingedSpace.basicOpen _ _).isOpen
simpa using H
end AlgebraicGeometry
| Mathlib/AlgebraicGeometry/Properties.lean | 307 | 317 | |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.List.TakeDrop
import Mathlib.Data.List.Induction
/-!
# Prefixes, suffixes, infixes
This file proves properties about
* `List.isPrefix`: `l₁` is a prefix of `l₂` if `l₂` starts with `l₁`.
* `List.isSuffix`: `l₁` is a suffix of `l₂` if `l₂` ends with `l₁`.
* `List.isInfix`: `l₁` is an infix of `l₂` if `l₁` is a prefix of some suffix of `l₂`.
* `List.inits`: The list of prefixes of a list.
* `List.tails`: The list of prefixes of a list.
* `insert` on lists
All those (except `insert`) are defined in `Mathlib.Data.List.Defs`.
## Notation
* `l₁ <+: l₂`: `l₁` is a prefix of `l₂`.
* `l₁ <:+ l₂`: `l₁` is a suffix of `l₂`.
* `l₁ <:+: l₂`: `l₁` is an infix of `l₂`.
-/
variable {α β : Type*}
namespace List
variable {l l₁ l₂ l₃ : List α} {a b : α}
/-! ### prefix, suffix, infix -/
section Fix
@[gcongr] lemma IsPrefix.take (h : l₁ <+: l₂) (n : ℕ) : l₁.take n <+: l₂.take n := by
simpa [prefix_take_iff, Nat.min_le_left] using (take_prefix n l₁).trans h
@[gcongr] lemma IsPrefix.drop (h : l₁ <+: l₂) (n : ℕ) : l₁.drop n <+: l₂.drop n := by
rw [prefix_iff_eq_take.mp h, drop_take]; apply take_prefix
attribute [gcongr] take_prefix_take_left
lemma isPrefix_append_of_length (h : l₁.length ≤ l₂.length) : l₁ <+: l₂ ++ l₃ ↔ l₁ <+: l₂ :=
⟨fun h ↦ by rw [prefix_iff_eq_take] at *; nth_rw 1 [h, take_eq_left_iff]; tauto,
fun h ↦ h.trans <| l₂.prefix_append l₃⟩
@[simp] lemma take_isPrefix_take {m n : ℕ} : l.take m <+: l.take n ↔ m ≤ n ∨ l.length ≤ n := by
simp [prefix_take_iff, take_prefix]; omega
@[gcongr]
protected theorem IsPrefix.flatten {l₁ l₂ : List (List α)} (h : l₁ <+: l₂) :
l₁.flatten <+: l₂.flatten := by
rcases h with ⟨l, rfl⟩
simp
@[gcongr]
protected theorem IsPrefix.flatMap (h : l₁ <+: l₂) (f : α → List β) :
l₁.flatMap f <+: l₂.flatMap f :=
(h.map _).flatten
@[gcongr]
protected theorem IsSuffix.flatten {l₁ l₂ : List (List α)} (h : l₁ <:+ l₂) :
l₁.flatten <:+ l₂.flatten := by
rcases h with ⟨l, rfl⟩
simp
@[gcongr]
protected theorem IsSuffix.flatMap (h : l₁ <:+ l₂) (f : α → List β) :
l₁.flatMap f <:+ l₂.flatMap f :=
(h.map _).flatten
@[gcongr]
protected theorem IsInfix.flatten {l₁ l₂ : List (List α)} (h : l₁ <:+: l₂) :
l₁.flatten <:+: l₂.flatten := by
rcases h with ⟨l, l', rfl⟩
simp
@[gcongr]
protected theorem IsInfix.flatMap (h : l₁ <:+: l₂) (f : α → List β) :
l₁.flatMap f <:+: l₂.flatMap f :=
(h.map _).flatten
lemma dropSlice_sublist (n m : ℕ) (l : List α) : l.dropSlice n m <+ l :=
calc
l.dropSlice n m = take n l ++ drop m (drop n l) := by rw [dropSlice_eq, drop_drop, Nat.add_comm]
_ <+ take n l ++ drop n l := (Sublist.refl _).append (drop_sublist _ _)
_ = _ := take_append_drop _ _
lemma dropSlice_subset (n m : ℕ) (l : List α) : l.dropSlice n m ⊆ l :=
(dropSlice_sublist n m l).subset
lemma mem_of_mem_dropSlice {n m : ℕ} {l : List α} {a : α} (h : a ∈ l.dropSlice n m) : a ∈ l :=
dropSlice_subset n m l h
theorem tail_subset (l : List α) : tail l ⊆ l :=
(tail_sublist l).subset
theorem mem_of_mem_dropLast (h : a ∈ l.dropLast) : a ∈ l :=
dropLast_subset l h
attribute [gcongr] Sublist.drop
attribute [refl] prefix_refl suffix_refl infix_refl
theorem concat_get_prefix {x y : List α} (h : x <+: y) (hl : x.length < y.length) :
x ++ [y.get ⟨x.length, hl⟩] <+: y := by
use y.drop (x.length + 1)
nth_rw 1 [List.prefix_iff_eq_take.mp h]
convert List.take_append_drop (x.length + 1) y using 2
rw [← List.take_concat_get, List.concat_eq_append]; rfl
instance decidableInfix [DecidableEq α] : ∀ l₁ l₂ : List α, Decidable (l₁ <:+: l₂)
| [], l₂ => isTrue ⟨[], l₂, rfl⟩
| a :: l₁, [] => isFalse fun ⟨s, t, te⟩ => by simp at te
| l₁, b :: l₂ =>
letI := l₁.decidableInfix l₂
@decidable_of_decidable_of_iff (l₁ <+: b :: l₂ ∨ l₁ <:+: l₂) _ _
infix_cons_iff.symm
protected theorem IsPrefix.reduceOption {l₁ l₂ : List (Option α)} (h : l₁ <+: l₂) :
l₁.reduceOption <+: l₂.reduceOption :=
h.filterMap id
instance : IsPartialOrder (List α) (· <+: ·) where
refl _ := prefix_rfl
trans _ _ _ := IsPrefix.trans
antisymm _ _ h₁ h₂ := h₁.eq_of_length <| h₁.length_le.antisymm h₂.length_le
instance : IsPartialOrder (List α) (· <:+ ·) where
refl _ := suffix_rfl
trans _ _ _ := IsSuffix.trans
antisymm _ _ h₁ h₂ := h₁.eq_of_length <| h₁.length_le.antisymm h₂.length_le
instance : IsPartialOrder (List α) (· <:+: ·) where
refl _ := infix_rfl
trans _ _ _ := IsInfix.trans
antisymm _ _ h₁ h₂ := h₁.eq_of_length <| h₁.length_le.antisymm h₂.length_le
end Fix
section InitsTails
@[simp]
theorem mem_inits : ∀ s t : List α, s ∈ inits t ↔ s <+: t
| s, [] =>
suffices s = nil ↔ s <+: nil by simpa only [inits, mem_singleton]
⟨fun h => h.symm ▸ prefix_rfl, eq_nil_of_prefix_nil⟩
| s, a :: t =>
suffices (s = nil ∨ ∃ l ∈ inits t, a :: l = s) ↔ s <+: a :: t by simpa
⟨fun o =>
match s, o with
| _, Or.inl rfl => ⟨_, rfl⟩
| s, Or.inr ⟨r, hr, hs⟩ => by
let ⟨s, ht⟩ := (mem_inits _ _).1 hr
rw [← hs, ← ht]; exact ⟨s, rfl⟩,
fun mi =>
match s, mi with
| [], ⟨_, rfl⟩ => Or.inl rfl
| b :: s, ⟨r, hr⟩ =>
(List.noConfusion hr) fun ba (st : s ++ r = t) =>
Or.inr <| by rw [ba]; exact ⟨_, (mem_inits _ _).2 ⟨_, st⟩, rfl⟩⟩
@[simp]
theorem mem_tails : ∀ s t : List α, s ∈ tails t ↔ s <:+ t
| s, [] => by
simp only [tails, mem_singleton, suffix_nil]
| s, a :: t => by
simp only [tails, mem_cons, mem_tails s t]
exact
show s = a :: t ∨ s <:+ t ↔ s <:+ a :: t from
⟨fun o =>
match s, t, o with
| _, t, Or.inl rfl => suffix_rfl
| s, _, Or.inr ⟨l, rfl⟩ => ⟨a :: l, rfl⟩,
fun e =>
match s, t, e with
| _, t, ⟨[], rfl⟩ => Or.inl rfl
| s, t, ⟨b :: l, he⟩ => List.noConfusion he fun _ lt => Or.inr ⟨l, lt⟩⟩
theorem inits_cons (a : α) (l : List α) : inits (a :: l) = [] :: l.inits.map fun t => a :: t := by
simp
theorem tails_cons (a : α) (l : List α) : tails (a :: l) = (a :: l) :: l.tails := by simp
@[simp]
theorem inits_append : ∀ s t : List α, inits (s ++ t) = s.inits ++ t.inits.tail.map fun l => s ++ l
| [], [] => by simp
| [], a :: t => by simp
| a :: s, t => by simp [inits_append s t, Function.comp_def]
@[simp]
theorem tails_append :
∀ s t : List α, tails (s ++ t) = (s.tails.map fun l => l ++ t) ++ t.tails.tail
| [], [] => by simp
| [], a :: t => by simp
| a :: s, t => by simp [tails_append s t]
-- the lemma names `inits_eq_tails` and `tails_eq_inits` are like `sublists_eq_sublists'`
theorem inits_eq_tails : ∀ l : List α, l.inits = (reverse <| map reverse <| tails <| reverse l)
| [] => by simp
| a :: l => by simp [inits_eq_tails l, map_inj_left, ← map_reverse]
theorem tails_eq_inits : ∀ l : List α, l.tails = (reverse <| map reverse <| inits <| reverse l)
| [] => by simp
| a :: l => by simp [tails_eq_inits l, append_left_inj]
theorem inits_reverse (l : List α) : inits (reverse l) = reverse (map reverse l.tails) := by
rw [tails_eq_inits l]
simp [reverse_involutive.comp_self, ← map_reverse]
theorem tails_reverse (l : List α) : tails (reverse l) = reverse (map reverse l.inits) := by
rw [inits_eq_tails l]
simp [reverse_involutive.comp_self, ← map_reverse]
theorem map_reverse_inits (l : List α) : map reverse l.inits = (reverse <| tails <| reverse l) := by
rw [inits_eq_tails l]
simp [reverse_involutive.comp_self, ← map_reverse]
theorem map_reverse_tails (l : List α) : map reverse l.tails = (reverse <| inits <| reverse l) := by
rw [tails_eq_inits l]
simp [reverse_involutive.comp_self, ← map_reverse]
@[simp]
theorem length_tails (l : List α) : length (tails l) = length l + 1 := by
induction' l with x l IH
· simp
· simpa using IH
@[simp]
theorem length_inits (l : List α) : length (inits l) = length l + 1 := by simp [inits_eq_tails]
@[simp]
theorem getElem_tails (l : List α) (n : Nat) (h : n < (tails l).length) :
(tails l)[n] = l.drop n := by
induction l generalizing n with
| nil => simp
| cons a l ihl =>
cases n with
| zero => simp
| succ n => simp [ihl]
theorem get_tails (l : List α) (n : Fin (length (tails l))) : (tails l).get n = l.drop n := by
simp
@[simp]
theorem getElem_inits (l : List α) (n : Nat) (h : n < length (inits l)) :
(inits l)[n] = l.take n := by
induction l generalizing n with
| nil => simp
| cons a l ihl =>
cases n with
| zero => simp
| succ n => simp [ihl]
theorem get_inits (l : List α) (n : Fin (length (inits l))) : (inits l).get n = l.take n := by
simp
lemma map_inits {β : Type*} (g : α → β) : (l.map g).inits = l.inits.map (map g) := by
induction' l using reverseRecOn <;> simp [*]
lemma map_tails {β : Type*} (g : α → β) : (l.map g).tails = l.tails.map (map g) := by
induction' l using reverseRecOn <;> simp [*]
lemma take_inits {n} : (l.take n).inits = l.inits.take (n + 1) := by
apply ext_getElem <;> (simp [take_take] <;> omega)
end InitsTails
/-! ### insert -/
section Insert
variable [DecidableEq α]
theorem insert_eq_ite (a : α) (l : List α) : insert a l = if a ∈ l then l else a :: l := by
simp only [← elem_iff]
rfl
@[simp]
theorem suffix_insert (a : α) (l : List α) : l <:+ l.insert a := by
by_cases h : a ∈ l
· simp only [insert_of_mem h, insert, suffix_refl]
· simp only [insert_of_not_mem h, suffix_cons, insert]
theorem infix_insert (a : α) (l : List α) : l <:+: l.insert a :=
(suffix_insert a l).isInfix
theorem sublist_insert (a : α) (l : List α) : l <+ l.insert a :=
(suffix_insert a l).sublist
theorem subset_insert (a : α) (l : List α) : l ⊆ l.insert a :=
(sublist_insert a l).subset
end Insert
end List
| Mathlib/Data/List/Infix.lean | 514 | 516 | |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau
-/
import Mathlib.Data.List.Forall2
/-!
# zip & unzip
This file provides results about `List.zipWith`, `List.zip` and `List.unzip` (definitions are in
core Lean).
`zipWith f l₁ l₂` applies `f : α → β → γ` pointwise to a list `l₁ : List α` and `l₂ : List β`. It
applies, until one of the lists is exhausted. For example,
`zipWith f [0, 1, 2] [6.28, 31] = [f 0 6.28, f 1 31]`.
`zip` is `zipWith` applied to `Prod.mk`. For example,
`zip [a₁, a₂] [b₁, b₂, b₃] = [(a₁, b₁), (a₂, b₂)]`.
`unzip` undoes `zip`. For example, `unzip [(a₁, b₁), (a₂, b₂)] = ([a₁, a₂], [b₁, b₂])`.
-/
-- Make sure we don't import algebra
assert_not_exists Monoid
universe u
open Nat
namespace List
variable {α : Type u} {β γ δ ε : Type*}
@[simp]
theorem zip_swap : ∀ (l₁ : List α) (l₂ : List β), (zip l₁ l₂).map Prod.swap = zip l₂ l₁
| [], _ => zip_nil_right.symm
| l₁, [] => by rw [zip_nil_right]; rfl
| a :: l₁, b :: l₂ => by
simp only [zip_cons_cons, map_cons, zip_swap l₁ l₂, Prod.swap_prod_mk]
theorem forall_zipWith {f : α → β → γ} {p : γ → Prop} :
∀ {l₁ : List α} {l₂ : List β}, length l₁ = length l₂ →
(Forall p (zipWith f l₁ l₂) ↔ Forall₂ (fun x y => p (f x y)) l₁ l₂)
| [], [], _ => by simp
| a :: l₁, b :: l₂, h => by
simp only [length_cons, succ_inj] at h
simp [forall_zipWith h]
theorem unzip_swap (l : List (α × β)) : unzip (l.map Prod.swap) = (unzip l).swap := by
simp only [unzip_eq_map, map_map]
rfl
@[congr]
theorem zipWith_congr (f g : α → β → γ) (la : List α) (lb : List β)
(h : List.Forall₂ (fun a b => f a b = g a b) la lb) : zipWith f la lb = zipWith g la lb := by
induction h with
| nil => rfl
| cons hfg _ ih => exact congr_arg₂ _ hfg ih
theorem zipWith_zipWith_left (f : δ → γ → ε) (g : α → β → δ) :
∀ (la : List α) (lb : List β) (lc : List γ),
zipWith f (zipWith g la lb) lc = zipWith3 (fun a b c => f (g a b) c) la lb lc
| [], _, _ => rfl
| _ :: _, [], _ => rfl
| _ :: _, _ :: _, [] => rfl
| _ :: as, _ :: bs, _ :: cs => congr_arg (cons _) <| zipWith_zipWith_left f g as bs cs
theorem zipWith_zipWith_right (f : α → δ → ε) (g : β → γ → δ) :
∀ (la : List α) (lb : List β) (lc : List γ),
zipWith f la (zipWith g lb lc) = zipWith3 (fun a b c => f a (g b c)) la lb lc
| [], _, _ => rfl
| _ :: _, [], _ => rfl
| _ :: _, _ :: _, [] => rfl
| _ :: as, _ :: bs, _ :: cs => congr_arg (cons _) <| zipWith_zipWith_right f g as bs cs
@[simp]
theorem zipWith3_same_left (f : α → α → β → γ) :
∀ (la : List α) (lb : List β), zipWith3 f la la lb = zipWith (fun a b => f a a b) la lb
| [], _ => rfl
| _ :: _, [] => rfl
| _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_left f as bs
@[simp]
theorem zipWith3_same_mid (f : α → β → α → γ) :
∀ (la : List α) (lb : List β), zipWith3 f la lb la = zipWith (fun a b => f a b a) la lb
| [], _ => rfl
| _ :: _, [] => rfl
| _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_mid f as bs
@[simp]
theorem zipWith3_same_right (f : α → β → β → γ) :
∀ (la : List α) (lb : List β), zipWith3 f la lb lb = zipWith (fun a b => f a b b) la lb
| [], _ => rfl
| _ :: _, [] => rfl
| _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_right f as bs
instance (f : α → α → β) [IsSymmOp f] : IsSymmOp (zipWith f) :=
⟨fun _ _ => zipWith_comm_of_comm IsSymmOp.symm_op⟩
@[simp]
theorem length_revzip (l : List α) : length (revzip l) = length l := by
simp only [revzip, length_zip, length_reverse, min_self]
@[simp]
theorem unzip_revzip (l : List α) : (revzip l).unzip = (l, l.reverse) :=
unzip_zip length_reverse.symm
@[simp]
theorem revzip_map_fst (l : List α) : (revzip l).map Prod.fst = l := by
rw [← unzip_fst, unzip_revzip]
@[simp]
theorem revzip_map_snd (l : List α) : (revzip l).map Prod.snd = l.reverse := by
rw [← unzip_snd, unzip_revzip]
theorem reverse_revzip (l : List α) : reverse l.revzip = revzip l.reverse := by
rw [← zip_unzip (revzip l).reverse]
simp [unzip_eq_map, revzip, map_reverse, map_fst_zip, map_snd_zip]
theorem revzip_swap (l : List α) : (revzip l).map Prod.swap = revzip l.reverse := by simp [revzip]
@[deprecated (since := "2025-02-14")] alias get?_zipWith' := getElem?_zipWith'
@[deprecated (since := "2025-02-14")] alias get?_zipWith_eq_some := getElem?_zipWith_eq_some
@[deprecated (since := "2025-02-14")] alias get?_zip_eq_some := getElem?_zip_eq_some
theorem mem_zip_inits_tails {l : List α} {init tail : List α} :
(init, tail) ∈ zip l.inits l.tails ↔ init ++ tail = l := by
induction' l with hd tl ih generalizing init tail <;> simp_rw [tails, inits, zip_cons_cons]
· simp
· constructor <;> rw [mem_cons, zip_map_left, mem_map, Prod.exists]
· rintro (⟨rfl, rfl⟩ | ⟨_, _, h, rfl, rfl⟩)
· simp
· simp [ih.mp h]
· rcases init with - | ⟨hd', tl'⟩
· rintro rfl
simp
· intro h
right
use tl', tail
simp_all
end List
| Mathlib/Data/List/Zip.lean | 143 | 145 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Div
import Mathlib.RingTheory.Coprime.Basic
/-!
# Theory of univariate polynomials
We prove basic results about univariate polynomials.
-/
assert_not_exists Ideal.map
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] {p q : R[X]}
section
variable [Semiring S]
theorem natDegree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S}
(hz : aeval z p = 0) (inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.natDegree :=
natDegree_pos_of_eval₂_root hp (algebraMap R S) hz inj
theorem degree_pos_of_aeval_root [Algebra R S] {p : R[X]} (hp : p ≠ 0) {z : S} (hz : aeval z p = 0)
(inj : ∀ x : R, algebraMap R S x = 0 → x = 0) : 0 < p.degree :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_aeval_root hp hz inj)
end
theorem smul_modByMonic (c : R) (p : R[X]) : c • p %ₘ q = c • (p %ₘ q) := by
by_cases hq : q.Monic
· rcases subsingleton_or_nontrivial R with hR | hR
· simp only [eq_iff_true_of_subsingleton]
· exact
(div_modByMonic_unique (c • (p /ₘ q)) (c • (p %ₘ q)) hq
⟨by rw [mul_smul_comm, ← smul_add, modByMonic_add_div p hq],
(degree_smul_le _ _).trans_lt (degree_modByMonic_lt _ hq)⟩).2
· simp_rw [modByMonic_eq_of_not_monic _ hq]
/-- `_ %ₘ q` as an `R`-linear map. -/
@[simps]
def modByMonicHom (q : R[X]) : R[X] →ₗ[R] R[X] where
toFun p := p %ₘ q
map_add' := add_modByMonic
map_smul' := smul_modByMonic
theorem mem_ker_modByMonic (hq : q.Monic) {p : R[X]} :
p ∈ LinearMap.ker (modByMonicHom q) ↔ q ∣ p :=
LinearMap.mem_ker.trans (modByMonic_eq_zero_iff_dvd hq)
section
variable [Ring S]
theorem aeval_modByMonic_eq_self_of_root [Algebra R S] {p q : R[X]} (hq : q.Monic) {x : S}
(hx : aeval x q = 0) : aeval x (p %ₘ q) = aeval x p := by
--`eval₂_modByMonic_eq_self_of_root` doesn't work here as it needs commutativity
rw [modByMonic_eq_sub_mul_div p hq, map_sub, map_mul, hx, zero_mul,
sub_zero]
end
end CommRing
section NoZeroDivisors
variable [Semiring R] [NoZeroDivisors R] {p q : R[X]}
theorem trailingDegree_mul : (p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by
by_cases hp : p = 0
· rw [hp, zero_mul, trailingDegree_zero, top_add]
by_cases hq : q = 0
· rw [hq, mul_zero, trailingDegree_zero, add_top]
· rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq,
trailingDegree_eq_natTrailingDegree (mul_ne_zero hp hq), natTrailingDegree_mul hp hq]
apply WithTop.coe_add
end NoZeroDivisors
section CommRing
variable [CommRing R]
theorem rootMultiplicity_eq_rootMultiplicity {p : R[X]} {t : R} :
p.rootMultiplicity t = (p.comp (X + C t)).rootMultiplicity 0 := by
classical
simp_rw [rootMultiplicity_eq_multiplicity, comp_X_add_C_eq_zero_iff]
congr 1
rw [C_0, sub_zero]
convert (multiplicity_map_eq <| algEquivAevalXAddC t).symm using 2
simp [C_eq_algebraMap]
/-- See `Polynomial.rootMultiplicity_eq_natTrailingDegree'` for the special case of `t = 0`. -/
theorem rootMultiplicity_eq_natTrailingDegree {p : R[X]} {t : R} :
p.rootMultiplicity t = (p.comp (X + C t)).natTrailingDegree :=
rootMultiplicity_eq_rootMultiplicity.trans rootMultiplicity_eq_natTrailingDegree'
section nonZeroDivisors
open scoped nonZeroDivisors
theorem Monic.mem_nonZeroDivisors {p : R[X]} (h : p.Monic) : p ∈ R[X]⁰ :=
mem_nonzeroDivisors_of_coeff_mem _ (h.coeff_natDegree ▸ one_mem R⁰)
theorem mem_nonZeroDivisors_of_leadingCoeff {p : R[X]} (h : p.leadingCoeff ∈ R⁰) : p ∈ R[X]⁰ :=
mem_nonzeroDivisors_of_coeff_mem _ h
theorem mem_nonZeroDivisors_of_trailingCoeff {p : R[X]} (h : p.trailingCoeff ∈ R⁰) : p ∈ R[X]⁰ :=
mem_nonzeroDivisors_of_coeff_mem _ h
end nonZeroDivisors
theorem natDegree_pos_of_monic_of_aeval_eq_zero [Nontrivial R] [Semiring S] [Algebra R S]
[FaithfulSMul R S] {p : R[X]} (hp : p.Monic) {x : S} (hx : aeval x p = 0) :
0 < p.natDegree :=
natDegree_pos_of_aeval_root (Monic.ne_zero hp) hx
((injective_iff_map_eq_zero (algebraMap R S)).mp (FaithfulSMul.algebraMap_injective R S))
theorem rootMultiplicity_mul_X_sub_C_pow {p : R[X]} {a : R} {n : ℕ} (h : p ≠ 0) :
(p * (X - C a) ^ n).rootMultiplicity a = p.rootMultiplicity a + n := by
have h2 := monic_X_sub_C a |>.pow n |>.mul_left_ne_zero h
refine le_antisymm ?_ ?_
· rw [rootMultiplicity_le_iff h2, add_assoc, add_comm n, ← add_assoc, pow_add,
dvd_cancel_right_mem_nonZeroDivisors (monic_X_sub_C a |>.pow n |>.mem_nonZeroDivisors)]
exact pow_rootMultiplicity_not_dvd h a
· rw [le_rootMultiplicity_iff h2, pow_add]
exact mul_dvd_mul_right (pow_rootMultiplicity_dvd p a) _
/-- The multiplicity of `a` as root of `(X - a) ^ n` is `n`. -/
theorem rootMultiplicity_X_sub_C_pow [Nontrivial R] (a : R) (n : ℕ) :
rootMultiplicity a ((X - C a) ^ n) = n := by
have := rootMultiplicity_mul_X_sub_C_pow (a := a) (n := n) C.map_one_ne_zero
rwa [rootMultiplicity_C, map_one, one_mul, zero_add] at this
theorem rootMultiplicity_X_sub_C_self [Nontrivial R] {x : R} :
rootMultiplicity x (X - C x) = 1 :=
pow_one (X - C x) ▸ rootMultiplicity_X_sub_C_pow x 1
-- Porting note: swapped instance argument order
theorem rootMultiplicity_X_sub_C [Nontrivial R] [DecidableEq R] {x y : R} :
rootMultiplicity x (X - C y) = if x = y then 1 else 0 := by
split_ifs with hxy
· rw [hxy]
exact rootMultiplicity_X_sub_C_self
exact rootMultiplicity_eq_zero (mt root_X_sub_C.mp (Ne.symm hxy))
theorem rootMultiplicity_mul' {p q : R[X]} {x : R}
(hpq : (p /ₘ (X - C x) ^ p.rootMultiplicity x).eval x *
(q /ₘ (X - C x) ^ q.rootMultiplicity x).eval x ≠ 0) :
rootMultiplicity x (p * q) = rootMultiplicity x p + rootMultiplicity x q := by
simp_rw [eval_divByMonic_eq_trailingCoeff_comp] at hpq
simp_rw [rootMultiplicity_eq_natTrailingDegree, mul_comp, natTrailingDegree_mul' hpq]
theorem Monic.neg_one_pow_natDegree_mul_comp_neg_X {p : R[X]} (hp : p.Monic) :
((-1) ^ p.natDegree * p.comp (-X)).Monic := by
simp only [Monic]
calc
((-1) ^ p.natDegree * p.comp (-X)).leadingCoeff =
(p.comp (-X) * C ((-1) ^ p.natDegree)).leadingCoeff := by
simp [mul_comm]
_ = 1 := by
apply monic_mul_C_of_leadingCoeff_mul_eq_one
| simp [← pow_add, hp]
variable [IsDomain R] {p q : R[X]}
| Mathlib/Algebra/Polynomial/RingDivision.lean | 183 | 186 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Real
/-!
# Power function on `ℝ≥0` and `ℝ≥0∞`
We construct the power functions `x ^ y` where
* `x` is a nonnegative real number and `y` is a real number;
* `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number.
We also prove basic properties of these functions.
-/
noncomputable section
open Real NNReal ENNReal ComplexConjugate Finset Function Set
namespace NNReal
variable {x : ℝ≥0} {w y z : ℝ}
/-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the
restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`,
one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 :=
⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩
noncomputable instance : Pow ℝ≥0 ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp, norm_cast]
theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y :=
rfl
@[simp]
theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 :=
NNReal.eq <| Real.rpow_zero _
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero]
exact Real.rpow_eq_zero_iff_of_nonneg x.2
lemma rpow_eq_zero (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [hy]
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 :=
NNReal.eq <| Real.zero_rpow h
@[simp]
theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x :=
NNReal.eq <| Real.rpow_one _
lemma rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ :=
NNReal.eq <| Real.rpow_neg x.2 _
@[simp, norm_cast]
lemma rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n
@[simp, norm_cast]
lemma rpow_intCast (x : ℝ≥0) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast,
Int.cast_negSucc, rpow_neg, zpow_negSucc]
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 :=
NNReal.eq <| Real.one_rpow _
theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _
theorem rpow_add' (h : y + z ≠ 0) (x : ℝ≥0) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add' x.2 h
lemma rpow_add_intCast (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast (mod_cast hx) _ _
lemma rpow_add_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast (mod_cast hx) _ _
lemma rpow_sub_intCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _
lemma rpow_sub_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _
lemma rpow_add_intCast' {n : ℤ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast' (mod_cast x.2) h
lemma rpow_add_natCast' {n : ℕ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast' (mod_cast x.2) h
lemma rpow_sub_intCast' {n : ℤ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h
lemma rpow_sub_natCast' {n : ℕ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h
lemma rpow_add_one (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_natCast hx y 1
lemma rpow_sub_one (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_natCast hx y 1
lemma rpow_add_one' (h : y + 1 ≠ 0) (x : ℝ≥0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' h, rpow_one]
lemma rpow_one_add' (h : 1 + y ≠ 0) (x : ℝ≥0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' h, rpow_one]
theorem rpow_add_of_nonneg (x : ℝ≥0) {y z : ℝ} (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
ext; exact Real.rpow_add_of_nonneg x.2 hy hz
/-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add']; rwa [h]
theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
NNReal.eq <| Real.rpow_mul x.2 y z
lemma rpow_natCast_mul (x : ℝ≥0) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_natCast]
lemma rpow_mul_natCast (x : ℝ≥0) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_natCast]
lemma rpow_intCast_mul (x : ℝ≥0) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_intCast]
lemma rpow_mul_intCast (x : ℝ≥0) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_intCast]
theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z
theorem rpow_sub' (h : y - z ≠ 0) (x : ℝ≥0) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub' x.2 h
lemma rpow_sub_one' (h : y - 1 ≠ 0) (x : ℝ≥0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' h, rpow_one]
lemma rpow_one_sub' (h : 1 - y ≠ 0) (x : ℝ≥0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' h, rpow_one]
theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by
field_simp [← rpow_mul]
theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by
field_simp [← rpow_mul]
theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ :=
NNReal.eq <| Real.inv_rpow x.2 y
theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z :=
NNReal.eq <| Real.div_rpow x.2 y.2 z
theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by
refine NNReal.eq ?_
push_cast
exact Real.sqrt_eq_rpow x.1
@[simp]
lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) :=
rpow_natCast x n
theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z :=
NNReal.eq <| Real.mul_rpow x.2 y.2
/-- `rpow` as a `MonoidHom` -/
@[simps]
def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where
toFun := (· ^ r)
map_one' := one_rpow _
map_mul' _x _y := mul_rpow
/-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0` -/
theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r :=
l.prod_hom (rpowMonoidHom r)
theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← list_prod_map_rpow, List.map_map]; rfl
/-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/
lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r :=
s.prod_hom' (rpowMonoidHom r) _
/-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/
lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
multiset_prod_map_rpow _ _ _
-- note: these don't really belong here, but they're much easier to prove in terms of the above
section Real
/-- `rpow` version of `List.prod_map_pow` for `Real`. -/
theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r := by
lift l to List ℝ≥0 using hl
have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r)
push_cast at this
rw [List.map_map] at this ⊢
exact mod_cast this
theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ)
(hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map]
· rfl
simpa using hl
/-- `rpow` version of `Multiset.prod_map_pow`. -/
theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ)
(hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r := by
induction' s using Quotient.inductionOn with l
simpa using Real.list_prod_map_rpow' l f hs r
/-- `rpow` version of `Finset.prod_pow`. -/
theorem _root_.Real.finset_prod_rpow
{ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
Real.multiset_prod_map_rpow s.val f hs r
end Real
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
Real.rpow_le_rpow x.2 h₁ h₂
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
Real.rpow_lt_rpow x.2 h₁ h₂
theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
Real.rpow_lt_rpow_iff x.2 y.2 hz
theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
Real.rpow_le_rpow_iff x.2 y.2 hz
theorem le_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem rpow_inv_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem lt_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by
simp only [← not_le, rpow_inv_le_iff hz]
theorem rpow_inv_lt_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by
simp only [← not_le, le_rpow_inv_iff hz]
section
variable {y : ℝ≥0}
lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z :=
Real.rpow_lt_rpow_of_neg hx hxy hz
lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z :=
Real.rpow_le_rpow_of_nonpos hx hxy hz
lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x :=
Real.rpow_lt_rpow_iff_of_neg hx hy hz
lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x :=
Real.rpow_le_rpow_iff_of_neg hx hy hz
lemma le_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y :=
Real.le_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_le_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z :=
Real.rpow_inv_le_iff_of_pos x.2 hy hz
lemma lt_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x < y ^ z⁻¹ ↔ x ^ z < y :=
Real.lt_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_lt_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ < y ↔ x < y ^ z :=
Real.rpow_inv_lt_iff_of_pos x.2 hy hz
lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z :=
Real.le_rpow_inv_iff_of_neg hx hy hz
lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z :=
Real.lt_rpow_inv_iff_of_neg hx hy hz
lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x :=
Real.rpow_inv_lt_iff_of_neg hx hy hz
lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x :=
Real.rpow_inv_le_iff_of_neg hx hy hz
end
@[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_lt hx hyz
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_le hx hyz
theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz
theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by
have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by
intro p hp_pos
rw [← zero_rpow hp_pos.ne']
exact rpow_lt_rpow hx_pos hp_pos
rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg)
· exact rpow_pos_of_nonneg hp_pos
· simp only [zero_lt_one, rpow_zero]
· rw [← neg_neg p, rpow_neg, inv_pos]
exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg)
theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 :=
Real.rpow_lt_one (coe_nonneg x) hx1 hz
theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 :=
Real.rpow_le_one x.2 hx2 hz
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 :=
Real.rpow_lt_one_of_one_lt_of_neg hx hz
theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 :=
Real.rpow_le_one_of_one_le_of_nonpos hx hz
theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z :=
Real.one_lt_rpow hx hz
theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z :=
Real.one_le_rpow h h₁
theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x ^ z :=
Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz
theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z ≤ 0) : 1 ≤ x ^ z :=
Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz
theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x))
· have : z ≠ 0 := by linarith
simp [this]
nth_rw 2 [← NNReal.rpow_one x]
exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le
theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x :=
fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz
theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y :=
(rpow_left_injective hz).eq_iff
theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x :=
fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancel₀ hx, rpow_one]⟩
theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x :=
⟨rpow_left_injective hx, rpow_left_surjective hx⟩
theorem eq_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
theorem rpow_inv_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
@[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul, inv_mul_cancel₀ hy, rpow_one]
theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow]
exact Real.pow_rpow_inv_natCast x.2 hn
theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow]
exact Real.rpow_inv_natCast_pow x.2 hn
theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) :
Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by
nth_rw 1 [← Real.coe_toNNReal x hx]
rw [← NNReal.coe_rpow, Real.toNNReal_coe]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z :=
fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe]
theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z :=
h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 =>
(strictMono_rpow_of_pos h0).monotone
/-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive,
where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/
@[simps! apply]
def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 :=
(strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y))
fun x => by
dsimp
rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one]
theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) :
(orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by
simp only [orderIsoRpow, one_div_one_div]; rfl
theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : ‖x ^ y‖₊ = ‖x‖₊ ^ y := by
ext; exact Real.norm_rpow_of_nonneg hx
end NNReal
namespace ENNReal
/-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and
`y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values
for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and
`⊤ ^ x = 1 / 0 ^ x`). -/
noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞
| some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0)
| none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0
noncomputable instance : Pow ℝ≥0∞ ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp]
theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by
cases x <;>
| · dsimp only [(· ^ ·), Pow.pow, rpow]
simp [lt_irrefl]
theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 :=
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 452 | 455 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Logic.Encodable.Pi
import Mathlib.Logic.Function.Iterate
/-!
# The primitive recursive functions
The primitive recursive functions are the least collection of functions
`ℕ → ℕ` which are closed under projections (using the `pair`
pairing function), composition, zero, successor, and primitive recursion
(i.e. `Nat.rec` where the motive is `C n := ℕ`).
We can extend this definition to a large class of basic types by
using canonical encodings of types as natural numbers (Gödel numbering),
which we implement through the type class `Encodable`. (More precisely,
we need that the composition of encode with decode yields a
primitive recursive function, so we have the `Primcodable` type class
for this.)
In the above, the pairing function is primitive recursive by definition.
This deviates from the textbook definition of primitive recursive functions,
which instead work with *`n`-ary* functions. We formalize the textbook
definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is
equivalent to our chosen formulation. For more discussionn of this and
other design choices in this formalization, see [carneiro2019].
## Main definitions
- `Nat.Primrec f`: `f` is primitive recursive, for functions `f : ℕ → ℕ`
- `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types
- `Primcodable α`: well-behaved encoding of `α` into `ℕ`, i.e. one such that roundtripping through
the encoding functions adds no computational power
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open List (Vector)
open Denumerable Encodable Function
namespace Nat
/-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/
@[simp, reducible]
def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α :=
f n.unpair.1 n.unpair.2
/-- The primitive recursive functions `ℕ → ℕ`. -/
protected inductive Primrec : (ℕ → ℕ) → Prop
| zero : Nat.Primrec fun _ => 0
| protected succ : Nat.Primrec succ
| left : Nat.Primrec fun n => n.unpair.1
| right : Nat.Primrec fun n => n.unpair.2
| pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n)
| comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n)
| prec {f g} :
Nat.Primrec f →
Nat.Primrec g →
Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH)
namespace Primrec
theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g :=
(funext H : f = g) ▸ hf
theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n
| 0 => zero
| n + 1 => Primrec.succ.comp (const n)
protected theorem id : Nat.Primrec id :=
(left.pair right).of_eq fun n => by simp
theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) :
Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH :=
((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp
theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) :=
(prec1 m (hf.comp left)).of_eq <| by simp
-- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor.
theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) :
Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) :=
(prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp
protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) :=
(pair right left).of_eq fun n => by simp
theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) :=
(hf.comp .swap).of_eq fun n => by simp
theorem pred : Nat.Primrec pred :=
(casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*]
theorem add : Nat.Primrec (unpaired (· + ·)) :=
(prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc]
theorem sub : Nat.Primrec (unpaired (· - ·)) :=
(prec .id ((pred.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq]
theorem mul : Nat.Primrec (unpaired (· * ·)) :=
(prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst]
theorem pow : Nat.Primrec (unpaired (· ^ ·)) :=
(prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ]
end Primrec
end Nat
/-- A `Primcodable` type is, essentially, an `Encodable` type for which
the encode/decode functions are primitive recursive.
However, such a definition is circular.
Instead, we ask that the composition of `decode : ℕ → Option α` with
`encode : Option α → ℕ` is primitive recursive. Said composition is
the identity function, restricted to the image of `encode`.
Thus, in a way, the added requirement ensures that no predicates
can be smuggled in through a cunning choice of the subset of `ℕ` into
which the type is encoded. -/
class Primcodable (α : Type*) extends Encodable α where
-- Porting note: was `prim [] `.
-- This means that `prim` does not take the type explicitly in Lean 4
prim : Nat.Primrec fun n => Encodable.encode (decode n)
namespace Primcodable
open Nat.Primrec
instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α :=
⟨Nat.Primrec.succ.of_eq <| by simp⟩
/-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/
def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β :=
{ __ := Encodable.ofEquiv α e
prim := (@Primcodable.prim α _).of_eq fun n => by
rw [decode_ofEquiv]
cases (@decode α _ n) <;>
simp [encode_ofEquiv] }
instance empty : Primcodable Empty :=
⟨zero⟩
instance unit : Primcodable PUnit :=
⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩
instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) :=
⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by
cases n with
| zero => rfl
| succ n =>
rw [decode_option_succ]
cases H : @decode α _ n <;> simp [H]⟩
instance bool : Primcodable Bool :=
⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with
| 0 => rfl
| 1 => rfl
| (n + 2) => by rw [decode_ge_two] <;> simp⟩
end Primcodable
/-- `Primrec f` means `f` is primitive recursive (after
encoding its input and output as natural numbers). -/
def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop :=
Nat.Primrec fun n => encode ((@decode α _ n).map f)
namespace Primrec
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
open Nat.Primrec
protected theorem encode : Primrec (@encode α _) :=
(@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl
protected theorem decode : Primrec (@decode α _) :=
Nat.Primrec.succ.comp (@Primcodable.prim α _)
theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} :
Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) :=
⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h =>
(Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩
theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f :=
dom_denumerable
theorem encdec : Primrec fun n => encode (@decode α _ n) :=
nat_iff.2 Primcodable.prim
theorem option_some : Primrec (@some α) :=
((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by
cases @decode α _ n <;> simp
theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g :=
(funext H : f = g) ▸ hf
theorem const (x : σ) : Primrec fun _ : α => x :=
((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by
cases @decode α _ n <;> rfl
protected theorem id : Primrec (@id α) :=
(@Primcodable.prim α).of_eq <| by simp
theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) :=
((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by
cases @decode α _ n <;> simp [encodek]
theorem succ : Primrec Nat.succ :=
nat_iff.2 Nat.Primrec.succ
theorem pred : Primrec Nat.pred :=
nat_iff.2 Nat.Primrec.pred
theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f :=
⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩
theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} :
Primrec f ↔ Primrec fun n => f (ofNat α n) :=
dom_denumerable.trans <| nat_iff.symm.trans encode_iff
protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) :=
ofNat_iff.1 Primrec.id
theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f :=
⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩
theorem of_equiv {β} {e : β ≃ α} :
haveI := Primcodable.ofEquiv α e
Primrec e :=
letI : Primcodable β := Primcodable.ofEquiv α e
encode_iff.1 Primrec.encode
theorem of_equiv_symm {β} {e : β ≃ α} :
haveI := Primcodable.ofEquiv α e
Primrec e.symm :=
letI := Primcodable.ofEquiv α e
encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode])
theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} :
haveI := Primcodable.ofEquiv α e
(Primrec fun a => e (f a)) ↔ Primrec f :=
letI := Primcodable.ofEquiv α e
⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩
theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} :
haveI := Primcodable.ofEquiv α e
(Primrec fun a => e.symm (f a)) ↔ Primrec f :=
letI := Primcodable.ofEquiv α e
⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩
end Primrec
namespace Primcodable
open Nat.Primrec
instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) :=
⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp
(pair right ((@Primcodable.prim α).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode α _ n.unpair.1; · simp
cases @decode β _ n.unpair.2 <;> simp⟩
end Primcodable
namespace Primrec
variable {α : Type*} [Primcodable α]
open Nat.Primrec
theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) :=
((casesOn' zero
((casesOn' zero (Nat.Primrec.succ.comp left)).comp
(pair right ((@Primcodable.prim β).comp left)))).comp
(pair right ((@Primcodable.prim α).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode α _ n.unpair.1 <;> simp
cases @decode β _ n.unpair.2 <;> simp
theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) :=
((casesOn' zero
((casesOn' zero (Nat.Primrec.succ.comp right)).comp
(pair right ((@Primcodable.prim β).comp left)))).comp
(pair right ((@Primcodable.prim α).comp left))).of_eq
fun n => by
simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val]
cases @decode α _ n.unpair.1 <;> simp
cases @decode β _ n.unpair.2 <;> simp
theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ}
(hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) :=
((casesOn1 0
(Nat.Primrec.succ.comp <|
.pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp
(@Primcodable.prim α _)).of_eq
fun n => by cases @decode α _ n <;> simp [encodek]
theorem unpair : Primrec Nat.unpair :=
(pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp
theorem list_getElem?₁ : ∀ l : List α, Primrec (l[·]? : ℕ → Option α)
| [] => dom_denumerable.2 zero
| a :: l =>
dom_denumerable.2 <|
(casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?₁ l).of_eq fun n => by
cases n <;> simp
@[deprecated (since := "2025-02-14")] alias list_get?₁ := list_getElem?₁
end Primrec
/-- `Primrec₂ f` means `f` is a binary primitive recursive function.
This is technically unnecessary since we can always curry all
the arguments together, but there are enough natural two-arg
functions that it is convenient to express this directly. -/
def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) :=
Primrec fun p : α × β => f p.1 p.2
/-- `PrimrecPred p` means `p : α → Prop` is a (decidable)
primitive recursive predicate, which is to say that
`decide ∘ p : α → Bool` is primitive recursive. -/
def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] :=
Primrec fun a => decide (p a)
/-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable)
primitive recursive relation, which is to say that
`decide ∘ p : α → β → Bool` is primitive recursive. -/
def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop)
[∀ a b, Decidable (s a b)] :=
Primrec₂ fun a b => decide (s a b)
namespace Primrec₂
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf
theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g :=
(by funext a b; apply H : f = g) ▸ hg
theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x :=
Primrec.const _
protected theorem pair : Primrec₂ (@Prod.mk α β) :=
Primrec.pair .fst .snd
theorem left : Primrec₂ fun (a : α) (_ : β) => a :=
.fst
theorem right : Primrec₂ fun (_ : α) (b : β) => b :=
.snd
theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor
theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f :=
⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩
theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f :=
Primrec.nat_iff.symm.trans unpaired
theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f :=
Primrec.encode_iff
theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f :=
Primrec.option_some_iff
theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} :
Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) :=
(Primrec.ofNat_iff.trans <| by simp).trans unpaired
theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by
rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl
theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by
rw [← uncurry, Function.uncurry_curry]
end Primrec₂
section Comp
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ]
theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec₂ fun a b => f (g a b) :=
hf.comp hg
theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g)
(hh : Primrec h) : Primrec fun a => f (g a) (h a) :=
Primrec.comp hf (hg.pair hh)
theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f)
(hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) :=
hf.comp hg hh
theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} :
PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) :=
Primrec.comp
theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} :
PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) :=
Primrec₂.comp
theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ}
{g : α → β → δ} :
PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) :=
PrimrecRel.comp
end Comp
theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q]
(hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q :=
Primrec.of_eq hp fun a => Bool.decide_congr (H a)
theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop}
[∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r)
(H : ∀ a b, r a b ↔ s a b) : PrimrecRel s :=
Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b)
namespace Primrec₂
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
open Nat.Primrec
theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) :=
h.comp₂ Primrec₂.right Primrec₂.left
theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec
(.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by
have :
∀ (a : Option α) (b : Option β),
Option.map (fun p : α × β => f p.1 p.2)
(Option.bind a fun a : α => Option.map (Prod.mk a) b) =
Option.bind a fun a => Option.map (f a) b := fun a b => by
cases a <;> cases b <;> rfl
simp [Primrec₂, Primrec, this]
theorem nat_iff' {f : α → β → σ} :
Primrec₂ f ↔
Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) :=
nat_iff.trans <| unpaired'.trans encode_iff
end Primrec₂
namespace Primrec
variable {α : Type*} {β : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable σ]
theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) :=
hf.of_eq fun _ => rfl
theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) :=
Primrec₂.nat_iff.2 <|
((Nat.Primrec.casesOn' .zero <|
(Nat.Primrec.prec hf <|
.comp hg <|
Nat.Primrec.left.pair <|
(Nat.Primrec.left.comp .right).pair <|
Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <|
Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <|
Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq
fun n => by
simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat,
Option.some_bind, Option.map_map, Option.map_some']
rcases @decode α _ n.unpair.1 with - | a; · rfl
simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some',
Option.some_bind, Option.map_map]
induction' n.unpair.2 with m <;> simp [encodek]
simp [*, encodek]
theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β}
(hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) :=
(nat_rec hg hh).comp .id hf
theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) :=
nat_rec' .id (const a) <| comp₂ hf Primrec₂.right
theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) :=
nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right
theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g)
(hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) :=
(nat_casesOn' hg hh).comp .id hf
theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) :
Primrec (fun (n : ℕ) => (n.casesOn a f : α)) :=
nat_casesOn .id (const a) (comp₂ hf .right)
theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g)
(hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) :=
(nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by
induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ']
theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o)
(hf : Primrec f) (hg : Primrec₂ g) :
@Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) :=
encode_iff.1 <|
(nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <|
pred.comp₂ <|
Primrec₂.encode_iff.2 <|
(Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂
Primrec₂.right).of_eq
fun a => by rcases o a with - | b <;> simp [encodek]
theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun a => (f a).bind (g a) :=
(option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl
| theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f :=
option_bind .id (hf.comp snd).to₂
theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun a => (f a).map (g a) :=
(option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl
theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) :=
option_map .id (hf.comp snd).to₂
| Mathlib/Computability/Primrec.lean | 530 | 538 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.FinMeasAdditive
/-!
# Extension of a linear function from indicators to L1
Given `T : Set α → E →L[ℝ] F` with `DominatedFinMeasAdditive μ T C`, we construct an extension
of `T` to integrable simple functions, which are finite sums of indicators of measurable sets
with finite measure, then to integrable functions, which are limits of integrable simple functions.
The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`.
This extension process is used to define the Bochner integral
in the `Mathlib.MeasureTheory.Integral.Bochner.Basic` file
and the conditional expectation of an integrable function
in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`.
## Main definitions
- `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T`
from indicators to L1.
- `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the
extension which applies to functions (with value 0 if the function is not integrable).
## Properties
For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on
all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on
measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`.
The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details.
Linearity:
- `setToFun_zero_left : setToFun μ 0 hT f = 0`
- `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f`
- `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f`
- `setToFun_zero : setToFun μ T hT (0 : α → E) = 0`
- `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f`
If `f` and `g` are integrable:
- `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g`
- `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g`
If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`:
- `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f`
Other:
- `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g`
- `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0`
If the space is also an ordered additive group with an order closed topology and `T` is such that
`0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties:
- `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f`
- `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f`
- `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g`
-/
noncomputable section
open scoped Topology NNReal
open Set Filter TopologicalSpace ENNReal
namespace MeasureTheory
variable {α E F F' G 𝕜 : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F']
[NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α}
namespace L1
open AEEqFun Lp.simpleFunc Lp
namespace SimpleFunc
theorem norm_eq_sum_mul (f : α →₁ₛ[μ] G) :
‖f‖ = ∑ x ∈ (toSimpleFunc f).range, μ.real (toSimpleFunc f ⁻¹' {x}) * ‖x‖ := by
rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm]
have h_eq := SimpleFunc.map_apply (‖·‖ₑ) (toSimpleFunc f)
simp_rw [← h_eq, measureReal_def]
rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum]
· congr
ext1 x
rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_enorm,
ENNReal.toReal_ofReal (norm_nonneg _)]
· intro x _
by_cases hx0 : x = 0
· rw [hx0]; simp
· exact
ENNReal.mul_ne_top ENNReal.coe_ne_top
(SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne
section SetToL1S
variable [NormedField 𝕜] [NormedSpace 𝕜 E]
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
/-- Extend `Set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/
def setToL1S (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F :=
(toSimpleFunc f).setToSimpleFunc T
theorem setToL1S_eq_setToSimpleFunc (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
setToL1S T f = (toSimpleFunc f).setToSimpleFunc T :=
rfl
@[simp]
theorem setToL1S_zero_left (f : α →₁ₛ[μ] E) : setToL1S (0 : Set α → E →L[ℝ] F) f = 0 :=
SimpleFunc.setToSimpleFunc_zero _
theorem setToL1S_zero_left' {T : Set α → E →L[ℝ] F}
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : setToL1S T f = 0 :=
SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f)
theorem setToL1S_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
setToL1S T f = setToL1S T g :=
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h
theorem setToL1S_congr_left (T T' : Set α → E →L[ℝ] F)
(h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) :
setToL1S T f = setToL1S T' f :=
SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f)
/-- `setToL1S` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement
uses two functions `f` and `f'` because they have to belong to different types, but morally these
are the same function (we have `f =ᵐ[μ] f'`). -/
theorem setToL1S_congr_measure {μ' : Measure α} (T : Set α → E →L[ℝ] F)
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hμ : μ ≪ μ')
(f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : (f : α → E) =ᵐ[μ] f') :
setToL1S T f = setToL1S T f' := by
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_
refine (toSimpleFunc_eq_toFun f).trans ?_
suffices (f' : α → E) =ᵐ[μ] simpleFunc.toSimpleFunc f' from h.trans this
have goal' : (f' : α → E) =ᵐ[μ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm
exact hμ.ae_eq goal'
theorem setToL1S_add_left (T T' : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
setToL1S (T + T') f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left T T'
theorem setToL1S_add_left' (T T' T'' : Set α → E →L[ℝ] F)
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
setToL1S T'' f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f)
theorem setToL1S_smul_left (T : Set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) :
setToL1S (fun s => c • T s) f = c • setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left T c _
theorem setToL1S_smul_left' (T T' : Set α → E →L[ℝ] F) (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) :
setToL1S T' f = c • setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f)
theorem setToL1S_add (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) :
setToL1S T (f + g) = setToL1S T f + setToL1S T g := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f)
(SimpleFunc.integrable g)]
exact
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _)
(add_toSimpleFunc f g)
theorem setToL1S_neg {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f : α →₁ₛ[μ] E) : setToL1S T (-f) = -setToL1S T f := by
simp_rw [setToL1S]
have : simpleFunc.toSimpleFunc (-f) =ᵐ[μ] ⇑(-simpleFunc.toSimpleFunc f) :=
neg_toSimpleFunc f
rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this]
exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f)
theorem setToL1S_sub {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) :
setToL1S T (f - g) = setToL1S T f - setToL1S T g := by
rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg]
theorem setToL1S_smul_real (T : Set α → E →L[ℝ] F)
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (c : ℝ)
(f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E]
[DistribSMul 𝕜 F] (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜)
(f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem norm_setToL1S_le (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * μ.real s) (f : α →₁ₛ[μ] E) :
‖setToL1S T f‖ ≤ C * ‖f‖ := by
rw [setToL1S, norm_eq_sum_mul f]
exact
SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _
(SimpleFunc.integrable f)
theorem setToL1S_indicatorConst {T : Set α → E →L[ℝ] F} {s : Set α}
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T)
(hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by
have h_empty : T ∅ = 0 := h_zero _ MeasurableSet.empty measure_empty
rw [setToL1S_eq_setToSimpleFunc]
refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x)
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact toSimpleFunc_indicatorConst hs hμs.ne x
theorem setToL1S_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F}
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) = T univ x :=
setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x
section Order
variable {G'' G' : Type*}
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G']
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G'']
{T : Set α → G'' →L[ℝ] G'}
theorem setToL1S_mono_left {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≤ T' s x)
(f : α →₁ₛ[μ] E) : setToL1S T f ≤ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1S_mono_left' {T T' : Set α → E →L[ℝ] G''}
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1S T f ≤ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G''] in
theorem setToL1S_nonneg (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G''}
(hf : 0 ≤ f) : 0 ≤ setToL1S T f := by
simp_rw [setToL1S]
obtain ⟨f', hf', hff'⟩ := exists_simpleFunc_nonneg_ae_eq hf
replace hff' : simpleFunc.toSimpleFunc f =ᵐ[μ] f' :=
(Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff'
rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff']
exact
SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff')
theorem setToL1S_mono (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G''}
(hfg : f ≤ g) : setToL1S T f ≤ setToL1S T g := by
rw [← sub_nonneg] at hfg ⊢
rw [← setToL1S_sub h_zero h_add]
exact setToL1S_nonneg h_zero h_add hT_nonneg hfg
end Order
variable [NormedSpace 𝕜 F]
variable (α E μ 𝕜)
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[𝕜] F`. -/
def setToL1SCLM' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁ₛ[μ] E) →L[𝕜] F :=
LinearMap.mkContinuous
⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩,
setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smul⟩
C fun f => norm_setToL1S_le T hT.2 f
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[ℝ] F`. -/
def setToL1SCLM {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) :
(α →₁ₛ[μ] E) →L[ℝ] F :=
LinearMap.mkContinuous
⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩,
setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩
C fun f => norm_setToL1S_le T hT.2 f
variable {α E μ 𝕜}
variable {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ}
@[simp]
theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C)
(f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = 0 :=
setToL1S_zero_left _
theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f = 0 :=
setToL1S_zero_left' h_zero f
theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f :=
setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f
theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s)
(f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f :=
setToL1S_congr_left T T' h f
theorem setToL1SCLM_congr_measure {μ' : Measure α} (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E)
(h : (f : α → E) =ᵐ[μ] f') : setToL1SCLM α E μ hT f = setToL1SCLM α E μ' hT' f' :=
setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hμ _ _ h
theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ (hT.add hT') f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f :=
setToL1S_add_left T T' f
theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT'' f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f :=
setToL1S_add_left' T T' T'' h_add f
theorem setToL1SCLM_smul_left (c : ℝ) (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ (hT.smul c) f = c • setToL1SCLM α E μ hT f :=
setToL1S_smul_left T c f
theorem setToL1SCLM_smul_left' (c : ℝ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C')
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT' f = c • setToL1SCLM α E μ hT f :=
setToL1S_smul_left' T T' c h_smul f
theorem norm_setToL1SCLM_le {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hC : 0 ≤ C) : ‖setToL1SCLM α E μ hT‖ ≤ C :=
LinearMap.mkContinuous_norm_le _ hC _
theorem norm_setToL1SCLM_le' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) :
‖setToL1SCLM α E μ hT‖ ≤ max C 0 :=
LinearMap.mkContinuous_norm_le' _ _
theorem setToL1SCLM_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F} {C : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (x : E) :
setToL1SCLM α E μ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) =
T univ x :=
setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G'']
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G']
theorem setToL1SCLM_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1SCLM_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G'] in
theorem setToL1SCLM_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G'}
(hf : 0 ≤ f) : 0 ≤ setToL1SCLM α G' μ hT f :=
setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf
theorem setToL1SCLM_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G'}
(hfg : f ≤ g) : setToL1SCLM α G' μ hT f ≤ setToL1SCLM α G' μ hT g :=
setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg
end Order
end SetToL1S
end SimpleFunc
open SimpleFunc
section SetToL1
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
variable (𝕜) [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [CompleteSpace F]
{T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ}
/-- Extend `Set α → (E →L[ℝ] F)` to `(α →₁[μ] E) →L[𝕜] F`. -/
def setToL1' (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁[μ] E) →L[𝕜] F :=
(setToL1SCLM' α E 𝕜 μ hT h_smul).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
variable {𝕜}
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁[μ] E) →L[ℝ] F`. -/
def setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F :=
(setToL1SCLM α E μ hT).extend (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) :
setToL1 hT f = setToL1SCLM α E μ hT f :=
uniformly_extend_of_ind simpleFunc.isUniformInducing (simpleFunc.denseRange one_ne_top)
(setToL1SCLM α E μ hT).uniformContinuous _
theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[μ] E) :
setToL1 hT f = setToL1' 𝕜 hT h_smul f :=
rfl
@[simp]
theorem setToL1_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C)
(f : α →₁[μ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply]
theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁[μ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp,
ContinuousLinearMap.zero_apply]
theorem setToL1_congr_left (T T' : Set α → E →L[ℝ] F) {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : T = T')
(f : α →₁[μ] E) : setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact setToL1SCLM_congr_left hT' hT h.symm f
theorem setToL1_congr_left' (T T' : Set α → E →L[ℝ] F) {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁[μ] E) :
setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact (setToL1SCLM_congr_left' hT hT' h f).symm
theorem setToL1_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁[μ] E) :
setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by
rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.add hT')) _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ (hT.add hT') f by
rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT']
theorem setToL1_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁[μ] E) :
setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT'') _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ hT'' f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM,
setToL1SCLM_add_left' hT hT' hT'' h_add]
theorem setToL1_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α →₁[μ] E) :
setToL1 (hT.smul c) f = c • setToL1 hT f := by
suffices setToL1 (hT.smul c) = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.smul c)) _ _ _ _ ?_
ext1 f
suffices c • setToL1 hT f = setToL1SCLM α E μ (hT.smul c) f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT]
theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁[μ] E) :
setToL1 hT' f = c • setToL1 hT f := by
suffices setToL1 hT' = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT') _ _ _ _ ?_
ext1 f
suffices c • setToL1 hT f = setToL1SCLM α E μ hT' f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul]
theorem setToL1_smul (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[μ] E) :
setToL1 hT (c • f) = c • setToL1 hT f := by
rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul]
exact ContinuousLinearMap.map_smul _ _ _
theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) :
setToL1 hT (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by
rw [setToL1_eq_setToL1SCLM]
exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hμs x
theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) :
setToL1 hT (indicatorConstLp 1 hs hμs x) = T s x := by
rw [← Lp.simpleFunc.coe_indicatorConst hs hμs x]
exact setToL1_simpleFunc_indicatorConst hT hs hμs.lt_top x
theorem setToL1_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) :
setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x :=
setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace ℝ G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G']
theorem setToL1_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁[μ] E) :
setToL1 hT f ≤ setToL1 hT' f := by
induction f using Lp.induction (hp_ne_top := one_ne_top) with
| @indicatorConst c s hs hμs =>
rw [setToL1_simpleFunc_indicatorConst hT hs hμs, setToL1_simpleFunc_indicatorConst hT' hs hμs]
exact hTT' s hs hμs c
| @add f g hf hg _ hf_le hg_le =>
rw [(setToL1 hT).map_add, (setToL1 hT').map_add]
exact add_le_add hf_le hg_le
| isClosed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous
theorem setToL1_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToL1 hT f ≤ setToL1 hT' f :=
setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToL1_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁[μ] G'}
(hf : 0 ≤ f) : 0 ≤ setToL1 hT f := by
suffices ∀ f : { g : α →₁[μ] G' // 0 ≤ g }, 0 ≤ setToL1 hT f from
this (⟨f, hf⟩ : { g : α →₁[μ] G' // 0 ≤ g })
refine fun g =>
@isClosed_property { g : α →₁ₛ[μ] G' // 0 ≤ g } { g : α →₁[μ] G' // 0 ≤ g } _ _
(fun g => 0 ≤ setToL1 hT g)
(denseRange_coeSimpleFuncNonnegToLpNonneg 1 μ G' one_ne_top) ?_ ?_ g
· exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom)
· intro g
have : (coeSimpleFuncNonnegToLpNonneg 1 μ G' g : α →₁[μ] G') = (g : α →₁ₛ[μ] G') := rfl
rw [this, setToL1_eq_setToL1SCLM]
exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2
theorem setToL1_mono [IsOrderedAddMonoid G']
{T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁[μ] G'}
(hfg : f ≤ g) : setToL1 hT f ≤ setToL1 hT g := by
rw [← sub_nonneg] at hfg ⊢
rw [← (setToL1 hT).map_sub]
exact setToL1_nonneg hT hT_nonneg hfg
end Order
theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) :
‖setToL1 hT‖ ≤ ‖setToL1SCLM α E μ hT‖ :=
calc
‖setToL1 hT‖ ≤ (1 : ℝ≥0) * ‖setToL1SCLM α E μ hT‖ := by
refine
ContinuousLinearMap.opNorm_extend_le (setToL1SCLM α E μ hT) (coeToLp α E ℝ)
(simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_
rw [NNReal.coe_one, one_mul]
simp [coeToLp]
_ = ‖setToL1SCLM α E μ hT‖ := by rw [NNReal.coe_one, one_mul]
theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C)
(f : α →₁[μ] E) : ‖setToL1 hT f‖ ≤ C * ‖f‖ :=
calc
‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ ≤ C * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC
theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
‖setToL1 hT f‖ ≤ max C 0 * ‖f‖ :=
calc
‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ ≤ max C 0 * ‖f‖ :=
mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _)
theorem norm_setToL1_le (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : ‖setToL1 hT‖ ≤ C :=
ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC)
theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive μ T C) : ‖setToL1 hT‖ ≤ max C 0 :=
ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT)
theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive μ T C) :
LipschitzWith (Real.toNNReal C) (setToL1 hT) :=
(setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT)
/-- If `fs i → f` in `L1`, then `setToL1 hT (fs i) → setToL1 hT f`. -/
theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) {ι}
(fs : ι → α →₁[μ] E) {l : Filter ι} (hfs : Tendsto fs l (𝓝 f)) :
Tendsto (fun i => setToL1 hT (fs i)) l (𝓝 <| setToL1 hT f) :=
((setToL1 hT).continuous.tendsto _).comp hfs
end SetToL1
end L1
section Function
variable [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E}
variable (μ T)
open Classical in
/-- Extend `T : Set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to
0 if the function is not integrable. -/
def setToFun (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F :=
if hf : Integrable f μ then L1.setToL1 hT (hf.toL1 f) else 0
variable {μ T}
theorem setToFun_eq (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
setToFun μ T hT f = L1.setToL1 hT (hf.toL1 f) :=
dif_pos hf
theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
setToFun μ T hT f = L1.setToL1 hT f := by
rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn]
theorem setToFun_undef (hT : DominatedFinMeasAdditive μ T C) (hf : ¬Integrable f μ) :
setToFun μ T hT f = 0 :=
dif_neg hf
theorem setToFun_non_aestronglyMeasurable (hT : DominatedFinMeasAdditive μ T C)
(hf : ¬AEStronglyMeasurable f μ) : setToFun μ T hT f = 0 :=
setToFun_undef hT (not_and_of_not_left _ hf)
@[deprecated (since := "2025-04-09")]
alias setToFun_non_aEStronglyMeasurable := setToFun_non_aestronglyMeasurable
theorem setToFun_congr_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α → E) :
setToFun μ T hT f = setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h]
· simp_rw [setToFun_undef _ hf]
theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s)
(f : α → E) : setToFun μ T hT f = setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h]
· simp_rw [setToFun_undef _ hf]
theorem setToFun_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α → E) :
setToFun μ (T + T') (hT.add hT') f = setToFun μ T hT f + setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT']
· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α → E) :
setToFun μ T'' hT'' f = setToFun μ T hT f + setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add]
· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α → E) :
setToFun μ (fun s => c • T s) (hT.smul c) f = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c]
· simp_rw [setToFun_undef _ hf, smul_zero]
theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α → E) :
setToFun μ T' hT' f = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul]
· simp_rw [setToFun_undef _ hf, smul_zero]
@[simp]
theorem setToFun_zero (hT : DominatedFinMeasAdditive μ T C) : setToFun μ T hT (0 : α → E) = 0 := by
rw [Pi.zero_def, setToFun_eq hT (integrable_zero _ _ _)]
simp only [← Pi.zero_def]
rw [Integrable.toL1_zero, ContinuousLinearMap.map_zero]
@[simp]
theorem setToFun_zero_left {hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C} :
setToFun μ 0 hT f = 0 := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _
· exact setToFun_undef hT hf
theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) : setToFun μ T hT f = 0 := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _
· exact setToFun_undef hT hf
theorem setToFun_add (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ)
(hg : Integrable g μ) : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g := by
rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add,
(L1.setToL1 hT).map_add]
theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι)
{f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) μ) :
setToFun μ T hT (∑ i ∈ s, f i) = ∑ i ∈ s, setToFun μ T hT (f i) := by
classical
revert hf
refine Finset.induction_on s ?_ ?_
· intro _
simp only [setToFun_zero, Finset.sum_empty]
· intro i s his ih hf
simp only [his, Finset.sum_insert, not_false_iff]
rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _]
· rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)]
· convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x
simp
theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι) {f : ι → α → E}
(hf : ∀ i ∈ s, Integrable (f i) μ) :
(setToFun μ T hT fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, setToFun μ T hT (f i) := by
convert setToFun_finset_sum' hT s hf with a; simp
theorem setToFun_neg (hT : DominatedFinMeasAdditive μ T C) (f : α → E) :
setToFun μ T hT (-f) = -setToFun μ T hT f := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg,
(L1.setToL1 hT).map_neg]
· rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero]
rwa [← integrable_neg_iff] at hf
theorem setToFun_sub (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ)
(hg : Integrable g μ) : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g := by
rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g]
theorem setToFun_smul [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F]
(hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜)
(f : α → E) : setToFun μ T hT (c • f) = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul',
L1.setToL1_smul hT h_smul c _]
· by_cases hr : c = 0
· rw [hr]; simp
· have hf' : ¬Integrable (c • f) μ := by rwa [integrable_smul_iff hr f]
rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero]
theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive μ T C) (h : f =ᵐ[μ] g) :
setToFun μ T hT f = setToFun μ T hT g := by
by_cases hfi : Integrable f μ
· have hgi : Integrable g μ := hfi.congr h
rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h]
· have hgi : ¬Integrable g μ := by rw [integrable_congr h] at hfi; exact hfi
rw [setToFun_undef hT hfi, setToFun_undef hT hgi]
theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive μ T C) (h : μ = 0) :
setToFun μ T hT f = 0 := by
have : f =ᵐ[μ] 0 := by simp [h, EventuallyEq]
rw [setToFun_congr_ae hT this, setToFun_zero]
theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive μ T C)
(h : ∀ s, MeasurableSet s → μ s < ∞ → μ s = 0) : setToFun μ T hT f = 0 :=
setToFun_zero_left' hT fun s hs hμs => hT.eq_zero_of_measure_zero hs (h s hs hμs)
theorem setToFun_toL1 (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
setToFun μ T hT (hf.toL1 f) = setToFun μ T hT f :=
setToFun_congr_ae hT hf.coeFn_toL1
theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) :
setToFun μ T hT (s.indicator fun _ => x) = T s x := by
rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hμs x).symm]
rw [L1.setToFun_eq_setToL1 hT]
exact L1.setToL1_indicatorConstLp hT hs hμs x
theorem setToFun_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) :
(setToFun μ T hT fun _ => x) = T univ x := by
have : (fun _ : α => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm
rw [this]
exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace ℝ G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G']
theorem setToFun_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α → E) :
setToFun μ T hT f ≤ setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _
· simp_rw [setToFun_undef _ hf, le_rfl]
theorem setToFun_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToFun μ T hT f ≤ setToFun μ T' hT' f :=
setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToFun_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α → G'}
(hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f := by
by_cases hfi : Integrable f μ
· simp_rw [setToFun_eq _ hfi]
refine L1.setToL1_nonneg hT hT_nonneg ?_
rw [← Lp.coeFn_le]
have h0 := Lp.coeFn_zero G' 1 μ
have h := Integrable.coeFn_toL1 hfi
filter_upwards [h0, h, hf] with _ h0a ha hfa
rw [h0a, ha]
exact hfa
· simp_rw [setToFun_undef _ hfi, le_rfl]
theorem setToFun_mono [IsOrderedAddMonoid G']
{T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α → G'}
(hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) :
setToFun μ T hT f ≤ setToFun μ T hT g := by
rw [← sub_nonneg, ← setToFun_sub hT hg hf]
refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_)
rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg]
exact ha
end Order
@[continuity]
theorem continuous_setToFun (hT : DominatedFinMeasAdditive μ T C) :
Continuous fun f : α →₁[μ] E => setToFun μ T hT f := by
simp_rw [L1.setToFun_eq_setToL1 hT]; exact ContinuousLinearMap.continuous _
/-- If `F i → f` in `L1`, then `setToFun μ T hT (F i) → setToFun μ T hT f`. -/
theorem tendsto_setToFun_of_L1 (hT : DominatedFinMeasAdditive μ T C) {ι} (f : α → E)
(hfi : Integrable f μ) {fs : ι → α → E} {l : Filter ι} (hfsi : ∀ᶠ i in l, Integrable (fs i) μ)
(hfs : Tendsto (fun i => ∫⁻ x, ‖fs i x - f x‖ₑ ∂μ) l (𝓝 0)) :
Tendsto (fun i => setToFun μ T hT (fs i)) l (𝓝 <| setToFun μ T hT f) := by
classical
let f_lp := hfi.toL1 f
let F_lp i := if hFi : Integrable (fs i) μ then hFi.toL1 (fs i) else 0
have tendsto_L1 : Tendsto F_lp l (𝓝 f_lp) := by
rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm']
simp_rw [eLpNorm_one_eq_lintegral_enorm, Pi.sub_apply]
refine (tendsto_congr' ?_).mp hfs
filter_upwards [hfsi] with i hi
refine lintegral_congr_ae ?_
filter_upwards [hi.coeFn_toL1, hfi.coeFn_toL1] with x hxi hxf
simp_rw [F_lp, dif_pos hi, hxi, f_lp, hxf]
suffices Tendsto (fun i => setToFun μ T hT (F_lp i)) l (𝓝 (setToFun μ T hT f)) by
refine (tendsto_congr' ?_).mp this
filter_upwards [hfsi] with i hi
suffices h_ae_eq : F_lp i =ᵐ[μ] fs i from setToFun_congr_ae hT h_ae_eq
simp_rw [F_lp, dif_pos hi]
exact hi.coeFn_toL1
rw [setToFun_congr_ae hT hfi.coeFn_toL1.symm]
exact ((continuous_setToFun hT).tendsto f_lp).comp tendsto_L1
theorem tendsto_setToFun_approxOn_of_measurable (hT : DominatedFinMeasAdditive μ T C)
[MeasurableSpace E] [BorelSpace E] {f : α → E} {s : Set E} [SeparableSpace s]
(hfi : Integrable f μ) (hfm : Measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E}
(h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) μ) :
Tendsto (fun n => setToFun μ T hT (SimpleFunc.approxOn f hfm s y₀ h₀ n)) atTop
(𝓝 <| setToFun μ T hT f) :=
tendsto_setToFun_of_L1 hT _ hfi
(Eventually.of_forall (SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i))
(SimpleFunc.tendsto_approxOn_L1_enorm hfm _ hs (hfi.sub h₀i).2)
theorem tendsto_setToFun_approxOn_of_measurable_of_range_subset
(hT : DominatedFinMeasAdditive μ T C) [MeasurableSpace E] [BorelSpace E] {f : α → E}
(fmeas : Measurable f) (hf : Integrable f μ) (s : Set E) [SeparableSpace s]
(hs : range f ∪ {0} ⊆ s) :
Tendsto (fun n => setToFun μ T hT (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n)) atTop
(𝓝 <| setToFun μ T hT f) := by
refine tendsto_setToFun_approxOn_of_measurable hT hf fmeas ?_ _ (integrable_zero _ _ _)
exact Eventually.of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))
/-- Auxiliary lemma for `setToFun_congr_measure`: the function sending `f : α →₁[μ] G` to
`f : α →₁[μ'] G` is continuous when `μ' ≤ c' • μ` for `c' ≠ ∞`. -/
theorem continuous_L1_toL1 {μ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ) :
Continuous fun f : α →₁[μ] G =>
(Integrable.of_measure_le_smul hc' hμ'_le (L1.integrable_coeFn f)).toL1 f := by
by_cases hc'0 : c' = 0
· have hμ'0 : μ' = 0 := by rw [← Measure.nonpos_iff_eq_zero']; refine hμ'_le.trans ?_; simp [hc'0]
have h_im_zero :
(fun f : α →₁[μ] G =>
(Integrable.of_measure_le_smul hc' hμ'_le (L1.integrable_coeFn f)).toL1 f) =
0 := by
ext1 f; ext1; simp_rw [hμ'0]; simp only [ae_zero, EventuallyEq, eventually_bot]
rw [h_im_zero]
exact continuous_zero
rw [Metric.continuous_iff]
intro f ε hε_pos
use ε / 2 / c'.toReal
refine ⟨div_pos (half_pos hε_pos) (toReal_pos hc'0 hc'), ?_⟩
intro g hfg
rw [Lp.dist_def] at hfg ⊢
let h_int := fun f' : α →₁[μ] G => (L1.integrable_coeFn f').of_measure_le_smul hc' hμ'_le
have :
eLpNorm (⇑(Integrable.toL1 g (h_int g)) - ⇑(Integrable.toL1 f (h_int f))) 1 μ' =
eLpNorm (⇑g - ⇑f) 1 μ' :=
eLpNorm_congr_ae ((Integrable.coeFn_toL1 _).sub (Integrable.coeFn_toL1 _))
rw [this]
have h_eLpNorm_ne_top : eLpNorm (⇑g - ⇑f) 1 μ ≠ ∞ := by
rw [← eLpNorm_congr_ae (Lp.coeFn_sub _ _)]; exact Lp.eLpNorm_ne_top _
calc
(eLpNorm (⇑g - ⇑f) 1 μ').toReal ≤ (c' * eLpNorm (⇑g - ⇑f) 1 μ).toReal := by
refine toReal_mono (ENNReal.mul_ne_top hc' h_eLpNorm_ne_top) ?_
refine (eLpNorm_mono_measure (⇑g - ⇑f) hμ'_le).trans_eq ?_
rw [eLpNorm_smul_measure_of_ne_zero hc'0, smul_eq_mul]
simp
_ = c'.toReal * (eLpNorm (⇑g - ⇑f) 1 μ).toReal := toReal_mul
_ ≤ c'.toReal * (ε / 2 / c'.toReal) := by gcongr
_ = ε / 2 := by
refine mul_div_cancel₀ (ε / 2) ?_; rw [Ne, toReal_eq_zero_iff]; simp [hc', hc'0]
_ < ε := half_lt_self hε_pos
theorem setToFun_congr_measure_of_integrable {μ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞)
(hμ'_le : μ' ≤ c' • μ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (f : α → E) (hfμ : Integrable f μ) :
setToFun μ T hT f = setToFun μ' T hT' f := by
-- integrability for `μ` implies integrability for `μ'`.
have h_int : ∀ g : α → E, Integrable g μ → Integrable g μ' := fun g hg =>
Integrable.of_measure_le_smul hc' hμ'_le hg
-- We use `Integrable.induction`
apply hfμ.induction (P := fun f => setToFun μ T hT f = setToFun μ' T hT' f)
· intro c s hs hμs
have hμ's : μ' s ≠ ∞ := by
refine ((hμ'_le s).trans_lt ?_).ne
rw [Measure.smul_apply, smul_eq_mul]
exact ENNReal.mul_lt_top hc'.lt_top hμs
rw [setToFun_indicator_const hT hs hμs.ne, setToFun_indicator_const hT' hs hμ's]
· intro f₂ g₂ _ hf₂ hg₂ h_eq_f h_eq_g
rw [setToFun_add hT hf₂ hg₂, setToFun_add hT' (h_int f₂ hf₂) (h_int g₂ hg₂), h_eq_f, h_eq_g]
· refine isClosed_eq (continuous_setToFun hT) ?_
have :
(fun f : α →₁[μ] E => setToFun μ' T hT' f) = fun f : α →₁[μ] E =>
setToFun μ' T hT' ((h_int f (L1.integrable_coeFn f)).toL1 f) := by
ext1 f; exact setToFun_congr_ae hT' (Integrable.coeFn_toL1 _).symm
rw [this]
exact (continuous_setToFun hT').comp (continuous_L1_toL1 c' hc' hμ'_le)
· intro f₂ g₂ hfg _ hf_eq
have hfg' : f₂ =ᵐ[μ'] g₂ := (Measure.absolutelyContinuous_of_le_smul hμ'_le).ae_eq hfg
rw [← setToFun_congr_ae hT hfg, hf_eq, setToFun_congr_ae hT' hfg']
theorem setToFun_congr_measure {μ' : Measure α} (c c' : ℝ≥0∞) (hc : c ≠ ∞) (hc' : c' ≠ ∞)
(hμ_le : μ ≤ c • μ') (hμ'_le : μ' ≤ c' • μ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (f : α → E) :
setToFun μ T hT f = setToFun μ' T hT' f := by
by_cases hf : Integrable f μ
· exact setToFun_congr_measure_of_integrable c' hc' hμ'_le hT hT' f hf
· -- if `f` is not integrable, both `setToFun` are 0.
have h_int : ∀ g : α → E, ¬Integrable g μ → ¬Integrable g μ' := fun g =>
mt fun h => h.of_measure_le_smul hc hμ_le
simp_rw [setToFun_undef _ hf, setToFun_undef _ (h_int f hf)]
theorem setToFun_congr_measure_of_add_right {μ' : Measure α}
(hT_add : DominatedFinMeasAdditive (μ + μ') T C') (hT : DominatedFinMeasAdditive μ T C)
(f : α → E) (hf : Integrable f (μ + μ')) :
setToFun (μ + μ') T hT_add f = setToFun μ T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [← add_zero μ]
exact add_le_add le_rfl bot_le
theorem setToFun_congr_measure_of_add_left {μ' : Measure α}
(hT_add : DominatedFinMeasAdditive (μ + μ') T C') (hT : DominatedFinMeasAdditive μ' T C)
(f : α → E) (hf : Integrable f (μ + μ')) :
setToFun (μ + μ') T hT_add f = setToFun μ' T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [← zero_add μ']
exact add_le_add_right bot_le μ'
theorem setToFun_top_smul_measure (hT : DominatedFinMeasAdditive (∞ • μ) T C) (f : α → E) :
setToFun (∞ • μ) T hT f = 0 := by
refine setToFun_measure_zero' hT fun s _ hμs => ?_
rw [lt_top_iff_ne_top] at hμs
simp only [true_and, Measure.smul_apply, ENNReal.mul_eq_top, eq_self_iff_true,
top_ne_zero, Ne, not_false_iff, not_or, Classical.not_not, smul_eq_mul] at hμs
simp only [hμs.right, Measure.smul_apply, mul_zero, smul_eq_mul]
theorem setToFun_congr_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞)
(hT : DominatedFinMeasAdditive μ T C) (hT_smul : DominatedFinMeasAdditive (c • μ) T C')
(f : α → E) : setToFun μ T hT f = setToFun (c • μ) T hT_smul f := by
by_cases hc0 : c = 0
· simp [hc0] at hT_smul
have h : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0 := fun s hs _ => hT_smul.eq_zero hs
rw [setToFun_zero_left' _ h, setToFun_measure_zero]
simp [hc0]
refine setToFun_congr_measure c⁻¹ c ?_ hc_ne_top (le_of_eq ?_) le_rfl hT hT_smul f
· simp [hc0]
· rw [smul_smul, ENNReal.inv_mul_cancel hc0 hc_ne_top, one_smul]
theorem norm_setToFun_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E)
(hC : 0 ≤ C) : ‖setToFun μ T hT f‖ ≤ C * ‖f‖ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm hT hC f
theorem norm_setToFun_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
‖setToFun μ T hT f‖ ≤ max C 0 * ‖f‖ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm' hT f
theorem norm_setToFun_le (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) (hC : 0 ≤ C) :
‖setToFun μ T hT f‖ ≤ C * ‖hf.toL1 f‖ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm hT hC _
theorem norm_setToFun_le' (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
‖setToFun μ T hT f‖ ≤ max C 0 * ‖hf.toL1 f‖ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm' hT _
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their image by
`setToFun`.
We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound μ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_setToFun_of_dominated_convergence (hT : DominatedFinMeasAdditive μ T C)
{fs : ℕ → α → E} {f : α → E} (bound : α → ℝ)
(fs_measurable : ∀ n, AEStronglyMeasurable (fs n) μ) (bound_integrable : Integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => fs n a) atTop (𝓝 (f a))) :
Tendsto (fun n => setToFun μ T hT (fs n)) atTop (𝓝 <| setToFun μ T hT f) := by
-- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions.
have f_measurable : AEStronglyMeasurable f μ :=
aestronglyMeasurable_of_tendsto_ae _ fs_measurable h_lim
-- all functions we consider are integrable
have fs_int : ∀ n, Integrable (fs n) μ := fun n =>
bound_integrable.mono' (fs_measurable n) (h_bound _)
have f_int : Integrable f μ :=
⟨f_measurable,
hasFiniteIntegral_of_dominated_convergence bound_integrable.hasFiniteIntegral h_bound
h_lim⟩
-- it suffices to prove the result for the corresponding L1 functions
suffices
Tendsto (fun n => L1.setToL1 hT ((fs_int n).toL1 (fs n))) atTop
(𝓝 (L1.setToL1 hT (f_int.toL1 f))) by
convert this with n
· exact setToFun_eq hT (fs_int n)
· exact setToFun_eq hT f_int
-- the convergence of setToL1 follows from the convergence of the L1 functions
refine L1.tendsto_setToL1 hT _ _ ?_
-- up to some rewriting, what we need to prove is `h_lim`
rw [tendsto_iff_norm_sub_tendsto_zero]
have lintegral_norm_tendsto_zero :
Tendsto (fun n => ENNReal.toReal <| ∫⁻ a, ENNReal.ofReal ‖fs n a - f a‖ ∂μ) atTop (𝓝 0) :=
(tendsto_toReal zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence fs_measurable
bound_integrable.hasFiniteIntegral h_bound h_lim)
convert lintegral_norm_tendsto_zero with n
rw [L1.norm_def]
congr 1
refine lintegral_congr_ae ?_
rw [← Integrable.toL1_sub]
refine ((fs_int n).sub f_int).coeFn_toL1.mono fun x hx => ?_
dsimp only
rw [hx, ofReal_norm_eq_enorm, Pi.sub_apply]
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
theorem tendsto_setToFun_filter_of_dominated_convergence (hT : DominatedFinMeasAdditive μ T C) {ι}
{l : Filter ι} [l.IsCountablyGenerated] {fs : ι → α → E} {f : α → E} (bound : α → ℝ)
(hfs_meas : ∀ᶠ n in l, AEStronglyMeasurable (fs n) μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => fs n a) l (𝓝 (f a))) :
Tendsto (fun n => setToFun μ T hT (fs n)) l (𝓝 <| setToFun μ T hT f) := by
rw [tendsto_iff_seq_tendsto]
intro x xl
have hxl : ∀ s ∈ l, ∃ a, ∀ b ≥ a, x b ∈ s := by rwa [tendsto_atTop'] at xl
have h :
{ x : ι | (fun n => AEStronglyMeasurable (fs n) μ) x } ∩
{ x : ι | (fun n => ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) x } ∈ l :=
inter_mem hfs_meas h_bound
obtain ⟨k, h⟩ := hxl _ h
rw [← tendsto_add_atTop_iff_nat k]
refine tendsto_setToFun_of_dominated_convergence hT bound ?_ bound_integrable ?_ ?_
· exact fun n => (h _ (self_le_add_left _ _)).1
· exact fun n => (h _ (self_le_add_left _ _)).2
· filter_upwards [h_lim]
refine fun a h_lin => @Tendsto.comp _ _ _ (fun n => x (n + k)) (fun n => fs n a) _ _ _ h_lin ?_
rwa [tendsto_add_atTop_iff_nat]
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
theorem continuousWithinAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C)
{fs : X → α → E} {x₀ : X} {bound : α → ℝ} {s : Set X}
(hfs_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousWithinAt (fun x => fs x a) s x₀) :
ContinuousWithinAt (fun x => setToFun μ T hT (fs x)) s x₀ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
theorem continuousAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{x₀ : X} {bound : α → ℝ} (hfs_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousAt (fun x => fs x a) x₀) :
ContinuousAt (fun x => setToFun μ T hT (fs x)) x₀ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
theorem continuousOn_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{bound : α → ℝ} {s : Set X} (hfs_meas : ∀ x ∈ s, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousOn (fun x => fs x a) s) :
ContinuousOn (fun x => setToFun μ T hT (fs x)) s := by
intro x hx
refine continuousWithinAt_setToFun_of_dominated hT ?_ ?_ bound_integrable ?_
· filter_upwards [self_mem_nhdsWithin] with x hx using hfs_meas x hx
· filter_upwards [self_mem_nhdsWithin] with x hx using h_bound x hx
· filter_upwards [h_cont] with a ha using ha x hx
theorem continuous_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{bound : α → ℝ} (hfs_meas : ∀ x, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ x, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, Continuous fun x => fs x a) : Continuous fun x => setToFun μ T hT (fs x) :=
continuous_iff_continuousAt.mpr fun _ =>
continuousAt_setToFun_of_dominated hT (Eventually.of_forall hfs_meas)
(Eventually.of_forall h_bound) ‹_› <|
h_cont.mono fun _ => Continuous.continuousAt
end Function
end MeasureTheory
| Mathlib/MeasureTheory/Integral/SetToL1.lean | 1,790 | 1,799 | |
/-
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.Order.Compact
import Mathlib.Topology.MetricSpace.ProperSpace
import Mathlib.Topology.MetricSpace.Cauchy
import Mathlib.Topology.EMetricSpace.Diam
/-!
## Boundedness in (pseudo)-metric spaces
This file contains one definition, and various results on boundedness in pseudo-metric spaces.
* `Metric.diam s` : The `iSup` of the distances of members of `s`.
Defined in terms of `EMetric.diam`, for better handling of the case when it should be infinite.
* `isBounded_iff_subset_closedBall`: a non-empty set is bounded if and only if
it is included in some closed ball
* describing the cobounded filter, relating to the cocompact filter
* `IsCompact.isBounded`: compact sets are bounded
* `TotallyBounded.isBounded`: totally bounded sets are bounded
* `isCompact_iff_isClosed_bounded`, the **Heine–Borel theorem**:
in a proper space, a set is compact if and only if it is closed and bounded.
* `cobounded_eq_cocompact`: in a proper space, cobounded and compact sets are the same
diameter of a subset, and its relation to boundedness
## Tags
metric, pseudo_metric, bounded, diameter, Heine-Borel theorem
-/
assert_not_exists Basis
open Set Filter Bornology
open scoped ENNReal Uniformity Topology Pointwise
universe u v w
variable {α : Type u} {β : Type v} {X ι : Type*}
variable [PseudoMetricSpace α]
namespace Metric
section Bounded
variable {x : α} {s t : Set α} {r : ℝ}
/-- Closed balls are bounded -/
theorem isBounded_closedBall : IsBounded (closedBall x r) :=
isBounded_iff.2 ⟨r + r, fun y hy z hz =>
calc dist y z ≤ dist y x + dist z x := dist_triangle_right _ _ _
_ ≤ r + r := add_le_add hy hz⟩
/-- Open balls are bounded -/
theorem isBounded_ball : IsBounded (ball x r) :=
isBounded_closedBall.subset ball_subset_closedBall
/-- Spheres are bounded -/
theorem isBounded_sphere : IsBounded (sphere x r) :=
isBounded_closedBall.subset sphere_subset_closedBall
/-- Given a point, a bounded subset is included in some ball around this point -/
theorem isBounded_iff_subset_closedBall (c : α) : IsBounded s ↔ ∃ r, s ⊆ closedBall c r :=
⟨fun h ↦ (isBounded_iff.1 (h.insert c)).imp fun _r hr _x hx ↦ hr (.inr hx) (mem_insert _ _),
fun ⟨_r, hr⟩ ↦ isBounded_closedBall.subset hr⟩
theorem _root_.Bornology.IsBounded.subset_closedBall (h : IsBounded s) (c : α) :
∃ r, s ⊆ closedBall c r :=
(isBounded_iff_subset_closedBall c).1 h
theorem _root_.Bornology.IsBounded.subset_ball_lt (h : IsBounded s) (a : ℝ) (c : α) :
∃ r, a < r ∧ s ⊆ ball c r :=
let ⟨r, hr⟩ := h.subset_closedBall c
⟨max r a + 1, (le_max_right _ _).trans_lt (lt_add_one _), hr.trans <| closedBall_subset_ball <|
(le_max_left _ _).trans_lt (lt_add_one _)⟩
theorem _root_.Bornology.IsBounded.subset_ball (h : IsBounded s) (c : α) : ∃ r, s ⊆ ball c r :=
(h.subset_ball_lt 0 c).imp fun _ ↦ And.right
theorem isBounded_iff_subset_ball (c : α) : IsBounded s ↔ ∃ r, s ⊆ ball c r :=
⟨(IsBounded.subset_ball · c), fun ⟨_r, hr⟩ ↦ isBounded_ball.subset hr⟩
theorem _root_.Bornology.IsBounded.subset_closedBall_lt (h : IsBounded s) (a : ℝ) (c : α) :
∃ r, a < r ∧ s ⊆ closedBall c r :=
let ⟨r, har, hr⟩ := h.subset_ball_lt a c
⟨r, har, hr.trans ball_subset_closedBall⟩
theorem isBounded_closure_of_isBounded (h : IsBounded s) : IsBounded (closure s) :=
let ⟨C, h⟩ := isBounded_iff.1 h
isBounded_iff.2 ⟨C, fun _a ha _b hb => isClosed_Iic.closure_subset <|
map_mem_closure₂ continuous_dist ha hb h⟩
protected theorem _root_.Bornology.IsBounded.closure (h : IsBounded s) : IsBounded (closure s) :=
isBounded_closure_of_isBounded h
@[simp]
theorem isBounded_closure_iff : IsBounded (closure s) ↔ IsBounded s :=
⟨fun h => h.subset subset_closure, fun h => h.closure⟩
theorem hasBasis_cobounded_compl_closedBall (c : α) :
(cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (closedBall c r)ᶜ) :=
⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_closedBall c).trans <| by simp⟩
theorem hasAntitoneBasis_cobounded_compl_closedBall (c : α) :
(cobounded α).HasAntitoneBasis (fun r ↦ (closedBall c r)ᶜ) :=
⟨Metric.hasBasis_cobounded_compl_closedBall _, fun _ _ hr _ ↦ by simpa using hr.trans_lt⟩
theorem hasBasis_cobounded_compl_ball (c : α) :
(cobounded α).HasBasis (fun _ ↦ True) (fun r ↦ (ball c r)ᶜ) :=
⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_ball c).trans <| by simp⟩
theorem hasAntitoneBasis_cobounded_compl_ball (c : α) :
(cobounded α).HasAntitoneBasis (fun r ↦ (ball c r)ᶜ) :=
⟨Metric.hasBasis_cobounded_compl_ball _, fun _ _ hr _ ↦ by simpa using hr.trans⟩
@[simp]
theorem comap_dist_right_atTop (c : α) : comap (dist · c) atTop = cobounded α :=
(atTop_basis.comap _).eq_of_same_basis <| by
simpa only [compl_def, mem_ball, not_lt] using hasBasis_cobounded_compl_ball c
@[simp]
theorem comap_dist_left_atTop (c : α) : comap (dist c) atTop = cobounded α := by
simpa only [dist_comm _ c] using comap_dist_right_atTop c
@[simp]
theorem tendsto_dist_right_atTop_iff (c : α) {f : β → α} {l : Filter β} :
Tendsto (fun x ↦ dist (f x) c) l atTop ↔ Tendsto f l (cobounded α) := by
rw [← comap_dist_right_atTop c, tendsto_comap_iff, Function.comp_def]
@[simp]
theorem tendsto_dist_left_atTop_iff (c : α) {f : β → α} {l : Filter β} :
Tendsto (fun x ↦ dist c (f x)) l atTop ↔ Tendsto f l (cobounded α) := by
simp only [dist_comm c, tendsto_dist_right_atTop_iff]
theorem tendsto_dist_right_cobounded_atTop (c : α) : Tendsto (dist · c) (cobounded α) atTop :=
tendsto_iff_comap.2 (comap_dist_right_atTop c).ge
theorem tendsto_dist_left_cobounded_atTop (c : α) : Tendsto (dist c) (cobounded α) atTop :=
tendsto_iff_comap.2 (comap_dist_left_atTop c).ge
/-- A totally bounded set is bounded -/
theorem _root_.TotallyBounded.isBounded {s : Set α} (h : TotallyBounded s) : IsBounded s :=
-- We cover the totally bounded set by finitely many balls of radius 1,
-- and then argue that a finite union of bounded sets is bounded
let ⟨_t, fint, subs⟩ := (totallyBounded_iff.mp h) 1 zero_lt_one
((isBounded_biUnion fint).2 fun _ _ => isBounded_ball).subset subs
/-- A compact set is bounded -/
theorem _root_.IsCompact.isBounded {s : Set α} (h : IsCompact s) : IsBounded s :=
-- A compact set is totally bounded, thus bounded
h.totallyBounded.isBounded
theorem cobounded_le_cocompact : cobounded α ≤ cocompact α :=
hasBasis_cocompact.ge_iff.2 fun _s hs ↦ hs.isBounded
theorem isCobounded_iff_closedBall_compl_subset {s : Set α} (c : α) :
IsCobounded s ↔ ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s := by
rw [← isBounded_compl_iff, isBounded_iff_subset_closedBall c]
apply exists_congr
intro r
rw [compl_subset_comm]
theorem _root_.Bornology.IsCobounded.closedBall_compl_subset {s : Set α} (hs : IsCobounded s)
(c : α) : ∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s :=
(isCobounded_iff_closedBall_compl_subset c).mp hs
theorem closedBall_compl_subset_of_mem_cocompact {s : Set α} (hs : s ∈ cocompact α) (c : α) :
∃ (r : ℝ), (Metric.closedBall c r)ᶜ ⊆ s :=
IsCobounded.closedBall_compl_subset (cobounded_le_cocompact hs) c
theorem mem_cocompact_of_closedBall_compl_subset [ProperSpace α] (c : α)
(h : ∃ r, (closedBall c r)ᶜ ⊆ s) : s ∈ cocompact α := by
rcases h with ⟨r, h⟩
rw [Filter.mem_cocompact]
exact ⟨closedBall c r, isCompact_closedBall c r, h⟩
theorem mem_cocompact_iff_closedBall_compl_subset [ProperSpace α] (c : α) :
s ∈ cocompact α ↔ ∃ r, (closedBall c r)ᶜ ⊆ s :=
⟨(closedBall_compl_subset_of_mem_cocompact · _), mem_cocompact_of_closedBall_compl_subset _⟩
/-- Characterization of the boundedness of the range of a function -/
theorem isBounded_range_iff {f : β → α} : IsBounded (range f) ↔ ∃ C, ∀ x y, dist (f x) (f y) ≤ C :=
isBounded_iff.trans <| by simp only [forall_mem_range]
theorem isBounded_image_iff {f : β → α} {s : Set β} :
IsBounded (f '' s) ↔ ∃ C, ∀ x ∈ s, ∀ y ∈ s, dist (f x) (f y) ≤ C :=
isBounded_iff.trans <| by simp only [forall_mem_image]
theorem isBounded_range_of_tendsto_cofinite_uniformity {f : β → α}
(hf : Tendsto (Prod.map f f) (.cofinite ×ˢ .cofinite) (𝓤 α)) : IsBounded (range f) := by
rcases (hasBasis_cofinite.prod_self.tendsto_iff uniformity_basis_dist).1 hf 1 zero_lt_one with
⟨s, hsf, hs1⟩
rw [← image_union_image_compl_eq_range]
refine (hsf.image f).isBounded.union (isBounded_image_iff.2 ⟨1, fun x hx y hy ↦ ?_⟩)
exact le_of_lt (hs1 (x, y) ⟨hx, hy⟩)
theorem isBounded_range_of_cauchy_map_cofinite {f : β → α} (hf : Cauchy (map f cofinite)) :
IsBounded (range f) :=
isBounded_range_of_tendsto_cofinite_uniformity <| (cauchy_map_iff.1 hf).2
theorem _root_.CauchySeq.isBounded_range {f : ℕ → α} (hf : CauchySeq f) : IsBounded (range f) :=
isBounded_range_of_cauchy_map_cofinite <| by rwa [Nat.cofinite_eq_atTop]
theorem isBounded_range_of_tendsto_cofinite {f : β → α} {a : α} (hf : Tendsto f cofinite (𝓝 a)) :
IsBounded (range f) :=
isBounded_range_of_tendsto_cofinite_uniformity <|
(hf.prodMap hf).mono_right <| nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)
/-- In a compact space, all sets are bounded -/
theorem isBounded_of_compactSpace [CompactSpace α] : IsBounded s :=
isCompact_univ.isBounded.subset (subset_univ _)
theorem isBounded_range_of_tendsto (u : ℕ → α) {x : α} (hu : Tendsto u atTop (𝓝 x)) :
IsBounded (range u) :=
hu.cauchySeq.isBounded_range
theorem disjoint_nhds_cobounded (x : α) : Disjoint (𝓝 x) (cobounded α) :=
disjoint_of_disjoint_of_mem disjoint_compl_right (ball_mem_nhds _ one_pos) isBounded_ball
theorem disjoint_cobounded_nhds (x : α) : Disjoint (cobounded α) (𝓝 x) :=
(disjoint_nhds_cobounded x).symm
theorem disjoint_nhdsSet_cobounded {s : Set α} (hs : IsCompact s) : Disjoint (𝓝ˢ s) (cobounded α) :=
hs.disjoint_nhdsSet_left.2 fun _ _ ↦ disjoint_nhds_cobounded _
theorem disjoint_cobounded_nhdsSet {s : Set α} (hs : IsCompact s) : Disjoint (cobounded α) (𝓝ˢ s) :=
(disjoint_nhdsSet_cobounded hs).symm
theorem exists_isBounded_image_of_tendsto {α β : Type*} [PseudoMetricSpace β]
{l : Filter α} {f : α → β} {x : β} (hf : Tendsto f l (𝓝 x)) :
∃ s ∈ l, IsBounded (f '' s) :=
(l.basis_sets.map f).disjoint_iff_left.mp <| (disjoint_nhds_cobounded x).mono_left hf
/-- If a function is continuous within a set `s` at every point of a compact set `k`, then it is
bounded on some open neighborhood of `k` in `s`. -/
theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt
[TopologicalSpace β] {k s : Set β} {f : β → α} (hk : IsCompact k)
(hf : ∀ x ∈ k, ContinuousWithinAt f s x) :
∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := by
have : Disjoint (𝓝ˢ k ⊓ 𝓟 s) (comap f (cobounded α)) := by
rw [disjoint_assoc, inf_comm, hk.disjoint_nhdsSet_left]
exact fun x hx ↦ disjoint_left_comm.2 <|
tendsto_comap.disjoint (disjoint_cobounded_nhds _) (hf x hx)
rcases ((((hasBasis_nhdsSet _).inf_principal _)).disjoint_iff ((basis_sets _).comap _)).1 this
with ⟨U, ⟨hUo, hkU⟩, t, ht, hd⟩
refine ⟨U, hkU, hUo, (isBounded_compl_iff.2 ht).subset ?_⟩
rwa [image_subset_iff, preimage_compl, subset_compl_iff_disjoint_right]
/-- If a function is continuous at every point of a compact set `k`, then it is bounded on
some open neighborhood of `k`. -/
theorem exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt [TopologicalSpace β]
{k : Set β} {f : β → α} (hk : IsCompact k) (hf : ∀ x ∈ k, ContinuousAt f x) :
∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) := by
simp_rw [← continuousWithinAt_univ] at hf
simpa only [inter_univ] using
exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk hf
/-- If a function is continuous on a set `s` containing a compact set `k`, then it is bounded on
some open neighborhood of `k` in `s`. -/
theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_continuousOn [TopologicalSpace β]
{k s : Set β} {f : β → α} (hk : IsCompact k) (hks : k ⊆ s) (hf : ContinuousOn f s) :
∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) :=
exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk fun x hx =>
hf x (hks hx)
/-- If a function is continuous on a neighborhood of a compact set `k`, then it is bounded on
some open neighborhood of `k`. -/
theorem exists_isOpen_isBounded_image_of_isCompact_of_continuousOn [TopologicalSpace β]
{k s : Set β} {f : β → α} (hk : IsCompact k) (hs : IsOpen s) (hks : k ⊆ s)
(hf : ContinuousOn f s) : ∃ t, k ⊆ t ∧ IsOpen t ∧ IsBounded (f '' t) :=
exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt hk fun _x hx =>
hf.continuousAt (hs.mem_nhds (hks hx))
/-- The **Heine–Borel theorem**: In a proper space, a closed bounded set is compact. -/
theorem isCompact_of_isClosed_isBounded [ProperSpace α] (hc : IsClosed s) (hb : IsBounded s) :
IsCompact s := by
| rcases eq_empty_or_nonempty s with (rfl | ⟨x, -⟩)
· exact isCompact_empty
· rcases hb.subset_closedBall x with ⟨r, hr⟩
exact (isCompact_closedBall x r).of_isClosed_subset hc hr
/-- The **Heine–Borel theorem**: In a proper space, the closure of a bounded set is compact. -/
| Mathlib/Topology/MetricSpace/Bounded.lean | 278 | 283 |
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Group.Fin.Tuple
import Mathlib.Data.Finset.NatAntidiagonal
import Mathlib.Order.Fin.Tuple
/-!
# Collections of tuples of naturals with the same sum
This file generalizes `List.Nat.Antidiagonal n`, `Multiset.Nat.Antidiagonal n`, and
`Finset.Nat.Antidiagonal n` from the pair of elements `x : ℕ × ℕ` such that `n = x.1 + x.2`, to
the sequence of elements `x : Fin k → ℕ` such that `n = ∑ i, x i`.
## Main definitions
* `List.Nat.antidiagonalTuple`
* `Multiset.Nat.antidiagonalTuple`
* `Finset.Nat.antidiagonalTuple`
## Main results
* `antidiagonalTuple 2 n` is analogous to `antidiagonal n`:
* `List.Nat.antidiagonalTuple_two`
* `Multiset.Nat.antidiagonalTuple_two`
* `Finset.Nat.antidiagonalTuple_two`
## Implementation notes
While we could implement this by filtering `(Fintype.PiFinset fun _ ↦ range (n + 1))` or similar,
this implementation would be much slower.
In the future, we could consider generalizing `Finset.Nat.antidiagonalTuple` further to
support finitely-supported functions, as is done with `cut` in
`archive/100-theorems-list/45_partition.lean`.
-/
/-! ### Lists -/
namespace List.Nat
/-- `List.antidiagonalTuple k n` is a list of all `k`-tuples which sum to `n`.
This list contains no duplicates (`List.Nat.nodup_antidiagonalTuple`), and is sorted
lexicographically (`List.Nat.antidiagonalTuple_pairwise_pi_lex`), starting with `![0, ..., n]`
and ending with `![n, ..., 0]`.
```
#eval antidiagonalTuple 3 2
-- [![0, 0, 2], ![0, 1, 1], ![0, 2, 0], ![1, 0, 1], ![1, 1, 0], ![2, 0, 0]]
```
-/
def antidiagonalTuple : ∀ k, ℕ → List (Fin k → ℕ)
| 0, 0 => [![]]
| 0, _ + 1 => []
| k + 1, n =>
(List.Nat.antidiagonal n).flatMap fun ni =>
(antidiagonalTuple k ni.2).map fun x => Fin.cons ni.1 x
@[simp]
theorem antidiagonalTuple_zero_zero : antidiagonalTuple 0 0 = [![]] :=
rfl
@[simp]
theorem antidiagonalTuple_zero_succ (n : ℕ) : antidiagonalTuple 0 (n + 1) = [] :=
rfl
theorem mem_antidiagonalTuple {n : ℕ} {k : ℕ} {x : Fin k → ℕ} :
x ∈ antidiagonalTuple k n ↔ ∑ i, x i = n := by
induction x using Fin.consInduction generalizing n with
| h0 =>
cases n
· decide
· simp [eq_comm]
| h x₀ x ih =>
simp_rw [Fin.sum_cons, antidiagonalTuple, List.mem_flatMap, List.mem_map,
List.Nat.mem_antidiagonal, Fin.cons_inj, exists_eq_right_right, ih,
@eq_comm _ _ (Prod.snd _), and_comm (a := Prod.snd _ = _),
← Prod.mk_inj (a₁ := Prod.fst _), exists_eq_right]
/-- The antidiagonal of `n` does not contain duplicate entries. -/
theorem nodup_antidiagonalTuple (k n : ℕ) : List.Nodup (antidiagonalTuple k n) := by
induction' k with k ih generalizing n
· cases n
· simp
· simp [eq_comm]
simp_rw [antidiagonalTuple, List.nodup_flatMap]
| constructor
· intro i _
exact (ih i.snd).map (Fin.cons_right_injective (α := fun _ => ℕ) i.fst)
induction' n with n n_ih
· exact List.pairwise_singleton _ _
· rw [List.Nat.antidiagonal_succ]
refine List.Pairwise.cons (fun a ha x hx₁ hx₂ => ?_) (n_ih.map _ fun a b h x hx₁ hx₂ => ?_)
· rw [List.mem_map] at hx₁ hx₂ ha
obtain ⟨⟨a, -, rfl⟩, ⟨x₁, -, rfl⟩, ⟨x₂, -, h⟩⟩ := ha, hx₁, hx₂
rw [Fin.cons_inj] at h
injection h.1
· rw [List.mem_map] at hx₁ hx₂
obtain ⟨⟨x₁, hx₁, rfl⟩, ⟨x₂, hx₂, h₁₂⟩⟩ := hx₁, hx₂
dsimp at h₁₂
rw [Fin.cons_inj, Nat.succ_inj] at h₁₂
obtain ⟨h₁₂, rfl⟩ := h₁₂
rw [Function.onFun, h₁₂] at h
exact h (List.mem_map_of_mem hx₁) (List.mem_map_of_mem hx₂)
theorem antidiagonalTuple_zero_right : ∀ k, antidiagonalTuple k 0 = [0]
| 0 => (congr_arg fun x => [x]) <| Subsingleton.elim _ _
| k + 1 => by
rw [antidiagonalTuple, antidiagonal_zero, List.flatMap_singleton,
antidiagonalTuple_zero_right k, List.map_singleton]
| Mathlib/Data/Fin/Tuple/NatAntidiagonal.lean | 94 | 117 |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Module.BigOperators
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Squarefree
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Tactic.ArithMult
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `IsMultiplicative` when `x.Coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function (spelled `moebius` in code).
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero`
* And variants that apply when the equalities only hold on a set `S : Set ℕ` such that
`m ∣ n → n ∈ S → m ∈ S`:
* `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero`
## Notation
All notation is localized in the namespace `ArithmeticFunction`.
The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names.
In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`,
`ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`,
`ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`,
to allow for selective access to these notations.
The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation
`∏ᵖ p ∣ n, f p` when applied to `n`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open Finset
open Nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by
Dirichlet convolution. -/
def ArithmeticFunction [Zero R] :=
ZeroHom ℕ R
instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) :=
inferInstanceAs (Zero (ZeroHom ℕ R))
instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R))
variable {R}
namespace ArithmeticFunction
section Zero
variable [Zero R]
instance : FunLike (ArithmeticFunction R) ℕ R :=
inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R)
@[simp]
theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl
@[simp]
theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _
(ZeroHom.mk f hf) = f := rfl
@[simp]
theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 :=
ZeroHom.map_zero' f
theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[simp]
theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 :=
ZeroHom.zero_apply x
@[ext]
theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g :=
ZeroHom.ext h
section One
variable [One R]
instance one : One (ArithmeticFunction R) :=
⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩
theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 :=
rfl
@[simp]
theorem one_one : (1 : ArithmeticFunction R) 1 = 1 :=
rfl
@[simp]
theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 :=
if_neg h
end One
end Zero
/-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline
this in `natCoe` because it gets unfolded too much. -/
@[coe]
def natToArithmeticFunction [AddMonoidWithOne R] :
(ArithmeticFunction ℕ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) :=
⟨natToArithmeticFunction⟩
@[simp]
theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f :=
ext fun _ => cast_id _
@[simp]
theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x :=
rfl
/-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline
this in `intCoe` because it gets unfolded too much. -/
@[coe]
def ofInt [AddGroupWithOne R] :
(ArithmeticFunction ℤ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) :=
⟨ofInt⟩
@[simp]
theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f :=
ext fun _ => Int.cast_id
@[simp]
theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x := rfl
@[simp]
theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} :
((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by
ext
simp
@[simp]
theorem natCoe_one [AddMonoidWithOne R] :
((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
@[simp]
theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) :
ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
section AddMonoid
variable [AddMonoid R]
instance add : Add (ArithmeticFunction R) :=
⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩
@[simp]
theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n :=
rfl
instance instAddMonoid : AddMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.zero R,
ArithmeticFunction.add with
add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _
zero_add := fun _ => ext fun _ => zero_add _
add_zero := fun _ => ext fun _ => add_zero _
nsmul := nsmulRec }
end AddMonoid
instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid,
ArithmeticFunction.one with
natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩
natCast_zero := by ext; simp
natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] }
instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ }
instance [NegZeroClass R] : Neg (ArithmeticFunction R) where
neg f := ⟨fun n => -f n, by simp⟩
instance [AddGroup R] : AddGroup (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with
neg_add_cancel := fun _ => ext fun _ => neg_add_cancel _
zsmul := zsmulRec }
instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) :=
{ show AddGroup (ArithmeticFunction R) by infer_instance with
add_comm := fun _ _ ↦ add_comm _ _ }
section SMul
variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) :=
⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} :
(f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd :=
rfl
end SMul
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [Semiring R] : Mul (ArithmeticFunction R) :=
⟨(· • ·)⟩
@[simp]
theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} :
(f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd :=
rfl
theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp
@[simp, norm_cast]
theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} :
(↑(f * g) : ArithmeticFunction R) = f * g := by
ext n
simp
@[simp, norm_cast]
theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} :
(↑(f * g) : ArithmeticFunction R) = ↑f * g := by
ext n
simp
section Module
variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :
(f * g) • h = f • g • h := by
ext n
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc)
theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff]
simp [y1ne]
end Module
section Semiring
variable [Semiring R]
instance instMonoid : Monoid (ArithmeticFunction R) :=
{ one := One.one
mul := Mul.mul
one_mul := one_smul'
mul_one := fun f => by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro ⟨y₁, y₂⟩ ymem ynmem
have y2ne : y₂ ≠ 1 := by
intro con
simp_all
simp [y2ne]
mul_assoc := mul_smul' }
instance instSemiring : Semiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoidWithOne,
ArithmeticFunction.instMonoid,
ArithmeticFunction.instAddCommMonoid with
zero_mul := fun f => by
ext
simp
mul_zero := fun f => by
ext
simp
left_distrib := fun a b c => by
ext
simp [← sum_add_distrib, mul_add]
right_distrib := fun a b c => by
ext
simp [← sum_add_distrib, add_mul] }
end Semiring
instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
mul_comm := fun f g => by
ext
rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map]
simp [mul_comm] }
instance [CommRing R] : CommRing (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
neg_add_cancel := neg_add_cancel
mul_comm := mul_comm
zsmul := (· • ·) }
instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] :
Module (ArithmeticFunction R) (ArithmeticFunction M) where
one_smul := one_smul'
mul_smul := mul_smul'
smul_add r x y := by
ext
simp only [sum_add_distrib, smul_add, smul_apply, add_apply]
smul_zero r := by
ext
simp only [smul_apply, sum_const_zero, smul_zero, zero_apply]
add_smul r s x := by
ext
simp only [add_smul, sum_add_distrib, smul_apply, add_apply]
zero_smul r := by
ext
simp only [smul_apply, sum_const_zero, zero_smul, zero_apply]
section Zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/
def zeta : ArithmeticFunction ℕ :=
⟨fun x => ite (x = 0) 0 1, rfl⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta
@[simp]
theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 :=
rfl
theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 :=
if_neg h
-- Porting note: removed `@[simp]`, LHS not in normal form
theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [MulAction R M]
{f : ArithmeticFunction M} {x : ℕ} :
((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by
rw [smul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.snd
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul]
· rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(↑ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply
theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_zeta_mul_apply]
theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_mul_zeta_apply]
end Zeta
open ArithmeticFunction
section Pmul
/-- This is the pointwise product of `ArithmeticFunction`s. -/
def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun x => f x * g x, by simp⟩
@[simp]
theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x :=
rfl
theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by
ext
simp [mul_comm]
lemma pmul_assoc [SemigroupWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) :
pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by
ext
simp only [pmul_apply, mul_assoc]
section NonAssocSemiring
variable [NonAssocSemiring R]
@[simp]
theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
@[simp]
theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
end NonAssocSemiring
variable [Semiring R]
/-- This is the pointwise power of `ArithmeticFunction`s. -/
def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R :=
if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩
@[simp]
theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl]
@[simp]
theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by
rw [ppow, dif_neg (Nat.ne_of_gt kpos), coe_mk]
theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ']
induction k <;> simp
theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ]
induction k <;> simp
end Pmul
section Pdiv
/-- This is the pointwise division of `ArithmeticFunction`s. -/
def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩
@[simp]
theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) :
pdiv f g n = f n / g n := rfl
/-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes
values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/
@[simp]
theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) :
pdiv f zeta = f := by
ext n
cases n <;> simp [succ_ne_zero]
end Pdiv
section ProdPrimeFactors
/-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/
def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where
toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p
map_zero' := if_pos rfl
open Batteries.ExtendedBinder
/-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/
scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term
scoped macro_rules (kind := bigproddvd)
| `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n)
@[simp]
theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) :
∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p :=
if_neg hn
end ProdPrimeFactors
/-- Multiplicative functions -/
def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop :=
f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n
namespace IsMultiplicative
section MonoidWithZero
variable [MonoidWithZero R]
@[simp, arith_mult]
theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 :=
h.1
@[simp]
theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ}
(h : m.Coprime n) : f (m * n) = f m * f n :=
hf.2 h
end MonoidWithZero
open scoped Function in -- required for scoped `on` notation
theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) :
f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by
classical
induction s using Finset.induction_on with
| empty => simp [hf]
| insert _ _ has ih =>
rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs
rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1]
exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm
theorem map_prod_of_prime [CommMonoidWithZero R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f)
(t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy
theorem map_prod_of_subset_primeFactors [CommMonoidWithZero R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ)
(t : Finset ℕ) (ht : t ⊆ l.primeFactors) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a)
theorem map_div_of_coprime [GroupWithZero R] {f : ArithmeticFunction R}
(hf : IsMultiplicative f) {l d : ℕ} (hdl : d ∣ l) (hl : (l / d).Coprime d) (hd : f d ≠ 0) :
f (l / d) = f l / f d := by
apply (div_eq_of_eq_mul hd ..).symm
rw [← hf.right hl, Nat.div_mul_cancel hdl]
@[arith_mult]
theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[arith_mult]
theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
@[arith_mult]
theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by
refine ⟨by simp [hf.1, hg.1], ?_⟩
simp only [mul_apply]
intro m n cop
rw [sum_mul_sum, ← sum_product']
symm
apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l)
· rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h
simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne]
constructor
· ring
rw [Nat.mul_eq_zero] at *
apply not_or_intro ha hb
· simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk_inj]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h
simp only [Prod.mk_inj] at h
ext <;> dsimp only
· trans Nat.gcd (a1 * a2) (a1 * b1)
· rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.1, Nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· trans Nat.gcd (a1 * a2) (a2 * b2)
· rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a1 * b1)
· rw [mul_comm, Nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a2 * b2)
· rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one,
one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.2, Nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul]
· simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product,
Set.mem_image, exists_prop, Prod.mk_inj]
rintro ⟨b1, b2⟩ h
dsimp at h
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n))
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _]
· rw [Nat.mul_eq_zero, not_or] at h
simp [h.2.1, h.2.2]
rw [mul_comm n m, h.1]
· simp only [mem_divisorsAntidiagonal, Ne, mem_product]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
dsimp only
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right]
ring
@[arith_mult]
theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop]
ring⟩
@[arith_mult]
theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f)
(hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop,
div_eq_mul_inv, mul_inv]
apply mul_mul_mul_comm ⟩
/-- For any multiplicative function `f` and any `n > 0`,
we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/
theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) :
f n = n.factorization.prod fun p k => f (p ^ k) :=
Nat.multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn
/-- A recapitulation of the definition of multiplicative that is simpler for proofs -/
theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} :
IsMultiplicative f ↔
f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by
refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩)
rcases eq_or_ne m 0 with (rfl | hm)
· simp
rcases eq_or_ne n 0 with (rfl | hn)
· simp
exact h hm hn hmn
/-- Two multiplicative functions `f` and `g` are equal if and only if
they agree on prime powers -/
theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) :
f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by
constructor
· intro h p i _
rw [h]
intro h
ext n
by_cases hn : n = 0
· rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero]
rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn]
exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp)
@[arith_mult]
theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) :
IsMultiplicative (prodPrimeFactors f) := by
rw [iff_ne_zero]
simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one,
prod_empty, true_and]
intro x y hx hy hxy
have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy
rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy,
Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors]
theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R}
(hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) :
∏ᵖ p ∣ n, (f + g) p = (f * g) n := by
rw [prodPrimeFactors_apply hn.ne_zero]
simp_rw [add_apply (f := f) (g := g)]
rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·),
← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero,
factors_eq]
apply Finset.sum_congr rfl
intro t ht
rw [t.prod_val, Function.id_def,
← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht),
hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht),
← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset]
theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} :
f (x.lcm y) * f (x.gcd y) = f x * f y := by
by_cases hx : x = 0
· simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left]
by_cases hy : y = 0
· simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul]
have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx
have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy
have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by
intro i; rw [Nat.pow_zero, hf.1]
iterate 4 rw [hf.multiplicative_factorization f (by assumption),
Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero)
(s := (x.primeFactors ∪ y.primeFactors))]
· rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro p _
rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;>
simp only [factorization_lcm hx hy, Finsupp.sup_apply, h, sup_of_le_right,
sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply,
inf_of_le_left, mul_comm]
· apply Finset.subset_union_right
· apply Finset.subset_union_left
· rw [factorization_gcd hx hy, Finsupp.support_inf]
apply Finset.inter_subset_union
· simp [factorization_lcm hx hy]
theorem map_gcd [CommGroupWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} (hf_lcm : f (x.lcm y) ≠ 0) :
f (x.gcd y) = f x * f y / f (x.lcm y) := by
rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_left₀ _ hf_lcm]
theorem map_lcm [CommGroupWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} (hf_gcd : f (x.gcd y) ≠ 0) :
f (x.lcm y) = f x * f y / f (x.gcd y) := by
rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_right₀ _ hf_gcd]
theorem eq_zero_of_squarefree_of_dvd_eq_zero [MonoidWithZero R] {f : ArithmeticFunction R}
(hf : IsMultiplicative f) {m n : ℕ} (hn : Squarefree n) (hmn : m ∣ n)
(h_zero : f m = 0) :
f n = 0 := by
rcases hmn with ⟨k, rfl⟩
simp only [MulZeroClass.zero_mul, eq_self_iff_true, hf.map_mul_of_coprime
(coprime_of_squarefree_mul hn), h_zero]
end IsMultiplicative
section SpecialFunctions
/-- The identity on `ℕ` as an `ArithmeticFunction`. -/
def id : ArithmeticFunction ℕ :=
⟨_root_.id, rfl⟩
@[simp]
theorem id_apply {x : ℕ} : id x = x :=
rfl
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : ArithmeticFunction ℕ :=
id.ppow k
@[simp]
theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by
cases k <;> simp [pow]
theorem pow_zero_eq_zeta : pow 0 = ζ := by
ext n
simp
/-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/
def sigma (k : ℕ) : ArithmeticFunction ℕ :=
⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma
@[inherit_doc]
scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma
theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k :=
rfl
theorem sigma_apply_prime_pow {k p i : ℕ} (hp : p.Prime) :
σ k (p ^ i) = ∑ j ∈ .range (i + 1), p ^ (j * k) := by
simp [sigma_apply, divisors_prime_pow hp, Nat.pow_mul]
theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply]
theorem sigma_one_apply_prime_pow {p i : ℕ} (hp : p.Prime) :
σ 1 (p ^ i) = ∑ k ∈ .range (i + 1), p ^ k := by
simp [sigma_apply_prime_pow hp]
theorem sigma_zero_apply (n : ℕ) : σ 0 n = #n.divisors := by simp [sigma_apply]
theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by
simp [sigma_apply_prime_pow hp]
theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by
ext
rw [sigma, zeta_mul_apply]
apply sum_congr rfl
intro x hx
rw [pow_apply, if_neg (not_and_of_not_right _ _)]
contrapose! hx
simp [hx]
@[arith_mult]
theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) :=
IsMultiplicative.iff_ne_zero.2
⟨by simp, by
intro m n hm _hn hmn
rcases eq_or_ne m 1 with (rfl | hm')
· simp
rw [one_apply_ne, one_apply_ne hm', zero_mul]
rw [Ne, mul_eq_one, not_and_or]
exact Or.inl hm'⟩
@[arith_mult]
theorem isMultiplicative_zeta : IsMultiplicative ζ :=
IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp +contextual⟩
@[arith_mult]
theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id :=
⟨rfl, fun {_ _} _ => rfl⟩
@[arith_mult]
theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative)
{k : ℕ} : IsMultiplicative (f.ppow k) := by
induction k with
| zero => exact isMultiplicative_zeta.natCast
| succ k hi => rw [ppow_succ']; apply hf.pmul hi
@[arith_mult]
theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) :=
isMultiplicative_id.ppow
@[arith_mult]
theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by
rw [← zeta_mul_pow_eq_sigma]
apply isMultiplicative_zeta.mul isMultiplicative_pow
/-- `Ω n` is the number of prime factors of `n`. -/
def cardFactors : ArithmeticFunction ℕ :=
⟨fun n => n.primeFactorsList.length, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors
@[inherit_doc]
scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors
theorem cardFactors_apply {n : ℕ} : Ω n = n.primeFactorsList.length :=
rfl
lemma cardFactors_zero : Ω 0 = 0 := by simp
@[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply]
@[simp]
theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by
refine ⟨fun h => ?_, fun h => List.length_eq_one_iff.2 ⟨n, primeFactorsList_prime h⟩⟩
cases n with | zero => simp at h | succ n =>
rcases List.length_eq_one_iff.1 h with ⟨x, hx⟩
rw [← prod_primeFactorsList n.add_one_ne_zero, hx, List.prod_singleton]
apply prime_of_mem_primeFactorsList
rw [hx, List.mem_singleton]
theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by
rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq,
UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq,
Multiset.card_add, Multiset.coe_card, Multiset.coe_card]
theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) :
Ω s.prod = (Multiset.map Ω s).sum := by
induction s using Multiset.induction_on with
| empty => simp
| cons ih => simp_all [cardFactors_mul, not_or]
@[simp]
theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 :=
cardFactors_eq_one_iff_prime.2 hp
@[simp]
theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by
rw [cardFactors_apply, hp.primeFactorsList_pow, List.length_replicate]
/-- `ω n` is the number of distinct prime factors of `n`. -/
def cardDistinctFactors : ArithmeticFunction ℕ :=
⟨fun n => n.primeFactorsList.dedup.length, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors
@[inherit_doc]
scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors
theorem cardDistinctFactors_zero : ω 0 = 0 := by simp
@[simp]
theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors]
theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.primeFactorsList.dedup.length :=
rfl
theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) :
ω n = Ω n ↔ Squarefree n := by
rw [squarefree_iff_nodup_primeFactorsList h0, cardDistinctFactors_apply]
constructor <;> intro h
· rw [← n.primeFactorsList.dedup_sublist.eq_of_length h]
apply List.nodup_dedup
· simp [h.dedup, cardFactors]
@[simp]
theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
ω (p ^ k) = 1 := by
rw [cardDistinctFactors_apply, hp.primeFactorsList_pow, List.replicate_dedup hk,
List.length_singleton]
@[simp]
theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by
rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero]
/-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors,
`μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`.
If `n` is not squarefree, `μ n = 0`. -/
def moebius : ArithmeticFunction ℤ :=
⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius
@[inherit_doc]
scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius
@[simp]
theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n :=
if_pos h
@[simp]
theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 :=
if_neg h
theorem moebius_apply_one : μ 1 = 1 := by simp
theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by
constructor <;> intro h
· contrapose! h
simp [h]
· simp [h, pow_ne_zero]
theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by
simp only [moebius, coe_mk]
split_ifs
· right
exact neg_one_pow_eq_or ..
· left
rfl
theorem moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 := by
have := moebius_eq_or n
aesop
theorem moebius_sq_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : μ l ^ 2 = 1 := by
rw [moebius_apply_of_squarefree hl, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]
theorem abs_moebius_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : |μ l| = 1 := by
simp only [moebius_apply_of_squarefree hl, abs_pow, abs_neg, abs_one, one_pow]
theorem moebius_sq {n : ℕ} :
μ n ^ 2 = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact moebius_sq_eq_one_of_squarefree h
· simp only [pow_eq_zero_iff, moebius_eq_zero_of_not_squarefree h,
zero_pow (show 2 ≠ 0 by norm_num)]
theorem abs_moebius {n : ℕ} :
|μ n| = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact abs_moebius_eq_one_of_squarefree h
· simp only [moebius_eq_zero_of_not_squarefree h, abs_zero]
theorem abs_moebius_le_one {n : ℕ} : |μ n| ≤ 1 := by
rw [abs_moebius, apply_ite (· ≤ 1)]
simp
theorem moebius_apply_prime {p : ℕ} (hp : p.Prime) : μ p = -1 := by
rw [moebius_apply_of_squarefree hp.squarefree, cardFactors_apply_prime hp, pow_one]
theorem moebius_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
μ (p ^ k) = if k = 1 then -1 else 0 := by
split_ifs with h
· rw [h, pow_one, moebius_apply_prime hp]
rw [moebius_eq_zero_of_not_squarefree]
rw [squarefree_pow_iff hp.ne_one hk, not_and_or]
exact Or.inr h
theorem moebius_apply_isPrimePow_not_prime {n : ℕ} (hn : IsPrimePow n) (hn' : ¬n.Prime) :
μ n = 0 := by
obtain ⟨p, k, hp, hk, rfl⟩ := (isPrimePow_nat_iff _).1 hn
rw [moebius_apply_prime_pow hp hk.ne', if_neg]
rintro rfl
exact hn' (by simpa)
@[arith_mult]
theorem isMultiplicative_moebius : IsMultiplicative μ := by
rw [IsMultiplicative.iff_ne_zero]
refine ⟨by simp, fun {n m} hn hm hnm => ?_⟩
simp only [moebius, ZeroHom.coe_mk, coe_mk, ZeroHom.toFun_eq_coe, Eq.ndrec, ZeroHom.coe_mk,
IsUnit.mul_iff, Nat.isUnit_iff, squarefree_mul hnm, ite_zero_mul_ite_zero,
cardFactors_mul hn hm, pow_add]
theorem IsMultiplicative.prodPrimeFactors_one_add_of_squarefree [CommSemiring R]
{f : ArithmeticFunction R} (h_mult : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 + f p) = ∑ d ∈ n.divisors, f d := by
trans (∏ᵖ p ∣ n, ((ζ : ArithmeticFunction R) + f) p)
· simp_rw [prodPrimeFactors_apply hn.ne_zero, add_apply, natCoe_apply]
apply Finset.prod_congr rfl; intro p hp
rw [zeta_apply_ne (prime_of_mem_primeFactorsList <| List.mem_toFinset.mp hp).ne_zero, cast_one]
rw [isMultiplicative_zeta.natCast.prodPrimeFactors_add_of_squarefree h_mult hn,
coe_zeta_mul_apply]
theorem IsMultiplicative.prodPrimeFactors_one_sub_of_squarefree [CommRing R]
(f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 - f p) = ∑ d ∈ n.divisors, μ d * f d := by
trans (∏ p ∈ n.primeFactors, (1 + (ArithmeticFunction.pmul (μ : ArithmeticFunction R) f) p))
· apply Finset.prod_congr rfl; intro p hp
rw [pmul_apply, intCoe_apply, ArithmeticFunction.moebius_apply_prime
(prime_of_mem_primeFactorsList (List.mem_toFinset.mp hp))]
ring
· rw [(isMultiplicative_moebius.intCast.pmul hf).prodPrimeFactors_one_add_of_squarefree hn]
simp_rw [pmul_apply, intCoe_apply]
open UniqueFactorizationMonoid
@[simp]
theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
ext n
refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n
· intro p n hp hn
rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ']
simp_rw [Nat.pow_zero, moebius_apply_one,
moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj, sum_ite_eq', mem_range,
if_pos hn, neg_add_cancel]
rw [one_apply_ne]
rw [Ne, pow_eq_one_iff]
· exact hp.ne_one
· exact hn.ne'
· rw [ZeroHom.map_zero, ZeroHom.map_zero]
· simp
· intro a b _ha _hb hab ha' hb'
rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb',
IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab]
exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast
@[simp]
theorem coe_zeta_mul_moebius : (ζ * μ : ArithmeticFunction ℤ) = 1 := by
rw [mul_comm, moebius_mul_coe_zeta]
@[simp]
theorem coe_moebius_mul_coe_zeta [Ring R] : (μ * ζ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, moebius_mul_coe_zeta, intCoe_one]
@[simp]
theorem coe_zeta_mul_coe_moebius [Ring R] : (ζ * μ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, coe_zeta_mul_moebius, intCoe_one]
section CommRing
variable [CommRing R]
instance : Invertible (ζ : ArithmeticFunction R) where
invOf := μ
invOf_mul_self := coe_moebius_mul_coe_zeta
mul_invOf_self := coe_zeta_mul_coe_moebius
/-- A unit in `ArithmeticFunction R` that evaluates to `ζ`, with inverse `μ`. -/
def zetaUnit : (ArithmeticFunction R)ˣ :=
⟨ζ, μ, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta⟩
@[simp]
theorem coe_zetaUnit : ((zetaUnit : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = ζ :=
rfl
@[simp]
theorem inv_zetaUnit : ((zetaUnit⁻¹ : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = μ :=
rfl
end CommRing
/-- Möbius inversion for functions to an `AddCommGroup`. -/
theorem sum_eq_iff_sum_smul_moebius_eq [AddCommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd = f n := by
let f' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else f x, if_pos rfl⟩
let g' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else g x, if_pos rfl⟩
trans (ζ : ArithmeticFunction ℤ) • f' = g'
· rw [ArithmeticFunction.ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
rw [coe_zeta_smul_apply]
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, ZeroHom.coe_mk]
simp only [f', g', coe_mk, succ_ne_zero, ite_false]
rw [sum_congr rfl fun x hx => ?_]
rw [if_neg (Nat.pos_of_mem_divisors hx).ne']
trans μ • g' = f'
· constructor <;> intro h
· rw [← h, ← mul_smul, moebius_mul_coe_zeta, one_smul]
· rw [← h, ← mul_smul, coe_zeta_mul_moebius, one_smul]
· rw [ArithmeticFunction.ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
simp only [forall_prop_of_true, succ_pos', smul_apply, f', g', coe_mk, succ_ne_zero,
ite_false]
rw [sum_congr rfl fun x hx => ?_]
simp [if_neg (Nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)).ne']
/-- Möbius inversion for functions to a `Ring`. -/
theorem sum_eq_iff_sum_mul_moebius_eq [NonAssocRing R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd = f n := by
rw [sum_eq_iff_sum_smul_moebius_eq]
apply forall_congr'
refine fun a => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
/-- Möbius inversion for functions to a `CommGroup`. -/
theorem prod_eq_iff_prod_pow_moebius_eq [CommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n :=
@sum_eq_iff_sum_smul_moebius_eq (Additive R) _ _ _
/-- Möbius inversion for functions to a `CommGroupWithZero`. -/
theorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [CommGroupWithZero R] {f g : ℕ → R}
(hf : ∀ n : ℕ, 0 < n → f n ≠ 0) (hg : ∀ n : ℕ, 0 < n → g n ≠ 0) :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n := by
| refine
Iff.trans
(Iff.trans (forall_congr' fun n => ?_)
(@prod_eq_iff_prod_pow_moebius_eq Rˣ _
(fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1) fun n =>
if h : 0 < n then Units.mk0 (g n) (hg n h) else 1))
(forall_congr' fun n => ?_) <;>
refine imp_congr_right fun hn => ?_
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0]
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)),
| Mathlib/NumberTheory/ArithmeticFunction.lean | 1,170 | 1,187 |
/-
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*}
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 608 | 609 |
/-
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.Homotopy
import Mathlib.Algebra.Ring.NegOnePow
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Tactic.Linarith
import Mathlib.CategoryTheory.Linear.LinearFunctor
/-! The cochain complex of homomorphisms between cochain complexes
If `F` and `G` are cochain complexes (indexed by `ℤ`) in a preadditive category,
there is a cochain complex of abelian groups whose `0`-cocycles identify to
morphisms `F ⟶ G`. Informally, in degree `n`, this complex shall consist of
cochains of degree `n` from `F` to `G`, i.e. arbitrary families for morphisms
`F.X p ⟶ G.X (p + n)`. This complex shall be denoted `HomComplex F G`.
In order to avoid type theoretic issues, a cochain of degree `n : ℤ`
(i.e. a term of type of `Cochain F G n`) shall be defined here
as the data of a morphism `F.X p ⟶ G.X q` for all triplets
`⟨p, q, hpq⟩` where `p` and `q` are integers and `hpq : p + n = q`.
If `α : Cochain F G n`, we shall define `α.v p q hpq : F.X p ⟶ G.X q`.
We follow the signs conventions appearing in the introduction of
[Brian Conrad's book *Grothendieck duality and base change*][conrad2000].
## References
* [Brian Conrad, Grothendieck duality and base change][conrad2000]
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category Limits Preadditive
universe v u
variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C]
namespace CochainComplex
variable {F G K L : CochainComplex C ℤ} (n m : ℤ)
namespace HomComplex
/-- A term of type `HomComplex.Triplet n` consists of two integers `p` and `q`
such that `p + n = q`. (This type is introduced so that the instance
`AddCommGroup (Cochain F G n)` defined below can be found automatically.) -/
structure Triplet (n : ℤ) where
/-- a first integer -/
p : ℤ
/-- a second integer -/
q : ℤ
/-- the condition on the two integers -/
hpq : p + n = q
variable (F G)
/-- A cochain of degree `n : ℤ` between to cochain complexes `F` and `G` consists
of a family of morphisms `F.X p ⟶ G.X q` whenever `p + n = q`, i.e. for all
triplets in `HomComplex.Triplet n`. -/
def Cochain := ∀ (T : Triplet n), F.X T.p ⟶ G.X T.q
instance : AddCommGroup (Cochain F G n) := by
dsimp only [Cochain]
infer_instance
instance : Module R (Cochain F G n) := by
dsimp only [Cochain]
infer_instance
namespace Cochain
variable {F G n}
/-- A practical constructor for cochains. -/
def mk (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) : Cochain F G n :=
fun ⟨p, q, hpq⟩ => v p q hpq
/-- The value of a cochain on a triplet `⟨p, q, hpq⟩`. -/
def v (γ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
F.X p ⟶ G.X q := γ ⟨p, q, hpq⟩
@[simp]
lemma mk_v (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) (p q : ℤ) (hpq : p + n = q) :
(Cochain.mk v).v p q hpq = v p q hpq := rfl
lemma congr_v {z₁ z₂ : Cochain F G n} (h : z₁ = z₂) (p q : ℤ) (hpq : p + n = q) :
z₁.v p q hpq = z₂.v p q hpq := by subst h; rfl
@[ext]
lemma ext (z₁ z₂ : Cochain F G n)
(h : ∀ (p q hpq), z₁.v p q hpq = z₂.v p q hpq) : z₁ = z₂ := by
funext ⟨p, q, hpq⟩
apply h
@[ext 1100]
lemma ext₀ (z₁ z₂ : Cochain F G 0)
(h : ∀ (p : ℤ), z₁.v p p (add_zero p) = z₂.v p p (add_zero p)) : z₁ = z₂ := by
ext p q hpq
obtain rfl : q = p := by rw [← hpq, add_zero]
exact h q
@[simp]
lemma zero_v {n : ℤ} (p q : ℤ) (hpq : p + n = q) :
(0 : Cochain F G n).v p q hpq = 0 := rfl
@[simp]
lemma add_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(z₁ + z₂).v p q hpq = z₁.v p q hpq + z₂.v p q hpq := rfl
@[simp]
lemma sub_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(z₁ - z₂).v p q hpq = z₁.v p q hpq - z₂.v p q hpq := rfl
@[simp]
lemma neg_v {n : ℤ} (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(-z).v p q hpq = - (z.v p q hpq) := rfl
@[simp]
lemma smul_v {n : ℤ} (k : R) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(k • z).v p q hpq = k • (z.v p q hpq) := rfl
@[simp]
lemma units_smul_v {n : ℤ} (k : Rˣ) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(k • z).v p q hpq = k • (z.v p q hpq) := rfl
/-- A cochain of degree `0` from `F` to `G` can be constructed from a family
of morphisms `F.X p ⟶ G.X p` for all `p : ℤ`. -/
def ofHoms (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) : Cochain F G 0 :=
Cochain.mk (fun p q hpq => ψ p ≫ eqToHom (by rw [← hpq, add_zero]))
@[simp]
lemma ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p : ℤ) :
(ofHoms ψ).v p p (add_zero p) = ψ p := by
simp only [ofHoms, mk_v, eqToHom_refl, comp_id]
@[simp]
lemma ofHoms_zero : ofHoms (fun p => (0 : F.X p ⟶ G.X p)) = 0 := by aesop_cat
@[simp]
lemma ofHoms_v_comp_d (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p q q' : ℤ) (hpq : p + 0 = q) :
(ofHoms ψ).v p q hpq ≫ G.d q q' = ψ p ≫ G.d p q' := by
rw [add_zero] at hpq
subst hpq
rw [ofHoms_v]
@[simp]
lemma d_comp_ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p' p q : ℤ) (hpq : p + 0 = q) :
F.d p' p ≫ (ofHoms ψ).v p q hpq = F.d p' q ≫ ψ q := by
rw [add_zero] at hpq
subst hpq
rw [ofHoms_v]
/-- The `0`-cochain attached to a morphism of cochain complexes. -/
def ofHom (φ : F ⟶ G) : Cochain F G 0 := ofHoms (fun p => φ.f p)
variable (F G)
@[simp]
lemma ofHom_zero : ofHom (0 : F ⟶ G) = 0 := by
simp only [ofHom, HomologicalComplex.zero_f_apply, ofHoms_zero]
variable {F G}
@[simp]
lemma ofHom_v (φ : F ⟶ G) (p : ℤ) : (ofHom φ).v p p (add_zero p) = φ.f p := by
simp only [ofHom, ofHoms_v]
@[simp]
lemma ofHom_v_comp_d (φ : F ⟶ G) (p q q' : ℤ) (hpq : p + 0 = q) :
(ofHom φ).v p q hpq ≫ G.d q q' = φ.f p ≫ G.d p q' := by
simp only [ofHom, ofHoms_v_comp_d]
@[simp]
lemma d_comp_ofHom_v (φ : F ⟶ G) (p' p q : ℤ) (hpq : p + 0 = q) :
F.d p' p ≫ (ofHom φ).v p q hpq = F.d p' q ≫ φ.f q := by
simp only [ofHom, d_comp_ofHoms_v]
@[simp]
lemma ofHom_add (φ₁ φ₂ : F ⟶ G) :
Cochain.ofHom (φ₁ + φ₂) = Cochain.ofHom φ₁ + Cochain.ofHom φ₂ := by aesop_cat
@[simp]
lemma ofHom_sub (φ₁ φ₂ : F ⟶ G) :
Cochain.ofHom (φ₁ - φ₂) = Cochain.ofHom φ₁ - Cochain.ofHom φ₂ := by aesop_cat
@[simp]
lemma ofHom_neg (φ : F ⟶ G) :
Cochain.ofHom (-φ) = -Cochain.ofHom φ := by aesop_cat
/-- The cochain of degree `-1` given by an homotopy between two morphism of complexes. -/
def ofHomotopy {φ₁ φ₂ : F ⟶ G} (ho : Homotopy φ₁ φ₂) : Cochain F G (-1) :=
Cochain.mk (fun p q _ => ho.hom p q)
@[simp]
lemma ofHomotopy_ofEq {φ₁ φ₂ : F ⟶ G} (h : φ₁ = φ₂) :
ofHomotopy (Homotopy.ofEq h) = 0 := rfl
@[simp]
lemma ofHomotopy_refl (φ : F ⟶ G) :
ofHomotopy (Homotopy.refl φ) = 0 := rfl
@[reassoc]
lemma v_comp_XIsoOfEq_hom
(γ : Cochain F G n) (p q q' : ℤ) (hpq : p + n = q) (hq' : q = q') :
γ.v p q hpq ≫ (HomologicalComplex.XIsoOfEq G hq').hom = γ.v p q' (by rw [← hq', hpq]) := by
subst hq'
simp only [HomologicalComplex.XIsoOfEq, eqToIso_refl, Iso.refl_hom, comp_id]
@[reassoc]
lemma v_comp_XIsoOfEq_inv
(γ : Cochain F G n) (p q q' : ℤ) (hpq : p + n = q) (hq' : q' = q) :
γ.v p q hpq ≫ (HomologicalComplex.XIsoOfEq G hq').inv = γ.v p q' (by rw [hq', hpq]) := by
subst hq'
simp only [HomologicalComplex.XIsoOfEq, eqToIso_refl, Iso.refl_inv, comp_id]
/-- The composition of cochains. -/
def comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂) :
Cochain F K n₁₂ :=
Cochain.mk (fun p q hpq => z₁.v p (p + n₁) rfl ≫ z₂.v (p + n₁) q (by omega))
/-! If `z₁` is a cochain of degree `n₁` and `z₂` is a cochain of degree `n₂`, and that
we have a relation `h : n₁ + n₂ = n₁₂`, then `z₁.comp z₂ h` is a cochain of degree `n₁₂`.
The following lemma `comp_v` computes the value of this composition `z₁.comp z₂ h`
on a triplet `⟨p₁, p₃, _⟩` (with `p₁ + n₁₂ = p₃`). In order to use this lemma,
we need to provide an intermediate integer `p₂` such that `p₁ + n₁ = p₂`.
It is advisable to use a `p₂` that has good definitional properties
(i.e. `p₁ + n₁` is not always the best choice.)
When `z₁` or `z₂` is a `0`-cochain, there is a better choice of `p₂`, and this leads
to the two simplification lemmas `comp_zero_cochain_v` and `zero_cochain_comp_v`.
-/
lemma comp_v {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂)
(p₁ p₂ p₃ : ℤ) (h₁ : p₁ + n₁ = p₂) (h₂ : p₂ + n₂ = p₃) :
(z₁.comp z₂ h).v p₁ p₃ (by rw [← h₂, ← h₁, ← h, add_assoc]) =
z₁.v p₁ p₂ h₁ ≫ z₂.v p₂ p₃ h₂ := by
subst h₁; rfl
@[simp]
lemma comp_zero_cochain_v (z₁ : Cochain F G n) (z₂ : Cochain G K 0) (p q : ℤ) (hpq : p + n = q) :
(z₁.comp z₂ (add_zero n)).v p q hpq = z₁.v p q hpq ≫ z₂.v q q (add_zero q) :=
comp_v z₁ z₂ (add_zero n) p q q hpq (add_zero q)
@[simp]
lemma zero_cochain_comp_v (z₁ : Cochain F G 0) (z₂ : Cochain G K n) (p q : ℤ) (hpq : p + n = q) :
(z₁.comp z₂ (zero_add n)).v p q hpq = z₁.v p p (add_zero p) ≫ z₂.v p q hpq :=
comp_v z₁ z₂ (zero_add n) p p q (add_zero p) hpq
/-- The associativity of the composition of cochains. -/
lemma comp_assoc {n₁ n₂ n₃ n₁₂ n₂₃ n₁₂₃ : ℤ}
(z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (z₃ : Cochain K L n₃)
(h₁₂ : n₁ + n₂ = n₁₂) (h₂₃ : n₂ + n₃ = n₂₃) (h₁₂₃ : n₁ + n₂ + n₃ = n₁₂₃) :
(z₁.comp z₂ h₁₂).comp z₃ (show n₁₂ + n₃ = n₁₂₃ by rw [← h₁₂, h₁₂₃]) =
z₁.comp (z₂.comp z₃ h₂₃) (by rw [← h₂₃, ← h₁₂₃, add_assoc]) := by
substs h₁₂ h₂₃ h₁₂₃
ext p q hpq
rw [comp_v _ _ rfl p (p + n₁ + n₂) q (add_assoc _ _ _).symm (by omega),
comp_v z₁ z₂ rfl p (p + n₁) (p + n₁ + n₂) (by omega) (by omega),
comp_v z₁ (z₂.comp z₃ rfl) (add_assoc n₁ n₂ n₃).symm p (p + n₁) q (by omega) (by omega),
comp_v z₂ z₃ rfl (p + n₁) (p + n₁ + n₂) q (by omega) (by omega), assoc]
/-! The formulation of the associativity of the composition of cochains given by the
lemma `comp_assoc` often requires a careful selection of degrees with good definitional
properties. In a few cases, like when one of the three cochains is a `0`-cochain,
there are better choices, which provides the following simplification lemmas. -/
@[simp]
lemma comp_assoc_of_first_is_zero_cochain {n₂ n₃ n₂₃ : ℤ}
(z₁ : Cochain F G 0) (z₂ : Cochain G K n₂) (z₃ : Cochain K L n₃)
(h₂₃ : n₂ + n₃ = n₂₃) :
(z₁.comp z₂ (zero_add n₂)).comp z₃ h₂₃ = z₁.comp (z₂.comp z₃ h₂₃) (zero_add n₂₃) :=
comp_assoc _ _ _ _ _ (by omega)
@[simp]
lemma comp_assoc_of_second_is_zero_cochain {n₁ n₃ n₁₃ : ℤ}
(z₁ : Cochain F G n₁) (z₂ : Cochain G K 0) (z₃ : Cochain K L n₃) (h₁₃ : n₁ + n₃ = n₁₃) :
(z₁.comp z₂ (add_zero n₁)).comp z₃ h₁₃ = z₁.comp (z₂.comp z₃ (zero_add n₃)) h₁₃ :=
comp_assoc _ _ _ _ _ (by omega)
@[simp]
lemma comp_assoc_of_third_is_zero_cochain {n₁ n₂ n₁₂ : ℤ}
(z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (z₃ : Cochain K L 0) (h₁₂ : n₁ + n₂ = n₁₂) :
(z₁.comp z₂ h₁₂).comp z₃ (add_zero n₁₂) = z₁.comp (z₂.comp z₃ (add_zero n₂)) h₁₂ :=
comp_assoc _ _ _ _ _ (by omega)
@[simp]
lemma comp_assoc_of_second_degree_eq_neg_third_degree {n₁ n₂ n₁₂ : ℤ}
(z₁ : Cochain F G n₁) (z₂ : Cochain G K (-n₂)) (z₃ : Cochain K L n₂) (h₁₂ : n₁ + (-n₂) = n₁₂) :
(z₁.comp z₂ h₁₂).comp z₃
(show n₁₂ + n₂ = n₁ by rw [← h₁₂, add_assoc, neg_add_cancel, add_zero]) =
z₁.comp (z₂.comp z₃ (neg_add_cancel n₂)) (add_zero n₁) :=
comp_assoc _ _ _ _ _ (by omega)
@[simp]
protected lemma zero_comp {n₁ n₂ n₁₂ : ℤ} (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : (0 : Cochain F G n₁).comp z₂ h = 0 := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), zero_v, zero_comp]
@[simp]
protected lemma add_comp {n₁ n₂ n₁₂ : ℤ} (z₁ z₁' : Cochain F G n₁) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : (z₁ + z₁').comp z₂ h = z₁.comp z₂ h + z₁'.comp z₂ h := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), add_v, add_comp]
@[simp]
protected lemma sub_comp {n₁ n₂ n₁₂ : ℤ} (z₁ z₁' : Cochain F G n₁) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : (z₁ - z₁').comp z₂ h = z₁.comp z₂ h - z₁'.comp z₂ h := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), sub_v, sub_comp]
@[simp]
protected lemma neg_comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : (-z₁).comp z₂ h = -z₁.comp z₂ h := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), neg_v, neg_comp]
@[simp]
protected lemma smul_comp {n₁ n₂ n₁₂ : ℤ} (k : R) (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : (k • z₁).comp z₂ h = k • (z₁.comp z₂ h) := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), smul_v, Linear.smul_comp]
@[simp]
lemma units_smul_comp {n₁ n₂ n₁₂ : ℤ} (k : Rˣ) (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : (k • z₁).comp z₂ h = k • (z₁.comp z₂ h) := by
apply Cochain.smul_comp
@[simp]
protected lemma id_comp {n : ℤ} (z₂ : Cochain F G n) :
(Cochain.ofHom (𝟙 F)).comp z₂ (zero_add n) = z₂ := by
ext p q hpq
simp only [zero_cochain_comp_v, ofHom_v, HomologicalComplex.id_f, id_comp]
@[simp]
protected lemma comp_zero {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁)
(h : n₁ + n₂ = n₁₂) : z₁.comp (0 : Cochain G K n₂) h = 0 := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), zero_v, comp_zero]
@[simp]
protected lemma comp_add {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ z₂' : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : z₁.comp (z₂ + z₂') h = z₁.comp z₂ h + z₁.comp z₂' h := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), add_v, comp_add]
@[simp]
protected lemma comp_sub {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ z₂' : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : z₁.comp (z₂ - z₂') h = z₁.comp z₂ h - z₁.comp z₂' h := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), sub_v, comp_sub]
@[simp]
protected lemma comp_neg {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂) : z₁.comp (-z₂) h = -z₁.comp z₂ h := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), neg_v, comp_neg]
@[simp]
protected lemma comp_smul {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (k : R) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂ ) : z₁.comp (k • z₂) h = k • (z₁.comp z₂ h) := by
ext p q hpq
simp only [comp_v _ _ h p _ q rfl (by omega), smul_v, Linear.comp_smul]
@[simp]
lemma comp_units_smul {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (k : Rˣ) (z₂ : Cochain G K n₂)
(h : n₁ + n₂ = n₁₂ ) : z₁.comp (k • z₂) h = k • (z₁.comp z₂ h) := by
apply Cochain.comp_smul
@[simp]
protected lemma comp_id {n : ℤ} (z₁ : Cochain F G n) :
z₁.comp (Cochain.ofHom (𝟙 G)) (add_zero n) = z₁ := by
ext p q hpq
simp only [comp_zero_cochain_v, ofHom_v, HomologicalComplex.id_f, comp_id]
@[simp]
lemma ofHoms_comp (φ : ∀ (p : ℤ), F.X p ⟶ G.X p) (ψ : ∀ (p : ℤ), G.X p ⟶ K.X p) :
(ofHoms φ).comp (ofHoms ψ) (zero_add 0) = ofHoms (fun p => φ p ≫ ψ p) := by aesop_cat
@[simp]
lemma ofHom_comp (f : F ⟶ G) (g : G ⟶ K) :
ofHom (f ≫ g) = (ofHom f).comp (ofHom g) (zero_add 0) := by
simp only [ofHom, HomologicalComplex.comp_f, ofHoms_comp]
variable (K)
/-- The differential on a cochain complex, as a cochain of degree `1`. -/
def diff : Cochain K K 1 := Cochain.mk (fun p q _ => K.d p q)
@[simp]
lemma diff_v (p q : ℤ) (hpq : p + 1 = q) : (diff K).v p q hpq = K.d p q := rfl
end Cochain
variable {F G}
/-- The differential on the complex of morphisms between cochain complexes. -/
def δ (z : Cochain F G n) : Cochain F G m :=
Cochain.mk (fun p q hpq => z.v p (p + n) rfl ≫ G.d (p + n) q +
m.negOnePow • F.d p (p + m - n) ≫ z.v (p + m - n) q (by rw [hpq, sub_add_cancel]))
/-! Similarly as for the composition of cochains, if `z : Cochain F G n`,
we usually need to carefully select intermediate indices with
good definitional properties in order to obtain a suitable expansion of the
morphisms which constitute `δ n m z : Cochain F G m` (when `n + 1 = m`, otherwise
it shall be zero). The basic equational lemma is `δ_v` below. -/
lemma δ_v (hnm : n + 1 = m) (z : Cochain F G n) (p q : ℤ) (hpq : p + m = q) (q₁ q₂ : ℤ)
(hq₁ : q₁ = q - 1) (hq₂ : p + 1 = q₂) : (δ n m z).v p q hpq =
z.v p q₁ (by rw [hq₁, ← hpq, ← hnm, ← add_assoc, add_sub_cancel_right]) ≫ G.d q₁ q
+ m.negOnePow • F.d p q₂ ≫ z.v q₂ q
(by rw [← hq₂, add_assoc, add_comm 1, hnm, hpq]) := by
obtain rfl : q₁ = p + n := by omega
obtain rfl : q₂ = p + m - n := by omega
rfl
lemma δ_shape (hnm : ¬ n + 1 = m) (z : Cochain F G n) : δ n m z = 0 := by
ext p q hpq
dsimp only [δ]
rw [Cochain.mk_v, Cochain.zero_v, F.shape, G.shape, comp_zero, zero_add, zero_comp, smul_zero]
all_goals
simp only [ComplexShape.up_Rel]
exact fun _ => hnm (by omega)
variable (F G) (R)
/-- The differential on the complex of morphisms between cochain complexes, as a linear map. -/
@[simps!]
def δ_hom : Cochain F G n →ₗ[R] Cochain F G m where
toFun := δ n m
map_add' α β := by
by_cases h : n + 1 = m
· ext p q hpq
dsimp
simp only [δ_v n m h _ p q hpq _ _ rfl rfl, Cochain.add_v, add_comp, comp_add, smul_add]
abel
· simp only [δ_shape _ _ h, add_zero]
map_smul' r a := by
by_cases h : n + 1 = m
· ext p q hpq
dsimp
simp only [δ_v n m h _ p q hpq _ _ rfl rfl, Cochain.smul_v, Linear.comp_smul,
Linear.smul_comp, smul_add, add_right_inj, smul_comm m.negOnePow r]
· simp only [δ_shape _ _ h, smul_zero]
variable {F G R}
@[simp] lemma δ_add (z₁ z₂ : Cochain F G n) : δ n m (z₁ + z₂) = δ n m z₁ + δ n m z₂ :=
(δ_hom ℤ F G n m).map_add z₁ z₂
@[simp] lemma δ_sub (z₁ z₂ : Cochain F G n) : δ n m (z₁ - z₂) = δ n m z₁ - δ n m z₂ :=
(δ_hom ℤ F G n m).map_sub z₁ z₂
@[simp] lemma δ_zero : δ n m (0 : Cochain F G n) = 0 := (δ_hom ℤ F G n m).map_zero
@[simp] lemma δ_neg (z : Cochain F G n) : δ n m (-z) = - δ n m z :=
(δ_hom ℤ F G n m).map_neg z
@[simp] lemma δ_smul (k : R) (z : Cochain F G n) : δ n m (k • z) = k • δ n m z :=
(δ_hom R F G n m).map_smul k z
@[simp] lemma δ_units_smul (k : Rˣ) (z : Cochain F G n) : δ n m (k • z) = k • δ n m z :=
δ_smul ..
lemma δ_δ (n₀ n₁ n₂ : ℤ) (z : Cochain F G n₀) : δ n₁ n₂ (δ n₀ n₁ z) = 0 := by
by_cases h₁₂ : n₁ + 1 = n₂; swap
· rw [δ_shape _ _ h₁₂]
by_cases h₀₁ : n₀ + 1 = n₁; swap
· rw [δ_shape _ _ h₀₁, δ_zero]
ext p q hpq
dsimp
simp only [δ_v n₁ n₂ h₁₂ _ p q hpq _ _ rfl rfl,
δ_v n₀ n₁ h₀₁ z p (q-1) (by omega) (q-2) _ (by omega) rfl,
δ_v n₀ n₁ h₀₁ z (p+1) q (by omega) _ (p+2) rfl (by omega),
← h₁₂, Int.negOnePow_succ, add_comp, assoc,
HomologicalComplex.d_comp_d, comp_zero, zero_add, comp_add,
HomologicalComplex.d_comp_d_assoc, zero_comp, smul_zero,
add_zero, add_neg_cancel, Units.neg_smul,
Linear.units_smul_comp, Linear.comp_units_smul]
lemma δ_comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂)
(m₁ m₂ m₁₂ : ℤ) (h₁₂ : n₁₂ + 1 = m₁₂) (h₁ : n₁ + 1 = m₁) (h₂ : n₂ + 1 = m₂) :
δ n₁₂ m₁₂ (z₁.comp z₂ h) = z₁.comp (δ n₂ m₂ z₂) (by rw [← h₁₂, ← h₂, ← h, add_assoc]) +
n₂.negOnePow • (δ n₁ m₁ z₁).comp z₂
(by rw [← h₁₂, ← h₁, ← h, add_assoc, add_comm 1, add_assoc]) := by
subst h₁₂ h₁ h₂ h
ext p q hpq
dsimp
rw [z₁.comp_v _ (add_assoc n₁ n₂ 1).symm p _ q rfl (by omega),
Cochain.comp_v _ _ (show n₁ + 1 + n₂ = n₁ + n₂ + 1 by omega) p (p+n₁+1) q
(by omega) (by omega),
δ_v (n₁ + n₂) _ rfl (z₁.comp z₂ rfl) p q hpq (p + n₁ + n₂) _ (by omega) rfl,
z₁.comp_v z₂ rfl p _ _ rfl rfl,
z₁.comp_v z₂ rfl (p+1) (p+n₁+1) q (by omega) (by omega),
δ_v n₂ (n₂+1) rfl z₂ (p+n₁) q (by omega) (p+n₁+n₂) _ (by omega) rfl,
δ_v n₁ (n₁+1) rfl z₁ p (p+n₁+1) (by omega) (p+n₁) _ (by omega) rfl]
simp only [assoc, comp_add, add_comp, Int.negOnePow_succ, Int.negOnePow_add n₁ n₂,
Units.neg_smul, comp_neg, neg_comp, smul_neg, smul_smul, Linear.units_smul_comp,
mul_comm n₁.negOnePow n₂.negOnePow, Linear.comp_units_smul, smul_add]
abel
lemma δ_zero_cochain_comp {n₂ : ℤ} (z₁ : Cochain F G 0) (z₂ : Cochain G K n₂)
(m₂ : ℤ) (h₂ : n₂ + 1 = m₂) :
δ n₂ m₂ (z₁.comp z₂ (zero_add n₂)) =
z₁.comp (δ n₂ m₂ z₂) (zero_add m₂) +
n₂.negOnePow • ((δ 0 1 z₁).comp z₂ (by rw [add_comm, h₂])) :=
δ_comp z₁ z₂ (zero_add n₂) 1 m₂ m₂ h₂ (zero_add 1) h₂
lemma δ_comp_zero_cochain {n₁ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K 0)
(m₁ : ℤ) (h₁ : n₁ + 1 = m₁) :
δ n₁ m₁ (z₁.comp z₂ (add_zero n₁)) =
z₁.comp (δ 0 1 z₂) h₁ + (δ n₁ m₁ z₁).comp z₂ (add_zero m₁) := by
simp only [δ_comp z₁ z₂ (add_zero n₁) m₁ 1 m₁ h₁ h₁ (zero_add 1), one_smul,
Int.negOnePow_zero]
@[simp]
lemma δ_zero_cochain_v (z : Cochain F G 0) (p q : ℤ) (hpq : p + 1 = q) :
(δ 0 1 z).v p q hpq = z.v p p (add_zero p) ≫ G.d p q - F.d p q ≫ z.v q q (add_zero q) := by
simp only [δ_v 0 1 (zero_add 1) z p q hpq p q (by omega) hpq, zero_add,
Int.negOnePow_one, Units.neg_smul, one_smul, sub_eq_add_neg]
@[simp]
lemma δ_ofHom {p : ℤ} (φ : F ⟶ G) : δ 0 p (Cochain.ofHom φ) = 0 := by
by_cases h : p = 1
· subst h
ext
simp
· rw [δ_shape]
omega
@[simp]
lemma δ_ofHomotopy {φ₁ φ₂ : F ⟶ G} (h : Homotopy φ₁ φ₂) :
δ (-1) 0 (Cochain.ofHomotopy h) = Cochain.ofHom φ₁ - Cochain.ofHom φ₂ := by
ext p
have eq := h.comm p
rw [dNext_eq h.hom (show (ComplexShape.up ℤ).Rel p (p+1) by simp),
prevD_eq h.hom (show (ComplexShape.up ℤ).Rel (p-1) p by simp)] at eq
rw [Cochain.ofHomotopy, δ_v (-1) 0 (neg_add_cancel 1) _ p p (add_zero p) (p-1) (p+1) rfl rfl]
simp only [Cochain.mk_v, neg_add_cancel, one_smul, Int.negOnePow_zero,
Cochain.sub_v, Cochain.ofHom_v, eq]
abel
lemma δ_neg_one_cochain (z : Cochain F G (-1)) :
δ (-1) 0 z = Cochain.ofHom (Homotopy.nullHomotopicMap'
(fun i j hij => z.v i j (by dsimp at hij; rw [← hij, add_neg_cancel_right]))) := by
ext p
rw [δ_v (-1) 0 (neg_add_cancel 1) _ p p (add_zero p) (p-1) (p+1) rfl rfl]
simp only [neg_add_cancel, one_smul, Cochain.ofHom_v, Int.negOnePow_zero]
rw [Homotopy.nullHomotopicMap'_f (show (ComplexShape.up ℤ).Rel (p-1) p by simp)
(show (ComplexShape.up ℤ).Rel p (p+1) by simp)]
abel
end HomComplex
variable (F G)
open HomComplex
/-- The cochain complex of homomorphisms between two cochain complexes `F` and `G`.
In degree `n : ℤ`, it consists of the abelian group `HomComplex.Cochain F G n`. -/
@[simps! X d_hom_apply]
def HomComplex : CochainComplex AddCommGrp ℤ where
X i := AddCommGrp.of (Cochain F G i)
d i j := AddCommGrp.ofHom (δ_hom ℤ F G i j)
shape _ _ hij := by ext; simp [δ_shape _ _ hij]
d_comp_d' _ _ _ _ _ := by ext; simp [δ_δ]
namespace HomComplex
/-- The subgroup of cocycles in `Cochain F G n`. -/
def cocycle : AddSubgroup (Cochain F G n) :=
AddMonoidHom.ker (δ_hom ℤ F G n (n + 1)).toAddMonoidHom
/-- The type of `n`-cocycles, as a subtype of `Cochain F G n`. -/
def Cocycle : Type v := cocycle F G n
instance : AddCommGroup (Cocycle F G n) := by
dsimp only [Cocycle]
infer_instance
namespace Cocycle
variable {F G}
lemma mem_iff (hnm : n + 1 = m) (z : Cochain F G n) :
z ∈ cocycle F G n ↔ δ n m z = 0 := by subst hnm; rfl
variable {n}
instance : Coe (Cocycle F G n) (Cochain F G n) where
coe x := x.1
@[ext]
lemma ext (z₁ z₂ : Cocycle F G n) (h : (z₁ : Cochain F G n) = z₂) : z₁ = z₂ :=
Subtype.ext h
instance : SMul R (Cocycle F G n) where
smul r z := ⟨r • z.1, by
have hz := z.2
rw [mem_iff n (n + 1) rfl] at hz ⊢
simp only [δ_smul, hz, smul_zero]⟩
variable (F G n)
@[simp]
lemma coe_zero : (↑(0 : Cocycle F G n) : Cochain F G n) = 0 := by rfl
variable {F G n}
@[simp]
lemma coe_add (z₁ z₂ : Cocycle F G n) :
(↑(z₁ + z₂) : Cochain F G n) = (z₁ : Cochain F G n) + (z₂ : Cochain F G n) := rfl
@[simp]
lemma coe_neg (z : Cocycle F G n) :
(↑(-z) : Cochain F G n) = -(z : Cochain F G n) := rfl
@[simp]
lemma coe_smul (z : Cocycle F G n) (x : R) :
(↑(x • z) : Cochain F G n) = x • (z : Cochain F G n) := rfl
@[simp]
lemma coe_units_smul (z : Cocycle F G n) (x : Rˣ) :
(↑(x • z) : Cochain F G n) = x • (z : Cochain F G n) := rfl
@[simp]
lemma coe_sub (z₁ z₂ : Cocycle F G n) :
(↑(z₁ - z₂) : Cochain F G n) = (z₁ : Cochain F G n) - (z₂ : Cochain F G n) := rfl
instance : Module R (Cocycle F G n) where
one_smul _ := by aesop
mul_smul _ _ _ := by ext; dsimp; rw [smul_smul]
smul_zero _ := by aesop
smul_add _ _ _ := by aesop
add_smul _ _ _ := by ext; dsimp; rw [add_smul]
zero_smul := by aesop
/-- Constructor for `Cocycle F G n`, taking as inputs `z : Cochain F G n`, an integer
`m : ℤ` such that `n + 1 = m`, and the relation `δ n m z = 0`. -/
@[simps]
def mk (z : Cochain F G n) (m : ℤ) (hnm : n + 1 = m) (h : δ n m z = 0) : Cocycle F G n :=
⟨z, by simpa only [mem_iff n m hnm z] using h⟩
@[simp]
lemma δ_eq_zero {n : ℤ} (z : Cocycle F G n) (m : ℤ) : δ n m (z : Cochain F G n) = 0 := by
by_cases h : n + 1 = m
· rw [← mem_iff n m h]
exact z.2
· exact δ_shape n m h _
/-- The `0`-cocycle associated to a morphism in `CochainComplex C ℤ`. -/
@[simps!]
def ofHom (φ : F ⟶ G) : Cocycle F G 0 := mk (Cochain.ofHom φ) 1 (zero_add 1) (by simp)
/-- The morphism in `CochainComplex C ℤ` associated to a `0`-cocycle. -/
@[simps]
def homOf (z : Cocycle F G 0) : F ⟶ G where
f i := (z : Cochain _ _ _).v i i (add_zero i)
comm' := by
rintro i j rfl
rcases z with ⟨z, hz⟩
dsimp
rw [mem_iff 0 1 (zero_add 1)] at hz
simpa only [δ_zero_cochain_v, Cochain.zero_v, sub_eq_zero]
using Cochain.congr_v hz i (i + 1) rfl
@[simp]
lemma homOf_ofHom_eq_self (φ : F ⟶ G) : homOf (ofHom φ) = φ := by aesop_cat
@[simp]
lemma ofHom_homOf_eq_self (z : Cocycle F G 0) : ofHom (homOf z) = z := by aesop_cat
@[simp]
lemma cochain_ofHom_homOf_eq_coe (z : Cocycle F G 0) :
Cochain.ofHom (homOf z) = (z : Cochain F G 0) := by
simpa only [Cocycle.ext_iff] using ofHom_homOf_eq_self z
variable (F G)
/-- The additive equivalence between morphisms in `CochainComplex C ℤ` and `0`-cocycles. -/
@[simps]
def equivHom : (F ⟶ G) ≃+ Cocycle F G 0 where
toFun := ofHom
invFun := homOf
left_inv := homOf_ofHom_eq_self
right_inv := ofHom_homOf_eq_self
map_add' := by aesop_cat
variable (K)
/-- The `1`-cocycle given by the differential on a cochain complex. -/
@[simps!]
def diff : Cocycle K K 1 :=
Cocycle.mk (Cochain.diff K) 2 rfl (by
ext p q hpq
simp only [Cochain.zero_v, δ_v 1 2 rfl _ p q hpq _ _ rfl rfl, Cochain.diff_v,
HomologicalComplex.d_comp_d, smul_zero, add_zero])
end Cocycle
variable {F G}
@[simp]
lemma δ_comp_zero_cocycle {n : ℤ} (z₁ : Cochain F G n) (z₂ : Cocycle G K 0) (m : ℤ) :
δ n m (z₁.comp z₂.1 (add_zero n)) =
(δ n m z₁).comp z₂.1 (add_zero m) := by
by_cases hnm : n + 1 = m
· simp [δ_comp_zero_cochain _ _ _ hnm]
· simp [δ_shape _ _ hnm]
@[simp]
lemma δ_comp_ofHom {n : ℤ} (z₁ : Cochain F G n) (f : G ⟶ K) (m : ℤ) :
δ n m (z₁.comp (Cochain.ofHom f) (add_zero n)) =
(δ n m z₁).comp (Cochain.ofHom f) (add_zero m) := by
rw [← Cocycle.ofHom_coe, δ_comp_zero_cocycle]
@[simp]
lemma δ_zero_cocycle_comp {n : ℤ} (z₁ : Cocycle F G 0) (z₂ : Cochain G K n) (m : ℤ) :
δ n m (z₁.1.comp z₂ (zero_add n)) =
z₁.1.comp (δ n m z₂) (zero_add m) := by
by_cases hnm : n + 1 = m
· simp [δ_zero_cochain_comp _ _ _ hnm]
· simp [δ_shape _ _ hnm]
@[simp]
lemma δ_ofHom_comp {n : ℤ} (f : F ⟶ G) (z : Cochain G K n) (m : ℤ) :
δ n m ((Cochain.ofHom f).comp z (zero_add n)) =
(Cochain.ofHom f).comp (δ n m z) (zero_add m) := by
rw [← Cocycle.ofHom_coe, δ_zero_cocycle_comp]
namespace Cochain
/-- Given two morphisms of complexes `φ₁ φ₂ : F ⟶ G`, the datum of an homotopy between `φ₁` and
`φ₂` is equivalent to the datum of a `1`-cochain `z` such that `δ (-1) 0 z` is the difference
of the zero cochains associated to `φ₂` and `φ₁`. -/
@[simps]
def equivHomotopy (φ₁ φ₂ : F ⟶ G) :
Homotopy φ₁ φ₂ ≃
{ z : Cochain F G (-1) // Cochain.ofHom φ₁ = δ (-1) 0 z + Cochain.ofHom φ₂ } where
toFun ho := ⟨Cochain.ofHomotopy ho, by simp only [δ_ofHomotopy, sub_add_cancel]⟩
invFun z :=
{ hom := fun i j => if hij : i + (-1) = j then z.1.v i j hij else 0
zero := fun i j (hij : j + 1 ≠ i) => dif_neg (fun _ => hij (by omega))
comm := fun p => by
have eq := Cochain.congr_v z.2 p p (add_zero p)
have h₁ : (ComplexShape.up ℤ).Rel (p - 1) p := by simp
have h₂ : (ComplexShape.up ℤ).Rel p (p + 1) := by simp
simp only [δ_neg_one_cochain, Cochain.ofHom_v, ComplexShape.up_Rel, Cochain.add_v,
Homotopy.nullHomotopicMap'_f h₁ h₂] at eq
rw [dNext_eq _ h₂, prevD_eq _ h₁, eq, dif_pos, dif_pos] }
left_inv := fun ho => by
ext i j
dsimp
split_ifs with h
· rfl
· rw [ho.zero i j (fun h' => h (by dsimp at h'; omega))]
right_inv := fun z => by
ext p q hpq
dsimp [Cochain.ofHomotopy]
rw [dif_pos hpq]
@[simp]
lemma equivHomotopy_apply_of_eq {φ₁ φ₂ : F ⟶ G} (h : φ₁ = φ₂) :
(equivHomotopy _ _ (Homotopy.ofEq h)).1 = 0 := rfl
lemma ofHom_injective {f₁ f₂ : F ⟶ G} (h : ofHom f₁ = ofHom f₂) : f₁ = f₂ :=
(Cocycle.equivHom F G).injective (by ext1; exact h)
end Cochain
section
variable {n} {D : Type*} [Category D] [Preadditive D] (z z' : Cochain K L n) (f : K ⟶ L)
(Φ : C ⥤ D) [Φ.Additive]
namespace Cochain
/-- If `Φ : C ⥤ D` is an additive functor, a cochain `z : Cochain K L n` between
cochain complexes in `C` can be mapped to a cochain between the cochain complexes
in `D` obtained by applying the functor
`Φ.mapHomologicalComplex _ : CochainComplex C ℤ ⥤ CochainComplex D ℤ`. -/
def map : Cochain ((Φ.mapHomologicalComplex _).obj K) ((Φ.mapHomologicalComplex _).obj L) n :=
Cochain.mk (fun p q hpq => Φ.map (z.v p q hpq))
@[simp]
lemma map_v (p q : ℤ) (hpq : p + n = q) : (z.map Φ).v p q hpq = Φ.map (z.v p q hpq) := rfl
@[simp]
protected lemma map_add : (z + z').map Φ = z.map Φ + z'.map Φ := by aesop_cat
@[simp]
protected lemma map_neg : (-z).map Φ = -z.map Φ := by aesop_cat
@[simp]
protected lemma map_sub : (z - z').map Φ = z.map Φ - z'.map Φ := by aesop_cat
variable (K L n)
@[simp]
protected lemma map_zero : (0 : Cochain K L n).map Φ = 0 := by aesop_cat
@[simp]
lemma map_comp {n₁ n₂ n₁₂ : ℤ} (z₁ : Cochain F G n₁) (z₂ : Cochain G K n₂) (h : n₁ + n₂ = n₁₂)
(Φ : C ⥤ D) [Φ.Additive] :
(Cochain.comp z₁ z₂ h).map Φ = Cochain.comp (z₁.map Φ) (z₂.map Φ) h := by
ext p q hpq
dsimp
simp only [map_v, comp_v _ _ h p _ q rfl (by omega), Φ.map_comp]
@[simp]
lemma map_ofHom :
(Cochain.ofHom f).map Φ = Cochain.ofHom ((Φ.mapHomologicalComplex _).map f) := by aesop_cat
end Cochain
variable (n)
| @[simp]
lemma δ_map : δ n m (z.map Φ) = (δ n m z).map Φ := by
by_cases hnm : n + 1 = m
| Mathlib/Algebra/Homology/HomotopyCategory/HomComplex.lean | 824 | 826 |
/-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.Group
import Mathlib.NumberTheory.EllipticDivisibilitySequence
/-!
# Division polynomials of Weierstrass curves
This file defines certain polynomials associated to division polynomials of Weierstrass curves.
These are defined in terms of the auxiliary sequences for normalised elliptic divisibility sequences
(EDS) as defined in `Mathlib.NumberTheory.EllipticDivisibilitySequence`.
## Mathematical background
Let `W` be a Weierstrass curve over a commutative ring `R`. The sequence of `n`-division polynomials
`ψₙ ∈ R[X, Y]` of `W` is the normalised EDS with initial values
* `ψ₀ := 0`,
* `ψ₁ := 1`,
* `ψ₂ := 2Y + a₁X + a₃`,
* `ψ₃ := 3X⁴ + b₂X³ + 3b₄X² + 3b₆X + b₈`, and
* `ψ₄ := ψ₂ ⬝ (2X⁶ + b₂X⁵ + 5b₄X⁴ + 10b₆X³ + 10b₈X² + (b₂b₈ - b₄b₆)X + (b₄b₈ - b₆²))`.
Furthermore, define the associated sequences `φₙ, ωₙ ∈ R[X, Y]` by
* `φₙ := Xψₙ² - ψₙ₊₁ ⬝ ψₙ₋₁`, and
* `ωₙ := (ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)) / 2`.
Note that `ωₙ` is always well-defined as a polynomial in `R[X, Y]`. As a start, it can be shown by
induction that `ψₙ` always divides `ψ₂ₙ` in `R[X, Y]`, so that `ψ₂ₙ / ψₙ` is always well-defined as
a polynomial, while division by `2` is well-defined when `R` has characteristic different from `2`.
In general, it can be shown that `2` always divides the polynomial `ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)`
in the characteristic `0` universal ring `𝓡[X, Y] := ℤ[A₁, A₂, A₃, A₄, A₆][X, Y]` of `W`, where the
`Aᵢ` are indeterminates. Then `ωₙ` can be equivalently defined as the image of this division under
the associated universal morphism `𝓡[X, Y] → R[X, Y]` mapping `Aᵢ` to `aᵢ`.
Now, in the coordinate ring `R[W]`, note that `ψ₂²` is congruent to the polynomial
`Ψ₂Sq := 4X³ + b₂X² + 2b₄X + b₆ ∈ R[X]`. As such, the recurrences of a normalised EDS show that
`ψₙ / ψ₂` are congruent to certain polynomials in `R[W]`. In particular, define `preΨₙ ∈ R[X]` as
the auxiliary sequence for a normalised EDS with extra parameter `Ψ₂Sq²` and initial values
* `preΨ₀ := 0`,
* `preΨ₁ := 1`,
* `preΨ₂ := 1`,
* `preΨ₃ := ψ₃`, and
* `preΨ₄ := ψ₄ / ψ₂`.
The corresponding normalised EDS `Ψₙ ∈ R[X, Y]` is then given by
* `Ψₙ := preΨₙ ⬝ ψ₂` if `n` is even, and
* `Ψₙ := preΨₙ` if `n` is odd.
Furthermore, define the associated sequences `ΨSqₙ, Φₙ ∈ R[X]` by
* `ΨSqₙ := preΨₙ² ⬝ Ψ₂Sq` if `n` is even,
* `ΨSqₙ := preΨₙ²` if `n` is odd,
* `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁` if `n` is even, and
* `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁ ⬝ Ψ₂Sq` if `n` is odd.
With these definitions, `ψₙ ∈ R[X, Y]` and `φₙ ∈ R[X, Y]` are congruent in `R[W]` to `Ψₙ ∈ R[X, Y]`
and `Φₙ ∈ R[X]` respectively, which are defined in terms of `Ψ₂Sq ∈ R[X]` and `preΨₙ ∈ R[X]`.
## Main definitions
* `WeierstrassCurve.preΨ`: the univariate polynomials `preΨₙ`.
* `WeierstrassCurve.ΨSq`: the univariate polynomials `ΨSqₙ`.
* `WeierstrassCurve.Ψ`: the bivariate polynomials `Ψₙ`.
* `WeierstrassCurve.Φ`: the univariate polynomials `Φₙ`.
* `WeierstrassCurve.ψ`: the bivariate `n`-division polynomials `ψₙ`.
* `WeierstrassCurve.φ`: the bivariate polynomials `φₙ`.
* TODO: the bivariate polynomials `ωₙ`.
## Implementation notes
Analogously to `Mathlib.NumberTheory.EllipticDivisibilitySequence`, the bivariate polynomials
`Ψₙ` are defined in terms of the univariate polynomials `preΨₙ`. This is done partially to avoid
ring division, but more crucially to allow the definition of `ΨSqₙ` and `Φₙ` as univariate
polynomials without needing to work under the coordinate ring, and to allow the computation of their
leading terms without ambiguity. Furthermore, evaluating these polynomials at a rational point on
`W` recovers their original definition up to linear combinations of the Weierstrass equation of `W`,
hence also avoiding the need to work in the coordinate ring.
TODO: implementation notes for the definition of `ωₙ`.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, division polynomial, torsion point
-/
open Polynomial
open scoped Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "map_simp" : tactic =>
`(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀,
Polynomial.map_ofNat, Polynomial.map_one, map_C, map_X, Polynomial.map_neg, Polynomial.map_add,
Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
apply_ite <| mapRingHom _, WeierstrassCurve.map])
universe r s u v
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} [CommRing R] [CommRing S] (W : WeierstrassCurve R)
section Ψ₂Sq
/-! ### The univariate polynomial `Ψ₂Sq` -/
/-- The `2`-division polynomial `ψ₂ = Ψ₂`. -/
noncomputable def ψ₂ : R[X][Y] :=
W.toAffine.polynomialY
/-- The univariate polynomial `Ψ₂Sq` congruent to `ψ₂²`. -/
noncomputable def Ψ₂Sq : R[X] :=
C 4 * X ^ 3 + C W.b₂ * X ^ 2 + C (2 * W.b₄) * X + C W.b₆
lemma C_Ψ₂Sq : C W.Ψ₂Sq = W.ψ₂ ^ 2 - 4 * W.toAffine.polynomial := by
rw [Ψ₂Sq, ψ₂, b₂, b₄, b₆, Affine.polynomialY, Affine.polynomial]
C_simp
ring1
lemma ψ₂_sq : W.ψ₂ ^ 2 = C W.Ψ₂Sq + 4 * W.toAffine.polynomial := by
rw [C_Ψ₂Sq, sub_add_cancel]
lemma Affine.CoordinateRing.mk_ψ₂_sq : mk W W.ψ₂ ^ 2 = mk W (C W.Ψ₂Sq) := by
rw [C_Ψ₂Sq, map_sub, map_mul, AdjoinRoot.mk_self, mul_zero, sub_zero, map_pow]
-- TODO: remove `twoTorsionPolynomial` in favour of `Ψ₂Sq`
lemma Ψ₂Sq_eq : W.Ψ₂Sq = W.twoTorsionPolynomial.toPoly :=
rfl
end Ψ₂Sq
section preΨ'
/-! ### The univariate polynomials `preΨₙ` for `n ∈ ℕ` -/
/-- The `3`-division polynomial `ψ₃ = Ψ₃`. -/
noncomputable def Ψ₃ : R[X] :=
3 * X ^ 4 + C W.b₂ * X ^ 3 + 3 * C W.b₄ * X ^ 2 + 3 * C W.b₆ * X + C W.b₈
/-- The univariate polynomial `preΨ₄`, which is auxiliary to the 4-division polynomial
`ψ₄ = Ψ₄ = preΨ₄ψ₂`. -/
noncomputable def preΨ₄ : R[X] :=
2 * X ^ 6 + C W.b₂ * X ^ 5 + 5 * C W.b₄ * X ^ 4 + 10 * C W.b₆ * X ^ 3 + 10 * C W.b₈ * X ^ 2 +
C (W.b₂ * W.b₈ - W.b₄ * W.b₆) * X + C (W.b₄ * W.b₈ - W.b₆ ^ 2)
/-- The univariate polynomials `preΨₙ` for `n ∈ ℕ`, which are auxiliary to the bivariate polynomials
`Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/
noncomputable def preΨ' (n : ℕ) : R[X] :=
preNormEDS' (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n
@[simp]
lemma preΨ'_zero : W.preΨ' 0 = 0 :=
preNormEDS'_zero ..
@[simp]
lemma preΨ'_one : W.preΨ' 1 = 1 :=
preNormEDS'_one ..
@[simp]
lemma preΨ'_two : W.preΨ' 2 = 1 :=
preNormEDS'_two ..
@[simp]
lemma preΨ'_three : W.preΨ' 3 = W.Ψ₃ :=
preNormEDS'_three ..
@[simp]
lemma preΨ'_four : W.preΨ' 4 = W.preΨ₄ :=
preNormEDS'_four ..
lemma preΨ'_even (m : ℕ) : W.preΨ' (2 * (m + 3)) =
W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2 :=
preNormEDS'_even ..
lemma preΨ'_odd (m : ℕ) : W.preΨ' (2 * (m + 2) + 1) =
W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS'_odd ..
end preΨ'
section preΨ
/-! ### The univariate polynomials `preΨₙ` for `n ∈ ℤ` -/
/-- The univariate polynomials `preΨₙ` for `n ∈ ℤ`, which are auxiliary to the bivariate polynomials
`Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/
noncomputable def preΨ (n : ℤ) : R[X] :=
preNormEDS (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n
@[simp]
lemma preΨ_ofNat (n : ℕ) : W.preΨ n = W.preΨ' n :=
preNormEDS_ofNat ..
@[simp]
lemma preΨ_zero : W.preΨ 0 = 0 :=
preNormEDS_zero ..
@[simp]
lemma preΨ_one : W.preΨ 1 = 1 :=
preNormEDS_one ..
@[simp]
lemma preΨ_two : W.preΨ 2 = 1 :=
preNormEDS_two ..
@[simp]
lemma preΨ_three : W.preΨ 3 = W.Ψ₃ :=
preNormEDS_three ..
@[simp]
lemma preΨ_four : W.preΨ 4 = W.preΨ₄ :=
preNormEDS_four ..
lemma preΨ_even_ofNat (m : ℕ) : W.preΨ (2 * (m + 3)) =
W.preΨ (m + 2) ^ 2 * W.preΨ (m + 3) * W.preΨ (m + 5) -
W.preΨ (m + 1) * W.preΨ (m + 3) * W.preΨ (m + 4) ^ 2 :=
preNormEDS_even_ofNat ..
lemma preΨ_odd_ofNat (m : ℕ) : W.preΨ (2 * (m + 2) + 1) =
W.preΨ (m + 4) * W.preΨ (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m + 1) * W.preΨ (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS_odd_ofNat ..
@[simp]
lemma preΨ_neg (n : ℤ) : W.preΨ (-n) = -W.preΨ n :=
preNormEDS_neg ..
lemma preΨ_even (m : ℤ) : W.preΨ (2 * m) =
W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) -
W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2 :=
preNormEDS_even ..
lemma preΨ_odd (m : ℤ) : W.preΨ (2 * m + 1) =
W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) :=
preNormEDS_odd ..
end preΨ
section ΨSq
/-! ### The univariate polynomials `ΨSqₙ` -/
/-- The univariate polynomials `ΨSqₙ` congruent to `ψₙ²`. -/
noncomputable def ΨSq (n : ℤ) : R[X] :=
W.preΨ n ^ 2 * if Even n then W.Ψ₂Sq else 1
@[simp]
lemma ΨSq_ofNat (n : ℕ) : W.ΨSq n = W.preΨ' n ^ 2 * if Even n then W.Ψ₂Sq else 1 := by
simp only [ΨSq, preΨ_ofNat, Int.even_coe_nat]
@[simp]
lemma ΨSq_zero : W.ΨSq 0 = 0 := by
rw [← Nat.cast_zero, ΨSq_ofNat, preΨ'_zero, zero_pow two_ne_zero, zero_mul]
@[simp]
lemma ΨSq_one : W.ΨSq 1 = 1 := by
rw [← Nat.cast_one, ΨSq_ofNat, preΨ'_one, one_pow, one_mul, if_neg Nat.not_even_one]
@[simp]
lemma ΨSq_two : W.ΨSq 2 = W.Ψ₂Sq := by
rw [← Nat.cast_two, ΨSq_ofNat, preΨ'_two, one_pow, one_mul, if_pos even_two]
@[simp]
lemma ΨSq_three : W.ΨSq 3 = W.Ψ₃ ^ 2 := by
rw [← Nat.cast_three, ΨSq_ofNat, preΨ'_three, if_neg <| by decide, mul_one]
@[simp]
lemma ΨSq_four : W.ΨSq 4 = W.preΨ₄ ^ 2 * W.Ψ₂Sq := by
rw [← Nat.cast_four, ΨSq_ofNat, preΨ'_four, if_pos <| by decide]
lemma ΨSq_even_ofNat (m : ℕ) : W.ΨSq (2 * (m + 3)) =
(W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2) ^ 2 * W.Ψ₂Sq := by
rw_mod_cast [ΨSq_ofNat, preΨ'_even, if_pos <| even_two_mul _]
lemma ΨSq_odd_ofNat (m : ℕ) : W.ΨSq (2 * (m + 2) + 1) =
(W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by
rw_mod_cast [ΨSq_ofNat, preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, mul_one]
@[simp]
lemma ΨSq_neg (n : ℤ) : W.ΨSq (-n) = W.ΨSq n := by
simp only [ΨSq, preΨ_neg, neg_sq, even_neg]
lemma ΨSq_even (m : ℤ) : W.ΨSq (2 * m) =
(W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) -
W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2) ^ 2 * W.Ψ₂Sq := by
rw [ΨSq, preΨ_even, if_pos <| even_two_mul _]
lemma ΨSq_odd (m : ℤ) : W.ΨSq (2 * m + 1) =
(W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) -
W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by
rw [ΨSq, preΨ_odd, if_neg m.not_even_two_mul_add_one, mul_one]
end ΨSq
section Ψ
/-! ### The bivariate polynomials `Ψₙ` -/
/-- The bivariate polynomials `Ψₙ` congruent to the `n`-division polynomials `ψₙ`. -/
protected noncomputable def Ψ (n : ℤ) : R[X][Y] :=
C (W.preΨ n) * if Even n then W.ψ₂ else 1
open WeierstrassCurve (Ψ)
@[simp]
lemma Ψ_ofNat (n : ℕ) : W.Ψ n = C (W.preΨ' n) * if Even n then W.ψ₂ else 1 := by
simp only [Ψ, preΨ_ofNat, Int.even_coe_nat]
@[simp]
lemma Ψ_zero : W.Ψ 0 = 0 := by
rw [← Nat.cast_zero, Ψ_ofNat, preΨ'_zero, C_0, zero_mul]
@[simp]
lemma Ψ_one : W.Ψ 1 = 1 := by
rw [← Nat.cast_one, Ψ_ofNat, preΨ'_one, C_1, if_neg Nat.not_even_one, mul_one]
@[simp]
lemma Ψ_two : W.Ψ 2 = W.ψ₂ := by
rw [← Nat.cast_two, Ψ_ofNat, preΨ'_two, C_1, one_mul, if_pos even_two]
@[simp]
lemma Ψ_three : W.Ψ 3 = C W.Ψ₃ := by
rw [← Nat.cast_three, Ψ_ofNat, preΨ'_three, if_neg <| by decide, mul_one]
@[simp]
lemma Ψ_four : W.Ψ 4 = C W.preΨ₄ * W.ψ₂ := by
rw [← Nat.cast_four, Ψ_ofNat, preΨ'_four, if_pos <| by decide]
lemma Ψ_even_ofNat (m : ℕ) : W.Ψ (2 * (m + 3)) * W.ψ₂ =
W.Ψ (m + 2) ^ 2 * W.Ψ (m + 3) * W.Ψ (m + 5) - W.Ψ (m + 1) * W.Ψ (m + 3) * W.Ψ (m + 4) ^ 2 := by
repeat rw_mod_cast [Ψ_ofNat]
simp_rw [preΨ'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not]
split_ifs <;> C_simp <;> ring1
lemma Ψ_odd_ofNat (m : ℕ) : W.Ψ (2 * (m + 2) + 1) =
W.Ψ (m + 4) * W.Ψ (m + 2) ^ 3 - W.Ψ (m + 1) * W.Ψ (m + 3) ^ 3 +
W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) *
C (if Even m then W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3
else -W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3) := by
repeat rw_mod_cast [Ψ_ofNat]
simp_rw [preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not]
split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1
@[simp]
lemma Ψ_neg (n : ℤ) : W.Ψ (-n) = -W.Ψ n := by
simp only [Ψ, preΨ_neg, C_neg, neg_mul (α := R[X][Y]), even_neg]
lemma Ψ_even (m : ℤ) : W.Ψ (2 * m) * W.ψ₂ =
W.Ψ (m - 1) ^ 2 * W.Ψ m * W.Ψ (m + 2) - W.Ψ (m - 2) * W.Ψ m * W.Ψ (m + 1) ^ 2 := by
repeat rw [Ψ]
simp_rw [preΨ_even, if_pos <| even_two_mul _, Int.even_add_one, show m + 2 = m + 1 + 1 by ring1,
Int.even_add_one, show m - 2 = m - 1 - 1 by ring1, Int.even_sub_one, ite_not]
split_ifs <;> C_simp <;> ring1
lemma Ψ_odd (m : ℤ) : W.Ψ (2 * m + 1) =
W.Ψ (m + 2) * W.Ψ m ^ 3 - W.Ψ (m - 1) * W.Ψ (m + 1) ^ 3 +
W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) *
C (if Even m then W.preΨ (m + 2) * W.preΨ m ^ 3
else -W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3) := by
repeat rw [Ψ]
simp_rw [preΨ_odd, if_neg m.not_even_two_mul_add_one, show m + 2 = m + 1 + 1 by ring1,
Int.even_add_one, Int.even_sub_one, ite_not]
split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1
lemma Affine.CoordinateRing.mk_Ψ_sq (n : ℤ) : mk W (W.Ψ n) ^ 2 = mk W (C <| W.ΨSq n) := by
simp only [Ψ, ΨSq, map_one, map_mul, map_pow, one_pow, mul_pow, ite_pow, apply_ite C,
apply_ite <| mk W, mk_ψ₂_sq]
end Ψ
section Φ
/-! ### The univariate polynomials `Φₙ` -/
/-- The univariate polynomials `Φₙ` congruent to `φₙ`. -/
protected noncomputable def Φ (n : ℤ) : R[X] :=
X * W.ΨSq n - W.preΨ (n + 1) * W.preΨ (n - 1) * if Even n then 1 else W.Ψ₂Sq
open WeierstrassCurve (Φ)
@[simp]
lemma Φ_ofNat (n : ℕ) : W.Φ (n + 1) =
X * W.preΨ' (n + 1) ^ 2 * (if Even n then 1 else W.Ψ₂Sq) -
W.preΨ' (n + 2) * W.preΨ' n * (if Even n then W.Ψ₂Sq else 1) := by
rw [Φ, ← Nat.cast_one, ← Nat.cast_add, ΨSq_ofNat, ← mul_assoc, ← Nat.cast_add, preΨ_ofNat,
Nat.cast_add, add_sub_cancel_right, preΨ_ofNat, ← Nat.cast_add]
simp only [Nat.even_add_one, Int.even_add_one, Int.even_coe_nat, ite_not]
@[simp]
lemma Φ_zero : W.Φ 0 = 1 := by
rw [Φ, ΨSq_zero, mul_zero, zero_sub, zero_add, preΨ_one, one_mul, zero_sub, preΨ_neg, preΨ_one,
neg_one_mul, neg_neg, if_pos Even.zero]
@[simp]
lemma Φ_one : W.Φ 1 = X := by
rw [show 1 = ((0 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_one, one_pow, mul_one, if_pos Even.zero,
mul_one, preΨ'_zero, mul_zero, zero_mul, sub_zero]
@[simp]
lemma Φ_two : W.Φ 2 = X ^ 4 - C W.b₄ * X ^ 2 - C (2 * W.b₆) * X - C W.b₈ := by
rw [show 2 = ((1 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_two, if_neg Nat.not_even_one, Ψ₂Sq,
preΨ'_three, preΨ'_one, if_neg Nat.not_even_one, Ψ₃]
C_simp
ring1
@[simp]
lemma Φ_three : W.Φ 3 = X * W.Ψ₃ ^ 2 - W.preΨ₄ * W.Ψ₂Sq := by
rw [show 3 = ((2 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_three, if_pos <| by decide, mul_one,
preΨ'_four, preΨ'_two, mul_one, if_pos even_two]
@[simp]
lemma Φ_four : W.Φ 4 = X * W.preΨ₄ ^ 2 * W.Ψ₂Sq - W.Ψ₃ * (W.preΨ₄ * W.Ψ₂Sq ^ 2 - W.Ψ₃ ^ 3) := by
rw [show 4 = ((3 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_four, if_neg <| by decide,
show 3 + 2 = 2 * 2 + 1 by rfl, preΨ'_odd, preΨ'_four, preΨ'_two, if_pos Even.zero, preΨ'_one,
preΨ'_three, if_pos Even.zero, if_neg <| by decide]
ring1
@[simp]
lemma Φ_neg (n : ℤ) : W.Φ (-n) = W.Φ n := by
simp only [Φ, ΨSq_neg, neg_add_eq_sub, ← neg_sub n, preΨ_neg, ← neg_add', preΨ_neg, neg_mul_neg,
mul_comm <| W.preΨ <| n - 1, even_neg]
end Φ
section ψ
/-! ### The bivariate polynomials `ψₙ` -/
/-- The bivariate `n`-division polynomials `ψₙ`. -/
protected noncomputable def ψ (n : ℤ) : R[X][Y] :=
normEDS W.ψ₂ (C W.Ψ₃) (C W.preΨ₄) n
open WeierstrassCurve (Ψ ψ)
@[simp]
lemma ψ_zero : W.ψ 0 = 0 :=
normEDS_zero ..
@[simp]
lemma ψ_one : W.ψ 1 = 1 :=
normEDS_one ..
@[simp]
lemma ψ_two : W.ψ 2 = W.ψ₂ :=
normEDS_two ..
@[simp]
lemma ψ_three : W.ψ 3 = C W.Ψ₃ :=
normEDS_three ..
@[simp]
lemma ψ_four : W.ψ 4 = C W.preΨ₄ * W.ψ₂ :=
normEDS_four ..
lemma ψ_even_ofNat (m : ℕ) : W.ψ (2 * (m + 3)) * W.ψ₂ =
W.ψ (m + 2) ^ 2 * W.ψ (m + 3) * W.ψ (m + 5) - W.ψ (m + 1) * W.ψ (m + 3) * W.ψ (m + 4) ^ 2 :=
normEDS_even_ofNat ..
lemma ψ_odd_ofNat (m : ℕ) : W.ψ (2 * (m + 2) + 1) =
W.ψ (m + 4) * W.ψ (m + 2) ^ 3 - W.ψ (m + 1) * W.ψ (m + 3) ^ 3 :=
normEDS_odd_ofNat ..
@[simp]
lemma ψ_neg (n : ℤ) : W.ψ (-n) = -W.ψ n :=
normEDS_neg ..
lemma ψ_even (m : ℤ) : W.ψ (2 * m) * W.ψ₂ =
W.ψ (m - 1) ^ 2 * W.ψ m * W.ψ (m + 2) - W.ψ (m - 2) * W.ψ m * W.ψ (m + 1) ^ 2 :=
normEDS_even ..
lemma ψ_odd (m : ℤ) : W.ψ (2 * m + 1) =
W.ψ (m + 2) * W.ψ m ^ 3 - W.ψ (m - 1) * W.ψ (m + 1) ^ 3 :=
normEDS_odd ..
lemma Affine.CoordinateRing.mk_ψ (n : ℤ) : mk W (W.ψ n) = mk W (W.Ψ n) := by
simp only [ψ, normEDS, Ψ, preΨ, map_mul, map_pow, map_preNormEDS, ← mk_ψ₂_sq, ← pow_mul]
end ψ
section φ
/-! ### The bivariate polynomials `φₙ` -/
/-- The bivariate polynomials `φₙ`. -/
protected noncomputable def φ (n : ℤ) : R[X][Y] :=
C X * W.ψ n ^ 2 - W.ψ (n + 1) * W.ψ (n - 1)
open WeierstrassCurve (Ψ Φ φ)
@[simp]
lemma φ_zero : W.φ 0 = 1 := by
rw [φ, ψ_zero, zero_pow two_ne_zero, mul_zero, zero_sub, zero_add, ψ_one, one_mul, zero_sub,
ψ_neg, neg_neg, ψ_one]
@[simp]
lemma φ_one : W.φ 1 = C X := by
rw [φ, ψ_one, one_pow, mul_one, sub_self, ψ_zero, mul_zero, sub_zero]
@[simp]
lemma φ_two : W.φ 2 = C X * W.ψ₂ ^ 2 - C W.Ψ₃ := by
rw [φ, ψ_two, two_add_one_eq_three, ψ_three, show (2 - 1 : ℤ) = 1 by rfl, ψ_one, mul_one]
@[simp]
lemma φ_three : W.φ 3 = C X * C W.Ψ₃ ^ 2 - C W.preΨ₄ * W.ψ₂ ^ 2 := by
rw [φ, ψ_three, three_add_one_eq_four, ψ_four, mul_assoc, show (3 - 1 : ℤ) = 2 by rfl, ψ_two,
← sq]
@[simp]
lemma φ_four :
W.φ 4 = C X * C W.preΨ₄ ^ 2 * W.ψ₂ ^ 2 - C W.preΨ₄ * W.ψ₂ ^ 4 * C W.Ψ₃ + C W.Ψ₃ ^ 4 := by
rw [φ, ψ_four, show (4 + 1 : ℤ) = 2 * 2 + 1 by rfl, ψ_odd, two_add_two_eq_four, ψ_four,
show (2 - 1 : ℤ) = 1 by rfl, ψ_two, ψ_one, two_add_one_eq_three, show (4 - 1 : ℤ) = 3 by rfl,
ψ_three]
ring1
@[simp]
lemma φ_neg (n : ℤ) : W.φ (-n) = W.φ n := by
rw [φ, ψ_neg, neg_sq (R := R[X][Y]), neg_add_eq_sub, ← neg_sub n, ψ_neg, ← neg_add', ψ_neg,
neg_mul_neg (α := R[X][Y]), mul_comm <| W.ψ _, φ]
lemma Affine.CoordinateRing.mk_φ (n : ℤ) : mk W (W.φ n) = mk W (C <| W.Φ n) := by
simp_rw [φ, Φ, map_sub, map_mul, map_pow, mk_ψ, mk_Ψ_sq, Ψ, map_mul,
mul_mul_mul_comm _ <| mk W <| ite .., Int.even_add_one, Int.even_sub_one, ← sq, ite_not,
apply_ite C, apply_ite <| mk W, ite_pow, map_one, one_pow, mk_ψ₂_sq]
end φ
section Map
/-! ### Maps across ring homomorphisms -/
open WeierstrassCurve (Ψ Φ ψ φ)
variable (f : R →+* S)
lemma map_ψ₂ : (W.map f).ψ₂ = W.ψ₂.map (mapRingHom f) := by
simp only [ψ₂, Affine.map_polynomialY]
| lemma map_Ψ₂Sq : (W.map f).Ψ₂Sq = W.Ψ₂Sq.map f := by
simp only [Ψ₂Sq, map_b₂, map_b₄, map_b₆]
| Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean | 551 | 552 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Tape
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.PFun
import Mathlib.Computability.PostTuringMachine
/-!
# Turing machines
The files `PostTuringMachine.lean` and `TuringMachine.lean` define
a sequence of simple machine languages, starting with Turing machines and working
up to more complex languages based on Wang B-machines.
`PostTuringMachine.lean` covers the TM0 model and TM1 model;
`TuringMachine.lean` adds the TM2 model.
## Naming conventions
Each model of computation in this file shares a naming convention for the elements of a model of
computation. These are the parameters for the language:
* `Γ` is the alphabet on the tape.
* `Λ` is the set of labels, or internal machine states.
* `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and
later models achieve this by mixing it into `Λ`.
* `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks.
All of these variables denote "essentially finite" types, but for technical reasons it is
convenient to allow them to be infinite anyway. When using an infinite type, we will be interested
to prove that only finitely many values of the type are ever interacted with.
Given these parameters, there are a few common structures for the model that arise:
* `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is
finite, and for later models it is an infinite inductive type representing "possible program
texts".
* `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with
its environment.
* `Machine` is the set of all machines in the model. Usually this is approximately a function
`Λ → Stmt`, although different models have different ways of halting and other actions.
* `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step.
If `step c = none`, then `c` is a terminal state, and the result of the computation is read off
from `c`. Because of the type of `step`, these models are all deterministic by construction.
* `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model;
in most cases it is `List Γ`.
* `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from
`init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to
the final state to obtain the result. The type `Output` depends on the model.
* `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and
can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input
cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when
convenient, and prove that only finitely many of these states are actually accessible. This
formalizes "essentially finite" mentioned above.
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Relation
open Nat (iterate)
open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply'
iterate_zero_apply)
namespace Turing
/-!
## The TM2 model
The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite)
collection of stacks, each with elements of different types (the alphabet of stack `k : K` is
`Γ k`). The statements are:
* `push k (f : σ → Γ k) q` puts `f a` on the `k`-th stack, then does `q`.
* `pop k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, and removes this element from the stack, then does `q`.
* `peek k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, then does `q`.
* `load (f : σ → σ) q` reads nothing but applies `f` to the internal state, then does `q`.
* `branch (f : σ → Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`.
* `goto (f : σ → Λ)` jumps to label `f a`.
* `halt` halts on the next step.
The configuration is a tuple `(l, var, stk)` where `l : Option Λ` is the current label to run or
`none` for the halting state, `var : σ` is the (finite) internal state, and `stk : ∀ k, List (Γ k)`
is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not
`ListBlank`s, they have definite ends that can be detected by the `pop` command.)
Given a designated stack `k` and a value `L : List (Γ k)`, the initial configuration has all the
stacks empty except the designated "input" stack; in `eval` this designated stack also functions
as the output stack.
-/
namespace TM2
variable {K : Type*}
-- Index type of stacks
variable (Γ : K → Type*)
-- Type of stack elements
variable (Λ : Type*)
-- Type of function labels
variable (σ : Type*)
-- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive Stmt
| push : ∀ k, (σ → Γ k) → Stmt → Stmt
| peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| load : (σ → σ) → Stmt → Stmt
| branch : (σ → Bool) → Stmt → Stmt → Stmt
| goto : (σ → Λ) → Stmt
| halt : Stmt
open Stmt
instance Stmt.inhabited : Inhabited (Stmt Γ Λ σ) :=
⟨halt⟩
/-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) -/
structure Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Λ
/-- The internal state -/
var : σ
/-- The (finite) collection of internal stacks -/
stk : ∀ k, List (Γ k)
instance Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) :=
⟨⟨default, default, default⟩⟩
variable {Γ Λ σ}
section
variable [DecidableEq K]
/-- The step function for the TM2 model. -/
def stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S)
| goto f, v, S => ⟨some (f v), v, S⟩
| halt, v, S => ⟨none, v, S⟩
/-- The step function for the TM2 model. -/
def step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ)
| ⟨none, _, _⟩ => none
| ⟨some l, v, S⟩ => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2
/-- The (reflexive) reachability relation for the TM2 model. -/
def Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop :=
ReflTransGen fun a b ↦ b ∈ step M a
end
/-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/
def SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂
| goto l => ∀ v, l v ∈ S
| halt => True
section
open scoped Classical in
/-- The set of subtree statements in a statement. -/
noncomputable def stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ)
| Q@(push _ _ q) => insert Q (stmts₁ q)
| Q@(peek _ _ q) => insert Q (stmts₁ q)
| Q@(pop _ _ q) => insert Q (stmts₁ q)
| Q@(load _ q) => insert Q (stmts₁ q)
| Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q@(goto _) => {Q}
| Q@halt => {Q}
theorem stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁]
theorem stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by
classical
intro h₁₂ q₀ h₀₁
induction q₂ with (
simp only [stmts₁] at h₁₂ ⊢
simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂)
| branch f q₁ q₂ IH₁ IH₂ =>
rcases h₁₂ with (rfl | h₁₂ | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂))
· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂))
| goto l => subst h₁₂; exact h₀₁
| halt => subst h₁₂; exact h₀₁
| load _ q IH | _ _ _ q IH =>
rcases h₁₂ with (rfl | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (IH h₁₂)
theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂)
(hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by
induction q₂ with
simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton]
at h hs
| branch f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in
/-- The set of statements accessible from initial set `S` of labels. -/
noncomputable def stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) :=
Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q))
theorem stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) :
some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩
end
variable [Inhabited Λ]
/-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states in `S`. -/
def Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) :=
default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q)
theorem stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ}
(ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls)
variable [DecidableEq K]
theorem step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) :
∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S
| ⟨some l₁, v, T⟩, c', h₁, h₂ => by
replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂)
simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c'
revert h₂; induction M l₁ generalizing v T with intro hs
| branch p q₁' q₂' IH₁ IH₂ =>
unfold stepAux; cases p v
· exact IH₂ _ _ hs.2
· exact IH₁ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited σ]
/-- The initial state of the TM2 model. The input is provided on a designated stack. -/
def init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ :=
⟨some default, default, update (fun _ ↦ []) k L⟩
/-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/
def eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) :=
(Turing.eval (step M) (init k L)).map fun c ↦ c.stk k
end TM2
/-!
## TM2 emulator in TM1
To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a
TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of
stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack
1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this:
```
bottom: ... | _ | T | _ | _ | _ | _ | ...
stack 1: ... | _ | b | a | _ | _ | _ | ...
stack 2: ... | _ | f | e | d | c | _ | ...
```
where a tape element is a vertical slice through the diagram. Here the alphabet is
`Γ' := Bool × ∀ k, Option (Γ k)`, where:
* `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the
tail of all stacks. It is never modified.
* `stk k : Option (Γ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is
the blank value). Note that the head of the stack is at the far end; this is so that push and pop
don't have to do any shifting.
In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions,
it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the
end of the appropriate stack, make its changes, and then return to the bottom. So the states are:
* `normal (l : Λ)`: waiting at `bottom` to execute function `l`
* `go k (s : StAct k) (q : Stmt₂)`: travelling to the right to get to the end of stack `k` in
order to perform stack action `s`, and later continue with executing `q`
* `ret (q : Stmt₂)`: travelling to the left after having performed a stack action, and executing
`q` once we arrive
Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the
length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)`
steps to run when emulated in TM1, where `m` is the length of the input.
-/
namespace TM2to1
-- A displaced lemma proved in unnecessary generality
theorem stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Γ : K → Type*)
variable {Λ σ : Type*}
/-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/
def Γ' :=
Bool × ∀ k, Option (Γ k)
variable {K Γ}
instance Γ'.inhabited : Inhabited (Γ' K Γ) :=
⟨⟨false, fun _ ↦ none⟩⟩
instance Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) :=
instFintypeProd _ _
/-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function
to express the program state in terms of a tape with only the stacks themselves. -/
def addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) :=
ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩)
theorem addBottom_map (L : ListBlank (∀ k, Option (Γ k))) :
(addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by
simp only [addBottom, ListBlank.map_cons]
convert ListBlank.cons_head_tail L
generalize ListBlank.tail L = L'
refine L'.induction_on fun l ↦ ?_; simp
theorem addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k))
(L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
(addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by
cases n <;>
simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons]
congr; symm; apply ListBlank.map_modifyNth; intro; rfl
theorem addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth n).2 = L.nth n := by
conv => rhs; rw [← addBottom_map L, ListBlank.nth_map]
theorem addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth (n + 1)).1 = false := by
rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map]
theorem addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by
rw [addBottom, ListBlank.head_cons]
variable (K Γ σ) in
/-- A stack action is a command that interacts with the top of a stack. Our default position
is at the bottom of all the stacks, so we have to hold on to this action while going to the end
to modify the stack. -/
inductive StAct (k : K)
| push : (σ → Γ k) → StAct k
| peek : (σ → Option (Γ k) → σ) → StAct k
| pop : (σ → Option (Γ k) → σ) → StAct k
instance StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) :=
⟨StAct.peek fun s _ ↦ s⟩
section
open StAct
/-- The TM2 statement corresponding to a stack action. -/
def stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ
| push f => TM2.Stmt.push k f
| peek f => TM2.Stmt.peek k f
| pop f => TM2.Stmt.pop k f
/-- The effect of a stack action on the local variables, given the value of the stack. -/
def stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ
| push _ => v
| peek f => f v l.head?
| pop f => f v l.head?
/-- The effect of a stack action on the stack. -/
def stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k)
| push f => f v :: l
| peek _ => l
| pop _ => l.tail
/-- We have partitioned the TM2 statements into "stack actions", which require going to the end
of the stack, and all other actions, which do not. This is a modified recursor which lumps the
stack actions into one. -/
@[elab_as_elim]
def stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l}
(run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q))
(load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q))
(branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂))
(goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n
| TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.branch _ q₁ q₂ =>
branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂)
| TM2.Stmt.goto _ => goto _
| TM2.Stmt.halt => halt
theorem supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by
cases s <;> rfl
end
variable (K Γ Λ σ)
/-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the
next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and
return to the bottom, respectively. -/
inductive Λ'
| normal : Λ → Λ'
| go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ'
| ret : TM2.Stmt Γ Λ σ → Λ'
variable {K Γ Λ σ}
open Λ'
instance Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) :=
⟨normal default⟩
open TM1.Stmt
section
variable [DecidableEq K]
/-- The program corresponding to state transitions at the end of a stack. Here we start out just
after the top of the stack, and should end just after the new top of the stack. -/
def trStAct {k : K} (q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ) :
StAct K Γ σ k → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q
| StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q
| StAct.pop f =>
branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q)
(move Dir.left <|
(load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q)
/-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty
except for the input stack, and the stack bottom mark is set at the head. -/
def trInit (k : K) (L : List (Γ k)) : List (Γ' K Γ) :=
let L' : List (Γ' K Γ) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a))
(true, L'.headI.2) :: L'.tail
theorem step_run {k : K} (q : TM2.Stmt Γ Λ σ) (v : σ) (S : ∀ k, List (Γ k)) : ∀ s : StAct K Γ σ k,
TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s))
| StAct.push _ => rfl
| StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl
| StAct.pop _ => rfl
end
/-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents,
but stack actions are deferred by going to the corresponding `go` state, so that we can find the
appropriate stack top. -/
def trNormal : TM2.Stmt Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q
| TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q
| TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q
| TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q)
| TM2.Stmt.branch f q₁ q₂ => branch (fun _ ↦ f) (trNormal q₁) (trNormal q₂)
| TM2.Stmt.goto l => goto fun _ s ↦ normal (l s)
| TM2.Stmt.halt => halt
theorem trNormal_run {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by
cases s <;> rfl
section
open scoped Classical in
/-- The set of machine states accessible from an initial TM2 statement. -/
noncomputable def trStmts₁ : TM2.Stmt Γ Λ σ → Finset (Λ' K Γ Λ σ)
| TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.load _ q => trStmts₁ q
| TM2.Stmt.branch _ q₁ q₂ => trStmts₁ q₁ ∪ trStmts₁ q₂
| _ => ∅
theorem trStmts₁_run {k : K} {s : StAct K Γ σ k} {q : TM2.Stmt Γ Λ σ} :
open scoped Classical in
trStmts₁ (stRun s q) = {go k s q, ret q} ∪ trStmts₁ q := by
cases s <;> simp only [trStmts₁, stRun]
theorem tr_respects_aux₂ [DecidableEq K] {k : K} {q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ} {v : σ}
{S : ∀ k, List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : ∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) :
let v' := stVar v (S k) o
let Sk' := stWrite v (S k) o
let S' := update S k Sk'
∃ L' : ListBlank (∀ k, Option (Γ k)),
(∀ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧
TM1.stepAux (trStAct q o) v
((Tape.move Dir.right)^[(S k).length] (Tape.mk' ∅ (addBottom L))) =
TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' ∅ (addBottom L'))) := by
simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux]
| push f =>
have := Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k (some (f v)))
refine
⟨_, fun k' ↦ ?_, by
-- Porting note: `rw [...]` to `erw [...]; rfl`.
-- https://github.com/leanprover-community/mathlib4/issues/5164
rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this]
erw [addBottom_modifyNth fun a ↦ update a k (some (f v))]
rw [Nat.add_one, iterate_succ']
rfl⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h
<;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map]
· rw [List.getI_eq_getElem _, List.getElem_append_right] <;>
simp only [List.length_append, List.length_reverse, List.length_map, ← h,
Nat.sub_self, List.length_singleton, List.getElem_singleton,
le_refl, Nat.lt_succ_self]
rw [← proj_map_nth, hL, ListBlank.nth_mk]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
| peek f =>
rw [Function.update_eq_self]
use L, hL; rw [Tape.move_left_right]; congr
cases e : S k; · rfl
rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left,
Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e,
List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length]
rfl
| pop f =>
rcases e : S k with - | ⟨hd, tl⟩
· simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length,
Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil]
rw [← e, Function.update_eq_self]
exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩
· refine
⟨_, fun k' ↦ ?_, by
erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst,
cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head,
Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k none),
addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd,
stk_nth_val _ (hL k), e,
show (List.cons hd tl).reverse[tl.length]? = some hd by
rw [List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length],
List.head?, List.tail]⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail]
· rw [List.getI_eq_default]
· rfl
rw [h, List.length_reverse, List.length_map]
rw [← proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
end
variable [DecidableEq K]
variable (M : Λ → TM2.Stmt Γ Λ σ)
/-- The TM2 emulator machine states written as a TM1 program.
This handles the `go` and `ret` states, which shuttle to and from a stack top. -/
def tr : Λ' K Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| normal q => trNormal (M q)
| go k s q =>
branch (fun a _ ↦ (a.2 k).isNone) (trStAct (goto fun _ _ ↦ ret q) s)
(move Dir.right <| goto fun _ _ ↦ go k s q)
| ret q => branch (fun a _ ↦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ ↦ ret q)
/-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/
inductive TrCfg : TM2.Cfg Γ Λ σ → TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ → Prop
| mk {q : Option Λ} {v : σ} {S : ∀ k, List (Γ k)} (L : ListBlank (∀ k, Option (Γ k))) :
(∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) →
TrCfg ⟨q, v, S⟩ ⟨q.map normal, v, Tape.mk' ∅ (addBottom L)⟩
theorem tr_respects_aux₁ {k} (o q v) {S : List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n ≤ S.length) :
Reaches₀ (TM1.step (tr M)) ⟨some (go k o q), v, Tape.mk' ∅ (addBottom L)⟩
⟨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ := by
induction' n with n IH; · rfl
apply (IH (le_of_lt H)).tail
rw [iterate_succ_apply']
simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head,
addBottom_nth_snd, Option.mem_def]
rw [stk_nth_val _ hL, List.getElem?_eq_getElem]
· rfl
· rwa [List.length_reverse]
theorem tr_respects_aux₃ {q v} {L : ListBlank (∀ k, Option (Γ k))} (n) : Reaches₀ (TM1.step (tr M))
⟨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩
⟨some (ret q), v, Tape.mk' ∅ (addBottom L)⟩ := by
induction' n with n IH; · rfl
refine Reaches₀.head ?_ IH
simp only [Option.mem_def, TM1.step]
rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat,
addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left]
rfl
theorem tr_respects_aux {q v T k} {S : ∀ k, List (Γ k)}
(hT : ∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse)
(o : StAct K Γ σ k)
(IH : ∀ {v : σ} {S : ∀ k : K, List (Γ k)} {T : ListBlank (∀ k, Option (Γ k))},
| (∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) →
∃ b, TrCfg (TM2.stepAux q v S) b ∧
Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' ∅ (addBottom T))) b) :
∃ b, TrCfg (TM2.stepAux (stRun o q) v S) b ∧ Reaches (TM1.step (tr M))
| Mathlib/Computability/TuringMachine.lean | 656 | 659 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Algebra.Module.BigOperators
import Mathlib.GroupTheory.Perm.Basic
import Mathlib.GroupTheory.Perm.Finite
import Mathlib.GroupTheory.Perm.List
import Mathlib.GroupTheory.Perm.Sign
/-!
# Cycles of a permutation
This file starts the theory of cycles in permutations.
## Main definitions
In the following, `f : Equiv.Perm β`.
* `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`.
* `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated
applications of `f`, and `f` is not the identity.
* `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by
repeated applications of `f`.
## Notes
`Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways:
* `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set.
* `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton).
* `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them.
-/
open Equiv Function Finset
variable {ι α β : Type*}
namespace Equiv.Perm
/-! ### `SameCycle` -/
section SameCycle
variable {f g : Perm α} {p : α → Prop} {x y z : α}
/-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/
def SameCycle (f : Perm α) (x y : α) : Prop :=
∃ i : ℤ, (f ^ i) x = y
@[refl]
theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x :=
⟨0, rfl⟩
theorem SameCycle.rfl : SameCycle f x x :=
SameCycle.refl _ _
protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h]
@[symm]
theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ =>
⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩
theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x :=
⟨SameCycle.symm, SameCycle.symm⟩
@[trans]
theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z :=
fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩
variable (f) in
theorem SameCycle.equivalence : Equivalence (SameCycle f) :=
⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩
/-- The setoid defined by the `SameCycle` relation. -/
def SameCycle.setoid (f : Perm α) : Setoid α where
r := f.SameCycle
iseqv := SameCycle.equivalence f
@[simp]
theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle]
@[simp]
theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y :=
(Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle]
alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv
@[simp]
theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) :=
exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq]
theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by
simp [sameCycle_conj]
theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by
rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply,
(f ^ i).injective.eq_iff]
theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y :=
let ⟨_, hn⟩ := h
(hx.perm_zpow _).eq.symm.trans hn
theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y :=
h.eq_of_left <| h.apply_eq_self_iff.2 hy
@[simp]
theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y :=
(Equiv.addRight 1).exists_congr_left.trans <| by
simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp]
@[simp]
theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm]
@[simp]
theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by
rw [← sameCycle_apply_left, apply_inv_self]
@[simp]
theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by
rw [← sameCycle_apply_right, apply_inv_self]
@[simp]
theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y :=
(Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add]
@[simp]
theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm]
@[simp]
theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_left]
@[simp]
theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_right]
alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left
alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right
alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left
alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right
alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left
alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right
alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left
alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right
theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
@[simp]
theorem sameCycle_subtypePerm {h} {x y : { x // p x }} :
(f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y :=
exists_congr fun n => by simp [Subtype.ext_iff]
alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm
@[simp]
theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} :
SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y :=
exists_congr fun n => by
rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff]
alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain
theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by
rintro ⟨k, rfl⟩
use (k % orderOf f).natAbs
have h₀ := Int.natCast_pos.mpr (orderOf_pos f)
have h₁ := Int.emod_nonneg k h₀.ne'
rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf]
refine ⟨?_, by rfl⟩
rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁]
exact Int.emod_lt_of_pos _ h₀
theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by
obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq'
· refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩
rw [pow_orderOf_eq_one, pow_zero]
· exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩
theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by
obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h
exact ⟨⟨i, hi⟩, hx⟩
theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, (f ^ i) x = y := by
obtain ⟨i, _, hi⟩ := h.exists_pow_eq'
exact ⟨i, hi⟩
instance (f : Perm α) [DecidableRel (SameCycle f)] :
DecidableRel (SameCycle f⁻¹) := fun x y =>
decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm
instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y =>
decidable_of_iff (x = y) sameCycle_one.symm
end SameCycle
/-!
### `IsCycle`
-/
section IsCycle
variable {f g : Perm α} {x y : α}
/-- A cycle is a non identity permutation where any two nonfixed points of the permutation are
related by repeated application of the permutation. -/
def IsCycle (f : Perm α) : Prop :=
∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y
theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h
@[simp]
theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl
protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
SameCycle f x y :=
let ⟨g, hg⟩ := hf
let ⟨a, ha⟩ := hg.2 hx
let ⟨b, hb⟩ := hg.2 hy
⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩
theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y :=
IsCycle.sameCycle
theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ :=
hf.imp fun _ ⟨hx, h⟩ =>
⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩
@[simp]
theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f :=
⟨fun h => h.inv, IsCycle.inv⟩
theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by
rintro ⟨x, hx, h⟩
refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩
rw [← apply_inv_self g y]
exact (h <| eq_inv_iff_eq.not.2 hy).conj
protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) :
IsCycle g → IsCycle (g.extendDomain f) := by
rintro ⟨a, ha, ha'⟩
refine ⟨f a, ?_, fun b hb => ?_⟩
· rw [extendDomain_apply_image]
exact Subtype.coe_injective.ne (f.injective.ne ha)
have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by
rw [apply_symm_apply, Subtype.coe_mk]
rw [h] at hb ⊢
simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb
exact (ha' hb).extendDomain
theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y :=
⟨fun hf y =>
⟨fun ⟨i, hi⟩ hy =>
hx <| by
rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi
rw [hi, hy],
hf.exists_zpow_eq hx⟩,
fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩
section Finite
variable [Finite α]
theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
∃ i : ℕ, (f ^ i) x = y := by
let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy
classical exact
⟨(n % orderOf f).toNat, by
{have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f)))
rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩
end Finite
variable [DecidableEq α]
theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) :=
⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) =>
if hya : y = a then ⟨0, hya⟩
else
⟨1, by
rw [zpow_one, swap_apply_def]
split_ifs at * <;> tauto⟩⟩
protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by
rintro ⟨x, y, hxy, rfl⟩
exact isCycle_swap hxy
variable [Fintype α]
theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ #f.support :=
two_le_card_support_of_ne_one h.ne_one
/-- The subgroup generated by a cycle is in bijection with its support -/
noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) :
(Subgroup.zpowers σ) ≃ σ.support :=
Equiv.ofBijective
(fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) =>
⟨(τ : Perm α) (Classical.choose hσ), by
obtain ⟨τ, n, rfl⟩ := τ
rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support]
exact (Classical.choose_spec hσ).1⟩)
(by
constructor
· rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h
ext y
by_cases hy : σ y = y
· simp_rw [zpow_apply_eq_self_of_apply_eq_self hy]
· obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy
rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i]
exact congr_arg _ (Subtype.ext_iff.mp h)
· rintro ⟨y, hy⟩
rw [mem_support] at hy
obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy
exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩)
@[simp]
theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} :
hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ =
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ :=
rfl
@[simp]
theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) :
hσ.zpowersEquivSupport.symm
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ =
⟨σ ^ n, n, rfl⟩ :=
(Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply
protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = #f.support := by
rw [← Fintype.card_zpowers, ← Fintype.card_coe]
convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf)
theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] :
∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
induction n with
| zero => exact fun _ h => ⟨0, h⟩
| succ n hn =>
| intro b x f hb h
exact if hfbx : f x = b then ⟨0, hfbx⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ←
f.injective.eq_iff, apply_inv_self]
| Mathlib/GroupTheory/Perm/Cycle/Basic.lean | 360 | 366 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.Module.End
import Mathlib.Algebra.Ring.Prod
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Tactic.FinCases
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `ZMod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
* A coercion `cast` is defined from `ZMod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
assert_not_exists Field Submodule TwoSidedIdeal
open Function ZMod
namespace ZMod
/-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/
def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n
| 0, h => (h.ne _ rfl).elim
| _ + 1, _ => .refl _
instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ)
/-- `val a` is a natural number defined as:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
See `ZMod.valMinAbs` for a variant that takes values in the integers.
-/
def val : ∀ {n : ℕ}, ZMod n → ℕ
| 0 => Int.natAbs
| n + 1 => ((↑) : Fin (n + 1) → ℕ)
theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by
cases n
· cases NeZero.ne 0 rfl
exact Fin.is_lt a
theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n :=
a.val_lt.le
@[simp]
theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0
| 0 => rfl
| _ + 1 => rfl
@[simp]
theorem val_one' : (1 : ZMod 0).val = 1 :=
rfl
@[simp]
theorem val_neg' {n : ZMod 0} : (-n).val = n.val :=
Int.natAbs_neg n
@[simp]
theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val :=
Int.natAbs_mul m n
@[simp]
theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by
cases n
· rw [Nat.mod_zero]
exact Int.natAbs_natCast a
· apply Fin.val_natCast
lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rwa [val_natCast, Nat.mod_eq_of_lt]
lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast ..
lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) :=
val_natCast_of_lt han
theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by
simp only [val]
rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one]
lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by
rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h]
instance charP (n : ℕ) : CharP (ZMod n) n where
cast_eq_zero_iff := by
intro k
rcases n with - | n
· simp [zero_dvd_iff, Int.natCast_eq_zero]
· exact Fin.natCast_eq_zero
@[simp]
theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n :=
CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n)
/-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `addOrderOf_coe'`. -/
@[simp]
theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rcases a with - | a
· simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right,
Nat.pos_of_ne_zero n0, Nat.div_self]
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one]
/-- This lemma works in the case in which `a ≠ 0`. The version where
`ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/
@[simp]
theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one]
/-- We have that `ringChar (ZMod n) = n`. -/
theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
rw [ringChar.eq_iff]
exact ZMod.charP n
theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
CharP.cast_eq_zero (ZMod n) n
@[simp]
theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by
rw [← Nat.cast_add_one, natCast_self (n + 1)]
section UniversalProperty
variable {n : ℕ} {R : Type*}
section
variable [AddGroupWithOne R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `ZMod.castHom` for a bundled version. -/
def cast : ∀ {n : ℕ}, ZMod n → R
| 0 => Int.cast
| _ + 1 => fun i => i.val
@[simp]
theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by
delta ZMod.cast
cases n
· exact Int.cast_zero
· simp
theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by
cases n
· cases NeZero.ne 0 rfl
rfl
variable {S : Type*} [AddGroupWithOne S]
@[simp]
theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by
cases n
· rfl
· simp [ZMod.cast]
@[simp]
theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by
cases n
· rfl
· simp [ZMod.cast]
end
/-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring,
see `ZMod.natCast_val`. -/
theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.cast_val_eq_self
theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) :=
natCast_zmod_val
theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) :=
natCast_rightInverse.surjective
/-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary
ring, see `ZMod.intCast_cast`. -/
@[norm_cast]
theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by
cases n
· simp [ZMod.cast, ZMod]
· dsimp [ZMod.cast]
rw [Int.cast_natCast, natCast_zmod_val]
theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) :=
intCast_zmod_cast
theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) :=
intCast_rightInverse.surjective
lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall
lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists
theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i
| 0, _ => Int.cast_id
| _ + 1, i => natCast_zmod_val i
@[simp]
theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id :=
funext (cast_id n)
variable (R) [Ring R]
/-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/
@[simp]
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n
· cases NeZero.ne 0 rfl
rfl
/-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/
@[simp]
theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by
cases n
· exact congr_arg (Int.cast ∘ ·) ZMod.cast_id'
· ext
simp [ZMod, ZMod.cast]
variable {R}
@[simp]
theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i :=
congr_fun (natCast_comp_val R) i
@[simp]
theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i :=
congr_fun (intCast_comp_cast R) i
theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) :
(cast (a + b) : ℤ) =
if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by
rcases n with - | n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· rw [Nat.cast_sub h]
congr
· rfl
section CharDvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variable {m : ℕ} [CharP R m]
@[simp]
theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by
rcases n with - | n
· exact Int.cast_one
show ((1 % (n + 1) : ℕ) : R) = 1
cases n
· rw [Nat.dvd_one] at h
subst m
subsingleton [CharP.CharOne.subsingleton]
rw [Nat.mod_eq_of_lt]
· exact Nat.cast_one
exact Nat.lt_of_sub_eq_succ rfl
theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by
cases n
· apply Int.cast_add
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by
cases n
· apply Int.cast_mul
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
/-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`.
See also `ZMod.lift` for a generalized version working in `AddGroup`s.
-/
def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where
toFun := cast
map_zero' := cast_zero
map_one' := cast_one h
map_add' := cast_add h
map_mul' := cast_mul h
@[simp]
theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i :=
rfl
@[simp]
theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
(castHom h R).map_sub a b
@[simp]
theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) :=
(castHom h R).map_neg a
@[simp]
theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k :=
(castHom h R).map_pow a k
@[simp, norm_cast]
theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
map_natCast (castHom h R) k
@[simp, norm_cast]
theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
map_intCast (castHom h R) k
end CharDvd
section CharEq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [CharP R n]
@[simp]
theorem cast_one' : (cast (1 : ZMod n) : R) = 1 :=
cast_one dvd_rfl
@[simp]
theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b :=
cast_add dvd_rfl a b
@[simp]
theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b :=
cast_mul dvd_rfl a b
@[simp]
theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
cast_sub dvd_rfl a b
@[simp]
theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k :=
cast_natCast dvd_rfl k
@[simp, norm_cast]
theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k :=
cast_intCast dvd_rfl k
variable (R)
theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by
rw [injective_iff_map_eq_zero]
intro x
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x
rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n]
exact id
theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) :
Function.Bijective (ZMod.castHom (dvd_refl n) R) := by
haveI : NeZero n :=
⟨by
intro hn
rw [hn] at h
exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩
rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true]
apply ZMod.castHom_injective
/-- The unique ring isomorphism between `ZMod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R :=
RingEquiv.ofBijective _ (ZMod.castHom_bijective R h)
/-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`.
If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv`
below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/
noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) :
ZMod p ≃+* R :=
have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt)
-- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`.
have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R)
ZMod.ringEquiv R hR
@[simp]
lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime)
(hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl
/-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/
def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by
rcases m with - | m <;> rcases n with - | n
· exact RingEquiv.refl _
· exfalso
exact n.succ_ne_zero h.symm
· exfalso
exact m.succ_ne_zero h
· exact
{ finCongr h with
map_mul' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h]
map_add' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] }
@[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by
cases a <;> rfl
lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by
rw [ringEquivCongr_refl]
rfl
lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) :
(ringEquivCongr hab).symm = ringEquivCongr hab.symm := by
subst hab
cases a <;> rfl
lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) :
(ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by
subst hab hbc
cases a <;> rfl
lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) :
ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by
rw [← ringEquivCongr_trans hab hbc]
rfl
lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) :
ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by
subst h
cases a <;> rfl
lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) :
ZMod.ringEquivCongr h z = z := by
subst h
cases a <;> rfl
end CharEq
end UniversalProperty
variable {m n : ℕ}
@[simp]
theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0
| 0, _ => Int.natAbs_eq_zero
| n + 1, a => by
rw [Fin.ext_iff]
exact Iff.rfl
theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] :=
CharP.intCast_eq_intCast (ZMod c) c
theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.intCast_eq_intCast_iff a b c
theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by
have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _
have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a)
refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_
rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id]
theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by
simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c
theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.natCast_eq_natCast_iff a b c
theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by
rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd]
theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by
rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd]
theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by
rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd]
theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by
cases n
· rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl
· rw [← val_intCast, val]; rfl
lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by
rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by
rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast]
@[simp]
theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by
dsimp [val, Fin.coe_neg]
cases n
· simp [Nat.mod_one]
· dsimp [ZMod, ZMod.cast]
rw [Fin.coe_neg_one]
/-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by
| rcases n with - | n
· dsimp [ZMod, ZMod.cast]; simp
· rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right]
| Mathlib/Data/ZMod/Basic.lean | 532 | 534 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.SetTheory.Game.State
/-!
# Domineering as a combinatorial game.
We define the game of Domineering, played on a chessboard of arbitrary shape
(possibly even disconnected).
Left moves by placing a domino vertically, while Right moves by placing a domino horizontally.
This is only a fragment of a full development;
in order to successfully analyse positions we would need some more theorems.
Most importantly, we need a general statement that allows us to discard irrelevant moves.
Specifically to domineering, we need the fact that
disjoint parts of the chessboard give sums of games.
-/
namespace SetTheory
namespace PGame
namespace Domineering
open Function
/-- The equivalence `(x, y) ↦ (x, y+1)`. -/
@[simps!]
def shiftUp : ℤ × ℤ ≃ ℤ × ℤ :=
(Equiv.refl ℤ).prodCongr (Equiv.addRight (1 : ℤ))
/-- The equivalence `(x, y) ↦ (x+1, y)`. -/
@[simps!]
def shiftRight : ℤ × ℤ ≃ ℤ × ℤ :=
(Equiv.addRight (1 : ℤ)).prodCongr (Equiv.refl ℤ)
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
-- Porting note: reducibility cannot be `local`. For now there are no dependents of this file so
-- being globally reducible is fine.
abbrev Board :=
Finset (ℤ × ℤ)
/-- Left can play anywhere that a square and the square below it are open. -/
def left (b : Board) : Finset (ℤ × ℤ) :=
b ∩ b.map shiftUp
/-- Right can play anywhere that a square and the square to the left are open. -/
def right (b : Board) : Finset (ℤ × ℤ) :=
b ∩ b.map shiftRight
theorem mem_left {b : Board} (x : ℤ × ℤ) : x ∈ left b ↔ x ∈ b ∧ (x.1, x.2 - 1) ∈ b :=
Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv)
theorem mem_right {b : Board} (x : ℤ × ℤ) : x ∈ right b ↔ x ∈ b ∧ (x.1 - 1, x.2) ∈ b :=
Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv)
/-- After Left moves, two vertically adjacent squares are removed from the board. -/
def moveLeft (b : Board) (m : ℤ × ℤ) : Board :=
(b.erase m).erase (m.1, m.2 - 1)
/-- After Left moves, two horizontally adjacent squares are removed from the board. -/
def moveRight (b : Board) (m : ℤ × ℤ) : Board :=
(b.erase m).erase (m.1 - 1, m.2)
theorem fst_pred_mem_erase_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) :
(m.1 - 1, m.2) ∈ b.erase m := by
rw [mem_right] at h
apply Finset.mem_erase_of_ne_of_mem _ h.2
exact ne_of_apply_ne Prod.fst (pred_ne_self m.1)
theorem snd_pred_mem_erase_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) :
(m.1, m.2 - 1) ∈ b.erase m := by
rw [mem_left] at h
apply Finset.mem_erase_of_ne_of_mem _ h.2
exact ne_of_apply_ne Prod.snd (pred_ne_self m.2)
theorem card_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : 2 ≤ Finset.card b := by
have w₁ : m ∈ b := (Finset.mem_inter.1 h).1
have w₂ : (m.1, m.2 - 1) ∈ b.erase m := snd_pred_mem_erase_of_mem_left h
have i₁ := Finset.card_erase_lt_of_mem w₁
have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂)
exact Nat.lt_of_le_of_lt i₂ i₁
|
theorem card_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : 2 ≤ Finset.card b := by
have w₁ : m ∈ b := (Finset.mem_inter.1 h).1
have w₂ := fst_pred_mem_erase_of_mem_right h
have i₁ := Finset.card_erase_lt_of_mem w₁
| Mathlib/SetTheory/Game/Domineering.lean | 86 | 90 |
/-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kyle Miller, Eric Wieser
-/
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Data.Int.GCD
import Mathlib.Tactic.NormNum
/-! # `norm_num` extensions for GCD-adjacent functions
This module defines some `norm_num` extensions for functions such as
`Nat.gcd`, `Nat.lcm`, `Int.gcd`, and `Int.lcm`.
Note that `Nat.coprime` is reducible and defined in terms of `Nat.gcd`, so the `Nat.gcd` extension
also indirectly provides a `Nat.coprime` extension.
-/
namespace Tactic
namespace NormNum
theorem int_gcd_helper' {d : ℕ} {x y : ℤ} (a b : ℤ) (h₁ : (d : ℤ) ∣ x) (h₂ : (d : ℤ) ∣ y)
(h₃ : x * a + y * b = d) : Int.gcd x y = d := by
refine Nat.dvd_antisymm ?_ (Int.natCast_dvd_natCast.1 (Int.dvd_coe_gcd h₁ h₂))
rw [← Int.natCast_dvd_natCast, ← h₃]
apply dvd_add
· exact Int.gcd_dvd_left.mul_right _
· exact Int.gcd_dvd_right.mul_right _
theorem nat_gcd_helper_dvd_left (x y : ℕ) (h : y % x = 0) : Nat.gcd x y = x :=
Nat.gcd_eq_left (Nat.dvd_of_mod_eq_zero h)
theorem nat_gcd_helper_dvd_right (x y : ℕ) (h : x % y = 0) : Nat.gcd x y = y :=
Nat.gcd_eq_right (Nat.dvd_of_mod_eq_zero h)
theorem nat_gcd_helper_2 (d x y a b : ℕ) (hu : x % d = 0) (hv : y % d = 0)
(h : x * a = y * b + d) : Nat.gcd x y = d := by
rw [← Int.gcd_natCast_natCast]
apply int_gcd_helper' a (-b)
(Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hu))
(Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hv))
rw [mul_neg, ← sub_eq_add_neg, sub_eq_iff_eq_add']
exact mod_cast h
theorem nat_gcd_helper_1 (d x y a b : ℕ) (hu : x % d = 0) (hv : y % d = 0)
(h : y * b = x * a + d) : Nat.gcd x y = d :=
(Nat.gcd_comm _ _).trans <| nat_gcd_helper_2 _ _ _ _ _ hv hu h
theorem nat_gcd_helper_1' (x y a b : ℕ) (h : y * b = x * a + 1) :
Nat.gcd x y = 1 :=
nat_gcd_helper_1 1 _ _ _ _ (Nat.mod_one _) (Nat.mod_one _) h
theorem nat_gcd_helper_2' (x y a b : ℕ) (h : x * a = y * b + 1) :
Nat.gcd x y = 1 :=
nat_gcd_helper_2 1 _ _ _ _ (Nat.mod_one _) (Nat.mod_one _) h
theorem nat_lcm_helper (x y d m : ℕ) (hd : Nat.gcd x y = d)
(d0 : Nat.beq d 0 = false)
(dm : x * y = d * m) : Nat.lcm x y = m :=
mul_right_injective₀ (Nat.ne_of_beq_eq_false d0) <| by
dsimp only
rw [← dm, ← hd, Nat.gcd_mul_lcm]
theorem int_gcd_helper {x y : ℤ} {x' y' d : ℕ}
(hx : x.natAbs = x') (hy : y.natAbs = y') (h : Nat.gcd x' y' = d) :
Int.gcd x y = d := by subst_vars; rw [Int.gcd_def]
|
theorem int_lcm_helper {x y : ℤ} {x' y' d : ℕ}
(hx : x.natAbs = x') (hy : y.natAbs = y') (h : Nat.lcm x' y' = d) :
| Mathlib/Tactic/NormNum/GCD.lean | 68 | 70 |
/-
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.UpperHalfPlane.Topology
import Mathlib.Analysis.SpecialFunctions.Arsinh
import Mathlib.Geometry.Euclidean.Inversion.Basic
/-!
# Metric on the upper half-plane
In this file we define a `MetricSpace` structure on the `UpperHalfPlane`. We use hyperbolic
(Poincaré) distance given by
`dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))` instead of the induced
Euclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of
the upper half-plane. However, we ensure that the projection to `TopologicalSpace` is
definitionally equal to the induced topological space structure.
We also prove that a metric ball/closed ball/sphere in Poincaré metric is a Euclidean ball/closed
ball/sphere with another center and radius.
-/
noncomputable section
open Filter Metric Real Set Topology
open scoped UpperHalfPlane ComplexConjugate NNReal Topology MatrixGroups
variable {z w : ℍ} {r : ℝ}
namespace UpperHalfPlane
instance : Dist ℍ :=
⟨fun z w => 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))⟩
theorem dist_eq (z w : ℍ) : dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im))) :=
rfl
theorem sinh_half_dist (z w : ℍ) :
sinh (dist z w / 2) = dist (z : ℂ) w / (2 * √(z.im * w.im)) := by
rw [dist_eq, mul_div_cancel_left₀ (arsinh _) two_ne_zero, sinh_arsinh]
theorem cosh_half_dist (z w : ℍ) :
cosh (dist z w / 2) = dist (z : ℂ) (conj (w : ℂ)) / (2 * √(z.im * w.im)) := by
rw [← sq_eq_sq₀, cosh_sq', sinh_half_dist, div_pow, div_pow, one_add_div, mul_pow, sq_sqrt]
· congr 1
simp only [Complex.dist_eq, Complex.sq_norm, Complex.normSq_sub, Complex.normSq_conj,
Complex.conj_conj, Complex.mul_re, Complex.conj_re, Complex.conj_im, coe_im]
ring
all_goals positivity
theorem tanh_half_dist (z w : ℍ) :
tanh (dist z w / 2) = dist (z : ℂ) w / dist (z : ℂ) (conj ↑w) := by
rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one]
positivity
theorem exp_half_dist (z w : ℍ) :
exp (dist z w / 2) = (dist (z : ℂ) w + dist (z : ℂ) (conj ↑w)) / (2 * √(z.im * w.im)) := by
rw [← sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div]
theorem cosh_dist (z w : ℍ) : cosh (dist z w) = 1 + dist (z : ℂ) w ^ 2 / (2 * z.im * w.im) := by
rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, ← two_mul, sinh_arsinh, div_pow, mul_pow,
sq_sqrt, sq (2 : ℝ), mul_assoc, ← mul_div_assoc, mul_assoc, mul_div_mul_left] <;> positivity
theorem sinh_half_dist_add_dist (a b c : ℍ) : sinh ((dist a b + dist b c) / 2) =
(dist (a : ℂ) b * dist (c : ℂ) (conj ↑b) + dist (b : ℂ) c * dist (a : ℂ) (conj ↑b)) /
(2 * √(a.im * c.im) * dist (b : ℂ) (conj ↑b)) := by
simp only [add_div _ _ (2 : ℝ), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm]
rw [← add_div, Complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist (b : ℂ) _),
dist_comm (b : ℂ), Complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im]
congr 2
rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (√a.im), mul_mul_mul_comm, mul_self_sqrt,
mul_comm] <;> exact (im_pos _).le
protected theorem dist_comm (z w : ℍ) : dist z w = dist w z := by
simp only [dist_eq, dist_comm (z : ℂ), mul_comm]
theorem dist_le_iff_le_sinh :
dist z w ≤ r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) ≤ sinh (r / 2) := by
rw [← div_le_div_iff_of_pos_right (zero_lt_two' ℝ), ← sinh_le_sinh, sinh_half_dist]
theorem dist_eq_iff_eq_sinh :
dist z w = r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) = sinh (r / 2) := by
rw [← div_left_inj' (two_ne_zero' ℝ), ← sinh_inj, sinh_half_dist]
theorem dist_eq_iff_eq_sq_sinh (hr : 0 ≤ r) :
dist z w = r ↔ dist (z : ℂ) w ^ 2 / (4 * z.im * w.im) = sinh (r / 2) ^ 2 := by
rw [dist_eq_iff_eq_sinh, ← sq_eq_sq₀, div_pow, mul_pow, sq_sqrt, mul_assoc]
· norm_num
all_goals positivity
protected theorem dist_triangle (a b c : ℍ) : dist a c ≤ dist a b + dist b c := by
rw [dist_le_iff_le_sinh, sinh_half_dist_add_dist, div_mul_eq_div_div _ _ (dist _ _), le_div_iff₀,
div_mul_eq_mul_div]
· gcongr
exact EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist (a : ℂ) b c (conj (b : ℂ))
· rw [dist_comm, dist_pos, Ne, Complex.conj_eq_iff_im]
exact b.im_ne_zero
theorem dist_le_dist_coe_div_sqrt (z w : ℍ) : dist z w ≤ dist (z : ℂ) w / √(z.im * w.im) := by
rw [dist_le_iff_le_sinh, ← div_mul_eq_div_div_swap, self_le_sinh_iff]
positivity
/-- An auxiliary `MetricSpace` instance on the upper half-plane. This instance has bad projection
to `TopologicalSpace`. We replace it later. -/
def metricSpaceAux : MetricSpace ℍ where
dist := dist
dist_self z := by rw [dist_eq, dist_self, zero_div, arsinh_zero, mul_zero]
dist_comm := UpperHalfPlane.dist_comm
dist_triangle := UpperHalfPlane.dist_triangle
eq_of_dist_eq_zero {z w} h := by
simpa [dist_eq, Real.sqrt_eq_zero', (mul_pos z.im_pos w.im_pos).not_le, Set.ext_iff] using h
open Complex
theorem cosh_dist' (z w : ℍ) :
Real.cosh (dist z w) = ((z.re - w.re) ^ 2 + z.im ^ 2 + w.im ^ 2) / (2 * z.im * w.im) := by
field_simp [cosh_dist, Complex.dist_eq, Complex.sq_norm, normSq_apply]
ring
/-- Euclidean center of the circle with center `z` and radius `r` in the hyperbolic metric. -/
def center (z : ℍ) (r : ℝ) : ℍ :=
⟨⟨z.re, z.im * Real.cosh r⟩, by positivity⟩
@[simp]
theorem center_re (z r) : (center z r).re = z.re :=
rfl
@[simp]
theorem center_im (z r) : (center z r).im = z.im * Real.cosh r :=
rfl
@[simp]
theorem center_zero (z : ℍ) : center z 0 = z :=
ext' rfl <| by rw [center_im, Real.cosh_zero, mul_one]
theorem dist_coe_center_sq (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) ^ 2 =
2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2 := by
have H : 2 * z.im * w.im ≠ 0 := by positivity
simp only [Complex.dist_eq, Complex.sq_norm, normSq_apply, coe_re, coe_im, center_re, center_im,
cosh_dist', mul_div_cancel₀ _ H, sub_sq z.im, mul_pow, Real.cosh_sq, sub_re, sub_im, mul_sub, ←
sq]
ring
theorem dist_coe_center (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) =
√(2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2) := by
rw [← sqrt_sq dist_nonneg, dist_coe_center_sq]
theorem cmp_dist_eq_cmp_dist_coe_center (z w : ℍ) (r : ℝ) :
cmp (dist z w) r = cmp (dist (z : ℂ) (w.center r)) (w.im * Real.sinh r) := by
letI := metricSpaceAux
rcases lt_or_le r 0 with hr₀ | hr₀
· trans Ordering.gt
exacts [(hr₀.trans_le dist_nonneg).cmp_eq_gt,
((mul_neg_of_pos_of_neg w.im_pos (sinh_neg_iff.2 hr₀)).trans_le dist_nonneg).cmp_eq_gt.symm]
have hr₀' : 0 ≤ w.im * Real.sinh r := by positivity
have hzw₀ : 0 < 2 * z.im * w.im := by positivity
#adaptation_note /-- https://github.com/leanprover/lean4/pull/6024
we need to give Lean the hint `(y := w.im * Real.sinh r)`. -/
simp only [← cosh_strictMonoOn.cmp_map_eq dist_nonneg hr₀,
← (pow_left_strictMonoOn₀ two_ne_zero).cmp_map_eq dist_nonneg (y := w.im * Real.sinh r) hr₀',
dist_coe_center_sq]
rw [← cmp_mul_pos_left hzw₀, ← cmp_sub_zero, ← mul_sub, ← cmp_add_right, zero_add]
theorem dist_eq_iff_dist_coe_center_eq :
dist z w = r ↔ dist (z : ℂ) (w.center r) = w.im * Real.sinh r :=
eq_iff_eq_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)
@[simp]
theorem dist_self_center (z : ℍ) (r : ℝ) :
dist (z : ℂ) (z.center r) = z.im * (Real.cosh r - 1) := by
rw [dist_of_re_eq (z.center_re r).symm, dist_comm, Real.dist_eq, mul_sub, mul_one]
exact abs_of_nonneg (sub_nonneg.2 <| le_mul_of_one_le_right z.im_pos.le (one_le_cosh _))
@[simp]
theorem dist_center_dist (z w : ℍ) :
dist (z : ℂ) (w.center (dist z w)) = w.im * Real.sinh (dist z w) :=
dist_eq_iff_dist_coe_center_eq.1 rfl
theorem dist_lt_iff_dist_coe_center_lt :
dist z w < r ↔ dist (z : ℂ) (w.center r) < w.im * Real.sinh r :=
lt_iff_lt_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)
theorem lt_dist_iff_lt_dist_coe_center :
r < dist z w ↔ w.im * Real.sinh r < dist (z : ℂ) (w.center r) :=
lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r)
theorem dist_le_iff_dist_coe_center_le :
dist z w ≤ r ↔ dist (z : ℂ) (w.center r) ≤ w.im * Real.sinh r :=
le_iff_le_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r)
theorem le_dist_iff_le_dist_coe_center :
r < dist z w ↔ w.im * Real.sinh r < dist (z : ℂ) (w.center r) :=
lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r)
/-- For two points on the same vertical line, the distance is equal to the distance between the
logarithms of their imaginary parts. -/
nonrec theorem dist_of_re_eq (h : z.re = w.re) : dist z w = dist (log z.im) (log w.im) := by
have h₀ : 0 < z.im / w.im := by positivity
rw [dist_eq_iff_dist_coe_center_eq, Real.dist_eq, ← abs_sinh, ← log_div z.im_ne_zero w.im_ne_zero,
sinh_log h₀, dist_of_re_eq, coe_im, coe_im, center_im, cosh_abs, cosh_log h₀, inv_div] <;>
[skip; exact h]
nth_rw 4 [← abs_of_pos w.im_pos]
simp only [← _root_.abs_mul, coe_im, Real.dist_eq]
congr 1
field_simp
ring
/-- Hyperbolic distance between two points is greater than or equal to the distance between the
logarithms of their imaginary parts. -/
theorem dist_log_im_le (z w : ℍ) : dist (log z.im) (log w.im) ≤ dist z w :=
calc
dist (log z.im) (log w.im) = dist (mk ⟨0, z.im⟩ z.im_pos) (mk ⟨0, w.im⟩ w.im_pos) :=
Eq.symm <| dist_of_re_eq rfl
_ ≤ dist z w := by
simp_rw [dist_eq]
dsimp only [coe_mk, mk_im]
gcongr
simpa [sqrt_sq_eq_abs] using Complex.abs_im_le_norm (z - w)
theorem im_le_im_mul_exp_dist (z w : ℍ) : z.im ≤ w.im * Real.exp (dist z w) := by
rw [← div_le_iff₀' w.im_pos, ← exp_log z.im_pos, ← exp_log w.im_pos, ← Real.exp_sub, exp_le_exp]
exact (le_abs_self _).trans (dist_log_im_le z w)
theorem im_div_exp_dist_le (z w : ℍ) : z.im / Real.exp (dist z w) ≤ w.im :=
(div_le_iff₀ (exp_pos _)).2 (im_le_im_mul_exp_dist z w)
/-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance
and the imaginary part of one of the points. -/
theorem dist_coe_le (z w : ℍ) : dist (z : ℂ) w ≤ w.im * (Real.exp (dist z w) - 1) :=
calc
dist (z : ℂ) w ≤ dist (z : ℂ) (w.center (dist z w)) + dist (w : ℂ) (w.center (dist z w)) :=
dist_triangle_right _ _ _
_ = w.im * (Real.exp (dist z w) - 1) := by
rw [dist_center_dist, dist_self_center, ← mul_add, ← add_sub_assoc, Real.sinh_add_cosh]
/-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance
and the imaginary part of one of the points. -/
theorem le_dist_coe (z w : ℍ) : w.im * (1 - Real.exp (-dist z w)) ≤ dist (z : ℂ) w :=
calc
w.im * (1 - Real.exp (-dist z w)) =
dist (z : ℂ) (w.center (dist z w)) - dist (w : ℂ) (w.center (dist z w)) := by
rw [dist_center_dist, dist_self_center, ← Real.cosh_sub_sinh]; ring
_ ≤ dist (z : ℂ) w := sub_le_iff_le_add.2 <| dist_triangle _ _ _
/-- The hyperbolic metric on the upper half plane. We ensure that the projection to
`TopologicalSpace` is definitionally equal to the subtype topology. -/
instance : MetricSpace ℍ :=
metricSpaceAux.replaceTopology <| by
refine le_antisymm (continuous_id_iff_le.1 ?_) ?_
· refine (@continuous_iff_continuous_dist ℍ ℍ metricSpaceAux.toPseudoMetricSpace _ _).2 ?_
have : ∀ x : ℍ × ℍ, 2 * √(x.1.im * x.2.im) ≠ 0 := fun x => by positivity
-- `continuity` fails to apply `Continuous.div`
apply_rules [Continuous.div, Continuous.mul, continuous_const, Continuous.arsinh,
Continuous.dist, continuous_coe.comp, continuous_fst, continuous_snd,
Real.continuous_sqrt.comp, continuous_im.comp]
· letI : MetricSpace ℍ := metricSpaceAux
refine le_of_nhds_le_nhds fun z => ?_
rw [nhds_induced]
refine (nhds_basis_ball.le_basis_iff (nhds_basis_ball.comap _)).2 fun R hR => ?_
have h₁ : 1 < R / im z + 1 := lt_add_of_pos_left _ (div_pos hR z.im_pos)
have h₀ : 0 < R / im z + 1 := one_pos.trans h₁
refine ⟨log (R / im z + 1), Real.log_pos h₁, ?_⟩
refine fun w hw => (dist_coe_le w z).trans_lt ?_
rwa [← lt_div_iff₀' z.im_pos, sub_lt_iff_lt_add, ← Real.lt_log_iff_exp_lt h₀]
theorem im_pos_of_dist_center_le {z : ℍ} {r : ℝ} {w : ℂ}
(h : dist w (center z r) ≤ z.im * Real.sinh r) : 0 < w.im :=
calc
0 < z.im * (Real.cosh r - Real.sinh r) := mul_pos z.im_pos (sub_pos.2 <| sinh_lt_cosh _)
_ = (z.center r).im - z.im * Real.sinh r := mul_sub _ _ _
_ ≤ (z.center r).im - dist (z.center r : ℂ) w := sub_le_sub_left (by rwa [dist_comm]) _
_ ≤ w.im := sub_le_comm.1 <| (le_abs_self _).trans (abs_im_le_norm <| z.center r - w)
theorem image_coe_closedBall (z : ℍ) (r : ℝ) :
((↑) : ℍ → ℂ) '' closedBall (α := ℍ) z r = closedBall ↑(z.center r) (z.im * Real.sinh r) := by
ext w; constructor
· rintro ⟨w, hw, rfl⟩
exact dist_le_iff_dist_coe_center_le.1 hw
· intro hw
lift w to ℍ using im_pos_of_dist_center_le hw
exact mem_image_of_mem _ (dist_le_iff_dist_coe_center_le.2 hw)
theorem image_coe_ball (z : ℍ) (r : ℝ) :
((↑) : ℍ → ℂ) '' ball (α := ℍ) z r = ball ↑(z.center r) (z.im * Real.sinh r) := by
ext w; constructor
· rintro ⟨w, hw, rfl⟩
exact dist_lt_iff_dist_coe_center_lt.1 hw
· intro hw
lift w to ℍ using im_pos_of_dist_center_le (ball_subset_closedBall hw)
exact mem_image_of_mem _ (dist_lt_iff_dist_coe_center_lt.2 hw)
theorem image_coe_sphere (z : ℍ) (r : ℝ) :
((↑) : ℍ → ℂ) '' sphere (α := ℍ) z r = sphere ↑(z.center r) (z.im * Real.sinh r) := by
ext w; constructor
· rintro ⟨w, hw, rfl⟩
exact dist_eq_iff_dist_coe_center_eq.1 hw
· intro hw
lift w to ℍ using im_pos_of_dist_center_le (sphere_subset_closedBall hw)
exact mem_image_of_mem _ (dist_eq_iff_dist_coe_center_eq.2 hw)
instance : ProperSpace ℍ := by
refine ⟨fun z r => ?_⟩
rw [IsInducing.subtypeVal.isCompact_iff (f := ((↑) : ℍ → ℂ)), image_coe_closedBall]
apply isCompact_closedBall
theorem isometry_vertical_line (a : ℝ) : Isometry fun y => mk ⟨a, exp y⟩ (exp_pos y) := by
refine Isometry.of_dist_eq fun y₁ y₂ => ?_
rw [dist_of_re_eq]
exacts [congr_arg₂ _ (log_exp _) (log_exp _), rfl]
theorem isometry_real_vadd (a : ℝ) : Isometry (a +ᵥ · : ℍ → ℍ) :=
Isometry.of_dist_eq fun y₁ y₂ => by simp only [dist_eq, coe_vadd, vadd_im, dist_add_left]
theorem isometry_pos_mul (a : { x : ℝ // 0 < x }) : Isometry (a • · : ℍ → ℍ) := by
refine Isometry.of_dist_eq fun y₁ y₂ => ?_
simp only [dist_eq, coe_pos_real_smul, pos_real_im]; congr 2
rw [dist_smul₀, mul_mul_mul_comm, Real.sqrt_mul (mul_self_nonneg _), Real.sqrt_mul_self_eq_abs,
Real.norm_eq_abs, mul_left_comm]
exact mul_div_mul_left _ _ (mt _root_.abs_eq_zero.1 a.2.ne')
/-- `SL(2, ℝ)` acts on the upper half plane as an isometry. -/
instance : IsIsometricSMul SL(2, ℝ) ℍ :=
⟨fun g => by
have h₀ : Isometry (fun z => ModularGroup.S • z : ℍ → ℍ) :=
Isometry.of_dist_eq fun y₁ y₂ => by
have h₁ : 0 ≤ im y₁ * im y₂ := mul_nonneg y₁.property.le y₂.property.le
have h₂ : ‖(y₁ * y₂ : ℂ)‖ ≠ 0 := by simp [y₁.ne_zero, y₂.ne_zero]
simp_rw [modular_S_smul, inv_neg, dist_eq, coe_mk, dist_neg_neg,
dist_inv_inv₀ y₁.ne_zero y₂.ne_zero, mk_im, neg_im, inv_im, coe_im, neg_div, neg_neg,
div_mul_div_comm, ← normSq_mul, Real.sqrt_div h₁, ← norm_def, mul_div (2 : ℝ)]
| rw [div_div_div_comm, ← norm_mul, div_self h₂, div_one]
by_cases hc : g 1 0 = 0
· obtain ⟨u, v, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_eq_zero g hc
rw [h]
exact (isometry_real_vadd v).comp (isometry_pos_mul u)
· obtain ⟨u, v, w, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_ne_zero g hc
rw [h]
exact
| Mathlib/Analysis/Complex/UpperHalfPlane/Metric.lean | 333 | 340 |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Alex Kontorovich
-/
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.Filter.Tendsto
import Mathlib.Order.Filter.Bases.Finite
/-!
# (Co)product of a family of filters
In this file we define two filters on `Π i, α i` and prove some basic properties of these filters.
* `Filter.pi (f : Π i, Filter (α i))` to be the maximal filter on `Π i, α i` such that
`∀ i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as
`Π i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed
products.
* `Filter.coprodᵢ (f : Π i, Filter (α i))`: a generalization of `Filter.coprod`; it is the supremum
of `comap (eval i) (f i)`.
-/
open Set Function Filter
namespace Filter
variable {ι : Type*} {α : ι → Type*} {f f₁ f₂ : (i : ι) → Filter (α i)} {s : (i : ι) → Set (α i)}
{p : ∀ i, α i → Prop}
section Pi
theorem tendsto_eval_pi (f : ∀ i, Filter (α i)) (i : ι) : Tendsto (eval i) (pi f) (f i) :=
tendsto_iInf' i tendsto_comap
theorem tendsto_pi {β : Type*} {m : β → ∀ i, α i} {l : Filter β} :
Tendsto m l (pi f) ↔ ∀ i, Tendsto (fun x => m x i) l (f i) := by
simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl
/-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to
`f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a
product of topological spaces. -/
alias ⟨Tendsto.apply, _⟩ := tendsto_pi
theorem le_pi {g : Filter (∀ i, α i)} : g ≤ pi f ↔ ∀ i, Tendsto (eval i) g (f i) :=
tendsto_pi
@[mono]
theorem pi_mono (h : ∀ i, f₁ i ≤ f₂ i) : pi f₁ ≤ pi f₂ :=
| iInf_mono fun i => comap_mono <| h i
theorem mem_pi_of_mem (i : ι) {s : Set (α i)} (hs : s ∈ f i) : eval i ⁻¹' s ∈ pi f :=
| Mathlib/Order/Filter/Pi.lean | 51 | 53 |
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.RingTheory.Polynomial.Pochhammer
/-!
# Cast of factorials
This file allows calculating factorials (including ascending and descending ones) as elements of a
semiring.
This is particularly crucial for `Nat.descFactorial` as subtraction on `ℕ` does **not** correspond
to subtraction on a general semiring. For example, we can't rely on existing cast lemmas to prove
`↑(a.descFactorial 2) = ↑a * (↑a - 1)`. We must use the fact that, whenever `↑(a - 1)` is not equal
to `↑a - 1`, the other factor is `0` anyway.
-/
open Nat
variable (S : Type*)
namespace Nat
section Semiring
variable [Semiring S] (a b : ℕ)
theorem cast_ascFactorial : a.ascFactorial b = (ascPochhammer S b).eval (a : S) := by
rw [← ascPochhammer_nat_eq_ascFactorial, ascPochhammer_eval_cast]
theorem cast_descFactorial :
a.descFactorial b = (ascPochhammer S b).eval (a - (b - 1) : S) := by
rw [← ascPochhammer_eval_cast, ascPochhammer_nat_eq_descFactorial]
induction' b with b
· simp
· simp_rw [add_succ, Nat.add_one_sub_one]
obtain h | h := le_total a b
· rw [descFactorial_of_lt (lt_succ_of_le h), descFactorial_of_lt (lt_succ_of_le _)]
rw [tsub_eq_zero_iff_le.mpr h, zero_add]
· rw [tsub_add_cancel_of_le h]
theorem cast_factorial : (a ! : S) = (ascPochhammer S a).eval 1 := by
rw [← one_ascFactorial, cast_ascFactorial, cast_one]
end Semiring
section Ring
variable [Ring S] (a b : ℕ)
/-- Convenience lemma. The `a - 1` is not using truncated subtraction, as opposed to the definition
of `Nat.descFactorial` as a natural. -/
theorem cast_descFactorial_two : (a.descFactorial 2 : S) = a * (a - 1) := by
rw [cast_descFactorial]
cases a
· simp
· rw [succ_sub_succ, tsub_zero, cast_succ, add_sub_cancel_right, ascPochhammer_succ_right,
ascPochhammer_one, Polynomial.X_mul, Polynomial.eval_mul_X, Polynomial.eval_add,
Polynomial.eval_X, cast_one, Polynomial.eval_one]
|
end Ring
end Nat
| Mathlib/Data/Nat/Factorial/Cast.lean | 63 | 69 |
/-
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.Additive
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.Algebra.Homology.ShortComplex.Preadditive
import Mathlib.Tactic.Linarith
/-!
# The short complexes attached to homological complexes
In this file, we define a functor
`shortComplexFunctor C c i : HomologicalComplex C c ⥤ ShortComplex C`.
By definition, the image of a homological complex `K` by this functor
is the short complex `K.X (c.prev i) ⟶ K.X i ⟶ K.X (c.next i)`.
The homology `K.homology i` of a homological complex `K` in degree `i` is defined as
the homology of the short complex `(shortComplexFunctor C c i).obj K`, which can be
abbreviated as `K.sc i`.
-/
open CategoryTheory Category Limits
namespace HomologicalComplex
variable (C : Type*) [Category C] [HasZeroMorphisms C] {ι : Type*} (c : ComplexShape ι)
/-- The functor `HomologicalComplex C c ⥤ ShortComplex C` which sends a homological
complex `K` to the short complex `K.X i ⟶ K.X j ⟶ K.X k` for arbitrary indices `i`, `j` and `k`. -/
@[simps]
def shortComplexFunctor' (i j k : ι) : HomologicalComplex C c ⥤ ShortComplex C where
obj K := ShortComplex.mk (K.d i j) (K.d j k) (K.d_comp_d i j k)
map f :=
{ τ₁ := f.f i
τ₂ := f.f j
τ₃ := f.f k }
/-- The functor `HomologicalComplex C c ⥤ ShortComplex C` which sends a homological
complex `K` to the short complex `K.X (c.prev i) ⟶ K.X i ⟶ K.X (c.next i)`. -/
@[simps!]
noncomputable def shortComplexFunctor (i : ι) :=
shortComplexFunctor' C c (c.prev i) i (c.next i)
/-- The natural isomorphism `shortComplexFunctor C c j ≅ shortComplexFunctor' C c i j k`
when `c.prev j = i` and `c.next j = k`. -/
@[simps!]
noncomputable def natIsoSc' (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) :
shortComplexFunctor C c j ≅ shortComplexFunctor' C c i j k :=
NatIso.ofComponents (fun K => ShortComplex.isoMk (K.XIsoOfEq hi) (Iso.refl _) (K.XIsoOfEq hk)
(by simp) (by simp)) (by aesop_cat)
variable {C c}
variable (K L M : HomologicalComplex C c) (φ : K ⟶ L) (ψ : L ⟶ M) (i j k : ι)
/-- The short complex `K.X i ⟶ K.X j ⟶ K.X k` for arbitrary indices `i`, `j` and `k`. -/
abbrev sc' := (shortComplexFunctor' C c i j k).obj K
/-- The short complex `K.X (c.prev i) ⟶ K.X i ⟶ K.X (c.next i)`. -/
noncomputable abbrev sc := (shortComplexFunctor C c i).obj K
/-- The canonical isomorphism `K.sc j ≅ K.sc' i j k` when `c.prev j = i` and `c.next j = k`. -/
noncomputable abbrev isoSc' (hi : c.prev j = i) (hk : c.next j = k) :
K.sc j ≅ K.sc' i j k := (natIsoSc' C c i j k hi hk).app K
/-- A homological complex `K` has homology in degree `i` if the associated
short complex `K.sc i` has. -/
abbrev HasHomology := (K.sc i).HasHomology
section
variable [K.HasHomology i]
/-- The homology in degree `i` of a homological complex. -/
noncomputable def homology := (K.sc i).homology
/-- The cycles in degree `i` of a homological complex. -/
noncomputable def cycles := (K.sc i).cycles
/-- The inclusion of the cycles of a homological complex. -/
noncomputable def iCycles : K.cycles i ⟶ K.X i := (K.sc i).iCycles
/-- The homology class map from cycles to the homology of a homological complex. -/
noncomputable def homologyπ : K.cycles i ⟶ K.homology i := (K.sc i).homologyπ
variable {i}
/-- The morphism to `K.cycles i` that is induced by a "cycle", i.e. a morphism
to `K.X i` whose postcomposition with the differential is zero. -/
noncomputable def liftCycles {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j)
(hk : k ≫ K.d i j = 0) : A ⟶ K.cycles i :=
(K.sc i).liftCycles k (by subst hj; exact hk)
/-- The morphism to `K.cycles i` that is induced by a "cycle", i.e. a morphism
to `K.X i` whose postcomposition with the differential is zero. -/
noncomputable abbrev liftCycles' {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.Rel i j)
(hk : k ≫ K.d i j = 0) : A ⟶ K.cycles i :=
K.liftCycles k j (c.next_eq' hj) hk
@[reassoc (attr := simp)]
lemma liftCycles_i {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j)
(hk : k ≫ K.d i j = 0) : K.liftCycles k j hj hk ≫ K.iCycles i = k := by
dsimp [liftCycles, iCycles]
simp
variable (i)
/-- The map `K.X i ⟶ K.cycles j` induced by the differential `K.d i j`. -/
noncomputable def toCycles [K.HasHomology j] :
K.X i ⟶ K.cycles j :=
K.liftCycles (K.d i j) (c.next j) rfl (K.d_comp_d _ _ _)
@[reassoc (attr := simp)]
lemma iCycles_d : K.iCycles i ≫ K.d i j = 0 := by
by_cases hij : c.Rel i j
· obtain rfl := c.next_eq' hij
exact (K.sc i).iCycles_g
· rw [K.shape _ _ hij, comp_zero]
/-- `K.cycles i` is the kernel of `K.d i j` when `c.next i = j`. -/
noncomputable def cyclesIsKernel (hj : c.next i = j) :
IsLimit (KernelFork.ofι (K.iCycles i) (K.iCycles_d i j)) := by
obtain rfl := hj
exact (K.sc i).cyclesIsKernel
end
@[reassoc (attr := simp)]
lemma toCycles_i [K.HasHomology j] :
K.toCycles i j ≫ K.iCycles j = K.d i j :=
liftCycles_i _ _ _ _ _
section
variable [K.HasHomology i]
instance : Mono (K.iCycles i) := by
dsimp only [iCycles]
infer_instance
instance : Epi (K.homologyπ i) := by
dsimp only [homologyπ]
infer_instance
end
@[reassoc (attr := simp)]
lemma d_toCycles [K.HasHomology k] :
K.d i j ≫ K.toCycles j k = 0 := by
simp only [← cancel_mono (K.iCycles k), assoc, toCycles_i, d_comp_d, zero_comp]
variable {i j} in
lemma toCycles_eq_zero [K.HasHomology j] (hij : ¬ c.Rel i j) :
K.toCycles i j = 0 := by
rw [← cancel_mono (K.iCycles j), toCycles_i, zero_comp, K.shape _ _ hij]
variable {i}
section
variable [K.HasHomology i]
@[reassoc]
lemma comp_liftCycles {A' A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j)
(hk : k ≫ K.d i j = 0) (α : A' ⟶ A) :
α ≫ K.liftCycles k j hj hk = K.liftCycles (α ≫ k) j hj (by rw [assoc, hk, comp_zero]) := by
simp only [← cancel_mono (K.iCycles i), assoc, liftCycles_i]
@[reassoc]
lemma liftCycles_homologyπ_eq_zero_of_boundary {A : C} (k : A ⟶ K.X i) (j : ι)
(hj : c.next i = j) {i' : ι} (x : A ⟶ K.X i') (hx : k = x ≫ K.d i' i) :
K.liftCycles k j hj (by rw [hx, assoc, K.d_comp_d, comp_zero]) ≫ K.homologyπ i = 0 := by
by_cases h : c.Rel i' i
· obtain rfl := c.prev_eq' h
exact (K.sc i).liftCycles_homologyπ_eq_zero_of_boundary _ x hx
· have : liftCycles K k j hj (by rw [hx, assoc, K.d_comp_d, comp_zero]) = 0 := by
rw [K.shape _ _ h, comp_zero] at hx
rw [← cancel_mono (K.iCycles i), zero_comp, liftCycles_i, hx]
rw [this, zero_comp]
end
variable (i)
@[reassoc (attr := simp)]
lemma toCycles_comp_homologyπ [K.HasHomology j] :
K.toCycles i j ≫ K.homologyπ j = 0 :=
K.liftCycles_homologyπ_eq_zero_of_boundary (K.d i j) (c.next j) rfl (𝟙 _) (by simp)
/-- `K.homology j` is the cokernel of `K.toCycles i j : K.X i ⟶ K.cycles j`
when `c.prev j = i`. -/
noncomputable def homologyIsCokernel (hi : c.prev j = i) [K.HasHomology j] :
IsColimit (CokernelCofork.ofπ (K.homologyπ j) (K.toCycles_comp_homologyπ i j)) := by
subst hi
exact (K.sc j).homologyIsCokernel
section
variable [K.HasHomology i]
/-- The opcycles in degree `i` of a homological complex. -/
noncomputable def opcycles := (K.sc i).opcycles
/-- The projection to the opcycles of a homological complex. -/
noncomputable def pOpcycles : K.X i ⟶ K.opcycles i := (K.sc i).pOpcycles
/-- The inclusion map of the homology of a homological complex into its opcycles. -/
noncomputable def homologyι : K.homology i ⟶ K.opcycles i := (K.sc i).homologyι
variable {i}
/-- The morphism from `K.opcycles i` that is induced by an "opcycle", i.e. a morphism
from `K.X i` whose precomposition with the differential is zero. -/
noncomputable def descOpcycles {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j)
(hk : K.d j i ≫ k = 0) : K.opcycles i ⟶ A :=
(K.sc i).descOpcycles k (by subst hj; exact hk)
/-- The morphism from `K.opcycles i` that is induced by an "opcycle", i.e. a morphism
from `K.X i` whose precomposition with the differential is zero. -/
noncomputable abbrev descOpcycles' {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.Rel j i)
(hk : K.d j i ≫ k = 0) : K.opcycles i ⟶ A :=
K.descOpcycles k j (c.prev_eq' hj) hk
@[reassoc (attr := simp)]
lemma p_descOpcycles {A : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j)
(hk : K.d j i ≫ k = 0) : K.pOpcycles i ≫ K.descOpcycles k j hj hk = k := by
dsimp [descOpcycles, pOpcycles]
simp
variable (i)
/-- The map `K.opcycles i ⟶ K.X j` induced by the differential `K.d i j`. -/
noncomputable def fromOpcycles :
K.opcycles i ⟶ K.X j :=
K.descOpcycles (K.d i j) (c.prev i) rfl (K.d_comp_d _ _ _)
@[reassoc (attr := simp)]
lemma d_pOpcycles [K.HasHomology j] : K.d i j ≫ K.pOpcycles j = 0 := by
by_cases hij : c.Rel i j
· obtain rfl := c.prev_eq' hij
exact (K.sc j).f_pOpcycles
· rw [K.shape _ _ hij, zero_comp]
/-- `K.opcycles j` is the cokernel of `K.d i j` when `c.prev j = i`. -/
noncomputable def opcyclesIsCokernel (hi : c.prev j = i) [K.HasHomology j] :
IsColimit (CokernelCofork.ofπ (K.pOpcycles j) (K.d_pOpcycles i j)) := by
obtain rfl := hi
exact (K.sc j).opcyclesIsCokernel
@[reassoc (attr := simp)]
lemma p_fromOpcycles :
K.pOpcycles i ≫ K.fromOpcycles i j = K.d i j :=
p_descOpcycles _ _ _ _ _
instance : Epi (K.pOpcycles i) := by
dsimp only [pOpcycles]
infer_instance
instance : Mono (K.homologyι i) := by
dsimp only [homologyι]
infer_instance
@[reassoc (attr := simp)]
lemma fromOpcycles_d :
K.fromOpcycles i j ≫ K.d j k = 0 := by
simp only [← cancel_epi (K.pOpcycles i), p_fromOpcycles_assoc, d_comp_d, comp_zero]
variable {i j} in
lemma fromOpcycles_eq_zero (hij : ¬ c.Rel i j) :
K.fromOpcycles i j = 0 := by
rw [← cancel_epi (K.pOpcycles i), p_fromOpcycles, comp_zero, K.shape _ _ hij]
variable {i}
@[reassoc]
lemma descOpcycles_comp {A A' : C} (k : K.X i ⟶ A) (j : ι) (hj : c.prev i = j)
(hk : K.d j i ≫ k = 0) (α : A ⟶ A') :
K.descOpcycles k j hj hk ≫ α = K.descOpcycles (k ≫ α) j hj
(by rw [reassoc_of% hk, zero_comp]) := by
simp only [← cancel_epi (K.pOpcycles i), p_descOpcycles_assoc, p_descOpcycles]
@[reassoc]
lemma homologyι_descOpcycles_eq_zero_of_boundary {A : C} (k : K.X i ⟶ A) (j : ι)
(hj : c.prev i = j) {i' : ι} (x : K.X i' ⟶ A) (hx : k = K.d i i' ≫ x) :
K.homologyι i ≫ K.descOpcycles k j hj (by rw [hx, K.d_comp_d_assoc, zero_comp]) = 0 := by
by_cases h : c.Rel i i'
· obtain rfl := c.next_eq' h
exact (K.sc i).homologyι_descOpcycles_eq_zero_of_boundary _ x hx
· have : K.descOpcycles k j hj (by rw [hx, K.d_comp_d_assoc, zero_comp]) = 0 := by
rw [K.shape _ _ h, zero_comp] at hx
rw [← cancel_epi (K.pOpcycles i), comp_zero, p_descOpcycles, hx]
rw [this, comp_zero]
variable (i)
@[reassoc (attr := simp)]
lemma homologyι_comp_fromOpcycles :
K.homologyι i ≫ K.fromOpcycles i j = 0 :=
K.homologyι_descOpcycles_eq_zero_of_boundary (K.d i j) _ rfl (𝟙 _) (by simp)
/-- `K.homology i` is the kernel of `K.fromOpcycles i j : K.opcycles i ⟶ K.X j`
when `c.next i = j`. -/
noncomputable def homologyIsKernel (hi : c.next i = j) :
IsLimit (KernelFork.ofι (K.homologyι i) (K.homologyι_comp_fromOpcycles i j)) := by
subst hi
exact (K.sc i).homologyIsKernel
variable {K L M}
variable [L.HasHomology i] [M.HasHomology i]
/-- The map `K.homology i ⟶ L.homology i` induced by a morphism in `HomologicalComplex`. -/
noncomputable def homologyMap : K.homology i ⟶ L.homology i :=
ShortComplex.homologyMap ((shortComplexFunctor C c i).map φ)
/-- The map `K.cycles i ⟶ L.cycles i` induced by a morphism in `HomologicalComplex`. -/
noncomputable def cyclesMap : K.cycles i ⟶ L.cycles i :=
ShortComplex.cyclesMap ((shortComplexFunctor C c i).map φ)
/-- The map `K.opcycles i ⟶ L.opcycles i` induced by a morphism in `HomologicalComplex`. -/
noncomputable def opcyclesMap : K.opcycles i ⟶ L.opcycles i :=
ShortComplex.opcyclesMap ((shortComplexFunctor C c i).map φ)
@[reassoc (attr := simp)]
lemma cyclesMap_i : cyclesMap φ i ≫ L.iCycles i = K.iCycles i ≫ φ.f i :=
ShortComplex.cyclesMap_i _
@[reassoc (attr := simp)]
lemma p_opcyclesMap : K.pOpcycles i ≫ opcyclesMap φ i = φ.f i ≫ L.pOpcycles i :=
ShortComplex.p_opcyclesMap _
instance [Mono (φ.f i)] : Mono (cyclesMap φ i) := mono_of_mono_fac (cyclesMap_i φ i)
instance [Epi (φ.f i)] : Epi (opcyclesMap φ i) := epi_of_epi_fac (p_opcyclesMap φ i)
variable (K)
@[simp]
lemma homologyMap_id : homologyMap (𝟙 K) i = 𝟙 _ :=
ShortComplex.homologyMap_id _
@[simp]
lemma cyclesMap_id : cyclesMap (𝟙 K) i = 𝟙 _ :=
ShortComplex.cyclesMap_id _
@[simp]
lemma opcyclesMap_id : opcyclesMap (𝟙 K) i = 𝟙 _ :=
ShortComplex.opcyclesMap_id _
variable {K}
@[reassoc]
lemma homologyMap_comp : homologyMap (φ ≫ ψ) i = homologyMap φ i ≫ homologyMap ψ i := by
dsimp [homologyMap]
rw [Functor.map_comp, ShortComplex.homologyMap_comp]
@[reassoc]
lemma cyclesMap_comp : cyclesMap (φ ≫ ψ) i = cyclesMap φ i ≫ cyclesMap ψ i := by
dsimp [cyclesMap]
rw [Functor.map_comp, ShortComplex.cyclesMap_comp]
@[reassoc]
lemma opcyclesMap_comp : opcyclesMap (φ ≫ ψ) i = opcyclesMap φ i ≫ opcyclesMap ψ i := by
dsimp [opcyclesMap]
rw [Functor.map_comp, ShortComplex.opcyclesMap_comp]
variable (K L)
@[simp]
lemma homologyMap_zero : homologyMap (0 : K ⟶ L) i = 0 :=
ShortComplex.homologyMap_zero _ _
@[simp]
lemma cyclesMap_zero : cyclesMap (0 : K ⟶ L) i = 0 :=
ShortComplex.cyclesMap_zero _ _
@[simp]
lemma opcyclesMap_zero : opcyclesMap (0 : K ⟶ L) i = 0 :=
ShortComplex.opcyclesMap_zero _ _
variable {K L}
@[reassoc (attr := simp)]
lemma homologyπ_naturality :
K.homologyπ i ≫ homologyMap φ i = cyclesMap φ i ≫ L.homologyπ i :=
ShortComplex.homologyπ_naturality _
@[reassoc (attr := simp)]
lemma homologyι_naturality :
homologyMap φ i ≫ L.homologyι i = K.homologyι i ≫ opcyclesMap φ i :=
ShortComplex.homologyι_naturality _
@[reassoc (attr := simp)]
lemma homology_π_ι :
K.homologyπ i ≫ K.homologyι i = K.iCycles i ≫ K.pOpcycles i :=
(K.sc i).homology_π_ι
variable {i}
@[reassoc (attr := simp)]
lemma opcyclesMap_comp_descOpcycles {A : C} (k : L.X i ⟶ A) (j : ι) (hj : c.prev i = j)
(hk : L.d j i ≫ k = 0) (φ : K ⟶ L) :
opcyclesMap φ i ≫ L.descOpcycles k j hj hk = K.descOpcycles (φ.f i ≫ k) j hj
(by rw [← φ.comm_assoc, hk, comp_zero]) := by
simp only [← cancel_epi (K.pOpcycles i), p_opcyclesMap_assoc, p_descOpcycles]
@[reassoc (attr := simp)]
lemma liftCycles_comp_cyclesMap {A : C} (k : A ⟶ K.X i) (j : ι) (hj : c.next i = j)
(hk : k ≫ K.d i j = 0) (φ : K ⟶ L) :
K.liftCycles k j hj hk ≫ cyclesMap φ i = L.liftCycles (k ≫ φ.f i) j hj
(by rw [assoc, φ.comm, reassoc_of% hk, zero_comp]) := by
simp only [← cancel_mono (L.iCycles i), assoc, cyclesMap_i, liftCycles_i_assoc, liftCycles_i]
section
variable (C c i)
attribute [local simp] homologyMap_comp cyclesMap_comp opcyclesMap_comp
/-- The `i`th homology functor `HomologicalComplex C c ⥤ C`. -/
@[simps]
noncomputable def homologyFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ C where
obj K := K.homology i
map f := homologyMap f i
/-- The homology functor to graded objects. -/
@[simps]
noncomputable def gradedHomologyFunctor [CategoryWithHomology C] :
HomologicalComplex C c ⥤ GradedObject ι C where
obj K i := K.homology i
map f i := homologyMap f i
/-- The `i`th cycles functor `HomologicalComplex C c ⥤ C`. -/
@[simps]
noncomputable def cyclesFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ C where
obj K := K.cycles i
map f := cyclesMap f i
/-- The `i`th opcycles functor `HomologicalComplex C c ⥤ C`. -/
@[simps]
noncomputable def opcyclesFunctor [CategoryWithHomology C] : HomologicalComplex C c ⥤ C where
obj K := K.opcycles i
map f := opcyclesMap f i
/-- The natural transformation `K.homologyπ i : K.cycles i ⟶ K.homology i`
for all `K : HomologicalComplex C c`. -/
@[simps]
noncomputable def natTransHomologyπ [CategoryWithHomology C] :
cyclesFunctor C c i ⟶ homologyFunctor C c i where
app K := K.homologyπ i
/-- The natural transformation `K.homologyι i : K.homology i ⟶ K.opcycles i`
for all `K : HomologicalComplex C c`. -/
@[simps]
noncomputable def natTransHomologyι [CategoryWithHomology C] :
homologyFunctor C c i ⟶ opcyclesFunctor C c i where
app K := K.homologyι i
/-- The natural isomorphism `K.homology i ≅ (K.sc i).homology`
for all homological complexes `K`. -/
@[simps!]
noncomputable def homologyFunctorIso [CategoryWithHomology C] :
homologyFunctor C c i ≅
shortComplexFunctor C c i ⋙ ShortComplex.homologyFunctor C :=
Iso.refl _
/-- The natural isomorphism `K.homology j ≅ (K.sc' i j k).homology`
for all homological complexes `K` when `c.prev j = i` and `c.next j = k`. -/
noncomputable def homologyFunctorIso' [CategoryWithHomology C]
(hi : c.prev j = i) (hk : c.next j = k) :
homologyFunctor C c j ≅
shortComplexFunctor' C c i j k ⋙ ShortComplex.homologyFunctor C :=
homologyFunctorIso C c j ≪≫ isoWhiskerRight (natIsoSc' C c i j k hi hk) _
instance [CategoryWithHomology C] : (homologyFunctor C c i).PreservesZeroMorphisms where
instance [CategoryWithHomology C] : (opcyclesFunctor C c i).PreservesZeroMorphisms where
instance [CategoryWithHomology C] : (cyclesFunctor C c i).PreservesZeroMorphisms where
end
end
section
variable (hj : c.next i = j) (h : K.d i j = 0) [K.HasHomology i]
include hj h
lemma isIso_iCycles : IsIso (K.iCycles i) := by
subst hj
exact ShortComplex.isIso_iCycles _ h
/-- The canonical isomorphism `K.cycles i ≅ K.X i` when the differential from `i` is zero. -/
@[simps! hom]
noncomputable def iCyclesIso : K.cycles i ≅ K.X i :=
have := K.isIso_iCycles i j hj h
asIso (K.iCycles i)
@[reassoc (attr := simp)]
lemma iCyclesIso_hom_inv_id :
K.iCycles i ≫ (K.iCyclesIso i j hj h).inv = 𝟙 _ :=
(K.iCyclesIso i j hj h).hom_inv_id
@[reassoc (attr := simp)]
lemma iCyclesIso_inv_hom_id :
(K.iCyclesIso i j hj h).inv ≫ K.iCycles i = 𝟙 _ :=
(K.iCyclesIso i j hj h).inv_hom_id
lemma isIso_homologyι : IsIso (K.homologyι i) :=
ShortComplex.isIso_homologyι _ (by aesop_cat)
/-- The canonical isomorphism `K.homology i ≅ K.opcycles i`
when the differential from `i` is zero. -/
@[simps! hom]
noncomputable def isoHomologyι : K.homology i ≅ K.opcycles i :=
have := K.isIso_homologyι i j hj h
asIso (K.homologyι i)
@[reassoc (attr := simp)]
lemma isoHomologyι_hom_inv_id :
K.homologyι i ≫ (K.isoHomologyι i j hj h).inv = 𝟙 _ :=
(K.isoHomologyι i j hj h).hom_inv_id
@[reassoc (attr := simp)]
lemma isoHomologyι_inv_hom_id :
(K.isoHomologyι i j hj h).inv ≫ K.homologyι i = 𝟙 _ :=
(K.isoHomologyι i j hj h).inv_hom_id
end
section
variable (hi : c.prev j = i) (h : K.d i j = 0) [K.HasHomology j]
include hi h
lemma isIso_pOpcycles : IsIso (K.pOpcycles j) := by
obtain rfl := hi
exact ShortComplex.isIso_pOpcycles _ h
/-- The canonical isomorphism `K.X j ≅ K.opCycles j` when the differential to `j` is zero. -/
@[simps! hom]
noncomputable def pOpcyclesIso : K.X j ≅ K.opcycles j :=
have := K.isIso_pOpcycles i j hi h
asIso (K.pOpcycles j)
@[reassoc (attr := simp)]
lemma pOpcyclesIso_hom_inv_id :
K.pOpcycles j ≫ (K.pOpcyclesIso i j hi h).inv = 𝟙 _ :=
(K.pOpcyclesIso i j hi h).hom_inv_id
@[reassoc (attr := simp)]
lemma pOpcyclesIso_inv_hom_id :
(K.pOpcyclesIso i j hi h).inv ≫ K.pOpcycles j = 𝟙 _ :=
(K.pOpcyclesIso i j hi h).inv_hom_id
lemma isIso_homologyπ : IsIso (K.homologyπ j) :=
ShortComplex.isIso_homologyπ _ (by aesop_cat)
/-- The canonical isomorphism `K.cycles j ≅ K.homology j`
when the differential to `j` is zero. -/
@[simps! hom]
noncomputable def isoHomologyπ : K.cycles j ≅ K.homology j :=
have := K.isIso_homologyπ i j hi h
asIso (K.homologyπ j)
@[reassoc (attr := simp)]
lemma isoHomologyπ_hom_inv_id :
K.homologyπ j ≫ (K.isoHomologyπ i j hi h).inv = 𝟙 _ :=
(K.isoHomologyπ i j hi h).hom_inv_id
@[reassoc (attr := simp)]
lemma isoHomologyπ_inv_hom_id :
| (K.isoHomologyπ i j hi h).inv ≫ K.homologyπ j = 𝟙 _ :=
(K.isoHomologyπ i j hi h).inv_hom_id
end
section
| Mathlib/Algebra/Homology/ShortComplex/HomologicalComplex.lean | 571 | 577 |
/-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import Mathlib.Algebra.NeZero
import Mathlib.Data.Int.DivMod
import Mathlib.Logic.Embedding.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Tactic.Common
import Mathlib.Tactic.Attr.Register
/-!
# The finite type with `n` elements
`Fin n` is the type whose elements are natural numbers smaller than `n`.
This file expands on the development in the core library.
## Main definitions
### Induction principles
* `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`.
Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas`
### Embeddings and isomorphisms
* `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`;
* `Fin.succEmb` : `Fin.succ` as an `Embedding`;
* `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`;
* `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`;
* `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`;
* `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`;
* `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right,
generalizes `Fin.succ`;
* `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left;
### Other casts
* `Fin.divNat i` : divides `i : Fin (m * n)` by `n`;
* `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`;
-/
assert_not_exists Monoid Finset
open Fin Nat Function
attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last
/-- Elimination principle for the empty set `Fin 0`, dependent version. -/
def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x :=
x.elim0
namespace Fin
@[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} :
(⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 :=
mk.inj_iff
@[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} :
1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by
simp [eq_comm]
instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where
prf k hk := ⟨⟨k, hk⟩, rfl⟩
/-- A dependent variant of `Fin.elim0`. -/
def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _)
variable {n m : ℕ}
--variable {a b : Fin n} -- this *really* breaks stuff
theorem val_injective : Function.Injective (@Fin.val n) :=
@Fin.eq_of_val_eq n
/-- If you actually have an element of `Fin n`, then the `n` is always positive -/
lemma size_positive : Fin n → 0 < n := Fin.pos
lemma size_positive' [Nonempty (Fin n)] : 0 < n :=
‹Nonempty (Fin n)›.elim Fin.pos
protected theorem prop (a : Fin n) : a.val < n :=
a.2
lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by
simp [Fin.lt_iff_le_and_ne, le_last]
lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 :=
Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab
lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n :=
Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last
/-- Equivalence between `Fin n` and `{ i // i < n }`. -/
@[simps apply symm_apply]
def equivSubtype : Fin n ≃ { i // i < n } where
toFun a := ⟨a.1, a.2⟩
invFun a := ⟨a.1, a.2⟩
left_inv := fun ⟨_, _⟩ => rfl
right_inv := fun ⟨_, _⟩ => rfl
section coe
/-!
### coercions and constructions
-/
theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b :=
Fin.ext_iff.symm
theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 :=
Fin.ext_iff.not
theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' :=
Fin.ext_iff
-- syntactic tautologies now
/-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element,
then they coincide (in the heq sense). -/
protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} :
HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by
subst h
simp [funext_iff]
/-- Assume `k = l` and `k' = l'`.
If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair,
then they coincide (in the heq sense). -/
protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l')
{f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} :
HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by
subst h
subst h'
simp [funext_iff]
/-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires
`k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/
protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} :
HEq i j ↔ (i : ℕ) = (j : ℕ) := by
subst h
simp [val_eq_val]
end coe
section Order
/-!
### order
-/
theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b :=
Iff.rfl
/-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=
Iff.rfl
/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=
Iff.rfl
theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp
theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp
/-- The inclusion map `Fin n → ℕ` is an embedding. -/
@[simps -fullyApplied apply]
def valEmbedding : Fin n ↪ ℕ :=
⟨val, val_injective⟩
@[simp]
theorem equivSubtype_symm_trans_valEmbedding :
equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) :=
rfl
/-- Use the ordering on `Fin n` for checking recursive definitions.
For example, the following definition is not accepted by the termination checker,
unless we declare the `WellFoundedRelation` instance:
```lean
def factorial {n : ℕ} : Fin n → ℕ
| ⟨0, _⟩ := 1
| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩
```
-/
instance {n : ℕ} : WellFoundedRelation (Fin n) :=
measure (val : Fin n → ℕ)
@[deprecated (since := "2025-02-24")]
alias val_zero' := val_zero
/-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl
/--
The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a :=
Nat.zero_le a.val
@[simp, norm_cast]
theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by
rw [Fin.ext_iff, val_zero]
theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 :=
val_eq_zero_iff.not
@[simp, norm_cast]
theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by
rw [← val_fin_lt, val_zero]
/--
The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by
rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff]
@[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl
@[simp] theorem cast_eq_zero {k l : ℕ} [NeZero k] [NeZero l]
(h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0 := by
simp [← val_eq_zero_iff]
lemma cast_injective {k l : ℕ} (h : k = l) : Injective (Fin.cast h) :=
fun a b hab ↦ by simpa [← val_eq_val] using hab
theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero
theorem one_lt_last [NeZero n] : 1 < last (n + 1) := by
rw [lt_iff_val_lt_val, val_one, val_last, Nat.lt_add_left_iff_pos, Nat.pos_iff_ne_zero]
exact NeZero.ne n
end Order
/-! ### Coercions to `ℤ` and the `fin_omega` tactic. -/
open Int
theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) :
((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by
rw [Fin.sub_def]
split
· rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
· rw [natCast_emod, Int.emod_eq_of_lt] <;> omega
theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) :
((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by
rw [coe_int_sub_eq_ite]
split
· rw [Int.emod_eq_of_lt] <;> omega
· rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega
theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) :
((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by
rw [Fin.add_def]
split
· rw [natCast_emod, Int.emod_eq_of_lt] <;> omega
· rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) :
((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by
rw [coe_int_add_eq_ite]
split
· rw [Int.emod_eq_of_lt] <;> omega
· rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
-- Write `a + b` as `if (a + b : ℕ) < n then (a + b : ℤ) else (a + b : ℤ) - n` and
-- similarly `a - b` as `if (b : ℕ) ≤ a then (a - b : ℤ) else (a - b : ℤ) + n`.
attribute [fin_omega] coe_int_sub_eq_ite coe_int_add_eq_ite
-- Rewrite inequalities in `Fin` to inequalities in `ℕ`
attribute [fin_omega] Fin.lt_iff_val_lt_val Fin.le_iff_val_le_val
-- Rewrite `1 : Fin (n + 2)` to `1 : ℤ`
attribute [fin_omega] val_one
/--
Preprocessor for `omega` to handle inequalities in `Fin`.
Note that this involves a lot of case splitting, so may be slow.
-/
-- Further adjustment to the simp set can probably make this more powerful.
-- Please experiment and PR updates!
macro "fin_omega" : tactic => `(tactic|
{ try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at *
omega })
section Add
/-!
### addition, numerals, and coercion from Nat
-/
@[simp]
theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n :=
rfl
@[deprecated val_one' (since := "2025-03-10")]
theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) :=
rfl
instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where
exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩
theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by
rcases n with (_ | _ | n) <;>
simp [Fin.nontrivial, not_nontrivial, Nat.succ_le_iff]
section Monoid
instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) :=
haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance
inferInstance
@[simp]
theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 :=
rfl
instance instNatCast [NeZero n] : NatCast (Fin n) where
natCast i := Fin.ofNat' n i
lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl
end Monoid
theorem val_add_eq_ite {n : ℕ} (a b : Fin n) :
(↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by
rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2),
Nat.mod_eq_of_lt (show ↑b < n from b.2)]
theorem val_add_eq_of_add_lt {n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
rw [val_add]
simp [Nat.mod_eq_of_lt huv]
lemma intCast_val_sub_eq_sub_add_ite {n : ℕ} (a b : Fin n) :
((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n := by
split <;> fin_omega
lemma one_le_of_ne_zero {n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
cases n with
| zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le]
| succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff]
lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt
(Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))]
section OfNatCoe
@[simp]
theorem ofNat'_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a :=
rfl
@[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl
/-- Converting an in-range number to `Fin (n + 1)` produces a result
whose value is the original number. -/
theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a :=
Nat.mod_eq_of_lt h
/-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results
in the same value. -/
@[simp, norm_cast] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a :=
Fin.ext <| val_cast_of_lt a.isLt
-- This is a special case of `CharP.cast_eq_zero` that doesn't require typeclass search
@[simp high] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp
@[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by
simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero]
@[simp]
theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp
theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by
rw [Fin.natCast_eq_last]
exact Fin.le_last i
variable {a b : ℕ}
lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by
rw [← Nat.lt_succ_iff] at han hbn
simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn]
lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by
rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn]
lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b :=
(natCast_le_natCast (hab.trans hbn) hbn).2 hab
lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b :=
(natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab
end OfNatCoe
end Add
section Succ
/-!
### succ and casts into larger Fin types
-/
lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff]
/-- `Fin.succ` as an `Embedding` -/
def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where
toFun := succ
inj' := succ_injective _
@[simp]
theorem coe_succEmb : ⇑(succEmb n) = Fin.succ :=
rfl
@[deprecated (since := "2025-04-12")]
alias val_succEmb := coe_succEmb
@[simp]
theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 :=
⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩
theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) :
∃ y, Fin.succ y = x := exists_succ_eq.mpr h
@[simp]
theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by
cases n
· exact (NeZero.ne 0 rfl).elim
· rfl
theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _
theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos'
/--
The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by
cases n
· exact (NeZero.ne 0 rfl).elim
· rfl
-- Version of `succ_one_eq_two` to be used by `dsimp`.
-- Note the `'` swapped around due to a move to std4.
/--
The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 :=
⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩
-- TODO: Move to Batteries
@[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by
simp [Fin.ext_iff]
@[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff]
attribute [simp] castSucc_inj
lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) :=
fun _ _ hab ↦ Fin.ext (congr_arg val hab :)
lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _
lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _
/-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/
@[simps apply]
def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where
toFun := castLE h
inj' := castLE_injective _
@[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl
/- The next proof can be golfed a lot using `Fintype.card`.
It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency
(not done yet). -/
lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by
refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩
induction n generalizing m with
| zero => exact m.zero_le
| succ n ihn =>
obtain ⟨e⟩ := h
rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne'
with ⟨m, rfl⟩
refine Nat.succ_le_succ <| ihn ⟨?_⟩
refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero),
fun i j h ↦ ?_⟩
simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h
lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n :=
⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩),
fun h ↦ h ▸ ⟨.refl _⟩⟩
@[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) :
i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) :=
rfl
@[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) :
Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) :=
rfl
@[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id :=
rfl
@[simp]
theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } :=
Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩
@[simp]
theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) :
((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by
rw [← coe_castLE h]
exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _)
theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) :=
fun _ => rfl
theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) :=
fun _ => rfl
@[simp]
theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by
simp [← val_inj]
@[simp]
theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b :=
Iff.rfl
@[simp]
theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b :=
Iff.rfl
/-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/
@[simps]
def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where
toFun := Fin.cast eq
invFun := Fin.cast eq.symm
left_inv := leftInverse_cast eq
right_inv := rightInverse_cast eq
@[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) :
finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl
@[simp]
lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp
@[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl
@[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl
lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl
/-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp
/-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by
subst h
ext
rfl
/-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`.
See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/
def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m)
@[simp]
lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl
lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl
/-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/
def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _
@[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl
lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl
theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i
@[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := .rfl
@[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by
rw [le_castSucc_iff, succ_lt_succ_iff]
@[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by
rw [castSucc_lt_iff_succ_le, succ_le_succ_iff]
theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n}
(hl : castSucc i < a) (hu : b < succ i) : b < a := by
simp [Fin.lt_def, -val_fin_lt] at *; omega
theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by
simp [Fin.lt_def, -val_fin_lt]; omega
theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by
rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le]
exact p.castSucc_lt_or_lt_succ i
theorem eq_castSucc_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) :
∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h
@[deprecated (since := "2025-02-06")]
alias exists_castSucc_eq_of_ne_last := eq_castSucc_of_ne_last
theorem forall_fin_succ' {P : Fin (n + 1) → Prop} :
(∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) :=
⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩
-- to match `Fin.eq_zero_or_eq_succ`
theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) :
(∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩)
@[simp]
theorem castSucc_ne_last {n : ℕ} (i : Fin n) : i.castSucc ≠ .last n :=
Fin.ne_of_lt i.castSucc_lt_last
theorem exists_fin_succ' {P : Fin (n + 1) → Prop} :
(∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) :=
⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h,
fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩
/--
The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl
@[simp]
theorem castSucc_pos_iff [NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i := by simp [← val_pos_iff]
/-- `castSucc i` is positive when `i` is positive.
The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis. -/
alias ⟨_, castSucc_pos'⟩ := castSucc_pos_iff
/--
The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 :=
Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm
/--
The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 :=
not_iff_not.mpr <| castSucc_eq_zero_iff' a
theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by
cases n
· exact i.elim0
· rw [castSucc_ne_zero_iff', Ne, Fin.ext_iff]
exact ((zero_le _).trans_lt h).ne'
theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n :=
not_iff_not.mpr <| succ_eq_last_succ
theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by
cases n
· exact i.elim0
· rw [succ_ne_last_iff, Ne, Fin.ext_iff]
exact ((le_last _).trans_lt' h).ne
@[norm_cast, simp]
theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by
ext
exact val_cast_of_lt (Nat.lt.step a.is_lt)
theorem coe_succ_lt_iff_lt {n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by
simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff]
@[simp]
theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) =
({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega)
@[simp]
theorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) :
((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by
rw [← coe_castSucc]
exact congr_arg val (Equiv.apply_ofInjective_symm _ _)
/-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/
@[simps! apply]
def addNatEmb (m) : Fin n ↪ Fin (n + m) where
toFun := (addNat · m)
inj' a b := by simp [Fin.ext_iff]
/-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/
@[simps! apply]
def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where
toFun := natAdd n
inj' a b := by simp [Fin.ext_iff]
theorem castSucc_castAdd (i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i := rfl
theorem castSucc_natAdd (i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i) := rfl
theorem succ_castAdd (i : Fin n) : succ (castAdd m i) =
if h : i.succ = last _ then natAdd n (0 : Fin (m + 1))
else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩ := by
split_ifs with h
exacts [Fin.ext (congr_arg Fin.val h :), rfl]
theorem succ_natAdd (i : Fin m) : succ (natAdd n i) = natAdd n (succ i) := rfl
end Succ
section Pred
/-!
### pred
-/
theorem pred_one' [NeZero n] (h := (zero_ne_one' (n := n)).symm) :
Fin.pred (1 : Fin (n + 1)) h = 0 := by
simp_rw [Fin.ext_iff, coe_pred, val_one', val_zero, Nat.sub_eq_zero_iff_le, Nat.mod_le]
theorem pred_last (h := Fin.ext_iff.not.2 last_pos'.ne') :
pred (last (n + 1)) h = last n := by simp_rw [← succ_last, pred_succ]
theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j := by
rw [← succ_lt_succ_iff, succ_pred]
theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by
rw [← succ_lt_succ_iff, succ_pred]
theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j := by
rw [← succ_le_succ_iff, succ_pred]
theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by
rw [← succ_le_succ_iff, succ_pred]
theorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0)
(ha' := castSucc_ne_zero_iff.mpr ha) :
(a.pred ha).castSucc = (castSucc a).pred ha' := rfl
theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) :
(a.pred ha).castSucc + 1 = a := by
cases a using cases
· exact (ha rfl).elim
· rw [pred_succ, coeSucc_eq_succ]
theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) :
b ≤ (castSucc a).pred ha ↔ b < a := by
rw [le_pred_iff, succ_le_castSucc_iff]
theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) :
(castSucc a).pred ha < b ↔ a ≤ b := by
rw [pred_lt_iff, castSucc_lt_succ_iff]
theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucc a ≠ 0) :
(castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def]
theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) :
b ≤ castSucc (a.pred ha) ↔ b < a := by
rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff]
theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) :
castSucc (a.pred ha) < b ↔ a ≤ b := by
rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff]
theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) :
castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def]
end Pred
section CastPred
/-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/
@[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h)
@[simp]
lemma castLT_eq_castPred (i : Fin (n + 1)) (h : i < last _) (h' := Fin.ext_iff.not.2 h.ne) :
castLT i h = castPred i h' := rfl
@[simp]
lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i := rfl
@[simp]
theorem castPred_castSucc {i : Fin n} (h' := Fin.ext_iff.not.2 (castSucc_lt_last i).ne) :
castPred (castSucc i) h' = i := rfl
@[simp]
theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) :
castSucc (i.castPred h) = i := by
rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩
rw [castPred_castSucc]
theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) :
castPred i hi = j ↔ i = castSucc j :=
⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩
@[simp]
theorem castPred_mk (i : ℕ) (h₁ : i < n) (h₂ := h₁.trans (Nat.lt_succ_self _))
(h₃ : ⟨i, h₂⟩ ≠ last _ := (ne_iff_vne _ _).mpr (val_last _ ▸ h₁.ne)) :
castPred ⟨i, h₂⟩ h₃ = ⟨i, h₁⟩ := rfl
@[simp]
theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
castPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl
/-- A version of the right-to-left implication of `castPred_le_castPred_iff`
that deduces `i ≠ last n` from `i ≤ j` and `j ≠ last n`. -/
@[gcongr]
theorem castPred_le_castPred {i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) :
castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤
castPred j hj :=
h
@[simp]
theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
castPred i hi < castPred j hj ↔ i < j := Iff.rfl
/-- A version of the right-to-left implication of `castPred_lt_castPred_iff`
that deduces `i ≠ last n` from `i < j`. -/
@[gcongr]
theorem castPred_lt_castPred {i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) :
castPred i (ne_last_of_lt h) < castPred j hj := h
theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
castPred i hi < j ↔ i < castSucc j := by
rw [← castSucc_lt_castSucc_iff, castSucc_castPred]
theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
j < castPred i hi ↔ castSucc j < i := by
rw [← castSucc_lt_castSucc_iff, castSucc_castPred]
theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
castPred i hi ≤ j ↔ i ≤ castSucc j := by
rw [← castSucc_le_castSucc_iff, castSucc_castPred]
theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
j ≤ castPred i hi ↔ castSucc j ≤ i := by
rw [← castSucc_le_castSucc_iff, castSucc_castPred]
@[simp]
theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
castPred i hi = castPred j hj ↔ i = j := by
simp_rw [Fin.ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff]
theorem castPred_zero' [NeZero n] (h := Fin.ext_iff.not.2 last_pos'.ne) :
castPred (0 : Fin (n + 1)) h = 0 := rfl
theorem castPred_zero (h := Fin.ext_iff.not.2 last_pos.ne) :
castPred (0 : Fin (n + 2)) h = 0 := rfl
@[simp]
theorem castPred_eq_zero [NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) :
Fin.castPred i h = 0 ↔ i = 0 := by
rw [← castPred_zero', castPred_inj]
@[simp]
theorem castPred_one [NeZero n] (h := Fin.ext_iff.not.2 one_lt_last.ne) :
castPred (1 : Fin (n + 2)) h = 1 := by
cases n
· exact subsingleton_one.elim _ 1
· rfl
theorem succ_castPred_eq_castPred_succ {a : Fin (n + 1)} (ha : a ≠ last n)
(ha' := a.succ_ne_last_iff.mpr ha) :
(a.castPred ha).succ = (succ a).castPred ha' := rfl
theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) :
(a.castPred ha).succ = a + 1 := by
cases a using lastCases
· exact (ha rfl).elim
· rw [castPred_castSucc, coeSucc_eq_succ]
theorem castpred_succ_le_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) :
(succ a).castPred ha ≤ b ↔ a < b := by
rw [castPred_le_iff, succ_le_castSucc_iff]
theorem lt_castPred_succ_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) :
b < (succ a).castPred ha ↔ b ≤ a := by
rw [lt_castPred_iff, castSucc_lt_succ_iff]
theorem lt_castPred_succ {a : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) :
a < (succ a).castPred ha := by rw [lt_castPred_succ_iff, le_def]
theorem succ_castPred_le_iff {a b : Fin (n + 1)} (ha : a ≠ last n) :
succ (a.castPred ha) ≤ b ↔ a < b := by
rw [succ_castPred_eq_castPred_succ ha, castpred_succ_le_iff]
theorem lt_succ_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) :
b < succ (a.castPred ha) ↔ b ≤ a := by
rw [succ_castPred_eq_castPred_succ ha, lt_castPred_succ_iff]
theorem lt_succ_castPred {a : Fin (n + 1)} (ha : a ≠ last n) :
a < succ (a.castPred ha) := by rw [lt_succ_castPred_iff, le_def]
theorem castPred_le_pred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) :
castPred a ha ≤ pred b hb ↔ a < b := by
rw [le_pred_iff, succ_castPred_le_iff]
theorem pred_lt_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) :
pred a ha < castPred b hb ↔ a ≤ b := by
rw [lt_castPred_iff, castSucc_pred_lt_iff ha]
theorem pred_lt_castPred {a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) :
pred a h₁ < castPred a h₂ := by
rw [pred_lt_castPred_iff, le_def]
end CastPred
section SuccAbove
variable {p : Fin (n + 1)} {i j : Fin n}
/-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/
def succAbove (p : Fin (n + 1)) (i : Fin n) : Fin (n + 1) :=
if castSucc i < p then i.castSucc else i.succ
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
embeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/
lemma succAbove_of_castSucc_lt (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) :
p.succAbove i = castSucc i := if_pos h
lemma succAbove_of_succ_le (p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) :
p.succAbove i = castSucc i :=
succAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h)
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
embeds `i` by `succ` when the resulting `p < i.succ`. -/
lemma succAbove_of_le_castSucc (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) :
p.succAbove i = i.succ := if_neg (Fin.not_lt.2 h)
lemma succAbove_of_lt_succ (p : Fin (n + 1)) (i : Fin n) (h : p < succ i) :
p.succAbove i = succ i := succAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h)
lemma succAbove_succ_of_lt (p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ :=
succAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h)
lemma succAbove_succ_of_le (p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc :=
succAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h)
@[simp] lemma succAbove_succ_self (j : Fin n) : j.succ.succAbove j = j.castSucc :=
succAbove_succ_of_le _ _ Fin.le_rfl
lemma succAbove_castSucc_of_lt (p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc :=
succAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h)
lemma succAbove_castSucc_of_le (p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ :=
succAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.2 h)
@[simp] lemma succAbove_castSucc_self (j : Fin n) : succAbove j.castSucc j = j.succ :=
succAbove_castSucc_of_le _ _ Fin.le_rfl
lemma succAbove_pred_of_lt (p i : Fin (n + 1)) (h : p < i)
(hi := Fin.ne_of_gt <| Fin.lt_of_le_of_lt p.zero_le h) : succAbove p (i.pred hi) = i := by
rw [succAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h), succ_pred]
lemma succAbove_pred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) :
succAbove p (i.pred hi) = (i.pred hi).castSucc := succAbove_of_succ_le _ _ (succ_pred _ _ ▸ h)
@[simp] lemma succAbove_pred_self (p : Fin (n + 1)) (h : p ≠ 0) :
succAbove p (p.pred h) = (p.pred h).castSucc := succAbove_pred_of_le _ _ Fin.le_rfl h
lemma succAbove_castPred_of_lt (p i : Fin (n + 1)) (h : i < p)
(hi := Fin.ne_of_lt <| Nat.lt_of_lt_of_le h p.le_last) : succAbove p (i.castPred hi) = i := by
rw [succAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h), castSucc_castPred]
lemma succAbove_castPred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) :
succAbove p (i.castPred hi) = (i.castPred hi).succ :=
succAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h)
lemma succAbove_castPred_self (p : Fin (n + 1)) (h : p ≠ last n) :
succAbove p (p.castPred h) = (p.castPred h).succ := succAbove_castPred_of_le _ _ Fin.le_rfl h
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
never results in `p` itself -/
@[simp]
lemma succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by
rcases p.castSucc_lt_or_lt_succ i with (h | h)
· rw [succAbove_of_castSucc_lt _ _ h]
exact Fin.ne_of_lt h
· rw [succAbove_of_lt_succ _ _ h]
exact Fin.ne_of_gt h
@[simp]
lemma ne_succAbove (p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i := (succAbove_ne _ _).symm
/-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/
lemma succAbove_right_injective : Injective p.succAbove := by
rintro i j hij
unfold succAbove at hij
split_ifs at hij with hi hj hj
· exact castSucc_injective _ hij
· rw [hij] at hi
cases hj <| Nat.lt_trans j.castSucc_lt_succ hi
· rw [← hij] at hj
cases hi <| Nat.lt_trans i.castSucc_lt_succ hj
· exact succ_injective _ hij
/-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/
lemma succAbove_right_inj : p.succAbove i = p.succAbove j ↔ i = j :=
succAbove_right_injective.eq_iff
/-- `Fin.succAbove p` as an `Embedding`. -/
@[simps!]
def succAboveEmb (p : Fin (n + 1)) : Fin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩
@[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl
@[simp]
lemma succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by
rw [Fin.succAbove_of_castSucc_lt]
· exact castSucc_zero'
· exact Fin.pos_iff_ne_zero.2 ha
lemma succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) :
a.succAbove b = 0 ↔ b = 0 := by
rw [← succAbove_ne_zero_zero ha, succAbove_right_inj]
lemma succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) :
a.succAbove b ≠ 0 := mt (succAbove_eq_zero_iff ha).mp hb
/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/
@[simp] lemma succAbove_zero : succAbove (0 : Fin (n + 1)) = Fin.succ := rfl
lemma succAbove_zero_apply (i : Fin n) : succAbove 0 i = succ i := by rw [succAbove_zero]
@[simp] lemma succAbove_ne_last_last {a : Fin (n + 2)} (h : a ≠ last (n + 1)) :
a.succAbove (last n) = last (n + 1) := by
rw [succAbove_of_lt_succ _ _ (succ_last _ ▸ lt_last_iff_ne_last.2 h), succ_last]
lemma succAbove_eq_last_iff {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) :
a.succAbove b = last _ ↔ b = last _ := by
rw [← succAbove_ne_last_last ha, succAbove_right_inj]
lemma succAbove_ne_last {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) :
a.succAbove b ≠ last _ := mt (succAbove_eq_last_iff ha).mp hb
/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/
@[simp] lemma succAbove_last : succAbove (last n) = castSucc := by
ext; simp only [succAbove_of_castSucc_lt, castSucc_lt_last]
lemma succAbove_last_apply (i : Fin n) : succAbove (last n) i = castSucc i := by rw [succAbove_last]
/-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is greater
results in a value that is less than `p`. -/
lemma succAbove_lt_iff_castSucc_lt (p : Fin (n + 1)) (i : Fin n) :
p.succAbove i < p ↔ castSucc i < p := by
rcases castSucc_lt_or_lt_succ p i with H | H
· rwa [iff_true_right H, succAbove_of_castSucc_lt _ _ H]
· rw [castSucc_lt_iff_succ_le, iff_false_right (Fin.not_le.2 H), succAbove_of_lt_succ _ _ H]
exact Fin.not_lt.2 <| Fin.le_of_lt H
lemma succAbove_lt_iff_succ_le (p : Fin (n + 1)) (i : Fin n) :
p.succAbove i < p ↔ succ i ≤ p := by
rw [succAbove_lt_iff_castSucc_lt, castSucc_lt_iff_succ_le]
/-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is lesser
results in a value that is greater than `p`. -/
lemma lt_succAbove_iff_le_castSucc (p : Fin (n + 1)) (i : Fin n) :
p < p.succAbove i ↔ p ≤ castSucc i := by
rcases castSucc_lt_or_lt_succ p i with H | H
· rw [iff_false_right (Fin.not_le.2 H), succAbove_of_castSucc_lt _ _ H]
exact Fin.not_lt.2 <| Fin.le_of_lt H
· rwa [succAbove_of_lt_succ _ _ H, iff_true_left H, le_castSucc_iff]
lemma lt_succAbove_iff_lt_castSucc (p : Fin (n + 1)) (i : Fin n) :
p < p.succAbove i ↔ p < succ i := by rw [lt_succAbove_iff_le_castSucc, le_castSucc_iff]
/-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/
lemma succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by
by_cases H : castSucc i < p
· simpa [succAbove_of_castSucc_lt _ _ H] using castSucc_pos' h
· simp [succAbove_of_le_castSucc _ _ (Fin.not_lt.1 H)]
lemma castPred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : castSucc x < y)
(h' := Fin.ne_last_of_lt <| (succAbove_lt_iff_castSucc_lt ..).2 h) :
(y.succAbove x).castPred h' = x := by
rw [castPred_eq_iff_eq_castSucc, succAbove_of_castSucc_lt _ _ h]
lemma pred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : y ≤ castSucc x)
(h' := Fin.ne_zero_of_lt <| (lt_succAbove_iff_le_castSucc ..).2 h) :
(y.succAbove x).pred h' = x := by simp only [succAbove_of_le_castSucc _ _ h, pred_succ]
lemma exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by
obtain hxy | hyx := Fin.lt_or_lt_of_ne h
exacts [⟨_, succAbove_castPred_of_lt _ _ hxy⟩, ⟨_, succAbove_pred_of_lt _ _ hyx⟩]
@[simp] lemma exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x :=
⟨by rintro ⟨y, rfl⟩; exact succAbove_ne _ _, exists_succAbove_eq⟩
/-- The range of `p.succAbove` is everything except `p`. -/
@[simp] lemma range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}ᶜ :=
Set.ext fun _ => exists_succAbove_eq_iff
@[simp] lemma range_succ (n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ := by
rw [← succAbove_zero]; exact range_succAbove (0 : Fin (n + 1))
/-- `succAbove` is injective at the pivot -/
lemma succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by
simpa [range_succAbove] using congr_arg (fun f : Fin n → Fin (n + 1) => (Set.range f)ᶜ) h
/-- `succAbove` is injective at the pivot -/
@[simp] lemma succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y :=
| succAbove_left_injective.eq_iff
| Mathlib/Data/Fin/Basic.lean | 1,118 | 1,119 |
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Heyting.Basic
import Mathlib.Order.Hom.Basic
import Mathlib.Order.WithBot
/-!
# Orders on a sum type
This file defines the disjoint sum and the linear (aka lexicographic) sum of two orders and
provides relation instances for `Sum.LiftRel` and `Sum.Lex`.
We declare the disjoint sum of orders as the default set of instances. The linear order goes on a
type synonym.
## Main declarations
* `Sum.LE`, `Sum.LT`: Disjoint sum of orders.
* `Sum.Lex.LE`, `Sum.Lex.LT`: Lexicographic/linear sum of orders.
## Notation
* `α ⊕ₗ β`: The linear sum of `α` and `β`.
-/
variable {α β γ : Type*}
namespace Sum
/-! ### Unbundled relation classes -/
section LiftRel
variable (r : α → α → Prop) (s : β → β → Prop)
@[refl]
theorem LiftRel.refl [IsRefl α r] [IsRefl β s] : ∀ x, LiftRel r s x x
| inl a => LiftRel.inl (_root_.refl a)
| inr a => LiftRel.inr (_root_.refl a)
instance [IsRefl α r] [IsRefl β s] : IsRefl (α ⊕ β) (LiftRel r s) :=
⟨LiftRel.refl _ _⟩
instance [IsIrrefl α r] [IsIrrefl β s] : IsIrrefl (α ⊕ β) (LiftRel r s) :=
⟨by rintro _ (⟨h⟩ | ⟨h⟩) <;> exact irrefl _ h⟩
@[trans]
theorem LiftRel.trans [IsTrans α r] [IsTrans β s] :
∀ {a b c}, LiftRel r s a b → LiftRel r s b c → LiftRel r s a c
| _, _, _, LiftRel.inl hab, LiftRel.inl hbc => LiftRel.inl <| _root_.trans hab hbc
| _, _, _, LiftRel.inr hab, LiftRel.inr hbc => LiftRel.inr <| _root_.trans hab hbc
instance [IsTrans α r] [IsTrans β s] : IsTrans (α ⊕ β) (LiftRel r s) :=
⟨fun _ _ _ => LiftRel.trans _ _⟩
instance [IsAntisymm α r] [IsAntisymm β s] : IsAntisymm (α ⊕ β) (LiftRel r s) :=
⟨by rintro _ _ (⟨hab⟩ | ⟨hab⟩) (⟨hba⟩ | ⟨hba⟩) <;> rw [antisymm hab hba]⟩
end LiftRel
section Lex
variable (r : α → α → Prop) (s : β → β → Prop)
instance [IsRefl α r] [IsRefl β s] : IsRefl (α ⊕ β) (Lex r s) :=
⟨by
rintro (a | a)
exacts [Lex.inl (refl _), Lex.inr (refl _)]⟩
instance [IsIrrefl α r] [IsIrrefl β s] : IsIrrefl (α ⊕ β) (Lex r s) :=
⟨by rintro _ (⟨h⟩ | ⟨h⟩) <;> exact irrefl _ h⟩
instance [IsTrans α r] [IsTrans β s] : IsTrans (α ⊕ β) (Lex r s) :=
⟨by
rintro _ _ _ (⟨hab⟩ | ⟨hab⟩) (⟨hbc⟩ | ⟨hbc⟩)
exacts [.inl (_root_.trans hab hbc), .sep _ _, .inr (_root_.trans hab hbc), .sep _ _]⟩
instance [IsAntisymm α r] [IsAntisymm β s] : IsAntisymm (α ⊕ β) (Lex r s) :=
⟨by rintro _ _ (⟨hab⟩ | ⟨hab⟩) (⟨hba⟩ | ⟨hba⟩) <;> rw [antisymm hab hba]⟩
instance [IsTotal α r] [IsTotal β s] : IsTotal (α ⊕ β) (Lex r s) :=
⟨fun a b =>
match a, b with
| inl a, inl b => (total_of r a b).imp Lex.inl Lex.inl
| inl _, inr _ => Or.inl (Lex.sep _ _)
| inr _, inl _ => Or.inr (Lex.sep _ _)
| inr a, inr b => (total_of s a b).imp Lex.inr Lex.inr⟩
instance [IsTrichotomous α r] [IsTrichotomous β s] : IsTrichotomous (α ⊕ β) (Lex r s) :=
⟨fun a b =>
match a, b with
| inl a, inl b => (trichotomous_of r a b).imp3 Lex.inl (congr_arg _) Lex.inl
| inl _, inr _ => Or.inl (Lex.sep _ _)
| inr _, inl _ => Or.inr (Or.inr <| Lex.sep _ _)
| inr a, inr b => (trichotomous_of s a b).imp3 Lex.inr (congr_arg _) Lex.inr⟩
instance [IsWellOrder α r] [IsWellOrder β s] :
IsWellOrder (α ⊕ β) (Sum.Lex r s) where wf := Sum.lex_wf IsWellFounded.wf IsWellFounded.wf
end Lex
/-! ### Disjoint sum of two orders -/
section Disjoint
instance instLESum [LE α] [LE β] : LE (α ⊕ β) :=
⟨LiftRel (· ≤ ·) (· ≤ ·)⟩
instance instLTSum [LT α] [LT β] : LT (α ⊕ β) :=
⟨LiftRel (· < ·) (· < ·)⟩
theorem le_def [LE α] [LE β] {a b : α ⊕ β} : a ≤ b ↔ LiftRel (· ≤ ·) (· ≤ ·) a b :=
Iff.rfl
theorem lt_def [LT α] [LT β] {a b : α ⊕ β} : a < b ↔ LiftRel (· < ·) (· < ·) a b :=
Iff.rfl
@[simp]
theorem inl_le_inl_iff [LE α] [LE β] {a b : α} : (inl a : α ⊕ β) ≤ inl b ↔ a ≤ b :=
liftRel_inl_inl
@[simp]
theorem inr_le_inr_iff [LE α] [LE β] {a b : β} : (inr a : α ⊕ β) ≤ inr b ↔ a ≤ b :=
liftRel_inr_inr
@[simp]
theorem inl_lt_inl_iff [LT α] [LT β] {a b : α} : (inl a : α ⊕ β) < inl b ↔ a < b :=
liftRel_inl_inl
@[simp]
theorem inr_lt_inr_iff [LT α] [LT β] {a b : β} : (inr a : α ⊕ β) < inr b ↔ a < b :=
liftRel_inr_inr
@[simp]
theorem not_inl_le_inr [LE α] [LE β] {a : α} {b : β} : ¬inl b ≤ inr a :=
not_liftRel_inl_inr
@[simp]
theorem not_inl_lt_inr [LT α] [LT β] {a : α} {b : β} : ¬inl b < inr a :=
not_liftRel_inl_inr
@[simp]
theorem not_inr_le_inl [LE α] [LE β] {a : α} {b : β} : ¬inr b ≤ inl a :=
not_liftRel_inr_inl
@[simp]
theorem not_inr_lt_inl [LT α] [LT β] {a : α} {b : β} : ¬inr b < inl a :=
not_liftRel_inr_inl
section Preorder
variable [Preorder α] [Preorder β]
instance instPreorderSum : Preorder (α ⊕ β) :=
{ instLESum, instLTSum with
le_refl := fun _ => LiftRel.refl _ _ _,
le_trans := fun _ _ _ => LiftRel.trans _ _,
lt_iff_le_not_le := fun a b => by
refine ⟨fun hab => ⟨hab.mono (fun _ _ => le_of_lt) fun _ _ => le_of_lt, ?_⟩, ?_⟩
· rintro (⟨hba⟩ | ⟨hba⟩)
· exact hba.not_lt (inl_lt_inl_iff.1 hab)
· exact hba.not_lt (inr_lt_inr_iff.1 hab)
· rintro ⟨⟨hab⟩ | ⟨hab⟩, hba⟩
· exact LiftRel.inl (hab.lt_of_not_le fun h => hba <| LiftRel.inl h)
· exact LiftRel.inr (hab.lt_of_not_le fun h => hba <| LiftRel.inr h) }
theorem inl_mono : Monotone (inl : α → α ⊕ β) := fun _ _ => LiftRel.inl
theorem inr_mono : Monotone (inr : β → α ⊕ β) := fun _ _ => LiftRel.inr
theorem inl_strictMono : StrictMono (inl : α → α ⊕ β) := fun _ _ => LiftRel.inl
theorem inr_strictMono : StrictMono (inr : β → α ⊕ β) := fun _ _ => LiftRel.inr
end Preorder
instance [PartialOrder α] [PartialOrder β] : PartialOrder (α ⊕ β) :=
{ instPreorderSum with
le_antisymm := fun _ _ => show LiftRel _ _ _ _ → _ from antisymm }
instance noMinOrder [LT α] [LT β] [NoMinOrder α] [NoMinOrder β] : NoMinOrder (α ⊕ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_lt a
⟨inl b, inl_lt_inl_iff.2 h⟩
| inr a =>
let ⟨b, h⟩ := exists_lt a
⟨inr b, inr_lt_inr_iff.2 h⟩⟩
instance noMaxOrder [LT α] [LT β] [NoMaxOrder α] [NoMaxOrder β] : NoMaxOrder (α ⊕ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_gt a
⟨inl b, inl_lt_inl_iff.2 h⟩
| inr a =>
let ⟨b, h⟩ := exists_gt a
⟨inr b, inr_lt_inr_iff.2 h⟩⟩
@[simp]
theorem noMinOrder_iff [LT α] [LT β] : NoMinOrder (α ⊕ β) ↔ NoMinOrder α ∧ NoMinOrder β :=
⟨fun _ =>
⟨⟨fun a => by
obtain ⟨b | b, h⟩ := exists_lt (inl a : α ⊕ β)
· exact ⟨b, inl_lt_inl_iff.1 h⟩
· exact (not_inr_lt_inl h).elim⟩,
⟨fun a => by
obtain ⟨b | b, h⟩ := exists_lt (inr a : α ⊕ β)
· exact (not_inl_lt_inr h).elim
· exact ⟨b, inr_lt_inr_iff.1 h⟩⟩⟩,
fun h => @Sum.noMinOrder _ _ _ _ h.1 h.2⟩
@[simp]
theorem noMaxOrder_iff [LT α] [LT β] : NoMaxOrder (α ⊕ β) ↔ NoMaxOrder α ∧ NoMaxOrder β :=
⟨fun _ =>
⟨⟨fun a => by
obtain ⟨b | b, h⟩ := exists_gt (inl a : α ⊕ β)
· exact ⟨b, inl_lt_inl_iff.1 h⟩
· exact (not_inl_lt_inr h).elim⟩,
⟨fun a => by
obtain ⟨b | b, h⟩ := exists_gt (inr a : α ⊕ β)
· exact (not_inr_lt_inl h).elim
· exact ⟨b, inr_lt_inr_iff.1 h⟩⟩⟩,
fun h => @Sum.noMaxOrder _ _ _ _ h.1 h.2⟩
instance denselyOrdered [LT α] [LT β] [DenselyOrdered α] [DenselyOrdered β] :
DenselyOrdered (α ⊕ β) :=
⟨fun a b h =>
match a, b, h with
| inl _, inl _, LiftRel.inl h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inl c), LiftRel.inl ha, LiftRel.inl hb⟩
| inr _, inr _, LiftRel.inr h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inr c), LiftRel.inr ha, LiftRel.inr hb⟩⟩
@[simp]
theorem denselyOrdered_iff [LT α] [LT β] :
DenselyOrdered (α ⊕ β) ↔ DenselyOrdered α ∧ DenselyOrdered β :=
⟨fun _ =>
⟨⟨fun a b h => by
obtain ⟨c | c, ha, hb⟩ := @exists_between (α ⊕ β) _ _ _ _ (inl_lt_inl_iff.2 h)
· exact ⟨c, inl_lt_inl_iff.1 ha, inl_lt_inl_iff.1 hb⟩
· exact (not_inl_lt_inr ha).elim⟩,
⟨fun a b h => by
obtain ⟨c | c, ha, hb⟩ := @exists_between (α ⊕ β) _ _ _ _ (inr_lt_inr_iff.2 h)
· exact (not_inl_lt_inr hb).elim
· exact ⟨c, inr_lt_inr_iff.1 ha, inr_lt_inr_iff.1 hb⟩⟩⟩,
fun h => @Sum.denselyOrdered _ _ _ _ h.1 h.2⟩
@[simp]
theorem swap_le_swap_iff [LE α] [LE β] {a b : α ⊕ β} : a.swap ≤ b.swap ↔ a ≤ b :=
liftRel_swap_iff
@[simp]
theorem swap_lt_swap_iff [LT α] [LT β] {a b : α ⊕ β} : a.swap < b.swap ↔ a < b :=
liftRel_swap_iff
| end Disjoint
/-! ### Linear sum of two orders -/
namespace Lex
/-- The linear sum of two orders -/
notation:30 α " ⊕ₗ " β:29 => _root_.Lex (α ⊕ β)
--TODO: Can we make `inlₗ`, `inrₗ` `local notation`?
| Mathlib/Data/Sum/Order.lean | 266 | 277 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Data.Stream.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic.Common
/-!
# Streams a.k.a. infinite lists a.k.a. infinite sequences
-/
open Nat Function Option
namespace Stream'
universe u v w
variable {α : Type u} {β : Type v} {δ : Type w}
variable (m n : ℕ) (x y : List α) (a b : Stream' α)
instance [Inhabited α] : Inhabited (Stream' α) :=
⟨Stream'.const default⟩
@[simp] protected theorem eta (s : Stream' α) : head s :: tail s = s :=
funext fun i => by cases i <;> rfl
/-- Alias for `Stream'.eta` to match `List` API. -/
alias cons_head_tail := Stream'.eta
@[ext]
protected theorem ext {s₁ s₂ : Stream' α} : (∀ n, get s₁ n = get s₂ n) → s₁ = s₂ :=
fun h => funext h
@[simp]
theorem get_zero_cons (a : α) (s : Stream' α) : get (a::s) 0 = a :=
rfl
@[simp]
theorem head_cons (a : α) (s : Stream' α) : head (a::s) = a :=
rfl
@[simp]
theorem tail_cons (a : α) (s : Stream' α) : tail (a::s) = s :=
rfl
@[simp]
theorem get_drop (n m : ℕ) (s : Stream' α) : get (drop m s) n = get s (m + n) := by
rw [Nat.add_comm]
rfl
theorem tail_eq_drop (s : Stream' α) : tail s = drop 1 s :=
rfl
@[simp]
theorem drop_drop (n m : ℕ) (s : Stream' α) : drop n (drop m s) = drop (m + n) s := by
ext; simp [Nat.add_assoc]
@[simp] theorem get_tail {n : ℕ} {s : Stream' α} : s.tail.get n = s.get (n + 1) := rfl
@[simp] theorem tail_drop' {i : ℕ} {s : Stream' α} : tail (drop i s) = s.drop (i + 1) := by
ext; simp [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm]
@[simp] theorem drop_tail' {i : ℕ} {s : Stream' α} : drop i (tail s) = s.drop (i + 1) := rfl
theorem tail_drop (n : ℕ) (s : Stream' α) : tail (drop n s) = drop n (tail s) := by simp
theorem get_succ (n : ℕ) (s : Stream' α) : get s (succ n) = get (tail s) n :=
rfl
@[simp]
theorem get_succ_cons (n : ℕ) (s : Stream' α) (x : α) : get (x :: s) n.succ = get s n :=
rfl
@[simp] lemma get_cons_append_zero {a : α} {x : List α} {s : Stream' α} :
(a :: x ++ₛ s).get 0 = a := rfl
@[simp] lemma append_eq_cons {a : α} {as : Stream' α} : [a] ++ₛ as = a :: as := by rfl
@[simp] theorem drop_zero {s : Stream' α} : s.drop 0 = s := rfl
theorem drop_succ (n : ℕ) (s : Stream' α) : drop (succ n) s = drop n (tail s) :=
rfl
theorem head_drop (a : Stream' α) (n : ℕ) : (a.drop n).head = a.get n := by simp
theorem cons_injective2 : Function.Injective2 (cons : α → Stream' α → Stream' α) := fun x y s t h =>
⟨by rw [← get_zero_cons x s, h, get_zero_cons],
Stream'.ext fun n => by rw [← get_succ_cons n _ x, h, get_succ_cons]⟩
theorem cons_injective_left (s : Stream' α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_injective_right (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
theorem all_def (p : α → Prop) (s : Stream' α) : All p s = ∀ n, p (get s n) :=
rfl
theorem any_def (p : α → Prop) (s : Stream' α) : Any p s = ∃ n, p (get s n) :=
rfl
@[simp]
theorem mem_cons (a : α) (s : Stream' α) : a ∈ a::s :=
Exists.intro 0 rfl
theorem mem_cons_of_mem {a : α} {s : Stream' α} (b : α) : a ∈ s → a ∈ b::s := fun ⟨n, h⟩ =>
Exists.intro (succ n) (by rw [get_succ, tail_cons, h])
theorem eq_or_mem_of_mem_cons {a b : α} {s : Stream' α} : (a ∈ b::s) → a = b ∨ a ∈ s :=
fun ⟨n, h⟩ => by
rcases n with - | n'
· left
exact h
· right
rw [get_succ, tail_cons] at h
exact ⟨n', h⟩
theorem mem_of_get_eq {n : ℕ} {s : Stream' α} {a : α} : a = get s n → a ∈ s := fun h =>
Exists.intro n h
section Map
variable (f : α → β)
theorem drop_map (n : ℕ) (s : Stream' α) : drop n (map f s) = map f (drop n s) :=
Stream'.ext fun _ => rfl
@[simp]
theorem get_map (n : ℕ) (s : Stream' α) : get (map f s) n = f (get s n) :=
rfl
theorem tail_map (s : Stream' α) : tail (map f s) = map f (tail s) := rfl
@[simp]
theorem head_map (s : Stream' α) : head (map f s) = f (head s) :=
rfl
theorem map_eq (s : Stream' α) : map f s = f (head s)::map f (tail s) := by
rw [← Stream'.eta (map f s), tail_map, head_map]
theorem map_cons (a : α) (s : Stream' α) : map f (a::s) = f a::map f s := by
rw [← Stream'.eta (map f (a::s)), map_eq]; rfl
@[simp]
theorem map_id (s : Stream' α) : map id s = s :=
rfl
@[simp]
theorem map_map (g : β → δ) (f : α → β) (s : Stream' α) : map g (map f s) = map (g ∘ f) s :=
rfl
@[simp]
theorem map_tail (s : Stream' α) : map f (tail s) = tail (map f s) :=
rfl
theorem mem_map {a : α} {s : Stream' α} : a ∈ s → f a ∈ map f s := fun ⟨n, h⟩ =>
Exists.intro n (by rw [get_map, h])
theorem exists_of_mem_map {f} {b : β} {s : Stream' α} : b ∈ map f s → ∃ a, a ∈ s ∧ f a = b :=
fun ⟨n, h⟩ => ⟨get s n, ⟨n, rfl⟩, h.symm⟩
end Map
section Zip
variable (f : α → β → δ)
theorem drop_zip (n : ℕ) (s₁ : Stream' α) (s₂ : Stream' β) :
drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) :=
Stream'.ext fun _ => rfl
@[simp]
theorem get_zip (n : ℕ) (s₁ : Stream' α) (s₂ : Stream' β) :
get (zip f s₁ s₂) n = f (get s₁ n) (get s₂ n) :=
rfl
theorem head_zip (s₁ : Stream' α) (s₂ : Stream' β) : head (zip f s₁ s₂) = f (head s₁) (head s₂) :=
rfl
theorem tail_zip (s₁ : Stream' α) (s₂ : Stream' β) :
tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) :=
rfl
theorem zip_eq (s₁ : Stream' α) (s₂ : Stream' β) :
zip f s₁ s₂ = f (head s₁) (head s₂)::zip f (tail s₁) (tail s₂) := by
rw [← Stream'.eta (zip f s₁ s₂)]; rfl
@[simp]
theorem get_enum (s : Stream' α) (n : ℕ) : get (enum s) n = (n, s.get n) :=
rfl
theorem enum_eq_zip (s : Stream' α) : enum s = zip Prod.mk nats s :=
rfl
end Zip
@[simp]
theorem mem_const (a : α) : a ∈ const a :=
Exists.intro 0 rfl
theorem const_eq (a : α) : const a = a::const a := by
apply Stream'.ext; intro n
cases n <;> rfl
@[simp]
theorem tail_const (a : α) : tail (const a) = const a :=
suffices tail (a::const a) = const a by rwa [← const_eq] at this
rfl
@[simp]
theorem map_const (f : α → β) (a : α) : map f (const a) = const (f a) :=
rfl
@[simp]
theorem get_const (n : ℕ) (a : α) : get (const a) n = a :=
rfl
@[simp]
theorem drop_const (n : ℕ) (a : α) : drop n (const a) = const a :=
Stream'.ext fun _ => rfl
@[simp]
theorem head_iterate (f : α → α) (a : α) : head (iterate f a) = a :=
rfl
theorem get_succ_iterate' (n : ℕ) (f : α → α) (a : α) :
get (iterate f a) (succ n) = f (get (iterate f a) n) := rfl
theorem tail_iterate (f : α → α) (a : α) : tail (iterate f a) = iterate f (f a) := by
ext n
rw [get_tail]
induction' n with n' ih
· rfl
· rw [get_succ_iterate', ih, get_succ_iterate']
theorem iterate_eq (f : α → α) (a : α) : iterate f a = a::iterate f (f a) := by
rw [← Stream'.eta (iterate f a)]
rw [tail_iterate]; rfl
@[simp]
theorem get_zero_iterate (f : α → α) (a : α) : get (iterate f a) 0 = a :=
rfl
theorem get_succ_iterate (n : ℕ) (f : α → α) (a : α) :
get (iterate f a) (succ n) = get (iterate f (f a)) n := by rw [get_succ, tail_iterate]
section Bisim
variable (R : Stream' α → Stream' α → Prop)
/-- equivalence relation -/
local infixl:50 " ~ " => R
/-- Streams `s₁` and `s₂` are defined to be bisimulations if
their heads are equal and tails are bisimulations. -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ →
head s₁ = head s₂ ∧ tail s₁ ~ tail s₂
theorem get_of_bisim (bisim : IsBisimulation R) {s₁ s₂} :
∀ n, s₁ ~ s₂ → get s₁ n = get s₂ n ∧ drop (n + 1) s₁ ~ drop (n + 1) s₂
| 0, h => bisim h
| n + 1, h =>
match bisim h with
| ⟨_, trel⟩ => get_of_bisim bisim n trel
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} : s₁ ~ s₂ → s₁ = s₂ := fun r =>
Stream'.ext fun n => And.left (get_of_bisim R bisim n r)
end Bisim
theorem bisim_simple (s₁ s₂ : Stream' α) :
head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ := fun hh ht₁ ht₂ =>
eq_of_bisim (fun s₁ s₂ => head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂)
(fun s₁ s₂ ⟨h₁, h₂, h₃⟩ => by
constructor
· exact h₁
rw [← h₂, ← h₃]
(repeat' constructor) <;> assumption)
(And.intro hh (And.intro ht₁ ht₂))
theorem coinduction {s₁ s₂ : Stream' α} :
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Stream' α → β),
fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ :=
fun hh ht =>
eq_of_bisim
(fun s₁ s₂ =>
head s₁ = head s₂ ∧
∀ (β : Type u) (fr : Stream' α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂))
(fun s₁ s₂ h =>
have h₁ : head s₁ = head s₂ := And.left h
have h₂ : head (tail s₁) = head (tail s₂) := And.right h α (@head α) h₁
have h₃ :
∀ (β : Type u) (fr : Stream' α → β),
fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)) :=
fun β fr => And.right h β fun s => fr (tail s)
And.intro h₁ (And.intro h₂ h₃))
(And.intro hh ht)
@[simp]
theorem iterate_id (a : α) : iterate id a = const a :=
coinduction rfl fun β fr ch => by rw [tail_iterate, tail_const]; exact ch
theorem map_iterate (f : α → α) (a : α) : iterate f (f a) = map f (iterate f a) := by
funext n
induction' n with n' ih
· rfl
· unfold map iterate get
rw [map, get] at ih
rw [iterate]
exact congrArg f ih
section Corec
theorem corec_def (f : α → β) (g : α → α) (a : α) : corec f g a = map f (iterate g a) :=
rfl
theorem corec_eq (f : α → β) (g : α → α) (a : α) : corec f g a = f a :: corec f g (g a) := by
rw [corec_def, map_eq, head_iterate, tail_iterate]; rfl
theorem corec_id_id_eq_const (a : α) : corec id id a = const a := by
rw [corec_def, map_id, iterate_id]
theorem corec_id_f_eq_iterate (f : α → α) (a : α) : corec id f a = iterate f a :=
rfl
end Corec
section Corec'
theorem corec'_eq (f : α → β × α) (a : α) : corec' f a = (f a).1 :: corec' f (f a).2 :=
corec_eq _ _ _
end Corec'
theorem unfolds_eq (g : α → β) (f : α → α) (a : α) : unfolds g f a = g a :: unfolds g f (f a) := by
unfold unfolds; rw [corec_eq]
theorem get_unfolds_head_tail : ∀ (n : ℕ) (s : Stream' α),
get (unfolds head tail s) n = get s n := by
intro n; induction' n with n' ih
· intro s
rfl
· intro s
rw [get_succ, get_succ, unfolds_eq, tail_cons, ih]
theorem unfolds_head_eq : ∀ s : Stream' α, unfolds head tail s = s := fun s =>
Stream'.ext fun n => get_unfolds_head_tail n s
theorem interleave_eq (s₁ s₂ : Stream' α) : s₁ ⋈ s₂ = head s₁::head s₂::(tail s₁ ⋈ tail s₂) := by
let t := tail s₁ ⋈ tail s₂
show s₁ ⋈ s₂ = head s₁::head s₂::t
unfold interleave; unfold corecOn; rw [corec_eq]; dsimp; rw [corec_eq]; rfl
theorem tail_interleave (s₁ s₂ : Stream' α) : tail (s₁ ⋈ s₂) = s₂ ⋈ tail s₁ := by
unfold interleave corecOn; rw [corec_eq]; rfl
theorem interleave_tail_tail (s₁ s₂ : Stream' α) : tail s₁ ⋈ tail s₂ = tail (tail (s₁ ⋈ s₂)) := by
rw [interleave_eq s₁ s₂]; rfl
theorem get_interleave_left : ∀ (n : ℕ) (s₁ s₂ : Stream' α),
get (s₁ ⋈ s₂) (2 * n) = get s₁ n
| 0, _, _ => rfl
| n + 1, s₁, s₂ => by
change get (s₁ ⋈ s₂) (succ (succ (2 * n))) = get s₁ (succ n)
rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons]
rw [get_interleave_left n (tail s₁) (tail s₂)]
rfl
theorem get_interleave_right : ∀ (n : ℕ) (s₁ s₂ : Stream' α),
get (s₁ ⋈ s₂) (2 * n + 1) = get s₂ n
| 0, _, _ => rfl
| n + 1, s₁, s₂ => by
change get (s₁ ⋈ s₂) (succ (succ (2 * n + 1))) = get s₂ (succ n)
rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons,
get_interleave_right n (tail s₁) (tail s₂)]
rfl
theorem mem_interleave_left {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₁ → a ∈ s₁ ⋈ s₂ :=
fun ⟨n, h⟩ => Exists.intro (2 * n) (by rw [h, get_interleave_left])
theorem mem_interleave_right {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₂ → a ∈ s₁ ⋈ s₂ :=
fun ⟨n, h⟩ => Exists.intro (2 * n + 1) (by rw [h, get_interleave_right])
theorem odd_eq (s : Stream' α) : odd s = even (tail s) :=
rfl
@[simp]
theorem head_even (s : Stream' α) : head (even s) = head s :=
rfl
theorem tail_even (s : Stream' α) : tail (even s) = even (tail (tail s)) := by
unfold even
rw [corec_eq]
rfl
theorem even_cons_cons (a₁ a₂ : α) (s : Stream' α) : even (a₁::a₂::s) = a₁::even s := by
unfold even
rw [corec_eq]; rfl
theorem even_tail (s : Stream' α) : even (tail s) = odd s :=
rfl
theorem even_interleave (s₁ s₂ : Stream' α) : even (s₁ ⋈ s₂) = s₁ :=
eq_of_bisim (fun s₁' s₁ => ∃ s₂, s₁' = even (s₁ ⋈ s₂))
(fun s₁' s₁ ⟨s₂, h₁⟩ => by
rw [h₁]
constructor
· rfl
· exact ⟨tail s₂, by rw [interleave_eq, even_cons_cons, tail_cons]⟩)
(Exists.intro s₂ rfl)
theorem interleave_even_odd (s₁ : Stream' α) : even s₁ ⋈ odd s₁ = s₁ :=
eq_of_bisim (fun s' s => s' = even s ⋈ odd s)
(fun s' s (h : s' = even s ⋈ odd s) => by
rw [h]; constructor
· rfl
· simp [odd_eq, odd_eq, tail_interleave, tail_even])
rfl
theorem get_even : ∀ (n : ℕ) (s : Stream' α), get (even s) n = get s (2 * n)
| 0, _ => rfl
| succ n, s => by
change get (even s) (succ n) = get s (succ (succ (2 * n)))
rw [get_succ, get_succ, tail_even, get_even n]; rfl
theorem get_odd : ∀ (n : ℕ) (s : Stream' α), get (odd s) n = get s (2 * n + 1) := fun n s => by
rw [odd_eq, get_even]; rfl
theorem mem_of_mem_even (a : α) (s : Stream' α) : a ∈ even s → a ∈ s := fun ⟨n, h⟩ =>
Exists.intro (2 * n) (by rw [h, get_even])
theorem mem_of_mem_odd (a : α) (s : Stream' α) : a ∈ odd s → a ∈ s := fun ⟨n, h⟩ =>
Exists.intro (2 * n + 1) (by rw [h, get_odd])
@[simp] theorem nil_append_stream (s : Stream' α) : appendStream' [] s = s :=
rfl
theorem cons_append_stream (a : α) (l : List α) (s : Stream' α) :
appendStream' (a::l) s = a::appendStream' l s :=
rfl
@[simp] theorem append_append_stream : ∀ (l₁ l₂ : List α) (s : Stream' α),
l₁ ++ l₂ ++ₛ s = l₁ ++ₛ (l₂ ++ₛ s)
| [], _, _ => rfl
| List.cons a l₁, l₂, s => by
rw [List.cons_append, cons_append_stream, cons_append_stream, append_append_stream l₁]
lemma get_append_left (h : n < x.length) : (x ++ₛ a).get n = x[n] := by
induction' x with b x ih generalizing n
· simp at h
· rcases n with (_ | n)
· simp
· simp [ih n (by simpa using h), cons_append_stream]
@[simp] lemma get_append_right : (x ++ₛ a).get (x.length + n) = a.get n := by
induction' x <;> simp [Nat.succ_add, *, cons_append_stream]
@[simp] lemma get_append_length : (x ++ₛ a).get x.length = a.get 0 := get_append_right 0 x a
lemma append_right_injective (h : x ++ₛ a = x ++ₛ b) : a = b := by
ext n; replace h := congr_arg (fun a ↦ a.get (x.length + n)) h; simpa using h
@[simp] lemma append_right_inj : x ++ₛ a = x ++ₛ b ↔ a = b :=
⟨append_right_injective x a b, by simp +contextual⟩
lemma append_left_injective (h : x ++ₛ a = y ++ₛ b) (hl : x.length = y.length) : x = y := by
apply List.ext_getElem hl
intros
rw [← get_append_left, ← get_append_left, h]
theorem map_append_stream (f : α → β) :
∀ (l : List α) (s : Stream' α), map f (l ++ₛ s) = List.map f l ++ₛ map f s
| [], _ => rfl
| List.cons a l, s => by
rw [cons_append_stream, List.map_cons, map_cons, cons_append_stream, map_append_stream f l]
theorem drop_append_stream : ∀ (l : List α) (s : Stream' α), drop l.length (l ++ₛ s) = s
| [], s => by rfl
| List.cons a l, s => by
rw [List.length_cons, drop_succ, cons_append_stream, tail_cons, drop_append_stream l s]
theorem append_stream_head_tail (s : Stream' α) : [head s] ++ₛ tail s = s := by
simp
theorem mem_append_stream_right : ∀ {a : α} (l : List α) {s : Stream' α}, a ∈ s → a ∈ l ++ₛ s
| _, [], _, h => h
| a, List.cons _ l, s, h =>
have ih : a ∈ l ++ₛ s := mem_append_stream_right l h
mem_cons_of_mem _ ih
theorem mem_append_stream_left : ∀ {a : α} {l : List α} (s : Stream' α), a ∈ l → a ∈ l ++ₛ s
| _, [], _, h => absurd h List.not_mem_nil
| a, List.cons b l, s, h =>
Or.elim (List.eq_or_mem_of_mem_cons h) (fun aeqb : a = b => Exists.intro 0 aeqb)
fun ainl : a ∈ l => mem_cons_of_mem b (mem_append_stream_left s ainl)
@[simp]
theorem take_zero (s : Stream' α) : take 0 s = [] :=
rfl
-- This lemma used to be simp, but we removed it from the simp set because:
-- 1) It duplicates the (often large) `s` term, resulting in large tactic states.
-- 2) It conflicts with the very useful `dropLast_take` lemma below (causing nonconfluence).
theorem take_succ (n : ℕ) (s : Stream' α) : take (succ n) s = head s::take n (tail s) :=
rfl
@[simp] theorem take_succ_cons {a : α} (n : ℕ) (s : Stream' α) :
take (n+1) (a::s) = a :: take n s := rfl
theorem take_succ' {s : Stream' α} : ∀ n, s.take (n+1) = s.take n ++ [s.get n]
| 0 => rfl
| n+1 => by rw [take_succ, take_succ' n, ← List.cons_append, ← take_succ, get_tail]
@[simp]
theorem length_take (n : ℕ) (s : Stream' α) : (take n s).length = n := by
induction n generalizing s <;> simp [*, take_succ]
@[simp]
theorem take_take {s : Stream' α} : ∀ {m n}, (s.take n).take m = s.take (min n m)
| 0, n => by rw [Nat.min_zero, List.take_zero, take_zero]
| m, 0 => by rw [Nat.zero_min, take_zero, List.take_nil]
| m+1, n+1 => by rw [take_succ, List.take_succ_cons, Nat.succ_min_succ, take_succ, take_take]
@[simp] theorem concat_take_get {n : ℕ} {s : Stream' α} : s.take n ++ [s.get n] = s.take (n + 1) :=
(take_succ' n).symm
theorem getElem?_take {s : Stream' α} : ∀ {k n}, k < n → (s.take n)[k]? = s.get k
| 0, _+1, _ => by simp only [length_take, zero_lt_succ, List.getElem?_eq_getElem]; rfl
| k+1, n+1, h => by
rw [take_succ, List.getElem?_cons_succ, getElem?_take (Nat.lt_of_succ_lt_succ h), get_succ]
@[deprecated (since := "2025-02-14")] alias get?_take := getElem?_take
theorem getElem?_take_succ (n : ℕ) (s : Stream' α) :
(take (succ n) s)[n]? = some (get s n) :=
getElem?_take (Nat.lt_succ_self n)
@[deprecated (since := "2025-02-14")] alias get?_take_succ := getElem?_take_succ
@[simp] theorem dropLast_take {n : ℕ} {xs : Stream' α} :
(Stream'.take n xs).dropLast = Stream'.take (n-1) xs := by
cases n with
| zero => simp
| succ n => rw [take_succ', List.dropLast_concat, Nat.add_one_sub_one]
@[simp]
theorem append_take_drop : ∀ (n : ℕ) (s : Stream' α),
appendStream' (take n s) (drop n s) = s := by
intro n
induction' n with n' ih
· intro s
rfl
· intro s
rw [take_succ, drop_succ, cons_append_stream, ih (tail s), Stream'.eta]
lemma append_take : x ++ (a.take n) = (x ++ₛ a).take (x.length + n) := by
induction' x <;> simp [take, Nat.add_comm, cons_append_stream, *]
@[simp] lemma take_get (h : m < (a.take n).length) : (a.take n)[m] = a.get m := by
nth_rw 2 [← append_take_drop n a]; rw [get_append_left]
theorem take_append_of_le_length (h : n ≤ x.length) :
(x ++ₛ a).take n = x.take n := by
apply List.ext_getElem (by simp [h])
intro _ _ _; rw [List.getElem_take, take_get, get_append_left]
lemma take_add : a.take (m + n) = a.take m ++ (a.drop m).take n := by
apply append_left_injective _ _ (a.drop (m + n)) ((a.drop m).drop n) <;>
simp [- drop_drop]
@[gcongr] lemma take_prefix_take_left (h : m ≤ n) : a.take m <+: a.take n := by
rw [(by simp [h] : a.take m = (a.take n).take m)]
apply List.take_prefix
@[simp] lemma take_prefix : a.take m <+: a.take n ↔ m ≤ n :=
⟨fun h ↦ by simpa using h.length_le, take_prefix_take_left m n a⟩
lemma map_take (f : α → β) : (a.take n).map f = (a.map f).take n := by
apply List.ext_getElem <;> simp
lemma take_drop : (a.drop m).take n = (a.take (m + n)).drop m := by
apply List.ext_getElem <;> simp
lemma drop_append_of_le_length (h : n ≤ x.length) :
(x ++ₛ a).drop n = x.drop n ++ₛ a := by
obtain ⟨m, hm⟩ := Nat.exists_eq_add_of_le h
ext k; rcases lt_or_ge k m with _ | hk
· rw [get_drop, get_append_left, get_append_left, List.getElem_drop]; simpa [hm]
· obtain ⟨p, rfl⟩ := Nat.exists_eq_add_of_le hk
have hm' : m = (x.drop n).length := by simp [hm]
simp_rw [get_drop, ← Nat.add_assoc, ← hm, get_append_right, hm', get_append_right]
-- Take theorem reduces a proof of equality of infinite streams to an
-- induction over all their finite approximations.
theorem take_theorem (s₁ s₂ : Stream' α) : (∀ n : ℕ, take n s₁ = take n s₂) → s₁ = s₂ := by
intro h; apply Stream'.ext; intro n
induction' n with n _
· have aux := h 1
simp? [take] at aux says
simp only [take, List.cons.injEq, and_true] at aux
exact aux
· have h₁ : some (get s₁ (succ n)) = some (get s₂ (succ n)) := by
rw [← getElem?_take_succ, ← getElem?_take_succ, h (succ (succ n))]
injection h₁
protected theorem cycle_g_cons (a : α) (a₁ : α) (l₁ : List α) (a₀ : α) (l₀ : List α) :
Stream'.cycleG (a, a₁::l₁, a₀, l₀) = (a₁, l₁, a₀, l₀) :=
rfl
theorem cycle_eq : ∀ (l : List α) (h : l ≠ []), cycle l h = l ++ₛ cycle l h
| [], h => absurd rfl h
| List.cons a l, _ =>
have gen : ∀ l' a', corec Stream'.cycleF Stream'.cycleG (a', l', a, l) =
(a'::l') ++ₛ corec Stream'.cycleF Stream'.cycleG (a, l, a, l) := by
intro l'
induction' l' with a₁ l₁ ih
· intros
rw [corec_eq]
rfl
· intros
rw [corec_eq, Stream'.cycle_g_cons, ih a₁]
rfl
gen l a
theorem mem_cycle {a : α} {l : List α} : ∀ h : l ≠ [], a ∈ l → a ∈ cycle l h := fun h ainl => by
rw [cycle_eq]; exact mem_append_stream_left _ ainl
@[simp]
theorem cycle_singleton (a : α) : cycle [a] (by simp) = const a :=
coinduction rfl fun β fr ch => by rwa [cycle_eq, const_eq]
theorem tails_eq (s : Stream' α) : tails s = tail s::tails (tail s) := by
unfold tails; rw [corec_eq]; rfl
@[simp]
theorem get_tails : ∀ (n : ℕ) (s : Stream' α), get (tails s) n = drop n (tail s) := by
intro n; induction' n with n' ih
· intros
rfl
· intro s
rw [get_succ, drop_succ, tails_eq, tail_cons, ih]
theorem tails_eq_iterate (s : Stream' α) : tails s = iterate tail (tail s) :=
rfl
theorem inits_core_eq (l : List α) (s : Stream' α) :
initsCore l s = l::initsCore (l ++ [head s]) (tail s) := by
unfold initsCore corecOn
rw [corec_eq]
theorem tail_inits (s : Stream' α) :
tail (inits s) = initsCore [head s, head (tail s)] (tail (tail s)) := by
unfold inits
rw [inits_core_eq]; rfl
theorem inits_tail (s : Stream' α) : inits (tail s) = initsCore [head (tail s)] (tail (tail s)) :=
rfl
theorem cons_get_inits_core :
∀ (a : α) (n : ℕ) (l : List α) (s : Stream' α),
(a::get (initsCore l s) n) = get (initsCore (a::l) s) n := by
intro a n
induction' n with n' ih
· intros
rfl
· intro l s
rw [get_succ, inits_core_eq, tail_cons, ih, inits_core_eq (a::l) s]
rfl
@[simp]
theorem get_inits : ∀ (n : ℕ) (s : Stream' α), get (inits s) n = take (succ n) s := by
intro n; induction' n with n' ih
· intros
rfl
· intros
rw [get_succ, take_succ, ← ih, tail_inits, inits_tail, cons_get_inits_core]
theorem inits_eq (s : Stream' α) :
inits s = [head s]::map (List.cons (head s)) (inits (tail s)) := by
| apply Stream'.ext; intro n
cases n
· rfl
· rw [get_inits, get_succ, tail_cons, get_map, get_inits]
| Mathlib/Data/Stream/Init.lean | 686 | 689 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.MeasurableSpace.Constructions
import Mathlib.Tactic.FunProp
/-!
# Measurable embeddings and equivalences
A measurable equivalence between measurable spaces is an equivalence
which respects the σ-algebras, that is, for which both directions of
the equivalence are measurable functions.
## Main definitions
* `MeasurableEmbedding`: a map `f : α → β` is called a *measurable embedding* if it is injective,
measurable, and sends measurable sets to measurable sets.
* `MeasurableEquiv`: an equivalence `α ≃ β` is a *measurable equivalence* if its forward and inverse
functions are measurable.
We prove a multitude of elementary lemmas about these, and one more substantial theorem:
* `MeasurableEmbedding.schroederBernstein`: the **measurable Schröder-Bernstein Theorem**: given
measurable embeddings `α → β` and `β → α`, we can find a measurable equivalence `α ≃ᵐ β`.
## Notation
* We write `α ≃ᵐ β` for measurable equivalences between the measurable spaces `α` and `β`.
This should not be confused with `≃ₘ` which is used for diffeomorphisms between manifolds.
## Tags
measurable equivalence, measurable embedding
-/
open Set Function Equiv MeasureTheory
universe uι
variable {α β γ δ δ' : Type*} {ι : Sort uι} {s t u : Set α}
/-- A map `f : α → β` is called a *measurable embedding* if it is injective, measurable, and sends
measurable sets to measurable sets. The latter assumption can be replaced with “`f` has measurable
inverse `g : Set.range f → α`”, see `MeasurableEmbedding.measurable_rangeSplitting`,
`MeasurableEmbedding.of_measurable_inverse_range`, and
`MeasurableEmbedding.of_measurable_inverse`.
One more interpretation: `f` is a measurable embedding if it defines a measurable equivalence to its
range and the range is a measurable set. One implication is formalized as
`MeasurableEmbedding.equivRange`; the other one follows from
`MeasurableEquiv.measurableEmbedding`, `MeasurableEmbedding.subtype_coe`, and
`MeasurableEmbedding.comp`. -/
structure MeasurableEmbedding [MeasurableSpace α] [MeasurableSpace β] (f : α → β) : Prop where
/-- A measurable embedding is injective. -/
protected injective : Injective f
/-- A measurable embedding is a measurable function. -/
protected measurable : Measurable f
/-- The image of a measurable set under a measurable embedding is a measurable set. -/
protected measurableSet_image' : ∀ ⦃s⦄, MeasurableSet s → MeasurableSet (f '' s)
attribute [fun_prop] MeasurableEmbedding.measurable
namespace MeasurableEmbedding
variable {mα : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] {f : α → β} {g : β → γ}
theorem measurableSet_image (hf : MeasurableEmbedding f) :
MeasurableSet (f '' s) ↔ MeasurableSet s :=
⟨fun h => by simpa only [hf.injective.preimage_image] using hf.measurable h, fun h =>
hf.measurableSet_image' h⟩
theorem id : MeasurableEmbedding (id : α → α) :=
⟨injective_id, measurable_id, fun s hs => by rwa [image_id]⟩
theorem comp (hg : MeasurableEmbedding g) (hf : MeasurableEmbedding f) :
MeasurableEmbedding (g ∘ f) :=
⟨hg.injective.comp hf.injective, hg.measurable.comp hf.measurable, fun s hs => by
rwa [image_comp, hg.measurableSet_image, hf.measurableSet_image]⟩
theorem subtype_coe (hs : MeasurableSet s) : MeasurableEmbedding ((↑) : s → α) where
injective := Subtype.coe_injective
measurable := measurable_subtype_coe
measurableSet_image' := fun _ => MeasurableSet.subtype_image hs
theorem measurableSet_range (hf : MeasurableEmbedding f) : MeasurableSet (range f) := by
rw [← image_univ]
exact hf.measurableSet_image' MeasurableSet.univ
theorem measurableSet_preimage (hf : MeasurableEmbedding f) {s : Set β} :
MeasurableSet (f ⁻¹' s) ↔ MeasurableSet (s ∩ range f) := by
rw [← image_preimage_eq_inter_range, hf.measurableSet_image]
theorem measurable_rangeSplitting (hf : MeasurableEmbedding f) :
Measurable (rangeSplitting f) := fun s hs => by
rwa [preimage_rangeSplitting hf.injective,
← (subtype_coe hf.measurableSet_range).measurableSet_image, ← image_comp,
coe_comp_rangeFactorization, hf.measurableSet_image]
theorem measurable_extend (hf : MeasurableEmbedding f) {g : α → γ} {g' : β → γ} (hg : Measurable g)
(hg' : Measurable g') : Measurable (extend f g g') := by
refine measurable_of_restrict_of_restrict_compl hf.measurableSet_range ?_ ?_
· rw [restrict_extend_range]
simpa only [rangeSplitting] using hg.comp hf.measurable_rangeSplitting
· rw [restrict_extend_compl_range]
exact hg'.comp measurable_subtype_coe
theorem exists_measurable_extend (hf : MeasurableEmbedding f) {g : α → γ} (hg : Measurable g)
(hne : β → Nonempty γ) : ∃ g' : β → γ, Measurable g' ∧ g' ∘ f = g :=
⟨extend f g fun x => Classical.choice (hne x),
hf.measurable_extend hg (measurable_const' fun _ _ => rfl),
funext fun _ => hf.injective.extend_apply _ _ _⟩
theorem measurable_comp_iff (hg : MeasurableEmbedding g) : Measurable (g ∘ f) ↔ Measurable f := by
refine ⟨fun H => ?_, hg.measurable.comp⟩
suffices Measurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) by
rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this
exact hg.measurable_rangeSplitting.comp H.subtype_mk
end MeasurableEmbedding
section gluing
variable {α₁ α₂ α₃ : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
{mα₁ : MeasurableSpace α₁} {mα₂ : MeasurableSpace α₂} {mα₃ : MeasurableSpace α₃}
{i₁ : α₁ → α} {i₂ : α₂ → α} {i₃ : α₃ → α} {s : Set α} {f : α → β}
lemma MeasurableSet.of_union_range_cover (hi₁ : MeasurableEmbedding i₁)
(hi₂ : MeasurableEmbedding i₂) (h : univ ⊆ range i₁ ∪ range i₂)
(hs₁ : MeasurableSet (i₁ ⁻¹' s)) (hs₂ : MeasurableSet (i₂ ⁻¹' s)) : MeasurableSet s := by
convert (hi₁.measurableSet_image' hs₁).union (hi₂.measurableSet_image' hs₂)
simp [image_preimage_eq_range_inter, ← union_inter_distrib_right,univ_subset_iff.1 h]
lemma MeasurableSet.of_union₃_range_cover (hi₁ : MeasurableEmbedding i₁)
(hi₂ : MeasurableEmbedding i₂) (hi₃ : MeasurableEmbedding i₃)
(h : univ ⊆ range i₁ ∪ range i₂ ∪ range i₃) (hs₁ : MeasurableSet (i₁ ⁻¹' s))
(hs₂ : MeasurableSet (i₂ ⁻¹' s)) (hs₃ : MeasurableSet (i₃ ⁻¹' s)) : MeasurableSet s := by
convert (hi₁.measurableSet_image' hs₁).union (hi₂.measurableSet_image' hs₂) |>.union
(hi₃.measurableSet_image' hs₃)
simp [image_preimage_eq_range_inter, ← union_inter_distrib_right, univ_subset_iff.1 h]
lemma Measurable.of_union_range_cover (hi₁ : MeasurableEmbedding i₁)
(hi₂ : MeasurableEmbedding i₂) (h : univ ⊆ range i₁ ∪ range i₂)
(hf₁ : Measurable (f ∘ i₁)) (hf₂ : Measurable (f ∘ i₂)) : Measurable f :=
fun _s hs ↦ .of_union_range_cover hi₁ hi₂ h (hf₁ hs) (hf₂ hs)
lemma Measurable.of_union₃_range_cover (hi₁ : MeasurableEmbedding i₁)
(hi₂ : MeasurableEmbedding i₂) (hi₃ : MeasurableEmbedding i₃)
(h : univ ⊆ range i₁ ∪ range i₂ ∪ range i₃) (hf₁ : Measurable (f ∘ i₁))
(hf₂ : Measurable (f ∘ i₂)) (hf₃ : Measurable (f ∘ i₃)) : Measurable f :=
fun _s hs ↦ .of_union₃_range_cover hi₁ hi₂ hi₃ h (hf₁ hs) (hf₂ hs) (hf₃ hs)
end gluing
| theorem MeasurableSet.exists_measurable_proj {_ : MeasurableSpace α}
(hs : MeasurableSet s) (hne : s.Nonempty) : ∃ f : α → s, Measurable f ∧ ∀ x : s, f x = x :=
let ⟨f, hfm, hf⟩ :=
| Mathlib/MeasureTheory/MeasurableSpace/Embedding.lean | 156 | 158 |
/-
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). -/
protected theorem const (b : β) : LipschitzWith 0 fun _ : α => b := fun x y => by
simp only [edist_self, zero_le]
protected theorem const' (b : β) {K : ℝ≥0} : LipschitzWith K fun _ : α => b := fun x y => by
simp only [edist_self, zero_le]
/-- The identity is 1-Lipschitz. -/
protected theorem id : LipschitzWith 1 (@id α) :=
LipschitzWith.of_edist_le fun _ _ => le_rfl
/-- The inclusion of a subset is 1-Lipschitz. -/
protected theorem subtype_val (s : Set α) : LipschitzWith 1 (Subtype.val : s → α) :=
LipschitzWith.of_edist_le fun _ _ => le_rfl
theorem subtype_mk (hf : LipschitzWith K f) {p : β → Prop} (hp : ∀ x, p (f x)) :
LipschitzWith K (fun x => ⟨f x, hp x⟩ : α → { y // p y }) :=
hf
protected theorem eval {α : ι → Type u} [∀ i, PseudoEMetricSpace (α i)] [Fintype ι] (i : ι) :
LipschitzWith 1 (Function.eval i : (∀ i, α i) → α i) :=
LipschitzWith.of_edist_le fun f g => by convert edist_le_pi_edist f g i
/-- The restriction of a `K`-Lipschitz function is `K`-Lipschitz. -/
protected theorem restrict (hf : LipschitzWith K f) (s : Set α) : LipschitzWith K (s.restrict f) :=
fun x y => hf x y
/-- The composition of Lipschitz functions is Lipschitz. -/
protected theorem comp {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} (hf : LipschitzWith Kf f)
(hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f ∘ g) := fun x y =>
calc
edist (f (g x)) (f (g y)) ≤ Kf * edist (g x) (g y) := hf _ _
_ ≤ Kf * (Kg * edist x y) := mul_left_mono (hg _ _)
_ = (Kf * Kg : ℝ≥0) * edist x y := by rw [← mul_assoc, ENNReal.coe_mul]
theorem comp_lipschitzOnWith {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} {s : Set α}
(hf : LipschitzWith Kf f) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (Kf * Kg) (f ∘ g) s :=
lipschitzOnWith_iff_restrict.mpr <| hf.comp hg.to_restrict
protected theorem prod_fst : LipschitzWith 1 (@Prod.fst α β) :=
LipschitzWith.of_edist_le fun _ _ => le_max_left _ _
protected theorem prod_snd : LipschitzWith 1 (@Prod.snd α β) :=
LipschitzWith.of_edist_le fun _ _ => le_max_right _ _
/-- If `f` and `g` are Lipschitz functions, so is the induced map `f × g` to the product type. -/
protected theorem prodMk {f : α → β} {Kf : ℝ≥0} (hf : LipschitzWith Kf f) {g : α → γ} {Kg : ℝ≥0}
(hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => (f x, g x) := by
intro x y
rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul]
exact max_le_max (hf x y) (hg x y)
@[deprecated (since := "2025-03-10")]
protected alias prod := LipschitzWith.prodMk
protected theorem prodMk_left (a : α) : LipschitzWith 1 (Prod.mk a : β → α × β) := by
simpa only [max_eq_right zero_le_one] using (LipschitzWith.const a).prodMk LipschitzWith.id
@[deprecated (since := "2025-03-10")]
protected alias prod_mk_left := LipschitzWith.prodMk_left
protected theorem prodMk_right (b : β) : LipschitzWith 1 fun a : α => (a, b) := by
| simpa only [max_eq_left zero_le_one] using LipschitzWith.id.prodMk (LipschitzWith.const b)
| Mathlib/Topology/EMetricSpace/Lipschitz.lean | 248 | 249 |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.IsPrimePow
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Data.Nat.Cast.Order.Ring
import Mathlib.Data.Nat.PrimeFin
import Mathlib.Order.Interval.Finset.Nat
/-!
# Divisor Finsets
This file defines sets of divisors of a natural number. This is particularly useful as background
for defining Dirichlet convolution.
## Main Definitions
Let `n : ℕ`. All of the following definitions are in the `Nat` namespace:
* `divisors n` is the `Finset` of natural numbers that divide `n`.
* `properDivisors n` is the `Finset` of natural numbers that divide `n`, other than `n`.
* `divisorsAntidiagonal n` is the `Finset` of pairs `(x,y)` such that `x * y = n`.
* `Perfect n` is true when `n` is positive and the sum of `properDivisors n` is `n`.
## Conventions
Since `0` has infinitely many divisors, none of the definitions in this file make sense for it.
Therefore we adopt the convention that `Nat.divisors 0`, `Nat.properDivisors 0`,
`Nat.divisorsAntidiagonal 0` and `Int.divisorsAntidiag 0` are all `∅`.
## Tags
divisors, perfect numbers
-/
open Finset
namespace Nat
variable (n : ℕ)
/-- `divisors n` is the `Finset` of divisors of `n`. By convention, we set `divisors 0 = ∅`. -/
def divisors : Finset ℕ := {d ∈ Ico 1 (n + 1) | d ∣ n}
/-- `properDivisors n` is the `Finset` of divisors of `n`, other than `n`.
By convention, we set `properDivisors 0 = ∅`. -/
def properDivisors : Finset ℕ := {d ∈ Ico 1 n | d ∣ n}
/-- Pairs of divisors of a natural number as a finset.
`n.divisorsAntidiagonal` is the finset of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`.
By convention, we set `Nat.divisorsAntidiagonal 0 = ∅`.
O(n). -/
def divisorsAntidiagonal : Finset (ℕ × ℕ) :=
(Icc 1 n).filterMap (fun x ↦ let y := n / x; if x * y = n then some (x, y) else none)
fun x₁ x₂ (x, y) hx₁ hx₂ ↦ by aesop
/-- Pairs of divisors of a natural number, as a list.
`n.divisorsAntidiagonalList` is the list of pairs `(a, b) : ℕ × ℕ` such that `a * b = n`, ordered
by increasing `a`. By convention, we set `Nat.divisorsAntidiagonalList 0 = []`.
-/
def divisorsAntidiagonalList (n : ℕ) : List (ℕ × ℕ) :=
(List.range' 1 n).filterMap
(fun x ↦ let y := n / x; if x * y = n then some (x, y) else none)
variable {n}
@[simp]
theorem filter_dvd_eq_divisors (h : n ≠ 0) : {d ∈ range n.succ | d ∣ n} = n.divisors := by
ext
simp only [divisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]
exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)
@[simp]
theorem filter_dvd_eq_properDivisors (h : n ≠ 0) : {d ∈ range n | d ∣ n} = n.properDivisors := by
ext
simp only [properDivisors, mem_filter, mem_range, mem_Ico, and_congr_left_iff, iff_and_self]
exact fun ha _ => succ_le_iff.mpr (pos_of_dvd_of_pos ha h.bot_lt)
theorem properDivisors.not_self_mem : ¬n ∈ properDivisors n := by simp [properDivisors]
@[simp]
theorem mem_properDivisors {m : ℕ} : n ∈ properDivisors m ↔ n ∣ m ∧ n < m := by
rcases eq_or_ne m 0 with (rfl | hm); · simp [properDivisors]
simp only [and_comm, ← filter_dvd_eq_properDivisors hm, mem_filter, mem_range]
theorem insert_self_properDivisors (h : n ≠ 0) : insert n (properDivisors n) = divisors n := by
rw [divisors, properDivisors, Ico_succ_right_eq_insert_Ico (one_le_iff_ne_zero.2 h),
Finset.filter_insert, if_pos (dvd_refl n)]
theorem cons_self_properDivisors (h : n ≠ 0) :
cons n (properDivisors n) properDivisors.not_self_mem = divisors n := by
rw [cons_eq_insert, insert_self_properDivisors h]
@[simp]
theorem mem_divisors {m : ℕ} : n ∈ divisors m ↔ n ∣ m ∧ m ≠ 0 := by
rcases eq_or_ne m 0 with (rfl | hm); · simp [divisors]
simp only [hm, Ne, not_false_iff, and_true, ← filter_dvd_eq_divisors hm, mem_filter,
mem_range, and_iff_right_iff_imp, Nat.lt_succ_iff]
exact le_of_dvd hm.bot_lt
theorem one_mem_divisors : 1 ∈ divisors n ↔ n ≠ 0 := by simp
theorem mem_divisors_self (n : ℕ) (h : n ≠ 0) : n ∈ n.divisors :=
mem_divisors.2 ⟨dvd_rfl, h⟩
theorem dvd_of_mem_divisors {m : ℕ} (h : n ∈ divisors m) : n ∣ m := by
cases m
· apply dvd_zero
· simp [mem_divisors.1 h]
@[simp]
theorem mem_divisorsAntidiagonal {x : ℕ × ℕ} :
x ∈ divisorsAntidiagonal n ↔ x.fst * x.snd = n ∧ n ≠ 0 := by
obtain ⟨a, b⟩ := x
simp only [divisorsAntidiagonal, mul_div_eq_iff_dvd, mem_filterMap, mem_Icc, one_le_iff_ne_zero,
Option.ite_none_right_eq_some, Option.some.injEq, Prod.ext_iff, and_left_comm, exists_eq_left]
constructor
· rintro ⟨han, ⟨ha, han'⟩, rfl⟩
simp [Nat.mul_div_eq_iff_dvd, han]
omega
· rintro ⟨rfl, hab⟩
rw [mul_ne_zero_iff] at hab
simpa [hab.1, hab.2] using Nat.le_mul_of_pos_right _ hab.2.bot_lt
@[simp] lemma divisorsAntidiagonalList_zero : divisorsAntidiagonalList 0 = [] := rfl
@[simp] lemma divisorsAntidiagonalList_one : divisorsAntidiagonalList 1 = [(1, 1)] := rfl
@[simp]
lemma toFinset_divisorsAntidiagonalList {n : ℕ} :
n.divisorsAntidiagonalList.toFinset = n.divisorsAntidiagonal := by
rw [divisorsAntidiagonalList, divisorsAntidiagonal, List.toFinset_filterMap (f_inj := by aesop),
List.toFinset_range'_1_1]
lemma sorted_divisorsAntidiagonalList_fst {n : ℕ} :
n.divisorsAntidiagonalList.Sorted (·.fst < ·.fst) := by
refine (List.sorted_lt_range' _ _ Nat.one_ne_zero).filterMap fun a b c d h h' ha => ?_
rw [Option.ite_none_right_eq_some, Option.some.injEq] at h h'
simpa [← h.right, ← h'.right]
lemma sorted_divisorsAntidiagonalList_snd {n : ℕ} :
n.divisorsAntidiagonalList.Sorted (·.snd > ·.snd) := by
obtain rfl | hn := eq_or_ne n 0
· simp
refine (List.sorted_lt_range' _ _ Nat.one_ne_zero).filterMap ?_
simp only [Option.ite_none_right_eq_some, Option.some.injEq, gt_iff_lt, and_imp, Prod.forall,
Prod.mk.injEq]
rintro a b _ _ _ _ ha rfl rfl hb rfl rfl hab
rwa [Nat.div_lt_div_left hn ⟨_, hb.symm⟩ ⟨_, ha.symm⟩]
lemma nodup_divisorsAntidiagonalList {n : ℕ} : n.divisorsAntidiagonalList.Nodup :=
have : IsIrrefl (ℕ × ℕ) (·.fst < ·.fst) := ⟨by simp⟩
sorted_divisorsAntidiagonalList_fst.nodup
/-- The `Finset` and `List` versions agree by definition. -/
@[simp]
theorem val_divisorsAntidiagonal (n : ℕ) :
(divisorsAntidiagonal n).val = divisorsAntidiagonalList n :=
rfl
@[simp]
lemma mem_divisorsAntidiagonalList {n : ℕ} {a : ℕ × ℕ} :
a ∈ n.divisorsAntidiagonalList ↔ a.1 * a.2 = n ∧ n ≠ 0 := by
rw [← List.mem_toFinset, toFinset_divisorsAntidiagonalList, mem_divisorsAntidiagonal]
@[simp high]
lemma swap_mem_divisorsAntidiagonalList {a : ℕ × ℕ} :
a.swap ∈ n.divisorsAntidiagonalList ↔ a ∈ n.divisorsAntidiagonalList := by simp [mul_comm]
lemma reverse_divisorsAntidiagonalList (n : ℕ) :
n.divisorsAntidiagonalList.reverse = n.divisorsAntidiagonalList.map .swap := by
have : IsAsymm (ℕ × ℕ) (·.snd < ·.snd) := ⟨fun _ _ ↦ lt_asymm⟩
refine List.eq_of_perm_of_sorted ?_ sorted_divisorsAntidiagonalList_snd.reverse <|
sorted_divisorsAntidiagonalList_fst.map _ fun _ _ ↦ id
simp [List.reverse_perm', List.perm_ext_iff_of_nodup nodup_divisorsAntidiagonalList
(nodup_divisorsAntidiagonalList.map Prod.swap_injective), mul_comm]
lemma ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) :
p.1 ≠ 0 ∧ p.2 ≠ 0 := by
obtain ⟨hp₁, hp₂⟩ := Nat.mem_divisorsAntidiagonal.mp hp
exact mul_ne_zero_iff.mp (hp₁.symm ▸ hp₂)
lemma left_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) :
p.1 ≠ 0 :=
(ne_zero_of_mem_divisorsAntidiagonal hp).1
lemma right_ne_zero_of_mem_divisorsAntidiagonal {p : ℕ × ℕ} (hp : p ∈ n.divisorsAntidiagonal) :
p.2 ≠ 0 :=
(ne_zero_of_mem_divisorsAntidiagonal hp).2
theorem divisor_le {m : ℕ} : n ∈ divisors m → n ≤ m := by
rcases m with - | m
· simp
· simp only [mem_divisors, Nat.succ_ne_zero m, and_true, Ne, not_false_iff]
exact Nat.le_of_dvd (Nat.succ_pos m)
theorem divisors_subset_of_dvd {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) : divisors m ⊆ divisors n :=
Finset.subset_iff.2 fun _x hx => Nat.mem_divisors.mpr ⟨(Nat.mem_divisors.mp hx).1.trans h, hzero⟩
theorem card_divisors_le_self (n : ℕ) : #n.divisors ≤ n := calc
_ ≤ #(Ico 1 (n + 1)) := by
apply card_le_card
simp only [divisors, filter_subset]
_ = n := by rw [card_Ico, add_tsub_cancel_right]
theorem divisors_subset_properDivisors {m : ℕ} (hzero : n ≠ 0) (h : m ∣ n) (hdiff : m ≠ n) :
divisors m ⊆ properDivisors n := by
apply Finset.subset_iff.2
intro x hx
exact
Nat.mem_properDivisors.2
⟨(Nat.mem_divisors.1 hx).1.trans h,
lt_of_le_of_lt (divisor_le hx)
(lt_of_le_of_ne (divisor_le (Nat.mem_divisors.2 ⟨h, hzero⟩)) hdiff)⟩
lemma divisors_filter_dvd_of_dvd {n m : ℕ} (hn : n ≠ 0) (hm : m ∣ n) :
{d ∈ n.divisors | d ∣ m} = m.divisors := by
ext k
simp_rw [mem_filter, mem_divisors]
exact ⟨fun ⟨_, hkm⟩ ↦ ⟨hkm, ne_zero_of_dvd_ne_zero hn hm⟩, fun ⟨hk, _⟩ ↦ ⟨⟨hk.trans hm, hn⟩, hk⟩⟩
@[simp]
theorem divisors_zero : divisors 0 = ∅ := by
ext
simp
@[simp]
theorem properDivisors_zero : properDivisors 0 = ∅ := by
ext
simp
@[simp]
lemma nonempty_divisors : (divisors n).Nonempty ↔ n ≠ 0 :=
⟨fun ⟨m, hm⟩ hn ↦ by simp [hn] at hm, fun hn ↦ ⟨1, one_mem_divisors.2 hn⟩⟩
@[simp]
lemma divisors_eq_empty : divisors n = ∅ ↔ n = 0 :=
not_nonempty_iff_eq_empty.symm.trans nonempty_divisors.not_left
theorem properDivisors_subset_divisors : properDivisors n ⊆ divisors n :=
filter_subset_filter _ <| Ico_subset_Ico_right n.le_succ
@[simp]
theorem divisors_one : divisors 1 = {1} := by
ext
simp
@[simp]
theorem properDivisors_one : properDivisors 1 = ∅ := by rw [properDivisors, Ico_self, filter_empty]
theorem pos_of_mem_divisors {m : ℕ} (h : m ∈ n.divisors) : 0 < m := by
cases m
· rw [mem_divisors, zero_dvd_iff (a := n)] at h
cases h.2 h.1
apply Nat.succ_pos
theorem pos_of_mem_properDivisors {m : ℕ} (h : m ∈ n.properDivisors) : 0 < m :=
pos_of_mem_divisors (properDivisors_subset_divisors h)
theorem one_mem_properDivisors_iff_one_lt : 1 ∈ n.properDivisors ↔ 1 < n := by
rw [mem_properDivisors, and_iff_right (one_dvd _)]
@[simp]
lemma sup_divisors_id (n : ℕ) : n.divisors.sup id = n := by
refine le_antisymm (Finset.sup_le fun _ ↦ divisor_le) ?_
rcases Decidable.eq_or_ne n 0 with rfl | hn
· apply zero_le
· exact Finset.le_sup (f := id) <| mem_divisors_self n hn
lemma one_lt_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) : 1 < n :=
lt_of_le_of_lt (pos_of_mem_properDivisors h) (mem_properDivisors.1 h).2
lemma one_lt_div_of_mem_properDivisors {m n : ℕ} (h : m ∈ n.properDivisors) :
1 < n / m := by
obtain ⟨h_dvd, h_lt⟩ := mem_properDivisors.mp h
rwa [Nat.lt_div_iff_mul_lt' h_dvd, mul_one]
/-- See also `Nat.mem_properDivisors`. -/
lemma mem_properDivisors_iff_exists {m n : ℕ} (hn : n ≠ 0) :
m ∈ n.properDivisors ↔ ∃ k > 1, n = m * k := by
refine ⟨fun h ↦ ⟨n / m, one_lt_div_of_mem_properDivisors h, ?_⟩, ?_⟩
· exact (Nat.mul_div_cancel' (mem_properDivisors.mp h).1).symm
· rintro ⟨k, hk, rfl⟩
rw [mul_ne_zero_iff] at hn
exact mem_properDivisors.mpr ⟨⟨k, rfl⟩, lt_mul_of_one_lt_right (Nat.pos_of_ne_zero hn.1) hk⟩
@[simp]
lemma nonempty_properDivisors : n.properDivisors.Nonempty ↔ 1 < n :=
⟨fun ⟨_m, hm⟩ ↦ one_lt_of_mem_properDivisors hm, fun hn ↦
⟨1, one_mem_properDivisors_iff_one_lt.2 hn⟩⟩
@[simp]
lemma properDivisors_eq_empty : n.properDivisors = ∅ ↔ n ≤ 1 := by
rw [← not_nonempty_iff_eq_empty, nonempty_properDivisors, not_lt]
@[simp]
theorem divisorsAntidiagonal_zero : divisorsAntidiagonal 0 = ∅ := by
ext
simp
@[simp]
theorem divisorsAntidiagonal_one : divisorsAntidiagonal 1 = {(1, 1)} := by
ext
simp [mul_eq_one, Prod.ext_iff]
@[simp high]
theorem swap_mem_divisorsAntidiagonal {x : ℕ × ℕ} :
x.swap ∈ divisorsAntidiagonal n ↔ x ∈ divisorsAntidiagonal n := by
rw [mem_divisorsAntidiagonal, mem_divisorsAntidiagonal, mul_comm, Prod.swap]
/-- `Nat.swap_mem_divisorsAntidiagonal` with the LHS in simp normal form. -/
@[deprecated swap_mem_divisorsAntidiagonal (since := "2025-02-17")]
theorem swap_mem_divisorsAntidiagonal_aux {x : ℕ × ℕ} :
x.snd * x.fst = n ∧ ¬n = 0 ↔ x ∈ divisorsAntidiagonal n := by
rw [mem_divisorsAntidiagonal, mul_comm]
lemma prodMk_mem_divisorsAntidiag {x y : ℕ} (hn : n ≠ 0) :
(x, y) ∈ n.divisorsAntidiagonal ↔ x * y = n := by simp [hn]
theorem fst_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) :
x.fst ∈ divisors n := by
rw [mem_divisorsAntidiagonal] at h
simp [Dvd.intro _ h.1, h.2]
theorem snd_mem_divisors_of_mem_antidiagonal {x : ℕ × ℕ} (h : x ∈ divisorsAntidiagonal n) :
x.snd ∈ divisors n := by
rw [mem_divisorsAntidiagonal] at h
simp [Dvd.intro_left _ h.1, h.2]
@[simp]
theorem map_swap_divisorsAntidiagonal :
(divisorsAntidiagonal n).map (Equiv.prodComm _ _).toEmbedding = divisorsAntidiagonal n := by
rw [← coe_inj, coe_map, Equiv.coe_toEmbedding, Equiv.coe_prodComm,
Set.image_swap_eq_preimage_swap]
ext
exact swap_mem_divisorsAntidiagonal
@[simp]
theorem image_fst_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.fst = divisors n := by
ext
simp [Dvd.dvd, @eq_comm _ n (_ * _)]
@[simp]
theorem image_snd_divisorsAntidiagonal : (divisorsAntidiagonal n).image Prod.snd = divisors n := by
rw [← map_swap_divisorsAntidiagonal, map_eq_image, image_image]
exact image_fst_divisorsAntidiagonal
theorem map_div_right_divisors :
n.divisors.map ⟨fun d => (d, n / d), fun _ _ => congr_arg Prod.fst⟩ =
n.divisorsAntidiagonal := by
ext ⟨d, nd⟩
simp only [mem_map, mem_divisorsAntidiagonal, Function.Embedding.coeFn_mk, mem_divisors,
Prod.ext_iff, exists_prop, and_left_comm, exists_eq_left]
constructor
· rintro ⟨⟨⟨k, rfl⟩, hn⟩, rfl⟩
rw [Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt]
exact ⟨rfl, hn⟩
· rintro ⟨rfl, hn⟩
exact ⟨⟨dvd_mul_right _ _, hn⟩, Nat.mul_div_cancel_left _ (left_ne_zero_of_mul hn).bot_lt⟩
theorem map_div_left_divisors :
n.divisors.map ⟨fun d => (n / d, d), fun _ _ => congr_arg Prod.snd⟩ =
n.divisorsAntidiagonal := by
apply Finset.map_injective (Equiv.prodComm _ _).toEmbedding
ext
rw [map_swap_divisorsAntidiagonal, ← map_div_right_divisors, Finset.map_map]
simp
theorem sum_divisors_eq_sum_properDivisors_add_self :
∑ i ∈ divisors n, i = (∑ i ∈ properDivisors n, i) + n := by
rcases Decidable.eq_or_ne n 0 with (rfl | hn)
· simp
· rw [← cons_self_properDivisors hn, Finset.sum_cons, add_comm]
/-- `n : ℕ` is perfect if and only the sum of the proper divisors of `n` is `n` and `n`
is positive. -/
def Perfect (n : ℕ) : Prop :=
| ∑ i ∈ properDivisors n, i = n ∧ 0 < n
theorem perfect_iff_sum_properDivisors (h : 0 < n) : Perfect n ↔ ∑ i ∈ properDivisors n, i = n :=
and_iff_left h
| Mathlib/NumberTheory/Divisors.lean | 382 | 386 |
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Basic
import Mathlib.Algebra.GroupWithZero.Basic
/-!
# Basic Translation Lemmas Between Functions Defined for Continued Fractions
## Summary
Some simple translation lemmas between the different definitions of functions defined in
`Algebra.ContinuedFractions.Basic`.
-/
namespace GenContFract
section General
/-!
### Translations Between General Access Functions
Here we give some basic translations that hold by definition between the various methods that allow
us to access the numerators and denominators of a continued fraction.
-/
variable {α : Type*} {g : GenContFract α} {n : ℕ}
theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl
theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl
theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq]
theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by
rw [terminatedAt_iff_s_none, partNum_none_iff_s_none]
theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq]
theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by
rw [terminatedAt_iff_s_none, partDen_none_iff_s_none]
| theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq]
| Mathlib/Algebra/ContinuedFractions/Translations.lean | 49 | 50 |
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Joseph Myers
-/
import Mathlib.Analysis.InnerProductSpace.Orthogonal
import Mathlib.Analysis.Normed.Group.AddTorsor
/-!
# Perpendicular bisector of a segment
We define `AffineSubspace.perpBisector p₁ p₂` to be the perpendicular bisector of the segment
`[p₁, p₂]`, as a bundled affine subspace. We also prove that a point belongs to the perpendicular
bisector if and only if it is equidistant from `p₁` and `p₂`, as well as a few linear equations that
define this subspace.
## Keywords
euclidean geometry, perpendicular, perpendicular bisector, line segment bisector, equidistant
-/
open Set
open scoped RealInnerProductSpace
variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
variable [NormedAddTorsor V P]
noncomputable section
namespace AffineSubspace
variable {c p₁ p₂ : P}
/-- Perpendicular bisector of a segment in a Euclidean affine space. -/
def perpBisector (p₁ p₂ : P) : AffineSubspace ℝ P :=
mk' (midpoint ℝ p₁ p₂) (LinearMap.ker (innerₛₗ ℝ (p₂ -ᵥ p₁)))
/-- A point `c` belongs the perpendicular bisector of `[p₁, p₂] iff `p₂ -ᵥ p₁` is orthogonal to
`c -ᵥ midpoint ℝ p₁ p₂`. -/
theorem mem_perpBisector_iff_inner_eq_zero' :
c ∈ perpBisector p₁ p₂ ↔ ⟪p₂ -ᵥ p₁, c -ᵥ midpoint ℝ p₁ p₂⟫ = 0 :=
Iff.rfl
/-- A point `c` belongs the perpendicular bisector of `[p₁, p₂] iff `c -ᵥ midpoint ℝ p₁ p₂` is
orthogonal to `p₂ -ᵥ p₁`. -/
theorem mem_perpBisector_iff_inner_eq_zero :
c ∈ perpBisector p₁ p₂ ↔ ⟪c -ᵥ midpoint ℝ p₁ p₂, p₂ -ᵥ p₁⟫ = 0 :=
inner_eq_zero_symm
theorem mem_perpBisector_iff_inner_pointReflection_vsub_eq_zero :
c ∈ perpBisector p₁ p₂ ↔ ⟪Equiv.pointReflection c p₁ -ᵥ p₂, p₂ -ᵥ p₁⟫ = 0 := by
rw [mem_perpBisector_iff_inner_eq_zero, Equiv.pointReflection_apply,
vsub_midpoint, invOf_eq_inv, ← smul_add, real_inner_smul_left, vadd_vsub_assoc]
simp
theorem mem_perpBisector_pointReflection_iff_inner_eq_zero :
c ∈ perpBisector p₁ (Equiv.pointReflection p₂ p₁) ↔ ⟪c -ᵥ p₂, p₁ -ᵥ p₂⟫ = 0 := by
rw [mem_perpBisector_iff_inner_eq_zero, midpoint_pointReflection_right,
Equiv.pointReflection_apply, vadd_vsub_assoc, inner_add_right, add_self_eq_zero,
← neg_eq_zero, ← inner_neg_right, neg_vsub_eq_vsub_rev]
theorem midpoint_mem_perpBisector (p₁ p₂ : P) :
midpoint ℝ p₁ p₂ ∈ perpBisector p₁ p₂ := by
simp [mem_perpBisector_iff_inner_eq_zero]
theorem perpBisector_nonempty : (perpBisector p₁ p₂ : Set P).Nonempty :=
⟨_, midpoint_mem_perpBisector _ _⟩
@[simp]
theorem direction_perpBisector (p₁ p₂ : P) :
(perpBisector p₁ p₂).direction = (ℝ ∙ (p₂ -ᵥ p₁))ᗮ := by
rw [perpBisector, direction_mk']
ext x
exact Submodule.mem_orthogonal_singleton_iff_inner_right.symm
theorem mem_perpBisector_iff_inner_eq_inner :
c ∈ perpBisector p₁ p₂ ↔ ⟪c -ᵥ p₁, p₂ -ᵥ p₁⟫ = ⟪c -ᵥ p₂, p₁ -ᵥ p₂⟫ := by
rw [Iff.comm, mem_perpBisector_iff_inner_eq_zero, ← add_neg_eq_zero, ← inner_neg_right,
neg_vsub_eq_vsub_rev, ← inner_add_left, vsub_midpoint, invOf_eq_inv, ← smul_add,
real_inner_smul_left]; simp
theorem mem_perpBisector_iff_inner_eq :
c ∈ perpBisector p₁ p₂ ↔ ⟪c -ᵥ p₁, p₂ -ᵥ p₁⟫ = (dist p₁ p₂) ^ 2 / 2 := by
rw [mem_perpBisector_iff_inner_eq_zero, ← vsub_sub_vsub_cancel_right _ _ p₁, inner_sub_left,
sub_eq_zero, midpoint_vsub_left, invOf_eq_inv, real_inner_smul_left, real_inner_self_eq_norm_sq,
dist_eq_norm_vsub' V, div_eq_inv_mul]
theorem mem_perpBisector_iff_dist_eq : c ∈ perpBisector p₁ p₂ ↔ dist c p₁ = dist c p₂ := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← real_inner_add_sub_eq_zero_iff,
vsub_sub_vsub_cancel_left, inner_add_left, add_eq_zero_iff_eq_neg, ← inner_neg_right,
neg_vsub_eq_vsub_rev, mem_perpBisector_iff_inner_eq_inner]
theorem mem_perpBisector_iff_dist_eq' : c ∈ perpBisector p₁ p₂ ↔ dist p₁ c = dist p₂ c := by
simp only [mem_perpBisector_iff_dist_eq, dist_comm]
theorem perpBisector_comm (p₁ p₂ : P) : perpBisector p₁ p₂ = perpBisector p₂ p₁ := by
ext c; simp only [mem_perpBisector_iff_dist_eq, eq_comm]
@[simp] theorem right_mem_perpBisector : p₂ ∈ perpBisector p₁ p₂ ↔ p₁ = p₂ := by
| simpa [mem_perpBisector_iff_inner_eq_inner] using eq_comm
| Mathlib/Geometry/Euclidean/PerpBisector.lean | 100 | 101 |
/-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Polynomial.Degree.Support
import Mathlib.Data.ENat.Basic
/-!
# Trailing degree of univariate polynomials
## Main definitions
* `trailingDegree p`: the multiplicity of `X` in the polynomial `p`
* `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers
* `trailingCoeff`: the coefficient at index `natTrailingDegree p`
Converts most results about `degree`, `natDegree` and `leadingCoeff` to results about the bottom
end of a polynomial
-/
noncomputable section
open Function Polynomial Finsupp Finset
open scoped Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest
`X`-exponent in `p`.
`trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears
in `p`, otherwise
`trailingDegree 0 = ⊤`. -/
def trailingDegree (p : R[X]) : ℕ∞ :=
p.support.min
theorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q :=
InvImage.wf trailingDegree wellFounded_lt
/-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining
`natTrailingDegree ⊤ = 0`. -/
def natTrailingDegree (p : R[X]) : ℕ :=
ENat.toNat (trailingDegree p)
/-- `trailingCoeff p` gives the coefficient of the smallest power of `X` in `p`. -/
def trailingCoeff (p : R[X]) : R :=
coeff p (natTrailingDegree p)
/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/
def TrailingMonic (p : R[X]) :=
trailingCoeff p = (1 : R)
theorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 :=
Iff.rfl
instance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) :=
inferInstanceAs <| Decidable (trailingCoeff p = (1 : R))
@[simp]
theorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 :=
hp
@[simp]
theorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ :=
rfl
@[simp]
theorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩
theorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) :
trailingDegree p = (natTrailingDegree p : ℕ∞) :=
.symm <| ENat.coe_toNat <| mt trailingDegree_eq_top.1 hp
theorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [trailingDegree_eq_natTrailingDegree hp, Nat.cast_inj]
theorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : n ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [natTrailingDegree, ENat.toNat_eq_iff hn]
theorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ}
(h : trailingDegree p = n) : natTrailingDegree p = n := by
simp [natTrailingDegree, h]
@[simp]
theorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p :=
ENat.coe_toNat_le_self _
theorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]}
(h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by
unfold natTrailingDegree
rw [h]
theorem trailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : trailingDegree p ≤ n :=
min_le (mem_support_iff.2 h)
theorem natTrailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : natTrailingDegree p ≤ n :=
ENat.toNat_le_of_le_coe <| trailingDegree_le_of_ne_zero h
@[simp] lemma coeff_natTrailingDegree_eq_zero : coeff p p.natTrailingDegree = 0 ↔ p = 0 := by
constructor
· rintro h
by_contra hp
obtain ⟨n, hpn, hn⟩ := by simpa using min_mem_image_coe <| support_nonempty.2 hp
obtain rfl := (trailingDegree_eq_iff_natTrailingDegree_eq hp).1 hn.symm
exact hpn h
· rintro rfl
simp
lemma coeff_natTrailingDegree_ne_zero : coeff p p.natTrailingDegree ≠ 0 ↔ p ≠ 0 :=
coeff_natTrailingDegree_eq_zero.not
@[simp]
lemma trailingDegree_eq_zero : trailingDegree p = 0 ↔ coeff p 0 ≠ 0 :=
Finset.min_eq_bot.trans mem_support_iff
@[simp] lemma natTrailingDegree_eq_zero : natTrailingDegree p = 0 ↔ p = 0 ∨ coeff p 0 ≠ 0 := by
simp [natTrailingDegree, or_comm]
lemma natTrailingDegree_ne_zero : natTrailingDegree p ≠ 0 ↔ p ≠ 0 ∧ coeff p 0 = 0 :=
natTrailingDegree_eq_zero.not.trans <| by rw [not_or, not_ne_iff]
lemma trailingDegree_ne_zero : trailingDegree p ≠ 0 ↔ coeff p 0 = 0 :=
trailingDegree_eq_zero.not_left
@[simp] theorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) ≠ 0) :
trailingDegree q ≤ trailingDegree p :=
(trailingDegree_le_of_ne_zero h).trans natTrailingDegree_le_trailingDegree
theorem trailingDegree_ne_of_natTrailingDegree_ne {n : ℕ} :
p.natTrailingDegree ≠ n → trailingDegree p ≠ n :=
mt fun h => by rw [natTrailingDegree, h, ENat.toNat_coe]
theorem natTrailingDegree_le_of_trailingDegree_le {n : ℕ} {hp : p ≠ 0}
(H : (n : ℕ∞) ≤ trailingDegree p) : n ≤ natTrailingDegree p := by
rwa [trailingDegree_eq_natTrailingDegree hp, Nat.cast_le] at H
theorem natTrailingDegree_le_natTrailingDegree (hq : q ≠ 0)
(hpq : p.trailingDegree ≤ q.trailingDegree) : p.natTrailingDegree ≤ q.natTrailingDegree :=
ENat.toNat_le_toNat hpq <| by simpa
@[simp]
theorem trailingDegree_monomial (ha : a ≠ 0) : trailingDegree (monomial n a) = n := by
rw [trailingDegree, support_monomial n ha, min_singleton]
rfl
theorem natTrailingDegree_monomial (ha : a ≠ 0) : natTrailingDegree (monomial n a) = n := by
rw [natTrailingDegree, trailingDegree_monomial ha]
rfl
theorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) ≤ n :=
letI := Classical.decEq R
if ha : a = 0 then by simp [ha] else (natTrailingDegree_monomial ha).le
theorem le_trailingDegree_monomial : ↑n ≤ trailingDegree (monomial n a) :=
letI := Classical.decEq R
if ha : a = 0 then by simp [ha] else (trailingDegree_monomial ha).ge
@[simp]
theorem trailingDegree_C (ha : a ≠ 0) : trailingDegree (C a) = (0 : ℕ∞) :=
trailingDegree_monomial ha
theorem le_trailingDegree_C : (0 : ℕ∞) ≤ trailingDegree (C a) :=
le_trailingDegree_monomial
theorem trailingDegree_one_le : (0 : ℕ∞) ≤ trailingDegree (1 : R[X]) := by
rw [← C_1]
exact le_trailingDegree_C
@[simp]
theorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 :=
nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le
@[simp]
theorem natTrailingDegree_one : natTrailingDegree (1 : R[X]) = 0 :=
natTrailingDegree_C 1
@[simp]
theorem natTrailingDegree_natCast (n : ℕ) : natTrailingDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natTrailingDegree_C]
@[simp]
theorem trailingDegree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : trailingDegree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, trailingDegree_monomial ha]
theorem le_trailingDegree_C_mul_X_pow (n : ℕ) (a : R) :
(n : ℕ∞) ≤ trailingDegree (C a * X ^ n) := by
rw [C_mul_X_pow_eq_monomial]
exact le_trailingDegree_monomial
theorem coeff_eq_zero_of_lt_trailingDegree (h : (n : ℕ∞) < trailingDegree p) : coeff p n = 0 :=
Classical.not_not.1 (mt trailingDegree_le_of_ne_zero (not_le_of_gt h))
theorem coeff_eq_zero_of_lt_natTrailingDegree {p : R[X]} {n : ℕ} (h : n < p.natTrailingDegree) :
p.coeff n = 0 := by
apply coeff_eq_zero_of_lt_trailingDegree
by_cases hp : p = 0
· rw [hp, trailingDegree_zero]
exact WithTop.coe_lt_top n
· rw [trailingDegree_eq_natTrailingDegree hp]
exact WithTop.coe_lt_coe.2 h
@[simp]
theorem coeff_natTrailingDegree_pred_eq_zero {p : R[X]} {hp : (0 : ℕ∞) < natTrailingDegree p} :
p.coeff (p.natTrailingDegree - 1) = 0 :=
coeff_eq_zero_of_lt_natTrailingDegree <|
Nat.sub_lt (WithTop.coe_pos.mp hp) Nat.one_pos
theorem le_trailingDegree_X_pow (n : ℕ) : (n : ℕ∞) ≤ trailingDegree (X ^ n : R[X]) := by
simpa only [C_1, one_mul] using le_trailingDegree_C_mul_X_pow n (1 : R)
theorem le_trailingDegree_X : (1 : ℕ∞) ≤ trailingDegree (X : R[X]) :=
le_trailingDegree_monomial
theorem natTrailingDegree_X_le : (X : R[X]).natTrailingDegree ≤ 1 :=
natTrailingDegree_monomial_le
@[simp]
theorem trailingCoeff_eq_zero : trailingCoeff p = 0 ↔ p = 0 :=
⟨fun h =>
_root_.by_contradiction fun hp =>
mt mem_support_iff.1 (Classical.not_not.2 h)
(mem_of_min (trailingDegree_eq_natTrailingDegree hp)),
fun h => h.symm ▸ leadingCoeff_zero⟩
theorem trailingCoeff_nonzero_iff_nonzero : trailingCoeff p ≠ 0 ↔ p ≠ 0 :=
not_congr trailingCoeff_eq_zero
theorem natTrailingDegree_mem_support_of_nonzero : p ≠ 0 → natTrailingDegree p ∈ p.support :=
mem_support_iff.mpr ∘ trailingCoeff_nonzero_iff_nonzero.mpr
theorem natTrailingDegree_le_of_mem_supp (a : ℕ) : a ∈ p.support → natTrailingDegree p ≤ a :=
natTrailingDegree_le_of_ne_zero ∘ mem_support_iff.mp
theorem natTrailingDegree_eq_support_min' (h : p ≠ 0) :
natTrailingDegree p = p.support.min' (nonempty_support_iff.mpr h) := by
rw [natTrailingDegree, trailingDegree, ← Finset.coe_min', ENat.some_eq_coe, ENat.toNat_coe]
theorem le_natTrailingDegree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) :
n ≤ p.natTrailingDegree := by
rw [natTrailingDegree_eq_support_min' hp]
exact Finset.le_min' _ _ _ fun m hm => not_lt.1 fun hmn => mem_support_iff.1 hm <| hn _ hmn
theorem natTrailingDegree_le_natDegree (p : R[X]) : p.natTrailingDegree ≤ p.natDegree := by
by_cases hp : p = 0
· rw [hp, natDegree_zero, natTrailingDegree_zero]
· exact le_natDegree_of_ne_zero (mt trailingCoeff_eq_zero.mp hp)
theorem natTrailingDegree_mul_X_pow {p : R[X]} (hp : p ≠ 0) (n : ℕ) :
(p * X ^ n).natTrailingDegree = p.natTrailingDegree + n := by
apply le_antisymm
· refine natTrailingDegree_le_of_ne_zero fun h => mt trailingCoeff_eq_zero.mp hp ?_
rwa [trailingCoeff, ← coeff_mul_X_pow]
· rw [natTrailingDegree_eq_support_min' fun h => hp (mul_X_pow_eq_zero h), Finset.le_min'_iff]
intro y hy
have key : n ≤ y := by
rw [mem_support_iff, coeff_mul_X_pow'] at hy
exact by_contra fun h => hy (if_neg h)
rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy
exact (le_tsub_iff_right key).mp (natTrailingDegree_le_of_ne_zero hy)
theorem le_trailingDegree_mul : p.trailingDegree + q.trailingDegree ≤ (p * q).trailingDegree := by
refine Finset.le_min fun n hn => ?_
rw [mem_support_iff, coeff_mul] at hn
obtain ⟨⟨i, j⟩, hij, hpq⟩ := exists_ne_zero_of_sum_ne_zero hn
refine
(add_le_add (min_le (mem_support_iff.mpr (left_ne_zero_of_mul hpq)))
(min_le (mem_support_iff.mpr (right_ne_zero_of_mul hpq)))).trans_eq ?_
rwa [← WithTop.coe_add, WithTop.coe_eq_coe, ← mem_antidiagonal]
theorem le_natTrailingDegree_mul (h : p * q ≠ 0) :
p.natTrailingDegree + q.natTrailingDegree ≤ (p * q).natTrailingDegree := by
have hp : p ≠ 0 := fun hp => h (by rw [hp, zero_mul])
have hq : q ≠ 0 := fun hq => h (by rw [hq, mul_zero])
rw [← WithTop.coe_le_coe, WithTop.coe_add, ← Nat.cast_withTop (natTrailingDegree p),
← Nat.cast_withTop (natTrailingDegree q), ← Nat.cast_withTop (natTrailingDegree (p * q)),
← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq,
← trailingDegree_eq_natTrailingDegree h]
exact le_trailingDegree_mul
theorem coeff_mul_natTrailingDegree_add_natTrailingDegree : (p * q).coeff
(p.natTrailingDegree + q.natTrailingDegree) = p.trailingCoeff * q.trailingCoeff := by
rw [coeff_mul]
refine
Finset.sum_eq_single (p.natTrailingDegree, q.natTrailingDegree) ?_ fun h =>
(h (mem_antidiagonal.mpr rfl)).elim
rintro ⟨i, j⟩ h₁ h₂
rw [mem_antidiagonal] at h₁
by_cases hi : i < p.natTrailingDegree
· rw [coeff_eq_zero_of_lt_natTrailingDegree hi, zero_mul]
by_cases hj : j < q.natTrailingDegree
· rw [coeff_eq_zero_of_lt_natTrailingDegree hj, mul_zero]
rw [not_lt] at hi hj
refine (h₂ (Prod.ext_iff.mpr ?_).symm).elim
exact (add_eq_add_iff_eq_and_eq hi hj).mp h₁.symm
theorem trailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) :
(p * q).trailingDegree = p.trailingDegree + q.trailingDegree := by
have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul])
have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero])
refine le_antisymm ?_ le_trailingDegree_mul
rw [trailingDegree_eq_natTrailingDegree hp, trailingDegree_eq_natTrailingDegree hq, ←
ENat.coe_add]
apply trailingDegree_le_of_ne_zero
rwa [coeff_mul_natTrailingDegree_add_natTrailingDegree]
theorem natTrailingDegree_mul' (h : p.trailingCoeff * q.trailingCoeff ≠ 0) :
(p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree := by
have hp : p ≠ 0 := fun hp => h (by rw [hp, trailingCoeff_zero, zero_mul])
have hq : q ≠ 0 := fun hq => h (by rw [hq, trailingCoeff_zero, mul_zero])
apply natTrailingDegree_eq_of_trailingDegree_eq_some
rw [trailingDegree_mul' h, Nat.cast_withTop (natTrailingDegree p + natTrailingDegree q),
WithTop.coe_add, ← Nat.cast_withTop, ← Nat.cast_withTop,
← trailingDegree_eq_natTrailingDegree hp, ← trailingDegree_eq_natTrailingDegree hq]
theorem natTrailingDegree_mul [NoZeroDivisors R] (hp : p ≠ 0) (hq : q ≠ 0) :
(p * q).natTrailingDegree = p.natTrailingDegree + q.natTrailingDegree :=
natTrailingDegree_mul'
(mul_ne_zero (mt trailingCoeff_eq_zero.mp hp) (mt trailingCoeff_eq_zero.mp hq))
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem trailingDegree_one : trailingDegree (1 : R[X]) = (0 : ℕ∞) :=
trailingDegree_C one_ne_zero
@[simp]
theorem trailingDegree_X : trailingDegree (X : R[X]) = 1 :=
trailingDegree_monomial one_ne_zero
@[simp]
theorem natTrailingDegree_X : (X : R[X]).natTrailingDegree = 1 :=
natTrailingDegree_monomial one_ne_zero
@[simp]
lemma trailingDegree_X_pow (n : ℕ) :
(X ^ n : R[X]).trailingDegree = n := by
rw [X_pow_eq_monomial, trailingDegree_monomial one_ne_zero]
@[simp]
lemma natTrailingDegree_X_pow (n : ℕ) :
(X ^ n : R[X]).natTrailingDegree = n := by
rw [X_pow_eq_monomial, natTrailingDegree_monomial one_ne_zero]
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem trailingDegree_neg (p : R[X]) : trailingDegree (-p) = trailingDegree p := by
unfold trailingDegree
rw [support_neg]
@[simp]
theorem natTrailingDegree_neg (p : R[X]) : natTrailingDegree (-p) = natTrailingDegree p := by
simp [natTrailingDegree]
@[simp]
theorem natTrailingDegree_intCast (n : ℤ) : natTrailingDegree (n : R[X]) = 0 := by
simp only [← C_eq_intCast, natTrailingDegree_C]
end Ring
section Semiring
variable [Semiring R]
/-- The second-lowest coefficient, or 0 for constants -/
def nextCoeffUp (p : R[X]) : R :=
if p.natTrailingDegree = 0 then 0 else p.coeff (p.natTrailingDegree + 1)
@[simp] lemma nextCoeffUp_zero : nextCoeffUp (0 : R[X]) = 0 := by simp [nextCoeffUp]
@[simp]
theorem nextCoeffUp_C_eq_zero (c : R) : nextCoeffUp (C c) = 0 := by
rw [nextCoeffUp]
simp
theorem nextCoeffUp_of_constantCoeff_eq_zero (p : R[X]) (hp : coeff p 0 = 0) :
nextCoeffUp p = p.coeff (p.natTrailingDegree + 1) := by
obtain rfl | hp₀ := eq_or_ne p 0
· simp
· rw [nextCoeffUp, if_neg (natTrailingDegree_ne_zero.2 ⟨hp₀, hp⟩)]
end Semiring
section Semiring
variable [Semiring R] {p q : R[X]}
theorem coeff_natTrailingDegree_eq_zero_of_trailingDegree_lt
(h : trailingDegree p < trailingDegree q) : coeff q (natTrailingDegree p) = 0 :=
coeff_eq_zero_of_lt_trailingDegree <| natTrailingDegree_le_trailingDegree.trans_lt h
theorem ne_zero_of_trailingDegree_lt {n : ℕ∞} (h : trailingDegree p < n) : p ≠ 0 := fun h₀ =>
h.not_le (by simp [h₀])
lemma natTrailingDegree_eq_zero_of_constantCoeff_ne_zero (h : constantCoeff p ≠ 0) :
p.natTrailingDegree = 0 :=
le_antisymm (natTrailingDegree_le_of_ne_zero h) zero_le'
namespace Monic
lemma eq_X_pow_iff_natDegree_le_natTrailingDegree (h₁ : p.Monic) :
p = X ^ p.natDegree ↔ p.natDegree ≤ p.natTrailingDegree := by
refine ⟨fun h => ?_, fun h => ?_⟩
· nontriviality R
rw [h, natTrailingDegree_X_pow, ← h]
· ext n
rw [coeff_X_pow]
obtain hn | rfl | hn := lt_trichotomy n p.natDegree
· rw [if_neg hn.ne, coeff_eq_zero_of_lt_natTrailingDegree (hn.trans_le h)]
· simpa only [if_pos rfl] using h₁.leadingCoeff
· rw [if_neg hn.ne', coeff_eq_zero_of_natDegree_lt hn]
lemma eq_X_pow_iff_natTrailingDegree_eq_natDegree (h₁ : p.Monic) :
p = X ^ p.natDegree ↔ p.natTrailingDegree = p.natDegree :=
h₁.eq_X_pow_iff_natDegree_le_natTrailingDegree.trans (natTrailingDegree_le_natDegree p).ge_iff_eq
end Monic
end Semiring
end Polynomial
| Mathlib/Algebra/Polynomial/Degree/TrailingDegree.lean | 524 | 534 | |
/-
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, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland, Aaron Anderson
-/
import Mathlib.Algebra.Divisibility.Basic
import Mathlib.Algebra.Group.Units.Basic
/-!
# Divisibility and units
## Main definition
* `IsRelPrime x y`: that `x` and `y` are relatively prime, defined to mean that the only common
divisors of `x` and `y` are the units.
-/
variable {α : Type*}
namespace Units
section Monoid
variable [Monoid α] {a b : α} {u : αˣ}
/-- Elements of the unit group of a monoid represented as elements of the monoid
divide any element of the monoid. -/
theorem coe_dvd : ↑u ∣ a :=
⟨↑u⁻¹ * a, by simp⟩
/-- In a monoid, an element `a` divides an element `b` iff `a` divides all
associates of `b`. -/
theorem dvd_mul_right : a ∣ b * u ↔ a ∣ b :=
Iff.intro (fun ⟨c, eq⟩ ↦ ⟨c * ↑u⁻¹, by rw [← mul_assoc, ← eq, Units.mul_inv_cancel_right]⟩)
fun ⟨_, eq⟩ ↦ eq.symm ▸ (_root_.dvd_mul_right _ _).mul_right _
/-- In a monoid, an element `a` divides an element `b` iff all associates of `a` divide `b`. -/
theorem mul_right_dvd : a * u ∣ b ↔ a ∣ b :=
Iff.intro (fun ⟨c, eq⟩ => ⟨↑u * c, eq.trans (mul_assoc _ _ _)⟩) fun h =>
dvd_trans (Dvd.intro (↑u⁻¹) (by rw [mul_assoc, u.mul_inv, mul_one])) h
end Monoid
section CommMonoid
variable [CommMonoid α] {a b : α} {u : αˣ}
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
associates of `b`. -/
theorem dvd_mul_left : a ∣ u * b ↔ a ∣ b := by
rw [mul_comm]
apply dvd_mul_right
/-- In a commutative monoid, an element `a` divides an element `b` iff all
left associates of `a` divide `b`. -/
theorem mul_left_dvd : ↑u * a ∣ b ↔ a ∣ b := by
rw [mul_comm]
apply mul_right_dvd
end CommMonoid
end Units
namespace IsUnit
section Monoid
variable [Monoid α] {a b u : α}
/-- Units of a monoid divide any element of the monoid. -/
@[simp]
theorem dvd (hu : IsUnit u) : u ∣ a := by
rcases hu with ⟨u, rfl⟩
apply Units.coe_dvd
@[simp]
theorem dvd_mul_right (hu : IsUnit u) : a ∣ b * u ↔ a ∣ b := by
rcases hu with ⟨u, rfl⟩
apply Units.dvd_mul_right
/-- In a monoid, an element a divides an element b iff all associates of `a` divide `b`. -/
@[simp]
theorem mul_right_dvd (hu : IsUnit u) : a * u ∣ b ↔ a ∣ b := by
rcases hu with ⟨u, rfl⟩
apply Units.mul_right_dvd
theorem isPrimal (hu : IsUnit u) : IsPrimal u :=
fun _ _ _ ↦ ⟨u, 1, hu.dvd, one_dvd _, (mul_one u).symm⟩
end Monoid
section CommMonoid
variable [CommMonoid α] {a b u : α}
/-- In a commutative monoid, an element `a` divides an element `b` iff `a` divides all left
associates of `b`. -/
@[simp]
theorem dvd_mul_left (hu : IsUnit u) : a ∣ u * b ↔ a ∣ b := by
rcases hu with ⟨u, rfl⟩
apply Units.dvd_mul_left
/-- In a commutative monoid, an element `a` divides an element `b` iff all
left associates of `a` divide `b`. -/
@[simp]
theorem mul_left_dvd (hu : IsUnit u) : u * a ∣ b ↔ a ∣ b := by
rcases hu with ⟨u, rfl⟩
apply Units.mul_left_dvd
end CommMonoid
end IsUnit
section CommMonoid
| variable [CommMonoid α]
theorem isUnit_iff_dvd_one {x : α} : IsUnit x ↔ x ∣ 1 :=
| Mathlib/Algebra/Divisibility/Units.lean | 118 | 120 |
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Topology.UniformSpace.CompactConvergence
import Mathlib.Topology.UniformSpace.Equicontinuity
import Mathlib.Topology.UniformSpace.Equiv
/-!
# Ascoli Theorem
In this file, we prove the general **Arzela-Ascoli theorem**, and various related statements about
the topology of equicontinuous subsetes of `X →ᵤ[𝔖] α`, where `X` is a topological space, `𝔖` is
a family of compact subsets of `X`, and `α` is a uniform space.
## Main statements
* If `X` is a compact space, then the uniform structures of uniform convergence and pointwise
convergence coincide on equicontinuous subsets. This is the key fact that makes equicontinuity
important in functional analysis. We state various versions of it:
- as an equality of `UniformSpace`s: `Equicontinuous.comap_uniformFun_eq`
- in terms of `IsUniformInducing`: `Equicontinuous.isUniformInducing_uniformFun_iff_pi`
- in terms of `IsInducing`: `Equicontinuous.inducing_uniformFun_iff_pi`
- in terms of convergence along a filter: `Equicontinuous.tendsto_uniformFun_iff_pi`
* As a consequence, if `𝔖` is a family of compact subsets of `X`, then the uniform structures of
uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` coincide on equicontinuous
subsets. Again, we prove multiple variations:
- as an equality of `UniformSpace`s: `EquicontinuousOn.comap_uniformOnFun_eq`
- in terms of `IsUniformInducing`: `EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi'`
- in terms of `IsInducing`: `EquicontinuousOn.inducing_uniformOnFun_iff_pi'`
- in terms of convergence along a filter: `EquicontinuousOn.tendsto_uniformOnFun_iff_pi'`
* The **Arzela-Ascoli theorem** follows from the previous fact and Tykhonov's theorem.
All of its variations can be found under the `ArzelaAscoli` namespace.
## Implementation details
* The statements in this file may be a bit daunting because we prove everything for families and
embeddings instead of subspaces with the subspace topology. This is done because, in practice,
one would rarely work with `X →ᵤ[𝔖] α` directly, so we need to provide API for bringing back the
statements to various other types, such as `C(X, Y)` or `E →L[𝕜] F`. To counteract this, all
statements (as well as most proofs!) are documented quite thoroughly.
* A lot of statements assume `∀ K ∈ 𝔖, EquicontinuousOn F K` instead of the more natural
`EquicontinuousOn F (⋃₀ 𝔖)`. This is in order to keep the most generality, as the first statement
is strictly weaker.
* In Bourbaki, the usual Arzela-Ascoli compactness theorem follows from a similar total boundedness
result. Here we go directly for the compactness result, which is the most useful in practice, but
this will be an easy addition/refactor if we ever need it.
## TODO
* Prove that, on an equicontinuous family, pointwise convergence and pointwise convergence on a
dense subset coincide, and deduce metrizability criterions for equicontinuous subsets.
* Prove the total boundedness version of the theorem
* Prove the converse statement: if a subset of `X →ᵤ[𝔖] α` is compact, then it is equicontinuous
on each `K ∈ 𝔖`.
## References
* [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966]
## Tags
equicontinuity, uniform convergence, ascoli
-/
open Set Filter Uniformity Topology Function UniformConvergence
variable {ι X α : Type*} [TopologicalSpace X] [UniformSpace α] {F : ι → X → α}
/-- Let `X` be a compact topological space, `α` a uniform space, and `F : ι → (X → α)` an
equicontinuous family. Then, the uniform structures of uniform convergence and pointwise
convergence induce the same uniform structure on `ι`.
In other words, pointwise convergence and uniform convergence coincide on an equicontinuous
subset of `X → α`.
Consider using `Equicontinuous.isUniformInducing_uniformFun_iff_pi` and
`Equicontinuous.inducing_uniformFun_iff_pi` instead, to avoid rewriting instances. -/
theorem Equicontinuous.comap_uniformFun_eq [CompactSpace X] (F_eqcont : Equicontinuous F) :
(UniformFun.uniformSpace X α).comap F =
(Pi.uniformSpace _).comap F := by
-- The `≤` inequality is trivial
refine le_antisymm (UniformSpace.comap_mono UniformFun.uniformContinuous_toFun) ?_
-- A bit of rewriting to get a nice intermediate statement.
simp_rw [UniformSpace.comap, UniformSpace.le_def, uniformity_comap, Pi.uniformity,
Filter.comap_iInf, comap_comap, Function.comp_def]
refine ((UniformFun.hasBasis_uniformity X α).comap (Prod.map F F)).ge_iff.mpr ?_
-- Core of the proof: we need to show that, for any entourage `U` in `α`,
-- the set `𝐓(U) := {(i,j) : ι × ι | ∀ x : X, (F i x, F j x) ∈ U}` belongs to the filter
-- `⨅ x, comap ((i,j) ↦ (F i x, F j x)) (𝓤 α)`.
-- In other words, we have to show that it contains a finite intersection of
-- sets of the form `𝐒(V, x) := {(i,j) : ι × ι | (F i x, F j x) ∈ V}` for some
-- `x : X` and `V ∈ 𝓤 α`.
intro U hU
-- We will do an `ε/3` argument, so we start by choosing a symmetric entourage `V ∈ 𝓤 α`
-- such that `V ○ V ○ V ⊆ U`.
rcases comp_comp_symm_mem_uniformity_sets hU with ⟨V, hV, Vsymm, hVU⟩
-- Set `Ω x := {y | ∀ i, (F i x, F i y) ∈ V}`. The equicontinuity of `F` guarantees that
-- each `Ω x` is a neighborhood of `x`.
let Ω x : Set X := {y | ∀ i, (F i x, F i y) ∈ V}
-- Hence, by compactness of `X`, we can find some `A ⊆ X` finite such that the `Ω a`s for `a ∈ A`
-- still cover `X`.
rcases CompactSpace.elim_nhds_subcover Ω (fun x ↦ F_eqcont x V hV) with ⟨A, Acover⟩
-- We now claim that `⋂ a ∈ A, 𝐒(V, a) ⊆ 𝐓(U)`.
have : (⋂ a ∈ A, {ij : ι × ι | (F ij.1 a, F ij.2 a) ∈ V}) ⊆
(Prod.map F F) ⁻¹' UniformFun.gen X α U := by
-- Given `(i, j) ∈ ⋂ a ∈ A, 𝐒(V, a)` and `x : X`, we have to prove that `(F i x, F j x) ∈ U`.
rintro ⟨i, j⟩ hij x
rw [mem_iInter₂] at hij
-- We know that `x ∈ Ω a` for some `a ∈ A`, so that both `(F i x, F i a)` and `(F j a, F j x)`
-- are in `V`.
rcases mem_iUnion₂.mp (Acover.symm.subset <| mem_univ x) with ⟨a, ha, hax⟩
-- Since `(i, j) ∈ 𝐒(V, a)` we also have `(F i a, F j a) ∈ V`, and finally we get
-- `(F i x, F j x) ∈ V ○ V ○ V ⊆ U`.
exact hVU (prodMk_mem_compRel (prodMk_mem_compRel
(Vsymm.mk_mem_comm.mp (hax i)) (hij a ha)) (hax j))
-- This completes the proof.
exact mem_of_superset
(A.iInter_mem_sets.mpr fun x _ ↦ mem_iInf_of_mem x <| preimage_mem_comap hV) this
/-- Let `X` be a compact topological space, `α` a uniform space, and `F : ι → (X → α)` an
equicontinuous family. Then, the uniform structures of uniform convergence and pointwise
convergence induce the same uniform structure on `ι`.
In other words, pointwise convergence and uniform convergence coincide on an equicontinuous
subset of `X → α`.
This is a version of `Equicontinuous.comap_uniformFun_eq` stated in terms of `IsUniformInducing`
for convenuence. -/
lemma Equicontinuous.isUniformInducing_uniformFun_iff_pi [UniformSpace ι] [CompactSpace X]
(F_eqcont : Equicontinuous F) :
IsUniformInducing (UniformFun.ofFun ∘ F) ↔ IsUniformInducing F := by
rw [isUniformInducing_iff_uniformSpace, isUniformInducing_iff_uniformSpace,
← F_eqcont.comap_uniformFun_eq]
rfl
/-- Let `X` be a compact topological space, `α` a uniform space, and `F : ι → (X → α)` an
equicontinuous family. Then, the topologies of uniform convergence and pointwise convergence induce
the same topology on `ι`.
In other words, pointwise convergence and uniform convergence coincide on an equicontinuous
subset of `X → α`.
This is a consequence of `Equicontinuous.comap_uniformFun_eq`, stated in terms of `IsInducing`
for convenuence. -/
lemma Equicontinuous.inducing_uniformFun_iff_pi [TopologicalSpace ι] [CompactSpace X]
(F_eqcont : Equicontinuous F) :
IsInducing (UniformFun.ofFun ∘ F) ↔ IsInducing F := by
rw [isInducing_iff, isInducing_iff]
change (_ = (UniformFun.uniformSpace X α |>.comap F |>.toTopologicalSpace)) ↔
(_ = (Pi.uniformSpace _ |>.comap F |>.toTopologicalSpace))
rw [F_eqcont.comap_uniformFun_eq]
/-- Let `X` be a compact topological space, `α` a uniform space, `F : ι → (X → α)` an
equicontinuous family, and `ℱ` a filter on `ι`. Then, `F` tends *uniformly* to `f : X → α` along
`ℱ` iff it tends to `f` *pointwise* along `ℱ`. -/
theorem Equicontinuous.tendsto_uniformFun_iff_pi [CompactSpace X]
(F_eqcont : Equicontinuous F) (ℱ : Filter ι) (f : X → α) :
Tendsto (UniformFun.ofFun ∘ F) ℱ (𝓝 <| UniformFun.ofFun f) ↔
Tendsto F ℱ (𝓝 f) := by
-- Assume `ℱ` is non trivial.
rcases ℱ.eq_or_neBot with rfl | ℱ_ne
· simp
constructor <;> intro H
-- The forward direction is always true, the interesting part is the converse.
· exact UniformFun.uniformContinuous_toFun.continuous.tendsto _|>.comp H
-- To prove it, assume that `F` tends to `f` *pointwise* along `ℱ`.
· set S : Set (X → α) := closure (range F)
set 𝒢 : Filter S := comap (↑) (map F ℱ)
-- We would like to use `Equicontinuous.comap_uniformFun_eq`, but applying it to `F` is not
-- enough since `f` has no reason to be in the range of `F`.
-- Instead, we will apply it to the inclusion `(↑) : S → (X → α)` where `S` is the closure of
-- the range of `F` *for the product topology*.
-- We know that `S` is still equicontinuous...
have hS : S.Equicontinuous := closure' (by rwa [equicontinuous_iff_range] at F_eqcont)
continuous_id
-- ... hence, as announced, the product topology and uniform convergence topology
-- coincide on `S`.
have ind : IsInducing (UniformFun.ofFun ∘ (↑) : S → X →ᵤ α) :=
hS.inducing_uniformFun_iff_pi.mpr ⟨rfl⟩
-- By construction, `f` is in `S`.
have f_mem : f ∈ S := mem_closure_of_tendsto H range_mem_map
-- To conclude, we just have to translate our hypothesis and goal as statements about
-- `S`, on which we know the two topologies at play coincide.
-- For this, we define a filter on `S` by `𝒢 := comap (↑) (map F ℱ)`, and note that
-- it satisfies `map (↑) 𝒢 = map F ℱ`. Thus, both our hypothesis and our goal
-- can be rewritten as `𝒢 ≤ 𝓝 f`, where the neighborhood filter in the RHS corresponds
-- to one of the two topologies at play on `S`. Since they coincide, we are done.
have h𝒢ℱ : map (↑) 𝒢 = map F ℱ := Filter.map_comap_of_mem
(Subtype.range_coe ▸ mem_of_superset range_mem_map subset_closure)
have H' : Tendsto id 𝒢 (𝓝 ⟨f, f_mem⟩) := by
rwa [tendsto_id', nhds_induced, ← map_le_iff_le_comap, h𝒢ℱ]
rwa [ind.tendsto_nhds_iff, comp_id, ← tendsto_map'_iff, h𝒢ℱ] at H'
/-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space,
and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the uniform
structures of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` induce the same
uniform structure on `ι`.
In particular, pointwise convergence and compact convergence coincide on an equicontinuous
subset of `X → α`.
Consider using `EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi'` and
`EquicontinuousOn.inducing_uniformOnFun_iff_pi'` instead to avoid rewriting instances,
as well as their unprimed versions in case `𝔖` covers `X`. -/
theorem EquicontinuousOn.comap_uniformOnFun_eq {𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) :
(UniformOnFun.uniformSpace X α 𝔖).comap F =
(Pi.uniformSpace _).comap ((⋃₀ 𝔖).restrict ∘ F) := by
-- Recall that the uniform structure on `X →ᵤ[𝔖] α` is the one induced by all the maps
-- `K.restrict : (X →ᵤ[𝔖] α) → (K →ᵤ α)` for `K ∈ 𝔖`. Its pullback along `F`, which is
-- the LHS of our goal, is thus the uniform structure induced by the maps
-- `K.restrict ∘ F : ι → (K →ᵤ α)` for `K ∈ 𝔖`.
have H1 : (UniformOnFun.uniformSpace X α 𝔖).comap F =
⨅ (K ∈ 𝔖), (UniformFun.uniformSpace _ _).comap (K.restrict ∘ F) := by
simp_rw [UniformOnFun.uniformSpace, UniformSpace.comap_iInf, ← UniformSpace.comap_comap,
UniformFun.ofFun, Equiv.coe_fn_mk, UniformOnFun.toFun, UniformOnFun.ofFun, Function.comp_def,
UniformFun, Equiv.coe_fn_symm_mk]
-- Now, note that a similar fact is true for the uniform structure on `X → α` induced by
-- the map `(⋃₀ 𝔖).restrict : (X → α) → ((⋃₀ 𝔖) → α)`: it is equal to the one induced by
-- all maps `K.restrict : (X → α) → (K → α)` for `K ∈ 𝔖`, which means that the RHS of our
-- goal is the uniform structure induced by the maps `K.restrict ∘ F : ι → (K → α)` for `K ∈ 𝔖`.
have H2 : (Pi.uniformSpace _).comap ((⋃₀ 𝔖).restrict ∘ F) =
⨅ (K ∈ 𝔖), (Pi.uniformSpace _).comap (K.restrict ∘ F) := by
simp_rw [UniformSpace.comap_comap, Pi.uniformSpace_comap_restrict_sUnion (fun _ ↦ α) 𝔖,
UniformSpace.comap_iInf]
-- But, for `K ∈ 𝔖` fixed, we know that the uniform structures of `K →ᵤ α` and `K → α`
-- induce, via the equicontinuous family `K.restrict ∘ F`, the same uniform structure on `ι`.
have H3 : ∀ K ∈ 𝔖, (UniformFun.uniformSpace K α).comap (K.restrict ∘ F) =
(Pi.uniformSpace _).comap (K.restrict ∘ F) := fun K hK ↦ by
have : CompactSpace K := isCompact_iff_compactSpace.mp (𝔖_compact K hK)
exact (equicontinuous_restrict_iff _ |>.mpr <| F_eqcont K hK).comap_uniformFun_eq
-- Combining these three facts completes the proof.
simp_rw [H1, H2, iInf_congr fun K ↦ iInf_congr fun hK ↦ H3 K hK]
/-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space,
and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the uniform
structures of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` induce the same
uniform structure on `ι`.
In particular, pointwise convergence and compact convergence coincide on an equicontinuous
subset of `X → α`.
This is a version of `EquicontinuousOn.comap_uniformOnFun_eq` stated in terms of `IsUniformInducing`
for convenuence. -/
lemma EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi' [UniformSpace ι]
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) :
IsUniformInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔
IsUniformInducing ((⋃₀ 𝔖).restrict ∘ F) := by
rw [isUniformInducing_iff_uniformSpace, isUniformInducing_iff_uniformSpace,
← EquicontinuousOn.comap_uniformOnFun_eq 𝔖_compact F_eqcont]
rfl
/-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, `α` a uniform space,
and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the uniform
structures of uniform convergence on `𝔖` and pointwise convergence induce the same
uniform structure on `ι`.
This is a specialization of `EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi'` to
the case where `𝔖` covers `X`. -/
lemma EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi [UniformSpace ι]
{𝔖 : Set (Set X)} (𝔖_covers : ⋃₀ 𝔖 = univ) (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) :
IsUniformInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔
IsUniformInducing F := by
rw [eq_univ_iff_forall] at 𝔖_covers
-- This obviously follows from the previous lemma, we formalize it by going through the
-- isomorphism of uniform spaces between `(⋃₀ 𝔖) → α` and `X → α`.
let φ : ((⋃₀ 𝔖) → α) ≃ᵤ (X → α) := UniformEquiv.piCongrLeft (β := fun _ ↦ α)
(Equiv.subtypeUnivEquiv 𝔖_covers)
rw [EquicontinuousOn.isUniformInducing_uniformOnFun_iff_pi' 𝔖_compact F_eqcont,
show restrict (⋃₀ 𝔖) ∘ F = φ.symm ∘ F by rfl]
exact ⟨fun H ↦ φ.isUniformInducing.comp H, fun H ↦ φ.symm.isUniformInducing.comp H⟩
/-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space,
and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the topologies
of uniform convergence on `𝔖` and pointwise convergence on `⋃₀ 𝔖` induce the same topology on `ι`.
In particular, pointwise convergence and compact convergence coincide on an equicontinuous
subset of `X → α`.
This is a consequence of `EquicontinuousOn.comap_uniformOnFun_eq` stated in terms of `IsInducing`
for convenience. -/
lemma EquicontinuousOn.inducing_uniformOnFun_iff_pi' [TopologicalSpace ι]
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) :
IsInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔
IsInducing ((⋃₀ 𝔖).restrict ∘ F) := by
rw [isInducing_iff, isInducing_iff]
change (_ = ((UniformOnFun.uniformSpace X α 𝔖).comap F).toTopologicalSpace) ↔
(_ = ((Pi.uniformSpace _).comap ((⋃₀ 𝔖).restrict ∘ F)).toTopologicalSpace)
rw [← EquicontinuousOn.comap_uniformOnFun_eq 𝔖_compact F_eqcont]
/-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, `α` a uniform space,
and `F : ι → (X → α)` a family which is equicontinuous on each `K ∈ 𝔖`. Then, the topologies
of uniform convergence on `𝔖` and pointwise convergence induce the same topology on `ι`.
This is a specialization of `EquicontinuousOn.inducing_uniformOnFun_iff_pi'` to
the case where `𝔖` covers `X`. -/
lemma EquicontinuousOn.isInducing_uniformOnFun_iff_pi [TopologicalSpace ι]
{𝔖 : Set (Set X)} (𝔖_covers : ⋃₀ 𝔖 = univ) (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) :
IsInducing (UniformOnFun.ofFun 𝔖 ∘ F) ↔
IsInducing F := by
rw [eq_univ_iff_forall] at 𝔖_covers
-- This obviously follows from the previous lemma, we formalize it by going through the
-- homeomorphism between `(⋃₀ 𝔖) → α` and `X → α`.
let φ : ((⋃₀ 𝔖) → α) ≃ₜ (X → α) := Homeomorph.piCongrLeft (Y := fun _ ↦ α)
(Equiv.subtypeUnivEquiv 𝔖_covers)
rw [EquicontinuousOn.inducing_uniformOnFun_iff_pi' 𝔖_compact F_eqcont,
show restrict (⋃₀ 𝔖) ∘ F = φ.symm ∘ F by rfl]
exact ⟨fun H ↦ φ.isInducing.comp H, fun H ↦ φ.symm.isInducing.comp H⟩
@[deprecated (since := "2024-10-28")]
alias EquicontinuousOn.inducing_uniformOnFun_iff_pi :=
EquicontinuousOn.isInducing_uniformOnFun_iff_pi
-- TODO: find a way to factor common elements of this proof and the proof of
-- `EquicontinuousOn.comap_uniformOnFun_eq`
/-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X`,
`α` a uniform space, `F : ι → (X → α)` a family equicontinuous on each `K ∈ 𝔖`, and `ℱ` a filter
on `ι`. Then, `F` tends to `f : X → α` along `ℱ` *uniformly on each `K ∈ 𝔖`* iff it tends to `f`
*pointwise on `⋃₀ 𝔖`* along `ℱ`. -/
theorem EquicontinuousOn.tendsto_uniformOnFun_iff_pi'
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (ℱ : Filter ι) (f : X → α) :
Tendsto (UniformOnFun.ofFun 𝔖 ∘ F) ℱ (𝓝 <| UniformOnFun.ofFun 𝔖 f) ↔
Tendsto ((⋃₀ 𝔖).restrict ∘ F) ℱ (𝓝 <| (⋃₀ 𝔖).restrict f) := by
-- Recall that the uniform structure on `X →ᵤ[𝔖] α` is the one induced by all the maps
-- `K.restrict : (X →ᵤ[𝔖] α) → (K →ᵤ α)` for `K ∈ 𝔖`.
-- Similarly, the uniform structure on `X → α` induced by the map
-- `(⋃₀ 𝔖).restrict : (X → α) → ((⋃₀ 𝔖) → α)` is equal to the one induced by
-- all maps `K.restrict : (X → α) → (K → α)` for `K ∈ 𝔖`
-- Thus, we just have to compare the two sides of our goal when restricted to some
-- `K ∈ 𝔖`, where we can apply `Equicontinuous.tendsto_uniformFun_iff_pi`.
rw [← Filter.tendsto_comap_iff (g := (⋃₀ 𝔖).restrict), ← nhds_induced]
simp_rw [UniformOnFun.topologicalSpace_eq, Pi.induced_restrict_sUnion 𝔖 (π := fun _ ↦ α),
_root_.nhds_iInf, nhds_induced, tendsto_iInf, tendsto_comap_iff]
congrm ∀ K (hK : K ∈ 𝔖), ?_
have : CompactSpace K := isCompact_iff_compactSpace.mp (𝔖_compact K hK)
rw [← (equicontinuous_restrict_iff _ |>.mpr <| F_eqcont K hK).tendsto_uniformFun_iff_pi]
rfl
/-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets,
`α` a uniform space, `F : ι → (X → α)` a family equicontinuous on each `K ∈ 𝔖`, and `ℱ` a filter
on `ι`. Then, `F` tends to `f : X → α` along `ℱ` *uniformly on each `K ∈ 𝔖`* iff it tends to `f`
*pointwise* along `ℱ`.
This is a specialization of `EquicontinuousOn.tendsto_uniformOnFun_iff_pi'` to the case
where `𝔖` covers `X`. -/
theorem EquicontinuousOn.tendsto_uniformOnFun_iff_pi
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (𝔖_covers : ⋃₀ 𝔖 = univ)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) (ℱ : Filter ι) (f : X → α) :
Tendsto (UniformOnFun.ofFun 𝔖 ∘ F) ℱ (𝓝 <| UniformOnFun.ofFun 𝔖 f) ↔
Tendsto F ℱ (𝓝 f) := by
rw [eq_univ_iff_forall] at 𝔖_covers
let φ : ((⋃₀ 𝔖) → α) ≃ₜ (X → α) := Homeomorph.piCongrLeft (Y := fun _ ↦ α)
(Equiv.subtypeUnivEquiv 𝔖_covers)
rw [EquicontinuousOn.tendsto_uniformOnFun_iff_pi' 𝔖_compact F_eqcont,
show restrict (⋃₀ 𝔖) ∘ F = φ.symm ∘ F by rfl, show restrict (⋃₀ 𝔖) f = φ.symm f by rfl,
φ.symm.isInducing.tendsto_nhds_iff]
/-- Let `X` be a topological space, `𝔖` a family of compact subsets of `X` and
`α` a uniform space. An equicontinuous subset of `X → α` is closed in the topology of uniform
convergence on all `K ∈ 𝔖` iff it is closed in the topology of pointwise convergence on `⋃₀ 𝔖`. -/
theorem EquicontinuousOn.isClosed_range_pi_of_uniformOnFun'
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K)
(H : IsClosed (range <| UniformOnFun.ofFun 𝔖 ∘ F)) :
IsClosed (range <| (⋃₀ 𝔖).restrict ∘ F) := by
-- Do we have no equivalent of `nontriviality`?
rcases isEmpty_or_nonempty α with _ | _
· simp [isClosed_discrete]
-- This follows from the previous lemmas and the characterization of the closure using filters.
simp_rw [isClosed_iff_clusterPt, ← Filter.map_top, ← mapClusterPt_def,
mapClusterPt_iff_ultrafilter, range_comp, Subtype.coe_injective.surjective_comp_right.forall,
← restrict_eq, ← EquicontinuousOn.tendsto_uniformOnFun_iff_pi' 𝔖_compact F_eqcont]
exact fun f ⟨u, _, hu⟩ ↦ mem_image_of_mem _ <| H.mem_of_tendsto hu <|
Eventually.of_forall mem_range_self
/-- Let `X` be a topological space, `𝔖` a covering of `X` by compact subsets, and
`α` a uniform space. An equicontinuous subset of `X → α` is closed in the topology of uniform
convergence on all `K ∈ 𝔖` iff it is closed in the topology of pointwise convergence.
This is a specialization of `EquicontinuousOn.isClosed_range_pi_of_uniformOnFun'` to the case where
`𝔖` covers `X`. -/
theorem EquicontinuousOn.isClosed_range_uniformOnFun_iff_pi
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (𝔖_covers : ⋃₀ 𝔖 = univ)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K) :
IsClosed (range <| UniformOnFun.ofFun 𝔖 ∘ F) ↔
IsClosed (range F) := by
-- This follows from the previous lemmas and the characterization of the closure using filters.
simp_rw [isClosed_iff_clusterPt, ← Filter.map_top, ← mapClusterPt_def,
mapClusterPt_iff_ultrafilter, range_comp, (UniformOnFun.ofFun 𝔖).surjective.forall,
← EquicontinuousOn.tendsto_uniformOnFun_iff_pi 𝔖_compact 𝔖_covers F_eqcont,
(UniformOnFun.ofFun 𝔖).injective.mem_set_image]
alias ⟨EquicontinuousOn.isClosed_range_pi_of_uniformOnFun, _⟩ :=
EquicontinuousOn.isClosed_range_uniformOnFun_iff_pi
/-- A version of the **Arzela-Ascoli theorem**.
Let `X` be a topological space, `𝔖` a family of compact subsets of `X`, `α` a uniform space,
and `F : ι → (X → α)`. Assume that:
* `F`, viewed as a function `ι → (X →ᵤ[𝔖] α)`, is closed and inducing
* `F` is equicontinuous on each `K ∈ 𝔖`
* For all `x ∈ ⋃₀ 𝔖`, the range of `i ↦ F i x` is contained in some fixed compact subset.
Then `ι` is compact. -/
theorem ArzelaAscoli.compactSpace_of_closed_inducing' [TopologicalSpace ι] {𝔖 : Set (Set X)}
(𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_ind : IsInducing (UniformOnFun.ofFun 𝔖 ∘ F))
(F_cl : IsClosed <| range <| UniformOnFun.ofFun 𝔖 ∘ F)
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K)
(F_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i, F i x ∈ Q) :
CompactSpace ι := by
-- By equicontinuity, we know that the topology on `ι` is also the one induced by
-- `restrict (⋃₀ 𝔖) ∘ F`.
have : IsInducing (restrict (⋃₀ 𝔖) ∘ F) := by
rwa [EquicontinuousOn.inducing_uniformOnFun_iff_pi' 𝔖_compact F_eqcont] at F_ind
-- Thus, we just have to check that the range of this map is compact.
rw [← isCompact_univ_iff, this.isCompact_iff, image_univ]
-- But then we are working in a product space, where compactness can easily be proven using
-- Tykhonov's theorem! More precisely, for each `x ∈ ⋃₀ 𝔖`, choose a compact set `Q x`
-- containing all `F i x`s.
rw [← forall_sUnion] at F_pointwiseCompact
choose! Q Q_compact F_in_Q using F_pointwiseCompact
-- Notice that, since the range of `F` is closed in `X →ᵤ[𝔖] α`, equicontinuity ensures that
-- the range of `(⋃₀ 𝔖).restrict ∘ F` is still closed in the product topology.
-- But it's contained in the product of the `Q x`s, which is compact by Tykhonov, hence
-- it is compact as well.
refine IsCompact.of_isClosed_subset (isCompact_univ_pi fun x ↦ Q_compact x x.2)
(EquicontinuousOn.isClosed_range_pi_of_uniformOnFun' 𝔖_compact F_eqcont F_cl)
(range_subset_iff.mpr fun i x _ ↦ F_in_Q x x.2 i)
/-- A version of the **Arzela-Ascoli theorem**.
Let `X, ι` be topological spaces, `𝔖` a covering of `X` by compact subsets, `α` a uniform space,
and `F : ι → (X → α)`. Assume that:
* `F`, viewed as a function `ι → (X →ᵤ[𝔖] α)`, is a closed embedding (in other words, `ι`
identifies to a closed subset of `X →ᵤ[𝔖] α` through `F`)
* `F` is equicontinuous on each `K ∈ 𝔖`
* For all `x`, the range of `i ↦ F i x` is contained in some fixed compact subset.
Then `ι` is compact. -/
theorem ArzelaAscoli.compactSpace_of_isClosedEmbedding [TopologicalSpace ι] {𝔖 : Set (Set X)}
(𝔖_compact : ∀ K ∈ 𝔖, IsCompact K) (F_clemb : IsClosedEmbedding (UniformOnFun.ofFun 𝔖 ∘ F))
(F_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn F K)
(F_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i, F i x ∈ Q) :
CompactSpace ι :=
compactSpace_of_closed_inducing' 𝔖_compact F_clemb.isInducing F_clemb.isClosed_range
F_eqcont F_pointwiseCompact
/-- A version of the **Arzela-Ascoli theorem**.
Let `X, ι` be topological spaces, `𝔖` a covering of `X` by compact subsets, `α` a T2 uniform space,
`F : ι → (X → α)`, and `s` a subset of `ι`. Assume that:
* `F`, viewed as a function `ι → (X →ᵤ[𝔖] α)`, is a closed embedding (in other words, `ι`
identifies to a closed subset of `X →ᵤ[𝔖] α` through `F`)
* `F '' s` is equicontinuous on each `K ∈ 𝔖`
* For all `x ∈ ⋃₀ 𝔖`, the image of `s` under `i ↦ F i x` is contained in some fixed compact subset.
Then `s` has compact closure in `ι`. -/
theorem ArzelaAscoli.isCompact_closure_of_isClosedEmbedding [TopologicalSpace ι] [T2Space α]
{𝔖 : Set (Set X)} (𝔖_compact : ∀ K ∈ 𝔖, IsCompact K)
(F_clemb : IsClosedEmbedding (UniformOnFun.ofFun 𝔖 ∘ F))
{s : Set ι} (s_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn (F ∘ ((↑) : s → ι)) K)
(s_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i ∈ s, F i x ∈ Q) :
IsCompact (closure s) := by
-- We apply `ArzelaAscoli.compactSpace_of_isClosedEmbedding` to the map
-- `F ∘ (↑) : closure s → (X → α)`, for which all the hypotheses are easily verified.
rw [isCompact_iff_compactSpace]
have : ∀ K ∈ 𝔖, ∀ x ∈ K, Continuous (eval x ∘ F) := fun K hK x hx ↦
UniformOnFun.uniformContinuous_eval_of_mem _ _ hx hK |>.continuous.comp F_clemb.continuous
have cls_eqcont : ∀ K ∈ 𝔖, EquicontinuousOn (F ∘ ((↑) : closure s → ι)) K :=
fun K hK ↦ (s_eqcont K hK).closure' <| show Continuous (K.restrict ∘ F) from
continuous_pi fun ⟨x, hx⟩ ↦ this K hK x hx
have cls_pointwiseCompact : ∀ K ∈ 𝔖, ∀ x ∈ K, ∃ Q, IsCompact Q ∧ ∀ i ∈ closure s, F i x ∈ Q :=
fun K hK x hx ↦ (s_pointwiseCompact K hK x hx).imp fun Q hQ ↦ ⟨hQ.1, closure_minimal hQ.2 <|
hQ.1.isClosed.preimage (this K hK x hx)⟩
exact ArzelaAscoli.compactSpace_of_isClosedEmbedding 𝔖_compact
(F_clemb.comp isClosed_closure.isClosedEmbedding_subtypeVal) cls_eqcont
fun K hK x hx ↦ (cls_pointwiseCompact K hK x hx).imp fun Q hQ ↦ ⟨hQ.1, by simpa using hQ.2⟩
/-- A version of the **Arzela-Ascoli theorem**.
|
If an equicontinuous family of continuous functions is compact in the pointwise topology, then it
is compact in the compact open topology. -/
theorem ArzelaAscoli.isCompact_of_equicontinuous
(S : Set C(X, α)) (hS1 : IsCompact (ContinuousMap.toFun '' S))
(hS2 : Equicontinuous ((↑) : S → X → α)) : IsCompact S := by
suffices h : IsInducing (Equiv.Set.image _ S DFunLike.coe_injective) by
rw [isCompact_iff_compactSpace] at hS1 ⊢
exact (Equiv.toHomeomorphOfIsInducing _ h).symm.compactSpace
rw [← IsInducing.subtypeVal.of_comp_iff, ← EquicontinuousOn.isInducing_uniformOnFun_iff_pi _ _ _]
· exact ContinuousMap.isUniformEmbedding_toUniformOnFunIsCompact.isInducing.comp .subtypeVal
| Mathlib/Topology/UniformSpace/Ascoli.lean | 491 | 501 |
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed
import Mathlib.RingTheory.PowerBasis
/-!
# A predicate on adjoining roots of polynomial
This file defines a predicate `IsAdjoinRoot S f`, which states that the ring `S` can be
constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`.
This predicate is useful when the same ring can be generated by adjoining the root of different
polynomials, and you want to vary which polynomial you're considering.
The results in this file are intended to mirror those in `RingTheory.AdjoinRoot`,
in order to provide an easier way to translate results from one to the other.
## Motivation
`AdjoinRoot` presents one construction of a ring `R[α]`. However, it is possible to obtain
rings of this form in many ways, such as `NumberField.ringOfIntegers ℚ(√-5)`,
or `Algebra.adjoin R {α, α^2}`, or `IntermediateField.adjoin R {α, 2 - α}`,
or even if we want to view `ℂ` as adjoining a root of `X^2 + 1` to `ℝ`.
## Main definitions
The two main predicates in this file are:
* `IsAdjoinRoot S f`: `S` is generated by adjoining a specified root of `f : R[X]` to `R`
* `IsAdjoinRootMonic S f`: `S` is generated by adjoining a root of the monic polynomial
`f : R[X]` to `R`
Using `IsAdjoinRoot` to map into `S`:
* `IsAdjoinRoot.map`: inclusion from `R[X]` to `S`
* `IsAdjoinRoot.root`: the specific root adjoined to `R` to give `S`
Using `IsAdjoinRoot` to map out of `S`:
* `IsAdjoinRoot.repr`: choose a non-unique representative in `R[X]`
* `IsAdjoinRoot.lift`, `IsAdjoinRoot.liftHom`: lift a morphism `R →+* T` to `S →+* T`
* `IsAdjoinRootMonic.modByMonicHom`: a unique representative in `R[X]` if `f` is monic
## Main results
* `AdjoinRoot.isAdjoinRoot` and `AdjoinRoot.isAdjoinRootMonic`:
`AdjoinRoot` satisfies the conditions on `IsAdjoinRoot`(`_monic`)
* `IsAdjoinRootMonic.powerBasis`: the `root` generates a power basis on `S` over `R`
* `IsAdjoinRoot.aequiv`: algebra isomorphism showing adjoining a root gives a unique ring
up to isomorphism
* `IsAdjoinRoot.ofEquiv`: transfer `IsAdjoinRoot` across an algebra isomorphism
* `IsAdjoinRootMonic.minpoly_eq`: the minimal polynomial of the adjoined root of `f` is equal to
`f`, if `f` is irreducible and monic, and `R` is a GCD domain
-/
open scoped Polynomial
open Polynomial
noncomputable section
universe u v
-- Porting note: this looks like something that should not be here
-- section MoveMe
--
-- end MoveMe
-- This class doesn't really make sense on a predicate
/-- `IsAdjoinRoot S f` states that the ring `S` can be constructed by adjoining a specified root
of the polynomial `f : R[X]` to `R`.
Compare `PowerBasis R S`, which does not explicitly specify which polynomial we adjoin a root of
(in particular `f` does not need to be the minimal polynomial of the root we adjoin),
and `AdjoinRoot` which constructs a new type.
This is not a typeclass because the choice of root given `S` and `f` is not unique.
-/
structure IsAdjoinRoot {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S]
(f : R[X]) : Type max u v where
map : R[X] →+* S
map_surjective : Function.Surjective map
ker_map : RingHom.ker map = Ideal.span {f}
algebraMap_eq : algebraMap R S = map.comp Polynomial.C
-- This class doesn't really make sense on a predicate
/-- `IsAdjoinRootMonic S f` states that the ring `S` can be constructed by adjoining a specified
root of the monic polynomial `f : R[X]` to `R`.
As long as `f` is monic, there is a well-defined representation of elements of `S` as polynomials
in `R[X]` of degree lower than `deg f` (see `modByMonicHom` and `coeff`). In particular,
we have `IsAdjoinRootMonic.powerBasis`.
Bundling `Monic` into this structure is very useful when working with explicit `f`s such as
`X^2 - C a * X - C b` since it saves you carrying around the proofs of monicity.
-/
-- @[nolint has_nonempty_instance] -- Porting note: This linter does not exist yet.
structure IsAdjoinRootMonic {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S]
(f : R[X]) extends IsAdjoinRoot S f where
Monic : Monic f
section Ring
variable {R : Type u} {S : Type v} [CommRing R] [Ring S] {f : R[X]} [Algebra R S]
namespace IsAdjoinRoot
/-- `(h : IsAdjoinRoot S f).root` is the root of `f` that can be adjoined to generate `S`. -/
def root (h : IsAdjoinRoot S f) : S :=
h.map X
theorem subsingleton (h : IsAdjoinRoot S f) [Subsingleton R] : Subsingleton S :=
h.map_surjective.subsingleton
theorem algebraMap_apply (h : IsAdjoinRoot S f) (x : R) :
algebraMap R S x = h.map (Polynomial.C x) := by rw [h.algebraMap_eq, RingHom.comp_apply]
theorem mem_ker_map (h : IsAdjoinRoot S f) {p} : p ∈ RingHom.ker h.map ↔ f ∣ p := by
rw [h.ker_map, Ideal.mem_span_singleton]
@[simp]
theorem map_eq_zero_iff (h : IsAdjoinRoot S f) {p} : h.map p = 0 ↔ f ∣ p := by
rw [← h.mem_ker_map, RingHom.mem_ker]
@[simp]
theorem map_X (h : IsAdjoinRoot S f) : h.map X = h.root := rfl
@[simp]
theorem map_self (h : IsAdjoinRoot S f) : h.map f = 0 := h.map_eq_zero_iff.mpr dvd_rfl
@[simp]
theorem aeval_eq (h : IsAdjoinRoot S f) (p : R[X]) : aeval h.root p = h.map p :=
Polynomial.induction_on p (fun x => by rw [aeval_C, h.algebraMap_apply])
(fun p q ihp ihq => by rw [map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by
rw [map_mul, aeval_C, map_pow, aeval_X, RingHom.map_mul, ← h.algebraMap_apply,
RingHom.map_pow, map_X]
theorem aeval_root (h : IsAdjoinRoot S f) : aeval h.root f = 0 := by rw [aeval_eq, map_self]
/-- Choose an arbitrary representative so that `h.map (h.repr x) = x`.
If `f` is monic, use `IsAdjoinRootMonic.modByMonicHom` for a unique choice of representative.
-/
def repr (h : IsAdjoinRoot S f) (x : S) : R[X] :=
(h.map_surjective x).choose
theorem map_repr (h : IsAdjoinRoot S f) (x : S) : h.map (h.repr x) = x :=
(h.map_surjective x).choose_spec
/-- `repr` preserves zero, up to multiples of `f` -/
theorem repr_zero_mem_span (h : IsAdjoinRoot S f) : h.repr 0 ∈ Ideal.span ({f} : Set R[X]) := by
rw [← h.ker_map, RingHom.mem_ker, h.map_repr]
/-- `repr` preserves addition, up to multiples of `f` -/
theorem repr_add_sub_repr_add_repr_mem_span (h : IsAdjoinRoot S f) (x y : S) :
h.repr (x + y) - (h.repr x + h.repr y) ∈ Ideal.span ({f} : Set R[X]) := by
rw [← h.ker_map, RingHom.mem_ker, map_sub, h.map_repr, map_add, h.map_repr, h.map_repr, sub_self]
/-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem`
for extensionality of the ring elements. -/
theorem ext_map (h h' : IsAdjoinRoot S f) (eq : ∀ x, h.map x = h'.map x) : h = h' := by
cases h; cases h'; congr
exact RingHom.ext eq
/-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem`
for extensionality of the ring elements. -/
@[ext]
theorem ext (h h' : IsAdjoinRoot S f) (eq : h.root = h'.root) : h = h' :=
h.ext_map h' fun x => by rw [← h.aeval_eq, ← h'.aeval_eq, eq]
section lift
variable {T : Type*} [CommRing T] {i : R →+* T} {x : T}
section
variable (hx : f.eval₂ i x = 0)
include hx
/-- Auxiliary lemma for `IsAdjoinRoot.lift` -/
theorem eval₂_repr_eq_eval₂_of_map_eq (h : IsAdjoinRoot S f) (z : S) (w : R[X])
(hzw : h.map w = z) : (h.repr z).eval₂ i x = w.eval₂ i x := by
rw [eq_comm, ← sub_eq_zero, ← h.map_repr z, ← map_sub, h.map_eq_zero_iff] at hzw
obtain ⟨y, hy⟩ := hzw
rw [← sub_eq_zero, ← eval₂_sub, hy, eval₂_mul, hx, zero_mul]
variable (i x)
-- To match `AdjoinRoot.lift`
/-- Lift a ring homomorphism `R →+* T` to `S →+* T` by specifying a root `x` of `f` in `T`,
where `S` is given by adjoining a root of `f` to `R`. -/
def lift (h : IsAdjoinRoot S f) (hx : f.eval₂ i x = 0) : S →+* T where
toFun z := (h.repr z).eval₂ i x
map_zero' := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_zero _), eval₂_zero]
map_add' z w := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z + h.repr w), eval₂_add]
rw [map_add, map_repr, map_repr]
map_one' := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_one _), eval₂_one]
map_mul' z w := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z * h.repr w), eval₂_mul]
rw [map_mul, map_repr, map_repr]
variable {i x}
@[simp]
theorem lift_map (h : IsAdjoinRoot S f) (z : R[X]) : h.lift i x hx (h.map z) = z.eval₂ i x := by
rw [lift, RingHom.coe_mk]
dsimp
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ rfl]
@[simp]
theorem lift_root (h : IsAdjoinRoot S f) : h.lift i x hx h.root = x := by
rw [← h.map_X, lift_map, eval₂_X]
@[simp]
theorem lift_algebraMap (h : IsAdjoinRoot S f) (a : R) :
h.lift i x hx (algebraMap R S a) = i a := by rw [h.algebraMap_apply, lift_map, eval₂_C]
/-- Auxiliary lemma for `apply_eq_lift` -/
theorem apply_eq_lift (h : IsAdjoinRoot S f) (g : S →+* T) (hmap : ∀ a, g (algebraMap R S a) = i a)
(hroot : g h.root = x) (a : S) : g a = h.lift i x hx a := by
rw [← h.map_repr a, Polynomial.as_sum_range_C_mul_X_pow (h.repr a)]
simp only [map_sum, map_mul, map_pow, h.map_X, hroot, ← h.algebraMap_apply, hmap, lift_root,
lift_algebraMap]
/-- Unicity of `lift`: a map that agrees on `R` and `h.root` agrees with `lift` everywhere. -/
theorem eq_lift (h : IsAdjoinRoot S f) (g : S →+* T) (hmap : ∀ a, g (algebraMap R S a) = i a)
(hroot : g h.root = x) : g = h.lift i x hx :=
RingHom.ext (h.apply_eq_lift hx g hmap hroot)
end
variable [Algebra R T] (hx' : aeval x f = 0)
variable (x) in
-- To match `AdjoinRoot.liftHom`
/-- Lift the algebra map `R → T` to `S →ₐ[R] T` by specifying a root `x` of `f` in `T`,
where `S` is given by adjoining a root of `f` to `R`. -/
def liftHom (h : IsAdjoinRoot S f) : S →ₐ[R] T :=
{ h.lift (algebraMap R T) x hx' with commutes' := fun a => h.lift_algebraMap hx' a }
@[simp]
theorem coe_liftHom (h : IsAdjoinRoot S f) :
(h.liftHom x hx' : S →+* T) = h.lift (algebraMap R T) x hx' := rfl
theorem lift_algebraMap_apply (h : IsAdjoinRoot S f) (z : S) :
h.lift (algebraMap R T) x hx' z = h.liftHom x hx' z := rfl
@[simp]
theorem liftHom_map (h : IsAdjoinRoot S f) (z : R[X]) : h.liftHom x hx' (h.map z) = aeval x z := by
rw [← lift_algebraMap_apply, lift_map, aeval_def]
@[simp]
theorem liftHom_root (h : IsAdjoinRoot S f) : h.liftHom x hx' h.root = x := by
rw [← lift_algebraMap_apply, lift_root]
/-- Unicity of `liftHom`: a map that agrees on `h.root` agrees with `liftHom` everywhere. -/
theorem eq_liftHom (h : IsAdjoinRoot S f) (g : S →ₐ[R] T) (hroot : g h.root = x) :
g = h.liftHom x hx' :=
AlgHom.ext (h.apply_eq_lift hx' g g.commutes hroot)
end lift
end IsAdjoinRoot
namespace AdjoinRoot
variable (f)
/-- `AdjoinRoot f` is indeed given by adjoining a root of `f`. -/
protected def isAdjoinRoot : IsAdjoinRoot (AdjoinRoot f) f where
map := AdjoinRoot.mk f
map_surjective := Ideal.Quotient.mk_surjective
ker_map := by
ext
rw [RingHom.mem_ker, ← @AdjoinRoot.mk_self _ _ f, AdjoinRoot.mk_eq_mk, Ideal.mem_span_singleton,
← dvd_add_left (dvd_refl f), sub_add_cancel]
algebraMap_eq := AdjoinRoot.algebraMap_eq f
/-- `AdjoinRoot f` is indeed given by adjoining a root of `f`. If `f` is monic this is more
powerful than `AdjoinRoot.isAdjoinRoot`. -/
protected def isAdjoinRootMonic (hf : Monic f) : IsAdjoinRootMonic (AdjoinRoot f) f :=
{ AdjoinRoot.isAdjoinRoot f with Monic := hf }
@[simp]
theorem isAdjoinRoot_map_eq_mk : (AdjoinRoot.isAdjoinRoot f).map = AdjoinRoot.mk f :=
rfl
@[simp]
theorem isAdjoinRootMonic_map_eq_mk (hf : f.Monic) :
(AdjoinRoot.isAdjoinRootMonic f hf).map = AdjoinRoot.mk f :=
rfl
@[simp]
theorem isAdjoinRoot_root_eq_root : (AdjoinRoot.isAdjoinRoot f).root = AdjoinRoot.root f := by
simp only [IsAdjoinRoot.root, AdjoinRoot.root, AdjoinRoot.isAdjoinRoot_map_eq_mk]
@[simp]
theorem isAdjoinRootMonic_root_eq_root (hf : Monic f) :
(AdjoinRoot.isAdjoinRootMonic f hf).root = AdjoinRoot.root f := by
simp only [IsAdjoinRoot.root, AdjoinRoot.root, AdjoinRoot.isAdjoinRootMonic_map_eq_mk]
end AdjoinRoot
namespace IsAdjoinRootMonic
open IsAdjoinRoot
theorem map_modByMonic (h : IsAdjoinRootMonic S f) (g : R[X]) : h.map (g %ₘ f) = h.map g := by
rw [← RingHom.sub_mem_ker_iff, mem_ker_map, modByMonic_eq_sub_mul_div _ h.Monic, sub_right_comm,
sub_self, zero_sub, dvd_neg]
exact ⟨_, rfl⟩
theorem modByMonic_repr_map (h : IsAdjoinRootMonic S f) (g : R[X]) :
h.repr (h.map g) %ₘ f = g %ₘ f :=
modByMonic_eq_of_dvd_sub h.Monic <| by rw [← h.mem_ker_map, RingHom.sub_mem_ker_iff, map_repr]
/-- `IsAdjoinRoot.modByMonicHom` sends the equivalence class of `f` mod `g` to `f %ₘ g`. -/
def modByMonicHom (h : IsAdjoinRootMonic S f) : S →ₗ[R] R[X] where
toFun x := h.repr x %ₘ f
map_add' x y := by
conv_lhs =>
rw [← h.map_repr x, ← h.map_repr y, ← map_add]
beta_reduce -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
rw [h.modByMonic_repr_map, add_modByMonic]
map_smul' c x := by
rw [RingHom.id_apply, ← h.map_repr x, Algebra.smul_def, h.algebraMap_apply, ← map_mul]
dsimp only -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10752): added `dsimp only`
rw [h.modByMonic_repr_map, ← smul_eq_C_mul, smul_modByMonic, h.map_repr]
@[simp]
theorem modByMonicHom_map (h : IsAdjoinRootMonic S f) (g : R[X]) :
h.modByMonicHom (h.map g) = g %ₘ f := h.modByMonic_repr_map g
@[simp]
theorem map_modByMonicHom (h : IsAdjoinRootMonic S f) (x : S) : h.map (h.modByMonicHom x) = x := by
simp [modByMonicHom, map_modByMonic, map_repr]
@[simp]
theorem modByMonicHom_root_pow (h : IsAdjoinRootMonic S f) {n : ℕ} (hdeg : n < natDegree f) :
h.modByMonicHom (h.root ^ n) = X ^ n := by
nontriviality R
rw [← h.map_X, ← map_pow, modByMonicHom_map, modByMonic_eq_self_iff h.Monic, degree_X_pow]
contrapose! hdeg
simpa [natDegree_le_iff_degree_le] using hdeg
@[simp]
theorem modByMonicHom_root (h : IsAdjoinRootMonic S f) (hdeg : 1 < natDegree f) :
h.modByMonicHom h.root = X := by simpa using modByMonicHom_root_pow h hdeg
/-- The basis on `S` generated by powers of `h.root`.
Auxiliary definition for `IsAdjoinRootMonic.powerBasis`. -/
def basis (h : IsAdjoinRootMonic S f) : Basis (Fin (natDegree f)) R S :=
Basis.ofRepr
{ toFun := fun x => (h.modByMonicHom x).toFinsupp.comapDomain _ Fin.val_injective.injOn
invFun := fun g => h.map (ofFinsupp (g.mapDomain Fin.val))
left_inv := fun x => by
cases subsingleton_or_nontrivial R
· subsingleton [h.subsingleton]
simp only
rw [Finsupp.mapDomain_comapDomain, Polynomial.eta, h.map_modByMonicHom x]
· exact Fin.val_injective
intro i hi
refine Set.mem_range.mpr ⟨⟨i, ?_⟩, rfl⟩
contrapose! hi
simp only [Polynomial.toFinsupp_apply, Classical.not_not, Finsupp.mem_support_iff, Ne,
modByMonicHom, LinearMap.coe_mk, Finset.mem_coe]
obtain rfl | hf := eq_or_ne f 1
· simp
· exact coeff_eq_zero_of_natDegree_lt <| (natDegree_modByMonic_lt _ h.Monic hf).trans_le hi
right_inv := fun g => by
nontriviality R
ext i
simp only [h.modByMonicHom_map, Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply]
rw [(Polynomial.modByMonic_eq_self_iff h.Monic).mpr, Polynomial.coeff]
· rw [Finsupp.mapDomain_apply Fin.val_injective]
rw [degree_eq_natDegree h.Monic.ne_zero, degree_lt_iff_coeff_zero]
intro m hm
rw [Polynomial.coeff]
rw [Finsupp.mapDomain_notin_range]
rw [Set.mem_range, not_exists]
rintro i rfl
exact i.prop.not_le hm
map_add' := fun x y => by
rw [map_add, toFinsupp_add, Finsupp.comapDomain_add_of_injective Fin.val_injective]
-- Porting note: the original simp proof with the same lemmas does not work
-- See https://github.com/leanprover-community/mathlib4/issues/5026
-- simp only [map_add, Finsupp.comapDomain_add_of_injective Fin.val_injective, toFinsupp_add]
map_smul' := fun c x => by
rw [map_smul, toFinsupp_smul, Finsupp.comapDomain_smul_of_injective Fin.val_injective,
RingHom.id_apply] }
-- Porting note: the original simp proof with the same lemmas does not work
-- See https://github.com/leanprover-community/mathlib4/issues/5026
-- simp only [map_smul, Finsupp.comapDomain_smul_of_injective Fin.val_injective,
-- RingHom.id_apply, toFinsupp_smul] }
@[simp]
theorem basis_apply (h : IsAdjoinRootMonic S f) (i) : h.basis i = h.root ^ (i : ℕ) :=
Basis.apply_eq_iff.mpr <|
show (h.modByMonicHom (h.toIsAdjoinRoot.root ^ (i : ℕ))).toFinsupp.comapDomain _
Fin.val_injective.injOn = Finsupp.single _ _ by
ext j
rw [Finsupp.comapDomain_apply, modByMonicHom_root_pow]
· rw [X_pow_eq_monomial, toFinsupp_monomial, Finsupp.single_apply_left Fin.val_injective]
· exact i.is_lt
theorem deg_pos [Nontrivial S] (h : IsAdjoinRootMonic S f) : 0 < natDegree f := by
rcases h.basis.index_nonempty with ⟨⟨i, hi⟩⟩
exact (Nat.zero_le _).trans_lt hi
theorem deg_ne_zero [Nontrivial S] (h : IsAdjoinRootMonic S f) : natDegree f ≠ 0 :=
h.deg_pos.ne'
/-- If `f` is monic, the powers of `h.root` form a basis. -/
@[simps! gen dim basis]
def powerBasis (h : IsAdjoinRootMonic S f) : PowerBasis R S where
gen := h.root
dim := natDegree f
basis := h.basis
basis_eq_pow := h.basis_apply
@[simp]
theorem basis_repr (h : IsAdjoinRootMonic S f) (x : S) (i : Fin (natDegree f)) :
h.basis.repr x i = (h.modByMonicHom x).coeff (i : ℕ) := by
change (h.modByMonicHom x).toFinsupp.comapDomain _ Fin.val_injective.injOn i = _
rw [Finsupp.comapDomain_apply, Polynomial.toFinsupp_apply]
theorem basis_one (h : IsAdjoinRootMonic S f) (hdeg : 1 < natDegree f) :
h.basis ⟨1, hdeg⟩ = h.root := by rw [h.basis_apply, Fin.val_mk, pow_one]
/-- `IsAdjoinRootMonic.liftPolyₗ` lifts a linear map on polynomials to a linear map on `S`. -/
@[simps!]
def liftPolyₗ {T : Type*} [AddCommGroup T] [Module R T] (h : IsAdjoinRootMonic S f)
(g : R[X] →ₗ[R] T) : S →ₗ[R] T :=
g.comp h.modByMonicHom
/-- `IsAdjoinRootMonic.coeff h x i` is the `i`th coefficient of the representative of `x : S`.
-/
def coeff (h : IsAdjoinRootMonic S f) : S →ₗ[R] ℕ → R :=
h.liftPolyₗ
{ toFun := Polynomial.coeff
map_add' := fun p q => funext (Polynomial.coeff_add p q)
map_smul' := fun c p => funext (Polynomial.coeff_smul c p) }
theorem coeff_apply_lt (h : IsAdjoinRootMonic S f) (z : S) (i : ℕ) (hi : i < natDegree f) :
h.coeff z i = h.basis.repr z ⟨i, hi⟩ := by
simp only [coeff, LinearMap.comp_apply, Finsupp.lcoeFun_apply, Finsupp.lmapDomain_apply,
LinearEquiv.coe_coe, liftPolyₗ_apply, LinearMap.coe_mk, h.basis_repr]
rfl
theorem coeff_apply_coe (h : IsAdjoinRootMonic S f) (z : S) (i : Fin (natDegree f)) :
h.coeff z i = h.basis.repr z i := h.coeff_apply_lt z i i.prop
theorem coeff_apply_le (h : IsAdjoinRootMonic S f) (z : S) (i : ℕ) (hi : natDegree f ≤ i) :
h.coeff z i = 0 := by
simp only [coeff, LinearMap.comp_apply, Finsupp.lcoeFun_apply, Finsupp.lmapDomain_apply,
LinearEquiv.coe_coe, liftPolyₗ_apply, LinearMap.coe_mk, h.basis_repr]
nontriviality R
exact
Polynomial.coeff_eq_zero_of_degree_lt
((degree_modByMonic_lt _ h.Monic).trans_le (Polynomial.degree_le_of_natDegree_le hi))
theorem coeff_apply (h : IsAdjoinRootMonic S f) (z : S) (i : ℕ) :
h.coeff z i = if hi : i < natDegree f then h.basis.repr z ⟨i, hi⟩ else 0 := by
split_ifs with hi
· exact h.coeff_apply_lt z i hi
· exact h.coeff_apply_le z i (le_of_not_lt hi)
|
theorem coeff_root_pow (h : IsAdjoinRootMonic S f) {n} (hn : n < natDegree f) :
h.coeff (h.root ^ n) = Pi.single n 1 := by
| Mathlib/RingTheory/IsAdjoinRoot.lean | 474 | 476 |
/-
Copyright (c) 2022 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Int.Log
/-!
# Real logarithm base `b`
In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We
define this as the division of the natural logarithms of the argument and the base, so that we have
a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and
`logb (-b) x = logb b x`.
We prove some basic properties of this function and its relation to `rpow`.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {b x y : ℝ}
/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to
be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/
@[pp_nodot]
noncomputable def logb (b x : ℝ) : ℝ :=
log x / log b
theorem log_div_log : log x / log b = logb b x :=
rfl
@[simp]
theorem logb_zero : logb b 0 = 0 := by simp [logb]
@[simp]
theorem logb_one : logb b 1 = 0 := by simp [logb]
theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero]
@[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply]
theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero]
@[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply]
@[simp]
lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 :=
div_self (log_pos hb).ne'
lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 :=
Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero
@[simp]
theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs]
@[simp]
theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by
rw [← logb_abs x, ← logb_abs (-x), abs_neg]
theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by
simp_rw [logb, log_mul hx hy, add_div]
theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by
simp_rw [logb, log_div hx hy, sub_div]
@[simp]
theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div]
theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div]
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
(logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by
simp_rw [inv_logb]; exact logb_mul h₁ h₂
theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
(logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by
simp_rw [inv_logb]; exact logb_div h₁ h₂
theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv]
theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv]
theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) :
logb a b * logb b c = logb a c := by
unfold logb
rw [mul_comm, div_mul_div_cancel₀ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)]
theorem div_logb {a b c : ℝ} (h₁ : c ≠ 0) (h₂ : c ≠ 1) (h₃ : c ≠ -1) :
logb a c / logb b c = logb a b :=
div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, h₂, h₃⟩
theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by
rw [logb, log_rpow hx, logb, mul_div_assoc]
theorem logb_pow (b x : ℝ) (k : ℕ) : logb b (x ^ k) = k * logb b x := by
rw [logb, logb, log_pow, mul_div_assoc]
section BPosAndNeOne
variable (b_pos : 0 < b) (b_ne_one : b ≠ 1)
include b_pos b_ne_one
private theorem log_b_ne_zero : log b ≠ 0 := by
have b_ne_zero : b ≠ 0 := by linarith
have b_ne_minus_one : b ≠ -1 := by linarith
simp [b_ne_one, b_ne_zero, b_ne_minus_one]
@[simp]
theorem logb_rpow : logb b (b ^ x) = x := by
rw [logb, div_eq_iff, log_rpow b_pos]
exact log_b_ne_zero b_pos b_ne_one
theorem rpow_logb_eq_abs (hx : x ≠ 0) : b ^ logb b x = |x| := by
apply log_injOn_pos
· simp only [Set.mem_Ioi]
apply rpow_pos_of_pos b_pos
· simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff]
rw [log_rpow b_pos, logb, log_abs]
field_simp [log_b_ne_zero b_pos b_ne_one]
@[simp]
theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by
rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
exact abs_of_pos hx
theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by
rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)]
exact abs_of_neg hx
theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x ↔ b ^ x = y := by
constructor <;> rintro rfl
· exact rpow_logb b_pos b_ne_one hy
· exact logb_rpow b_pos b_ne_one
theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ =>
⟨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one⟩
theorem logb_surjective : Surjective (logb b) := fun x => ⟨b ^ x, logb_rpow b_pos b_ne_one⟩
@[simp]
theorem range_logb : range (logb b) = univ :=
(logb_surjective b_pos b_ne_one).range_eq
theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by
intro x _
use -b ^ x
constructor
· simp only [Right.neg_neg_iff, Set.mem_Iio]
apply rpow_pos_of_pos b_pos
· rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one]
end BPosAndNeOne
section OneLtB
variable (hb : 1 < b)
include hb
private theorem b_pos : 0 < b := by linarith
-- Name has a prime added to avoid clashing with `b_ne_one` further down the file
private theorem b_ne_one' : b ≠ 1 := by linarith
@[simp]
theorem logb_le_logb (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ x ≤ y := by
rw [logb, logb, div_le_div_iff_of_pos_right (log_pos hb), log_le_log_iff h h₁]
@[gcongr]
theorem logb_le_logb_of_le (h : 0 < x) (hxy : x ≤ y) : logb b x ≤ logb b y :=
(logb_le_logb hb h (by linarith)).mpr hxy
@[gcongr]
theorem logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y := by
rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)]
exact log_lt_log hx hxy
@[simp]
theorem logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ x < y := by
rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)]
exact log_lt_log_iff hx hy
theorem logb_le_iff_le_rpow (hx : 0 < x) : logb b x ≤ y ↔ x ≤ b ^ y := by
rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx]
theorem logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y ↔ x < b ^ y := by
rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx]
theorem le_logb_iff_rpow_le (hy : 0 < y) : x ≤ logb b y ↔ b ^ x ≤ y := by
rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy]
theorem lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y ↔ b ^ x < y := by
rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy]
theorem logb_pos_iff (hx : 0 < x) : 0 < logb b x ↔ 1 < x := by
rw [← @logb_one b]
rw [logb_lt_logb_iff hb zero_lt_one hx]
theorem logb_pos (hx : 1 < x) : 0 < logb b x := by
rw [logb_pos_iff hb (lt_trans zero_lt_one hx)]
exact hx
theorem logb_neg_iff (h : 0 < x) : logb b x < 0 ↔ x < 1 := by
rw [← logb_one]
exact logb_lt_logb_iff hb h zero_lt_one
theorem logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 :=
(logb_neg_iff hb h0).2 h1
theorem logb_nonneg_iff (hx : 0 < x) : 0 ≤ logb b x ↔ 1 ≤ x := by
rw [← not_lt, logb_neg_iff hb hx, not_lt]
theorem logb_nonneg (hx : 1 ≤ x) : 0 ≤ logb b x :=
(logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx
theorem logb_nonpos_iff (hx : 0 < x) : logb b x ≤ 0 ↔ x ≤ 1 := by
rw [← not_lt, logb_pos_iff hb hx, not_lt]
theorem logb_nonpos_iff' (hx : 0 ≤ x) : logb b x ≤ 0 ↔ x ≤ 1 := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
exact logb_nonpos_iff hb hx
theorem logb_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : logb b x ≤ 0 :=
(logb_nonpos_iff' hb hx).2 h'x
theorem strictMonoOn_logb : StrictMonoOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy =>
logb_lt_logb hb hx hxy
theorem strictAntiOn_logb : StrictAntiOn (logb b) (Set.Iio 0) := by
rintro x (hx : x < 0) y (hy : y < 0) hxy
rw [← logb_abs y, ← logb_abs x]
refine logb_lt_logb hb (abs_pos.2 hy.ne) ?_
rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]
theorem logb_injOn_pos : Set.InjOn (logb b) (Set.Ioi 0) :=
(strictMonoOn_logb hb).injOn
theorem eq_one_of_pos_of_logb_eq_zero (h₁ : 0 < x) (h₂ : logb b x = 0) : x = 1 :=
logb_injOn_pos hb (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.logb_one.symm)
theorem logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x ≠ 1) : logb b x ≠ 0 :=
mt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx
theorem tendsto_logb_atTop : Tendsto (logb b) atTop atTop :=
Tendsto.atTop_div_const (log_pos hb) tendsto_log_atTop
end OneLtB
section BPosAndBLtOne
variable (b_pos : 0 < b) (b_lt_one : b < 1)
include b_lt_one
private theorem b_ne_one : b ≠ 1 := by linarith
include b_pos
@[simp]
theorem logb_le_logb_of_base_lt_one (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ y ≤ x := by
rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log_iff h₁ h]
theorem logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x := by
rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)]
exact log_lt_log hx hxy
@[simp]
theorem logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) :
logb b x < logb b y ↔ y < x := by
rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)]
exact log_lt_log_iff hy hx
theorem logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x ≤ y ↔ b ^ y ≤ x := by
rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]
theorem logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y ↔ b ^ y < x := by
rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]
theorem le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x ≤ logb b y ↔ y ≤ b ^ x := by
rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]
theorem lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y ↔ y < b ^ x := by
rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]
theorem logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x ↔ x < 1 := by
rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx]
theorem logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x := by
rw [logb_pos_iff_of_base_lt_one b_pos b_lt_one hx]
exact hx'
theorem logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 ↔ 1 < x := by
rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one]
theorem logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 :=
(logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1
theorem logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 ≤ logb b x ↔ x ≤ 1 := by
rw [← not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]
theorem logb_nonneg_of_base_lt_one (hx : 0 < x) (hx' : x ≤ 1) : 0 ≤ logb b x := by
rw [logb_nonneg_iff_of_base_lt_one b_pos b_lt_one hx]
exact hx'
theorem logb_nonpos_iff_of_base_lt_one (hx : 0 < x) : logb b x ≤ 0 ↔ 1 ≤ x := by
rw [← not_lt, logb_pos_iff_of_base_lt_one b_pos b_lt_one hx, not_lt]
theorem strictAntiOn_logb_of_base_lt_one : StrictAntiOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy =>
logb_lt_logb_of_base_lt_one b_pos b_lt_one hx hxy
theorem strictMonoOn_logb_of_base_lt_one : StrictMonoOn (logb b) (Set.Iio 0) := by
rintro x (hx : x < 0) y (hy : y < 0) hxy
rw [← logb_abs y, ← logb_abs x]
refine logb_lt_logb_of_base_lt_one b_pos b_lt_one (abs_pos.2 hy.ne) ?_
rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]
theorem logb_injOn_pos_of_base_lt_one : Set.InjOn (logb b) (Set.Ioi 0) :=
(strictAntiOn_logb_of_base_lt_one b_pos b_lt_one).injOn
theorem eq_one_of_pos_of_logb_eq_zero_of_base_lt_one (h₁ : 0 < x) (h₂ : logb b x = 0) : x = 1 :=
logb_injOn_pos_of_base_lt_one b_pos b_lt_one (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one)
(h₂.trans Real.logb_one.symm)
theorem logb_ne_zero_of_pos_of_ne_one_of_base_lt_one (hx_pos : 0 < x) (hx : x ≠ 1) : logb b x ≠ 0 :=
mt (eq_one_of_pos_of_logb_eq_zero_of_base_lt_one b_pos b_lt_one hx_pos) hx
theorem tendsto_logb_atTop_of_base_lt_one : Tendsto (logb b) atTop atBot := by
rw [tendsto_atTop_atBot]
intro e
| use 1 ⊔ b ^ e
intro a
simp only [and_imp, sup_le_iff]
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 344 | 346 |
/-
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.BigOperators.Finsupp.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Preimage
import Mathlib.Algebra.Module.Defs
import Mathlib.Data.Rat.BigOperators
/-!
# Miscellaneous definitions, lemmas, and constructions using finsupp
## Main declarations
* `Finsupp.graph`: the finset of input and output pairs with non-zero outputs.
* `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv.
* `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing.
* `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage
of its support.
* `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported
function on `α`.
* `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true
and 0 otherwise.
* `Finsupp.frange`: the image of a finitely supported function on its support.
* `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas,
so it should be divided into smaller pieces.
* Expand the list of definitions and important lemmas to the module docstring.
-/
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
namespace Finsupp
/-! ### Declarations about `graph` -/
section Graph
variable [Zero M]
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
pairs with non-zero outputs. -/
def graph (f : α →₀ M) : Finset (α × M) :=
f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩
theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by
simp_rw [graph, mem_map, mem_support_iff]
constructor
· rintro ⟨b, ha, rfl, -⟩
exact ⟨rfl, ha⟩
· rintro ⟨rfl, ha⟩
exact ⟨a, ha, rfl⟩
@[simp]
theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by
cases c
exact mk_mem_graph_iff
theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph :=
mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m :=
(mem_graph_iff.1 h).1
@[simp 1100] -- Higher priority shortcut instance for `mem_graph_iff`.
theorem not_mem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h =>
(mem_graph_iff.1 h).2.irrefl
@[simp]
theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by
classical
simp only [graph, map_eq_image, image_image, Embedding.coeFn_mk, Function.comp_def, image_id']
theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by
intro f g h
classical
have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph]
refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩
exact mk_mem_graph _ (hsup ▸ hx)
@[simp]
theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g :=
(graph_injective α M).eq_iff
@[simp]
theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph]
@[simp]
theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 :=
(graph_injective α M).eq_iff' graph_zero
end Graph
end Finsupp
/-! ### Declarations about `mapRange` -/
section MapRange
namespace Finsupp
section Equiv
variable [Zero M] [Zero N] [Zero P]
/-- `Finsupp.mapRange` as an equiv. -/
@[simps apply]
def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where
toFun := (mapRange f hf : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M)
left_inv x := by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv x := by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [Equiv.self_comp_symm]
· exact mapRange_id _
· rfl
@[simp]
theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) :=
Equiv.ext mapRange_id
theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') :
(mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂])
(by rw [Equiv.symm_trans_apply, hf₂', hf']) :
(α →₀ _) ≃ _) =
(mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') :=
Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂)
@[simp]
theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') :
((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf :=
Equiv.ext fun _ => rfl
end Equiv
section ZeroHom
variable [Zero M] [Zero N] [Zero P]
/-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism
on functions. -/
@[simps]
def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
@[simp]
theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) :=
ZeroHom.ext mapRange_id
theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) :
(mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) =
(mapRange.zeroHom f).comp (mapRange.zeroHom f₂) :=
ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
end ZeroHom
section AddMonoidHom
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N]
/-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
-- Porting note: need either `dsimp only` or to specify `hf`:
-- see also: https://github.com/leanprover-community/mathlib4/issues/12129
map_add' := mapRange_add (hf := f.map_zero) f.map_add
@[simp]
theorem mapRange.addMonoidHom_id :
mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext mapRange_id
theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) :
(mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) =
(mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) :=
AddMonoidHom.ext <|
mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
@[simp]
theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) :
(mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) :=
ZeroHom.ext fun _ => rfl
theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) :
mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum :=
(mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _
theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) :
mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) :=
map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _
/-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/
@[simps apply]
def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) :=
{ mapRange.addMonoidHom f.toAddMonoidHom with
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M)
left_inv := fun x => by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv := fun x => by
rw [← mapRange_comp _ _ _ _] <;> simp_rw [AddEquiv.self_comp_symm]
· exact mapRange_id _
· rfl }
@[simp]
theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) :=
AddEquiv.ext mapRange_id
theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) :
(mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) =
(mapRange.addEquiv f).trans (mapRange.addEquiv f₂) :=
AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp))
@[simp]
theorem mapRange.addEquiv_symm (f : M ≃+ N) :
((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm :=
AddEquiv.ext fun _ => rfl
@[simp]
theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) :
((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) =
(mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) :=
AddMonoidHom.ext fun _ => rfl
@[simp]
theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) :
↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) =
(mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) :=
Equiv.ext fun _ => rfl
end AddMonoidHom
end Finsupp
end MapRange
/-! ### Declarations about `equivCongrLeft` -/
section EquivCongrLeft
variable [Zero M]
namespace Finsupp
/-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably)
by mapping the support forwards and the function backwards. -/
def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where
support := l.support.map f.toEmbedding
toFun a := l (f.symm a)
mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl
@[simp]
theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) :
equivMapDomain f l b = l (f.symm b) :=
rfl
theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) :
equivMapDomain f.symm l a = l (f a) :=
rfl
@[simp]
theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl
theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl
theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) :
equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl
theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) :
@equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl
@[simp]
theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) :
equivMapDomain f (single a b) = single (f a) b := by
classical
ext x
simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply]
@[simp]
theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by
ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply]
@[to_additive (attr := simp)]
theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N) :
prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by
simp [prod, equivMapDomain]
/-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection:
`(α →₀ M) ≃ (β →₀ M)`.
This is the finitely-supported version of `Equiv.piCongrLeft`. -/
def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by
refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;>
simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply,
Equiv.apply_symm_apply]
@[simp]
theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l :=
rfl
@[simp]
theorem equivCongrLeft_symm (f : α ≃ β) :
(@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm :=
rfl
end Finsupp
end EquivCongrLeft
section CastFinsupp
| variable [Zero M] (f : α →₀ M)
namespace Nat
@[simp, norm_cast]
| Mathlib/Data/Finsupp/Basic.lean | 339 | 343 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Order.Bounds.Defs
import Mathlib.Order.Directed
import Mathlib.Order.BoundedOrder.Monotone
import Mathlib.Order.Interval.Set.Basic
/-!
# Upper / lower bounds
In this file we prove various lemmas about upper/lower bounds of a set:
monotonicity, behaviour under `∪`, `∩`, `insert`,
and provide formulas for `∅`, `univ`, and intervals.
-/
open Function Set
open OrderDual (toDual ofDual)
universe u v
variable {α : Type u} {γ : Type v}
section
variable [Preorder α] {s t : Set α} {a b : α}
theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a :=
Iff.rfl
theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x :=
Iff.rfl
lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl
lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl
theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x :=
Iff.rfl
theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y :=
Iff.rfl
theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le
theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top
@[simp]
theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s :=
and_iff_left <| bot_mem_lowerBounds _
@[simp]
theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s :=
and_iff_left <| top_mem_upperBounds _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x`
is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/
theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by
simp [BddAbove, upperBounds, Set.Nonempty]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x`
is not less than or equal to `y`. This version only assumes `Preorder` structure and uses
`¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/
theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y :=
@not_bddAbove_iff' αᵒᵈ _ _
/-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater
than `x`. A version for preorders is called `not_bddAbove_iff'`. -/
theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by
simp only [not_bddAbove_iff', not_le]
/-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less
than `x`. A version for preorders is called `not_bddBelow_iff'`. -/
theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} :
¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x :=
@not_bddAbove_iff αᵒᵈ _ _
@[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
@[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} :
BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl
@[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} :
BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl
theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) :=
h
theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) :=
h
theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) :=
h
theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) :=
h
/-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/
abbrev IsLeast.orderBot (h : IsLeast s a) :
OrderBot s where
bot := ⟨a, h.1⟩
bot_le := Subtype.forall.2 h.2
/-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/
abbrev IsGreatest.orderTop (h : IsGreatest s a) :
OrderTop s where
top := ⟨a, h.1⟩
le_top := Subtype.forall.2 h.2
theorem isLUB_congr (h : upperBounds s = upperBounds t) : IsLUB s a ↔ IsLUB t a := by
rw [IsLUB, IsLUB, h]
theorem isGLB_congr (h : lowerBounds s = lowerBounds t) : IsGLB s a ↔ IsGLB t a := by
rw [IsGLB, IsGLB, h]
/-!
### Monotonicity
-/
theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s :=
fun _ hb _ h => hb <| hst h
theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s :=
fun _ hb _ h => hb <| hst h
theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s :=
fun ha _ h => le_trans (ha h) hab
theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s :=
fun hb _ h => le_trans hab (hb h)
theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
a ∈ upperBounds t → b ∈ upperBounds s := fun ha =>
upperBounds_mono_set hst <| upperBounds_mono_mem hab ha
theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) :
b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb =>
lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb
/-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/
theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s :=
Nonempty.mono <| upperBounds_mono_set h
/-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/
theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s :=
Nonempty.mono <| lowerBounds_mono_set h
/-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsLUB t a :=
⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩
/-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any
set `t`, `s ⊆ t ⊆ p`. -/
theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t)
(htp : t ⊆ p) : IsGLB t a :=
hs.dual.of_subset_of_superset hp hst htp
theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a :=
hb.2 (hst ha.1)
theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b :=
hb.2 (hst ha.1)
theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b :=
IsLeast.mono hb ha <| upperBounds_mono_set hst
theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a :=
IsGreatest.mono hb ha <| lowerBounds_mono_set hst
theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) :=
fun _ hx _ hy => hy hx
theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) :=
fun _ hx _ hy => hy hx
theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) :=
hs.mono (subset_upperBounds_lowerBounds s)
theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) :=
hs.mono (subset_lowerBounds_upperBounds s)
/-!
### Conversions
-/
theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a :=
⟨h.2, fun _ hb => hb h.1⟩
theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a :=
Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩
theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a :=
h.dual.upperBounds_eq
theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a :=
h.isGLB.lowerBounds_eq
theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a :=
h.isLUB.upperBounds_eq
theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b :=
⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩
theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x :=
h.dual.lt_iff
theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by
rw [h.upperBounds_eq]
rfl
theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by
rw [h.lowerBounds_eq]
rfl
theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s :=
⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩
theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s :=
@isLUB_iff_le_iff αᵒᵈ _ _ _
/-- If `s` has a least upper bound, then it is bounded above. -/
theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s :=
⟨a, h.1⟩
/-- If `s` has a greatest lower bound, then it is bounded below. -/
theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s :=
⟨a, h.1⟩
/-- If `s` has a greatest element, then it is bounded above. -/
theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s :=
⟨a, h.2⟩
/-- If `s` has a least element, then it is bounded below. -/
theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s :=
⟨a, h.2⟩
theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty :=
⟨a, h.1⟩
theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty :=
⟨a, h.1⟩
/-!
### Union and intersection
-/
@[simp]
theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t :=
Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩)
fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht
@[simp]
theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t :=
@upperBounds_union αᵒᵈ _ s t
theorem union_upperBounds_subset_upperBounds_inter :
upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) :=
union_subset (upperBounds_mono_set inter_subset_left)
(upperBounds_mono_set inter_subset_right)
theorem union_lowerBounds_subset_lowerBounds_inter :
lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) :=
@union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t
theorem isLeast_union_iff {a : α} {s t : Set α} :
IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by
simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc]
theorem isGreatest_union_iff :
IsGreatest (s ∪ t) a ↔
IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a :=
@isLeast_union_iff αᵒᵈ _ a s t
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) :=
h.mono inter_subset_right
/-- If `s` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) :=
h.mono inter_subset_left
/-- If `t` is bounded, then so is `s ∩ t` -/
theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) :=
h.mono inter_subset_right
/-- In a directed order, the union of bounded above sets is bounded above. -/
theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove s → BddAbove t → BddAbove (s ∪ t) := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b
rw [BddAbove, upperBounds_union]
exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩
/-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/
theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} :
BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t :=
⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h =>
h.1.union h.2⟩
/-- In a codirected order, the union of bounded below sets is bounded below. -/
theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow s → BddBelow t → BddBelow (s ∪ t) :=
@BddAbove.union αᵒᵈ _ _ _ _
/-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/
theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} :
BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t :=
@bddAbove_union αᵒᵈ _ _ _ _
/-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`,
then `a ⊔ b` is the least upper bound of `s ∪ t`. -/
theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) :
IsLUB (s ∪ t) (a ⊔ b) :=
⟨fun _ h =>
h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h,
fun _ hc =>
sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩
/-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`,
then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/
theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁)
(ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) :=
hs.dual.union ht
/-- If `a` is the least element of `s` and `b` is the least element of `t`,
then `min a b` is the least element of `s ∪ t`. -/
theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a)
(hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩
/-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`,
then `max a b` is the greatest element of `s ∪ t`. -/
theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a)
(hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) :=
⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩
theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) :
IsLUB (s ∩ Ici b) a :=
⟨fun _ hx => ha.1 hx.1, fun c hc =>
have hbc : b ≤ c := hc ⟨hb, le_rfl⟩
ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩
theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) :
IsGLB (s ∩ Iic b) a :=
ha.dual.inter_Ici_of_mem hb
theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) :
BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by
rw [bddAbove_def, exists_ge_and_iff_exists]
exact Monotone.ball fun x _ => monotone_le
theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) :
BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
bddAbove_iff_exists_ge (toDual x₀)
theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) :
∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x :=
(bddAbove_iff_exists_ge x₀).mp hs
theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) :
∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y :=
(bddBelow_iff_exists_le x₀).mp hs
/-!
### Specific sets
#### Unbounded intervals
-/
theorem isLeast_Ici : IsLeast (Ici a) a :=
⟨left_mem_Ici, fun _ => id⟩
theorem isGreatest_Iic : IsGreatest (Iic a) a :=
⟨right_mem_Iic, fun _ => id⟩
theorem isLUB_Iic : IsLUB (Iic a) a :=
isGreatest_Iic.isLUB
theorem isGLB_Ici : IsGLB (Ici a) a :=
isLeast_Ici.isGLB
theorem upperBounds_Iic : upperBounds (Iic a) = Ici a :=
isLUB_Iic.upperBounds_eq
theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a :=
isGLB_Ici.lowerBounds_eq
theorem bddAbove_Iic : BddAbove (Iic a) :=
isLUB_Iic.bddAbove
theorem bddBelow_Ici : BddBelow (Ici a) :=
isGLB_Ici.bddBelow
theorem bddAbove_Iio : BddAbove (Iio a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem bddBelow_Ioi : BddBelow (Ioi a) :=
⟨a, fun _ hx => le_of_lt hx⟩
theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a :=
(isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk
theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b :=
@lub_Iio_le αᵒᵈ _ _ a hb
theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) :
j = i ∨ Iio i = Iic j := by
rcases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i | hj_lt_i
· exact Or.inl hj_eq_i
· right
exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩
theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) :
j = i ∨ Ioi i = Ici j :=
@lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj
section
variable [LinearOrder γ]
theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by
by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i
· obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt
exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩
· refine ⟨i, fun j hj => le_of_lt hj, ?_⟩
rw [mem_lowerBounds]
by_contra h
refine h_exists_lt ?_
push_neg at h
exact h
theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j :=
@exists_lub_Iio γᵒᵈ _ i
variable [DenselyOrdered γ]
theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a :=
⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_lt_imp_le_of_dense hy⟩
theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a :=
@isLUB_Iio γᵒᵈ _ _ a
theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a :=
isLUB_Iio.upperBounds_eq
theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a :=
isGLB_Ioi.lowerBounds_eq
end
/-!
#### Singleton
-/
@[simp] theorem isGreatest_singleton : IsGreatest {a} a :=
⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩
@[simp] theorem isLeast_singleton : IsLeast {a} a :=
@isGreatest_singleton αᵒᵈ _ a
@[simp] theorem isLUB_singleton : IsLUB {a} a :=
isGreatest_singleton.isLUB
@[simp] theorem isGLB_singleton : IsGLB {a} a :=
isLeast_singleton.isGLB
@[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove
@[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow
@[simp]
theorem upperBounds_singleton : upperBounds {a} = Ici a :=
isLUB_singleton.upperBounds_eq
@[simp]
theorem lowerBounds_singleton : lowerBounds {a} = Iic a :=
isGLB_singleton.lowerBounds_eq
/-!
#### Bounded intervals
-/
theorem bddAbove_Icc : BddAbove (Icc a b) :=
⟨b, fun _ => And.right⟩
theorem bddBelow_Icc : BddBelow (Icc a b) :=
⟨a, fun _ => And.left⟩
theorem bddAbove_Ico : BddAbove (Ico a b) :=
bddAbove_Icc.mono Ico_subset_Icc_self
theorem bddBelow_Ico : BddBelow (Ico a b) :=
bddBelow_Icc.mono Ico_subset_Icc_self
theorem bddAbove_Ioc : BddAbove (Ioc a b) :=
bddAbove_Icc.mono Ioc_subset_Icc_self
theorem bddBelow_Ioc : BddBelow (Ioc a b) :=
bddBelow_Icc.mono Ioc_subset_Icc_self
theorem bddAbove_Ioo : BddAbove (Ioo a b) :=
bddAbove_Icc.mono Ioo_subset_Icc_self
theorem bddBelow_Ioo : BddBelow (Ioo a b) :=
bddBelow_Icc.mono Ioo_subset_Icc_self
theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b :=
⟨right_mem_Icc.2 h, fun _ => And.right⟩
theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b :=
(isGreatest_Icc h).isLUB
theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b :=
(isLUB_Icc h).upperBounds_eq
theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a :=
⟨left_mem_Icc.2 h, fun _ => And.left⟩
theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a :=
(isLeast_Icc h).isGLB
theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a :=
(isGLB_Icc h).lowerBounds_eq
theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b :=
⟨right_mem_Ioc.2 h, fun _ => And.right⟩
theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b :=
(isGreatest_Ioc h).isLUB
theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b :=
(isLUB_Ioc h).upperBounds_eq
theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a :=
⟨left_mem_Ico.2 h, fun _ => And.left⟩
theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a :=
(isLeast_Ico h).isGLB
theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a :=
(isGLB_Ico h).lowerBounds_eq
section
variable [SemilatticeSup γ] [DenselyOrdered γ]
theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a :=
⟨fun _ hx => hx.1.le, fun x hx => by
rcases eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ | h₂
· exact h₁.symm ▸ le_sup_left
obtain ⟨y, lty, ylt⟩ := exists_between h₂
apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim
obtain ⟨u, au, ub⟩ := exists_between h
apply (hx ⟨au, ub⟩).trans ub.le⟩
theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a :=
(isGLB_Ioo hab).lowerBounds_eq
theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a :=
(isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self
theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a :=
(isGLB_Ioc hab).lowerBounds_eq
end
section
variable [SemilatticeInf γ] [DenselyOrdered γ]
theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by
simpa only [Ioo_toDual] using isGLB_Ioo hab.dual
theorem upperBounds_Ioo {a b : γ} (hab : a < b) : upperBounds (Ioo a b) = Ici b :=
(isLUB_Ioo hab).upperBounds_eq
theorem isLUB_Ico {a b : γ} (hab : a < b) : IsLUB (Ico a b) b := by
simpa only [Ioc_toDual] using isGLB_Ioc hab.dual
theorem upperBounds_Ico {a b : γ} (hab : a < b) : upperBounds (Ico a b) = Ici b :=
(isLUB_Ico hab).upperBounds_eq
end
theorem bddBelow_iff_subset_Ici : BddBelow s ↔ ∃ a, s ⊆ Ici a :=
Iff.rfl
theorem bddAbove_iff_subset_Iic : BddAbove s ↔ ∃ a, s ⊆ Iic a :=
Iff.rfl
theorem bddBelow_bddAbove_iff_subset_Icc : BddBelow s ∧ BddAbove s ↔ ∃ a b, s ⊆ Icc a b := by
simp [Ici_inter_Iic.symm, subset_inter_iff, bddBelow_iff_subset_Ici,
bddAbove_iff_subset_Iic, exists_and_left, exists_and_right]
/-!
#### Univ
-/
@[simp] theorem isGreatest_univ_iff : IsGreatest univ a ↔ IsTop a := by
simp [IsGreatest, mem_upperBounds, IsTop]
theorem isGreatest_univ [OrderTop α] : IsGreatest (univ : Set α) ⊤ :=
isGreatest_univ_iff.2 isTop_top
@[simp]
theorem OrderTop.upperBounds_univ [PartialOrder γ] [OrderTop γ] :
upperBounds (univ : Set γ) = {⊤} := by rw [isGreatest_univ.upperBounds_eq, Ici_top]
theorem isLUB_univ [OrderTop α] : IsLUB (univ : Set α) ⊤ :=
isGreatest_univ.isLUB
@[simp]
theorem OrderBot.lowerBounds_univ [PartialOrder γ] [OrderBot γ] :
lowerBounds (univ : Set γ) = {⊥} :=
@OrderTop.upperBounds_univ γᵒᵈ _ _
@[simp] theorem isLeast_univ_iff : IsLeast univ a ↔ IsBot a :=
@isGreatest_univ_iff αᵒᵈ _ _
theorem isLeast_univ [OrderBot α] : IsLeast (univ : Set α) ⊥ :=
@isGreatest_univ αᵒᵈ _ _
theorem isGLB_univ [OrderBot α] : IsGLB (univ : Set α) ⊥ :=
isLeast_univ.isGLB
@[simp]
theorem NoTopOrder.upperBounds_univ [NoTopOrder α] : upperBounds (univ : Set α) = ∅ :=
eq_empty_of_subset_empty fun b hb =>
not_isTop b fun x => hb (mem_univ x)
@[deprecated (since := "2025-04-18")]
alias NoMaxOrder.upperBounds_univ := NoTopOrder.upperBounds_univ
@[simp]
theorem NoBotOrder.lowerBounds_univ [NoBotOrder α] : lowerBounds (univ : Set α) = ∅ :=
@NoTopOrder.upperBounds_univ αᵒᵈ _ _
@[deprecated (since := "2025-04-18")]
alias NoMinOrder.lowerBounds_univ := NoBotOrder.lowerBounds_univ
@[simp]
theorem not_bddAbove_univ [NoTopOrder α] : ¬BddAbove (univ : Set α) := by simp [BddAbove]
@[simp]
theorem not_bddBelow_univ [NoBotOrder α] : ¬BddBelow (univ : Set α) :=
@not_bddAbove_univ αᵒᵈ _ _
/-!
#### Empty set
-/
@[simp]
theorem upperBounds_empty : upperBounds (∅ : Set α) = univ := by
simp only [upperBounds, eq_univ_iff_forall, mem_setOf_eq, forall_mem_empty, forall_true_iff]
@[simp]
theorem lowerBounds_empty : lowerBounds (∅ : Set α) = univ :=
@upperBounds_empty αᵒᵈ _
@[simp]
theorem bddAbove_empty [Nonempty α] : BddAbove (∅ : Set α) := by
simp only [BddAbove, upperBounds_empty, univ_nonempty]
@[simp]
theorem bddBelow_empty [Nonempty α] : BddBelow (∅ : Set α) := by
simp only [BddBelow, lowerBounds_empty, univ_nonempty]
@[simp] theorem isGLB_empty_iff : IsGLB ∅ a ↔ IsTop a := by
simp [IsGLB]
@[simp] theorem isLUB_empty_iff : IsLUB ∅ a ↔ IsBot a :=
@isGLB_empty_iff αᵒᵈ _ _
theorem isGLB_empty [OrderTop α] : IsGLB ∅ (⊤ : α) :=
isGLB_empty_iff.2 isTop_top
theorem isLUB_empty [OrderBot α] : IsLUB ∅ (⊥ : α) :=
@isGLB_empty αᵒᵈ _ _
theorem IsLUB.nonempty [NoBotOrder α] (hs : IsLUB s a) : s.Nonempty :=
nonempty_iff_ne_empty.2 fun h =>
not_isBot a fun _ => hs.right <| by rw [h, upperBounds_empty]; exact mem_univ _
theorem IsGLB.nonempty [NoTopOrder α] (hs : IsGLB s a) : s.Nonempty :=
hs.dual.nonempty
theorem nonempty_of_not_bddAbove [ha : Nonempty α] (h : ¬BddAbove s) : s.Nonempty :=
(Nonempty.elim ha) fun x => (not_bddAbove_iff'.1 h x).imp fun _ ha => ha.1
theorem nonempty_of_not_bddBelow [Nonempty α] (h : ¬BddBelow s) : s.Nonempty :=
@nonempty_of_not_bddAbove αᵒᵈ _ _ _ h
/-!
#### insert
-/
/-- Adding a point to a set preserves its boundedness above. -/
@[simp]
theorem bddAbove_insert [IsDirected α (· ≤ ·)] {s : Set α} {a : α} :
BddAbove (insert a s) ↔ BddAbove s := by
simp only [insert_eq, bddAbove_union, bddAbove_singleton, true_and]
protected theorem BddAbove.insert [IsDirected α (· ≤ ·)] {s : Set α} (a : α) :
BddAbove s → BddAbove (insert a s) :=
bddAbove_insert.2
/-- Adding a point to a set preserves its boundedness below. -/
@[simp]
theorem bddBelow_insert [IsDirected α (· ≥ ·)] {s : Set α} {a : α} :
BddBelow (insert a s) ↔ BddBelow s := by
simp only [insert_eq, bddBelow_union, bddBelow_singleton, true_and]
protected theorem BddBelow.insert [IsDirected α (· ≥ ·)] {s : Set α} (a : α) :
BddBelow s → BddBelow (insert a s) :=
bddBelow_insert.2
protected theorem IsLUB.insert [SemilatticeSup γ] (a) {b} {s : Set γ} (hs : IsLUB s b) :
IsLUB (insert a s) (a ⊔ b) := by
rw [insert_eq]
exact isLUB_singleton.union hs
protected theorem IsGLB.insert [SemilatticeInf γ] (a) {b} {s : Set γ} (hs : IsGLB s b) :
IsGLB (insert a s) (a ⊓ b) := by
rw [insert_eq]
exact isGLB_singleton.union hs
protected theorem IsGreatest.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsGreatest s b) :
IsGreatest (insert a s) (max a b) := by
rw [insert_eq]
exact isGreatest_singleton.union hs
protected theorem IsLeast.insert [LinearOrder γ] (a) {b} {s : Set γ} (hs : IsLeast s b) :
IsLeast (insert a s) (min a b) := by
rw [insert_eq]
exact isLeast_singleton.union hs
@[simp]
theorem upperBounds_insert (a : α) (s : Set α) :
upperBounds (insert a s) = Ici a ∩ upperBounds s := by
rw [insert_eq, upperBounds_union, upperBounds_singleton]
@[simp]
theorem lowerBounds_insert (a : α) (s : Set α) :
lowerBounds (insert a s) = Iic a ∩ lowerBounds s := by
rw [insert_eq, lowerBounds_union, lowerBounds_singleton]
/-- When there is a global maximum, every set is bounded above. -/
@[simp]
protected theorem OrderTop.bddAbove [OrderTop α] (s : Set α) : BddAbove s :=
⟨⊤, fun a _ => OrderTop.le_top a⟩
/-- When there is a global minimum, every set is bounded below. -/
@[simp]
protected theorem OrderBot.bddBelow [OrderBot α] (s : Set α) : BddBelow s :=
⟨⊥, fun a _ => OrderBot.bot_le a⟩
/-- Sets are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `bddDefault` in the statements,
in the form `(hA : BddAbove A := by bddDefault)`. -/
macro "bddDefault" : tactic =>
`(tactic| first
| apply OrderTop.bddAbove
| apply OrderBot.bddBelow)
/-!
#### Pair
-/
theorem isLUB_pair [SemilatticeSup γ] {a b : γ} : IsLUB {a, b} (a ⊔ b) :=
isLUB_singleton.insert _
theorem isGLB_pair [SemilatticeInf γ] {a b : γ} : IsGLB {a, b} (a ⊓ b) :=
isGLB_singleton.insert _
theorem isLeast_pair [LinearOrder γ] {a b : γ} : IsLeast {a, b} (min a b) :=
isLeast_singleton.insert _
theorem isGreatest_pair [LinearOrder γ] {a b : γ} : IsGreatest {a, b} (max a b) :=
isGreatest_singleton.insert _
/-!
#### Lower/upper bounds
-/
@[simp]
theorem isLUB_lowerBounds : IsLUB (lowerBounds s) a ↔ IsGLB s a :=
⟨fun H => ⟨fun _ hx => H.2 <| subset_upperBounds_lowerBounds s hx, H.1⟩, IsGreatest.isLUB⟩
@[simp]
theorem isGLB_upperBounds : IsGLB (upperBounds s) a ↔ IsLUB s a :=
@isLUB_lowerBounds αᵒᵈ _ _ _
end
/-!
### (In)equalities with the least upper bound and the greatest lower bound
-/
section Preorder
variable [Preorder α] {s : Set α} {a b : α}
theorem lowerBounds_le_upperBounds (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) :
s.Nonempty → a ≤ b
| ⟨_, hc⟩ => le_trans (ha hc) (hb hc)
theorem isGLB_le_isLUB (ha : IsGLB s a) (hb : IsLUB s b) (hs : s.Nonempty) : a ≤ b :=
lowerBounds_le_upperBounds ha.1 hb.1 hs
theorem isLUB_lt_iff (ha : IsLUB s a) : a < b ↔ ∃ c ∈ upperBounds s, c < b :=
⟨fun hb => ⟨a, ha.1, hb⟩, fun ⟨_, hcs, hcb⟩ => lt_of_le_of_lt (ha.2 hcs) hcb⟩
theorem lt_isGLB_iff (ha : IsGLB s a) : b < a ↔ ∃ c ∈ lowerBounds s, b < c :=
isLUB_lt_iff ha.dual
theorem le_of_isLUB_le_isGLB {x y} (ha : IsGLB s a) (hb : IsLUB s b) (hab : b ≤ a) (hx : x ∈ s)
(hy : y ∈ s) : x ≤ y :=
calc
x ≤ b := hb.1 hx
_ ≤ a := hab
_ ≤ y := ha.1 hy
end Preorder
section PartialOrder
variable [PartialOrder α] {s : Set α} {a b : α}
theorem IsLeast.unique (Ha : IsLeast s a) (Hb : IsLeast s b) : a = b :=
le_antisymm (Ha.right Hb.left) (Hb.right Ha.left)
theorem IsLeast.isLeast_iff_eq (Ha : IsLeast s a) : IsLeast s b ↔ a = b :=
Iff.intro Ha.unique fun h => h ▸ Ha
theorem IsGreatest.unique (Ha : IsGreatest s a) (Hb : IsGreatest s b) : a = b :=
le_antisymm (Hb.right Ha.left) (Ha.right Hb.left)
theorem IsGreatest.isGreatest_iff_eq (Ha : IsGreatest s a) : IsGreatest s b ↔ a = b :=
Iff.intro Ha.unique fun h => h ▸ Ha
theorem IsLUB.unique (Ha : IsLUB s a) (Hb : IsLUB s b) : a = b :=
IsLeast.unique Ha Hb
theorem IsGLB.unique (Ha : IsGLB s a) (Hb : IsGLB s b) : a = b :=
IsGreatest.unique Ha Hb
theorem Set.subsingleton_of_isLUB_le_isGLB (Ha : IsGLB s a) (Hb : IsLUB s b) (hab : b ≤ a) :
s.Subsingleton := fun _ hx _ hy =>
le_antisymm (le_of_isLUB_le_isGLB Ha Hb hab hx hy) (le_of_isLUB_le_isGLB Ha Hb hab hy hx)
theorem isGLB_lt_isLUB_of_ne (Ha : IsGLB s a) (Hb : IsLUB s b) {x y} (Hx : x ∈ s) (Hy : y ∈ s)
(Hxy : x ≠ y) : a < b :=
lt_iff_le_not_le.2
⟨lowerBounds_le_upperBounds Ha.1 Hb.1 ⟨x, Hx⟩, fun hab =>
Hxy <| Set.subsingleton_of_isLUB_le_isGLB Ha Hb hab Hx Hy⟩
end PartialOrder
section LinearOrder
variable [LinearOrder α] {s : Set α} {a b : α}
theorem lt_isLUB_iff (h : IsLUB s a) : b < a ↔ ∃ c ∈ s, b < c := by
simp_rw [← not_le, isLUB_le_iff h, mem_upperBounds, not_forall, not_le, exists_prop]
theorem isGLB_lt_iff (h : IsGLB s a) : a < b ↔ ∃ c ∈ s, c < b :=
lt_isLUB_iff h.dual
theorem IsLUB.exists_between (h : IsLUB s a) (hb : b < a) : ∃ c ∈ s, b < c ∧ c ≤ a :=
let ⟨c, hcs, hbc⟩ := (lt_isLUB_iff h).1 hb
⟨c, hcs, hbc, h.1 hcs⟩
theorem IsLUB.exists_between' (h : IsLUB s a) (h' : a ∉ s) (hb : b < a) : ∃ c ∈ s, b < c ∧ c < a :=
let ⟨c, hcs, hbc, hca⟩ := h.exists_between hb
⟨c, hcs, hbc, hca.lt_of_ne fun hac => h' <| hac ▸ hcs⟩
theorem IsGLB.exists_between (h : IsGLB s a) (hb : a < b) : ∃ c ∈ s, a ≤ c ∧ c < b :=
let ⟨c, hcs, hbc⟩ := (isGLB_lt_iff h).1 hb
⟨c, hcs, h.1 hcs, hbc⟩
theorem IsGLB.exists_between' (h : IsGLB s a) (h' : a ∉ s) (hb : a < b) : ∃ c ∈ s, a < c ∧ c < b :=
let ⟨c, hcs, hac, hcb⟩ := h.exists_between hb
⟨c, hcs, hac.lt_of_ne fun hac => h' <| hac.symm ▸ hcs, hcb⟩
end LinearOrder
theorem isGreatest_himp [GeneralizedHeytingAlgebra α] (a b : α) :
IsGreatest {w | w ⊓ a ≤ b} (a ⇨ b) := by
simp [IsGreatest, mem_upperBounds]
theorem isLeast_sdiff [GeneralizedCoheytingAlgebra α] (a b : α) :
IsLeast {w | a ≤ b ⊔ w} (a \ b) := by
simp [IsLeast, mem_lowerBounds]
theorem isGreatest_compl [HeytingAlgebra α] (a : α) :
IsGreatest {w | Disjoint w a} (aᶜ) := by
simpa only [himp_bot, disjoint_iff_inf_le] using isGreatest_himp a ⊥
theorem isLeast_hnot [CoheytingAlgebra α] (a : α) :
IsLeast {w | Codisjoint a w} (¬a) := by
simpa only [CoheytingAlgebra.top_sdiff, codisjoint_iff_le_sup] using isLeast_sdiff ⊤ a
| Mathlib/Order/Bounds/Basic.lean | 1,396 | 1,398 | |
/-
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, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
import Mathlib.MeasureTheory.Group.MeasurableEquiv
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Regular measures
A measure is `OuterRegular` if the measure of any measurable set `A` is the infimum of `μ U` over
all open sets `U` containing `A`.
A measure is `WeaklyRegular` if it satisfies the following properties:
* it is outer regular;
* it is inner regular for open sets with respect to closed sets: the measure of any open set `U`
is the supremum of `μ F` over all closed sets `F` contained in `U`.
A measure is `Regular` if it satisfies the following properties:
* it is finite on compact sets;
* it is outer regular;
* it is inner regular for open sets with respect to compacts closed sets: the measure of any open
set `U` is the supremum of `μ K` over all compact sets `K` contained in `U`.
A measure is `InnerRegular` if it is inner regular for measurable sets with respect to compact
sets: the measure of any measurable set `s` is the supremum of `μ K` over all compact
sets contained in `s`.
A measure is `InnerRegularCompactLTTop` if it is inner regular for measurable sets of finite
measure with respect to compact sets: the measure of any measurable set `s` is the supremum
of `μ K` over all compact sets contained in `s`.
There is a reason for this zoo of regularity classes:
* A finite measure on a metric space is always weakly regular. Therefore, in probability theory,
weakly regular measures play a prominent role.
* In locally compact topological spaces, there are two competing notions of Radon measures: the
ones that are regular, and the ones that are inner regular. For any of these two notions, there is
a Riesz representation theorem, and an existence and uniqueness statement for the Haar measure in
locally compact topological groups. The two notions coincide in sigma-compact spaces, but they
differ in general, so it is worth having the two of them.
* Both notions of Haar measure satisfy the weaker notion `InnerRegularCompactLTTop`, so it is worth
trying to express theorems using this weaker notion whenever possible, to make sure that it
applies to both Haar measures simultaneously.
While traditional textbooks on measure theory on locally compact spaces emphasize regular measures,
more recent textbooks emphasize that inner regular Haar measures are better behaved than regular
Haar measures, so we will develop both notions.
The five conditions above are registered as typeclasses for a measure `μ`, and implications between
them are recorded as instances. For example, in a Hausdorff topological space, regularity implies
weak regularity. Also, regularity or inner regularity both imply `InnerRegularCompactLTTop`.
In a regular locally compact finite measure space, then regularity, inner regularity
and `InnerRegularCompactLTTop` are all equivalent.
In order to avoid code duplication, we also define a measure `μ` to be `InnerRegularWRT` for sets
satisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set
`U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ F`.
There are two main nontrivial results in the development below:
* `InnerRegularWRT.measurableSet_of_isOpen` shows that, for an outer regular measure, inner
regularity for open sets with respect to compact sets or closed sets implies inner regularity for
all measurable sets of finite measure (with respect to compact sets or closed sets respectively).
* `InnerRegularWRT.weaklyRegular_of_finite` shows that a finite measure which is inner regular for
open sets with respect to closed sets (for instance a finite measure on a metric space) is weakly
regular.
All other results are deduced from these ones.
Here is an example showing how regularity and inner regularity may differ even on locally compact
spaces. Consider the group `ℝ × ℝ` where the first factor has the discrete topology and the second
one the usual topology. It is a locally compact Hausdorff topological group, with Haar measure equal
to Lebesgue measure on each vertical fiber. Let us consider the regular version of Haar measure.
Then the set `ℝ × {0}` has infinite measure (by outer regularity), but any compact set it contains
has zero measure (as it is finite). In fact, this set only contains subset with measure zero or
infinity. The inner regular version of Haar measure, on the other hand, gives zero mass to the
set `ℝ × {0}`.
Another interesting example is the sum of the Dirac masses at rational points in the real line.
It is a σ-finite measure on a locally compact metric space, but it is not outer regular: for
outer regularity, one needs additional locally finite assumptions. On the other hand, it is
inner regular.
Several authors require both regularity and inner regularity for their measures. We have opted
for the more fine grained definitions above as they apply more generally.
## Main definitions
* `MeasureTheory.Measure.OuterRegular μ`: a typeclass registering that a measure `μ` on a
topological space is outer regular.
* `MeasureTheory.Measure.Regular μ`: a typeclass registering that a measure `μ` on a topological
space is regular.
* `MeasureTheory.Measure.WeaklyRegular μ`: a typeclass registering that a measure `μ` on a
topological space is weakly regular.
* `MeasureTheory.Measure.InnerRegularWRT μ p q`: a non-typeclass predicate saying that a measure `μ`
is inner regular for sets satisfying `q` with respect to sets satisfying `p`.
* `MeasureTheory.Measure.InnerRegular μ`: a typeclass registering that a measure `μ` on a
topological space is inner regular for measurable sets with respect to compact sets.
* `MeasureTheory.Measure.InnerRegularCompactLTTop μ`: a typeclass registering that a measure `μ`
on a topological space is inner regular for measurable sets of finite measure with respect to
compact sets.
## Main results
### Outer regular measures
* `Set.measure_eq_iInf_isOpen` asserts that, when `μ` is outer regular, the measure of a
set is the infimum of the measure of open sets containing it.
* `Set.exists_isOpen_lt_of_lt` asserts that, when `μ` is outer regular, for every set `s`
and `r > μ s` there exists an open superset `U ⊇ s` of measure less than `r`.
* push forward of an outer regular measure is outer regular, and scalar multiplication of a regular
measure by a finite number is outer regular.
### Weakly regular measures
* `IsOpen.measure_eq_iSup_isClosed` asserts that the measure of an open set is the supremum of
the measure of closed sets it contains.
* `IsOpen.exists_lt_isClosed`: for an open set `U` and `r < μ U`, there exists a closed `F ⊆ U`
of measure greater than `r`;
* `MeasurableSet.measure_eq_iSup_isClosed_of_ne_top` asserts that the measure of a measurable set
of finite measure is the supremum of the measure of closed sets it contains.
* `MeasurableSet.exists_lt_isClosed_of_ne_top` and `MeasurableSet.exists_isClosed_lt_add`:
a measurable set of finite measure can be approximated by a closed subset (stated as
`r < μ F` and `μ s < μ F + ε`, respectively).
* `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_of_isFiniteMeasure` is an
instance registering that a finite measure on a metric space is weakly regular (in fact, a pseudo
metrizable space is enough);
* `MeasureTheory.Measure.WeaklyRegular.of_pseudoMetrizableSpace_secondCountable_of_locallyFinite`
is an instance registering that a locally finite measure on a second countable metric space (or
even a pseudo metrizable space) is weakly regular.
### Regular measures
* `IsOpen.measure_eq_iSup_isCompact` asserts that the measure of an open set is the supremum of
the measure of compact sets it contains.
* `IsOpen.exists_lt_isCompact`: for an open set `U` and `r < μ U`, there exists a compact `K ⊆ U`
of measure greater than `r`;
* `MeasureTheory.Measure.Regular.of_sigmaCompactSpace_of_isLocallyFiniteMeasure` is an
instance registering that a locally finite measure on a `σ`-compact metric space is regular (in
fact, an emetric space is enough).
### Inner regular measures
* `MeasurableSet.measure_eq_iSup_isCompact` asserts that the measure of a measurable set is the
supremum of the measure of compact sets it contains.
* `MeasurableSet.exists_lt_isCompact`: for a measurable set `s` and `r < μ s`, there exists a
compact `K ⊆ s` of measure greater than `r`;
### Inner regular measures for finite measure sets with respect to compact sets
* `MeasurableSet.measure_eq_iSup_isCompact_of_ne_top` asserts that the measure of a measurable set
of finite measure is the supremum of the measure of compact sets it contains.
* `MeasurableSet.exists_lt_isCompact_of_ne_top` and `MeasurableSet.exists_isCompact_lt_add`:
a measurable set of finite measure can be approximated by a compact subset (stated as
`r < μ K` and `μ s < μ K + ε`, respectively).
## Implementation notes
The main nontrivial statement is `MeasureTheory.Measure.InnerRegular.weaklyRegular_of_finite`,
expressing that in a finite measure space, if every open set can be approximated from inside by
closed sets, then the measure is in fact weakly regular. To prove that we show that any measurable
set can be approximated from inside by closed sets and from outside by open sets. This statement is
proved by measurable induction, starting from open sets and checking that it is stable by taking
complements (this is the point of this condition, being symmetrical between inside and outside) and
countable disjoint unions.
Once this statement is proved, one deduces results for `σ`-finite measures from this statement, by
restricting them to finite measure sets (and proving that this restriction is weakly regular, using
again the same statement).
For non-Hausdorff spaces, one may argue whether the right condition for inner regularity is with
respect to compact sets, or to compact closed sets. For instance,
[Fremlin, *Measure Theory* (volume 4, 411J)][fremlin_vol4] considers measures which are inner
regular with respect to compact closed sets (and calls them *tight*). However, since most of the
literature uses mere compact sets, we have chosen to follow this convention. It doesn't make a
difference in Hausdorff spaces, of course. In locally compact topological groups, the two
conditions coincide, since if a compact set `k` is contained in a measurable set `u`, then the
closure of `k` is a compact closed set still contained in `u`, see
`IsCompact.closure_subset_of_measurableSet_of_group`.
## References
[Halmos, Measure Theory, §52][halmos1950measure]. Note that Halmos uses an unusual definition of
Borel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his
proofs or statements do not apply directly.
[Billingsley, Convergence of Probability Measures][billingsley1999]
[Bogachev, Measure Theory, volume 2, Theorem 7.11.1][bogachev2007]
-/
open Set Filter ENNReal NNReal TopologicalSpace
open scoped symmDiff Topology
namespace MeasureTheory
namespace Measure
/-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : Set α → Prop`,
if for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ U` satisfying `p K`
of measure greater than `r`.
This definition is used to prove some facts about regular and weakly regular measures without
repeating the proofs. -/
def InnerRegularWRT {α} {_ : MeasurableSpace α} (μ : Measure α) (p q : Set α → Prop) :=
∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K, K ⊆ U ∧ p K ∧ r < μ K
namespace InnerRegularWRT
variable {α : Type*} {m : MeasurableSpace α} {μ : Measure α} {p q : Set α → Prop} {U : Set α}
{ε : ℝ≥0∞}
theorem measure_eq_iSup (H : InnerRegularWRT μ p q) (hU : q U) :
μ U = ⨆ (K) (_ : K ⊆ U) (_ : p K), μ K := by
refine
le_antisymm (le_of_forall_lt fun r hr => ?_) (iSup₂_le fun K hK => iSup_le fun _ => μ.mono hK)
simpa only [lt_iSup_iff, exists_prop] using H hU r hr
theorem exists_subset_lt_add (H : InnerRegularWRT μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞)
(hε : ε ≠ 0) : ∃ K, K ⊆ U ∧ p K ∧ μ U < μ K + ε := by
rcases eq_or_ne (μ U) 0 with h₀ | h₀
· refine ⟨∅, empty_subset _, h0, ?_⟩
rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero]
· rcases H hU _ (ENNReal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩
exact ⟨K, hKU, hKc, ENNReal.lt_add_of_sub_lt_right (Or.inl hμU) hrK⟩
protected theorem map {α β} [MeasurableSpace α] [MeasurableSpace β]
{μ : Measure α} {pa qa : Set α → Prop}
(H : InnerRegularWRT μ pa qa) {f : α → β} (hf : AEMeasurable f μ) {pb qb : Set β → Prop}
(hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K))
(hB₂ : ∀ U, qb U → MeasurableSet U) :
InnerRegularWRT (map f μ) pb qb := by
intro U hU r hr
rw [map_apply_of_aemeasurable hf (hB₂ _ hU)] at hr
rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩
refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩
exact hK.trans_le (le_map_apply_image hf _)
theorem map' {α β} [MeasurableSpace α] [MeasurableSpace β] {μ : Measure α} {pa qa : Set α → Prop}
(H : InnerRegularWRT μ pa qa) (f : α ≃ᵐ β) {pb qb : Set β → Prop}
(hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K)) :
InnerRegularWRT (map f μ) pb qb := by
intro U hU r hr
rw [f.map_apply U] at hr
rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩
refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, ?_⟩
rwa [f.map_apply, f.preimage_image]
theorem smul (H : InnerRegularWRT μ p q) (c : ℝ≥0∞) : InnerRegularWRT (c • μ) p q := by
intro U hU r hr
rw [smul_apply, H.measure_eq_iSup hU, smul_eq_mul] at hr
simpa only [ENNReal.mul_iSup, lt_iSup_iff, exists_prop] using hr
theorem trans {q' : Set α → Prop} (H : InnerRegularWRT μ p q) (H' : InnerRegularWRT μ q q') :
InnerRegularWRT μ p q' := by
intro U hU r hr
rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩; rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩
exact ⟨K, hKF.trans hFU, hpK, hrK⟩
theorem rfl {p : Set α → Prop} : InnerRegularWRT μ p p :=
fun U hU _r hr ↦ ⟨U, Subset.rfl, hU, hr⟩
theorem of_imp (h : ∀ s, q s → p s) : InnerRegularWRT μ p q :=
fun U hU _ hr ↦ ⟨U, Subset.rfl, h U hU, hr⟩
theorem mono {p' q' : Set α → Prop} (H : InnerRegularWRT μ p q)
(h : ∀ s, q' s → q s) (h' : ∀ s, p s → p' s) : InnerRegularWRT μ p' q' :=
of_imp h' |>.trans H |>.trans (of_imp h)
end InnerRegularWRT
variable {α β : Type*} [MeasurableSpace α] {μ : Measure α}
section Classes
variable [TopologicalSpace α]
/-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ U open}` for a measurable set `A`.
This definition implies the same equality for any (not necessarily measurable) set, see
`Set.measure_eq_iInf_isOpen`. -/
class OuterRegular (μ : Measure α) : Prop where
protected outerRegular :
∀ ⦃A : Set α⦄, MeasurableSet A → ∀ r > μ A, ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r
/-- A measure `μ` is regular if
- it is finite on all compact sets;
- it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;
- it is inner regular for open sets, using compact sets:
`μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/
class Regular (μ : Measure α) : Prop extends IsFiniteMeasureOnCompacts μ, OuterRegular μ where
innerRegular : InnerRegularWRT μ IsCompact IsOpen
/-- A measure `μ` is weakly regular if
- it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable;
- it is inner regular for open sets, using closed sets:
`μ(U) = sup {μ(F) | F ⊆ U closed}` for `U` open. -/
class WeaklyRegular (μ : Measure α) : Prop extends OuterRegular μ where
protected innerRegular : InnerRegularWRT μ IsClosed IsOpen
/-- A measure `μ` is inner regular if, for any measurable set `s`, then
`μ(s) = sup {μ(K) | K ⊆ s compact}`. -/
class InnerRegular (μ : Measure α) : Prop where
protected innerRegular : InnerRegularWRT μ IsCompact MeasurableSet
/-- A measure `μ` is inner regular for finite measure sets with respect to compact sets:
for any measurable set `s` with finite measure, then `μ(s) = sup {μ(K) | K ⊆ s compact}`.
The main interest of this class is that it is satisfied for both natural Haar measures (the
regular one and the inner regular one). -/
class InnerRegularCompactLTTop (μ : Measure α) : Prop where
protected innerRegular : InnerRegularWRT μ IsCompact (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)
-- see Note [lower instance priority]
/-- A regular measure is weakly regular in an R₁ space. -/
instance (priority := 100) Regular.weaklyRegular [R1Space α] [Regular μ] :
WeaklyRegular μ where
innerRegular := fun _U hU r hr ↦
let ⟨K, KU, K_comp, hK⟩ := Regular.innerRegular hU r hr
⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure,
hK.trans_le (measure_mono subset_closure)⟩
end Classes
namespace OuterRegular
variable [TopologicalSpace α]
instance zero : OuterRegular (0 : Measure α) :=
⟨fun A _ _r hr => ⟨univ, subset_univ A, isOpen_univ, hr⟩⟩
/-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with
measure less than `r`. -/
theorem _root_.Set.exists_isOpen_lt_of_lt [OuterRegular μ] (A : Set α) (r : ℝ≥0∞) (hr : μ A < r) :
∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < r := by
rcases OuterRegular.outerRegular (measurableSet_toMeasurable μ A) r
(by rwa [measure_toMeasurable]) with
⟨U, hAU, hUo, hU⟩
exact ⟨U, (subset_toMeasurable _ _).trans hAU, hUo, hU⟩
/-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets
containing it. -/
theorem _root_.Set.measure_eq_iInf_isOpen (A : Set α) (μ : Measure α) [OuterRegular μ] :
μ A = ⨅ (U : Set α) (_ : A ⊆ U) (_ : IsOpen U), μ U := by
refine le_antisymm (le_iInf₂ fun s hs => le_iInf fun _ => μ.mono hs) ?_
refine le_of_forall_lt' fun r hr => ?_
simpa only [iInf_lt_iff, exists_prop] using A.exists_isOpen_lt_of_lt r hr
theorem _root_.Set.exists_isOpen_lt_add [OuterRegular μ] (A : Set α) (hA : μ A ≠ ∞) {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < μ A + ε :=
A.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hA hε)
theorem _root_.Set.exists_isOpen_le_add (A : Set α) (μ : Measure α) [OuterRegular μ] {ε : ℝ≥0∞}
(hε : ε ≠ 0) : ∃ U, U ⊇ A ∧ IsOpen U ∧ μ U ≤ μ A + ε := by
rcases eq_or_ne (μ A) ∞ with (H | H)
· exact ⟨univ, subset_univ _, isOpen_univ, by simp only [H, _root_.top_add, le_top]⟩
· rcases A.exists_isOpen_lt_add H hε with ⟨U, AU, U_open, hU⟩
exact ⟨U, AU, U_open, hU.le⟩
theorem _root_.MeasurableSet.exists_isOpen_diff_lt [OuterRegular μ] {A : Set α}
(hA : MeasurableSet A) (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, U ⊇ A ∧ IsOpen U ∧ μ U < ∞ ∧ μ (U \ A) < ε := by
rcases A.exists_isOpen_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩
use U, hAU, hUo, hU.trans_le le_top
exact measure_diff_lt_of_lt_add hA.nullMeasurableSet hAU hA' hU
protected theorem map [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] (f : α ≃ₜ β) (μ : Measure α) [OuterRegular μ] :
(Measure.map f μ).OuterRegular := by
refine ⟨fun A hA r hr => ?_⟩
rw [map_apply f.measurable hA, ← f.image_symm] at hr
rcases Set.exists_isOpen_lt_of_lt _ r hr with ⟨U, hAU, hUo, hU⟩
have : IsOpen (f.symm ⁻¹' U) := hUo.preimage f.symm.continuous
refine ⟨f.symm ⁻¹' U, image_subset_iff.1 hAU, this, ?_⟩
rwa [map_apply f.measurable this.measurableSet, f.preimage_symm, f.preimage_image]
protected theorem smul (μ : Measure α) [OuterRegular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) :
(x • μ).OuterRegular := by
rcases eq_or_ne x 0 with (rfl | h0)
· rw [zero_smul]
exact OuterRegular.zero
· refine ⟨fun A _ r hr => ?_⟩
rw [smul_apply, A.measure_eq_iInf_isOpen, smul_eq_mul] at hr
simpa only [ENNReal.mul_iInf_of_ne h0 hx, gt_iff_lt, iInf_lt_iff, exists_prop] using hr
instance smul_nnreal (μ : Measure α) [OuterRegular μ] (c : ℝ≥0) :
OuterRegular (c • μ) :=
OuterRegular.smul μ coe_ne_top
open scoped Function in -- required for scoped `on` notation
/-- If the restrictions of a measure to countably many open sets covering the space are
outer regular, then the measure itself is outer regular. -/
lemma of_restrict [OpensMeasurableSpace α] {μ : Measure α} {s : ℕ → Set α}
(h : ∀ n, OuterRegular (μ.restrict (s n))) (h' : ∀ n, IsOpen (s n)) (h'' : univ ⊆ ⋃ n, s n) :
OuterRegular μ := by
refine ⟨fun A hA r hr => ?_⟩
have HA : μ A < ∞ := lt_of_lt_of_le hr le_top
have hm : ∀ n, MeasurableSet (s n) := fun n => (h' n).measurableSet
-- Note that `A = ⋃ n, A ∩ disjointed s n`. We replace `A` with this sequence.
obtain ⟨A, hAm, hAs, hAd, rfl⟩ :
∃ A' : ℕ → Set α,
(∀ n, MeasurableSet (A' n)) ∧
(∀ n, A' n ⊆ s n) ∧ Pairwise (Disjoint on A') ∧ A = ⋃ n, A' n := by
refine
⟨fun n => A ∩ disjointed s n, fun n => hA.inter (MeasurableSet.disjointed hm _), fun n =>
inter_subset_right.trans (disjointed_subset _ _),
(disjoint_disjointed s).mono fun k l hkl => hkl.mono inf_le_right inf_le_right, ?_⟩
rw [← inter_iUnion, iUnion_disjointed, univ_subset_iff.mp h'', inter_univ]
rcases ENNReal.exists_pos_sum_of_countable' (tsub_pos_iff_lt.2 hr).ne' ℕ with ⟨δ, δ0, hδε⟩
rw [lt_tsub_iff_right, add_comm] at hδε
have : ∀ n, ∃ U ⊇ A n, IsOpen U ∧ μ U < μ (A n) + δ n := by
intro n
have H₁ : ∀ t, μ.restrict (s n) t = μ (t ∩ s n) := fun t => restrict_apply' (hm n)
have Ht : μ.restrict (s n) (A n) ≠ ∞ := by
rw [H₁]
exact ((measure_mono (inter_subset_left.trans (subset_iUnion A n))).trans_lt HA).ne
rcases (A n).exists_isOpen_lt_add Ht (δ0 n).ne' with ⟨U, hAU, hUo, hU⟩
rw [H₁, H₁, inter_eq_self_of_subset_left (hAs _)] at hU
exact ⟨U ∩ s n, subset_inter hAU (hAs _), hUo.inter (h' n), hU⟩
choose U hAU hUo hU using this
refine ⟨⋃ n, U n, iUnion_mono hAU, isOpen_iUnion hUo, ?_⟩
calc
μ (⋃ n, U n) ≤ ∑' n, μ (U n) := measure_iUnion_le _
_ ≤ ∑' n, (μ (A n) + δ n) := ENNReal.tsum_le_tsum fun n => (hU n).le
_ = ∑' n, μ (A n) + ∑' n, δ n := ENNReal.tsum_add
_ = μ (⋃ n, A n) + ∑' n, δ n := (congr_arg₂ (· + ·) (measure_iUnion hAd hAm).symm rfl)
_ < r := hδε
/-- See also `IsCompact.measure_closure` for a version
that assumes the `σ`-algebra to be the Borel `σ`-algebra but makes no assumptions on `μ`. -/
lemma measure_closure_eq_of_isCompact [R1Space α] [OuterRegular μ]
{k : Set α} (hk : IsCompact k) : μ (closure k) = μ k := by
apply le_antisymm ?_ (measure_mono subset_closure)
simp only [measure_eq_iInf_isOpen k, le_iInf_iff]
intro u ku u_open
exact measure_mono (hk.closure_subset_of_isOpen u_open ku)
end OuterRegular
/-- If a measure `μ` admits finite spanning open sets such that the restriction of `μ` to each set
is outer regular, then the original measure is outer regular as well. -/
protected theorem FiniteSpanningSetsIn.outerRegular
[TopologicalSpace α] [OpensMeasurableSpace α] {μ : Measure α}
(s : μ.FiniteSpanningSetsIn { U | IsOpen U ∧ OuterRegular (μ.restrict U) }) :
OuterRegular μ :=
OuterRegular.of_restrict (s := fun n ↦ s.set n) (fun n ↦ (s.set_mem n).2)
(fun n ↦ (s.set_mem n).1) s.spanning.symm.subset
namespace InnerRegularWRT
variable {p : Set α → Prop}
/-- If the restrictions of a measure to a monotone sequence of sets covering the space are
inner regular for some property `p` and all measurable sets, then the measure itself is
inner regular. -/
lemma of_restrict {μ : Measure α} {s : ℕ → Set α}
(h : ∀ n, InnerRegularWRT (μ.restrict (s n)) p MeasurableSet)
(hs : univ ⊆ ⋃ n, s n) (hmono : Monotone s) : InnerRegularWRT μ p MeasurableSet := by
intro F hF r hr
have hBU : ⋃ n, F ∩ s n = F := by rw [← inter_iUnion, univ_subset_iff.mp hs, inter_univ]
have : μ F = ⨆ n, μ (F ∩ s n) := by
rw [← (monotone_const.inter hmono).measure_iUnion, hBU]
rw [this] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
rw [← restrict_apply hF] at hn
rcases h n hF _ hn with ⟨K, KF, hKp, hK⟩
exact ⟨K, KF, hKp, hK.trans_le (restrict_apply_le _ _)⟩
/-- If `μ` is inner regular for measurable finite measure sets with respect to some class of sets,
then its restriction to any set is also inner regular for measurable finite measure sets, with
respect to the same class of sets. -/
lemma restrict (h : InnerRegularWRT μ p (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞)) (A : Set α) :
InnerRegularWRT (μ.restrict A) p (fun s ↦ MeasurableSet s ∧ μ.restrict A s ≠ ∞) := by
rintro s ⟨s_meas, hs⟩ r hr
rw [restrict_apply s_meas] at hs
obtain ⟨K, K_subs, pK, rK⟩ : ∃ K, K ⊆ (toMeasurable μ (s ∩ A)) ∩ s ∧ p K ∧ r < μ K := by
have : r < μ ((toMeasurable μ (s ∩ A)) ∩ s) := by
apply hr.trans_le
rw [restrict_apply s_meas]
exact measure_mono <| subset_inter (subset_toMeasurable μ (s ∩ A)) inter_subset_left
refine h ⟨(measurableSet_toMeasurable _ _).inter s_meas, ?_⟩ _ this
apply (lt_of_le_of_lt _ hs.lt_top).ne
rw [← measure_toMeasurable (s ∩ A)]
exact measure_mono inter_subset_left
refine ⟨K, K_subs.trans inter_subset_right, pK, ?_⟩
calc
r < μ K := rK
_ = μ.restrict (toMeasurable μ (s ∩ A)) K := by
rw [restrict_apply' (measurableSet_toMeasurable μ (s ∩ A))]
congr
apply (inter_eq_left.2 ?_).symm
exact K_subs.trans inter_subset_left
_ = μ.restrict (s ∩ A) K := by rwa [restrict_toMeasurable]
_ ≤ μ.restrict A K := Measure.le_iff'.1 (restrict_mono inter_subset_right le_rfl) K
/-- If `μ` is inner regular for measurable finite measure sets with respect to some class of sets,
then its restriction to any finite measure set is also inner regular for measurable sets with
respect to the same class of sets. -/
lemma restrict_of_measure_ne_top (h : InnerRegularWRT μ p (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞))
{A : Set α} (hA : μ A ≠ ∞) :
InnerRegularWRT (μ.restrict A) p (fun s ↦ MeasurableSet s) := by
have : Fact (μ A < ∞) := ⟨hA.lt_top⟩
exact (restrict h A).trans (of_imp (fun s hs ↦ ⟨hs, measure_ne_top _ _⟩))
/-- Given a σ-finite measure, any measurable set can be approximated from inside by a measurable
set of finite measure. -/
lemma of_sigmaFinite [SigmaFinite μ] :
InnerRegularWRT μ (fun s ↦ MeasurableSet s ∧ μ s ≠ ∞) (fun s ↦ MeasurableSet s) := by
intro s hs r hr
set B : ℕ → Set α := spanningSets μ
have hBU : ⋃ n, s ∩ B n = s := by rw [← inter_iUnion, iUnion_spanningSets, inter_univ]
have : μ s = ⨆ n, μ (s ∩ B n) := by
rw [← (monotone_const.inter (monotone_spanningSets μ)).measure_iUnion, hBU]
rw [this] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
refine ⟨s ∩ B n, inter_subset_left, ⟨hs.inter (measurableSet_spanningSets μ n), ?_⟩, hn⟩
exact ((measure_mono inter_subset_right).trans_lt (measure_spanningSets_lt_top μ n)).ne
variable [TopologicalSpace α]
/-- If a measure is inner regular (using closed or compact sets) for open sets, then every
measurable set of finite measure can be approximated by a (closed or compact) subset. -/
theorem measurableSet_of_isOpen [OuterRegular μ] (H : InnerRegularWRT μ p IsOpen)
(hd : ∀ ⦃s U⦄, p s → IsOpen U → p (s \ U)) :
InnerRegularWRT μ p fun s => MeasurableSet s ∧ μ s ≠ ∞ := by
rintro s ⟨hs, hμs⟩ r hr
have h0 : p ∅ := by
have : 0 < μ univ := (bot_le.trans_lt hr).trans_le (measure_mono (subset_univ _))
obtain ⟨K, -, hK, -⟩ : ∃ K, K ⊆ univ ∧ p K ∧ 0 < μ K := H isOpen_univ _ this
simpa using hd hK isOpen_univ
obtain ⟨ε, hε, hεs, rfl⟩ : ∃ ε ≠ 0, ε + ε ≤ μ s ∧ r = μ s - (ε + ε) := by
use (μ s - r) / 2
simp [*, hr.le, ENNReal.add_halves, ENNReal.sub_sub_cancel, le_add_right, tsub_eq_zero_iff_le]
rcases hs.exists_isOpen_diff_lt hμs hε with ⟨U, hsU, hUo, hUt, hμU⟩
rcases (U \ s).exists_isOpen_lt_of_lt _ hμU with ⟨U', hsU', hU'o, hμU'⟩
replace hsU' := diff_subset_comm.1 hsU'
rcases H.exists_subset_lt_add h0 hUo hUt.ne hε with ⟨K, hKU, hKc, hKr⟩
refine ⟨K \ U', fun x hx => hsU' ⟨hKU hx.1, hx.2⟩, hd hKc hU'o, ENNReal.sub_lt_of_lt_add hεs ?_⟩
calc
μ s ≤ μ U := μ.mono hsU
_ < μ K + ε := hKr
_ ≤ μ (K \ U') + μ U' + ε := add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _
_ ≤ μ (K \ U') + ε + ε := by gcongr
_ = μ (K \ U') + (ε + ε) := add_assoc _ _ _
open Finset in
/-- In a finite measure space, assume that any open set can be approximated from inside by closed
sets. Then the measure is weakly regular. -/
theorem weaklyRegular_of_finite [BorelSpace α] (μ : Measure α) [IsFiniteMeasure μ]
(H : InnerRegularWRT μ IsClosed IsOpen) : WeaklyRegular μ := by
have hfin : ∀ {s}, μ s ≠ ∞ := @(measure_ne_top μ)
suffices ∀ s, MeasurableSet s → ∀ ε, ε ≠ 0 → ∃ F, F ⊆ s ∧ ∃ U, U ⊇ s ∧
IsClosed F ∧ IsOpen U ∧ μ s ≤ μ F + ε ∧ μ U ≤ μ s + ε by
refine
{ outerRegular := fun s hs r hr => ?_
innerRegular := H }
rcases exists_between hr with ⟨r', hsr', hr'r⟩
rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with ⟨-, -, U, hsU, -, hUo, -, H⟩
refine ⟨U, hsU, hUo, ?_⟩
rw [add_tsub_cancel_of_le hsr'.le] at H
exact H.trans_lt hr'r
apply MeasurableSet.induction_on_open
/- The proof is by measurable induction: we should check that the property is true for the empty
set, for open sets, and is stable by taking the complement and by taking countable disjoint
unions. The point of the property we are proving is that it is stable by taking complements
(exchanging the roles of closed and open sets and thanks to the finiteness of the measure). -/
-- check for open set
· intro U hU ε hε
rcases H.exists_subset_lt_add isClosed_empty hU hfin hε with ⟨F, hsF, hFc, hF⟩
exact ⟨F, hsF, U, Subset.rfl, hFc, hU, hF.le, le_self_add⟩
-- check for complements
· rintro s hs H ε hε
rcases H ε hε with ⟨F, hFs, U, hsU, hFc, hUo, hF, hU⟩
refine
⟨Uᶜ, compl_subset_compl.2 hsU, Fᶜ, compl_subset_compl.2 hFs, hUo.isClosed_compl,
hFc.isOpen_compl, ?_⟩
simp only [measure_compl_le_add_iff, *, hUo.measurableSet, hFc.measurableSet, true_and]
-- check for disjoint unions
· intro s hsd hsm H ε ε0
have ε0' : ε / 2 ≠ 0 := (ENNReal.half_pos ε0).ne'
rcases ENNReal.exists_pos_sum_of_countable' ε0' ℕ with ⟨δ, δ0, hδε⟩
choose F hFs U hsU hFc hUo hF hU using fun n => H n (δ n) (δ0 n).ne'
-- the approximating closed set is constructed by considering finitely many sets `s i`, which
-- cover all the measure up to `ε/2`, approximating each of these by a closed set `F i`, and
-- taking the union of these (finitely many) `F i`.
have : Tendsto (fun t => (∑ k ∈ t, μ (s k)) + ε / 2) atTop (𝓝 <| μ (⋃ n, s n) + ε / 2) := by
rw [measure_iUnion hsd hsm]
exact Tendsto.add ENNReal.summable.hasSum tendsto_const_nhds
rcases (this.eventually <| lt_mem_nhds <| ENNReal.lt_add_right hfin ε0').exists with ⟨t, ht⟩
-- the approximating open set is constructed by taking for each `s n` an approximating open set
-- `U n` with measure at most `μ (s n) + δ n` for a summable `δ`, and taking the union of these.
refine
⟨⋃ k ∈ t, F k, iUnion_mono fun k => iUnion_subset fun _ => hFs _, ⋃ n, U n, iUnion_mono hsU,
isClosed_biUnion_finset fun k _ => hFc k, isOpen_iUnion hUo, ht.le.trans ?_, ?_⟩
· calc
(∑ k ∈ t, μ (s k)) + ε / 2 ≤ ((∑ k ∈ t, μ (F k)) + ∑ k ∈ t, δ k) + ε / 2 := by
rw [← sum_add_distrib]
gcongr
apply hF
_ ≤ (∑ k ∈ t, μ (F k)) + ε / 2 + ε / 2 := by
gcongr
exact (ENNReal.sum_le_tsum _).trans hδε.le
_ = μ (⋃ k ∈ t, F k) + ε := by
rw [measure_biUnion_finset, add_assoc, ENNReal.add_halves]
exacts [fun k _ n _ hkn => (hsd hkn).mono (hFs k) (hFs n),
fun k _ => (hFc k).measurableSet]
· calc
μ (⋃ n, U n) ≤ ∑' n, μ (U n) := measure_iUnion_le _
_ ≤ ∑' n, (μ (s n) + δ n) := ENNReal.tsum_le_tsum hU
_ = μ (⋃ n, s n) + ∑' n, δ n := by rw [measure_iUnion hsd hsm, ENNReal.tsum_add]
_ ≤ μ (⋃ n, s n) + ε := add_le_add_left (hδε.le.trans ENNReal.half_le_self) _
/-- In a metrizable space (or even a pseudo metrizable space), an open set can be approximated from
inside by closed sets. -/
theorem of_pseudoMetrizableSpace {X : Type*} [TopologicalSpace X] [PseudoMetrizableSpace X]
[MeasurableSpace X] (μ : Measure X) : InnerRegularWRT μ IsClosed IsOpen := by
let A : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X
intro U hU r hr
rcases hU.exists_iUnion_isClosed with ⟨F, F_closed, -, rfl, F_mono⟩
rw [F_mono.measure_iUnion] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
exact ⟨F n, subset_iUnion _ _, F_closed n, hn⟩
/-- In a `σ`-compact space, any closed set can be approximated by a compact subset. -/
theorem isCompact_isClosed {X : Type*} [TopologicalSpace X] [SigmaCompactSpace X]
[MeasurableSpace X] (μ : Measure X) : InnerRegularWRT μ IsCompact IsClosed := by
intro F hF r hr
set B : ℕ → Set X := compactCovering X
have hBc : ∀ n, IsCompact (F ∩ B n) := fun n => (isCompact_compactCovering X n).inter_left hF
have hBU : ⋃ n, F ∩ B n = F := by rw [← inter_iUnion, iUnion_compactCovering, Set.inter_univ]
have : μ F = ⨆ n, μ (F ∩ B n) := by
rw [← Monotone.measure_iUnion, hBU]
exact monotone_const.inter monotone_accumulate
rw [this] at hr
rcases lt_iSup_iff.1 hr with ⟨n, hn⟩
exact ⟨_, inter_subset_left, hBc n, hn⟩
end InnerRegularWRT
namespace InnerRegular
variable [TopologicalSpace α]
/-- The measure of a measurable set is the supremum of the measures of compact sets it contains. -/
theorem _root_.MeasurableSet.measure_eq_iSup_isCompact ⦃U : Set α⦄ (hU : MeasurableSet U)
(μ : Measure α) [InnerRegular μ] :
μ U = ⨆ (K : Set α) (_ : K ⊆ U) (_ : IsCompact K), μ K :=
InnerRegular.innerRegular.measure_eq_iSup hU
instance zero : InnerRegular (0 : Measure α) :=
⟨fun _ _ _r hr => ⟨∅, empty_subset _, isCompact_empty, hr⟩⟩
instance smul [h : InnerRegular μ] (c : ℝ≥0∞) : InnerRegular (c • μ) :=
⟨InnerRegularWRT.smul h.innerRegular c⟩
instance smul_nnreal [InnerRegular μ] (c : ℝ≥0) : InnerRegular (c • μ) := smul (c : ℝ≥0∞)
instance (priority := 100) [InnerRegular μ] : InnerRegularCompactLTTop μ :=
⟨fun _s hs r hr ↦ InnerRegular.innerRegular hs.1 r hr⟩
lemma innerRegularWRT_isClosed_isOpen [R1Space α] [OpensMeasurableSpace α] [h : InnerRegular μ] :
InnerRegularWRT μ IsClosed IsOpen := by
intro U hU r hr
rcases h.innerRegular hU.measurableSet r hr with ⟨K, KU, K_comp, hK⟩
exact ⟨closure K, K_comp.closure_subset_of_isOpen hU KU, isClosed_closure,
hK.trans_le (measure_mono subset_closure)⟩
theorem exists_isCompact_not_null [InnerRegular μ] : (∃ K, IsCompact K ∧ μ K ≠ 0) ↔ μ ≠ 0 := by
simp_rw [Ne, ← measure_univ_eq_zero, MeasurableSet.univ.measure_eq_iSup_isCompact,
ENNReal.iSup_eq_zero, not_forall, exists_prop, subset_univ, true_and]
@[deprecated (since := "2024-11-19")] alias exists_compact_not_null := exists_isCompact_not_null
/-- If `μ` is inner regular, then any measurable set can be approximated by a compact subset.
See also `MeasurableSet.exists_isCompact_lt_add_of_ne_top`. -/
theorem _root_.MeasurableSet.exists_lt_isCompact [InnerRegular μ] ⦃A : Set α⦄
(hA : MeasurableSet A) {r : ℝ≥0∞} (hr : r < μ A) :
∃ K, K ⊆ A ∧ IsCompact K ∧ r < μ K :=
InnerRegular.innerRegular hA _ hr
protected theorem map_of_continuous [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [h : InnerRegular μ] {f : α → β} (hf : Continuous f) :
InnerRegular (Measure.map f μ) :=
⟨InnerRegularWRT.map h.innerRegular hf.aemeasurable (fun _s hs ↦ hf.measurable hs)
(fun _K hK ↦ hK.image hf) (fun _s hs ↦ hs)⟩
protected theorem map [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [InnerRegular μ] (f : α ≃ₜ β) : (Measure.map f μ).InnerRegular :=
InnerRegular.map_of_continuous f.continuous
protected theorem map_iff [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] (f : α ≃ₜ β) :
InnerRegular (Measure.map f μ) ↔ InnerRegular μ := by
refine ⟨fun h ↦ ?_, fun h ↦ h.map f⟩
convert h.map f.symm
rw [map_map f.symm.continuous.measurable f.continuous.measurable]
simp
end InnerRegular
namespace InnerRegularCompactLTTop
variable [TopologicalSpace α]
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_lt_isCompact_of_ne_top`. -/
theorem _root_.MeasurableSet.exists_isCompact_lt_add [InnerRegularCompactLTTop μ]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ μ A < μ K + ε :=
InnerRegularCompactLTTop.innerRegular.exists_subset_lt_add isCompact_empty ⟨hA, h'A⟩ h'A hε
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a compact closed subset.
Compared to `MeasurableSet.exists_isCompact_lt_add`,
this version additionally assumes that `α` is an R₁ space with Borel σ-algebra.
-/
theorem _root_.MeasurableSet.exists_isCompact_isClosed_lt_add
[InnerRegularCompactLTTop μ] [R1Space α] [BorelSpace α]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ IsClosed K ∧ μ A < μ K + ε :=
let ⟨K, hKA, hK, hμK⟩ := hA.exists_isCompact_lt_add h'A hε
⟨closure K, hK.closure_subset_measurableSet hA hKA, hK.closure, isClosed_closure,
by rwa [hK.measure_closure]⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_isCompact_lt_add` and
`MeasurableSet.exists_lt_isCompact_of_ne_top`. -/
theorem _root_.MeasurableSet.exists_isCompact_diff_lt [OpensMeasurableSpace α] [T2Space α]
[InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ μ (A \ K) < ε := by
rcases hA.exists_isCompact_lt_add h'A hε with ⟨K, hKA, hKc, hK⟩
exact ⟨K, hKA, hKc, measure_diff_lt_of_lt_add hKc.nullMeasurableSet hKA
(ne_top_of_le_ne_top h'A <| measure_mono hKA) hK⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a compact closed subset.
Compared to `MeasurableSet.exists_isCompact_diff_lt`,
this lemma additionally assumes that `α` is an R₁ space with Borel σ-algebra. -/
theorem _root_.MeasurableSet.exists_isCompact_isClosed_diff_lt [BorelSpace α] [R1Space α]
[InnerRegularCompactLTTop μ] ⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ A ∧ IsCompact K ∧ IsClosed K ∧ μ (A \ K) < ε := by
rcases hA.exists_isCompact_isClosed_lt_add h'A hε with ⟨K, hKA, hKco, hKcl, hK⟩
exact ⟨K, hKA, hKco, hKcl, measure_diff_lt_of_lt_add hKcl.nullMeasurableSet hKA
(ne_top_of_le_ne_top h'A <| measure_mono hKA) hK⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated by a
compact subset. See also `MeasurableSet.exists_isCompact_lt_add`. -/
theorem _root_.MeasurableSet.exists_lt_isCompact_of_ne_top [InnerRegularCompactLTTop μ] ⦃A : Set α⦄
(hA : MeasurableSet A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) :
∃ K, K ⊆ A ∧ IsCompact K ∧ r < μ K :=
InnerRegularCompactLTTop.innerRegular ⟨hA, h'A⟩ _ hr
/-- If `μ` is inner regular for finite measure sets with respect to compact sets,
any measurable set of finite mass can be approximated from inside by compact sets. -/
theorem _root_.MeasurableSet.measure_eq_iSup_isCompact_of_ne_top [InnerRegularCompactLTTop μ]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) :
μ A = ⨆ (K) (_ : K ⊆ A) (_ : IsCompact K), μ K :=
InnerRegularCompactLTTop.innerRegular.measure_eq_iSup ⟨hA, h'A⟩
/-- If `μ` is inner regular for finite measure sets with respect to compact sets, then its
restriction to any set also is. -/
instance restrict [h : InnerRegularCompactLTTop μ] (A : Set α) :
InnerRegularCompactLTTop (μ.restrict A) :=
⟨InnerRegularWRT.restrict h.innerRegular A⟩
instance (priority := 50) [h : InnerRegularCompactLTTop μ] [IsFiniteMeasure μ] :
InnerRegular μ := by
constructor
convert h.innerRegular with s
simp [measure_ne_top μ s]
instance (priority := 50) [BorelSpace α] [R1Space α] [InnerRegularCompactLTTop μ]
[IsFiniteMeasure μ] : WeaklyRegular μ :=
InnerRegular.innerRegularWRT_isClosed_isOpen.weaklyRegular_of_finite _
instance (priority := 50) [BorelSpace α] [R1Space α] [h : InnerRegularCompactLTTop μ]
[IsFiniteMeasure μ] : Regular μ where
innerRegular := InnerRegularWRT.trans h.innerRegular <|
InnerRegularWRT.of_imp (fun U hU ↦ ⟨hU.measurableSet, measure_ne_top μ U⟩)
protected lemma _root_.IsCompact.exists_isOpen_lt_of_lt [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α}
(hK : IsCompact K) (r : ℝ≥0∞) (hr : μ K < r) :
∃ U, K ⊆ U ∧ IsOpen U ∧ μ U < r := by
rcases hK.exists_open_superset_measure_lt_top μ with ⟨V, hKV, hVo, hμV⟩
have := Fact.mk hμV
obtain ⟨U, hKU, hUo, hμU⟩ : ∃ U, K ⊆ U ∧ IsOpen U ∧ μ.restrict V U < r :=
exists_isOpen_lt_of_lt K r <| (restrict_apply_le _ _).trans_lt hr
refine ⟨U ∩ V, subset_inter hKU hKV, hUo.inter hVo, ?_⟩
rwa [restrict_apply hUo.measurableSet] at hμU
/-- If `μ` is inner regular for finite measure sets with respect to compact sets
and is locally finite in an R₁ space,
then any compact set can be approximated from outside by open sets. -/
protected lemma _root_.IsCompact.measure_eq_iInf_isOpen [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α] {K : Set α} (hK : IsCompact K) :
μ K = ⨅ (U : Set α) (_ : K ⊆ U) (_ : IsOpen U), μ U := by
apply le_antisymm
· simp only [le_iInf_iff]
exact fun U KU _ ↦ measure_mono KU
· apply le_of_forall_lt'
simpa only [iInf_lt_iff, exists_prop, exists_and_left] using hK.exists_isOpen_lt_of_lt
protected theorem _root_.IsCompact.exists_isOpen_lt_add [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α]
{K : Set α} (hK : IsCompact K) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, K ⊆ U ∧ IsOpen U ∧ μ U < μ K + ε :=
hK.exists_isOpen_lt_of_lt _ (ENNReal.lt_add_right hK.measure_lt_top.ne hε)
/-- Let `μ` be a locally finite measure on an R₁ topological space with Borel σ-algebra.
If `μ` is inner regular for finite measure sets with respect to compact sets,
then any measurable set of finite measure can be approximated in measure by an open set.
See also `Set.exists_isOpen_lt_of_lt` and `MeasurableSet.exists_isOpen_diff_lt`
for the case of an outer regular measure. -/
protected theorem _root_.MeasurableSet.exists_isOpen_symmDiff_lt [InnerRegularCompactLTTop μ]
[IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α]
{s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, IsOpen U ∧ μ U < ∞ ∧ μ (U ∆ s) < ε := by
have : ε / 2 ≠ 0 := (ENNReal.half_pos hε).ne'
rcases hs.exists_isCompact_isClosed_diff_lt hμs this with ⟨K, hKs, hKco, hKcl, hμK⟩
rcases hKco.exists_isOpen_lt_add (μ := μ) this with ⟨U, hKU, hUo, hμU⟩
refine ⟨U, hUo, hμU.trans_le le_top, ?_⟩
rw [← ENNReal.add_halves ε, measure_symmDiff_eq hUo.nullMeasurableSet hs.nullMeasurableSet]
gcongr
· calc
μ (U \ s) ≤ μ (U \ K) := by gcongr
_ < ε / 2 := by
apply measure_diff_lt_of_lt_add hKcl.nullMeasurableSet hKU _ hμU
exact ne_top_of_le_ne_top hμs (by gcongr)
· exact lt_of_le_of_lt (by gcongr) hμK
/-- Let `μ` be a locally finite measure on an R₁ topological space with Borel σ-algebra.
If `μ` is inner regular for finite measure sets with respect to compact sets,
then any null measurable set of finite measure can be approximated in measure by an open set.
See also `Set.exists_isOpen_lt_of_lt` and `MeasurableSet.exists_isOpen_diff_lt`
for the case of an outer regular measure. -/
protected theorem _root_.MeasureTheory.NullMeasurableSet.exists_isOpen_symmDiff_lt
[InnerRegularCompactLTTop μ] [IsLocallyFiniteMeasure μ] [R1Space α] [BorelSpace α]
{s : Set α} (hs : NullMeasurableSet s μ) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ U, IsOpen U ∧ μ U < ∞ ∧ μ (U ∆ s) < ε := by
rcases hs with ⟨t, htm, hst⟩
rcases htm.exists_isOpen_symmDiff_lt (by rwa [← measure_congr hst]) hε with ⟨U, hUo, hμU, hUs⟩
refine ⟨U, hUo, hμU, ?_⟩
rwa [measure_congr <| (ae_eq_refl _).symmDiff hst]
instance smul [h : InnerRegularCompactLTTop μ] (c : ℝ≥0∞) : InnerRegularCompactLTTop (c • μ) := by
by_cases hc : c = 0
· simp only [hc, zero_smul]
infer_instance
by_cases h'c : c = ∞
· constructor
intro s hs r hr
simp only [h'c, smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply, smul_eq_mul] at hr
by_cases h's : μ s = 0
· simp [h's] at hr
· simp [h'c, ENNReal.mul_eq_top, h's] at hs
· constructor
convert InnerRegularWRT.smul h.innerRegular c using 2 with s
have : (c • μ) s ≠ ∞ ↔ μ s ≠ ∞ := by simp [not_iff_not, ENNReal.mul_eq_top, hc, h'c]
simp only [this]
instance smul_nnreal [InnerRegularCompactLTTop μ] (c : ℝ≥0) :
InnerRegularCompactLTTop (c • μ) :=
inferInstanceAs (InnerRegularCompactLTTop ((c : ℝ≥0∞) • μ))
instance (priority := 80) [InnerRegularCompactLTTop μ] [SigmaFinite μ] : InnerRegular μ :=
⟨InnerRegularCompactLTTop.innerRegular.trans InnerRegularWRT.of_sigmaFinite⟩
protected theorem map_of_continuous [BorelSpace α] [MeasurableSpace β] [TopologicalSpace β]
[BorelSpace β] [h : InnerRegularCompactLTTop μ] {f : α → β} (hf : Continuous f) :
InnerRegularCompactLTTop (Measure.map f μ) := by
constructor
refine InnerRegularWRT.map h.innerRegular hf.aemeasurable ?_ (fun K hK ↦ hK.image hf) ?_
· rintro s ⟨hs, h's⟩
exact ⟨hf.measurable hs, by rwa [map_apply hf.measurable hs] at h's⟩
· rintro s ⟨hs, -⟩
exact hs
end InnerRegularCompactLTTop
-- Generalized and moved to another file
namespace WeaklyRegular
variable [TopologicalSpace α]
instance zero : WeaklyRegular (0 : Measure α) :=
⟨fun _ _ _r hr => ⟨∅, empty_subset _, isClosed_empty, hr⟩⟩
/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/
theorem _root_.IsOpen.exists_lt_isClosed [WeaklyRegular μ] ⦃U : Set α⦄ (hU : IsOpen U) {r : ℝ≥0∞}
(hr : r < μ U) : ∃ F, F ⊆ U ∧ IsClosed F ∧ r < μ F :=
WeaklyRegular.innerRegular hU r hr
/-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/
theorem _root_.IsOpen.measure_eq_iSup_isClosed ⦃U : Set α⦄ (hU : IsOpen U) (μ : Measure α)
[WeaklyRegular μ] : μ U = ⨆ (F) (_ : F ⊆ U) (_ : IsClosed F), μ F :=
WeaklyRegular.innerRegular.measure_eq_iSup hU
theorem innerRegular_measurable [WeaklyRegular μ] :
InnerRegularWRT μ IsClosed fun s => MeasurableSet s ∧ μ s ≠ ∞ :=
WeaklyRegular.innerRegular.measurableSet_of_isOpen (fun _ _ h₁ h₂ ↦ h₁.inter h₂.isClosed_compl)
/-- If `s` is a measurable set, a weakly regular measure `μ` is finite on `s`, and `ε` is a positive
number, then there exist a closed set `K ⊆ s` such that `μ s < μ K + ε`. -/
theorem _root_.MeasurableSet.exists_isClosed_lt_add [WeaklyRegular μ] {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ K, K ⊆ s ∧ IsClosed K ∧ μ s < μ K + ε :=
innerRegular_measurable.exists_subset_lt_add isClosed_empty ⟨hs, hμs⟩ hμs hε
theorem _root_.MeasurableSet.exists_isClosed_diff_lt [OpensMeasurableSpace α] [WeaklyRegular μ]
⦃A : Set α⦄ (hA : MeasurableSet A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) :
∃ F, F ⊆ A ∧ IsClosed F ∧ μ (A \ F) < ε := by
rcases hA.exists_isClosed_lt_add h'A hε with ⟨F, hFA, hFc, hF⟩
exact ⟨F, hFA, hFc, measure_diff_lt_of_lt_add hFc.nullMeasurableSet hFA
(ne_top_of_le_ne_top h'A <| measure_mono hFA) hF⟩
/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from
inside by closed sets. -/
theorem _root_.MeasurableSet.exists_lt_isClosed_of_ne_top [WeaklyRegular μ] ⦃A : Set α⦄
(hA : MeasurableSet A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) :
∃ K, K ⊆ A ∧ IsClosed K ∧ r < μ K :=
innerRegular_measurable ⟨hA, h'A⟩ _ hr
/-- Given a weakly regular measure, any measurable set of finite mass can be approximated from
inside by closed sets. -/
theorem _root_.MeasurableSet.measure_eq_iSup_isClosed_of_ne_top [WeaklyRegular μ] ⦃A : Set α⦄
(hA : MeasurableSet A) (h'A : μ A ≠ ∞) : μ A = ⨆ (K) (_ : K ⊆ A) (_ : IsClosed K), μ K :=
innerRegular_measurable.measure_eq_iSup ⟨hA, h'A⟩
|
/-- The restriction of a weakly regular measure to a measurable set of finite measure is
weakly regular. -/
| Mathlib/MeasureTheory/Measure/Regular.lean | 934 | 936 |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll, Anatole Dedecker
-/
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Analysis.Seminorm
import Mathlib.Data.Real.Sqrt
import Mathlib.Topology.Algebra.Equicontinuity
import Mathlib.Topology.MetricSpace.Equicontinuity
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.Module.LocallyConvex
/-!
# Topology induced by a family of seminorms
## Main definitions
* `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms.
* `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls.
* `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be
bounded by a finite number of seminorms in `E`.
## Main statements
* `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally
convex.
* `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a
countable family of seminorms.
## Continuity of semilinear maps
If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then
we have a direct method to prove that a linear map is continuous:
* `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous.
If the topology of a space `E` is induced by a family of seminorms, then we can characterize von
Neumann boundedness in terms of that seminorm family. Together with
`LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity.
* `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.isVonNBounded_iff_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded`
* `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded`
## Tags
seminorm, locally convex
-/
open NormedField Set Seminorm TopologicalSpace Filter List
open NNReal Pointwise Topology Uniformity
variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*}
section FilterBasis
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E]
variable (𝕜 E ι)
/-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/
abbrev SeminormFamily :=
ι → Seminorm 𝕜 E
variable {𝕜 E ι}
namespace SeminormFamily
/-- The sets of a filter basis for the neighborhood filter of 0. -/
def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) :=
⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r)
variable (p : SeminormFamily 𝕜 E ι)
theorem basisSets_iff {U : Set E} :
U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by
simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff]
theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets :=
(basisSets_iff _).mpr ⟨i, _, hr, rfl⟩
theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets :=
(basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩
theorem basisSets_nonempty [Nonempty ι] : p.basisSets.Nonempty := by
let i := Classical.arbitrary ι
refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩
exact p.basisSets_singleton_mem i zero_lt_one
theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) :
∃ z ∈ p.basisSets, z ⊆ U ∩ V := by
classical
rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩
rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩
use ((s ∪ t).sup p).ball 0 (min r₁ r₂)
refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩
rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩),
ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂]
exact
Set.subset_inter
(Set.iInter₂_mono' fun i hi =>
⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩)
(Set.iInter₂_mono' fun i hi =>
⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩)
theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by
rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩
rw [hU, mem_ball_zero, map_zero]
exact hr
theorem basisSets_add (U) (hU : U ∈ p.basisSets) :
∃ V ∈ p.basisSets, V + V ⊆ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
use (s.sup p).ball 0 (r / 2)
refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩
refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_
rw [hU, add_zero, add_halves]
theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) :
∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by
rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩
rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero]
exact ⟨U, hU', Eq.subset hU⟩
/-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
protected def addGroupFilterBasis [Nonempty ι] : AddGroupFilterBasis E :=
addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero
p.basisSets_add p.basisSets_neg
theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) :
∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
rw [hU, Filter.eventually_iff]
simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul]
by_cases h : 0 < (s.sup p) v
· simp_rw [(lt_div_iff₀ h).symm]
rw [← _root_.ball_zero_eq]
exact Metric.ball_mem_nhds 0 (div_pos hr h)
simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr]
exact IsOpen.mem_nhds isOpen_univ (mem_univ 0)
variable [Nonempty ι]
theorem basisSets_smul (U) (hU : U ∈ p.basisSets) :
∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩
refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩
refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_
rw [hU, Real.mul_self_sqrt (le_of_lt hr)]
theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) :
∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by
rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩
rw [hU]
by_cases h : x ≠ 0
· rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero]
use (s.sup p).ball 0 (r / ‖x‖)
exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩
refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩
simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff,
preimage_const_of_mem, zero_smul]
/-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/
protected def moduleFilterBasis : ModuleFilterBasis 𝕜 E where
toAddGroupFilterBasis := p.addGroupFilterBasis
| smul' := p.basisSets_smul _
smul_left' := p.basisSets_smul_left
smul_right' := p.basisSets_smul_right
theorem filter_eq_iInf (p : SeminormFamily 𝕜 E ι) :
p.moduleFilterBasis.toFilterBasis.filter = ⨅ i, (𝓝 0).comap (p i) := by
refine le_antisymm (le_iInf fun i => ?_) ?_
· rw [p.moduleFilterBasis.toFilterBasis.hasBasis.le_basis_iff
(Metric.nhds_basis_ball.comap _)]
intro ε hε
refine ⟨(p i).ball 0 ε, ?_, ?_⟩
| Mathlib/Analysis/LocallyConvex/WithSeminorms.lean | 169 | 179 |
/-
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, Johan Commelin, Mario Carneiro
-/
import Mathlib.Data.Finsupp.Lex
import Mathlib.Algebra.MvPolynomial.Degrees
/-!
# Variables of polynomials
This file establishes many results about the variable sets of a multivariate polynomial.
The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$
that appears in a monomial in $P$.
## Main declarations
* `MvPolynomial.vars p` : the finset of variables occurring in `p`.
For example if `p = x⁴y+yz` then `vars p = {x, y, z}`
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Vars
/-! ### `vars` -/
/-- `vars p` is the set of variables appearing in the polynomial `p` -/
def vars (p : MvPolynomial σ R) : Finset σ :=
letI := Classical.decEq σ
p.degrees.toFinset
theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by
rw [vars]
convert rfl
@[simp]
theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by
classical rw [vars_def, degrees_zero, Multiset.toFinset_zero]
@[simp]
theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by
classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset]
@[simp]
theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by
classical rw [vars_def, degrees_C, Multiset.toFinset_zero]
@[simp]
theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by
rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)]
theorem mem_vars (i : σ) : i ∈ p.vars ↔ ∃ d ∈ p.support, i ∈ d.support := by
classical simp only [vars_def, Multiset.mem_toFinset, mem_degrees, mem_support_iff, exists_prop]
theorem mem_support_not_mem_vars_zero {f : MvPolynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support)
{v : σ} (h : v ∉ vars f) : x v = 0 := by
contrapose! h
exact (mem_vars v).mpr ⟨x, H, Finsupp.mem_support_iff.mpr h⟩
theorem vars_add_subset [DecidableEq σ] (p q : MvPolynomial σ R) :
(p + q).vars ⊆ p.vars ∪ q.vars := by
intro x hx
simp only [vars_def, Finset.mem_union, Multiset.mem_toFinset] at hx ⊢
simpa using Multiset.mem_of_le degrees_add_le hx
theorem vars_add_of_disjoint [DecidableEq σ] (h : Disjoint p.vars q.vars) :
(p + q).vars = p.vars ∪ q.vars := by
refine (vars_add_subset p q).antisymm fun x hx => ?_
simp only [vars_def, Multiset.disjoint_toFinset] at h hx ⊢
rwa [degrees_add_of_disjoint h, Multiset.toFinset_union]
section Mul
theorem vars_mul [DecidableEq σ] (φ ψ : MvPolynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars := by
simp_rw [vars_def, ← Multiset.toFinset_add, Multiset.toFinset_subset]
exact Multiset.subset_of_le degrees_mul_le
@[simp]
theorem vars_one : (1 : MvPolynomial σ R).vars = ∅ :=
vars_C
theorem vars_pow (φ : MvPolynomial σ R) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars := by
classical
induction n with
| zero => simp
| succ n ih =>
rw [pow_succ']
apply Finset.Subset.trans (vars_mul _ _)
exact Finset.union_subset (Finset.Subset.refl _) ih
/-- The variables of the product of a family of polynomials
are a subset of the union of the sets of variables of each polynomial.
-/
theorem vars_prod {ι : Type*} [DecidableEq σ] {s : Finset ι} (f : ι → MvPolynomial σ R) :
(∏ i ∈ s, f i).vars ⊆ s.biUnion fun i => (f i).vars := by
classical
induction s using Finset.induction_on with
| empty => simp
| insert _ _ hs hsub =>
simp only [hs, Finset.biUnion_insert, Finset.prod_insert, not_false_iff]
apply Finset.Subset.trans (vars_mul _ _)
exact Finset.union_subset_union (Finset.Subset.refl _) hsub
section IsDomain
variable {A : Type*} [CommRing A] [NoZeroDivisors A]
theorem vars_C_mul (a : A) (ha : a ≠ 0) (φ : MvPolynomial σ A) :
(C a * φ : MvPolynomial σ A).vars = φ.vars := by
ext1 i
simp only [mem_vars, exists_prop, mem_support_iff]
apply exists_congr
intro d
apply and_congr _ Iff.rfl
rw [coeff_C_mul, mul_ne_zero_iff, eq_true ha, true_and]
end IsDomain
end Mul
section Sum
variable {ι : Type*} (t : Finset ι) (φ : ι → MvPolynomial σ R)
theorem vars_sum_subset [DecidableEq σ] :
(∑ i ∈ t, φ i).vars ⊆ Finset.biUnion t fun i => (φ i).vars := by
classical
induction t using Finset.induction_on with
| empty => simp
| insert _ _ has hsum =>
rw [Finset.biUnion_insert, Finset.sum_insert has]
refine Finset.Subset.trans
(vars_add_subset _ _) (Finset.union_subset_union (Finset.Subset.refl _) ?_)
assumption
theorem vars_sum_of_disjoint [DecidableEq σ] (h : Pairwise <| (Disjoint on fun i => (φ i).vars)) :
(∑ i ∈ t, φ i).vars = Finset.biUnion t fun i => (φ i).vars := by
classical
induction t using Finset.induction_on with
| empty => simp
| insert _ _ has hsum =>
rw [Finset.biUnion_insert, Finset.sum_insert has, vars_add_of_disjoint, hsum]
unfold Pairwise onFun at h
rw [hsum]
simp only [Finset.disjoint_iff_ne] at h ⊢
intro v hv v2 hv2
rw [Finset.mem_biUnion] at hv2
rcases hv2 with ⟨i, his, hi⟩
refine h ?_ _ hv _ hi
rintro rfl
contradiction
end Sum
section Map
variable [CommSemiring S] (f : R →+* S)
variable (p)
theorem vars_map : (map f p).vars ⊆ p.vars := by
classical simp [vars_def, Multiset.subset_of_le degrees_map_le]
variable {f}
theorem vars_map_of_injective (hf : Injective f) : (map f p).vars = p.vars := by
simp [vars, degrees_map_of_injective _ hf]
theorem vars_monomial_single (i : σ) {e : ℕ} {r : R} (he : e ≠ 0) (hr : r ≠ 0) :
(monomial (Finsupp.single i e) r).vars = {i} := by
rw [vars_monomial hr, Finsupp.support_single_ne_zero _ he]
theorem vars_eq_support_biUnion_support [DecidableEq σ] :
p.vars = p.support.biUnion Finsupp.support := by
ext i
rw [mem_vars, Finset.mem_biUnion]
end Map
end Vars
section EvalVars
/-! ### `vars` and `eval` -/
variable [CommSemiring S]
theorem eval₂Hom_eq_constantCoeff_of_vars (f : R →+* S) {g : σ → S} {p : MvPolynomial σ R}
(hp : ∀ i ∈ p.vars, g i = 0) : eval₂Hom f g p = f (constantCoeff p) := by
conv_lhs => rw [p.as_sum]
simp only [map_sum, eval₂Hom_monomial]
by_cases h0 : constantCoeff p = 0
on_goal 1 =>
| rw [h0, f.map_zero, Finset.sum_eq_zero]
intro d hd
on_goal 2 =>
rw [Finset.sum_eq_single (0 : σ →₀ ℕ)]
| Mathlib/Algebra/MvPolynomial/Variables.lean | 231 | 234 |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.PowerSeries.Basic
/-! # Formal power series (in one variable) - Order
The `PowerSeries.order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`.
If the coefficients form an integral domain, then `PowerSeries.order` is an
additive valuation (`PowerSeries.order_mul`, `PowerSeries.min_order_le_order_add`).
We prove that if the commutative ring `R` of coefficients is an integral domain,
then the ring `R⟦X⟧` of formal power series in one variable over `R`
is an integral domain.
Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order. This is useful when
proving that `R⟦X⟧` is a normalization monoid, which is done in `PowerSeries.Inverse`.
-/
noncomputable section
open Polynomial
open Finset (antidiagonal mem_antidiagonal)
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section OrderBasic
variable [Semiring R] {φ : R⟦X⟧}
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
refine not_iff_not.mp ?_
push_neg
simp [(coeff R _).map_zero]
/-- The order of a formal power series `φ` is the greatest `n : PartENat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
def order (φ : R⟦X⟧) : ℕ∞ :=
letI := Classical.decEq R
letI := Classical.decEq R⟦X⟧
if h : φ = 0 then ⊤ else Nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h)
/-- The order of the `0` power series is infinite. -/
@[simp]
theorem order_zero : order (0 : R⟦X⟧) = ⊤ :=
dif_pos rfl
theorem order_finite_iff_ne_zero : (order φ < ⊤) ↔ φ ≠ 0 := by
simp only [order]
split_ifs with h <;> simpa
/-- The `0` power series is the unique power series with infinite order. -/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
simpa using order_finite_iff_ne_zero.not_left
theorem coe_toNat_order {φ : R⟦X⟧} (hf : φ ≠ 0) : φ.order.toNat = φ.order := by
rw [ENat.coe_toNat_eq_self.mpr (order_eq_top.not.mpr hf)]
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero. -/
theorem coeff_order (h : φ ≠ 0) : coeff R φ.order.toNat φ ≠ 0 := by
classical
simp only [order, h, not_false_iff, dif_neg]
generalize_proofs h
exact Nat.find_spec h
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`. -/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
classical
rw [order, dif_neg]
· simpa using ⟨n, le_rfl, h⟩
· exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series. -/
theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by
contrapose! h
exact order_le _ h
theorem coeff_of_lt_order_toNat (n : ℕ) (h : n < φ.order.toNat) : coeff R n φ = 0 := by
by_cases h' : φ = 0
· simp [h']
· refine coeff_of_lt_order _ ?_
rwa [← coe_toNat_order h', ENat.coe_lt_coe]
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`. -/
theorem nat_le_order (φ : R⟦X⟧) (n : ℕ) (h : ∀ i < n, coeff R i φ = 0) : ↑n ≤ order φ := by
classical
simp only [order]
split_ifs
· simp
· simpa [Nat.le_find_iff]
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`. -/
theorem le_order (φ : R⟦X⟧) (n : ℕ∞) (h : ∀ i : ℕ, ↑i < n → coeff R i φ = 0) :
n ≤ order φ := by
cases n with
| top => simpa using ext (by simpa using h)
| coe n =>
convert nat_le_order φ n _
simpa using h
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`. -/
theorem order_eq_nat {φ : R⟦X⟧} {n : ℕ} :
order φ = n ↔ coeff R n φ ≠ 0 ∧ ∀ i, i < n → coeff R i φ = 0 := by
classical
rcases eq_or_ne φ 0 with (rfl | hφ)
· simp
simp [order, dif_neg hφ, Nat.find_eq_iff]
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`. -/
theorem order_eq {φ : R⟦X⟧} {n : ℕ∞} :
order φ = n ↔ (∀ i : ℕ, ↑i = n → coeff R i φ ≠ 0) ∧ ∀ i : ℕ, ↑i < n → coeff R i φ = 0 := by
cases n with
| top => simp [ext_iff]
| coe n => simp [order_eq_nat]
/-- The order of the sum of two formal power series
is at least the minimum of their orders. -/
theorem min_order_le_order_add (φ ψ : R⟦X⟧) : min (order φ) (order ψ) ≤ order (φ + ψ) := by
refine le_order _ _ ?_
simp +contextual [coeff_of_lt_order]
@[deprecated (since := "2024-11-12")] alias le_order_add := min_order_le_order_add
private theorem order_add_of_order_eq.aux (φ ψ : R⟦X⟧)
(H : order φ < order ψ) : order (φ + ψ) ≤ order φ ⊓ order ψ := by
suffices order (φ + ψ) = order φ by
rw [le_inf_iff, this]
exact ⟨le_rfl, le_of_lt H⟩
rw [order_eq]
constructor
· intro i hi
rw [← hi] at H
rw [(coeff _ _).map_add, coeff_of_lt_order i H, add_zero]
exact (order_eq_nat.1 hi.symm).1
· intro i hi
rw [(coeff _ _).map_add, coeff_of_lt_order i hi, coeff_of_lt_order i (lt_trans hi H),
zero_add]
/-- The order of the sum of two formal power series
is the minimum of their orders if their orders differ. -/
theorem order_add_of_order_eq (φ ψ : R⟦X⟧) (h : order φ ≠ order ψ) :
order (φ + ψ) = order φ ⊓ order ψ := by
refine le_antisymm ?_ (min_order_le_order_add _ _)
rcases h.lt_or_lt with (φ_lt_ψ | ψ_lt_φ)
· apply order_add_of_order_eq.aux _ _ φ_lt_ψ
· simpa only [add_comm, inf_comm] using order_add_of_order_eq.aux _ _ ψ_lt_φ
/-- The order of the product of two formal power series
is at least the sum of their orders. -/
theorem le_order_mul (φ ψ : R⟦X⟧) : order φ + order ψ ≤ order (φ * ψ) := by
apply le_order
intro n hn; rw [coeff_mul, Finset.sum_eq_zero]
rintro ⟨i, j⟩ hij
by_cases hi : ↑i < order φ
· rw [coeff_of_lt_order i hi, zero_mul]
by_cases hj : ↑j < order ψ
· rw [coeff_of_lt_order j hj, mul_zero]
rw [not_lt] at hi hj; rw [mem_antidiagonal] at hij
exfalso
apply ne_of_lt (lt_of_lt_of_le hn <| add_le_add hi hj)
rw [← Nat.cast_add, hij]
theorem le_order_pow (φ : R⟦X⟧) (n : ℕ) : n • order φ ≤ order (φ ^ n) := by
induction n with
| zero => simp
| succ n hn =>
simp only [add_smul, one_smul, pow_succ]
apply le_trans _ (le_order_mul _ _)
exact add_le_add_right hn φ.order
alias order_mul_ge := le_order_mul
/-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise. -/
theorem order_monomial (n : ℕ) (a : R) [Decidable (a = 0)] :
order (monomial R n a) = if a = 0 then (⊤ : ℕ∞) else n := by
split_ifs with h
· rw [h, order_eq_top, LinearMap.map_zero]
· rw [order_eq]
constructor <;> intro i hi
· simp only [Nat.cast_inj] at hi
rwa [hi, coeff_monomial_same]
· simp only [Nat.cast_lt] at hi
rw [coeff_monomial, if_neg]
exact ne_of_lt hi
/-- The order of the monomial `a*X^n` is `n` if `a ≠ 0`. -/
theorem order_monomial_of_ne_zero (n : ℕ) (a : R) (h : a ≠ 0) : order (monomial R n a) = n := by
classical
rw [order_monomial, if_neg h]
/-- If `n` is strictly smaller than the order of `ψ`, then the `n`th coefficient of its product
with any other power series is `0`. -/
theorem coeff_mul_of_lt_order {φ ψ : R⟦X⟧} {n : ℕ} (h : ↑n < ψ.order) :
coeff R n (φ * ψ) = 0 := by
suffices coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, 0 by rw [this, Finset.sum_const_zero]
rw [coeff_mul]
apply Finset.sum_congr rfl
intro x hx
refine mul_eq_zero_of_right (coeff R x.fst φ) (coeff_of_lt_order x.snd (lt_of_le_of_lt ?_ h))
rw [mem_antidiagonal] at hx
norm_cast
omega
theorem coeff_mul_one_sub_of_lt_order {R : Type*} [Ring R] {φ ψ : R⟦X⟧} (n : ℕ)
(h : ↑n < ψ.order) : coeff R n (φ * (1 - ψ)) = coeff R n φ := by
simp [coeff_mul_of_lt_order h, mul_sub]
theorem coeff_mul_prod_one_sub_of_lt_order {R ι : Type*} [CommRing R] (k : ℕ) (s : Finset ι)
(φ : R⟦X⟧) (f : ι → R⟦X⟧) :
(∀ i ∈ s, ↑k < (f i).order) → coeff R k (φ * ∏ i ∈ s, (1 - f i)) = coeff R k φ := by
classical
induction' s using Finset.induction_on with a s ha ih t
· simp
· intro t
simp only [Finset.mem_insert, forall_eq_or_imp] at t
rw [Finset.prod_insert ha, ← mul_assoc, mul_right_comm, coeff_mul_one_sub_of_lt_order _ t.1]
exact ih t.2
/-- Given a non-zero power series `f`, `divXPowOrder f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order -/
def divXPowOrder (f : R⟦X⟧) : R⟦X⟧ :=
.mk fun n ↦ coeff R (n + f.order.toNat) f
@[deprecated (since := "2025-04-15")]
noncomputable alias divided_by_X_pow_order := divXPowOrder
@[simp]
lemma coeff_divXPowOrder {f : R⟦X⟧} {n : ℕ} :
| coeff R n (divXPowOrder f) = coeff R (n + f.order.toNat) f :=
coeff_mk _ _
@[simp]
lemma divXPowOrder_zero :
divXPowOrder (0 : R⟦X⟧) = 0 := by
ext
simp
lemma constantCoeff_divXPowOrder {f : R⟦X⟧} :
| Mathlib/RingTheory/PowerSeries/Order.lean | 250 | 259 |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Integral.IntegrableOn
/-!
# Locally integrable functions
A function is called *locally integrable* (`MeasureTheory.LocallyIntegrable`) if it is integrable
on a neighborhood of every point. More generally, it is *locally integrable on `s`* if it is
locally integrable on a neighbourhood within `s` of any point of `s`.
This file contains properties of locally integrable functions, and integrability results
on compact sets.
## Main statements
* `Continuous.locallyIntegrable`: A continuous function is locally integrable.
* `ContinuousOn.locallyIntegrableOn`: A function which is continuous on `s` is locally
integrable on `s`.
-/
open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Bornology
open scoped Topology Interval ENNReal
variable {X Y E F R : Type*} [MeasurableSpace X] [TopologicalSpace X]
variable [MeasurableSpace Y] [TopologicalSpace Y]
variable [NormedAddCommGroup E] [NormedAddCommGroup F] {f g : X → E} {μ : Measure X} {s : Set X}
namespace MeasureTheory
section LocallyIntegrableOn
/-- A function `f : X → E` is *locally integrable on s*, for `s ⊆ X`, if for every `x ∈ s` there is
a neighbourhood of `x` within `s` on which `f` is integrable. (Note this is, in general, strictly
weaker than local integrability with respect to `μ.restrict s`.) -/
def LocallyIntegrableOn (f : X → E) (s : Set X) (μ : Measure X := by volume_tac) : Prop :=
∀ x : X, x ∈ s → IntegrableAtFilter f (𝓝[s] x) μ
theorem LocallyIntegrableOn.mono_set (hf : LocallyIntegrableOn f s μ) {t : Set X}
(hst : t ⊆ s) : LocallyIntegrableOn f t μ := fun x hx =>
(hf x <| hst hx).filter_mono (nhdsWithin_mono x hst)
theorem LocallyIntegrableOn.norm (hf : LocallyIntegrableOn f s μ) :
LocallyIntegrableOn (fun x => ‖f x‖) s μ := fun t ht =>
let ⟨U, hU_nhd, hU_int⟩ := hf t ht
⟨U, hU_nhd, hU_int.norm⟩
theorem LocallyIntegrableOn.mono (hf : LocallyIntegrableOn f s μ) {g : X → F}
(hg : AEStronglyMeasurable g μ) (h : ∀ᵐ x ∂μ, ‖g x‖ ≤ ‖f x‖) :
LocallyIntegrableOn g s μ := by
intro x hx
rcases hf x hx with ⟨t, t_mem, ht⟩
exact ⟨t, t_mem, Integrable.mono ht hg.restrict (ae_restrict_of_ae h)⟩
theorem IntegrableOn.locallyIntegrableOn (hf : IntegrableOn f s μ) : LocallyIntegrableOn f s μ :=
fun _ _ => ⟨s, self_mem_nhdsWithin, hf⟩
/-- If a function is locally integrable on a compact set, then it is integrable on that set. -/
theorem LocallyIntegrableOn.integrableOn_isCompact (hf : LocallyIntegrableOn f s μ)
(hs : IsCompact s) : IntegrableOn f s μ :=
IsCompact.induction_on hs integrableOn_empty (fun _u _v huv hv => hv.mono_set huv)
(fun _u _v hu hv => integrableOn_union.mpr ⟨hu, hv⟩) hf
theorem LocallyIntegrableOn.integrableOn_compact_subset (hf : LocallyIntegrableOn f s μ) {t : Set X}
(hst : t ⊆ s) (ht : IsCompact t) : IntegrableOn f t μ :=
(hf.mono_set hst).integrableOn_isCompact ht
/-- If a function `f` is locally integrable on a set `s` in a second countable topological space,
then there exist countably many open sets `u` covering `s` such that `f` is integrable on each
set `u ∩ s`. -/
theorem LocallyIntegrableOn.exists_countable_integrableOn [SecondCountableTopology X]
(hf : LocallyIntegrableOn f s μ) : ∃ T : Set (Set X), T.Countable ∧
(∀ u ∈ T, IsOpen u) ∧ (s ⊆ ⋃ u ∈ T, u) ∧ (∀ u ∈ T, IntegrableOn f (u ∩ s) μ) := by
have : ∀ x : s, ∃ u, IsOpen u ∧ x.1 ∈ u ∧ IntegrableOn f (u ∩ s) μ := by
rintro ⟨x, hx⟩
rcases hf x hx with ⟨t, ht, h't⟩
rcases mem_nhdsWithin.1 ht with ⟨u, u_open, x_mem, u_sub⟩
exact ⟨u, u_open, x_mem, h't.mono_set u_sub⟩
choose u u_open xu hu using this
obtain ⟨T, T_count, hT⟩ : ∃ T : Set s, T.Countable ∧ s ⊆ ⋃ i ∈ T, u i := by
have : s ⊆ ⋃ x : s, u x := fun y hy => mem_iUnion_of_mem ⟨y, hy⟩ (xu ⟨y, hy⟩)
obtain ⟨T, hT_count, hT_un⟩ := isOpen_iUnion_countable u u_open
exact ⟨T, hT_count, by rwa [hT_un]⟩
refine ⟨u '' T, T_count.image _, ?_, by rwa [biUnion_image], ?_⟩
· rintro v ⟨w, -, rfl⟩
exact u_open _
· rintro v ⟨w, -, rfl⟩
exact hu _
/-- If a function `f` is locally integrable on a set `s` in a second countable topological space,
then there exists a sequence of open sets `u n` covering `s` such that `f` is integrable on each
set `u n ∩ s`. -/
theorem LocallyIntegrableOn.exists_nat_integrableOn [SecondCountableTopology X]
(hf : LocallyIntegrableOn f s μ) : ∃ u : ℕ → Set X,
(∀ n, IsOpen (u n)) ∧ (s ⊆ ⋃ n, u n) ∧ (∀ n, IntegrableOn f (u n ∩ s) μ) := by
rcases hf.exists_countable_integrableOn with ⟨T, T_count, T_open, sT, hT⟩
let T' : Set (Set X) := insert ∅ T
have T'_count : T'.Countable := Countable.insert ∅ T_count
have T'_ne : T'.Nonempty := by simp only [T', insert_nonempty]
rcases T'_count.exists_eq_range T'_ne with ⟨u, hu⟩
refine ⟨u, ?_, ?_, ?_⟩
· intro n
have : u n ∈ T' := by rw [hu]; exact mem_range_self n
rcases mem_insert_iff.1 this with h|h
· rw [h]
exact isOpen_empty
· exact T_open _ h
· intro x hx
obtain ⟨v, hv, h'v⟩ : ∃ v, v ∈ T ∧ x ∈ v := by simpa only [mem_iUnion, exists_prop] using sT hx
have : v ∈ range u := by rw [← hu]; exact subset_insert ∅ T hv
obtain ⟨n, rfl⟩ : ∃ n, u n = v := by simpa only [mem_range] using this
exact mem_iUnion_of_mem _ h'v
· intro n
have : u n ∈ T' := by rw [hu]; exact mem_range_self n
rcases mem_insert_iff.1 this with h|h
· simp only [h, empty_inter, integrableOn_empty]
· exact hT _ h
theorem LocallyIntegrableOn.aestronglyMeasurable [SecondCountableTopology X]
(hf : LocallyIntegrableOn f s μ) : AEStronglyMeasurable f (μ.restrict s) := by
rcases hf.exists_nat_integrableOn with ⟨u, -, su, hu⟩
have : s = ⋃ n, u n ∩ s := by rw [← iUnion_inter]; exact (inter_eq_right.mpr su).symm
rw [this, aestronglyMeasurable_iUnion_iff]
exact fun i : ℕ => (hu i).aestronglyMeasurable
/-- If `s` is locally closed (e.g. open or closed), then `f` is locally integrable on `s` iff it is
integrable on every compact subset contained in `s`. -/
theorem locallyIntegrableOn_iff [LocallyCompactSpace X] (hs : IsLocallyClosed s) :
LocallyIntegrableOn f s μ ↔ ∀ (k : Set X), k ⊆ s → IsCompact k → IntegrableOn f k μ := by
refine ⟨fun hf k hk ↦ hf.integrableOn_compact_subset hk, fun hf x hx ↦ ?_⟩
rcases hs with ⟨U, Z, hU, hZ, rfl⟩
rcases exists_compact_subset hU hx.1 with ⟨K, hK, hxK, hKU⟩
rw [nhdsWithin_inter_of_mem (nhdsWithin_le_nhds <| hU.mem_nhds hx.1)]
refine ⟨Z ∩ K, inter_mem_nhdsWithin _ (mem_interior_iff_mem_nhds.1 hxK), ?_⟩
exact hf (Z ∩ K) (fun y hy ↦ ⟨hKU hy.2, hy.1⟩) (.inter_left hK hZ)
protected theorem LocallyIntegrableOn.add
(hf : LocallyIntegrableOn f s μ) (hg : LocallyIntegrableOn g s μ) :
LocallyIntegrableOn (f + g) s μ := fun x hx ↦ (hf x hx).add (hg x hx)
protected theorem LocallyIntegrableOn.sub
(hf : LocallyIntegrableOn f s μ) (hg : LocallyIntegrableOn g s μ) :
LocallyIntegrableOn (f - g) s μ := fun x hx ↦ (hf x hx).sub (hg x hx)
protected theorem LocallyIntegrableOn.neg (hf : LocallyIntegrableOn f s μ) :
LocallyIntegrableOn (-f) s μ := fun x hx ↦ (hf x hx).neg
end LocallyIntegrableOn
/-- A function `f : X → E` is *locally integrable* if it is integrable on a neighborhood of every
point. In particular, it is integrable on all compact sets,
see `LocallyIntegrable.integrableOn_isCompact`. -/
def LocallyIntegrable (f : X → E) (μ : Measure X := by volume_tac) : Prop :=
∀ x : X, IntegrableAtFilter f (𝓝 x) μ
theorem locallyIntegrable_comap (hs : MeasurableSet s) :
LocallyIntegrable (fun x : s ↦ f x) (μ.comap Subtype.val) ↔ LocallyIntegrableOn f s μ := by
simp_rw [LocallyIntegrableOn, Subtype.forall', ← map_nhds_subtype_val]
exact forall_congr' fun _ ↦ (MeasurableEmbedding.subtype_coe hs).integrableAtFilter_iff_comap.symm
theorem locallyIntegrableOn_univ : LocallyIntegrableOn f univ μ ↔ LocallyIntegrable f μ := by
simp only [LocallyIntegrableOn, nhdsWithin_univ, mem_univ, true_imp_iff]; rfl
theorem LocallyIntegrable.locallyIntegrableOn (hf : LocallyIntegrable f μ) (s : Set X) :
LocallyIntegrableOn f s μ := fun x _ => (hf x).filter_mono nhdsWithin_le_nhds
theorem Integrable.locallyIntegrable (hf : Integrable f μ) : LocallyIntegrable f μ := fun _ =>
hf.integrableAtFilter _
theorem LocallyIntegrable.mono (hf : LocallyIntegrable f μ) {g : X → F}
(hg : AEStronglyMeasurable g μ) (h : ∀ᵐ x ∂μ, ‖g x‖ ≤ ‖f x‖) :
LocallyIntegrable g μ := by
rw [← locallyIntegrableOn_univ] at hf ⊢
exact hf.mono hg h
/-- If `f` is locally integrable with respect to `μ.restrict s`, it is locally integrable on `s`.
(See `locallyIntegrableOn_iff_locallyIntegrable_restrict` for an iff statement when `s` is
closed.) -/
theorem locallyIntegrableOn_of_locallyIntegrable_restrict [OpensMeasurableSpace X]
(hf : LocallyIntegrable f (μ.restrict s)) : LocallyIntegrableOn f s μ := by
intro x _
obtain ⟨t, ht_mem, ht_int⟩ := hf x
obtain ⟨u, hu_sub, hu_o, hu_mem⟩ := mem_nhds_iff.mp ht_mem
refine ⟨_, inter_mem_nhdsWithin s (hu_o.mem_nhds hu_mem), ?_⟩
simpa only [IntegrableOn, Measure.restrict_restrict hu_o.measurableSet, inter_comm] using
ht_int.mono_set hu_sub
/-- If `s` is closed, being locally integrable on `s` wrt `μ` is equivalent to being locally
integrable with respect to `μ.restrict s`. For the one-way implication without assuming `s` closed,
see `locallyIntegrableOn_of_locallyIntegrable_restrict`. -/
theorem locallyIntegrableOn_iff_locallyIntegrable_restrict [OpensMeasurableSpace X]
(hs : IsClosed s) : LocallyIntegrableOn f s μ ↔ LocallyIntegrable f (μ.restrict s) := by
refine ⟨fun hf x => ?_, locallyIntegrableOn_of_locallyIntegrable_restrict⟩
by_cases h : x ∈ s
· obtain ⟨t, ht_nhds, ht_int⟩ := hf x h
obtain ⟨u, hu_o, hu_x, hu_sub⟩ := mem_nhdsWithin.mp ht_nhds
refine ⟨u, hu_o.mem_nhds hu_x, ?_⟩
rw [IntegrableOn, restrict_restrict hu_o.measurableSet]
exact ht_int.mono_set hu_sub
· rw [← isOpen_compl_iff] at hs
refine ⟨sᶜ, hs.mem_nhds h, ?_⟩
rw [IntegrableOn, restrict_restrict, inter_comm, inter_compl_self, ← IntegrableOn]
exacts [integrableOn_empty, hs.measurableSet]
/-- If a function is locally integrable, then it is integrable on any compact set. -/
theorem LocallyIntegrable.integrableOn_isCompact {k : Set X} (hf : LocallyIntegrable f μ)
(hk : IsCompact k) : IntegrableOn f k μ :=
(hf.locallyIntegrableOn k).integrableOn_isCompact hk
/-- If a function is locally integrable, then it is integrable on an open neighborhood of any
compact set. -/
theorem LocallyIntegrable.integrableOn_nhds_isCompact (hf : LocallyIntegrable f μ) {k : Set X}
(hk : IsCompact k) : ∃ u, IsOpen u ∧ k ⊆ u ∧ IntegrableOn f u μ := by
refine IsCompact.induction_on hk ?_ ?_ ?_ ?_
· refine ⟨∅, isOpen_empty, Subset.rfl, integrableOn_empty⟩
· rintro s t hst ⟨u, u_open, tu, hu⟩
exact ⟨u, u_open, hst.trans tu, hu⟩
· rintro s t ⟨u, u_open, su, hu⟩ ⟨v, v_open, tv, hv⟩
exact ⟨u ∪ v, u_open.union v_open, union_subset_union su tv, hu.union hv⟩
· intro x _
rcases hf x with ⟨u, ux, hu⟩
rcases mem_nhds_iff.1 ux with ⟨v, vu, v_open, xv⟩
exact ⟨v, nhdsWithin_le_nhds (v_open.mem_nhds xv), v, v_open, Subset.rfl, hu.mono_set vu⟩
theorem locallyIntegrable_iff [LocallyCompactSpace X] :
LocallyIntegrable f μ ↔ ∀ k : Set X, IsCompact k → IntegrableOn f k μ :=
⟨fun hf _k hk => hf.integrableOn_isCompact hk, fun hf x =>
let ⟨K, hK, h2K⟩ := exists_compact_mem_nhds x
⟨K, h2K, hf K hK⟩⟩
theorem LocallyIntegrable.aestronglyMeasurable [SecondCountableTopology X]
(hf : LocallyIntegrable f μ) : AEStronglyMeasurable f μ := by
simpa only [restrict_univ] using (locallyIntegrableOn_univ.mpr hf).aestronglyMeasurable
/-- If a function is locally integrable in a second countable topological space,
then there exists a sequence of open sets covering the space on which it is integrable. -/
theorem LocallyIntegrable.exists_nat_integrableOn [SecondCountableTopology X]
(hf : LocallyIntegrable f μ) : ∃ u : ℕ → Set X,
(∀ n, IsOpen (u n)) ∧ ((⋃ n, u n) = univ) ∧ (∀ n, IntegrableOn f (u n) μ) := by
rcases (hf.locallyIntegrableOn univ).exists_nat_integrableOn with ⟨u, u_open, u_union, hu⟩
refine ⟨u, u_open, eq_univ_of_univ_subset u_union, fun n ↦ ?_⟩
simpa only [inter_univ] using hu n
theorem MemLp.locallyIntegrable [IsLocallyFiniteMeasure μ] {f : X → E} {p : ℝ≥0∞}
(hf : MemLp f p μ) (hp : 1 ≤ p) : LocallyIntegrable f μ := by
intro x
rcases μ.finiteAt_nhds x with ⟨U, hU, h'U⟩
have : Fact (μ U < ⊤) := ⟨h'U⟩
refine ⟨U, hU, ?_⟩
rw [IntegrableOn, ← memLp_one_iff_integrable]
apply (hf.restrict U).mono_exponent hp
@[deprecated (since := "2025-02-21")]
alias Memℒp.locallyIntegrable := MemLp.locallyIntegrable
theorem locallyIntegrable_const [IsLocallyFiniteMeasure μ] (c : E) :
LocallyIntegrable (fun _ => c) μ :=
(memLp_top_const c).locallyIntegrable le_top
theorem locallyIntegrableOn_const [IsLocallyFiniteMeasure μ] (c : E) :
LocallyIntegrableOn (fun _ => c) s μ :=
(locallyIntegrable_const c).locallyIntegrableOn s
theorem locallyIntegrable_zero : LocallyIntegrable (fun _ ↦ (0 : E)) μ :=
(integrable_zero X E μ).locallyIntegrable
theorem locallyIntegrableOn_zero : LocallyIntegrableOn (fun _ ↦ (0 : E)) s μ :=
locallyIntegrable_zero.locallyIntegrableOn s
theorem LocallyIntegrable.indicator (hf : LocallyIntegrable f μ) {s : Set X}
(hs : MeasurableSet s) : LocallyIntegrable (s.indicator f) μ := by
intro x
rcases hf x with ⟨U, hU, h'U⟩
exact ⟨U, hU, h'U.indicator hs⟩
theorem locallyIntegrable_map_homeomorph [BorelSpace X] [BorelSpace Y] (e : X ≃ₜ Y) {f : Y → E}
{μ : Measure X} : LocallyIntegrable f (Measure.map e μ) ↔ LocallyIntegrable (f ∘ e) μ := by
refine ⟨fun h x => ?_, fun h x => ?_⟩
· rcases h (e x) with ⟨U, hU, h'U⟩
refine ⟨e ⁻¹' U, e.continuous.continuousAt.preimage_mem_nhds hU, ?_⟩
exact (integrableOn_map_equiv e.toMeasurableEquiv).1 h'U
· rcases h (e.symm x) with ⟨U, hU, h'U⟩
refine ⟨e.symm ⁻¹' U, e.symm.continuous.continuousAt.preimage_mem_nhds hU, ?_⟩
apply (integrableOn_map_equiv e.toMeasurableEquiv).2
simp only [Homeomorph.toMeasurableEquiv_coe]
convert h'U
ext x
simp only [mem_preimage, Homeomorph.symm_apply_apply]
protected theorem LocallyIntegrable.add (hf : LocallyIntegrable f μ) (hg : LocallyIntegrable g μ) :
LocallyIntegrable (f + g) μ := fun x ↦ (hf x).add (hg x)
protected theorem LocallyIntegrable.sub (hf : LocallyIntegrable f μ) (hg : LocallyIntegrable g μ) :
LocallyIntegrable (f - g) μ := fun x ↦ (hf x).sub (hg x)
protected theorem LocallyIntegrable.neg (hf : LocallyIntegrable f μ) :
LocallyIntegrable (-f) μ := fun x ↦ (hf x).neg
protected theorem LocallyIntegrable.smul {𝕜 : Type*} [NormedAddCommGroup 𝕜] [SMulZeroClass 𝕜 E]
[IsBoundedSMul 𝕜 E] (hf : LocallyIntegrable f μ) (c : 𝕜) :
LocallyIntegrable (c • f) μ := fun x ↦ (hf x).smul c
theorem locallyIntegrable_finset_sum' {ι} (s : Finset ι) {f : ι → X → E}
| (hf : ∀ i ∈ s, LocallyIntegrable (f i) μ) : LocallyIntegrable (∑ i ∈ s, f i) μ :=
Finset.sum_induction f (fun g => LocallyIntegrable g μ) (fun _ _ => LocallyIntegrable.add)
locallyIntegrable_zero hf
theorem locallyIntegrable_finset_sum {ι} (s : Finset ι) {f : ι → X → E}
(hf : ∀ i ∈ s, LocallyIntegrable (f i) μ) : LocallyIntegrable (fun a ↦ ∑ i ∈ s, f i a) μ := by
simpa only [← Finset.sum_apply] using locallyIntegrable_finset_sum' s hf
/-- If `f` is locally integrable and `g` is continuous with compact support,
then `g • f` is integrable. -/
theorem LocallyIntegrable.integrable_smul_left_of_hasCompactSupport
[NormedSpace ℝ E] [OpensMeasurableSpace X] [T2Space X]
(hf : LocallyIntegrable f μ) {g : X → ℝ} (hg : Continuous g) (h'g : HasCompactSupport g) :
| Mathlib/MeasureTheory/Function/LocallyIntegrable.lean | 308 | 320 |
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.FieldTheory.Galois.Basic
/-!
# Cyclotomic extensions
Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ+`, we define a class
`IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th
primitive roots of unity, for all `n ∈ S`.
## Main definitions
* `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive
roots of unity, for all `n ∈ S`.
* `CyclotomicField`: given `n : ℕ+` and a field `K`, we define `CyclotomicField n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance
`IsCyclotomicExtension {n} K (CyclotomicField n K)`.
* `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ+`, we define
`CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of
`X ^ n - 1`. If `n` is nonzero in `A`, it has the instance
`IsCyclotomicExtension {n} A (CyclotomicRing n A K)`.
## Main results
* `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and
`IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if
`Function.Injective (algebraMap B C)`.
* `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then
`IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 }) B`.
* `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then
`IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ+, a ∈ S ∧ b ^ (a : ℕ) = 1 })`.
* `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then
`B` is a finite `A`-algebra.
* `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a
number field.
* `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `X ^ n - 1`.
* `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `cyclotomic n K`.
## Implementation details
Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic
and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains.
All results are in the `IsCyclotomicExtension` namespace.
Note that some results, for example `IsCyclotomicExtension.trans`,
`IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`,
`IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and
`CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are
included in the `Cyclotomic` locale.
-/
open Polynomial Algebra Module Set
universe u v w z
variable (n : ℕ+) (S T : Set ℕ+) (A : Type u) (B : Type v) (K : Type w) (L : Type z)
variable [CommRing A] [CommRing B] [Algebra A B]
variable [Field K] [Field L] [Algebra K L]
noncomputable section
/-- Given an `A`-algebra `B` and `S : Set ℕ+`, we define `IsCyclotomicExtension S A B` requiring
that there is an `n`-th primitive root of unity in `B` for all `n ∈ S` and that `B` is generated
over `A` by the roots of `X ^ n - 1`. -/
@[mk_iff]
class IsCyclotomicExtension : Prop where
/-- For all `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/
exists_prim_root {n : ℕ+} (ha : n ∈ S) : ∃ r : B, IsPrimitiveRoot r n
/-- The `n`-th roots of unity, for `n ∈ S`, generate `B` as an `A`-algebra. -/
adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1}
namespace IsCyclotomicExtension
section Basic
/-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/
theorem iff_adjoin_eq_top :
IsCyclotomicExtension S A B ↔
(∀ n : ℕ+, n ∈ S → ∃ r : B, IsPrimitiveRoot r n) ∧
adjoin A {b : B | ∃ n : ℕ+, n ∈ S ∧ b ^ (n : ℕ) = 1} = ⊤ :=
⟨fun h => ⟨fun _ => h.exists_prim_root, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h =>
⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩
/-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/
theorem iff_singleton :
IsCyclotomicExtension {n} A B ↔
(∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ (n : ℕ) = 1} := by
simp [isCyclotomicExtension_iff]
/-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/
theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by
simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h
/-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/
theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ :=
Algebra.eq_top_iff.2 fun x => by
| simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x
| Mathlib/NumberTheory/Cyclotomic/Basic.lean | 107 | 108 |
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.Topology.Sets.Compacts
/-!
# Contents
In this file we work with *contents*. A content `λ` is a function from a certain class of subsets
(such as the compact subsets) to `ℝ≥0` that is
* additive: If `K₁` and `K₂` are disjoint sets in the domain of `λ`,
then `λ(K₁ ∪ K₂) = λ(K₁) + λ(K₂)`;
* subadditive: If `K₁` and `K₂` are in the domain of `λ`, then `λ(K₁ ∪ K₂) ≤ λ(K₁) + λ(K₂)`;
* monotone: If `K₁ ⊆ K₂` are in the domain of `λ`, then `λ(K₁) ≤ λ(K₂)`.
We show that:
* Given a content `λ` on compact sets, let us define a function `λ*` on open sets, by letting
`λ* U` be the supremum of `λ K` for `K` included in `U`. This is a countably subadditive map that
vanishes at `∅`. In Halmos (1950) this is called the *inner content* `λ*` of `λ`, and formalized
as `innerContent`.
* Given an inner content, we define an outer measure `μ*`, by letting `μ* E` be the infimum of
`λ* U` over the open sets `U` containing `E`. This is indeed an outer measure. It is formalized
as `outerMeasure`.
* Restricting this outer measure to Borel sets gives a regular measure `μ`.
We define bundled contents as `Content`.
In this file we only work on contents on compact sets, and inner contents on open sets, and both
contents and inner contents map into the extended nonnegative reals. However, in other applications
other choices can be made, and it is not a priori clear what the best interface should be.
## Main definitions
For `μ : Content G`, we define
* `μ.innerContent` : the inner content associated to `μ`.
* `μ.outerMeasure` : the outer measure associated to `μ`.
* `μ.measure` : the Borel measure associated to `μ`.
These definitions are given for spaces which are R₁.
The resulting measure `μ.measure` is always outer regular by design.
When the space is locally compact, `μ.measure` is also regular.
## References
* Paul Halmos (1950), Measure Theory, §53
* <https://en.wikipedia.org/wiki/Content_(measure_theory)>
-/
universe u v w
noncomputable section
open Set TopologicalSpace
open NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {G : Type w} [TopologicalSpace G]
/-- A content is an additive function on compact sets taking values in `ℝ≥0`. It is a device
from which one can define a measure. -/
structure Content (G : Type w) [TopologicalSpace G] where
/-- The underlying additive function -/
toFun : Compacts G → ℝ≥0
mono' : ∀ K₁ K₂ : Compacts G, (K₁ : Set G) ⊆ K₂ → toFun K₁ ≤ toFun K₂
sup_disjoint' :
∀ K₁ K₂ : Compacts G, Disjoint (K₁ : Set G) K₂ → IsClosed (K₁ : Set G) → IsClosed (K₂ : Set G)
→ toFun (K₁ ⊔ K₂) = toFun K₁ + toFun K₂
sup_le' : ∀ K₁ K₂ : Compacts G, toFun (K₁ ⊔ K₂) ≤ toFun K₁ + toFun K₂
instance : Inhabited (Content G) :=
⟨{ toFun := fun _ => 0
mono' := by simp
sup_disjoint' := by simp
sup_le' := by simp }⟩
namespace Content
instance : FunLike (Content G) (Compacts G) ℝ≥0∞ where
coe μ s := μ.toFun s
coe_injective' := by
rintro ⟨μ, _, _⟩ ⟨v, _, _⟩ h; congr!; ext s : 1; exact ENNReal.coe_injective <| congr_fun h s
variable (μ : Content G)
@[simp] lemma toFun_eq_toNNReal_apply (K : Compacts G) : μ.toFun K = (μ K).toNNReal := rfl
@[simp]
lemma mk_apply (toFun : Compacts G → ℝ≥0) (mono' sup_disjoint' sup_le') (K : Compacts G) :
mk toFun mono' sup_disjoint' sup_le' K = toFun K := rfl
@[simp] lemma apply_ne_top {K : Compacts G} : μ K ≠ ∞ := coe_ne_top
@[deprecated toFun_eq_toNNReal_apply (since := "2025-02-11")]
theorem apply_eq_coe_toFun (K : Compacts G) : μ K = μ.toFun K :=
rfl
theorem mono (K₁ K₂ : Compacts G) (h : (K₁ : Set G) ⊆ K₂) : μ K₁ ≤ μ K₂ := by
simpa using μ.mono' _ _ h
theorem sup_disjoint (K₁ K₂ : Compacts G) (h : Disjoint (K₁ : Set G) K₂)
(h₁ : IsClosed (K₁ : Set G)) (h₂ : IsClosed (K₂ : Set G)) :
μ (K₁ ⊔ K₂) = μ K₁ + μ K₂ := by
simpa [toNNReal_eq_toNNReal_iff, ← toNNReal_add] using μ.sup_disjoint' _ _ h h₁ h₂
theorem sup_le (K₁ K₂ : Compacts G) : μ (K₁ ⊔ K₂) ≤ μ K₁ + μ K₂ := by
simpa [← toNNReal_add] using μ.sup_le' _ _
theorem lt_top (K : Compacts G) : μ K < ∞ :=
ENNReal.coe_lt_top
theorem empty : μ ⊥ = 0 := by simpa [toNNReal_eq_zero_iff] using μ.sup_disjoint' ⊥ ⊥
/-- Constructing the inner content of a content. From a content defined on the compact sets, we
obtain a function defined on all open sets, by taking the supremum of the content of all compact
subsets. -/
def innerContent (U : Opens G) : ℝ≥0∞ :=
⨆ (K : Compacts G) (_ : (K : Set G) ⊆ U), μ K
theorem le_innerContent (K : Compacts G) (U : Opens G) (h2 : (K : Set G) ⊆ U) :
μ K ≤ μ.innerContent U :=
le_iSup_of_le K <| le_iSup (fun _ ↦ (μ.toFun K : ℝ≥0∞)) h2
theorem innerContent_le (U : Opens G) (K : Compacts G) (h2 : (U : Set G) ⊆ K) :
μ.innerContent U ≤ μ K :=
iSup₂_le fun _ hK' => μ.mono _ _ (Subset.trans hK' h2)
theorem innerContent_of_isCompact {K : Set G} (h1K : IsCompact K) (h2K : IsOpen K) :
μ.innerContent ⟨K, h2K⟩ = μ ⟨K, h1K⟩ :=
le_antisymm (iSup₂_le fun _ hK' => μ.mono _ ⟨K, h1K⟩ hK') (μ.le_innerContent _ _ Subset.rfl)
theorem innerContent_bot : μ.innerContent ⊥ = 0 := by
refine le_antisymm ?_ (zero_le _)
rw [← μ.empty]
refine iSup₂_le fun K hK => ?_
have : K = ⊥ := by
ext1
rw [subset_empty_iff.mp hK, Compacts.coe_bot]
rw [this]
|
/-- This is "unbundled", because that is required for the API of `inducedOuterMeasure`. -/
theorem innerContent_mono ⦃U V : Set G⦄ (hU : IsOpen U) (hV : IsOpen V) (h2 : U ⊆ V) :
μ.innerContent ⟨U, hU⟩ ≤ μ.innerContent ⟨V, hV⟩ :=
biSup_mono fun _ hK => hK.trans h2
theorem innerContent_exists_compact {U : Opens G} (hU : μ.innerContent U ≠ ∞) {ε : ℝ≥0}
(hε : ε ≠ 0) : ∃ K : Compacts G, (K : Set G) ⊆ U ∧ μ.innerContent U ≤ μ K + ε := by
| Mathlib/MeasureTheory/Measure/Content.lean | 145 | 152 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Function.LpSeminorm.Basic
import Mathlib.MeasureTheory.Integral.MeanInequalities
/-!
# Triangle inequality for `Lp`-seminorm
In this file we prove several versions of the triangle inequality for the `Lp` seminorm,
as well as simple corollaries.
-/
open Filter
open scoped ENNReal Topology
namespace MeasureTheory
variable {α E : Type*} {m : MeasurableSpace α} [NormedAddCommGroup E]
{p : ℝ≥0∞} {q : ℝ} {μ : Measure α} {f g : α → E}
theorem eLpNorm'_add_le (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ)
(hq1 : 1 ≤ q) : eLpNorm' (f + g) q μ ≤ eLpNorm' f q μ + eLpNorm' g q μ :=
calc
(∫⁻ a, (‖(f + g) a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) ≤
(∫⁻ a, ((fun a => (‖f a‖₊ : ℝ≥0∞)) + fun a => (‖g a‖₊ : ℝ≥0∞)) a ^ q ∂μ) ^ (1 / q) := by
gcongr with a
simp only [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe, nnnorm_add_le]
_ ≤ eLpNorm' f q μ + eLpNorm' g q μ := ENNReal.lintegral_Lp_add_le hf.enorm hg.enorm hq1
theorem eLpNorm'_add_le_of_le_one (hf : AEStronglyMeasurable f μ) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) :
eLpNorm' (f + g) q μ ≤ (2 : ℝ≥0∞) ^ (1 / q - 1) * (eLpNorm' f q μ + eLpNorm' g q μ) :=
calc
(∫⁻ a, (‖(f + g) a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) ≤
(∫⁻ a, ((fun a => (‖f a‖₊ : ℝ≥0∞)) + fun a => (‖g a‖₊ : ℝ≥0∞)) a ^ q ∂μ) ^ (1 / q) := by
gcongr with a
simp only [Pi.add_apply, ← ENNReal.coe_add, ENNReal.coe_le_coe, nnnorm_add_le]
_ ≤ (2 : ℝ≥0∞) ^ (1 / q - 1) * (eLpNorm' f q μ + eLpNorm' g q μ) :=
ENNReal.lintegral_Lp_add_le_of_le_one hf.enorm hq0 hq1
theorem eLpNormEssSup_add_le {f g : α → E} :
eLpNormEssSup (f + g) μ ≤ eLpNormEssSup f μ + eLpNormEssSup g μ := by
refine le_trans (essSup_mono_ae (Eventually.of_forall fun x => ?_)) (ENNReal.essSup_add_le _ _)
simp_rw [Pi.add_apply, enorm_eq_nnnorm, ← ENNReal.coe_add, ENNReal.coe_le_coe]
exact nnnorm_add_le _ _
theorem eLpNorm_add_le {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ)
(hp1 : 1 ≤ p) : eLpNorm (f + g) p μ ≤ eLpNorm f p μ + eLpNorm g p μ := by
by_cases hp0 : p = 0
· simp [hp0]
by_cases hp_top : p = ∞
· simp [hp_top, eLpNormEssSup_add_le]
have hp1_real : 1 ≤ p.toReal := by
rwa [← ENNReal.toReal_one, ENNReal.toReal_le_toReal ENNReal.one_ne_top hp_top]
repeat rw [eLpNorm_eq_eLpNorm' hp0 hp_top]
exact eLpNorm'_add_le hf hg hp1_real
/-- A constant for the inequality `‖f + g‖_{L^p} ≤ C * (‖f‖_{L^p} + ‖g‖_{L^p})`. It is equal to `1`
for `p ≥ 1` or `p = 0`, and `2^(1/p-1)` in the more tricky interval `(0, 1)`. -/
noncomputable def LpAddConst (p : ℝ≥0∞) : ℝ≥0∞ :=
if p ∈ Set.Ioo (0 : ℝ≥0∞) 1 then (2 : ℝ≥0∞) ^ (1 / p.toReal - 1) else 1
theorem LpAddConst_of_one_le {p : ℝ≥0∞} (hp : 1 ≤ p) : LpAddConst p = 1 := by
rw [LpAddConst, if_neg]
intro h
exact lt_irrefl _ (h.2.trans_le hp)
theorem LpAddConst_zero : LpAddConst 0 = 1 := by
rw [LpAddConst, if_neg]
intro h
exact lt_irrefl _ h.1
theorem LpAddConst_lt_top (p : ℝ≥0∞) : LpAddConst p < ∞ := by
rw [LpAddConst]
split_ifs with h
· apply ENNReal.rpow_lt_top_of_nonneg _ ENNReal.ofNat_ne_top
rw [one_div, sub_nonneg, ← ENNReal.toReal_inv, ← ENNReal.toReal_one]
exact ENNReal.toReal_mono (by simpa using h.1.ne') (ENNReal.one_le_inv.2 h.2.le)
· exact ENNReal.one_lt_top
theorem eLpNorm_add_le' (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ)
(p : ℝ≥0∞) : eLpNorm (f + g) p μ ≤ LpAddConst p * (eLpNorm f p μ + eLpNorm g p μ) := by
rcases eq_or_ne p 0 with (rfl | hp)
· simp only [eLpNorm_exponent_zero, add_zero, mul_zero, le_zero_iff]
rcases lt_or_le p 1 with (h'p | h'p)
· simp only [eLpNorm_eq_eLpNorm' hp (h'p.trans ENNReal.one_lt_top).ne]
convert eLpNorm'_add_le_of_le_one hf ENNReal.toReal_nonneg _
· have : p ∈ Set.Ioo (0 : ℝ≥0∞) 1 := ⟨hp.bot_lt, h'p⟩
simp only [LpAddConst, if_pos this]
· simpa using ENNReal.toReal_mono ENNReal.one_ne_top h'p.le
· simpa [LpAddConst_of_one_le h'p] using eLpNorm_add_le hf hg h'p
variable (μ E)
/-- Technical lemma to control the addition of functions in `L^p` even for `p < 1`: Given `δ > 0`,
there exists `η` such that two functions bounded by `η` in `L^p` have a sum bounded by `δ`. One
could take `η = δ / 2` for `p ≥ 1`, but the point of the lemma is that it works also for `p < 1`.
-/
theorem exists_Lp_half (p : ℝ≥0∞) {δ : ℝ≥0∞} (hδ : δ ≠ 0) :
∃ η : ℝ≥0∞,
0 < η ∧
∀ (f g : α → E), AEStronglyMeasurable f μ → AEStronglyMeasurable g μ →
eLpNorm f p μ ≤ η → eLpNorm g p μ ≤ η → eLpNorm (f + g) p μ < δ := by
have :
Tendsto (fun η : ℝ≥0∞ => LpAddConst p * (η + η)) (𝓝[>] 0) (𝓝 (LpAddConst p * (0 + 0))) :=
(ENNReal.Tendsto.const_mul (tendsto_id.add tendsto_id)
(Or.inr (LpAddConst_lt_top p).ne)).mono_left
nhdsWithin_le_nhds
simp only [add_zero, mul_zero] at this
rcases (((tendsto_order.1 this).2 δ hδ.bot_lt).and self_mem_nhdsWithin).exists with ⟨η, hη, ηpos⟩
refine ⟨η, ηpos, fun f g hf hg Hf Hg => ?_⟩
calc
eLpNorm (f + g) p μ ≤ LpAddConst p * (eLpNorm f p μ + eLpNorm g p μ) := eLpNorm_add_le' hf hg p
_ ≤ LpAddConst p * (η + η) := by gcongr
_ < δ := hη
variable {μ E}
theorem eLpNorm_sub_le' (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ)
(p : ℝ≥0∞) : eLpNorm (f - g) p μ ≤ LpAddConst p * (eLpNorm f p μ + eLpNorm g p μ) := by
simpa only [sub_eq_add_neg, eLpNorm_neg] using eLpNorm_add_le' hf hg.neg p
theorem eLpNorm_sub_le {f g : α → E} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ)
(hp : 1 ≤ p) : eLpNorm (f - g) p μ ≤ eLpNorm f p μ + eLpNorm g p μ := by
simpa [LpAddConst_of_one_le hp] using eLpNorm_sub_le' hf hg p
theorem eLpNorm_add_lt_top {f g : α → E} (hf : MemLp f p μ) (hg : MemLp g p μ) :
eLpNorm (f + g) p μ < ∞ :=
calc
eLpNorm (f + g) p μ ≤ LpAddConst p * (eLpNorm f p μ + eLpNorm g p μ) :=
eLpNorm_add_le' hf.aestronglyMeasurable hg.aestronglyMeasurable p
_ < ∞ := by
apply ENNReal.mul_lt_top (LpAddConst_lt_top p)
exact ENNReal.add_lt_top.2 ⟨hf.2, hg.2⟩
theorem eLpNorm'_sum_le {ι} {f : ι → α → E} {s : Finset ι}
(hfs : ∀ i, i ∈ s → AEStronglyMeasurable (f i) μ) (hq1 : 1 ≤ q) :
eLpNorm' (∑ i ∈ s, f i) q μ ≤ ∑ i ∈ s, eLpNorm' (f i) q μ :=
Finset.le_sum_of_subadditive_on_pred (fun f : α → E => eLpNorm' f q μ)
(fun f => AEStronglyMeasurable f μ) (eLpNorm'_zero (zero_lt_one.trans_le hq1))
(fun _f _g hf hg => eLpNorm'_add_le hf hg hq1) (fun _f _g hf hg => hf.add hg) _ hfs
| theorem eLpNorm_sum_le {ι} {f : ι → α → E} {s : Finset ι}
(hfs : ∀ i, i ∈ s → AEStronglyMeasurable (f i) μ) (hp1 : 1 ≤ p) :
eLpNorm (∑ i ∈ s, f i) p μ ≤ ∑ i ∈ s, eLpNorm (f i) p μ :=
| Mathlib/MeasureTheory/Function/LpSeminorm/TriangleInequality.lean | 145 | 147 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov
-/
import Mathlib.Data.Set.Prod
import Mathlib.Data.Set.Restrict
/-!
# Functions over sets
This file contains basic results on the following predicates of functions and sets:
* `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`;
* `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`;
* `Set.InjOn f s` : restriction of `f` to `s` is injective;
* `Set.SurjOn f s t` : every point in `s` has a preimage in `s`;
* `Set.BijOn f s t` : `f` is a bijection between `s` and `t`;
* `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`;
* `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`;
* `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e.
we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`.
-/
variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*}
open Equiv Equiv.Perm Function
namespace Set
/-! ### Equality on a set -/
section equality
variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α}
/-- This lemma exists for use by `aesop` as a forward rule. -/
@[aesop safe forward]
lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a :=
h ha
@[simp]
theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim
@[simp]
theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by
simp [Set.EqOn]
@[simp]
theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by
simp [EqOn, funext_iff]
@[symm]
theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm
theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s :=
⟨EqOn.symm, EqOn.symm⟩
-- This can not be tagged as `@[refl]` with the current argument order.
-- See note below at `EqOn.trans`.
theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl
-- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it
-- the `trans` tactic could not use it.
-- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute.
-- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`.
-- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581).
theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx =>
(h₁ hx).trans (h₂ hx)
theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s :=
image_congr heq
/-- Variant of `EqOn.image_eq`, for one function being the identity. -/
theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by
rw [h.image_eq, image_id]
theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t :=
ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx]
theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx)
@[simp]
theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ :=
forall₂_or_left
theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) :=
eqOn_union.2 ⟨h₁, h₂⟩
theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha =>
congr_arg _ <| h ha
@[simp]
theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} :
EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f :=
forall_mem_range.trans <| funext_iff.symm
alias ⟨EqOn.comp_eq, _⟩ := eqOn_range
end equality
variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ}
{f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β}
section MapsTo
theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t :=
image_subset_iff.symm
theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) :=
diagonal_subset_iff.2 fun _ => rfl
@[deprecated (since := "2025-04-18")]
alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal
theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf
theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl
@[simp]
theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t :=
singleton_subset_iff
theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t :=
empty_subset _
@[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by
simp [mapsTo', subset_empty_iff]
/-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/
theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty :=
(hs.image f).mono (mapsTo'.mp h)
theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t :=
mapsTo'.1 h
theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx =>
h hx ▸ h₁ hx
theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) :=
fun _ ha => hg <| hf ha
theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h =>
h₁ (h₂ h)
theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id
theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s
| 0 => fun _ => id
| n + 1 => (MapsTo.iterate h n).comp h
theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) :
(h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by
funext x
rw [Subtype.ext_iff, MapsTo.val_restrict_apply]
induction n generalizing x with
| zero => rfl
| succ n ihn => simp [Nat.iterate, ihn]
lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) :
MapsTo f s t :=
fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩
lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s :=
mapsTo_of_subsingleton' _ id
theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ :=
fun _ hx => ht (hf <| hs hx)
theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx =>
hf (hs hx)
theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx =>
ht (hf hx)
theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx
theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t :=
union_self t ▸ h₁.union_union h₂
@[simp]
theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t :=
⟨fun h =>
⟨h.mono subset_union_left (Subset.refl t),
h.mono subset_union_right (Subset.refl t)⟩,
fun h => h.1.union h.2⟩
theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx =>
⟨h₁ hx, h₂ hx⟩
lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by
simpa [← singleton_union] using h.mono_right subset_union_right
theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩
@[simp]
theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ :=
⟨fun h =>
⟨h.mono (Subset.refl s) inter_subset_left,
h.mono (Subset.refl s) inter_subset_right⟩,
fun h => h.1.inter h.2⟩
theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial
theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) :=
(mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _)
@[simp]
theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} :
MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t :=
⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩
lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) :=
fun x hx ↦ ⟨f x, hf hx, rfl⟩
lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) :
MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx
@[simp]
lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t :=
⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩
@[simp]
lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t :=
forall_mem_range
theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s :=
⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩
end MapsTo
/-! ### Injectivity on a set -/
section injOn
theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ =>
hs hx hy
@[simp]
theorem injOn_empty (f : α → β) : InjOn f ∅ :=
subsingleton_empty.injOn f
@[simp]
theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} :=
subsingleton_singleton.injOn f
@[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop
theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y :=
⟨h hx hy, fun h => h ▸ rfl⟩
theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y :=
(h.eq_iff hx hy).not
alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff
theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy =>
h hx ▸ h hy ▸ h₁ hx hy
theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H =>
ht (h hx) (h hy) H
theorem injOn_union (h : Disjoint s₁ s₂) :
InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by
refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩
· intro x hx y hy hxy
obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy
exact h.le_bot ⟨hx, hy⟩
· rintro ⟨h₁, h₂, h₁₂⟩
rintro x (hx | hx) y (hy | hy) hxy
exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy]
theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) :
Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by
rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)]
simp
theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ :=
⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩
theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy
alias _root_.Function.Injective.injOn := injOn_of_injective
-- A specialization of `injOn_of_injective` for `Subtype.val`.
theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s :=
Subtype.coe_injective.injOn
lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn
theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s :=
fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq
lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s :=
fun _ hx _ hy heq ↦ h hx hy (by simp [heq])
lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) :=
forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq
lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) :=
⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩
lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) :
∀ n, InjOn f^[n] s
| 0 => injOn_id _
| (n + 1) => (h.iterate hf n).comp h hf
lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s :=
(injective_of_subsingleton _).injOn
theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by
rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H
exact congr_arg f (h H)
theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) :
Injective (g ∘ f) ↔ Injective f :=
⟨(·.of_comp), fun h _ ↦ by aesop⟩
theorem exists_injOn_iff_injective [Nonempty β] :
(∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f :=
⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩,
fun ⟨f, hf⟩ => by
lift f to α → β using trivial
exact ⟨f, injOn_iff_injective.2 hf⟩⟩
theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B :=
fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst
theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) :
x ∈ s₁ :=
let ⟨_, h', Eq⟩ := h₁
hf (hs h') h Eq ▸ h'
theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) :
f x ∈ f '' s₁ ↔ x ∈ s₁ :=
⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩
theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ :=
ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩
theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t)
(hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha)
theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) :
s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ :=
⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩
lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) :
f '' (s ∩ t) = f '' s ∩ f '' t := by
apply Subset.antisymm (image_inter_subset _ _ _)
intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩
have : y = z := by
apply hf (hs ys) (ht zt)
rwa [← hz] at hy
rw [← this] at zt
exact ⟨y, ⟨ys, zt⟩, hy⟩
lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) :=
fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂]
theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ = f '' s₂ ↔ s₁ = s₂ :=
h.image.eq_iff h₁ h₂
lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by
refine ⟨fun h' ↦ ?_, image_subset _⟩
rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂]
exact inter_subset_inter_left _ (preimage_mono h')
lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by
simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁]
-- TODO: can this move to a better place?
theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f)
(hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by
rw [disjoint_iff_inter_eq_empty] at h ⊢
rw [← hf.image_inter hs ht, h, image_empty]
lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by
refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩)
(diff_subset_iff.2 (by rw [← image_union, inter_union_diff]))
exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left
lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) :
f '' (s \ t) = f '' s \ f '' t := by
rw [h.image_diff, inter_eq_self_of_subset_right hst]
alias image_diff_of_injOn := InjOn.image_diff_subset
theorem InjOn.imageFactorization_injective (h : InjOn f s) :
Injective (s.imageFactorization f) :=
fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h'
@[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s :=
⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]),
InjOn.imageFactorization_injective⟩
end injOn
section graphOn
variable {x : α × β}
lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp
lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) :=
fun _f _g ↦ graphOn_univ_inj.1
lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} :
(∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by
refine ⟨?_, fun h ↦ ?_⟩
· rintro ⟨f, hf⟩
rw [hf]
exact InjOn.image_of_comp <| injOn_id _
· have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩
choose! f hf using this
rw [forall_mem_image] at hf
use f
rw [graphOn, image_image, EqOn.image_eq_self]
exact fun x hx ↦ h (hf hx) hx rfl
lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} :
(∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s :=
.trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩
exists_eq_graphOn_image_fst
end graphOn
/-! ### Surjectivity on a set -/
section surjOn
theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f :=
Subset.trans h <| image_subset_range f s
theorem surjOn_iff_exists_map_subtype :
SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x :=
⟨fun h =>
⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩,
fun ⟨t', g, htt', hg, hfg⟩ y hy =>
let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩
⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩
theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ :=
empty_subset _
@[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by
simp [SurjOn, subset_empty_iff]
@[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff
theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) :=
Subset.rfl
theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty :=
(ht.mono h).of_image
theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by
rwa [SurjOn, ← H.image_eq]
theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t :=
⟨fun H => H.congr h, fun H => H.congr h.symm⟩
theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ :=
Subset.trans ht <| Subset.trans hf <| image_subset _ hs
theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => h₁ hx) fun hx => h₂ hx
theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) :
SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) :=
(h₁.mono subset_union_left (Subset.refl _)).union
(h₂.mono subset_union_right (Subset.refl _))
theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by
intro y hy
rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩
rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩
obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm
exact mem_image_of_mem f ⟨hx₁, hx₂⟩
theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) :
SurjOn f (s₁ ∩ s₂) t :=
inter_self t ▸ h₁.inter_inter h₂ h
lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn]
theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p :=
Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _
lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by
intro z hz
obtain ⟨x, hx, rfl⟩ := h hz
exact ⟨f x, hr hx, rfl⟩
lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p :=
⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩
lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s
| 0 => surjOn_id _
| (n + 1) => (h.iterate n).comp h
lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by
rw [SurjOn, image_comp g f]; exact image_subset _ hf
lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) :
SurjOn (g ∘ f) (f ⁻¹' s) t := by
rwa [SurjOn, image_comp g f, image_preimage_eq _ hf]
lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) :
SurjOn f s t :=
fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _
lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s :=
surjOn_of_subsingleton' _ id
theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by
simp [Surjective, SurjOn, subset_def]
theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t :=
eq_of_subset_of_subset h₂.image_subset h₁
theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by
refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩
rintro rfl
exact ⟨s.surjOn_image f, s.mapsTo_image f⟩
lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ :=
image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx
theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ :=
fun _ hs ht =>
let ⟨_, hx', HEq⟩ := h ht
hs <| h' HEq ▸ hx'
theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ :=
h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs)
theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by
intro b hb
obtain ⟨a, ha, rfl⟩ := hf' hb
exact hf ha
theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) :
s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ :=
⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩
theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ :=
(s.surjOn_image f).cancel_right <| s.mapsTo_image f
theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) :
(∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) :=
⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩
end surjOn
/-! ### Bijectivity -/
section bijOn
theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t :=
h.left
theorem BijOn.injOn (h : BijOn f s t) : InjOn f s :=
h.right.left
theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t :=
h.right.right
theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t :=
⟨h₁, h₂, h₃⟩
theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ :=
⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩
@[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ :=
⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩
@[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ :=
⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩
@[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm]
theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy =>
let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1
⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩
theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃
theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left,
h₁.surjOn.inter_inter h₂.surjOn h⟩
theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) :=
⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩
theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f :=
h.surjOn.subset_range
theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) :=
BijOn.mk (mapsTo_image f s) h (Subset.refl _)
theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t :=
BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h)
theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t :=
h.surjOn.image_eq_of_mapsTo h.mapsTo
lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where
mp h _ ha := h _ <| hf.mapsTo ha
mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha
lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where
mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩
mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩
lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t :=
⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩,
BijOn.image_eq⟩
lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩
theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p :=
BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn)
/-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection
on `s` iff `g` is a bijection on `f '' s`. -/
theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by
simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf]
/--
If we have a commutative square
```
α --f--> β
| |
p₁ p₂
| |
\/ \/
γ --g--> δ
```
and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g`
induces a bijection from the image of `s` to the image of `t`, as long as `g` is
is injective on the image of `s`.
-/
theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a))
(hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by
obtain ⟨h1, h2, h3⟩ := hbij
refine ⟨?_, hinj, ?_⟩
· rintro _ ⟨a, ha, rfl⟩
exact ⟨f a, h1 ha, by rw [comm a]⟩
· rintro _ ⟨b, hb, rfl⟩
obtain ⟨a, ha, rfl⟩ := h3 hb
rw [← image_comp, comm]
exact ⟨a, ha, rfl⟩
lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s
| 0 => s.bijOn_id
| (n + 1) => (h.iterate n).comp h
lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β)
(h : s.Nonempty ↔ t.Nonempty) : BijOn f s t :=
⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩
lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s :=
bijOn_of_subsingleton' _ Iff.rfl
theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) :=
⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ =>
let ⟨x, hx, hxy⟩ := h.surjOn hy
⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩
theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ :=
Iff.intro
(fun h =>
let ⟨inj, surj⟩ := h
⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩)
fun h =>
let ⟨_map, inj, surj⟩ := h
⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩
alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ
theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ :=
⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩
theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) :
BijOn f (s ∩ f ⁻¹' r) r := by
refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩
obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx)
exact ⟨y, ⟨hy, hx⟩, rfl⟩
theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) :
BijOn f r (f '' r) :=
(hf.injOn.mono hrs).bijOn_image
theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) :
BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where
mp h := by
have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq)
simp only [mem_singleton_iff, insert_diff_of_mem] at this
rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this
· exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..),
by simp [← this, surjOn_image]⟩
simp only [mem_image, not_exists, not_and]
intro x hx
rw [h.injOn.eq_iff (by simp [hx]) (by simp)]
exact ha ∘ (· ▸ hx)
mpr h := by
repeat rw [insert_eq]
refine (bijOn_singleton.mpr rfl).union h ?_
simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image,
not_exists, not_and, true_and]
exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx)
theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) :
BijOn f (insert a s) (insert (f a) t) :=
(insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁
theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) :
BijOn f (s \ {a}) (t \ {f a}) := by
convert h₁.subset_left diff_subset
simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right]
end bijOn
/-! ### left inverse -/
namespace LeftInvOn
theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s :=
h
theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x :=
h hx
theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t)
(heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx
theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s :=
fun _ hx => heq hx ▸ h₁ hx
theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq =>
calc
x₁ = f₁' (f x₁) := Eq.symm <| h h₁
_ = f₁' (f x₂) := congr_arg f₁' heq
_ = x₂ := h h₂
theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx =>
⟨f x, hf hx, h hx⟩
theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) :
MapsTo f' t s := fun y hy => by
let ⟨x, hs, hx⟩ := hf hy
rwa [← hx, h hs]
lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl
theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) :
LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h =>
calc
(f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h))
_ = x := hf' h
theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx =>
hf (ht hx)
theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by
apply Subset.antisymm
· rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩
exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩
· rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩
exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩
theorem image_inter (hf : LeftInvOn f' f s) :
f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by
rw [hf.image_inter']
refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left))
rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩
theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by
rw [Set.image_image, image_congr hf, image_id']
theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ :=
(hf.mono hs).image_image
end LeftInvOn
/-! ### Right inverse -/
section RightInvOn
namespace RightInvOn
theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t :=
h
theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y :=
h hy
theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) :=
fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx)
theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) :
RightInvOn f₂' f t :=
h₁.congr_right heq
theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) :
RightInvOn f' f₂ t :=
LeftInvOn.congr_left h₁ hg heq
theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t :=
LeftInvOn.surjOn hf hf'
theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t :=
LeftInvOn.mapsTo h hf
lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl
theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) :
RightInvOn (f' ∘ g') (g ∘ f) p :=
LeftInvOn.comp hg hf g'pt
theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ :=
LeftInvOn.mono hf ht
end RightInvOn
theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t)
(h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h =>
hf (h₂ <| h₁ h) h (hf' (h₁ h))
theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t)
(h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy =>
calc
f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm
_ = f₂' y := h₁ (h hy)
theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) :
LeftInvOn f f' t := fun y hy => by
let ⟨x, hx, heq⟩ := hf hy
rw [← heq, hf' hx]
end RightInvOn
/-! ### Two-side inverses -/
namespace InvOn
lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩
lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t)
(g'pt : MapsTo g' p t) :
InvOn (f' ∘ g') (g ∘ f) s p :=
⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩
@[symm]
theorem symm (h : InvOn f' f s t) : InvOn f f' t s :=
⟨h.right, h.left⟩
theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ :=
⟨h.1.mono hs, h.2.mono ht⟩
/-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t`
into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from
`surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/
theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t :=
⟨hf, h.left.injOn, h.right.surjOn hf'⟩
end InvOn
end Set
/-! ### `invFunOn` is a left/right inverse -/
namespace Function
variable {s : Set α} {f : α → β} {a : α} {b : β}
/-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f`
on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/
noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α :=
open scoped Classical in
if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α›
variable [Nonempty α]
theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by
rw [invFunOn, dif_pos h]
exact Classical.choose_spec h
theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s :=
(invFunOn_pos h).left
theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b :=
(invFunOn_pos h).right
theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by
rw [invFunOn, dif_neg h]
@[simp]
theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s :=
invFunOn_mem ⟨a, h, rfl⟩
theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a :=
invFunOn_eq ⟨a, h, rfl⟩
end Function
open Function
namespace Set
variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β}
theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s :=
fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha)
theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) :
invFunOn f s₂ '' (f '' s₁) = s₁ :=
h.leftInvOn_invFunOn.image_image' ht
theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α]
(h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s :=
fun x hx ↦ by
obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx
rw [invFunOn_apply_eq (f := f) hx']
theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] :
InjOn f s ↔ (invFunOn f s) '' (f '' s) = s :=
⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦
(Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩
theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) :
Set.InjOn (invFunOn f s) (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he
rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx']
theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) :
(invFunOn f s) '' (f '' s) ⊆ s := by
rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx
theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy
theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t :=
⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩
theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
InvOn (invFunOn f s) f (invFunOn f s '' t) t := by
refine ⟨?_, h.rightInvOn_invFunOn⟩
rintro _ ⟨y, hy, rfl⟩
rw [h.rightInvOn_invFunOn hy]
theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s :=
fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy
/-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense
to use the other lemma directly in an application. -/
theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t)
(hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r :=
hf.rightInvOn_invFunOn.image_image' hrt
/-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense
to use the other lemma directly in an application. -/
theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) :
f '' (f.invFunOn s '' t) = t :=
hf.rightInvOn_invFunOn.image_image
theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by
refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _)
rintro _ ⟨y, hy, rfl⟩
rwa [h.rightInvOn_invFunOn hy]
theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by
constructor
· rcases eq_empty_or_nonempty t with (rfl | ht)
· exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩
· intro h
haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩
exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩
· rintro ⟨s', hs', hfs'⟩
exact hfs'.surjOn.mono hs' (Subset.refl _)
alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset
variable (f s)
lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) :=
surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s)
lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u :=
let ⟨u, _, hfu⟩ := exists_subset_bijOn s f
⟨u, hfu.image_eq, hfu.injOn⟩
variable {f s}
lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) :
∃ s, f '' s = t ∧ InjOn f s :=
image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _
/-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`,
then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/
theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t')
(ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by
obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f
rw [image_diff_preimage, image_inter_preimage] at hbij
refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩
· exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left
· rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff]
exact ⟨htt', diff_subset.trans inter_subset_right⟩
· rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn]
· refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_
rw [← h.image_eq]
exact ⟨x, hxs, hxy⟩
exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo
rw [image_union, h.image_eq, hbij.image_eq, union_diff_self]
exact .inr ⟨ht' hyt', hyt'⟩
/-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`,
then `f` maps some superset of `s` bijectively to `t'`. -/
theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) :
∃ s', s ⊆ s' ∧ BijOn f s' t' := by
simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn])
theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) :
∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by
obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs
(image_subset f hrs) Subset.rfl
exact ⟨u, hru, hus, h.image_eq, h.injOn⟩
theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α}
(h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by
ext x
rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx)
· simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false,
leftInverse_invFun hf _, hf.mem_set_image]
· simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true]
theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α}
(h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by
ext x
rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx)
· rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image]
· have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h')
simp only [mem_preimage, invFun_neg hx, h, this]
lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s :=
⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩
lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s :=
⟨BijOn.symm h, BijOn.symm h.symm⟩
end Set
namespace Function
open Set
variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α}
theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) :=
hg.injOn.comp hf (mapsTo_univ _ _)
theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s :=
(surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _)
theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s :=
fun x _ => h x
theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) :
RightInvOn f g s := fun x _ => h x
theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) :
RightInvOn f g (range g) :=
forall_mem_range.2 fun i => congr_arg g (h i)
namespace Semiconj
theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) :=
fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩
theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) :
MapsTo f (fa '' s) (fb '' t) :=
mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩
theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ =>
hy ▸ ⟨fa x, h x⟩
theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by
rintro y ⟨x, hxt, rfl⟩
rcases ha hxt with ⟨x, hxs, rfl⟩
rw [h x]
exact mem_image_of_mem _ (mem_image_of_mem _ hxs)
theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) :
SurjOn fb (range f) (range f) := by
rw [← image_univ]
exact h.surjOn_image (ha.surjOn univ)
theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) :
InjOn fb (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H
simp only [← h.eq] at H
exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H)
theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) :
InjOn fb (range f) := by
rw [← image_univ] at *
exact h.injOn_image ha.injOn hf
theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) :
BijOn fb (f '' s) (f '' t) :=
⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf),
h.surjOn_image ha.surjOn⟩
theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) :
BijOn fb (range f) (range f) := by
rw [← image_univ]
exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn
theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) :
MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx]
theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s)
(hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by
intro x hx y hy H
have := congr_arg f H
rw [h.eq, h.eq] at this
exact hf hx hy (hb hx hy this)
end Semiconj
theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β]
(g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) :
(fun j => update g i a (f j)) = fun j => g (f j) :=
(update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩
/-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/
theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β]
(g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f :=
update_comp_eq_of_not_mem_range' g a h
theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ =>
(insert_inj ha).1
lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) :
f a = b := by
simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a
end Function
/-! ### Equivalences, permutations -/
namespace Set
variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α}
protected lemma MapsTo.extendDomain (h : MapsTo g s t) :
MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩
protected lemma SurjOn.extendDomain (h : SurjOn g s t) :
SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩
obtain ⟨b, hb, rfl⟩ := h ha
exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩
protected lemma BijOn.extendDomain (h : BijOn g s t) :
BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) :=
⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩
protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) :
LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by
rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha]
protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) :
RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha]
protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) :
InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) :=
⟨h.1.extendDomain, h.2.extendDomain⟩
end Set
namespace Set
variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂}
{f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂}
lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) :
(s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) :=
fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2)
lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) :
SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by
rintro x hx
obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1
obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2
exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩
lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) :
MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩
lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) :
BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩
lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) :
LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) :=
fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2)
lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) :
RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) :=
fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2)
lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) :
InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩
end Set
namespace Equiv
open Set
variable (e : α ≃ β) {s : Set α} {t : Set β}
lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t :=
⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩
protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t :=
e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply]
lemma invOn : InvOn e e.symm t s :=
⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩
lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image
lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn
variable {e}
@[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn
alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm
variable [DecidableEq α] {a b : α}
lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s :=
(swap a b).bijOn fun x ↦ by
obtain rfl | hxa := eq_or_ne x a <;>
obtain rfl | hxb := eq_or_ne x b <;>
simp [*, swap_apply_of_ne_of_ne]
end Equiv
| Mathlib/Data/Set/Function.lean | 1,392 | 1,396 | |
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.NoZeroSMulDivisors.Basic
import Mathlib.Algebra.Order.GroupWithZero.Action.Synonym
import Mathlib.Tactic.GCongr
import Mathlib.Tactic.Positivity.Core
/-!
# Monotonicity of scalar multiplication by positive elements
This file defines typeclasses to reason about monotonicity of the operations
* `b ↦ a • b`, "left scalar multiplication"
* `a ↦ a • b`, "right scalar multiplication"
We use eight typeclasses to encode the various properties we care about for those two operations.
These typeclasses are meant to be mostly internal to this file, to set up each lemma in the
appropriate generality.
Less granular typeclasses like `OrderedAddCommMonoid`, `LinearOrderedField`, `OrderedSMul` should be
enough for most purposes, and the system is set up so that they imply the correct granular
typeclasses here. If those are enough for you, you may stop reading here! Else, beware that what
follows is a bit technical.
## Definitions
In all that follows, `α` and `β` are orders which have a `0` and such that `α` acts on `β` by scalar
multiplication. Note however that we do not use lawfulness of this action in most of the file. Hence
`•` should be considered here as a mostly arbitrary function `α → β → β`.
We use the following four typeclasses to reason about left scalar multiplication (`b ↦ a • b`):
* `PosSMulMono`: If `a ≥ 0`, then `b₁ ≤ b₂` implies `a • b₁ ≤ a • b₂`.
* `PosSMulStrictMono`: If `a > 0`, then `b₁ < b₂` implies `a • b₁ < a • b₂`.
* `PosSMulReflectLT`: If `a ≥ 0`, then `a • b₁ < a • b₂` implies `b₁ < b₂`.
* `PosSMulReflectLE`: If `a > 0`, then `a • b₁ ≤ a • b₂` implies `b₁ ≤ b₂`.
We use the following four typeclasses to reason about right scalar multiplication (`a ↦ a • b`):
* `SMulPosMono`: If `b ≥ 0`, then `a₁ ≤ a₂` implies `a₁ • b ≤ a₂ • b`.
* `SMulPosStrictMono`: If `b > 0`, then `a₁ < a₂` implies `a₁ • b < a₂ • b`.
* `SMulPosReflectLT`: If `b ≥ 0`, then `a₁ • b < a₂ • b` implies `a₁ < a₂`.
* `SMulPosReflectLE`: If `b > 0`, then `a₁ • b ≤ a₂ • b` implies `a₁ ≤ a₂`.
## Constructors
The four typeclasses about nonnegativity can usually be checked only on positive inputs due to their
condition becoming trivial when `a = 0` or `b = 0`. We therefore make the following constructors
available: `PosSMulMono.of_pos`, `PosSMulReflectLT.of_pos`, `SMulPosMono.of_pos`,
`SMulPosReflectLT.of_pos`
## Implications
As `α` and `β` get more and more structure, those typeclasses end up being equivalent. The commonly
used implications are:
* When `α`, `β` are partial orders:
* `PosSMulStrictMono → PosSMulMono`
* `SMulPosStrictMono → SMulPosMono`
* `PosSMulReflectLE → PosSMulReflectLT`
* `SMulPosReflectLE → SMulPosReflectLT`
* When `β` is a linear order:
* `PosSMulStrictMono → PosSMulReflectLE`
* `PosSMulReflectLT → PosSMulMono` (not registered as instance)
* `SMulPosReflectLT → SMulPosMono` (not registered as instance)
* `PosSMulReflectLE → PosSMulStrictMono` (not registered as instance)
* `SMulPosReflectLE → SMulPosStrictMono` (not registered as instance)
* When `α` is a linear order:
* `SMulPosStrictMono → SMulPosReflectLE`
* When `α` is an ordered ring, `β` an ordered group and also an `α`-module:
* `PosSMulMono → SMulPosMono`
* `PosSMulStrictMono → SMulPosStrictMono`
* When `α` is an linear ordered semifield, `β` is an `α`-module:
* `PosSMulStrictMono → PosSMulReflectLT`
* `PosSMulMono → PosSMulReflectLE`
* When `α` is a semiring, `β` is an `α`-module with `NoZeroSMulDivisors`:
* `PosSMulMono → PosSMulStrictMono` (not registered as instance)
* When `α` is a ring, `β` is an `α`-module with `NoZeroSMulDivisors`:
* `SMulPosMono → SMulPosStrictMono` (not registered as instance)
Further, the bundled non-granular typeclasses imply the granular ones like so:
* `OrderedSMul → PosSMulStrictMono`
* `OrderedSMul → PosSMulReflectLT`
Unless otherwise stated, all these implications are registered as instances,
which means that in practice you should not worry about these implications.
However, if you encounter a case where you think a statement is true but
not covered by the current implications, please bring it up on Zulip!
## Implementation notes
This file uses custom typeclasses instead of abbreviations of `CovariantClass`/`ContravariantClass`
because:
* They get displayed as classes in the docs. In particular, one can see their list of instances,
instead of their instances being invariably dumped to the `CovariantClass`/`ContravariantClass`
list.
* They don't pollute other typeclass searches. Having many abbreviations of the same typeclass for
different purposes always felt like a performance issue (more instances with the same key, for no
added benefit), and indeed making the classes here abbreviation previous creates timeouts due to
the higher number of `CovariantClass`/`ContravariantClass` instances.
* `SMulPosReflectLT`/`SMulPosReflectLE` do not fit in the framework since they relate `≤` on two
different types. So we would have to generalise `CovariantClass`/`ContravariantClass` to three
types and two relations.
* Very minor, but the constructors let you work with `a : α`, `h : 0 ≤ a` instead of
`a : {a : α // 0 ≤ a}`. This actually makes some instances surprisingly cleaner to prove.
* The `CovariantClass`/`ContravariantClass` framework is only useful to automate very simple logic
anyway. It is easily copied over.
In the future, it would be good to make the corresponding typeclasses in
`Mathlib.Algebra.Order.GroupWithZero.Unbundled` custom typeclasses too.
## TODO
This file acts as a substitute for `Mathlib.Algebra.Order.SMul`. We now need to
* finish the transition by deleting the duplicate lemmas
* rearrange the non-duplicate lemmas into new files
* generalise (most of) the lemmas from `Mathlib.Algebra.Order.Module` to here
* rethink `OrderedSMul`
-/
open OrderDual
variable (α β : Type*)
section Defs
variable [SMul α β] [Preorder α] [Preorder β]
section Left
variable [Zero α]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `b₁ ≤ b₂ → a • b₁ ≤ a • b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 ≤ a) ⦃b₁ b₂ : β⦄ (hb : b₁ ≤ b₂) : a • b₁ ≤ a • b₂
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `b₁ < b₂ → a • b₁ < a • b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ b₂ : β⦄ (hb : b₁ < b₂) : a • b₁ < a • b₂
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a • b₁ < a • b₂ → b₁ < b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 ≤ a) ⦃b₁ b₂ : β⦄ (hb : a • b₁ < a • b₂) : b₁ < b₂
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a • b₁ ≤ a • b₂ → b₁ ≤ b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ b₂ : β⦄ (hb : a • b₁ ≤ a • b₂) : b₁ ≤ b₂
end Left
section Right
variable [Zero β]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `a₁ ≤ a₂ → a₁ • b ≤ a₂ • b` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 ≤ b) ⦃a₁ a₂ : α⦄ (ha : a₁ ≤ a₂) : a₁ • b ≤ a₂ • b
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `a₁ < a₂ → a₁ • b < a₂ • b` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ a₂ : α⦄ (ha : a₁ < a₂) : a₁ • b < a₂ • b
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a₁ • b < a₂ • b → a₁ < a₂` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 ≤ b) ⦃a₁ a₂ : α⦄ (hb : a₁ • b < a₂ • b) : a₁ < a₂
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a₁ • b ≤ a₂ • b → a₁ ≤ a₂` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ a₂ : α⦄ (hb : a₁ • b ≤ a₂ • b) : a₁ ≤ a₂
end Right
end Defs
variable {α β} {a a₁ a₂ : α} {b b₁ b₂ : β}
section Mul
variable [Zero α] [Mul α] [Preorder α]
-- See note [lower instance priority]
instance (priority := 100) PosMulMono.toPosSMulMono [PosMulMono α] : PosSMulMono α α where
elim _a ha _b₁ _b₂ hb := mul_le_mul_of_nonneg_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulStrictMono.toPosSMulStrictMono [PosMulStrictMono α] :
PosSMulStrictMono α α where
elim _a ha _b₁ _b₂ hb := mul_lt_mul_of_pos_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLT.toPosSMulReflectLT [PosMulReflectLT α] :
PosSMulReflectLT α α where
elim _a ha _b₁ _b₂ h := lt_of_mul_lt_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLE.toPosSMulReflectLE [PosMulReflectLE α] :
PosSMulReflectLE α α where
elim _a ha _b₁ _b₂ h := le_of_mul_le_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) MulPosMono.toSMulPosMono [MulPosMono α] : SMulPosMono α α where
elim _b hb _a₁ _a₂ ha := mul_le_mul_of_nonneg_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosStrictMono.toSMulPosStrictMono [MulPosStrictMono α] :
SMulPosStrictMono α α where
elim _b hb _a₁ _a₂ ha := mul_lt_mul_of_pos_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLT.toSMulPosReflectLT [MulPosReflectLT α] :
SMulPosReflectLT α α where
elim _b hb _a₁ _a₂ h := lt_of_mul_lt_mul_right h hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLE.toSMulPosReflectLE [MulPosReflectLE α] :
SMulPosReflectLE α α where
elim _b hb _a₁ _a₂ h := le_of_mul_le_mul_right h hb
end Mul
section SMul
variable [SMul α β]
section Preorder
variable [Preorder α] [Preorder β]
section Left
variable [Zero α]
lemma monotone_smul_left_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) : Monotone ((a • ·) : β → β) :=
PosSMulMono.elim ha
lemma strictMono_smul_left_of_pos [PosSMulStrictMono α β] (ha : 0 < a) :
StrictMono ((a • ·) : β → β) := PosSMulStrictMono.elim ha
@[gcongr] lemma smul_le_smul_of_nonneg_left [PosSMulMono α β] (hb : b₁ ≤ b₂) (ha : 0 ≤ a) :
a • b₁ ≤ a • b₂ := monotone_smul_left_of_nonneg ha hb
@[gcongr] lemma smul_lt_smul_of_pos_left [PosSMulStrictMono α β] (hb : b₁ < b₂) (ha : 0 < a) :
a • b₁ < a • b₂ := strictMono_smul_left_of_pos ha hb
lemma lt_of_smul_lt_smul_left [PosSMulReflectLT α β] (h : a • b₁ < a • b₂) (ha : 0 ≤ a) : b₁ < b₂ :=
PosSMulReflectLT.elim ha h
lemma le_of_smul_le_smul_left [PosSMulReflectLE α β] (h : a • b₁ ≤ a • b₂) (ha : 0 < a) : b₁ ≤ b₂ :=
PosSMulReflectLE.elim ha h
alias lt_of_smul_lt_smul_of_nonneg_left := lt_of_smul_lt_smul_left
alias le_of_smul_le_smul_of_pos_left := le_of_smul_le_smul_left
@[simp]
lemma smul_le_smul_iff_of_pos_left [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) :
a • b₁ ≤ a • b₂ ↔ b₁ ≤ b₂ :=
⟨fun h ↦ le_of_smul_le_smul_left h ha, fun h ↦ smul_le_smul_of_nonneg_left h ha.le⟩
@[simp]
lemma smul_lt_smul_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a • b₁ < a • b₂ ↔ b₁ < b₂ :=
⟨fun h ↦ lt_of_smul_lt_smul_left h ha.le, fun hb ↦ smul_lt_smul_of_pos_left hb ha⟩
end Left
section Right
variable [Zero β]
lemma monotone_smul_right_of_nonneg [SMulPosMono α β] (hb : 0 ≤ b) : Monotone ((· • b) : α → β) :=
SMulPosMono.elim hb
lemma strictMono_smul_right_of_pos [SMulPosStrictMono α β] (hb : 0 < b) :
StrictMono ((· • b) : α → β) := SMulPosStrictMono.elim hb
@[gcongr] lemma smul_le_smul_of_nonneg_right [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : 0 ≤ b) :
a₁ • b ≤ a₂ • b := monotone_smul_right_of_nonneg hb ha
@[gcongr] lemma smul_lt_smul_of_pos_right [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : 0 < b) :
a₁ • b < a₂ • b := strictMono_smul_right_of_pos hb ha
lemma lt_of_smul_lt_smul_right [SMulPosReflectLT α β] (h : a₁ • b < a₂ • b) (hb : 0 ≤ b) :
a₁ < a₂ := SMulPosReflectLT.elim hb h
lemma le_of_smul_le_smul_right [SMulPosReflectLE α β] (h : a₁ • b ≤ a₂ • b) (hb : 0 < b) :
a₁ ≤ a₂ := SMulPosReflectLE.elim hb h
alias lt_of_smul_lt_smul_of_nonneg_right := lt_of_smul_lt_smul_right
alias le_of_smul_le_smul_of_pos_right := le_of_smul_le_smul_right
@[simp]
lemma smul_le_smul_iff_of_pos_right [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
a₁ • b ≤ a₂ • b ↔ a₁ ≤ a₂ :=
⟨fun h ↦ le_of_smul_le_smul_right h hb, fun ha ↦ smul_le_smul_of_nonneg_right ha hb.le⟩
@[simp]
lemma smul_lt_smul_iff_of_pos_right [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
a₁ • b < a₂ • b ↔ a₁ < a₂ :=
⟨fun h ↦ lt_of_smul_lt_smul_right h hb.le, fun ha ↦ smul_lt_smul_of_pos_right ha hb⟩
end Right
section LeftRight
variable [Zero α] [Zero β]
lemma smul_lt_smul_of_le_of_lt [PosSMulStrictMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂)
(hb : b₁ < b₂) (h₁ : 0 < a₁) (h₂ : 0 ≤ b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha h₂)
lemma smul_lt_smul_of_le_of_lt' [PosSMulStrictMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂)
(hb : b₁ < b₂) (h₂ : 0 < a₂) (h₁ : 0 ≤ b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_le_smul_of_nonneg_right ha h₁).trans_lt (smul_lt_smul_of_pos_left hb h₂)
lemma smul_lt_smul_of_lt_of_le [PosSMulMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂)
(hb : b₁ ≤ b₂) (h₁ : 0 ≤ a₁) (h₂ : 0 < b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_le_smul_of_nonneg_left hb h₁).trans_lt (smul_lt_smul_of_pos_right ha h₂)
lemma smul_lt_smul_of_lt_of_le' [PosSMulMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂)
(hb : b₁ ≤ b₂) (h₂ : 0 ≤ a₂) (h₁ : 0 < b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb h₂)
lemma smul_lt_smul [PosSMulStrictMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : b₁ < b₂)
(h₁ : 0 < a₁) (h₂ : 0 < b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_left hb h₁).trans (smul_lt_smul_of_pos_right ha h₂)
lemma smul_lt_smul' [PosSMulStrictMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : b₁ < b₂)
(h₂ : 0 < a₂) (h₁ : 0 < b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_right ha h₁).trans (smul_lt_smul_of_pos_left hb h₂)
lemma smul_le_smul [PosSMulMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂)
(h₁ : 0 ≤ a₁) (h₂ : 0 ≤ b₂) : a₁ • b₁ ≤ a₂ • b₂ :=
(smul_le_smul_of_nonneg_left hb h₁).trans (smul_le_smul_of_nonneg_right ha h₂)
lemma smul_le_smul' [PosSMulMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₂ : 0 ≤ a₂)
(h₁ : 0 ≤ b₁) : a₁ • b₁ ≤ a₂ • b₂ :=
(smul_le_smul_of_nonneg_right ha h₁).trans (smul_le_smul_of_nonneg_left hb h₂)
end LeftRight
end Preorder
section LinearOrder
variable [Preorder α] [LinearOrder β]
section Left
variable [Zero α]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulReflectLE [PosSMulStrictMono α β] :
PosSMulReflectLE α β where
elim _a ha _b₁ _b₂ := (strictMono_smul_left_of_pos ha).le_iff_le.1
lemma PosSMulReflectLE.toPosSMulStrictMono [PosSMulReflectLE α β] : PosSMulStrictMono α β where
elim _a ha _b₁ _b₂ hb := not_le.1 fun h ↦ hb.not_le <| le_of_smul_le_smul_left h ha
lemma posSMulStrictMono_iff_PosSMulReflectLE : PosSMulStrictMono α β ↔ PosSMulReflectLE α β :=
⟨fun _ ↦ inferInstance, fun _ ↦ PosSMulReflectLE.toPosSMulStrictMono⟩
instance PosSMulMono.toPosSMulReflectLT [PosSMulMono α β] : PosSMulReflectLT α β where
elim _a ha _b₁ _b₂ := (monotone_smul_left_of_nonneg ha).reflect_lt
lemma PosSMulReflectLT.toPosSMulMono [PosSMulReflectLT α β] : PosSMulMono α β where
elim _a ha _b₁ _b₂ hb := not_lt.1 fun h ↦ hb.not_lt <| lt_of_smul_lt_smul_left h ha
lemma posSMulMono_iff_posSMulReflectLT : PosSMulMono α β ↔ PosSMulReflectLT α β :=
⟨fun _ ↦ PosSMulMono.toPosSMulReflectLT, fun _ ↦ PosSMulReflectLT.toPosSMulMono⟩
lemma smul_max_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (b₁ b₂ : β) :
a • max b₁ b₂ = max (a • b₁) (a • b₂) := (monotone_smul_left_of_nonneg ha).map_max
lemma smul_min_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (b₁ b₂ : β) :
a • min b₁ b₂ = min (a • b₁) (a • b₂) := (monotone_smul_left_of_nonneg ha).map_min
end Left
section Right
variable [Zero β]
lemma SMulPosReflectLE.toSMulPosStrictMono [SMulPosReflectLE α β] : SMulPosStrictMono α β where
elim _b hb _a₁ _a₂ ha := not_le.1 fun h ↦ ha.not_le <| le_of_smul_le_smul_of_pos_right h hb
lemma SMulPosReflectLT.toSMulPosMono [SMulPosReflectLT α β] : SMulPosMono α β where
elim _b hb _a₁ _a₂ ha := not_lt.1 fun h ↦ ha.not_lt <| lt_of_smul_lt_smul_right h hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder α] [Preorder β]
section Right
variable [Zero β]
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosReflectLE [SMulPosStrictMono α β] :
SMulPosReflectLE α β where
elim _b hb _a₁ _a₂ h := not_lt.1 fun ha ↦ h.not_lt <| smul_lt_smul_of_pos_right ha hb
lemma SMulPosMono.toSMulPosReflectLT [SMulPosMono α β] : SMulPosReflectLT α β where
elim _b hb _a₁ _a₂ h := not_le.1 fun ha ↦ h.not_le <| smul_le_smul_of_nonneg_right ha hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder α] [LinearOrder β]
section Right
variable [Zero β]
lemma smulPosStrictMono_iff_SMulPosReflectLE : SMulPosStrictMono α β ↔ SMulPosReflectLE α β :=
⟨fun _ ↦ SMulPosStrictMono.toSMulPosReflectLE, fun _ ↦ SMulPosReflectLE.toSMulPosStrictMono⟩
lemma smulPosMono_iff_smulPosReflectLT : SMulPosMono α β ↔ SMulPosReflectLT α β :=
⟨fun _ ↦ SMulPosMono.toSMulPosReflectLT, fun _ ↦ SMulPosReflectLT.toSMulPosMono⟩
end Right
end LinearOrder
end SMul
section SMulZeroClass
variable [Zero α] [Zero β] [SMulZeroClass α β]
section Preorder
variable [Preorder α] [Preorder β]
lemma smul_pos [PosSMulStrictMono α β] (ha : 0 < a) (hb : 0 < b) : 0 < a • b := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
lemma smul_neg_of_pos_of_neg [PosSMulStrictMono α β] (ha : 0 < a) (hb : b < 0) : a • b < 0 := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
@[simp]
lemma smul_pos_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
0 < a • b ↔ 0 < b := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₁ := 0) (b₂ := b)
lemma smul_neg_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a • b < 0 ↔ b < 0 := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₂ := (0 : β))
lemma smul_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (hb : 0 ≤ b₁) : 0 ≤ a • b₁ := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma smul_nonpos_of_nonneg_of_nonpos [PosSMulMono α β] (ha : 0 ≤ a) (hb : b ≤ 0) : a • b ≤ 0 := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma pos_of_smul_pos_left [PosSMulReflectLT α β] (h : 0 < a • b) (ha : 0 ≤ a) : 0 < b :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
lemma neg_of_smul_neg_left [PosSMulReflectLT α β] (h : a • b < 0) (ha : 0 ≤ a) : b < 0 :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
end Preorder
end SMulZeroClass
section SMulWithZero
variable [Zero α] [Zero β] [SMulWithZero α β]
section Preorder
variable [Preorder α] [Preorder β]
lemma smul_pos' [SMulPosStrictMono α β] (ha : 0 < a) (hb : 0 < b) : 0 < a • b := by
simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb
lemma smul_neg_of_neg_of_pos [SMulPosStrictMono α β] (ha : a < 0) (hb : 0 < b) : a • b < 0 := by
simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb
@[simp]
lemma smul_pos_iff_of_pos_right [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
0 < a • b ↔ 0 < a := by
simpa only [zero_smul] using smul_lt_smul_iff_of_pos_right hb (a₁ := 0) (a₂ := a)
lemma smul_nonneg' [SMulPosMono α β] (ha : 0 ≤ a) (hb : 0 ≤ b₁) : 0 ≤ a • b₁ := by
simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb
lemma smul_nonpos_of_nonpos_of_nonneg [SMulPosMono α β] (ha : a ≤ 0) (hb : 0 ≤ b) : a • b ≤ 0 := by
simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb
lemma pos_of_smul_pos_right [SMulPosReflectLT α β] (h : 0 < a • b) (hb : 0 ≤ b) : 0 < a :=
lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb
lemma neg_of_smul_neg_right [SMulPosReflectLT α β] (h : a • b < 0) (hb : 0 ≤ b) : a < 0 :=
lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb
lemma pos_iff_pos_of_smul_pos [PosSMulReflectLT α β] [SMulPosReflectLT α β] (hab : 0 < a • b) :
0 < a ↔ 0 < b :=
⟨pos_of_smul_pos_left hab ∘ le_of_lt, pos_of_smul_pos_right hab ∘ le_of_lt⟩
end Preorder
section PartialOrder
variable [PartialOrder α] [Preorder β]
/-- A constructor for `PosSMulMono` requiring you to prove `b₁ ≤ b₂ → a • b₁ ≤ a • b₂` only when
`0 < a` -/
lemma PosSMulMono.of_pos (h₀ : ∀ a : α, 0 < a → ∀ b₁ b₂ : β, b₁ ≤ b₂ → a • b₁ ≤ a • b₂) :
PosSMulMono α β where
elim a ha b₁ b₂ h := by
obtain ha | ha := ha.eq_or_lt
· simp [← ha]
· exact h₀ _ ha _ _ h
/-- A constructor for `PosSMulReflectLT` requiring you to prove `a • b₁ < a • b₂ → b₁ < b₂` only
when `0 < a` -/
lemma PosSMulReflectLT.of_pos (h₀ : ∀ a : α, 0 < a → ∀ b₁ b₂ : β, a • b₁ < a • b₂ → b₁ < b₂) :
PosSMulReflectLT α β where
elim a ha b₁ b₂ h := by
obtain ha | ha := ha.eq_or_lt
· simp [← ha] at h
· exact h₀ _ ha _ _ h
end PartialOrder
section PartialOrder
variable [Preorder α] [PartialOrder β]
/-- A constructor for `SMulPosMono` requiring you to prove `a₁ ≤ a₂ → a₁ • b ≤ a₂ • b` only when
`0 < b` -/
lemma SMulPosMono.of_pos (h₀ : ∀ b : β, 0 < b → ∀ a₁ a₂ : α, a₁ ≤ a₂ → a₁ • b ≤ a₂ • b) :
SMulPosMono α β where
elim b hb a₁ a₂ h := by
obtain hb | hb := hb.eq_or_lt
· simp [← hb]
· exact h₀ _ hb _ _ h
/-- A constructor for `SMulPosReflectLT` requiring you to prove `a₁ • b < a₂ • b → a₁ < a₂` only
when `0 < b` -/
lemma SMulPosReflectLT.of_pos (h₀ : ∀ b : β, 0 < b → ∀ a₁ a₂ : α, a₁ • b < a₂ • b → a₁ < a₂) :
SMulPosReflectLT α β where
elim b hb a₁ a₂ h := by
obtain hb | hb := hb.eq_or_lt
· simp [← hb] at h
· exact h₀ _ hb _ _ h
end PartialOrder
section PartialOrder
variable [PartialOrder α] [PartialOrder β]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulMono [PosSMulStrictMono α β] :
PosSMulMono α β :=
PosSMulMono.of_pos fun _a ha ↦ (strictMono_smul_left_of_pos ha).monotone
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosMono [SMulPosStrictMono α β] :
SMulPosMono α β :=
SMulPosMono.of_pos fun _b hb ↦ (strictMono_smul_right_of_pos hb).monotone
-- See note [lower instance priority]
instance (priority := 100) PosSMulReflectLE.toPosSMulReflectLT [PosSMulReflectLE α β] :
PosSMulReflectLT α β :=
PosSMulReflectLT.of_pos fun a ha b₁ b₂ h ↦
(le_of_smul_le_smul_of_pos_left h.le ha).lt_of_ne <| by rintro rfl; simp at h
-- See note [lower instance priority]
instance (priority := 100) SMulPosReflectLE.toSMulPosReflectLT [SMulPosReflectLE α β] :
SMulPosReflectLT α β :=
SMulPosReflectLT.of_pos fun b hb a₁ a₂ h ↦
(le_of_smul_le_smul_of_pos_right h.le hb).lt_of_ne <| by rintro rfl; simp at h
lemma smul_eq_smul_iff_eq_and_eq_of_pos [PosSMulStrictMono α β] [SMulPosStrictMono α β]
(ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₁ : 0 < a₁) (h₂ : 0 < b₂) :
a₁ • b₁ = a₂ • b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
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 ?_⟩
· exact (smul_le_smul_of_nonneg_left hb h₁.le).trans_lt (smul_lt_smul_of_pos_right ha h₂)
· exact (smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha h₂.le)
lemma smul_eq_smul_iff_eq_and_eq_of_pos' [PosSMulStrictMono α β] [SMulPosStrictMono α β]
(ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₂ : 0 < a₂) (h₁ : 0 < b₁) :
a₁ • b₁ = a₂ • b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
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 ?_⟩
· exact (smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb h₂.le)
· exact (smul_le_smul_of_nonneg_right ha h₁.le).trans_lt (smul_lt_smul_of_pos_left hb h₂)
end PartialOrder
section LinearOrder
variable [LinearOrder α] [LinearOrder β]
lemma pos_and_pos_or_neg_and_neg_of_smul_pos [PosSMulMono α β] [SMulPosMono α β] (hab : 0 < a • b) :
0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
obtain ha | rfl | ha := lt_trichotomy a 0
· refine Or.inr ⟨ha, lt_imp_lt_of_le_imp_le (fun hb ↦ ?_) hab⟩
exact smul_nonpos_of_nonpos_of_nonneg ha.le hb
· rw [zero_smul] at hab
exact hab.false.elim
· refine Or.inl ⟨ha, lt_imp_lt_of_le_imp_le (fun hb ↦ ?_) hab⟩
exact smul_nonpos_of_nonneg_of_nonpos ha.le hb
lemma neg_of_smul_pos_right [PosSMulMono α β] [SMulPosMono α β] (h : 0 < a • b) (ha : a ≤ 0) :
b < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h ↦ h.1.not_le ha).2
lemma neg_of_smul_pos_left [PosSMulMono α β] [SMulPosMono α β] (h : 0 < a • b) (ha : b ≤ 0) :
a < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h ↦ h.2.not_le ha).1
lemma neg_iff_neg_of_smul_pos [PosSMulMono α β] [SMulPosMono α β] (hab : 0 < a • b) :
a < 0 ↔ b < 0 :=
⟨neg_of_smul_pos_right hab ∘ le_of_lt, neg_of_smul_pos_left hab ∘ le_of_lt⟩
lemma neg_of_smul_neg_left' [SMulPosMono α β] (h : a • b < 0) (ha : 0 ≤ a) : b < 0 :=
lt_of_not_ge fun hb ↦ (smul_nonneg' ha hb).not_lt h
lemma neg_of_smul_neg_right' [PosSMulMono α β] (h : a • b < 0) (hb : 0 ≤ b) : a < 0 :=
lt_of_not_ge fun ha ↦ (smul_nonneg ha hb).not_lt h
end LinearOrder
end SMulWithZero
section MulAction
variable [Monoid α] [Zero β] [MulAction α β]
section Preorder
variable [Preorder α] [Preorder β]
@[simp]
lemma le_smul_iff_one_le_left [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
b ≤ a • b ↔ 1 ≤ a := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb)
@[simp]
lemma lt_smul_iff_one_lt_left [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
b < a • b ↔ 1 < a := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb)
@[simp]
lemma smul_le_iff_le_one_left [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
a • b ≤ b ↔ a ≤ 1 := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb)
@[simp]
lemma smul_lt_iff_lt_one_left [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
a • b < b ↔ a < 1 := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb)
lemma smul_le_of_le_one_left [SMulPosMono α β] (hb : 0 ≤ b) (h : a ≤ 1) : a • b ≤ b := by
simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb
lemma le_smul_of_one_le_left [SMulPosMono α β] (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a • b := by
simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb
| lemma smul_lt_of_lt_one_left [SMulPosStrictMono α β] (hb : 0 < b) (h : a < 1) : a • b < b := by
simpa only [one_smul] using smul_lt_smul_of_pos_right h hb
| Mathlib/Algebra/Order/Module/Defs.lean | 672 | 674 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.MvPolynomial.PDeriv
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
import Mathlib.RingTheory.Polynomial.Pochhammer
/-!
# Bernstein polynomials
The definition of the Bernstein polynomials
```
bernsteinPolynomial (R : Type*) [CommRing R] (n ν : ℕ) : R[X] :=
(choose n ν) * X^ν * (1 - X)^(n - ν)
```
and the fact that for `ν : Fin (n+1)` these are linearly independent over `ℚ`.
We prove the basic identities
* `(Finset.range (n + 1)).sum (fun ν ↦ bernsteinPolynomial R n ν) = 1`
* `(Finset.range (n + 1)).sum (fun ν ↦ ν • bernsteinPolynomial R n ν) = n • X`
* `(Finset.range (n + 1)).sum (fun ν ↦ (ν * (ν-1)) • bernsteinPolynomial R n ν) = (n * (n-1)) • X^2`
## Notes
See also `Mathlib.Analysis.SpecialFunctions.Bernstein`, which defines the Bernstein approximations
of a continuous function `f : C([0,1], ℝ)`, and shows that these converge uniformly to `f`.
-/
noncomputable section
open Nat (choose)
open Polynomial (X)
open scoped Polynomial
variable (R : Type*) [CommRing R]
/-- `bernsteinPolynomial R n ν` is `(choose n ν) * X^ν * (1 - X)^(n - ν)`.
Although the coefficients are integers, it is convenient to work over an arbitrary commutative ring.
-/
def bernsteinPolynomial (n ν : ℕ) : R[X] :=
(choose n ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν)
example : bernsteinPolynomial ℤ 3 2 = 3 * X ^ 2 - 3 * X ^ 3 := by
norm_num [bernsteinPolynomial, choose]
ring
namespace bernsteinPolynomial
theorem eq_zero_of_lt {n ν : ℕ} (h : n < ν) : bernsteinPolynomial R n ν = 0 := by
simp [bernsteinPolynomial, Nat.choose_eq_zero_of_lt h]
section
variable {R} {S : Type*} [CommRing S]
@[simp]
theorem map (f : R →+* S) (n ν : ℕ) :
(bernsteinPolynomial R n ν).map f = bernsteinPolynomial S n ν := by simp [bernsteinPolynomial]
end
theorem flip (n ν : ℕ) (h : ν ≤ n) :
(bernsteinPolynomial R n ν).comp (1 - X) = bernsteinPolynomial R n (n - ν) := by
simp [bernsteinPolynomial, h, tsub_tsub_assoc, mul_right_comm]
theorem flip' (n ν : ℕ) (h : ν ≤ n) :
bernsteinPolynomial R n ν = (bernsteinPolynomial R n (n - ν)).comp (1 - X) := by
simp [← flip _ _ _ h, Polynomial.comp_assoc]
theorem eval_at_0 (n ν : ℕ) : (bernsteinPolynomial R n ν).eval 0 = if ν = 0 then 1 else 0 := by
rw [bernsteinPolynomial]
split_ifs with h
· subst h; simp
· simp [zero_pow h]
theorem eval_at_1 (n ν : ℕ) : (bernsteinPolynomial R n ν).eval 1 = if ν = n then 1 else 0 := by
rw [bernsteinPolynomial]
split_ifs with h
· subst h; simp
· obtain hνn | hnν := Ne.lt_or_lt h
· simp [zero_pow <| Nat.sub_ne_zero_of_lt hνn]
· simp [Nat.choose_eq_zero_of_lt hnν]
theorem derivative_succ_aux (n ν : ℕ) :
Polynomial.derivative (bernsteinPolynomial R (n + 1) (ν + 1)) =
(n + 1) * (bernsteinPolynomial R n ν - bernsteinPolynomial R n (ν + 1)) := by
rw [bernsteinPolynomial]
suffices ((n + 1).choose (ν + 1) : R[X]) * ((↑(ν + 1 : ℕ) : R[X]) * X ^ ν) * (1 - X) ^ (n - ν) -
((n + 1).choose (ν + 1) : R[X]) * X ^ (ν + 1) * ((↑(n - ν) : R[X]) * (1 - X) ^ (n - ν - 1)) =
(↑(n + 1) : R[X]) * ((n.choose ν : R[X]) * X ^ ν * (1 - X) ^ (n - ν) -
(n.choose (ν + 1) : R[X]) * X ^ (ν + 1) * (1 - X) ^ (n - (ν + 1))) by
simpa [Polynomial.derivative_pow, ← sub_eq_add_neg, Nat.succ_sub_succ_eq_sub,
Polynomial.derivative_mul, Polynomial.derivative_natCast, zero_mul,
Nat.cast_add, algebraMap.coe_one, Polynomial.derivative_X, mul_one, zero_add,
Polynomial.derivative_sub, Polynomial.derivative_one, zero_sub, mul_neg, Nat.sub_zero,
bernsteinPolynomial, map_add, map_natCast, Nat.cast_one]
conv_rhs => rw [mul_sub]
-- We'll prove the two terms match up separately.
refine congr (congr_arg Sub.sub ?_) ?_
· simp only [← mul_assoc]
apply congr (congr_arg (· * ·) (congr (congr_arg (· * ·) _) rfl)) rfl
-- Now it's just about binomial coefficients
exact mod_cast congr_arg (fun m : ℕ => (m : R[X])) (Nat.succ_mul_choose_eq n ν).symm
· rw [← tsub_add_eq_tsub_tsub, ← mul_assoc, ← mul_assoc]; congr 1
rw [mul_comm, ← mul_assoc, ← mul_assoc]; congr 1
norm_cast
congr 1
convert (Nat.choose_mul_succ_eq n (ν + 1)).symm using 1
· -- Porting note: was
-- convert mul_comm _ _ using 2
-- simp
rw [mul_comm, Nat.succ_sub_succ_eq_sub]
· apply mul_comm
theorem derivative_succ (n ν : ℕ) : Polynomial.derivative (bernsteinPolynomial R n (ν + 1)) =
n * (bernsteinPolynomial R (n - 1) ν - bernsteinPolynomial R (n - 1) (ν + 1)) := by
cases n
· simp [bernsteinPolynomial]
· rw [Nat.cast_succ]; apply derivative_succ_aux
theorem derivative_zero (n : ℕ) :
Polynomial.derivative (bernsteinPolynomial R n 0) = -n * bernsteinPolynomial R (n - 1) 0 := by
simp [bernsteinPolynomial, Polynomial.derivative_pow]
theorem iterate_derivative_at_0_eq_zero_of_lt (n : ℕ) {ν k : ℕ} :
k < ν → (Polynomial.derivative^[k] (bernsteinPolynomial R n ν)).eval 0 = 0 := by
rcases ν with - | ν
· rintro ⟨⟩
· rw [Nat.lt_succ_iff]
induction' k with k ih generalizing n ν
| · simp [eval_at_0]
· simp only [derivative_succ, Int.natCast_eq_zero, mul_eq_zero, Function.comp_apply,
Function.iterate_succ, Polynomial.iterate_derivative_sub,
| Mathlib/RingTheory/Polynomial/Bernstein.lean | 141 | 143 |
/-
Copyright (c) 2023 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Group.NatPowAssoc
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Eval.SMul
/-!
# Scalar-multiple polynomial evaluation
This file defines polynomial evaluation via scalar multiplication. Our polynomials have
coefficients in a semiring `R`, and we evaluate at a weak form of `R`-algebra, namely an additive
commutative monoid with an action of `R` and a notion of natural number power. This
is a generalization of `Algebra.Polynomial.Eval`.
## Main definitions
* `Polynomial.smeval`: function for evaluating a polynomial with coefficients in a `Semiring`
`R` at an element `x` of an `AddCommMonoid` `S` that has natural number powers and an `R`-action.
* `smeval.linearMap`: the `smeval` function as an `R`-linear map, when `S` is an `R`-module.
* `smeval.algebraMap`: the `smeval` function as an `R`-algebra map, when `S` is an `R`-algebra.
## Main results
* `smeval_monomial`: monomials evaluate as we expect.
* `smeval_add`, `smeval_smul`: linearity of evaluation, given an `R`-module.
* `smeval_mul`, `smeval_comp`: multiplicativity of evaluation, given power-associativity.
* `eval₂_smulOneHom_eq_smeval`, `leval_eq_smeval.linearMap`,
`aeval_eq_smeval`, etc.: comparisons
## TODO
* `smeval_neg` and `smeval_intCast` for `R` a ring and `S` an `AddCommGroup`.
* Nonunital evaluation for polynomials with vanishing constant term for `Pow S ℕ+` (different file?)
-/
namespace Polynomial
section MulActionWithZero
variable {R : Type*} [Semiring R] (r : R) (p : R[X]) {S : Type*} [AddCommMonoid S] [Pow S ℕ]
[MulActionWithZero R S] (x : S)
/-- Scalar multiplication together with taking a natural number power. -/
def smul_pow : ℕ → R → S := fun n r => r • x^n
/-- Evaluate a polynomial `p` in the scalar semiring `R` at an element `x` in the target `S` using
scalar multiple `R`-action. -/
irreducible_def smeval : S := p.sum (smul_pow x)
theorem smeval_eq_sum : p.smeval x = p.sum (smul_pow x) := by rw [smeval_def]
@[simp]
theorem smeval_C : (C r).smeval x = r • x ^ 0 := by
simp only [smeval_eq_sum, smul_pow, zero_smul, sum_C_index]
@[simp]
theorem smeval_monomial (n : ℕ) :
(monomial n r).smeval x = r • x ^ n := by
simp only [smeval_eq_sum, smul_pow, zero_smul, sum_monomial_index]
theorem eval_eq_smeval : p.eval r = p.smeval r := by
rw [eval_eq_sum, smeval_eq_sum]
rfl
theorem eval₂_smulOneHom_eq_smeval (R : Type*) [Semiring R] {S : Type*} [Semiring S] [Module R S]
[IsScalarTower R S S] (p : R[X]) (x : S) :
p.eval₂ RingHom.smulOneHom x = p.smeval x := by
rw [smeval_eq_sum, eval₂_eq_sum]
congr 1 with e a
simp only [RingHom.smulOneHom_apply, smul_one_mul, smul_pow]
variable (R)
@[simp]
theorem smeval_zero : (0 : R[X]).smeval x = 0 := by
simp only [smeval_eq_sum, smul_pow, sum_zero_index]
@[simp]
theorem smeval_one : (1 : R[X]).smeval x = 1 • x ^ 0 := by
rw [← C_1, smeval_C]
simp only [Nat.cast_one, one_smul]
@[simp]
theorem smeval_X :
(X : R[X]).smeval x = x ^ 1 := by
simp only [smeval_eq_sum, smul_pow, zero_smul, sum_X_index, one_smul]
@[simp]
theorem smeval_X_pow {n : ℕ} :
(X ^ n : R[X]).smeval x = x ^ n := by
simp only [smeval_eq_sum, smul_pow, X_pow_eq_monomial, zero_smul, sum_monomial_index, one_smul]
end MulActionWithZero
section Module
variable (R : Type*) [Semiring R] (p q : R[X]) {S : Type*} [AddCommMonoid S] [Pow S ℕ] [Module R S]
(x : S)
@[simp]
theorem smeval_add : (p + q).smeval x = p.smeval x + q.smeval x := by
simp only [smeval_eq_sum, smul_pow]
refine sum_add_index p q (smul_pow x) (fun _ ↦ ?_) (fun _ _ _ ↦ ?_)
· rw [smul_pow, zero_smul]
· rw [smul_pow, smul_pow, smul_pow, add_smul]
theorem smeval_natCast (n : ℕ) : (n : R[X]).smeval x = n • x ^ 0 := by
induction n with
| zero => simp only [smeval_zero, Nat.cast_zero, zero_smul]
| succ n ih => rw [n.cast_succ, smeval_add, ih, smeval_one, ← add_nsmul]
@[simp]
theorem smeval_smul (r : R) : (r • p).smeval x = r • p.smeval x := by
induction p using Polynomial.induction_on' with
| add p q ph qh => rw [smul_add, smeval_add, ph, qh, ← smul_add, smeval_add]
| monomial n a => rw [smul_monomial, smeval_monomial, smeval_monomial, smul_assoc]
/-- `Polynomial.smeval` as a linear map. -/
def smeval.linearMap : R[X] →ₗ[R] S where
toFun f := f.smeval x
map_add' f g := by simp only [smeval_add]
map_smul' c f := by simp only [smeval_smul, smul_eq_mul, RingHom.id_apply]
@[simp]
theorem smeval.linearMap_apply : smeval.linearMap R x p = p.smeval x := rfl
theorem leval_coe_eq_smeval {R : Type*} [Semiring R] (r : R) :
⇑(leval r) = fun p => p.smeval r := by
rw [funext_iff]
intro
rw [leval_apply, smeval_def, eval_eq_sum]
rfl
theorem leval_eq_smeval.linearMap {R : Type*} [Semiring R] (r : R) :
leval r = smeval.linearMap R r := by
refine LinearMap.ext ?_
intro
rw [leval_apply, smeval.linearMap_apply, eval_eq_smeval]
end Module
section Neg
variable (R : Type*) [Ring R] {S : Type*} [AddCommGroup S] [Pow S ℕ] [Module R S] (p q : R[X])
(x : S)
@[simp]
theorem smeval_neg : (-p).smeval x = - p.smeval x := by
rw [← add_eq_zero_iff_eq_neg, ← smeval_add, neg_add_cancel, smeval_zero]
@[simp]
theorem smeval_sub : (p - q).smeval x = p.smeval x - q.smeval x := by
rw [sub_eq_add_neg, smeval_add, smeval_neg, sub_eq_add_neg]
theorem smeval_neg_nat (S : Type*) [NonAssocRing S] [Pow S ℕ] [NatPowAssoc S] (q : ℕ[X])
(n : ℕ) : q.smeval (-(n : S)) = q.smeval (-n : ℤ) := by
rw [smeval_eq_sum, smeval_eq_sum]
simp only [Polynomial.smul_pow, sum_def, Int.cast_sum, Int.cast_mul, Int.cast_npow]
refine Finset.sum_congr rfl ?_
intro k _
rw [show -(n : S) = (-n : ℤ) by simp only [Int.cast_neg, Int.cast_natCast], nsmul_eq_mul,
← AddGroupWithOne.intCast_ofNat, ← Int.cast_npow, ← Int.cast_mul, ← nsmul_eq_mul]
end Neg
section NatPowAssoc
/-!
In the module docstring for algebras at `Mathlib.Algebra.Algebra.Basic`, we see that
`[CommSemiring R] [Semiring S] [Module R S] [IsScalarTower R S S] [SMulCommClass R S S]` is an
equivalent way to express `[CommSemiring R] [Semiring S] [Algebra R S]` that allows one to relax
the defining structures independently. For non-associative power-associative algebras (e.g.,
octonions), we replace the `[Semiring S]` with `[NonAssocSemiring S] [Pow S ℕ] [NatPowAssoc S]`.
-/
variable (R : Type*) [Semiring R] (r : R) (p q : R[X]) {S : Type*}
[NonAssocSemiring S] [Module R S] [Pow S ℕ] (x : S)
theorem smeval_C_mul : (C r * p).smeval x = r • p.smeval x := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp only [mul_add, smeval_add, ph, qh, smul_add]
| monomial n b => simp only [C_mul_monomial, smeval_monomial, mul_smul]
variable [NatPowAssoc S]
theorem smeval_at_natCast (q : ℕ[X]) : ∀(n : ℕ), q.smeval (n : S) = q.smeval n := by
induction q using Polynomial.induction_on' with
| add p q ph qh =>
intro n
simp only [add_mul, smeval_add, ph, qh, Nat.cast_add]
| monomial n a =>
intro n
rw [smeval_monomial, smeval_monomial, nsmul_eq_mul, smul_eq_mul, Nat.cast_mul, Nat.cast_npow]
theorem smeval_at_zero : p.smeval (0 : S) = (p.coeff 0) • (1 : S) := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp_all only [smeval_add, coeff_add, add_smul]
| monomial n a =>
cases n with
| zero => simp only [monomial_zero_left, smeval_C, npow_zero, coeff_C_zero]
| succ n => rw [coeff_monomial_succ, smeval_monomial, npow_add, npow_one, mul_zero, zero_smul,
smul_zero]
section
variable [SMulCommClass R S S]
theorem smeval_X_mul : (X * p).smeval x = x * p.smeval x := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp only [smeval_add, ph, qh, mul_add]
| monomial n a =>
rw [← monomial_one_one_eq_X, monomial_mul_monomial, smeval_monomial, one_mul, npow_add,
npow_one, ← mul_smul_comm, smeval_monomial]
theorem smeval_X_pow_assoc (m n : ℕ) :
x ^ m * x ^ n * p.smeval x = x ^ m * (x ^ n * p.smeval x) := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp only [smeval_add, ph, qh, mul_add]
| monomial n a => simp only [smeval_monomial, mul_smul_comm, npow_mul_assoc]
theorem smeval_X_pow_mul : ∀ (n : ℕ), (X^n * p).smeval x = x^n * p.smeval x
| 0 => by
simp [npow_zero, one_mul]
| n + 1 => by
rw [add_comm, npow_add, mul_assoc, npow_one, smeval_X_mul, smeval_X_pow_mul n, npow_add,
smeval_X_pow_assoc, npow_one]
theorem smeval_monomial_mul (n : ℕ) :
(monomial n r * p).smeval x = r • (x ^ n * p.smeval x) := by
induction p using Polynomial.induction_on' with
| add r s hr hs =>
simp only [add_comp, hr, hs, smeval_add, add_mul]
rw [← C_mul_X_pow_eq_monomial, mul_assoc, smeval_C_mul, smeval_X_pow_mul, smeval_add]
| monomial n a =>
rw [smeval_monomial, monomial_mul_monomial, smeval_monomial, npow_add, mul_smul, mul_smul_comm]
end
variable [IsScalarTower R S S]
theorem smeval_mul_X : (p * X).smeval x = p.smeval x * x := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp only [add_mul, smeval_add, ph, qh]
| monomial n a =>
simp only [← monomial_one_one_eq_X, monomial_mul_monomial, smeval_monomial, mul_one, pow_succ',
mul_assoc, npow_add, smul_mul_assoc, npow_one]
theorem smeval_assoc_X_pow (m n : ℕ) :
p.smeval x * x ^ m * x ^ n = p.smeval x * (x ^ m * x ^ n) := by
induction p using Polynomial.induction_on' with
| add p q ph qh => simp only [smeval_add, ph, qh, add_mul]
| monomial n a =>
rw [smeval_monomial, smul_mul_assoc, smul_mul_assoc, npow_mul_assoc, ← smul_mul_assoc]
theorem smeval_mul_X_pow : ∀ (n : ℕ), (p * X^n).smeval x = p.smeval x * x^n
| 0 => by
simp only [npow_zero, mul_one]
| n + 1 => by
rw [npow_add, ← mul_assoc, npow_one, smeval_mul_X, smeval_mul_X_pow n, npow_add,
← smeval_assoc_X_pow, npow_one]
variable [SMulCommClass R S S]
theorem smeval_mul : (p * q).smeval x = p.smeval x * q.smeval x := by
induction p using Polynomial.induction_on' with
| add r s hr hs => simp only [add_comp, hr, hs, smeval_add, add_mul]
| monomial n a =>
simp only [smeval_monomial, smeval_C_mul, smeval_mul_X_pow, smeval_monomial_mul, smul_mul_assoc]
theorem smeval_pow : ∀ (n : ℕ), (p^n).smeval x = (p.smeval x)^n
| 0 => by
simp only [npow_zero, smeval_one, one_smul]
| n + 1 => by
rw [npow_add, smeval_mul, smeval_pow n, pow_one, npow_add, npow_one]
theorem smeval_comp : (p.comp q).smeval x = p.smeval (q.smeval x) := by
induction p using Polynomial.induction_on' with
| add r s hr hs => simp [add_comp, hr, hs, smeval_add]
| monomial n a => simp [smeval_monomial, smeval_C_mul, smeval_pow]
end NatPowAssoc
section Commute
| variable (R : Type*) [Semiring R] (p q : R[X]) {S : Type*} [Semiring S]
[Module R S] [IsScalarTower R S S] [SMulCommClass R S S] {x y : S}
theorem smeval_commute_left (hc : Commute x y) : Commute (p.smeval x) y := by
induction p using Polynomial.induction_on' with
| Mathlib/Algebra/Polynomial/Smeval.lean | 288 | 292 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Group.TypeTags.Finite
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.RingTheory.SimpleModule.Basic
/-!
# Maschke's theorem
We prove **Maschke's theorem** for finite groups,
in the formulation that every submodule of a `k[G]` module has a complement,
when `k` is a field with `Fintype.card G` invertible in `k`.
We do the core computation in greater generality.
For any commutative ring `k` in which `Fintype.card G` is invertible,
and a `k[G]`-linear map `i : V → W` which admits a `k`-linear retraction `π`,
we produce a `k[G]`-linear retraction by
taking the average over `G` of the conjugates of `π`.
## Implementation Notes
* These results assume `IsUnit (Fintype.card G : k)` which is equivalent to the more
familiar `¬(ringChar k ∣ Fintype.card G)`.
## Future work
It's not so far to give the usual statement, that every finite dimensional representation
of a finite group is semisimple (i.e. a direct sum of irreducibles).
-/
universe u v w
noncomputable section
open Module MonoidAlgebra
/-!
We now do the key calculation in Maschke's theorem.
Given `V → W`, an inclusion of `k[G]` modules,
assume we have some retraction `π` (i.e. `∀ v, π (i v) = v`),
just as a `k`-linear map.
(When `k` is a field, this will be available cheaply, by choosing a basis.)
We now construct a retraction of the inclusion as a `k[G]`-linear map,
by the formula
$$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$
-/
namespace LinearMap
-- At first we work with any `[CommRing k]`, and add the assumption that
-- `IsUnit (Fintype.card G : k)` when it is required.
variable {k : Type u} [CommRing k] {G : Type u} [Group G]
variable {V : Type v} [AddCommGroup V] [Module k V] [Module (MonoidAlgebra k G) V]
variable [IsScalarTower k (MonoidAlgebra k G) V]
variable {W : Type w} [AddCommGroup W] [Module k W] [Module (MonoidAlgebra k G) W]
variable [IsScalarTower k (MonoidAlgebra k G) W]
variable (π : W →ₗ[k] V)
/-- We define the conjugate of `π` by `g`, as a `k`-linear map. -/
def conjugate (g : G) : W →ₗ[k] V :=
GroupSMul.linearMap k V g⁻¹ ∘ₗ π ∘ₗ GroupSMul.linearMap k W g
theorem conjugate_apply (g : G) (v : W) :
π.conjugate g v = MonoidAlgebra.single g⁻¹ (1 : k) • π (MonoidAlgebra.single g (1 : k) • v) :=
rfl
variable (i : V →ₗ[MonoidAlgebra k G] W)
section
theorem conjugate_i (h : ∀ v : V, π (i v) = v) (g : G) (v : V) :
(conjugate π g : W → V) (i v) = v := by
rw [conjugate_apply, ← i.map_smul, h, ← mul_smul, single_mul_single, mul_one, inv_mul_cancel,
← one_def, one_smul]
end
variable (G) [Fintype G]
/-- The sum of the conjugates of `π` by each element `g : G`, as a `k`-linear map.
(We postpone dividing by the size of the group as long as possible.)
-/
def sumOfConjugates : W →ₗ[k] V :=
∑ g : G, π.conjugate g
lemma sumOfConjugates_apply (v : W) : π.sumOfConjugates G v = ∑ g : G, π.conjugate g v :=
LinearMap.sum_apply _ _ _
/-- In fact, the sum over `g : G` of the conjugate of `π` by `g` is a `k[G]`-linear map.
-/
def sumOfConjugatesEquivariant : W →ₗ[MonoidAlgebra k G] V :=
MonoidAlgebra.equivariantOfLinearOfComm (π.sumOfConjugates G) fun g v => by
simp only [sumOfConjugates_apply, Finset.smul_sum, conjugate_apply]
refine Fintype.sum_bijective (· * g) (Group.mulRight_bijective g) _ _ fun i ↦ ?_
simp only [smul_smul, single_mul_single, mul_inv_rev, mul_inv_cancel_left, one_mul]
theorem sumOfConjugatesEquivariant_apply (v : W) :
π.sumOfConjugatesEquivariant G v = ∑ g : G, π.conjugate g v :=
π.sumOfConjugates_apply G v
section
/-- We construct our `k[G]`-linear retraction of `i` as
$$ \frac{1}{|G|} \sum_{g \in G} g⁻¹ • π(g • -). $$
-/
def equivariantProjection : W →ₗ[MonoidAlgebra k G] V :=
Ring.inverse (Fintype.card G : k) • π.sumOfConjugatesEquivariant G
theorem equivariantProjection_apply (v : W) :
π.equivariantProjection G v = Ring.inverse (Fintype.card G : k) • ∑ g : G, π.conjugate g v := by
simp only [equivariantProjection, smul_apply, sumOfConjugatesEquivariant_apply]
theorem equivariantProjection_condition (hcard : IsUnit (Fintype.card G : k))
(h : ∀ v : V, π (i v) = v) (v : V) : (π.equivariantProjection G) (i v) = v := by
rw [equivariantProjection_apply]
simp only [conjugate_i π i h]
| rw [Finset.sum_const, Finset.card_univ, ← Nat.cast_smul_eq_nsmul k, smul_smul,
Ring.inverse_mul_cancel _ hcard, one_smul]
| Mathlib/RepresentationTheory/Maschke.lean | 125 | 127 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Order.Filter.SmallSets
import Mathlib.Topology.UniformSpace.Defs
import Mathlib.Topology.ContinuousOn
/-!
# Basic results on uniform spaces
Uniform spaces are a generalization of metric spaces and topological groups.
## Main definitions
In this file we define a complete lattice structure on the type `UniformSpace X`
of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures
coming from the pullback of filters.
Like distance functions, uniform structures cannot be pushed forward in general.
## Notations
Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`,
and `○` for composition of relations, seen as terms with type `Set (X × X)`.
## References
The formalization uses the books:
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
But it makes a more systematic use of the filter library.
-/
open Set Filter Topology
universe u v ua ub uc ud
/-!
### Relations, seen as `Set (α × α)`
-/
variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*}
open Uniformity
section UniformSpace
variable [UniformSpace α]
/-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`,
we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/
theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) :
∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by
suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2
induction n generalizing s with
| zero => simpa
| succ _ ihn =>
rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩
refine (ihn htU).mono fun U hU => ?_
rw [Function.iterate_succ_apply']
exact
⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts,
(compRel_mono hU.1 hU.2).trans hts⟩
/-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`,
we have `t ○ t ⊆ s`. -/
theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s :=
eventually_uniformity_iterate_comp_subset hs 1
/-!
### Balls in uniform spaces
-/
namespace UniformSpace
open UniformSpace (ball)
lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) :=
hV.preimage <| .prodMk_right _
lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) :=
hV.preimage <| .prodMk_right _
/-!
### Neighborhoods in uniform spaces
-/
theorem hasBasis_nhds_prod (x y : α) :
HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by
rw [nhds_prod_eq]
apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y)
rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩
exact
⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V,
ball_inter_right y U V⟩
end UniformSpace
open UniformSpace
theorem nhds_eq_uniformity_prod {a b : α} :
𝓝 (a, b) =
(𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by
rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift']
· exact fun s => monotone_const.set_prod monotone_preimage
· refine fun t => Monotone.set_prod ?_ monotone_const
exact monotone_preimage (f := fun y => (y, a))
theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) :
∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧
t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by
let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d }
have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp =>
mem_nhds_iff.mp <|
show cl_d ∈ 𝓝 (x, y) by
rw [nhds_eq_uniformity_prod, mem_lift'_sets]
· exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩
· exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩
choose t ht using this
exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)),
isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left,
fun ⟨a, b⟩ hp => by
simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩,
iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩
/-- Entourages are neighborhoods of the diagonal. -/
theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by
intro V V_in
rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩
have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by
rw [nhds_prod_eq]
exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in)
apply mem_of_superset this
rintro ⟨u, v⟩ ⟨u_in, v_in⟩
exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in)
/-- Entourages are neighborhoods of the diagonal. -/
theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α :=
iSup_le nhds_le_uniformity
/-- Entourages are neighborhoods of the diagonal. -/
theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α :=
(nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity
section
variable (α)
theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] :
∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) :=
let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis
⟨U, hbasis, fun n => (hsym n).2⟩
end
/-!
### Closure and interior in uniform spaces
-/
theorem closure_eq_uniformity (s : Set <| α × α) :
closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by
ext ⟨x, y⟩
simp +contextual only
[mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq,
and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty]
theorem uniformity_hasBasis_closed :
HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by
refine Filter.hasBasis_self.2 fun t h => ?_
rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩
refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩
refine Subset.trans ?_ r
rw [closure_eq_uniformity]
apply iInter_subset_of_subset
apply iInter_subset
exact ⟨w_in, w_symm⟩
theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure :=
Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right
theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)}
(h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) :=
(@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure
/-- Closed entourages form a basis of the uniformity filter. -/
theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure :=
(𝓤 α).basis_sets.uniformity_closure
theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) :=
calc
closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t
_ = ⋂ V ∈ 𝓤 α, V ○ t ○ V :=
Eq.symm <|
UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV =>
compRel_mono (compRel_mono hV Subset.rfl) hV
_ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc]
theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior :=
le_antisymm
(le_iInf₂ fun d hd => by
let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd
let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs
have : s ⊆ interior d :=
calc
s ⊆ t := hst
_ ⊆ interior d :=
ht.subset_interior_iff.mpr fun x (hx : x ∈ t) =>
let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx
hs_comp ⟨x, h₁, y, h₂, h₃⟩
have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this
simp [this])
fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset
theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by
rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs
theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s :=
let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h
⟨t, ht_mem, htc, hts⟩
theorem isOpen_iff_isOpen_ball_subset {s : Set α} :
IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by
rw [isOpen_iff_ball_subset]
constructor <;> intro h x hx
· obtain ⟨V, hV, hV'⟩ := h x hx
exact
⟨interior V, interior_mem_uniformity hV, isOpen_interior,
(ball_mono interior_subset x).trans hV'⟩
· obtain ⟨V, hV, -, hV'⟩ := h x hx
exact ⟨V, hV, hV'⟩
@[deprecated (since := "2024-11-18")] alias
isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset
/-- The uniform neighborhoods of all points of a dense set cover the whole space. -/
theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) :
⋃ x ∈ s, ball x U = univ := by
refine iUnion₂_eq_univ_iff.2 fun y => ?_
rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩
exact ⟨x, hxs, hxy⟩
/-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/
lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α}
(xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) :
⋃ i, UniformSpace.ball (xs i) U = univ := by
rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)]
exact Dense.biUnion_uniformity_ball xs_dense hU
/-!
### Uniformity bases
-/
/-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/
theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id :=
hasBasis_self.2 fun s hs =>
⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩
theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)}
(h : (𝓤 α).HasBasis p s) {t : Set (α × α)} :
t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t :=
h.mem_iff.trans <| by simp only [Prod.forall, subset_def]
/-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis
of `𝓤 α`. -/
theorem uniformity_hasBasis_open_symmetric :
HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by
simp only [← and_assoc]
refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩
exact
⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩,
symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩
theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) :
∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by
obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs
obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁
exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩
end UniformSpace
open uniformity
section Constructions
instance : PartialOrder (UniformSpace α) :=
PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext
protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl
instance : InfSet (UniformSpace α) :=
⟨fun s =>
UniformSpace.ofCore
{ uniformity := ⨅ u ∈ s, 𝓤[u]
refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl
symm := le_iInf₂ fun u hu =>
le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm
comp := le_iInf₂ fun u hu =>
le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩
protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α}
(h : t ∈ tt) : sInf tt ≤ t :=
show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h
protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α}
(h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt :=
show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h
instance : Top (UniformSpace α) :=
⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩
instance : Bot (UniformSpace α) :=
⟨{ toTopologicalSpace := ⊥
uniformity := 𝓟 idRel
symm := by simp [Tendsto]
comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset
nhds_eq_comap_uniformity := fun s => by
let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α
simp [idRel] }⟩
instance : Min (UniformSpace α) :=
⟨fun u₁ u₂ =>
{ uniformity := 𝓤[u₁] ⊓ 𝓤[u₂]
symm := u₁.symm.inf u₂.symm
comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp
toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace
nhds_eq_comap_uniformity := fun _ ↦ by
rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁,
@nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩
instance : CompleteLattice (UniformSpace α) :=
{ inferInstanceAs (PartialOrder (UniformSpace α)) with
sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x }
le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h
le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h
sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩
inf := (· ⊓ ·)
le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂
inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left
inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right
top := ⊤
le_top := fun a => show a.uniformity ≤ ⊤ from le_top
bot := ⊥
bot_le := fun u => u.toCore.refl
sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t }
le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h
sSup_le := fun _ _ h => UniformSpace.sInf_le h
sInf := sInf
le_sInf := fun _ _ hs => UniformSpace.le_sInf hs
sInf_le := fun _ _ ha => UniformSpace.sInf_le ha }
theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] :=
iInf_range
theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl
lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl
lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl
instance inhabitedUniformSpace : Inhabited (UniformSpace α) :=
⟨⊥⟩
instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) :=
⟨@UniformSpace.toCore _ default⟩
instance [Subsingleton α] : Unique (UniformSpace α) where
uniq u := bot_unique <| le_principal_iff.2 <| by
rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem
/-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f`
is the inverse image in the filter sense of the induced function `α × α → β × β`.
See note [reducible non-instances]. -/
abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where
uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2)
symm := by
simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)]
exact tendsto_swap_uniformity.comp tendsto_comap
comp := le_trans
(by
rw [comap_lift'_eq, comap_lift'_eq2]
· exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩
· exact monotone_id.compRel monotone_id)
(comap_mono u.comp)
toTopologicalSpace := u.toTopologicalSpace.induced f
nhds_eq_comap_uniformity x := by
simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def]
theorem uniformity_comap {_ : UniformSpace β} (f : α → β) :
𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) :=
rfl
lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} :
UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by
ext : 1
simp only [UniformSpace.ball, mem_preimage, Prod.map_apply]
@[simp]
theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by
ext : 2
rw [uniformity_comap, Prod.map_id, comap_id]
theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} :
UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by
ext1
simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map]
theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} :
(u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f :=
UniformSpace.ext Filter.comap_inf
theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} :
(⨅ i, u i).comap f = ⨅ i, (u i).comap f := by
ext : 1
simp [uniformity_comap, iInf_uniformity]
theorem UniformSpace.comap_mono {α γ} {f : α → γ} :
Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu =>
Filter.comap_mono hu
theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} :
UniformContinuous f ↔ uα ≤ uβ.comap f :=
Filter.map_le_iff_le_comap
theorem le_iff_uniformContinuous_id {u v : UniformSpace α} :
u ≤ v ↔ @UniformContinuous _ _ u v id := by
rw [uniformContinuous_iff, uniformSpace_comap_id, id]
theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] :
@UniformContinuous α β (UniformSpace.comap f u) u f :=
tendsto_comap
theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α]
(h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g :=
tendsto_comap_iff.2 h
namespace UniformSpace
theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) :
@nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤
@nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by
rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl
theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) :
@UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ :=
le_of_nhds_le_nhds <| to_nhds_mono h
theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} :
@UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) =
TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) :=
rfl
lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] :=
le_bot_iff.symm.trans le_principal_iff
protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)}
{u : UniformSpace α} (h : 𝓤[u].HasBasis p s) :
u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by
simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not]
theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl
theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl
theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} :
(iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace :=
TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf,
iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf]
theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} :
(sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by
rw [sInf_eq_iInf]
simp only [← toTopologicalSpace_iInf]
theorem toTopologicalSpace_inf {u v : UniformSpace α} :
(u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace :=
rfl
end UniformSpace
theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β}
(hf : UniformContinuous f) : Continuous f :=
continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <|
uniformContinuous_iff.1 hf
/-- Uniform space structure on `ULift α`. -/
instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) :=
UniformSpace.comap ULift.down ‹_›
/-- Uniform space structure on `αᵒᵈ`. -/
instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) :=
‹UniformSpace α›
section UniformContinuousInfi
-- TODO: add an `iff` lemma?
theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β}
(h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) :
UniformContinuous[u₁, u₂ ⊓ u₃] f :=
tendsto_inf.mpr ⟨h₁, h₂⟩
theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β}
(hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f :=
tendsto_inf_left hf
theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β}
(hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f :=
tendsto_inf_right hf
theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β}
{u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) :
UniformContinuous[sInf u₁, u₂] f := by
delta UniformContinuous
rw [sInf_eq_iInf', iInf_uniformity]
exact tendsto_iInf' ⟨u, h₁⟩ hf
theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} :
UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by
delta UniformContinuous
rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall]
theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β}
{i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by
delta UniformContinuous
rw [iInf_uniformity]
exact tendsto_iInf' i hf
theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} :
UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by
delta UniformContinuous
rw [iInf_uniformity, tendsto_iInf]
end UniformContinuousInfi
/-- A uniform space with the discrete uniformity has the discrete topology. -/
theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) :
DiscreteTopology α :=
⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩
instance : UniformSpace Empty := ⊥
instance : UniformSpace PUnit := ⊥
instance : UniformSpace Bool := ⊥
instance : UniformSpace ℕ := ⊥
instance : UniformSpace ℤ := ⊥
section
variable [UniformSpace α]
open Additive Multiplicative
instance : UniformSpace (Additive α) := ‹UniformSpace α›
instance : UniformSpace (Multiplicative α) := ‹UniformSpace α›
theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) :=
uniformContinuous_id
theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) :=
uniformContinuous_id
theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) :=
uniformContinuous_id
theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) :=
uniformContinuous_id
theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl
theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl
end
instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) :=
UniformSpace.comap Subtype.val t
theorem uniformity_subtype {p : α → Prop} [UniformSpace α] :
𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) :=
rfl
theorem uniformity_setCoe {s : Set α} [UniformSpace α] :
𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) :=
rfl
theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] :
map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by
rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val]
theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] :
UniformContinuous (Subtype.val : { a : α // p a } → α) :=
uniformContinuous_comap
theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α}
(hf : UniformContinuous f) (h : ∀ x, p (f x)) :
UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) :=
uniformContinuous_comap' hf
theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} :
UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by
delta UniformContinuousOn UniformContinuous
rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl
theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β}
{s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) :
Tendsto f (𝓝 a) (𝓝 (f a)) := by
rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm]
exact tendsto_map' hf.continuous.continuousAt
theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α}
(h : UniformContinuousOn f s) : ContinuousOn f s := by
rw [uniformContinuousOn_iff_restrict] at h
rw [continuousOn_iff_continuous_restrict]
exact h.continuous
@[to_additive]
instance [UniformSpace α] : UniformSpace αᵐᵒᵖ :=
UniformSpace.comap MulOpposite.unop ‹_›
@[to_additive]
theorem uniformity_mulOpposite [UniformSpace α] :
𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) :=
rfl
@[to_additive (attr := simp)]
theorem comap_uniformity_mulOpposite [UniformSpace α] :
comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by
simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id
namespace MulOpposite
@[to_additive]
theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) :=
uniformContinuous_comap
@[to_additive]
theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) :=
uniformContinuous_comap' uniformContinuous_id
end MulOpposite
section Prod
open UniformSpace
/- a similar product space is possible on the function space (uniformity of pointwise convergence),
but we want to have the uniformity of uniform convergence on function spaces -/
instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) :=
u₁.comap Prod.fst ⊓ u₂.comap Prod.snd
-- check the above produces no diamond for `simp` and typeclass search
example [UniformSpace α] [UniformSpace β] :
(instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by
with_reducible_and_instances rfl
theorem uniformity_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) =
((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓
(𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) :=
rfl
instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)]
[UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by
rw [uniformity_prod]
infer_instance
theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) =
comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by
simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def]
theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] :
𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by
rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod]
theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β]
{s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2)
(hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by
rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf
rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩
exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩
/-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β`
once we permute coordinates. -/
def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) :=
{((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v}
theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} :
p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl
theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)}
{v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) :
entourageProd u v ∈ 𝓤 (α × β) := by
rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv)
theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) :
ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by
ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage]
lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)}
(hu : IsSymmetricRel u) (hv : IsSymmetricRel v) :
IsSymmetricRel (entourageProd u v) :=
Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm
theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β]
{pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)}
(ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) :
(𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2)
(fun i ↦ entourageProd (sa i.1) (sb i.2)) :=
(ha.comap _).inf (hb.comap _)
theorem entourageProd_subset [UniformSpace α] [UniformSpace β]
{s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) :
∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by
rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩
use w.1, hw.1.1, w.2, hw.1.2, hw.2
theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] :
Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) :=
le_trans (map_mono inf_le_left) map_comap_le
theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] :
Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) :=
le_trans (map_mono inf_le_right) map_comap_le
theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] :
UniformContinuous fun p : α × β => p.1 :=
tendsto_prod_uniformity_fst
theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] :
UniformContinuous fun p : α × β => p.2 :=
tendsto_prod_uniformity_snd
variable [UniformSpace α] [UniformSpace β] [UniformSpace γ]
theorem UniformContinuous.prodMk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁)
(h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by
rw [UniformContinuous, uniformity_prod]
exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
@[deprecated (since := "2025-03-10")]
alias UniformContinuous.prod_mk := UniformContinuous.prodMk
theorem UniformContinuous.prodMk_left {f : α × β → γ} (h : UniformContinuous f) (b) :
UniformContinuous fun a => f (a, b) :=
h.comp (uniformContinuous_id.prodMk uniformContinuous_const)
@[deprecated (since := "2025-03-10")]
alias UniformContinuous.prod_mk_left := UniformContinuous.prodMk_left
theorem UniformContinuous.prodMk_right {f : α × β → γ} (h : UniformContinuous f) (a) :
UniformContinuous fun b => f (a, b) :=
h.comp (uniformContinuous_const.prodMk uniformContinuous_id)
@[deprecated (since := "2025-03-10")]
alias UniformContinuous.prod_mk_right := UniformContinuous.prodMk_right
theorem UniformContinuous.prodMap [UniformSpace δ] {f : α → γ} {g : β → δ}
(hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) :=
(hf.comp uniformContinuous_fst).prodMk (hg.comp uniformContinuous_snd)
theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] :
@UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd =
@instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace :=
rfl
/-- A version of `UniformContinuous.inf_dom_left` for binary functions -/
theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α}
{ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ}
(h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2
exact UniformContinuous fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_inf_dom_left₂`
have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _))
have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _))
have h_unif_cont_id :=
@UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id
/-- A version of `UniformContinuous.inf_dom_right` for binary functions -/
theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α}
{ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ}
(h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2
exact UniformContinuous fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_inf_dom_right₂`
have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _))
have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _))
have h_unif_cont_id :=
@UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id
/-- A version of `uniformContinuous_sInf_dom` for binary functions -/
theorem uniformContinuous_sInf_dom₂ {α β γ} {f : α → β → γ} {uas : Set (UniformSpace α)}
{ubs : Set (UniformSpace β)} {ua : UniformSpace α} {ub : UniformSpace β} {uc : UniformSpace γ}
(ha : ua ∈ uas) (hb : ub ∈ ubs) (hf : UniformContinuous fun p : α × β => f p.1 p.2) : by
haveI := sInf uas; haveI := sInf ubs
exact @UniformContinuous _ _ _ uc fun p : α × β => f p.1 p.2 := by
-- proof essentially copied from `continuous_sInf_dom`
let _ : UniformSpace (α × β) := instUniformSpaceProd
have ha := uniformContinuous_sInf_dom ha uniformContinuous_id
have hb := uniformContinuous_sInf_dom hb uniformContinuous_id
have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (sInf uas) (sInf ubs) ua ub _ _ ha hb
exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ hf h_unif_cont_id
end Prod
section
open UniformSpace Function
variable {δ' : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace δ]
[UniformSpace δ']
local notation f " ∘₂ " g => Function.bicompr f g
/-- Uniform continuity for functions of two variables. -/
def UniformContinuous₂ (f : α → β → γ) :=
UniformContinuous (uncurry f)
theorem uniformContinuous₂_def (f : α → β → γ) :
UniformContinuous₂ f ↔ UniformContinuous (uncurry f) :=
Iff.rfl
theorem UniformContinuous₂.uniformContinuous {f : α → β → γ} (h : UniformContinuous₂ f) :
UniformContinuous (uncurry f) :=
h
theorem uniformContinuous₂_curry (f : α × β → γ) :
UniformContinuous₂ (Function.curry f) ↔ UniformContinuous f := by
rw [UniformContinuous₂, uncurry_curry]
theorem UniformContinuous₂.comp {f : α → β → γ} {g : γ → δ} (hg : UniformContinuous g)
(hf : UniformContinuous₂ f) : UniformContinuous₂ (g ∘₂ f) :=
hg.comp hf
theorem UniformContinuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β}
(hf : UniformContinuous₂ f) (hga : UniformContinuous ga) (hgb : UniformContinuous gb) :
UniformContinuous₂ (bicompl f ga gb) :=
hf.uniformContinuous.comp (hga.prodMap hgb)
end
theorem toTopologicalSpace_subtype [u : UniformSpace α] {p : α → Prop} :
@UniformSpace.toTopologicalSpace (Subtype p) instUniformSpaceSubtype =
@instTopologicalSpaceSubtype α p u.toTopologicalSpace :=
rfl
section Sum
variable [UniformSpace α] [UniformSpace β]
open Sum
-- Obsolete auxiliary definitions and lemmas
/-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained
by taking independently an entourage of the diagonal in the first part, and an entourage of
the diagonal in the second part. -/
instance Sum.instUniformSpace : UniformSpace (α ⊕ β) where
uniformity := map (fun p : α × α => (inl p.1, inl p.2)) (𝓤 α) ⊔
map (fun p : β × β => (inr p.1, inr p.2)) (𝓤 β)
symm := fun _ hs ↦ ⟨symm_le_uniformity hs.1, symm_le_uniformity hs.2⟩
comp := fun s hs ↦ by
rcases comp_mem_uniformity_sets hs.1 with ⟨tα, htα, Htα⟩
rcases comp_mem_uniformity_sets hs.2 with ⟨tβ, htβ, Htβ⟩
filter_upwards [mem_lift' (union_mem_sup (image_mem_map htα) (image_mem_map htβ))]
rintro ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩
exacts [@Htα (_, _) ⟨b, hab, hbc⟩, @Htβ (_, _) ⟨b, hab, hbc⟩]
nhds_eq_comap_uniformity x := by
ext
cases x <;> simp [mem_comap', -mem_comap, nhds_inl, nhds_inr, nhds_eq_comap_uniformity,
Prod.ext_iff]
/-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage
of the diagonal. -/
theorem union_mem_uniformity_sum {a : Set (α × α)} (ha : a ∈ 𝓤 α) {b : Set (β × β)} (hb : b ∈ 𝓤 β) :
Prod.map inl inl '' a ∪ Prod.map inr inr '' b ∈ 𝓤 (α ⊕ β) :=
union_mem_sup (image_mem_map ha) (image_mem_map hb)
theorem Sum.uniformity : 𝓤 (α ⊕ β) = map (Prod.map inl inl) (𝓤 α) ⊔ map (Prod.map inr inr) (𝓤 β) :=
rfl
lemma uniformContinuous_inl : UniformContinuous (Sum.inl : α → α ⊕ β) := le_sup_left
lemma uniformContinuous_inr : UniformContinuous (Sum.inr : β → α ⊕ β) := le_sup_right
instance [IsCountablyGenerated (𝓤 α)] [IsCountablyGenerated (𝓤 β)] :
IsCountablyGenerated (𝓤 (α ⊕ β)) := by
rw [Sum.uniformity]
infer_instance
end Sum
end Constructions
/-!
### Expressing continuity properties in uniform spaces
We reformulate the various continuity properties of functions taking values in a uniform space
in terms of the uniformity in the target. Since the same lemmas (essentially with the same names)
also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or
the edistance in the target), we put them in a namespace `Uniform` here.
In the metric and emetric space setting, there are also similar lemmas where one assumes that
both the source and the target are metric spaces, reformulating things in terms of the distance
on both sides. These lemmas are generally written without primes, and the versions where only
the target is a metric space is primed. We follow the same convention here, thus giving lemmas
with primes.
-/
namespace Uniform
variable [UniformSpace α]
theorem tendsto_nhds_right {f : Filter β} {u : β → α} {a : α} :
Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (a, u x)) f (𝓤 α) := by
rw [nhds_eq_comap_uniformity, tendsto_comap_iff]; rfl
theorem tendsto_nhds_left {f : Filter β} {u : β → α} {a : α} :
Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (u x, a)) f (𝓤 α) := by
rw [nhds_eq_comap_uniformity', tendsto_comap_iff]; rfl
theorem continuousAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := by
rw [ContinuousAt, tendsto_nhds_right]
theorem continuousAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := by
rw [ContinuousAt, tendsto_nhds_left]
theorem continuousAt_iff_prod [TopologicalSpace β] {f : β → α} {b : β} :
ContinuousAt f b ↔ Tendsto (fun x : β × β => (f x.1, f x.2)) (𝓝 (b, b)) (𝓤 α) :=
⟨fun H => le_trans (H.prodMap' H) (nhds_le_uniformity _), fun H =>
continuousAt_iff'_left.2 <| H.comp <| tendsto_id.prodMk_nhds tendsto_const_nhds⟩
theorem continuousWithinAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} :
ContinuousWithinAt f s b ↔ Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by
rw [ContinuousWithinAt, tendsto_nhds_right]
theorem continuousWithinAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} :
ContinuousWithinAt f s b ↔ Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by
rw [ContinuousWithinAt, tendsto_nhds_left]
theorem continuousOn_iff'_right [TopologicalSpace β] {f : β → α} {s : Set β} :
ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by
simp [ContinuousOn, continuousWithinAt_iff'_right]
theorem continuousOn_iff'_left [TopologicalSpace β] {f : β → α} {s : Set β} :
ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by
simp [ContinuousOn, continuousWithinAt_iff'_left]
theorem continuous_iff'_right [TopologicalSpace β] {f : β → α} :
Continuous f ↔ ∀ b, Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_right
theorem continuous_iff'_left [TopologicalSpace β] {f : β → α} :
Continuous f ↔ ∀ b, Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) :=
continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_left
/-- Consider two functions `f` and `g` which coincide on a set `s` and are continuous there.
Then there is an open neighborhood of `s` on which `f` and `g` are uniformly close. -/
lemma exists_is_open_mem_uniformity_of_forall_mem_eq
[TopologicalSpace β] {r : Set (α × α)} {s : Set β}
{f g : β → α} (hf : ∀ x ∈ s, ContinuousAt f x) (hg : ∀ x ∈ s, ContinuousAt g x)
(hfg : s.EqOn f g) (hr : r ∈ 𝓤 α) :
∃ t, IsOpen t ∧ s ⊆ t ∧ ∀ x ∈ t, (f x, g x) ∈ r := by
have A : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ∀ z ∈ t, (f z, g z) ∈ r := by
intro x hx
obtain ⟨t, ht, htsymm, htr⟩ := comp_symm_mem_uniformity_sets hr
have A : {z | (f x, f z) ∈ t} ∈ 𝓝 x := (hf x hx).preimage_mem_nhds (mem_nhds_left (f x) ht)
have B : {z | (g x, g z) ∈ t} ∈ 𝓝 x := (hg x hx).preimage_mem_nhds (mem_nhds_left (g x) ht)
rcases _root_.mem_nhds_iff.1 (inter_mem A B) with ⟨u, hu, u_open, xu⟩
refine ⟨u, u_open, xu, fun y hy ↦ ?_⟩
have I1 : (f y, f x) ∈ t := (htsymm.mk_mem_comm).2 (hu hy).1
have I2 : (g x, g y) ∈ t := (hu hy).2
rw [hfg hx] at I1
exact htr (prodMk_mem_compRel I1 I2)
choose! t t_open xt ht using A
refine ⟨⋃ x ∈ s, t x, isOpen_biUnion t_open, fun x hx ↦ mem_biUnion hx (xt x hx), ?_⟩
rintro x hx
simp only [mem_iUnion, exists_prop] at hx
rcases hx with ⟨y, ys, hy⟩
exact ht y ys x hy
end Uniform
theorem Filter.Tendsto.congr_uniformity {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β}
(hf : Tendsto f l (𝓝 b)) (hg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto g l (𝓝 b) :=
Uniform.tendsto_nhds_right.2 <| (Uniform.tendsto_nhds_right.1 hf).uniformity_trans hg
theorem Uniform.tendsto_congr {α β} [UniformSpace β] {f g : α → β} {l : Filter α} {b : β}
(hfg : Tendsto (fun x => (f x, g x)) l (𝓤 β)) : Tendsto f l (𝓝 b) ↔ Tendsto g l (𝓝 b) :=
⟨fun h => h.congr_uniformity hfg, fun h => h.congr_uniformity hfg.uniformity_symm⟩
| Mathlib/Topology/UniformSpace/Basic.lean | 1,924 | 1,926 | |
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
import Mathlib.Analysis.SpecialFunctions.Complex.Circle
import Mathlib.Analysis.InnerProductSpace.l2Space
import Mathlib.MeasureTheory.Function.ContinuousMapDense
import Mathlib.MeasureTheory.Function.L2Space
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Periodic
import Mathlib.Topology.ContinuousMap.StoneWeierstrass
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
/-!
# Fourier analysis on the additive circle
This file contains basic results on Fourier series for functions on the additive circle
`AddCircle T = ℝ / ℤ • T`.
## Main definitions
* `haarAddCircle`, Haar measure on `AddCircle T`, normalized to have total measure `1`.
Note that this is not the same normalisation
as the standard measure defined in `IntervalIntegral.Periodic`,
so we do not declare it as a `MeasureSpace` instance, to avoid confusion.
* for `n : ℤ`, `fourier n` is the monomial `fun x => exp (2 π i n x / T)`,
bundled as a continuous map from `AddCircle T` to `ℂ`.
* `fourierBasis` is the Hilbert basis of `Lp ℂ 2 haarAddCircle` given by the images of the
monomials `fourier n`.
* `fourierCoeff f n`, for `f : AddCircle T → E` (with `E` a complete normed `ℂ`-vector space), is
the `n`-th Fourier coefficient of `f`, defined as an integral over `AddCircle T`. The lemma
`fourierCoeff_eq_intervalIntegral` expresses this as an integral over `[a, a + T]` for any real
`a`.
* `fourierCoeffOn`, for `f : ℝ → E` and `a < b` reals, is the `n`-th Fourier
coefficient of the unique periodic function of period `b - a` which agrees with `f` on `(a, b]`.
The lemma `fourierCoeffOn_eq_integral` expresses this as an integral over `[a, b]`.
## Main statements
The theorem `span_fourier_closure_eq_top` states that the span of the monomials `fourier n` is
dense in `C(AddCircle T, ℂ)`, i.e. that its `Submodule.topologicalClosure` is `⊤`. This follows
from the Stone-Weierstrass theorem after checking that the span is a subalgebra, is closed under
conjugation, and separates points.
Using this and general theory on approximation of Lᵖ functions by continuous functions, we deduce
(`span_fourierLp_closure_eq_top`) that for any `1 ≤ p < ∞`, the span of the Fourier monomials is
dense in the Lᵖ space of `AddCircle T`. For `p = 2` we show (`orthonormal_fourier`) that the
monomials are also orthonormal, so they form a Hilbert basis for L², which is named as
`fourierBasis`; in particular, for `L²` functions `f`, the Fourier series of `f` converges to `f`
in the `L²` topology (`hasSum_fourier_series_L2`). Parseval's identity, `tsum_sq_fourierCoeff`, is
a direct consequence.
For continuous maps `f : AddCircle T → ℂ`, the theorem
`hasSum_fourier_series_of_summable` states that if the sequence of Fourier
coefficients of `f` is summable, then the Fourier series `∑ (i : ℤ), fourierCoeff f i * fourier i`
converges to `f` in the uniform-convergence topology of `C(AddCircle T, ℂ)`.
-/
noncomputable section
open scoped ENNReal ComplexConjugate Real
open TopologicalSpace ContinuousMap MeasureTheory MeasureTheory.Measure Algebra Submodule Set
variable {T : ℝ}
namespace AddCircle
/-! ### Measure on `AddCircle T`
In this file we use the Haar measure on `AddCircle T` normalised to have total measure 1 (which is
**not** the same as the standard measure defined in `Topology.Instances.AddCircle`). -/
variable [hT : Fact (0 < T)]
/-- Haar measure on the additive circle, normalised to have total measure 1. -/
def haarAddCircle : Measure (AddCircle T) :=
addHaarMeasure ⊤
-- The `IsAddHaarMeasure` instance should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : IsAddHaarMeasure (@haarAddCircle T _) :=
Measure.isAddHaarMeasure_addHaarMeasure ⊤
instance : IsProbabilityMeasure (@haarAddCircle T _) :=
IsProbabilityMeasure.mk addHaarMeasure_self
theorem volume_eq_smul_haarAddCircle :
(volume : Measure (AddCircle T)) = ENNReal.ofReal T • (@haarAddCircle T _) :=
rfl
end AddCircle
open AddCircle
section Monomials
/-- The family of exponential monomials `fun x => exp (2 π i n x / T)`, parametrized by `n : ℤ` and
considered as bundled continuous maps from `ℝ / ℤ • T` to `ℂ`. -/
def fourier (n : ℤ) : C(AddCircle T, ℂ) where
toFun x := toCircle (n • x :)
continuous_toFun := continuous_induced_dom.comp <| continuous_toCircle.comp <| continuous_zsmul _
@[simp]
theorem fourier_apply {n : ℤ} {x : AddCircle T} : fourier n x = toCircle (n • x :) :=
rfl
-- simp normal form is `fourier_coe_apply'`
theorem fourier_coe_apply {n : ℤ} {x : ℝ} :
fourier n (x : AddCircle T) = Complex.exp (2 * π * Complex.I * n * x / T) := by
rw [fourier_apply, ← QuotientAddGroup.mk_zsmul, toCircle, Function.Periodic.lift_coe,
Circle.coe_exp, Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_mul, zsmul_eq_mul,
Complex.ofReal_mul, Complex.ofReal_intCast]
norm_num
congr 1; ring
@[simp]
theorem fourier_coe_apply' {n : ℤ} {x : ℝ} :
toCircle (n • (x : AddCircle T) :) = Complex.exp (2 * π * Complex.I * n * x / T) := by
rw [← fourier_apply]; exact fourier_coe_apply
-- simp normal form is `fourier_zero'`
theorem fourier_zero {x : AddCircle T} : fourier 0 x = 1 := by
induction x using QuotientAddGroup.induction_on
simp only [fourier_coe_apply]
norm_num
theorem fourier_zero' {x : AddCircle T} : @toCircle T 0 = (1 : ℂ) := by
have : fourier 0 x = @toCircle T 0 := by rw [fourier_apply, zero_smul]
rw [← this]; exact fourier_zero
-- simp normal form is *also* `fourier_zero'`
theorem fourier_eval_zero (n : ℤ) : fourier n (0 : AddCircle T) = 1 := by
rw [← QuotientAddGroup.mk_zero, fourier_coe_apply, Complex.ofReal_zero, mul_zero,
zero_div, Complex.exp_zero]
theorem fourier_one {x : AddCircle T} : fourier 1 x = toCircle x := by rw [fourier_apply, one_zsmul]
-- simp normal form is `fourier_neg'`
theorem fourier_neg {n : ℤ} {x : AddCircle T} : fourier (-n) x = conj (fourier n x) := by
induction x using QuotientAddGroup.induction_on
simp_rw [fourier_apply, toCircle]
rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_zsmul]
simp_rw [Function.Periodic.lift_coe, ← Circle.coe_inv_eq_conj, ← Circle.exp_neg,
neg_smul, mul_neg]
@[simp]
theorem fourier_neg' {n : ℤ} {x : AddCircle T} : @toCircle T (-(n • x)) = conj (fourier n x) := by
rw [← neg_smul, ← fourier_apply]; exact fourier_neg
-- simp normal form is `fourier_add'`
theorem fourier_add {m n : ℤ} {x : AddCircle T} : fourier (m+n) x = fourier m x * fourier n x := by
simp_rw [fourier_apply, add_zsmul, toCircle_add, Circle.coe_mul]
@[simp]
theorem fourier_add' {m n : ℤ} {x : AddCircle T} :
toCircle ((m + n) • x :) = fourier m x * fourier n x := by
rw [← fourier_apply]; exact fourier_add
theorem fourier_norm [Fact (0 < T)] (n : ℤ) : ‖@fourier T n‖ = 1 := by
rw [ContinuousMap.norm_eq_iSup_norm]
have : ∀ x : AddCircle T, ‖fourier n x‖ = 1 := fun x => Circle.norm_coe _
simp_rw [this]
exact @ciSup_const _ _ _ Zero.instNonempty _
/-- For `n ≠ 0`, a translation by `T / 2 / n` negates the function `fourier n`. -/
theorem fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (hT : 0 < T) (x : AddCircle T) :
@fourier T n (x + ↑(T / 2 / n)) = -fourier n x := by
rw [fourier_apply, zsmul_add, ← QuotientAddGroup.mk_zsmul, toCircle_add,
Metric.unitSphere.coe_mul]
have : (n : ℂ) ≠ 0 := by simpa using hn
have : (@toCircle T (n • (T / 2 / n) : ℝ) : ℂ) = -1 := by
rw [zsmul_eq_mul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp]
replace hT := Complex.ofReal_ne_zero.mpr hT.ne'
convert Complex.exp_pi_mul_I using 3
field_simp; ring
rw [this]; simp
/-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` . -/
def fourierSubalgebra : StarSubalgebra ℂ C(AddCircle T, ℂ) where
toSubalgebra := Algebra.adjoin ℂ (range fourier)
star_mem' := by
show Algebra.adjoin ℂ (range (fourier (T := T))) ≤
star (Algebra.adjoin ℂ (range (fourier (T := T))))
refine adjoin_le ?_
rintro - ⟨n, rfl⟩
exact subset_adjoin ⟨-n, ext fun _ => fourier_neg⟩
/-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is in fact the
linear span of these functions. -/
theorem fourierSubalgebra_coe :
Subalgebra.toSubmodule (@fourierSubalgebra T).toSubalgebra = span ℂ (range (@fourier T)) := by
apply adjoin_eq_span_of_subset
refine Subset.trans ?_ Submodule.subset_span
intro x hx
refine Submonoid.closure_induction (fun _ => id) ⟨0, ?_⟩ ?_ hx
· ext1 z; exact fourier_zero
· rintro - - - - ⟨m, rfl⟩ ⟨n, rfl⟩
refine ⟨m + n, ?_⟩
ext1 z
exact fourier_add
/- a post-port refactor made `fourierSubalgebra` into a `StarSubalgebra`, and eliminated
`conjInvariantSubalgebra` entirely, making this lemma irrelevant. -/
variable [hT : Fact (0 < T)]
/-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ`
separates points. -/
theorem fourierSubalgebra_separatesPoints : (@fourierSubalgebra T).SeparatesPoints := by
intro x y hxy
refine ⟨_, ⟨fourier 1, subset_adjoin ⟨1, rfl⟩, rfl⟩, ?_⟩
dsimp only; rw [fourier_one, fourier_one]
contrapose! hxy
rw [Subtype.coe_inj] at hxy
exact injective_toCircle hT.elim.ne' hxy
/-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is dense. -/
theorem fourierSubalgebra_closure_eq_top : (@fourierSubalgebra T).topologicalClosure = ⊤ :=
ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints fourierSubalgebra
fourierSubalgebra_separatesPoints
/-- The linear span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`. -/
theorem span_fourier_closure_eq_top : (span ℂ (range <| @fourier T)).topologicalClosure = ⊤ := by
rw [← fourierSubalgebra_coe]
exact congr_arg (Subalgebra.toSubmodule <| StarSubalgebra.toSubalgebra ·)
fourierSubalgebra_closure_eq_top
/-- The family of monomials `fourier n`, parametrized by `n : ℤ` and considered as
elements of the `Lp` space of functions `AddCircle T → ℂ`. -/
abbrev fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : Lp ℂ p (@haarAddCircle T hT) :=
toLp (E := ℂ) p haarAddCircle ℂ (fourier n)
theorem coeFn_fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) :
@fourierLp T hT p _ n =ᵐ[haarAddCircle] fourier n :=
coeFn_toLp haarAddCircle (fourier n)
/-- For each `1 ≤ p < ∞`, the linear span of the monomials `fourier n` is dense in
`Lp ℂ p haarAddCircle`. -/
theorem span_fourierLp_closure_eq_top {p : ℝ≥0∞} [Fact (1 ≤ p)] (hp : p ≠ ∞) :
(span ℂ (range (@fourierLp T _ p _))).topologicalClosure = ⊤ := by
convert
(ContinuousMap.toLp_denseRange ℂ (@haarAddCircle T hT) ℂ hp).topologicalClosure_map_submodule
span_fourier_closure_eq_top
rw [map_span]
unfold fourierLp
rw [range_comp']
simp only [ContinuousLinearMap.coe_coe]
/-- The monomials `fourier n` are an orthonormal set with respect to normalised Haar measure. -/
theorem orthonormal_fourier : Orthonormal ℂ (@fourierLp T _ 2 _) := by
rw [orthonormal_iff_ite]
intro i j
rw [ContinuousMap.inner_toLp (@haarAddCircle T hT) (fourier i) (fourier j)]
simp_rw [← fourier_neg, ← fourier_add]
split_ifs with h
· simp_rw [h, add_neg_cancel]
have : ⇑(@fourier T 0) = (fun _ => 1 : AddCircle T → ℂ) := by ext1; exact fourier_zero
rw [this, integral_const, measureReal_univ_eq_one, Complex.real_smul,
Complex.ofReal_one, mul_one]
have hij : j + -i ≠ 0 := by
exact sub_ne_zero.mpr (Ne.symm h)
convert integral_eq_zero_of_add_right_eq_neg (μ := haarAddCircle)
(fourier_add_half_inv_index hij hT.elim)
end Monomials
section ScopeHT
-- everything from here on needs `0 < T`
variable [hT : Fact (0 < T)]
section fourierCoeff
variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E]
/-- The `n`-th Fourier coefficient of a function `AddCircle T → E`, for `E` a complete normed
`ℂ`-vector space, defined as the integral over `AddCircle T` of `fourier (-n) t • f t`. -/
def fourierCoeff (f : AddCircle T → E) (n : ℤ) : E :=
∫ t : AddCircle T, fourier (-n) t • f t ∂haarAddCircle
/-- The Fourier coefficients of a function on `AddCircle T` can be computed as an integral
over `[a, a + T]`, for any real `a`. -/
theorem fourierCoeff_eq_intervalIntegral (f : AddCircle T → E) (n : ℤ) (a : ℝ) :
fourierCoeff f n = (1 / T) • ∫ x in a..a + T, @fourier T (-n) x • f x := by
have : ∀ x : ℝ, @fourier T (-n) x • f x = (fun z : AddCircle T => @fourier T (-n) z • f z) x := by
intro x; rfl
-- After https://github.com/leanprover/lean4/pull/3124, we need to add `singlePass := true` to avoid an infinite loop.
simp_rw +singlePass [this]
rw [fourierCoeff, AddCircle.intervalIntegral_preimage T a (fun z => _ • _),
volume_eq_smul_haarAddCircle, integral_smul_measure, ENNReal.toReal_ofReal hT.out.le,
← smul_assoc, smul_eq_mul, one_div_mul_cancel hT.out.ne', one_smul]
theorem fourierCoeff.const_smul (f : AddCircle T → E) (c : ℂ) (n : ℤ) :
fourierCoeff (c • f :) n = c • fourierCoeff f n := by
simp_rw [fourierCoeff, Pi.smul_apply, ← smul_assoc, smul_eq_mul, mul_comm, ← smul_eq_mul,
smul_assoc, integral_smul]
theorem fourierCoeff.const_mul (f : AddCircle T → ℂ) (c : ℂ) (n : ℤ) :
fourierCoeff (fun x => c * f x) n = c * fourierCoeff f n :=
fourierCoeff.const_smul f c n
/-- For a function on `ℝ`, the Fourier coefficients of `f` on `[a, b]` are defined as the
Fourier coefficients of the unique periodic function agreeing with `f` on `Ioc a b`. -/
def fourierCoeffOn {a b : ℝ} (hab : a < b) (f : ℝ → E) (n : ℤ) : E :=
haveI := Fact.mk (by linarith : 0 < b - a)
fourierCoeff (AddCircle.liftIoc (b - a) a f) n
theorem fourierCoeffOn_eq_integral {a b : ℝ} (f : ℝ → E) (n : ℤ) (hab : a < b) :
fourierCoeffOn hab f n =
(1 / (b - a)) • ∫ x in a..b, fourier (-n) (x : AddCircle (b - a)) • f x := by
haveI := Fact.mk (by linarith : 0 < b - a)
rw [fourierCoeffOn, fourierCoeff_eq_intervalIntegral _ _ a, add_sub, add_sub_cancel_left]
congr 1
simp_rw [intervalIntegral.integral_of_le hab.le]
refine setIntegral_congr_fun measurableSet_Ioc fun x hx => ?_
rw [liftIoc_coe_apply]
rwa [add_sub, add_sub_cancel_left]
theorem fourierCoeffOn.const_smul {a b : ℝ} (f : ℝ → E) (c : ℂ) (n : ℤ) (hab : a < b) :
fourierCoeffOn hab (c • f) n = c • fourierCoeffOn hab f n := by
haveI := Fact.mk (by linarith : 0 < b - a)
apply fourierCoeff.const_smul
theorem fourierCoeffOn.const_mul {a b : ℝ} (f : ℝ → ℂ) (c : ℂ) (n : ℤ) (hab : a < b) :
fourierCoeffOn hab (fun x => c * f x) n = c * fourierCoeffOn hab f n :=
fourierCoeffOn.const_smul _ _ _ _
theorem fourierCoeff_liftIoc_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) :
fourierCoeff (AddCircle.liftIoc T a f) n =
fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by
rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral, add_sub_cancel_left a T]
· congr 1
refine intervalIntegral.integral_congr_ae (ae_of_all _ fun x hx => ?_)
rw [liftIoc_coe_apply]
rwa [uIoc_of_le (lt_add_of_pos_right a hT.out).le] at hx
theorem fourierCoeff_liftIco_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) :
fourierCoeff (AddCircle.liftIco T a f) n =
fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by
rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral _ _ a, add_sub_cancel_left a T]
congr 1
simp_rw [intervalIntegral.integral_of_le (lt_add_of_pos_right a hT.out).le]
iterate 2 rw [integral_Ioc_eq_integral_Ioo]
refine setIntegral_congr_fun measurableSet_Ioo fun x hx => ?_
rw [liftIco_coe_apply (Ioo_subset_Ico_self hx)]
end fourierCoeff
section FourierL2
/-- We define `fourierBasis` to be a `ℤ`-indexed Hilbert basis for `Lp ℂ 2 haarAddCircle`,
which by definition is an isometric isomorphism from `Lp ℂ 2 haarAddCircle` to `ℓ²(ℤ, ℂ)`. -/
def fourierBasis : HilbertBasis ℤ ℂ (Lp ℂ 2 <| @haarAddCircle T hT) :=
HilbertBasis.mk orthonormal_fourier (span_fourierLp_closure_eq_top (by norm_num)).ge
/-- The elements of the Hilbert basis `fourierBasis` are the functions `fourierLp 2`, i.e. the
monomials `fourier n` on the circle considered as elements of `L²`. -/
@[simp]
theorem coe_fourierBasis : ⇑(@fourierBasis T hT) = @fourierLp T hT 2 _ :=
HilbertBasis.coe_mk _ _
/-- Under the isometric isomorphism `fourierBasis` from `Lp ℂ 2 haarAddCircle` to `ℓ²(ℤ, ℂ)`, the
`i`-th coefficient is `fourierCoeff f i`, i.e., the integral over `AddCircle T` of
`fun t => fourier (-i) t * f t` with respect to the Haar measure of total mass 1. -/
theorem fourierBasis_repr (f : Lp ℂ 2 <| @haarAddCircle T hT) (i : ℤ) :
fourierBasis.repr f i = fourierCoeff f i := by
trans ∫ t : AddCircle T, conj ((@fourierLp T hT 2 _ i : AddCircle T → ℂ) t) * f t ∂haarAddCircle
· rw [fourierBasis.repr_apply_apply f i, MeasureTheory.L2.inner_def, coe_fourierBasis]
simp only [RCLike.inner_apply']
· apply integral_congr_ae
filter_upwards [coeFn_fourierLp 2 i] with _ ht
rw [ht, ← fourier_neg, smul_eq_mul]
/-- The Fourier series of an `L2` function `f` sums to `f`, in the `L²` space of `AddCircle T`. -/
theorem hasSum_fourier_series_L2 (f : Lp ℂ 2 <| @haarAddCircle T hT) :
HasSum (fun i => fourierCoeff f i • fourierLp 2 i) f := by
simp_rw [← fourierBasis_repr]; rw [← coe_fourierBasis]
exact HilbertBasis.hasSum_repr fourierBasis f
/-- **Parseval's identity**: for an `L²` function `f` on `AddCircle T`, the sum of the squared
norms of the Fourier coefficients equals the `L²` norm of `f`. -/
theorem tsum_sq_fourierCoeff (f : Lp ℂ 2 <| @haarAddCircle T hT) :
∑' i : ℤ, ‖fourierCoeff f i‖ ^ 2 = ∫ t : AddCircle T, ‖f t‖ ^ 2 ∂haarAddCircle := by
simp_rw [← fourierBasis_repr]
have H₁ : ‖fourierBasis.repr f‖ ^ 2 = ∑' i, ‖fourierBasis.repr f i‖ ^ 2 := by
apply_mod_cast lp.norm_rpow_eq_tsum ?_ (fourierBasis.repr f)
norm_num
have H₂ : ‖fourierBasis.repr f‖ ^ 2 = ‖f‖ ^ 2 := by simp
have H₃ := congr_arg RCLike.re (@L2.inner_def (AddCircle T) ℂ ℂ _ _ _ _ _ f f)
rw [← integral_re] at H₃
· simp only [← norm_sq_eq_re_inner] at H₃
rw [← H₁, H₂, H₃]
· exact L2.integrable_inner f f
end FourierL2
section Convergence
variable (f : C(AddCircle T, ℂ))
theorem fourierCoeff_toLp (n : ℤ) :
fourierCoeff (toLp (E := ℂ) 2 haarAddCircle ℂ f) n = fourierCoeff f n :=
integral_congr_ae (Filter.EventuallyEq.mul (Filter.Eventually.of_forall (by tauto))
(ContinuousMap.coeFn_toAEEqFun haarAddCircle f))
variable {f}
/-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series converges
uniformly to `f`. -/
theorem hasSum_fourier_series_of_summable (h : Summable (fourierCoeff f)) :
HasSum (fun i => fourierCoeff f i • fourier i) f := by
have sum_L2 := hasSum_fourier_series_L2 (toLp (E := ℂ) 2 haarAddCircle ℂ f)
simp_rw [fourierCoeff_toLp] at sum_L2
refine ContinuousMap.hasSum_of_hasSum_Lp (.of_norm ?_) sum_L2
simp_rw [norm_smul, fourier_norm, mul_one]
exact h.norm
/-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series of `f`
converges everywhere pointwise to `f`. -/
theorem has_pointwise_sum_fourier_series_of_summable (h : Summable (fourierCoeff f))
(x : AddCircle T) : HasSum (fun i => fourierCoeff f i • fourier i x) (f x) := by
convert (ContinuousMap.evalCLM ℂ x).hasSum (hasSum_fourier_series_of_summable h)
end Convergence
end ScopeHT
section deriv
open Complex intervalIntegral
open scoped Interval
variable (T)
theorem hasDerivAt_fourier (n : ℤ) (x : ℝ) :
HasDerivAt (fun y : ℝ => fourier n (y : AddCircle T))
(2 * π * I * n / T * fourier n (x : AddCircle T)) x := by
simp_rw [fourier_coe_apply]
refine (?_ : HasDerivAt (fun y => exp (2 * π * I * n * y / T)) _ _).comp_ofReal
rw [(fun α β => by ring : ∀ α β : ℂ, α * exp β = exp β * α)]
refine (hasDerivAt_exp _).comp (x : ℂ) ?_
convert hasDerivAt_mul_const (2 * ↑π * I * ↑n / T) using 1
ext1 y; ring
theorem hasDerivAt_fourier_neg (n : ℤ) (x : ℝ) :
HasDerivAt (fun y : ℝ => fourier (-n) (y : AddCircle T))
(-2 * π * I * n / T * fourier (-n) (x : AddCircle T)) x := by
simpa using hasDerivAt_fourier T (-n) x
variable {T}
theorem has_antideriv_at_fourier_neg (hT : Fact (0 < T)) {n : ℤ} (hn : n ≠ 0) (x : ℝ) :
HasDerivAt (fun y : ℝ => (T : ℂ) / (-2 * π * I * n) * fourier (-n) (y : AddCircle T))
(fourier (-n) (x : AddCircle T)) x := by
convert (hasDerivAt_fourier_neg T n x).div_const (-2 * π * I * n / T) using 1
· ext1 y; rw [div_div_eq_mul_div]; ring
· simp [mul_div_cancel_left₀, hn, (Fact.out : 0 < T).ne', Real.pi_pos.ne']
/-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/
theorem fourierCoeffOn_of_hasDeriv_right {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ}
{n : ℤ} (hn : n ≠ 0)
(hf : ContinuousOn f [[a, b]])
(hff' : ∀ x, x ∈ Ioo (min a b) (max a b) → HasDerivWithinAt f (f' x) (Ioi x) x)
(hf' : IntervalIntegrable f' volume a b) :
fourierCoeffOn hab f n = 1 / (-2 * π * I * n) *
(fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) := by
rw [← ofReal_sub]
have hT : Fact (0 < b - a) := ⟨by linarith⟩
simp_rw [fourierCoeffOn_eq_integral, smul_eq_mul, real_smul, ofReal_div, ofReal_one]
conv => pattern (occs := 1 2 3) fourier _ _ * _ <;> (rw [mul_comm])
rw [integral_mul_deriv_eq_deriv_mul_of_hasDeriv_right hf
(fun x _ ↦ has_antideriv_at_fourier_neg hT hn x |>.continuousAt |>.continuousWithinAt) hff'
(fun x _ ↦ has_antideriv_at_fourier_neg hT hn x |>.hasDerivWithinAt) hf'
(((map_continuous (fourier (-n))).comp (AddCircle.continuous_mk' _)).intervalIntegrable _ _)]
have : ∀ u v w : ℂ, u * ((b - a : ℝ) / v * w) = (b - a : ℝ) / v * (u * w) := by intros; ring
conv in intervalIntegral _ _ _ _ => congr; ext; rw [this]
rw [(by ring : ((b - a : ℝ) : ℂ) / (-2 * π * I * n) = ((b - a : ℝ) : ℂ) * (1 / (-2 * π * I * n)))]
have s2 : (b : AddCircle (b - a)) = (a : AddCircle (b - a)) := by
simpa using coe_add_period (b - a) a
rw [s2, intervalIntegral.integral_const_mul, ← sub_mul, mul_sub, mul_sub]
congr 1
· conv_lhs => rw [mul_comm, mul_div, mul_one]
rw [div_eq_iff (ofReal_ne_zero.mpr hT.out.ne')]
ring
· ring
/-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/
theorem fourierCoeffOn_of_hasDerivAt_Ioo {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ}
{n : ℤ} (hn : n ≠ 0)
(hf : ContinuousOn f [[a, b]])
(hff' : ∀ x, x ∈ Ioo (min a b) (max a b) → HasDerivAt f (f' x) x)
(hf' : IntervalIntegrable f' volume a b) :
fourierCoeffOn hab f n = 1 / (-2 * π * I * n) *
(fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) :=
fourierCoeffOn_of_hasDeriv_right hab hn hf (fun x hx ↦ hff' x hx |>.hasDerivWithinAt) hf'
/-- Express Fourier coefficients of `f` on an interval in terms of those of its derivative. -/
theorem fourierCoeffOn_of_hasDerivAt {a b : ℝ} (hab : a < b) {f f' : ℝ → ℂ} {n : ℤ} (hn : n ≠ 0)
(hf : ∀ x, x ∈ [[a, b]] → HasDerivAt f (f' x) x) (hf' : IntervalIntegrable f' volume a b) :
fourierCoeffOn hab f n = 1 / (-2 * π * I * n) *
(fourier (-n) (a : AddCircle (b - a)) * (f b - f a) - (b - a) * fourierCoeffOn hab f' n) :=
fourierCoeffOn_of_hasDerivAt_Ioo hab hn
(fun x hx ↦ hf x hx |>.continuousAt.continuousWithinAt)
(fun x hx ↦ hf x <| mem_Icc_of_Ioo hx)
hf'
end deriv
| Mathlib/Analysis/Fourier/AddCircle.lean | 515 | 540 | |
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Trifunctor
import Mathlib.CategoryTheory.Products.Basic
/-!
# Monoidal categories
A monoidal category is a category equipped with a tensor product, unitors, and an associator.
In the definition, we provide the tensor product as a pair of functions
* `tensorObj : C → C → C`
* `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))`
and allow use of the overloaded notation `⊗` for both.
The unitors and associator are provided componentwise.
The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`.
The unitors and associator are gathered together as natural
isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`.
Some consequences of the definition are proved in other files after proving the coherence theorem,
e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`.
## Implementation notes
In the definition of monoidal categories, we also provide the whiskering operators:
* `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`,
* `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`.
These are products of an object and a morphism (the terminology "whiskering"
is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined
in terms of the whiskerings. There are two possible such definitions, which are related by
the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def`
and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds
definitionally.
If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it,
you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`.
The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories.
### Simp-normal form for morphisms
Rewriting involving associators and unitors could be very complicated. We try to ease this
complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal
form defined below. Rewriting into simp-normal form is especially useful in preprocessing
performed by the `coherence` tactic.
The simp-normal form of morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is
either a structural morphisms (morphisms made up only of identities, associators, unitors)
or non-structural morphisms, and
2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`,
where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural
morphisms that is not the identity or a composite.
Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`.
Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`,
respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon.
## References
* Tensor categories, Etingof, Gelaki, Nikshych, Ostrik,
http://www-math.mit.edu/~etingof/egnobookfinal.pdf
* <https://stacks.math.columbia.edu/tag/0FFK>.
-/
universe v u
open CategoryTheory.Category
open CategoryTheory.Iso
namespace CategoryTheory
/-- Auxiliary structure to carry only the data fields of (and provide notation for)
`MonoidalCategory`. -/
class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where
/-- curried tensor product of objects -/
tensorObj : C → C → C
/-- left whiskering for morphisms -/
whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂
/-- right whiskering for morphisms -/
whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
-- By default, it is defined in terms of whiskerings.
tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) :=
whiskerRight f X₂ ≫ whiskerLeft Y₁ g
/-- The tensor unity in the monoidal structure `𝟙_ C` -/
tensorUnit (C) : C
/-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z)
/-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/
leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X
/-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/
rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X
namespace MonoidalCategory
export MonoidalCategoryStruct
(tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor)
end MonoidalCategory
namespace MonoidalCategory
/-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj
/-- Notation for the `whiskerLeft` operator of monoidal categories -/
scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft
/-- Notation for the `whiskerRight` operator of monoidal categories -/
scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight
/-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom
/-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/
scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C
/-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
scoped notation "α_" => MonoidalCategoryStruct.associator
/-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/
scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor
/-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/
scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor
/-- The property that the pentagon relation is satisfied by four objects
in a category equipped with a `MonoidalCategoryStruct`. -/
def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C]
(Y₁ Y₂ Y₃ Y₄ : C) : Prop :=
(α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom =
(α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom
end MonoidalCategory
open MonoidalCategory
/--
In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`.
Tensor product does not need to be strictly associative on objects, but there is a
specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`,
with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`.
These associators and unitors satisfy the pentagon and triangle equations. -/
@[stacks 0FFK]
-- Porting note: The Mathport did not translate the temporary notation
class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where
tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by
aesop_cat
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat
/--
Tensor product of compositions is composition of tensor products:
`(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)`
-/
tensor_comp :
∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂),
(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by
aesop_cat
whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by
aesop_cat
id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by
aesop_cat
/-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/
associator_naturality :
∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃),
((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by
aesop_cat
/--
Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y`
-/
leftUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by
aesop_cat
/--
Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y`
-/
rightUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by
aesop_cat
/--
The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W`
-/
pentagon :
∀ W X Y Z : C,
(α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom =
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by
aesop_cat
/--
The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y`
-/
triangle :
∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by
aesop_cat
attribute [reassoc] MonoidalCategory.tensorHom_def
attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id
attribute [reassoc, simp] MonoidalCategory.id_whiskerRight
attribute [reassoc] MonoidalCategory.tensor_comp
attribute [simp] MonoidalCategory.tensor_comp
attribute [reassoc] MonoidalCategory.associator_naturality
attribute [reassoc] MonoidalCategory.leftUnitor_naturality
attribute [reassoc] MonoidalCategory.rightUnitor_naturality
attribute [reassoc (attr := simp)] MonoidalCategory.pentagon
attribute [reassoc (attr := simp)] MonoidalCategory.triangle
namespace MonoidalCategory
variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C]
@[simp]
theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) :
𝟙 X ⊗ f = X ◁ f := by
simp [tensorHom_def]
@[simp]
theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
f ⊗ 𝟙 Y = f ▷ Y := by
simp [tensorHom_def]
@[reassoc, simp]
theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by
simp only [← id_tensorHom, ← tensor_comp, comp_id]
@[reassoc, simp]
theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) :
𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by
rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom]
@[reassoc, simp]
theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
(X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc, simp]
theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) :
(f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by
simp only [← tensorHom_id, ← tensor_comp, id_comp]
@[reassoc, simp]
theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) :
f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by
rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id]
@[reassoc, simp]
theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [associator_naturality]
simp [tensor_id]
@[reassoc, simp]
theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
(X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc]
theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) :
W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by
simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id]
@[reassoc]
theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ :=
whisker_exchange f g ▸ tensorHom_def f g
|
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) :
| Mathlib/CategoryTheory/Monoidal/Category.lean | 278 | 280 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Morenikeji Neri
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.EuclideanDomain.Field
import Mathlib.Algebra.GCDMonoid.Basic
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.Ideal.Nonunits
import Mathlib.RingTheory.Noetherian.UniqueFactorizationDomain
/-!
# Principal ideal rings, principal ideal domains, and Bézout rings
A principal ideal ring (PIR) is a ring in which all left ideals are principal. A
principal ideal domain (PID) is an integral domain which is a principal ideal ring.
The definition of `IsPrincipalIdealRing` can be found in `Mathlib.RingTheory.Ideal.Span`.
# Main definitions
Note that for principal ideal domains, one should use
`[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID.
Theorems about PID's are in the `PrincipalIdealRing` namespace.
- `IsBezout`: the predicate saying that every finitely generated left ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_uniqueFactorizationMonoid`: a PID is a unique factorization domain
# Main results
- `Ideal.IsPrime.to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
- `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID.
- `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain.
-/
universe u v
variable {R : Type u} {M : Type v}
open Set Function
open Submodule
section
variable [Semiring R] [AddCommGroup M] [Module R M]
instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal :=
⟨⟨0, by simp⟩⟩
instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal :=
⟨⟨1, Ideal.span_singleton_one.symm⟩⟩
variable (R)
/-- A Bézout ring is a ring whose finitely generated ideals are principal. -/
class IsBezout : Prop where
/-- Any finitely generated ideal is principal. -/
isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal
instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R :=
⟨fun I _ => IsPrincipalIdealRing.principal I⟩
instance (priority := 100) DivisionRing.isPrincipalIdealRing (K : Type u) [DivisionRing K] :
IsPrincipalIdealRing K where
principal S := by
rcases Ideal.eq_bot_or_top S with (rfl | rfl)
· apply bot_isPrincipal
· apply top_isPrincipal
end
namespace Submodule.IsPrincipal
variable [AddCommMonoid M]
section Semiring
variable [Semiring R] [Module R M]
/-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/
noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M :=
Classical.choose (principal S)
theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S :=
Eq.symm (Classical.choose_spec (principal S))
@[simp]
theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] :
Ideal.span ({generator I} : Set R) = I :=
Eq.symm (Classical.choose_spec (principal I))
@[simp]
theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by
have : generator S ∈ span R {generator S} := subset_span (mem_singleton _)
convert this
exact span_singleton_generator S |>.symm
theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} :
x ∈ S ↔ ∃ s : R, x = s • generator S := by
simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator]
theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] :
S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator]
|
protected lemma fg {S : Submodule R M} (h : S.IsPrincipal) : S.FG :=
⟨{h.generator}, by simp only [Finset.coe_singleton, span_singleton_generator]⟩
| Mathlib/RingTheory/PrincipalIdealDomain.lean | 109 | 111 |
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Algebra.Order.Group.Unbundled.Int
import Mathlib.Algebra.Order.Nonneg.Basic
import Mathlib.Algebra.Order.Ring.Unbundled.Rat
import Mathlib.Algebra.Ring.Rat
import Mathlib.Data.Set.Operations
import Mathlib.Order.Bounds.Defs
import Mathlib.Order.GaloisConnection.Defs
/-!
# Nonnegative rationals
This file defines the nonnegative rationals as a subtype of `Rat` and provides its basic algebraic
order structure.
Note that `NNRat` is not declared as a `Semifield` here. See `Mathlib.Algebra.Field.Rat` for that
instance.
We also define an instance `CanLift ℚ ℚ≥0`. This instance can be used by the `lift` tactic to
replace `x : ℚ` and `hx : 0 ≤ x` in the proof context with `x : ℚ≥0` while replacing all occurrences
of `x` with `↑x`. This tactic also works for a function `f : α → ℚ` with a hypothesis
`hf : ∀ x, 0 ≤ f x`.
## Notation
`ℚ≥0` is notation for `NNRat` in locale `NNRat`.
## Huge warning
Whenever you state a lemma about the coercion `ℚ≥0 → ℚ`, check that Lean inserts `NNRat.cast`, not
`Subtype.val`. Else your lemma will never apply.
-/
assert_not_exists CompleteLattice OrderedCommMonoid
library_note "specialised high priority simp lemma" /--
It sometimes happens that a `@[simp]` lemma declared early in the library can be proved by `simp`
using later, more general simp lemmas. In that case, the following reasons might be arguments for
the early lemma to be tagged `@[simp high]` (rather than `@[simp, nolint simpNF]` or
un``@[simp]``ed):
1. There is a significant portion of the library which needs the early lemma to be available via
`simp` and which doesn't have access to the more general lemmas.
2. The more general lemmas have more complicated typeclass assumptions, causing rewrites with them
to be slower.
-/
open Function
instance Rat.instZeroLEOneClass : ZeroLEOneClass ℚ where
zero_le_one := rfl
instance Rat.instPosMulMono : PosMulMono ℚ where
elim := fun r p q h => by
simp only [mul_comm]
simpa [sub_mul, sub_nonneg] using Rat.mul_nonneg (sub_nonneg.2 h) r.2
deriving instance CommSemiring for NNRat
deriving instance LinearOrder for NNRat
deriving instance Sub for NNRat
deriving instance Inhabited for NNRat
namespace NNRat
variable {p q : ℚ≥0}
instance instNontrivial : Nontrivial ℚ≥0 where exists_pair_ne := ⟨1, 0, by decide⟩
instance instOrderBot : OrderBot ℚ≥0 where
bot := 0
bot_le q := q.2
@[simp] lemma val_eq_cast (q : ℚ≥0) : q.1 = q := rfl
instance instCharZero : CharZero ℚ≥0 where
cast_injective a b hab := by simpa using congr_arg num hab
instance canLift : CanLift ℚ ℚ≥0 (↑) fun q ↦ 0 ≤ q where
prf q hq := ⟨⟨q, hq⟩, rfl⟩
@[ext]
theorem ext : (p : ℚ) = (q : ℚ) → p = q :=
Subtype.ext
protected theorem coe_injective : Injective ((↑) : ℚ≥0 → ℚ) :=
Subtype.coe_injective
-- See note [specialised high priority simp lemma]
@[simp high, norm_cast]
theorem coe_inj : (p : ℚ) = q ↔ p = q :=
Subtype.coe_inj
theorem ne_iff {x y : ℚ≥0} : (x : ℚ) ≠ (y : ℚ) ↔ x ≠ y :=
NNRat.coe_inj.not
-- TODO: We have to write `NNRat.cast` explicitly, else the statement picks up `Subtype.val` instead
@[simp, norm_cast] lemma coe_mk (q : ℚ) (hq) : NNRat.cast ⟨q, hq⟩ = q := rfl
lemma «forall» {p : ℚ≥0 → Prop} : (∀ q, p q) ↔ ∀ q hq, p ⟨q, hq⟩ := Subtype.forall
lemma «exists» {p : ℚ≥0 → Prop} : (∃ q, p q) ↔ ∃ q hq, p ⟨q, hq⟩ := Subtype.exists
/-- Reinterpret a rational number `q` as a non-negative rational number. Returns `0` if `q ≤ 0`. -/
def _root_.Rat.toNNRat (q : ℚ) : ℚ≥0 :=
⟨max q 0, le_max_right _ _⟩
theorem _root_.Rat.coe_toNNRat (q : ℚ) (hq : 0 ≤ q) : (q.toNNRat : ℚ) = q :=
max_eq_left hq
theorem _root_.Rat.le_coe_toNNRat (q : ℚ) : q ≤ q.toNNRat :=
le_max_left _ _
open Rat (toNNRat)
@[simp]
theorem coe_nonneg (q : ℚ≥0) : (0 : ℚ) ≤ q :=
q.2
@[simp, norm_cast] lemma coe_zero : ((0 : ℚ≥0) : ℚ) = 0 := rfl
@[simp] lemma num_zero : num 0 = 0 := rfl
@[simp] lemma den_zero : den 0 = 1 := rfl
@[simp, norm_cast] lemma coe_one : ((1 : ℚ≥0) : ℚ) = 1 := rfl
@[simp] lemma num_one : num 1 = 1 := rfl
@[simp] lemma den_one : den 1 = 1 := rfl
@[simp, norm_cast]
theorem coe_add (p q : ℚ≥0) : ((p + q : ℚ≥0) : ℚ) = p + q :=
rfl
@[simp, norm_cast]
theorem coe_mul (p q : ℚ≥0) : ((p * q : ℚ≥0) : ℚ) = p * q :=
rfl
@[simp, norm_cast] lemma coe_pow (q : ℚ≥0) (n : ℕ) : (↑(q ^ n) : ℚ) = (q : ℚ) ^ n :=
rfl
@[simp] lemma num_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).num = q.num ^ n := by simp [num, Int.natAbs_pow]
@[simp] lemma den_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl
@[simp, norm_cast]
theorem coe_sub (h : q ≤ p) : ((p - q : ℚ≥0) : ℚ) = p - q :=
max_eq_left <| le_sub_comm.2 <| by rwa [sub_zero]
-- See note [specialised high priority simp lemma]
@[simp high]
theorem coe_eq_zero : (q : ℚ) = 0 ↔ q = 0 := by norm_cast
theorem coe_ne_zero : (q : ℚ) ≠ 0 ↔ q ≠ 0 :=
coe_eq_zero.not
@[norm_cast]
theorem coe_le_coe : (p : ℚ) ≤ q ↔ p ≤ q :=
Iff.rfl
@[norm_cast]
theorem coe_lt_coe : (p : ℚ) < q ↔ p < q :=
Iff.rfl
@[norm_cast]
theorem coe_pos : (0 : ℚ) < q ↔ 0 < q :=
Iff.rfl
theorem coe_mono : Monotone ((↑) : ℚ≥0 → ℚ) :=
fun _ _ ↦ coe_le_coe.2
theorem toNNRat_mono : Monotone toNNRat :=
fun _ _ h ↦ max_le_max h le_rfl
@[simp]
theorem toNNRat_coe (q : ℚ≥0) : toNNRat q = q :=
ext <| max_eq_left q.2
@[simp]
theorem toNNRat_coe_nat (n : ℕ) : toNNRat n = n :=
ext <| by simp only [Nat.cast_nonneg', Rat.coe_toNNRat]; rfl
/-- `toNNRat` and `(↑) : ℚ≥0 → ℚ` form a Galois insertion. -/
protected def gi : GaloisInsertion toNNRat (↑) :=
GaloisInsertion.monotoneIntro coe_mono toNNRat_mono Rat.le_coe_toNNRat toNNRat_coe
/-- Coercion `ℚ≥0 → ℚ` as a `RingHom`. -/
def coeHom : ℚ≥0 →+* ℚ where
toFun := (↑)
map_one' := coe_one
map_mul' := coe_mul
map_zero' := coe_zero
map_add' := coe_add
@[simp, norm_cast] lemma coe_natCast (n : ℕ) : (↑(↑n : ℚ≥0) : ℚ) = n := rfl
@[simp]
theorem mk_natCast (n : ℕ) : @Eq ℚ≥0 (⟨(n : ℚ), Nat.cast_nonneg' n⟩ : ℚ≥0) n :=
rfl
@[simp]
theorem coe_coeHom : ⇑coeHom = ((↑) : ℚ≥0 → ℚ) :=
rfl
@[norm_cast]
theorem nsmul_coe (q : ℚ≥0) (n : ℕ) : ↑(n • q) = n • (q : ℚ) :=
coeHom.toAddMonoidHom.map_nsmul _ _
theorem bddAbove_coe {s : Set ℚ≥0} : BddAbove ((↑) '' s : Set ℚ) ↔ BddAbove s :=
⟨fun ⟨b, hb⟩ ↦
⟨toNNRat b, fun ⟨y, _⟩ hys ↦
show y ≤ max b 0 from (hb <| Set.mem_image_of_mem _ hys).trans <| le_max_left _ _⟩,
fun ⟨b, hb⟩ ↦ ⟨b, fun _ ⟨_, hx, Eq⟩ ↦ Eq ▸ hb hx⟩⟩
theorem bddBelow_coe (s : Set ℚ≥0) : BddBelow (((↑) : ℚ≥0 → ℚ) '' s) :=
⟨0, fun _ ⟨q, _, h⟩ ↦ h ▸ q.2⟩
@[norm_cast]
theorem coe_max (x y : ℚ≥0) : ((max x y : ℚ≥0) : ℚ) = max (x : ℚ) (y : ℚ) :=
coe_mono.map_max
@[norm_cast]
theorem coe_min (x y : ℚ≥0) : ((min x y : ℚ≥0) : ℚ) = min (x : ℚ) (y : ℚ) :=
coe_mono.map_min
theorem sub_def (p q : ℚ≥0) : p - q = toNNRat (p - q) :=
rfl
@[simp]
theorem abs_coe (q : ℚ≥0) : |(q : ℚ)| = q :=
abs_of_nonneg q.2
-- See note [specialised high priority simp lemma]
@[simp high]
theorem nonpos_iff_eq_zero (q : ℚ≥0) : q ≤ 0 ↔ q = 0 :=
⟨fun h => le_antisymm h q.2, fun h => h.symm ▸ q.2⟩
end NNRat
open NNRat
namespace Rat
variable {p q : ℚ}
@[simp]
theorem toNNRat_zero : toNNRat 0 = 0 := rfl
@[simp]
theorem toNNRat_one : toNNRat 1 = 1 := rfl
@[simp]
theorem toNNRat_pos : 0 < toNNRat q ↔ 0 < q := by simp [toNNRat, ← coe_lt_coe]
@[simp]
theorem toNNRat_eq_zero : toNNRat q = 0 ↔ q ≤ 0 := by
simpa [-toNNRat_pos] using (@toNNRat_pos q).not
alias ⟨_, toNNRat_of_nonpos⟩ := toNNRat_eq_zero
@[simp]
theorem toNNRat_le_toNNRat_iff (hp : 0 ≤ p) : toNNRat q ≤ toNNRat p ↔ q ≤ p := by
simp [← coe_le_coe, toNNRat, hp]
@[simp]
theorem toNNRat_lt_toNNRat_iff' : toNNRat q < toNNRat p ↔ q < p ∧ 0 < p := by
simp [← coe_lt_coe, toNNRat, lt_irrefl]
theorem toNNRat_lt_toNNRat_iff (h : 0 < p) : toNNRat q < toNNRat p ↔ q < p :=
toNNRat_lt_toNNRat_iff'.trans (and_iff_left h)
theorem toNNRat_lt_toNNRat_iff_of_nonneg (hq : 0 ≤ q) : toNNRat q < toNNRat p ↔ q < p :=
toNNRat_lt_toNNRat_iff'.trans ⟨And.left, fun h ↦ ⟨h, hq.trans_lt h⟩⟩
@[simp]
theorem toNNRat_add (hq : 0 ≤ q) (hp : 0 ≤ p) : toNNRat (q + p) = toNNRat q + toNNRat p :=
NNRat.ext <| by simp [toNNRat, hq, hp, add_nonneg]
theorem toNNRat_add_le : toNNRat (q + p) ≤ toNNRat q + toNNRat p :=
coe_le_coe.1 <| max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) <| coe_nonneg _
theorem toNNRat_le_iff_le_coe {p : ℚ≥0} : toNNRat q ≤ p ↔ q ≤ ↑p :=
NNRat.gi.gc q p
theorem le_toNNRat_iff_coe_le {q : ℚ≥0} (hp : 0 ≤ p) : q ≤ toNNRat p ↔ ↑q ≤ p := by
rw [← coe_le_coe, Rat.coe_toNNRat p hp]
theorem le_toNNRat_iff_coe_le' {q : ℚ≥0} (hq : 0 < q) : q ≤ toNNRat p ↔ ↑q ≤ p :=
| (le_or_lt 0 p).elim le_toNNRat_iff_coe_le fun hp ↦ by
simp only [(hp.trans_le q.coe_nonneg).not_le, toNNRat_eq_zero.2 hp.le, hq.not_le]
| Mathlib/Data/NNRat/Defs.lean | 285 | 286 |
/-
Copyright (c) 2024 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.Exact
import Mathlib.CategoryTheory.Shift.ShiftSequence
import Mathlib.CategoryTheory.Triangulated.Functor
import Mathlib.CategoryTheory.Triangulated.Subcategory
import Mathlib.Algebra.Homology.ExactSequence
/-! # Homological functors
In this file, given a functor `F : C ⥤ A` from a pretriangulated category to
an abelian category, we define the type class `F.IsHomological`, which is the property
that `F` sends distinguished triangles in `C` to exact sequences in `A`.
If `F` has been endowed with `[F.ShiftSequence ℤ]`, then we may think
of the functor `F` as a `H^0`, and then the `H^n` functors are the functors `F.shift n : C ⥤ A`:
we have isomorphisms `(F.shift n).obj X ≅ F.obj (X⟦n⟧)`, but through the choice of this
"shift sequence", the user may provide functors with better definitional properties.
Given a triangle `T` in `C`, we define a connecting homomorphism
`F.homologySequenceδ T n₀ n₁ h : (F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁`
under the assumption `h : n₀ + 1 = n₁`. When `T` is distinguished, this connecting
homomorphism is part of a long exact sequence
`... ⟶ (F.shift n₀).obj T.obj₁ ⟶ (F.shift n₀).obj T.obj₂ ⟶ (F.shift n₀).obj T.obj₃ ⟶ ...`
The exactness of this long exact sequence is given by three lemmas
`F.homologySequence_exact₁`, `F.homologySequence_exact₂` and `F.homologySequence_exact₃`.
If `F` is a homological functor, we define the strictly full triangulated subcategory
`F.homologicalKernel`: it consists of objects `X : C` such that for all `n : ℤ`,
`(F.shift n).obj X` (or `F.obj (X⟦n⟧)`) is zero. We show that a morphism `f` in `C`
belongs to `F.homologicalKernel.W` (i.e. the cone of `f` is in this kernel) iff
`(F.shift n).map f` is an isomorphism for all `n : ℤ`.
Note: depending on the sources, homological functors are sometimes
called cohomological functors, while certain authors use "cohomological functors"
for "contravariant" functors (i.e. functors `Cᵒᵖ ⥤ A`).
## TODO
* The long exact sequence in homology attached to an homological functor.
## References
* [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996]
-/
namespace CategoryTheory
open Category Limits Pretriangulated ZeroObject Preadditive
variable {C D A : Type*} [Category C] [HasShift C ℤ]
[Category D] [HasZeroObject D] [HasShift D ℤ] [Preadditive D]
[∀ (n : ℤ), (CategoryTheory.shiftFunctor D n).Additive] [Pretriangulated D]
[Category A]
namespace Functor
variable (F : C ⥤ A)
section Pretriangulated
variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
[Pretriangulated C] [Abelian A]
/-- A functor from a pretriangulated category to an abelian category is an homological functor
if it sends distinguished triangles to exact sequences. -/
class IsHomological : Prop extends F.PreservesZeroMorphisms where
exact (T : Triangle C) (hT : T ∈ distTriang C) :
((shortComplexOfDistTriangle T hT).map F).Exact
lemma map_distinguished_exact [F.IsHomological] (T : Triangle C) (hT : T ∈ distTriang C) :
((shortComplexOfDistTriangle T hT).map F).Exact :=
IsHomological.exact _ hT
instance (L : C ⥤ D) (F : D ⥤ A) [L.CommShift ℤ] [L.IsTriangulated] [F.IsHomological] :
(L ⋙ F).IsHomological where
exact T hT := F.map_distinguished_exact _ (L.map_distinguished T hT)
lemma IsHomological.mk' [F.PreservesZeroMorphisms]
(hF : ∀ (T : Pretriangulated.Triangle C) (hT : T ∈ distTriang C),
∃ (T' : Pretriangulated.Triangle C) (e : T ≅ T'),
((shortComplexOfDistTriangle T' (isomorphic_distinguished _ hT _ e.symm)).map F).Exact) :
F.IsHomological where
exact T hT := by
obtain ⟨T', e, h'⟩ := hF T hT
exact (ShortComplex.exact_iff_of_iso
(F.mapShortComplex.mapIso ((shortComplexOfDistTriangleIsoOfIso e hT)))).2 h'
lemma IsHomological.of_iso {F₁ F₂ : C ⥤ A} [F₁.IsHomological] (e : F₁ ≅ F₂) :
F₂.IsHomological :=
have := preservesZeroMorphisms_of_iso e
⟨fun T hT => ShortComplex.exact_of_iso (ShortComplex.mapNatIso _ e)
(F₁.map_distinguished_exact T hT)⟩
/-- The kernel of a homological functor `F : C ⥤ A` is the strictly full
triangulated subcategory consisting of objects `X` such that
for all `n : ℤ`, `F.obj (X⟦n⟧)` is zero. -/
def homologicalKernel [F.IsHomological] :
Triangulated.Subcategory C := Triangulated.Subcategory.mk'
(fun X => ∀ (n : ℤ), IsZero (F.obj (X⟦n⟧)))
(fun n => by
rw [IsZero.iff_id_eq_zero, ← F.map_id, ← Functor.map_id,
id_zero, Functor.map_zero, Functor.map_zero])
(fun X a hX b => IsZero.of_iso (hX (a + b)) (F.mapIso ((shiftFunctorAdd C a b).app X).symm))
(fun T hT h₁ h₃ n => (F.map_distinguished_exact _
(Triangle.shift_distinguished T hT n)).isZero_of_both_zeros
(IsZero.eq_of_src (h₁ n) _ _) (IsZero.eq_of_tgt (h₃ n) _ _))
instance [F.IsHomological] : F.homologicalKernel.P.IsClosedUnderIsomorphisms := by
dsimp only [homologicalKernel]
infer_instance
lemma mem_homologicalKernel_iff [F.IsHomological] [F.ShiftSequence ℤ] (X : C) :
F.homologicalKernel.P X ↔ ∀ (n : ℤ), IsZero ((F.shift n).obj X) := by
simp only [← fun (n : ℤ) => Iso.isZero_iff ((F.isoShift n).app X)]
rfl
noncomputable instance (priority := 100) [F.IsHomological] :
PreservesLimitsOfShape (Discrete WalkingPair) F := by
suffices ∀ (X₁ X₂ : C), PreservesLimit (pair X₁ X₂) F from
⟨fun {X} => preservesLimit_of_iso_diagram F (diagramIsoPair X).symm⟩
intro X₁ X₂
have : HasBinaryBiproduct (F.obj X₁) (F.obj X₂) := HasBinaryBiproducts.has_binary_biproduct _ _
have : Mono (F.biprodComparison X₁ X₂) := by
rw [mono_iff_cancel_zero]
intro Z f hf
let S := (ShortComplex.mk _ _ (biprod.inl_snd (X := X₁) (Y := X₂))).map F
have : Mono S.f := by dsimp [S]; infer_instance
have ex : S.Exact := F.map_distinguished_exact _ (binaryBiproductTriangle_distinguished X₁ X₂)
obtain ⟨g, rfl⟩ := ex.lift' f (by simpa using hf =≫ biprod.snd)
dsimp [S] at hf ⊢
replace hf := hf =≫ biprod.fst
simp only [assoc, biprodComparison_fst, zero_comp, ← F.map_comp, biprod.inl_fst,
F.map_id, comp_id] at hf
rw [hf, zero_comp]
have : PreservesBinaryBiproduct X₁ X₂ F := preservesBinaryBiproduct_of_mono_biprodComparison _
apply Limits.preservesBinaryProduct_of_preservesBinaryBiproduct
instance (priority := 100) [F.IsHomological] : F.Additive :=
F.additive_of_preserves_binary_products
lemma isHomological_of_localization (L : C ⥤ D)
[L.CommShift ℤ] [L.IsTriangulated] [L.mapArrow.EssSurj] (F : D ⥤ A)
(G : C ⥤ A) (e : L ⋙ F ≅ G) [G.IsHomological] :
F.IsHomological := by
have : F.PreservesZeroMorphisms := preservesZeroMorphisms_of_map_zero_object
(F.mapIso L.mapZeroObject.symm ≪≫ e.app _ ≪≫ G.mapZeroObject)
have : (L ⋙ F).IsHomological := IsHomological.of_iso e.symm
refine IsHomological.mk' _ (fun T hT => ?_)
rw [L.distTriang_iff] at hT
obtain ⟨T₀, e, hT₀⟩ := hT
exact ⟨L.mapTriangle.obj T₀, e, (L ⋙ F).map_distinguished_exact _ hT₀⟩
end Pretriangulated
section
/-- The connecting homomorphism in the long exact sequence attached to an homological
functor and a distinguished triangle. -/
noncomputable def homologySequenceδ
[F.ShiftSequence ℤ] (T : Triangle C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
(F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁ :=
F.shiftMap T.mor₃ n₀ n₁ (by rw [add_comm 1, h])
variable {T T'}
@[reassoc]
lemma homologySequenceδ_naturality
[F.ShiftSequence ℤ] (T T' : Triangle C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
(F.shift n₀).map φ.hom₃ ≫ F.homologySequenceδ T' n₀ n₁ h =
F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map φ.hom₁ := by
dsimp only [homologySequenceδ]
rw [← shiftMap_comp', ← φ.comm₃, shiftMap_comp]
variable (T)
variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
[Pretriangulated C] [Abelian A] [F.IsHomological]
variable [F.ShiftSequence ℤ] (T T' : Triangle C) (hT : T ∈ distTriang C)
(hT' : T' ∈ distTriang C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁)
|
section
include hT
@[reassoc]
lemma comp_homologySequenceδ :
| Mathlib/CategoryTheory/Triangulated/HomologicalFunctor.lean | 184 | 188 |
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Group.Conj
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Group.Subgroup.Ker
/-!
# Basic results on subgroups
We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid
homomorphisms.
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `A` is an `AddGroup`
- `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K`
is a subgroup of `G × N`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists OrderedAddCommMonoid Multiset Ring
open Function
open scoped Int
variable {G G' G'' : Type*} [Group G] [Group G'] [Group G'']
variable {A : Type*} [AddGroup A]
section SubgroupClass
variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S}
variable [SetLike S G] [SubgroupClass S G]
@[to_additive]
theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
inv_div b a ▸ inv_mem_iff
end SubgroupClass
namespace Subgroup
variable (H K : Subgroup G)
@[to_additive]
protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H :=
div_mem_comm_iff
variable {k : Set G}
open Set
variable {N : Type*} [Group N] {P : Type*} [Group P]
/-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/
@[to_additive prod
"Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K`
as an `AddSubgroup` of `A × B`."]
def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) :=
{ Submonoid.prod H.toSubmonoid K.toSubmonoid with
inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ }
@[to_additive coe_prod]
theorem coe_prod (H : Subgroup G) (K : Subgroup N) :
(H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) :=
rfl
@[to_additive mem_prod]
theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K :=
Iff.rfl
open scoped Relator in
@[to_additive prod_mono]
theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) :=
fun _s _s' hs _t _t' ht => Set.prod_mono hs ht
@[to_additive prod_mono_right]
theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t :=
prod_mono (le_refl K)
@[to_additive prod_mono_left]
theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs =>
prod_mono hs (le_refl H)
@[to_additive prod_top]
theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
@[to_additive top_prod]
theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[to_additive (attr := simp) top_prod_top]
theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ :=
(top_prod _).trans <| comap_top _
@[to_additive (attr := simp) bot_prod_bot]
theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ :=
SetLike.coe_injective <| by simp [coe_prod]
@[deprecated (since := "2025-03-11")]
alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot
@[to_additive le_prod_iff]
theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} :
J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by
simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff
@[to_additive prod_le_iff]
theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} :
H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by
simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff
@[to_additive (attr := simp) prod_eq_bot_iff]
theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by
simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff
@[to_additive closure_prod]
theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) :
closure (s ×ˢ t) = (closure s).prod (closure t) :=
le_antisymm
(closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩)
(prod_le_iff.2 ⟨
map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩,
map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩)
/-- Product of subgroups is isomorphic to their product as groups. -/
@[to_additive prodEquiv
"Product of additive subgroups is isomorphic to their product
as additive groups"]
def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K :=
{ Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl }
section Pi
variable {η : Type*} {f : η → Type*}
-- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi
/-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules
`s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that
`f i` belongs to `Pi I s` whenever `i ∈ I`. -/
@[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family
of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions
`f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."]
def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) :
Submonoid (∀ i, f i) where
carrier := I.pi fun i => (s i).carrier
one_mem' i _ := (s i).one_mem
mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI)
variable [∀ i, Group (f i)]
/-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules
`s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that
`f i` belongs to `pi I s` whenever `i ∈ I`. -/
@[to_additive
"A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family
of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions
`f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."]
def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) :=
{ Submonoid.pi I fun i => (H i).toSubmonoid with
inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) }
@[to_additive]
theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) :
(pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) :=
rfl
@[to_additive]
theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} :
p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i :=
Iff.rfl
@[to_additive]
theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ :=
ext fun x => by simp [mem_pi]
@[to_additive]
theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ :=
(eq_bot_iff_forall _).mpr fun p hp => by
simp only [mem_pi, mem_bot] at *
ext j
exact hp j trivial
@[to_additive]
theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} :
J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by
constructor
· intro h i hi
rintro _ ⟨x, hx, rfl⟩
exact (h hx) _ hi
· intro h x hx i hi
exact h i hi ⟨_, hx, rfl⟩
@[to_additive (attr := simp)]
theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) :
Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by
constructor
· intro h hi
simpa using h i hi
· intro h j hj
by_cases heq : j = i
· subst heq
simpa using h hj
· simp [heq, one_mem]
@[to_additive]
theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by
classical
simp only [eq_bot_iff_forall]
constructor
· intro h i x hx
have : MonoidHom.mulSingle f i x = 1 :=
h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx)
simpa using congr_fun this i
· exact fun h x hx => funext fun i => h _ _ (hx i trivial)
end Pi
end Subgroup
namespace Subgroup
variable {H K : Subgroup G}
variable (H)
/-- A subgroup is characteristic if it is fixed by all automorphisms.
Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/
structure Characteristic : Prop where
/-- `H` is fixed by all automorphisms -/
fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H
attribute [class] Characteristic
instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal :=
⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩
end Subgroup
namespace AddSubgroup
variable (H : AddSubgroup A)
/-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms.
Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/
structure Characteristic : Prop where
/-- `H` is fixed by all automorphisms -/
fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H
attribute [to_additive] Subgroup.Characteristic
attribute [class] Characteristic
instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal :=
⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩
end AddSubgroup
namespace Subgroup
variable {H K : Subgroup G}
@[to_additive]
theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H :=
⟨Characteristic.fixed, Characteristic.mk⟩
@[to_additive]
theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H :=
characteristic_iff_comap_eq.trans
⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ =>
le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩
@[to_additive]
theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom :=
characteristic_iff_comap_eq.trans
⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ =>
le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩
@[to_additive]
theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by
simp_rw [map_equiv_eq_comap_symm']
exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩
@[to_additive]
instance botCharacteristic : Characteristic (⊥ : Subgroup G) :=
characteristic_iff_le_map.mpr fun _ϕ => bot_le
@[to_additive]
instance topCharacteristic : Characteristic (⊤ : Subgroup G) :=
characteristic_iff_map_le.mpr fun _ϕ => le_top
variable (H)
section Normalizer
variable {H}
@[to_additive]
theorem normalizer_eq_top_iff : H.normalizer = ⊤ ↔ H.Normal :=
eq_top_iff.trans
⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b =>
⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩
variable (H) in
@[to_additive]
theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊤ :=
normalizer_eq_top_iff.mpr h
variable {N : Type*} [Group N]
/-- The preimage of the normalizer is contained in the normalizer of the preimage. -/
@[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."]
theorem le_normalizer_comap (f : N →* G) :
H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by
simp only [mem_normalizer_iff, mem_comap]
intro h n
simp [h (f n)]
/-- The image of the normalizer is contained in the normalizer of the image. -/
@[to_additive "The image of the normalizer is contained in the normalizer of the image."]
theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by
simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff]
rintro x hx rfl n
constructor
· rintro ⟨y, hy, rfl⟩
use x * y * x⁻¹, (hx y).1 hy
simp
· rintro ⟨y, hyH, hy⟩
use x⁻¹ * y * x
rw [hx]
simp [hy, hyH, mul_assoc]
@[to_additive]
theorem comap_normalizer_eq_of_le_range {f : N →* G} (h : H ≤ f.range) :
comap f H.normalizer = (comap f H).normalizer := by
apply le_antisymm (le_normalizer_comap f)
rw [← map_le_iff_le_comap]
apply (le_normalizer_map f).trans
rw [map_comap_eq_self h]
@[to_additive]
theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≤ N) :
H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer :=
comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm)
@[to_additive]
theorem normal_subgroupOf_iff_le_normalizer (h : H ≤ K) :
(H.subgroupOf K).Normal ↔ K ≤ H.normalizer := by
rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff]
@[to_additive]
theorem normal_subgroupOf_iff_le_normalizer_inf :
(H.subgroupOf K).Normal ↔ K ≤ (H ⊓ K).normalizer :=
inf_subgroupOf_right H K ▸ normal_subgroupOf_iff_le_normalizer inf_le_right
@[to_additive]
instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal :=
(normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl
@[to_additive]
theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) :
K ≤ H.normalizer :=
(normal_subgroupOf_iff_le_normalizer HK).mp hK
@[to_additive]
theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S ⊆ H.normalizer :=
(@normalizer_eq_top _ _ H hH) ▸ le_top
@[to_additive]
theorem le_normalizer_of_normal [H.Normal] : K ≤ H.normalizer := subset_normalizer_of_normal
@[to_additive]
theorem inf_normalizer_le_normalizer_inf : H.normalizer ⊓ K.normalizer ≤ (H ⊓ K).normalizer :=
fun _ h g ↦ and_congr (h.1 g) (h.2 g)
variable (G) in
/-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/
def _root_.NormalizerCondition :=
∀ H : Subgroup G, H < ⊤ → H < normalizer H
/-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing.
This may be easier to work with, as it avoids inequalities and negations. -/
theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing :
NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by
apply forall_congr'; intro H
simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne]
tauto
variable (H)
end Normalizer
end Subgroup
namespace Group
variable {s : Set G}
/-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of
the elements of `s`. -/
def conjugatesOfSet (s : Set G) : Set G :=
⋃ a ∈ s, conjugatesOf a
theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by
rw [conjugatesOfSet, Set.mem_iUnion₂]
simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop]
theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) =>
mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩
theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t :=
Set.biUnion_subset_biUnion_left h
theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) :
conjugatesOf a ⊆ N := by
rintro a hc
obtain ⟨c, rfl⟩ := isConj_iff.1 hc
exact tn.conj_mem a h c
theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) :
conjugatesOfSet s ⊆ N :=
Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H)
/-- The set of conjugates of `s` is closed under conjugation. -/
theorem conj_mem_conjugatesOfSet {x c : G} :
x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by
rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩
exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩
end Group
namespace Subgroup
open Group
variable {s : Set G}
/-- The normal closure of a set `s` is the subgroup closure of all the conjugates of
elements of `s`. It is the smallest normal subgroup containing `s`. -/
def normalClosure (s : Set G) : Subgroup G :=
closure (conjugatesOfSet s)
theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s :=
subset_closure
theorem subset_normalClosure : s ⊆ normalClosure s :=
Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure
theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h =>
subset_normalClosure h
/-- The normal closure of `s` is a normal subgroup. -/
instance normalClosure_normal : (normalClosure s).Normal :=
⟨fun n h g => by
refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_)
(fun x _ ihx => ?_) h
· exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx)
· simpa using (normalClosure s).one_mem
· rw [← conj_mul]
exact mul_mem ihx ihy
· rw [← conj_inv]
exact inv_mem ihx⟩
/-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/
theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by
intro a w
refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w
· exact conjugatesOfSet_subset h hx
· exact one_mem _
· exact mul_mem ihx ihy
· exact inv_mem ihx
theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N :=
⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩
@[gcongr]
theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t :=
normalClosure_le_normal (Set.Subset.trans h subset_normalClosure)
theorem normalClosure_eq_iInf :
normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N :=
le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal)
(iInf_le_of_le (normalClosure s)
(iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl)))
@[simp]
theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H :=
le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure
theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s :=
normalClosure_eq_self _
theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by
simp only [subset_normalClosure, closure_le]
@[simp]
theorem normalClosure_closure_eq_normalClosure {s : Set G} :
normalClosure ↑(closure s) = normalClosure s :=
le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure)
/-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`,
as shown by `Subgroup.normalCore_eq_iSup`. -/
def normalCore (H : Subgroup G) : Subgroup G where
carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H }
one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem
inv_mem' {_} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b))
mul_mem' {_ _} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c))
theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by
rw [← mul_one a, ← inv_one, ← one_mul a]
exact h 1
instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal :=
⟨fun a h b c => by
rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩
theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] :
N ≤ H.normalCore ↔ N ≤ H :=
⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩
theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore :=
normal_le_normalCore.mpr (H.normalCore_le.trans h)
theorem normalCore_eq_iSup (H : Subgroup G) :
H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N :=
le_antisymm
(le_iSup_of_le H.normalCore
(le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl)))
(iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr)
@[simp]
theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H :=
le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl)
theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore :=
H.normalCore.normalCore_eq_self
end Subgroup
namespace MonoidHom
variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G)
open Subgroup
section Ker
variable {M : Type*} [MulOneClass M]
@[to_additive prodMap_comap_prod]
theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N)
(g : G' →* N') (S : Subgroup N) (S' : Subgroup N') :
(S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) :=
SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _
@[deprecated (since := "2025-03-11")]
alias _root_.AddMonoidHom.sumMap_comap_sum := AddMonoidHom.prodMap_comap_prod
@[to_additive ker_prodMap]
theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') :
(prodMap f g).ker = f.ker.prod g.ker := by
rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot]
@[deprecated (since := "2025-03-11")]
alias _root_.AddMonoidHom.ker_sumMap := AddMonoidHom.ker_prodMap
@[to_additive (attr := simp)]
lemma ker_fst : ker (fst G G') = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm
@[to_additive (attr := simp)]
lemma ker_snd : ker (snd G G') = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm
end Ker
end MonoidHom
namespace Subgroup
variable {N : Type*} [Group N] (H : Subgroup G)
@[to_additive]
theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G →* N) (hf : Function.Surjective f) :
(H.map f).Normal := by
rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map,
← H.normalizer_eq_top]
exact le_normalizer_map _
end Subgroup
namespace Subgroup
open MonoidHom
variable {N : Type*} [Group N] (f : G →* N)
/-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective
function. -/
@[to_additive
"The preimage of the normalizer is equal to the normalizer of the preimage of
a surjective function."]
theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N →* G}
(hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer :=
comap_normalizer_eq_of_le_range fun x _ ↦ hf x
@[deprecated (since := "2025-03-13")]
alias comap_normalizer_eq_of_injective_of_le_range := comap_normalizer_eq_of_le_range
@[deprecated (since := "2025-03-13")]
alias _root_.AddSubgroup.comap_normalizer_eq_of_injective_of_le_range :=
AddSubgroup.comap_normalizer_eq_of_le_range
/-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/
@[to_additive
"The image of the normalizer is equal to the normalizer of the image of an
isomorphism."]
theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) :
H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by
ext x
simp only [mem_normalizer_iff, mem_map_equiv]
rw [f.toEquiv.forall_congr]
intro
simp
/-- The image of the normalizer is equal to the normalizer of the image of a bijective
function. -/
@[to_additive
"The image of the normalizer is equal to the normalizer of the image of a bijective
function."]
theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G →* N} (hf : Function.Bijective f) :
H.normalizer.map f = (H.map f).normalizer :=
map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf)
end Subgroup
namespace MonoidHom
variable {G₁ G₂ G₃ : Type*} [Group G₁] [Group G₂] [Group G₃]
variable (f : G₁ →* G₂) (f_inv : G₂ → G₁)
/-- Auxiliary definition used to define `liftOfRightInverse` -/
@[to_additive "Auxiliary definition used to define `liftOfRightInverse`"]
def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) :
G₂ →* G₃ where
toFun b := g (f_inv b)
map_one' := hg (hf 1)
map_mul' := by
intro x y
rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker]
apply hg
rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul]
simp only [hf _]
@[to_additive (attr := simp)]
theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃)
(hg : f.ker ≤ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by
dsimp [liftOfRightInverseAux]
rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker]
apply hg
rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one]
simp only [hf _]
/-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `φ`
* such that `φ.comp f = g` (`MonoidHom.liftOfRightInverse_comp`),
* where `f : G₁ →+* G₂` has a RightInverse `f_inv` (`hf`),
* and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`.
See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
G₁.
| \
f | \ g
| \
v \⌟
G₂----> G₃
∃!φ
```
-/
@[to_additive
"`liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `φ`
* such that `φ.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`),
* where `f : G₁ →+ G₂` has a RightInverse `f_inv` (`hf`),
* and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`.
See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
G₁.
| \\
f | \\ g
| \\
v \\⌟
G₂----> G₃
∃!φ
```"]
def liftOfRightInverse (hf : Function.RightInverse f_inv f) :
{ g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) where
toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2
invFun φ := ⟨φ.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩
left_inv g := by
ext
simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk]
right_inv φ := by
ext b
simp [liftOfRightInverseAux, hf b]
/-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right
inverse is available, that uses `Function.surjInv`. -/
@[to_additive (attr := simp)
"A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no
computable right inverse is available."]
noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) :
{ g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) :=
f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf)
@[to_additive (attr := simp)]
theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f)
(g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) (x : G₁) :
(f.liftOfRightInverse f_inv hf g) (f x) = g.1 x :=
f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x
@[to_additive (attr := simp)]
theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f)
(g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g :=
MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g
@[to_additive]
theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃)
(hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) :
h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by
simp_rw [← hh]
exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm
end MonoidHom
variable {N : Type*} [Group N]
namespace Subgroup
-- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`.
@[to_additive]
theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G →* N) : (H.comap f).Normal :=
⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩
@[to_additive]
instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G →* N) :
(H.comap f).Normal :=
nH.comap _
-- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`.
@[to_additive]
theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) :
(H.subgroupOf K).Normal :=
hH.comap _
@[to_additive]
instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] :
(N.subgroupOf H).Normal :=
Subgroup.normal_comap _
theorem map_normalClosure (s : Set G) (f : G →* N) (hf : Surjective f) :
(normalClosure s).map f = normalClosure (f '' s) := by
have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf
apply le_antisymm
· simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap,
← Set.image_subset_iff, subset_normalClosure]
· exact normalClosure_le_normal (Set.image_subset f subset_normalClosure)
theorem comap_normalClosure (s : Set N) (f : G ≃* N) :
normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by
have := Set.preimage_equiv_eq_image_symm s f.toEquiv
simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N →* G) f.symm.surjective]
lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {φ : G →* H}
(hφ : Function.Injective φ) {L : Subgroup G} (n : (L.map φ).Normal) : L.Normal :=
L.comap_map_eq_self_of_injective hφ ▸ n.comap φ
theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K}
(n : (Subgroup.map K.subtype L).Normal) : L.Normal :=
n.of_map_injective K.subtype_injective
end Subgroup
namespace Subgroup
section SubgroupNormal
@[to_additive]
theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≤ K) :
(H.subgroupOf K).Normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H :=
⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN =>
{ conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩
@[to_additive prod_addSubgroupOf_prod_normal]
instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {H₂ K₂ : Subgroup N}
[h₁ : (H₁.subgroupOf K₁).Normal] [h₂ : (H₂.subgroupOf K₂).Normal] :
((H₁.prod H₂).subgroupOf (K₁.prod K₂)).Normal where
conj_mem n hgHK g :=
⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1
⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩,
h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2
⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩
@[deprecated (since := "2025-03-11")]
alias _root_.AddSubgroup.sum_addSubgroupOf_sum_normal := AddSubgroup.prod_addSubgroupOf_prod_normal
@[to_additive prod_normal]
instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] :
(H.prod K).Normal where
conj_mem n hg g :=
⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst,
hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩
@[deprecated (since := "2025-03-11")]
alias _root_.AddSubgroup.sum_normal := AddSubgroup.prod_normal
@[to_additive]
theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G)
[hN : (B'.subgroupOf B).Normal] : ((A ⊓ B').subgroupOf (A ⊓ B)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢
rw [inf_inf_inf_comm, inf_idem]
exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf)
@[to_additive]
theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G)
[hN : (A'.subgroupOf A).Normal] : ((A' ⊓ B).subgroupOf (A ⊓ B)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢
rw [inf_inf_inf_comm, inf_idem]
exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf)
@[to_additive]
instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊓ K).Normal :=
⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩
@[to_additive]
theorem normal_iInf_normal {ι : Type*} {a : ι → Subgroup G}
(norm : ∀ i : ι, (a i).Normal) : (iInf a).Normal := by
constructor
intro g g_in_iInf h
rw [Subgroup.mem_iInf] at g_in_iInf ⊢
intro i
exact (norm i).conj_mem g (g_in_iInf i) h
@[to_additive]
theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≤ K) [hN : (H.subgroupOf K).Normal]
{a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by
have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb
rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this
/-- Elements of disjoint, normal subgroups commute. -/
@[to_additive "Elements of disjoint, normal subgroups commute."]
theorem commute_of_normal_of_disjoint (H₁ H₂ : Subgroup G) (hH₁ : H₁.Normal) (hH₂ : H₂.Normal)
(hdis : Disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : Commute x y := by
suffices x * y * x⁻¹ * y⁻¹ = 1 by
show x * y = y * x
· rw [mul_assoc, mul_eq_one_iff_eq_inv] at this
simpa
apply hdis.le_bot
constructor
· suffices x * (y * x⁻¹ * y⁻¹) ∈ H₁ by simpa [mul_assoc]
exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _)
· show x * y * x⁻¹ * y⁻¹ ∈ H₂
apply H₂.mul_mem _ (H₂.inv_mem hy)
apply hH₂.conj_mem _ hy
@[to_additive]
theorem normal_subgroupOf_of_le_normalizer {H N : Subgroup G}
(hLE : H ≤ N.normalizer) : (N.subgroupOf H).Normal := by
rw [normal_subgroupOf_iff_le_normalizer_inf]
exact (le_inf hLE H.le_normalizer).trans inf_normalizer_le_normalizer_inf
@[to_additive]
theorem normal_subgroupOf_sup_of_le_normalizer {H N : Subgroup G}
(hLE : H ≤ N.normalizer) : (N.subgroupOf (H ⊔ N)).Normal := by
rw [normal_subgroupOf_iff_le_normalizer le_sup_right]
exact sup_le hLE le_normalizer
end SubgroupNormal
end Subgroup
namespace IsConj
open Subgroup
theorem normalClosure_eq_top_of {N : Subgroup G} [hn : N.Normal] {g g' : G} {hg : g ∈ N}
{hg' : g' ∈ N} (hc : IsConj g g') (ht : normalClosure ({⟨g, hg⟩} : Set N) = ⊤) :
normalClosure ({⟨g', hg'⟩} : Set N) = ⊤ := by
obtain ⟨c, rfl⟩ := isConj_iff.1 hc
have h : ∀ x : N, (MulAut.conj c) x ∈ N := by
rintro ⟨x, hx⟩
exact hn.conj_mem _ hx c
have hs : Function.Surjective (((MulAut.conj c).toMonoidHom.restrict N).codRestrict _ h) := by
rintro ⟨x, hx⟩
refine ⟨⟨c⁻¹ * x * c, ?_⟩, ?_⟩
· have h := hn.conj_mem _ hx c⁻¹
rwa [inv_inv] at h
simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk,
MonoidHom.restrict_apply, Subtype.mk_eq_mk, ← mul_assoc, mul_inv_cancel, one_mul]
rw [mul_assoc, mul_inv_cancel, mul_one]
rw [eq_top_iff, ← MonoidHom.range_eq_top.2 hs, MonoidHom.range_eq_map]
refine le_trans (map_mono (eq_top_iff.1 ht)) (map_le_iff_le_comap.2 (normalClosure_le_normal ?_))
rw [Set.singleton_subset_iff, SetLike.mem_coe]
simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk,
MonoidHom.restrict_apply, mem_comap]
exact subset_normalClosure (Set.mem_singleton _)
end IsConj
namespace ConjClasses
/-- The conjugacy classes that are not trivial. -/
def noncenter (G : Type*) [Monoid G] : Set (ConjClasses G) :=
{x | x.carrier.Nontrivial}
@[simp] lemma mem_noncenter {G} [Monoid G] (g : ConjClasses G) :
g ∈ noncenter G ↔ g.carrier.Nontrivial := Iff.rfl
end ConjClasses
/-- Suppose `G` acts on `M` and `I` is a subgroup of `M`.
The inertia subgroup of `I` is the subgroup of `G` whose action is trivial mod `I`. -/
def AddSubgroup.inertia {M : Type*} [AddGroup M] (I : AddSubgroup M) (G : Type*)
[Group G] [MulAction G M] : Subgroup G where
carrier := { σ | ∀ x, σ • x - x ∈ I }
mul_mem' {a b} ha hb x := by simpa [mul_smul] using add_mem (ha (b • x)) (hb x)
one_mem' := by simp [zero_mem]
inv_mem' {a} ha x := by simpa using sub_mem_comm_iff.mp (ha (a⁻¹ • x))
@[simp] lemma AddSubgroup.mem_inertia {M : Type*} [AddGroup M] {I : AddSubgroup M} {G : Type*}
[Group G] [MulAction G M] {σ : G} : σ ∈ I.inertia G ↔ ∀ x, σ • x - x ∈ I := .rfl
| Mathlib/Algebra/Group/Subgroup/Basic.lean | 981 | 982 | |
/-
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.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.Basis.Defs
/-!
# Lemmas about bilinear maps with a basis over each argument
-/
namespace LinearMap
variable {ι₁ ι₂ : Type*}
variable {R R₂ S S₂ M N P Rₗ : Type*}
variable {Mₗ Nₗ Pₗ : Type*}
-- Could weaken [CommSemiring Rₗ] to [SMulCommClass Rₗ Rₗ Pₗ], but might impact performance
variable [Semiring R] [Semiring S] [Semiring R₂] [Semiring S₂] [CommSemiring Rₗ]
section AddCommMonoid
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [AddCommMonoid Mₗ] [AddCommMonoid Nₗ] [AddCommMonoid Pₗ]
variable [Module R M] [Module S N] [Module R₂ P] [Module S₂ P]
variable [Module Rₗ Mₗ] [Module Rₗ Nₗ] [Module Rₗ Pₗ]
variable [SMulCommClass S₂ R₂ P]
variable {ρ₁₂ : R →+* R₂} {σ₁₂ : S →+* S₂}
variable (b₁ : Basis ι₁ R M) (b₂ : Basis ι₂ S N) (b₁' : Basis ι₁ Rₗ Mₗ) (b₂' : Basis ι₂ Rₗ Nₗ)
/-- Two bilinear maps are equal when they are equal on all basis vectors. -/
theorem ext_basis {B B' : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (h : ∀ i j, B (b₁ i) (b₂ j) = B' (b₁ i) (b₂ j)) :
B = B' :=
b₁.ext fun i => b₂.ext fun j => h i j
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis.
Version for semi-bilinear maps, see `sum_repr_mul_repr_mul` for the bilinear version. -/
theorem sum_repr_mul_repr_mulₛₗ {B : M →ₛₗ[ρ₁₂] N →ₛₗ[σ₁₂] P} (x y) :
((b₁.repr x).sum fun i xi => (b₂.repr y).sum fun j yj => ρ₁₂ xi • σ₁₂ yj • B (b₁ i) (b₂ j)) =
B x y := by
| conv_rhs => rw [← b₁.linearCombination_repr x, ← b₂.linearCombination_repr y]
simp_rw [Finsupp.linearCombination_apply, Finsupp.sum, map_sum₂, map_sum, LinearMap.map_smulₛₗ₂,
LinearMap.map_smulₛₗ]
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis.
| Mathlib/LinearAlgebra/Basis/Bilinear.lean | 44 | 49 |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Reverse
import Mathlib.Algebra.Polynomial.Inductions
import Mathlib.RingTheory.Localization.Away.Basic
/-! # Laurent polynomials
We introduce Laurent polynomials over a semiring `R`. Mathematically, they are expressions of the
form
$$
\sum_{i \in \mathbb{Z}} a_i T ^ i
$$
where the sum extends over a finite subset of `ℤ`. Thus, negative exponents are allowed. The
coefficients come from the semiring `R` and the variable `T` commutes with everything.
Since we are going to convert back and forth between polynomials and Laurent polynomials, we
decided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for
Laurent polynomials.
## Notation
The symbol `R[T;T⁻¹]` stands for `LaurentPolynomial R`. We also define
* `C : R →+* R[T;T⁻¹]` the inclusion of constant polynomials, analogous to the one for `R[X]`;
* `T : ℤ → R[T;T⁻¹]` the sequence of powers of the variable `T`.
## Implementation notes
We define Laurent polynomials as `AddMonoidAlgebra R ℤ`.
Thus, they are essentially `Finsupp`s `ℤ →₀ R`.
This choice differs from the current irreducible design of `Polynomial`, that instead shields away
the implementation via `Finsupp`s. It is closer to the original definition of polynomials.
As a consequence, `LaurentPolynomial` plays well with polynomials, but there is a little roughness
in establishing the API, since the `Finsupp` implementation of `R[X]` is well-shielded.
Unlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only
natural exponents would be allowed. Moreover, in the end, it seems likely that we should aim to
perform computations on exponents in `ℤ` anyway and separating this via the symbol `T` seems
convenient.
I made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`.
Any comments or suggestions for improvements is greatly appreciated!
## Future work
Lots is missing!
-- (Riccardo) add inclusion into Laurent series.
-- A "better" definition of `trunc` would be as an `R`-linear map. This works:
-- ```
-- def trunc : R[T;T⁻¹] →[R] R[X] :=
-- refine (?_ : R[ℕ] →[R] R[X]).comp ?_
-- · exact ⟨(toFinsuppIso R).symm, by simp⟩
-- · refine ⟨fun r ↦ comapDomain _ r
-- (Set.injOn_of_injective (fun _ _ ↦ Int.ofNat.inj) _), ?_⟩
-- exact fun r f ↦ comapDomain_smul ..
-- ```
-- but it would make sense to bundle the maps better, for a smoother user experience.
-- I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to
-- this stage of the Laurent process!
-- This would likely involve adding a `comapDomain` analogue of
-- `AddMonoidAlgebra.mapDomainAlgHom` and an `R`-linear version of
-- `Polynomial.toFinsuppIso`.
-- Add `degree, intDegree, intTrailingDegree, leadingCoeff, trailingCoeff,...`.
-/
open Polynomial Function AddMonoidAlgebra Finsupp
noncomputable section
variable {R S : Type*}
/-- The semiring of Laurent polynomials with coefficients in the semiring `R`.
We denote it by `R[T;T⁻¹]`.
The ring homomorphism `C : R →+* R[T;T⁻¹]` includes `R` as the constant polynomials. -/
abbrev LaurentPolynomial (R : Type*) [Semiring R] :=
AddMonoidAlgebra R ℤ
@[nolint docBlame]
scoped[LaurentPolynomial] notation:9000 R "[T;T⁻¹]" => LaurentPolynomial R
open LaurentPolynomial
@[ext]
theorem LaurentPolynomial.ext [Semiring R] {p q : R[T;T⁻¹]} (h : ∀ a, p a = q a) : p = q :=
Finsupp.ext h
/-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial
with coefficients in `R`. -/
def Polynomial.toLaurent [Semiring R] : R[X] →+* R[T;T⁻¹] :=
(mapDomainRingHom R Int.ofNatHom).comp (toFinsuppIso R)
/-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X`
instead. -/
theorem Polynomial.toLaurent_apply [Semiring R] (p : R[X]) :
toLaurent p = p.toFinsupp.mapDomain (↑) :=
rfl
/-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial
with coefficients in `R`. -/
def Polynomial.toLaurentAlg [CommSemiring R] : R[X] →ₐ[R] R[T;T⁻¹] :=
(mapDomainAlgHom R R Int.ofNatHom).comp (toFinsuppIsoAlg R).toAlgHom
@[simp] lemma Polynomial.coe_toLaurentAlg [CommSemiring R] :
(toLaurentAlg : R[X] → R[T;T⁻¹]) = toLaurent :=
rfl
theorem Polynomial.toLaurentAlg_apply [CommSemiring R] (f : R[X]) : toLaurentAlg f = toLaurent f :=
rfl
namespace LaurentPolynomial
section Semiring
variable [Semiring R]
theorem single_zero_one_eq_one : (Finsupp.single 0 1 : R[T;T⁻¹]) = (1 : R[T;T⁻¹]) :=
rfl
/-! ### The functions `C` and `T`. -/
/-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as
the constant Laurent polynomials. -/
def C : R →+* R[T;T⁻¹] :=
singleZeroRingHom
theorem algebraMap_apply {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (r : R) :
algebraMap R (LaurentPolynomial A) r = C (algebraMap R A r) :=
rfl
/-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[T;T⁻¹]`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebraMap` is not available.)
-/
theorem C_eq_algebraMap {R : Type*} [CommSemiring R] (r : R) : C r = algebraMap R R[T;T⁻¹] r :=
rfl
theorem single_eq_C (r : R) : Finsupp.single 0 r = C r := rfl
@[simp] lemma C_apply (t : R) (n : ℤ) : C t n = if n = 0 then t else 0 := by
rw [← single_eq_C, Finsupp.single_apply]; aesop
/-- The function `n ↦ T ^ n`, implemented as a sequence `ℤ → R[T;T⁻¹]`.
Using directly `T ^ n` does not work, since we want the exponents to be of Type `ℤ` and there
is no `ℤ`-power defined on `R[T;T⁻¹]`. Using that `T` is a unit introduces extra coercions.
For these reasons, the definition of `T` is as a sequence. -/
def T (n : ℤ) : R[T;T⁻¹] :=
Finsupp.single n 1
@[simp] lemma T_apply (m n : ℤ) : (T n : R[T;T⁻¹]) m = if n = m then 1 else 0 :=
Finsupp.single_apply
@[simp]
theorem T_zero : (T 0 : R[T;T⁻¹]) = 1 :=
rfl
theorem T_add (m n : ℤ) : (T (m + n) : R[T;T⁻¹]) = T m * T n := by
simp [T, single_mul_single]
theorem T_sub (m n : ℤ) : (T (m - n) : R[T;T⁻¹]) = T m * T (-n) := by rw [← T_add, sub_eq_add_neg]
@[simp]
theorem T_pow (m : ℤ) (n : ℕ) : (T m ^ n : R[T;T⁻¹]) = T (n * m) := by
rw [T, T, single_pow n, one_pow, nsmul_eq_mul]
/-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/
@[simp]
theorem mul_T_assoc (f : R[T;T⁻¹]) (m n : ℤ) : f * T m * T n = f * T (m + n) := by
simp [← T_add, mul_assoc]
@[simp]
theorem single_eq_C_mul_T (r : R) (n : ℤ) :
(Finsupp.single n r : R[T;T⁻¹]) = (C r * T n : R[T;T⁻¹]) := by
simp [C, T, single_mul_single]
-- This lemma locks in the right changes and is what Lean proved directly.
-- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached.
@[simp]
theorem _root_.Polynomial.toLaurent_C_mul_T (n : ℕ) (r : R) :
(toLaurent (Polynomial.monomial n r) : R[T;T⁻¹]) = C r * T n :=
show Finsupp.mapDomain (↑) (monomial n r).toFinsupp = (C r * T n : R[T;T⁻¹]) by
rw [toFinsupp_monomial, Finsupp.mapDomain_single, single_eq_C_mul_T]
@[simp]
theorem _root_.Polynomial.toLaurent_C (r : R) : toLaurent (Polynomial.C r) = C r := by
convert Polynomial.toLaurent_C_mul_T 0 r
simp only [Int.ofNat_zero, T_zero, mul_one]
@[simp]
theorem _root_.Polynomial.toLaurent_comp_C : toLaurent (R := R) ∘ Polynomial.C = C :=
funext Polynomial.toLaurent_C
@[simp]
theorem _root_.Polynomial.toLaurent_X : (toLaurent Polynomial.X : R[T;T⁻¹]) = T 1 := by
have : (Polynomial.X : R[X]) = monomial 1 1 := by simp [← C_mul_X_pow_eq_monomial]
simp [this, Polynomial.toLaurent_C_mul_T]
@[simp]
theorem _root_.Polynomial.toLaurent_one : (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) 1 = 1 :=
map_one Polynomial.toLaurent
@[simp]
theorem _root_.Polynomial.toLaurent_C_mul_eq (r : R) (f : R[X]) :
toLaurent (Polynomial.C r * f) = C r * toLaurent f := by
simp only [map_mul, Polynomial.toLaurent_C]
@[simp]
theorem _root_.Polynomial.toLaurent_X_pow (n : ℕ) : toLaurent (X ^ n : R[X]) = T n := by
simp only [map_pow, Polynomial.toLaurent_X, T_pow, mul_one]
theorem _root_.Polynomial.toLaurent_C_mul_X_pow (n : ℕ) (r : R) :
toLaurent (Polynomial.C r * X ^ n) = C r * T n := by
simp only [map_mul, Polynomial.toLaurent_C, Polynomial.toLaurent_X_pow]
instance invertibleT (n : ℤ) : Invertible (T n : R[T;T⁻¹]) where
invOf := T (-n)
invOf_mul_self := by rw [← T_add, neg_add_cancel, T_zero]
mul_invOf_self := by rw [← T_add, add_neg_cancel, T_zero]
@[simp]
theorem invOf_T (n : ℤ) : ⅟ (T n : R[T;T⁻¹]) = T (-n) :=
rfl
theorem isUnit_T (n : ℤ) : IsUnit (T n : R[T;T⁻¹]) :=
isUnit_of_invertible _
@[elab_as_elim]
protected theorem induction_on {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (h_C : ∀ a, M (C a))
(h_add : ∀ {p q}, M p → M q → M (p + q))
(h_C_mul_T : ∀ (n : ℕ) (a : R), M (C a * T n) → M (C a * T (n + 1)))
(h_C_mul_T_Z : ∀ (n : ℕ) (a : R), M (C a * T (-n)) → M (C a * T (-n - 1))) : M p := by
have A : ∀ {n : ℤ} {a : R}, M (C a * T n) := by
intro n a
refine Int.induction_on n ?_ ?_ ?_
· simpa only [T_zero, mul_one] using h_C a
· exact fun m => h_C_mul_T m a
· exact fun m => h_C_mul_T_Z m a
have B : ∀ s : Finset ℤ, M (s.sum fun n : ℤ => C (p.toFun n) * T n) := by
apply Finset.induction
· convert h_C 0
simp only [Finset.sum_empty, map_zero]
· intro n s ns ih
rw [Finset.sum_insert ns]
exact h_add A ih
convert B p.support
ext a
simp_rw [← single_eq_C_mul_T]
-- Porting note: did not make progress in `simp_rw`
rw [Finset.sum_apply']
simp_rw [Finsupp.single_apply, Finset.sum_ite_eq']
split_ifs with h
· rfl
· exact Finsupp.not_mem_support_iff.mp h
/-- To prove something about Laurent polynomials, it suffices to show that
* the condition is closed under taking sums, and
* it holds for monomials.
-/
@[elab_as_elim]
protected theorem induction_on' {motive : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹])
(add : ∀ p q, motive p → motive q → motive (p + q))
(C_mul_T : ∀ (n : ℤ) (a : R), motive (C a * T n)) : motive p := by
refine p.induction_on (fun a => ?_) (fun {p q} => add p q) ?_ ?_ <;>
try exact fun n f _ => C_mul_T _ f
convert C_mul_T 0 a
exact (mul_one _).symm
theorem commute_T (n : ℤ) (f : R[T;T⁻¹]) : Commute (T n) f :=
f.induction_on' (fun _ _ Tp Tq => Commute.add_right Tp Tq) fun m a =>
show T n * _ = _ by
rw [T, T, ← single_eq_C, single_mul_single, single_mul_single, single_mul_single]
simp [add_comm]
@[simp]
theorem T_mul (n : ℤ) (f : R[T;T⁻¹]) : T n * f = f * T n :=
(commute_T n f).eq
theorem smul_eq_C_mul (r : R) (f : R[T;T⁻¹]) : r • f = C r * f := by
induction f using LaurentPolynomial.induction_on' with
| add _ _ hp hq =>
rw [smul_add, mul_add, hp, hq]
| C_mul_T n s =>
rw [← mul_assoc, ← smul_mul_assoc, mul_left_inj_of_invertible, ← map_mul, ← single_eq_C,
Finsupp.smul_single', single_eq_C]
/-- `trunc : R[T;T⁻¹] →+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of
nonnegative degree coincide with the ones of `f`. The terms of negative degree of `f` "vanish".
`trunc` is a left-inverse to `Polynomial.toLaurent`. -/
def trunc : R[T;T⁻¹] →+ R[X] :=
(toFinsuppIso R).symm.toAddMonoidHom.comp <| comapDomain.addMonoidHom fun _ _ => Int.ofNat.inj
@[simp]
theorem trunc_C_mul_T (n : ℤ) (r : R) : trunc (C r * T n) = ite (0 ≤ n) (monomial n.toNat r) 0 := by
apply (toFinsuppIso R).injective
rw [← single_eq_C_mul_T, trunc, AddMonoidHom.coe_comp, Function.comp_apply]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): was `rw`
erw [comapDomain.addMonoidHom_apply Int.ofNat_injective]
rw [toFinsuppIso_apply]
split_ifs with n0
· rw [toFinsupp_monomial]
lift n to ℕ using n0
apply comapDomain_single
· rw [toFinsupp_inj]
ext a
have : n ≠ a := by omega
simp only [coeff_ofFinsupp, comapDomain_apply, Int.ofNat_eq_coe, coeff_zero,
single_eq_of_ne this]
@[simp]
theorem leftInverse_trunc_toLaurent :
Function.LeftInverse (trunc : R[T;T⁻¹] → R[X]) Polynomial.toLaurent := by
refine fun f => f.induction_on' ?_ ?_
· intro f g hf hg
simp only [hf, hg, map_add]
· intro n r
simp only [Polynomial.toLaurent_C_mul_T, trunc_C_mul_T, Int.natCast_nonneg, Int.toNat_natCast,
if_true]
@[simp]
theorem _root_.Polynomial.trunc_toLaurent (f : R[X]) : trunc (toLaurent f) = f :=
leftInverse_trunc_toLaurent _
theorem _root_.Polynomial.toLaurent_injective :
Function.Injective (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) :=
leftInverse_trunc_toLaurent.injective
@[simp]
theorem _root_.Polynomial.toLaurent_inj (f g : R[X]) : toLaurent f = toLaurent g ↔ f = g :=
⟨fun h => Polynomial.toLaurent_injective h, congr_arg _⟩
theorem _root_.Polynomial.toLaurent_ne_zero {f : R[X]} : toLaurent f ≠ 0 ↔ f ≠ 0 :=
map_ne_zero_iff _ Polynomial.toLaurent_injective
@[simp]
theorem _root_.Polynomial.toLaurent_eq_zero {f : R[X]} : toLaurent f = 0 ↔ f = 0 :=
map_eq_zero_iff _ Polynomial.toLaurent_injective
theorem exists_T_pow (f : R[T;T⁻¹]) : ∃ (n : ℕ) (f' : R[X]), toLaurent f' = f * T n := by
refine f.induction_on' ?_ fun n a => ?_ <;> clear f
· rintro f g ⟨m, fn, hf⟩ ⟨n, gn, hg⟩
refine ⟨m + n, fn * X ^ n + gn * X ^ m, ?_⟩
simp only [hf, hg, add_mul, add_comm (n : ℤ), map_add, map_mul, Polynomial.toLaurent_X_pow,
mul_T_assoc, Int.natCast_add]
· rcases n with n | n
· exact ⟨0, Polynomial.C a * X ^ n, by simp⟩
· refine ⟨n + 1, Polynomial.C a, ?_⟩
simp only [Int.negSucc_eq, Polynomial.toLaurent_C, Int.natCast_succ, mul_T_assoc,
neg_add_cancel, T_zero, mul_one]
/-- This is a version of `exists_T_pow` stated as an induction principle. -/
@[elab_as_elim]
theorem induction_on_mul_T {Q : R[T;T⁻¹] → Prop} (f : R[T;T⁻¹])
(Qf : ∀ {f : R[X]} {n : ℕ}, Q (toLaurent f * T (-n))) : Q f := by
rcases f.exists_T_pow with ⟨n, f', hf⟩
rw [← mul_one f, ← T_zero, ← Nat.cast_zero, ← Nat.sub_self n, Nat.cast_sub rfl.le, T_sub,
← mul_assoc, ← hf]
exact Qf
/-- Suppose that `Q` is a statement about Laurent polynomials such that
* `Q` is true on *ordinary* polynomials;
* `Q (f * T)` implies `Q f`;
it follow that `Q` is true on all Laurent polynomials. -/
theorem reduce_to_polynomial_of_mul_T (f : R[T;T⁻¹]) {Q : R[T;T⁻¹] → Prop}
(Qf : ∀ f : R[X], Q (toLaurent f)) (QT : ∀ f, Q (f * T 1) → Q f) : Q f := by
induction' f using LaurentPolynomial.induction_on_mul_T with f n
induction n with
| zero => simpa only [Nat.cast_zero, neg_zero, T_zero, mul_one] using Qf _
| succ n hn => convert QT _ _; simpa using hn
section Support
theorem support_C_mul_T (a : R) (n : ℤ) : Finsupp.support (C a * T n) ⊆ {n} := by
rw [← single_eq_C_mul_T]
exact support_single_subset
theorem support_C_mul_T_of_ne_zero {a : R} (a0 : a ≠ 0) (n : ℤ) :
Finsupp.support (C a * T n) = {n} := by
rw [← single_eq_C_mul_T]
exact support_single_ne_zero _ a0
/-- The support of a polynomial `f` is a finset in `ℕ`. The lemma `toLaurent_support f`
shows that the support of `f.toLaurent` is the same finset, but viewed in `ℤ` under the natural
inclusion `ℕ ↪ ℤ`. -/
theorem toLaurent_support (f : R[X]) : f.toLaurent.support = f.support.map Nat.castEmbedding := by
generalize hd : f.support = s
revert f
refine Finset.induction_on s ?_ ?_ <;> clear s
· intro f hf
rw [Finset.map_empty, Finsupp.support_eq_empty, toLaurent_eq_zero]
exact Polynomial.support_eq_empty.mp hf
· intro a s as hf f fs
have : (erase a f).toLaurent.support = s.map Nat.castEmbedding := by
refine hf (f.erase a) ?_
simp only [fs, Finset.erase_eq_of_not_mem as, Polynomial.support_erase,
Finset.erase_insert_eq_erase]
rw [← monomial_add_erase f a, Finset.map_insert, ← this, map_add, Polynomial.toLaurent_C_mul_T,
support_add_eq, Finset.insert_eq]
· congr
exact support_C_mul_T_of_ne_zero (Polynomial.mem_support_iff.mp (by simp [fs])) _
· rw [this]
exact Disjoint.mono_left (support_C_mul_T _ _) (by simpa)
end Support
section Degrees
/-- The degree of a Laurent polynomial takes values in `WithBot ℤ`.
If `f : R[T;T⁻¹]` is a Laurent polynomial, then `f.degree` is the maximum of its support of `f`,
or `⊥`, if `f = 0`. -/
def degree (f : R[T;T⁻¹]) : WithBot ℤ :=
f.support.max
@[simp]
theorem degree_zero : degree (0 : R[T;T⁻¹]) = ⊥ :=
rfl
@[simp]
theorem degree_eq_bot_iff {f : R[T;T⁻¹]} : f.degree = ⊥ ↔ f = 0 := by
refine ⟨fun h => ?_, fun h => by rw [h, degree_zero]⟩
ext n
simp only [coe_zero, Pi.zero_apply]
simp_rw [degree, Finset.max_eq_sup_withBot, Finset.sup_eq_bot_iff, Finsupp.mem_support_iff, Ne,
WithBot.coe_ne_bot, imp_false, not_not] at h
exact h n
section ExactDegrees
@[simp]
theorem degree_C_mul_T (n : ℤ) (a : R) (a0 : a ≠ 0) : degree (C a * T n) = n := by
rw [degree, support_C_mul_T_of_ne_zero a0 n]
exact Finset.max_singleton
theorem degree_C_mul_T_ite [DecidableEq R] (n : ℤ) (a : R) :
degree (C a * T n) = if a = 0 then ⊥ else ↑n := by
split_ifs with h <;>
simp only [h, map_zero, zero_mul, degree_zero, degree_C_mul_T, Ne,
not_false_iff]
@[simp]
theorem degree_T [Nontrivial R] (n : ℤ) : (T n : R[T;T⁻¹]).degree = n := by
rw [← one_mul (T n), ← map_one C]
exact degree_C_mul_T n 1 (one_ne_zero : (1 : R) ≠ 0)
theorem degree_C {a : R} (a0 : a ≠ 0) : (C a).degree = 0 := by
rw [← mul_one (C a), ← T_zero]
exact degree_C_mul_T 0 a a0
theorem degree_C_ite [DecidableEq R] (a : R) : (C a).degree = if a = 0 then ⊥ else 0 := by
split_ifs with h <;> simp only [h, map_zero, degree_zero, degree_C, Ne, not_false_iff]
end ExactDegrees
section DegreeBounds
theorem degree_C_mul_T_le (n : ℤ) (a : R) : degree (C a * T n) ≤ n := by
by_cases a0 : a = 0
· simp only [a0, map_zero, zero_mul, degree_zero, bot_le]
· exact (degree_C_mul_T n a a0).le
theorem degree_T_le (n : ℤ) : (T n : R[T;T⁻¹]).degree ≤ n :=
(le_of_eq (by rw [map_one, one_mul])).trans (degree_C_mul_T_le n (1 : R))
theorem degree_C_le (a : R) : (C a).degree ≤ 0 :=
(le_of_eq (by rw [T_zero, mul_one])).trans (degree_C_mul_T_le 0 a)
end DegreeBounds
end Degrees
instance : Module R[X] R[T;T⁻¹] :=
Module.compHom _ Polynomial.toLaurent
instance (R : Type*) [Semiring R] : IsScalarTower R[X] R[X] R[T;T⁻¹] where
smul_assoc x y z := by dsimp; simp_rw [MulAction.mul_smul]
end Semiring
section CommSemiring
variable [CommSemiring R] {S : Type*} [CommSemiring S] (f : R →+* S) (x : Sˣ)
instance algebraPolynomial (R : Type*) [CommSemiring R] : Algebra R[X] R[T;T⁻¹] where
algebraMap := Polynomial.toLaurent
commutes' := fun f l => by simp [mul_comm]
smul_def' := fun _ _ => rfl
theorem algebraMap_X_pow (n : ℕ) : algebraMap R[X] R[T;T⁻¹] (X ^ n) = T n :=
Polynomial.toLaurent_X_pow n
@[simp]
theorem algebraMap_eq_toLaurent (f : R[X]) : algebraMap R[X] R[T;T⁻¹] f = toLaurent f :=
rfl
instance isLocalization : IsLocalization.Away (X : R[X]) R[T;T⁻¹] :=
{ map_units' := fun ⟨t, ht⟩ => by
obtain ⟨n, rfl⟩ := ht
rw [algebraMap_eq_toLaurent, toLaurent_X_pow]
exact isUnit_T ↑n
surj' := fun f => by
induction' f using LaurentPolynomial.induction_on_mul_T with f n
have : X ^ n ∈ Submonoid.powers (X : R[X]) := ⟨n, rfl⟩
refine ⟨(f, ⟨_, this⟩), ?_⟩
simp only [algebraMap_eq_toLaurent, toLaurent_X_pow, mul_T_assoc, neg_add_cancel, T_zero,
mul_one]
exists_of_eq := fun {f g} => by
rw [algebraMap_eq_toLaurent, algebraMap_eq_toLaurent, Polynomial.toLaurent_inj]
rintro rfl
exact ⟨1, rfl⟩ }
theorem mk'_mul_T (p : R[X]) (n : ℕ) :
IsLocalization.mk' R[T;T⁻¹] p (⟨X^n, n, rfl⟩ : Submonoid.powers (X : R[X])) * T n =
toLaurent p := by
rw [←toLaurent_X_pow, ←algebraMap_eq_toLaurent, IsLocalization.mk'_spec, algebraMap_eq_toLaurent]
@[simp]
theorem mk'_eq (p : R[X]) (n : ℕ) :
IsLocalization.mk' R[T;T⁻¹] p (⟨X^n, n, rfl⟩ : Submonoid.powers (X : R[X])) =
toLaurent p * T (-n) := by
rw [←IsUnit.mul_left_inj (isUnit_T n), mul_T_assoc, neg_add_cancel, T_zero, mul_one]
exact mk'_mul_T p n
theorem mk'_one_X_pow (n : ℕ) :
IsLocalization.mk' R[T;T⁻¹] 1 (⟨X^n, n, rfl⟩ : Submonoid.powers (X : R[X])) = T (-n) := by
rw [mk'_eq 1 n, toLaurent_one, one_mul]
@[simp]
theorem mk'_one_X :
IsLocalization.mk' R[T;T⁻¹] 1 (⟨X, 1, pow_one X⟩ : Submonoid.powers (X : R[X])) = T (-1) := by
convert mk'_one_X_pow 1
exact (pow_one X).symm
/-- Given a ring homomorphism `f : R →+* S` and a unit `x` in `S`, the induced homomorphism
`R[T;T⁻¹] →+* S` sending `T` to `x` and `T⁻¹` to `x⁻¹`. -/
def eval₂ : R[T;T⁻¹] →+* S :=
IsLocalization.lift (M := Submonoid.powers (X : R[X])) (g := Polynomial.eval₂RingHom f x) <| by
rintro ⟨y, n, rfl⟩
simpa only [coe_eval₂RingHom, eval₂_X_pow] using x.isUnit.pow n
@[simp]
theorem eval₂_toLaurent (p : R[X]) : eval₂ f x (toLaurent p) = Polynomial.eval₂ f x p := by
unfold eval₂
rw [←algebraMap_eq_toLaurent, IsLocalization.lift_eq, coe_eval₂RingHom]
theorem eval₂_T_n (n : ℕ) : eval₂ f x (T n) = x ^ n := by
rw [←Polynomial.toLaurent_X_pow, eval₂_toLaurent, eval₂_X_pow]
theorem eval₂_T_neg_n (n : ℕ) : eval₂ f x (T (-n)) = x⁻¹ ^ n := by
rw [←mk'_one_X_pow]
unfold eval₂
rw [IsLocalization.lift_mk'_spec, map_one, coe_eval₂RingHom, eval₂_X_pow, ←mul_pow,
Units.mul_inv, one_pow]
@[simp]
theorem eval₂_T (n : ℤ) : eval₂ f x (T n) = (x ^ n).val := by
by_cases hn : 0 ≤ n
· lift n to ℕ using hn
apply eval₂_T_n
· obtain ⟨m, rfl⟩ := Int.exists_eq_neg_ofNat (Int.le_of_not_le hn)
| rw [eval₂_T_neg_n, zpow_neg, zpow_natCast, ← inv_pow, Units.val_pow_eq_pow_val]
| Mathlib/Algebra/Polynomial/Laurent.lean | 564 | 565 |
/-
Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.Affine
import Mathlib.LinearAlgebra.FreeModule.Norm
import Mathlib.RingTheory.ClassGroup
import Mathlib.RingTheory.Polynomial.UniqueFactorization
/-!
# Group law on Weierstrass curves
This file proves that the nonsingular rational points on a Weierstrass curve form an abelian group
under the geometric group law defined in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`.
## Mathematical background
Let `W` be a Weierstrass curve over a field `F` given by a Weierstrass equation `W(X, Y) = 0` in
affine coordinates. As in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`, the set of
nonsingular rational points `W⟮F⟯` of `W` consist of the unique point at infinity `𝓞` and
nonsingular affine points `(x, y)`. With this description, there is an addition-preserving injection
between `W⟮F⟯` and the ideal class group of the *affine coordinate ring*
`F[W] := F[X, Y] / ⟨W(X, Y)⟩` of `W`. This is given by mapping `𝓞` to the trivial ideal class and a
nonsingular affine point `(x, y)` to the ideal class of the invertible ideal `⟨X - x, Y - y⟩`.
Proving that this is well-defined and preserves addition reduces to equalities of integral ideals
checked in `WeierstrassCurve.Affine.CoordinateRing.XYIdeal_neg_mul` and in
`WeierstrassCurve.Affine.CoordinateRing.XYIdeal_mul_XYIdeal` via explicit ideal computations.
Now `F[W]` is a free rank two `F[X]`-algebra with basis `{1, Y}`, so every element of `F[W]` is of
the form `p + qY` for some `p, q` in `F[X]`, and there is an algebra norm `N : F[W] → F[X]`.
Injectivity can then be shown by computing the degree of such a norm `N(p + qY)` in two different
ways, which is done in `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis` and in the
auxiliary lemmas in the proof of `WeierstrassCurve.Affine.Point.instAddCommGroup`.
## Main definitions
* `WeierstrassCurve.Affine.CoordinateRing`: the coordinate ring `F[W]` of a Weierstrass curve `W`.
* `WeierstrassCurve.Affine.CoordinateRing.basis`: the power basis of `F[W]` over `F[X]`.
## Main statements
* `WeierstrassCurve.Affine.CoordinateRing.instIsDomainCoordinateRing`: the affine coordinate ring
of a Weierstrass curve is an integral domain.
* `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis`: the degree of the norm of an
element in the affine coordinate ring in terms of its power basis.
* `WeierstrassCurve.Affine.Point.instAddCommGroup`: the type of nonsingular points `W⟮F⟯` in affine
coordinates forms an abelian group under addition.
## References
https://drops.dagstuhl.de/storage/00lipics/lipics-vol268-itp2023/LIPIcs.ITP.2023.6/LIPIcs.ITP.2023.6.pdf
## Tags
elliptic curve, group law, class group
-/
open Ideal Polynomial
open scoped nonZeroDivisors Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "eval_simp" : tactic =>
`(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow])
universe u v
namespace WeierstrassCurve.Affine
/-! ## Weierstrass curves in affine coordinates -/
variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] (W : Affine R) (f : R →+* S)
-- Porting note: in Lean 3, this is a `def` under a `derive comm_ring` tag.
-- This generates a reducible instance of `comm_ring` for `coordinate_ring`. In certain
-- circumstances this might be extremely slow, because all instances in its definition are unified
-- exponentially many times. In this case, one solution is to manually add the local attribute
-- `local attribute [irreducible] coordinate_ring.comm_ring` to block this type-level unification.
-- In Lean 4, this is no longer an issue and is now an `abbrev`. See Zulip thread:
-- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/.E2.9C.94.20class_group.2Emk
/-- The affine coordinate ring `R[W] := R[X, Y] / ⟨W(X, Y)⟩` of a Weierstrass curve `W`. -/
abbrev CoordinateRing : Type u :=
AdjoinRoot W.polynomial
/-- The function field `R(W) := Frac(R[W])` of a Weierstrass curve `W`. -/
abbrev FunctionField : Type u :=
FractionRing W.CoordinateRing
namespace CoordinateRing
section Algebra
/-! ### The coordinate ring as an `R[X]`-algebra -/
noncomputable instance : Algebra R W.CoordinateRing :=
Quotient.algebra R
noncomputable instance : Algebra R[X] W.CoordinateRing :=
Quotient.algebra R[X]
instance : IsScalarTower R R[X] W.CoordinateRing :=
Quotient.isScalarTower R R[X] _
instance [Subsingleton R] : Subsingleton W.CoordinateRing :=
Module.subsingleton R[X] _
/-- The natural ring homomorphism mapping `R[X][Y]` to `R[W]`. -/
noncomputable abbrev mk : R[X][Y] →+* W.CoordinateRing :=
AdjoinRoot.mk W.polynomial
/-- The power basis `{1, Y}` for `R[W]` over `R[X]`. -/
protected noncomputable def basis : Basis (Fin 2) R[X] W.CoordinateRing := by
classical exact (subsingleton_or_nontrivial R).by_cases (fun _ => default) fun _ =>
(AdjoinRoot.powerBasis' W.monic_polynomial).basis.reindex <| finCongr W.natDegree_polynomial
lemma basis_apply (n : Fin 2) :
CoordinateRing.basis W n = (AdjoinRoot.powerBasis' W.monic_polynomial).gen ^ (n : ℕ) := by
classical
nontriviality R
rw [CoordinateRing.basis, Or.by_cases, dif_neg <| not_subsingleton R, Basis.reindex_apply,
PowerBasis.basis_eq_pow]
rfl
@[simp]
lemma basis_zero : CoordinateRing.basis W 0 = 1 := by
simpa only [basis_apply] using pow_zero _
@[simp]
lemma basis_one : CoordinateRing.basis W 1 = mk W Y := by
simpa only [basis_apply] using pow_one _
lemma coe_basis : (CoordinateRing.basis W : Fin 2 → W.CoordinateRing) = ![1, mk W Y] := by
ext n
fin_cases n
exacts [basis_zero W, basis_one W]
variable {W} in
lemma smul (x : R[X]) (y : W.CoordinateRing) : x • y = mk W (C x) * y :=
(algebraMap_smul W.CoordinateRing x y).symm
variable {W} in
lemma smul_basis_eq_zero {p q : R[X]} (hpq : p • (1 : W.CoordinateRing) + q • mk W Y = 0) :
p = 0 ∧ q = 0 := by
have h := Fintype.linearIndependent_iff.mp (CoordinateRing.basis W).linearIndependent ![p, q]
rw [Fin.sum_univ_succ, basis_zero, Fin.sum_univ_one, Fin.succ_zero_eq_one, basis_one] at h
exact ⟨h hpq 0, h hpq 1⟩
variable {W} in
lemma exists_smul_basis_eq (x : W.CoordinateRing) :
∃ p q : R[X], p • (1 : W.CoordinateRing) + q • mk W Y = x := by
have h := (CoordinateRing.basis W).sum_equivFun x
rw [Fin.sum_univ_succ, Fin.sum_univ_one, basis_zero, Fin.succ_zero_eq_one, basis_one] at h
exact ⟨_, _, h⟩
lemma smul_basis_mul_C (y : R[X]) (p q : R[X]) :
(p • (1 : W.CoordinateRing) + q • mk W Y) * mk W (C y) =
(p * y) • (1 : W.CoordinateRing) + (q * y) • mk W Y := by
simp only [smul, map_mul]
ring1
lemma smul_basis_mul_Y (p q : R[X]) : (p • (1 : W.CoordinateRing) + q • mk W Y) * mk W Y =
(q * (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆)) • (1 : W.CoordinateRing) +
(p - q * (C W.a₁ * X + C W.a₃)) • mk W Y := by
have Y_sq : mk W Y ^ 2 =
mk W (C (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆) - C (C W.a₁ * X + C W.a₃) * Y) := by
exact AdjoinRoot.mk_eq_mk.mpr ⟨1, by rw [polynomial]; ring1⟩
simp only [smul, add_mul, mul_assoc, ← sq, Y_sq, C_sub, map_sub, C_mul, map_mul]
ring1
/-- The ring homomorphism `R[W] →+* S[W.map f]` induced by a ring homomorphism `f : R →+* S`. -/
noncomputable def map : W.CoordinateRing →+* (W.map f).toAffine.CoordinateRing :=
AdjoinRoot.lift ((AdjoinRoot.of _).comp <| mapRingHom f)
((AdjoinRoot.root (WeierstrassCurve.map W f).toAffine.polynomial)) <| by
rw [← eval₂_map, ← map_polynomial, AdjoinRoot.eval₂_root]
lemma map_mk (x : R[X][Y]) : map W f (mk W x) = mk (W.map f) (x.map <| mapRingHom f) := by
rw [map, AdjoinRoot.lift_mk, ← eval₂_map]
exact AdjoinRoot.aeval_eq <| x.map <| mapRingHom f
variable {W} in
protected lemma map_smul (x : R[X]) (y : W.CoordinateRing) :
map W f (x • y) = x.map f • map W f y := by
rw [smul, map_mul, map_mk, map_C, smul]
rfl
variable {f} in
lemma map_injective (hf : Function.Injective f) : Function.Injective <| map W f :=
(injective_iff_map_eq_zero _).mpr fun y hy => by
obtain ⟨p, q, rfl⟩ := exists_smul_basis_eq y
simp_rw [map_add, CoordinateRing.map_smul, map_one, map_mk, map_X] at hy
obtain ⟨hp, hq⟩ := smul_basis_eq_zero hy
rw [Polynomial.map_eq_zero_iff hf] at hp hq
simp_rw [hp, hq, zero_smul, add_zero]
instance [IsDomain R] : IsDomain W.CoordinateRing :=
have : IsDomain (W.map <| algebraMap R <| FractionRing R).toAffine.CoordinateRing :=
AdjoinRoot.isDomain_of_prime irreducible_polynomial.prime
(map_injective W <| IsFractionRing.injective R <| FractionRing R).isDomain
end Algebra
section Ring
/-! ### Ideals in the coordinate ring over a ring -/
/-- The class of the element `X - x` in `R[W]` for some `x` in `R`. -/
noncomputable def XClass (x : R) : W.CoordinateRing :=
mk W <| C <| X - C x
lemma XClass_ne_zero [Nontrivial R] (x : R) : XClass W x ≠ 0 :=
AdjoinRoot.mk_ne_zero_of_natDegree_lt W.monic_polynomial (C_ne_zero.mpr <| X_sub_C_ne_zero x) <|
| by rw [natDegree_polynomial, natDegree_C]; norm_num1
/-- The class of the element `Y - y(X)` in `R[W]` for some `y(X)` in `R[X]`. -/
noncomputable def YClass (y : R[X]) : W.CoordinateRing :=
mk W <| Y - C y
lemma YClass_ne_zero [Nontrivial R] (y : R[X]) : YClass W y ≠ 0 :=
| Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean | 214 | 220 |
/-
Copyright (c) 2024 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Filtered.Connected
import Mathlib.CategoryTheory.Limits.Types.Filtered
import Mathlib.CategoryTheory.Limits.Sifted
/-!
# Final functors with filtered (co)domain
If `C` is a filtered category, then the usual equivalent conditions for a functor `F : C ⥤ D` to be
final can be restated. We show:
* `final_iff_of_isFiltered`: a concrete description of finality which is sometimes a convenient way
to show that a functor is final.
* `final_iff_isFiltered_structuredArrow`: `F` is final if and only if `StructuredArrow d F` is
filtered for all `d : D`, which strengthens the usual statement that `F` is final if and only
if `StructuredArrow d F` is connected for all `d : D`.
* Under categories of objects of filtered categories are filtered and their forgetful functors
are final.
* If `D` is a filtered category and `F : C ⥤ D` is fully faithful and satisfies the additional
condition that for every `d : D` there is an object `c : D` and a morphism `d ⟶ F.obj c`, then
`C` is filtered and `F` is final.
* Finality and initiality of diagonal functors `diag : C ⥤ C × C` and of projection functors
of (co)structured arrow categories.
* Finality of `StructuredArrow.post`, given the finality of its arguments.
## References
* [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Section 3.2
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
open CategoryTheory.Limits CategoryTheory.Functor Opposite
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D)
/-- If `StructuredArrow d F` is filtered for any `d : D`, then `F : C ⥤ D` is final. This is
simply because filtered categories are connected. More profoundly, the converse is also true if
`C` is filtered, see `final_iff_isFiltered_structuredArrow`. -/
theorem Functor.final_of_isFiltered_structuredArrow [∀ d, IsFiltered (StructuredArrow d F)] :
Final F where
out _ := IsFiltered.isConnected _
/-- If `CostructuredArrow F d` is filtered for any `d : D`, then `F : C ⥤ D` is initial. This is
simply because cofiltered categories are connectged. More profoundly, the converse is also true
if `C` is cofiltered, see `initial_iff_isCofiltered_costructuredArrow`. -/
theorem Functor.initial_of_isCofiltered_costructuredArrow
[∀ d, IsCofiltered (CostructuredArrow F d)] : Initial F where
out _ := IsCofiltered.isConnected _
theorem isFiltered_structuredArrow_of_isFiltered_of_exists [IsFilteredOrEmpty C]
(h₁ : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) (h₂ : ∀ {d : D} {c : C} (s s' : d ⟶ F.obj c),
∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t) (d : D) :
IsFiltered (StructuredArrow d F) := by
have : Nonempty (StructuredArrow d F) := by
obtain ⟨c, ⟨f⟩⟩ := h₁ d
exact ⟨.mk f⟩
suffices IsFilteredOrEmpty (StructuredArrow d F) from IsFiltered.mk
refine ⟨fun f g => ?_, fun f g η μ => ?_⟩
· obtain ⟨c, ⟨t, ht⟩⟩ := h₂ (f.hom ≫ F.map (IsFiltered.leftToMax f.right g.right))
(g.hom ≫ F.map (IsFiltered.rightToMax f.right g.right))
refine ⟨.mk (f.hom ≫ F.map (IsFiltered.leftToMax f.right g.right ≫ t)), ?_, ?_, trivial⟩
· exact StructuredArrow.homMk (IsFiltered.leftToMax _ _ ≫ t) rfl
· exact StructuredArrow.homMk (IsFiltered.rightToMax _ _ ≫ t) (by simpa using ht.symm)
· refine ⟨.mk (f.hom ≫ F.map (η.right ≫ IsFiltered.coeqHom η.right μ.right)),
StructuredArrow.homMk (IsFiltered.coeqHom η.right μ.right) (by simp), ?_⟩
simpa using IsFiltered.coeq_condition _ _
theorem isCofiltered_costructuredArrow_of_isCofiltered_of_exists [IsCofilteredOrEmpty C]
(h₁ : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) (h₂ : ∀ {d : D} {c : C} (s s' : F.obj c ⟶ d),
∃ (c' : C) (t : c' ⟶ c), F.map t ≫ s = F.map t ≫ s') (d : D) :
IsCofiltered (CostructuredArrow F d) := by
suffices IsFiltered (CostructuredArrow F d)ᵒᵖ from isCofiltered_of_isFiltered_op _
suffices IsFiltered (StructuredArrow (op d) F.op) from
IsFiltered.of_equivalence (costructuredArrowOpEquivalence _ _).symm
apply isFiltered_structuredArrow_of_isFiltered_of_exists
· intro d
obtain ⟨c, ⟨t⟩⟩ := h₁ d.unop
exact ⟨op c, ⟨Quiver.Hom.op t⟩⟩
· intro d c s s'
obtain ⟨c', t, ht⟩ := h₂ s.unop s'.unop
exact ⟨op c', Quiver.Hom.op t, Quiver.Hom.unop_inj ht⟩
/-- If `C` is filtered, then we can give an explicit condition for a functor `F : C ⥤ D` to
be final. The converse is also true, see `final_iff_of_isFiltered`. -/
theorem Functor.final_of_exists_of_isFiltered [IsFilteredOrEmpty C]
(h₁ : ∀ d, ∃ c, Nonempty (d ⟶ F.obj c)) (h₂ : ∀ {d : D} {c : C} (s s' : d ⟶ F.obj c),
∃ (c' : C) (t : c ⟶ c'), s ≫ F.map t = s' ≫ F.map t) : Functor.Final F := by
suffices ∀ d, IsFiltered (StructuredArrow d F) from final_of_isFiltered_structuredArrow F
exact isFiltered_structuredArrow_of_isFiltered_of_exists F h₁ h₂
/-- The inclusion of a terminal object is final. -/
theorem Functor.final_const_of_isTerminal [IsFiltered C] {X : D} (hX : IsTerminal X) :
((Functor.const C).obj X).Final :=
Functor.final_of_exists_of_isFiltered _ (fun _ => ⟨IsFiltered.nonempty.some, ⟨hX.from _⟩⟩)
(fun {_ c} _ _ => ⟨c, 𝟙 _, hX.hom_ext _ _⟩)
/-- The inclusion of the terminal object is final. -/
theorem Functor.final_const_terminal [IsFiltered C] [HasTerminal D] :
((Functor.const C).obj (⊤_ D)).Final :=
| Functor.final_const_of_isTerminal terminalIsTerminal
/-- If `C` is cofiltered, then we can give an explicit condition for a functor `F : C ⥤ D` to
be final. The converse is also true, see `initial_iff_of_isCofiltered`. -/
theorem Functor.initial_of_exists_of_isCofiltered [IsCofilteredOrEmpty C]
(h₁ : ∀ d, ∃ c, Nonempty (F.obj c ⟶ d)) (h₂ : ∀ {d : D} {c : C} (s s' : F.obj c ⟶ d),
∃ (c' : C) (t : c' ⟶ c), F.map t ≫ s = F.map t ≫ s') : Functor.Initial F := by
suffices ∀ d, IsCofiltered (CostructuredArrow F d) from
initial_of_isCofiltered_costructuredArrow F
exact isCofiltered_costructuredArrow_of_isCofiltered_of_exists F h₁ h₂
| Mathlib/CategoryTheory/Filtered/Final.lean | 108 | 117 |
/-
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.Fintype.EquivFin
import Mathlib.Data.List.MinMax
import Mathlib.Data.Nat.Order.Lemmas
import Mathlib.Logic.Encodable.Basic
/-!
# Denumerable types
This file defines denumerable (countably infinite) types as a typeclass extending `Encodable`. This
is used to provide explicit encode/decode functions from and to `ℕ`, with the information that those
functions are inverses of each other.
## Implementation notes
This property already has a name, namely `α ≃ ℕ`, but here we are interested in using it as a
typeclass.
-/
assert_not_exists Monoid
variable {α β : Type*}
/-- A denumerable type is (constructively) bijective with `ℕ`. Typeclass equivalent of `α ≃ ℕ`. -/
class Denumerable (α : Type*) extends Encodable α where
/-- `decode` and `encode` are inverses. -/
decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n
open Finset Nat
namespace Denumerable
section
variable [Denumerable α] [Denumerable β]
open Encodable
theorem decode_isSome (α) [Denumerable α] (n : ℕ) : (decode (α := α) n).isSome :=
Option.isSome_iff_exists.2 <| (decode_inv n).imp fun _ => And.left
/-- Returns the `n`-th element of `α` indexed by the decoding. -/
def ofNat (α) [Denumerable α] (n : ℕ) : α :=
Option.get _ (decode_isSome α n)
@[simp]
theorem decode_eq_ofNat (α) [Denumerable α] (n : ℕ) : decode (α := α) n = some (ofNat α n) :=
Option.eq_some_of_isSome _
@[simp]
theorem ofNat_of_decode {n b} (h : decode (α := α) n = some b) : ofNat (α := α) n = b :=
Option.some.inj <| (decode_eq_ofNat _ _).symm.trans h
@[simp]
theorem encode_ofNat (n) : encode (ofNat α n) = n := by
obtain ⟨a, h, e⟩ := decode_inv (α := α) n
rwa [ofNat_of_decode h]
@[simp]
theorem ofNat_encode (a) : ofNat α (encode a) = a :=
ofNat_of_decode (encodek _)
/-- A denumerable type is equivalent to `ℕ`. -/
def eqv (α) [Denumerable α] : α ≃ ℕ :=
⟨encode, ofNat α, ofNat_encode, encode_ofNat⟩
-- See Note [lower instance priority]
instance (priority := 100) : Infinite α :=
Infinite.of_surjective _ (eqv α).surjective
/-- A type equivalent to `ℕ` is denumerable. -/
def mk' {α} (e : α ≃ ℕ) : Denumerable α where
encode := e
decode := some ∘ e.symm
encodek _ := congr_arg some (e.symm_apply_apply _)
decode_inv _ := ⟨_, rfl, e.apply_symm_apply _⟩
/-- Denumerability is conserved by equivalences. This is transitivity of equivalence the denumerable
way. -/
def ofEquiv (α) {β} [Denumerable α] (e : β ≃ α) : Denumerable β :=
{ Encodable.ofEquiv _ e with
decode_inv := fun n => by
simp [decode_ofEquiv, encode_ofEquiv] }
@[simp]
theorem ofEquiv_ofNat (α) {β} [Denumerable α] (e : β ≃ α) (n) :
@ofNat β (ofEquiv _ e) n = e.symm (ofNat α n) := by
letI := ofEquiv _ e
refine ofNat_of_decode ?_
rw [decode_ofEquiv e]
simp
/-- All denumerable types are equivalent. -/
def equiv₂ (α β) [Denumerable α] [Denumerable β] : α ≃ β :=
(eqv α).trans (eqv β).symm
instance nat : Denumerable ℕ :=
⟨fun _ => ⟨_, rfl, rfl⟩⟩
@[simp]
theorem ofNat_nat (n) : ofNat ℕ n = n :=
rfl
/-- If `α` is denumerable, then so is `Option α`. -/
instance option : Denumerable (Option α) :=
⟨fun n => by
cases n with
| zero =>
refine ⟨none, ?_, encode_none⟩
rw [decode_option_zero, Option.mem_def]
| succ n =>
refine ⟨some (ofNat α n), ?_, ?_⟩
· rw [decode_option_succ, decode_eq_ofNat, Option.map_some', Option.mem_def]
rw [encode_some, encode_ofNat]⟩
/-- If `α` and `β` are denumerable, then so is their sum. -/
instance sum : Denumerable (α ⊕ β) :=
⟨fun n => by
suffices ∃ a ∈ @decodeSum α β _ _ n, encodeSum a = bit (bodd n) (div2 n) by simpa [bit_decomp]
simp only [decodeSum, boddDiv2_eq, decode_eq_ofNat, Option.some.injEq, Option.map_some',
Option.mem_def, Sum.exists]
cases bodd n <;> simp [decodeSum, bit, encodeSum, Nat.two_mul]⟩
section Sigma
variable {γ : α → Type*} [∀ a, Denumerable (γ a)]
/-- A denumerable collection of denumerable types is denumerable. -/
instance sigma : Denumerable (Sigma γ) :=
⟨fun n => by simp [decodeSigma]⟩
@[simp]
theorem sigma_ofNat_val (n : ℕ) :
ofNat (Sigma γ) n = ⟨ofNat α (unpair n).1, ofNat (γ _) (unpair n).2⟩ :=
Option.some.inj <| by rw [← decode_eq_ofNat, decode_sigma_val]; simp
end Sigma
/-- If `α` and `β` are denumerable, then so is their product. -/
instance prod : Denumerable (α × β) :=
ofEquiv _ (Equiv.sigmaEquivProd α β).symm
theorem prod_ofNat_val (n : ℕ) :
ofNat (α × β) n = (ofNat α (unpair n).1, ofNat β (unpair n).2) := by simp
@[simp]
theorem prod_nat_ofNat : ofNat (ℕ × ℕ) = unpair := by funext; simp
instance int : Denumerable ℤ :=
Denumerable.mk' Equiv.intEquivNat
instance pnat : Denumerable ℕ+ :=
Denumerable.mk' Equiv.pnatEquivNat
/-- The lift of a denumerable type is denumerable. -/
instance ulift : Denumerable (ULift α) :=
ofEquiv _ Equiv.ulift
/-- The lift of a denumerable type is denumerable. -/
instance plift : Denumerable (PLift α) :=
ofEquiv _ Equiv.plift
/-- If `α` is denumerable, then `α × α` and `α` are equivalent. -/
def pair : α × α ≃ α :=
equiv₂ _ _
end
end Denumerable
namespace Nat.Subtype
open Function Encodable
/-! ### Subsets of `ℕ` -/
variable {s : Set ℕ} [Infinite s]
section Classical
theorem exists_succ (x : s) : ∃ n, (x : ℕ) + n + 1 ∈ s := by
by_contra h
have (a : ℕ) (ha : a ∈ s) : a < x + 1 :=
lt_of_not_ge fun hax => h ⟨a - (x + 1), by rwa [Nat.add_right_comm, Nat.add_sub_cancel' hax]⟩
classical
exact Fintype.false
⟨(((Multiset.range (succ x)).filter (· ∈ s)).pmap
(fun (y : ℕ) (hy : y ∈ s) => Subtype.mk y hy) (by simp [-Multiset.range_succ])).toFinset,
by simpa [Subtype.ext_iff_val, Multiset.mem_filter, -Multiset.range_succ] ⟩
end Classical
variable [DecidablePred (· ∈ s)]
/-- Returns the next natural in a set, according to the usual ordering of `ℕ`. -/
def succ (x : s) : s :=
have h : ∃ m, (x : ℕ) + m + 1 ∈ s := exists_succ x
⟨↑x + Nat.find h + 1, Nat.find_spec h⟩
theorem succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x :=
have hx : ∃ m, (y : ℕ) + m + 1 ∈ s := exists_succ _
let ⟨k, hk⟩ := Nat.exists_eq_add_of_lt h
have : Nat.find hx ≤ k := Nat.find_min' _ (hk ▸ x.2)
show (y : ℕ) + Nat.find hx + 1 ≤ x by omega
theorem le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y :=
have hx : ∃ m, (y : ℕ) + m + 1 ∈ s := exists_succ _
show (x : ℕ) ≤ (y : ℕ) + Nat.find hx + 1 from
le_of_not_gt fun hxy =>
(h ⟨_, Nat.find_spec hx⟩ hxy).not_lt <|
(by omega : (y : ℕ) < (y : ℕ) + Nat.find hx + 1)
theorem lt_succ_self (x : s) : x < succ x :=
calc
(x : ℕ) ≤ (x + _) := le_add_right ..
_ < (succ x) := Nat.lt_succ_self (x + _)
theorem lt_succ_iff_le {x y : s} : x < succ y ↔ x ≤ y :=
⟨fun h => le_of_not_gt fun h' => not_le_of_gt h (succ_le_of_lt h'), fun h =>
lt_of_le_of_lt h (lt_succ_self _)⟩
/-- Returns the `n`-th element of a set, according to the usual ordering of `ℕ`. -/
def ofNat (s : Set ℕ) [DecidablePred (· ∈ s)] [Infinite s] : ℕ → s
| 0 => ⊥
| n + 1 => succ (ofNat s n)
theorem ofNat_surjective : Surjective (ofNat s)
| ⟨x, hx⟩ => by
set t : List s :=
((List.range x).filter fun y => y ∈ s).pmap
(fun (y : ℕ) (hy : y ∈ s) => ⟨y, hy⟩)
(by intros a ha; simpa using (List.mem_filter.mp ha).2) with ht
have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
simp [List.mem_filter, Subtype.ext_iff_val, ht]
cases hmax : List.maximum t with
| bot =>
refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (a := (⊥ : s)) ?_)⟩
rwa [← List.maximum_eq_bot.1 hmax, hmt]
| | coe m =>
have wf : ↑m < x := by simpa using hmt.mp (List.maximum_mem hmax)
rcases ofNat_surjective m with ⟨a, rfl⟩
refine ⟨a + 1, le_antisymm (succ_le_of_lt wf) ?_⟩
exact le_succ_of_forall_lt_le fun z hz => List.le_maximum_of_mem (hmt.2 hz) hmax
| Mathlib/Logic/Denumerable.lean | 243 | 247 |
/-
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)
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 180 | 184 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Group.End
import Mathlib.Data.Set.Function
/-!
# Fixed points of a self-map
In this file we define
* the predicate `IsFixedPt f x := f x = x`;
* the set `fixedPoints f` of fixed points of a self-map `f`.
We also prove some simple lemmas about `IsFixedPt` and `∘`, `iterate`, and `Semiconj`.
## Tags
fixed point
-/
open Equiv
universe u v
variable {α : Type u} {β : Type v} {f fa g : α → α} {x : α} {fb : β → β} {e : Perm α}
namespace Function
open Function (Commute)
/-- Every point is a fixed point of `id`. -/
theorem isFixedPt_id (x : α) : IsFixedPt id x :=
(rfl :)
/-- A function fixes every point iff it is the identity. -/
@[simp] theorem forall_isFixedPt_iff : (∀ x, IsFixedPt f x) ↔ f = id :=
⟨funext, fun h ↦ h ▸ isFixedPt_id⟩
namespace IsFixedPt
instance decidable [h : DecidableEq α] {f : α → α} {x : α} : Decidable (IsFixedPt f x) :=
h (f x) x
/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`. -/
protected theorem eq (hf : IsFixedPt f x) : f x = x :=
hf
/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f ∘ g`. -/
protected theorem comp (hf : IsFixedPt f x) (hg : IsFixedPt g x) : IsFixedPt (f ∘ g) x :=
calc
f (g x) = f x := congr_arg f hg
_ = x := hf
/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/
protected theorem iterate (hf : IsFixedPt f x) (n : ℕ) : IsFixedPt f^[n] x :=
iterate_fixed hf n
/-- If `x` is a fixed point of `f ∘ g` and `g`, then it is a fixed point of `f`. -/
theorem left_of_comp (hfg : IsFixedPt (f ∘ g) x) (hg : IsFixedPt g x) : IsFixedPt f x :=
calc
f x = f (g x) := congr_arg f hg.symm
_ = x := hfg
/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed
point of `g`. -/
theorem to_leftInverse (hf : IsFixedPt f x) (h : LeftInverse g f) : IsFixedPt g x :=
calc
g x = g (f x) := congr_arg g hf.symm
_ = x := h x
/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points
of `fb`. -/
protected theorem map {x : α} (hx : IsFixedPt fa x) {g : α → β} (h : Semiconj g fa fb) :
IsFixedPt fb (g x) :=
calc
fb (g x) = g (fa x) := (h.eq x).symm
_ = g x := congr_arg g hx
protected theorem apply {x : α} (hx : IsFixedPt f x) : IsFixedPt f (f x) := by convert hx
theorem preimage_iterate {s : Set α} (h : IsFixedPt (Set.preimage f) s) (n : ℕ) :
IsFixedPt (Set.preimage f^[n]) s := by
rw [Set.preimage_iterate_eq]
exact h.iterate n
lemma image_iterate {s : Set α} (h : IsFixedPt (Set.image f) s) (n : ℕ) :
IsFixedPt (Set.image f^[n]) s :=
Set.image_iterate_eq ▸ h.iterate n
protected theorem equiv_symm (h : IsFixedPt e x) : IsFixedPt e.symm x :=
h.to_leftInverse e.leftInverse_symm
protected theorem perm_inv (h : IsFixedPt e x) : IsFixedPt (⇑e⁻¹) x :=
h.equiv_symm
protected theorem perm_pow (h : IsFixedPt e x) (n : ℕ) : IsFixedPt (⇑(e ^ n)) x := h.iterate _
protected theorem perm_zpow (h : IsFixedPt e x) : ∀ n : ℤ, IsFixedPt (⇑(e ^ n)) x
| Int.ofNat _ => h.perm_pow _
| Int.negSucc n => (h.perm_pow <| n + 1).perm_inv
end IsFixedPt
@[simp]
theorem Injective.isFixedPt_apply_iff (hf : Injective f) {x : α} :
IsFixedPt f (f x) ↔ IsFixedPt f x :=
⟨fun h => hf h.eq, IsFixedPt.apply⟩
/-- The set of fixed points of a map `f : α → α`. -/
def fixedPoints (f : α → α) : Set α :=
{ x : α | IsFixedPt f x }
instance fixedPoints.decidable [DecidableEq α] (f : α → α) (x : α) :
Decidable (x ∈ fixedPoints f) :=
IsFixedPt.decidable
@[simp]
theorem mem_fixedPoints : x ∈ fixedPoints f ↔ IsFixedPt f x :=
Iff.rfl
theorem mem_fixedPoints_iff {α : Type*} {f : α → α} {x : α} : x ∈ fixedPoints f ↔ f x = x := by
rfl
@[simp]
theorem fixedPoints_id : fixedPoints (@id α) = Set.univ :=
Set.ext fun _ => by simpa using isFixedPt_id _
theorem fixedPoints_subset_range : fixedPoints f ⊆ Set.range f := fun x hx => ⟨x, hx⟩
/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points
of `fb`. -/
theorem Semiconj.mapsTo_fixedPoints {g : α → β} (h : Semiconj g fa fb) :
Set.MapsTo g (fixedPoints fa) (fixedPoints fb) := fun _ hx => hx.map h
/-- Any two maps `f : α → β` and `g : β → α` are inverse of each other on the sets of fixed points
of `f ∘ g` and `g ∘ f`, respectively. -/
theorem invOn_fixedPoints_comp (f : α → β) (g : β → α) :
Set.InvOn f g (fixedPoints <| f ∘ g) (fixedPoints <| g ∘ f) :=
⟨fun _ => id, fun _ => id⟩
/-- Any map `f` sends fixed points of `g ∘ f` to fixed points of `f ∘ g`. -/
theorem mapsTo_fixedPoints_comp (f : α → β) (g : β → α) :
Set.MapsTo f (fixedPoints <| g ∘ f) (fixedPoints <| f ∘ g) := fun _ hx => hx.map fun _ => rfl
/-- Given two maps `f : α → β` and `g : β → α`, `g` is a bijective map between the fixed points
of `f ∘ g` and the fixed points of `g ∘ f`. The inverse map is `f`, see `invOn_fixedPoints_comp`. -/
theorem bijOn_fixedPoints_comp (f : α → β) (g : β → α) :
Set.BijOn g (fixedPoints <| f ∘ g) (fixedPoints <| g ∘ f) :=
(invOn_fixedPoints_comp f g).bijOn (mapsTo_fixedPoints_comp g f) (mapsTo_fixedPoints_comp f g)
/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points
of `f ∘ g`. This is a particular case of `Function.invOn_fixedPoints_comp`. -/
theorem Commute.invOn_fixedPoints_comp (h : Commute f g) :
Set.InvOn f g (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using Function.invOn_fixedPoints_comp f g
/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f ∘ g`.
This is a particular case of `Function.bijOn_fixedPoints_comp`. -/
theorem Commute.left_bijOn_fixedPoints_comp (h : Commute f g) :
Set.BijOn f (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using bijOn_fixedPoints_comp g f
/-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f ∘ g`.
This is a particular case of `Function.bijOn_fixedPoints_comp`. -/
theorem Commute.right_bijOn_fixedPoints_comp (h : Commute f g) :
Set.BijOn g (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using bijOn_fixedPoints_comp f g
end Function
| Mathlib/Dynamics/FixedPoints/Basic.lean | 192 | 194 | |
/-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed
import Mathlib.RingTheory.PowerBasis
/-!
# A predicate on adjoining roots of polynomial
This file defines a predicate `IsAdjoinRoot S f`, which states that the ring `S` can be
constructed by adjoining a specified root of the polynomial `f : R[X]` to `R`.
This predicate is useful when the same ring can be generated by adjoining the root of different
polynomials, and you want to vary which polynomial you're considering.
The results in this file are intended to mirror those in `RingTheory.AdjoinRoot`,
in order to provide an easier way to translate results from one to the other.
## Motivation
`AdjoinRoot` presents one construction of a ring `R[α]`. However, it is possible to obtain
rings of this form in many ways, such as `NumberField.ringOfIntegers ℚ(√-5)`,
or `Algebra.adjoin R {α, α^2}`, or `IntermediateField.adjoin R {α, 2 - α}`,
or even if we want to view `ℂ` as adjoining a root of `X^2 + 1` to `ℝ`.
## Main definitions
The two main predicates in this file are:
* `IsAdjoinRoot S f`: `S` is generated by adjoining a specified root of `f : R[X]` to `R`
* `IsAdjoinRootMonic S f`: `S` is generated by adjoining a root of the monic polynomial
`f : R[X]` to `R`
Using `IsAdjoinRoot` to map into `S`:
* `IsAdjoinRoot.map`: inclusion from `R[X]` to `S`
* `IsAdjoinRoot.root`: the specific root adjoined to `R` to give `S`
Using `IsAdjoinRoot` to map out of `S`:
* `IsAdjoinRoot.repr`: choose a non-unique representative in `R[X]`
* `IsAdjoinRoot.lift`, `IsAdjoinRoot.liftHom`: lift a morphism `R →+* T` to `S →+* T`
* `IsAdjoinRootMonic.modByMonicHom`: a unique representative in `R[X]` if `f` is monic
## Main results
* `AdjoinRoot.isAdjoinRoot` and `AdjoinRoot.isAdjoinRootMonic`:
`AdjoinRoot` satisfies the conditions on `IsAdjoinRoot`(`_monic`)
* `IsAdjoinRootMonic.powerBasis`: the `root` generates a power basis on `S` over `R`
* `IsAdjoinRoot.aequiv`: algebra isomorphism showing adjoining a root gives a unique ring
up to isomorphism
* `IsAdjoinRoot.ofEquiv`: transfer `IsAdjoinRoot` across an algebra isomorphism
* `IsAdjoinRootMonic.minpoly_eq`: the minimal polynomial of the adjoined root of `f` is equal to
`f`, if `f` is irreducible and monic, and `R` is a GCD domain
-/
open scoped Polynomial
open Polynomial
noncomputable section
universe u v
-- Porting note: this looks like something that should not be here
-- section MoveMe
--
-- end MoveMe
-- This class doesn't really make sense on a predicate
/-- `IsAdjoinRoot S f` states that the ring `S` can be constructed by adjoining a specified root
of the polynomial `f : R[X]` to `R`.
Compare `PowerBasis R S`, which does not explicitly specify which polynomial we adjoin a root of
(in particular `f` does not need to be the minimal polynomial of the root we adjoin),
and `AdjoinRoot` which constructs a new type.
This is not a typeclass because the choice of root given `S` and `f` is not unique.
-/
structure IsAdjoinRoot {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S]
(f : R[X]) : Type max u v where
map : R[X] →+* S
map_surjective : Function.Surjective map
ker_map : RingHom.ker map = Ideal.span {f}
algebraMap_eq : algebraMap R S = map.comp Polynomial.C
-- This class doesn't really make sense on a predicate
/-- `IsAdjoinRootMonic S f` states that the ring `S` can be constructed by adjoining a specified
root of the monic polynomial `f : R[X]` to `R`.
As long as `f` is monic, there is a well-defined representation of elements of `S` as polynomials
in `R[X]` of degree lower than `deg f` (see `modByMonicHom` and `coeff`). In particular,
we have `IsAdjoinRootMonic.powerBasis`.
Bundling `Monic` into this structure is very useful when working with explicit `f`s such as
`X^2 - C a * X - C b` since it saves you carrying around the proofs of monicity.
-/
-- @[nolint has_nonempty_instance] -- Porting note: This linter does not exist yet.
structure IsAdjoinRootMonic {R : Type u} (S : Type v) [CommSemiring R] [Semiring S] [Algebra R S]
(f : R[X]) extends IsAdjoinRoot S f where
Monic : Monic f
section Ring
variable {R : Type u} {S : Type v} [CommRing R] [Ring S] {f : R[X]} [Algebra R S]
namespace IsAdjoinRoot
/-- `(h : IsAdjoinRoot S f).root` is the root of `f` that can be adjoined to generate `S`. -/
def root (h : IsAdjoinRoot S f) : S :=
h.map X
theorem subsingleton (h : IsAdjoinRoot S f) [Subsingleton R] : Subsingleton S :=
h.map_surjective.subsingleton
theorem algebraMap_apply (h : IsAdjoinRoot S f) (x : R) :
algebraMap R S x = h.map (Polynomial.C x) := by rw [h.algebraMap_eq, RingHom.comp_apply]
theorem mem_ker_map (h : IsAdjoinRoot S f) {p} : p ∈ RingHom.ker h.map ↔ f ∣ p := by
rw [h.ker_map, Ideal.mem_span_singleton]
@[simp]
theorem map_eq_zero_iff (h : IsAdjoinRoot S f) {p} : h.map p = 0 ↔ f ∣ p := by
rw [← h.mem_ker_map, RingHom.mem_ker]
@[simp]
theorem map_X (h : IsAdjoinRoot S f) : h.map X = h.root := rfl
@[simp]
theorem map_self (h : IsAdjoinRoot S f) : h.map f = 0 := h.map_eq_zero_iff.mpr dvd_rfl
@[simp]
theorem aeval_eq (h : IsAdjoinRoot S f) (p : R[X]) : aeval h.root p = h.map p :=
Polynomial.induction_on p (fun x => by rw [aeval_C, h.algebraMap_apply])
(fun p q ihp ihq => by rw [map_add, RingHom.map_add, ihp, ihq]) fun n x _ => by
rw [map_mul, aeval_C, map_pow, aeval_X, RingHom.map_mul, ← h.algebraMap_apply,
RingHom.map_pow, map_X]
theorem aeval_root (h : IsAdjoinRoot S f) : aeval h.root f = 0 := by rw [aeval_eq, map_self]
/-- Choose an arbitrary representative so that `h.map (h.repr x) = x`.
If `f` is monic, use `IsAdjoinRootMonic.modByMonicHom` for a unique choice of representative.
-/
def repr (h : IsAdjoinRoot S f) (x : S) : R[X] :=
(h.map_surjective x).choose
theorem map_repr (h : IsAdjoinRoot S f) (x : S) : h.map (h.repr x) = x :=
(h.map_surjective x).choose_spec
/-- `repr` preserves zero, up to multiples of `f` -/
theorem repr_zero_mem_span (h : IsAdjoinRoot S f) : h.repr 0 ∈ Ideal.span ({f} : Set R[X]) := by
rw [← h.ker_map, RingHom.mem_ker, h.map_repr]
/-- `repr` preserves addition, up to multiples of `f` -/
theorem repr_add_sub_repr_add_repr_mem_span (h : IsAdjoinRoot S f) (x y : S) :
h.repr (x + y) - (h.repr x + h.repr y) ∈ Ideal.span ({f} : Set R[X]) := by
rw [← h.ker_map, RingHom.mem_ker, map_sub, h.map_repr, map_add, h.map_repr, h.map_repr, sub_self]
/-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem`
for extensionality of the ring elements. -/
theorem ext_map (h h' : IsAdjoinRoot S f) (eq : ∀ x, h.map x = h'.map x) : h = h' := by
cases h; cases h'; congr
exact RingHom.ext eq
/-- Extensionality of the `IsAdjoinRoot` structure itself. See `IsAdjoinRootMonic.ext_elem`
for extensionality of the ring elements. -/
@[ext]
theorem ext (h h' : IsAdjoinRoot S f) (eq : h.root = h'.root) : h = h' :=
h.ext_map h' fun x => by rw [← h.aeval_eq, ← h'.aeval_eq, eq]
section lift
variable {T : Type*} [CommRing T] {i : R →+* T} {x : T}
section
variable (hx : f.eval₂ i x = 0)
include hx
/-- Auxiliary lemma for `IsAdjoinRoot.lift` -/
theorem eval₂_repr_eq_eval₂_of_map_eq (h : IsAdjoinRoot S f) (z : S) (w : R[X])
(hzw : h.map w = z) : (h.repr z).eval₂ i x = w.eval₂ i x := by
rw [eq_comm, ← sub_eq_zero, ← h.map_repr z, ← map_sub, h.map_eq_zero_iff] at hzw
obtain ⟨y, hy⟩ := hzw
rw [← sub_eq_zero, ← eval₂_sub, hy, eval₂_mul, hx, zero_mul]
variable (i x)
-- To match `AdjoinRoot.lift`
/-- Lift a ring homomorphism `R →+* T` to `S →+* T` by specifying a root `x` of `f` in `T`,
where `S` is given by adjoining a root of `f` to `R`. -/
def lift (h : IsAdjoinRoot S f) (hx : f.eval₂ i x = 0) : S →+* T where
toFun z := (h.repr z).eval₂ i x
map_zero' := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_zero _), eval₂_zero]
map_add' z w := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z + h.repr w), eval₂_add]
rw [map_add, map_repr, map_repr]
map_one' := by
| rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ _ (map_one _), eval₂_one]
map_mul' z w := by
rw [h.eval₂_repr_eq_eval₂_of_map_eq hx _ (h.repr z * h.repr w), eval₂_mul]
rw [map_mul, map_repr, map_repr]
| Mathlib/RingTheory/IsAdjoinRoot.lean | 203 | 207 |
/-
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.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Data.Int.AbsoluteValue
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
/-!
# Absolute values and matrices
This file proves some bounds on matrices involving absolute values.
## Main results
* `Matrix.det_le`: if the entries of an `n × n` matrix are bounded by `x`,
then the determinant is bounded by `n! x^n`
* `Matrix.det_sum_le`: if we have `s` `n × n` matrices and the entries of each
matrix are bounded by `x`, then the determinant of their sum is bounded by `n! (s * x)^n`
* `Matrix.det_sum_smul_le`: if we have `s` `n × n` matrices each multiplied by
a constant bounded by `y`, and the entries of each matrix are bounded by `x`,
then the determinant of the linear combination is bounded by `n! (s * y * x)^n`
-/
open Matrix
namespace Matrix
open Equiv Finset
variable {R S : Type*} [CommRing R] [Nontrivial R]
[CommRing S] [LinearOrder S] [IsStrictOrderedRing S]
variable {n : Type*} [Fintype n] [DecidableEq n]
theorem det_le {A : Matrix n n R} {abv : AbsoluteValue R S} {x : S} (hx : ∀ i j, abv (A i j) ≤ x) :
abv A.det ≤ Nat.factorial (Fintype.card n) • x ^ Fintype.card n :=
calc
abv A.det = abv (∑ σ : Perm n, Perm.sign σ • ∏ i, A (σ i) i) := congr_arg abv (det_apply _)
_ ≤ ∑ σ : Perm n, abv (Perm.sign σ • ∏ i, A (σ i) i) := abv.sum_le _ _
_ = ∑ σ : Perm n, ∏ i, abv (A (σ i) i) :=
(sum_congr rfl fun σ _ => by rw [abv.map_units_int_smul, abv.map_prod])
_ ≤ ∑ _σ : Perm n, ∏ _i : n, x :=
(sum_le_sum fun _ _ => prod_le_prod (fun _ _ => abv.nonneg _) fun _ _ => hx _ _)
_ = ∑ _σ : Perm n, x ^ Fintype.card n :=
(sum_congr rfl fun _ _ => by rw [prod_const, Finset.card_univ])
_ = Nat.factorial (Fintype.card n) • x ^ Fintype.card n := by
rw [sum_const, Finset.card_univ, Fintype.card_perm]
theorem det_sum_le {ι : Type*} (s : Finset ι) {A : ι → Matrix n n R} {abv : AbsoluteValue R S}
{x : S} (hx : ∀ k i j, abv (A k i j) ≤ x) :
abv (det (∑ k ∈ s, A k)) ≤
Nat.factorial (Fintype.card n) • (#s• x) ^ Fintype.card n :=
det_le fun i j =>
calc
abv ((∑ k ∈ s, A k) i j) = abv (∑ k ∈ s, A k i j) := by simp only [sum_apply]
_ ≤ ∑ k ∈ s, abv (A k i j) := abv.sum_le _ _
_ ≤ ∑ _k ∈ s, x := sum_le_sum fun k _ => hx k i j
_ = #s • x := sum_const _
theorem det_sum_smul_le {ι : Type*} (s : Finset ι) {c : ι → R} {A : ι → Matrix n n R}
{abv : AbsoluteValue R S} {x : S} (hx : ∀ k i j, abv (A k i j) ≤ x) {y : S}
| (hy : ∀ k, abv (c k) ≤ y) :
abv (det (∑ k ∈ s, c k • A k)) ≤
Nat.factorial (Fintype.card n) • (#s • y * x) ^ Fintype.card n := by
simpa only [smul_mul_assoc] using
det_sum_le s fun k i j =>
calc
abv (c k * A k i j) = abv (c k) * abv (A k i j) := abv.map_mul _ _
_ ≤ y * x := mul_le_mul (hy k) (hx k i j) (abv.nonneg _) ((abv.nonneg _).trans (hy k))
end Matrix
| Mathlib/LinearAlgebra/Matrix/AbsoluteValue.lean | 64 | 73 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.MeasureTheory.Function.SimpleFuncDense
/-!
# Strongly measurable and finitely strongly measurable functions
A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions.
It is said to be finitely strongly measurable with respect to a measure `μ` if the supports
of those simple functions have finite measure.
If the target space has a second countable topology, strongly measurable and measurable are
equivalent.
If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent.
The main property of finitely strongly measurable functions is
`FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the
function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some
results for those functions as if the measure was sigma-finite.
We provide a solid API for strongly measurable functions, as a basis for the Bochner integral.
## Main definitions
* `StronglyMeasurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`.
* `FinStronglyMeasurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`
such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite.
## References
* [Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces.
Springer, 2016.][Hytonen_VanNeerven_Veraar_Wies_2016]
-/
-- Guard against import creep
assert_not_exists InnerProductSpace
open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure
open ENNReal Topology MeasureTheory NNReal
variable {α β γ ι : Type*} [Countable ι]
namespace MeasureTheory
local infixr:25 " →ₛ " => SimpleFunc
section Definitions
variable [TopologicalSpace β]
/-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/
def StronglyMeasurable [MeasurableSpace α] (f : α → β) : Prop :=
∃ fs : ℕ → α →ₛ β, ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))
/-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/
scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m
/-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple
functions with support with finite measure. -/
def FinStronglyMeasurable [Zero β]
{_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop :=
∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))
end Definitions
open MeasureTheory
/-! ## Strongly measurable functions -/
section StronglyMeasurable
variable {_ : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : ℕ → α} {m : ℕ}
variable [TopologicalSpace β]
theorem SimpleFunc.stronglyMeasurable (f : α →ₛ β) : StronglyMeasurable f :=
⟨fun _ => f, fun _ => tendsto_const_nhds⟩
@[simp, nontriviality]
lemma StronglyMeasurable.of_subsingleton_dom [Subsingleton α] : StronglyMeasurable f :=
⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩
@[simp, nontriviality]
lemma StronglyMeasurable.of_subsingleton_cod [Subsingleton β] : StronglyMeasurable f := by
let f_sf : α →ₛ β := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩
· exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩
· simp [Set.preimage, eq_iff_true_of_subsingleton]
@[deprecated StronglyMeasurable.of_subsingleton_cod (since := "2025-04-09")]
lemma Subsingleton.stronglyMeasurable [Subsingleton β] (f : α → β) : StronglyMeasurable f :=
.of_subsingleton_cod
@[deprecated StronglyMeasurable.of_subsingleton_dom (since := "2025-04-09")]
lemma Subsingleton.stronglyMeasurable' [Subsingleton α] (f : α → β) : StronglyMeasurable f :=
.of_subsingleton_dom
theorem stronglyMeasurable_const {b : β} : StronglyMeasurable fun _ : α => b :=
⟨fun _ => SimpleFunc.const α b, fun _ => tendsto_const_nhds⟩
@[to_additive]
theorem stronglyMeasurable_one [One β] : StronglyMeasurable (1 : α → β) := stronglyMeasurable_const
/-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`.
This version works for functions between empty types. -/
theorem stronglyMeasurable_const' (hf : ∀ x y, f x = f y) : StronglyMeasurable f := by
nontriviality α
inhabit α
convert stronglyMeasurable_const (β := β) using 1
exact funext fun x => hf x default
variable [MeasurableSingletonClass α]
section aux
omit [TopologicalSpace β]
/-- Auxiliary definition for `StronglyMeasurable.of_discrete`. -/
private noncomputable def simpleFuncAux (f : α → β) (g : ℕ → α) : ℕ → SimpleFunc α β
| 0 => .const _ (f (g 0))
| n + 1 => .piecewise {g n} (.singleton _) (.const _ <| f (g n)) (simpleFuncAux f g n)
private lemma simpleFuncAux_eq_of_lt : ∀ n > m, simpleFuncAux f g n (g m) = f (g m)
| _, .refl => by simp [simpleFuncAux]
| _, Nat.le.step (m := n) hmn => by
obtain hnm | hnm := eq_or_ne (g n) (g m) <;>
simp [simpleFuncAux, Set.piecewise_eq_of_not_mem , hnm.symm, simpleFuncAux_eq_of_lt _ hmn]
private lemma simpleFuncAux_eventuallyEq : ∀ᶠ n in atTop, simpleFuncAux f g n (g m) = f (g m) :=
eventually_atTop.2 ⟨_, simpleFuncAux_eq_of_lt⟩
end aux
lemma StronglyMeasurable.of_discrete [Countable α] : StronglyMeasurable f := by
nontriviality α
nontriviality β
obtain ⟨g, hg⟩ := exists_surjective_nat α
exact ⟨simpleFuncAux f g, hg.forall.2 fun m ↦
tendsto_nhds_of_eventually_eq simpleFuncAux_eventuallyEq⟩
@[deprecated StronglyMeasurable.of_discrete (since := "2025-04-09")]
theorem StronglyMeasurable.of_finite [Finite α] : StronglyMeasurable f := .of_discrete
end StronglyMeasurable
namespace StronglyMeasurable
variable {f g : α → β}
section BasicPropertiesInAnyTopologicalSpace
variable [TopologicalSpace β]
/-- A sequence of simple functions such that
`∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x))`.
That property is given by `stronglyMeasurable.tendsto_approx`. -/
protected noncomputable def approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) :
ℕ → α →ₛ β :=
hf.choose
protected theorem tendsto_approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) :
∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) :=
hf.choose_spec
/-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the
sequence is less than `c` everywhere. If `‖f x‖ ≤ c` this sequence of simple functions verifies
`Tendsto (fun n => hf.approxBounded n x) atTop (𝓝 (f x))`. -/
noncomputable def approxBounded {_ : MeasurableSpace α} [Norm β] [SMul ℝ β]
(hf : StronglyMeasurable f) (c : ℝ) : ℕ → SimpleFunc α β := fun n =>
(hf.approx n).map fun x => min 1 (c / ‖x‖) • x
theorem tendsto_approxBounded_of_norm_le {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β]
{m : MeasurableSpace α} (hf : StronglyMeasurable[m] f) {c : ℝ} {x : α} (hfx : ‖f x‖ ≤ c) :
Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by
have h_tendsto := hf.tendsto_approx x
simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply]
by_cases hfx0 : ‖f x‖ = 0
· rw [norm_eq_zero] at hfx0
rw [hfx0] at h_tendsto ⊢
have h_tendsto_norm : Tendsto (fun n => ‖hf.approx n x‖) atTop (𝓝 0) := by
convert h_tendsto.norm
rw [norm_zero]
refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm
calc
‖min 1 (c / ‖hf.approx n x‖) • hf.approx n x‖ =
‖min 1 (c / ‖hf.approx n x‖)‖ * ‖hf.approx n x‖ :=
norm_smul _ _
_ ≤ ‖(1 : ℝ)‖ * ‖hf.approx n x‖ := by
refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)
rw [norm_one, Real.norm_of_nonneg]
· exact min_le_left _ _
· exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _))
_ = ‖hf.approx n x‖ := by rw [norm_one, one_mul]
rw [← one_smul ℝ (f x)]
refine Tendsto.smul ?_ h_tendsto
have : min 1 (c / ‖f x‖) = 1 := by
rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))]
exact hfx
nth_rw 2 [this.symm]
refine Tendsto.min tendsto_const_nhds ?_
exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0
theorem tendsto_approxBounded_ae {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β]
{m m0 : MeasurableSpace α} {μ : Measure α} (hf : StronglyMeasurable[m] f) {c : ℝ}
(hf_bound : ∀ᵐ x ∂μ, ‖f x‖ ≤ c) :
∀ᵐ x ∂μ, Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by
filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx
theorem norm_approxBounded_le {β} {f : α → β} [SeminormedAddCommGroup β] [NormedSpace ℝ β]
{m : MeasurableSpace α} {c : ℝ} (hf : StronglyMeasurable[m] f) (hc : 0 ≤ c) (n : ℕ) (x : α) :
‖hf.approxBounded c n x‖ ≤ c := by
simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply]
refine (norm_smul_le _ _).trans ?_
by_cases h0 : ‖hf.approx n x‖ = 0
· simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero]
exact hc
rcases le_total ‖hf.approx n x‖ c with h | h
· rw [min_eq_left _]
· simpa only [norm_one, one_mul] using h
· rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))]
· rw [min_eq_right _]
· rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc,
inv_mul_cancel₀ h0, one_mul, Real.norm_of_nonneg hc]
· rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))]
theorem _root_.stronglyMeasurable_bot_iff [Nonempty β] [T2Space β] :
StronglyMeasurable[⊥] f ↔ ∃ c, f = fun _ => c := by
rcases isEmpty_or_nonempty α with hα | hα
· simp [eq_iff_true_of_subsingleton]
refine ⟨fun hf => ?_, fun hf_eq => ?_⟩
· refine ⟨f hα.some, ?_⟩
let fs := hf.approx
have h_fs_tendsto : ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) := hf.tendsto_approx
have : ∀ n, ∃ c, ∀ x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n)
let cs n := (this n).choose
have h_cs_eq : ∀ n, ⇑(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec
conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq]
have h_tendsto : Tendsto cs atTop (𝓝 (f hα.some)) := h_fs_tendsto hα.some
ext1 x
exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto
· obtain ⟨c, rfl⟩ := hf_eq
exact stronglyMeasurable_const
end BasicPropertiesInAnyTopologicalSpace
theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace β] [Zero β]
{m : MeasurableSpace α} {μ : Measure α} (hf_meas : StronglyMeasurable f) {t : Set α}
(ht : MeasurableSet t) (hft_zero : ∀ x ∈ tᶜ, f x = 0) (htμ : SigmaFinite (μ.restrict t)) :
FinStronglyMeasurable f μ := by
haveI : SigmaFinite (μ.restrict t) := htμ
let S := spanningSets (μ.restrict t)
have hS_meas : ∀ n, MeasurableSet (S n) := measurableSet_spanningSets (μ.restrict t)
let f_approx := hf_meas.approx
let fs n := SimpleFunc.restrict (f_approx n) (S n ∩ t)
have h_fs_t_compl : ∀ n, ∀ x, x ∉ t → fs n x = 0 := by
intro n x hxt
rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)]
refine Set.indicator_of_not_mem ?_ _
simp [hxt]
refine ⟨fs, ?_, fun x => ?_⟩
· simp_rw [SimpleFunc.support_eq, ← Finset.mem_coe]
classical
refine fun n => measure_biUnion_lt_top {y ∈ (fs n).range | y ≠ 0}.finite_toSet fun y hy => ?_
rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)]
swap
· letI : (y : β) → Decidable (y = 0) := fun y => Classical.propDecidable _
rw [Finset.mem_coe, Finset.mem_filter] at hy
exact hy.2
refine (measure_mono Set.inter_subset_left).trans_lt ?_
have h_lt_top := measure_spanningSets_lt_top (μ.restrict t) n
rwa [Measure.restrict_apply' ht] at h_lt_top
· by_cases hxt : x ∈ t
swap
· rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt]
exact tendsto_const_nhds
have h : Tendsto (fun n => (f_approx n) x) atTop (𝓝 (f x)) := hf_meas.tendsto_approx x
obtain ⟨n₁, hn₁⟩ : ∃ n, ∀ m, n ≤ m → fs m x = f_approx m x := by
obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m ∩ t := by
rsuffices ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m
· exact ⟨n, fun m hnm => Set.mem_inter (hn m hnm) hxt⟩
rsuffices ⟨n, hn⟩ : ∃ n, x ∈ S n
· exact ⟨n, fun m hnm => monotone_spanningSets (μ.restrict t) hnm hn⟩
rw [← Set.mem_iUnion, iUnion_spanningSets (μ.restrict t)]
trivial
refine ⟨n, fun m hnm => ?_⟩
simp_rw [fs, SimpleFunc.restrict_apply _ ((hS_meas m).inter ht),
Set.indicator_of_mem (hn m hnm)]
rw [tendsto_atTop'] at h ⊢
intro s hs
obtain ⟨n₂, hn₂⟩ := h s hs
refine ⟨max n₁ n₂, fun m hm => ?_⟩
rw [hn₁ m ((le_max_left _ _).trans hm.le)]
exact hn₂ m ((le_max_right _ _).trans hm.le)
/-- If the measure is sigma-finite, all strongly measurable functions are
`FinStronglyMeasurable`. -/
@[aesop 5% apply (rule_sets := [Measurable])]
protected theorem finStronglyMeasurable [TopologicalSpace β] [Zero β] {m0 : MeasurableSpace α}
(hf : StronglyMeasurable f) (μ : Measure α) [SigmaFinite μ] : FinStronglyMeasurable f μ :=
hf.finStronglyMeasurable_of_set_sigmaFinite MeasurableSet.univ (by simp)
(by rwa [Measure.restrict_univ])
/-- A strongly measurable function is measurable. -/
@[aesop 5% apply (rule_sets := [Measurable])]
protected theorem measurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β]
[MeasurableSpace β] [BorelSpace β] (hf : StronglyMeasurable f) : Measurable f :=
measurable_of_tendsto_metrizable (fun n => (hf.approx n).measurable)
(tendsto_pi_nhds.mpr hf.tendsto_approx)
/-- A strongly measurable function is almost everywhere measurable. -/
@[aesop 5% apply (rule_sets := [Measurable])]
protected theorem aemeasurable {_ : MeasurableSpace α} [TopologicalSpace β]
[PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {μ : Measure α}
(hf : StronglyMeasurable f) : AEMeasurable f μ :=
hf.measurable.aemeasurable
theorem _root_.Continuous.comp_stronglyMeasurable {_ : MeasurableSpace α} [TopologicalSpace β]
[TopologicalSpace γ] {g : β → γ} {f : α → β} (hg : Continuous g) (hf : StronglyMeasurable f) :
StronglyMeasurable fun x => g (f x) :=
⟨fun n => SimpleFunc.map g (hf.approx n), fun x => (hg.tendsto _).comp (hf.tendsto_approx x)⟩
@[to_additive]
nonrec theorem measurableSet_mulSupport {m : MeasurableSpace α} [One β] [TopologicalSpace β]
[MetrizableSpace β] (hf : StronglyMeasurable f) : MeasurableSet (mulSupport f) := by
borelize β
exact measurableSet_mulSupport hf.measurable
protected theorem mono {m m' : MeasurableSpace α} [TopologicalSpace β]
(hf : StronglyMeasurable[m'] f) (h_mono : m' ≤ m) : StronglyMeasurable[m] f := by
let f_approx : ℕ → @SimpleFunc α m β := fun n =>
@SimpleFunc.mk α m β
(hf.approx n)
(fun x => h_mono _ (SimpleFunc.measurableSet_fiber' _ x))
(SimpleFunc.finite_range (hf.approx n))
exact ⟨f_approx, hf.tendsto_approx⟩
protected theorem prodMk {m : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ]
{f : α → β} {g : α → γ} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) :
StronglyMeasurable fun x => (f x, g x) := by
refine ⟨fun n => SimpleFunc.pair (hf.approx n) (hg.approx n), fun x => ?_⟩
rw [nhds_prod_eq]
exact Tendsto.prodMk (hf.tendsto_approx x) (hg.tendsto_approx x)
@[deprecated (since := "2025-03-05")] protected alias prod_mk := StronglyMeasurable.prodMk
theorem comp_measurable [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ}
{f : α → β} {g : γ → α} (hf : StronglyMeasurable f) (hg : Measurable g) :
StronglyMeasurable (f ∘ g) :=
⟨fun n => SimpleFunc.comp (hf.approx n) g hg, fun x => hf.tendsto_approx (g x)⟩
theorem of_uncurry_left [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ}
{f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {x : α} : StronglyMeasurable (f x) :=
hf.comp_measurable measurable_prodMk_left
theorem of_uncurry_right [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ}
{f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {y : γ} :
StronglyMeasurable fun x => f x y :=
hf.comp_measurable measurable_prodMk_right
protected theorem prod_swap {_ : MeasurableSpace α} {_ : MeasurableSpace β} [TopologicalSpace γ]
{f : β × α → γ} (hf : StronglyMeasurable f) :
StronglyMeasurable (fun z : α × β => f z.swap) :=
hf.comp_measurable measurable_swap
protected theorem fst {_ : MeasurableSpace α} [mβ : MeasurableSpace β] [TopologicalSpace γ]
{f : α → γ} (hf : StronglyMeasurable f) :
StronglyMeasurable (fun z : α × β => f z.1) :=
hf.comp_measurable measurable_fst
protected theorem snd [mα : MeasurableSpace α] {_ : MeasurableSpace β} [TopologicalSpace γ]
{f : β → γ} (hf : StronglyMeasurable f) :
StronglyMeasurable (fun z : α × β => f z.2) :=
hf.comp_measurable measurable_snd
section Arithmetic
variable {mα : MeasurableSpace α} [TopologicalSpace β]
@[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))]
protected theorem mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f)
(hg : StronglyMeasurable g) : StronglyMeasurable (f * g) :=
⟨fun n => hf.approx n * hg.approx n, fun x => (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩
@[to_additive (attr := measurability)]
theorem mul_const [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) :
StronglyMeasurable fun x => f x * c :=
hf.mul stronglyMeasurable_const
@[to_additive (attr := measurability)]
theorem const_mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) :
StronglyMeasurable fun x => c * f x :=
stronglyMeasurable_const.mul hf
@[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable])) const_nsmul]
protected theorem pow [Monoid β] [ContinuousMul β] (hf : StronglyMeasurable f) (n : ℕ) :
StronglyMeasurable (f ^ n) :=
⟨fun k => hf.approx k ^ n, fun x => (hf.tendsto_approx x).pow n⟩
@[to_additive (attr := measurability)]
protected theorem inv [Inv β] [ContinuousInv β] (hf : StronglyMeasurable f) :
StronglyMeasurable f⁻¹ :=
⟨fun n => (hf.approx n)⁻¹, fun x => (hf.tendsto_approx x).inv⟩
@[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))]
protected theorem div [Div β] [ContinuousDiv β] (hf : StronglyMeasurable f)
(hg : StronglyMeasurable g) : StronglyMeasurable (f / g) :=
⟨fun n => hf.approx n / hg.approx n, fun x => (hf.tendsto_approx x).div' (hg.tendsto_approx x)⟩
@[to_additive]
theorem mul_iff_right [CommGroup β] [IsTopologicalGroup β] (hf : StronglyMeasurable f) :
StronglyMeasurable (f * g) ↔ StronglyMeasurable g :=
⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv,
fun h ↦ hf.mul h⟩
@[to_additive]
theorem mul_iff_left [CommGroup β] [IsTopologicalGroup β] (hf : StronglyMeasurable f) :
StronglyMeasurable (g * f) ↔ StronglyMeasurable g :=
mul_comm g f ▸ mul_iff_right hf
@[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))]
protected theorem smul {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜}
{g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) :
StronglyMeasurable fun x => f x • g x :=
continuous_smul.comp_stronglyMeasurable (hf.prodMk hg)
@[to_additive (attr := measurability)]
protected theorem const_smul {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f)
(c : 𝕜) : StronglyMeasurable (c • f) :=
⟨fun n => c • hf.approx n, fun x => (hf.tendsto_approx x).const_smul c⟩
@[to_additive (attr := measurability)]
protected theorem const_smul' {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f)
(c : 𝕜) : StronglyMeasurable fun x => c • f x :=
hf.const_smul c
@[to_additive (attr := measurability)]
protected theorem smul_const {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜}
(hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x • c :=
continuous_smul.comp_stronglyMeasurable (hf.prodMk stronglyMeasurable_const)
/-- In a normed vector space, the addition of a measurable function and a strongly measurable
function is measurable. Note that this is not true without further second-countability assumptions
for the addition of two measurable functions. -/
theorem _root_.Measurable.add_stronglyMeasurable
{α E : Type*} {_ : MeasurableSpace α} [AddCancelMonoid E] [TopologicalSpace E]
[MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E]
{g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) :
Measurable (g + f) := by
rcases hf with ⟨φ, hφ⟩
have : Tendsto (fun n x ↦ g x + φ n x) atTop (𝓝 (g + f)) :=
tendsto_pi_nhds.2 (fun x ↦ tendsto_const_nhds.add (hφ x))
apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this
exact hg.add_simpleFunc _
/-- In a normed vector space, the subtraction of a measurable function and a strongly measurable
function is measurable. Note that this is not true without further second-countability assumptions
for the subtraction of two measurable functions. -/
theorem _root_.Measurable.sub_stronglyMeasurable
{α E : Type*} {_ : MeasurableSpace α} [AddGroup E] [TopologicalSpace E]
[MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [ContinuousNeg E] [PseudoMetrizableSpace E]
{g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) :
Measurable (g - f) := by
rw [sub_eq_add_neg]
exact hg.add_stronglyMeasurable hf.neg
/-- In a normed vector space, the addition of a strongly measurable function and a measurable
function is measurable. Note that this is not true without further second-countability assumptions
for the addition of two measurable functions. -/
theorem _root_.Measurable.stronglyMeasurable_add
{α E : Type*} {_ : MeasurableSpace α} [AddCancelMonoid E] [TopologicalSpace E]
[MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E]
{g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) :
Measurable (f + g) := by
rcases hf with ⟨φ, hφ⟩
have : Tendsto (fun n x ↦ φ n x + g x) atTop (𝓝 (f + g)) :=
tendsto_pi_nhds.2 (fun x ↦ (hφ x).add tendsto_const_nhds)
apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this
exact hg.simpleFunc_add _
end Arithmetic
section MulAction
variable {M G G₀ : Type*}
variable [TopologicalSpace β]
variable [Monoid M] [MulAction M β] [ContinuousConstSMul M β]
variable [Group G] [MulAction G β] [ContinuousConstSMul G β]
variable [GroupWithZero G₀] [MulAction G₀ β] [ContinuousConstSMul G₀ β]
theorem _root_.stronglyMeasurable_const_smul_iff {m : MeasurableSpace α} (c : G) :
(StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f :=
⟨fun h => by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, fun h => h.const_smul c⟩
nonrec theorem _root_.IsUnit.stronglyMeasurable_const_smul_iff {_ : MeasurableSpace α} {c : M}
(hc : IsUnit c) :
(StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f :=
let ⟨u, hu⟩ := hc
hu ▸ stronglyMeasurable_const_smul_iff u
theorem _root_.stronglyMeasurable_const_smul_iff₀ {_ : MeasurableSpace α} {c : G₀} (hc : c ≠ 0) :
(StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f :=
(IsUnit.mk0 _ hc).stronglyMeasurable_const_smul_iff
end MulAction
section Order
variable [MeasurableSpace α] [TopologicalSpace β]
open Filter
@[aesop safe 20 (rule_sets := [Measurable])]
protected theorem sup [Max β] [ContinuousSup β] (hf : StronglyMeasurable f)
(hg : StronglyMeasurable g) : StronglyMeasurable (f ⊔ g) :=
⟨fun n => hf.approx n ⊔ hg.approx n, fun x =>
(hf.tendsto_approx x).sup_nhds (hg.tendsto_approx x)⟩
@[aesop safe 20 (rule_sets := [Measurable])]
protected theorem inf [Min β] [ContinuousInf β] (hf : StronglyMeasurable f)
(hg : StronglyMeasurable g) : StronglyMeasurable (f ⊓ g) :=
⟨fun n => hf.approx n ⊓ hg.approx n, fun x =>
(hf.tendsto_approx x).inf_nhds (hg.tendsto_approx x)⟩
end Order
/-!
### Big operators: `∏` and `∑`
-/
section Monoid
variable {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α}
@[to_additive (attr := measurability)]
theorem _root_.List.stronglyMeasurable_prod' (l : List (α → M))
(hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by
induction' l with f l ihl; · exact stronglyMeasurable_one
rw [List.forall_mem_cons] at hl
rw [List.prod_cons]
exact hl.1.mul (ihl hl.2)
@[to_additive (attr := measurability)]
theorem _root_.List.stronglyMeasurable_prod (l : List (α → M))
(hl : ∀ f ∈ l, StronglyMeasurable f) :
StronglyMeasurable fun x => (l.map fun f : α → M => f x).prod := by
simpa only [← Pi.list_prod_apply] using l.stronglyMeasurable_prod' hl
end Monoid
section CommMonoid
variable {M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α}
@[to_additive (attr := measurability)]
theorem _root_.Multiset.stronglyMeasurable_prod' (l : Multiset (α → M))
(hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by
rcases l with ⟨l⟩
simpa using l.stronglyMeasurable_prod' (by simpa using hl)
@[to_additive (attr := measurability)]
theorem _root_.Multiset.stronglyMeasurable_prod (s : Multiset (α → M))
(hs : ∀ f ∈ s, StronglyMeasurable f) :
StronglyMeasurable fun x => (s.map fun f : α → M => f x).prod := by
simpa only [← Pi.multiset_prod_apply] using s.stronglyMeasurable_prod' hs
@[to_additive (attr := measurability)]
theorem _root_.Finset.stronglyMeasurable_prod' {ι : Type*} {f : ι → α → M} (s : Finset ι)
(hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable (∏ i ∈ s, f i) :=
Finset.prod_induction _ _ (fun _a _b ha hb => ha.mul hb) (@stronglyMeasurable_one α M _ _ _) hf
@[to_additive (attr := measurability)]
theorem _root_.Finset.stronglyMeasurable_prod {ι : Type*} {f : ι → α → M} (s : Finset ι)
(hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable fun a => ∏ i ∈ s, f i a := by
simpa only [← Finset.prod_apply] using s.stronglyMeasurable_prod' hf
end CommMonoid
/-- The range of a strongly measurable function is separable. -/
protected theorem isSeparable_range {m : MeasurableSpace α} [TopologicalSpace β]
(hf : StronglyMeasurable f) : TopologicalSpace.IsSeparable (range f) := by
have : IsSeparable (closure (⋃ n, range (hf.approx n))) :=
.closure <| .iUnion fun n => (hf.approx n).finite_range.isSeparable
apply this.mono
rintro _ ⟨x, rfl⟩
apply mem_closure_of_tendsto (hf.tendsto_approx x)
filter_upwards with n
apply mem_iUnion_of_mem n
exact mem_range_self _
theorem separableSpace_range_union_singleton {_ : MeasurableSpace α} [TopologicalSpace β]
[PseudoMetrizableSpace β] (hf : StronglyMeasurable f) {b : β} :
SeparableSpace (range f ∪ {b} : Set β) :=
letI := pseudoMetrizableSpacePseudoMetric β
(hf.isSeparable_range.union (finite_singleton _).isSeparable).separableSpace
section SecondCountableStronglyMeasurable
variable {mα : MeasurableSpace α} [MeasurableSpace β]
/-- In a space with second countable topology, measurable implies strongly measurable. -/
@[aesop 90% apply (rule_sets := [Measurable])]
theorem _root_.Measurable.stronglyMeasurable [TopologicalSpace β] [PseudoMetrizableSpace β]
[SecondCountableTopology β] [OpensMeasurableSpace β] (hf : Measurable f) :
StronglyMeasurable f := by
letI := pseudoMetrizableSpacePseudoMetric β
nontriviality β; inhabit β
exact ⟨SimpleFunc.approxOn f hf Set.univ default (Set.mem_univ _), fun x ↦
SimpleFunc.tendsto_approxOn hf (Set.mem_univ _) (by rw [closure_univ]; simp)⟩
/-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/
theorem _root_.stronglyMeasurable_iff_measurable [TopologicalSpace β] [MetrizableSpace β]
[BorelSpace β] [SecondCountableTopology β] : StronglyMeasurable f ↔ Measurable f :=
⟨fun h => h.measurable, fun h => Measurable.stronglyMeasurable h⟩
@[measurability]
theorem _root_.stronglyMeasurable_id [TopologicalSpace α] [PseudoMetrizableSpace α]
[OpensMeasurableSpace α] [SecondCountableTopology α] : StronglyMeasurable (id : α → α) :=
measurable_id.stronglyMeasurable
end SecondCountableStronglyMeasurable
/-- A function is strongly measurable if and only if it is measurable and has separable
range. -/
theorem _root_.stronglyMeasurable_iff_measurable_separable {m : MeasurableSpace α}
[TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] :
StronglyMeasurable f ↔ Measurable f ∧ IsSeparable (range f) := by
refine ⟨fun H ↦ ⟨H.measurable, H.isSeparable_range⟩, fun ⟨Hm, Hsep⟩ ↦ ?_⟩
have := Hsep.secondCountableTopology
have Hm' : StronglyMeasurable (rangeFactorization f) := Hm.subtype_mk.stronglyMeasurable
exact continuous_subtype_val.comp_stronglyMeasurable Hm'
/-- A continuous function is strongly measurable when either the source space or the target space
is second-countable. -/
theorem _root_.Continuous.stronglyMeasurable [MeasurableSpace α] [TopologicalSpace α]
[OpensMeasurableSpace α] [TopologicalSpace β] [PseudoMetrizableSpace β]
[h : SecondCountableTopologyEither α β] {f : α → β} (hf : Continuous f) :
StronglyMeasurable f := by
borelize β
cases h.out
· rw [stronglyMeasurable_iff_measurable_separable]
refine ⟨hf.measurable, ?_⟩
exact isSeparable_range hf
· exact hf.measurable.stronglyMeasurable
/-- A continuous function whose support is contained in a compact set is strongly measurable. -/
@[to_additive]
theorem _root_.Continuous.stronglyMeasurable_of_mulSupport_subset_isCompact
[MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β]
[TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β}
(hf : Continuous f) {k : Set α} (hk : IsCompact k)
(h'f : mulSupport f ⊆ k) : StronglyMeasurable f := by
letI : PseudoMetricSpace β := pseudoMetrizableSpacePseudoMetric β
rw [stronglyMeasurable_iff_measurable_separable]
exact ⟨hf.measurable, (isCompact_range_of_mulSupport_subset_isCompact hf hk h'f).isSeparable⟩
/-- A continuous function with compact support is strongly measurable. -/
@[to_additive]
theorem _root_.Continuous.stronglyMeasurable_of_hasCompactMulSupport
[MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β]
[TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β}
(hf : Continuous f) (h'f : HasCompactMulSupport f) : StronglyMeasurable f :=
hf.stronglyMeasurable_of_mulSupport_subset_isCompact h'f (subset_mulTSupport f)
/-- A continuous function with compact support on a product space is strongly measurable for the
product sigma-algebra. The subtlety is that we do not assume that the spaces are separable, so the
product of the Borel sigma algebras might not contain all open sets, but still it contains enough
of them to approximate compactly supported continuous functions. -/
lemma _root_.HasCompactSupport.stronglyMeasurable_of_prod {X Y : Type*} [Zero α]
[TopologicalSpace X] [TopologicalSpace Y] [MeasurableSpace X] [MeasurableSpace Y]
[OpensMeasurableSpace X] [OpensMeasurableSpace Y] [TopologicalSpace α] [PseudoMetrizableSpace α]
{f : X × Y → α} (hf : Continuous f) (h'f : HasCompactSupport f) :
StronglyMeasurable f := by
borelize α
apply stronglyMeasurable_iff_measurable_separable.2 ⟨h'f.measurable_of_prod hf, ?_⟩
letI : PseudoMetricSpace α := pseudoMetrizableSpacePseudoMetric α
exact IsCompact.isSeparable (s := range f) (h'f.isCompact_range hf)
/-- If `g` is a topological embedding, then `f` is strongly measurable iff `g ∘ f` is. -/
theorem _root_.Embedding.comp_stronglyMeasurable_iff {m : MeasurableSpace α} [TopologicalSpace β]
[PseudoMetrizableSpace β] [TopologicalSpace γ] [PseudoMetrizableSpace γ] {g : β → γ} {f : α → β}
(hg : IsEmbedding g) : (StronglyMeasurable fun x => g (f x)) ↔ StronglyMeasurable f := by
letI := pseudoMetrizableSpacePseudoMetric γ
borelize β γ
refine
⟨fun H => stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩, fun H =>
hg.continuous.comp_stronglyMeasurable H⟩
· let G : β → range g := rangeFactorization g
have hG : IsClosedEmbedding G :=
{ hg.codRestrict _ _ with
isClosed_range := by
rw [surjective_onto_range.range_eq]
exact isClosed_univ }
have : Measurable (G ∘ f) := Measurable.subtype_mk H.measurable
exact hG.measurableEmbedding.measurable_comp_iff.1 this
· have : IsSeparable (g ⁻¹' range (g ∘ f)) := hg.isSeparable_preimage H.isSeparable_range
rwa [range_comp, hg.injective.preimage_image] at this
/-- A sequential limit of strongly measurable functions is strongly measurable. -/
theorem _root_.stronglyMeasurable_of_tendsto {ι : Type*} {m : MeasurableSpace α}
[TopologicalSpace β] [PseudoMetrizableSpace β] (u : Filter ι) [NeBot u] [IsCountablyGenerated u]
{f : ι → α → β} {g : α → β} (hf : ∀ i, StronglyMeasurable (f i)) (lim : Tendsto f u (𝓝 g)) :
StronglyMeasurable g := by
borelize β
refine stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩
· exact measurable_of_tendsto_metrizable' u (fun i => (hf i).measurable) lim
· rcases u.exists_seq_tendsto with ⟨v, hv⟩
have : IsSeparable (closure (⋃ i, range (f (v i)))) :=
.closure <| .iUnion fun i => (hf (v i)).isSeparable_range
apply this.mono
rintro _ ⟨x, rfl⟩
rw [tendsto_pi_nhds] at lim
apply mem_closure_of_tendsto ((lim x).comp hv)
filter_upwards with n
apply mem_iUnion_of_mem n
exact mem_range_self _
protected theorem piecewise {m : MeasurableSpace α} [TopologicalSpace β] {s : Set α}
{_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : StronglyMeasurable f)
(hg : StronglyMeasurable g) : StronglyMeasurable (Set.piecewise s f g) := by
refine ⟨fun n => SimpleFunc.piecewise s hs (hf.approx n) (hg.approx n), fun x => ?_⟩
by_cases hx : x ∈ s
· simpa [@Set.piecewise_eq_of_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx,
hx] using hf.tendsto_approx x
· simpa [@Set.piecewise_eq_of_not_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx,
hx] using hg.tendsto_approx x
/-- this is slightly different from `StronglyMeasurable.piecewise`. It can be used to show
`StronglyMeasurable (ite (x=0) 0 1)` by
`exact StronglyMeasurable.ite (measurableSet_singleton 0) stronglyMeasurable_const
stronglyMeasurable_const`, but replacing `StronglyMeasurable.ite` by
`StronglyMeasurable.piecewise` in that example proof does not work. -/
protected theorem ite {_ : MeasurableSpace α} [TopologicalSpace β] {p : α → Prop}
{_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : StronglyMeasurable f)
(hg : StronglyMeasurable g) : StronglyMeasurable fun x => ite (p x) (f x) (g x) :=
StronglyMeasurable.piecewise hp hf hg
@[measurability]
theorem _root_.MeasurableEmbedding.stronglyMeasurable_extend {f : α → β} {g : α → γ} {g' : γ → β}
{mα : MeasurableSpace α} {mγ : MeasurableSpace γ} [TopologicalSpace β]
(hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hg' : StronglyMeasurable g') :
StronglyMeasurable (Function.extend g f g') := by
refine ⟨fun n => SimpleFunc.extend (hf.approx n) g hg (hg'.approx n), ?_⟩
intro x
by_cases hx : ∃ y, g y = x
· rcases hx with ⟨y, rfl⟩
simpa only [SimpleFunc.extend_apply, hg.injective, Injective.extend_apply] using
hf.tendsto_approx y
· simpa only [hx, SimpleFunc.extend_apply', not_false_iff, extend_apply'] using
hg'.tendsto_approx x
theorem _root_.MeasurableEmbedding.exists_stronglyMeasurable_extend {f : α → β} {g : α → γ}
{_ : MeasurableSpace α} {_ : MeasurableSpace γ} [TopologicalSpace β]
(hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hne : γ → Nonempty β) :
∃ f' : γ → β, StronglyMeasurable f' ∧ f' ∘ g = f :=
⟨Function.extend g f fun x => Classical.choice (hne x),
hg.stronglyMeasurable_extend hf (stronglyMeasurable_const' fun _ _ => rfl),
funext fun _ => hg.injective.extend_apply _ _ _⟩
theorem _root_.stronglyMeasurable_of_stronglyMeasurable_union_cover {m : MeasurableSpace α}
[TopologicalSpace β] {f : α → β} (s t : Set α) (hs : MeasurableSet s) (ht : MeasurableSet t)
(h : univ ⊆ s ∪ t) (hc : StronglyMeasurable fun a : s => f a)
(hd : StronglyMeasurable fun a : t => f a) : StronglyMeasurable f := by
nontriviality β; inhabit β
suffices Function.extend Subtype.val (fun x : s ↦ f x)
(Function.extend (↑) (fun x : t ↦ f x) fun _ ↦ default) = f from
this ▸ (MeasurableEmbedding.subtype_coe hs).stronglyMeasurable_extend hc <|
(MeasurableEmbedding.subtype_coe ht).stronglyMeasurable_extend hd stronglyMeasurable_const
ext x
by_cases hxs : x ∈ s
· lift x to s using hxs
simp [Subtype.coe_injective.extend_apply]
· lift x to t using (h trivial).resolve_left hxs
rw [extend_apply', Subtype.coe_injective.extend_apply]
exact fun ⟨y, hy⟩ ↦ hxs <| hy ▸ y.2
theorem _root_.stronglyMeasurable_of_restrict_of_restrict_compl {_ : MeasurableSpace α}
[TopologicalSpace β] {f : α → β} {s : Set α} (hs : MeasurableSet s)
(h₁ : StronglyMeasurable (s.restrict f)) (h₂ : StronglyMeasurable (sᶜ.restrict f)) :
StronglyMeasurable f :=
stronglyMeasurable_of_stronglyMeasurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁
h₂
@[measurability]
protected theorem indicator {_ : MeasurableSpace α} [TopologicalSpace β] [Zero β]
(hf : StronglyMeasurable f) {s : Set α} (hs : MeasurableSet s) :
StronglyMeasurable (s.indicator f) :=
hf.piecewise hs stronglyMeasurable_const
/-- To prove that a property holds for any strongly measurable function, it is enough to show
that it holds for constant indicator functions of measurable sets and that it is closed under
addition and pointwise limit.
To use in an induction proof, the syntax is
`induction f, hf using StronglyMeasurable.induction with`. -/
theorem induction [MeasurableSpace α] [AddZeroClass β] [TopologicalSpace β]
{P : (f : α → β) → StronglyMeasurable f → Prop}
(ind : ∀ c ⦃s : Set α⦄ (hs : MeasurableSet s),
P (s.indicator fun _ ↦ c) (stronglyMeasurable_const.indicator hs))
(add : ∀ ⦃f g : α → β⦄ (hf : StronglyMeasurable f) (hg : StronglyMeasurable g)
(hfg : StronglyMeasurable (f + g)), Disjoint f.support g.support →
P f hf → P g hg → P (f + g) hfg)
(lim : ∀ ⦃f : ℕ → α → β⦄ ⦃g : α → β⦄ (hf : ∀ n, StronglyMeasurable (f n))
(hg : StronglyMeasurable g), (∀ n, P (f n) (hf n)) →
(∀ x, Tendsto (f · x) atTop (𝓝 (g x))) → P g hg)
(f : α → β) (hf : StronglyMeasurable f) : P f hf := by
let s := hf.approx
refine lim (fun n ↦ (s n).stronglyMeasurable) hf (fun n ↦ ?_) hf.tendsto_approx
change P (s n) (s n).stronglyMeasurable
induction s n using SimpleFunc.induction with
| const c hs => exact ind c hs
| @add f g h_supp hf hg =>
exact add f.stronglyMeasurable g.stronglyMeasurable (f + g).stronglyMeasurable h_supp hf hg
open scoped Classical in
/-- To prove that a property holds for any strongly measurable function, it is enough to show
that it holds for constant functions and that it is closed under piecewise combination of functions
and pointwise limits.
To use in an induction proof, the syntax is
`induction f, hf using StronglyMeasurable.induction' with`. -/
theorem induction' [MeasurableSpace α] [Nonempty β] [TopologicalSpace β]
{P : (f : α → β) → StronglyMeasurable f → Prop}
(const : ∀ (c), P (fun _ ↦ c) stronglyMeasurable_const)
(pcw : ∀ ⦃f g : α → β⦄ {s} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g)
(hs : MeasurableSet s), P f hf → P g hg → P (s.piecewise f g) (hf.piecewise hs hg))
(lim : ∀ ⦃f : ℕ → α → β⦄ ⦃g : α → β⦄ (hf : ∀ n, StronglyMeasurable (f n))
(hg : StronglyMeasurable g), (∀ n, P (f n) (hf n)) →
(∀ x, Tendsto (f · x) atTop (𝓝 (g x))) → P g hg)
(f : α → β) (hf : StronglyMeasurable f) : P f hf := by
let s := hf.approx
refine lim (fun n ↦ (s n).stronglyMeasurable) hf (fun n ↦ ?_) hf.tendsto_approx
change P (s n) (s n).stronglyMeasurable
induction s n with
| const c => exact const c
| @pcw f g s hs Pf Pg =>
simp_rw [SimpleFunc.coe_piecewise]
exact pcw f.stronglyMeasurable g.stronglyMeasurable hs Pf Pg
@[aesop safe 20 apply (rule_sets := [Measurable])]
protected theorem dist {_ : MeasurableSpace α} {β : Type*} [PseudoMetricSpace β] {f g : α → β}
(hf : StronglyMeasurable f) (hg : StronglyMeasurable g) :
StronglyMeasurable fun x => dist (f x) (g x) :=
continuous_dist.comp_stronglyMeasurable (hf.prodMk hg)
@[measurability]
protected theorem norm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β}
(hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖ :=
continuous_norm.comp_stronglyMeasurable hf
@[measurability]
protected theorem nnnorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β}
(hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖₊ :=
continuous_nnnorm.comp_stronglyMeasurable hf
/-- The `enorm` of a strongly measurable function is measurable.
Unlike `StrongMeasurable.norm` and `StronglyMeasurable.nnnorm`, this lemma proves measurability,
**not** strong measurability. This is an intentional decision: for functions taking values in
ℝ≥0∞, measurability is much more useful than strong measurability. -/
@[fun_prop, measurability]
protected theorem enorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β]
{f : α → β} (hf : StronglyMeasurable f) : Measurable (‖f ·‖ₑ) :=
(ENNReal.continuous_coe.comp_stronglyMeasurable hf.nnnorm).measurable
@[deprecated (since := "2025-01-21")] alias ennnorm := StronglyMeasurable.enorm
@[measurability]
protected theorem real_toNNReal {_ : MeasurableSpace α} {f : α → ℝ} (hf : StronglyMeasurable f) :
StronglyMeasurable fun x => (f x).toNNReal :=
continuous_real_toNNReal.comp_stronglyMeasurable hf
section PseudoMetrizableSpace
variable {E : Type*} {m m₀ : MeasurableSpace α} {μ : Measure[m₀] α} {f g : α → E}
[TopologicalSpace E] [Preorder E] [OrderClosedTopology E] [PseudoMetrizableSpace E]
lemma measurableSet_le (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) :
MeasurableSet[m] {a | f a ≤ g a} := by
borelize (E × E)
exact (hf.prodMk hg).measurable isClosed_le_prod.measurableSet
lemma measurableSet_lt (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) :
MeasurableSet[m] {a | f a < g a} := by
simpa only [lt_iff_le_not_le] using (hf.measurableSet_le hg).inter (hg.measurableSet_le hf).compl
lemma ae_le_trim_of_stronglyMeasurable (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f)
(hg : StronglyMeasurable[m] g) (hfg : f ≤ᵐ[μ] g) : f ≤ᵐ[μ.trim hm] g := by
rwa [EventuallyLE, ae_iff, trim_measurableSet_eq hm]
exact (hf.measurableSet_le hg).compl
lemma ae_le_trim_iff (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) :
f ≤ᵐ[μ.trim hm] g ↔ f ≤ᵐ[μ] g :=
⟨ae_le_of_ae_le_trim, ae_le_trim_of_stronglyMeasurable hm hf hg⟩
end PseudoMetrizableSpace
section MetrizableSpace
variable {E : Type*} {m m₀ : MeasurableSpace α} {μ : Measure[m₀] α} {f g : α → E}
[TopologicalSpace E] [MetrizableSpace E]
lemma measurableSet_eq_fun (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) :
MeasurableSet[m] {a | f a = g a} := by
borelize (E × E)
exact (hf.prodMk hg).measurable isClosed_diagonal.measurableSet
lemma ae_eq_trim_of_stronglyMeasurable (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f)
(hg : StronglyMeasurable[m] g) (hfg : f =ᵐ[μ] g) : f =ᵐ[μ.trim hm] g := by
rwa [EventuallyEq, ae_iff, trim_measurableSet_eq hm]
exact (hf.measurableSet_eq_fun hg).compl
lemma ae_eq_trim_iff (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) :
f =ᵐ[μ.trim hm] g ↔ f =ᵐ[μ] g :=
⟨ae_eq_of_ae_eq_trim, ae_eq_trim_of_stronglyMeasurable hm hf hg⟩
end MetrizableSpace
theorem stronglyMeasurable_in_set {m : MeasurableSpace α} [TopologicalSpace β] [Zero β] {s : Set α}
{f : α → β} (hs : MeasurableSet s) (hf : StronglyMeasurable f)
(hf_zero : ∀ x, x ∉ s → f x = 0) :
∃ fs : ℕ → α →ₛ β,
(∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))) ∧ ∀ x ∉ s, ∀ n, fs n x = 0 := by
let g_seq_s : ℕ → @SimpleFunc α m β := fun n => (hf.approx n).restrict s
have hg_eq : ∀ x ∈ s, ∀ n, g_seq_s n x = hf.approx n x := by
intro x hx n
rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_mem hx]
have hg_zero : ∀ x ∉ s, ∀ n, g_seq_s n x = 0 := by
intro x hx n
rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_not_mem hx]
refine ⟨g_seq_s, fun x => ?_, hg_zero⟩
by_cases hx : x ∈ s
· simp_rw [hg_eq x hx]
exact hf.tendsto_approx x
· simp_rw [hg_zero x hx, hf_zero x hx]
exact tendsto_const_nhds
/-- If the restriction to a set `s` of a σ-algebra `m` is included in the restriction to `s` of
another σ-algebra `m₂` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` supported
on `s` is `m`-strongly-measurable, then `f` is also `m₂`-strongly-measurable. -/
theorem stronglyMeasurable_of_measurableSpace_le_on {α E} {m m₂ : MeasurableSpace α}
[TopologicalSpace E] [Zero E] {s : Set α} {f : α → E} (hs_m : MeasurableSet[m] s)
(hs : ∀ t, MeasurableSet[m] (s ∩ t) → MeasurableSet[m₂] (s ∩ t))
(hf : StronglyMeasurable[m] f) (hf_zero : ∀ x ∉ s, f x = 0) :
StronglyMeasurable[m₂] f := by
have hs_m₂ : MeasurableSet[m₂] s := by
rw [← Set.inter_univ s]
refine hs Set.univ ?_
rwa [Set.inter_univ]
obtain ⟨g_seq_s, hg_seq_tendsto, hg_seq_zero⟩ := stronglyMeasurable_in_set hs_m hf hf_zero
let g_seq_s₂ : ℕ → @SimpleFunc α m₂ E := fun n =>
{ toFun := g_seq_s n
measurableSet_fiber' := fun x => by
rw [← Set.inter_univ (g_seq_s n ⁻¹' {x}), ← Set.union_compl_self s,
Set.inter_union_distrib_left, Set.inter_comm (g_seq_s n ⁻¹' {x})]
refine MeasurableSet.union (hs _ (hs_m.inter ?_)) ?_
· exact @SimpleFunc.measurableSet_fiber _ _ m _ _
by_cases hx : x = 0
· suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = sᶜ by
rw [this]
exact hs_m₂.compl
ext1 y
rw [hx, Set.mem_inter_iff, Set.mem_preimage, Set.mem_singleton_iff]
exact ⟨fun h => h.2, fun h => ⟨hg_seq_zero y h n, h⟩⟩
· suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = ∅ by
rw [this]
exact MeasurableSet.empty
ext1 y
simp only [mem_inter_iff, mem_preimage, mem_singleton_iff, mem_compl_iff,
mem_empty_iff_false, iff_false, not_and, not_not_mem]
refine Function.mtr fun hys => ?_
rw [hg_seq_zero y hys n]
exact Ne.symm hx
finite_range' := @SimpleFunc.finite_range _ _ m (g_seq_s n) }
exact ⟨g_seq_s₂, hg_seq_tendsto⟩
/-- If a function `f` is strongly measurable w.r.t. a sub-σ-algebra `m` and the measure is σ-finite
on `m`, then there exists spanning measurable sets with finite measure on which `f` has bounded
norm. In particular, `f` is integrable on each of those sets. -/
theorem exists_spanning_measurableSet_norm_le [SeminormedAddCommGroup β] {m m0 : MeasurableSpace α}
(hm : m ≤ m0) (hf : StronglyMeasurable[m] f) (μ : Measure α) [SigmaFinite (μ.trim hm)] :
∃ s : ℕ → Set α,
(∀ n, MeasurableSet[m] (s n) ∧ μ (s n) < ∞ ∧ ∀ x ∈ s n, ‖f x‖ ≤ n) ∧
⋃ i, s i = Set.univ := by
obtain ⟨s, hs, hs_univ⟩ :=
@exists_spanning_measurableSet_le _ m _ hf.nnnorm.measurable (μ.trim hm) _
refine ⟨s, fun n ↦ ⟨(hs n).1, (le_trim hm).trans_lt (hs n).2.1, fun x hx ↦ ?_⟩, hs_univ⟩
have hx_nnnorm : ‖f x‖₊ ≤ n := (hs n).2.2 x hx
rw [← coe_nnnorm]
norm_cast
end StronglyMeasurable
/-! ## Finitely strongly measurable functions -/
theorem finStronglyMeasurable_zero {α β} {m : MeasurableSpace α} {μ : Measure α} [Zero β]
[TopologicalSpace β] : FinStronglyMeasurable (0 : α → β) μ :=
⟨0, by
simp only [Pi.zero_apply, SimpleFunc.coe_zero, support_zero', measure_empty,
zero_lt_top, forall_const],
fun _ => tendsto_const_nhds⟩
namespace FinStronglyMeasurable
variable {m0 : MeasurableSpace α} {μ : Measure α} {f g : α → β}
section sequence
variable [Zero β] [TopologicalSpace β] (hf : FinStronglyMeasurable f μ)
/-- A sequence of simple functions such that `∀ x, Tendsto (fun n ↦ hf.approx n x) atTop (𝓝 (f x))`
and `∀ n, μ (support (hf.approx n)) < ∞`. These properties are given by
`FinStronglyMeasurable.tendsto_approx` and `FinStronglyMeasurable.fin_support_approx`. -/
protected noncomputable def approx : ℕ → α →ₛ β :=
hf.choose
protected theorem fin_support_approx : ∀ n, μ (support (hf.approx n)) < ∞ :=
hf.choose_spec.1
protected theorem tendsto_approx : ∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) :=
hf.choose_spec.2
end sequence
/-- A finitely strongly measurable function is strongly measurable. -/
@[aesop 5% apply (rule_sets := [Measurable])]
protected theorem stronglyMeasurable [Zero β] [TopologicalSpace β]
(hf : FinStronglyMeasurable f μ) : StronglyMeasurable f :=
⟨hf.approx, hf.tendsto_approx⟩
theorem exists_set_sigmaFinite [Zero β] [TopologicalSpace β] [T2Space β]
(hf : FinStronglyMeasurable f μ) :
∃ t, MeasurableSet t ∧ (∀ x ∈ tᶜ, f x = 0) ∧ SigmaFinite (μ.restrict t) := by
rcases hf with ⟨fs, hT_lt_top, h_approx⟩
let T n := support (fs n)
have hT_meas : ∀ n, MeasurableSet (T n) := fun n => SimpleFunc.measurableSet_support (fs n)
let t := ⋃ n, T n
refine ⟨t, MeasurableSet.iUnion hT_meas, ?_, ?_⟩
· have h_fs_zero : ∀ n, ∀ x ∈ tᶜ, fs n x = 0 := by
intro n x hxt
rw [Set.mem_compl_iff, Set.mem_iUnion, not_exists] at hxt
simpa [T] using hxt n
refine fun x hxt => tendsto_nhds_unique (h_approx x) ?_
rw [funext fun n => h_fs_zero n x hxt]
exact tendsto_const_nhds
· refine ⟨⟨⟨fun n => tᶜ ∪ T n, fun _ => trivial, fun n => ?_, ?_⟩⟩⟩
· rw [Measure.restrict_apply' (MeasurableSet.iUnion hT_meas), Set.union_inter_distrib_right,
Set.compl_inter_self t, Set.empty_union]
exact (measure_mono Set.inter_subset_left).trans_lt (hT_lt_top n)
· rw [← Set.union_iUnion tᶜ T]
exact Set.compl_union_self _
/-- A finitely strongly measurable function is measurable. -/
protected theorem measurable [Zero β] [TopologicalSpace β] [PseudoMetrizableSpace β]
[MeasurableSpace β] [BorelSpace β] (hf : FinStronglyMeasurable f μ) : Measurable f :=
hf.stronglyMeasurable.measurable
section Arithmetic
variable [TopologicalSpace β]
@[aesop safe 20 (rule_sets := [Measurable])]
protected theorem mul [MulZeroClass β] [ContinuousMul β] (hf : FinStronglyMeasurable f μ)
(hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f * g) μ := by
refine
⟨fun n => hf.approx n * hg.approx n, ?_, fun x =>
(hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩
intro n
exact (measure_mono (support_mul_subset_left _ _)).trans_lt (hf.fin_support_approx n)
@[aesop safe 20 (rule_sets := [Measurable])]
protected theorem add [AddZeroClass β] [ContinuousAdd β] (hf : FinStronglyMeasurable f μ)
(hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f + g) μ :=
⟨fun n => hf.approx n + hg.approx n, fun n =>
(measure_mono (Function.support_add _ _)).trans_lt
((measure_union_le _ _).trans_lt
(ENNReal.add_lt_top.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩)),
fun x => (hf.tendsto_approx x).add (hg.tendsto_approx x)⟩
@[measurability]
protected theorem neg [SubtractionMonoid β] [ContinuousNeg β] (hf : FinStronglyMeasurable f μ) :
FinStronglyMeasurable (-f) μ := by
refine ⟨fun n => -hf.approx n, fun n => ?_, fun x => (hf.tendsto_approx x).neg⟩
suffices μ (Function.support fun x => -(hf.approx n) x) < ∞ by convert this
rw [Function.support_neg (hf.approx n)]
exact hf.fin_support_approx n
@[measurability]
protected theorem sub [SubtractionMonoid β] [ContinuousSub β] (hf : FinStronglyMeasurable f μ)
(hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f - g) μ :=
⟨fun n => hf.approx n - hg.approx n, fun n =>
(measure_mono (Function.support_sub _ _)).trans_lt
((measure_union_le _ _).trans_lt
(ENNReal.add_lt_top.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩)),
fun x => (hf.tendsto_approx x).sub (hg.tendsto_approx x)⟩
@[measurability]
protected theorem const_smul {𝕜} [TopologicalSpace 𝕜] [Zero β]
[SMulZeroClass 𝕜 β] [ContinuousSMul 𝕜 β] (hf : FinStronglyMeasurable f μ) (c : 𝕜) :
FinStronglyMeasurable (c • f) μ := by
refine ⟨fun n => c • hf.approx n, fun n => ?_, fun x => (hf.tendsto_approx x).const_smul c⟩
rw [SimpleFunc.coe_smul]
exact (measure_mono (support_const_smul_subset c _)).trans_lt (hf.fin_support_approx n)
end Arithmetic
section Order
variable [TopologicalSpace β] [Zero β]
@[aesop safe 20 (rule_sets := [Measurable])]
protected theorem sup [SemilatticeSup β] [ContinuousSup β] (hf : FinStronglyMeasurable f μ)
(hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f ⊔ g) μ := by
refine
⟨fun n => hf.approx n ⊔ hg.approx n, fun n => ?_, fun x =>
(hf.tendsto_approx x).sup_nhds (hg.tendsto_approx x)⟩
refine (measure_mono (support_sup _ _)).trans_lt ?_
exact measure_union_lt_top_iff.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩
@[aesop safe 20 (rule_sets := [Measurable])]
protected theorem inf [SemilatticeInf β] [ContinuousInf β] (hf : FinStronglyMeasurable f μ)
(hg : FinStronglyMeasurable g μ) : FinStronglyMeasurable (f ⊓ g) μ := by
refine
⟨fun n => hf.approx n ⊓ hg.approx n, fun n => ?_, fun x =>
(hf.tendsto_approx x).inf_nhds (hg.tendsto_approx x)⟩
refine (measure_mono (support_inf _ _)).trans_lt ?_
exact measure_union_lt_top_iff.mpr ⟨hf.fin_support_approx n, hg.fin_support_approx n⟩
end Order
end FinStronglyMeasurable
theorem finStronglyMeasurable_iff_stronglyMeasurable_and_exists_set_sigmaFinite {α β} {f : α → β}
[TopologicalSpace β] [T2Space β] [Zero β] {_ : MeasurableSpace α} {μ : Measure α} :
FinStronglyMeasurable f μ ↔
StronglyMeasurable f ∧
∃ t, MeasurableSet t ∧ (∀ x ∈ tᶜ, f x = 0) ∧ SigmaFinite (μ.restrict t) :=
⟨fun hf => ⟨hf.stronglyMeasurable, hf.exists_set_sigmaFinite⟩, fun hf =>
hf.1.finStronglyMeasurable_of_set_sigmaFinite hf.2.choose_spec.1 hf.2.choose_spec.2.1
hf.2.choose_spec.2.2⟩
section SecondCountableTopology
variable {G : Type*} [SeminormedAddCommGroup G] [MeasurableSpace G] [BorelSpace G]
[SecondCountableTopology G] {f : α → G}
/-- In a space with second countable topology and a sigma-finite measure, `FinStronglyMeasurable`
and `Measurable` are equivalent. -/
theorem finStronglyMeasurable_iff_measurable {_m0 : MeasurableSpace α} (μ : Measure α)
[SigmaFinite μ] : FinStronglyMeasurable f μ ↔ Measurable f :=
⟨fun h => h.measurable, fun h => (Measurable.stronglyMeasurable h).finStronglyMeasurable μ⟩
/-- In a space with second countable topology and a sigma-finite measure, a measurable function
is `FinStronglyMeasurable`. -/
@[aesop 90% apply (rule_sets := [Measurable])]
theorem finStronglyMeasurable_of_measurable {_m0 : MeasurableSpace α} (μ : Measure α)
[SigmaFinite μ] (hf : Measurable f) : FinStronglyMeasurable f μ :=
(finStronglyMeasurable_iff_measurable μ).mpr hf
end SecondCountableTopology
theorem measurable_uncurry_of_continuous_of_measurable {α β ι : Type*} [TopologicalSpace ι]
[MetrizableSpace ι] [MeasurableSpace ι] [SecondCountableTopology ι] [OpensMeasurableSpace ι]
{mβ : MeasurableSpace β} [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β]
{m : MeasurableSpace α} {u : ι → α → β} (hu_cont : ∀ x, Continuous fun i => u i x)
(h : ∀ i, Measurable (u i)) : Measurable (Function.uncurry u) := by
obtain ⟨t_sf, ht_sf⟩ :
∃ t : ℕ → SimpleFunc ι ι, ∀ j x, Tendsto (fun n => u (t n j) x) atTop (𝓝 <| u j x) := by
have h_str_meas : StronglyMeasurable (id : ι → ι) := stronglyMeasurable_id
refine ⟨h_str_meas.approx, fun j x => ?_⟩
exact ((hu_cont x).tendsto j).comp (h_str_meas.tendsto_approx j)
let U (n : ℕ) (p : ι × α) := u (t_sf n p.fst) p.snd
have h_tendsto : Tendsto U atTop (𝓝 fun p => u p.fst p.snd) := by
rw [tendsto_pi_nhds]
exact fun p => ht_sf p.fst p.snd
refine measurable_of_tendsto_metrizable (fun n => ?_) h_tendsto
have h_meas : Measurable fun p : (t_sf n).range × α => u (↑p.fst) p.snd := by
have :
(fun p : ↥(t_sf n).range × α => u (↑p.fst) p.snd) =
(fun p : α × (t_sf n).range => u (↑p.snd) p.fst) ∘ Prod.swap :=
rfl
rw [this, @measurable_swap_iff α (↥(t_sf n).range) β m]
exact measurable_from_prod_countable fun j => h j
have :
(fun p : ι × α => u (t_sf n p.fst) p.snd) =
(fun p : ↥(t_sf n).range × α => u p.fst p.snd) ∘ fun p : ι × α =>
(⟨t_sf n p.fst, SimpleFunc.mem_range_self _ _⟩, p.snd) :=
rfl
simp_rw [U, this]
refine h_meas.comp (Measurable.prodMk ?_ measurable_snd)
exact ((t_sf n).measurable.comp measurable_fst).subtype_mk
theorem stronglyMeasurable_uncurry_of_continuous_of_stronglyMeasurable {α β ι : Type*}
[TopologicalSpace ι] [MetrizableSpace ι] [MeasurableSpace ι] [SecondCountableTopology ι]
[OpensMeasurableSpace ι] [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace α]
{u : ι → α → β} (hu_cont : ∀ x, Continuous fun i => u i x) (h : ∀ i, StronglyMeasurable (u i)) :
StronglyMeasurable (Function.uncurry u) := by
borelize β
obtain ⟨t_sf, ht_sf⟩ :
∃ t : ℕ → SimpleFunc ι ι, ∀ j x, Tendsto (fun n => u (t n j) x) atTop (𝓝 <| u j x) := by
have h_str_meas : StronglyMeasurable (id : ι → ι) := stronglyMeasurable_id
refine ⟨h_str_meas.approx, fun j x => ?_⟩
| exact ((hu_cont x).tendsto j).comp (h_str_meas.tendsto_approx j)
let U (n : ℕ) (p : ι × α) := u (t_sf n p.fst) p.snd
have h_tendsto : Tendsto U atTop (𝓝 fun p => u p.fst p.snd) := by
rw [tendsto_pi_nhds]
exact fun p => ht_sf p.fst p.snd
| Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean | 1,206 | 1,210 |
/-
Copyright (c) 2023 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Polynomial.Degree.Lemmas
/-!
# `compute_degree` and `monicity`: tactics for explicit polynomials
This file defines two related tactics: `compute_degree` and `monicity`.
Using `compute_degree` when the goal is of one of the five forms
* `natDegree f ≤ d`,
* `degree f ≤ d`,
* `natDegree f = d`,
* `degree f = d`,
* `coeff f d = r`, if `d` is the degree of `f`,
tries to solve the goal.
It may leave side-goals, in case it is not entirely successful.
Using `monicity` when the goal is of the form `Monic f` tries to solve the goal.
It may leave side-goals, in case it is not entirely successful.
Both tactics admit a `!` modifier (`compute_degree!` and `monicity!`) instructing
Lean to try harder to close the goal.
See the doc-strings for more details.
## Future work
* Currently, `compute_degree` does not deal correctly with some edge cases. For instance,
```lean
example [Semiring R] : natDegree (C 0 : R[X]) = 0 := by
compute_degree
-- ⊢ 0 ≠ 0
```
Still, it may not be worth to provide special support for `natDegree f = 0`.
* Make sure that numerals in coefficients are treated correctly.
* Make sure that `compute_degree` works with goals of the form `degree f ≤ ↑d`, with an
explicit coercion from `ℕ` on the RHS.
* Add support for proving goals of the from `natDegree f ≠ 0` and `degree f ≠ 0`.
* Make sure that `degree`, `natDegree` and `coeff` are equally supported.
## Implementation details
Assume that `f : R[X]` is a polynomial with coefficients in a semiring `R` and
`d` is either in `ℕ` or in `WithBot ℕ`.
If the goal has the form `natDegree f = d`, then we convert it to three separate goals:
* `natDegree f ≤ d`;
* `coeff f d = r`;
* `r ≠ 0`.
Similarly, an initial goal of the form `degree f = d` gives rise to goals of the form
* `degree f ≤ d`;
* `coeff f d = r`;
* `r ≠ 0`.
Next, we apply successively lemmas whose side-goals all have the shape
* `natDegree f ≤ d`;
* `degree f ≤ d`;
* `coeff f d = r`;
plus possibly "numerical" identities and choices of elements in `ℕ`, `WithBot ℕ`, and `R`.
Recursing into `f`, we break apart additions, multiplications, powers, subtractions,...
The leaves of the process are
* numerals, `C a`, `X` and `monomial a n`, to which we assign degree `0`, `1` and `a` respectively;
* `fvar`s `f`, to which we tautologically assign degree `natDegree f`.
-/
open Polynomial
namespace Mathlib.Tactic.ComputeDegree
section recursion_lemmas
/-!
### Simple lemmas about `natDegree`
The lemmas in this section all have the form `natDegree <some form of cast> ≤ 0`.
Their proofs are weakenings of the stronger lemmas `natDegree <same> = 0`.
These are the lemmas called by `compute_degree` on (almost) all the leaves of its recursion.
-/
variable {R : Type*}
section semiring
variable [Semiring R]
theorem natDegree_C_le (a : R) : natDegree (C a) ≤ 0 := (natDegree_C a).le
theorem natDegree_natCast_le (n : ℕ) : natDegree (n : R[X]) ≤ 0 := (natDegree_natCast _).le
theorem natDegree_zero_le : natDegree (0 : R[X]) ≤ 0 := natDegree_zero.le
theorem natDegree_one_le : natDegree (1 : R[X]) ≤ 0 := natDegree_one.le
theorem coeff_add_of_eq {n : ℕ} {a b : R} {f g : R[X]}
(h_add_left : f.coeff n = a) (h_add_right : g.coeff n = b) :
(f + g).coeff n = a + b := by subst ‹_› ‹_›; apply coeff_add
theorem coeff_mul_add_of_le_natDegree_of_eq_ite {d df dg : ℕ} {a b : R} {f g : R[X]}
(h_mul_left : natDegree f ≤ df) (h_mul_right : natDegree g ≤ dg)
(h_mul_left : f.coeff df = a) (h_mul_right : g.coeff dg = b) (ddf : df + dg ≤ d) :
(f * g).coeff d = if d = df + dg then a * b else 0 := by
split_ifs with h
· subst h_mul_left h_mul_right h
exact coeff_mul_of_natDegree_le ‹_› ‹_›
· apply coeff_eq_zero_of_natDegree_lt
apply lt_of_le_of_lt ?_ (lt_of_le_of_ne ddf ?_)
· exact natDegree_mul_le_of_le ‹_› ‹_›
· exact ne_comm.mp h
theorem coeff_pow_of_natDegree_le_of_eq_ite' {m n o : ℕ} {a : R} {p : R[X]}
(h_pow : natDegree p ≤ n) (h_exp : m * n ≤ o) (h_pow_bas : coeff p n = a) :
coeff (p ^ m) o = if o = m * n then a ^ m else 0 := by
split_ifs with h
· subst h h_pow_bas
exact coeff_pow_of_natDegree_le ‹_›
· apply coeff_eq_zero_of_natDegree_lt
apply lt_of_le_of_lt ?_ (lt_of_le_of_ne ‹_› ?_)
· exact natDegree_pow_le_of_le m ‹_›
· exact Iff.mp ne_comm h
theorem natDegree_smul_le_of_le {n : ℕ} {a : R} {f : R[X]} (hf : natDegree f ≤ n) :
natDegree (a • f) ≤ n :=
(natDegree_smul_le a f).trans hf
theorem degree_smul_le_of_le {n : ℕ} {a : R} {f : R[X]} (hf : degree f ≤ n) :
degree (a • f) ≤ n :=
(degree_smul_le a f).trans hf
theorem coeff_smul {n : ℕ} {a : R} {f : R[X]} : (a • f).coeff n = a * f.coeff n := rfl
section congr_lemmas
/-- The following two lemmas should be viewed as a hand-made "congr"-lemmas.
They achieve the following goals.
* They introduce *two* fresh metavariables replacing the given one `deg`,
one for the `natDegree ≤` computation and one for the `coeff =` computation.
This helps `compute_degree`, since it does not "pre-estimate" the degree,
but it "picks it up along the way".
* They split checking the inequality `coeff p n ≠ 0` into the task of
finding a value `c` for the `coeff` and then
proving that this value is non-zero by `coeff_ne_zero`.
-/
theorem natDegree_eq_of_le_of_coeff_ne_zero' {deg m o : ℕ} {c : R} {p : R[X]}
(h_natDeg_le : natDegree p ≤ m) (coeff_eq : coeff p o = c)
(coeff_ne_zero : c ≠ 0) (deg_eq_deg : m = deg) (coeff_eq_deg : o = deg) :
natDegree p = deg := by
subst coeff_eq deg_eq_deg coeff_eq_deg
exact natDegree_eq_of_le_of_coeff_ne_zero ‹_› ‹_›
theorem degree_eq_of_le_of_coeff_ne_zero' {deg m o : WithBot ℕ} {c : R} {p : R[X]}
(h_deg_le : degree p ≤ m) (coeff_eq : coeff p (WithBot.unbotD 0 deg) = c)
(coeff_ne_zero : c ≠ 0) (deg_eq_deg : m = deg) (coeff_eq_deg : o = deg) :
| degree p = deg := by
subst coeff_eq coeff_eq_deg deg_eq_deg
rcases eq_or_ne m ⊥ with rfl|hh
· exact bot_unique h_deg_le
· obtain ⟨m, rfl⟩ := WithBot.ne_bot_iff_exists.mp hh
exact degree_eq_of_le_of_coeff_ne_zero ‹_› ‹_›
variable {m n : ℕ} {f : R[X]} {r : R}
| Mathlib/Tactic/ComputeDegree.lean | 157 | 165 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Shing Tak Lam, Yury Kudryashov
-/
import Mathlib.Algebra.MvPolynomial.Derivation
import Mathlib.Algebra.MvPolynomial.Variables
/-!
# Partial derivatives of polynomials
This file defines the notion of the formal *partial derivative* of a polynomial,
the derivative with respect to a single variable.
This derivative is not connected to the notion of derivative from analysis.
It is based purely on the polynomial exponents and coefficients.
## Main declarations
* `MvPolynomial.pderiv i p` : the partial derivative of `p` with respect to `i`, as a bundled
derivation of `MvPolynomial σ R`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommRing R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
universe u v
namespace MvPolynomial
open Set Function Finsupp
variable {R : Type u} {σ : Type v} {a a' a₁ a₂ : R} {s : σ →₀ ℕ}
section PDeriv
variable [CommSemiring R]
/-- `pderiv i p` is the partial derivative of `p` with respect to `i` -/
def pderiv (i : σ) : Derivation R (MvPolynomial σ R) (MvPolynomial σ R) :=
letI := Classical.decEq σ
mkDerivation R <| Pi.single i 1
theorem pderiv_def [DecidableEq σ] (i : σ) : pderiv i = mkDerivation R (Pi.single i 1) := by
unfold pderiv; congr!
@[simp]
theorem pderiv_monomial {i : σ} :
pderiv i (monomial s a) = monomial (s - single i 1) (a * s i) := by
classical
simp only [pderiv_def, mkDerivation_monomial, Finsupp.smul_sum, smul_eq_mul, ← smul_mul_assoc,
← (monomial _).map_smul]
refine (Finset.sum_eq_single i (fun j _ hne => ?_) fun hi => ?_).trans ?_
· simp [Pi.single_eq_of_ne hne]
· rw [Finsupp.not_mem_support_iff] at hi; simp [hi]
· simp
lemma X_mul_pderiv_monomial {i : σ} {m : σ →₀ ℕ} {r : R} :
X i * pderiv i (monomial m r) = m i • monomial m r := by
rw [pderiv_monomial, X, monomial_mul, smul_monomial]
by_cases h : m i = 0
· simp_rw [h, Nat.cast_zero, mul_zero, zero_smul, monomial_zero]
rw [one_mul, mul_comm, nsmul_eq_mul, add_comm, sub_add_single_one_cancel h]
theorem pderiv_C {i : σ} : pderiv i (C a) = 0 :=
derivation_C _ _
theorem pderiv_one {i : σ} : pderiv i (1 : MvPolynomial σ R) = 0 := pderiv_C
@[simp]
theorem pderiv_X [DecidableEq σ] (i j : σ) :
pderiv i (X j : MvPolynomial σ R) = Pi.single (f := fun _ => _) i 1 j := by
rw [pderiv_def, mkDerivation_X]
@[simp]
theorem pderiv_X_self (i : σ) : pderiv i (X i : MvPolynomial σ R) = 1 := by classical simp
@[simp]
theorem pderiv_X_of_ne {i j : σ} (h : j ≠ i) : pderiv i (X j : MvPolynomial σ R) = 0 := by
classical simp [h]
theorem pderiv_eq_zero_of_not_mem_vars {i : σ} {f : MvPolynomial σ R} (h : i ∉ f.vars) :
pderiv i f = 0 :=
| derivation_eq_zero_of_forall_mem_vars fun _ hj => pderiv_X_of_ne <| ne_of_mem_of_not_mem hj h
| Mathlib/Algebra/MvPolynomial/PDeriv.lean | 101 | 102 |
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.NormedSpace.IndicatorFunction
import Mathlib.Data.Fintype.Order
import Mathlib.MeasureTheory.Function.AEEqFun
import Mathlib.MeasureTheory.Function.LpSeminorm.Defs
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Integral.Lebesgue.Sub
/-!
# Basic theorems about ℒp space
-/
noncomputable section
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology ComplexConjugate
variable {α ε ε' E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm ε] [ENorm ε']
namespace MeasureTheory
section Lp
section Top
theorem MemLp.eLpNorm_lt_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ < ∞ :=
hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top
theorem MemLp.eLpNorm_ne_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) :
eLpNorm f p μ ≠ ∞ :=
ne_of_lt hfp.2
@[deprecated (since := "2025-02-21")]
alias Memℒp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : α → ε} (hq0_lt : 0 < q)
(hfq : eLpNorm' f q μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ q ∂μ < ∞ := by
rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt]
exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq)
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' :=
lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) (hfp : eLpNorm f p μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ p.toReal ∂μ < ∞ := by
apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top
· simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top :=
lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top
theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) : eLpNorm f p μ < ∞ ↔ ∫⁻ a, (‖f a‖ₑ) ^ p.toReal ∂μ < ∞ :=
⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by
intro h
have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top
have : 0 < 1 / p.toReal := div_pos zero_lt_one hp'
simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using
ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩
@[deprecated (since := "2025-02-04")] alias
eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top
end Top
section Zero
@[simp]
theorem eLpNorm'_exponent_zero {f : α → ε} : eLpNorm' f 0 μ = 1 := by
rw [eLpNorm', div_zero, ENNReal.rpow_zero]
@[simp]
theorem eLpNorm_exponent_zero {f : α → ε} : eLpNorm f 0 μ = 0 := by simp [eLpNorm]
@[simp]
theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace ε] {f : α → ε} :
MemLp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [MemLp, eLpNorm_exponent_zero]
@[deprecated (since := "2025-02-21")]
alias memℒp_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable
section ENormedAddMonoid
variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε]
@[simp]
theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : α → ε) q μ = 0 := by
simp [eLpNorm'_eq_lintegral_enorm, hp0_lt]
@[simp]
theorem eLpNorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : eLpNorm' (0 : α → ε) q μ = 0 := by
rcases le_or_lt 0 q with hq0 | hq_neg
· exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm)
· simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hμ, hq_neg]
@[simp]
theorem eLpNormEssSup_zero : eLpNormEssSup (0 : α → ε) μ = 0 := by
simp [eLpNormEssSup, ← bot_eq_zero', essSup_const_bot]
@[simp]
theorem eLpNorm_zero : eLpNorm (0 : α → ε) p μ = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero]
rw [← Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top]
@[simp]
theorem eLpNorm_zero' : eLpNorm (fun _ : α => (0 : ε)) p μ = 0 := eLpNorm_zero
@[simp] lemma MemLp.zero : MemLp (0 : α → ε) p μ :=
⟨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_top⟩
@[simp] lemma MemLp.zero' : MemLp (fun _ : α => (0 : ε)) p μ := MemLp.zero
@[deprecated (since := "2025-02-21")]
alias Memℒp.zero' := MemLp.zero'
@[deprecated (since := "2025-01-21")] alias zero_memℒp := MemLp.zero
@[deprecated (since := "2025-01-21")] alias zero_mem_ℒp := MemLp.zero'
variable [MeasurableSpace α]
theorem eLpNorm'_measure_zero_of_pos {f : α → ε} (hq_pos : 0 < q) :
eLpNorm' f q (0 : Measure α) = 0 := by simp [eLpNorm', hq_pos]
theorem eLpNorm'_measure_zero_of_exponent_zero {f : α → ε} : eLpNorm' f 0 (0 : Measure α) = 1 := by
simp [eLpNorm']
theorem eLpNorm'_measure_zero_of_neg {f : α → ε} (hq_neg : q < 0) :
eLpNorm' f q (0 : Measure α) = ∞ := by simp [eLpNorm', hq_neg]
end ENormedAddMonoid
@[simp]
theorem eLpNormEssSup_measure_zero {f : α → ε} : eLpNormEssSup f (0 : Measure α) = 0 := by
simp [eLpNormEssSup]
@[simp]
theorem eLpNorm_measure_zero {f : α → ε} : eLpNorm f p (0 : Measure α) = 0 := by
by_cases h0 : p = 0
· simp [h0]
by_cases h_top : p = ∞
· simp [h_top]
rw [← Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top]
section ContinuousENorm
variable {ε : Type*} [TopologicalSpace ε] [ContinuousENorm ε]
@[simp] lemma memLp_measure_zero {f : α → ε} : MemLp f p (0 : Measure α) := by
simp [MemLp]
@[deprecated (since := "2025-02-21")]
alias memℒp_measure_zero := memLp_measure_zero
end ContinuousENorm
end Zero
section Neg
| @[simp]
| Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean | 179 | 179 |
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Johan Commelin, Patrick Massot
-/
import Mathlib.Algebra.GroupWithZero.InjSurj
import Mathlib.Algebra.GroupWithZero.Units.Equiv
import Mathlib.Algebra.GroupWithZero.WithZero
import Mathlib.Algebra.Order.AddGroupWithTop
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.OrderIso
import Mathlib.Algebra.Order.Monoid.Basic
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Algebra.Order.Monoid.TypeTags
/-!
# Linearly ordered commutative groups and monoids with a zero element adjoined
This file sets up a special class of linearly ordered commutative monoids
that show up as the target of so-called “valuations” in algebraic number theory.
Usually, in the informal literature, these objects are constructed
by taking a linearly ordered commutative group Γ and formally adjoining a zero element: Γ ∪ {0}.
The disadvantage is that a type such as `NNReal` is not of that form,
whereas it is a very common target for valuations.
The solutions is to use a typeclass, and that is exactly what we do in this file.
-/
variable {α : Type*}
/-- A linearly ordered commutative monoid with a zero element. -/
class LinearOrderedCommMonoidWithZero (α : Type*) extends CommMonoidWithZero α, LinearOrder α,
IsOrderedMonoid α, OrderBot α where
/-- `0 ≤ 1` in any linearly ordered commutative monoid. -/
zero_le_one : (0 : α) ≤ 1
/-- A linearly ordered commutative group with a zero element. -/
class LinearOrderedCommGroupWithZero (α : Type*) extends LinearOrderedCommMonoidWithZero α,
CommGroupWithZero α
instance (priority := 100) LinearOrderedCommMonoidWithZero.toZeroLeOneClass
[LinearOrderedCommMonoidWithZero α] : ZeroLEOneClass α :=
{ ‹LinearOrderedCommMonoidWithZero α› with }
instance (priority := 100) CanonicallyOrderedAdd.toZeroLeOneClass
[AddZeroClass α] [LE α] [CanonicallyOrderedAdd α] [One α] : ZeroLEOneClass α :=
⟨zero_le 1⟩
section LinearOrderedCommMonoidWithZero
variable [LinearOrderedCommMonoidWithZero α] {a b : α} {n : ℕ}
/-
The following facts are true more generally in a (linearly) ordered commutative monoid.
-/
/-- Pullback a `LinearOrderedCommMonoidWithZero` under an injective map.
See note [reducible non-instances]. -/
abbrev Function.Injective.linearOrderedCommMonoidWithZero {β : Type*} [Zero β] [Bot β] [One β]
[Mul β] [Pow β ℕ] [Max β] [Min β] (f : β → α) (hf : Function.Injective f) (zero : f 0 = 0)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) (npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y))
(bot : f ⊥ = ⊥) : LinearOrderedCommMonoidWithZero β where
__ := LinearOrder.lift f hf hsup hinf
__ := hf.isOrderedMonoid f one mul npow
__ := hf.commMonoidWithZero f zero one mul npow
zero_le_one :=
show f 0 ≤ f 1 by simp only [zero, one, LinearOrderedCommMonoidWithZero.zero_le_one]
bot_le a := show f ⊥ ≤ f a from bot ▸ bot_le
@[simp] lemma zero_le' : 0 ≤ a := by
simpa only [mul_zero, mul_one] using mul_le_mul_left' (zero_le_one' α) a
@[simp]
theorem not_lt_zero' : ¬a < 0 :=
not_lt_of_le zero_le'
@[simp]
theorem le_zero_iff : a ≤ 0 ↔ a = 0 :=
⟨fun h ↦ le_antisymm h zero_le', fun h ↦ h ▸ le_rfl⟩
theorem zero_lt_iff : 0 < a ↔ a ≠ 0 :=
⟨ne_of_gt, fun h ↦ lt_of_le_of_ne zero_le' h.symm⟩
theorem ne_zero_of_lt (h : b < a) : a ≠ 0 := fun h1 ↦ not_lt_zero' <| show b < 0 from h1 ▸ h
/-- See also `bot_eq_zero` and `bot_eq_zero'` for canonically ordered monoids. -/
lemma bot_eq_zero'' : (⊥ : α) = 0 := eq_of_forall_ge_iff fun _ ↦ by simp
instance instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual :
LinearOrderedAddCommMonoidWithTop (Additive αᵒᵈ) where
top := .ofMul <| .toDual 0
top_add' a := zero_mul a.toMul.ofDual
le_top _ := zero_le'
instance instLinearOrderedAddCommMonoidWithTopOrderDualAdditive :
LinearOrderedAddCommMonoidWithTop (Additive α)ᵒᵈ where
top := .toDual <| .ofMul _
top_add' := fun a ↦ zero_mul (Additive.toMul (OrderDual.ofDual a))
le_top := fun a ↦ @zero_le' _ _ (Additive.toMul (OrderDual.ofDual a))
variable [NoZeroDivisors α]
lemma pow_pos_iff (hn : n ≠ 0) : 0 < a ^ n ↔ 0 < a := by simp_rw [zero_lt_iff, pow_ne_zero_iff hn]
end LinearOrderedCommMonoidWithZero
section LinearOrderedCommGroupWithZero
variable [LinearOrderedCommGroupWithZero α] {a b c d : α} {m n : ℕ}
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toMulPosMono : MulPosMono α where
elim _a _b _c hbc := mul_le_mul_right' hbc _
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulMono : PosMulMono α where
elim _a _b _c hbc := mul_le_mul_left' hbc _
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulReflectLE :
PosMulReflectLE α where
elim a b c hbc := by simpa [a.2.ne'] using mul_le_mul_left' hbc a⁻¹
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toMulPosReflectLE :
MulPosReflectLE α where
elim a b c hbc := by simpa [a.2.ne'] using mul_le_mul_right' hbc a⁻¹
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulReflectLT :
PosMulReflectLT α where elim _a _b _c := lt_of_mul_lt_mul_left'
#adaptation_note /-- 2025-03-29 lean4#7717 Needed to add `dsimp only` -/
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toPosMulStrictMono :
PosMulStrictMono α where
elim a b c hbc := by dsimp only; by_contra! h; exact hbc.not_le <| (mul_le_mul_left a.2).1 h
#adaptation_note /-- 2025-03-29 lean4#7717 Needed to add `dsimp only` -/
-- See note [lower instance priority]
instance (priority := 100) LinearOrderedCommGroupWithZero.toMulPosStrictMono :
MulPosStrictMono α where
elim a b c hbc := by dsimp only; by_contra! h; exact hbc.not_le <| (mul_le_mul_right a.2).1 h
@[deprecated mul_inv_le_of_le_mul₀ (since := "2024-11-18")]
theorem mul_inv_le_of_le_mul (hab : a ≤ b * c) : a * c⁻¹ ≤ b :=
mul_inv_le_of_le_mul₀ zero_le' zero_le' hab
@[simp]
theorem Units.zero_lt (u : αˣ) : (0 : α) < u :=
zero_lt_iff.2 u.ne_zero
@[deprecated mul_lt_mul_of_le_of_lt_of_nonneg_of_pos (since := "2024-11-18")]
theorem mul_lt_mul_of_lt_of_le₀ (hab : a ≤ b) (hb : b ≠ 0) (hcd : c < d) : a * c < b * d :=
mul_lt_mul_of_le_of_lt_of_nonneg_of_pos hab hcd zero_le' (zero_lt_iff.2 hb)
@[deprecated mul_lt_mul'' (since := "2024-11-18")]
theorem mul_lt_mul₀ (hab : a < b) (hcd : c < d) : a * c < b * d :=
mul_lt_mul'' hab hcd zero_le' zero_le'
theorem mul_inv_lt_of_lt_mul₀ (h : a < b * c) : a * c⁻¹ < b := by
contrapose! h
simpa only [inv_inv] using mul_inv_le_of_le_mul₀ zero_le' zero_le' h
theorem inv_mul_lt_of_lt_mul₀ (h : a < b * c) : b⁻¹ * a < c := by
rw [mul_comm] at *
exact mul_inv_lt_of_lt_mul₀ h
theorem lt_of_mul_lt_mul_of_le₀ (h : a * b < c * d) (hc : 0 < c) (hh : c ≤ a) : b < d := by
have ha : a ≠ 0 := ne_of_gt (lt_of_lt_of_le hc hh)
rw [← inv_le_inv₀ (zero_lt_iff.2 ha) hc] at hh
simpa [inv_mul_cancel_left₀ ha, inv_mul_cancel_left₀ hc.ne']
using mul_lt_mul_of_le_of_lt_of_nonneg_of_pos hh h zero_le' (inv_pos.2 hc)
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-18")]
theorem div_le_div_right₀ (hc : c ≠ 0) : a / c ≤ b / c ↔ a ≤ b :=
div_le_div_iff_of_pos_right (zero_lt_iff.2 hc)
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-18")]
theorem div_le_div_left₀ (ha : a ≠ 0) (hb : b ≠ 0) (hc : c ≠ 0) : a / b ≤ a / c ↔ c ≤ b :=
div_le_div_iff_of_pos_left (zero_lt_iff.2 ha) (zero_lt_iff.2 hb) (zero_lt_iff.2 hc)
/-- `Equiv.mulLeft₀` as an `OrderIso` on a `LinearOrderedCommGroupWithZero.`. -/
@[simps! +simpRhs apply toEquiv,
deprecated OrderIso.mulLeft₀ (since := "2024-11-18")]
def OrderIso.mulLeft₀' {a : α} (ha : a ≠ 0) : α ≃o α := .mulLeft₀ a (zero_lt_iff.2 ha)
set_option linter.deprecated false in
@[deprecated OrderIso.mulLeft₀_symm (since := "2024-11-18")]
theorem OrderIso.mulLeft₀'_symm {a : α} (ha : a ≠ 0) :
(OrderIso.mulLeft₀' ha).symm = OrderIso.mulLeft₀' (inv_ne_zero ha) := by
ext
rfl
/-- `Equiv.mulRight₀` as an `OrderIso` on a `LinearOrderedCommGroupWithZero.`. -/
@[simps! +simpRhs apply toEquiv,
deprecated OrderIso.mulRight₀ (since := "2024-11-18")]
def OrderIso.mulRight₀' {a : α} (ha : a ≠ 0) : α ≃o α := .mulRight₀ a (zero_lt_iff.2 ha)
set_option linter.deprecated false in
@[deprecated OrderIso.mulRight₀_symm (since := "2024-11-18")]
theorem OrderIso.mulRight₀'_symm {a : α} (ha : a ≠ 0) :
(OrderIso.mulRight₀' ha).symm = OrderIso.mulRight₀' (inv_ne_zero ha) := by
ext
rfl
instance : LinearOrderedAddCommGroupWithTop (Additive αᵒᵈ) where
neg_top := inv_zero (G₀ := α)
add_neg_cancel := fun a ha ↦ mul_inv_cancel₀ (G₀ := α) (id ha : a.toMul ≠ 0)
instance : LinearOrderedAddCommGroupWithTop (Additive α)ᵒᵈ where
neg_top := inv_zero (G₀ := α)
add_neg_cancel := fun a ha ↦ mul_inv_cancel₀ (G₀ := α) (id ha : a.toMul ≠ 0)
@[deprecated pow_lt_pow_right₀ (since := "2024-11-18")]
lemma pow_lt_pow_succ (ha : 1 < a) : a ^ n < a ^ n.succ := pow_lt_pow_right₀ ha n.lt_succ_self
end LinearOrderedCommGroupWithZero
instance instLinearOrderedCommMonoidWithZeroMultiplicativeOrderDual
[LinearOrderedAddCommMonoidWithTop α] :
LinearOrderedCommMonoidWithZero (Multiplicative αᵒᵈ) where
zero := Multiplicative.ofAdd (OrderDual.toDual ⊤)
zero_mul := @top_add _ (_)
-- Porting note: Here and elsewhere in the file, just `zero_mul` worked in Lean 3. See
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Type.20synonyms
mul_zero := @add_top _ (_)
zero_le_one := (le_top : (0 : α) ≤ ⊤)
@[simp]
theorem ofAdd_toDual_eq_zero_iff [LinearOrderedAddCommMonoidWithTop α]
(x : α) : Multiplicative.ofAdd (OrderDual.toDual x) = 0 ↔ x = ⊤ := Iff.rfl
@[simp]
theorem ofDual_toAdd_eq_top_iff [LinearOrderedAddCommMonoidWithTop α]
(x : Multiplicative αᵒᵈ) : OrderDual.ofDual x.toAdd = ⊤ ↔ x = 0 := Iff.rfl
@[simp]
theorem ofAdd_bot [LinearOrderedAddCommMonoidWithTop α] :
Multiplicative.ofAdd ⊥ = (0 : Multiplicative αᵒᵈ) := rfl
@[simp]
theorem ofDual_toAdd_zero [LinearOrderedAddCommMonoidWithTop α] :
OrderDual.ofDual (0 : Multiplicative αᵒᵈ).toAdd = ⊤ := rfl
|
instance [LinearOrderedAddCommGroupWithTop α] :
| Mathlib/Algebra/Order/GroupWithZero/Canonical.lean | 243 | 244 |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.GCDMonoid.Finset
import Mathlib.Algebra.Polynomial.CancelLeads
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Algebra.Polynomial.FieldDivision
/-!
# GCD structures on polynomials
Definitions and basic results about polynomials over GCD domains, particularly their contents
and primitive polynomials.
## Main Definitions
Let `p : R[X]`.
- `p.content` is the `gcd` of the coefficients of `p`.
- `p.IsPrimitive` indicates that `p.content = 1`.
## Main Results
- `Polynomial.content_mul`:
If `p q : R[X]`, then `(p * q).content = p.content * q.content`.
- `Polynomial.NormalizedGcdMonoid`:
The polynomial ring of a GCD domain is itself a GCD domain.
## Note
This has nothing to do with minimal polynomials of primitive elements in finite fields.
-/
namespace Polynomial
section Primitive
variable {R : Type*} [CommSemiring R]
/-- A polynomial is primitive when the only constant polynomials dividing it are units.
Note: This has nothing to do with minimal polynomials of primitive elements in finite fields. -/
def IsPrimitive (p : R[X]) : Prop :=
∀ r : R, C r ∣ p → IsUnit r
theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ ∀ r : R, C r ∣ p → IsUnit r :=
Iff.rfl
@[simp]
theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h =>
isUnit_C.mp (isUnit_of_dvd_one h)
theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by
rintro r ⟨q, h⟩
exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h])
theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p ≠ 0 := by
rintro rfl
exact (hp 0 (dvd_zero (C 0))).ne_zero rfl
theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q :=
fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq)
/-- An irreducible nonconstant polynomial over a domain is primitive. -/
theorem _root_.Irreducible.isPrimitive [NoZeroDivisors R]
{p : Polynomial R} (hp : Irreducible p) (hp' : p.natDegree ≠ 0) : p.IsPrimitive := by
rintro r ⟨q, hq⟩
suffices ¬IsUnit q by simpa using ((hp.2 hq).resolve_right this).map Polynomial.constantCoeff
intro H
have hr : r ≠ 0 := by rintro rfl; simp_all
obtain ⟨s, hs, rfl⟩ := Polynomial.isUnit_iff.mp H
simp [hq, Polynomial.natDegree_C_mul hr] at hp'
end Primitive
variable {R : Type*} [CommRing R] [IsDomain R]
section NormalizedGCDMonoid
variable [NormalizedGCDMonoid R]
/-- `p.content` is the `gcd` of the coefficients of `p`. -/
def content (p : R[X]) : R :=
p.support.gcd p.coeff
theorem content_dvd_coeff {p : R[X]} (n : ℕ) : p.content ∣ p.coeff n := by
by_cases h : n ∈ p.support
· apply Finset.gcd_dvd h
rw [mem_support_iff, Classical.not_not] at h
rw [h]
apply dvd_zero
@[simp]
theorem content_C {r : R} : (C r).content = normalize r := by
rw [content]
by_cases h0 : r = 0
· simp [h0]
have h : (C r).support = {0} := support_monomial _ h0
simp [h]
@[simp]
theorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero]
@[simp]
theorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one]
theorem content_X_mul {p : R[X]} : content (X * p) = content p := by
rw [content, content, Finset.gcd_def, Finset.gcd_def]
refine congr rfl ?_
have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ := by
ext a
simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff]
rcases a with - | a
· simp [coeff_X_mul_zero, Nat.succ_ne_zero]
rw [mul_comm, coeff_mul_X]
constructor
· intro h
use a
· rintro ⟨b, ⟨h1, h2⟩⟩
rw [← Nat.succ_injective h2]
apply h1
rw [h]
simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map]
refine congr (congr rfl ?_) rfl
ext a
rw [mul_comm]
simp [coeff_mul_X]
@[simp]
theorem content_X_pow {k : ℕ} : content ((X : R[X]) ^ k) = 1 := by
induction' k with k hi
· simp
rw [pow_succ', content_X_mul, hi]
@[simp]
theorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one]
theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by
by_cases h0 : r = 0; · simp [h0]
rw [content]; rw [content]; rw [← Finset.gcd_mul_left]
refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff]
@[simp]
theorem content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by
rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one]
theorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by
rw [content, Finset.gcd_eq_zero_iff]
constructor <;> intro h
· ext n
by_cases h0 : n ∈ p.support
· rw [h n h0, coeff_zero]
· rw [mem_support_iff] at h0
push_neg at h0
simp [h0]
· intro x
simp [h]
-- Porting note: this reduced with simp so created `normUnit_content` and put simp on it
theorem normalize_content {p : R[X]} : normalize p.content = p.content :=
Finset.normalize_gcd
@[simp]
theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by
by_cases hp0 : p.content = 0
· simp [hp0]
· ext
apply mul_left_cancel₀ hp0
rw [← normalize_apply, normalize_content, Units.val_one, mul_one]
theorem content_eq_gcd_range_of_lt (p : R[X]) (n : ℕ) (h : p.natDegree < n) :
p.content = (Finset.range n).gcd p.coeff := by
apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd
· rw [Finset.dvd_gcd_iff]
intro i _
apply content_dvd_coeff _
· apply Finset.gcd_mono
intro i
simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range]
contrapose!
intro h1
apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1)
theorem content_eq_gcd_range_succ (p : R[X]) :
p.content = (Finset.range p.natDegree.succ).gcd p.coeff :=
content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _)
theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) :
p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by
by_cases h : p = 0
· simp [h]
rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne, ← mem_support_iff] at h
rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content,
eraseLead_support]
refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_)
rw [Finset.mem_erase] at hi
rw [eraseLead_coeff, if_neg hi.1]
theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by
rw [C_dvd_iff_dvd_coeff]
constructor
· intro h i
apply h.trans (content_dvd_coeff _)
· intro h
rw [content, Finset.dvd_gcd_iff]
intro i _
apply h i
theorem C_content_dvd (p : R[X]) : C p.content ∣ p :=
dvd_content_iff_C_dvd.1 dvd_rfl
theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by
rw [← normalize_content, normalize_eq_one, IsPrimitive]
simp_rw [← dvd_content_iff_C_dvd]
exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩
theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 :=
isPrimitive_iff_content_eq_one.mp hp
section PrimPart
/-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by
`p.content`. If `p = 0`, then `p.primPart = 1`. -/
noncomputable def primPart (p : R[X]) : R[X] :=
letI := Classical.decEq R
if p = 0 then 1 else Classical.choose (C_content_dvd p)
theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by
by_cases h : p = 0; · simp [h]
rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)]
@[simp]
theorem primPart_zero : primPart (0 : R[X]) = 1 :=
if_pos rfl
theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by
by_cases h : p = 0; · simp [h]
rw [← content_eq_zero_iff] at h
rw [isPrimitive_iff_content_eq_one]
apply mul_left_cancel₀ h
conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content]
theorem content_primPart (p : R[X]) : p.primPart.content = 1 :=
p.isPrimitive_primPart.content_eq_one
theorem primPart_ne_zero (p : R[X]) : p.primPart ≠ 0 :=
p.isPrimitive_primPart.ne_zero
theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by
by_cases h : C p.content = 0
· rw [C_eq_zero, content_eq_zero_iff] at h
simp [h]
conv_rhs =>
rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add]
@[simp]
theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by
rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart]
theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by
by_cases h0 : r = 0
· simp [h0]
unfold IsUnit
refine
⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by
rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩,
?_⟩
rw [← normalize_eq_zero, ← C_eq_zero] at h0
apply mul_left_cancel₀ h0
conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart]
simp only [Units.val_mk, normalize_apply, RingHom.map_mul]
rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one]
theorem primPart_dvd (p : R[X]) : p.primPart ∣ p :=
Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm
theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S]
[NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : aeval s p = 0) :
aeval s p.primPart = 0 := by
rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp
have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h)
replace hcont := Function.Injective.ne (FaithfulSMul.algebraMap_injective R S) hcont
rw [map_zero] at hcont
exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp
theorem eval₂_primPart_eq_zero {S : Type*} [CommSemiring S] [IsDomain S] {f : R →+* S}
(hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p ≠ 0) (hp : eval₂ f s p = 0) :
eval₂ f s p.primPart = 0 := by
rw [eq_C_content_mul_primPart p, eval₂_mul, eval₂_C] at hp
have hcont : p.content ≠ 0 := fun h => hpzero (content_eq_zero_iff.1 h)
replace hcont := Function.Injective.ne hinj hcont
rw [map_zero] at hcont
exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp
end PrimPart
theorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) :
GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by
rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).succ
(lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))]
rw [content_eq_gcd_range_of_lt q (max p.natDegree q.natDegree).succ
(lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))]
apply Finset.gcd_eq_of_dvd_sub
intro x _
obtain ⟨w, hw⟩ := h
use w.coeff x
rw [← coeff_sub, hw, coeff_C_mul]
theorem content_mul_aux {p q : R[X]} :
GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff =
GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff := by
rw [gcd_comm (content _) _, gcd_comm (content _) _]
apply gcd_content_eq_of_dvd_sub
rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,
sub_sub_cancel, leadingCoeff_mul, RingHom.map_mul, mul_assoc, mul_assoc]
apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl)
@[simp]
theorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by
classical
suffices h :
∀ (n : ℕ) (p q : R[X]), (p * q).degree < n → (p * q).content = p.content * q.content by
apply h
apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _))
intro n
induction' n with n ih
· intro p q hpq
rw [Nat.cast_zero,
Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq
rcases hpq with (rfl | rfl) <;> simp
intro p q hpq
by_cases p0 : p = 0
· simp [p0]
by_cases q0 : q = 0
· simp [q0]
rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_lt,
Nat.lt_succ_iff_lt_or_eq, ← Nat.cast_lt (α := WithBot ℕ),
← degree_eq_natDegree (mul_ne_zero p0 q0), natDegree_mul p0 q0] at hpq
rcases hpq with (hlt | heq)
· apply ih _ _ hlt
rw [← p.natDegree_primPart, ← q.natDegree_primPart, ← Nat.cast_inj (R := WithBot ℕ),
Nat.cast_add, ← degree_eq_natDegree p.primPart_ne_zero,
← degree_eq_natDegree q.primPart_ne_zero] at heq
rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart]
suffices h : (q.primPart * p.primPart).content = 1 by
rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul,
content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one]
rw [← normalize_content, normalize_eq_one, isUnit_iff_dvd_one,
content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm]
apply (gcd_mul_dvd_mul_gcd _ _ _).trans
rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ←
content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul,
mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ←
content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart]
· rw [← heq, degree_mul, WithBot.add_lt_add_iff_right]
· apply degree_erase_lt p.primPart_ne_zero
· rw [Ne, degree_eq_bot]
apply q.primPart_ne_zero
· rw [mul_comm, ← heq, degree_mul, WithBot.add_lt_add_iff_left]
· apply degree_erase_lt q.primPart_ne_zero
· rw [Ne, degree_eq_bot]
apply p.primPart_ne_zero
theorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :
(p * q).IsPrimitive := by
rw [isPrimitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]
@[simp]
theorem primPart_mul {p q : R[X]} (h0 : p * q ≠ 0) :
(p * q).primPart = p.primPart * q.primPart := by
rw [Ne, ← content_eq_zero_iff, ← C_eq_zero] at h0
apply mul_left_cancel₀ h0
conv_lhs =>
rw [← (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_primPart,
q.eq_C_content_mul_primPart]
rw [content_mul, RingHom.map_mul]
ring
theorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q ≠ 0) :
p ∣ q.primPart ↔ p ∣ q := by
refine ⟨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => ?_⟩
rcases h with ⟨r, rfl⟩
apply Dvd.intro _
rw [primPart_mul hq, hp.primPart_eq]
theorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :
∃ r : R[X], r.IsPrimitive ∧ ∀ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s := by
classical
have h : ∃ (n : ℕ) (r : R[X]), r.natDegree = n ∧ r.IsPrimitive ∧ p ∣ r ∧ q ∣ r :=
⟨(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩
rcases Nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩
refine ⟨r, rprim, fun s => ⟨?_, fun rs => ⟨pr.trans rs, qr.trans rs⟩⟩⟩
suffices hs : ∀ (n : ℕ) (s : R[X]), s.natDegree = n → p ∣ s ∧ q ∣ s → r ∣ s from
hs s.natDegree s rfl
clear s
by_contra! con
rcases Nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩
have s0 : s ≠ 0 := by
contrapose! rs
simp [rs]
have hs :=
Nat.find_min' h
⟨_, s.natDegree_primPart, s.isPrimitive_primPart, (hp.dvd_primPart_iff_dvd s0).2 ps,
(hq.dvd_primPart_iff_dvd s0).2 qs⟩
rw [← rdeg] at hs
by_cases sC : s.natDegree ≤ 0
· rw [eq_C_of_natDegree_le_zero (le_trans hs sC), isPrimitive_iff_content_eq_one, content_C,
normalize_eq_one] at rprim
rw [eq_C_of_natDegree_le_zero (le_trans hs sC), ← dvd_content_iff_C_dvd] at rs
apply rs rprim.dvd
have hcancel := natDegree_cancelLeads_lt_of_natDegree_le_natDegree hs (lt_of_not_ge sC)
rw [sdeg] at hcancel
apply Nat.find_min con hcancel
refine
⟨_, rfl, ⟨dvd_cancelLeads_of_dvd_of_dvd pr ps, dvd_cancelLeads_of_dvd_of_dvd qr qs⟩,
fun rcs => rs ?_⟩
rw [← rprim.dvd_primPart_iff_dvd s0]
rw [cancelLeads, tsub_eq_zero_iff_le.mpr hs, pow_zero, mul_one] at rcs
have h :=
dvd_add rcs (Dvd.intro_left (C (leadingCoeff s) * X ^ (natDegree s - natDegree r)) rfl)
have hC0 := rprim.ne_zero
rw [Ne, ← leadingCoeff_eq_zero, ← C_eq_zero] at hC0
rw [sub_add_cancel, ← rprim.dvd_primPart_iff_dvd (mul_ne_zero hC0 s0)] at h
rcases isUnit_primPart_C r.leadingCoeff with ⟨u, hu⟩
apply h.trans (Associated.symm ⟨u, _⟩).dvd
rw [primPart_mul (mul_ne_zero hC0 s0), hu, mul_comm]
theorem dvd_iff_content_dvd_content_and_primPart_dvd_primPart {p q : R[X]} (hq : q ≠ 0) :
p ∣ q ↔ p.content ∣ q.content ∧ p.primPart ∣ q.primPart := by
constructor <;> intro h
· rcases h with ⟨r, rfl⟩
rw [content_mul, p.isPrimitive_primPart.dvd_primPart_iff_dvd hq]
exact ⟨Dvd.intro _ rfl, p.primPart_dvd.trans (Dvd.intro _ rfl)⟩
· rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart]
exact mul_dvd_mul (RingHom.map_dvd C h.1) h.2
noncomputable instance (priority := 100) normalizedGcdMonoid : NormalizedGCDMonoid R[X] :=
letI := Classical.decEq R
normalizedGCDMonoidOfExistsLCM fun p q => by
rcases exists_primitive_lcm_of_isPrimitive p.isPrimitive_primPart
q.isPrimitive_primPart with
⟨r, rprim, hr⟩
refine ⟨C (lcm p.content q.content) * r, fun s => ?_⟩
by_cases hs : s = 0
· simp [hs]
by_cases hpq : C (lcm p.content q.content) = 0
· rw [C_eq_zero, lcm_eq_zero_iff, content_eq_zero_iff, content_eq_zero_iff] at hpq
rcases hpq with (hpq | hpq) <;> simp [hpq, hs]
iterate 3 rw [dvd_iff_content_dvd_content_and_primPart_dvd_primPart hs]
rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff,
primPart_mul (mul_ne_zero hpq rprim.ne_zero), rprim.primPart_eq,
(isUnit_primPart_C (lcm p.content q.content)).mul_left_dvd, ← hr s.primPart]
tauto
theorem degree_gcd_le_left {p : R[X]} (hp : p ≠ 0) (q) : (gcd p q).degree ≤ p.degree := by
have := natDegree_le_iff_degree_le.mp (natDegree_le_of_dvd (gcd_dvd_left p q) hp)
rwa [degree_eq_natDegree hp]
theorem degree_gcd_le_right (p) {q : R[X]} (hq : q ≠ 0) : (gcd p q).degree ≤ q.degree := by
rw [gcd_comm]
exact degree_gcd_le_left hq p
end NormalizedGCDMonoid
end Polynomial
| Mathlib/RingTheory/Polynomial/Content.lean | 505 | 507 | |
/-
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, Heather Macbeth, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Analysis.Normed.Group.Uniform
import Mathlib.Topology.Instances.NNReal.Lemmas
/-!
# Infinite sums in (semi)normed groups
In a complete (semi)normed group,
- `summable_iff_vanishing_norm`: a series `∑' i, f i` is summable if and only if for any `ε > 0`,
there exists a finite set `s` such that the sum `∑ i ∈ t, f i` over any finite set `t` disjoint
with `s` has norm less than `ε`;
- `Summable.of_norm_bounded`, `Summable.of_norm_bounded_eventually`: if `‖f i‖` is bounded above by
a summable series `∑' i, g i`, then `∑' i, f i` is summable as well; the same is true if the
inequality hold only off some finite set.
- `tsum_of_norm_bounded`, `HasSum.norm_le_of_bounded`: if `‖f i‖ ≤ g i`, where `∑' i, g i` is a
summable series, then `‖∑' i, f i‖ ≤ ∑' i, g i`.
## Tags
infinite series, absolute convergence, normed group
-/
open Topology NNReal
open Finset Filter Metric
variable {ι α E F : Type*} [SeminormedAddCommGroup E] [SeminormedAddCommGroup F]
theorem cauchySeq_finset_iff_vanishing_norm {f : ι → E} :
(CauchySeq fun s : Finset ι => ∑ i ∈ s, f i) ↔
∀ ε > (0 : ℝ), ∃ s : Finset ι, ∀ t, Disjoint t s → ‖∑ i ∈ t, f i‖ < ε := by
rw [cauchySeq_finset_iff_sum_vanishing, nhds_basis_ball.forall_iff]
· simp only [ball_zero_eq, Set.mem_setOf_eq]
· rintro s t hst ⟨s', hs'⟩
exact ⟨s', fun t' ht' => hst <| hs' _ ht'⟩
theorem summable_iff_vanishing_norm [CompleteSpace E] {f : ι → E} :
Summable f ↔ ∀ ε > (0 : ℝ), ∃ s : Finset ι, ∀ t, Disjoint t s → ‖∑ i ∈ t, f i‖ < ε := by
rw [summable_iff_cauchySeq_finset, cauchySeq_finset_iff_vanishing_norm]
theorem cauchySeq_finset_of_norm_bounded_eventually {f : ι → E} {g : ι → ℝ} (hg : Summable g)
(h : ∀ᶠ i in cofinite, ‖f i‖ ≤ g i) : CauchySeq fun s => ∑ i ∈ s, f i := by
refine cauchySeq_finset_iff_vanishing_norm.2 fun ε hε => ?_
rcases summable_iff_vanishing_norm.1 hg ε hε with ⟨s, hs⟩
classical
refine ⟨s ∪ h.toFinset, fun t ht => ?_⟩
have : ∀ i ∈ t, ‖f i‖ ≤ g i := by
intro i hi
simp only [disjoint_left, mem_union, not_or, h.mem_toFinset, Set.mem_compl_iff,
Classical.not_not] at ht
exact (ht hi).2
calc
‖∑ i ∈ t, f i‖ ≤ ∑ i ∈ t, g i := norm_sum_le_of_le _ this
_ ≤ ‖∑ i ∈ t, g i‖ := le_abs_self _
_ < ε := hs _ (ht.mono_right le_sup_left)
theorem cauchySeq_finset_of_norm_bounded {f : ι → E} (g : ι → ℝ) (hg : Summable g)
(h : ∀ i, ‖f i‖ ≤ g i) : CauchySeq fun s : Finset ι => ∑ i ∈ s, f i :=
cauchySeq_finset_of_norm_bounded_eventually hg <| Eventually.of_forall h
/-- A version of the **direct comparison test** for conditionally convergent series.
See `cauchySeq_finset_of_norm_bounded` for the same statement about absolutely convergent ones. -/
theorem cauchySeq_range_of_norm_bounded {f : ℕ → E} (g : ℕ → ℝ)
(hg : CauchySeq fun n => ∑ i ∈ range n, g i) (hf : ∀ i, ‖f i‖ ≤ g i) :
CauchySeq fun n => ∑ i ∈ range n, f i := by
refine Metric.cauchySeq_iff'.2 fun ε hε => ?_
refine (Metric.cauchySeq_iff'.1 hg ε hε).imp fun N hg n hn => ?_
specialize hg n hn
rw [dist_eq_norm, ← sum_Ico_eq_sub _ hn] at hg ⊢
calc
‖∑ k ∈ Ico N n, f k‖ ≤ ∑ k ∈ _, ‖f k‖ := norm_sum_le _ _
_ ≤ ∑ k ∈ _, g k := sum_le_sum fun x _ => hf x
_ ≤ ‖∑ k ∈ _, g k‖ := le_abs_self _
_ < ε := hg
theorem cauchySeq_finset_of_summable_norm {f : ι → E} (hf : Summable fun a => ‖f a‖) :
CauchySeq fun s : Finset ι => ∑ a ∈ s, f a :=
cauchySeq_finset_of_norm_bounded _ hf fun _i => le_rfl
/-- If a function `f` is summable in norm, and along some sequence of finsets exhausting the space
its sum is converging to a limit `a`, then this holds along all finsets, i.e., `f` is summable
with sum `a`. -/
theorem hasSum_of_subseq_of_summable {f : ι → E} (hf : Summable fun a => ‖f a‖) {s : α → Finset ι}
{p : Filter α} [NeBot p] (hs : Tendsto s p atTop) {a : E}
(ha : Tendsto (fun b => ∑ i ∈ s b, f i) p (𝓝 a)) : HasSum f a :=
tendsto_nhds_of_cauchySeq_of_subseq (cauchySeq_finset_of_summable_norm hf) hs ha
theorem hasSum_iff_tendsto_nat_of_summable_norm {f : ℕ → E} {a : E} (hf : Summable fun i => ‖f i‖) :
HasSum f a ↔ Tendsto (fun n : ℕ => ∑ i ∈ range n, f i) atTop (𝓝 a) :=
⟨fun h => h.tendsto_sum_nat, fun h => hasSum_of_subseq_of_summable hf tendsto_finset_range h⟩
/-- The direct comparison test for series: if the norm of `f` is bounded by a real function `g`
which is summable, then `f` is summable. -/
theorem Summable.of_norm_bounded [CompleteSpace E] {f : ι → E} (g : ι → ℝ) (hg : Summable g)
(h : ∀ i, ‖f i‖ ≤ g i) : Summable f := by
rw [summable_iff_cauchySeq_finset]
exact cauchySeq_finset_of_norm_bounded g hg h
theorem HasSum.norm_le_of_bounded {f : ι → E} {g : ι → ℝ} {a : E} {b : ℝ} (hf : HasSum f a)
(hg : HasSum g b) (h : ∀ i, ‖f i‖ ≤ g i) : ‖a‖ ≤ b := by
classical exact le_of_tendsto_of_tendsto' hf.norm hg fun _s ↦ norm_sum_le_of_le _ fun i _hi ↦ h i
/-- Quantitative result associated to the direct comparison test for series: If `∑' i, g i` is
summable, and for all `i`, `‖f i‖ ≤ g i`, then `‖∑' i, f i‖ ≤ ∑' i, g i`. Note that we do not
assume that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete space. -/
theorem tsum_of_norm_bounded {f : ι → E} {g : ι → ℝ} {a : ℝ} (hg : HasSum g a)
(h : ∀ i, ‖f i‖ ≤ g i) : ‖∑' i : ι, f i‖ ≤ a := by
by_cases hf : Summable f
· exact hf.hasSum.norm_le_of_bounded hg h
· rw [tsum_eq_zero_of_not_summable hf, norm_zero]
classical exact ge_of_tendsto' hg fun s => sum_nonneg fun i _hi => (norm_nonneg _).trans (h i)
/-- If `∑' i, ‖f i‖` is summable, then `‖∑' i, f i‖ ≤ (∑' i, ‖f i‖)`. Note that we do not assume
that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete space. -/
theorem norm_tsum_le_tsum_norm {f : ι → E} (hf : Summable fun i => ‖f i‖) :
‖∑' i, f i‖ ≤ ∑' i, ‖f i‖ :=
tsum_of_norm_bounded hf.hasSum fun _i => le_rfl
/-- Quantitative result associated to the direct comparison test for series: If `∑' i, g i` is
summable, and for all `i`, `‖f i‖₊ ≤ g i`, then `‖∑' i, f i‖₊ ≤ ∑' i, g i`. Note that we
do not assume that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete
space. -/
theorem tsum_of_nnnorm_bounded {f : ι → E} {g : ι → ℝ≥0} {a : ℝ≥0} (hg : HasSum g a)
(h : ∀ i, ‖f i‖₊ ≤ g i) : ‖∑' i : ι, f i‖₊ ≤ a := by
simp only [← NNReal.coe_le_coe, ← NNReal.hasSum_coe, coe_nnnorm] at *
exact tsum_of_norm_bounded hg h
/-- If `∑' i, ‖f i‖₊` is summable, then `‖∑' i, f i‖₊ ≤ ∑' i, ‖f i‖₊`. Note that
we do not assume that `∑' i, f i` is summable, and it might not be the case if `α` is not a complete
space. -/
theorem nnnorm_tsum_le {f : ι → E} (hf : Summable fun i => ‖f i‖₊) : ‖∑' i, f i‖₊ ≤ ∑' i, ‖f i‖₊ :=
tsum_of_nnnorm_bounded hf.hasSum fun _i => le_rfl
variable [CompleteSpace E]
/-- Variant of the direct comparison test for series: if the norm of `f` is eventually bounded by a
real function `g` which is summable, then `f` is summable. -/
| theorem Summable.of_norm_bounded_eventually {f : ι → E} (g : ι → ℝ) (hg : Summable g)
(h : ∀ᶠ i in cofinite, ‖f i‖ ≤ g i) : Summable f :=
summable_iff_cauchySeq_finset.2 <| cauchySeq_finset_of_norm_bounded_eventually hg h
| Mathlib/Analysis/Normed/Group/InfiniteSum.lean | 146 | 149 |
/-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.CategoryTheory.GlueData
import Mathlib.Topology.Category.TopCat.Limits.Pullbacks
import Mathlib.Topology.Category.TopCat.Opens
import Mathlib.Tactic.Generalize
import Mathlib.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.ConcreteCategory.EpiMono
/-!
# Gluing Topological spaces
Given a family of gluing data (see `Mathlib/CategoryTheory/GlueData.lean`), we can then glue them
together.
The construction should be "sealed" and considered as a black box, while only using the API
provided.
## Main definitions
* `TopCat.GlueData`: A structure containing the family of gluing data.
* `CategoryTheory.GlueData.glued`: The glued topological space.
This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API
can be used.
* `CategoryTheory.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : ι`.
* `TopCat.GlueData.Rel`: A relation on `Σ i, D.U i` defined by `⟨i, x⟩ ~ ⟨j, y⟩` iff
`⟨i, x⟩ = ⟨j, y⟩` or `t i j x = y`. See `TopCat.GlueData.ι_eq_iff_rel`.
* `TopCat.GlueData.mk`: A constructor of `GlueData` whose conditions are stated in terms of
elements rather than subobjects and pullbacks.
* `TopCat.GlueData.ofOpenSubsets`: Given a family of open sets, we may glue them into a new
topological space. This new space embeds into the original space, and is homeomorphic to it if
the given family is an open cover (`TopCat.GlueData.openCoverGlueHomeo`).
## Main results
* `TopCat.GlueData.isOpen_iff`: A set in `glued` is open iff its preimage along each `ι i` is
open.
* `TopCat.GlueData.ι_jointly_surjective`: The `ι i`s are jointly surjective.
* `TopCat.GlueData.rel_equiv`: `Rel` is an equivalence relation.
* `TopCat.GlueData.ι_eq_iff_rel`: `ι i x = ι j y ↔ ⟨i, x⟩ ~ ⟨j, y⟩`.
* `TopCat.GlueData.image_inter`: The intersection of the images of `U i` and `U j` in `glued` is
`V i j`.
* `TopCat.GlueData.preimage_range`: The preimage of the image of `U i` in `U j` is `V i j`.
* `TopCat.GlueData.preimage_image_eq_image`: The preimage of the image of some `U ⊆ U i` is
given by XXX.
* `TopCat.GlueData.ι_isOpenEmbedding`: Each of the `ι i`s are open embeddings.
-/
noncomputable section
open CategoryTheory TopologicalSpace Topology
universe v u
open CategoryTheory.Limits
namespace TopCat
/-- A family of gluing data consists of
1. An index type `J`
2. An object `U i` for each `i : J`.
3. An object `V i j` for each `i j : J`.
(Note that this is `J × J → TopCat` rather than `J → J → TopCat` to connect to the
limits library easier.)
4. An open embedding `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`.
(This merely means that `V i j ∩ V i k ⊆ t i j ⁻¹' (V j i ∩ V j k)`.)
9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`.
We can then glue the topological spaces `U i` together by identifying `V i j` with `V j i`, such
that the `U i`'s are open subspaces of the glued space.
Most of the times it would be easier to use the constructor `TopCat.GlueData.mk'` where the
conditions are stated in a less categorical way.
-/
structure GlueData extends CategoryTheory.GlueData TopCat where
f_open : ∀ i j, IsOpenEmbedding (f i j)
f_mono i j := (TopCat.mono_iff_injective _).mpr (f_open i j).isEmbedding.injective
namespace GlueData
variable (D : GlueData.{u})
local notation "𝖣" => D.toGlueData
theorem π_surjective : Function.Surjective 𝖣.π :=
(TopCat.epi_iff_surjective 𝖣.π).mp inferInstance
theorem isOpen_iff (U : Set 𝖣.glued) : IsOpen U ↔ ∀ i, IsOpen (𝖣.ι i ⁻¹' U) := by
delta CategoryTheory.GlueData.ι
simp_rw [← Multicoequalizer.ι_sigmaπ 𝖣.diagram]
rw [← (homeoOfIso (Multicoequalizer.isoCoequalizer 𝖣.diagram).symm).isOpen_preimage]
rw [coequalizer_isOpen_iff, colimit_isOpen_iff.{u}]
tauto
theorem ι_jointly_surjective (x : 𝖣.glued) : ∃ (i : _) (y : D.U i), 𝖣.ι i y = x :=
𝖣.ι_jointly_surjective (forget TopCat) x
/-- An equivalence relation on `Σ i, D.U i` that holds iff `𝖣.ι i x = 𝖣.ι j y`.
See `TopCat.GlueData.ι_eq_iff_rel`.
-/
def Rel (a b : Σ i, ((D.U i : TopCat) : Type _)) : Prop :=
∃ x : D.V (a.1, b.1), D.f _ _ x = a.2 ∧ D.f _ _ (D.t _ _ x) = b.2
theorem rel_equiv : Equivalence D.Rel :=
⟨fun x => ⟨inv (D.f _ _) x.2, IsIso.inv_hom_id_apply (D.f x.fst x.fst) _,
-- Use `elementwise_of%` elaborator instead of `IsIso.inv_hom_id_apply` to work around
-- `ConcreteCategory`/`HasForget` mismatch:
by simp [elementwise_of% IsIso.inv_hom_id (D.f x.fst x.fst)]⟩, by
rintro a b ⟨x, e₁, e₂⟩
exact ⟨D.t _ _ x, e₂, by rw [← e₁, D.t_inv_apply]⟩, by
rintro ⟨i, a⟩ ⟨j, b⟩ ⟨k, c⟩ ⟨x, e₁, e₂⟩
rintro ⟨y, e₃, e₄⟩
let z := (pullbackIsoProdSubtype (D.f j i) (D.f j k)).inv ⟨⟨_, _⟩, e₂.trans e₃.symm⟩
have eq₁ : (D.t j i) ((pullback.fst _ _ : _ /-(D.f j k)-/ ⟶ D.V (j, i)) z) = x := by
dsimp only [coe_of, z]
rw [pullbackIsoProdSubtype_inv_fst_apply, D.t_inv_apply]
have eq₂ : (pullback.snd _ _ : _ ⟶ D.V _) z = y := pullbackIsoProdSubtype_inv_snd_apply _ _ _
clear_value z
use (pullback.fst _ _ : _ ⟶ D.V (i, k)) (D.t' _ _ _ z)
dsimp only at *
substs eq₁ eq₂ e₁ e₃ e₄
have h₁ : D.t' j i k ≫ pullback.fst _ _ ≫ D.f i k = pullback.fst _ _ ≫ D.t j i ≫ D.f i j := by
rw [← 𝖣.t_fac_assoc]; congr 1; exact pullback.condition
have h₂ : D.t' j i k ≫ pullback.fst _ _ ≫ D.t i k ≫ D.f k i =
pullback.snd _ _ ≫ D.t j k ≫ D.f k j := by
rw [← 𝖣.t_fac_assoc]
apply @Epi.left_cancellation _ _ _ _ (D.t' k j i)
rw [𝖣.cocycle_assoc, 𝖣.t_fac_assoc, 𝖣.t_inv_assoc]
exact pullback.condition.symm
exact ⟨CategoryTheory.congr_fun h₁ z, CategoryTheory.congr_fun h₂ z⟩⟩
open CategoryTheory.Limits.WalkingParallelPair
theorem eqvGen_of_π_eq
-- Porting note: was `{x y : ∐ D.U}`
{x y : sigmaObj (β := D.toGlueData.J) (C := TopCat) D.toGlueData.U}
(h : 𝖣.π x = 𝖣.π y) :
Relation.EqvGen
(Function.Coequalizer.Rel 𝖣.diagram.fstSigmaMap 𝖣.diagram.sndSigmaMap) x y := by
delta GlueData.π Multicoequalizer.sigmaπ at h
replace h : coequalizer.π D.diagram.fstSigmaMap D.diagram.sndSigmaMap x =
coequalizer.π D.diagram.fstSigmaMap D.diagram.sndSigmaMap y :=
(TopCat.mono_iff_injective (Multicoequalizer.isoCoequalizer 𝖣.diagram).inv).mp
inferInstance h
let diagram := parallelPair 𝖣.diagram.fstSigmaMap 𝖣.diagram.sndSigmaMap ⋙ forget _
have : colimit.ι diagram one x = colimit.ι diagram one y := by
dsimp only [coequalizer.π] at h
rw [← ι_preservesColimitIso_hom, ConcreteCategory.forget_map_eq_coe, types_comp_apply]
erw [h]
simp
have :
(colimit.ι diagram _ ≫ colim.map _ ≫ (colimit.isoColimitCocone _).hom) _ =
(colimit.ι diagram _ ≫ colim.map _ ≫ (colimit.isoColimitCocone _).hom) _ :=
(congr_arg
(colim.map (diagramIsoParallelPair diagram).hom ≫
(colimit.isoColimitCocone (Types.coequalizerColimit _ _)).hom)
this :
_)
-- Porting note: was
-- simp only [eqToHom_refl, types_comp_apply, colimit.ι_map_assoc,
-- diagramIsoParallelPair_hom_app, colimit.isoColimitCocone_ι_hom, types_id_apply] at this
-- See https://github.com/leanprover-community/mathlib4/issues/5026
rw [colimit.ι_map_assoc, diagramIsoParallelPair_hom_app, eqToHom_refl,
colimit.isoColimitCocone_ι_hom, types_comp_apply, types_id_apply, types_comp_apply,
types_id_apply] at this
exact Quot.eq.1 this
theorem ι_eq_iff_rel (i j : D.J) (x : D.U i) (y : D.U j) :
𝖣.ι i x = 𝖣.ι j y ↔ D.Rel ⟨i, x⟩ ⟨j, y⟩ := by
constructor
· delta GlueData.ι
simp_rw [← Multicoequalizer.ι_sigmaπ]
intro h
rw [←
show _ = Sigma.mk i x from ConcreteCategory.congr_hom (sigmaIsoSigma.{_, u} D.U).inv_hom_id _]
rw [←
show _ = Sigma.mk j y from ConcreteCategory.congr_hom (sigmaIsoSigma.{_, u} D.U).inv_hom_id _]
change InvImage D.Rel (sigmaIsoSigma.{_, u} D.U).hom _ _
rw [← (InvImage.equivalence _ _ D.rel_equiv).eqvGen_iff]
refine Relation.EqvGen.mono ?_ (D.eqvGen_of_π_eq h :)
rintro _ _ ⟨x⟩
obtain ⟨⟨⟨i, j⟩, y⟩, rfl⟩ :=
(ConcreteCategory.bijective_of_isIso (sigmaIsoSigma.{u, u} _).inv).2 x
unfold InvImage MultispanIndex.fstSigmaMap MultispanIndex.sndSigmaMap
rw [sigmaIsoSigma_inv_apply]
-- `rw [← ConcreteCategory.comp_apply]` succeeds but rewrites the wrong expression
erw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, colimit.ι_desc_assoc,
← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, colimit.ι_desc_assoc]
-- previous line now `erw` after https://github.com/leanprover-community/mathlib4/pull/13170
erw [sigmaIsoSigma_hom_ι_apply, sigmaIsoSigma_hom_ι_apply]
exact ⟨y, ⟨rfl, rfl⟩⟩
· rintro ⟨z, e₁, e₂⟩
dsimp only at *
-- Porting note: there were `subst e₁` and `subst e₂`, instead of the `rw`
rw [← e₁, ← e₂] at *
rw [D.glue_condition_apply]
theorem ι_injective (i : D.J) : Function.Injective (𝖣.ι i) := by
intro x y h
rcases (D.ι_eq_iff_rel _ _ _ _).mp h with ⟨_, e₁, e₂⟩
· dsimp only at *
-- Porting note: there were `cases e₁` and `cases e₂`, instead of the `rw`
rw [← e₁, ← e₂]
simp
instance ι_mono (i : D.J) : Mono (𝖣.ι i) :=
(TopCat.mono_iff_injective _).mpr (D.ι_injective _)
theorem image_inter (i j : D.J) :
Set.range (𝖣.ι i) ∩ Set.range (𝖣.ι j) = Set.range (D.f i j ≫ 𝖣.ι _) := by
ext x
constructor
· rintro ⟨⟨x₁, eq₁⟩, ⟨x₂, eq₂⟩⟩
obtain ⟨y, e₁, -⟩ := (D.ι_eq_iff_rel _ _ _ _).mp (eq₁.trans eq₂.symm)
· substs eq₁
exact ⟨y, by simp [e₁]⟩
· rintro ⟨x, hx⟩
refine ⟨⟨D.f i j x, hx⟩, ⟨D.f j i (D.t _ _ x), ?_⟩⟩
rw [D.glue_condition_apply]
exact hx
theorem preimage_range (i j : D.J) : 𝖣.ι j ⁻¹' Set.range (𝖣.ι i) = Set.range (D.f j i) := by
rw [← Set.preimage_image_eq (Set.range (D.f j i)) (D.ι_injective j), ← Set.image_univ, ←
Set.image_univ, ← Set.image_comp, ← coe_comp, Set.image_univ, Set.image_univ, ← image_inter,
Set.preimage_range_inter]
theorem preimage_image_eq_image (i j : D.J) (U : Set (𝖣.U i)) :
𝖣.ι j ⁻¹' (𝖣.ι i '' U) = D.f _ _ '' ((D.t j i ≫ D.f _ _) ⁻¹' U) := by
have : D.f _ _ ⁻¹' (𝖣.ι j ⁻¹' (𝖣.ι i '' U)) = (D.t j i ≫ D.f _ _) ⁻¹' U := by
ext x
conv_rhs => rw [← Set.preimage_image_eq U (D.ι_injective _)]
simp
rw [← this, Set.image_preimage_eq_inter_range]
symm
apply Set.inter_eq_self_of_subset_left
rw [← D.preimage_range i j]
exact Set.preimage_mono (Set.image_subset_range _ _)
theorem preimage_image_eq_image' (i j : D.J) (U : Set (𝖣.U i)) :
𝖣.ι j ⁻¹' (𝖣.ι i '' U) = (D.t i j ≫ D.f _ _) '' (D.f _ _ ⁻¹' U) := by
convert D.preimage_image_eq_image i j U using 1
rw [coe_comp, coe_comp, Set.image_comp]
congr! 1
rw [← Set.eq_preimage_iff_image_eq, Set.preimage_preimage]
· change _ = (D.t i j ≫ D.t j i ≫ _) ⁻¹' _
rw [𝖣.t_inv_assoc]
rw [← isIso_iff_bijective]
apply (forget TopCat).map_isIso
theorem open_image_open (i : D.J) (U : Opens (𝖣.U i)) : IsOpen (𝖣.ι i '' U) := by
rw [isOpen_iff]
intro j
rw [preimage_image_eq_image]
apply (D.f_open _ _).isOpenMap
apply (D.t j i ≫ D.f i j).hom.continuous_toFun.isOpen_preimage
exact U.isOpen
theorem ι_isOpenEmbedding (i : D.J) : IsOpenEmbedding (𝖣.ι i) :=
.of_continuous_injective_isOpenMap (𝖣.ι i).hom.continuous_toFun (D.ι_injective i) fun U h =>
D.open_image_open i ⟨U, h⟩
/-- A family of gluing data consists of
1. An index type `J`
2. A bundled topological space `U i` for each `i : J`.
3. An open set `V i j ⊆ U i` for each `i j : J`.
4. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`.
such that
6. `V i i = U i`.
7. `t i i` is the identity.
8. For each `x ∈ V i j ∩ V i k`, `t i j x ∈ V j k`.
9. `t j k (t i j x) = t i k x`.
We can then glue the topological spaces `U i` together by identifying `V i j` with `V j i`.
-/
structure MkCore where
/-- The index type `J` -/
{J : Type u}
/-- For each `i : J`, a bundled topological space `U i` -/
U : J → TopCat.{u}
/-- For each `i j : J`, an open set `V i j ⊆ U i` -/
V : ∀ i, J → Opens (U i)
/-- For each `i j : ι`, a transition map `t i j : V i j ⟶ V j i` -/
t : ∀ i j, (Opens.toTopCat _).obj (V i j) ⟶ (Opens.toTopCat _).obj (V j i)
V_id : ∀ i, V i i = ⊤
t_id : ∀ i, ⇑(t i i) = id
t_inter : ∀ ⦃i j⦄ (k) (x : V i j), ↑x ∈ V i k → (((↑) : (V j i) → (U j)) (t i j x)) ∈ V j k
cocycle :
∀ (i j k) (x : V i j) (h : ↑x ∈ V i k),
-- Porting note: the underscore in the next line was `↑(t i j x)`, but Lean type-mismatched
(((↑) : (V k j) → (U k)) (t j k ⟨_, t_inter k x h⟩)) = ((↑) : (V k i) → (U k)) (t i k ⟨x, h⟩)
theorem MkCore.t_inv (h : MkCore) (i j : h.J) (x : h.V j i) : h.t i j ((h.t j i) x) = x := by
have := h.cocycle j i j x ?_
· rw [h.t_id] at this
· convert Subtype.eq this
rw [h.V_id]
trivial
instance (h : MkCore.{u}) (i j : h.J) : IsIso (h.t i j) := by
use h.t j i; constructor <;> ext1; exacts [h.t_inv _ _ _, h.t_inv _ _ _]
/-- (Implementation) the restricted transition map to be fed into `TopCat.GlueData`. -/
def MkCore.t' (h : MkCore.{u}) (i j k : h.J) :
pullback (h.V i j).inclusion' (h.V i k).inclusion' ⟶
pullback (h.V j k).inclusion' (h.V j i).inclusion' := by
refine (pullbackIsoProdSubtype _ _).hom ≫ ofHom ⟨?_, ?_⟩ ≫ (pullbackIsoProdSubtype _ _).inv
· intro x
refine ⟨⟨⟨(h.t i j x.1.1).1, ?_⟩, h.t i j x.1.1⟩, rfl⟩
rcases x with ⟨⟨⟨x, hx⟩, ⟨x', hx'⟩⟩, rfl : x = x'⟩
exact h.t_inter _ ⟨x, hx⟩ hx'
fun_prop
/-- This is a constructor of `TopCat.GlueData` whose arguments are in terms of elements and
intersections rather than subobjects and pullbacks. Please refer to `TopCat.GlueData.MkCore` for
details. -/
def mk' (h : MkCore.{u}) : TopCat.GlueData where
J := h.J
U := h.U
V i := (Opens.toTopCat _).obj (h.V i.1 i.2)
f i j := (h.V i j).inclusion'
f_id i := (h.V_id i).symm ▸ (Opens.inclusionTopIso (h.U i)).isIso_hom
f_open := fun i j : h.J => (h.V i j).isOpenEmbedding
t := h.t
t_id i := by ext; rw [h.t_id]; rfl
t' := h.t'
t_fac i j k := by
delta MkCore.t'
rw [Category.assoc, Category.assoc, pullbackIsoProdSubtype_inv_snd, ← Iso.eq_inv_comp,
pullbackIsoProdSubtype_inv_fst_assoc]
ext ⟨⟨⟨x, hx⟩, ⟨x', hx'⟩⟩, rfl : x = x'⟩
rfl
cocycle i j k := by
delta MkCore.t'
simp_rw [← Category.assoc]
rw [Iso.comp_inv_eq]
simp only [Iso.inv_hom_id_assoc, Category.assoc, Category.id_comp]
rw [← Iso.eq_inv_comp, Iso.inv_hom_id]
ext1 ⟨⟨⟨x, hx⟩, ⟨x', hx'⟩⟩, rfl : x = x'⟩
dsimp only [Opens.coe_inclusion', hom_comp, hom_ofHom, ContinuousMap.comp_assoc,
ContinuousMap.comp_apply, ContinuousMap.coe_mk, hom_id, ContinuousMap.id_apply]
rw [Subtype.mk_eq_mk, Prod.mk_inj, Subtype.mk_eq_mk, Subtype.ext_iff, and_self_iff]
convert congr_arg Subtype.val (h.t_inv k i ⟨x, hx'⟩) using 3
refine Subtype.ext ?_
exact h.cocycle i j k ⟨x, hx⟩ hx'
f_mono _ _ := (TopCat.mono_iff_injective _).mpr fun _ _ h => Subtype.ext h
variable {α : Type u} [TopologicalSpace α] {J : Type u} (U : J → Opens α)
/-- We may construct a glue data from a family of open sets. -/
@[simps! toGlueData_J toGlueData_U toGlueData_V toGlueData_t toGlueData_f]
def ofOpenSubsets : TopCat.GlueData.{u} :=
mk'.{u}
{ J
U := fun i => (Opens.toTopCat <| TopCat.of α).obj (U i)
V := fun _ j => (Opens.map <| Opens.inclusion' _).obj (U j)
t := fun i j => ofHom ⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, by fun_prop⟩
V_id := fun i => by ext; simp
| t_id := fun i => by ext; rfl
t_inter := fun _ _ _ _ hx => hx
cocycle := fun _ _ _ _ _ => rfl }
/-- The canonical map from the glue of a family of open subsets `α` into `α`.
This map is an open embedding (`fromOpenSubsetsGlue_isOpenEmbedding`),
| Mathlib/Topology/Gluing.lean | 368 | 373 |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Jujian Zhang
-/
import Mathlib.Algebra.GroupWithZero.Subgroup
import Mathlib.Algebra.Order.Group.Action
import Mathlib.LinearAlgebra.Finsupp.Supported
import Mathlib.LinearAlgebra.Span.Basic
/-! # Pointwise instances on `Submodule`s
This file provides:
* `Submodule.pointwiseNeg`
and the actions
* `Submodule.pointwiseDistribMulAction`
* `Submodule.pointwiseMulActionWithZero`
which matches the action of `Set.mulActionSet`.
This file also provides:
* `Submodule.pointwiseSetSMulSubmodule`: for `R`-module `M`, a `s : Set R` can act on
`N : Submodule R M` by defining `s • N` to be the smallest submodule containing all `a • n`
where `a ∈ s` and `n ∈ N`.
These actions are available in the `Pointwise` locale.
## Implementation notes
For an `R`-module `M`, the action of a subset of `R` acting on a submodule of `M` introduced in
section `set_acting_on_submodules` does not have a counterpart in the files
`Mathlib.Algebra.Group.Submonoid.Pointwise` and `Mathlib.Algebra.GroupWithZero.Submonoid.Pointwise`.
Other than section `set_acting_on_submodules`, most of the lemmas in this file are direct copies of
lemmas from the file `Mathlib.Algebra.Group.Submonoid.Pointwise`.
-/
assert_not_exists Ideal
variable {α : Type*} {R : Type*} {M : Type*}
open Pointwise
namespace Submodule
section Neg
section Semiring
variable [Semiring R] [AddCommGroup M] [Module R M]
/-- The submodule with every element negated. Note if `R` is a ring and not just a semiring, this
is a no-op, as shown by `Submodule.neg_eq_self`.
Recall that When `R` is the semiring corresponding to the nonnegative elements of `R'`,
`Submodule R' M` is the type of cones of `M`. This instance reflects such cones about `0`.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseNeg : Neg (Submodule R M) where
neg p :=
{ -p.toAddSubmonoid with
smul_mem' := fun r m hm => Set.mem_neg.2 <| smul_neg r m ▸ p.smul_mem r <| Set.mem_neg.1 hm }
scoped[Pointwise] attribute [instance] Submodule.pointwiseNeg
open Pointwise
@[simp]
theorem coe_set_neg (S : Submodule R M) : ↑(-S) = -(S : Set M) :=
rfl
@[simp]
theorem neg_toAddSubmonoid (S : Submodule R M) : (-S).toAddSubmonoid = -S.toAddSubmonoid :=
rfl
@[simp]
theorem mem_neg {g : M} {S : Submodule R M} : g ∈ -S ↔ -g ∈ S :=
Iff.rfl
/-- `Submodule.pointwiseNeg` is involutive.
This is available as an instance in the `Pointwise` locale. -/
protected def involutivePointwiseNeg : InvolutiveNeg (Submodule R M) where
neg := Neg.neg
neg_neg _S := SetLike.coe_injective <| neg_neg _
scoped[Pointwise] attribute [instance] Submodule.involutivePointwiseNeg
@[simp]
theorem neg_le_neg (S T : Submodule R M) : -S ≤ -T ↔ S ≤ T :=
SetLike.coe_subset_coe.symm.trans Set.neg_subset_neg
theorem neg_le (S T : Submodule R M) : -S ≤ T ↔ S ≤ -T :=
SetLike.coe_subset_coe.symm.trans Set.neg_subset
/-- `Submodule.pointwiseNeg` as an order isomorphism. -/
def negOrderIso : Submodule R M ≃o Submodule R M where
toEquiv := Equiv.neg _
map_rel_iff' := @neg_le_neg _ _ _ _ _
theorem span_neg_eq_neg (s : Set M) : span R (-s) = -span R s := by
apply le_antisymm
· rw [span_le, coe_set_neg, ← Set.neg_subset, neg_neg]
exact subset_span
· rw [neg_le, span_le, coe_set_neg, ← Set.neg_subset]
exact subset_span
@[deprecated (since := "2025-04-08")]
alias closure_neg := span_neg_eq_neg
@[simp]
theorem neg_inf (S T : Submodule R M) : -(S ⊓ T) = -S ⊓ -T := rfl
@[simp]
theorem neg_sup (S T : Submodule R M) : -(S ⊔ T) = -S ⊔ -T :=
(negOrderIso : Submodule R M ≃o Submodule R M).map_sup S T
@[simp]
theorem neg_bot : -(⊥ : Submodule R M) = ⊥ :=
SetLike.coe_injective <| (Set.neg_singleton 0).trans <| congr_arg _ neg_zero
@[simp]
theorem neg_top : -(⊤ : Submodule R M) = ⊤ :=
SetLike.coe_injective <| Set.neg_univ
@[simp]
theorem neg_iInf {ι : Sort*} (S : ι → Submodule R M) : (-⨅ i, S i) = ⨅ i, -S i :=
(negOrderIso : Submodule R M ≃o Submodule R M).map_iInf _
@[simp]
theorem neg_iSup {ι : Sort*} (S : ι → Submodule R M) : (-⨆ i, S i) = ⨆ i, -S i :=
(negOrderIso : Submodule R M ≃o Submodule R M).map_iSup _
end Semiring
open Pointwise
@[simp]
theorem neg_eq_self [Ring R] [AddCommGroup M] [Module R M] (p : Submodule R M) : -p = p :=
ext fun _ => p.neg_mem_iff
end Neg
variable [Semiring R] [AddCommMonoid M] [Module R M]
instance pointwiseZero : Zero (Submodule R M) where
zero := ⊥
instance pointwiseAdd : Add (Submodule R M) where
add := (· ⊔ ·)
instance pointwiseAddCommMonoid : AddCommMonoid (Submodule R M) where
add_assoc := sup_assoc
zero_add := bot_sup_eq
add_zero := sup_bot_eq
add_comm := sup_comm
nsmul := nsmulRec
@[simp]
theorem add_eq_sup (p q : Submodule R M) : p + q = p ⊔ q :=
rfl
@[simp]
theorem zero_eq_bot : (0 : Submodule R M) = ⊥ :=
rfl
instance : IsOrderedAddMonoid (Submodule R M) :=
{ add_le_add_left := fun _a _b => sup_le_sup_left }
instance : CanonicallyOrderedAdd (Submodule R M) where
exists_add_of_le := @fun _a b h => ⟨b, (sup_eq_right.2 h).symm⟩
le_self_add := fun _a _b => le_sup_left
section
variable [Monoid α] [DistribMulAction α M] [SMulCommClass α R M]
/-- The action on a submodule corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseDistribMulAction : DistribMulAction α (Submodule R M) where
smul a S := S.map (DistribMulAction.toLinearMap R M a : M →ₗ[R] M)
one_smul S :=
(congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| one_smul α)).trans S.map_id
mul_smul _a₁ _a₂ S :=
(congr_arg (fun f : Module.End R M => S.map f) (LinearMap.ext <| mul_smul _ _)).trans
(S.map_comp _ _)
smul_zero _a := map_bot _
smul_add _a _S₁ _S₂ := map_sup _ _ _
scoped[Pointwise] attribute [instance] Submodule.pointwiseDistribMulAction
open Pointwise
@[simp]
theorem coe_pointwise_smul (a : α) (S : Submodule R M) : ↑(a • S) = a • (S : Set M) :=
rfl
@[simp]
theorem pointwise_smul_toAddSubmonoid (a : α) (S : Submodule R M) :
(a • S).toAddSubmonoid = a • S.toAddSubmonoid :=
rfl
@[simp]
theorem pointwise_smul_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [DistribMulAction α M]
[Module R M] [SMulCommClass α R M] (a : α) (S : Submodule R M) :
(a • S).toAddSubgroup = a • S.toAddSubgroup :=
rfl
theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submodule R M) :
m ∈ a • S ↔ ∃ b ∈ S, a • b = m :=
Set.mem_smul_set
theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submodule R M) : m ∈ S → a • m ∈ a • S :=
(Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M))
instance : CovariantClass α (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ => map_mono⟩
/-- See also `Submodule.smul_bot`. -/
@[simp]
theorem smul_bot' (a : α) : a • (⊥ : Submodule R M) = ⊥ :=
map_bot _
/-- See also `Submodule.smul_sup`. -/
theorem smul_sup' (a : α) (S T : Submodule R M) : a • (S ⊔ T) = a • S ⊔ a • T :=
map_sup _ _ _
theorem smul_span (a : α) (s : Set M) : a • span R s = span R (a • s) :=
map_span _ _
lemma smul_def (a : α) (S : Submodule R M) : a • S = span R (a • S : Set M) := by simp [← smul_span]
theorem span_smul (a : α) (s : Set M) : span R (a • s) = a • span R s :=
Eq.symm (span_image _).symm
instance pointwiseCentralScalar [DistribMulAction αᵐᵒᵖ M] [SMulCommClass αᵐᵒᵖ R M]
[IsCentralScalar α M] : IsCentralScalar α (Submodule R M) :=
⟨fun _a S => (congr_arg fun f : Module.End R M => S.map f) <| LinearMap.ext <| op_smul_eq_smul _⟩
@[simp]
theorem smul_le_self_of_tower {α : Type*} [Monoid α] [SMul α R] [DistribMulAction α M]
[SMulCommClass α R M] [IsScalarTower α R M] (a : α) (S : Submodule R M) : a • S ≤ S := by
rintro y ⟨x, hx, rfl⟩
exact smul_of_tower_mem _ a hx
end
section
variable [Semiring α] [Module α M] [SMulCommClass α R M]
/-- The action on a submodule corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale.
This is a stronger version of `Submodule.pointwiseDistribMulAction`. Note that `add_smul` does
not hold so this cannot be stated as a `Module`. -/
protected def pointwiseMulActionWithZero : MulActionWithZero α (Submodule R M) :=
{ Submodule.pointwiseDistribMulAction with
zero_smul := fun S =>
(congr_arg (fun f : M →ₗ[R] M => S.map f) (LinearMap.ext <| zero_smul α)).trans S.map_zero }
scoped[Pointwise] attribute [instance] Submodule.pointwiseMulActionWithZero
end
/-!
### Sets acting on Submodules
Let `R` be a (semi)ring and `M` an `R`-module. Let `S` be a monoid which acts on `M` distributively,
then subsets of `S` can act on submodules of `M`.
For subset `s ⊆ S` and submodule `N ≤ M`, we define `s • N` to be the smallest submodule containing
all `r • n` where `r ∈ s` and `n ∈ N`.
#### Results
For arbitrary monoids `S` acting distributively on `M`, there is an induction principle for `s • N`:
To prove `P` holds for all `s • N`, it is enough
to prove:
- for all `r ∈ s` and `n ∈ N`, `P (r • n)`;
- for all `r` and `m ∈ s • N`, `P (r • n)`;
- for all `m₁, m₂`, `P m₁` and `P m₂` implies `P (m₁ + m₂)`;
- `P 0`.
To invoke this induction principle, use `induction x, hx using Submodule.set_smul_inductionOn` where
`x : M` and `hx : x ∈ s • N`
When we consider subset of `R` acting on `M`
- `Submodule.pointwiseSetDistribMulAction` : the action described above is distributive.
- `Submodule.mem_set_smul` : `x ∈ s • N` iff `x` can be written as `r₀ n₀ + ... + rₖ nₖ` where
`rᵢ ∈ s` and `nᵢ ∈ N`.
- `Submodule.coe_span_smul`: `s • N` is the same as `⟨s⟩ • N` where `⟨s⟩` is the ideal spanned
by `s`.
#### Notes
- If we assume the addition on subsets of `R` is the `⊔` and subtraction `⊓` i.e. use `SetSemiring`,
then this action actually gives a module structure on submodules of `M` over subsets of `R`.
- If we generalize so that `r • N` makes sense for all `r : S`, then `Submodule.singleton_set_smul`
and `Submodule.singleton_set_smul` can be generalized as well.
-/
section set_acting_on_submodules
variable {S : Type*} [Monoid S]
variable [DistribMulAction S M]
/--
Let `s ⊆ R` be a set and `N ≤ M` be a submodule, then `s • N` is the smallest submodule containing
all `r • n` where `r ∈ s` and `n ∈ N`.
-/
protected def pointwiseSetSMul : SMul (Set S) (Submodule R M) where
smul s N := sInf { p | ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p }
scoped[Pointwise] attribute [instance] Submodule.pointwiseSetSMul
variable (sR : Set R) (s : Set S) (N : Submodule R M)
lemma mem_set_smul_def (x : M) :
x ∈ s • N ↔
x ∈ sInf { p : Submodule R M | ∀ ⦃r : S⦄ {n : M}, r ∈ s → n ∈ N → r • n ∈ p } := Iff.rfl
variable {s N} in
@[aesop safe]
lemma mem_set_smul_of_mem_mem {r : S} {m : M} (mem1 : r ∈ s) (mem2 : m ∈ N) :
r • m ∈ s • N := by
rw [mem_set_smul_def, mem_sInf]
exact fun _ h => h mem1 mem2
lemma set_smul_le (p : Submodule R M)
(closed_under_smul : ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p) :
s • N ≤ p :=
sInf_le closed_under_smul
lemma set_smul_le_iff (p : Submodule R M) :
s • N ≤ p ↔
∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p := by
fconstructor
· intro h r n hr hn
exact h <| mem_set_smul_of_mem_mem hr hn
· apply set_smul_le
lemma set_smul_eq_of_le (p : Submodule R M)
(closed_under_smul : ∀ ⦃r : S⦄ ⦃n : M⦄, r ∈ s → n ∈ N → r • n ∈ p)
(le : p ≤ s • N) :
s • N = p :=
le_antisymm (set_smul_le s N p closed_under_smul) le
instance : CovariantClass (Set S) (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ _ le => set_smul_le _ _ _ fun _ _ hr hm => mem_set_smul_of_mem_mem (mem1 := hr)
(mem2 := le hm)⟩
lemma set_smul_mono_left {s t : Set S} (le : s ≤ t) :
s • N ≤ t • N :=
set_smul_le _ _ _ fun _ _ hr hm => mem_set_smul_of_mem_mem (mem1 := le hr)
(mem2 := hm)
lemma set_smul_le_of_le_le {s t : Set S} {p q : Submodule R M}
(le_set : s ≤ t) (le_submodule : p ≤ q) : s • p ≤ t • q :=
le_trans (set_smul_mono_left _ le_set) <| smul_mono_right _ le_submodule
lemma set_smul_eq_iSup [SMulCommClass S R M] (s : Set S) (N : Submodule R M) :
s • N = ⨆ (a ∈ s), a • N := by
refine Eq.trans (congrArg sInf ?_) csInf_Ici
simp_rw [← Set.Ici_def, iSup_le_iff, @forall_comm M]
exact Set.ext fun _ => forall₂_congr (fun _ _ => Iff.symm map_le_iff_le_comap)
theorem set_smul_span [SMulCommClass S R M] (s : Set S) (t : Set M) :
s • span R t = span R (s • t) := by
simp_rw [set_smul_eq_iSup, smul_span, iSup_span, Set.iUnion_smul_set]
theorem span_set_smul [SMulCommClass S R M] (s : Set S) (t : Set M) :
span R (s • t) = s • span R t := (set_smul_span s t).symm
variable {s N} in
/--
Induction principle for set acting on submodules. To prove `P` holds for all `s • N`, it is enough
to prove:
- for all `r ∈ s` and `n ∈ N`, `P (r • n)`;
- for all `r` and `m ∈ s • N`, `P (r • n)`;
- for all `m₁, m₂`, `P m₁` and `P m₂` implies `P (m₁ + m₂)`;
- `P 0`.
To invoke this induction principle, use `induction x, hx using Submodule.set_smul_inductionOn` where
`x : M` and `hx : x ∈ s • N`
-/
@[elab_as_elim]
lemma set_smul_inductionOn {motive : (x : M) → (_ : x ∈ s • N) → Prop}
(x : M)
(hx : x ∈ s • N)
(smul₀ : ∀ ⦃r : S⦄ ⦃n : M⦄ (mem₁ : r ∈ s) (mem₂ : n ∈ N),
motive (r • n) (mem_set_smul_of_mem_mem mem₁ mem₂))
(smul₁ : ∀ (r : R) ⦃m : M⦄ (mem : m ∈ s • N) ,
motive m mem → motive (r • m) (Submodule.smul_mem _ r mem)) --
(add : ∀ ⦃m₁ m₂ : M⦄ (mem₁ : m₁ ∈ s • N) (mem₂ : m₂ ∈ s • N),
motive m₁ mem₁ → motive m₂ mem₂ → motive (m₁ + m₂) (Submodule.add_mem _ mem₁ mem₂))
(zero : motive 0 (Submodule.zero_mem _)) :
motive x hx :=
let ⟨_, h⟩ := set_smul_le s N
{ carrier := { m | ∃ (mem : m ∈ s • N), motive m mem },
zero_mem' := ⟨Submodule.zero_mem _, zero⟩
add_mem' := fun ⟨mem, h⟩ ⟨mem', h'⟩ ↦ ⟨_, add mem mem' h h'⟩
smul_mem' := fun r _ ⟨mem, h⟩ ↦ ⟨_, smul₁ r mem h⟩ }
(fun _ _ mem mem' ↦ ⟨mem_set_smul_of_mem_mem mem mem', smul₀ mem mem'⟩) hx
h
-- Implementation note: if `N` is both an `R`-submodule and `S`-submodule and `SMulCommClass R S M`,
-- this lemma is also true for any `s : Set S`.
lemma set_smul_eq_map [SMulCommClass R R N] :
sR • N =
Submodule.map
(N.subtype.comp (Finsupp.lsum R <| DistribMulAction.toLinearMap _ _))
(Finsupp.supported N R sR) := by
classical
apply set_smul_eq_of_le
· intro r n hr hn
exact ⟨Finsupp.single r ⟨n, hn⟩, Finsupp.single_mem_supported _ _ hr, by simp⟩
· intro x hx
obtain ⟨c, hc, rfl⟩ := hx
simp only [LinearMap.coe_comp, coe_subtype, Finsupp.coe_lsum, Finsupp.sum, Function.comp_apply]
rw [AddSubmonoid.coe_finset_sum]
refine Submodule.sum_mem (p := sR • N) (t := c.support) ?_ _ ⟨sR • N, ?_⟩
· rintro r hr
rw [mem_set_smul_def, Submodule.mem_sInf]
rintro p hp
exact hp (hc hr) (c r).2
· ext x : 1
simp only [Set.mem_iInter, SetLike.mem_coe]
fconstructor
· refine fun h ↦ h fun r n hr hn ↦ ?_
rw [mem_set_smul_def, mem_sInf]
exact fun p hp ↦ hp hr hn
· aesop
lemma mem_set_smul (x : M) [SMulCommClass R R N] :
x ∈ sR • N ↔ ∃ (c : R →₀ N), (c.support : Set R) ⊆ sR ∧ x = c.sum fun r m ↦ r • m := by
fconstructor
· intros h
rw [set_smul_eq_map] at h
obtain ⟨c, hc, rfl⟩ := h
exact ⟨c, hc, rfl⟩
· rw [mem_set_smul_def, Submodule.mem_sInf]
rintro ⟨c, hc1, rfl⟩ p hp
rw [Finsupp.sum, AddSubmonoid.coe_finset_sum]
exact Submodule.sum_mem _ fun r hr ↦ hp (hc1 hr) (c _).2
@[simp] lemma empty_set_smul : (∅ : Set S) • N = ⊥ := by
ext
fconstructor
· intro hx
rw [mem_set_smul_def, Submodule.mem_sInf] at hx
exact hx ⊥ (fun r _ hr ↦ hr.elim)
· rintro rfl; exact Submodule.zero_mem _
@[simp] lemma set_smul_bot : s • (⊥ : Submodule R M) = ⊥ :=
eq_bot_iff.mpr fun x hx ↦ by induction x, hx using set_smul_inductionOn <;> aesop
lemma singleton_set_smul [SMulCommClass S R M] (r : S) : ({r} : Set S) • N = r • N := by
apply set_smul_eq_of_le
· rintro _ m rfl hm; exact ⟨m, hm, rfl⟩
· rintro _ ⟨m, hm, rfl⟩
rw [mem_set_smul_def, Submodule.mem_sInf]
intro _ hp; exact hp rfl hm
lemma mem_singleton_set_smul [SMulCommClass R S M] (r : S) (x : M) :
x ∈ ({r} : Set S) • N ↔ ∃ (m : M), m ∈ N ∧ x = r • m := by
fconstructor
· intro hx
induction x, hx using Submodule.set_smul_inductionOn with
| smul₀ => aesop
| @smul₁ t n mem h =>
rcases h with ⟨n, hn, rfl⟩
exact ⟨t • n, by aesop, smul_comm _ _ _⟩
| add mem₁ mem₂ h₁ h₂ =>
rcases h₁ with ⟨m₁, h₁, rfl⟩
rcases h₂ with ⟨m₂, h₂, rfl⟩
exact ⟨m₁ + m₂, Submodule.add_mem _ h₁ h₂, by simp⟩
| zero => exact ⟨0, Submodule.zero_mem _, by simp⟩
· aesop
lemma smul_inductionOn_pointwise [SMulCommClass S R M] {a : S} {p : (x : M) → x ∈ a • N → Prop}
(smul₀ : ∀ (s : M) (hs : s ∈ N), p (a • s) (Submodule.smul_mem_pointwise_smul _ _ _ hs))
| (smul₁ : ∀ (r : R) (m : M) (mem : m ∈ a • N), p m mem → p (r • m) (Submodule.smul_mem _ _ mem))
(add : ∀ (x y : M) (hx : x ∈ a • N) (hy : y ∈ a • N),
p x hx → p y hy → p (x + y) (Submodule.add_mem _ hx hy))
(zero : p 0 (Submodule.zero_mem _)) {x : M} (hx : x ∈ a • N) :
p x hx := by
simp_all only [← Submodule.singleton_set_smul]
let p' (x : M) (hx : x ∈ ({a} : Set S) • N) : Prop :=
| Mathlib/Algebra/Module/Submodule/Pointwise.lean | 486 | 492 |
/-
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.Logic.Encodable.Pi
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Topology.MetricSpace.Closeds
import Mathlib.Topology.MetricSpace.Completion
import Mathlib.Topology.MetricSpace.GromovHausdorffRealized
import Mathlib.Topology.MetricSpace.Kuratowski
/-!
# Gromov-Hausdorff distance
This file defines the Gromov-Hausdorff distance on the space of nonempty compact metric spaces
up to isometry.
We introduce the space of all nonempty compact metric spaces, up to isometry,
called `GHSpace`, and endow it with a metric space structure. The distance,
known as the Gromov-Hausdorff distance, is defined as follows: given two
nonempty compact spaces `X` and `Y`, their distance is the minimum Hausdorff distance
between all possible isometric embeddings of `X` and `Y` in all metric spaces.
To define properly the Gromov-Hausdorff space, we consider the non-empty
compact subsets of `ℓ^∞(ℝ)` up to isometry, which is a well-defined type,
and define the distance as the infimum of the Hausdorff distance over all
embeddings in `ℓ^∞(ℝ)`. We prove that this coincides with the previous description,
as all separable metric spaces embed isometrically into `ℓ^∞(ℝ)`, through an
embedding called the Kuratowski embedding.
To prove that we have a distance, we should show that if spaces can be coupled
to be arbitrarily close, then they are isometric. More generally, the Gromov-Hausdorff
distance is realized, i.e., there is a coupling for which the Hausdorff distance
is exactly the Gromov-Hausdorff distance. This follows from a compactness
argument, essentially following from Arzela-Ascoli.
## Main results
We prove the most important properties of the Gromov-Hausdorff space: it is a polish space,
i.e., it is complete and second countable. We also prove the Gromov compactness criterion.
-/
noncomputable section
open scoped Topology ENNReal Cardinal
open Set Function TopologicalSpace Filter Metric Quotient Bornology
open BoundedContinuousFunction Nat Int kuratowskiEmbedding
open Sum (inl inr)
local notation "ℓ_infty_ℝ" => lp (fun n : ℕ => ℝ) ∞
universe u v w
attribute [local instance] metricSpaceSum
namespace GromovHausdorff
/-! In this section, we define the Gromov-Hausdorff space, denoted `GHSpace` as the quotient
of nonempty compact subsets of `ℓ^∞(ℝ)` by identifying isometric sets.
Using the Kuratwoski embedding, we get a canonical map `toGHSpace` mapping any nonempty
compact type to `GHSpace`. -/
section GHSpace
/-- Equivalence relation identifying two nonempty compact sets which are isometric -/
private def IsometryRel (x : NonemptyCompacts ℓ_infty_ℝ) (y : NonemptyCompacts ℓ_infty_ℝ) : Prop :=
Nonempty (x ≃ᵢ y)
/-- This is indeed an equivalence relation -/
private theorem equivalence_isometryRel : Equivalence IsometryRel :=
⟨fun _ => Nonempty.intro (IsometryEquiv.refl _), fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e⟩ ⟨f⟩ => ⟨e.trans f⟩⟩
/-- setoid instance identifying two isometric nonempty compact subspaces of ℓ^∞(ℝ) -/
instance IsometryRel.setoid : Setoid (NonemptyCompacts ℓ_infty_ℝ) :=
Setoid.mk IsometryRel equivalence_isometryRel
/-- The Gromov-Hausdorff space -/
def GHSpace : Type :=
Quotient IsometryRel.setoid
/-- Map any nonempty compact type to `GHSpace` -/
def toGHSpace (X : Type u) [MetricSpace X] [CompactSpace X] [Nonempty X] : GHSpace :=
⟦NonemptyCompacts.kuratowskiEmbedding X⟧
instance : Inhabited GHSpace :=
⟨Quot.mk _ ⟨⟨{0}, isCompact_singleton⟩, singleton_nonempty _⟩⟩
/-- A metric space representative of any abstract point in `GHSpace` -/
def GHSpace.Rep (p : GHSpace) : Type :=
(Quotient.out p : NonemptyCompacts ℓ_infty_ℝ)
theorem eq_toGHSpace_iff {X : Type u} [MetricSpace X] [CompactSpace X] [Nonempty X]
{p : NonemptyCompacts ℓ_infty_ℝ} :
⟦p⟧ = toGHSpace X ↔ ∃ Ψ : X → ℓ_infty_ℝ, Isometry Ψ ∧ range Ψ = p := by
simp only [toGHSpace, Quotient.eq]
refine ⟨fun h => ?_, ?_⟩
· rcases Setoid.symm h with ⟨e⟩
have f := (kuratowskiEmbedding.isometry X).isometryEquivOnRange.trans e
use fun x => f x, isometry_subtype_coe.comp f.isometry
rw [range_comp', f.range_eq_univ, Set.image_univ, Subtype.range_coe]
· rintro ⟨Ψ, ⟨isomΨ, rangeΨ⟩⟩
have f :=
((kuratowskiEmbedding.isometry X).isometryEquivOnRange.symm.trans
isomΨ.isometryEquivOnRange).symm
have E : (range Ψ ≃ᵢ NonemptyCompacts.kuratowskiEmbedding X)
= (p ≃ᵢ range (kuratowskiEmbedding X)) := by
dsimp only [NonemptyCompacts.kuratowskiEmbedding]; rw [rangeΨ]; rfl
exact ⟨cast E f⟩
theorem eq_toGHSpace {p : NonemptyCompacts ℓ_infty_ℝ} : ⟦p⟧ = toGHSpace p :=
eq_toGHSpace_iff.2 ⟨fun x => x, isometry_subtype_coe, Subtype.range_coe⟩
section
instance repGHSpaceMetricSpace {p : GHSpace} : MetricSpace p.Rep :=
inferInstanceAs <| MetricSpace p.out
instance rep_gHSpace_compactSpace {p : GHSpace} : CompactSpace p.Rep :=
inferInstanceAs <| CompactSpace p.out
instance rep_gHSpace_nonempty {p : GHSpace} : Nonempty p.Rep :=
inferInstanceAs <| Nonempty p.out
end
theorem GHSpace.toGHSpace_rep (p : GHSpace) : toGHSpace p.Rep = p := by
change toGHSpace (Quot.out p : NonemptyCompacts ℓ_infty_ℝ) = p
rw [← eq_toGHSpace]
exact Quot.out_eq p
/-- Two nonempty compact spaces have the same image in `GHSpace` if and only if they are
isometric. -/
theorem toGHSpace_eq_toGHSpace_iff_isometryEquiv {X : Type u} [MetricSpace X] [CompactSpace X]
[Nonempty X] {Y : Type v} [MetricSpace Y] [CompactSpace Y] [Nonempty Y] :
toGHSpace X = toGHSpace Y ↔ Nonempty (X ≃ᵢ Y) :=
⟨by
simp only [toGHSpace]
rw [Quotient.eq]
rintro ⟨e⟩
have I :
(NonemptyCompacts.kuratowskiEmbedding X ≃ᵢ NonemptyCompacts.kuratowskiEmbedding Y) =
(range (kuratowskiEmbedding X) ≃ᵢ range (kuratowskiEmbedding Y)) := by
dsimp only [NonemptyCompacts.kuratowskiEmbedding]; rfl
have f := (kuratowskiEmbedding.isometry X).isometryEquivOnRange
have g := (kuratowskiEmbedding.isometry Y).isometryEquivOnRange.symm
exact ⟨f.trans <| (cast I e).trans g⟩, by
rintro ⟨e⟩
simp only [toGHSpace, Quotient.eq']
have f := (kuratowskiEmbedding.isometry X).isometryEquivOnRange.symm
| have g := (kuratowskiEmbedding.isometry Y).isometryEquivOnRange
have I :
(range (kuratowskiEmbedding X) ≃ᵢ range (kuratowskiEmbedding Y)) =
(NonemptyCompacts.kuratowskiEmbedding X ≃ᵢ NonemptyCompacts.kuratowskiEmbedding Y) := by
dsimp only [NonemptyCompacts.kuratowskiEmbedding]; rfl
rw [Quotient.eq]
exact ⟨cast I ((f.trans e).trans g)⟩⟩
/-- Distance on `GHSpace`: the distance between two nonempty compact spaces is the infimum
Hausdorff distance between isometric copies of the two spaces in a metric space. For the definition,
we only consider embeddings in `ℓ^∞(ℝ)`, but we will prove below that it works for all spaces. -/
instance : Dist GHSpace where
dist x y := sInf <| (fun p : NonemptyCompacts ℓ_infty_ℝ × NonemptyCompacts ℓ_infty_ℝ =>
hausdorffDist (p.1 : Set ℓ_infty_ℝ) p.2) '' { a | ⟦a⟧ = x } ×ˢ { b | ⟦b⟧ = y }
/-- The Gromov-Hausdorff distance between two nonempty compact metric spaces, equal by definition to
the distance of the equivalence classes of these spaces in the Gromov-Hausdorff space. -/
def ghDist (X : Type u) (Y : Type v) [MetricSpace X] [Nonempty X] [CompactSpace X] [MetricSpace Y]
[Nonempty Y] [CompactSpace Y] : ℝ :=
dist (toGHSpace X) (toGHSpace Y)
theorem dist_ghDist (p q : GHSpace) : dist p q = ghDist p.Rep q.Rep := by
rw [ghDist, p.toGHSpace_rep, q.toGHSpace_rep]
| Mathlib/Topology/MetricSpace/GromovHausdorff.lean | 150 | 173 |
/-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Utensil Song
-/
import Mathlib.Algebra.RingQuot
import Mathlib.LinearAlgebra.TensorAlgebra.Basic
import Mathlib.LinearAlgebra.QuadraticForm.Isometry
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
/-!
# Clifford Algebras
We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with
a quadratic form `Q`.
## Notation
The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is
an `R`-algebra denoted `CliffordAlgebra Q`.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra
morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`.
The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`.
## Theorems
The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property
of the Clifford algebra.
1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1.
## Implementation details
The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows.
1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`.
This is the smallest relation which identifies squares of elements of `M` with `Q m`.
2. The Clifford algebra is the quotient of the tensor algebra by this relation.
This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`.
-/
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
open TensorAlgebra
/-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`.
The Clifford algebra of `M` is defined as the quotient modulo this relation.
-/
inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop
| of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m))
end CliffordAlgebra
/-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`.
-/
def CliffordAlgebra :=
RingQuot (CliffordAlgebra.Rel Q)
namespace CliffordAlgebra
-- The `Inhabited, Semiring, Algebra` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _
instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _
instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A]
[Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M)
[IsScalarTower R A M] :
Algebra R (CliffordAlgebra Q) :=
RingQuot.instAlgebra _
-- verify there are no diamonds
-- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example : (Semiring.toNatAlgebra : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl
-- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example : (Ring.toIntAlgebra _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl
-- shortcut instance, as the other instance is slow
instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _
instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A]
[Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M)
[IsScalarTower R A M] [IsScalarTower S A M] :
SMulCommClass R S (CliffordAlgebra Q) :=
RingQuot.instSMulCommClass _
instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A]
[SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M]
[IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] (Q : QuadraticForm A M) :
IsScalarTower R S (CliffordAlgebra Q) :=
RingQuot.instIsScalarTower _
/-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`.
-/
def ι : M →ₗ[R] CliffordAlgebra Q :=
(RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R)
/-- As well as being linear, `ι Q` squares to the quadratic form -/
@[simp]
theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by
rw [ι]
erw [LinearMap.comp_apply]
rw [AlgHom.toLinearMap_apply, ← map_mul (RingQuot.mkAlgHom R (Rel Q)),
RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes]
rfl
variable {Q} {A : Type*} [Semiring A] [Algebra R A]
@[simp]
theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) :
g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by
rw [← map_mul, ι_sq_scalar, AlgHom.commutes]
variable (Q) in
| /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `CliffordAlgebra Q` to `A`.
| Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean | 125 | 127 |
/-
Copyright (c) 2022 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.WittVector.Identities
/-!
# Witt vectors over a domain
This file builds to the proof `WittVector.instIsDomain`,
an instance that says if `R` is an integral domain, then so is `𝕎 R`.
It depends on the API around iterated applications
of `WittVector.verschiebung` and `WittVector.frobenius`
found in `Identities.lean`.
The [proof sketch](https://math.stackexchange.com/questions/4117247/ring-of-witt-vectors-over-an-integral-domain/4118723#4118723)
goes as follows:
any nonzero $x$ is an iterated application of $V$
to some vector $w_x$ whose 0th component is nonzero (`WittVector.verschiebung_nonzero`).
Known identities (`WittVector.iterate_verschiebung_mul`) allow us to transform
the product of two such $x$ and $y$
to the form $V^{m+n}\left(F^n(w_x) \cdot F^m(w_y)\right)$,
the 0th component of which must be nonzero.
## Main declarations
* `WittVector.iterate_verschiebung_mul_coeff` : an identity from [Haze09]
* `WittVector.instIsDomain`
-/
noncomputable section
namespace WittVector
open Function
variable {p : ℕ} {R : Type*}
local notation "𝕎" => WittVector p -- type as `\bbW`
/-!
## The `shift` operator
-/
/--
`WittVector.verschiebung` translates the entries of a Witt vector upward, inserting 0s in the gaps.
`WittVector.shift` does the opposite, removing the first entries.
This is mainly useful as an auxiliary construction for `WittVector.verschiebung_nonzero`.
-/
def shift (x : 𝕎 R) (n : ℕ) : 𝕎 R :=
@mk' p R fun i => x.coeff (n + i)
theorem shift_coeff (x : 𝕎 R) (n k : ℕ) : (x.shift n).coeff k = x.coeff (n + k) :=
rfl
variable [hp : Fact p.Prime] [CommRing R]
theorem verschiebung_shift (x : 𝕎 R) (k : ℕ) (h : ∀ i < k + 1, x.coeff i = 0) :
verschiebung (x.shift k.succ) = x.shift k := by
ext ⟨j⟩
· rw [verschiebung_coeff_zero, shift_coeff, h]
apply Nat.lt_succ_self
· simp only [verschiebung_coeff_succ, shift]
| congr 1
rw [Nat.add_succ, add_comm, Nat.add_succ, add_comm]
theorem eq_iterate_verschiebung {x : 𝕎 R} {n : ℕ} (h : ∀ i < n, x.coeff i = 0) :
x = verschiebung^[n] (x.shift n) := by
induction' n with k ih
· cases x; simp [shift]
· dsimp; rw [verschiebung_shift]
| Mathlib/RingTheory/WittVector/Domain.lean | 69 | 76 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by
by_cases hp0 : p = 0
· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots ≤ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by
classical
rw [← count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R}
(hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by
rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) :
#Z ≤ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [← sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by
rintro ⟨k, rfl⟩
exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x ∈ (p - C a).roots ↔ p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = ∅ :=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X - C b).roots =
{a⁻¹ * b} := by
rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (a⁻¹ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X + C b).roots =
{-(a⁻¹ * b)} := by
rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ←
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by
rcases m with ⟨L⟩
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) :
s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with ⟨m, hm⟩
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a ≠ 0) (n : ℕ) :
Polynomial.roots (C a * X ^ n) = n • ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a ≠ 0) (n : ℕ) : (monomial n a).roots = n • ({0} : Multiset R) := by
rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
· rw [Multiset.mem_map]
rintro ⟨a, -, h⟩
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : ℕ} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) ≤ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot ℕ) ≤ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : ℕ) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp]
theorem mem_nthRoots {n : ℕ} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by
rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow,
eval_X, sub_eq_zero]
@[simp]
theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by
simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C]
@[simp]
theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : ℕ) :
nthRoots n (0 : R) = Multiset.replicate n 0 := by
rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton]
theorem card_nthRoots (n : ℕ) (a : R) : Multiset.card (nthRoots n a) ≤ n := by
classical exact
(if hn : n = 0 then
if h : (X : R[X]) ^ n - C a = 0 then by
simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero]
else
WithBot.coe_le_coe.1
(le_trans (card_roots h)
(by
rw [hn, pow_zero, ← C_1, ← RingHom.map_sub]
exact degree_C_le))
else by
rw [← Nat.cast_le (α := WithBot ℕ)]
rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a]
exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a))
@[simp]
theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ ¬IsSquare r := by
simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2),
← not_exists, eq_comm]
/-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be
`nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/
def nthRootsFinset (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R :=
haveI := Classical.decEq R
Multiset.toFinset (nthRoots n a)
lemma nthRootsFinset_def (n : ℕ) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] :
nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by
unfold nthRootsFinset
convert rfl
@[simp]
theorem mem_nthRootsFinset {n : ℕ} (h : 0 < n) (a : R) {x : R} :
x ∈ nthRootsFinset n a ↔ x ^ (n : ℕ) = a := by
classical
rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h]
@[simp]
theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = ∅ := by
classical simp [nthRootsFinset_def]
theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) :
f x ∈ nthRootsFinset n (f a) := by
by_cases hn : n = 0
· simp [hn] at hx
· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset
(Nat.pos_of_ne_zero hn) a).1 hx]
theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) :
f x ∈ nthRootsFinset n 1 := by
rw [← (map_one f)]
exact map_mem_nthRootsFinset hx _
theorem mul_mem_nthRootsFinset
{η₁ η₂ : R} {a₁ a₂ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hη₂ : η₂ ∈ nthRootsFinset n a₂) :
η₁ * η₂ ∈ nthRootsFinset n (a₁ * a₂) := by
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hη₁
| succ n =>
rw [mem_nthRootsFinset n.succ_pos] at hη₁ hη₂ ⊢
rw [mul_pow, hη₁, hη₂]
theorem ne_zero_of_mem_nthRootsFinset {η : R} {a : R} (ha : a ≠ 0) (hη : η ∈ nthRootsFinset n a) :
η ≠ 0 := by
nontriviality R
rintro rfl
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hη
| succ n =>
rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hη
exact ha hη.symm
theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by
rw [mem_nthRootsFinset hn, one_pow]
end NthRoots
theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : ∀ x, p.eval x = 0) : p = 0 := by
classical
by_contra hp
refine @Fintype.false R _ ?_
exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩
theorem funext [Infinite R] {p q : R[X]} (ext : ∀ r : R, p.eval r = q.eval r) : p = q := by
rw [← sub_eq_zero]
apply zero_of_eval_zero
intro x
rw [eval_sub, sub_eq_zero, ext]
variable [CommRing T]
/-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is
the multiset of roots of `p` regarded as a polynomial over `S`. -/
noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S :=
(p.map (algebraMap T S)).roots
theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
p.aroots S = (p.map (algebraMap T S)).roots :=
rfl
theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} :
a ∈ p.aroots S ↔ p.map (algebraMap T S) ≠ 0 ∧ aeval a p = 0 := by
rw [mem_roots', IsRoot.def, ← eval₂_eq_eval_map, aeval_def]
theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p ≠ 0 ∧ aeval a p = 0 := by
rw [mem_aroots', Polynomial.map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q ≠ 0) :
(p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q ≠ 0 by
rw [aroots_def, Polynomial.map_mul, roots_mul this]
rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff
(FaithfulSMul.algebraMap_injective T S)]
@[simp]
theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S]
(r : T) : aroots (X - C r) S = {algebraMap T S r} := by
rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C]
@[simp]
theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] :
aroots (X : T[X]) S = {0} := by
rw [aroots_def, map_X, roots_X]
@[simp]
theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by
rw [aroots_def, map_C, roots_C]
@[simp]
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [← C_0, aroots_C]
@[simp]
theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] :
(1 : T[X]).aroots S = 0 :=
aroots_C 1
@[simp]
theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) :
(-p).aroots S = p.aroots S := by
rw [aroots, Polynomial.map_neg, roots_neg]
@[simp]
theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(C a * p).aroots S = p.aroots S := by
rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul]
rwa [map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
@[simp]
theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a ≠ 0) :
(a • p).aroots S = p.aroots S := by
rw [smul_eq_C_mul, aroots_C_mul _ ha]
@[simp]
theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : ℕ) :
(p ^ n).aroots S = n • p.aroots S := by
rw [aroots_def, Polynomial.map_pow, roots_pow]
theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : ℕ) :
(X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_pow, aroots_X]
theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S]
| [NoZeroSMulDivisors T S] {a : T} (ha : a ≠ 0) (n : ℕ) :
(C a * X ^ n : T[X]).aroots S = n • ({0} : Multiset S) := by
rw [aroots_C_mul _ ha, aroots_X_pow]
@[simp]
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S]
| Mathlib/Algebra/Polynomial/Roots.lean | 465 | 470 |
/-
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.Topology.Compactness.Bases
import Mathlib.Topology.NoetherianSpace
/-!
# Quasi-separated spaces
A topological space is quasi-separated if the intersections of any pairs of compact open subsets
are still compact.
Notable examples include spectral spaces, Noetherian spaces, and Hausdorff spaces.
A non-example is the interval `[0, 1]` with doubled origin: the two copies of `[0, 1]` are compact
open subsets, but their intersection `(0, 1]` is not.
## Main results
- `IsQuasiSeparated`: A subset `s` of a topological space is quasi-separated if the intersections
of any pairs of compact open subsets of `s` are still compact.
- `QuasiSeparatedSpace`: A topological space is quasi-separated if the intersections of any pairs
of compact open subsets are still compact.
- `QuasiSeparatedSpace.of_isOpenEmbedding`: If `f : α → β` is an open embedding, and `β` is
a quasi-separated space, then so is `α`.
-/
open Set TopologicalSpace Topology
variable {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {f : α → β}
/-- A subset `s` of a topological space is quasi-separated if the intersections of any pairs of
compact open subsets of `s` are still compact.
Note that this is equivalent to `s` being a `QuasiSeparatedSpace` only when `s` is open. -/
def IsQuasiSeparated (s : Set α) : Prop :=
∀ U V : Set α, U ⊆ s → IsOpen U → IsCompact U → V ⊆ s → IsOpen V → IsCompact V → IsCompact (U ∩ V)
/-- A topological space is quasi-separated if the intersections of any pairs of compact open
subsets are still compact. -/
@[mk_iff]
class QuasiSeparatedSpace (α : Type*) [TopologicalSpace α] : Prop where
/-- The intersection of two open compact subsets of a quasi-separated space is compact. -/
inter_isCompact :
∀ U V : Set α, IsOpen U → IsCompact U → IsOpen V → IsCompact V → IsCompact (U ∩ V)
theorem isQuasiSeparated_univ_iff {α : Type*} [TopologicalSpace α] :
IsQuasiSeparated (Set.univ : Set α) ↔ QuasiSeparatedSpace α := by
rw [quasiSeparatedSpace_iff]
simp [IsQuasiSeparated]
theorem isQuasiSeparated_univ {α : Type*} [TopologicalSpace α] [QuasiSeparatedSpace α] :
IsQuasiSeparated (Set.univ : Set α) :=
isQuasiSeparated_univ_iff.mpr inferInstance
theorem IsQuasiSeparated.image_of_isEmbedding {s : Set α} (H : IsQuasiSeparated s)
(h : IsEmbedding f) : IsQuasiSeparated (f '' s) := by
intro U V hU hU' hU'' hV hV' hV''
convert
(H (f ⁻¹' U) (f ⁻¹' V)
?_ (h.continuous.1 _ hU') ?_ ?_ (h.continuous.1 _ hV') ?_).image h.continuous
· symm
rw [← Set.preimage_inter, Set.image_preimage_eq_inter_range, Set.inter_eq_left]
exact Set.inter_subset_left.trans (hU.trans (Set.image_subset_range _ _))
· intro x hx
rw [← h.injective.injOn.mem_image_iff (Set.subset_univ _) trivial]
exact hU hx
· rw [h.isCompact_iff]
convert hU''
rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left]
exact hU.trans (Set.image_subset_range _ _)
· intro x hx
rw [← h.injective.injOn.mem_image_iff (Set.subset_univ _) trivial]
exact hV hx
· rw [h.isCompact_iff]
convert hV''
rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left]
exact hV.trans (Set.image_subset_range _ _)
@[deprecated (since := "2024-10-26")]
alias IsQuasiSeparated.image_of_embedding := IsQuasiSeparated.image_of_isEmbedding
theorem Topology.IsOpenEmbedding.isQuasiSeparated_iff (h : IsOpenEmbedding f) {s : Set α} :
IsQuasiSeparated s ↔ IsQuasiSeparated (f '' s) := by
refine ⟨fun hs => hs.image_of_isEmbedding h.isEmbedding, ?_⟩
intro H U V hU hU' hU'' hV hV' hV''
rw [h.isEmbedding.isCompact_iff, Set.image_inter h.injective]
| exact
H (f '' U) (f '' V) (Set.image_subset _ hU) (h.isOpenMap _ hU') (hU''.image h.continuous)
(Set.image_subset _ hV) (h.isOpenMap _ hV') (hV''.image h.continuous)
theorem isQuasiSeparated_iff_quasiSeparatedSpace (s : Set α) (hs : IsOpen s) :
IsQuasiSeparated s ↔ QuasiSeparatedSpace s := by
rw [← isQuasiSeparated_univ_iff]
convert (hs.isOpenEmbedding_subtypeVal.isQuasiSeparated_iff (s := Set.univ)).symm
| Mathlib/Topology/QuasiSeparated.lean | 89 | 96 |
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Logic.Equiv.Basic
/-!
# Symmetric difference and bi-implication
This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.
## Examples
Some examples are
* The symmetric difference of two sets is the set of elements that are in either but not both.
* The symmetric difference on propositions is `Xor'`.
* The symmetric difference on `Bool` is `Bool.xor`.
* The equivalence of propositions. Two propositions are equivalent if they imply each other.
* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean
ring.
## Main declarations
* `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)`
* `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)`
In generalized Boolean algebras, the symmetric difference operator is:
* `symmDiff_comm`: commutative, and
* `symmDiff_assoc`: associative.
## Notations
* `a ∆ b`: `symmDiff a b`
* `a ⇔ b`: `bihimp a b`
## References
The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A
Proof from the Book" by John McCuan:
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
## Tags
boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,
Heyting
-/
assert_not_exists RelIso
open Function OrderDual
variable {ι α β : Type*} {π : ι → Type*}
/-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/
def symmDiff [Max α] [SDiff α] (a b : α) : α :=
a \ b ⊔ b \ a
/-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of
propositions. -/
def bihimp [Min α] [HImp α] (a b : α) : α :=
(b ⇨ a) ⊓ (a ⇨ b)
/-- Notation for symmDiff -/
scoped[symmDiff] infixl:100 " ∆ " => symmDiff
/-- Notation for bihimp -/
scoped[symmDiff] infixl:100 " ⇔ " => bihimp
open scoped symmDiff
theorem symmDiff_def [Max α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a :=
rfl
theorem bihimp_def [Min α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) :=
rfl
theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q :=
rfl
@[simp]
theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) :=
iff_iff_implies_and_implies.symm.trans Iff.comm
@[simp]
theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra α] (a b c : α)
@[simp]
theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b :=
rfl
@[simp]
theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b :=
rfl
theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm]
instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) :=
⟨symmDiff_comm⟩
@[simp]
theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self]
@[simp]
theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]
@[simp]
theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot]
@[simp]
theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by
simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]
theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]
theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]
theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c :=
sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb
theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by
simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]
@[simp]
theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b :=
sup_le_sup sdiff_le sdiff_le
theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff]
theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by
rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]
theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by
rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]
@[simp]
theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by
rw [symmDiff_sdiff]
simp [symmDiff]
@[simp]
theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by
rw [symmDiff, sdiff_idem]
exact
le_antisymm (sup_le_sup sdiff_le sdiff_le)
(sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)
@[simp]
theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by
rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm]
@[simp]
theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by
refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_
rw [sup_inf_left, symmDiff]
refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right)
· rw [sup_right_comm]
exact le_sup_of_le_left le_sdiff_sup
· rw [sup_assoc]
exact le_sup_of_le_right le_sdiff_sup
@[simp]
theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf]
@[simp]
theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by
rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf]
@[simp]
theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by
rw [symmDiff_comm, symmDiff_symmDiff_inf]
theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by
refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_
rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff]
theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by
convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot]
theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a :=
symmDiff_comm a b ▸ le_symmDiff_sup_right ..
end GeneralizedCoheytingAlgebra
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra α] (a b c : α)
@[simp]
theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b :=
rfl
@[simp]
theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b :=
rfl
theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm]
instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) :=
⟨bihimp_comm⟩
@[simp]
theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self]
@[simp]
theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq]
@[simp]
theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top]
@[simp]
theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b :=
@symmDiff_eq_bot αᵒᵈ _ _ _
theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by
rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]
theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by
rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq]
theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c :=
le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb
theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by
simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm]
@[simp]
theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b :=
inf_le_inf le_himp le_himp
theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp]
theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by
rw [bihimp, h.himp_eq_left, h.himp_eq_right]
theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by
rw [bihimp, himp_inf_distrib, himp_himp, himp_himp]
@[simp]
theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by
rw [himp_bihimp]
simp [bihimp]
| Mathlib/Order/SymmDiff.lean | 252 | 252 | |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Algebra.Order.Ring.Abs
/-!
# Lemmas about units in `ℤ`, which interact with the order structure.
-/
namespace Int
theorem isUnit_iff_abs_eq {x : ℤ} : IsUnit x ↔ abs x = 1 := by
rw [isUnit_iff_natAbs_eq, abs_eq_natAbs, ← Int.ofNat_one, natCast_inj]
|
theorem isUnit_sq {a : ℤ} (ha : IsUnit a) : a ^ 2 = 1 := by rw [sq, isUnit_mul_self ha]
| Mathlib/Data/Int/Order/Units.lean | 17 | 18 |
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Peter Pfaffelhuber, Yaël Dillies, Kin Yau James Wong
-/
import Mathlib.MeasureTheory.MeasurableSpace.Constructions
import Mathlib.MeasureTheory.PiSystem
import Mathlib.Topology.Constructions
/-!
# π-systems of cylinders and square cylinders
The instance `MeasurableSpace.pi` on `∀ i, α i`, where each `α i` has a `MeasurableSpace` `m i`,
is defined as `⨆ i, (m i).comap (fun a => a i)`.
That is, a function `g : β → ∀ i, α i` is measurable iff for all `i`, the function `b ↦ g b i`
is measurable.
We define two π-systems generating `MeasurableSpace.pi`, cylinders and square cylinders.
## Main definitions
Given a finite set `s` of indices, a cylinder is the product of a set of `∀ i : s, α i` and of
`univ` on the other indices. A square cylinder is a cylinder for which the set on `∀ i : s, α i` is
a product set.
* `cylinder s S`: cylinder with base set `S : Set (∀ i : s, α i)` where `s` is a `Finset`
* `squareCylinders C` with `C : ∀ i, Set (Set (α i))`: set of all square cylinders such that for
all `i` in the finset defining the box, the projection to `α i` belongs to `C i`. The main
application of this is with `C i = {s : Set (α i) | MeasurableSet s}`.
* `measurableCylinders`: set of all cylinders with measurable base sets.
* `cylinderEvents Δ`: The σ-algebra of cylinder events on `Δ`. It is the smallest σ-algebra making
the projections on the `i`-th coordinate continuous for all `i ∈ Δ`.
## Main statements
* `generateFrom_squareCylinders`: square cylinders formed from measurable sets generate the product
σ-algebra
* `generateFrom_measurableCylinders`: cylinders formed from measurable sets generate the
product σ-algebra
-/
open Function Set
namespace MeasureTheory
variable {ι : Type _} {α : ι → Type _}
section squareCylinders
/-- Given a finite set `s` of indices, a square cylinder is the product of a set `S` of
`∀ i : s, α i` and of `univ` on the other indices. The set `S` is a product of sets `t i` such that
for all `i : s`, `t i ∈ C i`.
`squareCylinders` is the set of all such squareCylinders. -/
def squareCylinders (C : ∀ i, Set (Set (α i))) : Set (Set (∀ i, α i)) :=
{S | ∃ s : Finset ι, ∃ t ∈ univ.pi C, S = (s : Set ι).pi t}
theorem squareCylinders_eq_iUnion_image (C : ∀ i, Set (Set (α i))) :
squareCylinders C = ⋃ s : Finset ι, (fun t ↦ (s : Set ι).pi t) '' univ.pi C := by
ext1 f
simp only [squareCylinders, mem_iUnion, mem_image, mem_univ_pi, exists_prop, mem_setOf_eq,
eq_comm (a := f)]
theorem isPiSystem_squareCylinders {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i))
(hC_univ : ∀ i, univ ∈ C i) :
IsPiSystem (squareCylinders C) := by
rintro S₁ ⟨s₁, t₁, h₁, rfl⟩ S₂ ⟨s₂, t₂, h₂, rfl⟩ hst_nonempty
classical
let t₁' := s₁.piecewise t₁ (fun i ↦ univ)
let t₂' := s₂.piecewise t₂ (fun i ↦ univ)
have h1 : ∀ i ∈ (s₁ : Set ι), t₁ i = t₁' i :=
fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm
have h1' : ∀ i ∉ (s₁ : Set ι), t₁' i = univ :=
fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi
have h2 : ∀ i ∈ (s₂ : Set ι), t₂ i = t₂' i :=
fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm
have h2' : ∀ i ∉ (s₂ : Set ι), t₂' i = univ :=
fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi
rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, ← union_pi_inter h1' h2']
refine ⟨s₁ ∪ s₂, fun i ↦ t₁' i ∩ t₂' i, ?_, ?_⟩
· rw [mem_univ_pi]
intro i
have : (t₁' i ∩ t₂' i).Nonempty := by
obtain ⟨f, hf⟩ := hst_nonempty
rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, mem_inter_iff, mem_pi, mem_pi] at hf
refine ⟨f i, ⟨?_, ?_⟩⟩
· by_cases hi₁ : i ∈ s₁
· exact hf.1 i hi₁
· rw [h1' i hi₁]
exact mem_univ _
· by_cases hi₂ : i ∈ s₂
· exact hf.2 i hi₂
· rw [h2' i hi₂]
exact mem_univ _
refine hC i _ ?_ _ ?_ this
· by_cases hi₁ : i ∈ s₁
· rw [← h1 i hi₁]
exact h₁ i (mem_univ _)
· rw [h1' i hi₁]
exact hC_univ i
· by_cases hi₂ : i ∈ s₂
· rw [← h2 i hi₂]
exact h₂ i (mem_univ _)
· rw [h2' i hi₂]
exact hC_univ i
· rw [Finset.coe_union]
theorem comap_eval_le_generateFrom_squareCylinders_singleton
(α : ι → Type*) [m : ∀ i, MeasurableSpace (α i)] (i : ι) :
MeasurableSpace.comap (Function.eval i) (m i) ≤
MeasurableSpace.generateFrom
((fun t ↦ ({i} : Set ι).pi t) '' univ.pi fun i ↦ {s : Set (α i) | MeasurableSet s}) := by
simp only [Function.eval, singleton_pi]
rw [MeasurableSpace.comap_eq_generateFrom]
refine MeasurableSpace.generateFrom_mono fun S ↦ ?_
simp only [mem_setOf_eq, mem_image, mem_univ_pi, forall_exists_index, and_imp]
intro t ht h
classical
refine ⟨fun j ↦ if hji : j = i then by convert t else univ, fun j ↦ ?_, ?_⟩
· by_cases hji : j = i
· simp only [hji, eq_self_iff_true, eq_mpr_eq_cast, dif_pos]
convert ht
simp only [id_eq, cast_heq]
· simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ]
· simp only [id_eq, eq_mpr_eq_cast, ← h]
ext1 x
simp only [singleton_pi, Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage]
/-- The square cylinders formed from measurable sets generate the product σ-algebra. -/
theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] :
MeasurableSpace.generateFrom (squareCylinders fun i ↦ {s : Set (α i) | MeasurableSet s}) =
MeasurableSpace.pi := by
apply le_antisymm
· rw [MeasurableSpace.generateFrom_le_iff]
rintro S ⟨s, t, h, rfl⟩
simp only [mem_univ_pi, mem_setOf_eq] at h
exact MeasurableSet.pi (Finset.countable_toSet _) (fun i _ ↦ h i)
· refine iSup_le fun i ↦ ?_
refine (comap_eval_le_generateFrom_squareCylinders_singleton α i).trans ?_
refine MeasurableSpace.generateFrom_mono ?_
rw [← Finset.coe_singleton, squareCylinders_eq_iUnion_image]
exact subset_iUnion
(fun (s : Finset ι) ↦
(fun t : ∀ i, Set (α i) ↦ (s : Set ι).pi t) '' univ.pi (fun i ↦ setOf MeasurableSet))
({i} : Finset ι)
end squareCylinders
section cylinder
/-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by
the projection from `∀ i, α i` to `∀ i : s, α i`. -/
def cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : Set (∀ i, α i) :=
s.restrict ⁻¹' S
@[simp]
theorem mem_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) (f : ∀ i, α i) :
f ∈ cylinder s S ↔ s.restrict f ∈ S :=
mem_preimage
@[simp]
theorem cylinder_empty (s : Finset ι) : cylinder s (∅ : Set (∀ i : s, α i)) = ∅ := by
rw [cylinder, preimage_empty]
@[simp]
theorem cylinder_univ (s : Finset ι) : cylinder s (univ : Set (∀ i : s, α i)) = univ := by
rw [cylinder, preimage_univ]
@[simp]
theorem cylinder_eq_empty_iff [h_nonempty : Nonempty (∀ i, α i)] (s : Finset ι)
(S : Set (∀ i : s, α i)) :
cylinder s S = ∅ ↔ S = ∅ := by
refine ⟨fun h ↦ ?_, fun h ↦ by (rw [h]; exact cylinder_empty _)⟩
by_contra hS
rw [← Ne, ← nonempty_iff_ne_empty] at hS
let f := hS.some
have hf : f ∈ S := hS.choose_spec
classical
let f' : ∀ i, α i := fun i ↦ if hi : i ∈ s then f ⟨i, hi⟩ else h_nonempty.some i
have hf' : f' ∈ cylinder s S := by
rw [mem_cylinder]
simpa only [Finset.restrict_def, Finset.coe_mem, dif_pos, f']
rw [h] at hf'
exact not_mem_empty _ hf'
|
theorem inter_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i))
[DecidableEq ι] :
cylinder s₁ S₁ ∩ cylinder s₂ S₂ =
cylinder (s₁ ∪ s₂)
(Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∩
Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by
| Mathlib/MeasureTheory/Constructions/Cylinders.lean | 185 | 191 |
/-
Copyright (c) 2022 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Integral.Bochner.Basic
import Mathlib.MeasureTheory.Group.Measure
/-!
# Bochner Integration on Groups
We develop properties of integrals with a group as domain.
This file contains properties about integrability and Bochner integration.
-/
namespace MeasureTheory
open Measure TopologicalSpace
open scoped ENNReal
variable {𝕜 M α G E F : Type*} [MeasurableSpace G]
variable [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F]
variable {μ : Measure G} {f : G → E} {g : G}
section MeasurableInv
variable [Group G] [MeasurableInv G]
@[to_additive]
theorem Integrable.comp_inv [IsInvInvariant μ] {f : G → F} (hf : Integrable f μ) :
Integrable (fun t => f t⁻¹) μ :=
(hf.mono_measure (map_inv_eq_self μ).le).comp_measurable measurable_inv
@[to_additive]
theorem integral_inv_eq_self (f : G → E) (μ : Measure G) [IsInvInvariant μ] :
∫ x, f x⁻¹ ∂μ = ∫ x, f x ∂μ := by
have h : MeasurableEmbedding fun x : G => x⁻¹ := (MeasurableEquiv.inv G).measurableEmbedding
rw [← h.integral_map, map_inv_eq_self]
@[to_additive]
theorem IntegrableOn.comp_inv [IsInvInvariant μ] {f : G → F} {s : Set G} (hf : IntegrableOn f s μ) :
IntegrableOn (fun x => f x⁻¹) s⁻¹ μ := by
apply (integrable_map_equiv (MeasurableEquiv.inv G) f).mp
have : s⁻¹ = MeasurableEquiv.inv G ⁻¹' s := by simp
rw [this, ← MeasurableEquiv.restrict_map]
simpa using hf
end MeasurableInv
section MeasurableInvOrder
variable [PartialOrder G] [CommGroup G] [IsOrderedMonoid G] [MeasurableInv G]
variable [IsInvInvariant μ]
@[to_additive]
theorem IntegrableOn.comp_inv_Iic {c : G} {f : G → F} (hf : IntegrableOn f (Set.Ici c⁻¹) μ) :
IntegrableOn (fun x => f x⁻¹) (Set.Iic c) μ := by
simpa using hf.comp_inv
@[to_additive]
theorem IntegrableOn.comp_inv_Ici {c : G} {f : G → F} (hf : IntegrableOn f (Set.Iic c⁻¹) μ) :
IntegrableOn (fun x => f x⁻¹) (Set.Ici c) μ := by
simpa using hf.comp_inv
@[to_additive]
theorem IntegrableOn.comp_inv_Iio {c : G} {f : G → F} (hf : IntegrableOn f (Set.Ioi c⁻¹) μ) :
IntegrableOn (fun x => f x⁻¹) (Set.Iio c) μ := by
simpa using hf.comp_inv
@[to_additive]
theorem IntegrableOn.comp_inv_Ioi {c : G} {f : G → F} (hf : IntegrableOn f (Set.Iio c⁻¹) μ) :
IntegrableOn (fun x => f x⁻¹) (Set.Ioi c) μ := by
simpa using hf.comp_inv
end MeasurableInvOrder
section MeasurableMul
|
variable [Group G] [MeasurableMul G]
/-- Translating a function by left-multiplication does not change its integral with respect to a
left-invariant measure. -/
| Mathlib/MeasureTheory/Group/Integral.lean | 79 | 83 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Filippo A. E. Nuccio
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.RingTheory.FractionalIdeal.Basic
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic
import Mathlib.RingTheory.LocalRing.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.FieldSimp
/-!
# More operations on fractional ideals
## Main definitions
* `map` is the pushforward of a fractional ideal along an algebra morphism
Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions).
* `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions
* `Div (FractionalIdeal R⁰ K)` instance:
the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined)
## Main statement
* `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian
## References
* https://en.wikipedia.org/wiki/Fractional_ideal
## Tags
fractional ideal, fractional ideals, invertible ideal
-/
open IsLocalization Pointwise nonZeroDivisors
namespace FractionalIdeal
open Set Submodule
variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P]
variable [Algebra R P]
section
variable {P' : Type*} [CommRing P'] [Algebra R P']
variable {P'' : Type*} [CommRing P''] [Algebra R P'']
theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} :
IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I)
| ⟨a, a_nonzero, hI⟩ =>
⟨a, a_nonzero, fun b hb => by
obtain ⟨b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb
rw [AlgHom.toLinearMap_apply] at hb'
obtain ⟨x, hx⟩ := hI b' b'_mem
use x
rw [← g.commutes, hx, map_smul, hb']⟩
/-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/
def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I =>
⟨Submodule.map g.toLinearMap I, I.isFractional.map g⟩
@[simp, norm_cast]
theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) :
↑(map g I) = Submodule.map g.toLinearMap I :=
rfl
@[simp]
theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} :
y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y :=
Submodule.mem_map
variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P')
@[simp]
theorem map_id : I.map (AlgHom.id _ _) = I :=
coeToSubmodule_injective (Submodule.map_id (I : Submodule R P))
@[simp]
theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' :=
coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I)
@[simp, norm_cast]
theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by
ext x
simp only [mem_coeIdeal]
constructor
· rintro ⟨_, ⟨y, hy, rfl⟩, rfl⟩
exact ⟨y, hy, (g.commutes y).symm⟩
· rintro ⟨y, hy, rfl⟩
exact ⟨_, ⟨y, hy, rfl⟩, g.commutes y⟩
@[simp]
protected theorem map_one : (1 : FractionalIdeal S P).map g = 1 :=
map_coeIdeal g ⊤
@[simp]
protected theorem map_zero : (0 : FractionalIdeal S P).map g = 0 :=
map_coeIdeal g 0
@[simp]
protected theorem map_add : (I + J).map g = I.map g + J.map g :=
coeToSubmodule_injective (Submodule.map_sup _ _ _)
@[simp]
protected theorem map_mul : (I * J).map g = I.map g * J.map g := by
simp only [mul_def]
exact coeToSubmodule_injective (Submodule.map_mul _ _ _)
@[simp]
theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by
rw [← map_comp, g.symm_comp, map_id]
@[simp]
theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') :
(I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by
rw [← map_comp, g.comp_symm, map_id]
theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} :
f x ∈ map f I ↔ x ∈ I :=
mem_map.trans ⟨fun ⟨_, hx', x'_eq⟩ => h x'_eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩
theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) :
Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ =>
ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▸ map_mem_map h)
/-- If `g` is an equivalence, `map g` is an isomorphism -/
def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where
toFun := map g
invFun := map g.symm
map_add' I J := FractionalIdeal.map_add I J _
map_mul' I J := FractionalIdeal.map_mul I J _
left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id]
right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id]
@[simp]
theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') :
(mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g :=
rfl
@[simp]
theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I :=
rfl
@[simp]
theorem mapEquiv_symm (g : P ≃ₐ[R] P') :
((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm :=
rfl
@[simp]
theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) :=
RingEquiv.ext fun x => by simp
theorem isFractional_span_iff {s : Set P} :
IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) :=
⟨fun ⟨a, a_mem, h⟩ => ⟨a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟨a, a_mem, h⟩ =>
⟨a, a_mem, fun _ hb =>
span_induction (hx := hb) h
(by
rw [smul_zero]
exact isInteger_zero)
(fun x y _ _ hx hy => by
rw [smul_add]
exact isInteger_add hx hy)
fun s x _ hx => by
rw [smul_comm]
exact isInteger_smul hx⟩⟩
theorem isFractional_of_fg [IsLocalization S P] {I : Submodule R P} (hI : I.FG) :
IsFractional S I := by
rcases hI with ⟨I, rfl⟩
rcases exist_integer_multiples_of_finset S I with ⟨⟨s, hs1⟩, hs⟩
rw [isFractional_span_iff]
exact ⟨s, hs1, hs⟩
theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) :
∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) :=
Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx)
variable (S) in
theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) :
FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG :=
coeSubmodule_fg _ inj _
theorem fg_unit (I : (FractionalIdeal S P)ˣ) : FG (I : Submodule R P) :=
Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I
theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) :=
fg_unit h.unit
theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R)
(h : IsUnit (I : FractionalIdeal S P)) : I.FG := by
rw [← coeIdeal_fg S inj I]
exact FractionalIdeal.fg_of_isUnit (R := R) I h
variable (S P P')
variable [IsLocalization S P] [IsLocalization S P']
/-- `canonicalEquiv f f'` is the canonical equivalence between the fractional
ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/
noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' :=
mapEquiv
{ ringEquivOfRingEquiv P P' (RingEquiv.refl R)
(show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with
commutes' := fun _ => ringEquivOfRingEquiv_eq _ _ }
@[simp]
theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} :
x ∈ canonicalEquiv S P P' I ↔
∃ y ∈ I,
IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy)
(y : P) =
x := by
rw [canonicalEquiv, mapEquiv_apply, mem_map]
exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩
@[simp]
theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P :=
RingEquiv.ext fun I =>
SetLike.ext_iff.mpr fun x => by
rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply,
mem_map]
exact ⟨fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩, fun ⟨y, mem, Eq⟩ => ⟨y, mem, Eq⟩⟩
theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by
rw [← canonicalEquiv_symm, RingEquiv.symm_apply_apply]
@[simp]
theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P'']
[IsLocalization S P''] (I : FractionalIdeal S P) :
canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by
ext
simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply,
exists_prop, exists_exists_and_eq_and]
theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P'']
[IsLocalization S P''] :
(canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' :=
RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'')
@[simp]
theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by
ext
simp [IsLocalization.map_eq]
@[simp]
theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by
rw [← canonicalEquiv_trans_canonicalEquiv S P P]
convert (canonicalEquiv S P P).symm_trans_self
exact (canonicalEquiv_symm S P P).symm
end
section IsFractionRing
/-!
### `IsFractionRing` section
This section concerns fractional ideals in the field of fractions,
i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`.
-/
variable {K K' : Type*} [Field K] [Field K']
variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K']
variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K')
/-- Nonzero fractional ideals contain a nonzero integer. -/
theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) :
∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by
obtain ⟨y : K, y_mem, y_not_mem⟩ :=
SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI)
have y_ne_zero : y ≠ 0 := by simpa using y_not_mem
obtain ⟨z, ⟨x, hx⟩⟩ := exists_integer_multiple R⁰ y
refine ⟨x, ?_, ?_⟩
· rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def]
exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero
· rw [hx]
exact smul_mem _ _ y_mem
theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by
obtain ⟨x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI
contrapose! x_ne_zero with map_eq_zero
refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_))
exact ⟨algebraMap R K x, hx, h.commutes x⟩
@[simp]
theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 :=
⟨not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▸ FractionalIdeal.map_zero h⟩
theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal R⁰ K)) :=
coeIdeal_injective' le_rfl
theorem coeIdeal_inj {I J : Ideal R} :
(I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J :=
coeIdeal_inj' le_rfl
@[simp]
theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ :=
coeIdeal_eq_zero' le_rfl
theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ :=
coeIdeal_ne_zero' le_rfl
@[simp]
theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by
simpa only [Ideal.one_eq_top] using coeIdeal_inj
theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 :=
not_iff_not.mpr coeIdeal_eq_one
theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 :=
⟨fun h ↦ zero_of_num_eq_bot zero_not_mem_nonZeroDivisors h,
fun h ↦ h ▸ num_zero_eq (IsFractionRing.injective R K)⟩
end IsFractionRing
section Quotient
/-!
### `quotient` section
This section defines the ideal quotient of fractional ideals.
In this section we need that each non-zero `y : R` has an inverse in
the localization, i.e. that the localization is a field. We satisfy this
assumption by taking `S = nonZeroDivisors R`, `R`'s localization at which
is a field because `R` is a domain.
-/
variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K]
variable [Algebra R₁ K]
instance : Nontrivial (FractionalIdeal R₁⁰ K) :=
⟨⟨0, 1, fun h =>
have this : (1 : K) ∈ (0 : FractionalIdeal R₁⁰ K) := by
rw [← (algebraMap R₁ K).map_one]
simpa only [h] using coe_mem_one R₁⁰ 1
one_ne_zero ((mem_zero_iff _).mp this)⟩⟩
theorem ne_zero_of_mul_eq_one (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) : I ≠ 0 := fun hI =>
zero_ne_one' (FractionalIdeal R₁⁰ K)
(by
convert h
simp [hI])
variable [IsFractionRing R₁ K] [IsDomain R₁]
theorem _root_.IsFractional.div_of_nonzero {I J : Submodule R₁ K} :
IsFractional R₁⁰ I → IsFractional R₁⁰ J → J ≠ 0 → IsFractional R₁⁰ (I / J)
| ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩, h => by
obtain ⟨y, mem_J, not_mem_zero⟩ :=
SetLike.exists_of_lt (show 0 < J by simpa only using bot_lt_iff_ne_bot.mpr h)
obtain ⟨y', hy'⟩ := hJ y mem_J
use aI * y'
constructor
· apply (nonZeroDivisors R₁).mul_mem haI (mem_nonZeroDivisors_iff_ne_zero.mpr _)
intro y'_eq_zero
have : algebraMap R₁ K aJ * y = 0 := by
rw [← Algebra.smul_def, ← hy', y'_eq_zero, RingHom.map_zero]
have y_zero :=
(mul_eq_zero.mp this).resolve_left
(mt ((injective_iff_map_eq_zero (algebraMap R₁ K)).1 (IsFractionRing.injective _ _) _)
(mem_nonZeroDivisors_iff_ne_zero.mp haJ))
apply not_mem_zero
simpa
intro b hb
convert hI _ (hb _ (Submodule.smul_mem _ aJ mem_J)) using 1
rw [← hy', mul_comm b, ← Algebra.smul_def, mul_smul]
theorem fractional_div_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) :
IsFractional R₁⁰ (I / J : Submodule R₁ K) :=
I.isFractional.div_of_nonzero J.isFractional fun H =>
h <| coeToSubmodule_injective <| H.trans coe_zero.symm
open Classical in
noncomputable instance : Div (FractionalIdeal R₁⁰ K) :=
⟨fun I J => if h : J = 0 then 0 else ⟨I / J, fractional_div_of_nonzero h⟩⟩
variable {I J : FractionalIdeal R₁⁰ K}
@[simp]
theorem div_zero {I : FractionalIdeal R₁⁰ K} : I / 0 = 0 :=
dif_pos rfl
theorem div_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) :
I / J = ⟨I / J, fractional_div_of_nonzero h⟩ :=
dif_neg h
@[simp]
theorem coe_div {I J : FractionalIdeal R₁⁰ K} (hJ : J ≠ 0) :
(↑(I / J) : Submodule R₁ K) = ↑I / (↑J : Submodule R₁ K) :=
congr_arg _ (dif_neg hJ)
theorem mem_div_iff_of_nonzero {I J : FractionalIdeal R₁⁰ K} (h : J ≠ 0) {x} :
x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I := by
rw [div_nonzero h]
exact Submodule.mem_div_iff_forall_mul_mem
theorem mul_one_div_le_one {I : FractionalIdeal R₁⁰ K} : I * (1 / I) ≤ 1 := by
by_cases hI : I = 0
· rw [hI, div_zero, mul_zero]
exact zero_le 1
· rw [← coe_le_coe, coe_mul, coe_div hI, coe_one]
apply Submodule.mul_one_div_le_one
theorem le_self_mul_one_div {I : FractionalIdeal R₁⁰ K} (hI : I ≤ (1 : FractionalIdeal R₁⁰ K)) :
I ≤ I * (1 / I) := by
by_cases hI_nz : I = 0
· rw [hI_nz, div_zero, mul_zero]
· rw [← coe_le_coe, coe_mul, coe_div hI_nz, coe_one]
rw [← coe_le_coe, coe_one] at hI
exact Submodule.le_self_mul_one_div hI
theorem le_div_iff_of_nonzero {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) :
I ≤ J / J' ↔ ∀ x ∈ I, ∀ y ∈ J', x * y ∈ J :=
⟨fun h _ hx => (mem_div_iff_of_nonzero hJ').mp (h hx), fun h x hx =>
(mem_div_iff_of_nonzero hJ').mpr (h x hx)⟩
theorem le_div_iff_mul_le {I J J' : FractionalIdeal R₁⁰ K} (hJ' : J' ≠ 0) :
I ≤ J / J' ↔ I * J' ≤ J := by
rw [div_nonzero hJ']
-- Porting note: this used to be { convert; rw }, flipped the order.
rw [← coe_le_coe (I := I * J') (J := J), coe_mul]
exact Submodule.le_div_iff_mul_le
@[simp]
theorem div_one {I : FractionalIdeal R₁⁰ K} : I / 1 = I := by
rw [div_nonzero (one_ne_zero' (FractionalIdeal R₁⁰ K))]
ext
constructor <;> intro h
· simpa using mem_div_iff_forall_mul_mem.mp h 1 ((algebraMap R₁ K).map_one ▸ coe_mem_one R₁⁰ 1)
· apply mem_div_iff_forall_mul_mem.mpr
rintro y ⟨y', _, rfl⟩
-- Porting note: this used to be { convert; rw }, flipped the order.
rw [mul_comm, Algebra.linearMap_apply, ← Algebra.smul_def]
exact Submodule.smul_mem _ y' h
theorem eq_one_div_of_mul_eq_one_right (I J : FractionalIdeal R₁⁰ K) (h : I * J = 1) :
J = 1 / I := by
have hI : I ≠ 0 := ne_zero_of_mul_eq_one I J h
suffices h' : I * (1 / I) = 1 from
congr_arg Units.inv <| @Units.ext _ _ (Units.mkOfMulEqOne _ _ h) (Units.mkOfMulEqOne _ _ h') rfl
apply le_antisymm
· apply mul_le.mpr _
intro x hx y hy
rw [mul_comm]
exact (mem_div_iff_of_nonzero hI).mp hy x hx
rw [← h]
apply mul_left_mono I
apply (le_div_iff_of_nonzero hI).mpr _
intro y hy x hx
rw [mul_comm]
exact mul_mem_mul hy hx
theorem mul_div_self_cancel_iff {I : FractionalIdeal R₁⁰ K} : I * (1 / I) = 1 ↔ ∃ J, I * J = 1 :=
⟨fun h => ⟨1 / I, h⟩, fun ⟨J, hJ⟩ => by rwa [← eq_one_div_of_mul_eq_one_right I J hJ]⟩
variable {K' : Type*} [Field K'] [Algebra R₁ K'] [IsFractionRing R₁ K']
@[simp]
protected theorem map_div (I J : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
(I / J).map (h : K →ₐ[R₁] K') = I.map h / J.map h := by
by_cases H : J = 0
· rw [H, div_zero, FractionalIdeal.map_zero, div_zero]
· -- Porting note: `simp` wouldn't apply these lemmas so do them manually using `rw`
rw [← coeToSubmodule_inj, div_nonzero H, div_nonzero (map_ne_zero _ H)]
simp [Submodule.map_div]
-- Porting note: doesn't need to be @[simp] because this follows from `map_one` and `map_div`
theorem map_one_div (I : FractionalIdeal R₁⁰ K) (h : K ≃ₐ[R₁] K') :
(1 / I).map (h : K →ₐ[R₁] K') = 1 / I.map h := by
rw [FractionalIdeal.map_div, FractionalIdeal.map_one]
end Quotient
section Field
variable {R₁ K L : Type*} [CommRing R₁] [Field K] [Field L]
variable [Algebra R₁ K] [IsFractionRing R₁ K] [Algebra K L] [IsFractionRing K L]
theorem eq_zero_or_one (I : FractionalIdeal K⁰ L) : I = 0 ∨ I = 1 := by
rw [or_iff_not_imp_left]
intro hI
simp_rw [@SetLike.ext_iff _ _ _ I 1, mem_one_iff]
intro x
constructor
· intro x_mem
obtain ⟨n, d, rfl⟩ := IsLocalization.mk'_surjective K⁰ x
refine ⟨n / d, ?_⟩
rw [map_div₀, IsFractionRing.mk'_eq_div]
· rintro ⟨x, rfl⟩
obtain ⟨y, y_ne, y_mem⟩ := exists_ne_zero_mem_isInteger hI
rw [← div_mul_cancel₀ x y_ne, RingHom.map_mul, ← Algebra.smul_def]
| exact smul_mem (M := L) I (x / y) y_mem
theorem eq_zero_or_one_of_isField (hF : IsField R₁) (I : FractionalIdeal R₁⁰ K) : I = 0 ∨ I = 1 :=
letI : Field R₁ := hF.toField
eq_zero_or_one I
end Field
section PrincipalIdeal
variable {R₁ : Type*} [CommRing R₁] {K : Type*} [Field K]
variable [Algebra R₁ K] [IsFractionRing R₁ K]
variable (R₁)
/-- `FractionalIdeal.span_finset R₁ s f` is the fractional ideal of `R₁` generated by `f '' s`. -/
| Mathlib/RingTheory/FractionalIdeal/Operations.lean | 499 | 514 |
/-
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
| Mathlib/MeasureTheory/Measure/AEMeasurable.lean | 244 | 249 |
/-
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.PreservesHomology
import Mathlib.Algebra.Homology.ShortComplex.Abelian
import Mathlib.Algebra.Homology.ShortComplex.QuasiIso
import Mathlib.CategoryTheory.Abelian.Opposite
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Preadditive.Injective.Basic
/-!
# Exact short complexes
When `S : ShortComplex C`, this file defines a structure
`S.Exact` which expresses the exactness of `S`, i.e. there
exists a homology data `h : S.HomologyData` such that
`h.left.H` is zero. When `[S.HasHomology]`, it is equivalent
to the assertion `IsZero S.homology`.
Almost by construction, this notion of exactness is self dual,
see `Exact.op` and `Exact.unop`.
-/
namespace CategoryTheory
open Category Limits ZeroObject Preadditive
variable {C D : Type*} [Category C] [Category D]
namespace ShortComplex
section
variable
[HasZeroMorphisms C] [HasZeroMorphisms D] (S : ShortComplex C) {S₁ S₂ : ShortComplex C}
/-- The assertion that the short complex `S : ShortComplex C` is exact. -/
structure Exact : Prop where
/-- the condition that there exists an homology data whose `left.H` field is zero -/
condition : ∃ (h : S.HomologyData), IsZero h.left.H
variable {S}
lemma Exact.hasHomology (h : S.Exact) : S.HasHomology :=
HasHomology.mk' h.condition.choose
lemma Exact.hasZeroObject (h : S.Exact) : HasZeroObject C :=
⟨h.condition.choose.left.H, h.condition.choose_spec⟩
variable (S)
lemma exact_iff_isZero_homology [S.HasHomology] :
S.Exact ↔ IsZero S.homology := by
constructor
· rintro ⟨⟨h', z⟩⟩
exact IsZero.of_iso z h'.left.homologyIso
· intro h
exact ⟨⟨_, h⟩⟩
variable {S}
lemma LeftHomologyData.exact_iff [S.HasHomology]
(h : S.LeftHomologyData) :
S.Exact ↔ IsZero h.H := by
rw [S.exact_iff_isZero_homology]
exact Iso.isZero_iff h.homologyIso
lemma RightHomologyData.exact_iff [S.HasHomology]
(h : S.RightHomologyData) :
S.Exact ↔ IsZero h.H := by
rw [S.exact_iff_isZero_homology]
exact Iso.isZero_iff h.homologyIso
variable (S)
lemma exact_iff_isZero_leftHomology [S.HasHomology] :
S.Exact ↔ IsZero S.leftHomology :=
LeftHomologyData.exact_iff _
lemma exact_iff_isZero_rightHomology [S.HasHomology] :
S.Exact ↔ IsZero S.rightHomology :=
RightHomologyData.exact_iff _
variable {S}
lemma HomologyData.exact_iff (h : S.HomologyData) :
S.Exact ↔ IsZero h.left.H := by
haveI := HasHomology.mk' h
exact LeftHomologyData.exact_iff h.left
lemma HomologyData.exact_iff' (h : S.HomologyData) :
S.Exact ↔ IsZero h.right.H := by
haveI := HasHomology.mk' h
exact RightHomologyData.exact_iff h.right
variable (S)
lemma exact_iff_homology_iso_zero [S.HasHomology] [HasZeroObject C] :
S.Exact ↔ Nonempty (S.homology ≅ 0) := by
rw [exact_iff_isZero_homology]
constructor
· intro h
exact ⟨h.isoZero⟩
· rintro ⟨e⟩
exact IsZero.of_iso (isZero_zero C) e
lemma exact_of_iso (e : S₁ ≅ S₂) (h : S₁.Exact) : S₂.Exact := by
obtain ⟨⟨h, z⟩⟩ := h
exact ⟨⟨HomologyData.ofIso e h, z⟩⟩
lemma exact_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ↔ S₂.Exact :=
⟨exact_of_iso e, exact_of_iso e.symm⟩
lemma exact_and_mono_f_iff_of_iso (e : S₁ ≅ S₂) :
S₁.Exact ∧ Mono S₁.f ↔ S₂.Exact ∧ Mono S₂.f := by
have : Mono S₁.f ↔ Mono S₂.f :=
(MorphismProperty.monomorphisms C).arrow_mk_iso_iff
(Arrow.isoMk (ShortComplex.π₁.mapIso e) (ShortComplex.π₂.mapIso e) e.hom.comm₁₂)
rw [exact_iff_of_iso e, this]
lemma exact_and_epi_g_iff_of_iso (e : S₁ ≅ S₂) :
S₁.Exact ∧ Epi S₁.g ↔ S₂.Exact ∧ Epi S₂.g := by
have : Epi S₁.g ↔ Epi S₂.g :=
(MorphismProperty.epimorphisms C).arrow_mk_iso_iff
(Arrow.isoMk (ShortComplex.π₂.mapIso e) (ShortComplex.π₃.mapIso e) e.hom.comm₂₃)
rw [exact_iff_of_iso e, this]
lemma exact_of_isZero_X₂ (h : IsZero S.X₂) : S.Exact := by
rw [(HomologyData.ofZeros S (IsZero.eq_of_tgt h _ _) (IsZero.eq_of_src h _ _)).exact_iff]
exact h
lemma exact_iff_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] :
S₁.Exact ↔ S₂.Exact := by
constructor
· rintro ⟨h₁, z₁⟩
exact ⟨HomologyData.ofEpiOfIsIsoOfMono φ h₁, z₁⟩
· rintro ⟨h₂, z₂⟩
exact ⟨HomologyData.ofEpiOfIsIsoOfMono' φ h₂, z₂⟩
variable {S}
lemma HomologyData.exact_iff_i_p_zero (h : S.HomologyData) :
S.Exact ↔ h.left.i ≫ h.right.p = 0 := by
haveI := HasHomology.mk' h
rw [h.left.exact_iff, ← h.comm]
constructor
· intro z
rw [IsZero.eq_of_src z h.iso.hom 0, zero_comp, comp_zero]
· intro eq
simp only [IsZero.iff_id_eq_zero, ← cancel_mono h.iso.hom, id_comp, ← cancel_mono h.right.ι,
← cancel_epi h.left.π, eq, zero_comp, comp_zero]
variable (S)
lemma exact_iff_i_p_zero [S.HasHomology] (h₁ : S.LeftHomologyData)
(h₂ : S.RightHomologyData) :
S.Exact ↔ h₁.i ≫ h₂.p = 0 :=
(HomologyData.ofIsIsoLeftRightHomologyComparison' h₁ h₂).exact_iff_i_p_zero
lemma exact_iff_iCycles_pOpcycles_zero [S.HasHomology] :
S.Exact ↔ S.iCycles ≫ S.pOpcycles = 0 :=
S.exact_iff_i_p_zero _ _
lemma exact_iff_kernel_ι_comp_cokernel_π_zero [S.HasHomology]
| [HasKernel S.g] [HasCokernel S.f] :
S.Exact ↔ kernel.ι S.g ≫ cokernel.π S.f = 0 := by
haveI := HasLeftHomology.hasCokernel S
haveI := HasRightHomology.hasKernel S
exact S.exact_iff_i_p_zero (LeftHomologyData.ofHasKernelOfHasCokernel S)
(RightHomologyData.ofHasCokernelOfHasKernel S)
| Mathlib/Algebra/Homology/ShortComplex/Exact.lean | 168 | 174 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.