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 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Family
import Mathlib.Tactic.Abel
/-!
# Natural operations on ordinals
The goal of this file is to define natural addition and multiplication on ordinals, also known as
the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals
`a ♯ b` is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for `a' < a`
and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least
ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for any `a' < a` and
`b' < b`.
These operations form a rich algebraic structure: they're commutative, associative, preserve order,
have the usual `0` and `1` from ordinals, and distribute over one another.
Moreover, these operations are the addition and multiplication of ordinals when viewed as
combinatorial `Game`s. This makes them particularly useful for game theory.
Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form.
The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were
polynomials in `ω`. Likewise, their natural multiplication corresponds to multiplying the Cantor
normal forms as polynomials.
## Implementation notes
Given the rich algebraic structure of these two operations, we choose to create a type synonym
`NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth
between both types, we attempt to prove and state most results on `Ordinal`.
## Todo
- Prove the characterizations of natural addition and multiplication in terms of the Cantor normal
form.
-/
universe u v
open Function Order Set
noncomputable section
/-! ### Basic casts between `Ordinal` and `NatOrdinal` -/
/-- A type synonym for ordinals with natural addition and multiplication. -/
def NatOrdinal : Type _ :=
Ordinal deriving Zero, Inhabited, One, WellFoundedRelation
-- The `LinearOrder, `SuccOrder` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance NatOrdinal.instLinearOrder : LinearOrder NatOrdinal := Ordinal.instLinearOrder
instance NatOrdinal.instSuccOrder : SuccOrder NatOrdinal := Ordinal.instSuccOrder
instance NatOrdinal.instOrderBot : OrderBot NatOrdinal := Ordinal.instOrderBot
instance NatOrdinal.instNoMaxOrder : NoMaxOrder NatOrdinal := Ordinal.instNoMaxOrder
instance NatOrdinal.instZeroLEOneClass : ZeroLEOneClass NatOrdinal := Ordinal.instZeroLEOneClass
instance NatOrdinal.instNeZeroOne : NeZero (1 : NatOrdinal) := Ordinal.instNeZeroOne
instance NatOrdinal.uncountable : Uncountable NatOrdinal :=
Ordinal.uncountable
/-- The identity function between `Ordinal` and `NatOrdinal`. -/
@[match_pattern]
def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal :=
OrderIso.refl _
/-- The identity function between `NatOrdinal` and `Ordinal`. -/
@[match_pattern]
def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal :=
OrderIso.refl _
namespace NatOrdinal
open Ordinal
@[simp]
theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal :=
rfl
@[simp]
theorem toOrdinal_toNatOrdinal (a : NatOrdinal) : a.toOrdinal.toNatOrdinal = a :=
rfl
theorem lt_wf : @WellFounded NatOrdinal (· < ·) :=
Ordinal.lt_wf
instance : WellFoundedLT NatOrdinal :=
Ordinal.wellFoundedLT
instance : ConditionallyCompleteLinearOrderBot NatOrdinal :=
WellFoundedLT.conditionallyCompleteLinearOrderBot _
@[simp] theorem bot_eq_zero : (⊥ : NatOrdinal) = 0 := rfl
@[simp] theorem toOrdinal_zero : toOrdinal 0 = 0 := rfl
@[simp] theorem toOrdinal_one : toOrdinal 1 = 1 := rfl
@[simp] theorem toOrdinal_eq_zero {a} : toOrdinal a = 0 ↔ a = 0 := Iff.rfl
@[simp] theorem toOrdinal_eq_one {a} : toOrdinal a = 1 ↔ a = 1 := Iff.rfl
@[simp]
theorem toOrdinal_max (a b : NatOrdinal) : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) :=
rfl
@[simp]
theorem toOrdinal_min (a b : NatOrdinal) : toOrdinal (min a b) = min (toOrdinal a) (toOrdinal b) :=
rfl
theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) :=
rfl
@[simp]
theorem zero_le (o : NatOrdinal) : 0 ≤ o :=
Ordinal.zero_le o
theorem not_lt_zero (o : NatOrdinal) : ¬ o < 0 :=
Ordinal.not_lt_zero o
@[simp]
theorem lt_one_iff_zero {o : NatOrdinal} : o < 1 ↔ o = 0 :=
Ordinal.lt_one_iff_zero
/-- A recursor for `NatOrdinal`. Use as `induction x`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
protected def rec {β : NatOrdinal → Sort*} (h : ∀ a, β (toNatOrdinal a)) : ∀ a, β a := fun a =>
h (toOrdinal a)
/-- `Ordinal.induction` but for `NatOrdinal`. -/
theorem induction {p : NatOrdinal → Prop} : ∀ (i) (_ : ∀ j, (∀ k, k < j → p k) → p j), p i :=
Ordinal.induction
instance small_Iio (a : NatOrdinal.{u}) : Small.{u} (Set.Iio a) := Ordinal.small_Iio a
instance small_Iic (a : NatOrdinal.{u}) : Small.{u} (Set.Iic a) := Ordinal.small_Iic a
instance small_Ico (a b : NatOrdinal.{u}) : Small.{u} (Set.Ico a b) := Ordinal.small_Ico a b
instance small_Icc (a b : NatOrdinal.{u}) : Small.{u} (Set.Icc a b) := Ordinal.small_Icc a b
instance small_Ioo (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioo a b) := Ordinal.small_Ioo a b
instance small_Ioc (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioc a b) := Ordinal.small_Ioc a b
end NatOrdinal
namespace Ordinal
variable {a b c : Ordinal.{u}}
@[simp] theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal := rfl
@[simp] theorem toNatOrdinal_toOrdinal (a : Ordinal) : a.toNatOrdinal.toOrdinal = a := rfl
@[simp] theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 := rfl
@[simp] theorem toNatOrdinal_one : toNatOrdinal 1 = 1 := rfl
@[simp] theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 := Iff.rfl
@[simp] theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 := Iff.rfl
@[simp]
theorem toNatOrdinal_max (a b : Ordinal) :
toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) :=
rfl
@[simp]
theorem toNatOrdinal_min (a b : Ordinal) :
toNatOrdinal (min a b) = min (toNatOrdinal a) (toNatOrdinal b) :=
rfl
/-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this
guarantees we only need to open the `NaturalOps` locale once. -/
/-- Natural addition on ordinals `a ♯ b`, also known as the Hessenberg sum, is recursively defined
as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for all `a' < a` and `b' < b`. In contrast
to normal ordinal addition, it is commutative.
Natural addition can equivalently be characterized as the ordinal resulting from adding up
corresponding coefficients in the Cantor normal forms of `a` and `b`. -/
noncomputable def nadd (a b : Ordinal.{u}) : Ordinal.{u} :=
max (⨆ x : Iio a, succ (nadd x.1 b)) (⨆ x : Iio b, succ (nadd a x.1))
termination_by (a, b)
decreasing_by all_goals cases x; decreasing_tactic
@[inherit_doc]
scoped[NaturalOps] infixl:65 " ♯ " => Ordinal.nadd
open NaturalOps
/-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively
defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for all
`a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and
distributive (over natural addition).
Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying
the Cantor normal forms of `a` and `b` as if they were polynomials in `ω`. Addition of exponents is
done via natural addition. -/
noncomputable def nmul (a b : Ordinal.{u}) : Ordinal.{u} :=
sInf {c | ∀ a' < a, ∀ b' < b, nmul a' b ♯ nmul a b' < c ♯ nmul a' b'}
termination_by (a, b)
@[inherit_doc]
scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul
/-! ### Natural addition -/
theorem lt_nadd_iff : a < b ♯ c ↔ (∃ b' < b, a ≤ b' ♯ c) ∨ ∃ c' < c, a ≤ b ♯ c' := by
rw [nadd]
simp [Ordinal.lt_iSup_iff]
theorem nadd_le_iff : b ♯ c ≤ a ↔ (∀ b' < b, b' ♯ c < a) ∧ ∀ c' < c, b ♯ c' < a := by
rw [← not_lt, lt_nadd_iff]
simp
theorem nadd_lt_nadd_left (h : b < c) (a) : a ♯ b < a ♯ c :=
lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩)
theorem nadd_lt_nadd_right (h : b < c) (a) : b ♯ a < c ♯ a :=
lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩)
theorem nadd_le_nadd_left (h : b ≤ c) (a) : a ♯ b ≤ a ♯ c := by
rcases lt_or_eq_of_le h with (h | rfl)
· exact (nadd_lt_nadd_left h a).le
· exact le_rfl
theorem nadd_le_nadd_right (h : b ≤ c) (a) : b ♯ a ≤ c ♯ a := by
rcases lt_or_eq_of_le h with (h | rfl)
· exact (nadd_lt_nadd_right h a).le
· exact le_rfl
variable (a b)
theorem nadd_comm (a b) : a ♯ b = b ♯ a := by
rw [nadd, nadd, max_comm]
congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_comm _ _)
termination_by (a, b)
@[deprecated "blsub will soon be deprecated" (since := "2024-11-18")]
theorem blsub_nadd_of_mono {f : ∀ c < a ♯ b, Ordinal.{max u v}}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) :
blsub.{u,v} _ f =
max (blsub.{u, v} a fun a' ha' => f (a' ♯ b) <| nadd_lt_nadd_right ha' b)
(blsub.{u, v} b fun b' hb' => f (a ♯ b') <| nadd_lt_nadd_left hb' a) := by
apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _)
· intro i h
rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩)
· exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha'))
· exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb'))
all_goals
apply blsub_le_of_brange_subset.{u, u, v}
rintro c ⟨d, hd, rfl⟩
apply mem_brange_self
private theorem iSup_nadd_of_monotone {a b} (f : Ordinal.{u} → Ordinal.{u}) (h : Monotone f) :
⨆ x : Iio (a ♯ b), f x = max (⨆ a' : Iio a, f (a'.1 ♯ b)) (⨆ b' : Iio b, f (a ♯ b'.1)) := by
apply (max_le _ _).antisymm'
· rw [Ordinal.iSup_le_iff]
rintro ⟨i, hi⟩
obtain ⟨x, hx, hi⟩ | ⟨x, hx, hi⟩ := lt_nadd_iff.1 hi
· exact le_max_of_le_left ((h hi).trans <| Ordinal.le_iSup (fun x : Iio a ↦ _) ⟨x, hx⟩)
· exact le_max_of_le_right ((h hi).trans <| Ordinal.le_iSup (fun x : Iio b ↦ _) ⟨x, hx⟩)
all_goals
apply csSup_le_csSup' (bddAbove_of_small _)
rintro _ ⟨⟨c, hc⟩, rfl⟩
refine mem_range_self (⟨_, ?_⟩ : Iio _)
apply_rules [nadd_lt_nadd_left, nadd_lt_nadd_right]
theorem nadd_assoc (a b c) : a ♯ b ♯ c = a ♯ (b ♯ c) := by
unfold nadd
rw [iSup_nadd_of_monotone fun a' ↦ succ (a' ♯ c), iSup_nadd_of_monotone fun b' ↦ succ (a ♯ b'),
max_assoc]
· congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_assoc _ _ _)
· exact succ_mono.comp fun x y h ↦ nadd_le_nadd_left h _
· exact succ_mono.comp fun x y h ↦ nadd_le_nadd_right h _
termination_by (a, b, c)
@[simp]
theorem nadd_zero (a : Ordinal) : a ♯ 0 = a := by
rw [nadd, ciSup_of_empty fun _ : Iio 0 ↦ _, sup_bot_eq]
convert iSup_succ a
rename_i x
cases x
exact nadd_zero _
termination_by a
@[simp]
theorem zero_nadd : 0 ♯ a = a := by rw [nadd_comm, nadd_zero]
@[simp]
theorem nadd_one (a : Ordinal) : a ♯ 1 = succ a := by
rw [nadd, ciSup_unique (s := fun _ : Iio 1 ↦ _), Iio_one_default_eq, nadd_zero,
max_eq_right_iff, Ordinal.iSup_le_iff]
rintro ⟨i, hi⟩
rwa [nadd_one, succ_le_succ_iff, succ_le_iff]
termination_by a
@[simp]
theorem one_nadd : 1 ♯ a = succ a := by rw [nadd_comm, nadd_one]
theorem nadd_succ : a ♯ succ b = succ (a ♯ b) := by rw [← nadd_one (a ♯ b), nadd_assoc, nadd_one]
theorem succ_nadd : succ a ♯ b = succ (a ♯ b) := by rw [← one_nadd (a ♯ b), ← nadd_assoc, one_nadd]
@[simp]
theorem nadd_nat (n : ℕ) : a ♯ n = a + n := by
induction' n with n hn
· simp
· rw [Nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn]
@[simp]
theorem nat_nadd (n : ℕ) : ↑n ♯ a = a + n := by rw [nadd_comm, nadd_nat]
theorem add_le_nadd : a + b ≤ a ♯ b := by
induction b using limitRecOn with
| zero => simp
| succ c h =>
rwa [add_succ, nadd_succ, succ_le_succ_iff]
| isLimit c hc H =>
rw [(isNormal_add_right a).apply_of_isLimit hc, Ordinal.iSup_le_iff]
rintro ⟨i, hi⟩
exact (H i hi).trans (nadd_le_nadd_left hi.le a)
end Ordinal
namespace NatOrdinal
| Mathlib/SetTheory/Ordinal/NaturalOps.lean | 324 | 324 | |
/-
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, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Pointwise
import Mathlib.Analysis.NormedSpace.Real
/-!
# Properties of pointwise scalar multiplication of sets in normed spaces.
We explore the relationships between scalar multiplication of sets in vector spaces, and the norm.
Notably, we express arbitrary balls as rescaling of other balls, and we show that the
multiplication of bounded sets remain bounded.
-/
open Metric Set
open Pointwise Topology
variable {𝕜 E : Type*}
section SMulZeroClass
variable [SeminormedAddCommGroup 𝕜] [SeminormedAddCommGroup E]
variable [SMulZeroClass 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem ediam_smul_le (c : 𝕜) (s : Set E) : EMetric.diam (c • s) ≤ ‖c‖₊ • EMetric.diam s :=
(lipschitzWith_smul c).ediam_image_le s
end SMulZeroClass
section DivisionRing
variable [NormedDivisionRing 𝕜] [SeminormedAddCommGroup E]
variable [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem ediam_smul₀ (c : 𝕜) (s : Set E) : EMetric.diam (c • s) = ‖c‖₊ • EMetric.diam s := by
refine le_antisymm (ediam_smul_le c s) ?_
obtain rfl | hc := eq_or_ne c 0
· obtain rfl | hs := s.eq_empty_or_nonempty
· simp
simp [zero_smul_set hs, ← Set.singleton_zero]
· have := (lipschitzWith_smul c⁻¹).ediam_image_le (c • s)
rwa [← smul_eq_mul, ← ENNReal.smul_def, Set.image_smul, inv_smul_smul₀ hc s, nnnorm_inv,
le_inv_smul_iff_of_pos (nnnorm_pos.2 hc)] at this
theorem diam_smul₀ (c : 𝕜) (x : Set E) : diam (c • x) = ‖c‖ * diam x := by
simp_rw [diam, ediam_smul₀, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm, smul_eq_mul]
theorem infEdist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) :
EMetric.infEdist (c • x) (c • s) = ‖c‖₊ • EMetric.infEdist x s := by
simp_rw [EMetric.infEdist]
have : Function.Surjective ((c • ·) : E → E) :=
Function.RightInverse.surjective (smul_inv_smul₀ hc)
trans ⨅ (y) (_ : y ∈ s), ‖c‖₊ • edist x y
· refine (this.iInf_congr _ fun y => ?_).symm
simp_rw [smul_mem_smul_set_iff₀ hc, edist_smul₀]
· have : (‖c‖₊ : ENNReal) ≠ 0 := by simp [hc]
simp_rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_iInf_of_ne this ENNReal.coe_ne_top]
theorem infDist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) :
Metric.infDist (c • x) (c • s) = ‖c‖ * Metric.infDist x s := by
simp_rw [Metric.infDist, infEdist_smul₀ hc s, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm,
smul_eq_mul]
end DivisionRing
variable [NormedField 𝕜]
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup E] [NormedSpace 𝕜 E]
theorem smul_ball {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • ball x r = ball (c • x) (‖c‖ * r) := by
ext y
rw [mem_smul_set_iff_inv_smul_mem₀ hc]
conv_lhs => rw [← inv_smul_smul₀ hc x]
simp [← div_eq_inv_mul, div_lt_iff₀ (norm_pos_iff.2 hc), mul_comm _ r, dist_smul₀]
theorem smul_unitBall {c : 𝕜} (hc : c ≠ 0) : c • ball (0 : E) (1 : ℝ) = ball (0 : E) ‖c‖ := by
rw [_root_.smul_ball hc, smul_zero, mul_one]
theorem smul_sphere' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • sphere x r = sphere (c • x) (‖c‖ * r) := by
ext y
rw [mem_smul_set_iff_inv_smul_mem₀ hc]
conv_lhs => rw [← inv_smul_smul₀ hc x]
simp only [mem_sphere, dist_smul₀, norm_inv, ← div_eq_inv_mul, div_eq_iff (norm_pos_iff.2 hc).ne',
mul_comm r]
theorem smul_closedBall' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • closedBall x r = closedBall (c • x) (‖c‖ * r) := by
simp only [← ball_union_sphere, Set.smul_set_union, _root_.smul_ball hc, smul_sphere' hc]
theorem set_smul_sphere_zero {s : Set 𝕜} (hs : 0 ∉ s) (r : ℝ) :
s • sphere (0 : E) r = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) :=
calc
s • sphere (0 : E) r = ⋃ c ∈ s, c • sphere (0 : E) r := iUnion_smul_left_image.symm
_ = ⋃ c ∈ s, sphere (0 : E) (‖c‖ * r) := iUnion₂_congr fun c hc ↦ by
rw [smul_sphere' (ne_of_mem_of_not_mem hc hs), smul_zero]
_ = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) := by ext; simp [eq_comm]
/-- Image of a bounded set in a normed space under scalar multiplication by a constant is
bounded. See also `Bornology.IsBounded.smul` for a similar lemma about an isometric action. -/
theorem Bornology.IsBounded.smul₀ {s : Set E} (hs : IsBounded s) (c : 𝕜) : IsBounded (c • s) :=
(lipschitzWith_smul c).isBounded_image hs
/-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r • s` is contained in any
fixed neighborhood of `x`. -/
theorem eventually_singleton_add_smul_subset {x : E} {s : Set E} (hs : Bornology.IsBounded s)
{u : Set E} (hu : u ∈ 𝓝 x) : ∀ᶠ r in 𝓝 (0 : 𝕜), {x} + r • s ⊆ u := by
obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ closedBall x ε ⊆ u := nhds_basis_closedBall.mem_iff.1 hu
obtain ⟨R, Rpos, hR⟩ : ∃ R : ℝ, 0 < R ∧ s ⊆ closedBall 0 R := hs.subset_closedBall_lt 0 0
have : Metric.closedBall (0 : 𝕜) (ε / R) ∈ 𝓝 (0 : 𝕜) := closedBall_mem_nhds _ (div_pos εpos Rpos)
filter_upwards [this] with r hr
simp only [image_add_left, singleton_add]
intro y hy
obtain ⟨z, zs, hz⟩ : ∃ z : E, z ∈ s ∧ r • z = -x + y := by simpa [mem_smul_set] using hy
have I : ‖r • z‖ ≤ ε :=
calc
‖r • z‖ = ‖r‖ * ‖z‖ := norm_smul _ _
_ ≤ ε / R * R :=
(mul_le_mul (mem_closedBall_zero_iff.1 hr) (mem_closedBall_zero_iff.1 (hR zs))
(norm_nonneg _) (div_pos εpos Rpos).le)
_ = ε := by field_simp
have : y = x + r • z := by simp only [hz, add_neg_cancel_left]
apply hε
simpa only [this, dist_eq_norm, add_sub_cancel_left, mem_closedBall] using I
variable [NormedSpace ℝ E] {x y z : E} {δ ε : ℝ}
/-- In a real normed space, the image of the unit ball under scalar multiplication by a positive
constant `r` is the ball of radius `r`. -/
theorem smul_unitBall_of_pos {r : ℝ} (hr : 0 < r) : r • ball (0 : E) 1 = ball (0 : E) r := by
rw [smul_unitBall hr.ne', Real.norm_of_nonneg hr.le]
lemma Ioo_smul_sphere_zero {a b r : ℝ} (ha : 0 ≤ a) (hr : 0 < r) :
Ioo a b • sphere (0 : E) r = ball 0 (b * r) \ closedBall 0 (a * r) := by
have : EqOn (‖·‖) id (Ioo a b) := fun x hx ↦ abs_of_pos (ha.trans_lt hx.1)
rw [set_smul_sphere_zero (by simp [ha.not_lt]), ← image_image (· * r), this.image_eq, image_id,
image_mul_right_Ioo _ _ hr]
ext x; simp [and_comm]
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_eq (x z : E) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
∃ y, dist x y = b * dist x z ∧ dist y z = a * dist x z := by
use a • x + b • z
nth_rw 1 [← one_smul ℝ x]
nth_rw 4 [← one_smul ℝ z]
simp [dist_eq_norm, ← hab, add_smul, ← smul_sub, norm_smul_of_nonneg, ha, hb]
theorem exists_dist_le_le (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (h : dist x z ≤ ε + δ) :
∃ y, dist x y ≤ δ ∧ dist y z ≤ ε := by
obtain rfl | hε' := hε.eq_or_lt
· exact ⟨z, by rwa [zero_add] at h, (dist_self _).le⟩
have hεδ := add_pos_of_pos_of_nonneg hε' hδ
refine (exists_dist_eq x z (div_nonneg hε <| add_nonneg hε hδ)
(div_nonneg hδ <| add_nonneg hε hδ) <| by
rw [← add_div, div_self hεδ.ne']).imp
fun y hy => ?_
rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε]
rw [← div_le_one hεδ] at h
exact ⟨mul_le_of_le_one_left hδ h, mul_le_of_le_one_left hε h⟩
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_le_lt (hδ : 0 ≤ δ) (hε : 0 < ε) (h : dist x z < ε + δ) :
∃ y, dist x y ≤ δ ∧ dist y z < ε := by
refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ)
(div_nonneg hδ <| add_nonneg hε.le hδ) <| by
rw [← add_div, div_self (add_pos_of_pos_of_nonneg hε hδ).ne']).imp
fun y hy => ?_
rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε]
rw [← div_lt_one (add_pos_of_pos_of_nonneg hε hδ)] at h
exact ⟨mul_le_of_le_one_left hδ h.le, mul_lt_of_lt_one_left hε h⟩
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_lt_le (hδ : 0 < δ) (hε : 0 ≤ ε) (h : dist x z < ε + δ) :
∃ y, dist x y < δ ∧ dist y z ≤ ε := by
obtain ⟨y, yz, xy⟩ :=
exists_dist_le_lt hε hδ (show dist z x < δ + ε by simpa only [dist_comm, add_comm] using h)
exact ⟨y, by simp [dist_comm x y, dist_comm y z, *]⟩
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_lt_lt (hδ : 0 < δ) (hε : 0 < ε) (h : dist x z < ε + δ) :
∃ y, dist x y < δ ∧ dist y z < ε := by
refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ.le)
(div_nonneg hδ.le <| add_nonneg hε.le hδ.le) <| by
rw [← add_div, div_self (add_pos hε hδ).ne']).imp
fun y hy => ?_
rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε]
rw [← div_lt_one (add_pos hε hδ)] at h
exact ⟨mul_lt_of_lt_one_left hδ h, mul_lt_of_lt_one_left hε h⟩
-- This is also true for `ℚ`-normed spaces
theorem disjoint_ball_ball_iff (hδ : 0 < δ) (hε : 0 < ε) :
Disjoint (ball x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by
refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_ball⟩
rw [add_comm] at hxy
obtain ⟨z, hxz, hzy⟩ := exists_dist_lt_lt hδ hε hxy
rw [dist_comm] at hxz
exact h.le_bot ⟨hxz, hzy⟩
-- This is also true for `ℚ`-normed spaces
theorem disjoint_ball_closedBall_iff (hδ : 0 < δ) (hε : 0 ≤ ε) :
Disjoint (ball x δ) (closedBall y ε) ↔ δ + ε ≤ dist x y := by
refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_closedBall⟩
rw [add_comm] at hxy
obtain ⟨z, hxz, hzy⟩ := exists_dist_lt_le hδ hε hxy
rw [dist_comm] at hxz
exact h.le_bot ⟨hxz, hzy⟩
-- This is also true for `ℚ`-normed spaces
theorem disjoint_closedBall_ball_iff (hδ : 0 ≤ δ) (hε : 0 < ε) :
Disjoint (closedBall x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by
rw [disjoint_comm, disjoint_ball_closedBall_iff hε hδ, add_comm, dist_comm]
theorem disjoint_closedBall_closedBall_iff (hδ : 0 ≤ δ) (hε : 0 ≤ ε) :
Disjoint (closedBall x δ) (closedBall y ε) ↔ δ + ε < dist x y := by
refine ⟨fun h => lt_of_not_ge fun hxy => ?_, closedBall_disjoint_closedBall⟩
rw [add_comm] at hxy
obtain ⟨z, hxz, hzy⟩ := exists_dist_le_le hδ hε hxy
rw [dist_comm] at hxz
exact h.le_bot ⟨hxz, hzy⟩
open EMetric ENNReal
@[simp]
theorem infEdist_thickening (hδ : 0 < δ) (s : Set E) (x : E) :
infEdist x (thickening δ s) = infEdist x s - ENNReal.ofReal δ := by
obtain hs | hs := lt_or_le (infEdist x s) (ENNReal.ofReal δ)
· rw [infEdist_zero_of_mem, tsub_eq_zero_of_le hs.le]
exact hs
refine (tsub_le_iff_right.2 infEdist_le_infEdist_thickening_add).antisymm' ?_
refine le_sub_of_add_le_right ofReal_ne_top ?_
refine le_infEdist.2 fun z hz => le_of_forall_lt' fun r h => ?_
cases r with
| top =>
exact add_lt_top.2 ⟨lt_top_iff_ne_top.2 <| infEdist_ne_top ⟨z, self_subset_thickening hδ _ hz⟩,
ofReal_lt_top⟩
| coe r =>
have hr : 0 < ↑r - δ := by
refine sub_pos_of_lt ?_
have := hs.trans_lt ((infEdist_le_edist_of_mem hz).trans_lt h)
rw [ofReal_eq_coe_nnreal hδ.le] at this
exact mod_cast this
rw [edist_lt_coe, ← dist_lt_coe, ← add_sub_cancel δ ↑r] at h
obtain ⟨y, hxy, hyz⟩ := exists_dist_lt_lt hr hδ h
refine (ENNReal.add_lt_add_right ofReal_ne_top <|
infEdist_lt_iff.2 ⟨_, mem_thickening_iff.2 ⟨_, hz, hyz⟩, edist_lt_ofReal.2 hxy⟩).trans_le ?_
rw [← ofReal_add hr.le hδ.le, sub_add_cancel, ofReal_coe_nnreal]
@[simp]
theorem thickening_thickening (hε : 0 < ε) (hδ : 0 < δ) (s : Set E) :
thickening ε (thickening δ s) = thickening (ε + δ) s :=
(thickening_thickening_subset _ _ _).antisymm fun x => by
simp_rw [mem_thickening_iff]
rintro ⟨z, hz, hxz⟩
rw [add_comm] at hxz
obtain ⟨y, hxy, hyz⟩ := exists_dist_lt_lt hε hδ hxz
exact ⟨y, ⟨_, hz, hyz⟩, hxy⟩
@[simp]
theorem cthickening_thickening (hε : 0 ≤ ε) (hδ : 0 < δ) (s : Set E) :
cthickening ε (thickening δ s) = cthickening (ε + δ) s :=
(cthickening_thickening_subset hε _ _).antisymm fun x => by
simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ.le, infEdist_thickening hδ]
exact tsub_le_iff_right.2
-- Note: `interior (cthickening δ s) ≠ thickening δ s` in general
@[simp]
theorem closure_thickening (hδ : 0 < δ) (s : Set E) :
closure (thickening δ s) = cthickening δ s := by
rw [← cthickening_zero, cthickening_thickening le_rfl hδ, zero_add]
@[simp]
theorem infEdist_cthickening (δ : ℝ) (s : Set E) (x : E) :
infEdist x (cthickening δ s) = infEdist x s - ENNReal.ofReal δ := by
obtain hδ | hδ := le_or_lt δ 0
· rw [cthickening_of_nonpos hδ, infEdist_closure, ofReal_of_nonpos hδ, tsub_zero]
· rw [← closure_thickening hδ, infEdist_closure, infEdist_thickening hδ]
@[simp]
theorem thickening_cthickening (hε : 0 < ε) (hδ : 0 ≤ δ) (s : Set E) :
thickening ε (cthickening δ s) = thickening (ε + δ) s := by
obtain rfl | hδ := hδ.eq_or_lt
· rw [cthickening_zero, thickening_closure, add_zero]
· rw [← closure_thickening hδ, thickening_closure, thickening_thickening hε hδ]
@[simp]
theorem cthickening_cthickening (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (s : Set E) :
cthickening ε (cthickening δ s) = cthickening (ε + δ) s :=
(cthickening_cthickening_subset hε hδ _).antisymm fun x => by
simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ, infEdist_cthickening]
exact tsub_le_iff_right.2
@[simp]
theorem thickening_ball (hε : 0 < ε) (hδ : 0 < δ) (x : E) :
thickening ε (ball x δ) = ball x (ε + δ) := by
rw [← thickening_singleton, thickening_thickening hε hδ, thickening_singleton]
@[simp]
theorem thickening_closedBall (hε : 0 < ε) (hδ : 0 ≤ δ) (x : E) :
thickening ε (closedBall x δ) = ball x (ε + δ) := by
rw [← cthickening_singleton _ hδ, thickening_cthickening hε hδ, thickening_singleton]
@[simp]
theorem cthickening_ball (hε : 0 ≤ ε) (hδ : 0 < δ) (x : E) :
cthickening ε (ball x δ) = closedBall x (ε + δ) := by
rw [← thickening_singleton, cthickening_thickening hε hδ,
cthickening_singleton _ (add_nonneg hε hδ.le)]
@[simp]
theorem cthickening_closedBall (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (x : E) :
cthickening ε (closedBall x δ) = closedBall x (ε + δ) := by
rw [← cthickening_singleton _ hδ, cthickening_cthickening hε hδ,
cthickening_singleton _ (add_nonneg hε hδ)]
theorem ball_add_ball (hε : 0 < ε) (hδ : 0 < δ) (a b : E) :
ball a ε + ball b δ = ball (a + b) (ε + δ) := by
rw [ball_add, thickening_ball hε hδ b, Metric.vadd_ball, vadd_eq_add]
theorem ball_sub_ball (hε : 0 < ε) (hδ : 0 < δ) (a b : E) :
ball a ε - ball b δ = ball (a - b) (ε + δ) := by
simp_rw [sub_eq_add_neg, neg_ball, ball_add_ball hε hδ]
theorem ball_add_closedBall (hε : 0 < ε) (hδ : 0 ≤ δ) (a b : E) :
ball a ε + closedBall b δ = ball (a + b) (ε + δ) := by
rw [ball_add, thickening_closedBall hε hδ b, Metric.vadd_ball, vadd_eq_add]
theorem ball_sub_closedBall (hε : 0 < ε) (hδ : 0 ≤ δ) (a b : E) :
ball a ε - closedBall b δ = ball (a - b) (ε + δ) := by
simp_rw [sub_eq_add_neg, neg_closedBall, ball_add_closedBall hε hδ]
theorem closedBall_add_ball (hε : 0 ≤ ε) (hδ : 0 < δ) (a b : E) :
closedBall a ε + ball b δ = ball (a + b) (ε + δ) := by
rw [add_comm, ball_add_closedBall hδ hε b, add_comm, add_comm δ]
theorem closedBall_sub_ball (hε : 0 ≤ ε) (hδ : 0 < δ) (a b : E) :
closedBall a ε - ball b δ = ball (a - b) (ε + δ) := by
simp_rw [sub_eq_add_neg, neg_ball, closedBall_add_ball hε hδ]
theorem closedBall_add_closedBall [ProperSpace E] (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (a b : E) :
closedBall a ε + closedBall b δ = closedBall (a + b) (ε + δ) := by
rw [(isCompact_closedBall _ _).add_closedBall hδ b, cthickening_closedBall hδ hε a,
Metric.vadd_closedBall, vadd_eq_add, add_comm, add_comm δ]
theorem closedBall_sub_closedBall [ProperSpace E] (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (a b : E) :
closedBall a ε - closedBall b δ = closedBall (a - b) (ε + δ) := by
rw [sub_eq_add_neg, neg_closedBall, closedBall_add_closedBall hε hδ, sub_eq_add_neg]
end SeminormedAddCommGroup
section NormedAddCommGroup
variable [NormedAddCommGroup E] [NormedSpace 𝕜 E]
theorem smul_closedBall (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) :
c • closedBall x r = closedBall (c • x) (‖c‖ * r) := by
rcases eq_or_ne c 0 with (rfl | hc)
· simp [hr, zero_smul_set, Set.singleton_zero, nonempty_closedBall]
· exact smul_closedBall' hc x r
theorem smul_unitClosedBall (c : 𝕜) : c • closedBall (0 : E) (1 : ℝ) = closedBall (0 : E) ‖c‖ := by
rw [_root_.smul_closedBall _ _ zero_le_one, smul_zero, mul_one]
@[deprecated (since := "2024-12-01")] alias smul_closedUnitBall := smul_unitClosedBall
variable [NormedSpace ℝ E]
/-- In a real normed space, the image of the unit closed ball under multiplication by a nonnegative
number `r` is the closed ball of radius `r` with center at the origin. -/
theorem smul_unitClosedBall_of_nonneg {r : ℝ} (hr : 0 ≤ r) :
r • closedBall (0 : E) 1 = closedBall (0 : E) r := by
rw [smul_unitClosedBall, Real.norm_of_nonneg hr]
@[deprecated (since := "2024-12-01")]
alias smul_closedUnitBall_of_nonneg := smul_unitClosedBall_of_nonneg
/-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is
nonnegative. -/
@[simp]
theorem NormedSpace.sphere_nonempty [Nontrivial E] {x : E} {r : ℝ} :
(sphere x r).Nonempty ↔ 0 ≤ r := by
obtain ⟨y, hy⟩ := exists_ne x
refine ⟨fun h => nonempty_closedBall.1 (h.mono sphere_subset_closedBall), fun hr =>
⟨r • ‖y - x‖⁻¹ • (y - x) + x, ?_⟩⟩
have : ‖y - x‖ ≠ 0 := by simpa [sub_eq_zero]
simp only [mem_sphere_iff_norm, add_sub_cancel_right, norm_smul, Real.norm_eq_abs, norm_inv,
norm_norm, ne_eq, norm_eq_zero]
simp only [abs_norm, ne_eq, norm_eq_zero]
rw [inv_mul_cancel₀ this, mul_one, abs_eq_self.mpr hr]
theorem smul_sphere [Nontrivial E] (c : 𝕜) (x : E) {r : ℝ} (hr : 0 ≤ r) :
c • sphere x r = sphere (c • x) (‖c‖ * r) := by
rcases eq_or_ne c 0 with (rfl | hc)
· simp [zero_smul_set, Set.singleton_zero, hr]
| · exact smul_sphere' hc x r
/-- Any ball `Metric.ball x r`, `0 < r` is the image of the unit ball under `fun y ↦ x + r • y`. -/
theorem affinity_unitBall {r : ℝ} (hr : 0 < r) (x : E) : x +ᵥ r • ball (0 : E) 1 = ball x r := by
rw [smul_unitBall_of_pos hr, vadd_ball_zero]
| Mathlib/Analysis/NormedSpace/Pointwise.lean | 400 | 404 |
/-
Copyright (c) 2023 Mohanad ahmed. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mohanad Ahmed
-/
import Mathlib.Data.Matrix.Block
import Mathlib.LinearAlgebra.Matrix.SemiringInverse
/-! # Block Matrices from Rows and Columns
This file provides the basic definitions of matrices composed from columns and rows.
The concatenation of two matrices with the same row indices can be expressed as
`A = fromCols A₁ A₂` the concatenation of two matrices with the same column indices
can be expressed as `B = fromRows B₁ B₂`.
We then provide a few lemmas that deal with the products of these with each other and
with block matrices
## Tags
column matrices, row matrices, column row block matrices
-/
namespace Matrix
variable {R : Type*}
variable {m m₁ m₂ n n₁ n₂ : Type*}
/-- Concatenate together two matrices A₁[m₁ × N] and A₂[m₂ × N] with the same columns (N) to get a
bigger matrix indexed by [(m₁ ⊕ m₂) × N] -/
def fromRows (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) : Matrix (m₁ ⊕ m₂) n R :=
of (Sum.elim A₁ A₂)
/-- Concatenate together two matrices B₁[m × n₁] and B₂[m × n₂] with the same rows (M) to get a
bigger matrix indexed by [m × (n₁ ⊕ n₂)] -/
def fromCols (B₁ : Matrix m n₁ R) (B₂ : Matrix m n₂ R) : Matrix m (n₁ ⊕ n₂) R :=
of fun i => Sum.elim (B₁ i) (B₂ i)
/-- Given a column partitioned matrix extract the first column -/
def toCols₁ (A : Matrix m (n₁ ⊕ n₂) R) : Matrix m n₁ R := of fun i j => (A i (Sum.inl j))
/-- Given a column partitioned matrix extract the second column -/
def toCols₂ (A : Matrix m (n₁ ⊕ n₂) R) : Matrix m n₂ R := of fun i j => (A i (Sum.inr j))
/-- Given a row partitioned matrix extract the first row -/
def toRows₁ (A : Matrix (m₁ ⊕ m₂) n R) : Matrix m₁ n R := of fun i j => (A (Sum.inl i) j)
/-- Given a row partitioned matrix extract the second row -/
def toRows₂ (A : Matrix (m₁ ⊕ m₂) n R) : Matrix m₂ n R := of fun i j => (A (Sum.inr i) j)
@[deprecated (since := "2024-12-11")] alias fromColumns := fromCols
@[deprecated (since := "2024-12-11")] alias toColumns₁ := toCols₁
@[deprecated (since := "2024-12-11")] alias toColumns₂ := toCols₂
@[simp]
lemma fromRows_apply_inl (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) (i : m₁) (j : n) :
(fromRows A₁ A₂) (Sum.inl i) j = A₁ i j := rfl
@[simp]
lemma fromRows_apply_inr (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) (i : m₂) (j : n) :
(fromRows A₁ A₂) (Sum.inr i) j = A₂ i j := rfl
@[simp]
lemma fromCols_apply_inl (A₁ : Matrix m n₁ R) (A₂ : Matrix m n₂ R) (i : m) (j : n₁) :
(fromCols A₁ A₂) i (Sum.inl j) = A₁ i j := rfl
@[deprecated (since := "2024-12-11")] alias fromColumns_apply_inl := fromCols_apply_inl
@[simp]
lemma fromCols_apply_inr (A₁ : Matrix m n₁ R) (A₂ : Matrix m n₂ R) (i : m) (j : n₂) :
(fromCols A₁ A₂) i (Sum.inr j) = A₂ i j := rfl
@[deprecated (since := "2024-12-11")] alias fromColumns_apply_inr := fromCols_apply_inr
@[simp]
lemma toRows₁_apply (A : Matrix (m₁ ⊕ m₂) n R) (i : m₁) (j : n) :
(toRows₁ A) i j = A (Sum.inl i) j := rfl
@[simp]
lemma toRows₂_apply (A : Matrix (m₁ ⊕ m₂) n R) (i : m₂) (j : n) :
(toRows₂ A) i j = A (Sum.inr i) j := rfl
@[simp]
lemma toRows₁_fromRows (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) :
toRows₁ (fromRows A₁ A₂) = A₁ := rfl
@[simp]
lemma toRows₂_fromRows (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) :
toRows₂ (fromRows A₁ A₂) = A₂ := rfl
@[simp]
lemma toCols₁_apply (A : Matrix m (n₁ ⊕ n₂) R) (i : m) (j : n₁) :
(toCols₁ A) i j = A i (Sum.inl j) := rfl
@[deprecated (since := "2024-12-11")] alias toColumns₁_apply := toCols₁_apply
@[simp]
lemma toCols₂_apply (A : Matrix m (n₁ ⊕ n₂) R) (i : m) (j : n₂) :
(toCols₂ A) i j = A i (Sum.inr j) := rfl
@[deprecated (since := "2024-12-11")] alias toColumns₂_apply := toCols₂_apply
@[simp]
| lemma toCols₁_fromCols (A₁ : Matrix m n₁ R) (A₂ : Matrix m n₂ R) :
toCols₁ (fromCols A₁ A₂) = A₁ := rfl
@[deprecated (since := "2024-12-11")] alias toColumns₁_fromColumns := toCols₁_fromCols
| Mathlib/Data/Matrix/ColumnRowPartitioned.lean | 104 | 107 |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Finset.Option
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Lemmas about products and sums over finite sets in `Option α`
In this file we prove formulas for products and sums over `Finset.insertNone s` and
`Finset.eraseNone s`.
-/
open Function
namespace Finset
variable {α M : Type*} [CommMonoid M]
@[to_additive (attr := simp)]
theorem prod_insertNone (f : Option α → M) (s : Finset α) :
∏ x ∈ insertNone s, f x = f none * ∏ x ∈ s, f (some x) := by simp [insertNone]
|
@[to_additive]
| Mathlib/Algebra/BigOperators/Option.lean | 25 | 26 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Comap
import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono, gcongr]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
@[gcongr]
theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) :
μ.restrict s ≤ ν.restrict s :=
restrict_mono subset_rfl h
@[gcongr]
theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) :
μ.restrict s ≤ μ.restrict t :=
restrict_mono h le_rfl
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s := by
simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
@[simp]
theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by
rw [← measure_univ_eq_zero, restrict_apply_univ]
/-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) :=
⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩
theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 :=
restrict_eq_zero.2 h
@[simp]
theorem restrict_empty : μ.restrict ∅ = 0 :=
restrict_zero_set measure_empty
@[simp]
theorem restrict_univ : μ.restrict univ = μ :=
ext fun s hs => by simp [hs]
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq]
exact measure_inter_add_diff₀ (u ∩ s) ht
theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s :=
restrict_inter_add_diff₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
restrict_union_add_inter₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h]
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
restrict_union₀ h.aedisjoint ht.nullMeasurableSet
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
μ.restrict s + μ.restrict sᶜ = μ := by
rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self,
restrict_univ]
@[simp]
theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by
rw [add_comm, restrict_add_restrict_compl hs]
theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
le_iff.2 fun t ht ↦ by
simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s')
theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by
simp only [restrict_apply, ht, inter_iUnion]
exact
measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right)
fun i => ht.nullMeasurableSet.inter (hm i)
theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht
theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s)
{t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion]
rw [Directed.measure_iUnion]
exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _]
/-- The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/
theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
ext fun t ht => by simp [*, hf ht]
theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h,
inter_comm]
theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄
(hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ :=
calc
μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs)
_ = μ := restrict_univ
theorem restrict_congr_meas (hs : MeasurableSet s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t :=
⟨fun H t hts ht => by
rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H =>
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩
theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s := by
rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
theorem restrict_union_congr :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by
refine ⟨fun h ↦ ⟨restrict_congr_mono subset_union_left h,
restrict_congr_mono subset_union_right h⟩, ?_⟩
rintro ⟨hs, ht⟩
ext1 u hu
simp only [restrict_apply hu, inter_union_distrib_left]
rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩
calc
μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) :=
measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl
_ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm.nullMeasurableSet _).symm
_ = restrict μ s u + restrict μ t (u \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc]
_ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht]
_ = ν US + ν ((u ∩ t) \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc]
_ = ν (US ∪ u ∩ t) := measure_add_diff hm.nullMeasurableSet _
_ = ν (u ∩ s ∪ u ∩ t) := .symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl
theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
classical
induction' s using Finset.induction_on with i s _ hs; · simp
simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert]
rw [restrict_union_congr, ← hs]
theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩
ext1 t ht
have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i :=
Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht
rw [iUnion_eq_iUnion_finset]
simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i]
theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr]
theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by
rw [sUnion_eq_biUnion, restrict_biUnion_congr hc]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)}
(hm : m.Nonempty) (ht : MeasurableSet t) :
(sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by
ext1 s hs
simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht),
Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ←
Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _),
OuterMeasure.restrict_apply]
theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop}
(hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by
rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs
exact (hs.and_eventually hp).exists
/-- If a quasi measure preserving map `f` maps a set `s` to a set `t`,
then it is quasi measure preserving with respect to the restrictions of the measures. -/
theorem QuasiMeasurePreserving.restrict {ν : Measure β} {f : α → β}
(hf : QuasiMeasurePreserving f μ ν) {t : Set β} (hmaps : MapsTo f s t) :
QuasiMeasurePreserving f (μ.restrict s) (ν.restrict t) where
measurable := hf.measurable
absolutelyContinuous := by
refine AbsolutelyContinuous.mk fun u hum ↦ ?_
suffices ν (u ∩ t) = 0 → μ (f ⁻¹' u ∩ s) = 0 by simpa [hum, hf.measurable, hf.measurable hum]
refine fun hu ↦ measure_mono_null ?_ (hf.preimage_null hu)
rw [preimage_inter]
gcongr
assumption
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `biUnion`). -/
theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable)
(hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion]
alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ
theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞)
(ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by
refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_
ext1 u hu
simp only [restrict_apply hu]
induction u, hu using induction_on_inter h_gen h_inter with
| empty => simp only [Set.empty_inter, measure_empty]
| basic u hu => exact ST_eq _ ht _ hu
| compl u hu ihu =>
have := T_eq t ht
rw [Set.inter_comm] at ihu ⊢
rwa [← measure_inter_add_diff t hu, ← measure_inter_add_diff t hu, ← ihu,
ENNReal.add_right_inj] at this
exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left)
| iUnion f hfd hfm ihf =>
simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at ihf ⊢
simp only [measure_iUnion hfd hfm, ihf]
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ)
(htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht)
intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H
· simp only [H, measure_empty]
· exact h_eq _ (h_inter _ hs _ (h_sub ht) H)
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `iUnion`.
`FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/
theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞)
(h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq
· rintro _ ⟨i, rfl⟩
apply h2B
· rintro _ ⟨i, rfl⟩
apply hμB
@[simp]
theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
(sum μ).restrict s = sum fun i => (μ i).restrict s :=
ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
@[simp]
theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) :
(sum μ).restrict s = sum fun i => (μ i).restrict s := by
ext t ht
simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable]
lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by
refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_)
rw [restrict_apply ht] at htν ⊢
exact h htν
theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht]
theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet
theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) :=
le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·)
end Measure
@[simp]
theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) :
ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) :=
le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <|
iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl
@[simp]
theorem ae_restrict_union_eq (s t : Set α) :
ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by
simp [union_eq_iUnion, iSup_bool_eq]
theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype'']
theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) :=
ae_restrict_biUnion_eq s t.countable_toSet
theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp
theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp
theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup]
@[simp]
theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup]
theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup]
theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup]
theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g :=
ae_eq_restrict_biUnion_iff s t.countable_toSet f g
open scoped Interval in
theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) :
ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by
simp only [uIoc_eq_union, ae_restrict_union_eq]
open scoped Interval in
/-- See also `MeasureTheory.ae_uIoc_iff`. -/
theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔
(∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by
rw [ae_restrict_uIoc_eq, eventually_sup]
theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff₀ hp.nullMeasurableSet
theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) :
∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff] at h ⊢
simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h
theorem ae_restrict_iff'₀ {p : α → Prop} (hs : NullMeasurableSet s μ) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, restrict_apply₀' hs]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff' {p : α → Prop} (hs : MeasurableSet s) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff'₀ hs.nullMeasurableSet
theorem _root_.Filter.EventuallyEq.restrict {f g : α → δ} {s : Set α} (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.restrict s] g := by
-- note that we cannot use `ae_restrict_iff` since we do not require measurability
refine hfg.filter_mono ?_
rw [Measure.ae_le_iff_absolutelyContinuous]
exact Measure.absolutelyContinuous_of_le Measure.restrict_le_self
theorem ae_restrict_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
(ae_restrict_iff'₀ hs).2 (Filter.Eventually.of_forall fun _ => id)
theorem ae_restrict_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
ae_restrict_mem₀ hs.nullMeasurableSet
theorem ae_restrict_of_forall_mem {μ : Measure α} {s : Set α}
(hs : MeasurableSet s) {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᵐ (x : α) ∂μ.restrict s, p x :=
(ae_restrict_mem hs).mono h
theorem ae_restrict_of_ae {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono Measure.restrict_le_self)
theorem ae_restrict_of_ae_restrict_of_subset {s t : Set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂μ.restrict t, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono <| Measure.restrict_mono hst (le_refl μ))
theorem ae_of_ae_restrict_of_ae_restrict_compl (t : Set α) {p : α → Prop}
(ht : ∀ᵐ x ∂μ.restrict t, p x) (htc : ∀ᵐ x ∂μ.restrict tᶜ, p x) : ∀ᵐ x ∂μ, p x :=
nonpos_iff_eq_zero.1 <|
calc
μ { x | ¬p x } ≤ μ ({ x | ¬p x } ∩ t) + μ ({ x | ¬p x } ∩ tᶜ) :=
measure_le_inter_add_diff _ _ _
_ ≤ μ.restrict t { x | ¬p x } + μ.restrict tᶜ { x | ¬p x } :=
add_le_add (le_restrict_apply _ _) (le_restrict_apply _ _)
_ = 0 := by rw [ae_iff.1 ht, ae_iff.1 htc, zero_add]
theorem mem_map_restrict_ae_iff {β} {s : Set α} {t : Set β} {f : α → β} (hs : MeasurableSet s) :
t ∈ Filter.map f (ae (μ.restrict s)) ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0 := by
rw [mem_map, mem_ae_iff, Measure.restrict_apply' hs]
theorem ae_add_measure_iff {p : α → Prop} {ν} :
(∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x :=
add_eq_zero
theorem ae_eq_comp' {ν : Measure β} {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ)
(h : g =ᵐ[ν] g') (h2 : μ.map f ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f :=
(tendsto_ae_map hf).mono_right h2.ae_le h
theorem Measure.QuasiMeasurePreserving.ae_eq_comp {ν : Measure β} {f : α → β} {g g' : β → δ}
(hf : QuasiMeasurePreserving f μ ν) (h : g =ᵐ[ν] g') : g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf.aemeasurable h hf.absolutelyContinuous
theorem ae_eq_comp {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ) (h : g =ᵐ[μ.map f] g') :
g ∘ f =ᵐ[μ] g' ∘ f :=
ae_eq_comp' hf h AbsolutelyContinuous.rfl
@[to_additive]
theorem div_ae_eq_one {β} [Group β] (f g : α → β) : f / g =ᵐ[μ] 1 ↔ f =ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun x hx ↦ ?_, fun h ↦ h.mono fun x hx ↦ ?_⟩
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one] at hx
· rwa [Pi.div_apply, Pi.one_apply, div_eq_one]
@[to_additive sub_nonneg_ae]
lemma one_le_div_ae {β : Type*} [Group β] [LE β] [MulRightMono β] (f g : α → β) :
1 ≤ᵐ[μ] g / f ↔ f ≤ᵐ[μ] g := by
refine ⟨fun h ↦ h.mono fun a ha ↦ ?_, fun h ↦ h.mono fun a ha ↦ ?_⟩
· rwa [Pi.one_apply, Pi.div_apply, one_le_div'] at ha
· rwa [Pi.one_apply, Pi.div_apply, one_le_div']
theorem le_ae_restrict : ae μ ⊓ 𝓟 s ≤ ae (μ.restrict s) := fun _s hs =>
eventually_inf_principal.2 (ae_imp_of_ae_restrict hs)
@[simp]
theorem ae_restrict_eq (hs : MeasurableSet s) : ae (μ.restrict s) = ae μ ⊓ 𝓟 s := by
ext t
simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_setOf,
Classical.not_imp, fun a => and_comm (a := a ∈ s) (b := ¬a ∈ t)]
rfl
lemma ae_restrict_le : ae (μ.restrict s) ≤ ae μ :=
ae_mono restrict_le_self
theorem ae_restrict_eq_bot {s} : ae (μ.restrict s) = ⊥ ↔ μ s = 0 :=
ae_eq_bot.trans restrict_eq_zero
theorem ae_restrict_neBot {s} : (ae <| μ.restrict s).NeBot ↔ μ s ≠ 0 :=
neBot_iff.trans ae_restrict_eq_bot.not
theorem self_mem_ae_restrict {s} (hs : MeasurableSet s) : s ∈ ae (μ.restrict s) := by
simp only [ae_restrict_eq hs, exists_prop, mem_principal, mem_inf_iff]
exact ⟨_, univ_mem, s, Subset.rfl, (univ_inter s).symm⟩
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_of_ae_eq_of_ae_restrict {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) → ∀ᵐ x ∂μ.restrict t, p x := by simp [Measure.restrict_congr_set hst]
/-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one
is almost everywhere true on the other -/
theorem ae_restrict_congr_set {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ.restrict t, p x :=
⟨ae_restrict_of_ae_eq_of_ae_restrict hst, ae_restrict_of_ae_eq_of_ae_restrict hst.symm⟩
lemma NullMeasurable.measure_preimage_eq_measure_restrict_preimage_of_ae_compl_eq_const
{β : Type*} [MeasurableSpace β] {b : β} {f : α → β} {s : Set α}
(f_mble : NullMeasurable f (μ.restrict s)) (hs : f =ᵐ[Measure.restrict μ sᶜ] (fun _ ↦ b))
{t : Set β} (t_mble : MeasurableSet t) (ht : b ∉ t) :
μ (f ⁻¹' t) = μ.restrict s (f ⁻¹' t) := by
rw [Measure.restrict_apply₀ (f_mble t_mble)]
rw [EventuallyEq, ae_iff, Measure.restrict_apply₀] at hs
· apply le_antisymm _ (measure_mono inter_subset_left)
apply (measure_mono (Eq.symm (inter_union_compl (f ⁻¹' t) s)).le).trans
apply (measure_union_le _ _).trans
have obs : μ ((f ⁻¹' t) ∩ sᶜ) = 0 := by
apply le_antisymm _ (zero_le _)
rw [← hs]
apply measure_mono (inter_subset_inter_left _ _)
intro x hx hfx
simp only [mem_preimage, mem_setOf_eq] at hx hfx
exact ht (hfx ▸ hx)
simp only [obs, add_zero, le_refl]
· exact NullMeasurableSet.of_null hs
namespace Measure
section Subtype
/-! ### Subtype of a measure space -/
section ComapAnyMeasure
theorem MeasurableSet.nullMeasurableSet_subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : MeasurableSet t) : NullMeasurableSet ((↑) '' t) μ := by
rw [Subtype.instMeasurableSpace, comap_eq_generateFrom] at ht
induction t, ht using generateFrom_induction with
| hC t' ht' =>
obtain ⟨s', hs', rfl⟩ := ht'
rw [Subtype.image_preimage_coe]
exact hs.inter (hs'.nullMeasurableSet)
| empty => simp only [image_empty, nullMeasurableSet_empty]
| compl t' _ ht' =>
simp only [← range_diff_image Subtype.coe_injective, Subtype.range_coe_subtype, setOf_mem_eq]
exact hs.diff ht'
| iUnion f _ hf =>
dsimp only []
rw [image_iUnion]
exact .iUnion hf
theorem NullMeasurableSet.subtype_coe {t : Set s} (hs : NullMeasurableSet s μ)
(ht : NullMeasurableSet t (μ.comap Subtype.val)) : NullMeasurableSet (((↑) : s → α) '' t) μ :=
NullMeasurableSet.image _ μ Subtype.coe_injective
(fun _ => MeasurableSet.nullMeasurableSet_subtype_coe hs) ht
theorem measure_subtype_coe_le_comap (hs : NullMeasurableSet s μ) (t : Set s) :
μ (((↑) : s → α) '' t) ≤ μ.comap Subtype.val t :=
le_comap_apply _ _ Subtype.coe_injective (fun _ =>
MeasurableSet.nullMeasurableSet_subtype_coe hs) _
theorem measure_subtype_coe_eq_zero_of_comap_eq_zero (hs : NullMeasurableSet s μ) {t : Set s}
(ht : μ.comap Subtype.val t = 0) : μ (((↑) : s → α) '' t) = 0 :=
eq_bot_iff.mpr <| (measure_subtype_coe_le_comap hs t).trans ht.le
end ComapAnyMeasure
section MeasureSpace
variable {u : Set δ} [MeasureSpace δ] {p : δ → Prop}
/-- In a measure space, one can restrict the measure to a subtype to get a new measure space.
Not registered as an instance, as there are other natural choices such as the normalized restriction
for a probability measure, or the subspace measure when restricting to a vector subspace. Enable
locally if needed with `attribute [local instance] Measure.Subtype.measureSpace`. -/
noncomputable def Subtype.measureSpace : MeasureSpace (Subtype p) where
volume := Measure.comap Subtype.val volume
attribute [local instance] Subtype.measureSpace
theorem Subtype.volume_def : (volume : Measure u) = volume.comap Subtype.val :=
rfl
theorem Subtype.volume_univ (hu : NullMeasurableSet u) : volume (univ : Set u) = volume u := by
rw [Subtype.volume_def, comap_apply₀ _ _ _ _ MeasurableSet.univ.nullMeasurableSet]
· congr
simp only [image_univ, Subtype.range_coe_subtype, setOf_mem_eq]
· exact Subtype.coe_injective
· exact fun t => MeasurableSet.nullMeasurableSet_subtype_coe hu
theorem volume_subtype_coe_le_volume (hu : NullMeasurableSet u) (t : Set u) :
volume (((↑) : u → δ) '' t) ≤ volume t :=
measure_subtype_coe_le_comap hu t
theorem volume_subtype_coe_eq_zero_of_volume_eq_zero (hu : NullMeasurableSet u) {t : Set u}
(ht : volume t = 0) : volume (((↑) : u → δ) '' t) = 0 :=
measure_subtype_coe_eq_zero_of_comap_eq_zero hu ht
end MeasureSpace
end Subtype
end Measure
end MeasureTheory
open MeasureTheory Measure
namespace MeasurableEmbedding
variable {m0 : MeasurableSpace α} {m1 : MeasurableSpace β} {f : α → β}
section
variable (hf : MeasurableEmbedding f)
include hf
theorem map_comap (μ : Measure β) : (comap f μ).map f = μ.restrict (range f) := by
ext1 t ht
rw [hf.map_apply, comap_apply f hf.injective hf.measurableSet_image' _ (hf.measurable ht),
image_preimage_eq_inter_range, Measure.restrict_apply ht]
theorem comap_apply (μ : Measure β) (s : Set α) : comap f μ s = μ (f '' s) :=
calc
comap f μ s = comap f μ (f ⁻¹' (f '' s)) := by rw [hf.injective.preimage_image]
_ = (comap f μ).map f (f '' s) := (hf.map_apply _ _).symm
_ = μ (f '' s) := by
rw [hf.map_comap, restrict_apply' hf.measurableSet_range,
inter_eq_self_of_subset_left (image_subset_range _ _)]
theorem comap_map (μ : Measure α) : (map f μ).comap f = μ := by
ext t _
rw [hf.comap_apply, hf.map_apply, preimage_image_eq _ hf.injective]
theorem ae_map_iff {p : β → Prop} {μ : Measure α} : (∀ᵐ x ∂μ.map f, p x) ↔ ∀ᵐ x ∂μ, p (f x) := by
simp only [ae_iff, hf.map_apply, preimage_setOf_eq]
theorem restrict_map (μ : Measure α) (s : Set β) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
Measure.ext fun t ht => by simp [hf.map_apply, ht, hf.measurable ht]
protected theorem comap_preimage (μ : Measure β) (s : Set β) :
μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by
rw [← hf.map_apply, hf.map_comap, restrict_apply' hf.measurableSet_range]
lemma comap_restrict (μ : Measure β) (s : Set β) :
(μ.restrict s).comap f = (μ.comap f).restrict (f ⁻¹' s) := by
ext t ht
rw [Measure.restrict_apply ht, comap_apply hf, comap_apply hf,
Measure.restrict_apply (hf.measurableSet_image.2 ht), image_inter_preimage]
lemma restrict_comap (μ : Measure β) (s : Set α) :
(μ.comap f).restrict s = (μ.restrict (f '' s)).comap f := by
rw [comap_restrict hf, preimage_image_eq _ hf.injective]
end
theorem _root_.MeasurableEquiv.restrict_map (e : α ≃ᵐ β) (μ : Measure α) (s : Set β) :
(μ.map e).restrict s = (μ.restrict <| e ⁻¹' s).map e :=
e.measurableEmbedding.restrict_map _ _
end MeasurableEmbedding
section Subtype
theorem comap_subtype_coe_apply {_m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s)
(μ : Measure α) (t : Set s) : comap (↑) μ t = μ ((↑) '' t) :=
(MeasurableEmbedding.subtype_coe hs).comap_apply _ _
theorem map_comap_subtype_coe {m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s)
(μ : Measure α) : (comap (↑) μ).map ((↑) : s → α) = μ.restrict s := by
rw [(MeasurableEmbedding.subtype_coe hs).map_comap, Subtype.range_coe]
theorem ae_restrict_iff_subtype {m0 : MeasurableSpace α} {μ : Measure α} {s : Set α}
(hs : MeasurableSet s) {p : α → Prop} :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ (x : s) ∂comap ((↑) : s → α) μ, p x := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).ae_map_iff]
variable [MeasureSpace α] {s t : Set α}
/-!
### Volume on `s : Set α`
Note the instance is provided earlier as `Subtype.measureSpace`.
-/
attribute [local instance] Subtype.measureSpace
theorem volume_set_coe_def (s : Set α) : (volume : Measure s) = comap ((↑) : s → α) volume :=
rfl
theorem MeasurableSet.map_coe_volume {s : Set α} (hs : MeasurableSet s) :
volume.map ((↑) : s → α) = restrict volume s := by
rw [volume_set_coe_def, (MeasurableEmbedding.subtype_coe hs).map_comap volume, Subtype.range_coe]
theorem volume_image_subtype_coe {s : Set α} (hs : MeasurableSet s) (t : Set s) :
volume ((↑) '' t : Set α) = volume t :=
(comap_subtype_coe_apply hs volume t).symm
@[simp]
theorem volume_preimage_coe (hs : NullMeasurableSet s) (ht : MeasurableSet t) :
volume (((↑) : s → α) ⁻¹' t) = volume (t ∩ s) := by
rw [volume_set_coe_def,
comap_apply₀ _ _ Subtype.coe_injective
(fun h => MeasurableSet.nullMeasurableSet_subtype_coe hs)
(measurable_subtype_coe ht).nullMeasurableSet,
image_preimage_eq_inter_range, Subtype.range_coe]
end Subtype
section Piecewise
variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f g : α → β}
theorem piecewise_ae_eq_restrict [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
piecewise s f g =ᵐ[μ.restrict s] f := by
rw [ae_restrict_eq hs]
exact (piecewise_eqOn s f g).eventuallyEq.filter_mono inf_le_right
theorem piecewise_ae_eq_restrict_compl [DecidablePred (· ∈ s)] (hs : MeasurableSet s) :
piecewise s f g =ᵐ[μ.restrict sᶜ] g := by
rw [ae_restrict_eq hs.compl]
exact (piecewise_eqOn_compl s f g).eventuallyEq.filter_mono inf_le_right
theorem piecewise_ae_eq_of_ae_eq_set [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)]
(hst : s =ᵐ[μ] t) : s.piecewise f g =ᵐ[μ] t.piecewise f g :=
hst.mem_iff.mono fun x hx => by simp [piecewise, hx]
end Piecewise
section IndicatorFunction
variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f : α → β}
theorem mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem [Zero β] {t : Set β}
(ht : (0 : β) ∈ t) (hs : MeasurableSet s) :
t ∈ Filter.map (s.indicator f) (ae μ) ↔ t ∈ Filter.map f (ae <| μ.restrict s) := by
classical
simp_rw [mem_map, mem_ae_iff]
rw [Measure.restrict_apply' hs, Set.indicator_preimage, Set.ite]
simp_rw [Set.compl_union, Set.compl_inter]
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((fun _ => (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0
simp only [ht, ← Set.compl_eq_univ_diff, compl_compl, Set.compl_union, if_true,
Set.preimage_const]
simp_rw [Set.union_inter_distrib_right, Set.compl_inter_self s, Set.union_empty]
theorem mem_map_indicator_ae_iff_of_zero_nmem [Zero β] {t : Set β} (ht : (0 : β) ∉ t) :
t ∈ Filter.map (s.indicator f) (ae μ) ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0 := by
classical
rw [mem_map, mem_ae_iff, Set.indicator_preimage, Set.ite, Set.compl_union, Set.compl_inter]
change μ (((f ⁻¹' t)ᶜ ∪ sᶜ) ∩ ((fun _ => (0 : β)) ⁻¹' t \ s)ᶜ) = 0 ↔ μ ((f ⁻¹' t)ᶜ ∪ sᶜ) = 0
simp only [ht, if_false, Set.compl_empty, Set.empty_diff, Set.inter_univ, Set.preimage_const]
theorem map_restrict_ae_le_map_indicator_ae [Zero β] (hs : MeasurableSet s) :
Filter.map f (ae <| μ.restrict s) ≤ Filter.map (s.indicator f) (ae μ) := by
intro t
by_cases ht : (0 : β) ∈ t
· rw [mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem ht hs]
exact id
rw [mem_map_indicator_ae_iff_of_zero_nmem ht, mem_map_restrict_ae_iff hs]
exact fun h => measure_mono_null (Set.inter_subset_left.trans Set.subset_union_left) h
variable [Zero β]
theorem indicator_ae_eq_restrict (hs : MeasurableSet s) : indicator s f =ᵐ[μ.restrict s] f := by
classical exact piecewise_ae_eq_restrict hs
theorem indicator_ae_eq_restrict_compl (hs : MeasurableSet s) :
indicator s f =ᵐ[μ.restrict sᶜ] 0 := by
classical exact piecewise_ae_eq_restrict_compl hs
theorem indicator_ae_eq_of_restrict_compl_ae_eq_zero (hs : MeasurableSet s)
(hf : f =ᵐ[μ.restrict sᶜ] 0) : s.indicator f =ᵐ[μ] f := by
rw [Filter.EventuallyEq, ae_restrict_iff' hs.compl] at hf
filter_upwards [hf] with x hx
by_cases hxs : x ∈ s
· simp only [hxs, Set.indicator_of_mem]
· simp only [hx hxs, Pi.zero_apply, Set.indicator_apply_eq_zero, eq_self_iff_true, imp_true_iff]
theorem indicator_ae_eq_zero_of_restrict_ae_eq_zero (hs : MeasurableSet s)
(hf : f =ᵐ[μ.restrict s] 0) : s.indicator f =ᵐ[μ] 0 := by
rw [Filter.EventuallyEq, ae_restrict_iff' hs] at hf
filter_upwards [hf] with x hx
by_cases hxs : x ∈ s
· simp only [hxs, hx hxs, Set.indicator_of_mem]
· simp [hx, hxs]
theorem indicator_ae_eq_of_ae_eq_set (hst : s =ᵐ[μ] t) : s.indicator f =ᵐ[μ] t.indicator f := by
classical exact piecewise_ae_eq_of_ae_eq_set hst
theorem indicator_meas_zero (hs : μ s = 0) : indicator s f =ᵐ[μ] 0 :=
indicator_empty' f ▸ indicator_ae_eq_of_ae_eq_set (ae_eq_empty.2 hs)
theorem ae_eq_restrict_iff_indicator_ae_eq {g : α → β} (hs : MeasurableSet s) :
f =ᵐ[μ.restrict s] g ↔ s.indicator f =ᵐ[μ] s.indicator g := by
rw [Filter.EventuallyEq, ae_restrict_iff' hs]
refine ⟨fun h => ?_, fun h => ?_⟩ <;> filter_upwards [h] with x hx
· by_cases hxs : x ∈ s
· simp [hxs, hx hxs]
· simp [hxs]
· intro hxs
simpa [hxs] using hx
end IndicatorFunction
| Mathlib/MeasureTheory/Measure/Restrict.lean | 976 | 978 | |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.UniformSpace.Cauchy
/-!
# Uniform convergence
A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality
`dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `ℕ` with `atTop`).
## Main results
Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β`
(where the index `n` belongs to an indexing type `ι` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fₙ y) ∈ u` for all `y ∈ s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends
to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then
`Fₙ gₙ` tends to `f x`.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set Uniform
variable {α β γ ι : Type*} [UniformSpace β]
variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α}
/-!
### Different notions of uniform convergence
We define uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/
def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u
/--
A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) :=
Iff.rfl
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/
def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forall₂_congr
simp_rw [eventually_prod_principal_iff]
simp
alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto :
TendstoUniformlyOn F f p s ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x`. -/
def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by
rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter]
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p :=
forall₂_congr fun u _ => by simp
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit.
-/
theorem tendstoUniformly_iff_tendsto :
TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by
simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')
(hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by
refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_
filter_upwards [(h u hu).curry]
intro i h
simpa using h.filter_mono hx
| /-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x ∈ s) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
| Mathlib/Topology/UniformSpace/UniformConvergence.lean | 142 | 144 |
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Constructions.Polish.Basic
import Mathlib.MeasureTheory.Function.UniformIntegrable
import Mathlib.Probability.Martingale.Upcrossing
/-!
# Martingale convergence theorems
The martingale convergence theorems are a collection of theorems characterizing the convergence
of a martingale provided it satisfies some boundedness conditions. This file contains the
almost everywhere martingale convergence theorem which provides an almost everywhere limit to
an L¹ bounded submartingale. It also contains the L¹ martingale convergence theorem which provides
an L¹ limit to a uniformly integrable submartingale. Finally, it also contains the Lévy upwards
theorems.
## Main results
* `MeasureTheory.Submartingale.ae_tendsto_limitProcess`: the almost everywhere martingale
convergence theorem: an L¹-bounded submartingale adapted to the filtration `ℱ` converges almost
everywhere to its limit process.
* `MeasureTheory.Submartingale.memLp_limitProcess`: the limit process of an Lᵖ-bounded
submartingale is Lᵖ.
* `MeasureTheory.Submartingale.tendsto_eLpNorm_one_limitProcess`: part a of the L¹ martingale
convergence theorem: a uniformly integrable submartingale adapted to the filtration `ℱ` converges
almost everywhere and in L¹ to an integrable function which is measurable with respect to
the σ-algebra `⨆ n, ℱ n`.
* `MeasureTheory.Martingale.ae_eq_condExp_limitProcess`: part b the L¹ martingale convergence
theorem: if `f` is a uniformly integrable martingale adapted to the filtration `ℱ`, then
`f n` equals `𝔼[g | ℱ n]` almost everywhere where `g` is the limiting process of `f`.
* `MeasureTheory.Integrable.tendsto_ae_condExp`: part c the L¹ martingale convergence theorem:
given a `⨆ n, ℱ n`-measurable function `g` where `ℱ` is a filtration, `𝔼[g | ℱ n]` converges
almost everywhere to `g`.
* `MeasureTheory.Integrable.tendsto_eLpNorm_condExp`: part c the L¹ martingale convergence theorem:
given a `⨆ n, ℱ n`-measurable function `g` where `ℱ` is a filtration, `𝔼[g | ℱ n]` converges in
L¹ to `g`.
-/
open TopologicalSpace Filter MeasureTheory.Filtration
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology
namespace MeasureTheory
variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} {ℱ : Filtration ℕ m0}
variable {a b : ℝ} {f : ℕ → Ω → ℝ} {ω : Ω} {R : ℝ≥0}
section AeConvergence
/-!
### Almost everywhere martingale convergence theorem
We will now prove the almost everywhere martingale convergence theorem.
The a.e. martingale convergence theorem states: if `f` is an L¹-bounded `ℱ`-submartingale, then
it converges almost everywhere to an integrable function which is measurable with respect to
the σ-algebra `ℱ∞ := ⨆ n, ℱ n`.
Mathematically, we proceed by first noting that a real sequence $(x_n)$ converges if
(a) $\limsup_{n \to \infty} |x_n| < \infty$, (b) for all $a < b \in \mathbb{Q}$ we have the
number of upcrossings of $(x_n)$ from below $a$ to above $b$ is finite.
Thus, for all $\omega$ satisfying $\limsup_{n \to \infty} |f_n(\omega)| < \infty$ and the number of
upcrossings of $(f_n(\omega))$ from below $a$ to above $b$ is finite for all $a < b \in \mathbb{Q}$,
we have $(f_n(\omega))$ is convergent.
Hence, assuming $(f_n)$ is L¹-bounded, using Fatou's lemma, we have
$$
\mathbb{E} \limsup_{n \to \infty} |f_n| \le \limsup_{n \to \infty} \mathbb{E}|f_n| < \infty
$$
implying $\limsup_{n \to \infty} |f_n| < \infty$ a.e. Furthermore, by the upcrossing estimate,
the number of upcrossings is finite almost everywhere implying $f$ converges pointwise almost
everywhere.
Thus, denoting $g$ the a.e. limit of $(f_n)$, $g$ is $\mathcal{F}_\infty$-measurable as for all
$n$, $f_n$ is $\mathcal{F}_n$-measurable and $\mathcal{F}_n \le \mathcal{F}_\infty$. Finally, $g$
is integrable as $|g| \le \liminf_{n \to \infty} |f_n|$ so
$$
\mathbb{E}|g| \le \mathbb{E} \limsup_{n \to \infty} |f_n| \le
\limsup_{n \to \infty} \mathbb{E}|f_n| < \infty
$$
as required.
Implementationwise, we have `tendsto_of_no_upcrossings` which shows that
a bounded sequence converges if it does not visit below $a$ and above $b$ infinitely often
for all $a, b ∈ s$ for some dense set $s$. So, we may skip the first step provided we can prove
that the realizations are bounded almost everywhere. Indeed, suppose $|f_n(\omega)|$ is not
bounded, then either $f_n(\omega) \to \pm \infty$ or one of $\limsup f_n(\omega)$ or
$\liminf f_n(\omega)$ equals $\pm \infty$ while the other is finite. But the first case
contradicts $\liminf |f_n(\omega)| < \infty$ while the second case contradicts finite upcrossings.
Furthermore, we introduce `Filtration.limitProcess` which chooses the limiting random variable
of a stochastic process if it exists, otherwise returning 0. Hence, instead of showing an
existence statement, we phrase the a.e. martingale convergence theorem by showing that a
submartingale converges to its `limitProcess` almost everywhere.
-/
/-- If a stochastic process has bounded upcrossing from below `a` to above `b`,
then it does not frequently visit both below `a` and above `b`. -/
theorem not_frequently_of_upcrossings_lt_top (hab : a < b) (hω : upcrossings a b f ω ≠ ∞) :
¬((∃ᶠ n in atTop, f n ω < a) ∧ ∃ᶠ n in atTop, b < f n ω) := by
| rw [← lt_top_iff_ne_top, upcrossings_lt_top_iff] at hω
replace hω : ∃ k, ∀ N, upcrossingsBefore a b f N ω < k := by
obtain ⟨k, hk⟩ := hω
exact ⟨k + 1, fun N => lt_of_le_of_lt (hk N) k.lt_succ_self⟩
rintro ⟨h₁, h₂⟩
rw [frequently_atTop] at h₁ h₂
refine Classical.not_not.2 hω ?_
push_neg
intro k
induction' k with k ih
· simp only [zero_le, exists_const]
· obtain ⟨N, hN⟩ := ih
obtain ⟨N₁, hN₁, hN₁'⟩ := h₁ N
obtain ⟨N₂, hN₂, hN₂'⟩ := h₂ N₁
exact ⟨N₂ + 1, Nat.succ_le_of_lt <|
lt_of_le_of_lt hN (upcrossingsBefore_lt_of_exists_upcrossing hab hN₁ hN₁' hN₂ hN₂')⟩
/-- A stochastic process that frequently visits below `a` and above `b` has infinite upcrossings. -/
| Mathlib/Probability/Martingale/Convergence.lean | 110 | 127 |
/-
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.Algebra.BigOperators.Fin
import Mathlib.Logic.Encodable.Pi
import Mathlib.MeasureTheory.Group.Measure
import Mathlib.MeasureTheory.MeasurableSpace.Pi
import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.Topology.Constructions
/-!
# Indexed product measures
In this file we define and prove properties about finite products of measures
(and at some point, countable products of measures).
## Main definition
* `MeasureTheory.Measure.pi`: The product of finitely many σ-finite measures.
Given `μ : (i : ι) → Measure (α i)` for `[Fintype ι]` it has type `Measure ((i : ι) → α i)`.
To apply Fubini's theorem or Tonelli's theorem along some subset, we recommend using the marginal
construction `MeasureTheory.lmarginal` and (todo) `MeasureTheory.marginal`. This allows you to
apply the theorems without any bookkeeping with measurable equivalences.
## Implementation Notes
We define `MeasureTheory.OuterMeasure.pi`, the product of finitely many outer measures, as the
maximal outer measure `n` with the property that `n (pi univ s) ≤ ∏ i, m i (s i)`,
where `pi univ s` is the product of the sets `{s i | i : ι}`.
We then show that this induces a product of measures, called `MeasureTheory.Measure.pi`.
For a collection of σ-finite measures `μ` and a collection of measurable sets `s` we show that
`Measure.pi μ (pi univ s) = ∏ i, m i (s i)`. To do this, we follow the following steps:
* We know that there is some ordering on `ι`, given by an element of `[Countable ι]`.
* Using this, we have an equivalence `MeasurableEquiv.piMeasurableEquivTProd` between
`∀ ι, α i` and an iterated product of `α i`, called `List.tprod α l` for some list `l`.
* On this iterated product we can easily define a product measure `MeasureTheory.Measure.tprod`
by iterating `MeasureTheory.Measure.prod`
* Using the previous two steps we construct `MeasureTheory.Measure.pi'` on `(i : ι) → α i` for
countable `ι`.
* We know that `MeasureTheory.Measure.pi'` sends products of sets to products of measures, and
since `MeasureTheory.Measure.pi` is the maximal such measure (or at least, it comes from an outer
measure which is the maximal such outer measure), we get the same rule for
`MeasureTheory.Measure.pi`.
## Tags
finitary product measure
-/
noncomputable section
open Function Set MeasureTheory.OuterMeasure Filter MeasurableSpace Encodable
open scoped Topology ENNReal
universe u v
variable {ι ι' : Type*} {α : ι → Type*}
namespace MeasureTheory
variable [Fintype ι] {m : ∀ i, OuterMeasure (α i)}
/-- An upper bound for the measure in a finite product space.
It is defined to by taking the image of the set under all projections, and taking the product
of the measures of these images.
For measurable boxes it is equal to the correct measure. -/
@[simp]
def piPremeasure (m : ∀ i, OuterMeasure (α i)) (s : Set (∀ i, α i)) : ℝ≥0∞ :=
∏ i, m i (eval i '' s)
theorem piPremeasure_pi {s : ∀ i, Set (α i)} (hs : (pi univ s).Nonempty) :
piPremeasure m (pi univ s) = ∏ i, m i (s i) := by simp [hs, piPremeasure]
theorem piPremeasure_pi' {s : ∀ i, Set (α i)} : piPremeasure m (pi univ s) = ∏ i, m i (s i) := by
cases isEmpty_or_nonempty ι
· simp [piPremeasure]
rcases (pi univ s).eq_empty_or_nonempty with h | h
· rcases univ_pi_eq_empty_iff.mp h with ⟨i, hi⟩
have : ∃ i, m i (s i) = 0 := ⟨i, by simp [hi]⟩
simpa [h, Finset.card_univ, zero_pow Fintype.card_ne_zero, @eq_comm _ (0 : ℝ≥0∞),
Finset.prod_eq_zero_iff, piPremeasure]
· simp [h, piPremeasure]
theorem piPremeasure_pi_mono {s t : Set (∀ i, α i)} (h : s ⊆ t) :
piPremeasure m s ≤ piPremeasure m t :=
Finset.prod_le_prod' fun _ _ => measure_mono (image_subset _ h)
theorem piPremeasure_pi_eval {s : Set (∀ i, α i)} :
piPremeasure m (pi univ fun i => eval i '' s) = piPremeasure m s := by
simp only [eval, piPremeasure_pi']; rfl
namespace OuterMeasure
/-- `OuterMeasure.pi m` is the finite product of the outer measures `{m i | i : ι}`.
It is defined to be the maximal outer measure `n` with the property that
`n (pi univ s) ≤ ∏ i, m i (s i)`, where `pi univ s` is the product of the sets
`{s i | i : ι}`. -/
protected def pi (m : ∀ i, OuterMeasure (α i)) : OuterMeasure (∀ i, α i) :=
boundedBy (piPremeasure m)
theorem pi_pi_le (m : ∀ i, OuterMeasure (α i)) (s : ∀ i, Set (α i)) :
OuterMeasure.pi m (pi univ s) ≤ ∏ i, m i (s i) := by
rcases (pi univ s).eq_empty_or_nonempty with h | h
· simp [h]
exact (boundedBy_le _).trans_eq (piPremeasure_pi h)
theorem le_pi {m : ∀ i, OuterMeasure (α i)} {n : OuterMeasure (∀ i, α i)} :
n ≤ OuterMeasure.pi m ↔
∀ s : ∀ i, Set (α i), (pi univ s).Nonempty → n (pi univ s) ≤ ∏ i, m i (s i) := by
rw [OuterMeasure.pi, le_boundedBy']; constructor
· intro h s hs; refine (h _ hs).trans_eq (piPremeasure_pi hs)
· intro h s hs; refine le_trans (n.mono <| subset_pi_eval_image univ s) (h _ ?_)
simp [univ_pi_nonempty_iff, hs]
end OuterMeasure
namespace Measure
variable [∀ i, MeasurableSpace (α i)] (μ : ∀ i, Measure (α i))
section Tprod
open List
variable {δ : Type*} {X : δ → Type*} [∀ i, MeasurableSpace (X i)]
-- for some reason the equation compiler doesn't like this definition
/-- A product of measures in `tprod α l`. -/
protected def tprod (l : List δ) (μ : ∀ i, Measure (X i)) : Measure (TProd X l) := by
induction' l with i l ih
· exact dirac PUnit.unit
· exact (μ i).prod (α := X i) ih
@[simp]
theorem tprod_nil (μ : ∀ i, Measure (X i)) : Measure.tprod [] μ = dirac PUnit.unit :=
rfl
@[simp]
theorem tprod_cons (i : δ) (l : List δ) (μ : ∀ i, Measure (X i)) :
Measure.tprod (i :: l) μ = (μ i).prod (Measure.tprod l μ) :=
rfl
instance sigmaFinite_tprod (l : List δ) (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)] :
SigmaFinite (Measure.tprod l μ) := by
induction l with
| nil => rw [tprod_nil]; infer_instance
| cons i l ih => rw [tprod_cons]; exact @prod.instSigmaFinite _ _ _ _ _ _ _ ih
theorem tprod_tprod (l : List δ) (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)]
(s : ∀ i, Set (X i)) :
Measure.tprod l μ (Set.tprod l s) = (l.map fun i => (μ i) (s i)).prod := by
induction l with
| nil => simp
| cons a l ih =>
rw [tprod_cons, Set.tprod]
dsimp only [foldr_cons, map_cons, prod_cons]
rw [prod_prod, ih]
end Tprod
section Encodable
open List MeasurableEquiv
variable [Encodable ι]
open scoped Classical in
/-- The product measure on an encodable finite type, defined by mapping `Measure.tprod` along the
equivalence `MeasurableEquiv.piMeasurableEquivTProd`.
The definition `MeasureTheory.Measure.pi` should be used instead of this one. -/
def pi' : Measure (∀ i, α i) :=
Measure.map (TProd.elim' mem_sortedUniv) (Measure.tprod (sortedUniv ι) μ)
theorem pi'_pi [∀ i, SigmaFinite (μ i)] (s : ∀ i, Set (α i)) :
pi' μ (pi univ s) = ∏ i, μ i (s i) := by
classical
rw [pi']
rw [← MeasurableEquiv.piMeasurableEquivTProd_symm_apply, MeasurableEquiv.map_apply,
MeasurableEquiv.piMeasurableEquivTProd_symm_apply, elim_preimage_pi, tprod_tprod _ μ, ←
List.prod_toFinset, sortedUniv_toFinset] <;>
exact sortedUniv_nodup ι
end Encodable
theorem pi_caratheodory :
MeasurableSpace.pi ≤ (OuterMeasure.pi fun i => (μ i).toOuterMeasure).caratheodory := by
refine iSup_le ?_
intro i s hs
rw [MeasurableSpace.comap] at hs
rcases hs with ⟨s, hs, rfl⟩
apply boundedBy_caratheodory
intro t
simp_rw [piPremeasure]
refine Finset.prod_add_prod_le' (Finset.mem_univ i) ?_ ?_ ?_
· simp [image_inter_preimage, image_diff_preimage, measure_inter_add_diff _ hs, le_refl]
· rintro j - _; gcongr; apply inter_subset_left
· rintro j - _; gcongr; apply diff_subset
/-- `Measure.pi μ` is the finite product of the measures `{μ i | i : ι}`.
It is defined to be measure corresponding to `MeasureTheory.OuterMeasure.pi`. -/
protected irreducible_def pi : Measure (∀ i, α i) :=
toMeasure (OuterMeasure.pi fun i => (μ i).toOuterMeasure) (pi_caratheodory μ)
instance _root_.MeasureTheory.MeasureSpace.pi {α : ι → Type*} [∀ i, MeasureSpace (α i)] :
MeasureSpace (∀ i, α i) :=
⟨Measure.pi fun _ => volume⟩
theorem pi_pi_aux [∀ i, SigmaFinite (μ i)] (s : ∀ i, Set (α i)) (hs : ∀ i, MeasurableSet (s i)) :
Measure.pi μ (pi univ s) = ∏ i, μ i (s i) := by
refine le_antisymm ?_ ?_
· rw [Measure.pi, toMeasure_apply _ _ (MeasurableSet.pi countable_univ fun i _ => hs i)]
apply OuterMeasure.pi_pi_le
· haveI : Encodable ι := Fintype.toEncodable ι
simp_rw [← pi'_pi μ s, Measure.pi,
toMeasure_apply _ _ (MeasurableSet.pi countable_univ fun i _ => hs i)]
suffices (pi' μ).toOuterMeasure ≤ OuterMeasure.pi fun i => (μ i).toOuterMeasure by exact this _
clear hs s
rw [OuterMeasure.le_pi]
intro s _
exact (pi'_pi μ s).le
variable {μ}
/-- `Measure.pi μ` has finite spanning sets in rectangles of finite spanning sets. -/
def FiniteSpanningSetsIn.pi {C : ∀ i, Set (Set (α i))}
(hμ : ∀ i, (μ i).FiniteSpanningSetsIn (C i)) :
(Measure.pi μ).FiniteSpanningSetsIn (pi univ '' pi univ C) := by
haveI := fun i => (hμ i).sigmaFinite
haveI := Fintype.toEncodable ι
refine ⟨fun n => Set.pi univ fun i => (hμ i).set ((@decode (ι → ℕ) _ n).iget i),
fun n => ?_, fun n => ?_, ?_⟩ <;>
-- TODO (kmill) If this let comes before the refine, while the noncomputability checker
-- correctly sees this definition is computable, the Lean VM fails to see the binding is
-- computationally irrelevant. The `noncomputable section` doesn't help because all it does
-- is insert `noncomputable` for you when necessary.
let e : ℕ → ι → ℕ := fun n => (@decode (ι → ℕ) _ n).iget
· refine mem_image_of_mem _ fun i _ => (hμ i).set_mem _
· calc
Measure.pi μ (Set.pi univ fun i => (hμ i).set (e n i)) ≤
Measure.pi μ (Set.pi univ fun i => toMeasurable (μ i) ((hμ i).set (e n i))) :=
measure_mono (pi_mono fun i _ => subset_toMeasurable _ _)
_ = ∏ i, μ i (toMeasurable (μ i) ((hμ i).set (e n i))) :=
(pi_pi_aux μ _ fun i => measurableSet_toMeasurable _ _)
_ = ∏ i, μ i ((hμ i).set (e n i)) := by simp only [measure_toMeasurable]
_ < ∞ := ENNReal.prod_lt_top fun i _ => (hμ i).finite _
· simp_rw [(surjective_decode_iget (ι → ℕ)).iUnion_comp fun x =>
Set.pi univ fun i => (hμ i).set (x i),
iUnion_univ_pi fun i => (hμ i).set, (hμ _).spanning, Set.pi_univ]
/-- A measure on a finite product space equals the product measure if they are equal on rectangles
with as sides sets that generate the corresponding σ-algebras. -/
theorem pi_eq_generateFrom {C : ∀ i, Set (Set (α i))}
(hC : ∀ i, generateFrom (C i) = by apply_assumption) (h2C : ∀ i, IsPiSystem (C i))
(h3C : ∀ i, (μ i).FiniteSpanningSetsIn (C i)) {μν : Measure (∀ i, α i)}
(h₁ : ∀ s : ∀ i, Set (α i), (∀ i, s i ∈ C i) → μν (pi univ s) = ∏ i, μ i (s i)) :
Measure.pi μ = μν := by
have h4C : ∀ (i) (s : Set (α i)), s ∈ C i → MeasurableSet s := by
intro i s hs; rw [← hC]; exact measurableSet_generateFrom hs
refine
(FiniteSpanningSetsIn.pi h3C).ext
(generateFrom_eq_pi hC fun i => (h3C i).isCountablySpanning).symm (IsPiSystem.pi h2C) ?_
rintro _ ⟨s, hs, rfl⟩
rw [mem_univ_pi] at hs
haveI := fun i => (h3C i).sigmaFinite
simp_rw [h₁ s hs, pi_pi_aux μ s fun i => h4C i _ (hs i)]
variable [∀ i, SigmaFinite (μ i)]
/-- A measure on a finite product space equals the product measure if they are equal on
rectangles. -/
theorem pi_eq {μ' : Measure (∀ i, α i)}
(h : ∀ s : ∀ i, Set (α i), (∀ i, MeasurableSet (s i)) → μ' (pi univ s) = ∏ i, μ i (s i)) :
Measure.pi μ = μ' :=
pi_eq_generateFrom (fun _ => generateFrom_measurableSet) (fun _ => isPiSystem_measurableSet)
(fun i => (μ i).toFiniteSpanningSetsIn) h
variable (μ)
theorem pi'_eq_pi [Encodable ι] : pi' μ = Measure.pi μ :=
Eq.symm <| pi_eq fun s _ => pi'_pi μ s
@[simp]
theorem pi_pi (s : ∀ i, Set (α i)) : Measure.pi μ (pi univ s) = ∏ i, μ i (s i) := by
haveI : Encodable ι := Fintype.toEncodable ι
rw [← pi'_eq_pi, pi'_pi]
nonrec theorem pi_univ : Measure.pi μ univ = ∏ i, μ i univ := by rw [← pi_univ, pi_pi μ]
theorem pi_ball [∀ i, MetricSpace (α i)] (x : ∀ i, α i) {r : ℝ} (hr : 0 < r) :
Measure.pi μ (Metric.ball x r) = ∏ i, μ i (Metric.ball (x i) r) := by rw [ball_pi _ hr, pi_pi]
theorem pi_closedBall [∀ i, MetricSpace (α i)] (x : ∀ i, α i) {r : ℝ} (hr : 0 ≤ r) :
Measure.pi μ (Metric.closedBall x r) = ∏ i, μ i (Metric.closedBall (x i) r) := by
rw [closedBall_pi _ hr, pi_pi]
instance pi.sigmaFinite : SigmaFinite (Measure.pi μ) :=
(FiniteSpanningSetsIn.pi fun i => (μ i).toFiniteSpanningSetsIn).sigmaFinite
instance {α : ι → Type*} [∀ i, MeasureSpace (α i)] [∀ i, SigmaFinite (volume : Measure (α i))] :
SigmaFinite (volume : Measure (∀ i, α i)) :=
pi.sigmaFinite _
instance pi.instIsFiniteMeasure [∀ i, IsFiniteMeasure (μ i)] :
IsFiniteMeasure (Measure.pi μ) :=
⟨Measure.pi_univ μ ▸ ENNReal.prod_lt_top (fun i _ ↦ measure_lt_top (μ i) _)⟩
instance {α : ι → Type*} [∀ i, MeasureSpace (α i)] [∀ i, IsFiniteMeasure (volume : Measure (α i))] :
IsFiniteMeasure (volume : Measure (∀ i, α i)) :=
pi.instIsFiniteMeasure _
instance pi.instIsProbabilityMeasure [∀ i, IsProbabilityMeasure (μ i)] :
IsProbabilityMeasure (Measure.pi μ) :=
⟨by simp only [Measure.pi_univ, measure_univ, Finset.prod_const_one]⟩
instance {α : ι → Type*} [∀ i, MeasureSpace (α i)]
[∀ i, IsProbabilityMeasure (volume : Measure (α i))] :
IsProbabilityMeasure (volume : Measure (∀ i, α i)) :=
pi.instIsProbabilityMeasure _
theorem pi_of_empty {α : Type*} [Fintype α] [IsEmpty α] {β : α → Type*}
{m : ∀ a, MeasurableSpace (β a)} (μ : ∀ a : α, Measure (β a)) (x : ∀ a, β a := isEmptyElim) :
Measure.pi μ = dirac x := by
haveI : ∀ a, SigmaFinite (μ a) := isEmptyElim
refine pi_eq fun s _ => ?_
rw [Fintype.prod_empty, dirac_apply_of_mem]
exact isEmptyElim (α := α)
lemma volume_pi_eq_dirac {ι : Type*} [Fintype ι] [IsEmpty ι]
{α : ι → Type*} [∀ i, MeasureSpace (α i)] (x : ∀ a, α a := isEmptyElim) :
(volume : Measure (∀ i, α i)) = Measure.dirac x :=
Measure.pi_of_empty _ _
@[simp]
theorem pi_empty_univ {α : Type*} [Fintype α] [IsEmpty α] {β : α → Type*}
{m : ∀ α, MeasurableSpace (β α)} (μ : ∀ a : α, Measure (β a)) :
Measure.pi μ (Set.univ) = 1 := by
rw [pi_of_empty, measure_univ]
theorem pi_eval_preimage_null {i : ι} {s : Set (α i)} (hs : μ i s = 0) :
Measure.pi μ (eval i ⁻¹' s) = 0 := by
classical
-- WLOG, `s` is measurable
rcases exists_measurable_superset_of_null hs with ⟨t, hst, _, hμt⟩
suffices Measure.pi μ (eval i ⁻¹' t) = 0 from measure_mono_null (preimage_mono hst) this
-- Now rewrite it as `Set.pi`, and apply `pi_pi`
rw [← univ_pi_update_univ, pi_pi]
apply Finset.prod_eq_zero (Finset.mem_univ i)
simp [hμt]
theorem pi_hyperplane (i : ι) [NoAtoms (μ i)] (x : α i) :
Measure.pi μ { f : ∀ i, α i | f i = x } = 0 :=
show Measure.pi μ (eval i ⁻¹' {x}) = 0 from pi_eval_preimage_null _ (measure_singleton x)
theorem ae_eval_ne (i : ι) [NoAtoms (μ i)] (x : α i) : ∀ᵐ y : ∀ i, α i ∂Measure.pi μ, y i ≠ x :=
compl_mem_ae_iff.2 (pi_hyperplane μ i x)
theorem restrict_pi_pi (s : (i : ι) → Set (α i)) :
(Measure.pi μ).restrict (Set.univ.pi fun i ↦ s i) = .pi (fun i ↦ (μ i).restrict (s i)) := by
refine (pi_eq fun _ h ↦ ?_).symm
simp_rw [restrict_apply (MeasurableSet.univ_pi h), restrict_apply (h _),
← Set.pi_inter_distrib, pi_pi]
variable {μ}
theorem tendsto_eval_ae_ae {i : ι} : Tendsto (eval i) (ae (Measure.pi μ)) (ae (μ i)) := fun _ hs =>
pi_eval_preimage_null μ hs
theorem ae_pi_le_pi : ae (Measure.pi μ) ≤ Filter.pi fun i => ae (μ i) :=
le_iInf fun _ => tendsto_eval_ae_ae.le_comap
theorem ae_eq_pi {β : ι → Type*} {f f' : ∀ i, α i → β i} (h : ∀ i, f i =ᵐ[μ i] f' i) :
(fun (x : ∀ i, α i) i => f i (x i)) =ᵐ[Measure.pi μ] fun x i => f' i (x i) :=
(eventually_all.2 fun i => tendsto_eval_ae_ae.eventually (h i)).mono fun _ hx => funext hx
theorem ae_le_pi {β : ι → Type*} [∀ i, Preorder (β i)] {f f' : ∀ i, α i → β i}
(h : ∀ i, f i ≤ᵐ[μ i] f' i) :
(fun (x : ∀ i, α i) i => f i (x i)) ≤ᵐ[Measure.pi μ] fun x i => f' i (x i) :=
(eventually_all.2 fun i => tendsto_eval_ae_ae.eventually (h i)).mono fun _ hx => hx
theorem ae_le_set_pi {I : Set ι} {s t : ∀ i, Set (α i)} (h : ∀ i ∈ I, s i ≤ᵐ[μ i] t i) :
Set.pi I s ≤ᵐ[Measure.pi μ] Set.pi I t :=
((eventually_all_finite I.toFinite).2 fun i hi => tendsto_eval_ae_ae.eventually (h i hi)).mono
fun _ hst hx i hi => hst i hi <| hx i hi
theorem ae_eq_set_pi {I : Set ι} {s t : ∀ i, Set (α i)} (h : ∀ i ∈ I, s i =ᵐ[μ i] t i) :
Set.pi I s =ᵐ[Measure.pi μ] Set.pi I t :=
(ae_le_set_pi fun i hi => (h i hi).le).antisymm (ae_le_set_pi fun i hi => (h i hi).symm.le)
lemma pi_map_piCongrLeft [hι' : Fintype ι'] (e : ι ≃ ι') {β : ι' → Type*}
[∀ i, MeasurableSpace (β i)] (μ : (i : ι') → Measure (β i)) [∀ i, SigmaFinite (μ i)] :
(Measure.pi fun i ↦ μ (e i)).map (MeasurableEquiv.piCongrLeft (fun i ↦ β i) e)
= Measure.pi μ := by
let e_meas : ((b : ι) → β (e b)) ≃ᵐ ((a : ι') → β a) :=
MeasurableEquiv.piCongrLeft (fun i ↦ β i) e
refine Measure.pi_eq (fun s _ ↦ ?_) |>.symm
rw [e_meas.measurableEmbedding.map_apply]
let s' : (i : ι) → Set (β (e i)) := fun i ↦ s (e i)
have : e_meas ⁻¹' pi univ s = pi univ s' := by
ext x
simp only [mem_preimage, Set.mem_pi, mem_univ, forall_true_left, s']
refine (e.forall_congr ?_).symm
intro i
rw [MeasurableEquiv.piCongrLeft_apply_apply e x i]
rw [this, pi_pi, Finset.prod_equiv e.symm]
· simp only [Finset.mem_univ, implies_true]
intro i _
simp only [s']
congr
all_goals rw [e.apply_symm_apply]
lemma pi_map_piOptionEquivProd {β : Option ι → Type*} [∀ i, MeasurableSpace (β i)]
(μ : (i : Option ι) → Measure (β i)) [∀ (i : Option ι), SigmaFinite (μ i)] :
((Measure.pi fun i ↦ μ (some i)).prod (μ none)).map
(MeasurableEquiv.piOptionEquivProd β).symm = Measure.pi μ := by
refine pi_eq (fun s _ ↦ ?_) |>.symm
let e_meas : ((i : ι) → β (some i)) × β none ≃ᵐ ((i : Option ι) → β i) :=
MeasurableEquiv.piOptionEquivProd β |>.symm
have me := MeasurableEquiv.measurableEmbedding e_meas
have : e_meas ⁻¹' pi univ s = (pi univ (fun i ↦ s (some i))) ×ˢ (s none) := by
ext x
simp only [mem_preimage, Set.mem_pi, mem_univ, forall_true_left, mem_prod]
refine ⟨by tauto, fun _ i ↦ ?_⟩
rcases i <;> tauto
simp only [e_meas, me.map_apply, univ_option, le_eq_subset, Finset.prod_insertNone, this,
prod_prod, pi_pi, mul_comm]
section Intervals
variable [∀ i, PartialOrder (α i)] [∀ i, NoAtoms (μ i)]
theorem pi_Iio_ae_eq_pi_Iic {s : Set ι} {f : ∀ i, α i} :
(pi s fun i => Iio (f i)) =ᵐ[Measure.pi μ] pi s fun i => Iic (f i) :=
ae_eq_set_pi fun _ _ => Iio_ae_eq_Iic
theorem pi_Ioi_ae_eq_pi_Ici {s : Set ι} {f : ∀ i, α i} :
(pi s fun i => Ioi (f i)) =ᵐ[Measure.pi μ] pi s fun i => Ici (f i) :=
ae_eq_set_pi fun _ _ => Ioi_ae_eq_Ici
theorem univ_pi_Iio_ae_eq_Iic {f : ∀ i, α i} :
(pi univ fun i => Iio (f i)) =ᵐ[Measure.pi μ] Iic f := by
rw [← pi_univ_Iic]; exact pi_Iio_ae_eq_pi_Iic
theorem univ_pi_Ioi_ae_eq_Ici {f : ∀ i, α i} :
(pi univ fun i => Ioi (f i)) =ᵐ[Measure.pi μ] Ici f := by
rw [← pi_univ_Ici]; exact pi_Ioi_ae_eq_pi_Ici
theorem pi_Ioo_ae_eq_pi_Icc {s : Set ι} {f g : ∀ i, α i} :
(pi s fun i => Ioo (f i) (g i)) =ᵐ[Measure.pi μ] pi s fun i => Icc (f i) (g i) :=
ae_eq_set_pi fun _ _ => Ioo_ae_eq_Icc
theorem pi_Ioo_ae_eq_pi_Ioc {s : Set ι} {f g : ∀ i, α i} :
(pi s fun i => Ioo (f i) (g i)) =ᵐ[Measure.pi μ] pi s fun i => Ioc (f i) (g i) :=
ae_eq_set_pi fun _ _ => Ioo_ae_eq_Ioc
theorem univ_pi_Ioo_ae_eq_Icc {f g : ∀ i, α i} :
(pi univ fun i => Ioo (f i) (g i)) =ᵐ[Measure.pi μ] Icc f g := by
rw [← pi_univ_Icc]; exact pi_Ioo_ae_eq_pi_Icc
theorem pi_Ioc_ae_eq_pi_Icc {s : Set ι} {f g : ∀ i, α i} :
(pi s fun i => Ioc (f i) (g i)) =ᵐ[Measure.pi μ] pi s fun i => Icc (f i) (g i) :=
ae_eq_set_pi fun _ _ => Ioc_ae_eq_Icc
theorem univ_pi_Ioc_ae_eq_Icc {f g : ∀ i, α i} :
(pi univ fun i => Ioc (f i) (g i)) =ᵐ[Measure.pi μ] Icc f g := by
rw [← pi_univ_Icc]; exact pi_Ioc_ae_eq_pi_Icc
theorem pi_Ico_ae_eq_pi_Icc {s : Set ι} {f g : ∀ i, α i} :
(pi s fun i => Ico (f i) (g i)) =ᵐ[Measure.pi μ] pi s fun i => Icc (f i) (g i) :=
ae_eq_set_pi fun _ _ => Ico_ae_eq_Icc
theorem univ_pi_Ico_ae_eq_Icc {f g : ∀ i, α i} :
(pi univ fun i => Ico (f i) (g i)) =ᵐ[Measure.pi μ] Icc f g := by
rw [← pi_univ_Icc]; exact pi_Ico_ae_eq_pi_Icc
end Intervals
/-- If one of the measures `μ i` has no atoms, them `Measure.pi µ`
has no atoms. The instance below assumes that all `μ i` have no atoms. -/
theorem pi_noAtoms (i : ι) [NoAtoms (μ i)] : NoAtoms (Measure.pi μ) :=
⟨fun x => flip measure_mono_null (pi_hyperplane μ i (x i)) (singleton_subset_iff.2 rfl)⟩
instance pi_noAtoms' [h : Nonempty ι] [∀ i, NoAtoms (μ i)] : NoAtoms (Measure.pi μ) :=
h.elim fun i => pi_noAtoms i
instance {α : ι → Type*} [Nonempty ι] [∀ i, MeasureSpace (α i)]
[∀ i, SigmaFinite (volume : Measure (α i))] [∀ i, NoAtoms (volume : Measure (α i))] :
NoAtoms (volume : Measure (∀ i, α i)) :=
pi_noAtoms'
instance pi.isLocallyFiniteMeasure
[∀ i, TopologicalSpace (α i)] [∀ i, IsLocallyFiniteMeasure (μ i)] :
IsLocallyFiniteMeasure (Measure.pi μ) := by
refine ⟨fun x => ?_⟩
choose s hxs ho hμ using fun i => (μ i).exists_isOpen_measure_lt_top (x i)
refine ⟨pi univ s, set_pi_mem_nhds finite_univ fun i _ => IsOpen.mem_nhds (ho i) (hxs i), ?_⟩
rw [pi_pi]
exact ENNReal.prod_lt_top fun i _ => hμ i
instance {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, MeasureSpace (X i)]
[∀ i, SigmaFinite (volume : Measure (X i))]
[∀ i, IsLocallyFiniteMeasure (volume : Measure (X i))] :
IsLocallyFiniteMeasure (volume : Measure (∀ i, X i)) :=
pi.isLocallyFiniteMeasure
variable (μ)
@[to_additive]
instance pi.isMulLeftInvariant [∀ i, Group (α i)] [∀ i, MeasurableMul (α i)]
[∀ i, IsMulLeftInvariant (μ i)] : IsMulLeftInvariant (Measure.pi μ) := by
refine ⟨fun v => (pi_eq fun s hs => ?_).symm⟩
rw [map_apply (measurable_const_mul _) (MeasurableSet.univ_pi hs),
show (v * ·) ⁻¹' univ.pi s = univ.pi fun i => (v i * ·) ⁻¹' s i by rfl, pi_pi]
simp_rw [measure_preimage_mul]
@[to_additive]
instance {G : ι → Type*} [∀ i, Group (G i)] [∀ i, MeasureSpace (G i)] [∀ i, MeasurableMul (G i)]
[∀ i, SigmaFinite (volume : Measure (G i))] [∀ i, IsMulLeftInvariant (volume : Measure (G i))] :
IsMulLeftInvariant (volume : Measure (∀ i, G i)) :=
pi.isMulLeftInvariant _
@[to_additive]
instance pi.isMulRightInvariant [∀ i, Group (α i)] [∀ i, MeasurableMul (α i)]
[∀ i, IsMulRightInvariant (μ i)] : IsMulRightInvariant (Measure.pi μ) := by
refine ⟨fun v => (pi_eq fun s hs => ?_).symm⟩
rw [map_apply (measurable_mul_const _) (MeasurableSet.univ_pi hs),
show (· * v) ⁻¹' univ.pi s = univ.pi fun i => (· * v i) ⁻¹' s i by rfl, pi_pi]
simp_rw [measure_preimage_mul_right]
@[to_additive]
instance {G : ι → Type*} [∀ i, Group (G i)] [∀ i, MeasureSpace (G i)] [∀ i, MeasurableMul (G i)]
[∀ i, SigmaFinite (volume : Measure (G i))]
[∀ i, IsMulRightInvariant (volume : Measure (G i))] :
IsMulRightInvariant (volume : Measure (∀ i, G i)) :=
pi.isMulRightInvariant _
@[to_additive]
instance pi.isInvInvariant [∀ i, Group (α i)] [∀ i, MeasurableInv (α i)]
[∀ i, IsInvInvariant (μ i)] : IsInvInvariant (Measure.pi μ) := by
refine ⟨(Measure.pi_eq fun s hs => ?_).symm⟩
have A : Inv.inv ⁻¹' pi univ s = Set.pi univ fun i => Inv.inv ⁻¹' s i := by ext; simp
simp_rw [Measure.inv, Measure.map_apply measurable_inv (MeasurableSet.univ_pi hs), A, pi_pi,
measure_preimage_inv]
@[to_additive]
instance {G : ι → Type*} [∀ i, Group (G i)] [∀ i, MeasureSpace (G i)] [∀ i, MeasurableInv (G i)]
[∀ i, SigmaFinite (volume : Measure (G i))] [∀ i, IsInvInvariant (volume : Measure (G i))] :
IsInvInvariant (volume : Measure (∀ i, G i)) :=
pi.isInvInvariant _
instance pi.isOpenPosMeasure [∀ i, TopologicalSpace (α i)] [∀ i, IsOpenPosMeasure (μ i)] :
IsOpenPosMeasure (MeasureTheory.Measure.pi μ) := by
constructor
rintro U U_open ⟨a, ha⟩
obtain ⟨s, ⟨hs, hsU⟩⟩ := isOpen_pi_iff'.1 U_open a ha
refine ne_of_gt (lt_of_lt_of_le ?_ (measure_mono hsU))
simp only [pi_pi]
rw [CanonicallyOrderedAdd.prod_pos]
intro i _
apply (hs i).1.measure_pos (μ i) ⟨a i, (hs i).2⟩
instance {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, MeasureSpace (X i)]
[∀ i, IsOpenPosMeasure (volume : Measure (X i))] [∀ i, SigmaFinite (volume : Measure (X i))] :
IsOpenPosMeasure (volume : Measure (∀ i, X i)) :=
pi.isOpenPosMeasure _
instance pi.isFiniteMeasureOnCompacts [∀ i, TopologicalSpace (α i)]
[∀ i, IsFiniteMeasureOnCompacts (μ i)] :
IsFiniteMeasureOnCompacts (MeasureTheory.Measure.pi μ) := by
constructor
intro K hK
suffices Measure.pi μ (Set.univ.pi fun j => Function.eval j '' K) < ⊤ by
exact lt_of_le_of_lt (measure_mono (univ.subset_pi_eval_image K)) this
rw [Measure.pi_pi]
refine WithTop.prod_lt_top ?_
exact fun i _ => IsCompact.measure_lt_top (IsCompact.image hK (continuous_apply i))
instance {X : ι → Type*} [∀ i, MeasureSpace (X i)] [∀ i, TopologicalSpace (X i)]
[∀ i, SigmaFinite (volume : Measure (X i))]
[∀ i, IsFiniteMeasureOnCompacts (volume : Measure (X i))] :
IsFiniteMeasureOnCompacts (volume : Measure (∀ i, X i)) :=
pi.isFiniteMeasureOnCompacts _
@[to_additive]
instance pi.isHaarMeasure [∀ i, Group (α i)] [∀ i, TopologicalSpace (α i)]
[∀ i, IsHaarMeasure (μ i)] [∀ i, MeasurableMul (α i)] : IsHaarMeasure (Measure.pi μ) where
| @[to_additive]
instance {G : ι → Type*} [∀ i, Group (G i)] [∀ i, MeasureSpace (G i)] [∀ i, MeasurableMul (G i)]
[∀ i, TopologicalSpace (G i)] [∀ i, SigmaFinite (volume : Measure (G i))]
| Mathlib/MeasureTheory/Constructions/Pi.lean | 593 | 595 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Contraction
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.RingTheory.Finiteness.Prod
import Mathlib.RingTheory.TensorProduct.Finite
import Mathlib.RingTheory.TensorProduct.Free
/-!
# Trace of a linear map
This file defines the trace of a linear map.
See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix.
## Tags
linear_map, trace, diagonal
-/
noncomputable section
universe u v w
namespace LinearMap
open scoped Matrix
open Module TensorProduct
section
variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M]
variable {ι : Type w} [DecidableEq ι] [Fintype ι]
variable {κ : Type*} [DecidableEq κ] [Fintype κ]
variable (b : Basis ι R M) (c : Basis κ R M)
/-- The trace of an endomorphism given a basis. -/
def traceAux : (M →ₗ[R] M) →ₗ[R] R :=
Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b)
-- Can't be `simp` because it would cause a loop.
theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) :
traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) :=
rfl
theorem traceAux_eq : traceAux R b = traceAux R c :=
LinearMap.ext fun f =>
calc
Matrix.trace (LinearMap.toMatrix b b f) =
Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by
rw [LinearMap.id_comp, LinearMap.comp_id]
_ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f *
LinearMap.toMatrix b c LinearMap.id) := by
rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id *
LinearMap.toMatrix c b LinearMap.id) := by
rw [Matrix.mul_assoc, Matrix.trace_mul_comm]
_ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by
rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id]
variable (M) in
open Classical in
/-- Trace of an endomorphism independent of basis. -/
def trace : (M →ₗ[R] M) →ₗ[R] R :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0
open Classical in
/-- Auxiliary lemma for `trace_eq_matrix_trace`. -/
theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩
rw [trace, dif_pos this, ← traceAux_def]
congr 1
apply traceAux_eq
theorem trace_eq_matrix_trace (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
classical
rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def,
traceAux_eq R b b.reindexFinsetRange]
theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s R M)
· let ⟨s, ⟨b⟩⟩ := H
simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul]
apply Matrix.trace_mul_comm
· rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply]
lemma trace_mul_cycle (f g h : M →ₗ[R] M) :
trace R M (f * g * h) = trace R M (h * f * g) := by
rw [LinearMap.trace_mul_comm, ← mul_assoc]
lemma trace_mul_cycle' (f g h : M →ₗ[R] M) :
trace R M (f * (g * h)) = trace R M (h * (f * g)) := by
rw [← mul_assoc, LinearMap.trace_mul_comm]
/-- The trace of an endomorphism is invariant under conjugation -/
@[simp]
theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) :
trace R M (↑f * g * ↑f⁻¹) = trace R M g := by
rw [trace_mul_comm]
simp
@[simp]
lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) :
trace R M ⁅f, g⁆ = 0 := by
rw [Ring.lie_def, map_sub, trace_mul_comm]
exact sub_self _
end
section
variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]
variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P]
variable {ι : Type*}
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M` -/
theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) :
LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by
classical
cases nonempty_fintype ι
apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b)
rintro ⟨i, j⟩
simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp]
rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom]
by_cases hij : i = j
· rw [hij]
simp
rw [Matrix.StdBasisMatrix.trace_zero j i (1 : R) hij]
simp [Finsupp.single_eq_pi_single, hij]
/-- The trace of a linear map corresponds to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`. -/
theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by
simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b]
section
variable (R M)
variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N]
/-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`. -/
@[simp]
theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M :=
trace_eq_contract_of_basis (Module.Free.chooseBasis R M)
@[simp]
theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) :
(LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by
rw [← comp_apply, trace_eq_contract]
/-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`. -/
theorem trace_eq_contract' :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap :=
trace_eq_contract_of_basis' (Module.Free.chooseBasis R M)
/-- The trace of the identity endomorphism is the dimension of the free module. -/
@[simp]
theorem trace_one : trace R M 1 = (finrank R M : R) := by
cases subsingleton_or_nontrivial R
· simp [eq_iff_true_of_subsingleton]
have b := Module.Free.chooseBasis R M
rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex]
simp
/-- The trace of the identity endomorphism is the dimension of the free module. -/
@[simp]
theorem trace_id : trace R M id = (finrank R M : R) := by rw [← Module.End.one_eq_id, trace_one]
@[simp]
theorem trace_transpose : trace R (Module.Dual R M) ∘ₗ Module.Dual.transpose = trace R M := by
let e := dualTensorHomEquiv R M M
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f m; simp [e]
theorem trace_prodMap :
trace R (M × N) ∘ₗ prodMapLinear R M N M N R =
(coprod id id : R × R →ₗ[R] R) ∘ₗ prodMap (trace R M) (trace R N) := by
let e := (dualTensorHomEquiv R M M).prodCongr (dualTensorHomEquiv R N N)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext
· simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr,
dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp,
curry_apply, coe_comp, coe_restrictScalars, coe_inl, Function.comp_apply, prodMap_apply,
map_zero, prodMapLinear_apply, dualTensorHom_prodMap_zero, trace_eq_contract_apply,
contractLeft_apply, coe_fst, coprod_apply, id_coe, id_eq, add_zero, e]
· simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr,
dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp,
curry_apply, coe_comp, coe_restrictScalars, coe_inr, Function.comp_apply, prodMap_apply,
map_zero, prodMapLinear_apply, zero_prodMap_dualTensorHom, trace_eq_contract_apply,
contractLeft_apply, coe_snd, coprod_apply, id_coe, id_eq, zero_add, e]
variable {R M N P}
theorem trace_prodMap' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M × N) (prodMap f g) = trace R M f + trace R N g := by
have h := LinearMap.ext_iff.1 (trace_prodMap R M N) (f, g)
simp only [coe_comp, Function.comp_apply, prodMap_apply, coprod_apply, id_coe, id,
prodMapLinear_apply] at h
exact h
variable (R M N P)
open TensorProduct Function
theorem trace_tensorProduct : compr₂ (mapBilinear R M N M N) (trace R (M ⊗ N)) =
compl₁₂ (lsmul R R : R →ₗ[R] R →ₗ[R] R) (trace R M) (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R M M) from (dualTensorHomEquiv R M M).surjective)
(show Surjective (dualTensorHom R N N) from (dualTensorHomEquiv R N N).surjective)).1
ext f m g n
simp only [AlgebraTensorModule.curry_apply, toFun_eq_coe, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, mapBilinear_apply,
trace_eq_contract_apply, contractLeft_apply, lsmul_apply, Algebra.id.smul_eq_mul,
map_dualTensorHom, dualDistrib_apply]
theorem trace_comp_comm :
compr₂ (llcomp R M N M) (trace R M) = compr₂ (llcomp R N M N).flip (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R N M) from (dualTensorHomEquiv R N M).surjective)
(show Surjective (dualTensorHom R M N) from (dualTensorHomEquiv R M N).surjective)).1
ext g m f n
simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, flip_apply, llcomp_apply',
comp_dualTensorHom, LinearMapClass.map_smul, trace_eq_contract_apply,
contractLeft_apply, smul_eq_mul, mul_comm]
variable {R M N P}
@[simp]
theorem trace_transpose' (f : M →ₗ[R] M) :
trace R _ (Module.Dual.transpose (R := R) f) = trace R M f := by
rw [← comp_apply, trace_transpose]
theorem trace_tensorProduct' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M ⊗ N) (map f g) = trace R M f * trace R N g := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_tensorProduct R M N) f) g
simp only [compr₂_apply, mapBilinear_apply, compl₁₂_apply, lsmul_apply,
| Algebra.id.smul_eq_mul] at h
exact h
theorem trace_comp_comm' (f : M →ₗ[R] N) (g : N →ₗ[R] M) :
trace R M (g ∘ₗ f) = trace R N (f ∘ₗ g) := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_comp_comm R M N) g) f
simp only [llcomp_apply', compr₂_apply, flip_apply] at h
exact h
end
| Mathlib/LinearAlgebra/Trace.lean | 250 | 259 |
/-
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.Data.Set.Prod
/-!
# N-ary images of sets
This file defines `Set.image2`, the binary image of sets.
This is mostly useful to define pointwise operations and `Set.seq`.
## Notes
This file is very similar to `Data.Finset.NAry`, to `Order.Filter.NAry`, and to
`Data.Option.NAry`. Please keep them in sync.
-/
open Function
namespace Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} {f f' : α → β → γ}
variable {s s' : Set α} {t t' : Set β} {u : Set γ} {v : Set δ} {a : α} {b : β}
theorem mem_image2_iff (hf : Injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t :=
⟨by
rintro ⟨a', ha', b', hb', h⟩
rcases hf h with ⟨rfl, rfl⟩
exact ⟨ha', hb'⟩, fun ⟨ha, hb⟩ => mem_image2_of_mem ha hb⟩
/-- image2 is monotone with respect to `⊆`. -/
@[gcongr]
theorem image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' := by
rintro _ ⟨a, ha, b, hb, rfl⟩
exact mem_image2_of_mem (hs ha) (ht hb)
@[gcongr]
theorem image2_subset_left (ht : t ⊆ t') : image2 f s t ⊆ image2 f s t' :=
image2_subset Subset.rfl ht
@[gcongr]
theorem image2_subset_right (hs : s ⊆ s') : image2 f s t ⊆ image2 f s' t :=
image2_subset hs Subset.rfl
theorem image_subset_image2_left (hb : b ∈ t) : (fun a => f a b) '' s ⊆ image2 f s t :=
forall_mem_image.2 fun _ ha => mem_image2_of_mem ha hb
theorem image_subset_image2_right (ha : a ∈ s) : f a '' t ⊆ image2 f s t :=
forall_mem_image.2 fun _ => mem_image2_of_mem ha
lemma forall_mem_image2 {p : γ → Prop} :
(∀ z ∈ image2 f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by aesop
lemma exists_mem_image2 {p : γ → Prop} :
(∃ z ∈ image2 f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by aesop
@[deprecated (since := "2024-11-23")] alias forall_image2_iff := forall_mem_image2
@[simp]
theorem image2_subset_iff {u : Set γ} : image2 f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image2
theorem image2_subset_iff_left : image2 f s t ⊆ u ↔ ∀ a ∈ s, (fun b => f a b) '' t ⊆ u := by
simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage]
theorem image2_subset_iff_right : image2 f s t ⊆ u ↔ ∀ b ∈ t, (fun a => f a b) '' s ⊆ u := by
simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage, @forall₂_swap α]
variable (f)
@[simp]
lemma image_prod : (fun x : α × β ↦ f x.1 x.2) '' s ×ˢ t = image2 f s t :=
ext fun _ ↦ by simp [and_assoc]
@[simp] lemma image_uncurry_prod (s : Set α) (t : Set β) : uncurry f '' s ×ˢ t = image2 f s t :=
image_prod _
@[simp] lemma image2_mk_eq_prod : image2 Prod.mk s t = s ×ˢ t := ext <| by simp
@[simp]
lemma image2_curry (f : α × β → γ) (s : Set α) (t : Set β) :
image2 (fun a b ↦ f (a, b)) s t = f '' s ×ˢ t := by
simp [← image_uncurry_prod, uncurry]
theorem image2_swap (s : Set α) (t : Set β) : image2 f s t = image2 (fun a b => f b a) t s := by
ext
constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨b, hb, a, ha, rfl⟩
variable {f}
theorem image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t := by
simp_rw [← image_prod, union_prod, image_union]
theorem image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' := by
rw [← image2_swap, image2_union_left, image2_swap f, image2_swap f]
lemma image2_inter_left (hf : Injective2 f) :
image2 f (s ∩ s') t = image2 f s t ∩ image2 f s' t := by
simp_rw [← image_uncurry_prod, inter_prod, image_inter hf.uncurry]
lemma image2_inter_right (hf : Injective2 f) :
image2 f s (t ∩ t') = image2 f s t ∩ image2 f s t' := by
simp_rw [← image_uncurry_prod, prod_inter, image_inter hf.uncurry]
@[simp]
theorem image2_empty_left : image2 f ∅ t = ∅ :=
ext <| by simp
@[simp]
theorem image2_empty_right : image2 f s ∅ = ∅ :=
ext <| by simp
theorem Nonempty.image2 : s.Nonempty → t.Nonempty → (image2 f s t).Nonempty :=
fun ⟨_, ha⟩ ⟨_, hb⟩ => ⟨_, mem_image2_of_mem ha hb⟩
@[simp]
theorem image2_nonempty_iff : (image2 f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
⟨fun ⟨_, a, ha, b, hb, _⟩ => ⟨⟨a, ha⟩, b, hb⟩, fun h => h.1.image2 h.2⟩
theorem Nonempty.of_image2_left (h : (Set.image2 f s t).Nonempty) : s.Nonempty :=
(image2_nonempty_iff.1 h).1
theorem Nonempty.of_image2_right (h : (Set.image2 f s t).Nonempty) : t.Nonempty :=
(image2_nonempty_iff.1 h).2
@[simp]
theorem image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
rw [← not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_or]
simp [not_nonempty_iff_eq_empty]
theorem Subsingleton.image2 (hs : s.Subsingleton) (ht : t.Subsingleton) (f : α → β → γ) :
(image2 f s t).Subsingleton := by
rw [← image_prod]
apply (hs.prod ht).image
theorem image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t :=
Monotone.map_inf_le (fun _ _ ↦ image2_subset_right) s s'
theorem image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' :=
Monotone.map_inf_le (fun _ _ ↦ image2_subset_left) t t'
@[simp]
theorem image2_singleton_left : image2 f {a} t = f a '' t :=
ext fun x => by simp
@[simp]
theorem image2_singleton_right : image2 f s {b} = (fun a => f a b) '' s :=
| ext fun x => by simp
theorem image2_singleton : image2 f {a} {b} = {f a b} := by simp
| Mathlib/Data/Set/NAry.lean | 149 | 151 |
/-
Copyright (c) 2019 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Normed.Group.AddCircle
import Mathlib.Algebra.CharZero.Quotient
import Mathlib.Topology.Instances.Sign
/-!
# The type of angles
In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas
about trigonometric functions and angles.
-/
open Real
noncomputable section
namespace Real
/-- The type of angles -/
def Angle : Type :=
AddCircle (2 * π)
-- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
namespace Angle
instance : NormedAddCommGroup Angle :=
inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π)))
instance : Inhabited Angle :=
inferInstanceAs (Inhabited (AddCircle (2 * π)))
/-- The canonical map from `ℝ` to the quotient `Angle`. -/
@[coe]
protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r
instance : Coe ℝ Angle := ⟨Angle.coe⟩
instance : CircularOrder Real.Angle :=
QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩)
@[continuity]
theorem continuous_coe : Continuous ((↑) : ℝ → Angle) :=
continuous_quotient_mk'
/-- Coercion `ℝ → Angle` as an additive homomorphism. -/
def coeHom : ℝ →+ Angle :=
QuotientAddGroup.mk' _
@[simp]
theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) :=
rfl
/-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with
`induction θ using Real.Angle.induction_on`. -/
@[elab_as_elim]
protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ :=
Quotient.inductionOn' θ h
@[simp]
theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) :=
rfl
@[simp]
theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) :=
rfl
@[simp]
theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) :=
rfl
@[simp]
theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) :=
rfl
theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) :=
rfl
theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) :=
rfl
theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x :=
AddCircle.coe_eq_zero_iff (2 * π)
@[simp, norm_cast]
theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by
simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n
@[simp, norm_cast]
theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by
simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n
theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by
simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
rw [Angle.coe, Angle.coe, QuotientAddGroup.eq]
simp only [AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
@[simp]
theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) :=
angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩
@[simp]
theorem neg_coe_pi : -(π : Angle) = π := by
rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub]
use -1
simp [two_mul, sub_eq_add_neg]
@[simp]
theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_nsmul, two_nsmul, add_halves]
@[simp]
theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_zsmul, two_zsmul, add_halves]
theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by
rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi]
theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by
rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two]
theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by
rw [sub_eq_add_neg, neg_coe_pi]
@[simp]
theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul]
@[simp]
theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul]
@[simp]
theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi]
theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) :=
QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz
theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) :=
QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz
theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
have : Int.natAbs 2 = 2 := rfl
rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero,
Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two,
mul_div_cancel_left₀ (_ : ℝ) two_ne_zero]
theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff]
theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
convert two_nsmul_eq_iff <;> simp
theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_nsmul_eq_zero_iff]
theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff]
theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_zsmul_eq_zero_iff]
theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by
rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff]
theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← eq_neg_self_iff.not]
theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff]
theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← neg_eq_self_iff.not]
theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves]
nth_rw 1 [h]
rw [coe_nsmul, two_nsmul_eq_iff]
-- Porting note: `congr` didn't simplify the goal of iff of `Or`s
convert Iff.rfl
rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc,
add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero]
theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff]
theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} :
cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by
constructor
· intro Hcos
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos
rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩)
· right
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul,
mul_comm, coe_two_pi, zsmul_zero]
· left
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn
rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero,
zero_add]
· rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero]
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul]
theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by
constructor
· intro Hsin
rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin
rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h
· left
rw [coe_sub, coe_sub] at h
exact sub_right_inj.1 h
right
rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add,
add_halves, sub_sub, sub_eq_zero] at h
exact h.symm
· rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul]
have H' : θ + ψ = 2 * k * π + π := by
rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←
mul_assoc] at H
rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero]
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by
rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; · exact hc
rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; · exact hs
rw [eq_neg_iff_add_eq_zero, hs] at hc
obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc)
rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero,
eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one,
← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn
have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn
rw [add_comm, Int.add_mul_emod_self_right] at this
exact absurd this one_ne_zero
/-- The sine of a `Real.Angle`. -/
def sin (θ : Angle) : ℝ :=
sin_periodic.lift θ
@[simp]
theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x :=
rfl
@[continuity]
theorem continuous_sin : Continuous sin :=
Real.continuous_sin.quotient_liftOn' _
/-- The cosine of a `Real.Angle`. -/
def cos (θ : Angle) : ℝ :=
cos_periodic.lift θ
@[simp]
theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x :=
rfl
@[continuity]
theorem continuous_cos : Continuous cos :=
Real.continuous_cos.quotient_liftOn' _
theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} :
cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction θ using Real.Angle.induction_on
exact cos_eq_iff_coe_eq_or_eq_neg
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction ψ using Real.Angle.induction_on
exact cos_eq_real_cos_iff_eq_or_eq_neg
theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} :
sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction θ using Real.Angle.induction_on
exact sin_eq_iff_coe_eq_or_add_eq_pi
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction ψ using Real.Angle.induction_on
exact sin_eq_real_sin_iff_eq_or_add_eq_pi
@[simp]
theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero]
theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi]
theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by
nth_rw 1 [← sin_zero]
rw [sin_eq_iff_eq_or_add_eq_pi]
simp
theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← sin_eq_zero_iff]
@[simp]
theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_neg _
theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.sin_antiperiodic _
@[simp]
theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ :=
sin_antiperiodic θ
@[simp]
theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ :=
sin_antiperiodic.sub_eq θ
@[simp]
theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero]
theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi]
@[simp]
theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_neg _
theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.cos_antiperiodic _
@[simp]
theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ :=
cos_antiperiodic θ
@[simp]
theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ :=
cos_antiperiodic.sub_eq θ
theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div]
theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by
induction θ₁ using Real.Angle.induction_on
induction θ₂ using Real.Angle.induction_on
exact Real.sin_add _ _
theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by
induction θ₂ using Real.Angle.induction_on
induction θ₁ using Real.Angle.induction_on
exact Real.cos_add _ _
@[simp]
theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by
induction θ using Real.Angle.induction_on
exact Real.cos_sq_add_sin_sq _
theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_add_pi_div_two _
theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_sub_pi_div_two _
theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_pi_div_two_sub _
theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_add_pi_div_two _
theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_sub_pi_div_two _
theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_pi_div_two_sub _
theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) :
|sin θ| = |sin ψ| := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· rw [sin_add_pi, abs_neg]
theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) :
|sin θ| = |sin ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_sin_eq_of_two_nsmul_eq h
theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) :
|cos θ| = |cos ψ| := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· rw [cos_add_pi, abs_neg]
theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) :
|cos θ| = |cos ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_cos_eq_of_two_nsmul_eq h
@[simp]
theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub]
refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩
rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm]
@[simp]
theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub]
refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩
rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm]
/-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/
def toReal (θ : Angle) : ℝ :=
(toIocMod_periodic two_pi_pos (-π)).lift θ
theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ :=
rfl
theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by
rw [toReal_coe, toIocMod_eq_self two_pi_pos]
ring_nf
rfl
theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by
rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc]
theorem toReal_injective : Function.Injective toReal := by
intro θ ψ h
induction θ using Real.Angle.induction_on
induction ψ using Real.Angle.induction_on
simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ←
angle_eq_iff_two_pi_dvd_sub, eq_comm] using h
@[simp]
theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ :=
toReal_injective.eq_iff
@[simp]
theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by
induction θ using Real.Angle.induction_on
exact coe_toIocMod _ _
theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by
induction θ using Real.Angle.induction_on
exact left_lt_toIocMod _ _ _
theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by
induction θ using Real.Angle.induction_on
convert toIocMod_le_right two_pi_pos _ _
ring
theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π :=
| abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩
theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π :=
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean | 469 | 471 |
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Vincent Beffara, Rida Hamadani
-/
import Mathlib.Combinatorics.SimpleGraph.Path
import Mathlib.Data.ENat.Lattice
/-!
# Graph metric
This module defines the `SimpleGraph.edist` function, which takes pairs of vertices to the length of
the shortest walk between them, or `⊤` if they are disconnected. It also defines `SimpleGraph.dist`
which is the `ℕ`-valued version of `SimpleGraph.edist`.
## Main definitions
- `SimpleGraph.edist` is the graph extended metric.
- `SimpleGraph.dist` is the graph metric.
## TODO
- Provide an additional computable version of `SimpleGraph.dist`
for when `G` is connected.
- When directed graphs exist, a directed notion of distance,
likely `ENat`-valued.
## Tags
graph metric, distance
-/
assert_not_exists Field
namespace SimpleGraph
variable {V : Type*} (G : SimpleGraph V)
/-! ## Metric -/
section edist
/--
The extended distance between two vertices is the length of the shortest walk between them.
It is `⊤` if no such walk exists.
-/
noncomputable def edist (u v : V) : ℕ∞ :=
⨅ w : G.Walk u v, w.length
variable {G} {u v w : V}
theorem edist_eq_sInf : G.edist u v = sInf (Set.range fun w : G.Walk u v ↦ (w.length : ℕ∞)) := rfl
protected theorem Reachable.exists_walk_length_eq_edist (hr : G.Reachable u v) :
∃ p : G.Walk u v, p.length = G.edist u v :=
csInf_mem <| Set.range_nonempty_iff_nonempty.mpr hr
protected theorem Connected.exists_walk_length_eq_edist (hconn : G.Connected) (u v : V) :
∃ p : G.Walk u v, p.length = G.edist u v :=
(hconn u v).exists_walk_length_eq_edist
theorem edist_le (p : G.Walk u v) :
G.edist u v ≤ p.length :=
sInf_le ⟨p, rfl⟩
protected alias Walk.edist_le := edist_le
@[simp]
theorem edist_eq_zero_iff :
G.edist u v = 0 ↔ u = v := by
apply Iff.intro <;> simp [edist, ENat.iInf_eq_zero]
@[simp]
theorem edist_self : edist G v v = 0 :=
edist_eq_zero_iff.mpr rfl
theorem edist_pos_of_ne (hne : u ≠ v) :
0 < G.edist u v :=
pos_iff_ne_zero.mpr <| edist_eq_zero_iff.ne.mpr hne
lemma edist_eq_top_of_not_reachable (h : ¬G.Reachable u v) :
G.edist u v = ⊤ := by
simp [edist, not_reachable_iff_isEmpty_walk.mp h]
theorem reachable_of_edist_ne_top (h : G.edist u v ≠ ⊤) :
G.Reachable u v :=
not_not.mp <| edist_eq_top_of_not_reachable.mt h
lemma exists_walk_of_edist_ne_top (h : G.edist u v ≠ ⊤) :
∃ p : G.Walk u v, p.length = G.edist u v :=
(reachable_of_edist_ne_top h).exists_walk_length_eq_edist
protected theorem edist_triangle : G.edist u w ≤ G.edist u v + G.edist v w := by
cases eq_or_ne (G.edist u v) ⊤ with
| inl huv => simp [huv]
| inr huv =>
cases eq_or_ne (G.edist v w) ⊤ with
| inl hvw => simp [hvw]
| inr hvw =>
obtain ⟨p, hp⟩ := exists_walk_of_edist_ne_top huv
obtain ⟨q, hq⟩ := exists_walk_of_edist_ne_top hvw
rw [← hp, ← hq, ← Nat.cast_add, ← Walk.length_append]
exact edist_le _
theorem edist_comm : G.edist u v = G.edist v u := by
rw [edist_eq_sInf, ← Set.image_univ, ← Set.image_univ_of_surjective Walk.reverse_surjective,
← Set.image_comp, Set.image_univ, Function.comp_def]
simp_rw [Walk.length_reverse, ← edist_eq_sInf]
lemma exists_walk_of_edist_eq_coe {k : ℕ} (h : G.edist u v = k) :
∃ p : G.Walk u v, p.length = k :=
have : G.edist u v ≠ ⊤ := by rw [h]; exact ENat.coe_ne_top _
have ⟨p, hp⟩ := exists_walk_of_edist_ne_top this
⟨p, Nat.cast_injective (hp.trans h)⟩
lemma edist_ne_top_iff_reachable : G.edist u v ≠ ⊤ ↔ G.Reachable u v := by
refine ⟨reachable_of_edist_ne_top, fun h ↦ ?_⟩
by_contra hx
simp only [edist, iInf_eq_top, ENat.coe_ne_top] at hx
exact h.elim hx
/--
The extended distance between vertices is equal to `1` if and only if these vertices are adjacent.
-/
@[simp]
theorem edist_eq_one_iff_adj : G.edist u v = 1 ↔ G.Adj u v := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· obtain ⟨w, hw⟩ := exists_walk_of_edist_ne_top <| by rw [h]; simp
exact w.adj_of_length_eq_one <| Nat.cast_eq_one.mp <| h ▸ hw
· exact le_antisymm (edist_le h.toWalk) (Order.one_le_iff_pos.mpr <| edist_pos_of_ne h.ne)
lemma edist_bot_of_ne (h : u ≠ v) : (⊥ : SimpleGraph V).edist u v = ⊤ := by
rwa [ne_eq, ← reachable_bot.not, ← edist_ne_top_iff_reachable.not, not_not] at h
lemma edist_bot [DecidableEq V] : (⊥ : SimpleGraph V).edist u v = (if u = v then 0 else ⊤) := by
by_cases h : u = v <;> simp [h, edist_bot_of_ne]
lemma edist_top_of_ne (h : u ≠ v) : (⊤ : SimpleGraph V).edist u v = 1 := by
simp [h]
lemma edist_top [DecidableEq V] : (⊤ : SimpleGraph V).edist u v = (if u = v then 0 else 1) := by
by_cases h : u = v <;> simp [h]
|
/-- Supergraphs have smaller or equal extended distances to their subgraphs. -/
@[gcongr]
theorem edist_anti {G' : SimpleGraph V} (h : G ≤ G') :
G'.edist u v ≤ G.edist u v := by
by_cases hr : G.Reachable u v
· obtain ⟨_, hw⟩ := hr.exists_walk_length_eq_edist
rw [← hw, ← Walk.length_map (.ofLE h)]
apply edist_le
· exact edist_eq_top_of_not_reachable hr ▸ le_top
| Mathlib/Combinatorics/SimpleGraph/Metric.lean | 144 | 153 |
/-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.Basic
import Mathlib.Data.Nat.Bits
/-! Lemmas about `size`. -/
namespace Nat
/-! ### `shiftLeft` and `shiftRight` -/
section
theorem shiftLeft_eq_mul_pow (m) : ∀ n, m <<< n = m * 2 ^ n := shiftLeft_eq _
theorem shiftLeft'_tt_eq_mul_pow (m) : ∀ n, shiftLeft' true m n + 1 = (m + 1) * 2 ^ n
| 0 => by simp [shiftLeft', pow_zero, Nat.one_mul]
| k + 1 => by
rw [shiftLeft', bit_val, Bool.toNat_true, add_assoc, ← Nat.mul_add_one,
shiftLeft'_tt_eq_mul_pow m k, mul_left_comm, mul_comm 2, pow_succ]
end
theorem shiftLeft'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftLeft' b m n ≠ 0 := by
induction n <;> simp [bit_ne_zero, shiftLeft', *]
theorem shiftLeft'_tt_ne_zero (m) : ∀ {n}, (n ≠ 0) → shiftLeft' true m n ≠ 0
| 0, h => absurd rfl h
| succ _, _ => by dsimp [shiftLeft', bit]; omega
/-! ### `size` -/
@[simp]
theorem size_zero : size 0 = 0 := by simp [size]
@[simp]
theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) := by
unfold size
conv =>
lhs
rw [binaryRec]
simp [h]
section
@[simp]
theorem size_one : size 1 = 1 :=
show size (bit true 0) = 1 by rw [size_bit, size_zero]; exact Nat.one_ne_zero
end
@[simp]
theorem size_shiftLeft' {b m n} (h : shiftLeft' b m n ≠ 0) :
size (shiftLeft' b m n) = size m + n := by
induction n with
| zero => simp [shiftLeft']
| succ n IH =>
simp only [shiftLeft', ne_eq] at h ⊢
rw [size_bit h, Nat.add_succ]
by_cases s0 : shiftLeft' b m n = 0
case neg => rw [IH s0]
rw [s0] at h ⊢
cases b; · exact absurd rfl h
have : shiftLeft' true m n + 1 = 1 := congr_arg (· + 1) s0
rw [shiftLeft'_tt_eq_mul_pow] at this
obtain rfl := succ.inj (eq_one_of_dvd_one ⟨_, this.symm⟩)
simp only [zero_add, one_mul] at this
obtain rfl : n = 0 := not_ne_iff.1 fun hn ↦ ne_of_gt (Nat.one_lt_pow hn (by decide)) this
rw [add_zero]
@[simp]
theorem size_shiftLeft {m} (h : m ≠ 0) (n) : size (m <<< n) = size m + n := by
simp only [size_shiftLeft' (shiftLeft'_ne_zero_left _ h _), ← shiftLeft'_false]
theorem lt_size_self (n : ℕ) : n < 2 ^ size n := by
rw [← one_shiftLeft]
have : ∀ {n}, n = 0 → n < 1 <<< (size n) := by simp
refine binaryRec ?_ ?_ n
· apply this rfl
intro b n IH
by_cases h : bit b n = 0
· apply this h
rw [size_bit h, shiftLeft_succ, shiftLeft_eq, one_mul]
cases b <;> dsimp [bit] <;> omega
theorem size_le {m n : ℕ} : size m ≤ n ↔ m < 2 ^ n :=
⟨fun h => lt_of_lt_of_le (lt_size_self _) (Nat.pow_le_pow_right (by decide) h), by
rw [← one_shiftLeft]
induction m using binaryRec generalizing n with
| z => simp
| f b m IH =>
intro h
by_cases e : bit b m = 0
· simp [e]
rw [size_bit e]
cases n with
| zero => exact e.elim (Nat.eq_zero_of_le_zero (le_of_lt_succ h))
| succ n =>
apply succ_le_succ (IH _)
apply Nat.lt_of_mul_lt_mul_left (a := 2)
simp only [shiftLeft_succ] at *
| refine lt_of_le_of_lt ?_ h
cases b <;> dsimp [bit] <;> omega⟩
theorem lt_size {m n : ℕ} : m < size n ↔ 2 ^ m ≤ n := by
rw [← not_lt, Decidable.iff_not_comm, not_lt, size_le]
theorem size_pos {n : ℕ} : 0 < size n ↔ 0 < n := by rw [lt_size]; rfl
theorem size_eq_zero {n : ℕ} : size n = 0 ↔ n = 0 := by
simpa [Nat.pos_iff_ne_zero, not_iff_not] using size_pos
| Mathlib/Data/Nat/Size.lean | 107 | 116 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Localization.Opposite
/-!
# Calculus of fractions
Following the definitions by [Gabriel and Zisman][gabriel-zisman-1967],
given a morphism property `W : MorphismProperty C` on a category `C`,
we introduce the class `W.HasLeftCalculusOfFractions`. The main
result `Localization.exists_leftFraction` is that if `L : C ⥤ D`
is a localization functor for `W`, then for any morphism `L.obj X ⟶ L.obj Y` in `D`,
there exists an auxiliary object `Y' : C` and morphisms `g : X ⟶ Y'` and `s : Y ⟶ Y'`,
with `W s`, such that the given morphism is a sort of fraction `g / s`,
or more precisely of the form `L.map g ≫ (Localization.isoOfHom L W s hs).inv`.
We also show that the functor `L.mapArrow : Arrow C ⥤ Arrow D` is essentially surjective.
Similar results are obtained when `W` has a right calculus of fractions.
## References
* [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967]
-/
namespace CategoryTheory
variable {C D : Type*} [Category C] [Category D]
open Category
namespace MorphismProperty
/-- A left fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the
datum of an object `Y' : C` and maps `f : X ⟶ Y'` and `s : Y ⟶ Y'` such that `W s`. -/
structure LeftFraction (W : MorphismProperty C) (X Y : C) where
/-- the auxiliary object of a left fraction -/
{Y' : C}
/-- the numerator of a left fraction -/
f : X ⟶ Y'
/-- the denominator of a left fraction -/
s : Y ⟶ Y'
/-- the condition that the denominator belongs to the given morphism property -/
hs : W s
namespace LeftFraction
variable (W : MorphismProperty C) {X Y : C}
/-- The left fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/
@[simps]
def ofHom (f : X ⟶ Y) [W.ContainsIdentities] :
W.LeftFraction X Y := mk f (𝟙 Y) (W.id_mem Y)
variable {W}
/-- The left fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/
@[simps]
def ofInv (s : Y ⟶ X) (hs : W s) :
W.LeftFraction X Y := mk (𝟙 X) s hs
/-- If `φ : W.LeftFraction X Y` and `L` is a functor which inverts `W`, this is the
induced morphism `L.obj X ⟶ L.obj Y` -/
noncomputable def map (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.obj X ⟶ L.obj Y :=
have := hL _ φ.hs
L.map φ.f ≫ inv (L.map φ.s)
@[reassoc (attr := simp)]
lemma map_comp_map_s (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
φ.map L hL ≫ L.map φ.s = L.map φ.f := by
letI := hL _ φ.hs
simp [map]
variable (W)
lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] :
(ofHom W f).map L hL = L.map f := by
simp [map]
@[reassoc (attr := simp)]
lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by
letI := hL _ hs
simp [map]
@[reassoc (attr := simp)]
lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by
letI := hL _ hs
simp [map]
variable {W}
lemma cases (α : W.LeftFraction X Y) :
∃ (Y' : C) (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s), α = LeftFraction.mk f s hs :=
⟨_, _, _, _, rfl⟩
end LeftFraction
/-- A right fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the
datum of an object `X' : C` and maps `s : X' ⟶ X` and `f : X' ⟶ Y` such that `W s`. -/
structure RightFraction (W : MorphismProperty C) (X Y : C) where
/-- the auxiliary object of a right fraction -/
{X' : C}
/-- the denominator of a right fraction -/
s : X' ⟶ X
/-- the condition that the denominator belongs to the given morphism property -/
hs : W s
/-- the numerator of a right fraction -/
f : X' ⟶ Y
namespace RightFraction
variable (W : MorphismProperty C)
variable {X Y : C}
/-- The right fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/
@[simps]
def ofHom (f : X ⟶ Y) [W.ContainsIdentities] :
W.RightFraction X Y := mk (𝟙 X) (W.id_mem X) f
variable {W}
/-- The right fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/
@[simps]
def ofInv (s : Y ⟶ X) (hs : W s) :
W.RightFraction X Y := mk s hs (𝟙 Y)
/-- If `φ : W.RightFraction X Y` and `L` is a functor which inverts `W`, this is the
induced morphism `L.obj X ⟶ L.obj Y` -/
noncomputable def map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.obj X ⟶ L.obj Y :=
have := hL _ φ.hs
inv (L.map φ.s) ≫ L.map φ.f
@[reassoc (attr := simp)]
lemma map_s_comp_map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map φ.s ≫ φ.map L hL = L.map φ.f := by
letI := hL _ φ.hs
simp [map]
variable (W)
@[simp]
lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] :
(ofHom W f).map L hL = L.map f := by
simp [map]
@[reassoc (attr := simp)]
lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by
letI := hL _ hs
simp [map]
@[reassoc (attr := simp)]
lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by
letI := hL _ hs
simp [map]
variable {W}
lemma cases (α : W.RightFraction X Y) :
∃ (X' : C) (s : X' ⟶ X) (hs : W s) (f : X' ⟶ Y) , α = RightFraction.mk s hs f :=
⟨_, _, _, _, rfl⟩
end RightFraction
variable (W : MorphismProperty C)
/-- A multiplicative morphism property `W` has left calculus of fractions if
any right fraction can be turned into a left fraction and that two morphisms
that can be equalized by precomposition with a morphism in `W` can also
be equalized by postcomposition with a morphism in `W`. -/
class HasLeftCalculusOfFractions : Prop extends W.IsMultiplicative where
exists_leftFraction ⦃X Y : C⦄ (φ : W.RightFraction X Y) :
∃ (ψ : W.LeftFraction X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f
ext : ∀ ⦃X' X Y : C⦄ (f₁ f₂ : X ⟶ Y) (s : X' ⟶ X) (_ : W s)
(_ : s ≫ f₁ = s ≫ f₂), ∃ (Y' : C) (t : Y ⟶ Y') (_ : W t), f₁ ≫ t = f₂ ≫ t
/-- A multiplicative morphism property `W` has right calculus of fractions if
any left fraction can be turned into a right fraction and that two morphisms
that can be equalized by postcomposition with a morphism in `W` can also
be equalized by precomposition with a morphism in `W`. -/
class HasRightCalculusOfFractions : Prop extends W.IsMultiplicative where
exists_rightFraction ⦃X Y : C⦄ (φ : W.LeftFraction X Y) :
∃ (ψ : W.RightFraction X Y), ψ.s ≫ φ.f = ψ.f ≫ φ.s
ext : ∀ ⦃X Y Y' : C⦄ (f₁ f₂ : X ⟶ Y) (s : Y ⟶ Y') (_ : W s)
(_ : f₁ ≫ s = f₂ ≫ s), ∃ (X' : C) (t : X' ⟶ X) (_ : W t), t ≫ f₁ = t ≫ f₂
variable {W}
lemma RightFraction.exists_leftFraction [W.HasLeftCalculusOfFractions] {X Y : C}
(φ : W.RightFraction X Y) : ∃ (ψ : W.LeftFraction X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f :=
HasLeftCalculusOfFractions.exists_leftFraction φ
/-- A choice of a left fraction deduced from a right fraction for a morphism property `W`
when `W` has left calculus of fractions. -/
noncomputable def RightFraction.leftFraction [W.HasLeftCalculusOfFractions] {X Y : C}
(φ : W.RightFraction X Y) : W.LeftFraction X Y :=
φ.exists_leftFraction.choose
@[reassoc]
lemma RightFraction.leftFraction_fac [W.HasLeftCalculusOfFractions] {X Y : C}
(φ : W.RightFraction X Y) : φ.f ≫ φ.leftFraction.s = φ.s ≫ φ.leftFraction.f :=
φ.exists_leftFraction.choose_spec
lemma LeftFraction.exists_rightFraction [W.HasRightCalculusOfFractions] {X Y : C}
(φ : W.LeftFraction X Y) : ∃ (ψ : W.RightFraction X Y), ψ.s ≫ φ.f = ψ.f ≫ φ.s :=
HasRightCalculusOfFractions.exists_rightFraction φ
/-- A choice of a right fraction deduced from a left fraction for a morphism property `W`
when `W` has right calculus of fractions. -/
noncomputable def LeftFraction.rightFraction [W.HasRightCalculusOfFractions] {X Y : C}
(φ : W.LeftFraction X Y) : W.RightFraction X Y :=
φ.exists_rightFraction.choose
@[reassoc]
lemma LeftFraction.rightFraction_fac [W.HasRightCalculusOfFractions] {X Y : C}
(φ : W.LeftFraction X Y) : φ.rightFraction.s ≫ φ.f = φ.rightFraction.f ≫ φ.s :=
φ.exists_rightFraction.choose_spec
/-- The equivalence relation on left fractions for a morphism property `W`. -/
def LeftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) : Prop :=
∃ (Z : C) (t₁ : z₁.Y' ⟶ Z) (t₂ : z₂.Y' ⟶ Z) (_ : z₁.s ≫ t₁ = z₂.s ≫ t₂)
(_ : z₁.f ≫ t₁ = z₂.f ≫ t₂), W (z₁.s ≫ t₁)
namespace LeftFractionRel
lemma refl {X Y : C} (z : W.LeftFraction X Y) : LeftFractionRel z z :=
⟨z.Y', 𝟙 _, 𝟙 _, rfl, rfl, by simpa only [Category.comp_id] using z.hs⟩
lemma symm {X Y : C} {z₁ z₂ : W.LeftFraction X Y} (h : LeftFractionRel z₁ z₂) :
LeftFractionRel z₂ z₁ := by
obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h
exact ⟨Z, t₂, t₁, hst.symm, hft.symm, by simpa only [← hst] using ht⟩
lemma trans {X Y : C} {z₁ z₂ z₃ : W.LeftFraction X Y}
[HasLeftCalculusOfFractions W]
(h₁₂ : LeftFractionRel z₁ z₂) (h₂₃ : LeftFractionRel z₂ z₃) :
LeftFractionRel z₁ z₃ := by
obtain ⟨Z₄, t₁, t₂, hst, hft, ht⟩ := h₁₂
obtain ⟨Z₅, u₂, u₃, hsu, hfu, hu⟩ := h₂₃
obtain ⟨⟨v₄, v₅, hv₅⟩, fac⟩ := HasLeftCalculusOfFractions.exists_leftFraction
(RightFraction.mk (z₁.s ≫ t₁) ht (z₃.s ≫ u₃))
simp only [Category.assoc] at fac
have eq : z₂.s ≫ u₂ ≫ v₅ = z₂.s ≫ t₂ ≫ v₄ := by
simpa only [← reassoc_of% hsu, reassoc_of% hst] using fac
obtain ⟨Z₇, w, hw, fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ z₂.hs eq
simp only [Category.assoc] at fac'
refine ⟨Z₇, t₁ ≫ v₄ ≫ w, u₃ ≫ v₅ ≫ w, ?_, ?_, ?_⟩
· rw [reassoc_of% fac]
· rw [reassoc_of% hft, ← fac', reassoc_of% hfu]
· rw [← reassoc_of% fac, ← reassoc_of% hsu, ← Category.assoc]
exact W.comp_mem _ _ hu (W.comp_mem _ _ hv₅ hw)
end LeftFractionRel
section
variable (W)
lemma equivalenceLeftFractionRel [W.HasLeftCalculusOfFractions] (X Y : C) :
@_root_.Equivalence (W.LeftFraction X Y) LeftFractionRel where
refl := LeftFractionRel.refl
symm := LeftFractionRel.symm
trans := LeftFractionRel.trans
variable {W}
namespace LeftFraction
open HasLeftCalculusOfFractions
/-- Auxiliary definition for the composition of left fractions. -/
@[simp]
def comp₀ [W.HasLeftCalculusOfFractions] {X Y Z : C}
(z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ : W.LeftFraction z₁.Y' z₂.Y') :
W.LeftFraction X Z :=
mk (z₁.f ≫ z₃.f) (z₂.s ≫ z₃.s) (W.comp_mem _ _ z₂.hs z₃.hs)
/-- The equivalence class of `z₁.comp₀ z₂ z₃` does not depend on the choice of `z₃` provided
they satisfy the compatibility `z₂.f ≫ z₃.s = z₁.s ≫ z₃.f`. -/
lemma comp₀_rel [W.HasLeftCalculusOfFractions]
{X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ z₃' : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f)
(h₃' : z₂.f ≫ z₃'.s = z₁.s ≫ z₃'.f) :
LeftFractionRel (z₁.comp₀ z₂ z₃) (z₁.comp₀ z₂ z₃') := by
obtain ⟨z₄, fac⟩ := exists_leftFraction (RightFraction.mk z₃.s z₃.hs z₃'.s)
dsimp at fac
have eq : z₁.s ≫ z₃.f ≫ z₄.f = z₁.s ≫ z₃'.f ≫ z₄.s := by
rw [← reassoc_of% h₃, ← reassoc_of% h₃', fac]
obtain ⟨Y, t, ht, fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ z₁.hs eq
simp only [assoc] at fac'
refine ⟨Y, z₄.f ≫ t, z₄.s ≫ t, ?_, ?_, ?_⟩
· simp only [comp₀, assoc, reassoc_of% fac]
· simp only [comp₀, assoc, fac']
· simp only [comp₀, assoc, ← reassoc_of% fac]
exact W.comp_mem _ _ z₂.hs (W.comp_mem _ _ z₃'.hs (W.comp_mem _ _ z₄.hs ht))
variable (W) in
/-- The morphisms in the constructed localized category for a morphism property `W`
that has left calculus of fractions are equivalence classes of left fractions. -/
def Localization.Hom (X Y : C) :=
Quot (LeftFractionRel : W.LeftFraction X Y → W.LeftFraction X Y → Prop)
/-- The morphism in the constructed localized category that is induced by a left fraction. -/
def Localization.Hom.mk {X Y : C} (z : W.LeftFraction X Y) : Localization.Hom W X Y :=
Quot.mk _ z
lemma Localization.Hom.mk_surjective {X Y : C} (f : Localization.Hom W X Y) :
∃ (z : W.LeftFraction X Y), f = mk z := by
obtain ⟨z⟩ := f
exact ⟨z, rfl⟩
variable [W.HasLeftCalculusOfFractions]
/-- Auxiliary definition towards the definition of the composition of morphisms
in the constructed localized category for a morphism property that has
left calculus of fractions. -/
noncomputable def comp
{X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) :
Localization.Hom W X Z :=
Localization.Hom.mk (z₁.comp₀ z₂ (RightFraction.mk z₁.s z₁.hs z₂.f).leftFraction)
lemma comp_eq {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) :
z₁.comp z₂ = Localization.Hom.mk (z₁.comp₀ z₂ z₃) :=
Quot.sound (LeftFraction.comp₀_rel _ _ _ _
(RightFraction.leftFraction_fac (RightFraction.mk z₁.s z₁.hs z₂.f)) h₃)
namespace Localization
/-- Composition of morphisms in the constructed localized category
for a morphism property that has left calculus of fractions. -/
noncomputable def Hom.comp {X Y Z : C} (z₁ : Hom W X Y) (z₂ : Hom W Y Z) : Hom W X Z := by
refine Quot.lift₂ (fun a b => a.comp b) ?_ ?_ z₁ z₂
· rintro a b₁ b₂ ⟨U, t₁, t₂, hst, hft, ht⟩
obtain ⟨z₁, fac₁⟩ := exists_leftFraction (RightFraction.mk a.s a.hs b₁.f)
obtain ⟨z₂, fac₂⟩ := exists_leftFraction (RightFraction.mk a.s a.hs b₂.f)
obtain ⟨w₁, fac₁'⟩ := exists_leftFraction (RightFraction.mk z₁.s z₁.hs t₁)
obtain ⟨w₂, fac₂'⟩ := exists_leftFraction (RightFraction.mk z₂.s z₂.hs t₂)
obtain ⟨u, fac₃⟩ := exists_leftFraction (RightFraction.mk w₁.s w₁.hs w₂.s)
dsimp at fac₁ fac₂ fac₁' fac₂' fac₃ ⊢
have eq : a.s ≫ z₁.f ≫ w₁.f ≫ u.f = a.s ≫ z₂.f ≫ w₂.f ≫ u.s := by
rw [← reassoc_of% fac₁, ← reassoc_of% fac₂, ← reassoc_of% fac₁', ← reassoc_of% fac₂',
reassoc_of% hft, fac₃]
obtain ⟨Z, p, hp, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a.hs eq
simp only [assoc] at fac₄
rw [comp_eq _ _ z₁ fac₁, comp_eq _ _ z₂ fac₂]
apply Quot.sound
refine ⟨Z, w₁.f ≫ u.f ≫ p, w₂.f ≫ u.s ≫ p, ?_, ?_, ?_⟩
· dsimp
simp only [assoc, ← reassoc_of% fac₁', ← reassoc_of% fac₂',
reassoc_of% hst, reassoc_of% fac₃]
· dsimp
simp only [assoc, fac₄]
· dsimp
simp only [assoc]
rw [← reassoc_of% fac₁', ← reassoc_of% fac₃, ← assoc]
exact W.comp_mem _ _ ht (W.comp_mem _ _ w₂.hs (W.comp_mem _ _ u.hs hp))
· rintro a₁ a₂ b ⟨U, t₁, t₂, hst, hft, ht⟩
obtain ⟨z₁, fac₁⟩ := exists_leftFraction (RightFraction.mk a₁.s a₁.hs b.f)
obtain ⟨z₂, fac₂⟩ := exists_leftFraction (RightFraction.mk a₂.s a₂.hs b.f)
obtain ⟨w₁, fac₁'⟩ := exists_leftFraction (RightFraction.mk (a₁.s ≫ t₁) ht (b.f ≫ z₁.s))
obtain ⟨w₂, fac₂'⟩ := exists_leftFraction (RightFraction.mk (a₂.s ≫ t₂)
(show W _ by rw [← hst]; exact ht) (b.f ≫ z₂.s))
let p₁ : W.LeftFraction X Z := LeftFraction.mk (a₁.f ≫ t₁ ≫ w₁.f) (b.s ≫ z₁.s ≫ w₁.s)
(W.comp_mem _ _ b.hs (W.comp_mem _ _ z₁.hs w₁.hs))
let p₂ : W.LeftFraction X Z := LeftFraction.mk (a₂.f ≫ t₂ ≫ w₂.f) (b.s ≫ z₂.s ≫ w₂.s)
(W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs w₂.hs))
dsimp at fac₁ fac₂ fac₁' fac₂' ⊢
simp only [assoc] at fac₁' fac₂'
rw [comp_eq _ _ z₁ fac₁, comp_eq _ _ z₂ fac₂]
apply Quot.sound
refine LeftFractionRel.trans ?_ ((?_ : LeftFractionRel p₁ p₂).trans ?_)
· have eq : a₁.s ≫ z₁.f ≫ w₁.s = a₁.s ≫ t₁ ≫ w₁.f := by rw [← fac₁', reassoc_of% fac₁]
obtain ⟨Z, u, hu, fac₃⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₁.hs eq
simp only [assoc] at fac₃
refine ⟨Z, w₁.s ≫ u, u, ?_, ?_, ?_⟩
· dsimp [p₁]
simp only [assoc]
· dsimp [p₁]
simp only [assoc, fac₃]
· dsimp
simp only [assoc]
exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₁.hs (W.comp_mem _ _ w₁.hs hu))
· obtain ⟨q, fac₃⟩ := exists_leftFraction (RightFraction.mk (z₁.s ≫ w₁.s)
(W.comp_mem _ _ z₁.hs w₁.hs) (z₂.s ≫ w₂.s))
dsimp at fac₃
simp only [assoc] at fac₃
have eq : a₁.s ≫ t₁ ≫ w₁.f ≫ q.f = a₁.s ≫ t₁ ≫ w₂.f ≫ q.s := by
rw [← reassoc_of% fac₁', ← fac₃, reassoc_of% hst, reassoc_of% fac₂']
obtain ⟨Z, u, hu, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₁.hs eq
simp only [assoc] at fac₄
refine ⟨Z, q.f ≫ u, q.s ≫ u, ?_, ?_, ?_⟩
· simp only [p₁, p₂, assoc, reassoc_of% fac₃]
· rw [assoc, assoc, assoc, assoc, fac₄, reassoc_of% hft]
· simp only [p₁, p₂, assoc, ← reassoc_of% fac₃]
exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs
(W.comp_mem _ _ w₂.hs (W.comp_mem _ _ q.hs hu)))
· have eq : a₂.s ≫ z₂.f ≫ w₂.s = a₂.s ≫ t₂ ≫ w₂.f := by
rw [← fac₂', reassoc_of% fac₂]
obtain ⟨Z, u, hu, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₂.hs eq
simp only [assoc] at fac₄
refine ⟨Z, u, w₂.s ≫ u, ?_, ?_, ?_⟩
· dsimp [p₁, p₂]
simp only [assoc]
· dsimp [p₁, p₂]
simp only [assoc, fac₄]
· dsimp [p₁, p₂]
simp only [assoc]
exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs (W.comp_mem _ _ w₂.hs hu))
lemma Hom.comp_eq {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) :
Hom.comp (mk z₁) (mk z₂) = z₁.comp z₂ := rfl
end Localization
/-- The constructed localized category for a morphism property
that has left calculus of fractions. -/
@[nolint unusedArguments]
def Localization (_ : MorphismProperty C) := C
namespace Localization
noncomputable instance : Category (Localization W) where
Hom X Y := Localization.Hom W X Y
id _ := Localization.Hom.mk (ofHom W (𝟙 _))
comp f g := f.comp g
comp_id := by
rintro (X Y : C) f
obtain ⟨z, rfl⟩ := Hom.mk_surjective f
change (Hom.mk z).comp (Hom.mk (ofHom W (𝟙 Y))) = Hom.mk z
rw [Hom.comp_eq, comp_eq z (ofHom W (𝟙 Y)) (ofInv z.s z.hs) (by simp)]
dsimp [comp₀]
simp only [comp_id, id_comp]
id_comp := by
rintro (X Y : C) f
obtain ⟨z, rfl⟩ := Hom.mk_surjective f
change (Hom.mk (ofHom W (𝟙 X))).comp (Hom.mk z) = Hom.mk z
rw [Hom.comp_eq, comp_eq (ofHom W (𝟙 X)) z (ofHom W z.f) (by simp)]
dsimp
simp only [comp₀, id_comp, comp_id]
assoc := by
rintro (X₁ X₂ X₃ X₄ : C) f₁ f₂ f₃
obtain ⟨z₁, rfl⟩ := Hom.mk_surjective f₁
obtain ⟨z₂, rfl⟩ := Hom.mk_surjective f₂
obtain ⟨z₃, rfl⟩ := Hom.mk_surjective f₃
change ((Hom.mk z₁).comp (Hom.mk z₂)).comp (Hom.mk z₃) =
(Hom.mk z₁).comp ((Hom.mk z₂).comp (Hom.mk z₃))
rw [Hom.comp_eq z₁ z₂, Hom.comp_eq z₂ z₃]
obtain ⟨z₁₂, fac₁₂⟩ := exists_leftFraction (RightFraction.mk z₁.s z₁.hs z₂.f)
obtain ⟨z₂₃, fac₂₃⟩ := exists_leftFraction (RightFraction.mk z₂.s z₂.hs z₃.f)
obtain ⟨z', fac⟩ := exists_leftFraction (RightFraction.mk z₁₂.s z₁₂.hs z₂₃.f)
dsimp at fac₁₂ fac₂₃ fac
rw [comp_eq z₁ z₂ z₁₂ fac₁₂, comp_eq z₂ z₃ z₂₃ fac₂₃, comp₀, comp₀,
Hom.comp_eq, Hom.comp_eq,
comp_eq _ z₃ (mk z'.f (z₂₃.s ≫ z'.s) (W.comp_mem _ _ z₂₃.hs z'.hs))
(by dsimp; rw [assoc, reassoc_of% fac₂₃, fac]),
comp_eq z₁ _ (mk (z₁₂.f ≫ z'.f) z'.s z'.hs)
(by dsimp; rw [assoc, ← reassoc_of% fac₁₂, fac])]
simp
variable (W) in
/-- The localization functor to the constructed localized category for a morphism property
that has left calculus of fractions. -/
@[simps obj]
def Q : C ⥤ Localization W where
obj X := X
map f := Hom.mk (ofHom W f)
map_id _ := rfl
map_comp {X Y Z} f g := by
change _ = Hom.comp _ _
rw [Hom.comp_eq, comp_eq (ofHom W f) (ofHom W g) (ofHom W g) (by simp)]
simp only [ofHom, comp₀, comp_id]
/-- The morphism on `Localization W` that is induced by a left fraction. -/
abbrev homMk {X Y : C} (f : W.LeftFraction X Y) : (Q W).obj X ⟶ (Q W).obj Y := Hom.mk f
lemma homMk_eq_hom_mk {X Y : C} (f : W.LeftFraction X Y) : homMk f = Hom.mk f := rfl
variable (W)
lemma Q_map {X Y : C} (f : X ⟶ Y) : (Q W).map f = homMk (ofHom W f) := rfl
variable {W}
lemma homMk_comp_homMk {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) :
homMk z₁ ≫ homMk z₂ = homMk (z₁.comp₀ z₂ z₃) := by
change Hom.comp _ _ = _
rw [Hom.comp_eq, comp_eq z₁ z₂ z₃ h₃]
lemma homMk_eq_of_leftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y)
(h : LeftFractionRel z₁ z₂) :
homMk z₁ = homMk z₂ :=
Quot.sound h
lemma homMk_eq_iff_leftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) :
homMk z₁ = homMk z₂ ↔ LeftFractionRel z₁ z₂ :=
@Equivalence.quot_mk_eq_iff _ _ (equivalenceLeftFractionRel W X Y) _ _
/-- The morphism in `Localization W` that is the formal inverse of a morphism
which belongs to `W`. -/
def Qinv {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).obj Y ⟶ (Q W).obj X := homMk (ofInv s hs)
lemma Q_map_comp_Qinv {X Y Y' : C} (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s) :
(Q W).map f ≫ Qinv s hs = homMk (mk f s hs) := by
dsimp only [Q_map, Qinv]
rw [homMk_comp_homMk (ofHom W f) (ofInv s hs) (ofHom W (𝟙 _)) (by simp)]
simp
/-- The isomorphism in `Localization W` that is induced by a morphism in `W`. -/
@[simps]
def Qiso {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).obj X ≅ (Q W).obj Y where
hom := (Q W).map s
inv := Qinv s hs
hom_inv_id := by
rw [Q_map_comp_Qinv]
apply homMk_eq_of_leftFractionRel
exact ⟨_, 𝟙 Y, s, by simp, by simp, by simpa using hs⟩
inv_hom_id := by
dsimp only [Qinv, Q_map]
rw [homMk_comp_homMk (ofInv s hs) (ofHom W s) (ofHom W (𝟙 Y)) (by simp)]
apply homMk_eq_of_leftFractionRel
exact ⟨_, 𝟙 Y, 𝟙 Y, by simp, by simp, by simpa using W.id_mem Y⟩
@[reassoc (attr := simp)]
lemma Qiso_hom_inv_id {X Y : C} (s : X ⟶ Y) (hs : W s) :
(Q W).map s ≫ Qinv s hs = 𝟙 _ := (Qiso s hs).hom_inv_id
@[reassoc (attr := simp)]
lemma Qiso_inv_hom_id {X Y : C} (s : X ⟶ Y) (hs : W s) :
Qinv s hs ≫ (Q W).map s = 𝟙 _ := (Qiso s hs).inv_hom_id
instance {X Y : C} (s : X ⟶ Y) (hs : W s) : IsIso (Qinv s hs) :=
(inferInstance : IsIso (Qiso s hs).inv)
section
variable {E : Type*} [Category E]
/-- The image by a functor which inverts `W` of an equivalence class of left fractions. -/
noncomputable def Hom.map {X Y : C} (f : Hom W X Y) (F : C ⥤ E) (hF : W.IsInvertedBy F) :
F.obj X ⟶ F.obj Y :=
Quot.lift (fun f => f.map F hF) (by
intro a₁ a₂ ⟨Z, t₁, t₂, hst, hft, h⟩
dsimp
have := hF _ h
rw [← cancel_mono (F.map (a₁.s ≫ t₁)), F.map_comp, map_comp_map_s_assoc,
← F.map_comp, ← F.map_comp, hst, hft, F.map_comp,
F.map_comp, map_comp_map_s_assoc]) f
@[simp]
lemma Hom.map_mk {W} {X Y : C} (f : LeftFraction W X Y)
(F : C ⥤ E) (hF : W.IsInvertedBy F) :
Hom.map (Hom.mk f) F hF = f.map F hF := rfl
namespace StrictUniversalPropertyFixedTarget
variable (W)
lemma inverts : W.IsInvertedBy (Q W) := fun _ _ s hs =>
(inferInstance : IsIso (Qiso s hs).hom)
variable {W}
/-- The functor `Localization W ⥤ E` that is induced by a functor `C ⥤ E` which inverts `W`,
when `W` has a left calculus of fractions. -/
noncomputable def lift (F : C ⥤ E) (hF : W.IsInvertedBy F) :
Localization W ⥤ E where
obj X := F.obj X
map {_ _ : C} f := f.map F hF
map_id := by
intro (X : C)
change (Hom.mk (ofHom W (𝟙 X))).map F hF = _
rw [Hom.map_mk, map_ofHom, F.map_id]
map_comp := by
rintro (X Y Z : C) f g
obtain ⟨f, rfl⟩ := Hom.mk_surjective f
obtain ⟨g, rfl⟩ := Hom.mk_surjective g
dsimp
obtain ⟨z, fac⟩ := HasLeftCalculusOfFractions.exists_leftFraction
(RightFraction.mk f.s f.hs g.f)
rw [homMk_comp_homMk f g z fac, Hom.map_mk]
dsimp at fac ⊢
have := hF _ g.hs
have := hF _ z.hs
rw [← cancel_mono (F.map g.s), assoc, map_comp_map_s,
← cancel_mono (F.map z.s), assoc, assoc, ← F.map_comp,
← F.map_comp, map_comp_map_s, fac]
dsimp
rw [F.map_comp, F.map_comp, map_comp_map_s_assoc]
lemma fac (F : C ⥤ E) (hF : W.IsInvertedBy F) : Q W ⋙ lift F hF = F :=
Functor.ext (fun _ => rfl) (fun X Y f => by
dsimp [lift]
rw [Q_map, Hom.map_mk, id_comp, comp_id, map_ofHom])
lemma uniq (F₁ F₂ : Localization W ⥤ E) (h : Q W ⋙ F₁ = Q W ⋙ F₂) : F₁ = F₂ :=
Functor.ext (fun X => Functor.congr_obj h X) (by
rintro (X Y : C) f
obtain ⟨f, rfl⟩ := Hom.mk_surjective f
rw [show Hom.mk f = homMk (mk f.f f.s f.hs) by rfl,
← Q_map_comp_Qinv f.f f.s f.hs, F₁.map_comp, F₂.map_comp, assoc]
erw [Functor.congr_hom h f.f]
rw [assoc, assoc]
congr 2
have := inverts W _ f.hs
rw [← cancel_epi (F₂.map ((Q W).map f.s)), ← F₂.map_comp_assoc,
Qiso_hom_inv_id, Functor.map_id, id_comp]
erw [Functor.congr_hom h.symm f.s]
dsimp
rw [assoc, assoc, eqToHom_trans_assoc, eqToHom_refl, id_comp, ← F₁.map_comp,
Qiso_hom_inv_id]
dsimp
rw [F₁.map_id, comp_id])
end StrictUniversalPropertyFixedTarget
variable (W)
open StrictUniversalPropertyFixedTarget in
/-- The universal property of the localization for the constructed localized category
when there is a left calculus of fractions. -/
noncomputable def strictUniversalPropertyFixedTarget (E : Type*) [Category E] :
Localization.StrictUniversalPropertyFixedTarget (Q W) W E where
inverts := inverts W
lift := lift
fac := fac
uniq := uniq
instance : (Q W).IsLocalization W :=
Functor.IsLocalization.mk' _ _
(strictUniversalPropertyFixedTarget W _)
(strictUniversalPropertyFixedTarget W _)
end
lemma homMk_eq {X Y : C} (f : LeftFraction W X Y) :
homMk f = f.map (Q W) (Localization.inverts _ W) := by
have := Localization.inverts (Q W) W f.s f.hs
rw [← Q_map_comp_Qinv f.f f.s f.hs, ← cancel_mono ((Q W).map f.s),
assoc, Qiso_inv_hom_id, comp_id, map_comp_map_s]
lemma map_eq_iff {X Y : C} (f g : LeftFraction W X Y) :
f.map (LeftFraction.Localization.Q W) (Localization.inverts _ _) =
g.map (LeftFraction.Localization.Q W) (Localization.inverts _ _) ↔
LeftFractionRel f g := by
simp only [← Hom.map_mk _ (Q W)]
constructor
· intro h
rw [← homMk_eq_iff_leftFractionRel, homMk_eq, homMk_eq]
exact h
· intro h
congr 1
exact Quot.sound h
end Localization
section
lemma map_eq {W} {X Y : C} (φ : W.LeftFraction X Y) (L : C ⥤ D) [L.IsLocalization W] :
φ.map L (Localization.inverts L W) =
L.map φ.f ≫ (Localization.isoOfHom L W φ.s φ.hs).inv := rfl
lemma map_compatibility {W} {X Y : C}
(φ : W.LeftFraction X Y) {E : Type*} [Category E]
(L₁ : C ⥤ D) (L₂ : C ⥤ E) [L₁.IsLocalization W] [L₂.IsLocalization W] :
(Localization.uniq L₁ L₂ W).functor.map (φ.map L₁ (Localization.inverts L₁ W)) =
(Localization.compUniqFunctor L₁ L₂ W).hom.app X ≫
φ.map L₂ (Localization.inverts L₂ W) ≫
(Localization.compUniqFunctor L₁ L₂ W).inv.app Y := by
let e := Localization.compUniqFunctor L₁ L₂ W
have := Localization.inverts L₂ W φ.s φ.hs
rw [← cancel_mono (e.hom.app Y), assoc, assoc, e.inv_hom_id_app, comp_id,
← cancel_mono (L₂.map φ.s), assoc, assoc, map_comp_map_s, ← e.hom.naturality]
simpa [← Functor.map_comp_assoc, map_comp_map_s] using e.hom.naturality φ.f
lemma map_eq_of_map_eq {W} {X Y : C}
(φ₁ φ₂ : W.LeftFraction X Y) {E : Type*} [Category E]
(L₁ : C ⥤ D) (L₂ : C ⥤ E) [L₁.IsLocalization W] [L₂.IsLocalization W]
(h : φ₁.map L₁ (Localization.inverts L₁ W) = φ₂.map L₁ (Localization.inverts L₁ W)) :
φ₁.map L₂ (Localization.inverts L₂ W) = φ₂.map L₂ (Localization.inverts L₂ W) := by
apply (Localization.uniq L₂ L₁ W).functor.map_injective
rw [map_compatibility φ₁ L₂ L₁, map_compatibility φ₂ L₂ L₁, h]
lemma map_comp_map_eq_map {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f)
(L : C ⥤ D) [L.IsLocalization W] :
z₁.map L (Localization.inverts L W) ≫ z₂.map L (Localization.inverts L W) =
(z₁.comp₀ z₂ z₃).map L (Localization.inverts L W) := by
have := Localization.inverts L W _ z₂.hs
have := Localization.inverts L W _ z₃.hs
have : IsIso (L.map (z₂.s ≫ z₃.s)) := by
rw [L.map_comp]
infer_instance
dsimp [LeftFraction.comp₀]
rw [← cancel_mono (L.map (z₂.s ≫ z₃.s)), map_comp_map_s,
L.map_comp, assoc, map_comp_map_s_assoc, ← L.map_comp, h₃,
L.map_comp, map_comp_map_s_assoc, L.map_comp]
end
end LeftFraction
end
end MorphismProperty
variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W]
section
variable [W.HasLeftCalculusOfFractions]
lemma Localization.exists_leftFraction {X Y : C} (f : L.obj X ⟶ L.obj Y) :
∃ (φ : W.LeftFraction X Y), f = φ.map L (Localization.inverts L W) := by
let E := Localization.uniq (MorphismProperty.LeftFraction.Localization.Q W) L W
let e : _ ⋙ E.functor ≅ L := Localization.compUniqFunctor _ _ _
obtain ⟨f', rfl⟩ : ∃ (f' : E.functor.obj X ⟶ E.functor.obj Y),
f = e.inv.app _ ≫ f' ≫ e.hom.app _ := ⟨e.hom.app _ ≫ f ≫ e.inv.app _, by simp⟩
obtain ⟨g, rfl⟩ := E.functor.map_surjective f'
obtain ⟨g, rfl⟩ := MorphismProperty.LeftFraction.Localization.Hom.mk_surjective g
refine ⟨g, ?_⟩
rw [← MorphismProperty.LeftFraction.Localization.homMk_eq_hom_mk,
MorphismProperty.LeftFraction.Localization.homMk_eq g,
g.map_compatibility (MorphismProperty.LeftFraction.Localization.Q W) L,
assoc, assoc, Iso.inv_hom_id_app, comp_id, Iso.inv_hom_id_app_assoc]
lemma MorphismProperty.LeftFraction.map_eq_iff
{X Y : C} (φ ψ : W.LeftFraction X Y) :
φ.map L (Localization.inverts _ _) = ψ.map L (Localization.inverts _ _) ↔
LeftFractionRel φ ψ := by
constructor
· intro h
rw [← MorphismProperty.LeftFraction.Localization.map_eq_iff]
apply map_eq_of_map_eq _ _ _ _ h
· intro h
simp only [← Localization.Hom.map_mk _ L (Localization.inverts _ _)]
congr 1
exact Quot.sound h
lemma MorphismProperty.map_eq_iff_postcomp {X Y : C} (f₁ f₂ : X ⟶ Y) :
L.map f₁ = L.map f₂ ↔ ∃ (Z : C) (s : Y ⟶ Z) (_ : W s), f₁ ≫ s = f₂ ≫ s := by
constructor
· intro h
rw [← LeftFraction.map_ofHom W _ L (Localization.inverts _ _),
← LeftFraction.map_ofHom W _ L (Localization.inverts _ _),
LeftFraction.map_eq_iff] at h
obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h
dsimp at t₁ t₂ hst hft ht
simp only [id_comp] at hst
exact ⟨Z, t₁, by simpa using ht, by rw [hft, hst]⟩
· rintro ⟨Z, s, hs, fac⟩
simp only [← cancel_mono (Localization.isoOfHom L W s hs).hom,
Localization.isoOfHom_hom, ← L.map_comp, fac]
include W in
lemma Localization.essSurj_mapArrow :
L.mapArrow.EssSurj where
mem_essImage f := by
have := Localization.essSurj L W
obtain ⟨X, ⟨eX⟩⟩ : ∃ (X : C), Nonempty (L.obj X ≅ f.left) :=
⟨_, ⟨L.objObjPreimageIso f.left⟩⟩
obtain ⟨Y, ⟨eY⟩⟩ : ∃ (Y : C), Nonempty (L.obj Y ≅ f.right) :=
⟨_, ⟨L.objObjPreimageIso f.right⟩⟩
obtain ⟨φ, hφ⟩ := Localization.exists_leftFraction L W (eX.hom ≫ f.hom ≫ eY.inv)
refine ⟨Arrow.mk φ.f, ⟨Iso.symm ?_⟩⟩
refine Arrow.isoMk eX.symm (eY.symm ≪≫ Localization.isoOfHom L W φ.s φ.hs) ?_
dsimp
simp only [← cancel_epi eX.hom, Iso.hom_inv_id_assoc, reassoc_of% hφ,
MorphismProperty.LeftFraction.map_comp_map_s]
end
namespace MorphismProperty
variable {W}
/-- The right fraction in the opposite category corresponding to a left fraction. -/
@[simps]
def LeftFraction.op {X Y : C} (φ : W.LeftFraction X Y) :
W.op.RightFraction (Opposite.op Y) (Opposite.op X) where
X' := Opposite.op φ.Y'
s := φ.s.op
hs := φ.hs
f := φ.f.op
/-- The left fraction in the opposite category corresponding to a right fraction. -/
@[simps]
def RightFraction.op {X Y : C} (φ : W.RightFraction X Y) :
W.op.LeftFraction (Opposite.op Y) (Opposite.op X) where
Y' := Opposite.op φ.X'
s := φ.s.op
hs := φ.hs
f := φ.f.op
/-- The right fraction corresponding to a left fraction in the opposite category. -/
@[simps]
def LeftFraction.unop {W : MorphismProperty Cᵒᵖ}
{X Y : Cᵒᵖ} (φ : W.LeftFraction X Y) :
W.unop.RightFraction (Opposite.unop Y) (Opposite.unop X) where
X' := Opposite.unop φ.Y'
s := φ.s.unop
hs := φ.hs
f := φ.f.unop
/-- The left fraction corresponding to a right fraction in the opposite category. -/
@[simps]
def RightFraction.unop {W : MorphismProperty Cᵒᵖ}
{X Y : Cᵒᵖ} (φ : W.RightFraction X Y) :
W.unop.LeftFraction (Opposite.unop Y) (Opposite.unop X) where
Y' := Opposite.unop φ.X'
s := φ.s.unop
hs := φ.hs
f := φ.f.unop
lemma RightFraction.op_map
{X Y : C} (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
| (φ.map L hL).op = φ.op.map L.op hL.op := by
dsimp [map, LeftFraction.map]
rw [op_inv]
lemma LeftFraction.op_map
| Mathlib/CategoryTheory/Localization/CalculusOfFractions.lean | 827 | 831 |
/-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Yuyang Zhao
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Comp
import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars
/-!
# One-dimensional derivatives of compositions of functions
In this file we prove the chain rule for the following cases:
* `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`;
* `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`;
* `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`;
Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra
over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`).
We also give versions with the `of_eq` suffix, which require an equality proof instead
of definitional equality of the different points used in the composition. These versions are
often more flexible to use.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, chain rule
-/
universe u v w
open scoped Topology Filter ENNReal
open Filter Asymptotics Set
open ContinuousLinearMap (smulRight smulRight_one_eq_iff)
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {f : 𝕜 → F}
variable {f' : F}
variable {x : 𝕜}
variable {s : Set 𝕜}
variable {L : Filter 𝕜}
section Composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F]
[IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'}
{g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x)
theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter
theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L')
(hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
rw [hy] at hg; exact hg.scomp x hh hL
theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x))
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩
theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y)
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs
nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp x hh hst
/-- The chain rule. -/
nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh hh.continuousAt
/-- The chain rule. -/
theorem HasDerivAt.scomp_of_eq
(hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt
theorem HasStrictDerivAt.scomp_of_eq
(hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _)
theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh
theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x))
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y)
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t')
(hy : y = h x) :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
rw [hy] at hg; exact derivWithin.scomp x hg hh hs
theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) :=
(HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv
theorem deriv.scomp_of_eq
(hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by
rw [hy] at hg; exact deriv.scomp x hg hh
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
convert (hh₂.restrictScalars 𝕜).comp x hf hL
ext x
simp [mul_comm]
theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq
{f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL
theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [HasStrictDerivAt] at hh
convert (hh.restrictScalars 𝕜).comp x hf
ext x
simp [mul_comm]
theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousAt
theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) :
HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt
theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf
theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t)
(hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst
/-! ### Derivative of the composition of two scalar functions -/
theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [mul_comm]
exact hh₂.scomp x hh hL
| theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [hy] at hh₂; exact hh₂.comp x hh hL
| Mathlib/Analysis/Calculus/Deriv/Comp.lean | 217 | 221 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Subalgebra
import Mathlib.LinearAlgebra.Finsupp.Span
/-!
# Lie submodules of a Lie algebra
In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we
use it to define various important operations, notably the Lie span of a subset of a Lie module.
## Main definitions
* `LieSubmodule`
* `LieSubmodule.wellFounded_of_noetherian`
* `LieSubmodule.lieSpan`
* `LieSubmodule.map`
* `LieSubmodule.comap`
## Tags
lie algebra, lie submodule, lie ideal, lattice structure
-/
universe u v w w₁ w₂
section LieSubmodule
variable (R : Type u) (L : Type v) (M : Type w)
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
/-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie module. -/
structure LieSubmodule extends Submodule R M where
lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier
attribute [nolint docBlame] LieSubmodule.toSubmodule
attribute [coe] LieSubmodule.toSubmodule
namespace LieSubmodule
variable {R L M}
variable (N N' : LieSubmodule R L M)
instance : SetLike (LieSubmodule R L M) M where
coe s := s.carrier
coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h
instance : AddSubgroupClass (LieSubmodule R L M) M where
add_mem {N} _ _ := N.add_mem'
zero_mem N := N.zero_mem'
neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx
instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where
smul_mem {s} c _ h := s.smul_mem' c h
/-- The zero module is a Lie submodule of any Lie module. -/
instance : Zero (LieSubmodule R L M) :=
⟨{ (0 : Submodule R M) with
lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩
instance : Inhabited (LieSubmodule R L M) :=
⟨0⟩
instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where
coe N := { x : M // x ∈ N }
instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) :=
⟨toSubmodule⟩
instance : CanLift (Submodule R M) (LieSubmodule R L M) (·)
(fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where
prf N hN := ⟨⟨N, hN⟩, rfl⟩
@[norm_cast]
theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N :=
rfl
theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) :=
Iff.rfl
theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} :
x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} :
x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p :=
Iff.rfl
@[simp]
theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N :=
Iff.rfl
@[deprecated (since := "2024-12-30")] alias mem_coeSubmodule := mem_toSubmodule
theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N :=
Iff.rfl
@[simp]
protected theorem zero_mem : (0 : M) ∈ N :=
zero_mem N
@[simp]
theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 :=
Subtype.ext_iff_val
@[simp]
theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) :
((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S :=
rfl
theorem toSubmodule_mk (p : Submodule R M) (h) :
(({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl
@[deprecated (since := "2024-12-30")] alias coe_toSubmodule_mk := toSubmodule_mk
theorem toSubmodule_injective :
Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by
cases x; cases y; congr
@[deprecated (since := "2024-12-30")] alias coeSubmodule_injective := toSubmodule_injective
@[ext]
theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' :=
SetLike.ext h
@[simp]
theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' :=
toSubmodule_injective.eq_iff
@[deprecated (since := "2024-12-30")] alias coe_toSubmodule_inj := toSubmodule_inj
@[deprecated (since := "2024-12-29")] alias toSubmodule_eq_iff := toSubmodule_inj
/-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where
carrier := s
zero_mem' := by simp [hs]
add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y
smul_mem' := by exact hs.symm ▸ N.smul_mem'
lie_mem := by exact hs.symm ▸ N.lie_mem
@[simp]
theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s :=
rfl
theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
instance : LieRingModule L N where
bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩
add_lie := by intro x y m; apply SetCoe.ext; apply add_lie
lie_add := by intro x m n; apply SetCoe.ext; apply lie_add
leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie
@[simp, norm_cast]
theorem coe_zero : ((0 : N) : M) = (0 : M) :=
rfl
@[simp, norm_cast]
theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) :=
rfl
@[simp, norm_cast]
theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) :=
rfl
@[simp, norm_cast]
theorem coe_bracket (x : L) (m : N) :
(↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ :=
rfl
-- Copying instances from `Submodule` for correct discrimination keys
instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N :=
inferInstanceAs <| IsNoetherian R N.toSubmodule
instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N :=
inferInstanceAs <| IsArtinian R N.toSubmodule
instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N :=
inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule
variable [LieAlgebra R L] [LieModule R L M]
instance instLieModule : LieModule R L N where
lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul
smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie
instance [Subsingleton M] : Unique (LieSubmodule R L M) :=
⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩
end LieSubmodule
variable {R M}
theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) :
(∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by
constructor
· rintro ⟨N, rfl⟩ _ _; exact N.lie_mem
· intro h; use { p with lie_mem := @h }
namespace LieSubalgebra
variable {L}
variable [LieAlgebra R L]
variable (K : LieSubalgebra R L)
/-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains
a distinguished Lie submodule for the action of `K`, namely `K` itself. -/
def toLieSubmodule : LieSubmodule R K L :=
{ (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy }
@[simp]
theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl
variable {K}
@[simp]
theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K :=
Iff.rfl
end LieSubalgebra
end LieSubmodule
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w}
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
variable (N N' : LieSubmodule R L M)
section LatticeStructure
open Set
theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) :=
SetLike.coe_injective
@[simp, norm_cast]
theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' :=
Iff.rfl
@[deprecated (since := "2024-12-30")]
alias coeSubmodule_le_coeSubmodule := toSubmodule_le_toSubmodule
instance : Bot (LieSubmodule R L M) :=
⟨0⟩
instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) :=
inferInstanceAs <| Unique (⊥ : Submodule R M)
@[simp]
theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} :=
rfl
@[simp]
theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ :=
rfl
@[deprecated (since := "2024-12-30")] alias bot_coeSubmodule := bot_toSubmodule
@[simp]
theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_bot_iff := toSubmodule_eq_bot
@[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[simp]
theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 :=
mem_singleton_iff
instance : Top (LieSubmodule R L M) :=
⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩
@[simp]
theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ :=
rfl
@[simp]
theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ :=
rfl
@[deprecated (since := "2024-12-30")] alias top_coeSubmodule := top_toSubmodule
@[simp]
theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_top_iff := toSubmodule_eq_top
@[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) :=
mem_univ x
instance : Min (LieSubmodule R L M) :=
⟨fun N N' ↦
{ (N ⊓ N' : Submodule R M) with
lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩
instance : InfSet (LieSubmodule R L M) :=
⟨fun S ↦
{ toSubmodule := sInf {(s : Submodule R M) | s ∈ S}
lie_mem := fun {x m} h ↦ by
simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq,
forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢
intro N hN; apply N.lie_mem (h N hN) }⟩
@[simp]
theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' :=
rfl
@[norm_cast, simp]
theorem inf_toSubmodule :
(↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) :=
rfl
@[deprecated (since := "2024-12-30")] alias inf_coe_toSubmodule := inf_toSubmodule
@[simp]
theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} :=
rfl
@[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule := sInf_toSubmodule
theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by
rw [sInf_toSubmodule, ← Set.image, sInf_image]
@[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule' := sInf_toSubmodule_eq_iInf
@[simp]
theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by
rw [iInf, sInf_toSubmodule]; ext; simp
@[deprecated (since := "2024-12-30")] alias iInf_coe_toSubmodule := iInf_toSubmodule
@[simp]
theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by
rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe]
ext m
simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp,
and_imp, SetLike.mem_coe, mem_toSubmodule]
@[simp]
theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by
rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq']
@[simp]
theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by
rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl
instance : Max (LieSubmodule R L M) where
max N N' :=
{ toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M)
lie_mem := by
rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M))
change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)
rw [Submodule.mem_sup] at hm ⊢
obtain ⟨y, hy, z, hz, rfl⟩ := hm
exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ }
instance : SupSet (LieSubmodule R L M) where
sSup S :=
{ toSubmodule := sSup {(p : Submodule R M) | p ∈ S}
lie_mem := by
intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S})
change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S}
obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm
clear hm
classical
induction s using Finset.induction_on generalizing m with
| empty =>
replace hsm : m = 0 := by simpa using hsm
simp [hsm]
| insert q t hqt ih =>
rw [Finset.iSup_insert] at hsm
obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm
rw [lie_add]
refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu)
obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t)
suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm')
exact le_sSup ⟨p, hp, rfl⟩ }
@[norm_cast, simp]
theorem sup_toSubmodule :
(↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by
rfl
@[deprecated (since := "2024-12-30")] alias sup_coe_toSubmodule := sup_toSubmodule
@[simp]
theorem sSup_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} :=
rfl
@[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule := sSup_toSubmodule
theorem sSup_toSubmodule_eq_iSup (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by
rw [sSup_toSubmodule, ← Set.image, sSup_image]
@[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule' := sSup_toSubmodule_eq_iSup
@[simp]
theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by
rw [iSup, sSup_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup]
@[deprecated (since := "2024-12-30")] alias iSup_coe_toSubmodule := iSup_toSubmodule
/-- The set of Lie submodules of a Lie module form a complete lattice. -/
instance : CompleteLattice (LieSubmodule R L M) :=
{ toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule
sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with
toPartialOrder := SetLike.instPartialOrder }
theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) :
b ∈ ⨆ i, N i :=
(le_iSup N i) h
@[elab_as_elim]
lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {motive : M → Prop} {x : M}
(hx : x ∈ ⨆ i, N i) (mem : ∀ i, ∀ y ∈ N i, motive y) (zero : motive 0)
(add : ∀ y z, motive y → motive z → motive (y + z)) : motive x := by
rw [← LieSubmodule.mem_toSubmodule, LieSubmodule.iSup_toSubmodule] at hx
exact Submodule.iSup_induction (motive := motive) (fun i ↦ (N i : Submodule R M)) hx mem zero add
@[elab_as_elim]
theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {motive : (x : M) → (x ∈ ⨆ i, N i) → Prop}
(mem : ∀ (i) (x) (hx : x ∈ N i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, N i) : motive x hx := by
refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : motive x hx) => hc
refine iSup_induction N (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), motive x hx) hx
(fun i x hx => ?_) ?_ fun x y => ?_
· exact ⟨_, mem _ _ hx⟩
· exact ⟨_, zero⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, add _ _ _ _ Cx Cy⟩
variable {N N'}
@[simp] lemma disjoint_toSubmodule :
Disjoint (N : Submodule R M) (N' : Submodule R M) ↔ Disjoint N N' := by
rw [disjoint_iff, disjoint_iff, ← toSubmodule_inj, inf_toSubmodule, bot_toSubmodule,
← disjoint_iff]
@[deprecated disjoint_toSubmodule (since := "2025-04-03")]
theorem disjoint_iff_toSubmodule :
Disjoint N N' ↔ Disjoint (N : Submodule R M) (N' : Submodule R M) := disjoint_toSubmodule.symm
@[deprecated (since := "2024-12-30")] alias disjoint_iff_coe_toSubmodule := disjoint_iff_toSubmodule
@[simp] lemma codisjoint_toSubmodule :
Codisjoint (N : Submodule R M) (N' : Submodule R M) ↔ Codisjoint N N' := by
rw [codisjoint_iff, codisjoint_iff, ← toSubmodule_inj, sup_toSubmodule,
top_toSubmodule, ← codisjoint_iff]
@[deprecated codisjoint_toSubmodule (since := "2025-04-03")]
theorem codisjoint_iff_toSubmodule :
Codisjoint N N' ↔ Codisjoint (N : Submodule R M) (N' : Submodule R M) :=
codisjoint_toSubmodule.symm
@[deprecated (since := "2024-12-30")]
alias codisjoint_iff_coe_toSubmodule := codisjoint_iff_toSubmodule
@[simp] lemma isCompl_toSubmodule :
IsCompl (N : Submodule R M) (N' : Submodule R M) ↔ IsCompl N N' := by
simp [isCompl_iff]
@[deprecated isCompl_toSubmodule (since := "2025-04-03")]
theorem isCompl_iff_toSubmodule :
IsCompl N N' ↔ IsCompl (N : Submodule R M) (N' : Submodule R M) := isCompl_toSubmodule.symm
@[deprecated (since := "2024-12-30")] alias isCompl_iff_coe_toSubmodule := isCompl_iff_toSubmodule
@[simp] lemma iSupIndep_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep (fun i ↦ (N i : Submodule R M)) ↔ iSupIndep N := by
simp [iSupIndep_def, ← disjoint_toSubmodule]
@[deprecated iSupIndep_toSubmodule (since := "2025-04-03")]
theorem iSupIndep_iff_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep N ↔ iSupIndep fun i ↦ (N i : Submodule R M) := iSupIndep_toSubmodule.symm
@[deprecated (since := "2024-12-30")]
alias iSupIndep_iff_coe_toSubmodule := iSupIndep_iff_toSubmodule
@[deprecated (since := "2024-11-24")]
alias independent_iff_toSubmodule := iSupIndep_iff_toSubmodule
@[deprecated (since := "2024-12-30")]
alias independent_iff_coe_toSubmodule := independent_iff_toSubmodule
@[simp] lemma iSup_toSubmodule_eq_top {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, (N i : Submodule R M) = ⊤ ↔ ⨆ i, N i = ⊤ := by
rw [← iSup_toSubmodule, ← top_toSubmodule (L := L), toSubmodule_inj]
@[deprecated iSup_toSubmodule_eq_top (since := "2025-04-03")]
theorem iSup_eq_top_iff_toSubmodule {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, N i = ⊤ ↔ ⨆ i, (N i : Submodule R M) = ⊤ := iSup_toSubmodule_eq_top.symm
@[deprecated (since := "2024-12-30")]
alias iSup_eq_top_iff_coe_toSubmodule := iSup_eq_top_iff_toSubmodule
instance : Add (LieSubmodule R L M) where add := max
instance : Zero (LieSubmodule R L M) where zero := ⊥
instance : AddCommMonoid (LieSubmodule R L M) where
add_assoc := sup_assoc
zero_add := bot_sup_eq
add_zero := sup_bot_eq
add_comm := sup_comm
nsmul := nsmulRec
variable (N N')
@[simp]
theorem add_eq_sup : N + N' = N ⊔ N' :=
rfl
@[simp]
theorem mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' := by
rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule,
Submodule.mem_inf]
theorem mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ y ∈ N, ∃ z ∈ N', y + z = x := by
rw [← mem_toSubmodule, sup_toSubmodule, Submodule.mem_sup]; exact Iff.rfl
nonrec theorem eq_bot_iff : N = ⊥ ↔ ∀ m : M, m ∈ N → m = 0 := by rw [eq_bot_iff]; exact Iff.rfl
instance subsingleton_of_bot : Subsingleton (LieSubmodule R L (⊥ : LieSubmodule R L M)) := by
apply subsingleton_of_bot_eq_top
ext ⟨_, hx⟩
simp only [mem_bot, mk_eq_zero, mem_top, iff_true]
exact hx
instance : IsModularLattice (LieSubmodule R L M) where
sup_inf_le_assoc_of_le _ _ := by
simp only [← toSubmodule_le_toSubmodule, sup_toSubmodule, inf_toSubmodule]
exact IsModularLattice.sup_inf_le_assoc_of_le _
variable (R L M)
/-- The natural functor that forgets the action of `L` as an order embedding. -/
@[simps] def toSubmodule_orderEmbedding : LieSubmodule R L M ↪o Submodule R M :=
{ toFun := (↑)
inj' := toSubmodule_injective
map_rel_iff' := Iff.rfl }
instance wellFoundedGT_of_noetherian [IsNoetherian R M] : WellFoundedGT (LieSubmodule R L M) :=
RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).dual.ltEmbedding
theorem wellFoundedLT_of_isArtinian [IsArtinian R M] : WellFoundedLT (LieSubmodule R L M) :=
RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).ltEmbedding
instance [IsArtinian R M] : IsAtomic (LieSubmodule R L M) :=
isAtomic_of_orderBot_wellFounded_lt <| (wellFoundedLT_of_isArtinian R L M).wf
@[simp]
theorem subsingleton_iff : Subsingleton (LieSubmodule R L M) ↔ Subsingleton M :=
have h : Subsingleton (LieSubmodule R L M) ↔ Subsingleton (Submodule R M) := by
rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← toSubmodule_inj,
top_toSubmodule, bot_toSubmodule]
h.trans <| Submodule.subsingleton_iff R
@[simp]
theorem nontrivial_iff : Nontrivial (LieSubmodule R L M) ↔ Nontrivial M :=
not_iff_not.mp
((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R L M).trans
not_nontrivial_iff_subsingleton.symm)
instance [Nontrivial M] : Nontrivial (LieSubmodule R L M) :=
(nontrivial_iff R L M).mpr ‹_›
theorem nontrivial_iff_ne_bot {N : LieSubmodule R L M} : Nontrivial N ↔ N ≠ ⊥ := by
constructor <;> contrapose!
· rintro rfl
⟨⟨m₁, h₁ : m₁ ∈ (⊥ : LieSubmodule R L M)⟩, ⟨m₂, h₂ : m₂ ∈ (⊥ : LieSubmodule R L M)⟩, h₁₂⟩
simp [(LieSubmodule.mem_bot _).mp h₁, (LieSubmodule.mem_bot _).mp h₂] at h₁₂
· rw [not_nontrivial_iff_subsingleton, LieSubmodule.eq_bot_iff]
rintro ⟨h⟩ m hm
simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩
variable {R L M}
section InclusionMaps
/-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/
def incl : N →ₗ⁅R,L⁆ M :=
{ Submodule.subtype (N : Submodule R M) with map_lie' := fun {_ _} ↦ rfl }
@[simp]
theorem incl_coe : (N.incl : N →ₗ[R] M) = (N : Submodule R M).subtype :=
rfl
@[simp]
theorem incl_apply (m : N) : N.incl m = m :=
rfl
theorem incl_eq_val : (N.incl : N → M) = Subtype.val :=
rfl
theorem injective_incl : Function.Injective N.incl := Subtype.coe_injective
variable {N N'}
variable (h : N ≤ N')
/-- Given two nested Lie submodules `N ⊆ N'`,
the inclusion `N ↪ N'` is a morphism of Lie modules. -/
def inclusion : N →ₗ⁅R,L⁆ N' where
__ := Submodule.inclusion (show N.toSubmodule ≤ N'.toSubmodule from h)
map_lie' := rfl
@[simp]
theorem coe_inclusion (m : N) : (inclusion h m : M) = m :=
rfl
theorem inclusion_apply (m : N) : inclusion h m = ⟨m.1, h m.2⟩ :=
rfl
theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by
simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe]
end InclusionMaps
section LieSpan
variable (R L) (s : Set M)
/-- The `lieSpan` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/
def lieSpan : LieSubmodule R L M :=
sInf { N | s ⊆ N }
variable {R L s}
theorem mem_lieSpan {x : M} : x ∈ lieSpan R L s ↔ ∀ N : LieSubmodule R L M, s ⊆ N → x ∈ N := by
rw [← SetLike.mem_coe, lieSpan, sInf_coe]
exact mem_iInter₂
theorem subset_lieSpan : s ⊆ lieSpan R L s := by
intro m hm
rw [SetLike.mem_coe, mem_lieSpan]
intro N hN
exact hN hm
theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by
rw [Submodule.span_le]
apply subset_lieSpan
@[simp]
theorem lieSpan_le {N} : lieSpan R L s ≤ N ↔ s ⊆ N := by
constructor
· exact Subset.trans subset_lieSpan
· intro hs m hm; rw [mem_lieSpan] at hm; exact hm _ hs
theorem lieSpan_mono {t : Set M} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by
rw [lieSpan_le]
exact Subset.trans h subset_lieSpan
theorem lieSpan_eq (N : LieSubmodule R L M) : lieSpan R L (N : Set M) = N :=
le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan
theorem coe_lieSpan_submodule_eq_iff {p : Submodule R M} :
(lieSpan R L (p : Set M) : Submodule R M) = p ↔ ∃ N : LieSubmodule R L M, ↑N = p := by
rw [p.exists_lieSubmodule_coe_eq_iff L]; constructor <;> intro h
· intro x m hm; rw [← h, mem_toSubmodule]; exact lie_mem _ (subset_lieSpan hm)
· rw [← toSubmodule_mk p @h, coe_toSubmodule, toSubmodule_inj, lieSpan_eq]
variable (R L M)
/-- `lieSpan` forms a Galois insertion with the coercion from `LieSubmodule` to `Set`. -/
protected def gi : GaloisInsertion (lieSpan R L : Set M → LieSubmodule R L M) (↑) where
choice s _ := lieSpan R L s
gc _ _ := lieSpan_le
le_l_u _ := subset_lieSpan
choice_eq _ _ := rfl
@[simp]
theorem span_empty : lieSpan R L (∅ : Set M) = ⊥ :=
(LieSubmodule.gi R L M).gc.l_bot
@[simp]
theorem span_univ : lieSpan R L (Set.univ : Set M) = ⊤ :=
eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan
theorem lieSpan_eq_bot_iff : lieSpan R L s = ⊥ ↔ ∀ m ∈ s, m = (0 : M) := by
rw [_root_.eq_bot_iff, lieSpan_le, bot_coe, subset_singleton_iff]
variable {M}
theorem span_union (s t : Set M) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t :=
(LieSubmodule.gi R L M).gc.l_sup
theorem span_iUnion {ι} (s : ι → Set M) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) :=
(LieSubmodule.gi R L M).gc.l_iSup
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition, scalar multiplication and the Lie bracket, then `p` holds for all
elements of the Lie submodule spanned by `s`. -/
@[elab_as_elim]
theorem lieSpan_induction {p : (x : M) → x ∈ lieSpan R L s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_lieSpan h))
(zero : p 0 (LieSubmodule.zero_mem _))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›))
(smul : ∀ (a : R) (x hx), p x hx → p (a • x) (SMulMemClass.smul_mem _ hx)) {x}
(lie : ∀ (x : L) (y hy), p y hy → p (⁅x, y⁆) (LieSubmodule.lie_mem _ ‹_›))
(hx : x ∈ lieSpan R L s) : p x hx := by
let p : LieSubmodule R L M :=
{ carrier := { x | ∃ hx, p x hx }
add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩
zero_mem' := ⟨_, zero⟩
smul_mem' := fun r ↦ fun ⟨_, hpx⟩ ↦ ⟨_, smul r _ _ hpx⟩
lie_mem := fun ⟨_, hpy⟩ ↦ ⟨_, lie _ _ _ hpy⟩ }
exact lieSpan_le (N := p) |>.mpr (fun y hy ↦ ⟨subset_lieSpan hy, mem y hy⟩) hx |>.elim fun _ ↦ id
lemma isCompactElement_lieSpan_singleton (m : M) :
CompleteLattice.IsCompactElement (lieSpan R L {m}) := by
rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le]
intro s hne hdir hsup
replace hsup : m ∈ (↑(sSup s) : Set M) := (SetLike.le_def.mp hsup) (subset_lieSpan rfl)
suffices (↑(sSup s) : Set M) = ⋃ N ∈ s, ↑N by
obtain ⟨N : LieSubmodule R L M, hN : N ∈ s, hN' : m ∈ N⟩ := by
simp_rw [this, Set.mem_iUnion, SetLike.mem_coe, exists_prop] at hsup; assumption
exact ⟨N, hN, by simpa⟩
replace hne : Nonempty s := Set.nonempty_coe_sort.mpr hne
have := Submodule.coe_iSup_of_directed _ hdir.directed_val
simp_rw [← iSup_toSubmodule, Set.iUnion_coe_set, coe_toSubmodule] at this
rw [← this, SetLike.coe_set_eq, sSup_eq_iSup, iSup_subtype]
@[simp]
lemma sSup_image_lieSpan_singleton : sSup ((fun x ↦ lieSpan R L {x}) '' N) = N := by
refine le_antisymm (sSup_le <| by simp) ?_
simp_rw [← toSubmodule_le_toSubmodule, sSup_toSubmodule, Set.mem_image, SetLike.mem_coe]
refine fun m hm ↦ Submodule.mem_sSup.mpr fun N' hN' ↦ ?_
replace hN' : ∀ m ∈ N, lieSpan R L {m} ≤ N' := by simpa using hN'
exact hN' _ hm (subset_lieSpan rfl)
instance instIsCompactlyGenerated : IsCompactlyGenerated (LieSubmodule R L M) :=
⟨fun N ↦ ⟨(fun x ↦ lieSpan R L {x}) '' N, fun _ ⟨m, _, hm⟩ ↦
hm ▸ isCompactElement_lieSpan_singleton R L m, N.sSup_image_lieSpan_singleton⟩⟩
end LieSpan
end LatticeStructure
end LieSubmodule
section LieSubmoduleMapAndComap
variable {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁}
variable [CommRing R] [LieRing L] [LieRing L'] [LieAlgebra R L']
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup M'] [Module R M'] [LieRingModule L M']
namespace LieSubmodule
variable (f : M →ₗ⁅R,L⁆ M') (N N₂ : LieSubmodule R L M) (N' : LieSubmodule R L M')
/-- A morphism of Lie modules `f : M → M'` pushes forward Lie submodules of `M` to Lie submodules
of `M'`. -/
def map : LieSubmodule R L M' :=
{ (N : Submodule R M).map (f : M →ₗ[R] M') with
lie_mem := fun {x m'} h ↦ by
rcases h with ⟨m, hm, hfm⟩; use ⁅x, m⁆; constructor
· apply N.lie_mem hm
· norm_cast at hfm; simp [hfm] }
@[simp] theorem coe_map : (N.map f : Set M') = f '' N := rfl
@[simp]
theorem toSubmodule_map : (N.map f : Submodule R M') = (N : Submodule R M).map (f : M →ₗ[R] M') :=
rfl
@[deprecated (since := "2024-12-30")] alias coeSubmodule_map := toSubmodule_map
/-- A morphism of Lie modules `f : M → M'` pulls back Lie submodules of `M'` to Lie submodules of
`M`. -/
def comap : LieSubmodule R L M :=
{ (N' : Submodule R M').comap (f : M →ₗ[R] M') with
lie_mem := fun {x m} h ↦ by
suffices ⁅x, f m⁆ ∈ N' by simp [this]
apply N'.lie_mem h }
@[simp]
theorem toSubmodule_comap :
(N'.comap f : Submodule R M) = (N' : Submodule R M').comap (f : M →ₗ[R] M') :=
rfl
@[deprecated (since := "2024-12-30")] alias coeSubmodule_comap := toSubmodule_comap
variable {f N N₂ N'}
theorem map_le_iff_le_comap : map f N ≤ N' ↔ N ≤ comap f N' :=
Set.image_subset_iff
variable (f) in
theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap
theorem map_inf_le : (N ⊓ N₂).map f ≤ N.map f ⊓ N₂.map f :=
Set.image_inter_subset f N N₂
theorem map_inf (hf : Function.Injective f) :
(N ⊓ N₂).map f = N.map f ⊓ N₂.map f :=
SetLike.coe_injective <| Set.image_inter hf
@[simp]
theorem map_sup : (N ⊔ N₂).map f = N.map f ⊔ N₂.map f :=
(gc_map_comap f).l_sup
@[simp]
theorem comap_inf {N₂' : LieSubmodule R L M'} :
(N' ⊓ N₂').comap f = N'.comap f ⊓ N₂'.comap f :=
rfl
@[simp]
theorem map_iSup {ι : Sort*} (N : ι → LieSubmodule R L M) :
(⨆ i, N i).map f = ⨆ i, (N i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
@[simp]
theorem mem_map (m' : M') : m' ∈ N.map f ↔ ∃ m, m ∈ N ∧ f m = m' :=
Submodule.mem_map
theorem mem_map_of_mem {m : M} (h : m ∈ N) : f m ∈ N.map f :=
Set.mem_image_of_mem _ h
@[simp]
theorem mem_comap {m : M} : m ∈ comap f N' ↔ f m ∈ N' :=
Iff.rfl
theorem comap_incl_eq_top : N₂.comap N.incl = ⊤ ↔ N ≤ N₂ := by
rw [← LieSubmodule.toSubmodule_inj, LieSubmodule.toSubmodule_comap, LieSubmodule.incl_coe,
LieSubmodule.top_toSubmodule, Submodule.comap_subtype_eq_top, toSubmodule_le_toSubmodule]
theorem comap_incl_eq_bot : N₂.comap N.incl = ⊥ ↔ N ⊓ N₂ = ⊥ := by
simp only [← toSubmodule_inj, toSubmodule_comap, incl_coe, bot_toSubmodule,
inf_toSubmodule]
rw [← Submodule.disjoint_iff_comap_eq_bot, disjoint_iff]
@[gcongr, mono]
theorem map_mono (h : N ≤ N₂) : N.map f ≤ N₂.map f :=
Set.image_subset _ h
theorem map_comp
{M'' : Type*} [AddCommGroup M''] [Module R M''] [LieRingModule L M''] {g : M' →ₗ⁅R,L⁆ M''} :
N.map (g.comp f) = (N.map f).map g :=
SetLike.coe_injective <| by
simp only [← Set.image_comp, coe_map, LinearMap.coe_comp, LieModuleHom.coe_comp]
@[simp]
theorem map_id : N.map LieModuleHom.id = N := by ext; simp
@[simp] theorem map_bot :
(⊥ : LieSubmodule R L M).map f = ⊥ := by
ext m; simp [eq_comm]
lemma map_le_map_iff (hf : Function.Injective f) :
N.map f ≤ N₂.map f ↔ N ≤ N₂ :=
Set.image_subset_image_iff hf
lemma map_injective_of_injective (hf : Function.Injective f) :
Function.Injective (map f) := fun {N N'} h ↦
SetLike.coe_injective <| hf.image_injective <| by simp only [← coe_map, h]
/-- An injective morphism of Lie modules embeds the lattice of submodules of the domain into that
of the target. -/
@[simps] def mapOrderEmbedding {f : M →ₗ⁅R,L⁆ M'} (hf : Function.Injective f) :
LieSubmodule R L M ↪o LieSubmodule R L M' where
toFun := LieSubmodule.map f
inj' := map_injective_of_injective hf
map_rel_iff' := Set.image_subset_image_iff hf
variable (N) in
/-- For an injective morphism of Lie modules, any Lie submodule is equivalent to its image. -/
noncomputable def equivMapOfInjective (hf : Function.Injective f) :
N ≃ₗ⁅R,L⁆ N.map f :=
{ Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N with
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `invFun` explicitly this way, otherwise we'd get a type mismatch
invFun := by exact DFunLike.coe (Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N).symm
map_lie' := by rintro x ⟨m, hm : m ∈ N⟩; ext; exact f.map_lie x m }
/-- An equivalence of Lie modules yields an order-preserving equivalence of their lattices of Lie
Submodules. -/
@[simps] def orderIsoMapComap (e : M ≃ₗ⁅R,L⁆ M') :
LieSubmodule R L M ≃o LieSubmodule R L M' where
toFun := map e
invFun := comap e
left_inv := fun N ↦ by ext; simp
right_inv := fun N ↦ by ext; simp [e.apply_eq_iff_eq_symm_apply]
map_rel_iff' := fun {_ _} ↦ Set.image_subset_image_iff e.injective
end LieSubmodule
end LieSubmoduleMapAndComap
namespace LieModuleHom
variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup N] [Module R N] [LieRingModule L N]
variable (f : M →ₗ⁅R,L⁆ N)
/-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/
def ker : LieSubmodule R L M :=
LieSubmodule.comap f ⊥
@[simp]
theorem ker_toSubmodule : (f.ker : Submodule R M) = LinearMap.ker (f : M →ₗ[R] N) :=
rfl
@[deprecated (since := "2024-12-30")] alias ker_coeSubmodule := ker_toSubmodule
theorem ker_eq_bot : f.ker = ⊥ ↔ Function.Injective f := by
rw [← LieSubmodule.toSubmodule_inj, ker_toSubmodule, LieSubmodule.bot_toSubmodule,
LinearMap.ker_eq_bot, coe_toLinearMap]
variable {f}
@[simp]
theorem mem_ker {m : M} : m ∈ f.ker ↔ f m = 0 :=
Iff.rfl
@[simp]
theorem ker_id : (LieModuleHom.id : M →ₗ⁅R,L⁆ M).ker = ⊥ :=
rfl
@[simp]
theorem comp_ker_incl : f.comp f.ker.incl = 0 := by ext ⟨m, hm⟩; exact mem_ker.mp hm
theorem le_ker_iff_map (M' : LieSubmodule R L M) : M' ≤ f.ker ↔ LieSubmodule.map f M' = ⊥ := by
rw [ker, eq_bot_iff, LieSubmodule.map_le_iff_le_comap]
variable (f)
/-- The range of a morphism of Lie modules `f : M → N` is a Lie submodule of `N`.
See Note [range copy pattern]. -/
def range : LieSubmodule R L N :=
(LieSubmodule.map f ⊤).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : f.range = Set.range f :=
rfl
@[simp]
theorem toSubmodule_range : f.range = LinearMap.range (f : M →ₗ[R] N) :=
rfl
@[deprecated (since := "2024-12-30")] alias coeSubmodule_range := toSubmodule_range
@[simp]
theorem mem_range (n : N) : n ∈ f.range ↔ ∃ m, f m = n :=
Iff.rfl
@[simp]
theorem map_top : LieSubmodule.map f ⊤ = f.range := by ext; simp [LieSubmodule.mem_map]
theorem range_eq_top : f.range = ⊤ ↔ Function.Surjective f := by
rw [SetLike.ext'_iff, coe_range, LieSubmodule.top_coe, Set.range_eq_univ]
/-- A morphism of Lie modules `f : M → N` whose values lie in a Lie submodule `P ⊆ N` can be
restricted to a morphism of Lie modules `M → P`. -/
def codRestrict (P : LieSubmodule R L N) (f : M →ₗ⁅R,L⁆ N) (h : ∀ m, f m ∈ P) :
M →ₗ⁅R,L⁆ P where
toFun := f.toLinearMap.codRestrict P h
__ := f.toLinearMap.codRestrict P h
map_lie' {x m} := by ext; simp
@[simp]
lemma codRestrict_apply (P : LieSubmodule R L N) (f : M →ₗ⁅R,L⁆ N) (h : ∀ m, f m ∈ P) (m : M) :
(f.codRestrict P h m : N) = f m :=
rfl
end LieModuleHom
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable (N : LieSubmodule R L M)
@[simp]
theorem ker_incl : N.incl.ker = ⊥ := (LieModuleHom.ker_eq_bot N.incl).mpr <| injective_incl N
@[simp]
theorem range_incl : N.incl.range = N := by
simp only [← toSubmodule_inj, LieModuleHom.toSubmodule_range, incl_coe]
rw [Submodule.range_subtype]
@[simp]
theorem comap_incl_self : comap N.incl N = ⊤ := by
simp only [← toSubmodule_inj, toSubmodule_comap, incl_coe, top_toSubmodule]
rw [Submodule.comap_subtype_self]
theorem map_incl_top : (⊤ : LieSubmodule R L N).map N.incl = N := by simp
variable {N}
@[simp]
lemma map_le_range {M' : Type*}
[AddCommGroup M'] [Module R M'] [LieRingModule L M'] (f : M →ₗ⁅R,L⁆ M') :
N.map f ≤ f.range := by
rw [← LieModuleHom.map_top]
exact LieSubmodule.map_mono le_top
@[simp]
lemma map_incl_lt_iff_lt_top {N' : LieSubmodule R L N} :
N'.map (LieSubmodule.incl N) < N ↔ N' < ⊤ := by
convert (LieSubmodule.mapOrderEmbedding (f := N.incl) Subtype.coe_injective).lt_iff_lt
simp
@[simp]
lemma map_incl_le {N' : LieSubmodule R L N} :
N'.map N.incl ≤ N := by
conv_rhs => rw [← N.map_incl_top]
exact LieSubmodule.map_mono le_top
end LieSubmodule
section TopEquiv
variable (R : Type u) (L : Type v)
variable [CommRing R] [LieRing L]
variable (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M]
/-- The natural equivalence between the 'top' Lie submodule and the enclosing Lie module. -/
def LieModuleEquiv.ofTop : (⊤ : LieSubmodule R L M) ≃ₗ⁅R,L⁆ M :=
{ LinearEquiv.ofTop ⊤ rfl with
map_lie' := rfl }
variable {R L}
lemma LieModuleEquiv.ofTop_apply (x : (⊤ : LieSubmodule R L M)) :
LieModuleEquiv.ofTop R L M x = x :=
rfl
@[simp] lemma LieModuleEquiv.range_coe {M' : Type*}
[AddCommGroup M'] [Module R M'] [LieRingModule L M'] (e : M ≃ₗ⁅R,L⁆ M') :
LieModuleHom.range (e : M →ₗ⁅R,L⁆ M') = ⊤ := by
rw [LieModuleHom.range_eq_top]
exact e.surjective
variable [LieAlgebra R L] [LieModule R L M]
/-- The natural equivalence between the 'top' Lie subalgebra and the enclosing Lie algebra.
This is the Lie subalgebra version of `Submodule.topEquiv`. -/
def LieSubalgebra.topEquiv : (⊤ : LieSubalgebra R L) ≃ₗ⁅R⁆ L :=
{ (⊤ : LieSubalgebra R L).incl with
invFun := fun x ↦ ⟨x, Set.mem_univ x⟩
left_inv := fun x ↦ by ext; rfl
right_inv := fun _ ↦ rfl }
@[simp]
theorem LieSubalgebra.topEquiv_apply (x : (⊤ : LieSubalgebra R L)) : LieSubalgebra.topEquiv x = x :=
rfl
end TopEquiv
| Mathlib/Algebra/Lie/Submodule.lean | 1,298 | 1,300 | |
/-
Copyright (c) 2014 Microsoft Corporation. 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.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Nat.PSub
import Mathlib.Data.Nat.Size
import Mathlib.Data.Num.Bitwise
/-!
# Properties of the binary representation of integers
-/
open Int
attribute [local simp] add_assoc
namespace PosNum
variable {α : Type*}
@[simp, norm_cast]
theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 :=
rfl
@[simp]
theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 :=
rfl
@[simp, norm_cast]
theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = (n : α) + n :=
rfl
@[simp, norm_cast]
theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = ((n : α) + n) + 1 :=
rfl
@[simp, norm_cast]
theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n
| 1 => Nat.cast_one
| bit0 p => by dsimp; rw [Nat.cast_add, p.cast_to_nat]
| bit1 p => by dsimp; rw [Nat.cast_add, Nat.cast_add, Nat.cast_one, p.cast_to_nat]
@[norm_cast]
theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n :=
cast_to_nat _
@[simp, norm_cast]
theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by
rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat]
theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1
| 1 => rfl
| bit0 _ => rfl
| bit1 p =>
(congr_arg (fun n ↦ n + n) (succ_to_nat p)).trans <|
show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm]
theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl
theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n
| 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one]
| a, 1 => by rw [add_one a, succ_to_nat, cast_one]
| bit0 a, bit0 b => (congr_arg (fun n ↦ n + n) (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _
| bit0 a, bit1 b =>
| (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <|
show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm]
| bit1 a, bit0 b =>
(congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <|
show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm]
| bit1 a, bit1 b =>
| Mathlib/Data/Num/Lemmas.lean | 73 | 78 |
/-
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.Polynomial.Reverse
import Mathlib.Algebra.Regular.SMul
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`Monic.mul`, `Monic.map`, `Monic.pow`.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v y
variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R :=
subsingleton_iff_zero_eq_one
theorem not_monic_zero_iff : ¬Monic (0 : R[X]) ↔ (0 : R) ≠ 1 :=
(monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not
theorem monic_zero_iff_subsingleton' :
Monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ ∀ a b : R, a = b :=
Polynomial.monic_zero_iff_subsingleton.trans
⟨by
intro
simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩
theorem Monic.as_sum (hp : p.Monic) :
p = X ^ p.natDegree + ∑ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by
conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm]
suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul]
exact congr_arg C hp
theorem ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : Monic q) : q ≠ 0 := by
rintro rfl
rw [Monic.def, leadingCoeff_zero] at hq
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp
exact hp rfl
theorem Monic.map [Semiring S] (f : R →+* S) (hp : Monic p) : Monic (p.map f) := by
unfold Monic
nontriviality
have : f p.leadingCoeff ≠ 0 := by
rw [show _ = _ from hp, f.map_one]
exact one_ne_zero
rw [Polynomial.leadingCoeff, coeff_map]
suffices p.coeff (p.map f).natDegree = 1 by simp [this]
rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)]
theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) :
Monic (C b * p) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) :
Monic (p * C b) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : Monic p :=
Decidable.byCases
(fun H : degree p < n => eq_of_zero_eq_one (H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
fun H : ¬degree p < n => by
rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H]
theorem monic_X_pow_add {n : ℕ} (H : degree p < n) : Monic (X ^ n + p) :=
monic_of_degree_le n
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero])
variable (a) in
theorem monic_X_pow_add_C {n : ℕ} (h : n ≠ 0) : (X ^ n + C a).Monic :=
monic_X_pow_add <| (lt_of_le_of_lt degree_C_le
(by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true]))
theorem monic_X_add_C (x : R) : Monic (X + C x) :=
pow_one (X : R[X]) ▸ monic_X_pow_add_C x one_ne_zero
theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) :=
letI := Classical.decEq R
if h0 : (0 : R) = 1 then
haveI := subsingleton_of_zero_eq_one h0
Subsingleton.elim _ _
else by
have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0]
rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul]
theorem Monic.pow (hp : Monic p) : ∀ n : ℕ, Monic (p ^ n)
| 0 => monic_one
| n + 1 => by
rw [pow_succ]
exact (Monic.pow hp n).mul hp
theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by
rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by
rwa [Monic, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_monic_mul hp]
theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_mul_monic hq]
namespace Monic
lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree ≠ 0) : (p.comp q).Monic := by
nontriviality R
have : (p.comp q).natDegree = p.natDegree * q.natDegree :=
natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff]
rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff,
hq.leadingCoeff, one_pow, mul_one]
lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by
nontriviality R
refine hp.comp (monic_X_add_C _) fun ha ↦ ?_
rw [natDegree_X_add_C] at ha
exact one_ne_zero ha
@[simp]
theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by
constructor <;> intro h
swap
· rw [h]
exact natDegree_one
have : p = C (p.coeff 0) := by
rw [← Polynomial.degree_le_zero_iff]
rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h
rw [this]
rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1]
@[simp]
theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≤ 0 ↔ p = 1 := by
rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero]
theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) :
(p * q).natDegree = p.natDegree + q.natDegree := by
nontriviality R
apply natDegree_mul'
simp [hp.leadingCoeff, hq.leadingCoeff]
theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by
by_cases h : q = 0
· simp [h]
rw [degree_mul', hp.degree_mul]
· exact add_comm _ _
· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero]
nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q ≠ 0) :
(p * q).natDegree = p.natDegree + q.natDegree := by
rw [natDegree_mul']
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by
by_cases h : q = 0
· simp [h]
rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm]
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : natDegree q < natDegree p) :
¬p ∣ q := by
rintro ⟨r, rfl⟩
rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl
exact hl.not_le (Nat.le_add_right _ _)
theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : degree q < degree p) : ¬p ∣ q :=
Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl
theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) :
nextCoeff (p * q) = nextCoeff p + nextCoeff q := by
nontriviality
simp only [← coeff_one_reverse]
rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm]
theorem nextCoeff_pow (hp : p.Monic) (n : ℕ) : (p ^ n).nextCoeff = n • p.nextCoeff := by
induction n with
| zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero]
| succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul]
theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R →+* S) (hp : p.Monic)
(map_eq : p.map f = 1) : p = 1 := by
nontriviality R
have hdeg : p.degree = 0 := by
rw [← degree_map_eq_of_leadingCoeff_ne_zero f _, map_eq, degree_one]
· rw [hp.leadingCoeff, f.map_one]
exact one_ne_zero
have hndeg : p.natDegree = 0 :=
WithBot.coe_eq_coe.mp ((degree_eq_natDegree hp.ne_zero).symm.trans hdeg)
convert eq_C_of_degree_eq_zero hdeg
rw [← hndeg, ← Polynomial.leadingCoeff, hp.leadingCoeff, C.map_one]
theorem natDegree_pow (hp : p.Monic) (n : ℕ) : (p ^ n).natDegree = n * p.natDegree := by
induction n with
| zero => simp
| succ n hn => rw [pow_succ, (hp.pow n).natDegree_mul hp, hn, Nat.succ_mul, add_comm]
| end Monic
@[simp]
theorem natDegree_pow_X_add_C [Nontrivial R] (n : ℕ) (r : R) : ((X + C r) ^ n).natDegree = n := by
| Mathlib/Algebra/Polynomial/Monic.lean | 223 | 226 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.HomotopyCategory
import Mathlib.Algebra.Ring.NegOnePow
import Mathlib.CategoryTheory.Shift.Quotient
import Mathlib.CategoryTheory.Linear.LinearFunctor
import Mathlib.Tactic.Linarith
/-!
# The shift on cochain complexes and on the homotopy category
In this file, we show that for any preadditive category `C`, the categories
`CochainComplex C ℤ` and `HomotopyCategory C (ComplexShape.up ℤ)` are
equipped with a shift by `ℤ`.
We also show that if `F : C ⥤ D` is an additive functor, then the functors
`F.mapHomologicalComplex (ComplexShape.up ℤ)` and
`F.mapHomotopyCategory (ComplexShape.up ℤ)` commute with the shift by `ℤ`.
-/
assert_not_exists TwoSidedIdeal
universe v v' u u'
open CategoryTheory
variable (C : Type u) [Category.{v} C] [Preadditive C]
{D : Type u'} [Category.{v'} D] [Preadditive D]
namespace CochainComplex
open HomologicalComplex
/-- The shift functor by `n : ℤ` on `CochainComplex C ℤ` which sends a cochain
complex `K` to the complex which is `K.X (i + n)` in degree `i`, and which
multiplies the differentials by `(-1)^n`. -/
@[simps]
def shiftFunctor (n : ℤ) : CochainComplex C ℤ ⥤ CochainComplex C ℤ where
obj K :=
{ X := fun i => K.X (i + n)
d := fun _ _ => n.negOnePow • K.d _ _
d_comp_d' := by
intros
simp only [Linear.comp_units_smul, Linear.units_smul_comp, d_comp_d, smul_zero]
shape := fun i j hij => by
rw [K.shape, smul_zero]
intro hij'
apply hij
dsimp at hij' ⊢
omega }
map φ :=
{ f := fun _ => φ.f _
comm' := by
intros
dsimp
simp only [Linear.comp_units_smul, Hom.comm, Linear.units_smul_comp] }
map_id := by intros; rfl
map_comp := by intros; rfl
instance (n : ℤ) : (shiftFunctor C n).Additive where
variable {C}
/-- The canonical isomorphism `((shiftFunctor C n).obj K).X i ≅ K.X m` when `m = i + n`. -/
@[simp]
def shiftFunctorObjXIso (K : CochainComplex C ℤ) (n i m : ℤ) (hm : m = i + n) :
((shiftFunctor C n).obj K).X i ≅ K.X m := K.XIsoOfEq hm.symm
section
variable (C)
attribute [local simp] XIsoOfEq_hom_naturality
/-- The shift functor by `n` on `CochainComplex C ℤ` identifies to the identity
functor when `n = 0`. -/
@[simps!]
def shiftFunctorZero' (n : ℤ) (h : n = 0) :
shiftFunctor C n ≅ 𝟭 _ :=
NatIso.ofComponents (fun K => Hom.isoOfComponents
(fun i => K.shiftFunctorObjXIso _ _ _ (by omega))
(fun _ _ _ => by dsimp; simp [h])) (fun _ ↦ by ext; dsimp; simp)
/-- The compatibility of the shift functors on `CochainComplex C ℤ` with respect
to the addition of integers. -/
@[simps!]
def shiftFunctorAdd' (n₁ n₂ n₁₂ : ℤ) (h : n₁ + n₂ = n₁₂) :
shiftFunctor C n₁₂ ≅ shiftFunctor C n₁ ⋙ shiftFunctor C n₂ :=
NatIso.ofComponents (fun K => Hom.isoOfComponents
(fun i => K.shiftFunctorObjXIso _ _ _ (by omega))
(fun _ _ _ => by
subst h
dsimp
simp only [add_comm n₁ n₂, Int.negOnePow_add, Linear.units_smul_comp,
Linear.comp_units_smul, d_comp_XIsoOfEq_hom, smul_smul, XIsoOfEq_hom_comp_d]))
(by intros; ext; dsimp; simp)
attribute [local simp] XIsoOfEq
instance : HasShift (CochainComplex C ℤ) ℤ := hasShiftMk _ _
{ F := shiftFunctor C
zero := shiftFunctorZero' C _ rfl
add := fun n₁ n₂ => shiftFunctorAdd' C n₁ n₂ _ rfl }
instance (n : ℤ) :
(CategoryTheory.shiftFunctor (HomologicalComplex C (ComplexShape.up ℤ)) n).Additive :=
(inferInstance : (CochainComplex.shiftFunctor C n).Additive)
end
@[simp]
lemma shiftFunctor_obj_X' (K : CochainComplex C ℤ) (n p : ℤ) :
((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).X p = K.X (p + n) := rfl
@[simp]
lemma shiftFunctor_map_f' {K L : CochainComplex C ℤ} (φ : K ⟶ L) (n p : ℤ) :
((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).map φ).f p = φ.f (p + n) := rfl
@[simp]
lemma shiftFunctor_obj_d' (K : CochainComplex C ℤ) (n i j : ℤ) :
((CategoryTheory.shiftFunctor (CochainComplex C ℤ) n).obj K).d i j =
n.negOnePow • K.d _ _ := rfl
lemma shiftFunctorAdd_inv_app_f (K : CochainComplex C ℤ) (a b n : ℤ) :
((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n =
(K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := rfl
lemma shiftFunctorAdd_hom_app_f (K : CochainComplex C ℤ) (a b n : ℤ) :
((shiftFunctorAdd (CochainComplex C ℤ) a b).hom.app K).f n =
(K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := by
have : IsIso (((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n) := by
rw [shiftFunctorAdd_inv_app_f]
infer_instance
rw [← cancel_mono (((shiftFunctorAdd (CochainComplex C ℤ) a b).inv.app K).f n),
← comp_f, Iso.hom_inv_id_app, id_f, shiftFunctorAdd_inv_app_f]
simp only [XIsoOfEq, eqToIso.hom, eqToHom_trans, eqToHom_refl]
lemma shiftFunctorAdd'_inv_app_f' (K : CochainComplex C ℤ) (a b ab : ℤ) (h : a + b = ab) (n : ℤ) :
((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b ab h).inv.app K).f n =
(K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by
subst h
rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_inv_app_f]
lemma shiftFunctorAdd'_hom_app_f' (K : CochainComplex C ℤ) (a b ab : ℤ) (h : a + b = ab) (n : ℤ) :
((CategoryTheory.shiftFunctorAdd' (CochainComplex C ℤ) a b ab h).hom.app K).f n =
(K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by
subst h
rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_hom_app_f]
lemma shiftFunctorZero_inv_app_f (K : CochainComplex C ℤ) (n : ℤ) :
((CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n =
(K.XIsoOfEq (by dsimp; rw [add_zero])).hom := rfl
lemma shiftFunctorZero_hom_app_f (K : CochainComplex C ℤ) (n : ℤ) :
((CategoryTheory.shiftFunctorZero (CochainComplex C ℤ) ℤ).hom.app K).f n =
(K.XIsoOfEq (by dsimp; rw [add_zero])).hom := by
have : IsIso (((shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n) := by
rw [shiftFunctorZero_inv_app_f]
| infer_instance
rw [← cancel_mono (((shiftFunctorZero (CochainComplex C ℤ) ℤ).inv.app K).f n), ← comp_f,
| Mathlib/Algebra/Homology/HomotopyCategory/Shift.lean | 163 | 164 |
/-
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. -/
theorem _root_.Bornology.IsBounded.isCompact_closure [ProperSpace α] (h : IsBounded s) :
IsCompact (closure s) :=
isCompact_of_isClosed_isBounded isClosed_closure h.closure
-- TODO: assume `[MetricSpace α]` instead of `[PseudoMetricSpace α] [T2Space α]`
/-- The **Heine–Borel theorem**:
In a proper Hausdorff space, a set is compact if and only if it is closed and bounded. -/
theorem isCompact_iff_isClosed_bounded [T2Space α] [ProperSpace α] :
IsCompact s ↔ IsClosed s ∧ IsBounded s :=
⟨fun h => ⟨h.isClosed, h.isBounded⟩, fun h => isCompact_of_isClosed_isBounded h.1 h.2⟩
theorem compactSpace_iff_isBounded_univ [ProperSpace α] :
CompactSpace α ↔ IsBounded (univ : Set α) :=
⟨@isBounded_of_compactSpace α _ _, fun hb => ⟨isCompact_of_isClosed_isBounded isClosed_univ hb⟩⟩
section CompactIccSpace
variable [Preorder α] [CompactIccSpace α]
theorem _root_.totallyBounded_Icc (a b : α) : TotallyBounded (Icc a b) :=
isCompact_Icc.totallyBounded
theorem _root_.totallyBounded_Ico (a b : α) : TotallyBounded (Ico a b) :=
(totallyBounded_Icc a b).subset Ico_subset_Icc_self
theorem _root_.totallyBounded_Ioc (a b : α) : TotallyBounded (Ioc a b) :=
(totallyBounded_Icc a b).subset Ioc_subset_Icc_self
theorem _root_.totallyBounded_Ioo (a b : α) : TotallyBounded (Ioo a b) :=
(totallyBounded_Icc a b).subset Ioo_subset_Icc_self
theorem isBounded_Icc (a b : α) : IsBounded (Icc a b) :=
(totallyBounded_Icc a b).isBounded
theorem isBounded_Ico (a b : α) : IsBounded (Ico a b) :=
(totallyBounded_Ico a b).isBounded
theorem isBounded_Ioc (a b : α) : IsBounded (Ioc a b) :=
(totallyBounded_Ioc a b).isBounded
theorem isBounded_Ioo (a b : α) : IsBounded (Ioo a b) :=
(totallyBounded_Ioo a b).isBounded
/-- In a pseudo metric space with a conditionally complete linear order such that the order and the
metric structure give the same topology, any order-bounded set is metric-bounded. -/
theorem isBounded_of_bddAbove_of_bddBelow {s : Set α} (h₁ : BddAbove s) (h₂ : BddBelow s) :
IsBounded s :=
let ⟨u, hu⟩ := h₁
let ⟨l, hl⟩ := h₂
(isBounded_Icc l u).subset (fun _x hx => mem_Icc.mpr ⟨hl hx, hu hx⟩)
end CompactIccSpace
end Bounded
section Diam
variable {s : Set α} {x y z : α}
/-- The diameter of a set in a metric space. To get controllable behavior even when the diameter
should be infinite, we express it in terms of the `EMetric.diam` -/
noncomputable def diam (s : Set α) : ℝ :=
ENNReal.toReal (EMetric.diam s)
/-- The diameter of a set is always nonnegative -/
theorem diam_nonneg : 0 ≤ diam s :=
ENNReal.toReal_nonneg
theorem diam_subsingleton (hs : s.Subsingleton) : diam s = 0 := by
simp only [diam, EMetric.diam_subsingleton hs, ENNReal.toReal_zero]
/-- The empty set has zero diameter -/
@[simp]
theorem diam_empty : diam (∅ : Set α) = 0 :=
diam_subsingleton subsingleton_empty
/-- A singleton has zero diameter -/
@[simp]
theorem diam_singleton : diam ({x} : Set α) = 0 :=
diam_subsingleton subsingleton_singleton
@[to_additive (attr := simp)]
theorem diam_one [One α] : diam (1 : Set α) = 0 :=
diam_singleton
-- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x})
theorem diam_pair : diam ({x, y} : Set α) = dist x y := by
simp only [diam, EMetric.diam_pair, dist_edist]
-- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x}))
theorem diam_triple :
Metric.diam ({x, y, z} : Set α) = max (max (dist x y) (dist x z)) (dist y z) := by
simp only [Metric.diam, EMetric.diam_triple, dist_edist]
rw [ENNReal.toReal_max, ENNReal.toReal_max] <;> apply_rules [ne_of_lt, edist_lt_top, max_lt]
/-- If the distance between any two points in a set is bounded by some constant `C`,
then `ENNReal.ofReal C` bounds the emetric diameter of this set. -/
theorem ediam_le_of_forall_dist_le {C : ℝ} (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) :
EMetric.diam s ≤ ENNReal.ofReal C :=
EMetric.diam_le fun x hx y hy => (edist_dist x y).symm ▸ ENNReal.ofReal_le_ofReal (h x hx y hy)
/-- If the distance between any two points in a set is bounded by some non-negative constant,
this constant bounds the diameter. -/
theorem diam_le_of_forall_dist_le {C : ℝ} (h₀ : 0 ≤ C) (h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) :
diam s ≤ C :=
ENNReal.toReal_le_of_le_ofReal h₀ (ediam_le_of_forall_dist_le h)
/-- If the distance between any two points in a nonempty set is bounded by some constant,
this constant bounds the diameter. -/
theorem diam_le_of_forall_dist_le_of_nonempty (hs : s.Nonempty) {C : ℝ}
(h : ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ C) : diam s ≤ C :=
have h₀ : 0 ≤ C :=
let ⟨x, hx⟩ := hs
le_trans dist_nonneg (h x hx x hx)
diam_le_of_forall_dist_le h₀ h
/-- The distance between two points in a set is controlled by the diameter of the set. -/
theorem dist_le_diam_of_mem' (h : EMetric.diam s ≠ ⊤) (hx : x ∈ s) (hy : y ∈ s) :
dist x y ≤ diam s := by
rw [diam, dist_edist]
exact ENNReal.toReal_mono h <| EMetric.edist_le_diam_of_mem hx hy
/-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/
theorem isBounded_iff_ediam_ne_top : IsBounded s ↔ EMetric.diam s ≠ ⊤ :=
isBounded_iff.trans <| Iff.intro
(fun ⟨_C, hC⟩ => ne_top_of_le_ne_top ENNReal.ofReal_ne_top <| ediam_le_of_forall_dist_le hC)
fun h => ⟨diam s, fun _x hx _y hy => dist_le_diam_of_mem' h hx hy⟩
alias ⟨_root_.Bornology.IsBounded.ediam_ne_top, _⟩ := isBounded_iff_ediam_ne_top
theorem ediam_eq_top_iff_unbounded : EMetric.diam s = ⊤ ↔ ¬IsBounded s :=
isBounded_iff_ediam_ne_top.not_left.symm
theorem ediam_univ_eq_top_iff_noncompact [ProperSpace α] :
EMetric.diam (univ : Set α) = ∞ ↔ NoncompactSpace α := by
rw [← not_compactSpace_iff, compactSpace_iff_isBounded_univ, isBounded_iff_ediam_ne_top,
Classical.not_not]
@[simp]
theorem ediam_univ_of_noncompact [ProperSpace α] [NoncompactSpace α] :
EMetric.diam (univ : Set α) = ∞ :=
ediam_univ_eq_top_iff_noncompact.mpr ‹_›
@[simp]
theorem diam_univ_of_noncompact [ProperSpace α] [NoncompactSpace α] : diam (univ : Set α) = 0 := by
simp [diam]
/-- The distance between two points in a set is controlled by the diameter of the set. -/
theorem dist_le_diam_of_mem (h : IsBounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≤ diam s :=
dist_le_diam_of_mem' h.ediam_ne_top hx hy
theorem ediam_of_unbounded (h : ¬IsBounded s) : EMetric.diam s = ∞ := ediam_eq_top_iff_unbounded.2 h
/-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `EMetric.diam`.
This lemma makes it possible to avoid side conditions in some situations -/
theorem diam_eq_zero_of_unbounded (h : ¬IsBounded s) : diam s = 0 := by
rw [diam, ediam_of_unbounded h, ENNReal.toReal_top]
/-- If `s ⊆ t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/
theorem diam_mono {s t : Set α} (h : s ⊆ t) (ht : IsBounded t) : diam s ≤ diam t :=
ENNReal.toReal_mono ht.ediam_ne_top <| EMetric.diam_mono h
/-- The diameter of a union is controlled by the sum of the diameters, and the distance between
any two points in each of the sets. This lemma is true without any side condition, since it is
obviously true if `s ∪ t` is unbounded. -/
theorem diam_union {t : Set α} (xs : x ∈ s) (yt : y ∈ t) :
diam (s ∪ t) ≤ diam s + dist x y + diam t := by
simp only [diam, dist_edist]
refine (ENNReal.toReal_le_add' (EMetric.diam_union xs yt) ?_ ?_).trans
(add_le_add_right ENNReal.toReal_add_le _)
· simp only [ENNReal.add_eq_top, edist_ne_top, or_false]
exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono subset_union_left
· exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono subset_union_right
/-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/
theorem diam_union' {t : Set α} (h : (s ∩ t).Nonempty) : diam (s ∪ t) ≤ diam s + diam t := by
rcases h with ⟨x, ⟨xs, xt⟩⟩
simpa using diam_union xs xt
theorem diam_le_of_subset_closedBall {r : ℝ} (hr : 0 ≤ r) (h : s ⊆ closedBall x r) :
diam s ≤ 2 * r :=
diam_le_of_forall_dist_le (mul_nonneg zero_le_two hr) fun a ha b hb =>
calc
dist a b ≤ dist a x + dist b x := dist_triangle_right _ _ _
_ ≤ r + r := add_le_add (h ha) (h hb)
_ = 2 * r := by simp [mul_two, mul_comm]
/-- The diameter of a closed ball of radius `r` is at most `2 r`. -/
theorem diam_closedBall {r : ℝ} (h : 0 ≤ r) : diam (closedBall x r) ≤ 2 * r :=
diam_le_of_subset_closedBall h Subset.rfl
/-- The diameter of a ball of radius `r` is at most `2 r`. -/
| theorem diam_ball {r : ℝ} (h : 0 ≤ r) : diam (ball x r) ≤ 2 * r :=
diam_le_of_subset_closedBall h ball_subset_closedBall
/-- If a family of complete sets with diameter tending to `0` is such that each finite intersection
| Mathlib/Topology/MetricSpace/Bounded.lean | 476 | 479 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Data.Finite.Sum
import Mathlib.RingTheory.FiniteType
import Mathlib.RingTheory.Finiteness.Ideal
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.RingTheory.MvPolynomial.Tower
/-!
# Finiteness conditions in commutative algebra
In this file we define several notions of finiteness that are common in commutative algebra.
## Main declarations
- `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite`
all of these express that some object is finitely generated *as module* over some base ring.
- `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType`
all of these express that some object is finitely generated *as algebra* over some base ring.
- `Algebra.FinitePresentation`, `RingHom.FinitePresentation`, `AlgHom.FinitePresentation`
all of these express that some object is finitely presented *as algebra* over some base ring.
-/
open Function (Surjective)
open Polynomial
section ModuleAndAlgebra
universe w₁ w₂ w₃
-- Porting note: `M, N` is never used
variable (R : Type w₁) (A : Type w₂) (B : Type w₃)
/-- An algebra over a commutative semiring is `Algebra.FinitePresentation` if it is the quotient of
a polynomial ring in `n` variables by a finitely generated ideal. -/
class Algebra.FinitePresentation [CommSemiring R] [Semiring A] [Algebra R A] : Prop where
out : ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] A), Surjective f ∧ (RingHom.ker f.toRingHom).FG
namespace Algebra
variable [CommRing R] [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
namespace FiniteType
variable {R A B}
/-- A finitely presented algebra is of finite type. -/
instance of_finitePresentation [FinitePresentation R A] : FiniteType R A := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
apply FiniteType.iff_quotient_mvPolynomial''.2
exact ⟨n, f, hf.1⟩
end FiniteType
namespace FinitePresentation
variable {R A B}
/-- An algebra over a Noetherian ring is finitely generated if and only if it is finitely
presented. -/
theorem of_finiteType [IsNoetherianRing R] : FiniteType R A ↔ FinitePresentation R A := by
refine ⟨fun h => ?_, fun hfp => Algebra.FiniteType.of_finitePresentation⟩
obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.1 h
refine ⟨n, f, hf, ?_⟩
have hnoet : IsNoetherianRing (MvPolynomial (Fin n) R) := by infer_instance
-- Porting note: rewrote code to help typeclass inference
rw [isNoetherianRing_iff] at hnoet
letI : Module (MvPolynomial (Fin n) R) (MvPolynomial (Fin n) R) := Semiring.toModule
convert hnoet.noetherian (RingHom.ker f.toRingHom)
/-- If `e : A ≃ₐ[R] B` and `A` is finitely presented, then so is `B`. -/
theorem equiv [FinitePresentation R A] (e : A ≃ₐ[R] B) : FinitePresentation R B := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
use n, AlgHom.comp (↑e) f
constructor
· rw [AlgHom.coe_comp]
exact Function.Surjective.comp e.surjective hf.1
suffices (RingHom.ker (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom) = RingHom.ker f.toRingHom by
rw [this]
exact hf.2
have hco : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = RingHom.comp (e.toRingEquiv : A ≃+* B)
f.toRingHom := by
have h : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom =
e.toAlgHom.toRingHom.comp f.toRingHom := rfl
have h1 : ↑e.toRingEquiv = e.toAlgHom.toRingHom := rfl
rw [h, h1]
rw [RingHom.ker_eq_comap_bot, hco, ← Ideal.comap_comap, ← RingHom.ker_eq_comap_bot,
RingHom.ker_coe_equiv (AlgEquiv.toRingEquiv e), RingHom.ker_eq_comap_bot]
variable (R)
/-- The ring of polynomials in finitely many variables is finitely presented. -/
protected instance mvPolynomial (ι : Type*) [Finite ι] :
FinitePresentation R (MvPolynomial ι R) where
out := by
cases nonempty_fintype ι
let eqv := (MvPolynomial.renameEquiv R <| Fintype.equivFin ι).symm
exact
⟨Fintype.card ι, eqv, eqv.surjective,
((RingHom.injective_iff_ker_eq_bot _).1 eqv.injective).symm ▸ Submodule.fg_bot⟩
/-- `R` is finitely presented as `R`-algebra. -/
instance self : FinitePresentation R R :=
-- Porting note: replaced `PEmpty` with `Empty`
equiv (MvPolynomial.isEmptyAlgEquiv R Empty)
/-- `R[X]` is finitely presented as `R`-algebra. -/
instance polynomial : FinitePresentation R R[X] :=
-- Porting note: replaced `PUnit` with `Unit`
letI := FinitePresentation.mvPolynomial R Unit
equiv (MvPolynomial.pUnitAlgEquiv R)
variable {R}
/-- The quotient of a finitely presented algebra by a finitely generated ideal is finitely
presented. -/
protected theorem quotient {I : Ideal A} (h : I.FG) [FinitePresentation R A] :
FinitePresentation R (A ⧸ I) where
out := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
refine ⟨n, (Ideal.Quotient.mkₐ R I).comp f, ?_, ?_⟩
· exact (Ideal.Quotient.mkₐ_surjective R I).comp hf.1
· refine Ideal.fg_ker_comp _ _ hf.2 ?_ hf.1
simp [h]
/-- If `f : A →ₐ[R] B` is surjective with finitely generated kernel and `A` is finitely presented,
then so is `B`. -/
theorem of_surjective {f : A →ₐ[R] B} (hf : Function.Surjective f)
(hker : (RingHom.ker f.toRingHom).FG)
[FinitePresentation R A] : FinitePresentation R B :=
letI : FinitePresentation R (A ⧸ RingHom.ker f) := FinitePresentation.quotient hker
equiv (Ideal.quotientKerAlgEquivOfSurjective hf)
theorem iff :
FinitePresentation R A ↔
∃ (n : _) (I : Ideal (MvPolynomial (Fin n) R)) (_ : (_ ⧸ I) ≃ₐ[R] A), I.FG := by
constructor
· rintro ⟨n, f, hf⟩
exact ⟨n, RingHom.ker f.toRingHom, Ideal.quotientKerAlgEquivOfSurjective hf.1, hf.2⟩
· rintro ⟨n, I, e, hfg⟩
letI := (FinitePresentation.mvPolynomial R _).quotient hfg
exact equiv e
/-- An algebra is finitely presented if and only if it is a quotient of a polynomial ring whose
variables are indexed by a fintype by a finitely generated ideal. -/
theorem iff_quotient_mvPolynomial' :
FinitePresentation R A ↔
∃ (ι : Type*) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] A),
Surjective f ∧ (RingHom.ker f.toRingHom).FG := by
constructor
· rintro ⟨n, f, hfs, hfk⟩
set ulift_var := MvPolynomial.renameEquiv R Equiv.ulift
refine
⟨ULift (Fin n), inferInstance, f.comp ulift_var.toAlgHom, hfs.comp ulift_var.surjective,
Ideal.fg_ker_comp _ _ ?_ hfk ulift_var.surjective⟩
simpa using Submodule.fg_bot
· rintro ⟨ι, hfintype, f, hf⟩
have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι)
use Fintype.card ι, f.comp equiv.symm, hf.1.comp (AlgEquiv.symm equiv).surjective
refine Ideal.fg_ker_comp (S := MvPolynomial ι R) (A := A) _ f ?_ hf.2 equiv.symm.surjective
simpa using Submodule.fg_bot
universe v in
-- Porting note: make universe level explicit to ensure `ι, ι'` has the same universe level
/-- If `A` is a finitely presented `R`-algebra, then `MvPolynomial (Fin n) A` is finitely presented
as `R`-algebra. -/
theorem mvPolynomial_of_finitePresentation [FinitePresentation.{w₁, w₂} R A]
(ι : Type v) [Finite ι] :
FinitePresentation.{w₁, max v w₂} R (MvPolynomial ι A) := by
have hfp : FinitePresentation.{w₁, w₂} R A := inferInstance
rw [iff_quotient_mvPolynomial'] at hfp ⊢
classical
-- Porting note: use the same universe level
obtain ⟨(ι' : Type v), _, f, hf_surj, hf_ker⟩ := hfp
let g := (MvPolynomial.mapAlgHom f).comp (MvPolynomial.sumAlgEquiv R ι ι').toAlgHom
cases nonempty_fintype (ι ⊕ ι')
refine
⟨ι ⊕ ι', by infer_instance, g,
(MvPolynomial.map_surjective f.toRingHom hf_surj).comp (AlgEquiv.surjective _),
Ideal.fg_ker_comp _ _ ?_ ?_ (AlgEquiv.surjective _)⟩
· rw [AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, AlgHom.ker_coe_equiv]
exact Submodule.fg_bot
· rw [AlgHom.toRingHom_eq_coe, MvPolynomial.mapAlgHom_coe_ringHom, MvPolynomial.ker_map]
exact hf_ker.map MvPolynomial.C
variable (R A B)
/-- If `A` is an `R`-algebra and `S` is an `A`-algebra, both finitely presented, then `S` is
finitely presented as `R`-algebra. -/
theorem trans [Algebra A B] [IsScalarTower R A B] [FinitePresentation R A]
[FinitePresentation A B] : FinitePresentation R B := by
have hfpB : FinitePresentation A B := inferInstance
obtain ⟨n, I, e, hfg⟩ := iff.1 hfpB
letI : FinitePresentation R (MvPolynomial (Fin n) A ⧸ I) :=
(mvPolynomial_of_finitePresentation _).quotient hfg
exact equiv (e.restrictScalars R)
open MvPolynomial
-- TODO: extract out helper lemmas and tidy proof.
@[stacks 0561]
theorem of_restrict_scalars_finitePresentation [Algebra A B] [IsScalarTower R A B]
[FinitePresentation.{w₁, w₃} R B] [FiniteType R A] :
FinitePresentation.{w₂, w₃} A B := by
classical
obtain ⟨n, f, hf, s, hs⟩ := FinitePresentation.out (R := R) (A := B)
letI RX := MvPolynomial (Fin n) R
letI AX := MvPolynomial (Fin n) A
refine ⟨n, MvPolynomial.aeval (f ∘ X), ?_, ?_⟩
· rw [← AlgHom.range_eq_top, ← Algebra.adjoin_range_eq_range_aeval,
Set.range_comp f MvPolynomial.X, eq_top_iff, ← @adjoin_adjoin_of_tower R A B,
adjoin_image, adjoin_range_X, Algebra.map_top, (AlgHom.range_eq_top _).mpr hf]
exact fun {x} => subset_adjoin ⟨⟩
· obtain ⟨t, ht⟩ := FiniteType.out (R := R) (A := A)
have := fun i : t => hf (algebraMap A B i)
choose t' ht' using this
have ht'' : Algebra.adjoin R (algebraMap A AX '' t ∪ Set.range (X : _ → AX)) = ⊤ := by
rw [adjoin_union_eq_adjoin_adjoin, ← Subalgebra.restrictScalars_top R (A := AX)
(S := { x // x ∈ adjoin R ((algebraMap A AX) '' t) })]
refine congrArg (Subalgebra.restrictScalars R) ?_
rw [adjoin_algebraMap, ht]
apply Subalgebra.restrictScalars_injective R
rw [← adjoin_restrictScalars, adjoin_range_X, Subalgebra.restrictScalars_top,
Subalgebra.restrictScalars_top]
letI g : t → AX := fun x => MvPolynomial.C (x : A) - map (algebraMap R A) (t' x)
refine ⟨s.image (map (algebraMap R A)) ∪ t.attach.image g, ?_⟩
rw [Finset.coe_union, Finset.coe_image, Finset.coe_image, Finset.attach_eq_univ,
Finset.coe_univ, Set.image_univ]
let s₀ := (MvPolynomial.map (algebraMap R A)) '' s ∪ Set.range g
let I := RingHom.ker (MvPolynomial.aeval (R := A) (f ∘ MvPolynomial.X))
change Ideal.span s₀ = I
have leI : Ideal.span ((MvPolynomial.map (algebraMap R A)) '' s ∪ Set.range g) ≤
RingHom.ker (MvPolynomial.aeval (R := A) (f ∘ MvPolynomial.X)) := by
rw [Ideal.span_le]
rintro _ (⟨x, hx, rfl⟩ | ⟨⟨x, hx⟩, rfl⟩) <;>
rw [SetLike.mem_coe, RingHom.mem_ker]
· rw [MvPolynomial.aeval_map_algebraMap (R := R) (A := A), ← aeval_unique]
have := Ideal.subset_span hx
rwa [hs] at this
· rw [map_sub, MvPolynomial.aeval_map_algebraMap, ← aeval_unique,
MvPolynomial.aeval_C, ht', Subtype.coe_mk, sub_self]
apply leI.antisymm
intro x hx
rw [RingHom.mem_ker] at hx
let s₀ := (MvPolynomial.map (algebraMap R A)) '' ↑s ∪ Set.range g
change x ∈ Ideal.span s₀
have : x ∈ (MvPolynomial.map (algebraMap R A) : _ →+* AX).range.toAddSubmonoid ⊔
(Ideal.span s₀).toAddSubmonoid := by
have : x ∈ (⊤ : Subalgebra R AX) := trivial
rw [← ht''] at this
refine adjoin_induction ?_ ?_ ?_ ?_ this
· rintro _ (⟨x, hx, rfl⟩ | ⟨i, rfl⟩)
· rw [MvPolynomial.algebraMap_eq, ← sub_add_cancel (MvPolynomial.C x)
(map (algebraMap R A) (t' ⟨x, hx⟩)), add_comm]
apply AddSubmonoid.add_mem_sup
· exact Set.mem_range_self _
· apply Ideal.subset_span
apply Set.mem_union_right
exact Set.mem_range_self _
· apply AddSubmonoid.mem_sup_left
exact ⟨X i, map_X _ _⟩
· intro r
apply AddSubmonoid.mem_sup_left
exact ⟨C r, map_C _ _⟩
· intro _ _ _ _ h₁ h₂
exact add_mem h₁ h₂
· intro x₁ x₂ _ _ h₁ h₂
obtain ⟨_, ⟨p₁, rfl⟩, q₁, hq₁, rfl⟩ := AddSubmonoid.mem_sup.mp h₁
obtain ⟨_, ⟨p₂, rfl⟩, q₂, hq₂, rfl⟩ := AddSubmonoid.mem_sup.mp h₂
rw [add_mul, mul_add, add_assoc, ← map_mul]
apply AddSubmonoid.add_mem_sup
· exact Set.mem_range_self _
· refine add_mem (Ideal.mul_mem_left _ _ hq₂) (Ideal.mul_mem_right _ _ hq₁)
obtain ⟨_, ⟨p, rfl⟩, q, hq, rfl⟩ := AddSubmonoid.mem_sup.mp this
rw [map_add, aeval_map_algebraMap, ← aeval_unique, show MvPolynomial.aeval (f ∘ X) q = 0
from leI hq, add_zero] at hx
suffices Ideal.span (s : Set RX) ≤ (Ideal.span s₀).comap (MvPolynomial.map <| algebraMap R A) by
refine add_mem ?_ hq
rw [hs] at this
exact this hx
rw [Ideal.span_le]
intro x hx
apply Ideal.subset_span
apply Set.mem_union_left
exact Set.mem_image_of_mem _ hx
variable {R A B}
-- TODO: extract out helper lemmas and tidy proof.
/-- This is used to prove the strictly stronger `ker_fg_of_surjective`. Use it instead. -/
theorem ker_fg_of_mvPolynomial {n : ℕ} (f : MvPolynomial (Fin n) R →ₐ[R] A)
(hf : Function.Surjective f) [FinitePresentation R A] : (RingHom.ker f.toRingHom).FG := by
classical
obtain ⟨m, f', hf', s, hs⟩ := FinitePresentation.out (R := R) (A := A)
let RXn := MvPolynomial (Fin n) R
let RXm := MvPolynomial (Fin m) R
have := fun i : Fin n => hf' (f <| X i)
choose g hg using this
have := fun i : Fin m => hf (f' <| X i)
choose h hh using this
let aeval_h : RXm →ₐ[R] RXn := aeval h
let g' : Fin n → RXn := fun i => X i - aeval_h (g i)
refine ⟨Finset.univ.image g' ∪ s.image aeval_h, ?_⟩
simp only [Finset.coe_image, Finset.coe_union, Finset.coe_univ, Set.image_univ]
have hh' : ∀ x, f (aeval_h x) = f' x := by
intro x
rw [← f.coe_toRingHom, map_aeval]
simp_rw [AlgHom.coe_toRingHom, hh]
rw [AlgHom.comp_algebraMap, ← aeval_eq_eval₂Hom,
-- Porting note: added line below
← funext fun i => Function.comp_apply (f := ↑f') (g := MvPolynomial.X),
← aeval_unique]
let s' := Set.range g' ∪ aeval_h '' s
have leI : Ideal.span s' ≤ RingHom.ker f.toRingHom := by
rw [Ideal.span_le]
rintro _ (⟨i, rfl⟩ | ⟨x, hx, rfl⟩)
· change f (g' i) = 0
rw [map_sub, ← hg, hh', sub_self]
· change f (aeval_h x) = 0
rw [hh']
change x ∈ RingHom.ker f'.toRingHom
rw [← hs]
exact Ideal.subset_span hx
apply leI.antisymm
intro x hx
have : x ∈ aeval_h.range.toAddSubmonoid ⊔ (Ideal.span s').toAddSubmonoid := by
have : x ∈ adjoin R (Set.range X : Set RXn) := by
rw [adjoin_range_X]
trivial
refine adjoin_induction ?_ ?_ ?_ ?_ this
· rintro _ ⟨i, rfl⟩
rw [← sub_add_cancel (X i) (aeval h (g i)), add_comm]
apply AddSubmonoid.add_mem_sup
· exact Set.mem_range_self _
· apply Submodule.subset_span
apply Set.mem_union_left
exact Set.mem_range_self _
· intro r
apply AddSubmonoid.mem_sup_left
exact ⟨C r, aeval_C _ _⟩
· intro _ _ _ _ h₁ h₂
exact add_mem h₁ h₂
· intro p₁ p₂ _ _ h₁ h₂
obtain ⟨_, ⟨x₁, rfl⟩, y₁, hy₁, rfl⟩ := AddSubmonoid.mem_sup.mp h₁
obtain ⟨_, ⟨x₂, rfl⟩, y₂, hy₂, rfl⟩ := AddSubmonoid.mem_sup.mp h₂
rw [mul_add, add_mul, add_assoc, ← map_mul]
apply AddSubmonoid.add_mem_sup
· exact Set.mem_range_self _
· exact add_mem (Ideal.mul_mem_right _ _ hy₁) (Ideal.mul_mem_left _ _ hy₂)
obtain ⟨_, ⟨x, rfl⟩, y, hy, rfl⟩ := AddSubmonoid.mem_sup.mp this
refine add_mem ?_ hy
simp only [RXn, RingHom.mem_ker, AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom, map_add,
show f y = 0 from leI hy, add_zero, hh'] at hx
suffices Ideal.span (s : Set RXm) ≤ (Ideal.span s').comap aeval_h by
apply this
rwa [hs]
rw [Ideal.span_le]
intro x hx
apply Submodule.subset_span
apply Set.mem_union_right
exact Set.mem_image_of_mem _ hx
/-- If `f : A →ₐ[R] B` is a surjection between finitely-presented `R`-algebras, then the kernel of
`f` is finitely generated. -/
theorem ker_fG_of_surjective (f : A →ₐ[R] B) (hf : Function.Surjective f)
[FinitePresentation R A] [FinitePresentation R B] : (RingHom.ker f.toRingHom).FG := by
obtain ⟨n, g, hg, _⟩ := FinitePresentation.out (R := R) (A := A)
convert (ker_fg_of_mvPolynomial (f.comp g) (hf.comp hg)).map g.toRingHom
simp_rw [RingHom.ker_eq_comap_bot, AlgHom.toRingHom_eq_coe, AlgHom.comp_toRingHom]
rw [← Ideal.comap_comap, Ideal.map_comap_of_surjective (g : MvPolynomial (Fin n) R →+* A) hg]
end FinitePresentation
end Algebra
end ModuleAndAlgebra
namespace RingHom
variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C]
/-- A ring morphism `A →+* B` is of `RingHom.FinitePresentation` if `B` is finitely presented as
`A`-algebra. -/
@[algebraize]
def FinitePresentation (f : A →+* B) : Prop :=
@Algebra.FinitePresentation A B _ _ f.toAlgebra
@[simp]
lemma finitePresentation_algebraMap [Algebra A B] :
(algebraMap A B).FinitePresentation ↔ Algebra.FinitePresentation A B := by
delta RingHom.FinitePresentation
congr!
exact Algebra.algebra_ext _ _ fun _ ↦ rfl
namespace FiniteType
theorem of_finitePresentation {f : A →+* B} (hf : f.FinitePresentation) : f.FiniteType :=
@Algebra.FiniteType.of_finitePresentation A B _ _ f.toAlgebra hf
end FiniteType
namespace FinitePresentation
variable (A) in
theorem id : FinitePresentation (RingHom.id A) :=
Algebra.FinitePresentation.self A
theorem comp_surjective {f : A →+* B} {g : B →+* C} (hf : f.FinitePresentation) (hg : Surjective g)
(hker : (RingHom.ker g).FG) : (g.comp f).FinitePresentation := by
algebraize [f, g.comp f]
exact Algebra.FinitePresentation.of_surjective
(f :=
{ g with
toFun := g
commutes' := fun _ => rfl })
hg hker
theorem of_surjective (f : A →+* B) (hf : Surjective f) (hker : (RingHom.ker f).FG) :
f.FinitePresentation := by
rw [← f.comp_id]
exact (id A).comp_surjective hf hker
theorem of_finiteType [IsNoetherianRing A] {f : A →+* B} : f.FiniteType ↔ f.FinitePresentation :=
@Algebra.FinitePresentation.of_finiteType A B _ _ f.toAlgebra _
theorem comp {g : B →+* C} {f : A →+* B} (hg : g.FinitePresentation) (hf : f.FinitePresentation) :
(g.comp f).FinitePresentation := by
-- Porting note: specify `Algebra` instances to get `SMul`
algebraize [f, g, g.comp f]
exact Algebra.FinitePresentation.trans A B C
theorem of_comp_finiteType (f : A →+* B) {g : B →+* C} (hg : (g.comp f).FinitePresentation)
(hf : f.FiniteType) : g.FinitePresentation := by
-- Porting note: need to specify some instances
algebraize [f, g, g.comp f]
exact Algebra.FinitePresentation.of_restrict_scalars_finitePresentation A B C
end FinitePresentation
end RingHom
namespace RingHom.FinitePresentation
universe u v
open Polynomial
/-- Induction principle for finitely presented ring homomorphisms.
For a property to hold for all finitely presented ring homs, it suffices for it to hold for
`Polynomial.C : R → R[X]`, surjective ring homs with finitely generated kernels, and to be closed
under composition.
Note that to state this conveniently for ring homs between rings of different universes, we carry
around two predicates `P` and `Q`, which should be "the same" apart from universes:
* `P`, for ring homs `(R : Type u) → (S : Type u)`.
* `Q`, for ring homs `(R : Type u) → (S : Type v)`.
-/
lemma polynomial_induction
(P : ∀ (R : Type u) [CommRing R] (S : Type u) [CommRing S], (R →+* S) → Prop)
(Q : ∀ (R : Type u) [CommRing R] (S : Type v) [CommRing S], (R →+* S) → Prop)
(polynomial : ∀ (R) [CommRing R], P R R[X] C)
(fg_ker : ∀ (R : Type u) [CommRing R] (S : Type v) [CommRing S] (f : R →+* S),
Surjective f → (ker f).FG → Q R S f)
(comp : ∀ (R) [CommRing R] (S) [CommRing S] (T) [CommRing T] (f : R →+* S) (g : S →+* T),
P R S f → Q S T g → Q R T (g.comp f))
{R : Type u} {S : Type v} [CommRing R] [CommRing S] (f : R →+* S) (hf : f.FinitePresentation) :
Q R S f := by
letI := f.toAlgebra
obtain ⟨n, g, hg, hg'⟩ := hf
let g' := g.toRingHom
change Surjective g' at hg
change (ker g').FG at hg'
have : g'.comp MvPolynomial.C = f := g.comp_algebraMap
clear_value g'
subst this
clear g
induction n generalizing R S with
| zero =>
refine fg_ker _ _ _ (hg.comp (MvPolynomial.C_surjective (Fin 0))) ?_
rw [← comap_ker]
convert hg'.map (MvPolynomial.isEmptyRingEquiv R (Fin 0)).toRingHom using 1
simp only [RingEquiv.toRingHom_eq_coe]
exact Ideal.comap_symm (MvPolynomial.isEmptyRingEquiv R (Fin 0))
| succ n IH =>
let e : MvPolynomial (Fin (n + 1)) R ≃ₐ[R] MvPolynomial (Fin n) R[X] :=
(MvPolynomial.renameEquiv R (finSuccEquiv n)).trans (MvPolynomial.optionEquivRight R (Fin n))
have he : (ker (g'.comp <| RingHomClass.toRingHom e.symm)).FG := by
rw [← RingHom.comap_ker]
convert hg'.map e.toAlgHom.toRingHom using 1
exact Ideal.comap_symm e.toRingEquiv
have := IH (R := R[X]) (S := S) (g'.comp e.symm) (hg.comp e.symm.surjective) he
convert comp _ _ _ _ _ (polynomial _) this using 1
rw [comp_assoc, comp_assoc]
congr 1 with r
simp [e]
end RingHom.FinitePresentation
namespace AlgHom
variable {R A B C : Type*} [CommRing R]
variable [CommRing A] [CommRing B] [CommRing C]
variable [Algebra R A] [Algebra R B] [Algebra R C]
/-- An algebra morphism `A →ₐ[R] B` is of `AlgHom.FinitePresentation` if it is of finite
presentation as ring morphism. In other words, if `B` is finitely presented as `A`-algebra. -/
def FinitePresentation (f : A →ₐ[R] B) : Prop :=
f.toRingHom.FinitePresentation
namespace FiniteType
theorem of_finitePresentation {f : A →ₐ[R] B} (hf : f.FinitePresentation) : f.FiniteType :=
RingHom.FiniteType.of_finitePresentation hf
end FiniteType
namespace FinitePresentation
variable (R A)
theorem id : FinitePresentation (AlgHom.id R A) :=
RingHom.FinitePresentation.id A
variable {R A}
| theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.FinitePresentation)
(hf : f.FinitePresentation) : (g.comp f).FinitePresentation :=
RingHom.FinitePresentation.comp hg hf
| Mathlib/RingTheory/FinitePresentation.lean | 531 | 534 |
/-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,
Amelia Livingston, Yury Kudryashov, Yakov Pechersky, Jireh Loreaux
-/
import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Group.Subsemigroup.Basic
import Mathlib.Algebra.Group.TypeTags.Basic
/-!
# Operations on `Subsemigroup`s
In this file we define various operations on `Subsemigroup`s and `MulHom`s.
## Main definitions
### Conversion between multiplicative and additive definitions
* `Subsemigroup.toAddSubsemigroup`, `Subsemigroup.toAddSubsemigroup'`,
`AddSubsemigroup.toSubsemigroup`, `AddSubsemigroup.toSubsemigroup'`:
convert between multiplicative and additive subsemigroups of `M`,
`Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s.
### (Commutative) semigroup structure on a subsemigroup
* `Subsemigroup.toSemigroup`, `Subsemigroup.toCommSemigroup`: a subsemigroup inherits a
(commutative) semigroup structure.
### Operations on subsemigroups
* `Subsemigroup.comap`: preimage of a subsemigroup under a semigroup homomorphism as a subsemigroup
of the domain;
* `Subsemigroup.map`: image of a subsemigroup under a semigroup homomorphism as a subsemigroup of
the codomain;
* `Subsemigroup.prod`: product of two subsemigroups `s : Subsemigroup M` and `t : Subsemigroup N`
as a subsemigroup of `M × N`;
### Semigroup homomorphisms between subsemigroups
* `Subsemigroup.subtype`: embedding of a subsemigroup into the ambient semigroup.
* `Subsemigroup.inclusion`: given two subsemigroups `S`, `T` such that `S ≤ T`, `S.inclusion T` is
the inclusion of `S` into `T` as a semigroup homomorphism;
* `MulEquiv.subsemigroupCongr`: converts a proof of `S = T` into a semigroup isomorphism between
`S` and `T`.
* `Subsemigroup.prodEquiv`: semigroup isomorphism between `s.prod t` and `s × t`;
### Operations on `MulHom`s
* `MulHom.srange`: range of a semigroup homomorphism as a subsemigroup of the codomain;
* `MulHom.restrict`: restrict a semigroup homomorphism to a subsemigroup;
* `MulHom.codRestrict`: restrict the codomain of a semigroup homomorphism to a subsemigroup;
* `MulHom.srangeRestrict`: restrict a semigroup homomorphism to its range;
### Implementation notes
This file follows closely `GroupTheory/Submonoid/Operations.lean`, omitting only that which is
necessary.
## Tags
subsemigroup, range, product, map, comap
-/
assert_not_exists MonoidWithZero
variable {M N P σ : Type*}
/-!
### Conversion to/from `Additive`/`Multiplicative`
-/
section
variable [Mul M]
/-- Subsemigroups of semigroup `M` are isomorphic to additive subsemigroups of `Additive M`. -/
@[simps]
def Subsemigroup.toAddSubsemigroup : Subsemigroup M ≃o AddSubsemigroup (Additive M) where
toFun S :=
{ carrier := Additive.toMul ⁻¹' S
add_mem' := S.mul_mem' }
invFun S :=
{ carrier := Additive.ofMul ⁻¹' S
mul_mem' := S.add_mem' }
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
/-- Additive subsemigroups of an additive semigroup `Additive M` are isomorphic to subsemigroups
of `M`. -/
abbrev AddSubsemigroup.toSubsemigroup' : AddSubsemigroup (Additive M) ≃o Subsemigroup M :=
Subsemigroup.toAddSubsemigroup.symm
theorem Subsemigroup.toAddSubsemigroup_closure (S : Set M) :
Subsemigroup.toAddSubsemigroup (Subsemigroup.closure S) =
AddSubsemigroup.closure (Additive.toMul ⁻¹' S) :=
le_antisymm
(Subsemigroup.toAddSubsemigroup.le_symm_apply.1 <|
Subsemigroup.closure_le.2 (AddSubsemigroup.subset_closure (M := Additive M)))
(AddSubsemigroup.closure_le.2 (Subsemigroup.subset_closure (M := M)))
theorem AddSubsemigroup.toSubsemigroup'_closure (S : Set (Additive M)) :
AddSubsemigroup.toSubsemigroup' (AddSubsemigroup.closure S) =
Subsemigroup.closure (Additive.ofMul ⁻¹' S) :=
le_antisymm
(AddSubsemigroup.toSubsemigroup'.le_symm_apply.1 <|
AddSubsemigroup.closure_le.2 (Subsemigroup.subset_closure (M := M)))
(Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := Additive M))
end
section
variable {A : Type*} [Add A]
/-- Additive subsemigroups of an additive semigroup `A` are isomorphic to
multiplicative subsemigroups of `Multiplicative A`. -/
@[simps]
def AddSubsemigroup.toSubsemigroup : AddSubsemigroup A ≃o Subsemigroup (Multiplicative A) where
toFun S :=
{ carrier := Multiplicative.toAdd ⁻¹' S
mul_mem' := S.add_mem' }
invFun S :=
{ carrier := Multiplicative.ofAdd ⁻¹' S
add_mem' := S.mul_mem' }
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
/-- Subsemigroups of a semigroup `Multiplicative A` are isomorphic to additive subsemigroups
of `A`. -/
abbrev Subsemigroup.toAddSubsemigroup' : Subsemigroup (Multiplicative A) ≃o AddSubsemigroup A :=
AddSubsemigroup.toSubsemigroup.symm
theorem AddSubsemigroup.toSubsemigroup_closure (S : Set A) :
AddSubsemigroup.toSubsemigroup (AddSubsemigroup.closure S) =
Subsemigroup.closure (Multiplicative.toAdd ⁻¹' S) :=
le_antisymm
(AddSubsemigroup.toSubsemigroup.to_galoisConnection.l_le <|
AddSubsemigroup.closure_le.2 <| Subsemigroup.subset_closure (M := Multiplicative A))
(Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := A))
theorem Subsemigroup.toAddSubsemigroup'_closure (S : Set (Multiplicative A)) :
Subsemigroup.toAddSubsemigroup' (Subsemigroup.closure S) =
AddSubsemigroup.closure (Multiplicative.ofAdd ⁻¹' S) :=
le_antisymm
(Subsemigroup.toAddSubsemigroup'.to_galoisConnection.l_le <|
Subsemigroup.closure_le.2 <| AddSubsemigroup.subset_closure (M := A))
(AddSubsemigroup.closure_le.2 <| Subsemigroup.subset_closure (M := Multiplicative A))
end
namespace Subsemigroup
open Set
/-!
### `comap` and `map`
-/
variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M)
/-- The preimage of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/
@[to_additive
"The preimage of an `AddSubsemigroup` along an `AddSemigroup` homomorphism is an
`AddSubsemigroup`."]
def comap (f : M →ₙ* N) (S : Subsemigroup N) :
Subsemigroup M where
carrier := f ⁻¹' S
mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact mul_mem ha hb
@[to_additive (attr := simp)]
theorem coe_comap (S : Subsemigroup N) (f : M →ₙ* N) : (S.comap f : Set M) = f ⁻¹' S :=
rfl
@[to_additive (attr := simp)]
theorem mem_comap {S : Subsemigroup N} {f : M →ₙ* N} {x : M} : x ∈ S.comap f ↔ f x ∈ S :=
Iff.rfl
@[to_additive]
theorem comap_comap (S : Subsemigroup P) (g : N →ₙ* P) (f : M →ₙ* N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[to_additive (attr := simp)]
theorem comap_id (S : Subsemigroup P) : S.comap (MulHom.id _) = S :=
ext (by simp)
/-- The image of a subsemigroup along a semigroup homomorphism is a subsemigroup. -/
@[to_additive
"The image of an `AddSubsemigroup` along an `AddSemigroup` homomorphism is
an `AddSubsemigroup`."]
def map (f : M →ₙ* N) (S : Subsemigroup M) : Subsemigroup N where
carrier := f '' S
mul_mem' := by
rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩
exact ⟨x * y, @mul_mem (Subsemigroup M) M _ _ _ _ _ _ hx hy, by rw [map_mul]⟩
@[to_additive (attr := simp)]
theorem coe_map (f : M →ₙ* N) (S : Subsemigroup M) : (S.map f : Set N) = f '' S :=
rfl
@[to_additive (attr := simp)]
theorem mem_map {f : M →ₙ* N} {S : Subsemigroup M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
mem_image _ _ _
@[to_additive]
theorem mem_map_of_mem (f : M →ₙ* N) {S : Subsemigroup M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
@[to_additive]
theorem apply_coe_mem_map (f : M →ₙ* N) (S : Subsemigroup M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.prop
@[to_additive]
theorem map_map (g : N →ₙ* P) (f : M →ₙ* N) : (S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| image_image _ _ _
-- The simpNF linter says that the LHS can be simplified via `Subsemigroup.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[to_additive (attr := simp, nolint simpNF)]
theorem mem_map_iff_mem {f : M →ₙ* N} (hf : Function.Injective f) {S : Subsemigroup M} {x : M} :
f x ∈ S.map f ↔ x ∈ S :=
hf.mem_set_image
@[to_additive]
theorem map_le_iff_le_comap {f : M →ₙ* N} {S : Subsemigroup M} {T : Subsemigroup N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
@[to_additive]
theorem gc_map_comap (f : M →ₙ* N) : GaloisConnection (map f) (comap f) := fun _ _ =>
map_le_iff_le_comap
@[to_additive]
theorem map_le_of_le_comap {T : Subsemigroup N} {f : M →ₙ* N} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
@[to_additive]
theorem le_comap_of_map_le {T : Subsemigroup N} {f : M →ₙ* N} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
@[to_additive]
theorem le_comap_map {f : M →ₙ* N} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
@[to_additive]
theorem map_comap_le {S : Subsemigroup N} {f : M →ₙ* N} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
@[to_additive]
theorem monotone_map {f : M →ₙ* N} : Monotone (map f) :=
(gc_map_comap f).monotone_l
@[to_additive]
theorem monotone_comap {f : M →ₙ* N} : Monotone (comap f) :=
(gc_map_comap f).monotone_u
@[to_additive (attr := simp)]
theorem map_comap_map {f : M →ₙ* N} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[to_additive (attr := simp)]
theorem comap_map_comap {S : Subsemigroup N} {f : M →ₙ* N} :
((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
@[to_additive]
theorem map_sup (S T : Subsemigroup M) (f : M →ₙ* N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f).l_sup
@[to_additive]
theorem map_iSup {ι : Sort*} (f : M →ₙ* N) (s : ι → Subsemigroup M) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
@[to_additive]
theorem map_inf (S T : Subsemigroup M) (f : M →ₙ* N) (hf : Function.Injective f) :
(S ⊓ T).map f = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf)
@[to_additive]
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : M →ₙ* N) (hf : Function.Injective f)
(s : ι → Subsemigroup M) : (iInf s).map f = ⨅ i, (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
@[to_additive]
theorem comap_inf (S T : Subsemigroup N) (f : M →ₙ* N) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f).u_inf
@[to_additive]
theorem comap_iInf {ι : Sort*} (f : M →ₙ* N) (s : ι → Subsemigroup N) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[to_additive (attr := simp)]
theorem map_bot (f : M →ₙ* N) : (⊥ : Subsemigroup M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[to_additive (attr := simp)]
theorem comap_top (f : M →ₙ* N) : (⊤ : Subsemigroup N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[to_additive (attr := simp)]
theorem map_id (S : Subsemigroup M) : S.map (MulHom.id M) = S :=
ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩
section GaloisCoinsertion
variable {ι : Type*} {f : M →ₙ* N}
/-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/
@[to_additive "`map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective."]
def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff]
variable (hf : Function.Injective f)
include hf
@[to_additive]
theorem comap_map_eq_of_injective (S : Subsemigroup M) : (S.map f).comap f = S :=
(gciMapComap hf).u_l_eq _
@[to_additive]
theorem comap_surjective_of_injective : Function.Surjective (comap f) :=
(gciMapComap hf).u_surjective
@[to_additive]
theorem map_injective_of_injective : Function.Injective (map f) :=
(gciMapComap hf).l_injective
@[to_additive]
theorem comap_inf_map_of_injective (S T : Subsemigroup M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gciMapComap hf).u_inf_l _ _
@[to_additive]
theorem comap_iInf_map_of_injective (S : ι → Subsemigroup M) :
(⨅ i, (S i).map f).comap f = iInf S :=
(gciMapComap hf).u_iInf_l _
@[to_additive]
theorem comap_sup_map_of_injective (S T : Subsemigroup M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gciMapComap hf).u_sup_l _ _
@[to_additive]
theorem comap_iSup_map_of_injective (S : ι → Subsemigroup M) :
(⨆ i, (S i).map f).comap f = iSup S :=
(gciMapComap hf).u_iSup_l _
@[to_additive]
theorem map_le_map_iff_of_injective {S T : Subsemigroup M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gciMapComap hf).l_le_l_iff
@[to_additive]
theorem map_strictMono_of_injective : StrictMono (map f) :=
(gciMapComap hf).strictMono_l
end GaloisCoinsertion
section GaloisInsertion
variable {ι : Type*} {f : M →ₙ* N} (hf : Function.Surjective f)
include hf
/-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/
@[to_additive "`map f` and `comap f` form a `GaloisInsertion` when `f` is surjective."]
def giMapComap : GaloisInsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisInsertion fun S x h =>
let ⟨y, hy⟩ := hf x
mem_map.2 ⟨y, by simp [hy, h]⟩
@[to_additive]
theorem map_comap_eq_of_surjective (S : Subsemigroup N) : (S.comap f).map f = S :=
(giMapComap hf).l_u_eq _
@[to_additive]
theorem map_surjective_of_surjective : Function.Surjective (map f) :=
(giMapComap hf).l_surjective
@[to_additive]
theorem comap_injective_of_surjective : Function.Injective (comap f) :=
(giMapComap hf).u_injective
@[to_additive]
theorem map_inf_comap_of_surjective (S T : Subsemigroup N) :
(S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(giMapComap hf).l_inf_u _ _
@[to_additive]
theorem map_iInf_comap_of_surjective (S : ι → Subsemigroup N) :
(⨅ i, (S i).comap f).map f = iInf S :=
(giMapComap hf).l_iInf_u _
@[to_additive]
theorem map_sup_comap_of_surjective (S T : Subsemigroup N) :
(S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(giMapComap hf).l_sup_u _ _
@[to_additive]
theorem map_iSup_comap_of_surjective (S : ι → Subsemigroup N) :
(⨆ i, (S i).comap f).map f = iSup S :=
(giMapComap hf).l_iSup_u _
@[to_additive]
theorem comap_le_comap_iff_of_surjective {S T : Subsemigroup N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(giMapComap hf).u_le_u_iff
@[to_additive]
theorem comap_strictMono_of_surjective : StrictMono (comap f) :=
(giMapComap hf).strictMono_u
end GaloisInsertion
end Subsemigroup
namespace Subsemigroup
variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M)
/-- The top subsemigroup is isomorphic to the semigroup. -/
@[to_additive (attr := simps)
"The top additive subsemigroup is isomorphic to the additive semigroup."]
def topEquiv : (⊤ : Subsemigroup M) ≃* M where
toFun x := x
invFun x := ⟨x, mem_top x⟩
left_inv x := x.eta _
right_inv _ := rfl
map_mul' _ _ := rfl
@[to_additive (attr := simp)]
theorem topEquiv_toMulHom :
((topEquiv : _ ≃* M) : _ →ₙ* M) = MulMemClass.subtype (⊤ : Subsemigroup M) :=
rfl
/-- A subsemigroup is isomorphic to its image under an injective function -/
@[to_additive "An additive subsemigroup is isomorphic to its image under an injective function"]
noncomputable def equivMapOfInjective (f : M →ₙ* N) (hf : Function.Injective f) : S ≃* S.map f :=
{ Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) }
@[to_additive (attr := simp)]
theorem coe_equivMapOfInjective_apply (f : M →ₙ* N) (hf : Function.Injective f) (x : S) :
(equivMapOfInjective S f hf x : N) = f x :=
rfl
@[to_additive (attr := simp)]
theorem closure_closure_coe_preimage {s : Set M} :
closure ((Subtype.val : closure s → M) ⁻¹' s) = ⊤ :=
eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦
closure_induction (fun _ h ↦ subset_closure h) (fun _ _ _ _ ↦ mul_mem) hx'
/-- Given `Subsemigroup`s `s`, `t` of semigroups `M`, `N` respectively, `s × t` as a subsemigroup
of `M × N`. -/
@[to_additive prod
"Given `AddSubsemigroup`s `s`, `t` of `AddSemigroup`s `A`, `B` respectively,
`s × t` as an `AddSubsemigroup` of `A × B`."]
def prod (s : Subsemigroup M) (t : Subsemigroup N) : Subsemigroup (M × N) where
carrier := s ×ˢ t
mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩
@[to_additive coe_prod]
theorem coe_prod (s : Subsemigroup M) (t : Subsemigroup N) :
(s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) :=
rfl
@[to_additive mem_prod]
theorem mem_prod {s : Subsemigroup M} {t : Subsemigroup N} {p : M × N} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t :=
Iff.rfl
@[to_additive prod_mono]
theorem prod_mono {s₁ s₂ : Subsemigroup M} {t₁ t₂ : Subsemigroup N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) :
s₁.prod t₁ ≤ s₂.prod t₂ :=
Set.prod_mono hs ht
@[to_additive prod_top]
theorem prod_top (s : Subsemigroup M) : s.prod (⊤ : Subsemigroup N) = s.comap (MulHom.fst M N) :=
ext fun x => by simp [mem_prod, MulHom.coe_fst]
@[to_additive top_prod]
theorem top_prod (s : Subsemigroup N) : (⊤ : Subsemigroup M).prod s = s.comap (MulHom.snd M N) :=
ext fun x => by simp [mem_prod, MulHom.coe_snd]
@[to_additive (attr := simp) top_prod_top]
theorem top_prod_top : (⊤ : Subsemigroup M).prod (⊤ : Subsemigroup N) = ⊤ :=
(top_prod _).trans <| comap_top _
@[to_additive bot_prod_bot]
theorem bot_prod_bot : (⊥ : Subsemigroup M).prod (⊥ : Subsemigroup N) = ⊥ :=
SetLike.coe_injective <| by simp [coe_prod]
/-- The product of subsemigroups is isomorphic to their product as semigroups. -/
@[to_additive prodEquiv
"The product of additive subsemigroups is isomorphic to their product as additive semigroups"]
def prodEquiv (s : Subsemigroup M) (t : Subsemigroup N) : s.prod t ≃* s × t :=
{ (Equiv.Set.prod (s : Set M) (t : Set N)) with
map_mul' := fun _ _ => rfl }
open MulHom
@[to_additive]
theorem mem_map_equiv {f : M ≃* N} {K : Subsemigroup M} {x : N} :
x ∈ K.map (f : M →ₙ* N) ↔ f.symm x ∈ K :=
@Set.mem_image_equiv _ _ (K : Set M) f.toEquiv x
@[to_additive]
theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Subsemigroup M) :
K.map (f : M →ₙ* N) = K.comap (f.symm : N →ₙ* M) :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage K)
@[to_additive]
theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Subsemigroup M) :
K.comap (f : N →ₙ* M) = K.map (f.symm : M →ₙ* N) :=
(map_equiv_eq_comap_symm f.symm K).symm
@[to_additive (attr := simp)]
theorem map_equiv_top (f : M ≃* N) : (⊤ : Subsemigroup M).map (f : M →ₙ* N) = ⊤ :=
SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq
@[to_additive le_prod_iff]
theorem le_prod_iff {s : Subsemigroup M} {t : Subsemigroup N} {u : Subsemigroup (M × N)} :
u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by
constructor
· intro h
constructor
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).1
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).2
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h
exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩
end Subsemigroup
namespace MulHom
open Subsemigroup
variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M)
/-- The range of a semigroup homomorphism is a subsemigroup. See Note [range copy pattern]. -/
@[to_additive "The range of an `AddHom` is an `AddSubsemigroup`."]
def srange (f : M →ₙ* N) : Subsemigroup N :=
((⊤ : Subsemigroup M).map f).copy (Set.range f) Set.image_univ.symm
@[to_additive (attr := simp)]
theorem coe_srange (f : M →ₙ* N) : (f.srange : Set N) = Set.range f :=
rfl
@[to_additive (attr := simp)]
theorem mem_srange {f : M →ₙ* N} {y : N} : y ∈ f.srange ↔ ∃ x, f x = y :=
Iff.rfl
@[to_additive]
private theorem srange_mk_aux_mul {f : M → N} (hf : ∀ (x y : M), f (x * y) = f x * f y)
{x y : N} (hx : x ∈ Set.range f) (hy : y ∈ Set.range f) :
x * y ∈ Set.range f :=
(srange ⟨f, hf⟩).mul_mem hx hy
@[to_additive (attr := simp)] theorem srange_mk (f : M → N) (hf) :
srange ⟨f, hf⟩ = ⟨Set.range f, srange_mk_aux_mul hf⟩ := rfl
@[to_additive]
theorem srange_eq_map (f : M →ₙ* N) : f.srange = (⊤ : Subsemigroup M).map f :=
copy_eq _
@[to_additive]
theorem map_srange (g : N →ₙ* P) (f : M →ₙ* N) : f.srange.map g = (g.comp f).srange := by
simpa only [srange_eq_map] using (⊤ : Subsemigroup M).map_map g f
@[to_additive]
theorem srange_eq_top_iff_surjective {N} [Mul N] {f : M →ₙ* N} :
f.srange = (⊤ : Subsemigroup N) ↔ Function.Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_srange, coe_top]) Set.range_eq_univ
@[deprecated (since := "2024-11-11")]
alias srange_top_iff_surjective := srange_eq_top_iff_surjective
/-- The range of a surjective semigroup hom is the whole of the codomain. -/
@[to_additive (attr := simp)
"The range of a surjective `AddSemigroup` hom is the whole of the codomain."]
theorem srange_eq_top_of_surjective {N} [Mul N] (f : M →ₙ* N) (hf : Function.Surjective f) :
f.srange = (⊤ : Subsemigroup N) :=
srange_eq_top_iff_surjective.2 hf
@[deprecated (since := "2024-11-11")] alias srange_top_of_surjective := srange_eq_top_of_surjective
@[to_additive]
theorem mclosure_preimage_le (f : M →ₙ* N) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a semigroup hom of the subsemigroup generated by a set equals the subsemigroup
generated by the image of the set. -/
@[to_additive
"The image under an `AddSemigroup` hom of the `AddSubsemigroup` generated by a set
equals the `AddSubsemigroup` generated by the image of the set."]
theorem map_mclosure (f : M →ₙ* N) (s : Set M) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Subsemigroup.gi N).gc (Subsemigroup.gi M).gc
fun _ ↦ rfl
/-- Restriction of a semigroup hom to a subsemigroup of the domain. -/
@[to_additive "Restriction of an AddSemigroup hom to an `AddSubsemigroup` of the domain."]
def restrict {N : Type*} [Mul N] [SetLike σ M] [MulMemClass σ M] (f : M →ₙ* N) (S : σ) : S →ₙ* N :=
f.comp (MulMemClass.subtype S)
@[to_additive (attr := simp)]
theorem restrict_apply {N : Type*} [Mul N] [SetLike σ M] [MulMemClass σ M] (f : M →ₙ* N) {S : σ}
(x : S) : f.restrict S x = f x :=
rfl
/-- Restriction of a semigroup hom to a subsemigroup of the codomain. -/
@[to_additive (attr := simps)
"Restriction of an `AddSemigroup` hom to an `AddSubsemigroup` of the codomain."]
def codRestrict [SetLike σ N] [MulMemClass σ N] (f : M →ₙ* N) (S : σ) (h : ∀ x, f x ∈ S) :
M →ₙ* S where
toFun n := ⟨f n, h n⟩
map_mul' x y := Subtype.eq (map_mul f x y)
/-- Restriction of a semigroup hom to its range interpreted as a subsemigroup. -/
@[to_additive "Restriction of an `AddSemigroup` hom to its range interpreted as a subsemigroup."]
def srangeRestrict {N} [Mul N] (f : M →ₙ* N) : M →ₙ* f.srange :=
(f.codRestrict f.srange) fun x => ⟨x, rfl⟩
@[to_additive (attr := simp)]
theorem coe_srangeRestrict {N} [Mul N] (f : M →ₙ* N) (x : M) : (f.srangeRestrict x : N) = f x :=
rfl
@[to_additive]
theorem srangeRestrict_surjective (f : M →ₙ* N) : Function.Surjective f.srangeRestrict :=
fun ⟨_, ⟨x, rfl⟩⟩ => ⟨x, rfl⟩
@[to_additive prod_map_comap_prod']
theorem prod_map_comap_prod' {M' : Type*} {N' : Type*} [Mul M'] [Mul N'] (f : M →ₙ* N)
(g : M' →ₙ* N') (S : Subsemigroup N) (S' : Subsemigroup 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 _ _
/-- The `MulHom` from the preimage of a subsemigroup to itself. -/
@[to_additive (attr := simps)
"The `AddHom` from the preimage of an additive subsemigroup to itself."]
def subsemigroupComap (f : M →ₙ* N) (N' : Subsemigroup N) :
N'.comap f →ₙ* N' where
toFun x := ⟨f x, x.prop⟩
map_mul' x y := Subtype.eq <| map_mul (M := M) (N := N) f x y
/-- The `MulHom` from a subsemigroup to its image.
See `MulEquiv.subsemigroupMap` for a variant for `MulEquiv`s. -/
@[to_additive (attr := simps)
"the `AddHom` from an additive subsemigroup to its image. See
`AddEquiv.addSubsemigroupMap` for a variant for `AddEquiv`s."]
def subsemigroupMap (f : M →ₙ* N) (M' : Subsemigroup M) :
M' →ₙ* M'.map f where
toFun x := ⟨f x, ⟨x, x.prop, rfl⟩⟩
map_mul' x y := Subtype.eq <| map_mul (M := M) (N := N) f x y
@[to_additive]
theorem subsemigroupMap_surjective (f : M →ₙ* N) (M' : Subsemigroup M) :
Function.Surjective (f.subsemigroupMap M') := by
rintro ⟨_, x, hx, rfl⟩
exact ⟨⟨x, hx⟩, rfl⟩
end MulHom
namespace Subsemigroup
open MulHom
variable [Mul M] [Mul N] [Mul P] (S : Subsemigroup M)
@[to_additive (attr := simp)]
theorem srange_fst [Nonempty N] : (fst M N).srange = ⊤ :=
(fst M N).srange_eq_top_of_surjective <| Prod.fst_surjective
@[to_additive (attr := simp)]
theorem srange_snd [Nonempty M] : (snd M N).srange = ⊤ :=
(snd M N).srange_eq_top_of_surjective <| Prod.snd_surjective
@[to_additive prod_eq_top_iff]
theorem prod_eq_top_iff [Nonempty M] [Nonempty N] {s : Subsemigroup M} {t : Subsemigroup N} :
s.prod t = ⊤ ↔ s = ⊤ ∧ t = ⊤ := by
simp only [eq_top_iff, le_prod_iff, ← (gc_map_comap _).le_iff_le, ← srange_eq_map, srange_fst,
srange_snd]
/-- The semigroup hom associated to an inclusion of subsemigroups. -/
@[to_additive "The `AddSemigroup` hom associated to an inclusion of subsemigroups."]
def inclusion {S T : Subsemigroup M} (h : S ≤ T) : S →ₙ* T :=
(MulMemClass.subtype S).codRestrict _ fun x => h x.2
@[to_additive (attr := simp)]
theorem range_subtype (s : Subsemigroup M) : (MulMemClass.subtype s).srange = s :=
SetLike.coe_injective <| (coe_srange _).trans <| Subtype.range_coe
@[to_additive]
theorem eq_top_iff' : S = ⊤ ↔ ∀ x : M, x ∈ S :=
eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩
end Subsemigroup
namespace MulEquiv
variable [Mul M] [Mul N] {S T : Subsemigroup M}
/-- Makes the identity isomorphism from a proof that two subsemigroups of a multiplicative
semigroup are equal. -/
@[to_additive
"Makes the identity additive isomorphism from a proof two
subsemigroups of an additive semigroup are equal."]
def subsemigroupCongr (h : S = T) : S ≃* T :=
{ Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl }
-- this name is primed so that the version to `f.range` instead of `f.srange` can be unprimed.
/-- A semigroup homomorphism `f : M →ₙ* N` with a left-inverse `g : N → M` defines a multiplicative
equivalence between `M` and `f.srange`.
This is a bidirectional version of `MulHom.srangeRestrict`. -/
@[to_additive (attr := simps +simpRhs)
"An additive semigroup homomorphism `f : M →+ N` with a left-inverse
`g : N → M` defines an additive equivalence between `M` and `f.srange`.
This is a bidirectional version of `AddHom.srangeRestrict`. "]
def ofLeftInverse (f : M →ₙ* N) {g : N → M} (h : Function.LeftInverse g f) : M ≃* f.srange :=
{ f.srangeRestrict with
toFun := f.srangeRestrict
invFun := g ∘ MulMemClass.subtype f.srange
| left_inv := h
right_inv := fun x =>
Subtype.ext <|
let ⟨x', hx'⟩ := MulHom.mem_srange.mp x.prop
show f (g x) = x by rw [← hx', h x'] }
/-- A `MulEquiv` `φ` between two semigroups `M` and `N` induces a `MulEquiv` between
a subsemigroup `S ≤ M` and the subsemigroup `φ(S) ≤ N`.
See `MulHom.subsemigroupMap` for a variant for `MulHom`s. -/
@[to_additive (attr := simps)
"An `AddEquiv` `φ` between two additive semigroups `M` and `N` induces an `AddEquiv`
| Mathlib/Algebra/Group/Subsemigroup/Operations.lean | 728 | 738 |
/-
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.RightAngle
import Mathlib.Geometry.Euclidean.Circumcenter
/-!
# Angles in circles and sphere.
This file proves results about angles in circles and spheres.
-/
noncomputable section
open Module Complex
open scoped EuclideanGeometry Real RealInnerProductSpace ComplexConjugate
namespace Orientation
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle
form. -/
theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z)
(hxy : ‖x‖ = ‖y‖) (hxz : ‖x‖ = ‖z‖) : o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) := by
have hy : y ≠ 0 := by
rintro rfl
rw [norm_zero, norm_eq_zero] at hxy
exact hxyne hxy
have hx : x ≠ 0 := norm_ne_zero_iff.1 (hxy.symm ▸ norm_ne_zero_iff.2 hy)
have hz : z ≠ 0 := norm_ne_zero_iff.1 (hxz ▸ norm_ne_zero_iff.2 hx)
calc
o.oangle y z = o.oangle x z - o.oangle x y := (o.oangle_sub_left hx hy hz).symm
_ = π - (2 : ℤ) • o.oangle (x - z) x - (π - (2 : ℤ) • o.oangle (x - y) x) := by
rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxzne.symm hxz.symm,
o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxyne.symm hxy.symm]
_ = (2 : ℤ) • (o.oangle (x - y) x - o.oangle (x - z) x) := by abel
_ = (2 : ℤ) • o.oangle (x - y) (x - z) := by
rw [o.oangle_sub_right (sub_ne_zero_of_ne hxyne) (sub_ne_zero_of_ne hxzne) hx]
_ = (2 : ℤ) • o.oangle (y - x) (z - x) := by rw [← oangle_neg_neg, neg_sub, neg_sub]
/-- Angle at center of a circle equals twice angle at circumference, oriented vector angle
form with radius specified. -/
theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z)
{r : ℝ} (hx : ‖x‖ = r) (hy : ‖y‖ = r) (hz : ‖z‖ = r) :
o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) :=
o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne (hy.symm ▸ hx) (hz.symm ▸ hx)
/-- Oriented vector angle version of "angles in same segment are equal" and "opposite angles of
a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same
result), represented here as equality of twice the angles. -/
theorem two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x₁ x₂ y z : V} (hx₁yne : x₁ ≠ y)
(hx₁zne : x₁ ≠ z) (hx₂yne : x₂ ≠ y) (hx₂zne : x₂ ≠ z) {r : ℝ} (hx₁ : ‖x₁‖ = r) (hx₂ : ‖x₂‖ = r)
(hy : ‖y‖ = r) (hz : ‖z‖ = r) :
(2 : ℤ) • o.oangle (y - x₁) (z - x₁) = (2 : ℤ) • o.oangle (y - x₂) (z - x₂) :=
o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₁yne hx₁zne hx₁ hy hz ▸
o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₂yne hx₂zne hx₂ hy hz
end Orientation
namespace EuclideanGeometry
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)]
local notation "o" => Module.Oriented.positiveOrientation
namespace Sphere
/-- Angle at center of a circle equals twice angle at circumference, oriented angle version. -/
theorem oangle_center_eq_two_zsmul_oangle {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃) :
∡ p₁ s.center p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃ := by
rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃
rw [oangle, oangle, o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real _ _ hp₂ hp₁ hp₃] <;>
simp [hp₂p₁, hp₂p₃]
/-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a
cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result),
represented here as equality of twice the angles. -/
theorem two_zsmul_oangle_eq {s : Sphere P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s)
(hp₃ : p₃ ∈ s) (hp₄ : p₄ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄) (hp₃p₁ : p₃ ≠ p₁)
(hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by
rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃ hp₄
rw [oangle, oangle, ← vsub_sub_vsub_cancel_right p₁ p₂ s.center, ←
vsub_sub_vsub_cancel_right p₄ p₂ s.center,
o.two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq _ _ _ _ hp₂ hp₃ hp₁ hp₄] <;>
simp [hp₂p₁, hp₂p₄, hp₃p₁, hp₃p₄]
end Sphere
/-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a
cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result),
represented here as equality of twice the angles. -/
theorem Cospherical.two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ : P}
(h : Cospherical ({p₁, p₂, p₃, p₄} : Set P)) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄)
(hp₃p₁ : p₃ ≠ p₁) (hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by
obtain ⟨s, hs⟩ := cospherical_iff_exists_sphere.1 h
simp_rw [Set.insert_subset_iff, Set.singleton_subset_iff, Sphere.mem_coe] at hs
exact Sphere.two_zsmul_oangle_eq hs.1 hs.2.1 hs.2.2.1 hs.2.2.2 hp₂p₁ hp₂p₄ hp₃p₁ hp₃p₄
namespace Sphere
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
angle-at-point form where the apex is given as the center of a circle. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_center_left {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : ∡ p₁ s.center p₂ = π - (2 : ℤ) • ∡ s.center p₂ p₁ := by
rw [oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq h.symm
(dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)]
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
angle-at-point form where the apex is given as the center of a circle. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_center_right {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (h : p₁ ≠ p₂) : ∡ p₁ s.center p₂ = π - (2 : ℤ) • ∡ p₂ p₁ s.center := by
rw [oangle_eq_pi_sub_two_zsmul_oangle_center_left hp₁ hp₂ h,
oangle_eq_oangle_of_dist_eq (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)]
/-- Twice a base angle of an isosceles triangle with apex at the center of a circle, plus twice
the angle at the apex of a triangle with the same base but apex on the circle, equals `π`. -/
theorem two_zsmul_oangle_center_add_two_zsmul_oangle_eq_pi {s : Sphere P} {p₁ p₂ p₃ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃)
(hp₁p₃ : p₁ ≠ p₃) : (2 : ℤ) • ∡ p₃ p₁ s.center + (2 : ℤ) • ∡ p₁ p₂ p₃ = π := by
rw [← oangle_center_eq_two_zsmul_oangle hp₁ hp₂ hp₃ hp₂p₁ hp₂p₃,
oangle_eq_pi_sub_two_zsmul_oangle_center_right hp₁ hp₃ hp₁p₃, add_sub_cancel]
/-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/
theorem abs_oangle_center_left_toReal_lt_pi_div_two {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) : |(∡ s.center p₂ p₁).toReal| < π / 2 :=
abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq
| (dist_center_eq_dist_center_of_mem_sphere' hp₂ hp₁)
/-- A base angle of an isosceles triangle with apex at the center of a circle is acute. -/
theorem abs_oangle_center_right_toReal_lt_pi_div_two {s : Sphere P} {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) : |(∡ p₂ p₁ s.center).toReal| < π / 2 :=
| Mathlib/Geometry/Euclidean/Angle/Sphere.lean | 136 | 140 |
/-
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.CategoryTheory.Localization.LocalizerMorphism
import Mathlib.CategoryTheory.HomCongr
/-!
# Bijections between morphisms in two localized categories
Given two localization functors `L₁ : C ⥤ D₁` and `L₂ : C ⥤ D₂` for the same
class of morphisms `W : MorphismProperty C`, we define a bijection
`Localization.homEquiv W L₁ L₂ : (L₁.obj X ⟶ L₁.obj Y) ≃ (L₂.obj X ⟶ L₂.obj Y)`
between the types of morphisms in the two localized categories.
More generally, given a localizer morphism `Φ : LocalizerMorphism W₁ W₂`, we define a map
`Φ.homMap L₁ L₂ : (L₁.obj X ⟶ L₁.obj Y) ⟶ (L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y))`.
The definition `Localization.homEquiv` is obtained by applying the construction
to the identity localizer morphism.
-/
namespace CategoryTheory
open Category
variable {C C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C]
[Category C₁] [Category C₂] [Category C₃]
[Category D₁] [Category D₂] [Category D₃]
namespace LocalizerMorphism
variable {W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂} {W₃ : MorphismProperty C₃}
(Φ : LocalizerMorphism W₁ W₂) (Ψ : LocalizerMorphism W₂ W₃)
(L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁]
(L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂]
(L₃ : C₃ ⥤ D₃) [L₃.IsLocalization W₃]
{X Y Z : C₁}
/-- If `Φ : LocalizerMorphism W₁ W₂` is a morphism of localizers, `L₁` and `L₂`
are localization functors for `W₁` and `W₂`, then this is the induced map
`(L₁.obj X ⟶ L₁.obj Y) ⟶ (L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y))`
for all objects `X` and `Y`. -/
noncomputable def homMap (f : L₁.obj X ⟶ L₁.obj Y) :
L₂.obj (Φ.functor.obj X) ⟶ L₂.obj (Φ.functor.obj Y) :=
Iso.homCongr ((CatCommSq.iso _ _ _ _).symm.app _) ((CatCommSq.iso _ _ _ _).symm.app _)
((Φ.localizedFunctor L₁ L₂).map f)
@[simp]
lemma homMap_map (f : X ⟶ Y) :
Φ.homMap L₁ L₂ (L₁.map f) = L₂.map (Φ.functor.map f) := by
dsimp [homMap]
erw [← NatTrans.naturality_assoc]
simp
variable (X) in
| @[simp]
lemma homMap_id :
Φ.homMap L₁ L₂ (𝟙 (L₁.obj X)) = 𝟙 (L₂.obj (Φ.functor.obj X)) := by
simpa using Φ.homMap_map L₁ L₂ (𝟙 X)
| Mathlib/CategoryTheory/Localization/HomEquiv.lean | 59 | 62 |
/-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Reduced
import Mathlib.FieldTheory.KummerPolynomial
import Mathlib.FieldTheory.Separable
/-!
# Perfect fields and rings
In this file we define perfect fields, together with a generalisation to (commutative) rings in
prime characteristic.
## Main definitions / statements:
* `PerfectRing`: a ring of characteristic `p` (prime) is said to be perfect in the sense of Serre,
if its absolute Frobenius map `x ↦ xᵖ` is bijective.
* `PerfectField`: a field `K` is said to be perfect if every irreducible polynomial over `K` is
separable.
* `PerfectRing.toPerfectField`: a field that is perfect in the sense of Serre is a perfect field.
* `PerfectField.toPerfectRing`: a perfect field of characteristic `p` (prime) is perfect in the
sense of Serre.
* `PerfectField.ofCharZero`: all fields of characteristic zero are perfect.
* `PerfectField.ofFinite`: all finite fields are perfect.
* `PerfectField.separable_iff_squarefree`: a polynomial over a perfect field is separable iff
it is square-free.
* `Algebra.IsAlgebraic.isSeparable_of_perfectField`, `Algebra.IsAlgebraic.perfectField`:
if `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable,
and `L` is also a perfect field.
-/
open Function Polynomial
/-- A perfect ring of characteristic `p` (prime) in the sense of Serre.
NB: This is not related to the concept with the same name introduced by Bass (related to projective
covers of modules). -/
class PerfectRing (R : Type*) (p : ℕ) [CommSemiring R] [ExpChar R p] : Prop where
/-- A ring is perfect if the Frobenius map is bijective. -/
bijective_frobenius : Bijective <| frobenius R p
section PerfectRing
variable (R : Type*) (p m n : ℕ) [CommSemiring R] [ExpChar R p]
/-- For a reduced ring, surjectivity of the Frobenius map is a sufficient condition for perfection.
-/
lemma PerfectRing.ofSurjective (R : Type*) (p : ℕ) [CommRing R] [ExpChar R p]
[IsReduced R] (h : Surjective <| frobenius R p) : PerfectRing R p :=
⟨frobenius_inj R p, h⟩
instance PerfectRing.ofFiniteOfIsReduced (R : Type*) [CommRing R] [ExpChar R p]
[Finite R] [IsReduced R] : PerfectRing R p :=
ofSurjective _ _ <| Finite.surjective_of_injective (frobenius_inj R p)
variable [PerfectRing R p]
@[simp]
theorem bijective_frobenius : Bijective (frobenius R p) := PerfectRing.bijective_frobenius
theorem bijective_iterateFrobenius : Bijective (iterateFrobenius R p n) :=
coe_iterateFrobenius R p n ▸ (bijective_frobenius R p).iterate n
@[simp]
theorem injective_frobenius : Injective (frobenius R p) := (bijective_frobenius R p).1
@[simp]
theorem surjective_frobenius : Surjective (frobenius R p) := (bijective_frobenius R p).2
/-- The Frobenius automorphism for a perfect ring. -/
@[simps! apply]
noncomputable def frobeniusEquiv : R ≃+* R :=
RingEquiv.ofBijective (frobenius R p) PerfectRing.bijective_frobenius
@[simp]
theorem coe_frobeniusEquiv : ⇑(frobeniusEquiv R p) = frobenius R p := rfl
theorem frobeniusEquiv_def (x : R) : frobeniusEquiv R p x = x ^ p := rfl
/-- The iterated Frobenius automorphism for a perfect ring. -/
@[simps! apply]
noncomputable def iterateFrobeniusEquiv : R ≃+* R :=
RingEquiv.ofBijective (iterateFrobenius R p n) (bijective_iterateFrobenius R p n)
@[simp]
theorem coe_iterateFrobeniusEquiv : ⇑(iterateFrobeniusEquiv R p n) = iterateFrobenius R p n := rfl
theorem iterateFrobeniusEquiv_def (x : R) : iterateFrobeniusEquiv R p n x = x ^ p ^ n := rfl
theorem iterateFrobeniusEquiv_add_apply (x : R) : iterateFrobeniusEquiv R p (m + n) x =
iterateFrobeniusEquiv R p m (iterateFrobeniusEquiv R p n x) :=
iterateFrobenius_add_apply R p m n x
theorem iterateFrobeniusEquiv_add : iterateFrobeniusEquiv R p (m + n) =
(iterateFrobeniusEquiv R p n).trans (iterateFrobeniusEquiv R p m) :=
RingEquiv.ext (iterateFrobeniusEquiv_add_apply R p m n)
theorem iterateFrobeniusEquiv_symm_add_apply (x : R) : (iterateFrobeniusEquiv R p (m + n)).symm x =
(iterateFrobeniusEquiv R p m).symm ((iterateFrobeniusEquiv R p n).symm x) :=
(iterateFrobeniusEquiv R p (m + n)).injective <| by rw [RingEquiv.apply_symm_apply, add_comm,
iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply, RingEquiv.apply_symm_apply]
theorem iterateFrobeniusEquiv_symm_add : (iterateFrobeniusEquiv R p (m + n)).symm =
(iterateFrobeniusEquiv R p n).symm.trans (iterateFrobeniusEquiv R p m).symm :=
RingEquiv.ext (iterateFrobeniusEquiv_symm_add_apply R p m n)
theorem iterateFrobeniusEquiv_zero_apply (x : R) : iterateFrobeniusEquiv R p 0 x = x := by
rw [iterateFrobeniusEquiv_def, pow_zero, pow_one]
theorem iterateFrobeniusEquiv_one_apply (x : R) : iterateFrobeniusEquiv R p 1 x = x ^ p := by
rw [iterateFrobeniusEquiv_def, pow_one]
@[simp]
theorem iterateFrobeniusEquiv_zero : iterateFrobeniusEquiv R p 0 = RingEquiv.refl R :=
RingEquiv.ext (iterateFrobeniusEquiv_zero_apply R p)
@[simp]
theorem iterateFrobeniusEquiv_one : iterateFrobeniusEquiv R p 1 = frobeniusEquiv R p :=
RingEquiv.ext (iterateFrobeniusEquiv_one_apply R p)
theorem iterateFrobeniusEquiv_eq_pow : iterateFrobeniusEquiv R p n = frobeniusEquiv R p ^ n :=
DFunLike.ext' <| show _ = ⇑(RingAut.toPerm _ _) by
rw [map_pow, Equiv.Perm.coe_pow]; exact (pow_iterate p n).symm
theorem iterateFrobeniusEquiv_symm :
(iterateFrobeniusEquiv R p n).symm = (frobeniusEquiv R p).symm ^ n := by
rw [iterateFrobeniusEquiv_eq_pow]; exact (inv_pow _ _).symm
@[simp]
theorem frobeniusEquiv_symm_apply_frobenius (x : R) :
(frobeniusEquiv R p).symm (frobenius R p x) = x :=
leftInverse_surjInv PerfectRing.bijective_frobenius x
@[simp]
theorem frobenius_apply_frobeniusEquiv_symm (x : R) :
frobenius R p ((frobeniusEquiv R p).symm x) = x :=
surjInv_eq _ _
@[simp]
theorem frobenius_comp_frobeniusEquiv_symm :
(frobenius R p).comp (frobeniusEquiv R p).symm = RingHom.id R := by
ext; simp
@[simp]
theorem frobeniusEquiv_symm_comp_frobenius :
((frobeniusEquiv R p).symm : R →+* R).comp (frobenius R p) = RingHom.id R := by
ext; simp
@[simp]
theorem frobeniusEquiv_symm_pow_p (x : R) : ((frobeniusEquiv R p).symm x) ^ p = x :=
frobenius_apply_frobeniusEquiv_symm R p x
theorem injective_pow_p {x y : R} (h : x ^ p = y ^ p) : x = y := (frobeniusEquiv R p).injective h
lemma polynomial_expand_eq (f : R[X]) :
expand R p f = (f.map (frobeniusEquiv R p).symm) ^ p := by
rw [← (f.map (S := R) (frobeniusEquiv R p).symm).expand_char p, map_expand, map_map,
frobenius_comp_frobeniusEquiv_symm, map_id]
@[simp]
theorem not_irreducible_expand (R p) [CommSemiring R] [Fact p.Prime] [CharP R p] [PerfectRing R p]
(f : R[X]) : ¬ Irreducible (expand R p f) := by
rw [polynomial_expand_eq]
exact not_irreducible_pow (Fact.out : p.Prime).ne_one
instance instPerfectRingProd (S : Type*) [CommSemiring S] [ExpChar S p] [PerfectRing S p] :
PerfectRing (R × S) p where
bijective_frobenius := (bijective_frobenius R p).prodMap (bijective_frobenius S p)
end PerfectRing
/-- A perfect field.
See also `PerfectRing` for a generalisation in positive characteristic. -/
class PerfectField (K : Type*) [Field K] : Prop where
/-- A field is perfect if every irreducible polynomial is separable. -/
separable_of_irreducible : ∀ {f : K[X]}, Irreducible f → f.Separable
lemma PerfectRing.toPerfectField (K : Type*) (p : ℕ)
[Field K] [ExpChar K p] [PerfectRing K p] : PerfectField K := by
obtain hp | ⟨hp⟩ := ‹ExpChar K p›
· exact ⟨Irreducible.separable⟩
refine PerfectField.mk fun hf ↦ ?_
rcases separable_or p hf with h | ⟨-, g, -, rfl⟩
· assumption
· exfalso; revert hf; haveI := Fact.mk hp; simp
namespace PerfectField
variable {K : Type*} [Field K]
instance ofCharZero [CharZero K] : PerfectField K := ⟨Irreducible.separable⟩
instance ofFinite [Finite K] : PerfectField K := by
obtain ⟨p, _instP⟩ := CharP.exists K
have : Fact p.Prime := ⟨CharP.char_is_prime K p⟩
exact PerfectRing.toPerfectField K p
variable [PerfectField K]
/-- A perfect field of characteristic `p` (prime) is a perfect ring. -/
instance toPerfectRing (p : ℕ) [hp : ExpChar K p] : PerfectRing K p := by
refine PerfectRing.ofSurjective _ _ fun y ↦ ?_
rcases hp with _ | hp
· simp [frobenius]
rw [← not_forall_not]
apply mt (X_pow_sub_C_irreducible_of_prime hp)
apply mt separable_of_irreducible
simp [separable_def, isCoprime_zero_right, isUnit_iff_degree_eq_zero,
derivative_X_pow, degree_X_pow_sub_C hp.pos, hp.ne_zero]
theorem separable_iff_squarefree {g : K[X]} : g.Separable ↔ Squarefree g := by
refine ⟨Separable.squarefree, fun sqf ↦ isCoprime_of_irreducible_dvd (sqf.ne_zero ·.1) ?_⟩
rintro p (h : Irreducible p) ⟨q, rfl⟩ (dvd : p ∣ derivative (p * q))
replace dvd : p ∣ q := by
rw [derivative_mul, dvd_add_left (dvd_mul_right p _)] at dvd
exact (separable_of_irreducible h).dvd_of_dvd_mul_left dvd
exact (h.1 : ¬ IsUnit p) (sqf _ <| mul_dvd_mul_left _ dvd)
end PerfectField
/-- If `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable. -/
instance Algebra.IsAlgebraic.isSeparable_of_perfectField {K L : Type*} [Field K] [Field L]
[Algebra K L] [Algebra.IsAlgebraic K L] [PerfectField K] : Algebra.IsSeparable K L :=
⟨fun x ↦ PerfectField.separable_of_irreducible <|
minpoly.irreducible (Algebra.IsIntegral.isIntegral x)⟩
/-- If `L / K` is an algebraic extension, `K` is a perfect field, then so is `L`. -/
theorem Algebra.IsAlgebraic.perfectField {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsAlgebraic K L] [PerfectField K] : PerfectField L := ⟨fun {f} hf ↦ by
obtain ⟨_, _, hi, h⟩ := hf.exists_dvd_monic_irreducible_of_isIntegral (K := K)
exact (PerfectField.separable_of_irreducible hi).map |>.of_dvd h⟩
namespace Polynomial
variable {R : Type*} [CommRing R] [IsDomain R] (p n : ℕ) [ExpChar R p] (f : R[X])
open Multiset
theorem roots_expand_pow_map_iterateFrobenius_le :
(expand R (p ^ n) f).roots.map (iterateFrobenius R p n) ≤ p ^ n • f.roots := by
classical
refine le_iff_count.2 fun r ↦ ?_
by_cases h : ∃ s, r = s ^ p ^ n
· obtain ⟨s, rfl⟩ := h
simp_rw [count_nsmul, count_roots, ← rootMultiplicity_expand_pow, ← count_roots, count_map,
count_eq_card_filter_eq]
exact card_le_card (monotone_filter_right _ fun _ h ↦ iterateFrobenius_inj R p n h)
convert Nat.zero_le _
simp_rw [count_map, card_eq_zero]
exact ext' fun t ↦ count_zero t ▸ count_filter_of_neg fun h' ↦ h ⟨t, h'⟩
theorem roots_expand_map_frobenius_le :
(expand R p f).roots.map (frobenius R p) ≤ p • f.roots := by
rw [← iterateFrobenius_one]
convert ← roots_expand_pow_map_iterateFrobenius_le p 1 f <;> apply pow_one
theorem roots_expand_pow_image_iterateFrobenius_subset [DecidableEq R] :
(expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) ⊆ f.roots.toFinset := by
rw [Finset.image_toFinset, ← (roots f).toFinset_nsmul _ (expChar_pow_pos R p n).ne',
toFinset_subset]
exact subset_of_le (roots_expand_pow_map_iterateFrobenius_le p n f)
theorem roots_expand_image_frobenius_subset [DecidableEq R] :
(expand R p f).roots.toFinset.image (frobenius R p) ⊆ f.roots.toFinset := by
rw [← iterateFrobenius_one]
convert ← roots_expand_pow_image_iterateFrobenius_subset p 1 f
apply pow_one
section PerfectRing
variable {p n f}
variable [PerfectRing R p]
theorem roots_expand_pow :
(expand R (p ^ n) f).roots = p ^ n • f.roots.map (iterateFrobeniusEquiv R p n).symm := by
classical
refine ext' fun r ↦ ?_
rw [count_roots, rootMultiplicity_expand_pow, ← count_roots, count_nsmul, count_map,
count_eq_card_filter_eq]; congr; ext
exact (iterateFrobeniusEquiv R p n).eq_symm_apply.symm
theorem roots_expand : (expand R p f).roots = p • f.roots.map (frobeniusEquiv R p).symm := by
conv_lhs => rw [← pow_one p, roots_expand_pow, iterateFrobeniusEquiv_eq_pow, pow_one]
rfl
theorem roots_X_pow_char_pow_sub_C {y : R} :
(X ^ p ^ n - C y).roots = p ^ n • {(iterateFrobeniusEquiv R p n).symm y} := by
have H := roots_expand_pow (p := p) (n := n) (f := X - C y)
rwa [roots_X_sub_C, Multiset.map_singleton, map_sub, expand_X, expand_C] at H
theorem roots_X_pow_char_pow_sub_C_pow {y : R} {m : ℕ} :
((X ^ p ^ n - C y) ^ m).roots = (m * p ^ n) • {(iterateFrobeniusEquiv R p n).symm y} := by
rw [roots_pow, roots_X_pow_char_pow_sub_C, mul_smul]
theorem roots_X_pow_char_sub_C {y : R} :
(X ^ p - C y).roots = p • {(frobeniusEquiv R p).symm y} := by
have H := roots_X_pow_char_pow_sub_C (p := p) (n := 1) (y := y)
rwa [pow_one, iterateFrobeniusEquiv_one] at H
theorem roots_X_pow_char_sub_C_pow {y : R} {m : ℕ} :
((X ^ p - C y) ^ m).roots = (m * p) • {(frobeniusEquiv R p).symm y} := by
have H := roots_X_pow_char_pow_sub_C_pow (p := p) (n := 1) (y := y) (m := m)
rwa [pow_one, iterateFrobeniusEquiv_one] at H
theorem roots_expand_pow_map_iterateFrobenius :
(expand R (p ^ n) f).roots.map (iterateFrobenius R p n) = p ^ n • f.roots := by
simp_rw [← coe_iterateFrobeniusEquiv, roots_expand_pow, Multiset.map_nsmul,
Multiset.map_map, comp_apply, RingEquiv.apply_symm_apply, map_id']
theorem roots_expand_map_frobenius : (expand R p f).roots.map (frobenius R p) = p • f.roots := by
simp [roots_expand, Multiset.map_nsmul]
| theorem roots_expand_image_iterateFrobenius [DecidableEq R] :
(expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) = f.roots.toFinset := by
rw [Finset.image_toFinset, roots_expand_pow_map_iterateFrobenius,
| Mathlib/FieldTheory/Perfect.lean | 317 | 319 |
/-
Copyright (c) 2022 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.LinearAlgebra.Dimension.FreeAndStrongRankCondition
import Mathlib.LinearAlgebra.FiniteDimensional.Basic
/-!
# Projective Spaces
This file contains the definition of the projectivization of a vector space over a field,
as well as the bijection between said projectivization and the collection of all one
dimensional subspaces of the vector space.
## Notation
`ℙ K V` is localized notation for `Projectivization K V`, the projectivization of a `K`-vector
space `V`.
## Constructing terms of `ℙ K V`.
We have three ways to construct terms of `ℙ K V`:
- `Projectivization.mk K v hv` where `v : V` and `hv : v ≠ 0`.
- `Projectivization.mk' K v` where `v : { w : V // w ≠ 0 }`.
- `Projectivization.mk'' H h` where `H : Submodule K V` and `h : finrank H = 1`.
## Other definitions
- For `v : ℙ K V`, `v.submodule` gives the corresponding submodule of `V`.
- `Projectivization.equivSubmodule` is the equivalence between `ℙ K V`
and `{ H : Submodule K V // finrank H = 1 }`.
- For `v : ℙ K V`, `v.rep : V` is a representative of `v`.
-/
variable (K V : Type*) [DivisionRing K] [AddCommGroup V] [Module K V]
/-- The setoid whose quotient is the projectivization of `V`. -/
def projectivizationSetoid : Setoid { v : V // v ≠ 0 } :=
(MulAction.orbitRel Kˣ V).comap (↑)
/-- The projectivization of the `K`-vector space `V`.
The notation `ℙ K V` is preferred. -/
def Projectivization := Quotient (projectivizationSetoid K V)
/-- We define notations `ℙ K V` for the projectivization of the `K`-vector space `V`. -/
scoped[LinearAlgebra.Projectivization] notation "ℙ" => Projectivization
namespace Projectivization
open scoped LinearAlgebra.Projectivization
variable {V}
/-- Construct an element of the projectivization from a nonzero vector. -/
def mk (v : V) (hv : v ≠ 0) : ℙ K V :=
Quotient.mk'' ⟨v, hv⟩
/-- A variant of `Projectivization.mk` in terms of a subtype. `mk` is preferred. -/
def mk' (v : { v : V // v ≠ 0 }) : ℙ K V :=
Quotient.mk'' v
@[simp]
theorem mk'_eq_mk (v : { v : V // v ≠ 0 }) : mk' K v = mk K ↑v v.2 := rfl
instance [Nontrivial V] : Nonempty (ℙ K V) :=
let ⟨v, hv⟩ := exists_ne (0 : V)
⟨mk K v hv⟩
variable {K}
/-- A function on non-zero vectors which is independent of scale, descends to a function on the
projectivization. -/
protected def lift {α : Type*} (f : { v : V // v ≠ 0 } → α)
(hf : ∀ (a b : { v : V // v ≠ 0 }) (t : K), a = t • (b : V) → f a = f b)
(x : ℙ K V) : α :=
Quotient.lift f (by rintro ⟨-, hv⟩ ⟨w, hw⟩ ⟨⟨t, -⟩, rfl⟩; exact hf ⟨_, hv⟩ ⟨w, hw⟩ t rfl) x
@[simp]
protected lemma lift_mk {α : Type*} (f : { v : V // v ≠ 0 } → α)
(hf : ∀ (a b : { v : V // v ≠ 0 }) (t : K), a = t • (b : V) → f a = f b)
(v : V) (hv : v ≠ 0) :
Projectivization.lift f hf (mk K v hv) = f ⟨v, hv⟩ :=
rfl
/-- Choose a representative of `v : Projectivization K V` in `V`. -/
protected noncomputable def rep (v : ℙ K V) : V :=
v.out
theorem rep_nonzero (v : ℙ K V) : v.rep ≠ 0 :=
v.out.2
@[simp]
theorem mk_rep (v : ℙ K V) : mk K v.rep v.rep_nonzero = v := Quotient.out_eq' _
open Module
/-- Consider an element of the projectivization as a submodule of `V`. -/
protected def submodule (v : ℙ K V) : Submodule K V :=
(Quotient.liftOn' v fun v => K ∙ (v : V)) <| by
rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨x, rfl : x • b = a⟩
exact Submodule.span_singleton_group_smul_eq _ x _
variable (K)
theorem mk_eq_mk_iff (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) :
mk K v hv = mk K w hw ↔ ∃ a : Kˣ, a • w = v :=
Quotient.eq''
/-- Two nonzero vectors go to the same point in projective space if and only if one is
a scalar multiple of the other. -/
theorem mk_eq_mk_iff' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) :
mk K v hv = mk K w hw ↔ ∃ a : K, a • w = v := by
rw [mk_eq_mk_iff K v w hv hw]
constructor
· rintro ⟨a, ha⟩
exact ⟨a, ha⟩
· rintro ⟨a, ha⟩
refine ⟨Units.mk0 a fun c => hv.symm ?_, ha⟩
rwa [c, zero_smul] at ha
theorem exists_smul_eq_mk_rep (v : V) (hv : v ≠ 0) : ∃ a : Kˣ, a • v = (mk K v hv).rep :=
(mk_eq_mk_iff K _ _ (rep_nonzero _) hv).1 (mk_rep _)
variable {K}
/-- An induction principle for `Projectivization`. Use as `induction v`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
theorem ind {P : ℙ K V → Prop} (h : ∀ (v : V) (h : v ≠ 0), P (mk K v h)) : ∀ p, P p :=
Quotient.ind' <| Subtype.rec <| h
@[simp]
theorem submodule_mk (v : V) (hv : v ≠ 0) : (mk K v hv).submodule = K ∙ v :=
rfl
theorem submodule_eq (v : ℙ K V) : v.submodule = K ∙ v.rep := by
conv_lhs => rw [← v.mk_rep]
rfl
theorem finrank_submodule (v : ℙ K V) : finrank K v.submodule = 1 := by
rw [submodule_eq]
exact finrank_span_singleton v.rep_nonzero
instance (v : ℙ K V) : FiniteDimensional K v.submodule := by
rw [← v.mk_rep]
change FiniteDimensional K (K ∙ v.rep)
infer_instance
theorem submodule_injective :
Function.Injective (Projectivization.submodule : ℙ K V → Submodule K V) := fun u v h ↦ by
induction u using ind with | h u hu =>
| induction v using ind with | h v hv =>
rw [submodule_mk, submodule_mk, Submodule.span_singleton_eq_span_singleton] at h
exact ((mk_eq_mk_iff K v u hv hu).2 h).symm
variable (K V)
| Mathlib/LinearAlgebra/Projectivization/Basic.lean | 151 | 156 |
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Set.Prod
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.ModelTheory.LanguageMap
import Mathlib.Algebra.Order.Group.Nat
/-!
# Basics on First-Order Syntax
This file defines first-order terms, formulas, sentences, and theories in a style inspired by the
[Flypitch project](https://flypitch.github.io/).
## Main Definitions
- A `FirstOrder.Language.Term` is defined so that `L.Term α` is the type of `L`-terms with free
variables indexed by `α`.
- A `FirstOrder.Language.Formula` is defined so that `L.Formula α` is the type of `L`-formulas with
free variables indexed by `α`.
- A `FirstOrder.Language.Sentence` is a formula with no free variables.
- A `FirstOrder.Language.Theory` is a set of sentences.
- The variables of terms and formulas can be relabelled with `FirstOrder.Language.Term.relabel`,
`FirstOrder.Language.BoundedFormula.relabel`, and `FirstOrder.Language.Formula.relabel`.
- Given an operation on terms and an operation on relations,
`FirstOrder.Language.BoundedFormula.mapTermRel` gives an operation on formulas.
- `FirstOrder.Language.BoundedFormula.castLE` adds more `Fin`-indexed variables.
- `FirstOrder.Language.BoundedFormula.liftAt` raises the indexes of the `Fin`-indexed variables
above a particular index.
- `FirstOrder.Language.Term.subst` and `FirstOrder.Language.BoundedFormula.subst` substitute
variables with given terms.
- Language maps can act on syntactic objects with functions such as
`FirstOrder.Language.LHom.onFormula`.
- `FirstOrder.Language.Term.constantsVarsEquiv` and
`FirstOrder.Language.BoundedFormula.constantsVarsEquiv` switch terms and formulas between having
constants in the language and having extra variables indexed by the same type.
## Implementation Notes
- Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable (L : Language.{u, v}) {L' : Language}
variable {M : Type w} {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder
open Structure Fin
/-- A term on `α` is either a variable indexed by an element of `α`
or a function symbol applied to simpler terms. -/
inductive Term (α : Type u') : Type max u u'
| var : α → Term α
| func : ∀ {l : ℕ} (_f : L.Functions l) (_ts : Fin l → Term α), Term α
export Term (var func)
variable {L}
namespace Term
instance instDecidableEq [DecidableEq α] [∀ n, DecidableEq (L.Functions n)] : DecidableEq (L.Term α)
| .var a, .var b => decidable_of_iff (a = b) <| by simp
| @Term.func _ _ m f xs, @Term.func _ _ n g ys =>
if h : m = n then
letI : DecidableEq (L.Term α) := instDecidableEq
decidable_of_iff (f = h ▸ g ∧ ∀ i : Fin m, xs i = ys (Fin.cast h i)) <| by
subst h
simp [funext_iff]
else
.isFalse <| by simp [h]
| .var _, .func _ _ | .func _ _, .var _ => .isFalse <| by simp
open Finset
/-- The `Finset` of variables used in a given term. -/
@[simp]
def varFinset [DecidableEq α] : L.Term α → Finset α
| var i => {i}
| func _f ts => univ.biUnion fun i => (ts i).varFinset
/-- The `Finset` of variables from the left side of a sum used in a given term. -/
@[simp]
def varFinsetLeft [DecidableEq α] : L.Term (α ⊕ β) → Finset α
| var (Sum.inl i) => {i}
| var (Sum.inr _i) => ∅
| func _f ts => univ.biUnion fun i => (ts i).varFinsetLeft
/-- Relabels a term's variables along a particular function. -/
@[simp]
def relabel (g : α → β) : L.Term α → L.Term β
| var i => var (g i)
| func f ts => func f fun {i} => (ts i).relabel g
theorem relabel_id (t : L.Term α) : t.relabel id = t := by
induction t with
| var => rfl
| func _ _ ih => simp [ih]
@[simp]
theorem relabel_id_eq_id : (Term.relabel id : L.Term α → L.Term α) = id :=
funext relabel_id
@[simp]
theorem relabel_relabel (f : α → β) (g : β → γ) (t : L.Term α) :
(t.relabel f).relabel g = t.relabel (g ∘ f) := by
induction t with
| var => rfl
| func _ _ ih => simp [ih]
@[simp]
theorem relabel_comp_relabel (f : α → β) (g : β → γ) :
(Term.relabel g ∘ Term.relabel f : L.Term α → L.Term γ) = Term.relabel (g ∘ f) :=
funext (relabel_relabel f g)
/-- Relabels a term's variables along a bijection. -/
@[simps]
def relabelEquiv (g : α ≃ β) : L.Term α ≃ L.Term β :=
⟨relabel g, relabel g.symm, fun t => by simp, fun t => by simp⟩
/-- Restricts a term to use only a set of the given variables. -/
def restrictVar [DecidableEq α] : ∀ (t : L.Term α) (_f : t.varFinset → β), L.Term β
| var a, f => var (f ⟨a, mem_singleton_self a⟩)
| func F ts, f =>
func F fun i => (ts i).restrictVar (f ∘ Set.inclusion
(subset_biUnion_of_mem (fun i => varFinset (ts i)) (mem_univ i)))
/-- Restricts a term to use only a set of the given variables on the left side of a sum. -/
def restrictVarLeft [DecidableEq α] {γ : Type*} :
∀ (t : L.Term (α ⊕ γ)) (_f : t.varFinsetLeft → β), L.Term (β ⊕ γ)
| var (Sum.inl a), f => var (Sum.inl (f ⟨a, mem_singleton_self a⟩))
| var (Sum.inr a), _f => var (Sum.inr a)
| func F ts, f =>
func F fun i =>
(ts i).restrictVarLeft (f ∘ Set.inclusion (subset_biUnion_of_mem
(fun i => varFinsetLeft (ts i)) (mem_univ i)))
end Term
/-- The representation of a constant symbol as a term. -/
def Constants.term (c : L.Constants) : L.Term α :=
func c default
/-- Applies a unary function to a term. -/
def Functions.apply₁ (f : L.Functions 1) (t : L.Term α) : L.Term α :=
func f ![t]
/-- Applies a binary function to two terms. -/
def Functions.apply₂ (f : L.Functions 2) (t₁ t₂ : L.Term α) : L.Term α :=
func f ![t₁, t₂]
namespace Term
/-- Sends a term with constants to a term with extra variables. -/
@[simp]
def constantsToVars : L[[γ]].Term α → L.Term (γ ⊕ α)
| var a => var (Sum.inr a)
| @func _ _ 0 f ts =>
Sum.casesOn f (fun f => func f fun i => (ts i).constantsToVars) fun c => var (Sum.inl c)
| @func _ _ (_n + 1) f ts =>
Sum.casesOn f (fun f => func f fun i => (ts i).constantsToVars) fun c => isEmptyElim c
/-- Sends a term with extra variables to a term with constants. -/
@[simp]
def varsToConstants : L.Term (γ ⊕ α) → L[[γ]].Term α
| var (Sum.inr a) => var a
| var (Sum.inl c) => Constants.term (Sum.inr c)
| func f ts => func (Sum.inl f) fun i => (ts i).varsToConstants
/-- A bijection between terms with constants and terms with extra variables. -/
@[simps]
def constantsVarsEquiv : L[[γ]].Term α ≃ L.Term (γ ⊕ α) :=
⟨constantsToVars, varsToConstants, by
intro t
induction t with
| var => rfl
| @func n f _ ih =>
cases n
· cases f
· simp [constantsToVars, varsToConstants, ih]
· simp [constantsToVars, varsToConstants, Constants.term, eq_iff_true_of_subsingleton]
· obtain - | f := f
· simp [constantsToVars, varsToConstants, ih]
· exact isEmptyElim f, by
intro t
induction t with
| var x => cases x <;> rfl
| @func n f _ ih => cases n <;> · simp [varsToConstants, constantsToVars, ih]⟩
/-- A bijection between terms with constants and terms with extra variables. -/
def constantsVarsEquivLeft : L[[γ]].Term (α ⊕ β) ≃ L.Term ((γ ⊕ α) ⊕ β) :=
constantsVarsEquiv.trans (relabelEquiv (Equiv.sumAssoc _ _ _)).symm
@[simp]
theorem constantsVarsEquivLeft_apply (t : L[[γ]].Term (α ⊕ β)) :
constantsVarsEquivLeft t = (constantsToVars t).relabel (Equiv.sumAssoc _ _ _).symm :=
rfl
@[simp]
theorem constantsVarsEquivLeft_symm_apply (t : L.Term ((γ ⊕ α) ⊕ β)) :
constantsVarsEquivLeft.symm t = varsToConstants (t.relabel (Equiv.sumAssoc _ _ _)) :=
rfl
instance inhabitedOfVar [Inhabited α] : Inhabited (L.Term α) :=
⟨var default⟩
instance inhabitedOfConstant [Inhabited L.Constants] : Inhabited (L.Term α) :=
⟨(default : L.Constants).term⟩
/-- Raises all of the `Fin`-indexed variables of a term greater than or equal to `m` by `n'`. -/
def liftAt {n : ℕ} (n' m : ℕ) : L.Term (α ⊕ (Fin n)) → L.Term (α ⊕ (Fin (n + n'))) :=
relabel (Sum.map id fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n')
/-- Substitutes the variables in a given term with terms. -/
@[simp]
def subst : L.Term α → (α → L.Term β) → L.Term β
| var a, tf => tf a
| func f ts, tf => func f fun i => (ts i).subst tf
end Term
/-- `&n` is notation for the `n`-th free variable of a bounded formula. -/
scoped[FirstOrder] prefix:arg "&" => FirstOrder.Language.Term.var ∘ Sum.inr
namespace LHom
open Term
/-- Maps a term's symbols along a language map. -/
@[simp]
def onTerm (φ : L →ᴸ L') : L.Term α → L'.Term α
| var i => var i
| func f ts => func (φ.onFunction f) fun i => onTerm φ (ts i)
@[simp]
theorem id_onTerm : ((LHom.id L).onTerm : L.Term α → L.Term α) = id := by
ext t
induction t with
| var => rfl
| func _ _ ih => simp_rw [onTerm, ih]; rfl
@[simp]
theorem comp_onTerm {L'' : Language} (φ : L' →ᴸ L'') (ψ : L →ᴸ L') :
((φ.comp ψ).onTerm : L.Term α → L''.Term α) = φ.onTerm ∘ ψ.onTerm := by
ext t
induction t with
| var => rfl
| func _ _ ih => simp_rw [onTerm, ih]; rfl
end LHom
/-- Maps a term's symbols along a language equivalence. -/
@[simps]
| def LEquiv.onTerm (φ : L ≃ᴸ L') : L.Term α ≃ L'.Term α where
toFun := φ.toLHom.onTerm
invFun := φ.invLHom.onTerm
left_inv := by
rw [Function.leftInverse_iff_comp, ← LHom.comp_onTerm, φ.left_inv, LHom.id_onTerm]
right_inv := by
| Mathlib/ModelTheory/Syntax.lean | 274 | 279 |
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Control.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Option.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.List.Monad
import Mathlib.Logic.OpClass
import Mathlib.Logic.Unique
import Mathlib.Order.Basic
import Mathlib.Tactic.Common
/-!
# Basic properties of lists
-/
assert_not_exists GroupWithZero
assert_not_exists Lattice
assert_not_exists Prod.swap_eq_iff_eq_swap
assert_not_exists Ring
assert_not_exists Set.range
open Function
open Nat hiding one_pos
namespace List
universe u v w
variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α}
/-- There is only one list of an empty type -/
instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) :=
{ instInhabitedList with
uniq := fun l =>
match l with
| [] => rfl
| a :: _ => isEmptyElim a }
instance : Std.LawfulIdentity (α := List α) Append.append [] where
left_id := nil_append
right_id := append_nil
instance : Std.Associative (α := List α) Append.append where
assoc := append_assoc
@[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq
theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1
theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } :=
Set.ext fun _ => mem_cons
/-! ### mem -/
theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α]
{a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by
by_cases hab : a = b
· exact Or.inl hab
· exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩))
lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by
rw [mem_cons, mem_singleton]
-- The simpNF linter says that the LHS can be simplified via `List.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[simp 1100, nolint simpNF]
theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} :
f a ∈ map f l ↔ a ∈ l :=
⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩
@[simp]
theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α}
(hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l :=
⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩
theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} :
a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff]
/-! ### length -/
alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff
theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] :=
⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩
theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t
| [], H => absurd H.symm <| succ_ne_zero n
| h :: t, _ => ⟨h, t, rfl⟩
@[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by
constructor
· intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl
· intros hα l1 l2 hl
induction l1 generalizing l2 <;> cases l2
· rfl
· cases hl
· cases hl
· next ih _ _ =>
congr
· subsingleton
· apply ih; simpa using hl
@[simp default+1] -- Raise priority above `length_injective_iff`.
lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) :=
length_injective_iff.mpr inferInstance
theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] :=
⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩
theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] :=
⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩
/-! ### set-theoretic notation of lists -/
instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩
instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩
instance [DecidableEq α] : LawfulSingleton α (List α) :=
{ insert_empty_eq := fun x =>
show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil }
theorem singleton_eq (x : α) : ({x} : List α) = [x] :=
rfl
theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) :
Insert.insert x l = x :: l :=
insert_of_not_mem h
theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l :=
insert_of_mem h
theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by
rw [insert_neg, singleton_eq]
rwa [singleton_eq, mem_singleton]
/-! ### bounded quantifiers over lists -/
theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) :
∀ x ∈ l, p x := (forall_mem_cons.1 h).2
theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x :=
⟨a, mem_cons_self, h⟩
theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) →
∃ x ∈ a :: l, p x :=
fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩
theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) →
p a ∨ ∃ x ∈ l, p x :=
fun ⟨x, xal, px⟩ =>
Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px)
fun h : x ∈ l => Or.inr ⟨x, h, px⟩
theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) :
(∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x :=
Iff.intro or_exists_of_exists_mem_cons fun h =>
Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists
/-! ### list subset -/
theorem cons_subset_of_subset_of_mem {a : α} {l m : List α}
(ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m :=
cons_subset.2 ⟨ainm, lsubm⟩
theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) :
l₁ ++ l₂ ⊆ l :=
fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _)
theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) :
map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by
refine ⟨?_, map_subset f⟩; intro h2 x hx
rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩
cases h hxx'; exact hx'
/-! ### append -/
theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ :=
rfl
theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t :=
fun _ _ ↦ append_cancel_left
theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t :=
fun _ _ ↦ append_cancel_right
/-! ### replicate -/
theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a
| [] => by simp
| (b :: l) => by simp [eq_replicate_length, replicate_succ]
theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by
rw [replicate_append_replicate]
theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h =>
mem_singleton.2 (eq_of_mem_replicate h)
theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by
simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left']
theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) :=
fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩
theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) :
replicate n a = replicate n b ↔ a = b :=
(replicate_right_injective hn).eq_iff
theorem replicate_right_inj' {a b : α} : ∀ {n},
replicate n a = replicate n b ↔ n = 0 ∨ a = b
| 0 => by simp
| n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or]
theorem replicate_left_injective (a : α) : Injective (replicate · a) :=
LeftInverse.injective (length_replicate (n := ·))
theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m :=
(replicate_left_injective a).eq_iff
@[simp]
theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.head? = l.head? := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
induction l <;> simp [replicate]
@[simp]
theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) :
(List.replicate n l).flatten.getLast? = l.getLast? := by
rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate,
List.reverse_replicate, head?_flatten_replicate h]
/-! ### pure -/
theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp
/-! ### bind -/
@[simp]
theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f :=
rfl
/-! ### concat -/
/-! ### reverse -/
theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by
simp only [reverse_cons, concat_eq_append]
theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by
rw [reverse_append]; rfl
@[simp]
theorem reverse_singleton (a : α) : reverse [a] = [a] :=
rfl
@[simp]
theorem reverse_involutive : Involutive (@reverse α) :=
reverse_reverse
@[simp]
theorem reverse_injective : Injective (@reverse α) :=
reverse_involutive.injective
theorem reverse_surjective : Surjective (@reverse α) :=
reverse_involutive.surjective
theorem reverse_bijective : Bijective (@reverse α) :=
reverse_involutive.bijective
theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by
simp only [concat_eq_append, reverse_cons, reverse_reverse]
theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) :
map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by
simp only [reverseAux_eq, map_append, map_reverse]
-- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self`
@[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where
mp := l₁.reverse_perm.symm.trans
mpr := l₁.reverse_perm.trans
@[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where
mp hl := hl.trans l₂.reverse_perm
mpr hl := hl.trans l₂.reverse_perm.symm
/-! ### getLast -/
attribute [simp] getLast_cons
theorem getLast_append_singleton {a : α} (l : List α) :
getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by
simp [getLast_append]
theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) :
getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by
induction l₁ with
| nil => simp
| cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih
@[deprecated (since := "2025-02-06")]
alias getLast_append' := getLast_append_of_right_ne_nil
theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by
simp
@[simp]
theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl
@[simp]
theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) :
getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) :=
rfl
theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l
| [], h => absurd rfl h
| [_], _ => rfl
| a :: b :: l, h => by
rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)]
congr
exact dropLast_append_getLast (cons_ne_nil b l)
theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) :
getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl
theorem getLast_replicate_succ (m : ℕ) (a : α) :
(replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by
simp only [replicate_succ']
exact getLast_append_singleton _
@[deprecated (since := "2025-02-07")]
alias getLast_filter' := getLast_filter_of_pos
/-! ### getLast? -/
theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h
| [], x, hx => False.elim <| by simp at hx
| [a], x, hx =>
have : a = x := by simpa using hx
this ▸ ⟨cons_ne_nil a [], rfl⟩
| a :: b :: l, x, hx => by
rw [getLast?_cons_cons] at hx
rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩
use cons_ne_nil _ _
assumption
theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
| [], h => (h rfl).elim
| [_], _ => rfl
| _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _)
theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
| [], _ => by contradiction
| _ :: _, h => h
theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l
| [], a, ha => (Option.not_mem_none a ha).elim
| [a], _, rfl => rfl
| a :: b :: l, c, hc => by
rw [getLast?_cons_cons] at hc
rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc]
theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget
| [] => by simp [getLastI, Inhabited.default]
| [_] => rfl
| [_, _] => rfl
| [_, _, _] => rfl
| _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)]
theorem getLast?_append_cons :
∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂)
| [], _, _ => rfl
| [_], _, _ => rfl
| b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons,
← cons_append, getLast?_append_cons (c :: l₁)]
theorem getLast?_append_of_ne_nil (l₁ : List α) :
∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂
| [], hl₂ => by contradiction
| b :: l₂, _ => getLast?_append_cons l₁ b l₂
theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) :
x ∈ (l₁ ++ l₂).getLast? := by
cases l₂
· contradiction
· rw [List.getLast?_append_cons]
exact h
/-! ### head(!?) and tail -/
@[simp]
theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl
@[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by
cases x <;> simp at h ⊢
theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) :
l.head hl = l[0]'(length_pos_iff.2 hl) :=
(getElem_zero _).symm
theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl
theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩
theorem surjective_head? : Surjective (@head? α) :=
Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩
theorem surjective_tail : Surjective (@tail α)
| [] => ⟨[], rfl⟩
| a :: l => ⟨a :: a :: l, rfl⟩
theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l
| [], h => (Option.not_mem_none _ h).elim
| a :: l, h => by
simp only [head?, Option.mem_def, Option.some_inj] at h
exact h ▸ rfl
@[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl
@[simp]
theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) :
head! (s ++ t) = head! s := by
induction s
· contradiction
· rfl
theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) :
x ∈ (s ++ t).head? := by
cases s
· contradiction
· exact h
theorem head?_append_of_ne_nil :
∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁
| _ :: _, _, _ => rfl
theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) :
tail (l ++ [a]) = tail l ++ [a] := by
induction l
· contradiction
· rw [tail, cons_append, tail]
theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l
| [], a, h => by contradiction
| b :: l, a, h => by
simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h
simp [h]
theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l
| [], h => by contradiction
| _ :: _, _ => rfl
theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l :=
cons_head?_tail (head!_mem_head? h)
theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by
have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self
rwa [cons_head!_tail h] at h'
theorem get_eq_getElem? (l : List α) (i : Fin l.length) :
l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by
simp
@[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem?
theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} :
(∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by
simp only [mem_iff_getElem]
exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩
theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} :
(∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by
simp [mem_iff_getElem, @forall_swap α]
theorem get_tail (l : List α) (i) (h : i < l.tail.length)
(h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) :
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by
cases l <;> [cases h; rfl]
/-! ### sublists -/
attribute [refl] List.Sublist.refl
theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ :=
Sublist.cons₂ _ s
lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by
constructor
· rintro (_ | _)
· exact Or.inl ‹_›
· exact Or.inr ⟨rfl, ‹_›⟩
· rintro (h | ⟨rfl, h⟩)
· exact h.cons _
· rwa [cons_sublist_cons]
theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _
@[deprecated (since := "2025-02-07")]
alias sublist_nil_iff_eq_nil := sublist_nil
@[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by
constructor <;> rintro (_ | _) <;> aesop
theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ :=
s₁.eq_of_length_le s₂.length_le
/-- If the first element of two lists are different, then a sublist relation can be reduced. -/
theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ :=
match h₁, h₂ with
| _, .cons _ h => h
/-! ### indexOf -/
section IndexOf
variable [DecidableEq α]
theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0
| e => by rw [← e]; exact idxOf_cons_self
@[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq
@[simp]
theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l)
| h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h]
@[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne
theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by
induction l with
| nil => exact iff_of_true rfl not_mem_nil
| cons b l ih =>
simp only [length, mem_cons, idxOf_cons, eq_comm]
rw [cond_eq_if]
split_ifs with h <;> simp at h
· exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm
· simp only [Ne.symm h, false_or]
rw [← ih]
exact succ_inj
@[simp]
theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l :=
idxOf_eq_length_iff.2
@[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem
theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by
induction l with | nil => rfl | cons b l ih => ?_
simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq]
by_cases h : b = a
· rw [if_pos h]; exact Nat.zero_le _
· rw [if_neg h]; exact succ_le_succ ih
@[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length
theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l :=
⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al,
fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩
@[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff
theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by
induction l₁ with
| nil =>
exfalso
exact not_mem_nil h
| cons d₁ t₁ ih =>
rw [List.cons_append]
by_cases hh : d₁ = a
· iterate 2 rw [idxOf_cons_eq _ hh]
rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem
theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) :
idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by
induction l₁ with
| nil => rw [List.nil_append, List.length, Nat.zero_add]
| cons d₁ t₁ ih =>
rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length,
ih (not_mem_of_not_mem_cons h), Nat.succ_add]
@[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem
end IndexOf
/-! ### nth element -/
section deprecated
@[simp]
theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl
/-- A version of `getElem_map` that can be used for rewriting. -/
theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} :
f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _)
theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) :
l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) :=
(getLast_eq_getElem _).symm
theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) :
(l.drop n).take 1 = [l.get ⟨n, h⟩] := by
rw [drop_eq_getElem_cons h, take, take]
simp
theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) :
l₁ = l₂ := by
apply ext_getElem?
intro n
rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn
· exact h' n hn
· simp_all [Nat.max_le, getElem?_eq_none]
@[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?'
@[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff
theorem ext_get_iff {l₁ l₂ : List α} :
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by
constructor
· rintro rfl
exact ⟨rfl, fun _ _ _ ↦ rfl⟩
· intro ⟨h₁, h₂⟩
exact ext_get h₁ h₂
theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔
∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? :=
⟨by rintro rfl _ _; rfl, ext_getElem?'⟩
@[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff'
/-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`,
then the lists are equal. -/
theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) :
l₁ = l₂ :=
ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n
@[simp]
theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length),
l[idxOf a l] = a
| b :: l, h => by
by_cases h' : b = a <;>
simp [h', if_pos, if_false, getElem_idxOf]
@[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf
-- This is incorrectly named and should be `get_idxOf`;
-- this already exists, so will require a deprecation dance.
theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by
simp
@[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get
@[simp]
theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) :
l[idxOf a l]? = some a := by
rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)]
@[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf
@[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf
@[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf
theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) :
idxOf x l = idxOf y l ↔ x = y :=
⟨fun h => by
have x_eq_y :
get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ =
get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by
simp only [h]
simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩
@[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj
theorem get_reverse' (l : List α) (n) (hn') :
l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by
simp
theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by
refine ext_get (by convert h) fun n h₁ h₂ => ?_
simp
congr
omega
end deprecated
@[simp]
theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α)
(hj : j < (l.set i a).length) :
(l.set i a)[j] = l[j]'(by simpa using hj) := by
rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h,
List.getElem?_eq_getElem]
/-! ### map -/
-- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged
-- `simp` in Core
-- TODO: Upstream the tagging to Core?
attribute [simp] map_const'
theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l :=
.symm <| map_eq_flatMap ..
theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) :
l.flatMap f = l.flatMap g :=
(congr_arg List.flatten <| map_congr_left h :)
theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) :
f a <:+: as.flatMap f :=
infix_of_mem_flatten (mem_map_of_mem h)
@[simp]
theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l :=
rfl
/-- A single `List.map` of a composition of functions is equal to
composing a `List.map` with another `List.map`, fully applied.
This is the reverse direction of `List.map_map`.
-/
theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) :=
map_map.symm
/-- Composing a `List.map` with another `List.map` is equal to
a single `List.map` of composed functions.
-/
@[simp]
theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by
ext l; rw [comp_map, Function.comp_apply]
section map_bijectivity
theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) :
LeftInverse (map f) (map g)
| [] => by simp_rw [map_nil]
| x :: xs => by simp_rw [map_cons, h x, h.list_map xs]
nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α}
(h : RightInverse f g) : RightInverse (map f) (map g) :=
h.list_map
nonrec theorem _root_.Function.Involutive.list_map {f : α → α}
(h : Involutive f) : Involutive (map f) :=
Function.LeftInverse.list_map h
@[simp]
theorem map_leftInverse_iff {f : α → β} {g : β → α} :
LeftInverse (map f) (map g) ↔ LeftInverse f g :=
⟨fun h x => by injection h [x], (·.list_map)⟩
@[simp]
theorem map_rightInverse_iff {f : α → β} {g : β → α} :
RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff
@[simp]
theorem map_involutive_iff {f : α → α} :
Involutive (map f) ↔ Involutive f := map_leftInverse_iff
theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) :
Injective (map f)
| [], [], _ => rfl
| x :: xs, y :: ys, hxy => by
injection hxy with hxy hxys
rw [h hxy, h.list_map hxys]
@[simp]
theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by
refine ⟨fun h x y hxy => ?_, (·.list_map)⟩
suffices [x] = [y] by simpa using this
apply h
simp [hxy]
theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) :
Surjective (map f) :=
let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective
@[simp]
theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by
refine ⟨fun h x => ?_, (·.list_map)⟩
let ⟨[y], hxy⟩ := h [x]
exact ⟨_, List.singleton_injective hxy⟩
theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) :=
⟨h.1.list_map, h.2.list_map⟩
@[simp]
theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by
simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff]
end map_bijectivity
theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) :
b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h
/-- `eq_nil_or_concat` in simp normal form -/
lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by
simpa using l.eq_nil_or_concat
/-! ### foldl, foldr -/
theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) :
foldl f a l = foldl g a l := by
induction l generalizing a with
| nil => rfl
| cons hd tl ih =>
unfold foldl
rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self]
theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) :
foldr f b l = foldr g b l := by
induction l with | nil => rfl | cons hd tl ih => ?_
simp only [mem_cons, or_imp, forall_and, forall_eq] at H
simp only [foldr, ih H.2, H.1]
theorem foldl_concat
(f : β → α → β) (b : β) (x : α) (xs : List α) :
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by
simp only [List.foldl_append, List.foldl]
theorem foldr_concat
(f : α → β → β) (b : β) (x : α) (xs : List α) :
List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by
simp only [List.foldr_append, List.foldr]
theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a
| [] => rfl
| b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l]
theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b
| [] => rfl
| a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a]
@[simp]
theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a :=
foldl_fixed' fun _ => rfl
@[simp]
theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b :=
foldr_fixed' fun _ => rfl
@[deprecated foldr_cons_nil (since := "2025-02-10")]
theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil
theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by
simp
theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) :
foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) :=
Eq.symm <| by
revert a b
induction l <;> intros <;> [rfl; simp only [*, foldl]]
theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) :
foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by
revert a
induction l <;> intros <;> [rfl; simp only [*, foldr]]
theorem injective_foldl_comp {l : List (α → α)} {f : α → α}
(hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) :
Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by
induction l generalizing f with
| nil => exact hf
| cons lh lt l_ih =>
apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h)
apply Function.Injective.comp hf
apply hl _ mem_cons_self
/-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them:
`l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`.
Assume the designated element `a₂` is present in neither `x₁` nor `z₁`.
We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal
(`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/
lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α}
(notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) :
x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by
constructor
· simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons]
rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ |
⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all
· rintro ⟨rfl, rfl, rfl⟩
rfl
section FoldlEqFoldr
-- foldl and foldr coincide when f is commutative and associative
variable {f : α → α → α}
theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] :
∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l)
| _, _, nil => rfl
| a, b, c :: l => by
simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]
rw [hassoc.assoc]
theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] :
∀ a b l, foldl f a (b :: l) = f b (foldl f a l)
| a, b, nil => hcomm.comm a b
| a, b, c :: l => by
simp only [foldl_cons]
have : RightCommutative f := inferInstance
rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons]
theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] :
∀ a l, foldl f a l = foldr f a l
| _, nil => rfl
| a, b :: l => by
simp only [foldr_cons, foldl_eq_of_comm_of_assoc]
rw [foldl_eq_foldr a l]
end FoldlEqFoldr
section FoldlEqFoldlr'
variable {f : α → β → α}
variable (hf : ∀ a b c, f (f a b) c = f (f a c) b)
include hf
theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b
| _, _, [] => rfl
| a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf]
theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l
| _, [] => rfl
| a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl
end FoldlEqFoldlr'
section FoldlEqFoldlr'
variable {f : α → β → β}
theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) :
∀ a b l, foldr f a (b :: l) = foldr f (f b a) l
| _, _, [] => rfl
| a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl
end FoldlEqFoldlr'
section
variable {op : α → α → α} [ha : Std.Associative op]
/-- Notation for `op a b`. -/
local notation a " ⋆ " b => op a b
/-- Notation for `foldl op a l`. -/
local notation l " <*> " a => foldl op a l
theorem foldl_op_eq_op_foldr_assoc :
∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂
| [], _, _ => rfl
| a :: l, a₁, a₂ => by
simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc]
variable [hc : Std.Commutative op]
theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by
rw [foldl_cons, hc.comm, foldl_assoc]
end
/-! ### foldlM, foldrM, mapM -/
section FoldlMFoldrM
variable {m : Type v → Type w} [Monad m]
variable [LawfulMonad m]
theorem foldrM_eq_foldr (f : α → β → m β) (b l) :
foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*]
theorem foldlM_eq_foldl (f : β → α → m β) (b l) :
List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by
suffices h :
∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l
by simp [← h (pure b)]
induction l with
| nil => intro; simp
| cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm]
end FoldlMFoldrM
/-! ### intersperse -/
@[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single
@[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂
/-! ### map for partial functions -/
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) :
SizeOf.sizeOf x < SizeOf.sizeOf l := by
induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec]
· omega
· specialize ih ‹_›
omega
/-! ### filter -/
theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) :
l.length = (l.filter f).length + (l.filter (! f ·)).length := by
simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true,
Bool.decide_eq_false]
/-! ### filterMap -/
theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) :
l.filterMap f = l.flatMap fun a ↦ (f a).toList := by
induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons]
rcases f a <;> simp [ih]
theorem filterMap_congr {f g : α → Option β} {l : List α}
(h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by
induction l <;> simp_all [filterMap_cons]
theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} :
l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where
mp := by
induction l with | nil => simp | cons a l ih => ?_
rcases ha : f a with - | b <;> simp [ha, filterMap_cons]
· intro h
simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff]
using List.length_filterMap_le f l
· rintro rfl h
exact ⟨rfl, ih h⟩
mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _)
/-! ### filter -/
section Filter
variable {p : α → Bool}
theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] :=
rfl
theorem filter_eq_foldr (p : α → Bool) (l : List α) :
filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by
induction l <;> simp [*, filter]; rfl
#adaptation_note /-- nightly-2024-07-27
This has to be temporarily renamed to avoid an unintentional collision.
The prime should be removed at nightly-2024-07-27. -/
@[simp]
theorem filter_subset' (l : List α) : filter p l ⊆ l :=
filter_sublist.subset
theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2
theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l :=
filter_subset' l h
theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l :=
mem_filter.2 ⟨h₁, h₂⟩
@[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset
variable (p)
theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄
(h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by
induction l with
| nil => rfl
| cons hd tl IH =>
by_cases hp : p hd
· rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)]
exact IH.cons_cons hd
· rw [filter_cons_of_neg hp]
by_cases hq : q hd
· rw [filter_cons_of_pos hq]
exact sublist_cons_of_sublist hd IH
· rw [filter_cons_of_neg hq]
exact IH
lemma map_filter {f : α → β} (hf : Injective f) (l : List α)
[DecidablePred fun b => ∃ a, p a ∧ f a = b] :
(l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [comp_def, filter_map, hf.eq_iff]
@[deprecated (since := "2025-02-07")] alias map_filter' := map_filter
lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] :
l.attach.filter p =
(l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by
classical
refine map_injective_iff.2 Subtype.coe_injective ?_
simp [comp_def, map_filter _ Subtype.coe_injective]
lemma filter_attach (l : List α) (p : α → Bool) :
(l.attach.filter fun x => p x : List {x // x ∈ l}) =
(l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) :=
map_injective_iff.2 Subtype.coe_injective <| by
simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val),
← filter_map, attach_map_subtype_val]
lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by
simp [Bool.and_comm]
@[simp]
theorem filter_true (l : List α) :
filter (fun _ => true) l = l := by induction l <;> simp [*, filter]
@[simp]
theorem filter_false (l : List α) :
filter (fun _ => false) l = [] := by induction l <;> simp [*, filter]
end Filter
/-! ### eraseP -/
section eraseP
variable {p : α → Bool}
@[simp]
theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) :
(l.eraseP p).length + 1 = l.length := by
let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa
rw [h₂, h₁, length_append, length_append]
rfl
end eraseP
/-! ### erase -/
section Erase
variable [DecidableEq α]
@[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) :
(l.erase a).length + 1 = l.length := by
rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)]
theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) :
map f (l.erase a) = (map f l).erase (f a) := by
have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff]
rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl
theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by
induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]]
theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) :
Perm (l.erase l[i]) (l.eraseIdx i) := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
have hi' : i < l.length := by simpa using hi
if ha : a = l[i] then
simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi'))
else
simpa [ha] using IH hi'
theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) :
(l.eraseIdx i).length + 1 = l.length := by
rw [length_eraseIdx]
split <;> omega
end Erase
/-! ### diff -/
section Diff
variable [DecidableEq α]
@[simp]
theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} :
map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by
simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj]
@[deprecated (since := "2025-04-10")]
alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist
end Diff
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
/-! ### Forall -/
section Forall
variable {p q : α → Prop} {l : List α}
@[simp]
theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l
| [] => (and_iff_left_of_imp fun _ ↦ trivial).symm
| _ :: _ => Iff.rfl
@[simp]
theorem forall_append {p : α → Prop} : ∀ {xs ys : List α},
Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys
| [] => by simp
| _ :: _ => by simp [forall_append, and_assoc]
theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x
| [] => (iff_true_intro <| forall_mem_nil _).symm
| x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem]
theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l
| [] => id
| x :: l => by
simp only [forall_cons, and_imp]
rw [← and_imp]
exact And.imp (h x) (Forall.imp h)
@[simp]
theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by
induction l <;> simp [*]
instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ =>
decidable_of_iff' _ forall_iff_forall_mem
end Forall
/-! ### Miscellaneous lemmas -/
theorem get_attach (l : List α) (i) :
(l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp
section Disjoint
/-- The images of disjoint lists under a partially defined map are disjoint -/
theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α}
(hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a)
(hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a')
(h : Disjoint s t) :
Disjoint (s.pmap f hs) (t.pmap f ht) := by
simp only [Disjoint, mem_pmap]
rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩
apply h ha
rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm]
/-- The images of disjoint lists under an injective map are disjoint -/
theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f)
(h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by
rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)]
exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h
alias Disjoint.map := disjoint_map
theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) :
Disjoint s t := fun _a has hat ↦
h (mem_map_of_mem has) (mem_map_of_mem hat)
theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩
theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l₁ l ↔ Disjoint l₂ l := by
simp_rw [List.disjoint_left, p.mem_iff]
theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) :
Disjoint l l₁ ↔ Disjoint l l₂ := by
simp_rw [List.disjoint_right, p.mem_iff]
@[simp]
theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_left
@[simp]
theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ :=
reverse_perm _ |>.disjoint_right
end Disjoint
section lookup
variable [BEq α] [LawfulBEq α]
lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) :
lookup a (as.map fun x => (x, f x)) = some (f a) := by
induction as with
| nil => exact (not_mem_nil h).elim
| cons a' as ih =>
by_cases ha : a = a'
· simp [ha, lookup_cons]
· simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h)
end lookup
section range'
@[simp]
lemma range'_0 (a b : ℕ) :
range' a b 0 = replicate b a := by
induction b with
| zero => simp
| succ b ih => simp [range'_succ, ih, replicate_succ]
lemma left_le_of_mem_range' {a b s x : ℕ}
(hx : x ∈ List.range' a b s) : a ≤ x := by
obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx
exact le_add_right a (s * i)
end range'
end List
| Mathlib/Data/List/Basic.lean | 2,720 | 2,723 | |
/-
Copyright (c) 2023 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Yaël Dillies
-/
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Data.Set.Function
import Mathlib.Order.Directed
/-!
# Monotone functions on intervals
This file shows many variants of the fact that a monotone function `f` sends an interval with
endpoints `a` and `b` to the interval with endpoints `f a` and `f b`.
-/
variable {α β : Type*} {f : α → β}
open Set
section Preorder
variable [Preorder α] [Preorder β] {a b : α}
lemma MonotoneOn.mapsTo_Ici (h : MonotoneOn f (Ici a)) : MapsTo f (Ici a) (Ici (f a)) :=
fun _ _ ↦ by aesop
lemma MonotoneOn.mapsTo_Iic (h : MonotoneOn f (Iic b)) : MapsTo f (Iic b) (Iic (f b)) :=
fun _ _ ↦ by aesop
lemma MonotoneOn.mapsTo_Icc (h : MonotoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f a) (f b)) :=
fun _c hc ↦
⟨h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1, h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2⟩
lemma AntitoneOn.mapsTo_Ici (h : AntitoneOn f (Ici a)) : MapsTo f (Ici a) (Iic (f a)) :=
fun _ _ ↦ by aesop
lemma AntitoneOn.mapsTo_Iic (h : AntitoneOn f (Iic b)) : MapsTo f (Iic b) (Ici (f b)) :=
fun _ _ ↦ by aesop
lemma AntitoneOn.mapsTo_Icc (h : AntitoneOn f (Icc a b)) : MapsTo f (Icc a b) (Icc (f b) (f a)) :=
fun _c hc ↦
⟨h hc (right_mem_Icc.2 <| hc.1.trans hc.2) hc.2, h (left_mem_Icc.2 <| hc.1.trans hc.2) hc hc.1⟩
lemma StrictMonoOn.mapsTo_Ioi (h : StrictMonoOn f (Ici a)) : MapsTo f (Ioi a) (Ioi (f a)) :=
fun _c hc ↦ h le_rfl hc.le hc
lemma StrictMonoOn.mapsTo_Iio (h : StrictMonoOn f (Iic b)) : MapsTo f (Iio b) (Iio (f b)) :=
fun _c hc ↦ h hc.le le_rfl hc
lemma StrictMonoOn.mapsTo_Ioo (h : StrictMonoOn f (Icc a b)) :
MapsTo f (Ioo a b) (Ioo (f a) (f b)) :=
fun _c hc ↦
⟨h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1,
h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2⟩
lemma StrictAntiOn.mapsTo_Ioi (h : StrictAntiOn f (Ici a)) : MapsTo f (Ioi a) (Iio (f a)) :=
fun _c hc ↦ h le_rfl hc.le hc
lemma StrictAntiOn.mapsTo_Iio (h : StrictAntiOn f (Iic b)) : MapsTo f (Iio b) (Ioi (f b)) :=
fun _c hc ↦ h hc.le le_rfl hc
lemma StrictAntiOn.mapsTo_Ioo (h : StrictAntiOn f (Icc a b)) :
MapsTo f (Ioo a b) (Ioo (f b) (f a)) :=
fun _c hc ↦
⟨h (Ioo_subset_Icc_self hc) (right_mem_Icc.2 (hc.1.trans hc.2).le) hc.2,
h (left_mem_Icc.2 (hc.1.trans hc.2).le) (Ioo_subset_Icc_self hc) hc.1⟩
lemma Monotone.mapsTo_Ici (h : Monotone f) : MapsTo f (Ici a) (Ici (f a)) :=
(h.monotoneOn _).mapsTo_Ici
lemma Monotone.mapsTo_Iic (h : Monotone f) : MapsTo f (Iic b) (Iic (f b)) :=
(h.monotoneOn _).mapsTo_Iic
lemma Monotone.mapsTo_Icc (h : Monotone f) : MapsTo f (Icc a b) (Icc (f a) (f b)) :=
(h.monotoneOn _).mapsTo_Icc
lemma Antitone.mapsTo_Ici (h : Antitone f) : MapsTo f (Ici a) (Iic (f a)) :=
(h.antitoneOn _).mapsTo_Ici
lemma Antitone.mapsTo_Iic (h : Antitone f) : MapsTo f (Iic b) (Ici (f b)) :=
(h.antitoneOn _).mapsTo_Iic
lemma Antitone.mapsTo_Icc (h : Antitone f) : MapsTo f (Icc a b) (Icc (f b) (f a)) :=
(h.antitoneOn _).mapsTo_Icc
lemma StrictMono.mapsTo_Ioi (h : StrictMono f) : MapsTo f (Ioi a) (Ioi (f a)) :=
(h.strictMonoOn _).mapsTo_Ioi
lemma StrictMono.mapsTo_Iio (h : StrictMono f) : MapsTo f (Iio b) (Iio (f b)) :=
(h.strictMonoOn _).mapsTo_Iio
lemma StrictMono.mapsTo_Ioo (h : StrictMono f) : MapsTo f (Ioo a b) (Ioo (f a) (f b)) :=
(h.strictMonoOn _).mapsTo_Ioo
lemma StrictAnti.mapsTo_Ioi (h : StrictAnti f) : MapsTo f (Ioi a) (Iio (f a)) :=
(h.strictAntiOn _).mapsTo_Ioi
lemma StrictAnti.mapsTo_Iio (h : StrictAnti f) : MapsTo f (Iio b) (Ioi (f b)) :=
(h.strictAntiOn _).mapsTo_Iio
lemma StrictAnti.mapsTo_Ioo (h : StrictAnti f) : MapsTo f (Ioo a b) (Ioo (f b) (f a)) :=
(h.strictAntiOn _).mapsTo_Ioo
lemma MonotoneOn.image_Ici_subset (h : MonotoneOn f (Ici a)) : f '' Ici a ⊆ Ici (f a) :=
h.mapsTo_Ici.image_subset
lemma MonotoneOn.image_Iic_subset (h : MonotoneOn f (Iic b)) : f '' Iic b ⊆ Iic (f b) :=
h.mapsTo_Iic.image_subset
lemma MonotoneOn.image_Icc_subset (h : MonotoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f a) (f b) :=
h.mapsTo_Icc.image_subset
lemma AntitoneOn.image_Ici_subset (h : AntitoneOn f (Ici a)) : f '' Ici a ⊆ Iic (f a) :=
h.mapsTo_Ici.image_subset
lemma AntitoneOn.image_Iic_subset (h : AntitoneOn f (Iic b)) : f '' Iic b ⊆ Ici (f b) :=
h.mapsTo_Iic.image_subset
lemma AntitoneOn.image_Icc_subset (h : AntitoneOn f (Icc a b)) : f '' Icc a b ⊆ Icc (f b) (f a) :=
h.mapsTo_Icc.image_subset
lemma StrictMonoOn.image_Ioi_subset (h : StrictMonoOn f (Ici a)) : f '' Ioi a ⊆ Ioi (f a) :=
h.mapsTo_Ioi.image_subset
lemma StrictMonoOn.image_Iio_subset (h : StrictMonoOn f (Iic b)) : f '' Iio b ⊆ Iio (f b) :=
h.mapsTo_Iio.image_subset
lemma StrictMonoOn.image_Ioo_subset (h : StrictMonoOn f (Icc a b)) :
f '' Ioo a b ⊆ Ioo (f a) (f b) := h.mapsTo_Ioo.image_subset
lemma StrictAntiOn.image_Ioi_subset (h : StrictAntiOn f (Ici a)) : f '' Ioi a ⊆ Iio (f a) :=
h.mapsTo_Ioi.image_subset
lemma StrictAntiOn.image_Iio_subset (h : StrictAntiOn f (Iic b)) : f '' Iio b ⊆ Ioi (f b) :=
h.mapsTo_Iio.image_subset
lemma StrictAntiOn.image_Ioo_subset (h : StrictAntiOn f (Icc a b)) :
f '' Ioo a b ⊆ Ioo (f b) (f a) := h.mapsTo_Ioo.image_subset
lemma Monotone.image_Ici_subset (h : Monotone f) : f '' Ici a ⊆ Ici (f a) :=
(h.monotoneOn _).image_Ici_subset
lemma Monotone.image_Iic_subset (h : Monotone f) : f '' Iic b ⊆ Iic (f b) :=
(h.monotoneOn _).image_Iic_subset
lemma Monotone.image_Icc_subset (h : Monotone f) : f '' Icc a b ⊆ Icc (f a) (f b) :=
(h.monotoneOn _).image_Icc_subset
lemma Antitone.image_Ici_subset (h : Antitone f) : f '' Ici a ⊆ Iic (f a) :=
(h.antitoneOn _).image_Ici_subset
lemma Antitone.image_Iic_subset (h : Antitone f) : f '' Iic b ⊆ Ici (f b) :=
(h.antitoneOn _).image_Iic_subset
lemma Antitone.image_Icc_subset (h : Antitone f) : f '' Icc a b ⊆ Icc (f b) (f a) :=
(h.antitoneOn _).image_Icc_subset
lemma StrictMono.image_Ioi_subset (h : StrictMono f) : f '' Ioi a ⊆ Ioi (f a) :=
(h.strictMonoOn _).image_Ioi_subset
lemma StrictMono.image_Iio_subset (h : StrictMono f) : f '' Iio b ⊆ Iio (f b) :=
(h.strictMonoOn _).image_Iio_subset
lemma StrictMono.image_Ioo_subset (h : StrictMono f) : f '' Ioo a b ⊆ Ioo (f a) (f b) :=
(h.strictMonoOn _).image_Ioo_subset
lemma StrictAnti.image_Ioi_subset (h : StrictAnti f) : f '' Ioi a ⊆ Iio (f a) :=
(h.strictAntiOn _).image_Ioi_subset
lemma StrictAnti.image_Iio_subset (h : StrictAnti f) : f '' Iio b ⊆ Ioi (f b) :=
(h.strictAntiOn _).image_Iio_subset
lemma StrictAnti.image_Ioo_subset (h : StrictAnti f) : f '' Ioo a b ⊆ Ioo (f b) (f a) :=
(h.strictAntiOn _).image_Ioo_subset
end Preorder
section PartialOrder
variable [PartialOrder α] [Preorder β] {a b : α}
lemma StrictMonoOn.mapsTo_Ico (h : StrictMonoOn f (Icc a b)) :
MapsTo f (Ico a b) (Ico (f a) (f b)) :=
fun _c hc ↦ ⟨h.monotoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1,
h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2⟩
lemma StrictMonoOn.mapsTo_Ioc (h : StrictMonoOn f (Icc a b)) :
MapsTo f (Ioc a b) (Ioc (f a) (f b)) :=
fun _c hc ↦ ⟨h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1,
h.monotoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2⟩
lemma StrictAntiOn.mapsTo_Ico (h : StrictAntiOn f (Icc a b)) :
MapsTo f (Ico a b) (Ioc (f b) (f a)) :=
fun _c hc ↦ ⟨h (Ico_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.trans hc.2.le) hc.2,
h.antitoneOn (left_mem_Icc.2 <| hc.1.trans hc.2.le) (Ico_subset_Icc_self hc) hc.1⟩
lemma StrictAntiOn.mapsTo_Ioc (h : StrictAntiOn f (Icc a b)) :
MapsTo f (Ioc a b) (Ico (f b) (f a)) :=
fun _c hc ↦ ⟨h.antitoneOn (Ioc_subset_Icc_self hc) (right_mem_Icc.2 <| hc.1.le.trans hc.2) hc.2,
h (left_mem_Icc.2 <| hc.1.le.trans hc.2) (Ioc_subset_Icc_self hc) hc.1⟩
lemma StrictMono.mapsTo_Ico (h : StrictMono f) : MapsTo f (Ico a b) (Ico (f a) (f b)) :=
(h.strictMonoOn _).mapsTo_Ico
lemma StrictMono.mapsTo_Ioc (h : StrictMono f) : MapsTo f (Ioc a b) (Ioc (f a) (f b)) :=
(h.strictMonoOn _).mapsTo_Ioc
lemma StrictAnti.mapsTo_Ico (h : StrictAnti f) : MapsTo f (Ico a b) (Ioc (f b) (f a)) :=
(h.strictAntiOn _).mapsTo_Ico
lemma StrictAnti.mapsTo_Ioc (h : StrictAnti f) : MapsTo f (Ioc a b) (Ico (f b) (f a)) :=
(h.strictAntiOn _).mapsTo_Ioc
lemma StrictMonoOn.image_Ico_subset (h : StrictMonoOn f (Icc a b)) :
f '' Ico a b ⊆ Ico (f a) (f b) := h.mapsTo_Ico.image_subset
lemma StrictMonoOn.image_Ioc_subset (h : StrictMonoOn f (Icc a b)) :
f '' Ioc a b ⊆ Ioc (f a) (f b) :=
h.mapsTo_Ioc.image_subset
lemma StrictAntiOn.image_Ico_subset (h : StrictAntiOn f (Icc a b)) :
f '' Ico a b ⊆ Ioc (f b) (f a) := h.mapsTo_Ico.image_subset
lemma StrictAntiOn.image_Ioc_subset (h : StrictAntiOn f (Icc a b)) :
f '' Ioc a b ⊆ Ico (f b) (f a) := h.mapsTo_Ioc.image_subset
lemma StrictMono.image_Ico_subset (h : StrictMono f) : f '' Ico a b ⊆ Ico (f a) (f b) :=
(h.strictMonoOn _).image_Ico_subset
lemma StrictMono.image_Ioc_subset (h : StrictMono f) : f '' Ioc a b ⊆ Ioc (f a) (f b) :=
(h.strictMonoOn _).image_Ioc_subset
lemma StrictAnti.image_Ico_subset (h : StrictAnti f) : f '' Ico a b ⊆ Ioc (f b) (f a) :=
(h.strictAntiOn _).image_Ico_subset
lemma StrictAnti.image_Ioc_subset (h : StrictAnti f) : f '' Ioc a b ⊆ Ico (f b) (f a) :=
(h.strictAntiOn _).image_Ioc_subset
end PartialOrder
namespace Set
private lemma image_subtype_val_Ixx_Ixi {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b})
(h : ∀ {x}, r c x → p a x) :
Subtype.val '' {y : {x // p a x ∧ q x b} | r c.1 y.1} = {y : α | r c.1 y ∧ q y b} :=
(Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r c.1 y}).trans <| by
ext; simp +contextual [@and_comm (r _ _), h]
private lemma image_subtype_val_Ixx_Iix {p q r : α → α → Prop} {a b : α} (c : {x // p a x ∧ q x b})
(h : ∀ {x}, r x c → q x b) :
Subtype.val '' {y : {x // p a x ∧ q x b} | r y.1 c.1} = {y : α | p a y ∧ r y c.1} :=
(Subtype.image_preimage_val {x | p a x ∧ q x b} {y | r y c.1}).trans <| by
ext; simp +contextual [h]
variable [Preorder α] {p : α → Prop}
@[simp] lemma preimage_subtype_val_Ici (a : {x // p x}) : (↑) ⁻¹' (Ici a.1) = Ici a := rfl
@[simp] lemma preimage_subtype_val_Iic (a : {x // p x}) : (↑) ⁻¹' (Iic a.1) = Iic a := rfl
@[simp] lemma preimage_subtype_val_Ioi (a : {x // p x}) : (↑) ⁻¹' (Ioi a.1) = Ioi a := rfl
@[simp] lemma preimage_subtype_val_Iio (a : {x // p x}) : (↑) ⁻¹' (Iio a.1) = Iio a := rfl
@[simp] lemma preimage_subtype_val_Icc (a b : {x // p x}) : (↑) ⁻¹' (Icc a.1 b) = Icc a b := rfl
@[simp] lemma preimage_subtype_val_Ico (a b : {x // p x}) : (↑) ⁻¹' (Ico a.1 b) = Ico a b := rfl
@[simp] lemma preimage_subtype_val_Ioc (a b : {x // p x}) : (↑) ⁻¹' (Ioc a.1 b) = Ioc a b := rfl
@[simp] lemma preimage_subtype_val_Ioo (a b : {x // p x}) : (↑) ⁻¹' (Ioo a.1 b) = Ioo a b := rfl
theorem image_subtype_val_Icc_subset (a b : {x // p x}) :
Subtype.val '' Icc a b ⊆ Icc a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ico_subset (a b : {x // p x}) :
Subtype.val '' Ico a b ⊆ Ico a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ioc_subset (a b : {x // p x}) :
Subtype.val '' Ioc a b ⊆ Ioc a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ioo_subset (a b : {x // p x}) :
Subtype.val '' Ioo a b ⊆ Ioo a.val b.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Iic_subset (a : {x // p x}) :
Subtype.val '' Iic a ⊆ Iic a.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Iio_subset (a : {x // p x}) :
Subtype.val '' Iio a ⊆ Iio a.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ici_subset (a : {x // p x}) :
Subtype.val '' Ici a ⊆ Ici a.val :=
image_subset_iff.mpr fun _ m => m
theorem image_subtype_val_Ioi_subset (a : {x // p x}) :
Subtype.val '' Ioi a ⊆ Ioi a.val :=
image_subset_iff.mpr fun _ m => m
@[simp]
lemma image_subtype_val_Ici_Iic {a : α} (b : Ici a) : Subtype.val '' Iic b = Icc a b :=
(Subtype.image_preimage_val (Ici a) (Iic b.1)).trans Ici_inter_Iic
@[simp]
lemma image_subtype_val_Ici_Iio {a : α} (b : Ici a) : Subtype.val '' Iio b = Ico a b :=
(Subtype.image_preimage_val (Ici a) (Iio b.1)).trans Ici_inter_Iio
@[simp]
lemma image_subtype_val_Ici_Ici {a : α} (b : Ici a) : Subtype.val '' Ici b = Ici b.1 :=
(Subtype.image_preimage_val (Ici a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ici.2 b.2
@[simp]
lemma image_subtype_val_Ici_Ioi {a : α} (b : Ici a) : Subtype.val '' Ioi b = Ioi b.1 :=
(Subtype.image_preimage_val (Ici a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ici b.2
@[simp]
lemma image_subtype_val_Iic_Ici {a : α} (b : Iic a) : Subtype.val '' Ici b = Icc b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iic_Ioi {a : α} (b : Iic a) : Subtype.val '' Ioi b = Ioc b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iic_Iic {a : α} (b : Iic a) : Subtype.val '' Iic b = Iic b.1 :=
image_subtype_val_Ici_Ici (α := αᵒᵈ) _
@[simp]
lemma image_subtype_val_Iic_Iio {a : α} (b : Iic a) : Subtype.val '' Iio b = Iio b.1 :=
image_subtype_val_Ici_Ioi (α := αᵒᵈ) _
@[simp]
lemma image_subtype_val_Ioi_Ici {a : α} (b : Ioi a) : Subtype.val '' Ici b = Ici b.1 :=
(Subtype.image_preimage_val (Ioi a) (Ici b.1)).trans <| inter_eq_right.2 <| Ici_subset_Ioi.2 b.2
@[simp]
lemma image_subtype_val_Ioi_Iic {a : α} (b : Ioi a) : Subtype.val '' Iic b = Ioc a b :=
(Subtype.image_preimage_val (Ioi a) (Iic b.1)).trans Ioi_inter_Iic
@[simp]
lemma image_subtype_val_Ioi_Ioi {a : α} (b : Ioi a) : Subtype.val '' Ioi b = Ioi b.1 :=
(Subtype.image_preimage_val (Ioi a) (Ioi b.1)).trans <| inter_eq_right.2 <| Ioi_subset_Ioi b.2.le
@[simp]
lemma image_subtype_val_Ioi_Iio {a : α} (b : Ioi a) : Subtype.val '' Iio b = Ioo a b :=
(Subtype.image_preimage_val (Ioi a) (Iio b.1)).trans Ioi_inter_Iio
@[simp]
lemma image_subtype_val_Iio_Ici {a : α} (b : Iio a) : Subtype.val '' Ici b = Ico b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
lemma image_subtype_val_Iio_Iic {a : α} (b : Iio a) : Subtype.val '' Iic b = Iic b.1 :=
image_subtype_val_Ioi_Ici (α := αᵒᵈ) _
| @[simp]
lemma image_subtype_val_Iio_Ioi {a : α} (b : Iio a) : Subtype.val '' Ioi b = Ioo b.1 a :=
(Subtype.image_preimage_val _ _).trans <| inter_comm _ _
@[simp]
| Mathlib/Order/Interval/Set/Image.lean | 353 | 357 |
/-
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.Module.Basic
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
/-!
# Midpoint of a segment
## Main definitions
* `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y`
in a module over a ring `R` with invertible `2`.
* `AddMonoidHom.ofMapMidpoint`: construct an `AddMonoidHom` given a map `f` such that
`f` sends zero to zero and midpoints to midpoints.
## Main theorems
* `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`,
* `midpoint_unique`: `midpoint R x y` does not depend on `R`;
* `midpoint x y` is linear both in `x` and `y`;
* `pointReflection_midpoint_left`, `pointReflection_midpoint_right`:
`Equiv.pointReflection (midpoint R x y)` swaps `x` and `y`.
We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler.
## Tags
midpoint, AddMonoidHom
-/
open AffineMap AffineEquiv
section
variable (R : Type*) {V V' P P' : Type*} [Ring R] [Invertible (2 : R)] [AddCommGroup V]
[Module R V] [AddTorsor V P] [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/
def midpoint (x y : P) : P :=
lineMap x y (⅟ 2 : R)
variable {R} {x y z : P}
@[simp]
theorem AffineMap.map_midpoint (f : P →ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
@[simp]
theorem AffineEquiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_lineMap a b _
theorem AffineEquiv.pointReflection_midpoint_left (x y : P) :
pointReflection R (midpoint R x y) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
@[simp]
theorem Equiv.pointReflection_midpoint_left (x y : P) :
(Equiv.pointReflection (midpoint R x y)) x = y := by
rw [midpoint, pointReflection_apply, lineMap_apply, vadd_vsub, vadd_vadd, ← add_smul, ← two_mul,
mul_invOf_self, one_smul, vsub_vadd]
theorem midpoint_comm (x y : P) : midpoint R x y = midpoint R y x := by
rw [midpoint, ← lineMap_apply_one_sub, one_sub_invOf_two, midpoint]
theorem AffineEquiv.pointReflection_midpoint_right (x y : P) :
pointReflection R (midpoint R x y) y = x := by
rw [midpoint_comm, AffineEquiv.pointReflection_midpoint_left]
@[simp]
theorem Equiv.pointReflection_midpoint_right (x y : P) :
(Equiv.pointReflection (midpoint R x y)) y = x := by
rw [midpoint_comm, Equiv.pointReflection_midpoint_left]
theorem midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) :
midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) :=
lineMap_vsub_lineMap _ _ _ _ _
theorem midpoint_vadd_midpoint (v v' : V) (p p' : P) :
midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') :=
lineMap_vadd_lineMap _ _ _ _ _
theorem midpoint_eq_iff {x y z : P} : midpoint R x y = z ↔ pointReflection R z x = y :=
eq_comm.trans
((injective_pointReflection_left_of_module R x).eq_iff'
(AffineEquiv.pointReflection_midpoint_left x y)).symm
@[simp]
theorem midpoint_pointReflection_left (x y : P) :
midpoint R (Equiv.pointReflection x y) y = x :=
midpoint_eq_iff.2 <| Equiv.pointReflection_involutive _ _
@[simp]
theorem midpoint_pointReflection_right (x y : P) :
midpoint R y (Equiv.pointReflection x y) = x :=
midpoint_eq_iff.2 rfl
nonrec lemma AffineEquiv.midpoint_pointReflection_left (x y : P) :
midpoint R (pointReflection R x y) y = x :=
midpoint_pointReflection_left x y
nonrec lemma AffineEquiv.midpoint_pointReflection_right (x y : P) :
midpoint R y (pointReflection R x y) = x :=
midpoint_pointReflection_right x y
@[simp]
theorem midpoint_vsub_left (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₁ = (⅟ 2 : R) • (p₂ -ᵥ p₁) :=
lineMap_vsub_left _ _ _
@[simp]
theorem midpoint_vsub_right (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₂ = (⅟ 2 : R) • (p₁ -ᵥ p₂) := by
rw [midpoint_comm, midpoint_vsub_left]
@[simp]
theorem left_vsub_midpoint (p₁ p₂ : P) : p₁ -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p₁ -ᵥ p₂) :=
left_vsub_lineMap _ _ _
@[simp]
theorem right_vsub_midpoint (p₁ p₂ : P) : p₂ -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p₂ -ᵥ p₁) := by
rw [midpoint_comm, left_vsub_midpoint]
theorem midpoint_vsub (p₁ p₂ p : P) :
midpoint R p₁ p₂ -ᵥ p = (⅟ 2 : R) • (p₁ -ᵥ p) + (⅟ 2 : R) • (p₂ -ᵥ p) := by
rw [← vsub_sub_vsub_cancel_right p₁ p p₂, smul_sub, sub_eq_add_neg, ← smul_neg,
neg_vsub_eq_vsub_rev, add_assoc, invOf_two_smul_add_invOf_two_smul, ← vadd_vsub_assoc,
midpoint_comm, midpoint, lineMap_apply]
| theorem vsub_midpoint (p₁ p₂ p : P) :
p -ᵥ midpoint R p₁ p₂ = (⅟ 2 : R) • (p -ᵥ p₁) + (⅟ 2 : R) • (p -ᵥ p₂) := by
rw [← neg_vsub_eq_vsub_rev, midpoint_vsub, neg_add, ← smul_neg, ← smul_neg, neg_vsub_eq_vsub_rev,
neg_vsub_eq_vsub_rev]
| Mathlib/LinearAlgebra/AffineSpace/Midpoint.lean | 133 | 137 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.WithBot
/-!
# Degree of univariate polynomials
## Main definitions
* `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥`
* `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0`
* `Polynomial.leadingCoeff`: the leading coefficient of a polynomial
* `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0
* `Polynomial.nextCoeff`: the next coefficient after the leading coefficient
## Main results
* `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : R[X]) : WithBot ℕ :=
p.support.max
/-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/
def natDegree (p : R[X]) : ℕ :=
(degree p).unbotD 0
/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/
def leadingCoeff (p : R[X]) : R :=
coeff p (natDegree p)
/-- a polynomial is `Monic` if its leading coefficient is 1 -/
def Monic (p : R[X]) :=
leadingCoeff p = (1 : R)
theorem Monic.def : Monic p ↔ leadingCoeff p = 1 :=
Iff.rfl
instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance
@[simp]
theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=
hp
theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=
hp
@[simp]
theorem degree_zero : degree (0 : R[X]) = ⊥ :=
rfl
@[simp]
theorem natDegree_zero : natDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=
rfl
@[simp]
theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩
theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not
theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by
let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))
have hn : degree p = some n := Classical.not_not.1 hn
rw [natDegree, hn]; rfl
theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe
theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.natDegree = n := by
obtain rfl|h := eq_or_ne p 0
· simp [hn.ne]
· exact degree_eq_iff_natDegree_eq h
theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by
rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe]
theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n :=
mt natDegree_eq_of_degree_eq_some
@[simp]
theorem degree_le_natDegree : degree p ≤ natDegree p :=
WithBot.giUnbotDBot.gc.le_u_l _
theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) :
natDegree p = natDegree q := by unfold natDegree; rw [h]
theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by
rw [Nat.cast_withBot]
exact Finset.le_sup (mem_support_iff.2 h)
theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) :
f.degree ≤ g.degree :=
Finset.sup_mono h
theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by
by_cases hp : p = 0
· rw [hp, degree_zero]
exact bot_le
· rw [degree_eq_natDegree hp]
exact le_degree_of_ne_zero h
theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n :=
WithBot.unbotD_le_iff (fun _ ↦ bot_le)
theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n :=
WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp))
alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le
theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :
p.natDegree ≤ q.natDegree :=
WithBot.giUnbotDBot.gc.monotone_l hpq
@[simp]
theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by
rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,
WithBot.coe_zero]
theorem degree_C_le : degree (C a) ≤ 0 := by
by_cases h : a = 0
· rw [h, C_0]
exact bot_le
· rw [degree_C h]
theorem degree_C_lt : degree (C a) < 1 :=
degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one
theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le
@[simp]
theorem natDegree_C (a : R) : natDegree (C a) = 0 := by
by_cases ha : a = 0
· have : C a = 0 := by rw [ha, C_0]
rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot]
· rw [natDegree, degree_C ha, WithBot.unbotD_zero]
@[simp]
theorem natDegree_one : natDegree (1 : R[X]) = 0 :=
natDegree_C 1
@[simp]
theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natDegree_C]
@[simp]
theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] :
natDegree (ofNat(n) : R[X]) = 0 :=
natDegree_natCast _
theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by
rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot]
@[simp]
theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]
theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by
simpa only [pow_one] using degree_C_mul_X_pow 1 ha
theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
letI := Classical.decEq R
if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le
else le_of_eq (degree_monomial n h)
theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by
rw [C_mul_X_pow_eq_monomial]
apply degree_monomial_le
theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by
simpa only [pow_one] using degree_C_mul_X_pow_le 1 a
@[simp]
theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp]
theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by
simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha
@[simp]
theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) :
natDegree (monomial i r) = if r = 0 then 0 else i := by
split_ifs with hr
· simp [hr]
· rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr]
theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by
classical
rw [Polynomial.natDegree_monomial]
split_ifs
exacts [Nat.zero_le _, le_rfl]
theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i :=
letI := Classical.decEq R
Eq.trans (natDegree_monomial _ _) (if_neg r0)
theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h =>
mem_support_iff.mp (mem_of_max hn) h
theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by
simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R)
theorem degree_X_le : degree (X : R[X]) ≤ 1 :=
degree_monomial_le _ _
theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 :=
natDegree_le_of_degree_le degree_X_le
theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by
rw [degree_eq_natDegree h]
exact WithBot.succ_coe p.natDegree
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) :=
degree_C one_ne_zero
@[simp]
theorem degree_X : degree (X : R[X]) = 1 :=
degree_monomial _ one_ne_zero
@[simp]
theorem natDegree_X : (X : R[X]).natDegree = 1 :=
natDegree_eq_of_degree_eq_some degree_X
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg]
theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a :=
p.degree_neg.le.trans hp
@[simp]
theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree]
theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m :=
(natDegree_neg p).le.trans hp
@[simp]
theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by
rw [← C_eq_intCast, natDegree_C]
theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by
rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg]
end Ring
section Semiring
variable [Semiring R] {p : R[X]}
/-- The second-highest coefficient, or 0 for constants -/
def nextCoeff (p : R[X]) : R :=
if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1)
lemma nextCoeff_eq_zero :
p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by
simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop
lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by
simp [nextCoeff]
@[simp]
theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by
rw [nextCoeff]
simp
theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) :
nextCoeff p = p.coeff (p.natDegree - 1) := by
rw [nextCoeff, if_neg]
contrapose! hp
simpa
variable {p q : R[X]} {ι : Type*}
theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by
simpa only [degree, ← support_toFinsupp, toFinsupp_add]
using AddMonoidAlgebra.sup_support_add_le _ _ _
theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) :
degree (p + q) ≤ n :=
(degree_add_le p q).trans <| max_le hp hq
theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p + q) ≤ max a b :=
(p.degree_add_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by
rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h]
theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n)
(hq : natDegree q ≤ n) : natDegree (p + q) ≤ n :=
(natDegree_add_le p q).trans <| max_le hp hq
theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p + q) ≤ max m n :=
(p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_›
@[simp]
theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 :=
⟨fun h =>
Classical.by_contradiction fun hp =>
mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)),
fun h => h.symm ▸ leadingCoeff_zero⟩
theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero]
theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by
rw [leadingCoeff_eq_zero, degree_eq_bot]
theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n :=
natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _
theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by
rcases p with ⟨p⟩
simp only [erase_def, degree, coeff, support]
apply sup_mono
rw [Finsupp.support_erase]
apply Finset.erase_subset
theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by
apply lt_of_le_of_ne (degree_erase_le _ _)
rw [degree_eq_natDegree hp, degree, support_erase]
exact fun h => not_mem_erase _ _ (mem_of_max h)
theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by
classical
rw [degree, support_update]
split_ifs
· exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _)
· rw [max_insert, max_comm]
exact le_rfl
theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) :
degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) :=
Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl])
fun a s has ih =>
calc
degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by
rw [Finset.sum_cons]; exact degree_add_le _ _
_ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih
theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by
simpa only [degree, ← support_toFinsupp, toFinsupp_mul]
using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _
theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p * q) ≤ a + b :=
(p.degree_mul_le _).trans <| add_le_add ‹_› ‹_›
theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p
| 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le
| n + 1 =>
calc
degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by
rw [pow_succ]; exact degree_mul_le _ _
_ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _
theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) :
degree (p ^ b) ≤ b * a := by
induction b with
| zero => simp [degree_one_le]
| succ n hn =>
rw [Nat.cast_succ, add_mul, one_mul, pow_succ]
exact degree_mul_le_of_le hn hp
@[simp]
theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by
classical
by_cases ha : a = 0
· simp only [ha, (monomial n).map_zero, leadingCoeff_zero]
· rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial]
simp
theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by
rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial]
theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by
simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1
@[simp]
theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a :=
leadingCoeff_monomial a 0
theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by
simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n
theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by
simpa only [pow_one] using @leadingCoeff_X_pow R _ 1
@[simp]
theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) :=
leadingCoeff_X_pow n
@[simp]
theorem monic_X : Monic (X : R[X]) :=
leadingCoeff_X
theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 :=
leadingCoeff_C 1
@[simp]
theorem monic_one : Monic (1 : R[X]) :=
leadingCoeff_C _
theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) :
p ≠ 0 := by
rintro rfl
simp [Monic] at hp
theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by
nontriviality R
exact hp.ne_zero
theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 :=
haveI := Nontrivial.of_polynomial_ne hne
hp.ne_zero
theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by
apply natDegree_le_of_degree_le
apply le_trans (degree_mul_le p q)
rw [Nat.cast_add]
apply add_le_add <;> apply degree_le_natDegree
theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) :
natDegree (p * q) ≤ m + n :=
natDegree_mul_le.trans <| add_le_add ‹_› ‹_›
theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by
induction n with
| zero => simp
| succ i hi =>
rw [pow_succ, Nat.succ_mul]
apply le_trans natDegree_mul_le (add_le_add_right hi _)
theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) :
natDegree (p ^ n) ≤ n * m :=
natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›)
theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by
rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero]
theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl
theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by
simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le,
not_imp_comm, Nat.cast_withBot]
theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by
simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff,
WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not]
theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le
end Semiring
section NontrivialSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ)
@[simp]
theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by
rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]
@[simp]
theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_X_pow n)
end NontrivialSemiring
section Ring
variable [Ring R] {p q : R[X]}
theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by
simpa only [degree_neg q] using degree_add_le p (-q)
theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p - q) ≤ max a b :=
(p.degree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by
simpa only [← natDegree_neg q] using natDegree_add_le p (-q)
theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p - q) ≤ max m n :=
(p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0)
(hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p :=
have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p :=
monomial_add_erase _ _
have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q :=
monomial_add_erase _ _
have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd]
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0)
calc
degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by
conv =>
lhs
rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]
_ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) :=
(degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _)
_ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 :=
(degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))
theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 :=
natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r
end Ring
end Polynomial
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 1,107 | 1,112 | |
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
# Pseudoelements in abelian categories
A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows
ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a
common domain making a commutative square with the two arrows. While the construction shows that
pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these
pseudoelements through commutative diagrams in an abelian category to prove exactness properties.
This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof
in the category of abelian groups can more or less directly be converted into a proof using
pseudoelements.
A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma.
Pseudoelements are in some ways weaker than actual elements in a concrete category. The most
important limitation is that there is no extensionality principle: If `f g : X ⟶ Y`, then
`∀ x ∈ X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`,
it does). A corollary of this is that we can not define arrows in abelian categories by dictating
their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this:
First, we construct some morphism using universal properties, and then we use diagram chasing
of pseudoelements to verify that is has some desirable property such as exactness.
It should be noted that the Freyd-Mitchell embedding theorem
(see `CategoryTheory.Abelian.FreydMitchell`) gives a vastly stronger notion of
pseudoelement (in particular one that gives extensionality) and this file should be updated to
go use that instead!
## Main results
We define the type of pseudoelements of an object and, in particular, the zero pseudoelement.
We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`)
and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`).
Here are the metatheorems we provide:
* A morphism `f` is zero if and only if it is the zero function on pseudoelements.
* A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements.
* A morphism `f` is a monomorphism if and only if it is injective on pseudoelements
if and only if `∀ a, f a = 0 → f = 0`.
* A sequence `f, g` of morphisms is exact if and only if
`∀ a, g (f a) = 0` and `∀ b, g b = 0 → ∃ a, f a = b`.
* If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some
pseudoelement `a''` such that `f a'' = 0` and for every `g` we have
`g a' = 0 → g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away
by that: pseudoelements of an object do not form an abelian group.
## Notations
We introduce coercions from an object of an abelian category to the set of its pseudoelements
and from a morphism to the function it induces on pseudoelements.
These coercions must be explicitly enabled via local instances:
`attribute [local instance] objectToSort homToFun`
## Implementation notes
It appears that sometimes the coercion from morphisms to functions does not work, i.e.,
writing `g a` raises a "function expected" error. This error can be fixed by writing
`(g : X ⟶ Y) a`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Abelian
open CategoryTheory.Preadditive
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
attribute [local instance] Over.coeFromHom
/-- This is just composition of morphisms in `C`. Another way to express this would be
`(Over.map f).obj a`, but our definition has nicer definitional properties. -/
def app {P Q : C} (f : P ⟶ Q) (a : Over P) : Over Q :=
a.hom ≫ f
@[simp]
theorem app_hom {P Q : C} (f : P ⟶ Q) (a : Over P) : (app f a).hom = a.hom ≫ f := rfl
/-- Two arrows `f : X ⟶ P` and `g : Y ⟶ P` are called pseudo-equal if there is some object
`R` and epimorphisms `p : R ⟶ X` and `q : R ⟶ Y` such that `p ≫ f = q ≫ g`. -/
def PseudoEqual (P : C) (f g : Over P) : Prop :=
∃ (R : C) (p : R ⟶ f.1) (q : R ⟶ g.1) (_ : Epi p) (_ : Epi q), p ≫ f.hom = q ≫ g.hom
theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) :=
fun f => ⟨f.1, 𝟙 f.1, 𝟙 f.1, inferInstance, inferInstance, by simp⟩
theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) :=
fun _ _ ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, q, p, Eq, ep, comm.symm⟩
variable [Abelian.{v} C]
section
/-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will
be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/
theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by
intro f g h ⟨R, p, q, ep, Eq, comm⟩ ⟨R', p', q', ep', eq', comm'⟩
refine ⟨pullback q p', pullback.fst _ _ ≫ p, pullback.snd _ _ ≫ q',
epi_comp _ _, epi_comp _ _, ?_⟩
rw [Category.assoc, comm, ← Category.assoc, pullback.condition, Category.assoc, comm',
Category.assoc]
end
/-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/
def Pseudoelement.setoid (P : C) : Setoid (Over P) :=
⟨_, ⟨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _⟩⟩
attribute [local instance] Pseudoelement.setoid
/-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being
pseudo-equal. -/
def Pseudoelement (P : C) : Type max u v :=
Quotient (Pseudoelement.setoid P)
namespace Pseudoelement
/-- A coercion from an object of an abelian category to its pseudoelements. -/
def objectToSort : CoeSort C (Type max u v) :=
⟨fun P => Pseudoelement P⟩
attribute [local instance] objectToSort
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort
/-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/
def overToSort {P : C} : Coe (Over P) (Pseudoelement P) :=
⟨Quot.mk (PseudoEqual P)⟩
attribute [local instance] overToSort
theorem over_coe_def {P Q : C} (a : Q ⟶ P) : (a : Pseudoelement P) = ⟦↑a⟧ := rfl
/-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/
theorem pseudoApply_aux {P Q : C} (f : P ⟶ Q) (a b : Over P) : a ≈ b → app f a ≈ app f b :=
fun ⟨R, p, q, ep, Eq, comm⟩ =>
⟨R, p, q, ep, Eq, show p ≫ a.hom ≫ f = q ≫ b.hom ≫ f by rw [reassoc_of% comm]⟩
/-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/
def pseudoApply {P Q : C} (f : P ⟶ Q) : P → Q :=
Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f)
/-- A coercion from morphisms to functions on pseudoelements. -/
def homToFun {P Q : C} : CoeFun (P ⟶ Q) fun _ => P → Q :=
⟨pseudoApply⟩
attribute [local instance] homToFun
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun
theorem pseudoApply_mk' {P Q : C} (f : P ⟶ Q) (a : Over P) : f ⟦a⟧ = ⟦↑(a.hom ≫ f)⟧ := rfl
/-- Applying a pseudoelement to a composition of morphisms is the same as composing
with each morphism. Sadly, this is not a definitional equality, but at least it is
true. -/
theorem comp_apply {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) (a : P) : (f ≫ g) a = g (f a) :=
Quotient.inductionOn a fun x =>
Quotient.sound <| by
simp only [app]
rw [← Category.assoc, Over.coe_hom]
/-- Composition of functions on pseudoelements is composition of morphisms. -/
theorem comp_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : g ∘ f = f ≫ g :=
funext fun _ => (comp_apply _ _ _).symm
section Zero
/-!
In this section we prove that for every `P` there is an equivalence class that contains
precisely all the zero morphisms ending in `P` and use this to define *the* zero
pseudoelement.
-/
section
attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts
/-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/
theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f ≈ (0 : Q ⟶ P) ↔ f.hom = 0 :=
⟨fun ⟨R, p, q, _, _, comm⟩ => zero_of_epi_comp p (by simp [comm]), fun hf =>
⟨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by
rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]⟩⟩
end
theorem zero_eq_zero' {P Q R : C} :
(⟦((0 : Q ⟶ P) : Over P)⟧ : Pseudoelement P) = ⟦((0 : R ⟶ P) : Over P)⟧ :=
Quotient.sound <| (pseudoZero_aux R _).2 rfl
/-- The zero pseudoelement is the class of a zero morphism. -/
def pseudoZero {P : C} : P :=
⟦(0 : P ⟶ P)⟧
-- Porting note: in mathlib3, we couldn't make this an instance
-- as it would have fired on `coe_sort`.
-- However now that coercions are treated differently, this is a structural instance triggered by
-- the appearance of `Pseudoelement`.
instance hasZero {P : C} : Zero P :=
⟨pseudoZero⟩
instance {P : C} : Inhabited P :=
⟨0⟩
theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = ⟦↑(0 : P ⟶ P)⟧ := rfl
@[simp]
theorem zero_eq_zero {P Q : C} : ⟦((0 : Q ⟶ P) : Over P)⟧ = (0 : Pseudoelement P) :=
zero_eq_zero'
/-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/
theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) ↔ a.hom = 0 := by
rw [← pseudoZero_aux P a]
exact Quotient.eq'
end Zero
open Pseudoelement
/-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/
@[simp]
theorem apply_zero {P Q : C} (f : P ⟶ Q) : f 0 = 0 := by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- The zero morphism maps every pseudoelement to 0. -/
@[simp]
theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P ⟶ Q) a = 0 :=
Quotient.inductionOn a fun a' => by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- An extensionality lemma for being the zero arrow. -/
theorem zero_morphism_ext {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → f = 0 := fun h => by
rw [← Category.id_comp f]
exact (pseudoZero_iff (𝟙 P ≫ f : Over Q)).1 (h (𝟙 P))
theorem zero_morphism_ext' {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → 0 = f :=
Eq.symm ∘ zero_morphism_ext f
theorem eq_zero_iff {P Q : C} (f : P ⟶ Q) : f = 0 ↔ ∀ a, f a = 0 :=
⟨fun h a => by simp [h], zero_morphism_ext _⟩
/-- A monomorphism is injective on pseudoelements. -/
theorem pseudo_injective_of_mono {P Q : C} (f : P ⟶ Q) [Mono f] : Function.Injective f := by
intro abar abar'
refine Quotient.inductionOn₂ abar abar' fun a a' ha => ?_
apply Quotient.sound
have : (⟦(a.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(a'.hom ≫ f)⟧ := by convert ha
have ⟨R, p, q, ep, Eq, comm⟩ := Quotient.exact this
exact ⟨R, p, q, ep, Eq, (cancel_mono f).1 <| by
simp only [Category.assoc]
exact comm⟩
/-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/
theorem zero_of_map_zero {P Q : C} (f : P ⟶ Q) : Function.Injective f → ∀ a, f a = 0 → a = 0 :=
fun h a ha => by
rw [← apply_zero f] at ha
exact h ha
/-- A morphism that only maps the zero pseudoelement to zero is a monomorphism. -/
theorem mono_of_zero_of_map_zero {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0 → a = 0) → Mono f :=
fun h => (mono_iff_cancel_zero _).2 fun _ g hg =>
(pseudoZero_iff (g : Over P)).1 <|
h _ <| show f g = 0 from (pseudoZero_iff (g ≫ f : Over Q)).2 hg
section
/-- An epimorphism is surjective on pseudoelements. -/
theorem pseudo_surjective_of_epi {P Q : C} (f : P ⟶ Q) [Epi f] : Function.Surjective f :=
fun qbar =>
Quotient.inductionOn qbar fun q =>
⟨(pullback.fst f q.hom : Over P),
Quotient.sound <|
⟨pullback f q.hom, 𝟙 (pullback f q.hom), pullback.snd _ _, inferInstance, inferInstance, by
rw [Category.id_comp, ← pullback.condition, app_hom, Over.coe_hom]⟩⟩
end
/-- A morphism that is surjective on pseudoelements is an epimorphism. -/
| theorem epi_of_pseudo_surjective {P Q : C} (f : P ⟶ Q) : Function.Surjective f → Epi f := by
intro h
have ⟨pbar, hpbar⟩ := h (𝟙 Q)
have ⟨p, hp⟩ := Quotient.exists_rep pbar
have : (⟦(p.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(𝟙 Q)⟧ := by
rw [← hp] at hpbar
exact hpbar
have ⟨R, x, y, _, ey, comm⟩ := Quotient.exact this
apply @epi_of_epi_fac _ _ _ _ _ (x ≫ p.hom) f y ey
| Mathlib/CategoryTheory/Abelian/Pseudoelements.lean | 302 | 310 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Util.AssertExists
/-!
# Ordered groups
This file defines bundled ordered groups and develops a few basic results.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
/-
`NeZero` theory should not be needed at this point in the ordered algebraic hierarchy.
-/
assert_not_imported Mathlib.Algebra.NeZero
open Function
universe u
variable {α : Type u}
/-- An ordered additive commutative group is an additive commutative group
with a partial order in which addition is strictly monotone. -/
@[deprecated "Use `[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]` instead."
(since := "2025-04-10")]
structure OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where
/-- Addition is monotone in an ordered additive commutative group. -/
protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b
set_option linter.existingAttributeWarning false in
/-- An ordered commutative group is a commutative group
with a partial order in which multiplication is strictly monotone. -/
@[to_additive,
deprecated "Use `[CommGroup α] [PartialOrder α] [IsOrderedMonoid α]` instead."
(since := "2025-04-10")]
structure OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where
/-- Multiplication is monotone in an ordered commutative group. -/
protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b
alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left'
attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left'
alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left'
attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left
alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left'
attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left
-- See note [lower instance priority]
@[to_additive IsOrderedAddMonoid.toIsOrderedCancelAddMonoid]
instance (priority := 100) IsOrderedMonoid.toIsOrderedCancelMonoid
[CommGroup α] [PartialOrder α] [IsOrderedMonoid α] : IsOrderedCancelMonoid α where
le_of_mul_le_mul_left a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
le_of_mul_le_mul_right a b c bc := by simpa using mul_le_mul_left' bc a⁻¹
/-!
### Linearly ordered commutative groups
-/
set_option linter.deprecated false in
/-- A linearly ordered additive commutative group is an
additive commutative group with a linear order in which
addition is monotone. -/
@[deprecated "Use `[AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]` instead."
(since := "2025-04-10")]
structure LinearOrderedAddCommGroup (α : Type u) extends OrderedAddCommGroup α, LinearOrder α
set_option linter.existingAttributeWarning false in
set_option linter.deprecated false in
/-- A linearly ordered commutative group is a
commutative group with a linear order in which
multiplication is monotone. -/
@[to_additive,
deprecated "Use `[CommGroup α] [LinearOrder α] [IsOrderedMonoid α]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommGroup (α : Type u) extends OrderedCommGroup α, LinearOrder α
attribute [nolint docBlame]
LinearOrderedCommGroup.toLinearOrder LinearOrderedAddCommGroup.toLinearOrder
section LinearOrderedCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] {a : α}
@[to_additive LinearOrderedAddCommGroup.add_lt_add_left]
theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : α) (h : a < b) (c : α) : c * a < c * b :=
_root_.mul_lt_mul_left' h c
@[to_additive eq_zero_of_neg_eq]
theorem eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 :=
match lt_trichotomy a 1 with
| Or.inl h₁ =>
have : 1 < a := h ▸ one_lt_inv_of_inv h₁
absurd h₁ this.asymm
| Or.inr (Or.inl h₁) => h₁
| Or.inr (Or.inr h₁) =>
have : a < 1 := h ▸ inv_lt_one'.mpr h₁
absurd h₁ this.asymm
@[to_additive exists_zero_lt]
theorem exists_one_lt' [Nontrivial α] : ∃ a : α, 1 < a := by
obtain ⟨y, hy⟩ := Decidable.exists_ne (1 : α)
obtain h|h := hy.lt_or_lt
· exact ⟨y⁻¹, one_lt_inv'.mpr h⟩
· exact ⟨y, h⟩
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMaxOrder [Nontrivial α] : NoMaxOrder α :=
⟨by
obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt'
exact fun a => ⟨a * y, lt_mul_of_one_lt_right' a hy⟩⟩
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMinOrder [Nontrivial α] : NoMinOrder α :=
⟨by
obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt'
exact fun a => ⟨a / y, (div_lt_self_iff a).mpr hy⟩⟩
@[to_additive (attr := simp)]
theorem inv_le_self_iff : a⁻¹ ≤ a ↔ 1 ≤ a := by simp [inv_le_iff_one_le_mul']
@[to_additive (attr := simp)]
theorem inv_lt_self_iff : a⁻¹ < a ↔ 1 < a := by simp [inv_lt_iff_one_lt_mul]
@[to_additive (attr := simp)]
theorem le_inv_self_iff : a ≤ a⁻¹ ↔ a ≤ 1 := by simp [← not_iff_not]
@[to_additive (attr := simp)]
theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by simp [← not_iff_not]
end LinearOrderedCommGroup
section NormNumLemmas
/- The following lemmas are stated so that the `norm_num` tactic can use them with the
expected signatures. -/
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {a b : α}
@[to_additive (attr := gcongr) neg_le_neg]
theorem inv_le_inv' : a ≤ b → b⁻¹ ≤ a⁻¹ :=
inv_le_inv_iff.mpr
@[to_additive (attr := gcongr) neg_lt_neg]
theorem inv_lt_inv' : a < b → b⁻¹ < a⁻¹ :=
inv_lt_inv_iff.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_lt_one_of_one_lt : 1 < a → a⁻¹ < 1 :=
inv_lt_one_iff_one_lt.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_le_one_of_one_le : 1 ≤ a → a⁻¹ ≤ 1 :=
inv_le_one'.mpr
@[to_additive neg_nonneg_of_nonpos]
theorem one_le_inv_of_le_one : a ≤ 1 → 1 ≤ a⁻¹ :=
one_le_inv'.mpr
end NormNumLemmas
| Mathlib/Algebra/Order/Group/Defs.lean | 709 | 710 | |
/-
Copyright (c) 2024 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Kernel.Composition.IntegralCompProd
import Mathlib.Probability.Kernel.Disintegration.StandardBorel
/-!
# Lebesgue and Bochner integrals of conditional kernels
Integrals of `ProbabilityTheory.Kernel.condKernel` and `MeasureTheory.Measure.condKernel`.
## Main statements
* `ProbabilityTheory.setIntegral_condKernel`: the integral
`∫ b in s, ∫ ω in t, f (b, ω) ∂(Kernel.condKernel κ (a, b)) ∂(Kernel.fst κ a)` is equal to
`∫ x in s ×ˢ t, f x ∂(κ a)`.
* `MeasureTheory.Measure.setIntegral_condKernel`:
`∫ b in s, ∫ ω in t, f (b, ω) ∂(ρ.condKernel b) ∂ρ.fst = ∫ x in s ×ˢ t, f x ∂ρ`
Corresponding statements for the Lebesgue integral and/or without the sets `s` and `t` are also
provided.
-/
open MeasureTheory ProbabilityTheory MeasurableSpace
open scoped ENNReal
namespace ProbabilityTheory
variable {α β Ω : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
[MeasurableSpace Ω] [StandardBorelSpace Ω] [Nonempty Ω]
section Lintegral
variable [CountableOrCountablyGenerated α β] {κ : Kernel α (β × Ω)} [IsFiniteKernel κ]
{f : β × Ω → ℝ≥0∞}
lemma lintegral_condKernel_mem (a : α) {s : Set (β × Ω)} (hs : MeasurableSet s) :
∫⁻ x, Kernel.condKernel κ (a, x) (Prod.mk x ⁻¹' s) ∂(Kernel.fst κ a) = κ a s := by
conv_rhs => rw [← κ.disintegrate κ.condKernel]
simp_rw [Kernel.compProd_apply hs]
|
lemma setLIntegral_condKernel_eq_measure_prod (a : α) {s : Set β} (hs : MeasurableSet s)
{t : Set Ω} (ht : MeasurableSet t) :
∫⁻ b in s, Kernel.condKernel κ (a, b) t ∂(Kernel.fst κ a) = κ a (s ×ˢ t) := by
have : κ a (s ×ˢ t) = (Kernel.fst κ ⊗ₖ Kernel.condKernel κ) a (s ×ˢ t) := by
congr; exact (κ.disintegrate _).symm
rw [this, Kernel.compProd_apply (hs.prod ht)]
classical
have : ∀ b, Kernel.condKernel κ (a, b) {c | (b, c) ∈ s ×ˢ t}
= s.indicator (fun b ↦ Kernel.condKernel κ (a, b) t) b := by
intro b
by_cases hb : b ∈ s <;> simp [hb]
simp_rw [Set.preimage, this]
| Mathlib/Probability/Kernel/Disintegration/Integral.lean | 44 | 56 |
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Geißer, Michael Stoll
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.DiophantineApproximation.Basic
import Mathlib.NumberTheory.Zsqrtd.Basic
import Mathlib.Tactic.Qify
/-!
# Pell's Equation
*Pell's Equation* is the equation $x^2 - d y^2 = 1$, where $d$ is a positive integer
that is not a square, and one is interested in solutions in integers $x$ and $y$.
In this file, we aim at providing all of the essential theory of Pell's Equation for general $d$
(as opposed to the contents of `NumberTheory.PellMatiyasevic`, which is specific to the case
$d = a^2 - 1$ for some $a > 1$).
We begin by defining a type `Pell.Solution₁ d` for solutions of the equation,
show that it has a natural structure as an abelian group, and prove some basic
properties.
We then prove the following
**Theorem.** Let $d$ be a positive integer that is not a square. Then the equation
$x^2 - d y^2 = 1$ has a nontrivial (i.e., with $y \ne 0$) solution in integers.
See `Pell.exists_of_not_isSquare` and `Pell.Solution₁.exists_nontrivial_of_not_isSquare`.
We then define the *fundamental solution* to be the solution
with smallest $x$ among all solutions satisfying $x > 1$ and $y > 0$.
We show that every solution is a power (in the sense of the group structure mentioned above)
of the fundamental solution up to a (common) sign,
see `Pell.IsFundamental.eq_zpow_or_neg_zpow`, and that a (positive) solution has this property
if and only if it is fundamental, see `Pell.pos_generator_iff_fundamental`.
## References
* [K. Ireland, M. Rosen, *A classical introduction to modern number theory*
(Section 17.5)][IrelandRosen1990]
## Tags
Pell's equation
## TODO
* Extend to `x ^ 2 - d * y ^ 2 = -1` and further generalizations.
* Connect solutions to the continued fraction expansion of `√d`.
-/
namespace Pell
/-!
### Group structure of the solution set
We define a structure of a commutative multiplicative group with distributive negation
on the set of all solutions to the Pell equation `x^2 - d*y^2 = 1`.
The type of such solutions is `Pell.Solution₁ d`. It corresponds to a pair of integers `x` and `y`
and a proof that `(x, y)` is indeed a solution.
The multiplication is given by `(x, y) * (x', y') = (x*y' + d*y*y', x*y' + y*x')`.
This is obtained by mapping `(x, y)` to `x + y*√d` and multiplying the results.
In fact, we define `Pell.Solution₁ d` to be `↥(unitary (ℤ√d))` and transport
the "commutative group with distributive negation" structure from `↥(unitary (ℤ√d))`.
We then set up an API for `Pell.Solution₁ d`.
-/
open CharZero Zsqrtd
/-- An element of `ℤ√d` has norm one (i.e., `a.re^2 - d*a.im^2 = 1`) if and only if
it is contained in the submonoid of unitary elements.
TODO: merge this result with `Pell.isPell_iff_mem_unitary`. -/
theorem is_pell_solution_iff_mem_unitary {d : ℤ} {a : ℤ√d} :
a.re ^ 2 - d * a.im ^ 2 = 1 ↔ a ∈ unitary (ℤ√d) := by
rw [← norm_eq_one_iff_mem_unitary, norm_def, sq, sq, ← mul_assoc]
-- We use `solution₁ d` to allow for a more general structure `solution d m` that
-- encodes solutions to `x^2 - d*y^2 = m` to be added later.
/-- `Pell.Solution₁ d` is the type of solutions to the Pell equation `x^2 - d*y^2 = 1`.
We define this in terms of elements of `ℤ√d` of norm one.
-/
def Solution₁ (d : ℤ) : Type :=
↥(unitary (ℤ√d))
namespace Solution₁
variable {d : ℤ}
instance instCommGroup : CommGroup (Solution₁ d) :=
inferInstanceAs (CommGroup (unitary (ℤ√d)))
instance instHasDistribNeg : HasDistribNeg (Solution₁ d) :=
inferInstanceAs (HasDistribNeg (unitary (ℤ√d)))
instance instInhabited : Inhabited (Solution₁ d) :=
inferInstanceAs (Inhabited (unitary (ℤ√d)))
instance : Coe (Solution₁ d) (ℤ√d) where coe := Subtype.val
/-- The `x` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def x (a : Solution₁ d) : ℤ :=
(a : ℤ√d).re
/-- The `y` component of a solution to the Pell equation `x^2 - d*y^2 = 1` -/
protected def y (a : Solution₁ d) : ℤ :=
(a : ℤ√d).im
/-- The proof that `a` is a solution to the Pell equation `x^2 - d*y^2 = 1` -/
theorem prop (a : Solution₁ d) : a.x ^ 2 - d * a.y ^ 2 = 1 :=
is_pell_solution_iff_mem_unitary.mpr a.property
/-- An alternative form of the equation, suitable for rewriting `x^2`. -/
theorem prop_x (a : Solution₁ d) : a.x ^ 2 = 1 + d * a.y ^ 2 := by rw [← a.prop]; ring
/-- An alternative form of the equation, suitable for rewriting `d * y^2`. -/
theorem prop_y (a : Solution₁ d) : d * a.y ^ 2 = a.x ^ 2 - 1 := by rw [← a.prop]; ring
/-- Two solutions are equal if their `x` and `y` components are equal. -/
@[ext]
theorem ext {a b : Solution₁ d} (hx : a.x = b.x) (hy : a.y = b.y) : a = b :=
Subtype.ext <| Zsqrtd.ext hx hy
/-- Construct a solution from `x`, `y` and a proof that the equation is satisfied. -/
def mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : Solution₁ d where
val := ⟨x, y⟩
property := is_pell_solution_iff_mem_unitary.mp prop
@[simp]
theorem x_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).x = x :=
rfl
@[simp]
theorem y_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (mk x y prop).y = y :=
rfl
@[simp]
theorem coe_mk (x y : ℤ) (prop : x ^ 2 - d * y ^ 2 = 1) : (↑(mk x y prop) : ℤ√d) = ⟨x, y⟩ :=
Zsqrtd.ext (x_mk x y prop) (y_mk x y prop)
@[simp]
theorem x_one : (1 : Solution₁ d).x = 1 :=
rfl
@[simp]
theorem y_one : (1 : Solution₁ d).y = 0 :=
rfl
@[simp]
theorem x_mul (a b : Solution₁ d) : (a * b).x = a.x * b.x + d * (a.y * b.y) := by
rw [← mul_assoc]
rfl
@[simp]
theorem y_mul (a b : Solution₁ d) : (a * b).y = a.x * b.y + a.y * b.x :=
rfl
@[simp]
theorem x_inv (a : Solution₁ d) : a⁻¹.x = a.x :=
rfl
@[simp]
theorem y_inv (a : Solution₁ d) : a⁻¹.y = -a.y :=
rfl
@[simp]
theorem x_neg (a : Solution₁ d) : (-a).x = -a.x :=
rfl
@[simp]
| theorem y_neg (a : Solution₁ d) : (-a).y = -a.y :=
rfl
| Mathlib/NumberTheory/Pell.lean | 178 | 180 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Sean Leather
-/
import Batteries.Data.List.Perm
import Mathlib.Data.List.Pairwise
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Lookmap
import Mathlib.Data.Sigma.Basic
/-!
# Utilities for lists of sigmas
This file includes several ways of interacting with `List (Sigma β)`, treated as a key-value store.
If `α : Type*` and `β : α → Type*`, then we regard `s : Sigma β` as having key `s.1 : α` and value
`s.2 : β s.1`. Hence, `List (Sigma β)` behaves like a key-value store.
## Main Definitions
- `List.keys` extracts the list of keys.
- `List.NodupKeys` determines if the store has duplicate keys.
- `List.lookup`/`lookup_all` accesses the value(s) of a particular key.
- `List.kreplace` replaces the first value with a given key by a given value.
- `List.kerase` removes a value.
- `List.kinsert` inserts a value.
- `List.kunion` computes the union of two stores.
- `List.kextract` returns a value with a given key and the rest of the values.
-/
universe u u' v v'
namespace List
variable {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} {l l₁ l₂ : List (Sigma β)}
/-! ### `keys` -/
/-- List of keys from a list of key-value pairs -/
def keys : List (Sigma β) → List α :=
map Sigma.fst
@[simp]
theorem keys_nil : @keys α β [] = [] :=
rfl
@[simp]
theorem keys_cons {s} {l : List (Sigma β)} : (s :: l).keys = s.1 :: l.keys :=
rfl
theorem mem_keys_of_mem {s : Sigma β} {l : List (Sigma β)} : s ∈ l → s.1 ∈ l.keys :=
mem_map_of_mem
theorem exists_of_mem_keys {a} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ b : β a, Sigma.mk a b ∈ l :=
let ⟨⟨_, b'⟩, m, e⟩ := exists_of_mem_map h
Eq.recOn e (Exists.intro b' m)
theorem mem_keys {a} {l : List (Sigma β)} : a ∈ l.keys ↔ ∃ b : β a, Sigma.mk a b ∈ l :=
⟨exists_of_mem_keys, fun ⟨_, h⟩ => mem_keys_of_mem h⟩
theorem not_mem_keys {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ b : β a, Sigma.mk a b ∉ l :=
(not_congr mem_keys).trans not_exists
theorem ne_key {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ s : Sigma β, s ∈ l → a ≠ s.1 :=
Iff.intro (fun h₁ s h₂ e => absurd (mem_keys_of_mem h₂) (by rwa [e] at h₁)) fun f h₁ =>
let ⟨_, h₂⟩ := exists_of_mem_keys h₁
f _ h₂ rfl
@[deprecated (since := "2025-04-27")]
alias not_eq_key := ne_key
/-! ### `NodupKeys` -/
/-- Determines whether the store uses a key several times. -/
def NodupKeys (l : List (Sigma β)) : Prop :=
l.keys.Nodup
theorem nodupKeys_iff_pairwise {l} : NodupKeys l ↔ Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
pairwise_map
theorem NodupKeys.pairwise_ne {l} (h : NodupKeys l) :
Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
nodupKeys_iff_pairwise.1 h
@[simp]
theorem nodupKeys_nil : @NodupKeys α β [] :=
Pairwise.nil
@[simp]
theorem nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} :
NodupKeys (s :: l) ↔ s.1 ∉ l.keys ∧ NodupKeys l := by simp [keys, NodupKeys]
theorem not_mem_keys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
s.1 ∉ l.keys :=
(nodupKeys_cons.1 h).1
theorem nodupKeys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
NodupKeys l :=
(nodupKeys_cons.1 h).2
theorem NodupKeys.eq_of_fst_eq {l : List (Sigma β)} (nd : NodupKeys l) {s s' : Sigma β} (h : s ∈ l)
(h' : s' ∈ l) : s.1 = s'.1 → s = s' :=
@Pairwise.forall_of_forall _ (fun s s' : Sigma β => s.1 = s'.1 → s = s') _
(fun _ _ H h => (H h.symm).symm) (fun _ _ _ => rfl)
((nodupKeys_iff_pairwise.1 nd).imp fun h h' => (h h').elim) _ h _ h'
theorem NodupKeys.eq_of_mk_mem {a : α} {b b' : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) (h' : Sigma.mk a b' ∈ l) : b = b' := by
cases nd.eq_of_fst_eq h h' rfl; rfl
theorem nodupKeys_singleton (s : Sigma β) : NodupKeys [s] :=
nodup_singleton _
theorem NodupKeys.sublist {l₁ l₂ : List (Sigma β)} (h : l₁ <+ l₂) : NodupKeys l₂ → NodupKeys l₁ :=
Nodup.sublist <| h.map _
protected theorem NodupKeys.nodup {l : List (Sigma β)} : NodupKeys l → Nodup l :=
Nodup.of_map _
theorem perm_nodupKeys {l₁ l₂ : List (Sigma β)} (h : l₁ ~ l₂) : NodupKeys l₁ ↔ NodupKeys l₂ :=
(h.map _).nodup_iff
theorem nodupKeys_flatten {L : List (List (Sigma β))} :
NodupKeys (flatten L) ↔ (∀ l ∈ L, NodupKeys l) ∧ Pairwise Disjoint (L.map keys) := by
rw [nodupKeys_iff_pairwise, pairwise_flatten, pairwise_map]
refine and_congr (forall₂_congr fun l _ => by simp [nodupKeys_iff_pairwise]) ?_
apply iff_of_eq; congr! with (l₁ l₂)
simp [keys, disjoint_iff_ne, Sigma.forall]
theorem nodup_zipIdx_map_snd (l : List α) : (l.zipIdx.map Prod.snd).Nodup := by
simp [List.nodup_range']
@[deprecated (since := "2025-01-28")] alias nodup_enum_map_fst := nodup_zipIdx_map_snd
theorem mem_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.Nodup) (nd₁ : l₁.Nodup)
(h : ∀ x, x ∈ l₀ ↔ x ∈ l₁) : l₀ ~ l₁ :=
(perm_ext_iff_of_nodup nd₀ nd₁).2 h
variable [DecidableEq α] [DecidableEq α']
/-! ### `dlookup` -/
/-- `dlookup a l` is the first value in `l` corresponding to the key `a`,
or `none` if no such element exists. -/
def dlookup (a : α) : List (Sigma β) → Option (β a)
| [] => none
| ⟨a', b⟩ :: l => if h : a' = a then some (Eq.recOn h b) else dlookup a l
@[simp]
theorem dlookup_nil (a : α) : dlookup a [] = @none (β a) :=
rfl
@[simp]
theorem dlookup_cons_eq (l) (a : α) (b : β a) : dlookup a (⟨a, b⟩ :: l) = some b :=
dif_pos rfl
@[simp]
theorem dlookup_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → dlookup a (s :: l) = dlookup a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem dlookup_isSome {a : α} : ∀ {l : List (Sigma β)}, (dlookup a l).isSome ↔ a ∈ l.keys
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simp [h, dlookup_isSome]
theorem dlookup_eq_none {a : α} {l : List (Sigma β)} : dlookup a l = none ↔ a ∉ l.keys := by
simp [← dlookup_isSome, Option.isNone_iff_eq_none]
theorem of_mem_dlookup {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ dlookup a l → Sigma.mk a b ∈ l
| ⟨a', b'⟩ :: l, H => by
by_cases h : a = a'
· subst a'
simp? at H says simp only [dlookup_cons_eq, Option.mem_def, Option.some.injEq] at H
simp [H]
· simp only [ne_eq, h, not_false_iff, dlookup_cons_ne] at H
simp [of_mem_dlookup H]
theorem mem_dlookup {a} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) (h : Sigma.mk a b ∈ l) :
b ∈ dlookup a l := by
obtain ⟨b', h'⟩ := Option.isSome_iff_exists.mp (dlookup_isSome.mpr (mem_keys_of_mem h))
cases nd.eq_of_mk_mem h (of_mem_dlookup h')
exact h'
theorem map_dlookup_eq_find (a : α) :
∀ l : List (Sigma β), (dlookup a l).map (Sigma.mk a) = find? (fun s => a = s.1) l
| [] => rfl
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simpa [h] using map_dlookup_eq_find a l
theorem mem_dlookup_iff {a : α} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) :
b ∈ dlookup a l ↔ Sigma.mk a b ∈ l :=
⟨of_mem_dlookup, mem_dlookup nd⟩
theorem perm_dlookup (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : dlookup a l₁ = dlookup a l₂ := by
ext b; simp only [mem_dlookup_iff nd₁, mem_dlookup_iff nd₂]; exact p.mem_iff
theorem lookup_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.NodupKeys) (nd₁ : l₁.NodupKeys)
(h : ∀ x y, y ∈ l₀.dlookup x ↔ y ∈ l₁.dlookup x) : l₀ ~ l₁ :=
mem_ext nd₀.nodup nd₁.nodup fun ⟨a, b⟩ => by
rw [← mem_dlookup_iff, ← mem_dlookup_iff, h] <;> assumption
theorem dlookup_map (l : List (Sigma β))
{f : α → α'} (hf : Function.Injective f) (g : ∀ a, β a → β' (f a)) (a : α) :
(l.map fun x => ⟨f x.1, g _ x.2⟩).dlookup (f a) = (l.dlookup a).map (g a) := by
induction' l with b l IH
· rw [map_nil, dlookup_nil, dlookup_nil, Option.map_none']
· rw [map_cons]
obtain rfl | h := eq_or_ne a b.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.map_some']
· rw [dlookup_cons_ne _ _ h, dlookup_cons_ne _ _ (fun he => h <| hf he), IH]
theorem dlookup_map₁ {β : Type v} (l : List (Σ _ : α, β))
{f : α → α'} (hf : Function.Injective f) (a : α) :
(l.map fun x => ⟨f x.1, x.2⟩ : List (Σ _ : α', β)).dlookup (f a) = l.dlookup a := by
rw [dlookup_map (β' := fun _ => β) l hf (fun _ x => x) a, Option.map_id']
theorem dlookup_map₂ {γ δ : α → Type*} {l : List (Σ a, γ a)} {f : ∀ a, γ a → δ a} (a : α) :
(l.map fun x => ⟨x.1, f _ x.2⟩ : List (Σ a, δ a)).dlookup a = (l.dlookup a).map (f a) :=
dlookup_map l Function.injective_id _ _
/-! ### `lookupAll` -/
/-- `lookup_all a l` is the list of all values in `l` corresponding to the key `a`. -/
def lookupAll (a : α) : List (Sigma β) → List (β a)
| [] => []
| ⟨a', b⟩ :: l => if h : a' = a then Eq.recOn h b :: lookupAll a l else lookupAll a l
@[simp]
theorem lookupAll_nil (a : α) : lookupAll a [] = @nil (β a) :=
rfl
@[simp]
theorem lookupAll_cons_eq (l) (a : α) (b : β a) : lookupAll a (⟨a, b⟩ :: l) = b :: lookupAll a l :=
dif_pos rfl
@[simp]
theorem lookupAll_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → lookupAll a (s :: l) = lookupAll a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem lookupAll_eq_nil {a : α} :
∀ {l : List (Sigma β)}, lookupAll a l = [] ↔ ∀ b : β a, Sigma.mk a b ∉ l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp only [lookupAll_cons_eq, mem_cons, Sigma.mk.inj_iff, heq_eq_eq, true_and, not_or,
false_iff, not_forall, not_and, not_not, reduceCtorEq]
use b
simp
· simp [h, lookupAll_eq_nil]
theorem head?_lookupAll (a : α) : ∀ l : List (Sigma β), head? (lookupAll a l) = dlookup a l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst h; simp
· rw [lookupAll_cons_ne, dlookup_cons_ne, head?_lookupAll a l] <;> assumption
theorem mem_lookupAll {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ lookupAll a l ↔ Sigma.mk a b ∈ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp [*, mem_lookupAll]
· simp [*, mem_lookupAll]
theorem lookupAll_sublist (a : α) : ∀ l : List (Sigma β), (lookupAll a l).map (Sigma.mk a) <+ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp only [ne_eq, not_true, lookupAll_cons_eq, List.map]
exact (lookupAll_sublist a l).cons₂ _
· simp only [ne_eq, h, not_false_iff, lookupAll_cons_ne]
exact (lookupAll_sublist a l).cons _
theorem lookupAll_length_le_one (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
length (lookupAll a l) ≤ 1 := by
have := Nodup.sublist ((lookupAll_sublist a l).map _) h
rw [map_map] at this
rwa [← nodup_replicate, ← map_const]
theorem lookupAll_eq_dlookup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
lookupAll a l = (dlookup a l).toList := by
rw [← head?_lookupAll]
have h1 := lookupAll_length_le_one a h; revert h1
rcases lookupAll a l with (_ | ⟨b, _ | ⟨c, l⟩⟩) <;> intro h1 <;> try rfl
exact absurd h1 (by simp)
theorem lookupAll_nodup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : (lookupAll a l).Nodup := by
(rw [lookupAll_eq_dlookup a h]; apply Option.toList_nodup)
theorem perm_lookupAll (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : lookupAll a l₁ = lookupAll a l₂ := by
simp [lookupAll_eq_dlookup, nd₁, nd₂, perm_dlookup a nd₁ nd₂ p]
theorem dlookup_append (l₁ l₂ : List (Sigma β)) (a : α) :
(l₁ ++ l₂).dlookup a = (l₁.dlookup a).or (l₂.dlookup a) := by
induction l₁ with
| nil => rfl
| cons x l₁ IH =>
rw [cons_append]
obtain rfl | hb := Decidable.eq_or_ne a x.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.or]
· rw [dlookup_cons_ne _ _ hb, dlookup_cons_ne _ _ hb, IH]
/-! ### `kreplace` -/
/-- Replaces the first value with key `a` by `b`. -/
def kreplace (a : α) (b : β a) : List (Sigma β) → List (Sigma β) :=
lookmap fun s => if a = s.1 then some ⟨a, b⟩ else none
theorem kreplace_of_forall_not (a : α) (b : β a) {l : List (Sigma β)}
(H : ∀ b : β a, Sigma.mk a b ∉ l) : kreplace a b l = l :=
lookmap_of_forall_not _ <| by
rintro ⟨a', b'⟩ h; dsimp; split_ifs
· subst a'
exact H _ h
· rfl
theorem kreplace_self {a : α} {b : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) : kreplace a b l = l := by
refine (lookmap_congr ?_).trans (lookmap_id' (Option.guard fun (s : Sigma β) => a = s.1) ?_ _)
· rintro ⟨a', b'⟩ h'
dsimp [Option.guard]
split_ifs
· subst a'
simp [nd.eq_of_mk_mem h h']
· rfl
· rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩
dsimp [Option.guard]
split_ifs
· simp
· rintro ⟨⟩
theorem keys_kreplace (a : α) (b : β a) : ∀ l : List (Sigma β), (kreplace a b l).keys = l.keys :=
lookmap_map_eq _ _ <| by
rintro ⟨a₁, b₂⟩ ⟨a₂, b₂⟩
dsimp
split_ifs with h <;> simp +contextual [h]
theorem kreplace_nodupKeys (a : α) (b : β a) {l : List (Sigma β)} :
(kreplace a b l).NodupKeys ↔ l.NodupKeys := by simp [NodupKeys, keys_kreplace]
theorem Perm.kreplace {a : α} {b : β a} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kreplace a b l₁ ~ kreplace a b l₂ :=
perm_lookmap _ <| by
refine nd.pairwise_ne.imp ?_
intro x y h z h₁ w h₂
split_ifs at h₁ h₂ with h_2 h_1 <;> cases h₁ <;> cases h₂
exact (h (h_2.symm.trans h_1)).elim
/-! ### `kerase` -/
/-- Remove the first pair with the key `a`. -/
def kerase (a : α) : List (Sigma β) → List (Sigma β) :=
eraseP fun s => a = s.1
@[simp]
theorem kerase_nil {a} : @kerase _ β _ a [] = [] :=
rfl
@[simp]
theorem kerase_cons_eq {a} {s : Sigma β} {l : List (Sigma β)} (h : a = s.1) :
kerase a (s :: l) = l := by simp [kerase, h]
@[simp]
theorem kerase_cons_ne {a} {s : Sigma β} {l : List (Sigma β)} (h : a ≠ s.1) :
kerase a (s :: l) = s :: kerase a l := by simp [kerase, h]
@[simp]
theorem kerase_of_not_mem_keys {a} {l : List (Sigma β)} (h : a ∉ l.keys) : kerase a l = l := by
induction l with
| nil => rfl
| cons _ _ ih => simp [not_or] at h; simp [h.1, ih h.2]
theorem kerase_sublist (a : α) (l : List (Sigma β)) : kerase a l <+ l :=
eraseP_sublist
theorem kerase_keys_subset (a) (l : List (Sigma β)) : (kerase a l).keys ⊆ l.keys :=
((kerase_sublist a l).map _).subset
theorem mem_keys_of_mem_keys_kerase {a₁ a₂} {l : List (Sigma β)} :
a₁ ∈ (kerase a₂ l).keys → a₁ ∈ l.keys :=
@kerase_keys_subset _ _ _ _ _ _
theorem exists_of_kerase {a : α} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ (b : β a) (l₁ l₂ : List (Sigma β)),
a ∉ l₁.keys ∧ l = l₁ ++ ⟨a, b⟩ :: l₂ ∧ kerase a l = l₁ ++ l₂ := by
induction l with
| nil => cases h
| cons hd tl ih =>
by_cases e : a = hd.1
· subst e
exact ⟨hd.2, [], tl, by simp, by cases hd; rfl, by simp⟩
· simp only [keys_cons, mem_cons] at h
rcases h with h | h
· exact absurd h e
rcases ih h with ⟨b, tl₁, tl₂, h₁, h₂, h₃⟩
exact ⟨b, hd :: tl₁, tl₂, not_mem_cons_of_ne_of_not_mem e h₁, by (rw [h₂]; rfl), by
simp [e, h₃]⟩
@[simp]
theorem mem_keys_kerase_of_ne {a₁ a₂} {l : List (Sigma β)} (h : a₁ ≠ a₂) :
a₁ ∈ (kerase a₂ l).keys ↔ a₁ ∈ l.keys :=
(Iff.intro mem_keys_of_mem_keys_kerase) fun p =>
if q : a₂ ∈ l.keys then
match l, kerase a₂ l, exists_of_kerase q, p with
| _, _, ⟨_, _, _, _, rfl, rfl⟩, p => by simpa [keys, h] using p
else by simp [q, p]
theorem keys_kerase {a} {l : List (Sigma β)} : (kerase a l).keys = l.keys.erase a := by
rw [keys, kerase, erase_eq_eraseP, eraseP_map, Function.comp_def]
congr
theorem kerase_kerase {a a'} {l : List (Sigma β)} :
(kerase a' l).kerase a = (kerase a l).kerase a' := by
by_cases h : a = a'
· subst a'; rfl
induction' l with x xs
· rfl
· by_cases a' = x.1
· subst a'
simp [kerase_cons_ne h, kerase_cons_eq rfl]
by_cases h' : a = x.1
· subst a
simp [kerase_cons_eq rfl, kerase_cons_ne (Ne.symm h)]
· simp [kerase_cons_ne, *]
theorem NodupKeys.kerase (a : α) : NodupKeys l → (kerase a l).NodupKeys :=
NodupKeys.sublist <| kerase_sublist _ _
theorem Perm.kerase {a : α} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kerase a l₁ ~ kerase a l₂ := by
apply Perm.eraseP
apply (nodupKeys_iff_pairwise.1 nd).imp
intros; simp_all
@[simp]
theorem not_mem_keys_kerase (a) {l : List (Sigma β)} (nd : l.NodupKeys) :
a ∉ (kerase a l).keys := by
induction l with
| nil => simp
| cons hd tl ih =>
simp? at nd says simp only [nodupKeys_cons] at nd
by_cases h : a = hd.1
· subst h
simp [nd.1]
· simp [h, ih nd.2]
@[simp]
theorem dlookup_kerase (a) {l : List (Sigma β)} (nd : l.NodupKeys) :
dlookup a (kerase a l) = none :=
dlookup_eq_none.mpr (not_mem_keys_kerase a nd)
@[simp]
theorem dlookup_kerase_ne {a a'} {l : List (Sigma β)} (h : a ≠ a') :
dlookup a (kerase a' l) = dlookup a l := by
induction l with
| nil => rfl
| cons hd tl ih =>
obtain ⟨ah, bh⟩ := hd
by_cases h₁ : a = ah <;> by_cases h₂ : a' = ah
· substs h₁ h₂
cases Ne.irrefl h
· subst h₁
simp [h₂]
· subst h₂
simp [h]
· simp [h₁, h₂, ih]
theorem kerase_append_left {a} :
∀ {l₁ l₂ : List (Sigma β)}, a ∈ l₁.keys → kerase a (l₁ ++ l₂) = kerase a l₁ ++ l₂
| [], _, h => by cases h
| s :: l₁, l₂, h₁ => by
if h₂ : a = s.1 then simp [h₂]
else simp at h₁; rcases h₁ with h₁ | h₁ <;>
[exact absurd h₁ h₂; simp [h₂, kerase_append_left h₁]]
theorem kerase_append_right {a} :
∀ {l₁ l₂ : List (Sigma β)}, a ∉ l₁.keys → kerase a (l₁ ++ l₂) = l₁ ++ kerase a l₂
| [], _, _ => rfl
| _ :: l₁, l₂, h => by
simp only [keys_cons, mem_cons, not_or] at h
simp [h.1, kerase_append_right h.2]
theorem kerase_comm (a₁ a₂) (l : List (Sigma β)) :
kerase a₂ (kerase a₁ l) = kerase a₁ (kerase a₂ l) :=
if h : a₁ = a₂ then by simp [h]
else
if ha₁ : a₁ ∈ l.keys then
if ha₂ : a₂ ∈ l.keys then
match l, kerase a₁ l, exists_of_kerase ha₁, ha₂ with
| _, _, ⟨b₁, l₁, l₂, a₁_nin_l₁, rfl, rfl⟩, _ =>
if h' : a₂ ∈ l₁.keys then by
simp [kerase_append_left h',
kerase_append_right (mt (mem_keys_kerase_of_ne h).mp a₁_nin_l₁)]
else by
simp [kerase_append_right h', kerase_append_right a₁_nin_l₁,
@kerase_cons_ne _ _ _ a₂ ⟨a₁, b₁⟩ _ (Ne.symm h)]
else by simp [ha₂, mt mem_keys_of_mem_keys_kerase ha₂]
else by simp [ha₁, mt mem_keys_of_mem_keys_kerase ha₁]
theorem sizeOf_kerase [SizeOf (Sigma β)] (x : α)
(xs : List (Sigma β)) : SizeOf.sizeOf (List.kerase x xs) ≤ SizeOf.sizeOf xs := by
simp only [SizeOf.sizeOf, _sizeOf_1]
induction' xs with y ys
· simp
· by_cases x = y.1 <;> simp [*]
/-! ### `kinsert` -/
/-- Insert the pair `⟨a, b⟩` and erase the first pair with the key `a`. -/
def kinsert (a : α) (b : β a) (l : List (Sigma β)) : List (Sigma β) :=
⟨a, b⟩ :: kerase a l
@[simp]
theorem kinsert_def {a} {b : β a} {l : List (Sigma β)} : kinsert a b l = ⟨a, b⟩ :: kerase a l :=
rfl
theorem mem_keys_kinsert {a a'} {b' : β a'} {l : List (Sigma β)} :
a ∈ (kinsert a' b' l).keys ↔ a = a' ∨ a ∈ l.keys := by by_cases h : a = a' <;> simp [h]
theorem kinsert_nodupKeys (a) (b : β a) {l : List (Sigma β)} (nd : l.NodupKeys) :
(kinsert a b l).NodupKeys :=
nodupKeys_cons.mpr ⟨not_mem_keys_kerase a nd, nd.kerase a⟩
theorem Perm.kinsert {a} {b : β a} {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (p : l₁ ~ l₂) :
kinsert a b l₁ ~ kinsert a b l₂ :=
(p.kerase nd₁).cons _
theorem dlookup_kinsert {a} {b : β a} (l : List (Sigma β)) :
dlookup a (kinsert a b l) = some b := by
simp only [kinsert, dlookup_cons_eq]
theorem dlookup_kinsert_ne {a a'} {b' : β a'} {l : List (Sigma β)} (h : a ≠ a') :
dlookup a (kinsert a' b' l) = dlookup a l := by simp [h]
/-! ### `kextract` -/
/-- Finds the first entry with a given key `a` and returns its value (as an `Option` because there
might be no entry with key `a`) alongside with the rest of the entries. -/
def kextract (a : α) : List (Sigma β) → Option (β a) × List (Sigma β)
| [] => (none, [])
| s :: l =>
if h : s.1 = a then (some (Eq.recOn h s.2), l)
else
let (b', l') := kextract a l
(b', s :: l')
@[simp]
theorem kextract_eq_dlookup_kerase (a : α) :
∀ l : List (Sigma β), kextract a l = (dlookup a l, kerase a l)
| [] => rfl
| ⟨a', b⟩ :: l => by
simp only [kextract]; dsimp; split_ifs with h
· subst a'
simp [kerase]
· simp [kextract, Ne.symm h, kextract_eq_dlookup_kerase a l, kerase]
/-! ### `dedupKeys` -/
/-- Remove entries with duplicate keys from `l : List (Sigma β)`. -/
def dedupKeys : List (Sigma β) → List (Sigma β) :=
List.foldr (fun x => kinsert x.1 x.2) []
theorem dedupKeys_cons {x : Sigma β} (l : List (Sigma β)) :
dedupKeys (x :: l) = kinsert x.1 x.2 (dedupKeys l) :=
rfl
theorem nodupKeys_dedupKeys (l : List (Sigma β)) : NodupKeys (dedupKeys l) := by
dsimp [dedupKeys]
generalize hl : nil = l'
have : NodupKeys l' := by
rw [← hl]
apply nodup_nil
clear hl
induction' l with x xs l_ih
· apply this
· cases x
simp only [foldr_cons, kinsert_def, nodupKeys_cons, ne_eq, not_true]
constructor
· simp only [keys_kerase]
apply l_ih.not_mem_erase
· exact l_ih.kerase _
theorem dlookup_dedupKeys (a : α) (l : List (Sigma β)) : dlookup a (dedupKeys l) = dlookup a l := by
induction' l with l_hd _ l_ih
· rfl
obtain ⟨a', b⟩ := l_hd
by_cases h : a = a'
· subst a'
rw [dedupKeys_cons, dlookup_kinsert, dlookup_cons_eq]
· rw [dedupKeys_cons, dlookup_kinsert_ne h, l_ih, dlookup_cons_ne]
exact h
theorem sizeOf_dedupKeys [SizeOf (Sigma β)]
(xs : List (Sigma β)) : SizeOf.sizeOf (dedupKeys xs) ≤ SizeOf.sizeOf xs := by
simp only [SizeOf.sizeOf, _sizeOf_1]
induction' xs with x xs
· simp [dedupKeys]
· simp only [dedupKeys_cons, kinsert_def, Nat.add_le_add_iff_left, Sigma.eta]
trans
· apply sizeOf_kerase
· assumption
/-! ### `kunion` -/
/-- `kunion l₁ l₂` is the append to l₁ of l₂ after, for each key in l₁, the
first matching pair in l₂ is erased. -/
def kunion : List (Sigma β) → List (Sigma β) → List (Sigma β)
| [], l₂ => l₂
| s :: l₁, l₂ => s :: kunion l₁ (kerase s.1 l₂)
@[simp]
theorem nil_kunion {l : List (Sigma β)} : kunion [] l = l :=
rfl
@[simp]
theorem kunion_nil : ∀ {l : List (Sigma β)}, kunion l [] = l
| [] => rfl
| _ :: l => by rw [kunion, kerase_nil, kunion_nil]
@[simp]
theorem kunion_cons {s} {l₁ l₂ : List (Sigma β)} :
kunion (s :: l₁) l₂ = s :: kunion l₁ (kerase s.1 l₂) :=
rfl
@[simp]
theorem mem_keys_kunion {a} {l₁ l₂ : List (Sigma β)} :
a ∈ (kunion l₁ l₂).keys ↔ a ∈ l₁.keys ∨ a ∈ l₂.keys := by
induction l₁ generalizing l₂ with
| nil => simp
| cons s l₁ ih => by_cases h : a = s.1 <;> [simp [h]; simp [h, ih]]
@[simp]
theorem kunion_kerase {a} :
∀ {l₁ l₂ : List (Sigma β)}, kunion (kerase a l₁) (kerase a l₂) = kerase a (kunion l₁ l₂)
| [], _ => rfl
| s :: _, l => by by_cases h : a = s.1 <;> simp [h, kerase_comm a s.1 l, kunion_kerase]
theorem NodupKeys.kunion (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys) : (kunion l₁ l₂).NodupKeys := by
induction l₁ generalizing l₂ with
| nil => simp only [nil_kunion, nd₂]
| cons s l₁ ih =>
simp? at nd₁ says simp only [nodupKeys_cons] at nd₁
simp [not_or, nd₁.1, nd₂, ih nd₁.2 (nd₂.kerase s.1)]
theorem Perm.kunion_right {l₁ l₂ : List (Sigma β)} (p : l₁ ~ l₂) (l) :
kunion l₁ l ~ kunion l₂ l := by
induction p generalizing l with
| nil => rfl
| cons hd _ ih =>
simp [ih (List.kerase _ _), Perm.cons]
| swap s₁ s₂ l => simp [kerase_comm, Perm.swap]
| trans _ _ ih₁₂ ih₂₃ => exact Perm.trans (ih₁₂ l) (ih₂₃ l)
theorem Perm.kunion_left :
∀ (l) {l₁ l₂ : List (Sigma β)}, l₁.NodupKeys → l₁ ~ l₂ → kunion l l₁ ~ kunion l l₂
| [], _, _, _, p => p
| s :: l, _, _, nd₁, p => ((p.kerase nd₁).kunion_left l <| nd₁.kerase s.1).cons s
theorem Perm.kunion {l₁ l₂ l₃ l₄ : List (Sigma β)} (nd₃ : l₃.NodupKeys) (p₁₂ : l₁ ~ l₂)
(p₃₄ : l₃ ~ l₄) : kunion l₁ l₃ ~ kunion l₂ l₄ :=
(p₁₂.kunion_right l₃).trans (p₃₄.kunion_left l₂ nd₃)
@[simp]
theorem dlookup_kunion_left {a} {l₁ l₂ : List (Sigma β)} (h : a ∈ l₁.keys) :
dlookup a (kunion l₁ l₂) = dlookup a l₁ := by
induction' l₁ with s _ ih generalizing l₂ <;> simp at h; rcases h with h | h <;> obtain ⟨a'⟩ := s
· subst h
simp
· rw [kunion_cons]
by_cases h' : a = a'
· subst h'
simp
· simp [h', ih h]
@[simp]
theorem dlookup_kunion_right {a} {l₁ l₂ : List (Sigma β)} (h : a ∉ l₁.keys) :
dlookup a (kunion l₁ l₂) = dlookup a l₂ := by
induction l₁ generalizing l₂ with
| nil => simp
| cons _ _ ih => simp_all [not_or]
theorem mem_dlookup_kunion {a} {b : β a} {l₁ l₂ : List (Sigma β)} :
b ∈ dlookup a (kunion l₁ l₂) ↔ b ∈ dlookup a l₁ ∨ a ∉ l₁.keys ∧ b ∈ dlookup a l₂ := by
induction l₁ generalizing l₂ with
| | nil => simp
| cons s _ ih =>
obtain ⟨a'⟩ := s
by_cases h₁ : a = a'
· subst h₁
| Mathlib/Data/List/Sigma.lean | 710 | 714 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Localization.Equivalence
/-!
# Morphisms of localizers
A morphism of localizers consists of a functor `F : C₁ ⥤ C₂` between
two categories equipped with morphism properties `W₁` and `W₂` such
that `F` sends morphisms in `W₁` to morphisms in `W₂`.
If `Φ : LocalizerMorphism W₁ W₂`, and that `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂`
are localization functors for `W₁` and `W₂`, the induced functor `D₁ ⥤ D₂`
is denoted `Φ.localizedFunctor L₁ L₂`; we introduce the condition
`Φ.IsLocalizedEquivalence` which expresses that this functor is an equivalence
of categories. This condition is independent of the choice of the
localized categories.
## References
* [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008]
-/
universe v₁ v₂ v₃ v₄ v₄' v₅ v₅' v₆ u₁ u₂ u₃ u₄ u₄' u₅ u₅' u₆
namespace CategoryTheory
open Localization
variable {C₁ : Type u₁} {C₂ : Type u₂} {C₃ : Type u₃} {D₁ : Type u₄} {D₂ : Type u₅}
[Category.{v₁} C₁] [Category.{v₂} C₂] [Category.{v₃} C₃] [Category.{v₄} D₁] [Category.{v₅} D₂]
(W₁ : MorphismProperty C₁) (W₂ : MorphismProperty C₂) (W₃ : MorphismProperty C₃)
/-- If `W₁ : MorphismProperty C₁` and `W₂ : MorphismProperty C₂`, a `LocalizerMorphism W₁ W₂`
is the datum of a functor `C₁ ⥤ C₂` which sends morphisms in `W₁` to morphisms in `W₂` -/
structure LocalizerMorphism where
/-- a functor between the two categories -/
functor : C₁ ⥤ C₂
/-- the functor is compatible with the `MorphismProperty` -/
map : W₁ ≤ W₂.inverseImage functor
namespace LocalizerMorphism
/-- The identity functor as a morphism of localizers. -/
@[simps]
def id : LocalizerMorphism W₁ W₁ where
functor := 𝟭 C₁
map _ _ _ hf := hf
variable {W₁ W₂ W₃}
/-- The composition of two localizers morphisms. -/
@[simps]
def comp (Φ : LocalizerMorphism W₁ W₂) (Ψ : LocalizerMorphism W₂ W₃) :
LocalizerMorphism W₁ W₃ where
functor := Φ.functor ⋙ Ψ.functor
map _ _ _ hf := Ψ.map _ (Φ.map _ hf)
variable (Φ : LocalizerMorphism W₁ W₂)
/-- The opposite localizer morphism `LocalizerMorphism W₁.op W₂.op` deduced
from `Φ : LocalizerMorphism W₁ W₂`. -/
@[simps]
def op : LocalizerMorphism W₁.op W₂.op where
functor := Φ.functor.op
map _ _ _ hf := Φ.map _ hf
variable (L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁] (L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂]
lemma inverts : W₁.IsInvertedBy (Φ.functor ⋙ L₂) :=
fun _ _ _ hf => Localization.inverts L₂ W₂ _ (Φ.map _ hf)
/-- When `Φ : LocalizerMorphism W₁ W₂` and that `L₁` and `L₂` are localization functors
for `W₁` and `W₂`, then `Φ.localizedFunctor L₁ L₂` is the induced functor on the
localized categories. -/
noncomputable def localizedFunctor : D₁ ⥤ D₂ :=
lift (Φ.functor ⋙ L₂) (Φ.inverts _) L₁
noncomputable instance liftingLocalizedFunctor :
Lifting L₁ W₁ (Φ.functor ⋙ L₂) (Φ.localizedFunctor L₁ L₂) := by
dsimp [localizedFunctor]
infer_instance
/-- The 2-commutative square expressing that `Φ.localizedFunctor L₁ L₂` lifts the
functor `Φ.functor` -/
noncomputable instance catCommSq : CatCommSq Φ.functor L₁ L₂ (Φ.localizedFunctor L₁ L₂) :=
CatCommSq.mk (Lifting.iso _ W₁ _ _).symm
variable (G : D₁ ⥤ D₂)
section
variable [CatCommSq Φ.functor L₁ L₂ G]
{D₁' : Type u₄'} {D₂' : Type u₅'}
[Category.{v₄'} D₁'] [Category.{v₅'} D₂']
(L₁' : C₁ ⥤ D₁') (L₂' : C₂ ⥤ D₂') [L₁'.IsLocalization W₁] [L₂'.IsLocalization W₂]
(G' : D₁' ⥤ D₂') [CatCommSq Φ.functor L₁' L₂' G']
include W₁ W₂ Φ L₁ L₂ L₁' L₂'
/-- If a localizer morphism induces an equivalence on some choice of localized categories,
it will be so for any choice of localized categoriees. -/
lemma isEquivalence_imp [G.IsEquivalence] : G'.IsEquivalence :=
let E₁ := Localization.uniq L₁ L₁' W₁
let E₂ := Localization.uniq L₂ L₂' W₂
let e : L₁ ⋙ G ⋙ E₂.functor ≅ L₁ ⋙ E₁.functor ⋙ G' :=
calc
L₁ ⋙ G ⋙ E₂.functor ≅ Φ.functor ⋙ L₂ ⋙ E₂.functor :=
(Functor.associator _ _ _).symm ≪≫
isoWhiskerRight (CatCommSq.iso Φ.functor L₁ L₂ G).symm E₂.functor ≪≫
Functor.associator _ _ _
_ ≅ Φ.functor ⋙ L₂' := isoWhiskerLeft Φ.functor (compUniqFunctor L₂ L₂' W₂)
_ ≅ L₁' ⋙ G' := CatCommSq.iso Φ.functor L₁' L₂' G'
_ ≅ L₁ ⋙ E₁.functor ⋙ G' :=
isoWhiskerRight (compUniqFunctor L₁ L₁' W₁).symm G' ≪≫ Functor.associator _ _ _
have := Functor.isEquivalence_of_iso
(liftNatIso L₁ W₁ _ _ (G ⋙ E₂.functor) (E₁.functor ⋙ G') e)
Functor.isEquivalence_of_comp_left E₁.functor G'
lemma isEquivalence_iff : G.IsEquivalence ↔ G'.IsEquivalence :=
⟨fun _ => Φ.isEquivalence_imp L₁ L₂ G L₁' L₂' G',
fun _ => Φ.isEquivalence_imp L₁' L₂' G' L₁ L₂ G⟩
end
/-- Condition that a `LocalizerMorphism` induces an equivalence on the localized categories -/
class IsLocalizedEquivalence : Prop where
/-- the induced functor on the constructed localized categories is an equivalence -/
isEquivalence : (Φ.localizedFunctor W₁.Q W₂.Q).IsEquivalence
lemma IsLocalizedEquivalence.mk' [CatCommSq Φ.functor L₁ L₂ G] [G.IsEquivalence] :
Φ.IsLocalizedEquivalence where
isEquivalence := by
rw [Φ.isEquivalence_iff W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q) L₁ L₂ G]
exact inferInstance
/-- If a `LocalizerMorphism` is a localized equivalence, then any compatible functor
between the localized categories is an equivalence. -/
lemma isEquivalence [h : Φ.IsLocalizedEquivalence] [CatCommSq Φ.functor L₁ L₂ G] :
G.IsEquivalence := (by
rw [Φ.isEquivalence_iff L₁ L₂ G W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q)]
exact h.isEquivalence)
/-- If a `LocalizerMorphism` is a localized equivalence, then the induced functor on
the localized categories is an equivalence -/
instance localizedFunctor_isEquivalence [Φ.IsLocalizedEquivalence] :
(Φ.localizedFunctor L₁ L₂).IsEquivalence :=
Φ.isEquivalence L₁ L₂ _
/-- When `Φ : LocalizerMorphism W₁ W₂`, if the composition `Φ.functor ⋙ L₂` is a
localization functor for `W₁`, then `Φ` is a localized equivalence. -/
lemma IsLocalizedEquivalence.of_isLocalization_of_isLocalization
[(Φ.functor ⋙ L₂).IsLocalization W₁] :
IsLocalizedEquivalence Φ := by
have : CatCommSq Φ.functor (Φ.functor ⋙ L₂) L₂ (𝟭 D₂) :=
CatCommSq.mk (Functor.rightUnitor _).symm
exact IsLocalizedEquivalence.mk' Φ (Φ.functor ⋙ L₂) L₂ (𝟭 D₂)
| /-- When the underlying functor `Φ.functor` of `Φ : LocalizerMorphism W₁ W₂` is
an equivalence of categories and that `W₁` and `W₂` essentially correspond to each
other via this equivalence, then `Φ` is a localized equivalence. -/
lemma IsLocalizedEquivalence.of_equivalence [Φ.functor.IsEquivalence]
(h : W₂ ≤ W₁.map Φ.functor) : IsLocalizedEquivalence Φ := by
haveI : Functor.IsLocalization (Φ.functor ⋙ MorphismProperty.Q W₂) W₁ := by
refine Functor.IsLocalization.of_equivalence_source W₂.Q W₂ (Φ.functor ⋙ W₂.Q) W₁
(Functor.asEquivalence Φ.functor).symm ?_ (Φ.inverts W₂.Q)
((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight ((Equivalence.unitIso _).symm) _ ≪≫
Functor.leftUnitor _)
erw [W₁.isoClosure.inverseImage_equivalence_functor_eq_map_inverse]
rw [MorphismProperty.map_isoClosure]
exact h
exact IsLocalizedEquivalence.of_isLocalization_of_isLocalization Φ W₂.Q
| Mathlib/CategoryTheory/Localization/LocalizerMorphism.lean | 161 | 175 |
/-
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₂ ∧
| Mathlib/Data/Stream/Init.lean | 292 | 293 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
| @[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
| Mathlib/Data/Complex/Exponential.lean | 334 | 337 |
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Rémy Degenne
-/
import Mathlib.Probability.Process.Adapted
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
/-!
# Stopping times, stopped processes and stopped values
Definition and properties of stopping times.
## Main definitions
* `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a
function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is
`f i`-measurable
* `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time
## Main results
* `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is
progressively measurable.
* `memLp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped
process belongs to `ℒp` as well.
## Tags
stopping time, stochastic process
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ω β ι : Type*} {m : MeasurableSpace Ω}
/-! ### Stopping times -/
/-- A stopping time with respect to some filtration `f` is a function
`τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable
with respect to `f i`.
Intuitively, the stopping time `τ` describes some stopping rule such that at time
`i`, we may determine it with the information we have at time `i`. -/
def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) :=
∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i}
theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) :
IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const]
section MeasurableSet
section Preorder
variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι}
protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω ≤ i} :=
hτ i
theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) :
MeasurableSet[f i] {ω | τ ω < i} := by
by_cases hi_min : IsMin i
· suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 ω
| simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
rw [isMin_iff_forall_not_lt] at hi_min
exact hi_min (τ ω)
have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min]
rw [this]
exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i)
end Preorder
section CountableStoppingTime
| Mathlib/Probability/Process/Stopping.lean | 72 | 82 |
/-
Copyright (c) 2022 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno, Calle Sönne
-/
import Mathlib.CategoryTheory.Bicategory.Functor.Oplax
import Mathlib.CategoryTheory.Bicategory.Functor.Lax
/-!
# Pseudofunctors
A pseudofunctor is an oplax (or lax) functor whose `mapId` and `mapComp` are isomorphisms.
We provide several constructors for pseudofunctors:
* `Pseudofunctor.mk` : the default constructor, which requires `map₂_whiskerLeft` and
`map₂_whiskerRight` instead of naturality of `mapComp`.
* `Pseudofunctor.mkOfOplax` : construct a pseudofunctor from an oplax functor whose
`mapId` and `mapComp` are isomorphisms. This constructor uses `Iso` to describe isomorphisms.
* `pseudofunctor.mkOfOplax'` : similar to `mkOfOplax`, but uses `IsIso` to describe isomorphisms.
* `Pseudofunctor.mkOfLax` : construct a pseudofunctor from a lax functor whose
`mapId` and `mapComp` are isomorphisms. This constructor uses `Iso` to describe isomorphisms.
* `pseudofunctor.mkOfLax'` : similar to `mkOfLax`, but uses `IsIso` to describe isomorphisms.
## Main definitions
* `CategoryTheory.Pseudofunctor B C` : a pseudofunctor between bicategories `B` and `C`
* `CategoryTheory.Pseudofunctor.comp F G` : the composition of pseudofunctors
-/
namespace CategoryTheory
open Category Bicategory
open Bicategory
universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃
variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C]
variable {D : Type u₃} [Bicategory.{w₃, v₃} D]
/-- A pseudofunctor `F` between bicategories `B` and `C` consists of a function between objects
`F.obj`, a function between 1-morphisms `F.map`, and a function between 2-morphisms `F.map₂`.
Unlike functors between categories, `F.map` do not need to strictly commute with the compositions,
and do not need to strictly preserve the identity. Instead, there are specified 2-isomorphisms
`F.map (𝟙 a) ≅ 𝟙 (F.obj a)` and `F.map (f ≫ g) ≅ F.map f ≫ F.map g`.
`F.map₂` strictly commute with compositions and preserve the identity. They also preserve the
associator, the left unitor, and the right unitor modulo some adjustments of domains and codomains
of 2-morphisms.
-/
structure Pseudofunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂)
[Bicategory.{w₂, v₂} C] extends PrelaxFunctor B C where
mapId (a : B) : map (𝟙 a) ≅ 𝟙 (obj a)
mapComp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : map (f ≫ g) ≅ map f ≫ map g
map₂_whisker_left :
∀ {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h),
map₂ (f ◁ η) = (mapComp f g).hom ≫ map f ◁ map₂ η ≫ (mapComp f h).inv := by
aesop_cat
map₂_whisker_right :
∀ {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c),
map₂ (η ▷ h) = (mapComp f h).hom ≫ map₂ η ▷ map h ≫ (mapComp g h).inv := by
aesop_cat
map₂_associator :
∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d),
map₂ (α_ f g h).hom = (mapComp (f ≫ g) h).hom ≫ (mapComp f g).hom ▷ map h ≫
(α_ (map f) (map g) (map h)).hom ≫ map f ◁ (mapComp g h).inv ≫
(mapComp f (g ≫ h)).inv := by
aesop_cat
map₂_left_unitor :
∀ {a b : B} (f : a ⟶ b),
map₂ (λ_ f).hom = (mapComp (𝟙 a) f).hom ≫ (mapId a).hom ▷ map f ≫ (λ_ (map f)).hom := by
aesop_cat
map₂_right_unitor :
∀ {a b : B} (f : a ⟶ b),
map₂ (ρ_ f).hom = (mapComp f (𝟙 b)).hom ≫ map f ◁ (mapId b).hom ≫ (ρ_ (map f)).hom := by
aesop_cat
initialize_simps_projections Pseudofunctor (+toPrelaxFunctor, -obj, -map, -map₂)
namespace Pseudofunctor
attribute [simp, reassoc, to_app]
map₂_whisker_left map₂_whisker_right map₂_associator map₂_left_unitor map₂_right_unitor
section
open Iso
/-- The underlying prelax functor. -/
add_decl_doc Pseudofunctor.toPrelaxFunctor
attribute [nolint docBlame] CategoryTheory.Pseudofunctor.mapId
CategoryTheory.Pseudofunctor.mapComp
CategoryTheory.Pseudofunctor.map₂_whisker_left
CategoryTheory.Pseudofunctor.map₂_whisker_right
CategoryTheory.Pseudofunctor.map₂_associator
CategoryTheory.Pseudofunctor.map₂_left_unitor
CategoryTheory.Pseudofunctor.map₂_right_unitor
variable (F : Pseudofunctor B C)
/-- The oplax functor associated with a pseudofunctor. -/
@[simps]
def toOplax : OplaxFunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := fun a => (F.mapId a).hom
mapComp := fun f g => (F.mapComp f g).hom
instance hasCoeToOplax : Coe (Pseudofunctor B C) (OplaxFunctor B C) :=
⟨toOplax⟩
/-- The Lax functor associated with a pseudofunctor. -/
@[simps]
def toLax : LaxFunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := fun a => (F.mapId a).inv
mapComp := fun f g => (F.mapComp f g).inv
map₂_leftUnitor f := by
rw [← F.map₂Iso_inv, eq_inv_comp, comp_inv_eq]
simp
map₂_rightUnitor f := by
rw [← F.map₂Iso_inv, eq_inv_comp, comp_inv_eq]
simp
instance hasCoeToLax : Coe (Pseudofunctor B C) (LaxFunctor B C) :=
⟨toLax⟩
/-- The identity pseudofunctor. -/
@[simps]
def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : Pseudofunctor B B where
toPrelaxFunctor := PrelaxFunctor.id B
mapId := fun a => Iso.refl (𝟙 a)
mapComp := fun f g => Iso.refl (f ≫ g)
instance : Inhabited (Pseudofunctor B B) :=
⟨id B⟩
/-- Composition of pseudofunctors. -/
@[simps]
def comp (F : Pseudofunctor B C) (G : Pseudofunctor C D) : Pseudofunctor B D where
toPrelaxFunctor := F.toPrelaxFunctor.comp G.toPrelaxFunctor
mapId := fun a => G.map₂Iso (F.mapId a) ≪≫ G.mapId (F.obj a)
mapComp := fun f g => (G.map₂Iso (F.mapComp f g)) ≪≫ G.mapComp (F.map f) (F.map g)
-- Note: whilst these are all provable by `aesop_cat`, the proof is very slow
map₂_whisker_left f η := by dsimp; simp
map₂_whisker_right η h := by dsimp; simp
map₂_associator f g h := by dsimp; simp
map₂_left_unitor f := by dsimp; simp
map₂_right_unitor f := by dsimp; simp
section
variable (F : Pseudofunctor B C) {a b : B}
@[reassoc, to_app]
lemma mapComp_assoc_right_hom {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(F.mapComp f (g ≫ h)).hom ≫ F.map f ◁ (F.mapComp g h).hom = F.map₂ (α_ f g h).inv ≫
(F.mapComp (f ≫ g) h).hom ≫ (F.mapComp f g).hom ▷ F.map h ≫
(α_ (F.map f) (F.map g) (F.map h)).hom :=
F.toOplax.mapComp_assoc_right _ _ _
@[reassoc, to_app]
lemma mapComp_assoc_left_hom {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(F.mapComp (f ≫ g) h).hom ≫ (F.mapComp f g).hom ▷ F.map h =
F.map₂ (α_ f g h).hom ≫ (F.mapComp f (g ≫ h)).hom ≫ F.map f ◁ (F.mapComp g h).hom
≫ (α_ (F.map f) (F.map g) (F.map h)).inv :=
F.toOplax.mapComp_assoc_left _ _ _
@[reassoc, to_app]
lemma mapComp_assoc_right_inv {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
F.map f ◁ (F.mapComp g h).inv ≫ (F.mapComp f (g ≫ h)).inv =
(α_ (F.map f) (F.map g) (F.map h)).inv ≫ (F.mapComp f g).inv ▷ F.map h ≫
(F.mapComp (f ≫ g) h).inv ≫ F.map₂ (α_ f g h).hom :=
F.toLax.mapComp_assoc_right _ _ _
@[reassoc, to_app]
lemma mapComp_assoc_left_inv {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(F.mapComp f g).inv ▷ F.map h ≫ (F.mapComp (f ≫ g) h).inv =
(α_ (F.map f) (F.map g) (F.map h)).hom ≫ F.map f ◁ (F.mapComp g h).inv ≫
(F.mapComp f (g ≫ h)).inv ≫ F.map₂ (α_ f g h).inv :=
F.toLax.mapComp_assoc_left _ _ _
@[reassoc, to_app]
lemma mapComp_id_left_hom (f : a ⟶ b) : (F.mapComp (𝟙 a) f).hom =
F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv ≫ (F.mapId a).inv ▷ F.map f := by
simp
lemma mapComp_id_left (f : a ⟶ b) : (F.mapComp (𝟙 a) f) = F.map₂Iso (λ_ f) ≪≫
(λ_ (F.map f)).symm ≪≫ (whiskerRightIso (F.mapId a) (F.map f)).symm :=
Iso.ext <| F.mapComp_id_left_hom f
@[reassoc, to_app]
lemma mapComp_id_left_inv (f : a ⟶ b) : (F.mapComp (𝟙 a) f).inv =
(F.mapId a).hom ▷ F.map f ≫ (λ_ (F.map f)).hom ≫ F.map₂ (λ_ f).inv := by
simp [mapComp_id_left]
lemma whiskerRightIso_mapId (f : a ⟶ b) : whiskerRightIso (F.mapId a) (F.map f) =
(F.mapComp (𝟙 a) f).symm ≪≫ F.map₂Iso (λ_ f) ≪≫ (λ_ (F.map f)).symm := by
simp [mapComp_id_left]
@[reassoc, to_app]
lemma whiskerRight_mapId_hom (f : a ⟶ b) : (F.mapId a).hom ▷ F.map f =
(F.mapComp (𝟙 a) f).inv ≫ F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv := by
simp [whiskerRightIso_mapId]
@[reassoc, to_app]
lemma whiskerRight_mapId_inv (f : a ⟶ b) : (F.mapId a).inv ▷ F.map f =
(λ_ (F.map f)).hom ≫ F.map₂ (λ_ f).inv ≫ (F.mapComp (𝟙 a) f).hom := by
simpa using congrArg (·.inv) (F.whiskerRightIso_mapId f)
@[reassoc, to_app]
lemma mapComp_id_right_hom (f : a ⟶ b) : (F.mapComp f (𝟙 b)).hom =
F.map₂ (ρ_ f).hom ≫ (ρ_ (F.map f)).inv ≫ F.map f ◁ (F.mapId b).inv := by
simp
lemma mapComp_id_right (f : a ⟶ b) : (F.mapComp f (𝟙 b)) = F.map₂Iso (ρ_ f) ≪≫
(ρ_ (F.map f)).symm ≪≫ (whiskerLeftIso (F.map f) (F.mapId b)).symm :=
Iso.ext <| F.mapComp_id_right_hom f
@[reassoc, to_app]
lemma mapComp_id_right_inv (f : a ⟶ b) : (F.mapComp f (𝟙 b)).inv =
F.map f ◁ (F.mapId b).hom ≫ (ρ_ (F.map f)).hom ≫ F.map₂ (ρ_ f).inv := by
simp [mapComp_id_right]
lemma whiskerLeftIso_mapId (f : a ⟶ b) : whiskerLeftIso (F.map f) (F.mapId b) =
| (F.mapComp f (𝟙 b)).symm ≪≫ F.map₂Iso (ρ_ f) ≪≫ (ρ_ (F.map f)).symm := by
simp [mapComp_id_right]
@[reassoc, to_app]
| Mathlib/CategoryTheory/Bicategory/Functor/Pseudofunctor.lean | 230 | 233 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.TangentCone
import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics
import Mathlib.Analysis.Asymptotics.TVS
import Mathlib.Analysis.Asymptotics.Lemmas
/-!
# The Fréchet derivative
Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a
continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then
`HasFDerivWithinAt f f' s x`
says that `f` has derivative `f'` at `x`, where the domain of interest
is restricted to `s`. We also have
`HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ`
Finally,
`HasStrictFDerivAt f f' x`
means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,
i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse
function theorem, and is defined here only to avoid proving theorems like
`IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for
`HasStrictFDerivAt`.
## Main results
In addition to the definition and basic properties of the derivative,
the folder `Analysis/Calculus/FDeriv/` contains the usual formulas
(and existence assertions) for the derivative of
* constants
* the identity
* bounded linear maps (`Linear.lean`)
* bounded bilinear maps (`Bilinear.lean`)
* sum of two functions (`Add.lean`)
* sum of finitely many functions (`Add.lean`)
* multiplication of a function by a scalar constant (`Add.lean`)
* negative of a function (`Add.lean`)
* subtraction of two functions (`Add.lean`)
* multiplication of a function by a scalar function (`Mul.lean`)
* multiplication of two scalar functions (`Mul.lean`)
* composition of functions (the chain rule) (`Comp.lean`)
* inverse function (`Mul.lean`)
(assuming that it exists; the inverse function theorem is in `../Inverse.lean`)
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier,
and they more frequently lead to the desired result.
One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying
a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are
translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The
derivative of polynomials is handled there, as it is naturally one-dimensional.
The simplifier is set up to prove automatically that some functions are differentiable, or
differentiable at a point (but not differentiable on a set or within a set at a point, as checking
automatically that the good domains are mapped one to the other when using composition is not
something the simplifier can easily do). This means that one can write
`example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`.
If there are divisions, one needs to supply to the simplifier proofs that the denominators do
not vanish, as in
```lean
example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by
simp [h]
```
Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be
differentiable, in `Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv`.
The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general
complicated multidimensional linear maps), but it will compute one-dimensional derivatives,
see `Deriv.lean`.
## Implementation details
The derivative is defined in terms of the `IsLittleOTVS` relation to ensure the definition does not
ingrain a choice of norm, and is then quickly translated to the more convenient `IsLittleO` in the
subsequent theorems.
It is also characterized in terms of the `Tendsto` relation.
We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field,
`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,
and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`,
`DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative.
To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x`
for some choice of a derivative if it exists, and the zero function otherwise. This choice only
behaves well along sets for which the derivative is unique, i.e., those for which the tangent
directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and
`UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed
they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular
for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very
beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.
To make sure that the simplifier can prove automatically that functions are differentiable, we tag
many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable
functions is differentiable, as well as their product, their cartesian product, and so on. A notable
exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are
differentiable, then their composition also is: `simp` would always be able to match this lemma,
by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),
we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding
some boilerplate lemmas, but these can also be useful in their own right.
Tests for this ability of the simplifier (with more examples) are provided in
`Tests/Differentiable.lean`.
## TODO
Generalize more results to topological vector spaces.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section TVS
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
variable {F : Type*} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F]
/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition
is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion
of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to
the notion of Fréchet derivative along the set `s`. -/
@[mk_iff hasFDerivAtFilter_iff_isLittleOTVS]
structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where
of_isLittleOTVS ::
isLittleOTVS : (fun x' => f x' - f x - f' (x' - x)) =o[𝕜; L] (fun x' => x' - x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/
@[fun_prop]
def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) :=
HasFDerivAtFilter f f' x (𝓝[s] x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/
@[fun_prop]
def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
HasFDerivAtFilter f f' x (𝓝 x)
/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*
if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required,
e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly
differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/
@[fun_prop, mk_iff hasStrictFDerivAt_iff_isLittleOTVS]
structure HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) where
of_isLittleOTVS ::
isLittleOTVS :
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2))
=o[𝕜; 𝓝 (x, x)] (fun p : E × E => p.1 - p.2)
variable (𝕜)
/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative
there (possibly non-unique). -/
@[fun_prop]
def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x
/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly
non-unique). -/
@[fun_prop]
def DifferentiableAt (f : E → F) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivAt f f' x
open scoped Classical in
/-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. We also set it to be zero, if zero is one of possible derivatives. -/
irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F :=
if HasFDerivWithinAt f (0 : E →L[𝕜] F) s x
then 0
else if h : DifferentiableWithinAt 𝕜 f s x
then Classical.choose h
else 0
/-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is
set to `0`. -/
irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F :=
fderivWithin 𝕜 f univ x
/-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/
@[fun_prop]
def DifferentiableOn (f : E → F) (s : Set E) :=
∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x
/-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/
@[fun_prop]
def Differentiable (f : E → F) :=
∀ x, DifferentiableAt 𝕜 f x
variable {𝕜}
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) :
fderivWithin 𝕜 f s x = 0 := by
simp [fderivWithin, h]
@[simp]
theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by
ext
rw [fderiv]
end TVS
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem hasFDerivAtFilter_iff_isLittleO :
HasFDerivAtFilter f f' x L ↔ (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x :=
(hasFDerivAtFilter_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasFDerivAtFilter.isLittleO, HasFDerivAtFilter.of_isLittleO⟩ :=
hasFDerivAtFilter_iff_isLittleO
theorem hasStrictFDerivAt_iff_isLittleO :
HasStrictFDerivAt f f' x ↔
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
(hasStrictFDerivAt_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasStrictFDerivAt.isLittleO, HasStrictFDerivAt.of_isLittleO⟩ :=
hasStrictFDerivAt_iff_isLittleO
section DerivativeUniqueness
/- In this section, we discuss the uniqueness of the derivative.
We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the
uniqueness of the derivative. -/
/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',
i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity
and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses
this fact, for functions having a derivative within a set. Its specific formulation is useful for
tangent cone related discussions. -/
theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α)
{c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)
(clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) :
Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by
have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by
conv in 𝓝[s] x => rw [← add_zero x]
rw [nhdsWithin, tendsto_inf]
constructor
· apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim)
· rwa [tendsto_principal]
have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO
have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x :=
this.comp_tendsto tendsto_arg
have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left]
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n :=
(isBigO_refl c l).smul_isLittleO this
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) :=
this.trans_isBigO (cdlim.isBigO_one ℝ)
have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=
(isLittleO_one_iff ℝ).1 this
have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) :=
Tendsto.comp f'.cont.continuousAt cdlim
have L3 :
Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) :=
L1.add L2
have :
(fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n =>
c n • (f (x + d n) - f x) := by
ext n
simp [smul_add, smul_sub]
rwa [this, zero_add] at L3
/-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the
tangent cone to `s` at `x` -/
theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) :=
fun _ ⟨_, _, dtop, clim, cdlim⟩ =>
tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim)
/-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/
theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
ContinuousLinearMap.ext_on H.1 (hf.unique_on hg)
theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x)
(h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
(H x hx).eq h h₁
end DerivativeUniqueness
section FDerivProperties
/-! ### Basic properties of the derivative -/
theorem hasFDerivAtFilter_iff_tendsto :
HasFDerivAtFilter f f' x L ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by
have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by
rw [sub_eq_zero.1 (norm_eq_zero.1 hx')]
simp
rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right,
isLittleO_iff_tendsto h]
exact tendsto_congr fun _ => div_eq_inv_mul _ _
theorem hasFDerivWithinAt_iff_tendsto :
HasFDerivWithinAt f f' s x ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_tendsto :
HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_isLittleO_nhds_zero :
HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by
rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map]
simp [Function.comp_def]
nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) :
HasFDerivAtFilter f f' x L₁ :=
.of_isLittleOTVS <| h.isLittleOTVS.mono hst
theorem HasFDerivWithinAt.mono_of_mem_nhdsWithin
(h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_le_iff.mpr hst
@[deprecated (since := "2024-10-31")]
alias HasFDerivWithinAt.mono_of_mem := HasFDerivWithinAt.mono_of_mem_nhdsWithin
nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_mono _ hst
theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) :
HasFDerivAtFilter f f' x L :=
h.mono hL
@[fun_prop]
theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x :=
h.hasFDerivAtFilter inf_le_left
@[fun_prop]
theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) :
DifferentiableWithinAt 𝕜 f s x :=
⟨f', h⟩
@[fun_prop]
theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x :=
⟨f', h⟩
@[simp]
theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by
simp only [HasFDerivWithinAt, nhdsWithin_univ, HasFDerivAt]
alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ
theorem differentiableWithinAt_univ :
DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt]
theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by
rw [fderiv, fderivWithin_zero_of_not_differentiableWithinAt]
rwa [differentiableWithinAt_univ]
theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by
rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h]
lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x :=
hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx)
@[simp]
theorem hasFDerivWithinAt_insert {y : E} :
HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by
rcases eq_or_ne x y with (rfl | h)
· simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
apply isLittleOTVS_insert
simp only [sub_self, map_zero]
refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem_nhdsWithin ?_⟩
simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin]
alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert
protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) :
HasFDerivWithinAt g g' (insert x s) x :=
h.insert'
@[simp]
theorem hasFDerivWithinAt_diff_singleton (y : E) :
HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by
rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert]
@[simp]
protected theorem HasFDerivWithinAt.empty : HasFDerivWithinAt f f' ∅ x := by
simp [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
@[simp]
protected theorem DifferentiableWithinAt.empty : DifferentiableWithinAt 𝕜 f ∅ x :=
⟨0, .empty⟩
theorem HasFDerivWithinAt.of_finite (h : s.Finite) : HasFDerivWithinAt f f' s x := by
induction s, h using Set.Finite.induction_on with
| empty => exact .empty
| insert _ _ ih => exact ih.insert'
theorem DifferentiableWithinAt.of_finite (h : s.Finite) : DifferentiableWithinAt 𝕜 f s x :=
⟨0, .of_finite h⟩
@[simp]
protected theorem HasFDerivWithinAt.singleton {y} : HasFDerivWithinAt f f' {x} y :=
.of_finite <| finite_singleton _
@[simp]
protected theorem DifferentiableWithinAt.singleton {y} : DifferentiableWithinAt 𝕜 f {x} y :=
⟨0, .singleton⟩
theorem HasFDerivWithinAt.of_subsingleton (h : s.Subsingleton) : HasFDerivWithinAt f f' s x :=
.of_finite h.finite
theorem DifferentiableWithinAt.of_subsingleton (h : s.Subsingleton) :
DifferentiableWithinAt 𝕜 f s x :=
.of_finite h.finite
theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) :
(fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
hf.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _)
theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) :
(fun x' => f x' - f x) =O[L] fun x' => x' - x :=
h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _)
@[fun_prop]
protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) :
HasFDerivAt f f' x :=
.of_isLittleOTVS <| by
simpa only using hf.isLittleOTVS.comp_tendsto (tendsto_id.prodMk_nhds tendsto_const_nhds)
protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) :
DifferentiableAt 𝕜 f x :=
hf.hasFDerivAt.differentiableAt
/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is
`K`-Lipschitz in a neighborhood of `x`. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x)
(K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by
have := hf.isLittleO.add_isBigOWith (f'.isBigOWith_comp _ _) hK
simp only [sub_add_cancel, IsBigOWith] at this
rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩
exact
⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩
/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a
neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a
more precise statement. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) :
∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s :=
(exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt
/-- Directional derivative agrees with `HasFDeriv`. -/
theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α}
(hc : Tendsto (fun n => ‖c n‖) l atTop) :
Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by
refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_
intro U hU
refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_
convert mem_of_mem_nhds hU
dsimp only
rw [← mul_smul, mul_inv_cancel₀ hy, one_smul]
theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by
rw [← hasFDerivWithinAt_univ] at h₀ h₁
exact uniqueDiffWithinAt_univ.eq h₀ h₁
theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h]
theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict' s h]
theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x)
(ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by
simp only [HasFDerivWithinAt, nhdsWithin_union]
exact .of_isLittleOTVS <| hs.isLittleOTVS.sup ht.isLittleOTVS
theorem HasFDerivWithinAt.hasFDerivAt (h : HasFDerivWithinAt f f' s x) (hs : s ∈ 𝓝 x) :
HasFDerivAt f f' x := by
rwa [← univ_inter s, hasFDerivWithinAt_inter hs, hasFDerivWithinAt_univ] at h
theorem DifferentiableWithinAt.differentiableAt (h : DifferentiableWithinAt 𝕜 f s x)
(hs : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x :=
h.imp fun _ hf' => hf'.hasFDerivAt hs
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_not_accPt (h : ¬AccPt x (𝓟 s)) : HasFDerivWithinAt f f' s x := by
rw [accPt_principal_iff_nhdsWithin, not_neBot] at h
rw [← hasFDerivWithinAt_diff_singleton x, HasFDerivWithinAt, h,
hasFDerivAtFilter_iff_isLittleOTVS]
exact .bot
/-- If `x` is isolated in `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
@[deprecated HasFDerivWithinAt.of_not_accPt (since := "2025-04-20")]
theorem HasFDerivWithinAt.of_nhdsWithin_eq_bot (h : 𝓝[s \ {x}] x = ⊥) :
HasFDerivWithinAt f f' s x :=
.of_not_accPt <| by rwa [accPt_principal_iff_nhdsWithin, not_neBot]
/-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`,
as this statement is empty. -/
theorem HasFDerivWithinAt.of_not_mem_closure (h : x ∉ closure s) : HasFDerivWithinAt f f' s x :=
.of_not_accPt (h ·.clusterPt.mem_closure)
@[deprecated (since := "2025-04-20")]
alias hasFDerivWithinAt_of_nmem_closure := HasFDerivWithinAt.of_not_mem_closure
theorem fderivWithin_zero_of_not_accPt (h : ¬AccPt x (𝓟 s)) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos (.of_not_accPt h)]
set_option linter.deprecated false in
@[deprecated fderivWithin_zero_of_not_accPt (since := "2025-04-20")]
theorem fderivWithin_zero_of_isolated (h : 𝓝[s \ {x}] x = ⊥) : fderivWithin 𝕜 f s x = 0 := by
rw [fderivWithin, if_pos (.of_nhdsWithin_eq_bot h)]
theorem fderivWithin_zero_of_nmem_closure (h : x ∉ closure s) : fderivWithin 𝕜 f s x = 0 :=
fderivWithin_zero_of_not_accPt (h ·.clusterPt.mem_closure)
theorem DifferentiableWithinAt.hasFDerivWithinAt (h : DifferentiableWithinAt 𝕜 f s x) :
HasFDerivWithinAt f (fderivWithin 𝕜 f s x) s x := by
simp only [fderivWithin, dif_pos h]
split_ifs with h₀
exacts [h₀, Classical.choose_spec h]
theorem DifferentiableAt.hasFDerivAt (h : DifferentiableAt 𝕜 f x) :
HasFDerivAt f (fderiv 𝕜 f x) x := by
rw [fderiv, ← hasFDerivWithinAt_univ]
rw [← differentiableWithinAt_univ] at h
exact h.hasFDerivWithinAt
theorem DifferentiableOn.hasFDerivAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
HasFDerivAt f (fderiv 𝕜 f x) x :=
((h x (mem_of_mem_nhds hs)).differentiableAt hs).hasFDerivAt
theorem DifferentiableOn.differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
DifferentiableAt 𝕜 f x :=
(h.hasFDerivAt hs).differentiableAt
theorem DifferentiableOn.eventually_differentiableAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) :
∀ᶠ y in 𝓝 x, DifferentiableAt 𝕜 f y :=
(eventually_eventually_nhds.2 hs).mono fun _ => h.differentiableAt
protected theorem HasFDerivAt.fderiv (h : HasFDerivAt f f' x) : fderiv 𝕜 f x = f' := by
ext
rw [h.unique h.differentiableAt.hasFDerivAt]
theorem fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, HasFDerivAt f (f' x) x) : fderiv 𝕜 f = f' :=
funext fun x => (h x).fderiv
protected theorem HasFDerivWithinAt.fderivWithin (h : HasFDerivWithinAt f f' s x)
(hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 f s x = f' :=
(hxs.eq h h.differentiableWithinAt.hasFDerivWithinAt).symm
theorem DifferentiableWithinAt.mono (h : DifferentiableWithinAt 𝕜 f t x) (st : s ⊆ t) :
DifferentiableWithinAt 𝕜 f s x := by
rcases h with ⟨f', hf'⟩
| exact ⟨f', hf'.mono st⟩
theorem DifferentiableWithinAt.mono_of_mem_nhdsWithin
(h : DifferentiableWithinAt 𝕜 f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) :
DifferentiableWithinAt 𝕜 f t x :=
(h.hasFDerivWithinAt.mono_of_mem_nhdsWithin hst).differentiableWithinAt
| Mathlib/Analysis/Calculus/FDeriv/Basic.lean | 588 | 594 |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.BigOperators.Group.List.Lemmas
import Mathlib.Algebra.Group.Action.Hom
import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Data.List.FinRange
import Mathlib.Data.SetLike.Basic
import Mathlib.Data.Sigma.Basic
import Lean.Elab.Tactic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Additively-graded multiplicative structures
This module provides a set of heterogeneous typeclasses for defining a multiplicative structure
over the sigma type `GradedMonoid A` such that `(*) : A i → A j → A (i + j)`; that is to say, `A`
forms an additively-graded monoid. The typeclasses are:
* `GradedMonoid.GOne A`
* `GradedMonoid.GMul A`
* `GradedMonoid.GMonoid A`
* `GradedMonoid.GCommMonoid A`
These respectively imbue:
* `One (GradedMonoid A)`
* `Mul (GradedMonoid A)`
* `Monoid (GradedMonoid A)`
* `CommMonoid (GradedMonoid A)`
the base type `A 0` with:
* `GradedMonoid.GradeZero.One`
* `GradedMonoid.GradeZero.Mul`
* `GradedMonoid.GradeZero.Monoid`
* `GradedMonoid.GradeZero.CommMonoid`
and the `i`th grade `A i` with `A 0`-actions (`•`) defined as left-multiplication:
* (nothing)
* `GradedMonoid.GradeZero.SMul (A 0)`
* `GradedMonoid.GradeZero.MulAction (A 0)`
* (nothing)
For now, these typeclasses are primarily used in the construction of `DirectSum.Ring` and the rest
of that file.
## Dependent graded products
This also introduces `List.dProd`, which takes the (possibly non-commutative) product of a list
of graded elements of type `A i`. This definition primarily exist to allow `GradedMonoid.mk`
and `DirectSum.of` to be pulled outside a product, such as in `GradedMonoid.mk_list_dProd` and
`DirectSum.of_list_dProd`.
## Internally graded monoids
In addition to the above typeclasses, in the most frequent case when `A` is an indexed collection of
`SetLike` subobjects (such as `AddSubmonoid`s, `AddSubgroup`s, or `Submodule`s), this file
provides the `Prop` typeclasses:
* `SetLike.GradedOne A` (which provides the obvious `GradedMonoid.GOne A` instance)
* `SetLike.GradedMul A` (which provides the obvious `GradedMonoid.GMul A` instance)
* `SetLike.GradedMonoid A` (which provides the obvious `GradedMonoid.GMonoid A` and
`GradedMonoid.GCommMonoid A` instances)
which respectively provide the API lemmas
* `SetLike.one_mem_graded`
* `SetLike.mul_mem_graded`
* `SetLike.pow_mem_graded`, `SetLike.list_prod_map_mem_graded`
Strictly this last class is unnecessary as it has no fields not present in its parents, but it is
included for convenience. Note that there is no need for `SetLike.GradedRing` or similar, as all
the information it would contain is already supplied by `GradedMonoid` when `A` is a collection
of objects satisfying `AddSubmonoidClass` such as `Submodule`s. These constructions are explored
in `Algebra.DirectSum.Internal`.
This file also defines:
* `SetLike.IsHomogeneousElem A` (which says that `a` is homogeneous iff `a ∈ A i` for some `i : ι`)
* `SetLike.homogeneousSubmonoid A`, which is, as the name suggests, the submonoid consisting of
all the homogeneous elements.
## Tags
graded monoid
-/
variable {ι : Type*}
/-- A type alias of sigma types for graded monoids. -/
def GradedMonoid (A : ι → Type*) :=
Sigma A
namespace GradedMonoid
instance {A : ι → Type*} [Inhabited ι] [Inhabited (A default)] : Inhabited (GradedMonoid A) :=
inferInstanceAs <| Inhabited (Sigma _)
/-- Construct an element of a graded monoid. -/
def mk {A : ι → Type*} : ∀ i, A i → GradedMonoid A :=
Sigma.mk
/-! ### Actions -/
section actions
variable {α β} {A : ι → Type*}
/-- If `R` acts on each `A i`, then it acts on `GradedMonoid A` via the `.2` projection. -/
instance [∀ i, SMul α (A i)] : SMul α (GradedMonoid A) where
smul r g := GradedMonoid.mk g.1 (r • g.2)
@[simp] theorem fst_smul [∀ i, SMul α (A i)] (a : α) (x : GradedMonoid A) :
(a • x).fst = x.fst := rfl
@[simp] theorem snd_smul [∀ i, SMul α (A i)] (a : α) (x : GradedMonoid A) :
(a • x).snd = a • x.snd := rfl
theorem smul_mk [∀ i, SMul α (A i)] {i} (c : α) (a : A i) :
c • mk i a = mk i (c • a) :=
rfl
instance [∀ i, SMul α (A i)] [∀ i, SMul β (A i)]
[∀ i, SMulCommClass α β (A i)] :
SMulCommClass α β (GradedMonoid A) where
smul_comm a b g := Sigma.ext rfl <| heq_of_eq <| smul_comm a b g.2
instance [SMul α β] [∀ i, SMul α (A i)] [∀ i, SMul β (A i)]
[∀ i, IsScalarTower α β (A i)] :
IsScalarTower α β (GradedMonoid A) where
smul_assoc a b g := Sigma.ext rfl <| heq_of_eq <| smul_assoc a b g.2
instance [Monoid α] [∀ i, MulAction α (A i)] :
MulAction α (GradedMonoid A) where
one_smul g := Sigma.ext rfl <| heq_of_eq <| one_smul _ g.2
mul_smul r₁ r₂ g := Sigma.ext rfl <| heq_of_eq <| mul_smul r₁ r₂ g.2
end actions
/-! ### Typeclasses -/
section Defs
variable (A : ι → Type*)
/-- A graded version of `One`, which must be of grade 0. -/
class GOne [Zero ι] where
/-- The term `one` of grade 0 -/
one : A 0
/-- `GOne` implies `One (GradedMonoid A)` -/
instance GOne.toOne [Zero ι] [GOne A] : One (GradedMonoid A) :=
⟨⟨_, GOne.one⟩⟩
@[simp] theorem fst_one [Zero ι] [GOne A] : (1 : GradedMonoid A).fst = 0 := rfl
@[simp] theorem snd_one [Zero ι] [GOne A] : (1 : GradedMonoid A).snd = GOne.one := rfl
/-- A graded version of `Mul`. Multiplication combines grades additively, like
`AddMonoidAlgebra`. -/
class GMul [Add ι] where
/-- The homogeneous multiplication map `mul` -/
mul {i j} : A i → A j → A (i + j)
/-- `GMul` implies `Mul (GradedMonoid A)`. -/
instance GMul.toMul [Add ι] [GMul A] : Mul (GradedMonoid A) :=
⟨fun x y : GradedMonoid A => ⟨_, GMul.mul x.snd y.snd⟩⟩
@[simp] theorem fst_mul [Add ι] [GMul A] (x y : GradedMonoid A) :
(x * y).fst = x.fst + y.fst := rfl
@[simp] theorem snd_mul [Add ι] [GMul A] (x y : GradedMonoid A) :
(x * y).snd = GMul.mul x.snd y.snd := rfl
theorem mk_mul_mk [Add ι] [GMul A] {i j} (a : A i) (b : A j) :
mk i a * mk j b = mk (i + j) (GMul.mul a b) :=
rfl
namespace GMonoid
variable {A}
variable [AddMonoid ι] [GMul A] [GOne A]
/-- A default implementation of power on a graded monoid, like `npowRec`.
`GMonoid.gnpow` should be used instead. -/
def gnpowRec : ∀ (n : ℕ) {i}, A i → A (n • i)
| 0, i, _ => cast (congr_arg A (zero_nsmul i).symm) GOne.one
| n + 1, i, a => cast (congr_arg A (succ_nsmul i n).symm) (GMul.mul (gnpowRec _ a) a)
@[simp]
theorem gnpowRec_zero (a : GradedMonoid A) : GradedMonoid.mk _ (gnpowRec 0 a.snd) = 1 :=
Sigma.ext (zero_nsmul _) (heq_of_cast_eq _ rfl).symm
@[simp]
theorem gnpowRec_succ (n : ℕ) (a : GradedMonoid A) :
(GradedMonoid.mk _ <| gnpowRec n.succ a.snd) = ⟨_, gnpowRec n a.snd⟩ * a :=
Sigma.ext (succ_nsmul _ _) (heq_of_cast_eq _ rfl).symm
end GMonoid
/-- A tactic to for use as an optional value for `GMonoid.gnpow_zero'`. -/
macro "apply_gmonoid_gnpowRec_zero_tac" : tactic => `(tactic| apply GMonoid.gnpowRec_zero)
/-- A tactic to for use as an optional value for `GMonoid.gnpow_succ'`. -/
macro "apply_gmonoid_gnpowRec_succ_tac" : tactic => `(tactic| apply GMonoid.gnpowRec_succ)
/-- A graded version of `Monoid`
Like `Monoid.npow`, this has an optional `GMonoid.gnpow` field to allow definitional control of
natural powers of a graded monoid. -/
class GMonoid [AddMonoid ι] extends GMul A, GOne A where
/-- Multiplication by `one` on the left is the identity -/
one_mul (a : GradedMonoid A) : 1 * a = a
/-- Multiplication by `one` on the right is the identity -/
mul_one (a : GradedMonoid A) : a * 1 = a
/-- Multiplication is associative -/
mul_assoc (a b c : GradedMonoid A) : a * b * c = a * (b * c)
/-- Optional field to allow definitional control of natural powers -/
gnpow : ∀ (n : ℕ) {i}, A i → A (n • i) := GMonoid.gnpowRec
/-- The zeroth power will yield 1 -/
gnpow_zero' : ∀ a : GradedMonoid A, GradedMonoid.mk _ (gnpow 0 a.snd) = 1 := by
apply_gmonoid_gnpowRec_zero_tac
/-- Successor powers behave as expected -/
gnpow_succ' :
∀ (n : ℕ) (a : GradedMonoid A),
(GradedMonoid.mk _ <| gnpow n.succ a.snd) = ⟨_, gnpow n a.snd⟩ * a := by
apply_gmonoid_gnpowRec_succ_tac
/-- `GMonoid` implies a `Monoid (GradedMonoid A)`. -/
instance GMonoid.toMonoid [AddMonoid ι] [GMonoid A] : Monoid (GradedMonoid A) where
one := 1
mul := (· * ·)
npow n a := GradedMonoid.mk _ (GMonoid.gnpow n a.snd)
npow_zero a := GMonoid.gnpow_zero' a
npow_succ n a := GMonoid.gnpow_succ' n a
one_mul := GMonoid.one_mul
mul_one := GMonoid.mul_one
mul_assoc := GMonoid.mul_assoc
@[simp] theorem fst_pow [AddMonoid ι] [GMonoid A] (x : GradedMonoid A) (n : ℕ) :
(x ^ n).fst = n • x.fst := rfl
@[simp] theorem snd_pow [AddMonoid ι] [GMonoid A] (x : GradedMonoid A) (n : ℕ) :
(x ^ n).snd = GMonoid.gnpow n x.snd := rfl
theorem mk_pow [AddMonoid ι] [GMonoid A] {i} (a : A i) (n : ℕ) :
mk i a ^ n = mk (n • i) (GMonoid.gnpow _ a) := rfl
/-- A graded version of `CommMonoid`. -/
class GCommMonoid [AddCommMonoid ι] extends GMonoid A where
/-- Multiplication is commutative -/
mul_comm (a : GradedMonoid A) (b : GradedMonoid A) : a * b = b * a
/-- `GCommMonoid` implies a `CommMonoid (GradedMonoid A)`, although this is only used as an
instance locally to define notation in `gmonoid` and similar typeclasses. -/
instance GCommMonoid.toCommMonoid [AddCommMonoid ι] [GCommMonoid A] : CommMonoid (GradedMonoid A) :=
{ GMonoid.toMonoid A with mul_comm := GCommMonoid.mul_comm }
end Defs
/-! ### Instances for `A 0`
The various `g*` instances are enough to promote the `AddCommMonoid (A 0)` structure to various
types of multiplicative structure.
-/
section GradeZero
variable (A : ι → Type*)
section One
variable [Zero ι] [GOne A]
/-- `1 : A 0` is the value provided in `GOne.one`. -/
@[nolint unusedArguments]
instance GradeZero.one : One (A 0) :=
⟨GOne.one⟩
end One
section Mul
variable [AddZeroClass ι] [GMul A]
/-- `(•) : A 0 → A i → A i` is the value provided in `GradedMonoid.GMul.mul`, composed with
an `Eq.rec` to turn `A (0 + i)` into `A i`.
-/
instance GradeZero.smul (i : ι) : SMul (A 0) (A i) where
smul x y := @Eq.rec ι (0+i) (fun a _ => A a) (GMul.mul x y) i (zero_add i)
/-- `(*) : A 0 → A 0 → A 0` is the value provided in `GradedMonoid.GMul.mul`, composed with
an `Eq.rec` to turn `A (0 + 0)` into `A 0`.
-/
instance GradeZero.mul : Mul (A 0) where mul := (· • ·)
variable {A}
@[simp]
theorem mk_zero_smul {i} (a : A 0) (b : A i) : mk _ (a • b) = mk _ a * mk _ b :=
Sigma.ext (zero_add _).symm <| eqRec_heq _ _
@[scoped simp]
theorem GradeZero.smul_eq_mul (a b : A 0) : a • b = a * b :=
rfl
end Mul
section Monoid
variable [AddMonoid ι] [GMonoid A]
instance : NatPow (A 0) where
pow x n := @Eq.rec ι (n • (0 : ι)) (fun a _ => A a) (GMonoid.gnpow n x) 0 (nsmul_zero n)
variable {A} in
@[simp]
theorem mk_zero_pow (a : A 0) (n : ℕ) : mk _ (a ^ n) = mk _ a ^ n :=
Sigma.ext (nsmul_zero n).symm <| eqRec_heq _ _
/-- The `Monoid` structure derived from `GMonoid A`. -/
instance GradeZero.monoid : Monoid (A 0) :=
Function.Injective.monoid (mk 0) sigma_mk_injective rfl mk_zero_smul mk_zero_pow
end Monoid
section Monoid
variable [AddCommMonoid ι] [GCommMonoid A]
/-- The `CommMonoid` structure derived from `GCommMonoid A`. -/
instance GradeZero.commMonoid : CommMonoid (A 0) :=
Function.Injective.commMonoid (mk 0) sigma_mk_injective rfl mk_zero_smul mk_zero_pow
end Monoid
section MulAction
variable [AddMonoid ι] [GMonoid A]
/-- `GradedMonoid.mk 0` is a `MonoidHom`, using the `GradedMonoid.GradeZero.monoid` structure.
-/
def mkZeroMonoidHom : A 0 →* GradedMonoid A where
toFun := mk 0
map_one' := rfl
map_mul' := mk_zero_smul
/-- Each grade `A i` derives an `A 0`-action structure from `GMonoid A`. -/
instance GradeZero.mulAction {i} : MulAction (A 0) (A i) :=
letI := MulAction.compHom (GradedMonoid A) (mkZeroMonoidHom A)
Function.Injective.mulAction (mk i) sigma_mk_injective mk_zero_smul
end MulAction
end GradeZero
end GradedMonoid
/-! ### Dependent products of graded elements -/
section DProd
variable {α : Type*} {A : ι → Type*} [AddMonoid ι] [GradedMonoid.GMonoid A]
/-- The index used by `List.dProd`. Propositionally this is equal to `(l.map fι).Sum`, but
definitionally it needs to have a different form to avoid introducing `Eq.rec`s in `List.dProd`. -/
def List.dProdIndex (l : List α) (fι : α → ι) : ι :=
l.foldr (fun i b => fι i + b) 0
@[simp]
theorem List.dProdIndex_nil (fι : α → ι) : ([] : List α).dProdIndex fι = 0 :=
rfl
@[simp]
theorem List.dProdIndex_cons (a : α) (l : List α) (fι : α → ι) :
(a :: l).dProdIndex fι = fι a + l.dProdIndex fι :=
rfl
theorem List.dProdIndex_eq_map_sum (l : List α) (fι : α → ι) :
l.dProdIndex fι = (l.map fι).sum := by
match l with
| [] => simp
| head::tail => simp [List.dProdIndex_eq_map_sum tail fι]
/-- A dependent product for graded monoids represented by the indexed family of types `A i`.
This is a dependent version of `(l.map fA).prod`.
For a list `l : List α`, this computes the product of `fA a` over `a`, where each `fA` is of type
`A (fι a)`. -/
def List.dProd (l : List α) (fι : α → ι) (fA : ∀ a, A (fι a)) : A (l.dProdIndex fι) :=
l.foldrRecOn _ GradedMonoid.GOne.one fun _ x a _ => GradedMonoid.GMul.mul (fA a) x
@[simp]
theorem List.dProd_nil (fι : α → ι) (fA : ∀ a, A (fι a)) :
(List.nil : List α).dProd fι fA = GradedMonoid.GOne.one :=
rfl
-- the `( :)` in this lemma statement results in the type on the RHS not being unfolded, which
-- is nicer in the goal view.
@[simp]
theorem List.dProd_cons (fι : α → ι) (fA : ∀ a, A (fι a)) (a : α) (l : List α) :
(a :: l).dProd fι fA = (GradedMonoid.GMul.mul (fA a) (l.dProd fι fA) :) :=
rfl
theorem GradedMonoid.mk_list_dProd (l : List α) (fι : α → ι) (fA : ∀ a, A (fι a)) :
GradedMonoid.mk _ (l.dProd fι fA) = (l.map fun a => GradedMonoid.mk (fι a) (fA a)).prod := by
match l with
| [] => simp only [List.dProdIndex_nil, List.dProd_nil, List.map_nil, List.prod_nil]; rfl
| head::tail =>
simp [← GradedMonoid.mk_list_dProd tail _ _, GradedMonoid.mk_mul_mk, List.prod_cons]
/-- A variant of `GradedMonoid.mk_list_dProd` for rewriting in the other direction. -/
theorem GradedMonoid.list_prod_map_eq_dProd (l : List α) (f : α → GradedMonoid A) :
(l.map f).prod = GradedMonoid.mk _ (l.dProd (fun i => (f i).1) fun i => (f i).2) := by
rw [GradedMonoid.mk_list_dProd, GradedMonoid.mk]
simp_rw [Sigma.eta]
theorem GradedMonoid.list_prod_ofFn_eq_dProd {n : ℕ} (f : Fin n → GradedMonoid A) :
(List.ofFn f).prod =
GradedMonoid.mk _ ((List.finRange n).dProd (fun i => (f i).1) fun i => (f i).2) := by
rw [List.ofFn_eq_map, GradedMonoid.list_prod_map_eq_dProd]
end DProd
/-! ### Concrete instances -/
section
variable (ι) {R : Type*}
@[simps one]
instance One.gOne [Zero ι] [One R] : GradedMonoid.GOne fun _ : ι => R where one := 1
@[simps mul]
instance Mul.gMul [Add ι] [Mul R] : GradedMonoid.GMul fun _ : ι => R where mul x y := x * y
/-- If all grades are the same type and themselves form a monoid, then there is a trivial grading
structure. -/
@[simps gnpow]
instance Monoid.gMonoid [AddMonoid ι] [Monoid R] : GradedMonoid.GMonoid fun _ : ι => R :=
-- { Mul.gMul ι, One.gOne ι with
{ One.gOne ι with
mul := fun x y => x * y
one_mul := fun _ => Sigma.ext (zero_add _) (heq_of_eq (one_mul _))
mul_one := fun _ => Sigma.ext (add_zero _) (heq_of_eq (mul_one _))
mul_assoc := fun _ _ _ => Sigma.ext (add_assoc _ _ _) (heq_of_eq (mul_assoc _ _ _))
gnpow := fun n _ a => a ^ n
gnpow_zero' := fun _ => Sigma.ext (zero_nsmul _) (heq_of_eq (Monoid.npow_zero _))
gnpow_succ' := fun _ ⟨_, _⟩ => Sigma.ext (succ_nsmul _ _) (heq_of_eq (Monoid.npow_succ _ _)) }
/-- If all grades are the same type and themselves form a commutative monoid, then there is a
trivial grading structure. -/
instance CommMonoid.gCommMonoid [AddCommMonoid ι] [CommMonoid R] :
GradedMonoid.GCommMonoid fun _ : ι => R :=
{ Monoid.gMonoid ι with
mul_comm := fun _ _ => Sigma.ext (add_comm _ _) (heq_of_eq (mul_comm _ _)) }
/-- When all the indexed types are the same, the dependent product is just the regular product. -/
@[simp]
theorem List.dProd_monoid {α} [AddMonoid ι] [Monoid R] (l : List α) (fι : α → ι) (fA : α → R) :
@List.dProd _ _ (fun _ : ι => R) _ _ l fι fA = (l.map fA).prod := by
match l with
| [] =>
rw [List.dProd_nil, List.map_nil, List.prod_nil]
rfl
| head::tail =>
rw [List.dProd_cons, List.map_cons, List.prod_cons, List.dProd_monoid tail _ _]
rfl
end
/-! ### Shorthands for creating instance of the above typeclasses for collections of subobjects -/
section Subobjects
variable {R : Type*}
/-- A version of `GradedMonoid.GOne` for internally graded objects. -/
class SetLike.GradedOne {S : Type*} [SetLike S R] [One R] [Zero ι] (A : ι → S) : Prop where
/-- One has grade zero -/
one_mem : (1 : R) ∈ A 0
theorem SetLike.one_mem_graded {S : Type*} [SetLike S R] [One R] [Zero ι] (A : ι → S)
[SetLike.GradedOne A] : (1 : R) ∈ A 0 :=
SetLike.GradedOne.one_mem
instance SetLike.gOne {S : Type*} [SetLike S R] [One R] [Zero ι] (A : ι → S)
[SetLike.GradedOne A] : GradedMonoid.GOne fun i => A i where
one := ⟨1, SetLike.one_mem_graded _⟩
@[simp]
theorem SetLike.coe_gOne {S : Type*} [SetLike S R] [One R] [Zero ι] (A : ι → S)
[SetLike.GradedOne A] : ↑(@GradedMonoid.GOne.one _ (fun i => A i) _ _) = (1 : R) :=
rfl
/-- A version of `GradedMonoid.ghas_one` for internally graded objects. -/
class SetLike.GradedMul {S : Type*} [SetLike S R] [Mul R] [Add ι] (A : ι → S) : Prop where
/-- Multiplication is homogeneous -/
mul_mem : ∀ ⦃i j⦄ {gi gj}, gi ∈ A i → gj ∈ A j → gi * gj ∈ A (i + j)
theorem SetLike.mul_mem_graded {S : Type*} [SetLike S R] [Mul R] [Add ι] {A : ι → S}
[SetLike.GradedMul A] ⦃i j⦄ {gi gj} (hi : gi ∈ A i) (hj : gj ∈ A j) : gi * gj ∈ A (i + j) :=
SetLike.GradedMul.mul_mem hi hj
instance SetLike.gMul {S : Type*} [SetLike S R] [Mul R] [Add ι] (A : ι → S)
[SetLike.GradedMul A] : GradedMonoid.GMul fun i => A i where
mul := fun a b => ⟨(a * b : R), SetLike.mul_mem_graded a.prop b.prop⟩
@[simp]
theorem SetLike.coe_gMul {S : Type*} [SetLike S R] [Mul R] [Add ι] (A : ι → S)
[SetLike.GradedMul A] {i j : ι} (x : A i) (y : A j) :
↑(@GradedMonoid.GMul.mul _ (fun i => A i) _ _ _ _ x y) = (x * y : R) :=
rfl
/-- A version of `GradedMonoid.GMonoid` for internally graded objects. -/
class SetLike.GradedMonoid {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ι] (A : ι → S) : Prop
extends SetLike.GradedOne A, SetLike.GradedMul A
namespace SetLike
variable {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ι]
variable {A : ι → S} [SetLike.GradedMonoid A]
namespace GradeZero
variable (A) in
/-- The submonoid `A 0` of `R`. -/
@[simps]
def submonoid : Submonoid R where
carrier := A 0
mul_mem' ha hb := add_zero (0 : ι) ▸ SetLike.mul_mem_graded ha hb
one_mem' := SetLike.one_mem_graded A
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The monoid `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instMonoid : Monoid (A 0) := inferInstanceAs <| Monoid (GradeZero.submonoid A)
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The commutative monoid `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instCommMonoid
{R S : Type*} [SetLike S R] [CommMonoid R]
{A : ι → S} [SetLike.GradedMonoid A] :
CommMonoid (A 0) :=
inferInstanceAs <| CommMonoid (GradeZero.submonoid A)
@[simp, norm_cast] theorem coe_one : ↑(1 : A 0) = (1 : R) := rfl
@[simp, norm_cast] theorem coe_mul (a b : A 0) : ↑(a * b) = (↑a * ↑b : R) := rfl
@[simp, norm_cast] theorem coe_pow (a : A 0) (n : ℕ) : ↑(a ^ n) = (↑a : R) ^ n := rfl
end GradeZero
theorem pow_mem_graded (n : ℕ) {r : R} {i : ι} (h : r ∈ A i) : r ^ n ∈ A (n • i) := by
match n with
| 0 =>
rw [pow_zero, zero_nsmul]
exact one_mem_graded _
| n+1 =>
rw [pow_succ', succ_nsmul']
exact mul_mem_graded h (pow_mem_graded n h)
theorem list_prod_map_mem_graded {ι'} (l : List ι') (i : ι' → ι) (r : ι' → R)
(h : ∀ j ∈ l, r j ∈ A (i j)) : (l.map r).prod ∈ A (l.map i).sum := by
match l with
| [] =>
rw [List.map_nil, List.map_nil, List.prod_nil, List.sum_nil]
exact one_mem_graded _
| head::tail =>
rw [List.map_cons, List.map_cons, List.prod_cons, List.sum_cons]
exact
mul_mem_graded (h _ List.mem_cons_self)
(list_prod_map_mem_graded tail _ _ fun j hj => h _ <| List.mem_cons_of_mem _ hj)
theorem list_prod_ofFn_mem_graded {n} (i : Fin n → ι) (r : Fin n → R) (h : ∀ j, r j ∈ A (i j)) :
(List.ofFn r).prod ∈ A (List.ofFn i).sum := by
rw [List.ofFn_eq_map, List.ofFn_eq_map]
exact list_prod_map_mem_graded _ _ _ fun _ _ => h _
end SetLike
/-- Build a `GMonoid` instance for a collection of subobjects. -/
instance SetLike.gMonoid {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ι] (A : ι → S)
[SetLike.GradedMonoid A] : GradedMonoid.GMonoid fun i => A i :=
{ SetLike.gOne A,
SetLike.gMul A with
one_mul := fun ⟨_, _, _⟩ => Sigma.subtype_ext (zero_add _) (one_mul _)
mul_one := fun ⟨_, _, _⟩ => Sigma.subtype_ext (add_zero _) (mul_one _)
mul_assoc := fun ⟨_, _, _⟩ ⟨_, _, _⟩ ⟨_, _, _⟩ =>
Sigma.subtype_ext (add_assoc _ _ _) (mul_assoc _ _ _)
gnpow := fun n _ a => ⟨(a:R)^n, SetLike.pow_mem_graded n a.prop⟩
gnpow_zero' := fun _ => Sigma.subtype_ext (zero_nsmul _) (pow_zero _)
gnpow_succ' := fun _ _ => Sigma.subtype_ext (succ_nsmul _ _) (pow_succ _ _) }
@[simp]
theorem SetLike.coe_gnpow {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ι] (A : ι → S)
[SetLike.GradedMonoid A] {i : ι} (x : A i) (n : ℕ) :
↑(@GradedMonoid.GMonoid.gnpow _ (fun i => A i) _ _ n _ x) = (x:R)^n :=
rfl
/-- Build a `GCommMonoid` instance for a collection of subobjects. -/
instance SetLike.gCommMonoid {S : Type*} [SetLike S R] [CommMonoid R] [AddCommMonoid ι] (A : ι → S)
[SetLike.GradedMonoid A] : GradedMonoid.GCommMonoid fun i => A i :=
{ SetLike.gMonoid A with
mul_comm := fun ⟨_, _, _⟩ ⟨_, _, _⟩ => Sigma.subtype_ext (add_comm _ _) (mul_comm _ _) }
section DProd
open SetLike SetLike.GradedMonoid
variable {α S : Type*} [SetLike S R] [Monoid R] [AddMonoid ι]
@[simp]
theorem SetLike.coe_list_dProd (A : ι → S) [SetLike.GradedMonoid A] (fι : α → ι)
(fA : ∀ a, A (fι a)) (l : List α) : ↑(@List.dProd _ _ (fun i => ↥(A i)) _ _ l fι fA)
= (List.prod (l.map fun a => fA a) : R) := by
match l with
| [] =>
rw [List.dProd_nil, coe_gOne, List.map_nil, List.prod_nil]
| head::tail =>
rw [List.dProd_cons, coe_gMul, List.map_cons, List.prod_cons,
SetLike.coe_list_dProd _ _ _ tail]
/-- A version of `List.coe_dProd_set_like` with `Subtype.mk`. -/
theorem SetLike.list_dProd_eq (A : ι → S) [SetLike.GradedMonoid A] (fι : α → ι) (fA : ∀ a, A (fι a))
(l : List α) :
(@List.dProd _ _ (fun i => ↥(A i)) _ _ l fι fA) =
⟨List.prod (l.map fun a => fA a),
(l.dProdIndex_eq_map_sum fι).symm ▸
list_prod_map_mem_graded l _ _ fun i _ => (fA i).prop⟩ :=
Subtype.ext <| SetLike.coe_list_dProd _ _ _ _
end DProd
end Subobjects
section HomogeneousElements
|
variable {R S : Type*} [SetLike S R]
/-- An element `a : R` is said to be homogeneous if there is some `i : ι` such that `a ∈ A i`. -/
def SetLike.IsHomogeneousElem (A : ι → S) (a : R) : Prop :=
∃ i, a ∈ A i
@[simp]
theorem SetLike.isHomogeneousElem_coe {A : ι → S} {i} (x : A i) :
SetLike.IsHomogeneousElem A (x : R) :=
⟨i, x.prop⟩
| Mathlib/Algebra/GradedMonoid.lean | 645 | 655 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.NonUnitalSubalgebra
import Mathlib.RingTheory.SimpleRing.Basic
/-!
# Subalgebras over Commutative Semiring
In this file we define `Subalgebra`s and the usual operations on them (`map`, `comap`).
The `Algebra.adjoin` operation and complete lattice structure can be found in
`Mathlib.Algebra.Algebra.Subalgebra.Lattice`.
-/
universe u u' v w w'
/-- A subalgebra is a sub(semi)ring that includes the range of `algebraMap`. -/
structure Subalgebra (R : Type u) (A : Type v) [CommSemiring R] [Semiring A] [Algebra R A] : Type v
extends Subsemiring A where
/-- The image of `algebraMap` is contained in the underlying set of the subalgebra -/
algebraMap_mem' : ∀ r, algebraMap R A r ∈ carrier
zero_mem' := (algebraMap R A).map_zero ▸ algebraMap_mem' 0
one_mem' := (algebraMap R A).map_one ▸ algebraMap_mem' 1
/-- Reinterpret a `Subalgebra` as a `Subsemiring`. -/
add_decl_doc Subalgebra.toSubsemiring
namespace Subalgebra
variable {R' : Type u'} {R : Type u} {A : Type v} {B : Type w} {C : Type w'}
variable [CommSemiring R]
variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] [Semiring C] [Algebra R C]
instance : SetLike (Subalgebra R A) A where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective' h
initialize_simps_projections Subalgebra (carrier → coe, as_prefix coe)
/-- The actual `Subalgebra` obtained from an element of a type satisfying `SubsemiringClass` and
`SMulMemClass`. -/
@[simps]
def ofClass {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
[SetLike S A] [SubsemiringClass S A] [SMulMemClass S R A] (s : S) :
Subalgebra R A where
carrier := s
add_mem' := add_mem
zero_mem' := zero_mem _
mul_mem' := mul_mem
one_mem' := one_mem _
algebraMap_mem' r :=
Algebra.algebraMap_eq_smul_one (A := A) r ▸ SMulMemClass.smul_mem r (one_mem s)
instance (priority := 100) : CanLift (Set A) (Subalgebra R A) (↑)
(fun s ↦ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧
(∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ (r : R), algebraMap R A r ∈ s) where
prf s h :=
⟨ { carrier := s
zero_mem' := by simpa using h.2.2 0
add_mem' := h.1
one_mem' := by simpa using h.2.2 1
mul_mem' := h.2.1
algebraMap_mem' := h.2.2 },
rfl ⟩
|
instance : SubsemiringClass (Subalgebra R A) A where
add_mem {s} := add_mem (s := s.toSubsemiring)
| Mathlib/Algebra/Algebra/Subalgebra/Basic.lean | 69 | 71 |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Cover.Open
import Mathlib.AlgebraicGeometry.GammaSpecAdjunction
import Mathlib.AlgebraicGeometry.Restrict
import Mathlib.CategoryTheory.Limits.Opposites
import Mathlib.RingTheory.Localization.InvSubmonoid
import Mathlib.RingTheory.RingHom.Surjective
import Mathlib.Topology.Sheaves.CommRingCat
/-!
# Affine schemes
We define the category of `AffineScheme`s as the essential image of `Spec`.
We also define predicates about affine schemes and affine open sets.
## Main definitions
* `AlgebraicGeometry.AffineScheme`: The category of affine schemes.
* `AlgebraicGeometry.IsAffine`: A scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an
isomorphism.
* `AlgebraicGeometry.Scheme.isoSpec`: The canonical isomorphism `X ≅ Spec Γ(X)` for an affine
scheme.
* `AlgebraicGeometry.AffineScheme.equivCommRingCat`: The equivalence of categories
`AffineScheme ≌ CommRingᵒᵖ` given by `AffineScheme.Spec : CommRingᵒᵖ ⥤ AffineScheme` and
`AffineScheme.Γ : AffineSchemeᵒᵖ ⥤ CommRingCat`.
* `AlgebraicGeometry.IsAffineOpen`: An open subset of a scheme is affine if the open subscheme is
affine.
* `AlgebraicGeometry.IsAffineOpen.fromSpec`: The immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`.
-/
-- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737
noncomputable section
open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace
universe u
namespace AlgebraicGeometry
open Spec (structureSheaf)
/-- The category of affine schemes -/
def AffineScheme :=
Scheme.Spec.EssImageSubcategory
deriving Category
/-- A Scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. -/
class IsAffine (X : Scheme) : Prop where
affine : IsIso X.toSpecΓ
attribute [instance] IsAffine.affine
instance (X : Scheme.{u}) [IsAffine X] : IsIso (ΓSpec.adjunction.unit.app X) := @IsAffine.affine X _
/-- The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. -/
@[simps! -isSimp hom]
def Scheme.isoSpec (X : Scheme) [IsAffine X] : X ≅ Spec Γ(X, ⊤) :=
asIso X.toSpecΓ
@[reassoc]
theorem Scheme.isoSpec_hom_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
X.isoSpec.hom ≫ Spec.map (f.appTop) = f ≫ Y.isoSpec.hom := by
simp only [isoSpec, asIso_hom, Scheme.toSpecΓ_naturality]
@[reassoc]
theorem Scheme.isoSpec_inv_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
Spec.map (f.appTop) ≫ Y.isoSpec.inv = X.isoSpec.inv ≫ f := by
rw [Iso.eq_inv_comp, isoSpec, asIso_hom, ← Scheme.toSpecΓ_naturality_assoc, isoSpec,
asIso_inv, IsIso.hom_inv_id, Category.comp_id]
@[reassoc (attr := simp)]
lemma Scheme.toSpecΓ_isoSpec_inv (X : Scheme.{u}) [IsAffine X] :
X.toSpecΓ ≫ X.isoSpec.inv = 𝟙 _ :=
X.isoSpec.hom_inv_id
@[reassoc (attr := simp)]
lemma Scheme.isoSpec_inv_toSpecΓ (X : Scheme.{u}) [IsAffine X] :
X.isoSpec.inv ≫ X.toSpecΓ = 𝟙 _ :=
X.isoSpec.inv_hom_id
/-- Construct an affine scheme from a scheme and the information that it is affine.
Also see `AffineScheme.of` for a typeclass version. -/
@[simps]
def AffineScheme.mk (X : Scheme) (_ : IsAffine X) : AffineScheme :=
⟨X, ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩
/-- Construct an affine scheme from a scheme. Also see `AffineScheme.mk` for a non-typeclass
version. -/
def AffineScheme.of (X : Scheme) [h : IsAffine X] : AffineScheme :=
AffineScheme.mk X h
/-- Type check a morphism of schemes as a morphism in `AffineScheme`. -/
def AffineScheme.ofHom {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
AffineScheme.of X ⟶ AffineScheme.of Y :=
f
@[simp]
theorem essImage_Spec {X : Scheme} : Scheme.Spec.essImage X ↔ IsAffine X :=
⟨fun h => ⟨Functor.essImage.unit_isIso h⟩,
fun _ => ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩
@[deprecated (since := "2025-04-08")] alias mem_Spec_essImage := essImage_Spec
instance isAffine_affineScheme (X : AffineScheme.{u}) : IsAffine X.obj :=
⟨Functor.essImage.unit_isIso X.property⟩
instance (R : CommRingCatᵒᵖ) : IsAffine (Scheme.Spec.obj R) :=
AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage R⟩
instance isAffine_Spec (R : CommRingCat) : IsAffine (Spec R) :=
AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage (op R)⟩
theorem IsAffine.of_isIso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] [h : IsAffine Y] : IsAffine X := by
rw [← essImage_Spec] at h ⊢; exact Functor.essImage.ofIso (asIso f).symm h
@[deprecated (since := "2025-03-31")] alias isAffine_of_isIso := IsAffine.of_isIso
/-- If `f : X ⟶ Y` is a morphism between affine schemes, the corresponding arrow is isomorphic
to the arrow of the morphism on prime spectra induced by the map on global sections. -/
noncomputable
def arrowIsoSpecΓOfIsAffine {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
Arrow.mk f ≅ Arrow.mk (Spec.map f.appTop) :=
Arrow.isoMk X.isoSpec Y.isoSpec (ΓSpec.adjunction.unit_naturality _)
/-- If `f : A ⟶ B` is a ring homomorphism, the corresponding arrow is isomorphic
to the arrow of the morphism induced on global sections by the map on prime spectra. -/
def arrowIsoΓSpecOfIsAffine {A B : CommRingCat} (f : A ⟶ B) :
Arrow.mk f ≅ Arrow.mk ((Spec.map f).appTop) :=
Arrow.isoMk (Scheme.ΓSpecIso _).symm (Scheme.ΓSpecIso _).symm
(Scheme.ΓSpecIso_inv_naturality f).symm
theorem Scheme.isoSpec_Spec (R : CommRingCat.{u}) :
(Spec R).isoSpec = Scheme.Spec.mapIso (Scheme.ΓSpecIso R).op :=
Iso.ext (SpecMap_ΓSpecIso_hom R).symm
@[simp] theorem Scheme.isoSpec_Spec_hom (R : CommRingCat.{u}) :
(Spec R).isoSpec.hom = Spec.map (Scheme.ΓSpecIso R).hom :=
(SpecMap_ΓSpecIso_hom R).symm
@[simp] theorem Scheme.isoSpec_Spec_inv (R : CommRingCat.{u}) :
(Spec R).isoSpec.inv = Spec.map (Scheme.ΓSpecIso R).inv :=
congr($(isoSpec_Spec R).inv)
lemma ext_of_isAffine {X Y : Scheme} [IsAffine Y] {f g : X ⟶ Y} (e : f.appTop = g.appTop) :
f = g := by
rw [← cancel_mono Y.toSpecΓ, Scheme.toSpecΓ_naturality, Scheme.toSpecΓ_naturality, e]
namespace AffineScheme
/-- The `Spec` functor into the category of affine schemes. -/
def Spec : CommRingCatᵒᵖ ⥤ AffineScheme :=
Scheme.Spec.toEssImage
/-! We copy over instances from `Scheme.Spec.toEssImage`. -/
instance Spec_full : Spec.Full := Functor.Full.toEssImage _
instance Spec_faithful : Spec.Faithful := Functor.Faithful.toEssImage _
instance Spec_essSurj : Spec.EssSurj := Functor.EssSurj.toEssImage (F := _)
/-- The forgetful functor `AffineScheme ⥤ Scheme`. -/
@[simps!]
def forgetToScheme : AffineScheme ⥤ Scheme :=
Scheme.Spec.essImage.ι
/-! We copy over instances from `Scheme.Spec.essImageInclusion`. -/
instance forgetToScheme_full : forgetToScheme.Full :=
inferInstanceAs Scheme.Spec.essImage.ι.Full
instance forgetToScheme_faithful : forgetToScheme.Faithful :=
inferInstanceAs Scheme.Spec.essImage.ι.Faithful
/-- The global section functor of an affine scheme. -/
def Γ : AffineSchemeᵒᵖ ⥤ CommRingCat :=
forgetToScheme.op ⋙ Scheme.Γ
/-- The category of affine schemes is equivalent to the category of commutative rings. -/
def equivCommRingCat : AffineScheme ≌ CommRingCatᵒᵖ :=
equivEssImageOfReflective.symm
instance : Γ.{u}.rightOp.IsEquivalence := equivCommRingCat.isEquivalence_functor
instance : Γ.{u}.rightOp.op.IsEquivalence := equivCommRingCat.op.isEquivalence_functor
instance ΓIsEquiv : Γ.{u}.IsEquivalence :=
inferInstanceAs (Γ.{u}.rightOp.op ⋙ (opOpEquivalence _).functor).IsEquivalence
instance hasColimits : HasColimits AffineScheme.{u} :=
haveI := Adjunction.has_limits_of_equivalence.{u} Γ.{u}
Adjunction.has_colimits_of_equivalence.{u} (opOpEquivalence AffineScheme.{u}).inverse
instance hasLimits : HasLimits AffineScheme.{u} := by
haveI := Adjunction.has_colimits_of_equivalence Γ.{u}
haveI : HasLimits AffineScheme.{u}ᵒᵖᵒᵖ := Limits.hasLimits_op_of_hasColimits
exact Adjunction.has_limits_of_equivalence (opOpEquivalence AffineScheme.{u}).inverse
noncomputable instance Γ_preservesLimits : PreservesLimits Γ.{u}.rightOp := inferInstance
noncomputable instance forgetToScheme_preservesLimits : PreservesLimits forgetToScheme := by
apply (config := { allowSynthFailures := true })
@preservesLimits_of_natIso _ _ _ _ _ _
(isoWhiskerRight equivCommRingCat.unitIso forgetToScheme).symm
change PreservesLimits (equivCommRingCat.functor ⋙ Scheme.Spec)
infer_instance
end AffineScheme
/-- An open subset of a scheme is affine if the open subscheme is affine. -/
def IsAffineOpen {X : Scheme} (U : X.Opens) : Prop :=
IsAffine U
/-- The set of affine opens as a subset of `opens X`. -/
def Scheme.affineOpens (X : Scheme) : Set X.Opens :=
{U : X.Opens | IsAffineOpen U}
instance {Y : Scheme.{u}} (U : Y.affineOpens) : IsAffine U :=
U.property
theorem isAffineOpen_opensRange {X Y : Scheme} [IsAffine X] (f : X ⟶ Y)
[H : IsOpenImmersion f] : IsAffineOpen (Scheme.Hom.opensRange f) := by
refine .of_isIso (IsOpenImmersion.isoOfRangeEq f (Y.ofRestrict _) ?_).inv
exact Subtype.range_val.symm
theorem isAffineOpen_top (X : Scheme) [IsAffine X] : IsAffineOpen (⊤ : X.Opens) := by
convert isAffineOpen_opensRange (𝟙 X)
ext1
exact Set.range_id.symm
instance Scheme.isAffine_affineCover (X : Scheme) (i : X.affineCover.J) :
IsAffine (X.affineCover.obj i) :=
isAffine_Spec _
instance Scheme.isAffine_affineBasisCover (X : Scheme) (i : X.affineBasisCover.J) :
IsAffine (X.affineBasisCover.obj i) :=
isAffine_Spec _
instance Scheme.isAffine_affineOpenCover (X : Scheme) (𝒰 : X.AffineOpenCover) (i : 𝒰.J) :
IsAffine (𝒰.openCover.obj i) :=
inferInstanceAs (IsAffine (Spec (𝒰.obj i)))
instance {X} [IsAffine X] (i) :
IsAffine ((Scheme.coverOfIsIso (P := @IsOpenImmersion) (𝟙 X)).obj i) := by
dsimp; infer_instance
theorem isBasis_affine_open (X : Scheme) : Opens.IsBasis X.affineOpens := by
rw [Opens.isBasis_iff_nbhd]
rintro U x (hU : x ∈ (U : Set X))
obtain ⟨S, hS, hxS, hSU⟩ := X.affineBasisCover_is_basis.exists_subset_of_mem_open hU U.isOpen
refine ⟨⟨S, X.affineBasisCover_is_basis.isOpen hS⟩, ?_, hxS, hSU⟩
rcases hS with ⟨i, rfl⟩
exact isAffineOpen_opensRange _
theorem iSup_affineOpens_eq_top (X : Scheme) : ⨆ i : X.affineOpens, (i : X.Opens) = ⊤ := by
apply Opens.ext
rw [Opens.coe_iSup]
apply IsTopologicalBasis.sUnion_eq
rw [← Set.image_eq_range]
exact isBasis_affine_open X
theorem Scheme.map_PrimeSpectrum_basicOpen_of_affine
(X : Scheme) [IsAffine X] (f : Γ(X, ⊤)) :
X.isoSpec.hom ⁻¹ᵁ PrimeSpectrum.basicOpen f = X.basicOpen f :=
Scheme.toSpecΓ_preimage_basicOpen _ _
theorem isBasis_basicOpen (X : Scheme) [IsAffine X] :
Opens.IsBasis (Set.range (X.basicOpen : Γ(X, ⊤) → X.Opens)) := by
delta Opens.IsBasis
convert PrimeSpectrum.isBasis_basic_opens.isInducing
(TopCat.homeoOfIso (Scheme.forgetToTop.mapIso X.isoSpec)).isInducing using 1
ext
simp only [Set.mem_image, exists_exists_eq_and]
constructor
· rintro ⟨_, ⟨x, rfl⟩, rfl⟩
refine ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, ?_⟩
exact congr_arg Opens.carrier (Scheme.toSpecΓ_preimage_basicOpen _ _)
· rintro ⟨_, ⟨_, ⟨x, rfl⟩, rfl⟩, rfl⟩
refine ⟨_, ⟨x, rfl⟩, ?_⟩
exact congr_arg Opens.carrier (Scheme.toSpecΓ_preimage_basicOpen _ _).symm
/-- The canonical map `U ⟶ Spec Γ(X, U)` for an open `U ⊆ X`. -/
noncomputable
def Scheme.Opens.toSpecΓ {X : Scheme.{u}} (U : X.Opens) :
U.toScheme ⟶ Spec Γ(X, U) :=
U.toScheme.toSpecΓ ≫ Spec.map U.topIso.inv
@[reassoc (attr := simp)]
lemma Scheme.Opens.toSpecΓ_SpecMap_map {X : Scheme} (U V : X.Opens) (h : U ≤ V) :
U.toSpecΓ ≫ Spec.map (X.presheaf.map (homOfLE h).op) = X.homOfLE h ≫ V.toSpecΓ := by
delta Scheme.Opens.toSpecΓ
simp [← Spec.map_comp, ← X.presheaf.map_comp, toSpecΓ_naturality_assoc]
@[simp]
lemma Scheme.Opens.toSpecΓ_top {X : Scheme} :
(⊤ : X.Opens).toSpecΓ = (⊤ : X.Opens).ι ≫ X.toSpecΓ := by
simp [Scheme.Opens.toSpecΓ, toSpecΓ_naturality]; rfl
@[reassoc]
lemma Scheme.Opens.toSpecΓ_appTop {X : Scheme.{u}} (U : X.Opens) :
U.toSpecΓ.appTop = (Scheme.ΓSpecIso Γ(X, U)).hom ≫ U.topIso.inv := by
simp [Scheme.Opens.toSpecΓ]
namespace IsAffineOpen
variable {X Y : Scheme.{u}} {U : X.Opens} (hU : IsAffineOpen U) (f : Γ(X, U))
attribute [-simp] eqToHom_op in
/-- The isomorphism `U ≅ Spec Γ(X, U)` for an affine `U`. -/
@[simps! -isSimp inv]
def isoSpec :
↑U ≅ Spec Γ(X, U) :=
haveI : IsAffine U := hU
U.toScheme.isoSpec ≪≫ Scheme.Spec.mapIso U.topIso.symm.op
lemma isoSpec_hom : hU.isoSpec.hom = U.toSpecΓ := rfl
@[reassoc (attr := simp)]
lemma toSpecΓ_isoSpec_inv : U.toSpecΓ ≫ hU.isoSpec.inv = 𝟙 _ := hU.isoSpec.hom_inv_id
@[reassoc (attr := simp)]
lemma isoSpec_inv_toSpecΓ : hU.isoSpec.inv ≫ U.toSpecΓ = 𝟙 _ := hU.isoSpec.inv_hom_id
open IsLocalRing in
lemma isoSpec_hom_base_apply (x : U) :
hU.isoSpec.hom.base x = (Spec.map (X.presheaf.germ U x x.2)).base (closedPoint _) := by
dsimp [IsAffineOpen.isoSpec_hom, Scheme.isoSpec_hom, Scheme.toSpecΓ_base, Scheme.Opens.toSpecΓ]
rw [← Scheme.comp_base_apply, ← Spec.map_comp,
(Iso.eq_comp_inv _).mpr (Scheme.Opens.germ_stalkIso_hom U (V := ⊤) x trivial),
X.presheaf.germ_res_assoc, Spec.map_comp, Scheme.comp_base_apply]
congr 1
exact IsLocalRing.comap_closedPoint (U.stalkIso x).inv.hom
lemma isoSpec_inv_appTop :
hU.isoSpec.inv.appTop = U.topIso.hom ≫ (Scheme.ΓSpecIso Γ(X, U)).inv := by
simp_rw [Scheme.Opens.toScheme_presheaf_obj, isoSpec_inv, Scheme.isoSpec, asIso_inv,
Scheme.comp_app, Scheme.Opens.topIso_hom, Scheme.ΓSpecIso_inv_naturality,
Scheme.inv_appTop, -- `check_compositions` reports defeq problems starting after this step.
IsIso.inv_comp_eq]
rw [Scheme.toSpecΓ_appTop]
-- We need `erw` here because the goal has
-- `Scheme.ΓSpecIso Γ(↑U, ⊤)).hom ≫ Scheme.ΓSpecIso Γ(X, U.ι ''ᵁ ⊤)).inv`
-- and `Γ(X, U.ι ''ᵁ ⊤)` is non-reducibly defeq to `Γ(↑U, ⊤)`.
erw [Iso.hom_inv_id_assoc]
simp only [Opens.map_top]
lemma isoSpec_hom_appTop :
hU.isoSpec.hom.appTop = (Scheme.ΓSpecIso Γ(X, U)).hom ≫ U.topIso.inv := by
have := congr(inv $hU.isoSpec_inv_appTop)
rw [IsIso.inv_comp, IsIso.Iso.inv_inv, IsIso.Iso.inv_hom] at this
have := (Scheme.Γ.map_inv hU.isoSpec.inv.op).trans this
rwa [← op_inv, IsIso.Iso.inv_inv] at this
@[deprecated (since := "2024-11-16")] alias isoSpec_inv_app_top := isoSpec_inv_appTop
@[deprecated (since := "2024-11-16")] alias isoSpec_hom_app_top := isoSpec_hom_appTop
/-- The open immersion `Spec Γ(X, U) ⟶ X` for an affine `U`. -/
def fromSpec :
Spec Γ(X, U) ⟶ X :=
haveI : IsAffine U := hU
hU.isoSpec.inv ≫ U.ι
instance isOpenImmersion_fromSpec :
IsOpenImmersion hU.fromSpec := by
delta fromSpec
infer_instance
@[reassoc (attr := simp)]
lemma isoSpec_inv_ι : hU.isoSpec.inv ≫ U.ι = hU.fromSpec := rfl
@[reassoc (attr := simp)]
lemma toSpecΓ_fromSpec : U.toSpecΓ ≫ hU.fromSpec = U.ι := toSpecΓ_isoSpec_inv_assoc _ _
@[simp]
theorem range_fromSpec :
Set.range hU.fromSpec.base = (U : Set X) := by
delta IsAffineOpen.fromSpec; dsimp [IsAffineOpen.isoSpec_inv]
rw [Set.range_comp, Set.range_eq_univ.mpr, Set.image_univ]
· exact Subtype.range_coe
rw [← TopCat.coe_comp, ← TopCat.epi_iff_surjective]
infer_instance
@[simp]
theorem opensRange_fromSpec : hU.fromSpec.opensRange = U := Opens.ext (range_fromSpec hU)
@[reassoc (attr := simp)]
theorem map_fromSpec {V : X.Opens} (hV : IsAffineOpen V) (f : op U ⟶ op V) :
Spec.map (X.presheaf.map f) ≫ hU.fromSpec = hV.fromSpec := by
have : IsAffine U := hU
haveI : IsAffine _ := hV
conv_rhs =>
rw [fromSpec, ← X.homOfLE_ι (V := U) f.unop.le, isoSpec_inv, Category.assoc,
← Scheme.isoSpec_inv_naturality_assoc,
← Spec.map_comp_assoc, Scheme.homOfLE_appTop, ← Functor.map_comp]
rw [fromSpec, isoSpec_inv, Category.assoc, ← Spec.map_comp_assoc, ← Functor.map_comp]
rfl
@[reassoc]
lemma Spec_map_appLE_fromSpec (f : X ⟶ Y) {V : X.Opens} {U : Y.Opens}
(hU : IsAffineOpen U) (hV : IsAffineOpen V) (i : V ≤ f ⁻¹ᵁ U) :
Spec.map (f.appLE U V i) ≫ hU.fromSpec = hV.fromSpec ≫ f := by
have : IsAffine U := hU
simp only [IsAffineOpen.fromSpec, Category.assoc, isoSpec_inv]
| simp_rw [← Scheme.homOfLE_ι _ i]
rw [Category.assoc, ← morphismRestrict_ι,
← Category.assoc _ (f ∣_ U) U.ι, ← @Scheme.isoSpec_inv_naturality_assoc,
← Spec.map_comp_assoc, ← Spec.map_comp_assoc, Scheme.comp_appTop, morphismRestrict_appTop,
Scheme.homOfLE_appTop, Scheme.Hom.app_eq_appLE, Scheme.Hom.appLE_map,
Scheme.Hom.appLE_map, Scheme.Hom.appLE_map, Scheme.Hom.map_appLE]
| Mathlib/AlgebraicGeometry/AffineScheme.lean | 410 | 416 |
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudryashov, Yaël Dillies
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Algebra.Ring.Action.Pointwise.Set
import Mathlib.Analysis.Convex.Star
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.NoncommRing
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Defs
/-!
# Convex sets and functions in vector spaces
In a 𝕜-vector space, we define the following objects and properties.
* `Convex 𝕜 s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment 𝕜 x y`.
* `stdSimplex 𝕜 ι`: The standard simplex in `ι → 𝕜` (currently requires `Fintype ι`). It is the
intersection of the positive quadrant with the hyperplane `s.sum = 1`.
We also provide various equivalent versions of the definitions above, prove that some specific sets
are convex.
## TODO
Generalize all this file to affine spaces.
-/
variable {𝕜 E F β : Type*}
open LinearMap Set
open scoped Convex Pointwise
/-! ### Convexity of sets -/
section OrderedSemiring
variable [Semiring 𝕜] [PartialOrder 𝕜]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section SMul
variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E) {x : E}
/-- Convexity of sets. -/
def Convex : Prop :=
∀ ⦃x : E⦄, x ∈ s → StarConvex 𝕜 x s
variable {𝕜 s}
theorem Convex.starConvex (hs : Convex 𝕜 s) (hx : x ∈ s) : StarConvex 𝕜 x s :=
hs hx
theorem convex_iff_segment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s :=
forall₂_congr fun _ _ => starConvex_iff_segment_subset
theorem Convex.segment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
[x -[𝕜] y] ⊆ s :=
convex_iff_segment_subset.1 h hx hy
theorem Convex.openSegment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
openSegment 𝕜 x y ⊆ s :=
(openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hx hy)
/-- Alternative definition of set convexity, in terms of pointwise set operations. -/
theorem convex_iff_pointwise_add_subset :
Convex 𝕜 s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s :=
Iff.intro
(by
rintro hA a b ha hb hab w ⟨au, ⟨u, hu, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩
exact hA hu hv ha hb hab)
fun h _ hx _ hy _ _ ha hb hab => (h ha hb hab) (Set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩)
alias ⟨Convex.set_combo_subset, _⟩ := convex_iff_pointwise_add_subset
theorem convex_empty : Convex 𝕜 (∅ : Set E) := fun _ => False.elim
theorem convex_univ : Convex 𝕜 (Set.univ : Set E) := fun _ _ => starConvex_univ _
theorem Convex.inter {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ∩ t) :=
fun _ hx => (hs hx.1).inter (ht hx.2)
theorem convex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, Convex 𝕜 s) : Convex 𝕜 (⋂₀ S) := fun _ hx =>
starConvex_sInter fun _ hs => h _ hs <| hx _ hs
theorem convex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, Convex 𝕜 (s i)) :
Convex 𝕜 (⋂ i, s i) :=
sInter_range s ▸ convex_sInter <| forall_mem_range.2 h
theorem convex_iInter₂ {ι : Sort*} {κ : ι → Sort*} {s : (i : ι) → κ i → Set E}
(h : ∀ i j, Convex 𝕜 (s i j)) : Convex 𝕜 (⋂ (i) (j), s i j) :=
convex_iInter fun i => convex_iInter <| h i
theorem Convex.prod {s : Set E} {t : Set F} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) :
Convex 𝕜 (s ×ˢ t) := fun _ hx => (hs hx.1).prod (ht hx.2)
theorem convex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)]
{s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → Convex 𝕜 (t i)) : Convex 𝕜 (s.pi t) :=
fun _ hx => starConvex_pi fun _ hi => ht hi <| hx _ hi
theorem Directed.convex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s)
(hc : ∀ ⦃i : ι⦄, Convex 𝕜 (s i)) : Convex 𝕜 (⋃ i, s i) := by
rintro x hx y hy a b ha hb hab
rw [mem_iUnion] at hx hy ⊢
obtain ⟨i, hx⟩ := hx
obtain ⟨j, hy⟩ := hy
obtain ⟨k, hik, hjk⟩ := hdir i j
exact ⟨k, hc (hik hx) (hjk hy) ha hb hab⟩
theorem DirectedOn.convex_sUnion {c : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) c)
(hc : ∀ ⦃A : Set E⦄, A ∈ c → Convex 𝕜 A) : Convex 𝕜 (⋃₀ c) := by
rw [sUnion_eq_iUnion]
exact (directedOn_iff_directed.1 hdir).convex_iUnion fun A => hc A.2
end SMul
section Module
variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E} {x : E}
theorem convex_iff_openSegment_subset [ZeroLEOneClass 𝕜] :
Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s :=
forall₂_congr fun _ => starConvex_iff_openSegment_subset
theorem convex_iff_forall_pos :
Convex 𝕜 s ↔
∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s :=
forall₂_congr fun _ => starConvex_iff_forall_pos
theorem convex_iff_pairwise_pos : Convex 𝕜 s ↔
s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by
refine convex_iff_forall_pos.trans ⟨fun h x hx y hy _ => h hx hy, ?_⟩
intro h x hx y hy a b ha hb hab
obtain rfl | hxy := eq_or_ne x y
· rwa [Convex.combo_self hab]
· exact h hx hy hxy ha hb hab
theorem Convex.starConvex_iff [ZeroLEOneClass 𝕜] (hs : Convex 𝕜 s) (h : s.Nonempty) :
StarConvex 𝕜 x s ↔ x ∈ s :=
⟨fun hxs => hxs.mem h, hs.starConvex⟩
protected theorem Set.Subsingleton.convex {s : Set E} (h : s.Subsingleton) : Convex 𝕜 s :=
convex_iff_pairwise_pos.mpr (h.pairwise _)
@[simp] theorem convex_singleton (c : E) : Convex 𝕜 ({c} : Set E) :=
subsingleton_singleton.convex
theorem convex_zero : Convex 𝕜 (0 : Set E) :=
convex_singleton _
theorem convex_segment [IsOrderedRing 𝕜] (x y : E) : Convex 𝕜 [x -[𝕜] y] := by
rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ a b ha hb hab
refine
⟨a * ap + b * aq, a * bp + b * bq, add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq),
add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), ?_, ?_⟩
· rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab]
· match_scalars <;> noncomm_ring
theorem Convex.linear_image (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ a b ha hb hab
exact ⟨a • x + b • y, hs hx hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩
theorem Convex.is_linear_image (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) :
Convex 𝕜 (f '' s) :=
hs.linear_image <| hf.mk' f
theorem Convex.linear_preimage {𝕜₁ : Type*} [Semiring 𝕜₁] [Module 𝕜₁ E] [Module 𝕜₁ F] {s : Set F}
[SMul 𝕜 𝕜₁] [IsScalarTower 𝕜 𝕜₁ E] [IsScalarTower 𝕜 𝕜₁ F] (hs : Convex 𝕜 s) (f : E →ₗ[𝕜₁] F) :
Convex 𝕜 (f ⁻¹' s) := fun x hx y hy a b ha hb hab => by
rw [mem_preimage, f.map_add, LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower]
exact hs hx hy ha hb hab
theorem Convex.is_linear_preimage {𝕜₁ : Type*} [Semiring 𝕜₁] [Module 𝕜₁ E] [Module 𝕜₁ F] {s : Set F}
[SMul 𝕜 𝕜₁] [IsScalarTower 𝕜 𝕜₁ E] [IsScalarTower 𝕜 𝕜₁ F] (hs : Convex 𝕜 s) {f : E → F}
(hf : IsLinearMap 𝕜₁ f) :
Convex 𝕜 (f ⁻¹' s) :=
hs.linear_preimage <| hf.mk' f
theorem Convex.add {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s + t) := by
rw [← add_image_prod]
exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add
variable (𝕜 E)
/-- The convex sets form an additive submonoid under pointwise addition. -/
def convexAddSubmonoid : AddSubmonoid (Set E) where
carrier := {s : Set E | Convex 𝕜 s}
zero_mem' := convex_zero
add_mem' := Convex.add
@[simp, norm_cast]
theorem coe_convexAddSubmonoid : ↑(convexAddSubmonoid 𝕜 E) = {s : Set E | Convex 𝕜 s} :=
rfl
variable {𝕜 E}
@[simp]
theorem mem_convexAddSubmonoid {s : Set E} : s ∈ convexAddSubmonoid 𝕜 E ↔ Convex 𝕜 s :=
Iff.rfl
theorem convex_list_sum {l : List (Set E)} (h : ∀ i ∈ l, Convex 𝕜 i) : Convex 𝕜 l.sum :=
(convexAddSubmonoid 𝕜 E).list_sum_mem h
theorem convex_multiset_sum {s : Multiset (Set E)} (h : ∀ i ∈ s, Convex 𝕜 i) : Convex 𝕜 s.sum :=
(convexAddSubmonoid 𝕜 E).multiset_sum_mem _ h
theorem convex_sum {ι} {s : Finset ι} (t : ι → Set E) (h : ∀ i ∈ s, Convex 𝕜 (t i)) :
Convex 𝕜 (∑ i ∈ s, t i) :=
(convexAddSubmonoid 𝕜 E).sum_mem h
theorem Convex.vadd (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 (z +ᵥ s) := by
simp_rw [← image_vadd, vadd_eq_add, ← singleton_add]
exact (convex_singleton _).add hs
theorem Convex.translate (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) '' s) :=
hs.vadd _
/-- The translation of a convex set is also convex. -/
theorem Convex.translate_preimage_right (hs : Convex 𝕜 s) (z : E) :
Convex 𝕜 ((fun x => z + x) ⁻¹' s) := by
intro x hx y hy a b ha hb hab
have h := hs hx hy ha hb hab
rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h
/-- The translation of a convex set is also convex. -/
theorem Convex.translate_preimage_left (hs : Convex 𝕜 s) (z : E) :
Convex 𝕜 ((fun x => x + z) ⁻¹' s) := by
simpa only [add_comm] using hs.translate_preimage_right z
section OrderedAddCommMonoid
variable [AddCommMonoid β] [PartialOrder β] [IsOrderedAddMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β]
theorem convex_Iic (r : β) : Convex 𝕜 (Iic r) := fun x hx y hy a b ha hb hab =>
calc
a • x + b • y ≤ a • r + b • r :=
add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb)
_ = r := Convex.combo_self hab _
theorem convex_Ici (r : β) : Convex 𝕜 (Ici r) :=
convex_Iic (β := βᵒᵈ) r
theorem convex_Icc (r s : β) : Convex 𝕜 (Icc r s) :=
Ici_inter_Iic.subst ((convex_Ici r).inter <| convex_Iic s)
theorem convex_halfSpace_le {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w ≤ r } :=
(convex_Iic r).is_linear_preimage h
@[deprecated (since := "2024-11-12")] alias convex_halfspace_le := convex_halfSpace_le
theorem convex_halfSpace_ge {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r ≤ f w } :=
(convex_Ici r).is_linear_preimage h
@[deprecated (since := "2024-11-12")] alias convex_halfspace_ge := convex_halfSpace_ge
theorem convex_hyperplane {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w = r } := by
simp_rw [le_antisymm_iff]
exact (convex_halfSpace_le h r).inter (convex_halfSpace_ge h r)
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [AddCommMonoid β] [PartialOrder β] [IsOrderedCancelAddMonoid β]
[Module 𝕜 β] [OrderedSMul 𝕜 β]
theorem convex_Iio (r : β) : Convex 𝕜 (Iio r) := by
intro x hx y hy a b ha hb hab
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_add] at hab
rwa [zero_smul, zero_add, hab, one_smul]
rw [mem_Iio] at hx hy
calc
a • x + b • y < a • r + b • r := add_lt_add_of_lt_of_le
(smul_lt_smul_of_pos_left hx ha') (smul_le_smul_of_nonneg_left hy.le hb)
_ = r := Convex.combo_self hab _
theorem convex_Ioi (r : β) : Convex 𝕜 (Ioi r) :=
convex_Iio (β := βᵒᵈ) r
theorem convex_Ioo (r s : β) : Convex 𝕜 (Ioo r s) :=
Ioi_inter_Iio.subst ((convex_Ioi r).inter <| convex_Iio s)
theorem convex_Ico (r s : β) : Convex 𝕜 (Ico r s) :=
Ici_inter_Iio.subst ((convex_Ici r).inter <| convex_Iio s)
theorem convex_Ioc (r s : β) : Convex 𝕜 (Ioc r s) :=
Ioi_inter_Iic.subst ((convex_Ioi r).inter <| convex_Iic s)
theorem convex_halfSpace_lt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w < r } :=
(convex_Iio r).is_linear_preimage h
@[deprecated (since := "2024-11-12")] alias convex_halfspace_lt := convex_halfSpace_lt
theorem convex_halfSpace_gt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r < f w } :=
(convex_Ioi r).is_linear_preimage h
@[deprecated (since := "2024-11-12")] alias convex_halfspace_gt := convex_halfSpace_gt
end OrderedCancelAddCommMonoid
section LinearOrderedAddCommMonoid
variable [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β]
theorem convex_uIcc (r s : β) : Convex 𝕜 (uIcc r s) :=
convex_Icc _ _
end LinearOrderedAddCommMonoid
end Module
end AddCommMonoid
section LinearOrderedAddCommMonoid
variable [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E]
[PartialOrder β] [Module 𝕜 E] [OrderedSMul 𝕜 E]
{s : Set E} {f : E → β}
theorem MonotoneOn.convex_le (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy _ _ ha hb hab =>
⟨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans
(max_rec' { x | f x ≤ r } hx.2 hy.2)⟩
theorem MonotoneOn.convex_lt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | f x < r }) := fun x hx y hy _ _ ha hb hab =>
⟨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1)
(Convex.combo_le_max x y ha hb hab)).trans_lt
(max_rec' { x | f x < r } hx.2 hy.2)⟩
theorem MonotoneOn.convex_ge (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | r ≤ f x }) :=
MonotoneOn.convex_le (E := Eᵒᵈ) (β := βᵒᵈ) hf.dual hs r
theorem MonotoneOn.convex_gt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | r < f x }) :=
MonotoneOn.convex_lt (E := Eᵒᵈ) (β := βᵒᵈ) hf.dual hs r
theorem AntitoneOn.convex_le (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | f x ≤ r }) :=
MonotoneOn.convex_ge (β := βᵒᵈ) hf hs r
theorem AntitoneOn.convex_lt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | f x < r }) :=
MonotoneOn.convex_gt (β := βᵒᵈ) hf hs r
theorem AntitoneOn.convex_ge (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | r ≤ f x }) :=
MonotoneOn.convex_le (β := βᵒᵈ) hf hs r
theorem AntitoneOn.convex_gt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) :
Convex 𝕜 ({ x ∈ s | r < f x }) :=
MonotoneOn.convex_lt (β := βᵒᵈ) hf hs r
theorem Monotone.convex_le (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r)
theorem Monotone.convex_lt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r)
theorem Monotone.convex_ge (hf : Monotone f) (r : β) : Convex 𝕜 { x | r ≤ f x } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_ge convex_univ r)
theorem Monotone.convex_gt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r)
theorem Antitone.convex_le (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x ≤ r } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_le convex_univ r)
theorem Antitone.convex_lt (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x < r } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_lt convex_univ r)
theorem Antitone.convex_ge (hf : Antitone f) (r : β) : Convex 𝕜 { x | r ≤ f x } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_ge convex_univ r)
theorem Antitone.convex_gt (hf : Antitone f) (r : β) : Convex 𝕜 { x | r < f x } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_gt convex_univ r)
end LinearOrderedAddCommMonoid
end OrderedSemiring
section OrderedCommSemiring
variable [CommSemiring 𝕜] [PartialOrder 𝕜]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E}
theorem Convex.smul (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 (c • s) :=
hs.linear_image (LinearMap.lsmul _ _ c)
theorem Convex.smul_preimage (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 ((fun z => c • z) ⁻¹' s) :=
hs.linear_preimage (LinearMap.lsmul _ _ c)
theorem Convex.affinity (hs : Convex 𝕜 s) (z : E) (c : 𝕜) :
Convex 𝕜 ((fun x => z + c • x) '' s) := by
simpa only [← image_smul, ← image_vadd, image_image] using (hs.smul c).vadd z
end AddCommMonoid
end OrderedCommSemiring
section StrictOrderedCommSemiring
variable [CommSemiring 𝕜] [PartialOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E]
theorem convex_openSegment (a b : E) : Convex 𝕜 (openSegment 𝕜 a b) := by
rw [convex_iff_openSegment_subset]
rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩
refine ⟨a * ap + b * aq, a * bp + b * bq, by positivity, by positivity, ?_, ?_⟩
· linear_combination (norm := noncomm_ring) a * habp + b * habq + hab
· module
end StrictOrderedCommSemiring
section OrderedRing
variable [Ring 𝕜] [PartialOrder 𝕜]
section AddCommGroup
variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s t : Set E}
@[simp]
theorem convex_vadd (a : E) : Convex 𝕜 (a +ᵥ s) ↔ Convex 𝕜 s :=
⟨fun h ↦ by simpa using h.vadd (-a), fun h ↦ h.vadd _⟩
/-- Affine subspaces are convex. -/
theorem AffineSubspace.convex (Q : AffineSubspace 𝕜 E) : Convex 𝕜 (Q : Set E) :=
fun x hx y hy a b _ _ hab ↦ by simpa [Convex.combo_eq_smul_sub_add hab] using Q.2 _ hy hx hx
/-- The preimage of a convex set under an affine map is convex. -/
theorem Convex.affine_preimage (f : E →ᵃ[𝕜] F) {s : Set F} (hs : Convex 𝕜 s) : Convex 𝕜 (f ⁻¹' s) :=
fun _ hx => (hs hx).affine_preimage _
/-- The image of a convex set under an affine map is convex. -/
theorem Convex.affine_image (f : E →ᵃ[𝕜] F) (hs : Convex 𝕜 s) : Convex 𝕜 (f '' s) := by
rintro _ ⟨x, hx, rfl⟩
exact (hs hx).affine_image _
theorem Convex.neg (hs : Convex 𝕜 s) : Convex 𝕜 (-s) :=
hs.is_linear_preimage IsLinearMap.isLinearMap_neg (𝕜₁ := 𝕜)
theorem Convex.sub (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s - t) := by
rw [sub_eq_add_neg]
exact hs.add ht.neg
variable [AddRightMono 𝕜]
theorem Convex.add_smul_mem (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s) {t : 𝕜}
(ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s := by
have h : x + t • y = (1 - t) • x + t • (x + y) := by match_scalars <;> noncomm_ring
rw [h]
exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _)
theorem Convex.smul_mem_of_zero_mem (hs : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s)
{t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : t • x ∈ s := by
simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht
theorem Convex.mapsTo_lineMap (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) :
MapsTo (AffineMap.lineMap x y) (Icc (0 : 𝕜) 1) s := by
simpa only [mapsTo', segment_eq_image_lineMap] using h.segment_subset hx hy
theorem Convex.lineMap_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜}
(ht : t ∈ Icc 0 1) : AffineMap.lineMap x y t ∈ s :=
h.mapsTo_lineMap hx hy ht
theorem Convex.add_smul_sub_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜}
(ht : t ∈ Icc (0 : 𝕜) 1) : x + t • (y - x) ∈ s := by
rw [add_comm]
exact h.lineMap_mem hx hy ht
end AddCommGroup
end OrderedRing
section LinearOrderedSemiring
variable [Semiring 𝕜] [LinearOrder 𝕜] [IsOrderedRing 𝕜] [AddCommMonoid E]
theorem Convex_subadditive_le [SMul 𝕜 E] {f : E → 𝕜} (hf1 : ∀ x y, f (x + y) ≤ (f x) + (f y))
(hf2 : ∀ ⦃c⦄ x, 0 ≤ c → f (c • x) ≤ c * f x) (B : 𝕜) :
Convex 𝕜 { x | f x ≤ B } := by
rw [convex_iff_segment_subset]
rintro x hx y hy z ⟨a, b, ha, hb, hs, rfl⟩
calc
_ ≤ a • (f x) + b • (f y) := le_trans (hf1 _ _) (add_le_add (hf2 x ha) (hf2 y hb))
_ ≤ a • B + b • B := by gcongr <;> assumption
_ ≤ B := by rw [← add_smul, hs, one_smul]
end LinearOrderedSemiring
theorem Convex.midpoint_mem [Ring 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
[AddCommGroup E] [Module 𝕜 E] [Invertible (2 : 𝕜)] {s : Set E} {x y : E}
(h : Convex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) : midpoint 𝕜 x y ∈ s :=
h.segment_subset hx hy <| midpoint_mem_segment x y
section LinearOrderedField
variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
section AddCommGroup
variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E}
/-- Alternative definition of set convexity, using division. -/
theorem convex_iff_div :
Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s →
∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s :=
forall₂_congr fun _ _ => starConvex_iff_div
theorem Convex.mem_smul_of_zero_mem (h : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s)
{t : 𝕜} (ht : 1 ≤ t) : x ∈ t • s := by
rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne']
exact h.smul_mem_of_zero_mem zero_mem hx
⟨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one_of_one_le₀ ht⟩
theorem Convex.exists_mem_add_smul_eq (h : Convex 𝕜 s) {x y : E} {p q : 𝕜} (hx : x ∈ s) (hy : y ∈ s)
(hp : 0 ≤ p) (hq : 0 ≤ q) : ∃ z ∈ s, (p + q) • z = p • x + q • y := by
rcases _root_.em (p = 0 ∧ q = 0) with (⟨rfl, rfl⟩ | hpq)
· use x, hx
simp
· replace hpq : 0 < p + q :=
(add_nonneg hp hq).lt_of_ne' (mt (add_eq_zero_iff_of_nonneg hp hq).1 hpq)
refine ⟨_, convex_iff_div.1 h hx hy hp hq hpq, ?_⟩
match_scalars <;> field_simp
theorem Convex.add_smul (h_conv : Convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) :
(p + q) • s = p • s + q • s := (add_smul_subset _ _ _).antisymm <| by
rintro _ ⟨_, ⟨v₁, h₁, rfl⟩, _, ⟨v₂, h₂, rfl⟩, rfl⟩
exact h_conv.exists_mem_add_smul_eq h₁ h₂ hp hq
end AddCommGroup
end LinearOrderedField
/-!
#### Convex sets in an ordered space
Relates `Convex` and `OrdConnected`.
-/
section
theorem Set.OrdConnected.convex_of_chain [Semiring 𝕜] [PartialOrder 𝕜]
[AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E]
[OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) (h : IsChain (· ≤ ·) s) : Convex 𝕜 s := by
refine convex_iff_segment_subset.mpr fun x hx y hy => ?_
obtain hxy | hyx := h.total hx hy
· exact (segment_subset_Icc hxy).trans (hs.out hx hy)
· rw [segment_symm]
exact (segment_subset_Icc hyx).trans (hs.out hy hx)
theorem Set.OrdConnected.convex [Semiring 𝕜] [PartialOrder 𝕜]
[AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E]
[OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) : Convex 𝕜 s :=
hs.convex_of_chain <| isChain_of_trichotomous s
theorem convex_iff_ordConnected [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {s : Set 𝕜} :
Convex 𝕜 s ↔ s.OrdConnected := by
simp_rw [convex_iff_segment_subset, segment_eq_uIcc, ordConnected_iff_uIcc_subset]
alias ⟨Convex.ordConnected, _⟩ := convex_iff_ordConnected
end
/-! #### Convexity of submodules/subspaces -/
namespace Submodule
variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [Module 𝕜 E]
protected theorem convex (K : Submodule 𝕜 E) : Convex 𝕜 (↑K : Set E) := by
repeat' intro
refine add_mem (smul_mem _ _ ?_) (smul_mem _ _ ?_) <;> assumption
protected theorem starConvex (K : Submodule 𝕜 E) : StarConvex 𝕜 (0 : E) K :=
K.convex K.zero_mem
end Submodule
/-! ### Simplex -/
section Simplex
section OrderedSemiring
variable (𝕜) (ι : Type*) [Semiring 𝕜] [PartialOrder 𝕜] [Fintype ι]
/-- The standard simplex in the space of functions `ι → 𝕜` is the set of vectors with non-negative
coordinates with total sum `1`. This is the free object in the category of convex spaces. -/
def stdSimplex : Set (ι → 𝕜) :=
{ f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1 }
theorem stdSimplex_eq_inter : stdSimplex 𝕜 ι = (⋂ x, { f | 0 ≤ f x }) ∩ { f | ∑ x, f x = 1 } := by
ext f
simp only [stdSimplex, Set.mem_inter_iff, Set.mem_iInter, Set.mem_setOf_eq]
theorem convex_stdSimplex [IsOrderedRing 𝕜] : Convex 𝕜 (stdSimplex 𝕜 ι) := by
refine fun f hf g hg a b ha hb hab => ⟨fun x => ?_, ?_⟩
· apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1]
· simp_rw [Pi.add_apply, Pi.smul_apply]
rwa [Finset.sum_add_distrib, ← Finset.smul_sum, ← Finset.smul_sum, hf.2, hg.2, smul_eq_mul,
smul_eq_mul, mul_one, mul_one]
@[nontriviality] lemma stdSimplex_of_subsingleton [Subsingleton 𝕜] : stdSimplex 𝕜 ι = univ :=
eq_univ_of_forall fun _ ↦ ⟨fun _ ↦ (Subsingleton.elim _ _).le, Subsingleton.elim _ _⟩
/-- The standard simplex in the zero-dimensional space is empty. -/
lemma stdSimplex_of_isEmpty_index [IsEmpty ι] [Nontrivial 𝕜] : stdSimplex 𝕜 ι = ∅ :=
eq_empty_of_forall_not_mem <| by rintro f ⟨-, hf⟩; simp at hf
lemma stdSimplex_unique [ZeroLEOneClass 𝕜] [Nonempty ι] [Subsingleton ι] :
stdSimplex 𝕜 ι = {fun _ ↦ 1} := by
cases nonempty_unique ι
refine eq_singleton_iff_unique_mem.2 ⟨⟨fun _ ↦ zero_le_one, Fintype.sum_unique _⟩, ?_⟩
rintro f ⟨-, hf⟩
rw [Fintype.sum_unique] at hf
exact funext (Unique.forall_iff.2 hf)
variable {ι} [DecidableEq ι] [ZeroLEOneClass 𝕜]
theorem single_mem_stdSimplex (i : ι) : Pi.single i 1 ∈ stdSimplex 𝕜 ι :=
⟨le_update_iff.2 ⟨zero_le_one, fun _ _ ↦ le_rfl⟩, by simp⟩
theorem ite_eq_mem_stdSimplex (i : ι) : (if i = · then (1 : 𝕜) else 0) ∈ stdSimplex 𝕜 ι := by
simpa only [@eq_comm _ i, ← Pi.single_apply] using single_mem_stdSimplex 𝕜 i
variable [IsOrderedRing 𝕜]
#adaptation_note /-- nightly-2024-03-11
we need a type annotation on the segment in the following two lemmas. -/
/-- The edges are contained in the simplex. -/
lemma segment_single_subset_stdSimplex (i j : ι) :
([Pi.single i 1 -[𝕜] Pi.single j 1] : Set (ι → 𝕜)) ⊆ stdSimplex 𝕜 ι :=
(convex_stdSimplex 𝕜 ι).segment_subset (single_mem_stdSimplex _ _) (single_mem_stdSimplex _ _)
lemma stdSimplex_fin_two :
stdSimplex 𝕜 (Fin 2) = ([Pi.single 0 1 -[𝕜] Pi.single 1 1] : Set (Fin 2 → 𝕜)) := by
| refine Subset.antisymm ?_ (segment_single_subset_stdSimplex 𝕜 (0 : Fin 2) 1)
rintro f ⟨hf₀, hf₁⟩
rw [Fin.sum_univ_two] at hf₁
| Mathlib/Analysis/Convex/Basic.lean | 652 | 654 |
/-
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.Embedding.Basic
import Mathlib.Algebra.Homology.Additive
/-!
# The restriction functor of an embedding of complex shapes
Given `c` and `c'` complex shapes on two types, and `e : c.Embedding c'`
(satisfying `[e.IsRelIff]`), we define the restriction functor
`e.restrictionFunctor C : HomologicalComplex C c' ⥤ HomologicalComplex C c`.
-/
open CategoryTheory Category Limits ZeroObject
variable {ι ι' : Type*} {c : ComplexShape ι} {c' : ComplexShape ι'}
namespace HomologicalComplex
variable {C : Type*} [Category C] [HasZeroMorphisms C]
(K L M : HomologicalComplex C c') (φ : K ⟶ L) (φ' : L ⟶ M)
(e : c.Embedding c') [e.IsRelIff]
/-- Given `K : HomologicalComplex C c'` and `e : c.Embedding c'` (satisfying `[e.IsRelIff]`),
this is the homological complex in `HomologicalComplex C c` obtained by restriction. -/
@[simps]
def restriction : HomologicalComplex C c where
X i := K.X (e.f i)
d _ _ := K.d _ _
shape i j hij := K.shape _ _ (by simpa only [← e.rel_iff] using hij)
/-- The isomorphism `(K.restriction e).X i ≅ K.X i'` when `e.f i = i'`. -/
def restrictionXIso {i : ι} {i' : ι'} (h : e.f i = i') :
(K.restriction e).X i ≅ K.X i' :=
eqToIso (h ▸ rfl)
@[reassoc]
lemma restriction_d_eq {i j : ι} {i' j' : ι'} (hi : e.f i = i') (hj : e.f j = j') :
(K.restriction e).d i j = (K.restrictionXIso e hi).hom ≫ K.d i' j' ≫
(K.restrictionXIso e hj).inv := by
subst hi hj
simp [restrictionXIso]
variable {K L}
/-- The morphism `K.restriction e ⟶ L.restriction e` induced by a morphism `φ : K ⟶ L`. -/
@[simps]
def restrictionMap : K.restriction e ⟶ L.restriction e where
f i := φ.f (e.f i)
| @[reassoc]
lemma restrictionMap_f' {i : ι} {i' : ι'} (hi : e.f i = i') :
(restrictionMap φ e).f i = (K.restrictionXIso e hi).hom ≫
φ.f i' ≫ (L.restrictionXIso e hi).inv := by
subst hi
simp [restrictionXIso]
| Mathlib/Algebra/Homology/Embedding/Restriction.lean | 55 | 60 |
/-
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.Pi.Basic
import Mathlib.Data.Set.BooleanAlgebra
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.Interval.Set.UnorderedInterval
/-!
# Intervals in `pi`-space
In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`,
`Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals
usually include the corresponding products as proper subsets.
-/
-- Porting note: Added, since dot notation no longer works on `Function.update`
open Function
variable {ι : Type*} {α : ι → Type*}
namespace Set
section PiPreorder
variable [∀ i, Preorder (α i)] (x y : ∀ i, α i)
@[simp]
theorem pi_univ_Ici : (pi univ fun i ↦ Ici (x i)) = Ici x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Iic : (pi univ fun i ↦ Iic (x i)) = Iic x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Icc : (pi univ fun i ↦ Icc (x i) (y i)) = Icc x y :=
ext fun y ↦ by simp [Pi.le_def, forall_and]
theorem piecewise_mem_Icc {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : ∀ i ∈ s, f₁ i ∈ Icc (g₁ i) (g₂ i)) (h₂ : ∀ i ∉ s, f₂ i ∈ Icc (g₁ i) (g₂ i)) :
s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
⟨le_piecewise (fun i hi ↦ (h₁ i hi).1) fun i hi ↦ (h₂ i hi).1,
piecewise_le (fun i hi ↦ (h₁ i hi).2) fun i hi ↦ (h₂ i hi).2⟩
theorem piecewise_mem_Icc' {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : f₁ ∈ Icc g₁ g₂) (h₂ : f₂ ∈ Icc g₁ g₂) : s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
piecewise_mem_Icc (fun _ _ ↦ ⟨h₁.1 _, h₁.2 _⟩) fun _ _ ↦ ⟨h₂.1 _, h₂.2 _⟩
section Nonempty
theorem pi_univ_Ioi_subset [Nonempty ι]: (pi univ fun i ↦ Ioi (x i)) ⊆ Ioi x := fun _ hz ↦
⟨fun i ↦ le_of_lt <| hz i trivial, fun h ↦
(‹Nonempty ι›.elim) fun i ↦ not_lt_of_le (h i) (hz i trivial)⟩
theorem pi_univ_Iio_subset [Nonempty ι]: (pi univ fun i ↦ Iio (x i)) ⊆ Iio x :=
pi_univ_Ioi_subset (α := fun i ↦ (α i)ᵒᵈ) x
theorem pi_univ_Ioo_subset [Nonempty ι]: (pi univ fun i ↦ Ioo (x i) (y i)) ⊆ Ioo x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
theorem pi_univ_Ioc_subset [Nonempty ι]: (pi univ fun i ↦ Ioc (x i) (y i)) ⊆ Ioc x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, fun i ↦ (hx i trivial).2⟩
theorem pi_univ_Ico_subset [Nonempty ι]: (pi univ fun i ↦ Ico (x i) (y i)) ⊆ Ico x y := fun _ hx ↦
⟨fun i ↦ (hx i trivial).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
end Nonempty
variable [DecidableEq ι]
open Function (update)
theorem pi_univ_Ioc_update_left {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) :
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) =
{ z | m < z i₀ } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc m (y i₀) = Ioi m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, ← inter_assoc,
inter_eq_self_of_subset_left (Ioi_subset_Ioi hm)]
simp_rw [univ_pi_update i₀ _ _ fun i z ↦ Ioc z (y i), ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem pi_univ_Ioc_update_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) :
(pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) =
{ z | z i₀ ≤ m } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc (x i₀) m = Iic m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_left_comm,
inter_eq_self_of_subset_left (Iic_subset_Iic.2 hm)]
simp_rw [univ_pi_update i₀ y m fun i z ↦ Ioc (x i) z, ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem disjoint_pi_univ_Ioc_update_left_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} :
Disjoint (pi univ fun i ↦ Ioc (x i) (update y i₀ m i))
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) := by
rw [disjoint_left]
rintro z h₁ h₂
refine (h₁ i₀ (mem_univ _)).2.not_lt ?_
simpa only [Function.update_self] using (h₂ i₀ (mem_univ _)).1
end PiPreorder
section PiPartialOrder
variable [DecidableEq ι] [∀ i, PartialOrder (α i)]
-- Porting note: Dot notation on `Function.update` broke
theorem image_update_Icc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Icc a b = Icc (update f i a) (update f i b) := by
ext x
rw [← Set.pi_univ_Icc]
refine ⟨?_, fun h => ⟨x i, ?_, ?_⟩⟩
· rintro ⟨c, hc, rfl⟩
simpa [update_le_update_iff]
· simpa only [Function.update_self] using h i (mem_univ i)
· ext j
obtain rfl | hij := eq_or_ne i j
· exact Function.update_self ..
· simpa only [Function.update_of_ne hij.symm, le_antisymm_iff] using h j (mem_univ j)
theorem image_update_Ico (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ico a b = Ico (update f i a) (update f i b) := by
rw [← Icc_diff_right, ← Icc_diff_right, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioc a b = Ioc (update f i a) (update f i b) := by
rw [← Icc_diff_left, ← Icc_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioo (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioo a b = Ioo (update f i a) (update f i b) := by
rw [← Ico_diff_left, ← Ico_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Ico]
theorem image_update_Icc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Icc a (f i) = Icc (update f i a) f := by simpa using image_update_Icc f i a (f i)
theorem image_update_Ico_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ico a (f i) = Ico (update f i a) f := by simpa using image_update_Ico f i a (f i)
theorem image_update_Ioc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioc a (f i) = Ioc (update f i a) f := by simpa using image_update_Ioc f i a (f i)
theorem image_update_Ioo_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioo a (f i) = Ioo (update f i a) f := by simpa using image_update_Ioo f i a (f i)
theorem image_update_Icc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Icc (f i) b = Icc f (update f i b) := by simpa using image_update_Icc f i (f i) b
theorem image_update_Ico_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ico (f i) b = Ico f (update f i b) := by simpa using image_update_Ico f i (f i) b
theorem image_update_Ioc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioc (f i) b = Ioc f (update f i b) := by simpa using image_update_Ioc f i (f i) b
theorem image_update_Ioo_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioo (f i) b = Ioo f (update f i b) := by simpa using image_update_Ioo f i (f i) b
variable [∀ i, One (α i)]
@[to_additive]
theorem image_mulSingle_Icc (i : ι) (a b : α i) :
| Pi.mulSingle i '' Icc a b = Icc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Icc _ _ _ _
| Mathlib/Order/Interval/Set/Pi.lean | 168 | 169 |
/-
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 :=
rfl
@[simp]
theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h]
@[simp]
theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by
simp [top_rpow_def, asymm h, ne_of_lt h]
@[simp]
theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, asymm h, ne_of_gt h]
@[simp]
theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, ne_of_gt h]
theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by
rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H)
· simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl]
· simp [lt_irrefl]
· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg]
@[simp]
theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by
rw [zero_rpow_def]
split_ifs
exacts [zero_mul _, one_mul _, top_mul_top]
@[norm_cast]
theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (↑(x ^ y) : ℝ≥0∞) = x ^ y := by
rw [← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), Pow.pow, rpow]
simp [h]
@[norm_cast]
theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : ↑(x ^ y) = (x : ℝ≥0∞) ^ y := by
by_cases hx : x = 0
· rcases le_iff_eq_or_lt.1 h with (H | H)
· simp [hx, H.symm]
· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)]
· exact coe_rpow_of_ne_zero hx _
theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) :
(x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) :=
rfl
theorem rpow_ofNNReal {M : ℝ≥0} {P : ℝ} (hP : 0 ≤ P) : (M : ℝ≥0∞) ^ P = ↑(M ^ P) := by
rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow]
@[simp]
theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by
cases x
· exact dif_pos zero_lt_one
· change ite _ _ _ = _
simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp]
exact fun _ => zero_le_one.not_lt
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by
rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero]
simp
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by
simp [hy, hy.not_lt]
@[simp]
theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by
simp [rpow_eq_top_iff, hy, asymm hy]
lemma rpow_lt_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by
simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy]
theorem rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ := by
rw [ENNReal.rpow_eq_top_iff]
rintro (h|h)
· exfalso
rw [lt_iff_not_ge] at h
exact h.right hy0
· exact h.left
theorem rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ :=
mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h
theorem rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ :=
lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h)
theorem rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z := by
cases x with
| top => exact (h'x rfl).elim
| coe x =>
have : x ≠ 0 := fun h => by simp [h] at hx
simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this]
theorem rpow_add_of_nonneg {x : ℝ≥0∞} (y z : ℝ) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
induction x using recTopCoe
· rcases hy.eq_or_lt with rfl|hy
· rw [rpow_zero, one_mul, zero_add]
rcases hz.eq_or_lt with rfl|hz
· rw [rpow_zero, mul_one, add_zero]
simp [top_rpow_of_pos, hy, hz, add_pos hy hz]
simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz]
theorem rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr]
· have A : x ^ y ≠ 0 := by simp [h]
simp [← coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg]
theorem rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z := by
rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv]
theorem rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
· have : x ^ y ≠ 0 := by simp [h]
simp [← coe_rpow_of_ne_zero, h, this, NNReal.rpow_mul]
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by
cases x
· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)]
· simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)]
@[simp]
lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n) :=
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]
theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) :
(x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z := by
rcases eq_or_ne z 0 with (rfl | hz); · simp
replace hz := hz.lt_or_lt
wlog hxy : x ≤ y
· convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm]
rcases eq_or_ne x 0 with (rfl | hx0)
· induction y <;> rcases hz with hz | hz <;> simp [*, hz.not_lt]
rcases eq_or_ne y 0 with (rfl | hy0)
· exact (hx0 (bot_unique hxy)).elim
induction x
· rcases hz with hz | hz <;> simp [hz, top_unique hxy]
induction y
· rw [ne_eq, coe_eq_zero] at hx0
rcases hz with hz | hz <;> simp [*]
simp only [*, if_false]
norm_cast at *
rw [← coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow]
norm_cast
theorem mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite]
@[norm_cast]
theorem coe_mul_rpow (x y : ℝ≥0) (z : ℝ) : ((x : ℝ≥0∞) * y) ^ z = (x : ℝ≥0∞) ^ z * (y : ℝ≥0∞) ^ z :=
mul_rpow_of_ne_top coe_ne_top coe_ne_top z
theorem prod_coe_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
∏ i ∈ s, (f i : ℝ≥0∞) ^ r = ((∏ i ∈ s, f i : ℝ≥0) : ℝ≥0∞) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul]
theorem mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite]
theorem mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x * y) ^ z = x ^ z * y ^ z := by
simp [hz.not_lt, mul_rpow_eq_ite]
theorem prod_rpow_of_ne_top {ι} {s : Finset ι} {f : ι → ℝ≥0∞} (hf : ∀ i ∈ s, f i ≠ ∞) (r : ℝ) :
∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert i s hi ih =>
have h2f : ∀ i ∈ s, f i ≠ ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi
rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..]
apply prod_ne_top h2f
theorem prod_rpow_of_nonneg {ι} {s : Finset ι} {f : ι → ℝ≥0∞} {r : ℝ} (hr : 0 ≤ r) :
∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr]
theorem inv_rpow (x : ℝ≥0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by
rcases eq_or_ne y 0 with (rfl | hy); · simp only [rpow_zero, inv_one]
replace hy := hy.lt_or_lt
rcases eq_or_ne x 0 with (rfl | h0); · cases hy <;> simp [*]
rcases eq_or_ne x ⊤ with (rfl | h_top); · cases hy <;> simp [*]
apply ENNReal.eq_inv_of_mul_eq_one_left
rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top,
one_rpow]
theorem div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x / y) ^ z = x ^ z / y ^ z := by
rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0∞ => x ^ z := by
intro x y hxy
lift x to ℝ≥0 using ne_top_of_lt hxy
rcases eq_or_ne y ∞ with (rfl | hy)
· simp only [top_rpow_of_pos h, ← coe_rpow_of_nonneg _ h.le, coe_lt_top]
· lift y to ℝ≥0 using hy
simp only [← coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 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_apply (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
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
monotone_rpow_of_nonneg h₂ h₁
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
strictMono_rpow_of_pos h₂ h₁
theorem rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
(strictMono_rpow_of_pos hz).le_iff_le
theorem rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
(strictMono_rpow_of_pos hz).lt_iff_lt
theorem le_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
nth_rw 1 [← rpow_one x]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne']
rw [rpow_mul, @rpow_le_rpow_iff _ _ z⁻¹ (by simp [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]
theorem lt_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := by
nth_rw 1 [← rpow_one x]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z (ne_of_lt hz).symm]
rw [rpow_mul, @rpow_lt_rpow_iff _ _ z⁻¹ (by simp [hz])]
theorem rpow_inv_le_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
nth_rw 1 [← ENNReal.rpow_one y]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne.symm]
rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (inv_pos.2 hz)]
theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) :
x ^ y < x ^ z := by
lift x to ℝ≥0 using hx'
rw [one_lt_coe_iff] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
NNReal.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 := by
cases x
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;>
linarith
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
NNReal.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 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top)
simp only [coe_lt_one_iff, coe_pos] at hx0 hx1
simp [← coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz]
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top)
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;>
linarith
· rw [coe_le_one_iff] at hx1
simp [← coe_rpow_of_ne_zero h,
NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz]
theorem rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
nth_rw 2 [← ENNReal.rpow_one x]
exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le
theorem le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z := by
nth_rw 1 [← ENNReal.rpow_one x]
exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le
theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≤ p) : 0 < x ^ p := by
by_cases hp_zero : p = 0
· simp [hp_zero, zero_lt_one]
· rw [← Ne] at hp_zero
have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm
rw [← zero_rpow_of_pos hp_pos]
exact rpow_lt_rpow hx_pos hp_pos
theorem rpow_pos {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hx_ne_top : x ≠ ⊤) : 0 < x ^ p := by
rcases lt_or_le 0 p with hp_pos | hp_nonpos
· exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos)
· rw [← neg_neg p, rpow_neg, ENNReal.inv_pos]
exact rpow_ne_top_of_nonneg (Right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top
theorem rpow_lt_one {x : ℝ≥0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x ^ z < 1 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx le_top)
simp only [coe_lt_one_iff] at hx
simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.rpow_lt_one hx hz]
theorem rpow_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top)
simp only [coe_le_one_iff] at hx
simp [← coe_rpow_of_nonneg _ hz, NNReal.rpow_le_one hx hz]
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by
cases x
· simp [top_rpow_of_neg hz, zero_lt_one]
· simp only [some_eq_coe, one_lt_coe_iff] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
NNReal.rpow_lt_one_of_one_lt_of_neg hx hz]
theorem rpow_le_one_of_one_le_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : z < 0) : x ^ z ≤ 1 := by
cases x
· simp [top_rpow_of_neg hz, zero_lt_one]
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
NNReal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)]
theorem one_lt_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by
cases x
· simp [top_rpow_of_pos hz]
· simp only [some_eq_coe, one_lt_coe_iff] at hx
simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_lt_rpow hx hz]
theorem one_le_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : 0 < z) : 1 ≤ x ^ z := by
cases x
· simp [top_rpow_of_pos hz]
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_le_rpow hx (le_of_lt hz)]
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 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx2 le_top)
simp only [coe_lt_one_iff, coe_pos] at hx1 hx2 ⊢
simp [← coe_rpow_of_ne_zero (ne_of_gt hx1), NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz]
theorem one_le_rpow_of_pos_of_le_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z < 0) : 1 ≤ x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx2 coe_lt_top)
simp only [coe_le_one_iff, coe_pos] at hx1 hx2 ⊢
simp [← coe_rpow_of_ne_zero (ne_of_gt hx1),
NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 (le_of_lt hz)]
@[simp] lemma toNNReal_rpow (x : ℝ≥0∞) (z : ℝ) : (x ^ z).toNNReal = x.toNNReal ^ z := by
rcases lt_trichotomy z 0 with (H | H | H)
· cases x with
| top => simp [H, ne_of_lt]
| coe x =>
by_cases hx : x = 0
· simp [hx, H, ne_of_lt]
· simp [← coe_rpow_of_ne_zero hx]
· simp [H]
· cases x
· simp [H, ne_of_gt]
simp [← coe_rpow_of_nonneg _ (le_of_lt H)]
theorem toReal_rpow (x : ℝ≥0∞) (z : ℝ) : x.toReal ^ z = (x ^ z).toReal := by
rw [ENNReal.toReal, ENNReal.toReal, ← NNReal.coe_rpow, ENNReal.toNNReal_rpow]
theorem ofReal_rpow_of_pos {x p : ℝ} (hx_pos : 0 < x) :
ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by
simp_rw [ENNReal.ofReal]
rw [← coe_rpow_of_ne_zero, coe_inj, Real.toNNReal_rpow_of_nonneg hx_pos.le]
simp [hx_pos]
theorem ofReal_rpow_of_nonneg {x p : ℝ} (hx_nonneg : 0 ≤ x) (hp_nonneg : 0 ≤ p) :
ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by
by_cases hp0 : p = 0
· simp [hp0]
by_cases hx0 : x = 0
· rw [← Ne] at hp0
have hp_pos : 0 < p := lt_of_le_of_ne hp_nonneg hp0.symm
simp [hx0, hp_pos, hp_pos.ne.symm]
rw [← Ne] at hx0
exact ofReal_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm)
@[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]
lemma pow_rpow_inv_natCast {n : ℕ} (hn : n ≠ 0) (x : ℝ≥0∞) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← rpow_natCast, ← rpow_mul, mul_inv_cancel₀ (by positivity), rpow_one]
lemma rpow_inv_natCast_pow {n : ℕ} (hn : n ≠ 0) (x : ℝ≥0∞) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← rpow_natCast, ← rpow_mul, inv_mul_cancel₀ (by positivity), rpow_one]
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]
|
lemma rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Injective fun y : ℝ≥0∞ ↦ y ^ x :=
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 926 | 927 |
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten, Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Morphisms.ClosedImmersion
import Mathlib.AlgebraicGeometry.PullbackCarrier
import Mathlib.CategoryTheory.Limits.Constructions.Over.Basic
import Mathlib.CategoryTheory.Limits.Constructions.Over.Products
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Equalizer
/-!
# Separated morphisms
A morphism of schemes is separated if its diagonal morphism is a closed immmersion.
## Main definitions
- `AlgebraicGeometry.IsSeparated`: The class of separated morphisms.
- `AlgebraicGeometry.Scheme.IsSeparated`: The class of separated schemes.
- `AlgebraicGeometry.IsSeparated.hasAffineProperty`:
A morphism is separated iff the preimage of affine opens are separated schemes.
-/
noncomputable section
open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace
universe u
open scoped AlgebraicGeometry
namespace AlgebraicGeometry
variable {W X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z)
/-- A morphism is separated if the diagonal map is a closed immersion. -/
@[mk_iff]
class IsSeparated : Prop where
/-- A morphism is separated if the diagonal map is a closed immersion. -/
diagonal_isClosedImmersion : IsClosedImmersion (pullback.diagonal f) := by infer_instance
namespace IsSeparated
attribute [instance] diagonal_isClosedImmersion
theorem isSeparated_eq_diagonal_isClosedImmersion :
@IsSeparated = MorphismProperty.diagonal @IsClosedImmersion := by
ext
exact isSeparated_iff _
/-- Monomorphisms are separated. -/
instance (priority := 900) isSeparated_of_mono [Mono f] : IsSeparated f where
instance : MorphismProperty.RespectsIso @IsSeparated := by
| rw [isSeparated_eq_diagonal_isClosedImmersion]
infer_instance
instance (priority := 900) [IsSeparated f] : QuasiSeparated f where
| Mathlib/AlgebraicGeometry/Morphisms/Separated.lean | 57 | 60 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.TangentCone
import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics
import Mathlib.Analysis.Asymptotics.TVS
import Mathlib.Analysis.Asymptotics.Lemmas
/-!
# The Fréchet derivative
Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a
continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then
`HasFDerivWithinAt f f' s x`
says that `f` has derivative `f'` at `x`, where the domain of interest
is restricted to `s`. We also have
`HasFDerivAt f f' x := HasFDerivWithinAt f f' x univ`
Finally,
`HasStrictFDerivAt f f' x`
means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability,
i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse
function theorem, and is defined here only to avoid proving theorems like
`IsBoundedBilinearMap.hasFDerivAt` twice: first for `HasFDerivAt`, then for
`HasStrictFDerivAt`.
## Main results
In addition to the definition and basic properties of the derivative,
the folder `Analysis/Calculus/FDeriv/` contains the usual formulas
(and existence assertions) for the derivative of
* constants
* the identity
* bounded linear maps (`Linear.lean`)
* bounded bilinear maps (`Bilinear.lean`)
* sum of two functions (`Add.lean`)
* sum of finitely many functions (`Add.lean`)
* multiplication of a function by a scalar constant (`Add.lean`)
* negative of a function (`Add.lean`)
* subtraction of two functions (`Add.lean`)
* multiplication of a function by a scalar function (`Mul.lean`)
* multiplication of two scalar functions (`Mul.lean`)
* composition of functions (the chain rule) (`Comp.lean`)
* inverse function (`Mul.lean`)
(assuming that it exists; the inverse function theorem is in `../Inverse.lean`)
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `HasDerivAt`'s easier,
and they more frequently lead to the desired result.
One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying
a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are
translated to this more elementary point of view on the derivative in the file `Deriv.lean`. The
derivative of polynomials is handled there, as it is naturally one-dimensional.
The simplifier is set up to prove automatically that some functions are differentiable, or
differentiable at a point (but not differentiable on a set or within a set at a point, as checking
automatically that the good domains are mapped one to the other when using composition is not
something the simplifier can easily do). This means that one can write
`example (x : ℝ) : Differentiable ℝ (fun x ↦ sin (exp (3 + x^2)) - 5 * cos x) := by simp`.
If there are divisions, one needs to supply to the simplifier proofs that the denominators do
not vanish, as in
```lean
example (x : ℝ) (h : 1 + sin x ≠ 0) : DifferentiableAt ℝ (fun x ↦ exp x / (1 + sin x)) x := by
simp [h]
```
Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be
differentiable, in `Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv`.
The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general
complicated multidimensional linear maps), but it will compute one-dimensional derivatives,
see `Deriv.lean`.
## Implementation details
The derivative is defined in terms of the `IsLittleOTVS` relation to ensure the definition does not
ingrain a choice of norm, and is then quickly translated to the more convenient `IsLittleO` in the
subsequent theorems.
It is also characterized in terms of the `Tendsto` relation.
We also introduce predicates `DifferentiableWithinAt 𝕜 f s x` (where `𝕜` is the base field,
`f` the function to be differentiated, `x` the point at which the derivative is asserted to exist,
and `s` the set along which the derivative is defined), as well as `DifferentiableAt 𝕜 f x`,
`DifferentiableOn 𝕜 f s` and `Differentiable 𝕜 f` to express the existence of a derivative.
To be able to compute with derivatives, we write `fderivWithin 𝕜 f s x` and `fderiv 𝕜 f x`
for some choice of a derivative if it exists, and the zero function otherwise. This choice only
behaves well along sets for which the derivative is unique, i.e., those for which the tangent
directions span a dense subset of the whole space. The predicates `UniqueDiffWithinAt s x` and
`UniqueDiffOn s`, defined in `TangentCone.lean` express this property. We prove that indeed
they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular
for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very
beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever.
To make sure that the simplifier can prove automatically that functions are differentiable, we tag
many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable
functions is differentiable, as well as their product, their cartesian product, and so on. A notable
exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are
differentiable, then their composition also is: `simp` would always be able to match this lemma,
by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`),
we add a lemma that if `f` is differentiable then so is `(fun x ↦ exp (f x))`. This means adding
some boilerplate lemmas, but these can also be useful in their own right.
Tests for this ability of the simplifier (with more examples) are provided in
`Tests/Differentiable.lean`.
## TODO
Generalize more results to topological vector spaces.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section TVS
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
variable {F : Type*} [AddCommGroup F] [Module 𝕜 F] [TopologicalSpace F]
/-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition
is designed to be specialized for `L = 𝓝 x` (in `HasFDerivAt`), giving rise to the usual notion
of Fréchet derivative, and for `L = 𝓝[s] x` (in `HasFDerivWithinAt`), giving rise to
the notion of Fréchet derivative along the set `s`. -/
@[mk_iff hasFDerivAtFilter_iff_isLittleOTVS]
structure HasFDerivAtFilter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : Filter E) : Prop where
of_isLittleOTVS ::
isLittleOTVS : (fun x' => f x' - f x - f' (x' - x)) =o[𝕜; L] (fun x' => x' - x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/
@[fun_prop]
def HasFDerivWithinAt (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (x : E) :=
HasFDerivAtFilter f f' x (𝓝[s] x)
/-- A function `f` has the continuous linear map `f'` as derivative at `x` if
`f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/
@[fun_prop]
def HasFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) :=
HasFDerivAtFilter f f' x (𝓝 x)
/-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability*
if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required,
e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly
differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/
@[fun_prop, mk_iff hasStrictFDerivAt_iff_isLittleOTVS]
structure HasStrictFDerivAt (f : E → F) (f' : E →L[𝕜] F) (x : E) where
of_isLittleOTVS ::
isLittleOTVS :
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2))
=o[𝕜; 𝓝 (x, x)] (fun p : E × E => p.1 - p.2)
variable (𝕜)
/-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative
there (possibly non-unique). -/
@[fun_prop]
def DifferentiableWithinAt (f : E → F) (s : Set E) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivWithinAt f f' s x
/-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly
non-unique). -/
@[fun_prop]
def DifferentiableAt (f : E → F) (x : E) :=
∃ f' : E →L[𝕜] F, HasFDerivAt f f' x
open scoped Classical in
/-- If `f` has a derivative at `x` within `s`, then `fderivWithin 𝕜 f s x` is such a derivative.
Otherwise, it is set to `0`. We also set it to be zero, if zero is one of possible derivatives. -/
irreducible_def fderivWithin (f : E → F) (s : Set E) (x : E) : E →L[𝕜] F :=
if HasFDerivWithinAt f (0 : E →L[𝕜] F) s x
then 0
else if h : DifferentiableWithinAt 𝕜 f s x
then Classical.choose h
else 0
/-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is
set to `0`. -/
irreducible_def fderiv (f : E → F) (x : E) : E →L[𝕜] F :=
fderivWithin 𝕜 f univ x
/-- `DifferentiableOn 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/
@[fun_prop]
def DifferentiableOn (f : E → F) (s : Set E) :=
∀ x ∈ s, DifferentiableWithinAt 𝕜 f s x
/-- `Differentiable 𝕜 f` means that `f` is differentiable at any point. -/
@[fun_prop]
def Differentiable (f : E → F) :=
∀ x, DifferentiableAt 𝕜 f x
variable {𝕜}
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem fderivWithin_zero_of_not_differentiableWithinAt (h : ¬DifferentiableWithinAt 𝕜 f s x) :
fderivWithin 𝕜 f s x = 0 := by
simp [fderivWithin, h]
@[simp]
theorem fderivWithin_univ : fderivWithin 𝕜 f univ = fderiv 𝕜 f := by
ext
rw [fderiv]
end TVS
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
theorem hasFDerivAtFilter_iff_isLittleO :
HasFDerivAtFilter f f' x L ↔ (fun x' => f x' - f x - f' (x' - x)) =o[L] fun x' => x' - x :=
(hasFDerivAtFilter_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasFDerivAtFilter.isLittleO, HasFDerivAtFilter.of_isLittleO⟩ :=
hasFDerivAtFilter_iff_isLittleO
theorem hasStrictFDerivAt_iff_isLittleO :
HasStrictFDerivAt f f' x ↔
(fun p : E × E => f p.1 - f p.2 - f' (p.1 - p.2)) =o[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
(hasStrictFDerivAt_iff_isLittleOTVS ..).trans isLittleOTVS_iff_isLittleO
alias ⟨HasStrictFDerivAt.isLittleO, HasStrictFDerivAt.of_isLittleO⟩ :=
hasStrictFDerivAt_iff_isLittleO
section DerivativeUniqueness
/- In this section, we discuss the uniqueness of the derivative.
We prove that the definitions `UniqueDiffWithinAt` and `UniqueDiffOn` indeed imply the
uniqueness of the derivative. -/
/-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f',
i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity
and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses
this fact, for functions having a derivative within a set. Its specific formulation is useful for
tangent cone related discussions. -/
theorem HasFDerivWithinAt.lim (h : HasFDerivWithinAt f f' s x) {α : Type*} (l : Filter α)
{c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s)
(clim : Tendsto (fun n => ‖c n‖) l atTop) (cdlim : Tendsto (fun n => c n • d n) l (𝓝 v)) :
Tendsto (fun n => c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := by
have tendsto_arg : Tendsto (fun n => x + d n) l (𝓝[s] x) := by
conv in 𝓝[s] x => rw [← add_zero x]
rw [nhdsWithin, tendsto_inf]
constructor
· apply tendsto_const_nhds.add (tangentConeAt.lim_zero l clim cdlim)
· rwa [tendsto_principal]
have : (fun y => f y - f x - f' (y - x)) =o[𝓝[s] x] fun y => y - x := h.isLittleO
have : (fun n => f (x + d n) - f x - f' (x + d n - x)) =o[l] fun n => x + d n - x :=
this.comp_tendsto tendsto_arg
have : (fun n => f (x + d n) - f x - f' (d n)) =o[l] d := by simpa only [add_sub_cancel_left]
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun n => c n • d n :=
(isBigO_refl c l).smul_isLittleO this
have : (fun n => c n • (f (x + d n) - f x - f' (d n))) =o[l] fun _ => (1 : ℝ) :=
this.trans_isBigO (cdlim.isBigO_one ℝ)
have L1 : Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n))) l (𝓝 0) :=
(isLittleO_one_iff ℝ).1 this
have L2 : Tendsto (fun n => f' (c n • d n)) l (𝓝 (f' v)) :=
Tendsto.comp f'.cont.continuousAt cdlim
have L3 :
Tendsto (fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) l (𝓝 (0 + f' v)) :=
L1.add L2
have :
(fun n => c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n)) = fun n =>
c n • (f (x + d n) - f x) := by
ext n
simp [smul_add, smul_sub]
rwa [this, zero_add] at L3
/-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the
tangent cone to `s` at `x` -/
theorem HasFDerivWithinAt.unique_on (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : EqOn f' f₁' (tangentConeAt 𝕜 s x) :=
fun _ ⟨_, _, dtop, clim, cdlim⟩ =>
tendsto_nhds_unique (hf.lim atTop dtop clim cdlim) (hg.lim atTop dtop clim cdlim)
/-- `UniqueDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/
theorem UniqueDiffWithinAt.eq (H : UniqueDiffWithinAt 𝕜 s x) (hf : HasFDerivWithinAt f f' s x)
(hg : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
ContinuousLinearMap.ext_on H.1 (hf.unique_on hg)
theorem UniqueDiffOn.eq (H : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h : HasFDerivWithinAt f f' s x)
(h₁ : HasFDerivWithinAt f f₁' s x) : f' = f₁' :=
(H x hx).eq h h₁
end DerivativeUniqueness
section FDerivProperties
/-! ### Basic properties of the derivative -/
theorem hasFDerivAtFilter_iff_tendsto :
HasFDerivAtFilter f f' x L ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) L (𝓝 0) := by
have h : ∀ x', ‖x' - x‖ = 0 → ‖f x' - f x - f' (x' - x)‖ = 0 := fun x' hx' => by
rw [sub_eq_zero.1 (norm_eq_zero.1 hx')]
simp
rw [hasFDerivAtFilter_iff_isLittleO, ← isLittleO_norm_left, ← isLittleO_norm_right,
isLittleO_iff_tendsto h]
exact tendsto_congr fun _ => div_eq_inv_mul _ _
theorem hasFDerivWithinAt_iff_tendsto :
HasFDerivWithinAt f f' s x ↔
Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝[s] x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_tendsto :
HasFDerivAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - f' (x' - x)‖) (𝓝 x) (𝓝 0) :=
hasFDerivAtFilter_iff_tendsto
theorem hasFDerivAt_iff_isLittleO_nhds_zero :
HasFDerivAt f f' x ↔ (fun h : E => f (x + h) - f x - f' h) =o[𝓝 0] fun h => h := by
rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO, ← map_add_left_nhds_zero x, isLittleO_map]
simp [Function.comp_def]
nonrec theorem HasFDerivAtFilter.mono (h : HasFDerivAtFilter f f' x L₂) (hst : L₁ ≤ L₂) :
HasFDerivAtFilter f f' x L₁ :=
.of_isLittleOTVS <| h.isLittleOTVS.mono hst
theorem HasFDerivWithinAt.mono_of_mem_nhdsWithin
(h : HasFDerivWithinAt f f' t x) (hst : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_le_iff.mpr hst
@[deprecated (since := "2024-10-31")]
alias HasFDerivWithinAt.mono_of_mem := HasFDerivWithinAt.mono_of_mem_nhdsWithin
nonrec theorem HasFDerivWithinAt.mono (h : HasFDerivWithinAt f f' t x) (hst : s ⊆ t) :
HasFDerivWithinAt f f' s x :=
h.mono <| nhdsWithin_mono _ hst
theorem HasFDerivAt.hasFDerivAtFilter (h : HasFDerivAt f f' x) (hL : L ≤ 𝓝 x) :
HasFDerivAtFilter f f' x L :=
h.mono hL
@[fun_prop]
theorem HasFDerivAt.hasFDerivWithinAt (h : HasFDerivAt f f' x) : HasFDerivWithinAt f f' s x :=
h.hasFDerivAtFilter inf_le_left
@[fun_prop]
theorem HasFDerivWithinAt.differentiableWithinAt (h : HasFDerivWithinAt f f' s x) :
DifferentiableWithinAt 𝕜 f s x :=
⟨f', h⟩
@[fun_prop]
theorem HasFDerivAt.differentiableAt (h : HasFDerivAt f f' x) : DifferentiableAt 𝕜 f x :=
⟨f', h⟩
@[simp]
theorem hasFDerivWithinAt_univ : HasFDerivWithinAt f f' univ x ↔ HasFDerivAt f f' x := by
simp only [HasFDerivWithinAt, nhdsWithin_univ, HasFDerivAt]
alias ⟨HasFDerivWithinAt.hasFDerivAt_of_univ, _⟩ := hasFDerivWithinAt_univ
theorem differentiableWithinAt_univ :
DifferentiableWithinAt 𝕜 f univ x ↔ DifferentiableAt 𝕜 f x := by
simp only [DifferentiableWithinAt, hasFDerivWithinAt_univ, DifferentiableAt]
theorem fderiv_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : fderiv 𝕜 f x = 0 := by
rw [fderiv, fderivWithin_zero_of_not_differentiableWithinAt]
rwa [differentiableWithinAt_univ]
theorem hasFDerivWithinAt_of_mem_nhds (h : s ∈ 𝓝 x) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x := by
rw [HasFDerivAt, HasFDerivWithinAt, nhdsWithin_eq_nhds.mpr h]
lemma hasFDerivWithinAt_of_isOpen (h : IsOpen s) (hx : x ∈ s) :
HasFDerivWithinAt f f' s x ↔ HasFDerivAt f f' x :=
hasFDerivWithinAt_of_mem_nhds (h.mem_nhds hx)
@[simp]
theorem hasFDerivWithinAt_insert {y : E} :
HasFDerivWithinAt f f' (insert y s) x ↔ HasFDerivWithinAt f f' s x := by
rcases eq_or_ne x y with (rfl | h)
· simp_rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
apply isLittleOTVS_insert
simp only [sub_self, map_zero]
refine ⟨fun h => h.mono <| subset_insert y s, fun hf => hf.mono_of_mem_nhdsWithin ?_⟩
simp_rw [nhdsWithin_insert_of_ne h, self_mem_nhdsWithin]
alias ⟨HasFDerivWithinAt.of_insert, HasFDerivWithinAt.insert'⟩ := hasFDerivWithinAt_insert
protected theorem HasFDerivWithinAt.insert (h : HasFDerivWithinAt g g' s x) :
HasFDerivWithinAt g g' (insert x s) x :=
h.insert'
@[simp]
theorem hasFDerivWithinAt_diff_singleton (y : E) :
HasFDerivWithinAt f f' (s \ {y}) x ↔ HasFDerivWithinAt f f' s x := by
rw [← hasFDerivWithinAt_insert, insert_diff_singleton, hasFDerivWithinAt_insert]
@[simp]
protected theorem HasFDerivWithinAt.empty : HasFDerivWithinAt f f' ∅ x := by
simp [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleOTVS]
@[simp]
protected theorem DifferentiableWithinAt.empty : DifferentiableWithinAt 𝕜 f ∅ x :=
⟨0, .empty⟩
theorem HasFDerivWithinAt.of_finite (h : s.Finite) : HasFDerivWithinAt f f' s x := by
induction s, h using Set.Finite.induction_on with
| empty => exact .empty
| insert _ _ ih => exact ih.insert'
theorem DifferentiableWithinAt.of_finite (h : s.Finite) : DifferentiableWithinAt 𝕜 f s x :=
⟨0, .of_finite h⟩
@[simp]
protected theorem HasFDerivWithinAt.singleton {y} : HasFDerivWithinAt f f' {x} y :=
.of_finite <| finite_singleton _
@[simp]
protected theorem DifferentiableWithinAt.singleton {y} : DifferentiableWithinAt 𝕜 f {x} y :=
⟨0, .singleton⟩
theorem HasFDerivWithinAt.of_subsingleton (h : s.Subsingleton) : HasFDerivWithinAt f f' s x :=
.of_finite h.finite
theorem DifferentiableWithinAt.of_subsingleton (h : s.Subsingleton) :
DifferentiableWithinAt 𝕜 f s x :=
.of_finite h.finite
theorem HasStrictFDerivAt.isBigO_sub (hf : HasStrictFDerivAt f f' x) :
(fun p : E × E => f p.1 - f p.2) =O[𝓝 (x, x)] fun p : E × E => p.1 - p.2 :=
hf.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_comp _ _)
theorem HasFDerivAtFilter.isBigO_sub (h : HasFDerivAtFilter f f' x L) :
(fun x' => f x' - f x) =O[L] fun x' => x' - x :=
h.isLittleO.isBigO.congr_of_sub.2 (f'.isBigO_sub _ _)
@[fun_prop]
protected theorem HasStrictFDerivAt.hasFDerivAt (hf : HasStrictFDerivAt f f' x) :
HasFDerivAt f f' x :=
.of_isLittleOTVS <| by
simpa only using hf.isLittleOTVS.comp_tendsto (tendsto_id.prodMk_nhds tendsto_const_nhds)
protected theorem HasStrictFDerivAt.differentiableAt (hf : HasStrictFDerivAt f f' x) :
DifferentiableAt 𝕜 f x :=
hf.hasFDerivAt.differentiableAt
/-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ‖f'‖₊`, then `f` is
`K`-Lipschitz in a neighborhood of `x`. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt (hf : HasStrictFDerivAt f f' x)
(K : ℝ≥0) (hK : ‖f'‖₊ < K) : ∃ s ∈ 𝓝 x, LipschitzOnWith K f s := by
have := hf.isLittleO.add_isBigOWith (f'.isBigOWith_comp _ _) hK
simp only [sub_add_cancel, IsBigOWith] at this
rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩
exact
⟨U, Uo.mem_nhds xU, lipschitzOnWith_iff_norm_sub_le.2 fun x hx y hy => hU (mk_mem_prod hx hy)⟩
/-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a
neighborhood of `x`. See also `HasStrictFDerivAt.exists_lipschitzOnWith_of_nnnorm_lt` for a
more precise statement. -/
theorem HasStrictFDerivAt.exists_lipschitzOnWith (hf : HasStrictFDerivAt f f' x) :
∃ K, ∃ s ∈ 𝓝 x, LipschitzOnWith K f s :=
(exists_gt _).imp hf.exists_lipschitzOnWith_of_nnnorm_lt
/-- Directional derivative agrees with `HasFDeriv`. -/
theorem HasFDerivAt.lim (hf : HasFDerivAt f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : Filter α}
(hc : Tendsto (fun n => ‖c n‖) l atTop) :
Tendsto (fun n => c n • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := by
refine (hasFDerivWithinAt_univ.2 hf).lim _ univ_mem hc ?_
intro U hU
refine (eventually_ne_of_tendsto_norm_atTop hc (0 : 𝕜)).mono fun y hy => ?_
convert mem_of_mem_nhds hU
dsimp only
rw [← mul_smul, mul_inv_cancel₀ hy, one_smul]
theorem HasFDerivAt.unique (h₀ : HasFDerivAt f f₀' x) (h₁ : HasFDerivAt f f₁' x) : f₀' = f₁' := by
rw [← hasFDerivWithinAt_univ] at h₀ h₁
exact uniqueDiffWithinAt_univ.eq h₀ h₁
theorem hasFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict'' s h]
theorem hasFDerivWithinAt_inter (h : t ∈ 𝓝 x) :
HasFDerivWithinAt f f' (s ∩ t) x ↔ HasFDerivWithinAt f f' s x := by
simp [HasFDerivWithinAt, nhdsWithin_restrict' s h]
| theorem HasFDerivWithinAt.union (hs : HasFDerivWithinAt f f' s x)
(ht : HasFDerivWithinAt f f' t x) : HasFDerivWithinAt f f' (s ∪ t) x := by
simp only [HasFDerivWithinAt, nhdsWithin_union]
| Mathlib/Analysis/Calculus/FDeriv/Basic.lean | 503 | 505 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finsupp.Single
/-!
# Building finitely supported functions off finsets
This file defines `Finsupp.indicator` to help create finsupps from finsets.
## Main declarations
* `Finsupp.indicator`: Turns a map from a `Finset` into a `Finsupp` from the entire type.
-/
noncomputable section
open Finset Function
variable {ι α : Type*}
namespace Finsupp
variable [Zero α] {s : Finset ι} (f : ∀ i ∈ s, α) {i : ι}
/-- Create an element of `ι →₀ α` from a finset `s` and a function `f` defined on this finset. -/
def indicator (s : Finset ι) (f : ∀ i ∈ s, α) : ι →₀ α where
toFun i :=
haveI := Classical.decEq ι
if H : i ∈ s then f i H else 0
support :=
haveI := Classical.decEq α
({i | f i.1 i.2 ≠ 0} : Finset s).map (Embedding.subtype _)
mem_support_toFun i := by
classical simp
theorem indicator_of_mem (hi : i ∈ s) (f : ∀ i ∈ s, α) : indicator s f i = f i hi :=
@dif_pos _ (id _) hi _ _ _
theorem indicator_of_not_mem (hi : i ∉ s) (f : ∀ i ∈ s, α) : indicator s f i = 0 :=
@dif_neg _ (id _) hi _ _ _
variable (s i)
@[simp]
theorem indicator_apply [DecidableEq ι] : indicator s f i = if hi : i ∈ s then f i hi else 0 := by
simp only [indicator, ne_eq, coe_mk]
congr
theorem indicator_injective : Injective fun f : ∀ i ∈ s, α => indicator s f := by
intro a b h
ext i hi
rw [← indicator_of_mem hi a, ← indicator_of_mem hi b]
exact DFunLike.congr_fun h i
theorem support_indicator_subset : ((indicator s f).support : Set ι) ⊆ s := by
intro i hi
rw [mem_coe, mem_support_iff] at hi
by_contra h
exact hi (indicator_of_not_mem h _)
lemma single_eq_indicator (b : α) : single i b = indicator {i} (fun _ _ => b) := by
| classical
ext j
simp [single_apply, indicator_apply, @eq_comm _ j]
end Finsupp
| Mathlib/Data/Finsupp/Indicator.lean | 66 | 70 |
/-
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.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Order.Monotone.Monovary
/-!
# Monovarying functions and algebraic operations
This file characterises the interaction of ordered algebraic structures with monovariance
of functions.
## See also
`Algebra.Order.Rearrangement` for the n-ary rearrangement inequality
-/
variable {ι α β : Type*}
/-! ### Algebraic operations on monovarying functions -/
section OrderedCommGroup
section
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] [PartialOrder β]
{s : Set ι} {f f₁ f₂ : ι → α} {g : ι → β}
@[to_additive (attr := simp)]
lemma monovaryOn_inv_left : MonovaryOn f⁻¹ g s ↔ AntivaryOn f g s := by
simp [MonovaryOn, AntivaryOn]
@[to_additive (attr := simp)]
lemma antivaryOn_inv_left : AntivaryOn f⁻¹ g s ↔ MonovaryOn f g s := by
simp [MonovaryOn, AntivaryOn]
|
@[to_additive (attr := simp)] lemma monovary_inv_left : Monovary f⁻¹ g ↔ Antivary f g := by
simp [Monovary, Antivary]
| Mathlib/Algebra/Order/Monovary.lean | 39 | 41 |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Order.Atoms
import Mathlib.Order.OrderIsoNat
import Mathlib.Order.RelIso.Set
import Mathlib.Order.SupClosed
import Mathlib.Order.SupIndep
import Mathlib.Order.Zorn
import Mathlib.Data.Finset.Order
import Mathlib.Order.Interval.Set.OrderIso
import Mathlib.Data.Finite.Set
import Mathlib.Tactic.TFAE
/-!
# Compactness properties for complete lattices
For complete lattices, there are numerous equivalent ways to express the fact that the relation `>`
is well-founded. In this file we define three especially-useful characterisations and provide
proofs that they are indeed equivalent to well-foundedness.
## Main definitions
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `CompleteLattice.IsCompactElement`
* `IsCompactlyGenerated`
## Main results
The main result is that the following four conditions are equivalent for a complete lattice:
* `well_founded (>)`
* `CompleteLattice.IsSupClosedCompact`
* `CompleteLattice.IsSupFiniteCompact`
* `∀ k, CompleteLattice.IsCompactElement k`
This is demonstrated by means of the following four lemmas:
* `CompleteLattice.WellFounded.isSupFiniteCompact`
* `CompleteLattice.IsSupFiniteCompact.isSupClosedCompact`
* `CompleteLattice.IsSupClosedCompact.wellFounded`
* `CompleteLattice.isSupFiniteCompact_iff_all_elements_compact`
We also show well-founded lattices are compactly generated
(`CompleteLattice.isCompactlyGenerated_of_wellFounded`).
## References
- [G. Călugăreanu, *Lattice Concepts of Module Theory*][calugareanu]
## Tags
complete lattice, well-founded, compact
-/
open Set
variable {ι : Sort*} {α : Type*} [CompleteLattice α] {f : ι → α}
namespace CompleteLattice
variable (α)
/-- A compactness property for a complete lattice is that any `sup`-closed non-empty subset
contains its `sSup`. -/
def IsSupClosedCompact : Prop :=
∀ (s : Set α) (_ : s.Nonempty), SupClosed s → sSup s ∈ s
/-- A compactness property for a complete lattice is that any subset has a finite subset with the
same `sSup`. -/
def IsSupFiniteCompact : Prop :=
∀ s : Set α, ∃ t : Finset α, ↑t ⊆ s ∧ sSup s = t.sup id
/-- An element `k` of a complete lattice is said to be compact if any set with `sSup`
above `k` has a finite subset with `sSup` above `k`. Such an element is also called
"finite" or "S-compact". -/
def IsCompactElement {α : Type*} [CompleteLattice α] (k : α) :=
∀ s : Set α, k ≤ sSup s → ∃ t : Finset α, ↑t ⊆ s ∧ k ≤ t.sup id
theorem isCompactElement_iff.{u} {α : Type u} [CompleteLattice α] (k : α) :
CompleteLattice.IsCompactElement k ↔
∀ (ι : Type u) (s : ι → α), k ≤ iSup s → ∃ t : Finset ι, k ≤ t.sup s := by
classical
constructor
· intro H ι s hs
obtain ⟨t, ht, ht'⟩ := H (Set.range s) hs
have : ∀ x : t, ∃ i, s i = x := fun x => ht x.prop
choose f hf using this
refine ⟨Finset.univ.image f, ht'.trans ?_⟩
rw [Finset.sup_le_iff]
intro b hb
rw [← show s (f ⟨b, hb⟩) = id b from hf _]
exact Finset.le_sup (Finset.mem_image_of_mem f <| Finset.mem_univ (Subtype.mk b hb))
· intro H s hs
obtain ⟨t, ht⟩ :=
H s Subtype.val
(by
delta iSup
rwa [Subtype.range_coe])
refine ⟨t.image Subtype.val, by simp, ht.trans ?_⟩
rw [Finset.sup_le_iff]
exact fun x hx => @Finset.le_sup _ _ _ _ _ id _ (Finset.mem_image_of_mem Subtype.val hx)
/-- An element `k` is compact if and only if any directed set with `sSup` above
`k` already got above `k` at some point in the set. -/
theorem isCompactElement_iff_le_of_directed_sSup_le (k : α) :
IsCompactElement k ↔
∀ s : Set α, s.Nonempty → DirectedOn (· ≤ ·) s → k ≤ sSup s → ∃ x : α, x ∈ s ∧ k ≤ x := by
classical
constructor
· intro hk s hne hdir hsup
obtain ⟨t, ht⟩ := hk s hsup
-- certainly every element of t is below something in s, since ↑t ⊆ s.
have t_below_s : ∀ x ∈ t, ∃ y ∈ s, x ≤ y := fun x hxt => ⟨x, ht.left hxt, le_rfl⟩
obtain ⟨x, ⟨hxs, hsupx⟩⟩ := Finset.sup_le_of_le_directed s hne hdir t t_below_s
exact ⟨x, ⟨hxs, le_trans ht.right hsupx⟩⟩
· intro hk s hsup
-- Consider the set of finite joins of elements of the (plain) set s.
let S : Set α := { x | ∃ t : Finset α, ↑t ⊆ s ∧ x = t.sup id }
-- S is directed, nonempty, and still has sup above k.
have dir_US : DirectedOn (· ≤ ·) S := by
rintro x ⟨c, hc⟩ y ⟨d, hd⟩
use x ⊔ y
constructor
· use c ∪ d
constructor
· simp only [hc.left, hd.left, Set.union_subset_iff, Finset.coe_union, and_self_iff]
· simp only [hc.right, hd.right, Finset.sup_union]
simp only [and_self_iff, le_sup_left, le_sup_right]
have sup_S : sSup s ≤ sSup S := by
apply sSup_le_sSup
intro x hx
use {x}
simpa only [and_true, id, Finset.coe_singleton, eq_self_iff_true,
Finset.sup_singleton, Set.singleton_subset_iff]
have Sne : S.Nonempty := by
suffices ⊥ ∈ S from Set.nonempty_of_mem this
use ∅
simp only [Set.empty_subset, Finset.coe_empty, Finset.sup_empty, eq_self_iff_true,
and_self_iff]
-- Now apply the defn of compact and finish.
obtain ⟨j, ⟨hjS, hjk⟩⟩ := hk S Sne dir_US (le_trans hsup sup_S)
obtain ⟨t, ⟨htS, htsup⟩⟩ := hjS
use t
exact ⟨htS, by rwa [← htsup]⟩
theorem IsCompactElement.exists_finset_of_le_iSup {k : α} (hk : IsCompactElement k) {ι : Type*}
(f : ι → α) (h : k ≤ ⨆ i, f i) : ∃ s : Finset ι, k ≤ ⨆ i ∈ s, f i := by
classical
let g : Finset ι → α := fun s => ⨆ i ∈ s, f i
have h1 : DirectedOn (· ≤ ·) (Set.range g) := by
rintro - ⟨s, rfl⟩ - ⟨t, rfl⟩
exact
⟨g (s ∪ t), ⟨s ∪ t, rfl⟩, iSup_le_iSup_of_subset Finset.subset_union_left,
iSup_le_iSup_of_subset Finset.subset_union_right⟩
have h2 : k ≤ sSup (Set.range g) :=
h.trans
(iSup_le fun i =>
le_sSup_of_le ⟨{i}, rfl⟩
(le_iSup_of_le i (le_iSup_of_le (Finset.mem_singleton_self i) le_rfl)))
obtain ⟨-, ⟨s, rfl⟩, hs⟩ :=
(isCompactElement_iff_le_of_directed_sSup_le α k).mp hk (Set.range g) (Set.range_nonempty g)
h1 h2
exact ⟨s, hs⟩
/-- A compact element `k` has the property that any directed set lying strictly below `k` has
its `sSup` strictly below `k`. -/
theorem IsCompactElement.directed_sSup_lt_of_lt {α : Type*} [CompleteLattice α] {k : α}
(hk : IsCompactElement k) {s : Set α} (hemp : s.Nonempty) (hdir : DirectedOn (· ≤ ·) s)
(hbelow : ∀ x ∈ s, x < k) : sSup s < k := by
rw [isCompactElement_iff_le_of_directed_sSup_le] at hk
by_contra h
have sSup' : sSup s ≤ k := sSup_le s k fun s hs => (hbelow s hs).le
replace sSup : sSup s = k := eq_iff_le_not_lt.mpr ⟨sSup', h⟩
obtain ⟨x, hxs, hkx⟩ := hk s hemp hdir sSup.symm.le
obtain hxk := hbelow x hxs
exact hxk.ne (hxk.le.antisymm hkx)
theorem isCompactElement_finsetSup {α β : Type*} [CompleteLattice α] {f : β → α} (s : Finset β)
(h : ∀ x ∈ s, IsCompactElement (f x)) : IsCompactElement (s.sup f) := by
classical
rw [isCompactElement_iff_le_of_directed_sSup_le]
intro d hemp hdir hsup
rw [← Function.id_comp f]
rw [← Finset.sup_image]
apply Finset.sup_le_of_le_directed d hemp hdir
rintro x hx
obtain ⟨p, ⟨hps, rfl⟩⟩ := Finset.mem_image.mp hx
specialize h p hps
rw [isCompactElement_iff_le_of_directed_sSup_le] at h
specialize h d hemp hdir (le_trans (Finset.le_sup hps) hsup)
simpa only [exists_prop]
theorem WellFoundedGT.isSupFiniteCompact [WellFoundedGT α] :
IsSupFiniteCompact α := fun s => by
let S := { x | ∃ t : Finset α, ↑t ⊆ s ∧ t.sup id = x }
obtain ⟨m, ⟨t, ⟨ht₁, rfl⟩⟩, hm⟩ := wellFounded_gt.has_min S ⟨⊥, ∅, by simp⟩
refine ⟨t, ht₁, (sSup_le _ _ fun y hy => ?_).antisymm ?_⟩
· classical
rw [eq_of_le_of_not_lt (Finset.sup_mono (t.subset_insert y))
(hm _ ⟨insert y t, by simp [Set.insert_subset_iff, hy, ht₁]⟩)]
simp
· rw [Finset.sup_id_eq_sSup]
exact sSup_le_sSup ht₁
theorem IsSupFiniteCompact.isSupClosedCompact (h : IsSupFiniteCompact α) :
IsSupClosedCompact α := by
intro s hne hsc; obtain ⟨t, ht₁, ht₂⟩ := h s; clear h
rcases t.eq_empty_or_nonempty with h | h
· subst h
rw [Finset.sup_empty] at ht₂
rw [ht₂]
simp [eq_singleton_bot_of_sSup_eq_bot_of_nonempty ht₂ hne]
· rw [ht₂]
exact hsc.finsetSup_mem h ht₁
| theorem IsSupClosedCompact.wellFoundedGT (h : IsSupClosedCompact α) :
WellFoundedGT α where
wf := by
refine RelEmbedding.wellFounded_iff_no_descending_seq.mpr ⟨fun a => ?_⟩
suffices sSup (Set.range a) ∈ Set.range a by
obtain ⟨n, hn⟩ := Set.mem_range.mp this
have h' : sSup (Set.range a) < a (n + 1) := by
change _ > _
simp [← hn, a.map_rel_iff]
apply lt_irrefl (a (n + 1))
| Mathlib/Order/CompactlyGenerated/Basic.lean | 215 | 224 |
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.ContDiff.Operations
import Mathlib.Analysis.Calculus.UniformLimitsDeriv
import Mathlib.Topology.Algebra.InfiniteSum.Module
import Mathlib.Analysis.NormedSpace.FunctionSeries
/-!
# Smoothness of series
We show that series of functions are differentiable, or smooth, when each individual
function in the series is and additionally suitable uniform summable bounds are satisfied.
More specifically,
* `differentiable_tsum` ensures that a series of differentiable functions is differentiable.
* `contDiff_tsum` ensures that a series of `C^n` functions is `C^n`.
We also give versions of these statements which are localized to a set.
-/
open Set Metric TopologicalSpace Function Asymptotics Filter
open scoped Topology NNReal
variable {α β 𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜]
[NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [CompleteSpace F] {u : α → ℝ}
/-! ### Differentiability -/
variable [NormedSpace 𝕜 F]
variable {f : α → E → F} {f' : α → E → E →L[𝕜] F} {g : α → 𝕜 → F} {g' : α → 𝕜 → F} {v : ℕ → α → ℝ}
{s : Set E} {t : Set 𝕜} {x₀ x : E} {y₀ y : 𝕜} {N : ℕ∞}
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
derivatives, then the series converges everywhere on the set. -/
theorem summable_of_summable_hasFDerivAt_of_isPreconnected (hu : Summable u) (hs : IsOpen s)
(h's : IsPreconnected s) (hf : ∀ n x, x ∈ s → HasFDerivAt (f n) (f' n x) x)
| (hf' : ∀ n x, x ∈ s → ‖f' n x‖ ≤ u n) (hx₀ : x₀ ∈ s) (hf0 : Summable (f · x₀))
(hx : x ∈ s) : Summable fun n => f n x := by
haveI := Classical.decEq α
rw [summable_iff_cauchySeq_finset] at hf0 ⊢
have A : UniformCauchySeqOn (fun t : Finset α => fun x => ∑ i ∈ t, f' i x) atTop s :=
(tendstoUniformlyOn_tsum hu hf').uniformCauchySeqOn
refine cauchy_map_of_uniformCauchySeqOn_fderiv (f := fun t x ↦ ∑ i ∈ t, f i x)
hs h's A (fun t y hy => ?_) hx₀ hx hf0
exact HasFDerivAt.sum fun i _ => hf i y hy
/-- Consider a series of functions `∑' n, f n x` on a preconnected open set. If the series converges
at a point, and all functions in the series are differentiable with a summable bound on the
| Mathlib/Analysis/Calculus/SmoothSeries.lean | 43 | 54 |
/-
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. -/
| Mathlib/MeasureTheory/Measure/Regular.lean | 832 | 840 |
/-
Copyright (c) 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri
-/
import Mathlib.Geometry.Manifold.Algebra.Monoid
/-!
# Lie groups
A Lie group is a group that is also a `C^n` manifold, in which the group operations of
multiplication and inversion are `C^n` maps. Regularity of the group multiplication means that
multiplication is a `C^n` mapping of the product manifold `G` × `G` into `G`.
Note that, since a manifold here is not second-countable and Hausdorff a Lie group here is not
guaranteed to be second-countable (even though it can be proved it is Hausdorff). Note also that Lie
groups here are not necessarily finite dimensional.
## Main definitions
* `LieAddGroup I G` : a Lie additive group where `G` is a manifold on the model with corners `I`.
* `LieGroup I G` : a Lie multiplicative group where `G` is a manifold on the model with corners `I`.
* `ContMDiffInv₀`: typeclass for `C^n` manifolds with `0` and `Inv` such that inversion is `C^n`
map at each non-zero point. This includes complete normed fields and (multiplicative) Lie groups.
## Main results
* `ContMDiff.inv`, `ContMDiff.div` and variants: point-wise inversion and division of maps `M → G`
is `C^n`.
* `ContMDiff.inv₀` and variants: if `ContMDiffInv₀ I n N`, point-wise inversion of `C^n`
maps `f : M → N` is `C^n` at all points at which `f` doesn't vanish.
* `ContMDiff.div₀` and variants: if also `ContMDiffMul I n N` (i.e., `N` is a Lie group except
possibly for smoothness of inversion at `0`), similar results hold for point-wise division.
* `instNormedSpaceLieAddGroup` : a normed vector space over a nontrivially normed field
is an additive Lie group.
* `Instances/UnitsOfNormedAlgebra` shows that the group of units of a complete normed `𝕜`-algebra
is a multiplicative Lie group.
## Implementation notes
A priori, a Lie group here is a manifold with corners.
The definition of Lie group cannot require `I : ModelWithCorners 𝕜 E E` with the same space as the
model space and as the model vector space, as one might hope, because in the product situation,
the model space is `ModelProd E E'` and the model vector space is `E × E'`, which are not the same,
so the definition does not apply. Hence the definition should be more general, allowing
`I : ModelWithCorners 𝕜 E H`.
-/
noncomputable section
open scoped Manifold ContDiff
-- See note [Design choices about smooth algebraic structures]
/-- An additive Lie group is a group and a `C^n` manifold at the same time in which
the addition and negation operations are `C^n`. -/
class LieAddGroup {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] (I : ModelWithCorners 𝕜 E H)
(n : WithTop ℕ∞) (G : Type*)
[AddGroup G] [TopologicalSpace G] [ChartedSpace H G] : Prop extends ContMDiffAdd I n G where
/-- Negation is smooth in an additive Lie group. -/
contMDiff_neg : ContMDiff I I n fun a : G => -a
-- See note [Design choices about smooth algebraic structures]
/-- A (multiplicative) Lie group is a group and a `C^n` manifold at the same time in which
the multiplication and inverse operations are `C^n`. -/
@[to_additive]
class LieGroup {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] (I : ModelWithCorners 𝕜 E H)
(n : WithTop ℕ∞) (G : Type*)
[Group G] [TopologicalSpace G] [ChartedSpace H G] : Prop extends ContMDiffMul I n G where
/-- Inversion is smooth in a Lie group. -/
contMDiff_inv : ContMDiff I I n fun a : G => a⁻¹
/-!
### Smoothness of inversion, negation, division and subtraction
Let `f : M → G` be a `C^n` function into a Lie group, then `f` is point-wise
invertible with smooth inverse `f`. If `f` and `g` are two such functions, the quotient
`f / g` (i.e., the point-wise product of `f` and the point-wise inverse of `g`) is also `C^n`. -/
section PointwiseDivision
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*}
[NormedAddCommGroup E] [NormedSpace 𝕜 E] {I : ModelWithCorners 𝕜 E H} {n : WithTop ℕ∞} {G : Type*}
[TopologicalSpace G] [ChartedSpace H G] [Group G] {E' : Type*}
[NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H' M]
@[to_additive]
protected theorem LieGroup.of_le {m n : WithTop ℕ∞} (hmn : m ≤ n)
[h : LieGroup I n G] : LieGroup I m G := by
have : ContMDiffMul I m G := ContMDiffMul.of_le hmn
exact ⟨h.contMDiff_inv.of_le hmn⟩
@[to_additive]
instance {a : WithTop ℕ∞} [LieGroup I ∞ G] [h : ENat.LEInfty a] : LieGroup I a G :=
LieGroup.of_le h.out
@[to_additive]
instance {a : WithTop ℕ∞} [LieGroup I ω G] : LieGroup I a G :=
LieGroup.of_le le_top
@[to_additive]
instance [IsTopologicalGroup G] : LieGroup I 0 G := by
constructor
rw [contMDiff_zero_iff]
exact continuous_inv
@[to_additive]
instance [LieGroup I 2 G] : LieGroup I 1 G :=
LieGroup.of_le one_le_two
variable [LieGroup I n G]
section
variable (I n)
/-- In a Lie group, inversion is `C^n`. -/
@[to_additive "In an additive Lie group, inversion is a smooth map."]
theorem contMDiff_inv : ContMDiff I I n fun x : G => x⁻¹ :=
LieGroup.contMDiff_inv
@[deprecated (since := "2024-11-21")] alias smooth_inv := contMDiff_inv
@[deprecated (since := "2024-11-21")] alias smooth_neg := contMDiff_neg
include I n in
/-- A Lie group is a topological group. This is not an instance for technical reasons,
see note [Design choices about smooth algebraic structures]. -/
@[to_additive "An additive Lie group is an additive topological group. This is not an instance for
technical reasons, see note [Design choices about smooth algebraic structures]."]
theorem topologicalGroup_of_lieGroup : IsTopologicalGroup G :=
{ continuousMul_of_contMDiffMul I n with continuous_inv := (contMDiff_inv I n).continuous }
end
@[to_additive]
theorem ContMDiffWithinAt.inv {f : M → G} {s : Set M} {x₀ : M}
(hf : ContMDiffWithinAt I' I n f s x₀) : ContMDiffWithinAt I' I n (fun x => (f x)⁻¹) s x₀ :=
(contMDiff_inv I n).contMDiffAt.contMDiffWithinAt.comp x₀ hf <| Set.mapsTo_univ _ _
@[to_additive]
theorem ContMDiffAt.inv {f : M → G} {x₀ : M} (hf : ContMDiffAt I' I n f x₀) :
ContMDiffAt I' I n (fun x => (f x)⁻¹) x₀ :=
(contMDiff_inv I n).contMDiffAt.comp x₀ hf
@[to_additive]
theorem ContMDiffOn.inv {f : M → G} {s : Set M} (hf : ContMDiffOn I' I n f s) :
ContMDiffOn I' I n (fun x => (f x)⁻¹) s := fun x hx => (hf x hx).inv
@[to_additive]
theorem ContMDiff.inv {f : M → G} (hf : ContMDiff I' I n f) : ContMDiff I' I n fun x => (f x)⁻¹ :=
fun x => (hf x).inv
@[deprecated (since := "2024-11-21")] alias SmoothWithinAt.inv := ContMDiffWithinAt.inv
@[deprecated (since := "2024-11-21")] alias SmoothAt.inv := ContMDiffAt.inv
@[deprecated (since := "2024-11-21")] alias SmoothOn.inv := ContMDiffOn.inv
@[deprecated (since := "2024-11-21")] alias Smooth.inv := ContMDiff.inv
@[deprecated (since := "2024-11-21")] alias SmoothWithinAt.neg := ContMDiffWithinAt.neg
@[deprecated (since := "2024-11-21")] alias SmoothAt.neg := ContMDiffAt.neg
@[deprecated (since := "2024-11-21")] alias SmoothOn.neg := ContMDiffOn.neg
@[deprecated (since := "2024-11-21")] alias Smooth.neg := ContMDiff.neg
@[to_additive]
theorem ContMDiffWithinAt.div {f g : M → G} {s : Set M} {x₀ : M}
(hf : ContMDiffWithinAt I' I n f s x₀) (hg : ContMDiffWithinAt I' I n g s x₀) :
ContMDiffWithinAt I' I n (fun x => f x / g x) s x₀ := by
simp_rw [div_eq_mul_inv]; exact hf.mul hg.inv
| @[to_additive]
theorem ContMDiffAt.div {f g : M → G} {x₀ : M} (hf : ContMDiffAt I' I n f x₀)
(hg : ContMDiffAt I' I n g x₀) : ContMDiffAt I' I n (fun x => f x / g x) x₀ := by
simp_rw [div_eq_mul_inv]; exact hf.mul hg.inv
| Mathlib/Geometry/Manifold/Algebra/LieGroup.lean | 171 | 174 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Monoidal.Functor
import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory
/-!
# Monoidal natural transformations
Natural transformations between (lax) monoidal functors must satisfy
an additional compatibility relation with the tensorators:
`F.μ X Y ≫ app (X ⊗ Y) = (app X ⊗ app Y) ≫ G.μ X Y`.
-/
open CategoryTheory
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
open CategoryTheory.Category
open CategoryTheory.Functor
namespace CategoryTheory
open MonoidalCategory
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C]
{D : Type u₂} [Category.{v₂} D] [MonoidalCategory D]
{E : Type u₃} [Category.{v₃} E] [MonoidalCategory E]
{E' : Type u₄} [Category.{v₄} E'] [MonoidalCategory E']
variable {F₁ F₂ F₃ : C ⥤ D} (τ : F₁ ⟶ F₂) [F₁.LaxMonoidal] [F₂.LaxMonoidal] [F₃.LaxMonoidal]
namespace NatTrans
open Functor.LaxMonoidal
/-- A natural transformation between (lax) monoidal functors is monoidal if it satisfies
`ε F ≫ τ.app (𝟙_ C) = ε G` and `μ F X Y ≫ app (X ⊗ Y) = (app X ⊗ app Y) ≫ μ G X Y`. -/
class IsMonoidal : Prop where
unit : ε F₁ ≫ τ.app (𝟙_ C) = ε F₂ := by aesop_cat
tensor (X Y : C) : μ F₁ _ _ ≫ τ.app (X ⊗ Y) = (τ.app X ⊗ τ.app Y) ≫ μ F₂ _ _ := by aesop_cat
namespace IsMonoidal
attribute [reassoc (attr := simp)] unit tensor
instance id : IsMonoidal (𝟙 F₁) where
instance comp (τ' : F₂ ⟶ F₃) [IsMonoidal τ] [IsMonoidal τ'] :
IsMonoidal (τ ≫ τ') where
instance hcomp {G₁ G₂ : D ⥤ E} [G₁.LaxMonoidal] [G₂.LaxMonoidal] (τ' : G₁ ⟶ G₂)
[IsMonoidal τ] [IsMonoidal τ'] : IsMonoidal (τ ◫ τ') where
unit := by
simp only [comp_obj, comp_ε, hcomp_app, assoc, naturality_assoc, unit_assoc, ← map_comp, unit]
tensor X Y := by
simp only [comp_obj, comp_μ, hcomp_app, assoc, naturality_assoc,
tensor_assoc, tensor_comp, μ_natural_assoc]
simp only [← map_comp, tensor]
instance (F : C ⥤ D) [F.LaxMonoidal] : NatTrans.IsMonoidal F.leftUnitor.hom where
instance (F : C ⥤ D) [F.LaxMonoidal] : NatTrans.IsMonoidal F.rightUnitor.hom where
instance (F : C ⥤ D) (G : D ⥤ E) (H : E ⥤ E') [F.LaxMonoidal] [G.LaxMonoidal] [H.LaxMonoidal] :
NatTrans.IsMonoidal (Functor.associator F G H).hom where
unit := by
simp only [comp_obj, comp_ε, assoc, Functor.map_comp, associator_hom_app, comp_id,
Functor.comp_map]
tensor X Y := by
simp only [comp_obj, comp_μ, associator_hom_app, Functor.comp_map, map_comp,
comp_id, tensorHom_id, id_whiskerRight, assoc, id_comp]
end IsMonoidal
instance {F G : C ⥤ D} {H K : C ⥤ E} (α : F ⟶ G) (β : H ⟶ K)
[F.LaxMonoidal] [G.LaxMonoidal] [IsMonoidal α]
[H.LaxMonoidal] [K.LaxMonoidal] [IsMonoidal β] :
IsMonoidal (NatTrans.prod' α β) where
unit := by
ext
· rw [prod_comp_fst, prod'_ε_fst, prod'_ε_fst, prod'_app_fst, IsMonoidal.unit]
· rw [prod_comp_snd, prod'_ε_snd, prod'_ε_snd, prod'_app_snd, IsMonoidal.unit]
tensor X Y := by
ext
· simp only [prod_comp_fst, prod'_μ_fst, prod'_app_fst,
prodMonoidal_tensorHom, IsMonoidal.tensor]
· simp only [prod_comp_snd, prod'_μ_snd, prod'_app_snd,
prodMonoidal_tensorHom, IsMonoidal.tensor]
end NatTrans
namespace Iso
variable (e : F₁ ≅ F₂) [NatTrans.IsMonoidal e.hom]
instance : NatTrans.IsMonoidal e.inv where
unit := by rw [← NatTrans.IsMonoidal.unit (τ := e.hom), assoc, hom_inv_id_app, comp_id]
tensor X Y := by
rw [← cancel_mono (e.hom.app (X ⊗ Y)), assoc, assoc, inv_hom_id_app, comp_id,
NatTrans.IsMonoidal.tensor, ← MonoidalCategory.tensor_comp_assoc,
inv_hom_id_app, inv_hom_id_app, tensorHom_id, id_whiskerRight, id_comp]
end Iso
namespace Adjunction
variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G)
open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal
namespace IsMonoidal
variable [F.Monoidal] [G.LaxMonoidal] [adj.IsMonoidal]
instance : NatTrans.IsMonoidal adj.unit where
unit := by
dsimp
rw [id_comp, ← unit_app_unit_comp_map_η adj, assoc, Monoidal.map_η_ε]
dsimp
rw [comp_id]
tensor X Y := by
dsimp
rw [← unit_app_tensor_comp_map_δ_assoc, id_comp, Monoidal.map_δ_μ, comp_id]
instance : NatTrans.IsMonoidal adj.counit where
unit := by
dsimp
rw [assoc, map_ε_comp_counit_app_unit adj, ε_η]
tensor X Y := by
dsimp
rw [assoc, map_μ_comp_counit_app_tensor, μ_δ_assoc, comp_id]
end IsMonoidal
namespace Equivalence
variable (e : C ≌ D) [e.functor.Monoidal] [e.inverse.Monoidal] [e.IsMonoidal]
instance : NatTrans.IsMonoidal e.unit :=
inferInstanceAs (NatTrans.IsMonoidal e.toAdjunction.unit)
instance : NatTrans.IsMonoidal e.counit :=
inferInstanceAs (NatTrans.IsMonoidal e.toAdjunction.counit)
end Equivalence
end Adjunction
namespace LaxMonoidalFunctor
/-- The type of monoidal natural transformations between (bundled) lax monoidal functors. -/
structure Hom (F G : LaxMonoidalFunctor C D) where
/-- the natural transformation between the underlying functors -/
hom : F.toFunctor ⟶ G.toFunctor
isMonoidal : NatTrans.IsMonoidal hom := by infer_instance
attribute [instance] Hom.isMonoidal
instance : Category (LaxMonoidalFunctor C D) where
Hom := Hom
comp α β := ⟨α.1 ≫ β.1, by have := α.2; have := β.2; infer_instance⟩
id _ := ⟨𝟙 _, inferInstance⟩
@[simp]
| lemma id_hom (F : LaxMonoidalFunctor C D) : Hom.hom (𝟙 F) = 𝟙 _ := rfl
| Mathlib/CategoryTheory/Monoidal/NaturalTransformation.lean | 171 | 172 |
/-
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]
| Mathlib/Data/List/Infix.lean | 239 | 244 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.FieldTheory.Finiteness
import Mathlib.LinearAlgebra.AffineSpace.Basis
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
/-!
# Finite-dimensional subspaces of affine spaces.
This file provides a few results relating to finite-dimensional
subspaces of affine spaces.
## Main definitions
* `Collinear` defines collinear sets of points as those that span a
subspace of dimension at most 1.
-/
noncomputable section
open Affine
open scoped Finset
section AffineSpace'
variable (k : Type*) {V : Type*} {P : Type*}
variable {ι : Type*}
open AffineSubspace Module
variable [DivisionRing k] [AddCommGroup V] [Module k V] [AffineSpace V P]
/-- The `vectorSpan` of a finite set is finite-dimensional. -/
theorem finiteDimensional_vectorSpan_of_finite {s : Set P} (h : Set.Finite s) :
FiniteDimensional k (vectorSpan k s) :=
.span_of_finite k <| h.vsub h
/-- The vector span of a singleton is finite-dimensional. -/
instance finiteDimensional_vectorSpan_singleton (p : P) :
FiniteDimensional k (vectorSpan k {p}) :=
finiteDimensional_vectorSpan_of_finite _ (Set.finite_singleton p)
/-- The `vectorSpan` of a family indexed by a `Fintype` is
finite-dimensional. -/
instance finiteDimensional_vectorSpan_range [Finite ι] (p : ι → P) :
FiniteDimensional k (vectorSpan k (Set.range p)) :=
finiteDimensional_vectorSpan_of_finite k (Set.finite_range _)
/-- The `vectorSpan` of a subset of a family indexed by a `Fintype`
is finite-dimensional. -/
instance finiteDimensional_vectorSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) :
FiniteDimensional k (vectorSpan k (p '' s)) :=
finiteDimensional_vectorSpan_of_finite k (Set.toFinite _)
/-- The direction of the affine span of a finite set is
finite-dimensional. -/
theorem finiteDimensional_direction_affineSpan_of_finite {s : Set P} (h : Set.Finite s) :
FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ finiteDimensional_vectorSpan_of_finite k h
/-- The direction of the affine span of a singleton is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_singleton (p : P) :
FiniteDimensional k (affineSpan k {p}).direction := by
rw [direction_affineSpan]
infer_instance
/-- The direction of the affine span of a family indexed by a
`Fintype` is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_range [Finite ι] (p : ι → P) :
FiniteDimensional k (affineSpan k (Set.range p)).direction :=
finiteDimensional_direction_affineSpan_of_finite k (Set.finite_range _)
/-- The direction of the affine span of a subset of a family indexed
by a `Fintype` is finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_image_of_finite [Finite ι] (p : ι → P) (s : Set ι) :
FiniteDimensional k (affineSpan k (p '' s)).direction :=
finiteDimensional_direction_affineSpan_of_finite k (Set.toFinite _)
/-- An affine-independent family of points in a finite-dimensional affine space is finite. -/
theorem finite_of_fin_dim_affineIndependent [FiniteDimensional k V] {p : ι → P}
(hi : AffineIndependent k p) : Finite ι := by
nontriviality ι; inhabit ι
rw [affineIndependent_iff_linearIndependent_vsub k p default] at hi
letI : IsNoetherian k V := IsNoetherian.iff_fg.2 inferInstance
exact
(Set.finite_singleton default).finite_of_compl (Set.finite_coe_iff.1 hi.finite_of_isNoetherian)
/-- An affine-independent subset of a finite-dimensional affine space is finite. -/
theorem finite_set_of_fin_dim_affineIndependent [FiniteDimensional k V] {s : Set ι} {f : s → P}
(hi : AffineIndependent k f) : s.Finite :=
@Set.toFinite _ s (finite_of_fin_dim_affineIndependent k hi)
variable {k}
/-- The `vectorSpan` of a finite subset of an affinely independent
family has dimension one less than its cardinality. -/
theorem AffineIndependent.finrank_vectorSpan_image_finset [DecidableEq P]
{p : ι → P} (hi : AffineIndependent k p) {s : Finset ι} {n : ℕ} (hc : #s = n + 1) :
finrank k (vectorSpan k (s.image p : Set P)) = n := by
classical
have hi' := hi.range.mono (Set.image_subset_range p ↑s)
have hc' : #(s.image p) = n + 1 := by rwa [s.card_image_of_injective hi.injective]
have hn : (s.image p).Nonempty := by simp [hc', ← Finset.card_pos]
rcases hn with ⟨p₁, hp₁⟩
have hp₁' : p₁ ∈ p '' s := by simpa using hp₁
rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁', ← Finset.coe_singleton,
← Finset.coe_image, ← Finset.coe_sdiff, Finset.sdiff_singleton_eq_erase, ← Finset.coe_image]
at hi'
have hc : #(((s.image p).erase p₁).image (· -ᵥ p₁)) = n := by
rw [Finset.card_image_of_injective _ (vsub_left_injective _), Finset.card_erase_of_mem hp₁]
exact Nat.pred_eq_of_eq_succ hc'
rwa [vectorSpan_eq_span_vsub_finset_right_ne k hp₁, finrank_span_finset_eq_card, hc]
/-- The `vectorSpan` of a finite affinely independent family has
dimension one less than its cardinality. -/
theorem AffineIndependent.finrank_vectorSpan [Fintype ι] {p : ι → P} (hi : AffineIndependent k p)
{n : ℕ} (hc : Fintype.card ι = n + 1) : finrank k (vectorSpan k (Set.range p)) = n := by
classical
rw [← Finset.card_univ] at hc
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image]
exact hi.finrank_vectorSpan_image_finset hc
/-- The `vectorSpan` of a finite affinely independent family has dimension one less than its
cardinality. -/
lemma AffineIndependent.finrank_vectorSpan_add_one [Fintype ι] [Nonempty ι] {p : ι → P}
(hi : AffineIndependent k p) : finrank k (vectorSpan k (Set.range p)) + 1 = Fintype.card ι := by
rw [hi.finrank_vectorSpan (tsub_add_cancel_of_le _).symm, tsub_add_cancel_of_le] <;>
exact Fintype.card_pos
/-- The `vectorSpan` of a finite affinely independent family whose
cardinality is one more than that of the finite-dimensional space is
`⊤`. -/
theorem AffineIndependent.vectorSpan_eq_top_of_card_eq_finrank_add_one [FiniteDimensional k V]
[Fintype ι] {p : ι → P} (hi : AffineIndependent k p) (hc : Fintype.card ι = finrank k V + 1) :
vectorSpan k (Set.range p) = ⊤ :=
Submodule.eq_top_of_finrank_eq <| hi.finrank_vectorSpan hc
variable (k)
/-- The `vectorSpan` of `n + 1` points in an indexed family has
dimension at most `n`. -/
theorem finrank_vectorSpan_image_finset_le [DecidableEq P] (p : ι → P) (s : Finset ι) {n : ℕ}
(hc : #s = n + 1) : finrank k (vectorSpan k (s.image p : Set P)) ≤ n := by
classical
have hn : (s.image p).Nonempty := by
rw [Finset.image_nonempty, ← Finset.card_pos, hc]
apply Nat.succ_pos
rcases hn with ⟨p₁, hp₁⟩
rw [vectorSpan_eq_span_vsub_finset_right_ne k hp₁]
refine le_trans (finrank_span_finset_le_card (((s.image p).erase p₁).image fun p => p -ᵥ p₁)) ?_
rw [Finset.card_image_of_injective _ (vsub_left_injective p₁), Finset.card_erase_of_mem hp₁,
tsub_le_iff_right, ← hc]
apply Finset.card_image_le
/-- The `vectorSpan` of an indexed family of `n + 1` points has
dimension at most `n`. -/
theorem finrank_vectorSpan_range_le [Fintype ι] (p : ι → P) {n : ℕ} (hc : Fintype.card ι = n + 1) :
finrank k (vectorSpan k (Set.range p)) ≤ n := by
classical
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image]
rw [← Finset.card_univ] at hc
exact finrank_vectorSpan_image_finset_le _ _ _ hc
/-- The `vectorSpan` of an indexed family of `n + 1` points has dimension at most `n`. -/
lemma finrank_vectorSpan_range_add_one_le [Fintype ι] [Nonempty ι] (p : ι → P) :
finrank k (vectorSpan k (Set.range p)) + 1 ≤ Fintype.card ι :=
(le_tsub_iff_right <| Nat.succ_le_iff.2 Fintype.card_pos).1 <| finrank_vectorSpan_range_le _ _
(tsub_add_cancel_of_le <| Nat.succ_le_iff.2 Fintype.card_pos).symm
/-- `n + 1` points are affinely independent if and only if their
`vectorSpan` has dimension `n`. -/
theorem affineIndependent_iff_finrank_vectorSpan_eq [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 1) :
AffineIndependent k p ↔ finrank k (vectorSpan k (Set.range p)) = n := by
classical
have hn : Nonempty ι := by simp [← Fintype.card_pos_iff, hc]
obtain ⟨i₁⟩ := hn
rw [affineIndependent_iff_linearIndependent_vsub _ _ i₁,
linearIndependent_iff_card_eq_finrank_span, eq_comm,
vectorSpan_range_eq_span_range_vsub_right_ne k p i₁, Set.finrank]
rw [← Finset.card_univ] at hc
rw [Fintype.subtype_card]
simp [Finset.filter_ne', Finset.card_erase_of_mem, hc]
/-- `n + 1` points are affinely independent if and only if their
`vectorSpan` has dimension at least `n`. -/
theorem affineIndependent_iff_le_finrank_vectorSpan [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 1) :
AffineIndependent k p ↔ n ≤ finrank k (vectorSpan k (Set.range p)) := by
rw [affineIndependent_iff_finrank_vectorSpan_eq k p hc]
constructor
· rintro rfl
rfl
· exact fun hle => le_antisymm (finrank_vectorSpan_range_le k p hc) hle
/-- `n + 2` points are affinely independent if and only if their
`vectorSpan` does not have dimension at most `n`. -/
theorem affineIndependent_iff_not_finrank_vectorSpan_le [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 2) :
AffineIndependent k p ↔ ¬finrank k (vectorSpan k (Set.range p)) ≤ n := by
rw [affineIndependent_iff_le_finrank_vectorSpan k p hc, ← Nat.lt_iff_add_one_le, lt_iff_not_ge]
/-- `n + 2` points have a `vectorSpan` with dimension at most `n` if
and only if they are not affinely independent. -/
theorem finrank_vectorSpan_le_iff_not_affineIndependent [Fintype ι] (p : ι → P) {n : ℕ}
(hc : Fintype.card ι = n + 2) :
finrank k (vectorSpan k (Set.range p)) ≤ n ↔ ¬AffineIndependent k p :=
(not_iff_comm.1 (affineIndependent_iff_not_finrank_vectorSpan_le k p hc).symm).symm
variable {k}
lemma AffineIndependent.card_le_finrank_succ [Fintype ι] {p : ι → P} (hp : AffineIndependent k p) :
Fintype.card ι ≤ Module.finrank k (vectorSpan k (Set.range p)) + 1 := by
cases isEmpty_or_nonempty ι
· simp [Fintype.card_eq_zero]
rw [← tsub_le_iff_right]
exact (affineIndependent_iff_le_finrank_vectorSpan _ _
(tsub_add_cancel_of_le <| Nat.one_le_iff_ne_zero.2 Fintype.card_ne_zero).symm).1 hp
open Finset in
/-- If an affine independent finset is contained in the affine span of another finset, then its
cardinality is at most the cardinality of that finset. -/
lemma AffineIndependent.card_le_card_of_subset_affineSpan {s t : Finset V}
(hs : AffineIndependent k ((↑) : s → V)) (hst : (s : Set V) ⊆ affineSpan k (t : Set V)) :
#s ≤ #t := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simp
obtain rfl | ht' := t.eq_empty_or_nonempty
· simpa [Set.subset_empty_iff] using hst
have := hs'.to_subtype
have := ht'.to_set.to_subtype
have direction_le := AffineSubspace.direction_le (affineSpan_mono k hst)
rw [AffineSubspace.affineSpan_coe, direction_affineSpan, direction_affineSpan,
← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at direction_le
have finrank_le := add_le_add_right (Submodule.finrank_mono direction_le) 1
-- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}`
erw [hs.finrank_vectorSpan_add_one] at finrank_le
simpa using finrank_le.trans <| finrank_vectorSpan_range_add_one_le _ _
open Finset in
/-- If the affine span of an affine independent finset is strictly contained in the affine span of
another finset, then its cardinality is strictly less than the cardinality of that finset. -/
lemma AffineIndependent.card_lt_card_of_affineSpan_lt_affineSpan {s t : Finset V}
(hs : AffineIndependent k ((↑) : s → V))
(hst : affineSpan k (s : Set V) < affineSpan k (t : Set V)) : #s < #t := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simpa [card_pos] using hst
obtain rfl | ht' := t.eq_empty_or_nonempty
· simp [Set.subset_empty_iff] at hst
have := hs'.to_subtype
have := ht'.to_set.to_subtype
have dir_lt := AffineSubspace.direction_lt_of_nonempty (k := k) hst <| hs'.to_set.affineSpan k
rw [direction_affineSpan, direction_affineSpan,
← @Subtype.range_coe _ (s : Set V), ← @Subtype.range_coe _ (t : Set V)] at dir_lt
have finrank_lt := add_lt_add_right (Submodule.finrank_lt_finrank_of_lt dir_lt) 1
-- We use `erw` to elide the difference between `↥s` and `↥(s : Set V)}`
erw [hs.finrank_vectorSpan_add_one] at finrank_lt
simpa using finrank_lt.trans_le <| finrank_vectorSpan_range_add_one_le _ _
/-- If the `vectorSpan` of a finite subset of an affinely independent
family lies in a submodule with dimension one less than its
cardinality, it equals that submodule. -/
theorem AffineIndependent.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one
[DecidableEq P] {p : ι → P}
(hi : AffineIndependent k p) {s : Finset ι} {sm : Submodule k V} [FiniteDimensional k sm]
(hle : vectorSpan k (s.image p : Set P) ≤ sm) (hc : #s = finrank k sm + 1) :
vectorSpan k (s.image p : Set P) = sm :=
Submodule.eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan_image_finset hc
/-- If the `vectorSpan` of a finite affinely independent
family lies in a submodule with dimension one less than its
cardinality, it equals that submodule. -/
theorem AffineIndependent.vectorSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P}
(hi : AffineIndependent k p) {sm : Submodule k V} [FiniteDimensional k sm]
(hle : vectorSpan k (Set.range p) ≤ sm) (hc : Fintype.card ι = finrank k sm + 1) :
vectorSpan k (Set.range p) = sm :=
Submodule.eq_of_le_of_finrank_eq hle <| hi.finrank_vectorSpan hc
/-- If the `affineSpan` of a finite subset of an affinely independent
family lies in an affine subspace whose direction has dimension one
less than its cardinality, it equals that subspace. -/
theorem AffineIndependent.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one
[DecidableEq P] {p : ι → P}
(hi : AffineIndependent k p) {s : Finset ι} {sp : AffineSubspace k P}
[FiniteDimensional k sp.direction] (hle : affineSpan k (s.image p : Set P) ≤ sp)
(hc : #s = finrank k sp.direction + 1) : affineSpan k (s.image p : Set P) = sp := by
have hn : s.Nonempty := by
rw [← Finset.card_pos, hc]
apply Nat.succ_pos
refine eq_of_direction_eq_of_nonempty_of_le ?_ ((hn.image p).to_set.affineSpan k) hle
have hd := direction_le hle
rw [direction_affineSpan] at hd ⊢
exact hi.vectorSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hd hc
/-- If the `affineSpan` of a finite affinely independent family lies
in an affine subspace whose direction has dimension one less than its
cardinality, it equals that subspace. -/
theorem AffineIndependent.affineSpan_eq_of_le_of_card_eq_finrank_add_one [Fintype ι] {p : ι → P}
(hi : AffineIndependent k p) {sp : AffineSubspace k P} [FiniteDimensional k sp.direction]
(hle : affineSpan k (Set.range p) ≤ sp) (hc : Fintype.card ι = finrank k sp.direction + 1) :
affineSpan k (Set.range p) = sp := by
classical
rw [← Finset.card_univ] at hc
rw [← Set.image_univ, ← Finset.coe_univ, ← Finset.coe_image] at hle ⊢
exact hi.affineSpan_image_finset_eq_of_le_of_card_eq_finrank_add_one hle hc
/-- The `affineSpan` of a finite affinely independent family is `⊤` iff the
family's cardinality is one more than that of the finite-dimensional space. -/
theorem AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one [FiniteDimensional k V]
[Fintype ι] {p : ι → P} (hi : AffineIndependent k p) :
affineSpan k (Set.range p) = ⊤ ↔ Fintype.card ι = finrank k V + 1 := by
constructor
· intro h_tot
let n := Fintype.card ι - 1
have hn : Fintype.card ι = n + 1 :=
(Nat.succ_pred_eq_of_pos (card_pos_of_affineSpan_eq_top k V P h_tot)).symm
rw [hn, ← finrank_top, ← (vectorSpan_eq_top_of_affineSpan_eq_top k V P) h_tot,
← hi.finrank_vectorSpan hn]
· intro hc
rw [← finrank_top, ← direction_top k V P] at hc
exact hi.affineSpan_eq_of_le_of_card_eq_finrank_add_one le_top hc
theorem Affine.Simplex.span_eq_top [FiniteDimensional k V] {n : ℕ} (T : Affine.Simplex k V n)
(hrank : finrank k V = n) : affineSpan k (Set.range T.points) = ⊤ := by
rw [AffineIndependent.affineSpan_eq_top_iff_card_eq_finrank_add_one T.independent,
Fintype.card_fin, hrank]
/-- The `vectorSpan` of adding a point to a finite-dimensional subspace is finite-dimensional. -/
instance finiteDimensional_vectorSpan_insert (s : AffineSubspace k P)
[FiniteDimensional k s.direction] (p : P) :
FiniteDimensional k (vectorSpan k (insert p (s : Set P))) := by
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan]
rcases (s : Set P).eq_empty_or_nonempty with (hs | ⟨p₀, hp₀⟩)
· rw [coe_eq_bot_iff] at hs
rw [hs, bot_coe, span_empty, bot_coe, direction_affineSpan]
convert finiteDimensional_bot k V <;> simp
· rw [affineSpan_coe, direction_affineSpan_insert hp₀]
infer_instance
/-- The direction of the affine span of adding a point to a finite-dimensional subspace is
finite-dimensional. -/
instance finiteDimensional_direction_affineSpan_insert (s : AffineSubspace k P)
[FiniteDimensional k s.direction] (p : P) :
FiniteDimensional k (affineSpan k (insert p (s : Set P))).direction :=
(direction_affineSpan k (insert p (s : Set P))).symm ▸ finiteDimensional_vectorSpan_insert s p
variable (k)
/-- The `vectorSpan` of adding a point to a set with a finite-dimensional `vectorSpan` is
finite-dimensional. -/
instance finiteDimensional_vectorSpan_insert_set (s : Set P) [FiniteDimensional k (vectorSpan k s)]
(p : P) : FiniteDimensional k (vectorSpan k (insert p s)) := by
haveI : FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ inferInstance
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, direction_affineSpan]
exact finiteDimensional_vectorSpan_insert (affineSpan k s) p
/-- A set of points is collinear if their `vectorSpan` has dimension
at most `1`. -/
def Collinear (s : Set P) : Prop :=
Module.rank k (vectorSpan k s) ≤ 1
/-- The definition of `Collinear`. -/
theorem collinear_iff_rank_le_one (s : Set P) :
Collinear k s ↔ Module.rank k (vectorSpan k s) ≤ 1 := Iff.rfl
variable {k}
/-- A set of points, whose `vectorSpan` is finite-dimensional, is
collinear if and only if their `vectorSpan` has dimension at most
`1`. -/
theorem collinear_iff_finrank_le_one {s : Set P} [FiniteDimensional k (vectorSpan k s)] :
Collinear k s ↔ finrank k (vectorSpan k s) ≤ 1 := by
have h := collinear_iff_rank_le_one k s
rw [← finrank_eq_rank] at h
exact mod_cast h
alias ⟨Collinear.finrank_le_one, _⟩ := collinear_iff_finrank_le_one
/-- A subset of a collinear set is collinear. -/
theorem Collinear.subset {s₁ s₂ : Set P} (hs : s₁ ⊆ s₂) (h : Collinear k s₂) : Collinear k s₁ :=
(Submodule.rank_mono (vectorSpan_mono k hs)).trans h
/-- The `vectorSpan` of collinear points is finite-dimensional. -/
theorem Collinear.finiteDimensional_vectorSpan {s : Set P} (h : Collinear k s) :
FiniteDimensional k (vectorSpan k s) :=
IsNoetherian.iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h Cardinal.one_lt_aleph0))
/-- The direction of the affine span of collinear points is finite-dimensional. -/
theorem Collinear.finiteDimensional_direction_affineSpan {s : Set P} (h : Collinear k s) :
FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ h.finiteDimensional_vectorSpan
variable (k P)
/-- The empty set is collinear. -/
theorem collinear_empty : Collinear k (∅ : Set P) := by
rw [collinear_iff_rank_le_one, vectorSpan_empty]
simp
variable {P}
/-- A single point is collinear. -/
theorem collinear_singleton (p : P) : Collinear k ({p} : Set P) := by
rw [collinear_iff_rank_le_one, vectorSpan_singleton]
simp
variable {k}
/-- Given a point `p₀` in a set of points, that set is collinear if and
only if the points can all be expressed as multiples of the same
vector, added to `p₀`. -/
theorem collinear_iff_of_mem {s : Set P} {p₀ : P} (h : p₀ ∈ s) :
Collinear k s ↔ ∃ v : V, ∀ p ∈ s, ∃ r : k, p = r • v +ᵥ p₀ := by
simp_rw [collinear_iff_rank_le_one, rank_submodule_le_one_iff', Submodule.le_span_singleton_iff]
constructor
· rintro ⟨v₀, hv⟩
use v₀
intro p hp
obtain ⟨r, hr⟩ := hv (p -ᵥ p₀) (vsub_mem_vectorSpan k hp h)
use r
rw [eq_vadd_iff_vsub_eq]
exact hr.symm
· rintro ⟨v, hp₀v⟩
use v
intro w hw
have hs : vectorSpan k s ≤ k ∙ v := by
rw [vectorSpan_eq_span_vsub_set_right k h, Submodule.span_le, Set.subset_def]
intro x hx
rw [SetLike.mem_coe, Submodule.mem_span_singleton]
rw [Set.mem_image] at hx
rcases hx with ⟨p, hp, rfl⟩
rcases hp₀v p hp with ⟨r, rfl⟩
use r
simp
have hw' := SetLike.le_def.1 hs hw
rwa [Submodule.mem_span_singleton] at hw'
/-- A set of points is collinear if and only if they can all be
expressed as multiples of the same vector, added to the same base
point. -/
theorem collinear_iff_exists_forall_eq_smul_vadd (s : Set P) :
Collinear k s ↔ ∃ (p₀ : P) (v : V), ∀ p ∈ s, ∃ r : k, p = r • v +ᵥ p₀ := by
rcases Set.eq_empty_or_nonempty s with (rfl | ⟨⟨p₁, hp₁⟩⟩)
· simp [collinear_empty]
· rw [collinear_iff_of_mem hp₁]
constructor
· exact fun h => ⟨p₁, h⟩
· rintro ⟨p, v, hv⟩
use v
intro p₂ hp₂
rcases hv p₂ hp₂ with ⟨r, rfl⟩
rcases hv p₁ hp₁ with ⟨r₁, rfl⟩
use r - r₁
simp [vadd_vadd, ← add_smul]
variable (k) in
/-- Two points are collinear. -/
theorem collinear_pair (p₁ p₂ : P) : Collinear k ({p₁, p₂} : Set P) := by
rw [collinear_iff_exists_forall_eq_smul_vadd]
use p₁, p₂ -ᵥ p₁
intro p hp
rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hp
rcases hp with hp | hp
· use 0
simp [hp]
· use 1
simp [hp]
/-- Three points are affinely independent if and only if they are not
collinear. -/
theorem affineIndependent_iff_not_collinear {p : Fin 3 → P} :
AffineIndependent k p ↔ ¬Collinear k (Set.range p) := by
rw [collinear_iff_finrank_le_one,
affineIndependent_iff_not_finrank_vectorSpan_le k p (Fintype.card_fin 3)]
/-- Three points are collinear if and only if they are not affinely
independent. -/
theorem collinear_iff_not_affineIndependent {p : Fin 3 → P} :
Collinear k (Set.range p) ↔ ¬AffineIndependent k p := by
rw [collinear_iff_finrank_le_one,
finrank_vectorSpan_le_iff_not_affineIndependent k p (Fintype.card_fin 3)]
/-- Three points are affinely independent if and only if they are not collinear. -/
theorem affineIndependent_iff_not_collinear_set {p₁ p₂ p₃ : P} :
AffineIndependent k ![p₁, p₂, p₃] ↔ ¬Collinear k ({p₁, p₂, p₃} : Set P) := by
rw [affineIndependent_iff_not_collinear]
simp_rw [Matrix.range_cons, Matrix.range_empty, Set.singleton_union, insert_empty_eq]
/-- Three points are collinear if and only if they are not affinely independent. -/
theorem collinear_iff_not_affineIndependent_set {p₁ p₂ p₃ : P} :
Collinear k ({p₁, p₂, p₃} : Set P) ↔ ¬AffineIndependent k ![p₁, p₂, p₃] :=
affineIndependent_iff_not_collinear_set.not_left.symm
/-- Three points are affinely independent if and only if they are not collinear. -/
theorem affineIndependent_iff_not_collinear_of_ne {p : Fin 3 → P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂)
(h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) :
AffineIndependent k p ↔ ¬Collinear k ({p i₁, p i₂, p i₃} : Set P) := by
have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by decide +revert
rw [affineIndependent_iff_not_collinear, ← Set.image_univ, ← Finset.coe_univ, hu,
Finset.coe_insert, Finset.coe_insert, Finset.coe_singleton, Set.image_insert_eq, Set.image_pair]
/-- Three points are collinear if and only if they are not affinely independent. -/
theorem collinear_iff_not_affineIndependent_of_ne {p : Fin 3 → P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂)
(h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) :
Collinear k ({p i₁, p i₂, p i₃} : Set P) ↔ ¬AffineIndependent k p :=
(affineIndependent_iff_not_collinear_of_ne h₁₂ h₁₃ h₂₃).not_left.symm
/-- If three points are not collinear, the first and second are different. -/
theorem ne₁₂_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) :
p₁ ≠ p₂ := by
rintro rfl
simp [collinear_pair] at h
/-- If three points are not collinear, the first and third are different. -/
theorem ne₁₃_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) :
p₁ ≠ p₃ := by
rintro rfl
simp [collinear_pair] at h
/-- If three points are not collinear, the second and third are different. -/
theorem ne₂₃_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear k ({p₁, p₂, p₃} : Set P)) :
p₂ ≠ p₃ := by
rintro rfl
simp [collinear_pair] at h
/-- A point in a collinear set of points lies in the affine span of any two distinct points of
that set. -/
theorem Collinear.mem_affineSpan_of_mem_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ p₃ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₁p₂ : p₁ ≠ p₂) : p₃ ∈ line[k, p₁, p₂] := by
rw [collinear_iff_of_mem hp₁] at h
rcases h with ⟨v, h⟩
rcases h p₂ hp₂ with ⟨r₂, rfl⟩
rcases h p₃ hp₃ with ⟨r₃, rfl⟩
rw [vadd_left_mem_affineSpan_pair]
refine ⟨r₃ / r₂, ?_⟩
have h₂ : r₂ ≠ 0 := by
rintro rfl
simp at hp₁p₂
simp [smul_smul, h₂]
/-- The affine span of any two distinct points of a collinear set of points equals the affine
span of the whole set. -/
theorem Collinear.affineSpan_eq_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ : P} (hp₁ : p₁ ∈ s)
(hp₂ : p₂ ∈ s) (hp₁p₂ : p₁ ≠ p₂) : line[k, p₁, p₂] = affineSpan k s :=
le_antisymm (affineSpan_mono _ (Set.insert_subset_iff.2 ⟨hp₁, Set.singleton_subset_iff.2 hp₂⟩))
(affineSpan_le.2 fun _ hp => h.mem_affineSpan_of_mem_of_ne hp₁ hp₂ hp hp₁p₂)
/-- Given a collinear set of points, and two distinct points `p₂` and `p₃` in it, a point `p₁` is
collinear with the set if and only if it is collinear with `p₂` and `p₃`. -/
theorem Collinear.collinear_insert_iff_of_ne {s : Set P} (h : Collinear k s) {p₁ p₂ p₃ : P}
(hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₃ : p₂ ≠ p₃) :
Collinear k (insert p₁ s) ↔ Collinear k ({p₁, p₂, p₃} : Set P) := by
have hv : vectorSpan k (insert p₁ s) = vectorSpan k ({p₁, p₂, p₃} : Set P) := by
conv_rhs => rw [← direction_affineSpan, ← affineSpan_insert_affineSpan]
rw [← direction_affineSpan, ← affineSpan_insert_affineSpan, h.affineSpan_eq_of_ne hp₂ hp₃ hp₂p₃]
rw [Collinear, Collinear, hv]
/-- Adding a point in the affine span of a set does not change whether that set is collinear. -/
theorem collinear_insert_iff_of_mem_affineSpan {s : Set P} {p : P} (h : p ∈ affineSpan k s) :
Collinear k (insert p s) ↔ Collinear k s := by
rw [Collinear, Collinear, vectorSpan_insert_eq_vectorSpan h]
/-- If a point lies in the affine span of two points, those three points are collinear. -/
theorem collinear_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ : P} (h : p₁ ∈ line[k, p₂, p₃]) :
Collinear k ({p₁, p₂, p₃} : Set P) := by
rw [collinear_insert_iff_of_mem_affineSpan h]
exact collinear_pair _ _ _
/-- If two points lie in the affine span of two points, those four points are collinear. -/
theorem collinear_insert_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ : P} (h₁ : p₁ ∈ line[k, p₃, p₄])
(h₂ : p₂ ∈ line[k, p₃, p₄]) : Collinear k ({p₁, p₂, p₃, p₄} : Set P) := by
rw [collinear_insert_iff_of_mem_affineSpan
((AffineSubspace.le_def' _ _).1 (affineSpan_mono k (Set.subset_insert _ _)) _ h₁),
collinear_insert_iff_of_mem_affineSpan h₂]
exact collinear_pair _ _ _
/-- If three points lie in the affine span of two points, those five points are collinear. -/
theorem collinear_insert_insert_insert_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P}
(h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) :
Collinear k ({p₁, p₂, p₃, p₄, p₅} : Set P) := by
rw [collinear_insert_iff_of_mem_affineSpan
((AffineSubspace.le_def' _ _).1
(affineSpan_mono k ((Set.subset_insert _ _).trans (Set.subset_insert _ _))) _ h₁),
collinear_insert_iff_of_mem_affineSpan
((AffineSubspace.le_def' _ _).1 (affineSpan_mono k (Set.subset_insert _ _)) _ h₂),
collinear_insert_iff_of_mem_affineSpan h₃]
exact collinear_pair _ _ _
/-- If three points lie in the affine span of two points, the first four points are collinear. -/
theorem collinear_insert_insert_insert_left_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P}
(h₁ : p₁ ∈ line[k, p₄, p₅]) (h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) :
Collinear k ({p₁, p₂, p₃, p₄} : Set P) := by
refine (collinear_insert_insert_insert_of_mem_affineSpan_pair h₁ h₂ h₃).subset ?_
repeat apply Set.insert_subset_insert
simp
/-- If three points lie in the affine span of two points, the first three points are collinear. -/
theorem collinear_triple_of_mem_affineSpan_pair {p₁ p₂ p₃ p₄ p₅ : P} (h₁ : p₁ ∈ line[k, p₄, p₅])
(h₂ : p₂ ∈ line[k, p₄, p₅]) (h₃ : p₃ ∈ line[k, p₄, p₅]) :
Collinear k ({p₁, p₂, p₃} : Set P) := by
refine (collinear_insert_insert_insert_left_of_mem_affineSpan_pair h₁ h₂ h₃).subset ?_
simp [Set.insert_subset_insert]
variable (k) in
/-- A set of points is coplanar if their `vectorSpan` has dimension at most `2`. -/
def Coplanar (s : Set P) : Prop :=
Module.rank k (vectorSpan k s) ≤ 2
/-- The `vectorSpan` of coplanar points is finite-dimensional. -/
theorem Coplanar.finiteDimensional_vectorSpan {s : Set P} (h : Coplanar k s) :
FiniteDimensional k (vectorSpan k s) := by
refine IsNoetherian.iff_fg.1 (IsNoetherian.iff_rank_lt_aleph0.2 (lt_of_le_of_lt h ?_))
exact Cardinal.lt_aleph0.2 ⟨2, rfl⟩
/-- The direction of the affine span of coplanar points is finite-dimensional. -/
theorem Coplanar.finiteDimensional_direction_affineSpan {s : Set P} (h : Coplanar k s) :
FiniteDimensional k (affineSpan k s).direction :=
(direction_affineSpan k s).symm ▸ h.finiteDimensional_vectorSpan
/-- A set of points, whose `vectorSpan` is finite-dimensional, is coplanar if and only if their
`vectorSpan` has dimension at most `2`. -/
theorem coplanar_iff_finrank_le_two {s : Set P} [FiniteDimensional k (vectorSpan k s)] :
Coplanar k s ↔ finrank k (vectorSpan k s) ≤ 2 := by
have h : Coplanar k s ↔ Module.rank k (vectorSpan k s) ≤ 2 := Iff.rfl
rw [← finrank_eq_rank] at h
exact mod_cast h
alias ⟨Coplanar.finrank_le_two, _⟩ := coplanar_iff_finrank_le_two
/-- A subset of a coplanar set is coplanar. -/
theorem Coplanar.subset {s₁ s₂ : Set P} (hs : s₁ ⊆ s₂) (h : Coplanar k s₂) : Coplanar k s₁ :=
(Submodule.rank_mono (vectorSpan_mono k hs)).trans h
/-- Collinear points are coplanar. -/
theorem Collinear.coplanar {s : Set P} (h : Collinear k s) : Coplanar k s :=
le_trans h one_le_two
variable (k) (P)
/-- The empty set is coplanar. -/
theorem coplanar_empty : Coplanar k (∅ : Set P) :=
(collinear_empty k P).coplanar
variable {P}
/-- A single point is coplanar. -/
theorem coplanar_singleton (p : P) : Coplanar k ({p} : Set P) :=
(collinear_singleton k p).coplanar
/-- Two points are coplanar. -/
| theorem coplanar_pair (p₁ p₂ : P) : Coplanar k ({p₁, p₂} : Set P) :=
(collinear_pair k p₁ p₂).coplanar
variable {k}
| Mathlib/LinearAlgebra/AffineSpace/FiniteDimensional.lean | 658 | 662 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.Order.Interval.Set.Group
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.Convex.Segment
import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional
import Mathlib.Tactic.FieldSimp
/-!
# Betweenness in affine spaces
This file defines notions of a point in an affine space being between two given points.
## Main definitions
* `affineSegment R x y`: The segment of points weakly between `x` and `y`.
* `Wbtw R x y z`: The point `y` is weakly between `x` and `z`.
* `Sbtw R x y z`: The point `y` is strictly between `x` and `z`.
-/
variable (R : Type*) {V V' P P' : Type*}
open AffineEquiv AffineMap
section OrderedRing
/-- The segment of points weakly between `x` and `y`. When convexity is refactored to support
abstract affine combination spaces, this will no longer need to be a separate definition from
`segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a
refactoring, as distinct from versions involving `+` or `-` in a module. -/
def affineSegment [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V]
[AddTorsor V P] (x y : P) :=
lineMap x y '' Set.Icc (0 : R) 1
variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P]
variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
variable {R} in
@[simp]
theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) :
f '' affineSegment R x y = affineSegment R (f x) (f y) := by
rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap]
rfl
@[simp]
theorem affineSegment_const_vadd_image (x y : P) (v : V) :
(v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) :=
affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y
@[simp]
theorem affineSegment_vadd_const_image (x y : V) (p : P) :
(· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) :=
affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y
@[simp]
theorem affineSegment_const_vsub_image (x y p : P) :
(p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) :=
affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y
@[simp]
theorem affineSegment_vsub_const_image (x y p : P) :
(· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) :=
affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y
variable {R}
@[simp]
theorem mem_const_vadd_affineSegment {x y z : P} (v : V) :
v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image]
@[simp]
theorem mem_vadd_const_affineSegment {x y z : V} (p : P) :
z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image]
@[simp]
theorem mem_const_vsub_affineSegment {x y z : P} (p : P) :
p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image]
@[simp]
theorem mem_vsub_const_affineSegment {x y z : P} (p : P) :
z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image]
variable (R)
section OrderedRing
variable [IsOrderedRing R]
theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by
rw [segment_eq_image_lineMap, affineSegment]
theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by
refine Set.ext fun z => ?_
constructor <;>
· rintro ⟨t, ht, hxy⟩
refine ⟨1 - t, ?_, ?_⟩
· rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero]
· rwa [lineMap_apply_one_sub]
theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y :=
⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩
theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y :=
⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩
@[simp]
theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by
simp_rw [affineSegment, lineMap_same, AffineMap.coe_const, Function.const,
(Set.nonempty_Icc.mpr zero_le_one).image_const]
end OrderedRing
/-- The point `y` is weakly between `x` and `z`. -/
def Wbtw (x y z : P) : Prop :=
y ∈ affineSegment R x z
/-- The point `y` is strictly between `x` and `z`. -/
def Sbtw (x y z : P) : Prop :=
Wbtw R x y z ∧ y ≠ x ∧ y ≠ z
variable {R}
section OrderedRing
variable [IsOrderedRing R]
lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by
rw [Wbtw, affineSegment_eq_segment]
alias ⟨_, Wbtw.mem_segment⟩ := mem_segment_iff_wbtw
lemma Convex.mem_of_wbtw {p₀ p₁ p₂ : V} {s : Set V} (hs : Convex R s) (h₀₁₂ : Wbtw R p₀ p₁ p₂)
(h₀ : p₀ ∈ s) (h₂ : p₂ ∈ s) : p₁ ∈ s := hs.segment_subset h₀ h₂ h₀₁₂.mem_segment
theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by
rw [Wbtw, Wbtw, affineSegment_comm]
alias ⟨Wbtw.symm, _⟩ := wbtw_comm
theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by
rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm]
alias ⟨Sbtw.symm, _⟩ := sbtw_comm
end OrderedRing
lemma AffineSubspace.mem_of_wbtw {s : AffineSubspace R P} {x y z : P} (hxyz : Wbtw R x y z)
(hx : x ∈ s) (hz : z ∈ s) : y ∈ s := by obtain ⟨ε, -, rfl⟩ := hxyz; exact lineMap_mem _ hx hz
theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by
rw [Wbtw, ← affineSegment_image]
exact Set.mem_image_of_mem _ h
theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) :
Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h
theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) :
Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by
simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff]
@[simp]
theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') :
Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by
have : Function.Injective f.toAffineMap := f.injective
-- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing.
apply this.wbtw_map_iff
@[simp]
theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') :
Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by
have : Function.Injective f.toAffineMap := f.injective
-- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing.
apply this.sbtw_map_iff
@[simp]
theorem wbtw_const_vadd_iff {x y z : P} (v : V) :
Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z :=
mem_const_vadd_affineSegment _
@[simp]
theorem wbtw_vadd_const_iff {x y z : V} (p : P) :
Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z :=
mem_vadd_const_affineSegment _
@[simp]
theorem wbtw_const_vsub_iff {x y z : P} (p : P) :
Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z :=
mem_const_vsub_affineSegment _
@[simp]
theorem wbtw_vsub_const_iff {x y z : P} (p : P) :
Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z :=
mem_vsub_const_affineSegment _
@[simp]
theorem sbtw_const_vadd_iff {x y z : P} (v : V) :
Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff,
(AddAction.injective v).ne_iff]
@[simp]
theorem sbtw_vadd_const_iff {x y z : V} (p : P) :
Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff,
(vadd_right_injective p).ne_iff]
@[simp]
theorem sbtw_const_vsub_iff {x y z : P} (p : P) :
Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff,
(vsub_right_injective p).ne_iff]
@[simp]
theorem sbtw_vsub_const_iff {x y z : P} (p : P) :
Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff,
(vsub_left_injective p).ne_iff]
theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z :=
h.1
theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x :=
h.2.1
theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y :=
h.2.1.symm
theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z :=
h.2.2
theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y :=
h.2.2.symm
theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) :
y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by
rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩
rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho)
· exfalso
exact hyx (lineMap_apply_zero _ _)
· exfalso
exact hyz (lineMap_apply_one _ _)
· exact ⟨t, ho, rfl⟩
theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by
rcases h with ⟨r, ⟨-, rfl⟩⟩
exact lineMap_mem_affineSpan_pair _ _ _
variable (R)
section OrderedRing
variable [IsOrderedRing R]
@[simp]
theorem wbtw_self_left (x y : P) : Wbtw R x x y :=
left_mem_affineSegment _ _ _
@[simp]
theorem wbtw_self_right (x y : P) : Wbtw R x y y :=
right_mem_affineSegment _ _ _
@[simp]
theorem wbtw_self_iff {x y : P} : Wbtw R x y x ↔ y = x := by
refine ⟨fun h => ?_, fun h => ?_⟩
· simpa [Wbtw, affineSegment] using h
· rw [h]
exact wbtw_self_left R x x
end OrderedRing
@[simp]
theorem not_sbtw_self_left (x y : P) : ¬Sbtw R x x y :=
fun h => h.ne_left rfl
@[simp]
theorem not_sbtw_self_right (x y : P) : ¬Sbtw R x y y :=
fun h => h.ne_right rfl
variable {R}
variable [IsOrderedRing R]
theorem Wbtw.left_ne_right_of_ne_left {x y z : P} (h : Wbtw R x y z) (hne : y ≠ x) : x ≠ z := by
rintro rfl
rw [wbtw_self_iff] at h
exact hne h
theorem Wbtw.left_ne_right_of_ne_right {x y z : P} (h : Wbtw R x y z) (hne : y ≠ z) : x ≠ z := by
rintro rfl
rw [wbtw_self_iff] at h
exact hne h
theorem Sbtw.left_ne_right {x y z : P} (h : Sbtw R x y z) : x ≠ z :=
h.wbtw.left_ne_right_of_ne_left h.2.1
theorem sbtw_iff_mem_image_Ioo_and_ne [NoZeroSMulDivisors R V] {x y z : P} :
Sbtw R x y z ↔ y ∈ lineMap x z '' Set.Ioo (0 : R) 1 ∧ x ≠ z := by
refine ⟨fun h => ⟨h.mem_image_Ioo, h.left_ne_right⟩, fun h => ?_⟩
rcases h with ⟨⟨t, ht, rfl⟩, hxz⟩
refine ⟨⟨t, Set.mem_Icc_of_Ioo ht, rfl⟩, ?_⟩
rw [lineMap_apply, ← @vsub_ne_zero V, ← @vsub_ne_zero V _ _ _ _ z, vadd_vsub_assoc, vsub_self,
vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z x, ← @neg_one_smul R, ← add_smul, ← sub_eq_add_neg]
simp [smul_ne_zero, sub_eq_zero, ht.1.ne.symm, ht.2.ne, hxz.symm]
variable (R)
@[simp]
theorem not_sbtw_self (x y : P) : ¬Sbtw R x y x :=
fun h => h.left_ne_right rfl
theorem wbtw_swap_left_iff [NoZeroSMulDivisors R V] {x y : P} (z : P) :
Wbtw R x y z ∧ Wbtw R y x z ↔ x = y := by
constructor
· rintro ⟨hxyz, hyxz⟩
rcases hxyz with ⟨ty, hty, rfl⟩
rcases hyxz with ⟨tx, htx, hx⟩
rw [lineMap_apply, lineMap_apply, ← add_vadd] at hx
rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, vsub_vadd_eq_vsub_sub, smul_sub, smul_smul, ← sub_smul,
← add_smul, smul_eq_zero] at hx
rcases hx with (h | h)
· nth_rw 1 [← mul_one tx] at h
rw [← mul_sub, add_eq_zero_iff_neg_eq] at h
have h' : ty = 0 := by
refine le_antisymm ?_ hty.1
rw [← h, Left.neg_nonpos_iff]
exact mul_nonneg htx.1 (sub_nonneg.2 hty.2)
simp [h']
· rw [vsub_eq_zero_iff_eq] at h
rw [h, lineMap_same_apply]
· rintro rfl
exact ⟨wbtw_self_left _ _ _, wbtw_self_left _ _ _⟩
theorem wbtw_swap_right_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} :
Wbtw R x y z ∧ Wbtw R x z y ↔ y = z := by
rw [wbtw_comm, wbtw_comm (z := y), eq_comm]
exact wbtw_swap_left_iff R x
theorem wbtw_rotate_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} :
Wbtw R x y z ∧ Wbtw R z x y ↔ x = y := by rw [wbtw_comm, wbtw_swap_right_iff, eq_comm]
variable {R}
theorem Wbtw.swap_left_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R y x z ↔ x = y := by rw [← wbtw_swap_left_iff R z, and_iff_right h]
theorem Wbtw.swap_right_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R x z y ↔ y = z := by rw [← wbtw_swap_right_iff R x, and_iff_right h]
theorem Wbtw.rotate_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R z x y ↔ x = y := by rw [← wbtw_rotate_iff R x, and_iff_right h]
theorem Sbtw.not_swap_left [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) :
¬Wbtw R y x z := fun hs => h.left_ne (h.wbtw.swap_left_iff.1 hs)
theorem Sbtw.not_swap_right [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) :
¬Wbtw R x z y := fun hs => h.ne_right (h.wbtw.swap_right_iff.1 hs)
theorem Sbtw.not_rotate [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R z x y :=
fun hs => h.left_ne (h.wbtw.rotate_iff.1 hs)
@[simp]
theorem wbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} :
Wbtw R x (lineMap x y r) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := by
by_cases hxy : x = y
· rw [hxy, lineMap_same_apply]
simp
rw [or_iff_right hxy, Wbtw, affineSegment, (lineMap_injective R hxy).mem_set_image]
@[simp]
theorem sbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} :
Sbtw R x (lineMap x y r) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := by
rw [sbtw_iff_mem_image_Ioo_and_ne, and_comm, and_congr_right]
intro hxy
rw [(lineMap_injective R hxy).mem_set_image]
@[simp]
theorem wbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} :
Wbtw R x (r * (y - x) + x) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 :=
wbtw_lineMap_iff
@[simp]
theorem sbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} :
Sbtw R x (r * (y - x) + x) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 :=
sbtw_lineMap_iff
omit [IsOrderedRing R] in
@[simp]
theorem wbtw_zero_one_iff {x : R} : Wbtw R 0 x 1 ↔ x ∈ Set.Icc (0 : R) 1 := by
rw [Wbtw, affineSegment, Set.mem_image]
simp_rw [lineMap_apply_ring]
simp
@[simp]
theorem wbtw_one_zero_iff {x : R} : Wbtw R 1 x 0 ↔ x ∈ Set.Icc (0 : R) 1 := by
rw [wbtw_comm, wbtw_zero_one_iff]
omit [IsOrderedRing R] in
@[simp]
theorem sbtw_zero_one_iff {x : R} : Sbtw R 0 x 1 ↔ x ∈ Set.Ioo (0 : R) 1 := by
rw [Sbtw, wbtw_zero_one_iff, Set.mem_Icc, Set.mem_Ioo]
exact
⟨fun h => ⟨h.1.1.lt_of_ne (Ne.symm h.2.1), h.1.2.lt_of_ne h.2.2⟩, fun h =>
⟨⟨h.1.le, h.2.le⟩, h.1.ne', h.2.ne⟩⟩
@[simp]
theorem sbtw_one_zero_iff {x : R} : Sbtw R 1 x 0 ↔ x ∈ Set.Ioo (0 : R) 1 := by
rw [sbtw_comm, sbtw_zero_one_iff]
theorem Wbtw.trans_left {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R w x z := by
rcases h₁ with ⟨t₁, ht₁, rfl⟩
rcases h₂ with ⟨t₂, ht₂, rfl⟩
refine ⟨t₂ * t₁, ⟨mul_nonneg ht₂.1 ht₁.1, mul_le_one₀ ht₂.2 ht₁.1 ht₁.2⟩, ?_⟩
rw [lineMap_apply, lineMap_apply, lineMap_vsub_left, smul_smul]
theorem Wbtw.trans_right {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w y z := by
rw [wbtw_comm] at *
exact h₁.trans_left h₂
theorem Wbtw.trans_sbtw_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Sbtw R w x y) : Sbtw R w x z := by
refine ⟨h₁.trans_left h₂.wbtw, h₂.ne_left, ?_⟩
rintro rfl
exact h₂.right_ne ((wbtw_swap_right_iff R w).1 ⟨h₁, h₂.wbtw⟩)
theorem Wbtw.trans_sbtw_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
(h₂ : Sbtw R x y z) : Sbtw R w y z := by
rw [wbtw_comm] at *
rw [sbtw_comm] at *
exact h₁.trans_sbtw_left h₂
theorem Sbtw.trans_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z)
(h₂ : Sbtw R w x y) : Sbtw R w x z :=
h₁.wbtw.trans_sbtw_left h₂
theorem Sbtw.trans_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z)
(h₂ : Sbtw R x y z) : Sbtw R w y z :=
h₁.wbtw.trans_sbtw_right h₂
theorem Wbtw.trans_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Wbtw R w x y) (h : y ≠ z) : x ≠ z := by
rintro rfl
exact h (h₁.swap_right_iff.1 h₂)
theorem Wbtw.trans_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
(h₂ : Wbtw R x y z) (h : w ≠ x) : w ≠ y := by
rintro rfl
exact h (h₁.swap_left_iff.1 h₂)
theorem Sbtw.trans_wbtw_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z)
(h₂ : Wbtw R w x y) : x ≠ z :=
h₁.wbtw.trans_left_ne h₂ h₁.ne_right
theorem Sbtw.trans_wbtw_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z)
(h₂ : Wbtw R x y z) : w ≠ y :=
h₁.wbtw.trans_right_ne h₂ h₁.left_ne
theorem Sbtw.affineCombination_of_mem_affineSpan_pair [NoZeroDivisors R] [NoZeroSMulDivisors R V]
{ι : Type*} {p : ι → P} (ha : AffineIndependent R p) {w w₁ w₂ : ι → R} {s : Finset ι}
(hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1)
(h : s.affineCombination R p w ∈
line[R, s.affineCombination R p w₁, s.affineCombination R p w₂])
{i : ι} (his : i ∈ s) (hs : Sbtw R (w₁ i) (w i) (w₂ i)) :
Sbtw R (s.affineCombination R p w₁) (s.affineCombination R p w)
(s.affineCombination R p w₂) := by
rw [affineCombination_mem_affineSpan_pair ha hw hw₁ hw₂] at h
rcases h with ⟨r, hr⟩
rw [hr i his, sbtw_mul_sub_add_iff] at hs
change ∀ i ∈ s, w i = (r • (w₂ - w₁) + w₁) i at hr
rw [s.affineCombination_congr hr fun _ _ => rfl]
rw [← s.weightedVSub_vadd_affineCombination, s.weightedVSub_const_smul,
← s.affineCombination_vsub, ← lineMap_apply, sbtw_lineMap_iff, and_iff_left hs.2,
← @vsub_ne_zero V, s.affineCombination_vsub]
intro hz
have hw₁w₂ : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by
simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, hw₁, hw₂, sub_self]
refine hs.1 ?_
have ha' := ha s (w₁ - w₂) hw₁w₂ hz i his
rwa [Pi.sub_apply, sub_eq_zero] at ha'
end OrderedRing
section StrictOrderedCommRing
variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P]
variable {R}
theorem Wbtw.sameRay_vsub {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ y) := by
rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩
simp_rw [lineMap_apply]
rcases ht0.lt_or_eq with (ht0' | rfl); swap; · simp
rcases ht1.lt_or_eq with (ht1' | rfl); swap; · simp
refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩)
simp only [vadd_vsub, smul_smul, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul]
ring_nf
theorem Wbtw.sameRay_vsub_left {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ x) := by
rcases h with ⟨t, ⟨ht0, _⟩, rfl⟩
simpa [lineMap_apply] using SameRay.sameRay_nonneg_smul_left (z -ᵥ x) ht0
theorem Wbtw.sameRay_vsub_right {x y z : P} (h : Wbtw R x y z) : SameRay R (z -ᵥ x) (z -ᵥ y) := by
rcases h with ⟨t, ⟨_, ht1⟩, rfl⟩
simpa [lineMap_apply, vsub_vadd_eq_vsub_sub, sub_smul] using
SameRay.sameRay_nonneg_smul_right (z -ᵥ x) (sub_nonneg.2 ht1)
end StrictOrderedCommRing
section LinearOrderedRing
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P]
variable {R}
/-- Suppose lines from two vertices of a triangle to interior points of the opposite side meet at
`p`. Then `p` lies in the interior of the first (and by symmetry the other) segment from a
vertex to the point on the opposite side. -/
theorem sbtw_of_sbtw_of_sbtw_of_mem_affineSpan_pair [NoZeroSMulDivisors R V]
{t : Affine.Triangle R P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) {p₁ p₂ p : P}
(h₁ : Sbtw R (t.points i₂) p₁ (t.points i₃)) (h₂ : Sbtw R (t.points i₁) p₂ (t.points i₃))
(h₁' : p ∈ line[R, t.points i₁, p₁]) (h₂' : p ∈ line[R, t.points i₂, p₂]) :
Sbtw R (t.points i₁) p p₁ := by
have h₁₃ : i₁ ≠ i₃ := by
rintro rfl
simp at h₂
have h₂₃ : i₂ ≠ i₃ := by
rintro rfl
simp at h₁
have h3 : ∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃ := by omega
have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by
clear h₁ h₂ h₁' h₂'
decide +revert
have hp : p ∈ affineSpan R (Set.range t.points) := by
have hle : line[R, t.points i₁, p₁] ≤ affineSpan R (Set.range t.points) := by
refine affineSpan_pair_le_of_mem_of_mem (mem_affineSpan R (Set.mem_range_self _)) ?_
have hle : line[R, t.points i₂, t.points i₃] ≤ affineSpan R (Set.range t.points) := by
refine affineSpan_mono R ?_
simp [Set.insert_subset_iff]
rw [AffineSubspace.le_def'] at hle
exact hle _ h₁.wbtw.mem_affineSpan
rw [AffineSubspace.le_def'] at hle
exact hle _ h₁'
have h₁i := h₁.mem_image_Ioo
have h₂i := h₂.mem_image_Ioo
rw [Set.mem_image] at h₁i h₂i
rcases h₁i with ⟨r₁, ⟨hr₁0, hr₁1⟩, rfl⟩
rcases h₂i with ⟨r₂, ⟨hr₂0, hr₂1⟩, rfl⟩
rcases eq_affineCombination_of_mem_affineSpan_of_fintype hp with ⟨w, hw, rfl⟩
have h₁s :=
sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _)
(Finset.mem_univ _) (Finset.mem_univ _) h₁₂ h₁₃ h₂₃ hr₁0 hr₁1 h₁'
have h₂s :=
sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _)
(Finset.mem_univ _) (Finset.mem_univ _) h₁₂.symm h₂₃ h₁₃ hr₂0 hr₂1 h₂'
rw [← Finset.univ.affineCombination_affineCombinationSingleWeights R t.points
(Finset.mem_univ i₁),
← Finset.univ.affineCombination_affineCombinationLineMapWeights t.points (Finset.mem_univ _)
(Finset.mem_univ _)] at h₁' ⊢
refine
Sbtw.affineCombination_of_mem_affineSpan_pair t.independent hw
(Finset.univ.sum_affineCombinationSingleWeights R (Finset.mem_univ _))
(Finset.univ.sum_affineCombinationLineMapWeights (Finset.mem_univ _) (Finset.mem_univ _) _)
h₁' (Finset.mem_univ i₁) ?_
rw [Finset.affineCombinationSingleWeights_apply_self,
Finset.affineCombinationLineMapWeights_apply_of_ne h₁₂ h₁₃, sbtw_one_zero_iff]
have hs : ∀ i : Fin 3, SignType.sign (w i) = SignType.sign (w i₃) := by
intro i
rcases h3 i with (rfl | rfl | rfl)
· exact h₂s
· exact h₁s
· rfl
have hss : SignType.sign (∑ i, w i) = 1 := by simp [hw]
have hs' := sign_sum Finset.univ_nonempty (SignType.sign (w i₃)) fun i _ => hs i
rw [hs'] at hss
simp_rw [hss, sign_eq_one_iff] at hs
refine ⟨hs i₁, ?_⟩
rw [hu] at hw
rw [Finset.sum_insert, Finset.sum_insert, Finset.sum_singleton] at hw
· by_contra hle
rw [not_lt] at hle
exact (hle.trans_lt (lt_add_of_pos_right _ (Left.add_pos (hs i₂) (hs i₃)))).ne' hw
· simpa using h₂₃
· simpa [not_or] using ⟨h₁₂, h₁₃⟩
end LinearOrderedRing
section LinearOrderedField
variable [Field R] [LinearOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P] {x y z : P}
variable {R}
lemma wbtw_iff_of_le {x y z : R} (hxz : x ≤ z) : Wbtw R x y z ↔ x ≤ y ∧ y ≤ z := by
cases hxz.eq_or_lt with
| inl hxz =>
subst hxz
rw [← le_antisymm_iff, wbtw_self_iff, eq_comm]
| inr hxz =>
have hxz' : 0 < z - x := sub_pos.mpr hxz
let r := (y - x) / (z - x)
have hy : y = r * (z - x) + x := by simp [r, hxz'.ne']
simp [hy, wbtw_mul_sub_add_iff, mul_nonneg_iff_of_pos_right hxz', ← le_sub_iff_add_le,
mul_le_iff_le_one_left hxz', hxz.ne]
lemma Wbtw.of_le_of_le {x y z : R} (hxy : x ≤ y) (hyz : y ≤ z) : Wbtw R x y z :=
(wbtw_iff_of_le (hxy.trans hyz)).mpr ⟨hxy, hyz⟩
lemma Sbtw.of_lt_of_lt {x y z : R} (hxy : x < y) (hyz : y < z) : Sbtw R x y z :=
⟨.of_le_of_le hxy.le hyz.le, hxy.ne', hyz.ne⟩
theorem wbtw_iff_left_eq_or_right_mem_image_Ici {x y z : P} :
Wbtw R x y z ↔ x = y ∨ z ∈ lineMap x y '' Set.Ici (1 : R) := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩
rcases hr0.lt_or_eq with (hr0' | rfl)
· rw [Set.mem_image]
refine .inr ⟨r⁻¹, (one_le_inv₀ hr0').2 hr1, ?_⟩
simp only [lineMap_apply, smul_smul, vadd_vsub]
rw [inv_mul_cancel₀ hr0'.ne', one_smul, vsub_vadd]
· simp
· rcases h with (rfl | ⟨r, ⟨hr, rfl⟩⟩)
· exact wbtw_self_left _ _ _
· rw [Set.mem_Ici] at hr
refine ⟨r⁻¹, ⟨inv_nonneg.2 (zero_le_one.trans hr), inv_le_one_of_one_le₀ hr⟩, ?_⟩
simp only [lineMap_apply, smul_smul, vadd_vsub]
rw [inv_mul_cancel₀ (one_pos.trans_le hr).ne', one_smul, vsub_vadd]
theorem Wbtw.right_mem_image_Ici_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) :
z ∈ lineMap x y '' Set.Ici (1 : R) :=
(wbtw_iff_left_eq_or_right_mem_image_Ici.1 h).resolve_left hne
theorem Wbtw.right_mem_affineSpan_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) :
z ∈ line[R, x, y] := by
rcases h.right_mem_image_Ici_of_left_ne hne with ⟨r, ⟨-, rfl⟩⟩
exact lineMap_mem_affineSpan_pair _ _ _
theorem sbtw_iff_left_ne_and_right_mem_image_Ioi {x y z : P} :
Sbtw R x y z ↔ x ≠ y ∧ z ∈ lineMap x y '' Set.Ioi (1 : R) := by
refine ⟨fun h => ⟨h.left_ne, ?_⟩, fun h => ?_⟩
· obtain ⟨r, ⟨hr, rfl⟩⟩ := h.wbtw.right_mem_image_Ici_of_left_ne h.left_ne
rw [Set.mem_Ici] at hr
rcases hr.lt_or_eq with (hrlt | rfl)
· exact Set.mem_image_of_mem _ hrlt
· exfalso
simp at h
· rcases h with ⟨hne, r, hr, rfl⟩
rw [Set.mem_Ioi] at hr
refine
⟨wbtw_iff_left_eq_or_right_mem_image_Ici.2
(Or.inr (Set.mem_image_of_mem _ (Set.mem_of_mem_of_subset hr Set.Ioi_subset_Ici_self))),
hne.symm, ?_⟩
rw [lineMap_apply, ← @vsub_ne_zero V, vsub_vadd_eq_vsub_sub]
nth_rw 1 [← one_smul R (y -ᵥ x)]
rw [← sub_smul, smul_ne_zero_iff, vsub_ne_zero, sub_ne_zero]
exact ⟨hr.ne, hne.symm⟩
theorem Sbtw.right_mem_image_Ioi {x y z : P} (h : Sbtw R x y z) :
z ∈ lineMap x y '' Set.Ioi (1 : R) :=
(sbtw_iff_left_ne_and_right_mem_image_Ioi.1 h).2
theorem Sbtw.right_mem_affineSpan {x y z : P} (h : Sbtw R x y z) : z ∈ line[R, x, y] :=
h.wbtw.right_mem_affineSpan_of_left_ne h.left_ne
theorem wbtw_iff_right_eq_or_left_mem_image_Ici {x y z : P} :
Wbtw R x y z ↔ z = y ∨ x ∈ lineMap z y '' Set.Ici (1 : R) := by
rw [wbtw_comm, wbtw_iff_left_eq_or_right_mem_image_Ici]
theorem Wbtw.left_mem_image_Ici_of_right_ne {x y z : P} (h : Wbtw R x y z) (hne : z ≠ y) :
x ∈ lineMap z y '' Set.Ici (1 : R) :=
h.symm.right_mem_image_Ici_of_left_ne hne
theorem Wbtw.left_mem_affineSpan_of_right_ne {x y z : P} (h : Wbtw R x y z) (hne : z ≠ y) :
x ∈ line[R, z, y] :=
h.symm.right_mem_affineSpan_of_left_ne hne
theorem sbtw_iff_right_ne_and_left_mem_image_Ioi {x y z : P} :
Sbtw R x y z ↔ z ≠ y ∧ x ∈ lineMap z y '' Set.Ioi (1 : R) := by
rw [sbtw_comm, sbtw_iff_left_ne_and_right_mem_image_Ioi]
theorem Sbtw.left_mem_image_Ioi {x y z : P} (h : Sbtw R x y z) :
x ∈ lineMap z y '' Set.Ioi (1 : R) :=
h.symm.right_mem_image_Ioi
theorem Sbtw.left_mem_affineSpan {x y z : P} (h : Sbtw R x y z) : x ∈ line[R, z, y] :=
h.symm.right_mem_affineSpan
omit [IsStrictOrderedRing R] in
lemma AffineSubspace.right_mem_of_wbtw {s : AffineSubspace R P} (hxyz : Wbtw R x y z) (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) : z ∈ s := by
obtain ⟨ε, -, rfl⟩ := hxyz
have hε : ε ≠ 0 := by rintro rfl; simp at hxy
simpa [hε] using lineMap_mem ε⁻¹ hx hy
theorem wbtw_smul_vadd_smul_vadd_of_nonneg_of_le (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁)
(hr₂ : r₁ ≤ r₂) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) := by
refine ⟨r₁ / r₂, ⟨div_nonneg hr₁ (hr₁.trans hr₂), div_le_one_of_le₀ hr₂ (hr₁.trans hr₂)⟩, ?_⟩
by_cases h : r₁ = 0; · simp [h]
simp [lineMap_apply, smul_smul, ((hr₁.lt_of_ne' h).trans_le hr₂).ne.symm]
theorem wbtw_or_wbtw_smul_vadd_of_nonneg (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) :
Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) ∨ Wbtw R x (r₂ • v +ᵥ x) (r₁ • v +ᵥ x) := by
rcases le_total r₁ r₂ with (h | h)
· exact Or.inl (wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x v hr₁ h)
· exact Or.inr (wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x v hr₂ h)
theorem wbtw_smul_vadd_smul_vadd_of_nonpos_of_le (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0)
(hr₂ : r₂ ≤ r₁) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) := by
convert wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x (-v) (Left.nonneg_neg_iff.2 hr₁)
(neg_le_neg_iff.2 hr₂) using 1 <;>
rw [neg_smul_neg]
theorem wbtw_or_wbtw_smul_vadd_of_nonpos (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0) (hr₂ : r₂ ≤ 0) :
Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) ∨ Wbtw R x (r₂ • v +ᵥ x) (r₁ • v +ᵥ x) := by
rcases le_total r₁ r₂ with (h | h)
· exact Or.inr (wbtw_smul_vadd_smul_vadd_of_nonpos_of_le x v hr₂ h)
· exact Or.inl (wbtw_smul_vadd_smul_vadd_of_nonpos_of_le x v hr₁ h)
theorem wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0)
(hr₂ : 0 ≤ r₂) : Wbtw R (r₁ • v +ᵥ x) x (r₂ • v +ᵥ x) := by
convert wbtw_smul_vadd_smul_vadd_of_nonneg_of_le (r₁ • v +ᵥ x) v (Left.nonneg_neg_iff.2 hr₁)
(neg_le_sub_iff_le_add.2 ((le_add_iff_nonneg_left r₁).2 hr₂)) using 1 <;>
simp [sub_smul, ← add_vadd]
theorem wbtw_smul_vadd_smul_vadd_of_nonneg_of_nonpos (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁)
(hr₂ : r₂ ≤ 0) : Wbtw R (r₁ • v +ᵥ x) x (r₂ • v +ᵥ x) := by
rw [wbtw_comm]
exact wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg x v hr₂ hr₁
theorem Wbtw.trans_left_right {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) :
Wbtw R x y z := by
rcases h₁ with ⟨t₁, ht₁, rfl⟩
rcases h₂ with ⟨t₂, ht₂, rfl⟩
refine
⟨(t₁ - t₂ * t₁) / (1 - t₂ * t₁),
⟨div_nonneg (sub_nonneg.2 (mul_le_of_le_one_left ht₁.1 ht₂.2))
(sub_nonneg.2 (mul_le_one₀ ht₂.2 ht₁.1 ht₁.2)), div_le_one_of_le₀
(sub_le_sub_right ht₁.2 _) (sub_nonneg.2 (mul_le_one₀ ht₂.2 ht₁.1 ht₁.2))⟩,
?_⟩
simp only [lineMap_apply, smul_smul, ← add_vadd, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul,
← add_smul, vadd_vsub, vadd_right_cancel_iff, div_mul_eq_mul_div, div_sub_div_same]
nth_rw 1 [← mul_one (t₁ - t₂ * t₁)]
rw [← mul_sub, mul_div_assoc]
by_cases h : 1 - t₂ * t₁ = 0
· rw [sub_eq_zero, eq_comm] at h
rw [h]
suffices t₁ = 1 by simp [this]
exact
eq_of_le_of_not_lt ht₁.2 fun ht₁lt =>
(mul_lt_one_of_nonneg_of_lt_one_right ht₂.2 ht₁.1 ht₁lt).ne h
· rw [div_self h]
ring_nf
theorem Wbtw.trans_right_left {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) :
Wbtw R w x y := by
rw [wbtw_comm] at *
exact h₁.trans_left_right h₂
theorem Sbtw.trans_left_right {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Sbtw R w x y) :
Sbtw R x y z :=
⟨h₁.wbtw.trans_left_right h₂.wbtw, h₂.right_ne, h₁.ne_right⟩
theorem Sbtw.trans_right_left {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Sbtw R x y z) :
Sbtw R w x y :=
⟨h₁.wbtw.trans_right_left h₂.wbtw, h₁.ne_left, h₂.left_ne⟩
omit [IsStrictOrderedRing R] in
theorem Wbtw.collinear {x y z : P} (h : Wbtw R x y z) : Collinear R ({x, y, z} : Set P) := by
rw [collinear_iff_exists_forall_eq_smul_vadd]
refine ⟨x, z -ᵥ x, ?_⟩
intro p hp
simp_rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hp
rcases hp with (rfl | rfl | rfl)
· refine ⟨0, ?_⟩
simp
· rcases h with ⟨t, -, rfl⟩
exact ⟨t, rfl⟩
· refine ⟨1, ?_⟩
simp
theorem Collinear.wbtw_or_wbtw_or_wbtw {x y z : P} (h : Collinear R ({x, y, z} : Set P)) :
Wbtw R x y z ∨ Wbtw R y z x ∨ Wbtw R z x y := by
rw [collinear_iff_of_mem (Set.mem_insert _ _)] at h
rcases h with ⟨v, h⟩
simp_rw [Set.mem_insert_iff, Set.mem_singleton_iff] at h
have hy := h y (Or.inr (Or.inl rfl))
have hz := h z (Or.inr (Or.inr rfl))
rcases hy with ⟨ty, rfl⟩
rcases hz with ⟨tz, rfl⟩
rcases lt_trichotomy ty 0 with (hy0 | rfl | hy0)
· rcases lt_trichotomy tz 0 with (hz0 | rfl | hz0)
· rw [wbtw_comm (z := x)]
rw [← or_assoc]
exact Or.inl (wbtw_or_wbtw_smul_vadd_of_nonpos _ _ hy0.le hz0.le)
· simp
· exact Or.inr (Or.inr (wbtw_smul_vadd_smul_vadd_of_nonneg_of_nonpos _ _ hz0.le hy0.le))
· simp
· rcases lt_trichotomy tz 0 with (hz0 | rfl | hz0)
· refine Or.inr (Or.inr (wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg _ _ hz0.le hy0.le))
· simp
· rw [wbtw_comm (z := x)]
rw [← or_assoc]
exact Or.inl (wbtw_or_wbtw_smul_vadd_of_nonneg _ _ hy0.le hz0.le)
theorem wbtw_iff_sameRay_vsub {x y z : P} : Wbtw R x y z ↔ SameRay R (y -ᵥ x) (z -ᵥ y) := by
refine ⟨Wbtw.sameRay_vsub, fun h => ?_⟩
rcases h with (h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩)
· rw [vsub_eq_zero_iff_eq] at h
simp [h]
· rw [vsub_eq_zero_iff_eq] at h
simp [h]
· refine
⟨r₂ / (r₁ + r₂),
⟨div_nonneg hr₂.le (add_nonneg hr₁.le hr₂.le),
div_le_one_of_le₀ (le_add_of_nonneg_left hr₁.le) (add_nonneg hr₁.le hr₂.le)⟩,
?_⟩
have h' : z = r₂⁻¹ • r₁ • (y -ᵥ x) +ᵥ y := by simp [h, hr₂.ne']
rw [eq_comm]
simp only [lineMap_apply, h', vadd_vsub_assoc, smul_smul, ← add_smul, eq_vadd_iff_vsub_eq,
smul_add]
convert (one_smul R (y -ᵥ x)).symm
field_simp [(add_pos hr₁ hr₂).ne', hr₂.ne']
ring
/-- If `T` is an affine independent family of points,
then any 3 distinct points form a triangle. -/
theorem AffineIndependent.not_wbtw_of_injective {ι} (i j k : ι)
(h : Function.Injective ![i, j, k]) {T : ι → P} (hT : AffineIndependent R T) :
¬ Wbtw R (T i) (T j) (T k) := by
replace hT := hT.comp_embedding ⟨_, h⟩
rw [affineIndependent_iff_not_collinear] at hT
contrapose! hT
simp [Set.range_comp, Set.image_insert_eq, hT.symm.collinear]
variable (R)
theorem wbtw_pointReflection (x y : P) : Wbtw R y x (pointReflection R x y) := by
refine ⟨2⁻¹, ⟨by norm_num, by norm_num⟩, ?_⟩
rw [lineMap_apply, pointReflection_apply, vadd_vsub_assoc, ← two_smul R (x -ᵥ y)]
simp
theorem sbtw_pointReflection_of_ne {x y : P} (h : x ≠ y) : Sbtw R y x (pointReflection R x y) := by
refine ⟨wbtw_pointReflection _ _ _, h, ?_⟩
nth_rw 1 [← pointReflection_self R x]
exact (pointReflection_involutive R x).injective.ne h
theorem wbtw_midpoint (x y : P) : Wbtw R x (midpoint R x y) y := by
convert wbtw_pointReflection R (midpoint R x y) x
rw [pointReflection_midpoint_left]
theorem sbtw_midpoint_of_ne {x y : P} (h : x ≠ y) : Sbtw R x (midpoint R x y) y := by
have h : midpoint R x y ≠ x := by simp [h]
convert sbtw_pointReflection_of_ne R h
rw [pointReflection_midpoint_left]
end LinearOrderedField
| Mathlib/Analysis/Convex/Between.lean | 899 | 902 | |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Localization.Ideal
import Mathlib.RingTheory.Noetherian.Defs
/-!
# Submodules in localizations of commutative rings
## Implementation notes
See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variable {R : Type*} [CommSemiring R] (M : Submonoid R) (S : Type*) [CommSemiring S]
variable [Algebra R S]
namespace IsLocalization
-- This was previously a `hasCoe` instance, but if `S = R` then this will loop.
-- It could be a `hasCoeT` instance, but we keep it explicit here to avoid slowing down
-- the rest of the library.
/-- Map from ideals of `R` to submodules of `S` induced by `f`. -/
def coeSubmodule (I : Ideal R) : Submodule R S :=
Submodule.map (Algebra.linearMap R S) I
theorem mem_coeSubmodule (I : Ideal R) {x : S} :
x ∈ coeSubmodule S I ↔ ∃ y : R, y ∈ I ∧ algebraMap R S y = x :=
Iff.rfl
theorem coeSubmodule_mono {I J : Ideal R} (h : I ≤ J) : coeSubmodule S I ≤ coeSubmodule S J :=
Submodule.map_mono h
@[simp]
theorem coeSubmodule_bot : coeSubmodule S (⊥ : Ideal R) = ⊥ := by
rw [coeSubmodule, Submodule.map_bot]
@[simp]
theorem coeSubmodule_top : coeSubmodule S (⊤ : Ideal R) = 1 := by
rw [coeSubmodule, Submodule.map_top, Submodule.one_eq_range]
@[simp]
theorem coeSubmodule_sup (I J : Ideal R) :
coeSubmodule S (I ⊔ J) = coeSubmodule S I ⊔ coeSubmodule S J :=
Submodule.map_sup _ _ _
@[simp]
theorem coeSubmodule_mul (I J : Ideal R) :
coeSubmodule S (I * J) = coeSubmodule S I * coeSubmodule S J :=
Submodule.map_mul _ _ (Algebra.ofId R S)
theorem coeSubmodule_fg (hS : Function.Injective (algebraMap R S)) (I : Ideal R) :
Submodule.FG (coeSubmodule S I) ↔ Submodule.FG I :=
⟨Submodule.fg_of_fg_map_injective _ hS, Submodule.FG.map _⟩
@[simp]
theorem coeSubmodule_span (s : Set R) :
coeSubmodule S (Ideal.span s) = Submodule.span R (algebraMap R S '' s) := by
rw [IsLocalization.coeSubmodule, Ideal.span, Submodule.map_span]
rfl
theorem coeSubmodule_span_singleton (x : R) :
coeSubmodule S (Ideal.span {x}) = Submodule.span R {(algebraMap R S) x} := by
rw [coeSubmodule_span, Set.image_singleton]
variable [IsLocalization M S]
|
include M in
theorem isNoetherianRing (h : IsNoetherianRing R) : IsNoetherianRing S := by
rw [isNoetherianRing_iff, isNoetherian_iff] at h ⊢
| Mathlib/RingTheory/Localization/Submodule.lean | 75 | 78 |
/-
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
-/
import Mathlib.Data.Stream.Init
import Mathlib.Topology.Algebra.Semigroup
import Mathlib.Topology.StoneCech
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Hindman's theorem on finite sums
We prove Hindman's theorem on finite sums, using idempotent ultrafilters.
Given an infinite sequence `a₀, a₁, a₂, …` of positive integers, the set `FS(a₀, …)` is the set
of positive integers that can be expressed as a finite sum of `aᵢ`'s, without repetition. Hindman's
theorem asserts that whenever the positive integers are finitely colored, there exists a sequence
`a₀, a₁, a₂, …` such that `FS(a₀, …)` is monochromatic. There is also a stronger version, saying
that whenever a set of the form `FS(a₀, …)` is finitely colored, there exists a sequence
`b₀, b₁, b₂, …` such that `FS(b₀, …)` is monochromatic and contained in `FS(a₀, …)`. We prove both
these versions for a general semigroup `M` instead of `ℕ+` since it is no harder, although this
special case implies the general case.
The idea of the proof is to extend the addition `(+) : M → M → M` to addition `(+) : βM → βM → βM`
on the space `βM` of ultrafilters on `M`. One can prove that if `U` is an _idempotent_ ultrafilter,
i.e. `U + U = U`, then any `U`-large subset of `M` contains some set `FS(a₀, …)` (see
`exists_FS_of_large`). And with the help of a general topological argument one can show that any set
of the form `FS(a₀, …)` is `U`-large according to some idempotent ultrafilter `U` (see
`exists_idempotent_ultrafilter_le_FS`). This is enough to prove the theorem since in any finite
partition of a `U`-large set, one of the parts is `U`-large.
## Main results
- `FS_partition_regular`: the strong form of Hindman's theorem
- `exists_FS_of_finite_cover`: the weak form of Hindman's theorem
## Tags
Ramsey theory, ultrafilter
-/
open Filter
/-- Multiplication of ultrafilters given by `∀ᶠ m in U*V, p m ↔ ∀ᶠ m in U, ∀ᶠ m' in V, p (m*m')`. -/
@[to_additive
"Addition of ultrafilters given by `∀ᶠ m in U+V, p m ↔ ∀ᶠ m in U, ∀ᶠ m' in V, p (m+m')`."]
def Ultrafilter.mul {M} [Mul M] : Mul (Ultrafilter M) where mul U V := (· * ·) <$> U <*> V
attribute [local instance] Ultrafilter.mul Ultrafilter.add
/- We could have taken this as the definition of `U * V`, but then we would have to prove that it
defines an ultrafilter. -/
@[to_additive]
theorem Ultrafilter.eventually_mul {M} [Mul M] (U V : Ultrafilter M) (p : M → Prop) :
(∀ᶠ m in ↑(U * V), p m) ↔ ∀ᶠ m in U, ∀ᶠ m' in V, p (m * m') :=
Iff.rfl
/-- Semigroup structure on `Ultrafilter M` induced by a semigroup structure on `M`. -/
@[to_additive
"Additive semigroup structure on `Ultrafilter M` induced by an additive semigroup
structure on `M`."]
def Ultrafilter.semigroup {M} [Semigroup M] : Semigroup (Ultrafilter M) :=
{ Ultrafilter.mul with
mul_assoc := fun U V W =>
Ultrafilter.coe_inj.mp <|
Filter.ext' fun p => by simp [Ultrafilter.eventually_mul, mul_assoc] }
attribute [local instance] Ultrafilter.semigroup Ultrafilter.addSemigroup
-- We don't prove `continuous_mul_right`, because in general it is false!
@[to_additive]
theorem Ultrafilter.continuous_mul_left {M} [Mul M] (V : Ultrafilter M) :
Continuous (· * V) :=
ultrafilterBasis_is_basis.continuous_iff.2 <| Set.forall_mem_range.mpr fun s ↦
ultrafilter_isOpen_basic { m : M | ∀ᶠ m' in V, m * m' ∈ s }
namespace Hindman
/-- `FS a` is the set of finite sums in `a`, i.e. `m ∈ FS a` if `m` is the sum of a nonempty
subsequence of `a`. We give a direct inductive definition instead of talking about subsequences. -/
inductive FS {M} [AddSemigroup M] : Stream' M → Set M
| head (a : Stream' M) : FS a a.head
| tail (a : Stream' M) (m : M) (h : FS a.tail m) : FS a m
| cons (a : Stream' M) (m : M) (h : FS a.tail m) : FS a (a.head + m)
/-- `FP a` is the set of finite products in `a`, i.e. `m ∈ FP a` if `m` is the product of a nonempty
subsequence of `a`. We give a direct inductive definition instead of talking about subsequences. -/
@[to_additive FS]
inductive FP {M} [Semigroup M] : Stream' M → Set M
| head (a : Stream' M) : FP a a.head
| tail (a : Stream' M) (m : M) (h : FP a.tail m) : FP a m
| cons (a : Stream' M) (m : M) (h : FP a.tail m) : FP a (a.head * m)
/-- If `m` and `m'` are finite products in `M`, then so is `m * m'`, provided that `m'` is obtained
from a subsequence of `M` starting sufficiently late. -/
@[to_additive
"If `m` and `m'` are finite sums in `M`, then so is `m + m'`, provided that `m'`
is obtained from a subsequence of `M` starting sufficiently late."]
theorem FP.mul {M} [Semigroup M] {a : Stream' M} {m : M} (hm : m ∈ FP a) :
∃ n, ∀ m' ∈ FP (a.drop n), m * m' ∈ FP a := by
induction hm with
| head a => exact ⟨1, fun m hm => FP.cons a m hm⟩
| tail a m _ ih =>
obtain ⟨n, hn⟩ := ih
use n + 1
intro m' hm'
exact FP.tail _ _ (hn _ hm')
| cons a m _ ih =>
obtain ⟨n, hn⟩ := ih
use n + 1
intro m' hm'
rw [mul_assoc]
exact FP.cons _ _ (hn _ hm')
@[to_additive exists_idempotent_ultrafilter_le_FS]
| theorem exists_idempotent_ultrafilter_le_FP {M} [Semigroup M] (a : Stream' M) :
∃ U : Ultrafilter M, U * U = U ∧ ∀ᶠ m in U, m ∈ FP a := by
let S : Set (Ultrafilter M) := ⋂ n, { U | ∀ᶠ m in U, m ∈ FP (a.drop n) }
have h := exists_idempotent_in_compact_subsemigroup ?_ S ?_ ?_ ?_
· rcases h with ⟨U, hU, U_idem⟩
refine ⟨U, U_idem, ?_⟩
convert Set.mem_iInter.mp hU 0
· exact Ultrafilter.continuous_mul_left
· apply IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed
· intro n U hU
filter_upwards [hU]
rw [← Stream'.drop_drop, ← Stream'.tail_eq_drop]
exact FP.tail _
| Mathlib/Combinatorics/Hindman.lean | 119 | 131 |
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.Convex.Combination
import Mathlib.Analysis.Convex.Extreme
/-!
# Convex independence
This file defines convex independent families of points.
Convex independence is closely related to affine independence. In both cases, no point can be
written as a combination of others. When the combination is affine (that is, any coefficients), this
yields affine independence. When the combination is convex (that is, all coefficients are
nonnegative), then this yields convex independence. In particular, affine independence implies
convex independence.
## Main declarations
* `ConvexIndependent p`: Convex independence of the indexed family `p : ι → E`. Every point of the
family only belongs to convex hulls of sets of the family containing it.
* `convexIndependent_iff_finset`: Carathéodory's theorem allows us to only check finsets to
conclude convex independence.
* `Convex.convexIndependent_extremePoints`: Extreme points of a convex set are convex independent.
## References
* https://en.wikipedia.org/wiki/Convex_position
## TODO
Prove `AffineIndependent.convexIndependent`. This requires some glue between `affineCombination`
and `Finset.centerMass`.
## Tags
independence, convex position
-/
open Affine Finset Function
variable {𝕜 E ι : Type*}
section OrderedSemiring
variable (𝕜) [Semiring 𝕜] [PartialOrder 𝕜] [AddCommGroup E] [Module 𝕜 E]
/-- An indexed family is said to be convex independent if every point only belongs to convex hulls
of sets containing it. -/
def ConvexIndependent (p : ι → E) : Prop :=
∀ (s : Set ι) (x : ι), p x ∈ convexHull 𝕜 (p '' s) → x ∈ s
variable {𝕜}
/-- A family with at most one point is convex independent. -/
theorem Subsingleton.convexIndependent [Subsingleton ι] (p : ι → E) : ConvexIndependent 𝕜 p := by
intro s x hx
have : (convexHull 𝕜 (p '' s)).Nonempty := ⟨p x, hx⟩
rw [convexHull_nonempty_iff, Set.image_nonempty] at this
rwa [Subsingleton.mem_iff_nonempty]
/-- A convex independent family is injective. -/
protected theorem ConvexIndependent.injective {p : ι → E} (hc : ConvexIndependent 𝕜 p) :
Function.Injective p := by
refine fun i j hij => hc {j} i ?_
rw [hij, Set.image_singleton, convexHull_singleton]
exact Set.mem_singleton _
/-- If a family is convex independent, so is any subfamily given by composition of an embedding into
index type with the original family. -/
theorem ConvexIndependent.comp_embedding {ι' : Type*} (f : ι' ↪ ι) {p : ι → E}
(hc : ConvexIndependent 𝕜 p) : ConvexIndependent 𝕜 (p ∘ f) := by
intro s x hx
rw [← f.injective.mem_set_image]
exact hc _ _ (by rwa [Set.image_image])
/-- If a family is convex independent, so is any subfamily indexed by a subtype of the index type.
-/
protected theorem ConvexIndependent.subtype {p : ι → E} (hc : ConvexIndependent 𝕜 p) (s : Set ι) :
ConvexIndependent 𝕜 fun i : s => p i :=
hc.comp_embedding (Embedding.subtype _)
/-- If an indexed family of points is convex independent, so is the corresponding set of points. -/
protected theorem ConvexIndependent.range {p : ι → E} (hc : ConvexIndependent 𝕜 p) :
ConvexIndependent 𝕜 ((↑) : Set.range p → E) := by
let f : Set.range p → ι := fun x => x.property.choose
have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec
let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩
convert hc.comp_embedding fe
ext
rw [Embedding.coeFn_mk, comp_apply, hf]
/-- A subset of a convex independent set of points is convex independent as well. -/
protected theorem ConvexIndependent.mono {s t : Set E} (hc : ConvexIndependent 𝕜 ((↑) : t → E))
(hs : s ⊆ t) : ConvexIndependent 𝕜 ((↑) : s → E) :=
hc.comp_embedding (s.embeddingOfSubset t hs)
/-- The range of an injective indexed family of points is convex independent iff that family is. -/
theorem Function.Injective.convexIndependent_iff_set {p : ι → E} (hi : Function.Injective p) :
ConvexIndependent 𝕜 ((↑) : Set.range p → E) ↔ ConvexIndependent 𝕜 p :=
⟨fun hc =>
hc.comp_embedding
(⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ :
ι ↪ Set.range p),
ConvexIndependent.range⟩
/-- If a family is convex independent, a point in the family is in the convex hull of some of the
points given by a subset of the index type if and only if the point's index is in this subset. -/
@[simp]
protected theorem ConvexIndependent.mem_convexHull_iff {p : ι → E} (hc : ConvexIndependent 𝕜 p)
(s : Set ι) (i : ι) : p i ∈ convexHull 𝕜 (p '' s) ↔ i ∈ s :=
⟨hc _ _, fun hi => subset_convexHull 𝕜 _ (Set.mem_image_of_mem p hi)⟩
/-- If a family is convex independent, a point in the family is not in the convex hull of the other
points. See `convexIndependent_set_iff_not_mem_convexHull_diff` for the `Set` version. -/
theorem convexIndependent_iff_not_mem_convexHull_diff {p : ι → E} :
ConvexIndependent 𝕜 p ↔ ∀ i s, p i ∉ convexHull 𝕜 (p '' (s \ {i})) := by
refine ⟨fun hc i s h => ?_, fun h s i hi => ?_⟩
· rw [hc.mem_convexHull_iff] at h
exact h.2 (Set.mem_singleton _)
· by_contra H
refine h i s ?_
rw [Set.diff_singleton_eq_self H]
exact hi
theorem convexIndependent_set_iff_inter_convexHull_subset {s : Set E} :
ConvexIndependent 𝕜 ((↑) : s → E) ↔ ∀ t, t ⊆ s → s ∩ convexHull 𝕜 t ⊆ t := by
constructor
· rintro hc t h x ⟨hxs, hxt⟩
| refine hc { x | ↑x ∈ t } ⟨x, hxs⟩ ?_
rw [Subtype.coe_image_of_subset h]
exact hxt
· intro hc t x h
rw [← Subtype.coe_injective.mem_set_image]
exact hc (t.image ((↑) : s → E)) (Subtype.coe_image_subset s t) ⟨x.prop, h⟩
/-- If a set is convex independent, a point in the set is not in the convex hull of the other
points. See `convexIndependent_iff_not_mem_convexHull_diff` for the indexed family version. -/
| Mathlib/Analysis/Convex/Independent.lean | 133 | 141 |
/-
Copyright (c) 2019 Rohan Mitta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.Setoid.Basic
import Mathlib.Dynamics.FixedPoints.Topology
import Mathlib.Topology.MetricSpace.Lipschitz
/-!
# Contracting maps
A Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*.
In this file we prove the Banach fixed point theorem, some explicit estimates on the rate
of convergence, and some properties of the map sending a contracting map to its fixed point.
## Main definitions
* `ContractingWith K f` : a Lipschitz continuous self-map with `K < 1`;
* `efixedPoint` : given a contracting map `f` on a complete emetric space and a point `x`
such that `edist x (f x) ≠ ∞`, `efixedPoint f hf x hx` is the unique fixed point of `f`
in `EMetric.ball x ∞`;
* `fixedPoint` : the unique fixed point of a contracting map on a complete nonempty metric space.
## Tags
contracting map, fixed point, Banach fixed point theorem
-/
open NNReal Topology ENNReal Filter Function
variable {α : Type*}
/-- A map is said to be `ContractingWith K`, if `K < 1` and `f` is `LipschitzWith K`. -/
def ContractingWith [EMetricSpace α] (K : ℝ≥0) (f : α → α) :=
K < 1 ∧ LipschitzWith K f
namespace ContractingWith
variable [EMetricSpace α] {K : ℝ≥0} {f : α → α}
open EMetric Set
theorem toLipschitzWith (hf : ContractingWith K f) : LipschitzWith K f := hf.2
theorem one_sub_K_pos' (hf : ContractingWith K f) : (0 : ℝ≥0∞) < 1 - K := by simp [hf.1]
theorem one_sub_K_ne_zero (hf : ContractingWith K f) : (1 : ℝ≥0∞) - K ≠ 0 :=
ne_of_gt hf.one_sub_K_pos'
theorem one_sub_K_ne_top : (1 : ℝ≥0∞) - K ≠ ∞ := by
norm_cast
exact ENNReal.coe_ne_top
theorem edist_inequality (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) :
edist x y ≤ (edist x (f x) + edist y (f y)) / (1 - K) :=
suffices edist x y ≤ edist x (f x) + edist y (f y) + K * edist x y by
rwa [ENNReal.le_div_iff_mul_le (Or.inl hf.one_sub_K_ne_zero) (Or.inl one_sub_K_ne_top),
mul_comm, ENNReal.sub_mul fun _ _ ↦ h, one_mul, tsub_le_iff_right]
calc
edist x y ≤ edist x (f x) + edist (f x) (f y) + edist (f y) y := edist_triangle4 _ _ _ _
_ = edist x (f x) + edist y (f y) + edist (f x) (f y) := by rw [edist_comm y, add_right_comm]
_ ≤ edist x (f x) + edist y (f y) + K * edist x y := add_le_add le_rfl (hf.2 _ _)
theorem edist_le_of_fixedPoint (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞)
(hy : IsFixedPt f y) : edist x y ≤ edist x (f x) / (1 - K) := by
simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h
theorem eq_or_edist_eq_top_of_fixedPoints (hf : ContractingWith K f) {x y} (hx : IsFixedPt f x)
(hy : IsFixedPt f y) : x = y ∨ edist x y = ∞ := by
refine or_iff_not_imp_right.2 fun h ↦ edist_le_zero.1 ?_
simpa only [hx.eq, edist_self, add_zero, ENNReal.zero_div] using hf.edist_le_of_fixedPoint h hy
/-- If a map `f` is `ContractingWith K`, and `s` is a forward-invariant set, then
restriction of `f` to `s` is `ContractingWith K` as well. -/
theorem restrict (hf : ContractingWith K f) {s : Set α} (hs : MapsTo f s s) :
ContractingWith K (hs.restrict f s s) :=
⟨hf.1, fun x y ↦ hf.2 x y⟩
section
variable [CompleteSpace α]
/-- Banach fixed-point theorem, contraction mapping theorem, `EMetricSpace` version.
A contracting map on a complete metric space has a fixed point.
We include more conclusions in this theorem to avoid proving them again later.
The main API for this theorem are the functions `efixedPoint` and `fixedPoint`,
and lemmas about these functions. -/
theorem exists_fixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) :
∃ y, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧
∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) :=
have : CauchySeq fun n ↦ f^[n] x :=
cauchySeq_of_edist_le_geometric K (edist x (f x)) (ENNReal.coe_lt_one_iff.2 hf.1) hx
(hf.toLipschitzWith.edist_iterate_succ_le_geometric x)
let ⟨y, hy⟩ := cauchySeq_tendsto_of_complete this
⟨y, isFixedPt_of_tendsto_iterate hy hf.2.continuous.continuousAt, hy,
edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x))
(hf.toLipschitzWith.edist_iterate_succ_le_geometric x) hy⟩
variable (f) in
-- avoid `efixedPoint _` in pretty printer
/-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map,
and `edist x (f x) ≠ ∞`. Then `efixedPoint` is the unique fixed point of `f`
in `EMetric.ball x ∞`. -/
noncomputable def efixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) : α :=
Classical.choose <| hf.exists_fixedPoint x hx
theorem efixedPoint_isFixedPt (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
IsFixedPt f (efixedPoint f hf x hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint x hx).1
theorem tendsto_iterate_efixedPoint (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint f hf x hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint x hx).2.1
theorem apriori_edist_iterate_efixedPoint_le (hf : ContractingWith K f) {x : α}
(hx : edist x (f x) ≠ ∞) (n : ℕ) :
edist (f^[n] x) (efixedPoint f hf x hx) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) :=
(Classical.choose_spec <| hf.exists_fixedPoint x hx).2.2 n
theorem edist_efixedPoint_le (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint f hf x hx) ≤ edist x (f x) / (1 - K) := by
convert hf.apriori_edist_iterate_efixedPoint_le hx 0
simp only [pow_zero, mul_one]
theorem edist_efixedPoint_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint f hf x hx) < ∞ :=
(hf.edist_efixedPoint_le hx).trans_lt
(ENNReal.mul_ne_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero).lt_top
theorem efixedPoint_eq_of_edist_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞)
{y : α} (hy : edist y (f y) ≠ ∞) (h : edist x y ≠ ∞) :
efixedPoint f hf x hx = efixedPoint f hf y hy := by
refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h')
<;> try apply efixedPoint_isFixedPt
change edistLtTopSetoid _ _
trans x
· apply Setoid.symm'
exact hf.edist_efixedPoint_lt_top hx
trans y
exacts [lt_top_iff_ne_top.2 h, hf.edist_efixedPoint_lt_top hy]
end
/-- Banach fixed-point theorem for maps contracting on a complete subset. -/
theorem exists_fixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
∃ y ∈ s, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧
∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := by
haveI := hsc.completeSpace_coe
rcases hf.exists_fixedPoint ⟨x, hxs⟩ hx with ⟨y, hfy, h_tendsto, hle⟩
refine ⟨y, y.2, Subtype.ext_iff_val.1 hfy, ?_, fun n ↦ ?_⟩
· convert (continuous_subtype_val.tendsto _).comp h_tendsto
simp only [(· ∘ ·), MapsTo.iterate_restrict, MapsTo.val_restrict_apply]
· convert hle n
rw [MapsTo.iterate_restrict]
rfl
variable (f) in
-- avoid `efixedPoint _` in pretty printer
/-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s`
and `x ∈ s` satisfies `edist x (f x) ≠ ∞`, then `efixedPoint'` is the unique fixed point
of the restriction of `f` to `s ∩ EMetric.ball x ∞`. -/
noncomputable def efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) (x : α) (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
α :=
Classical.choose <| hf.exists_fixedPoint' hsc hsf hxs hx
theorem efixedPoint_mem' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
efixedPoint' f hsc hsf hf x hxs hx ∈ s :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).1
theorem efixedPoint_isFixedPt' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
IsFixedPt f (efixedPoint' f hsc hsf hf x hxs hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.1
theorem tendsto_iterate_efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint' f hsc hsf hf x hxs hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.1
theorem apriori_edist_iterate_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞)
(n : ℕ) :
edist (f^[n] x) (efixedPoint' f hsc hsf hf x hxs hx) ≤
edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.2 n
theorem edist_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint' f hsc hsf hf x hxs hx) ≤ edist x (f x) / (1 - K) := by
convert hf.apriori_edist_iterate_efixedPoint_le' hsc hsf hxs hx 0
rw [pow_zero, mul_one]
theorem edist_efixedPoint_lt_top' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint' f hsc hsf hf x hxs hx) < ∞ :=
(hf.edist_efixedPoint_le' hsc hsf hxs hx).trans_lt
(ENNReal.mul_ne_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero).lt_top
/-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`,
and `x ∈ s` is at a finite distance from `y ∈ t`, then the `efixedPoint'` constructed by `x`
is the same as the `efixedPoint'` constructed by `y`.
This lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way
it can be used to prove the desired equality with non-trivial proofs of these facts. -/
theorem efixedPoint_eq_of_edist_lt_top' (hf : ContractingWith K f) {s : Set α} (hsc : IsComplete s)
(hsf : MapsTo f s s) (hfs : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s)
(hx : edist x (f x) ≠ ∞) {t : Set α} (htc : IsComplete t) (htf : MapsTo f t t)
(hft : ContractingWith K <| htf.restrict f t t) {y : α} (hyt : y ∈ t) (hy : edist y (f y) ≠ ∞)
(hxy : edist x y ≠ ∞) :
efixedPoint' f hsc hsf hfs x hxs hx = efixedPoint' f htc htf hft y hyt hy := by
refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h')
<;> try apply efixedPoint_isFixedPt'
change edistLtTopSetoid _ _
trans x
· apply Setoid.symm'
apply edist_efixedPoint_lt_top'
trans y
· exact lt_top_iff_ne_top.2 hxy
· apply edist_efixedPoint_lt_top'
end ContractingWith
namespace ContractingWith
variable [MetricSpace α] {K : ℝ≥0} {f : α → α}
theorem one_sub_K_pos (hf : ContractingWith K f) : (0 : ℝ) < 1 - K :=
sub_pos.2 hf.1
section
variable (hf : ContractingWith K f)
include hf
theorem dist_le_mul (x y : α) : dist (f x) (f y) ≤ K * dist x y :=
hf.toLipschitzWith.dist_le_mul x y
theorem dist_inequality (x y) : dist x y ≤ (dist x (f x) + dist y (f y)) / (1 - K) :=
suffices dist x y ≤ dist x (f x) + dist y (f y) + K * dist x y by
rwa [le_div_iff₀ hf.one_sub_K_pos, mul_comm, _root_.sub_mul, one_mul, sub_le_iff_le_add]
calc
dist x y ≤ dist x (f x) + dist y (f y) + dist (f x) (f y) := dist_triangle4_right _ _ _ _
_ ≤ dist x (f x) + dist y (f y) + K * dist x y := add_le_add_left (hf.dist_le_mul _ _) _
theorem dist_le_of_fixedPoint (x) {y} (hy : IsFixedPt f y) : dist x y ≤ dist x (f x) / (1 - K) := by
simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y
theorem fixedPoint_unique' {x y} (hx : IsFixedPt f x) (hy : IsFixedPt f y) : x = y :=
(hf.eq_or_edist_eq_top_of_fixedPoints hx hy).resolve_right (edist_ne_top _ _)
/-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly
`C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y ≤ C / (1 - K)`. -/
theorem dist_fixedPoint_fixedPoint_of_dist_le' (g : α → α) {x y} (hx : IsFixedPt f x)
(hy : IsFixedPt g y) {C} (hfg : ∀ z, dist (f z) (g z) ≤ C) : dist x y ≤ C / (1 - K) :=
calc
dist x y = dist y x := dist_comm x y
_ ≤ dist y (f y) / (1 - K) := hf.dist_le_of_fixedPoint y hx
_ = dist (f y) (g y) / (1 - K) := by rw [hy.eq, dist_comm]
_ ≤ C / (1 - K) := (div_le_div_iff_of_pos_right hf.one_sub_K_pos).2 (hfg y)
variable [Nonempty α] [CompleteSpace α]
variable (f) in
/-- The unique fixed point of a contracting map in a nonempty complete metric space. -/
noncomputable def fixedPoint : α :=
efixedPoint f hf _ (edist_ne_top (Classical.choice ‹Nonempty α›) _)
/-- The point provided by `ContractingWith.fixedPoint` is actually a fixed point. -/
theorem fixedPoint_isFixedPt : IsFixedPt f (fixedPoint f hf) :=
hf.efixedPoint_isFixedPt _
theorem fixedPoint_unique {x} (hx : IsFixedPt f x) : x = fixedPoint f hf :=
hf.fixedPoint_unique' hx hf.fixedPoint_isFixedPt
theorem dist_fixedPoint_le (x) : dist x (fixedPoint f hf) ≤ dist x (f x) / (1 - K) :=
hf.dist_le_of_fixedPoint x hf.fixedPoint_isFixedPt
/-- Aposteriori estimates on the convergence of iterates to the fixed point. -/
theorem aposteriori_dist_iterate_fixedPoint_le (x n) :
dist (f^[n] x) (fixedPoint f hf) ≤ dist (f^[n] x) (f^[n + 1] x) / (1 - K) := by
rw [iterate_succ']
apply hf.dist_fixedPoint_le
theorem apriori_dist_iterate_fixedPoint_le (x n) :
dist (f^[n] x) (fixedPoint f hf) ≤ dist x (f x) * (K : ℝ) ^ n / (1 - K) :=
calc
_ ≤ dist (f^[n] x) (f^[n + 1] x) / (1 - K) := hf.aposteriori_dist_iterate_fixedPoint_le x n
_ ≤ _ := by
gcongr; exacts [hf.one_sub_K_pos.le, hf.toLipschitzWith.dist_iterate_succ_le_geometric x n]
theorem tendsto_iterate_fixedPoint (x) :
Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| fixedPoint f hf) := by
convert tendsto_iterate_efixedPoint hf (edist_ne_top x _)
refine (fixedPoint_unique _ ?_).symm
apply efixedPoint_isFixedPt
theorem fixedPoint_lipschitz_in_map {g : α → α} (hg : ContractingWith K g) {C}
(hfg : ∀ z, dist (f z) (g z) ≤ C) : dist (fixedPoint f hf) (fixedPoint g hg) ≤ C / (1 - K) :=
hf.dist_fixedPoint_fixedPoint_of_dist_le' g hf.fixedPoint_isFixedPt hg.fixedPoint_isFixedPt hfg
end
variable [Nonempty α] [CompleteSpace α]
/-- If a map `f` has a contracting iterate `f^[n]`, then the fixed point of `f^[n]` is also a fixed
point of `f`. -/
theorem isFixedPt_fixedPoint_iterate {n : ℕ} (hf : ContractingWith K f^[n]) :
IsFixedPt f (hf.fixedPoint f^[n]) := by
set x := hf.fixedPoint f^[n]
have hx : f^[n] x = x := hf.fixedPoint_isFixedPt
have := hf.toLipschitzWith.dist_le_mul x (f x)
rw [← iterate_succ_apply, iterate_succ_apply', hx] at this
contrapose! this
have := dist_pos.2 (Ne.symm this)
simpa only [NNReal.coe_one, one_mul, NNReal.val_eq_coe] using (mul_lt_mul_right this).mpr hf.left
end ContractingWith
| Mathlib/Topology/MetricSpace/Contracting.lean | 338 | 342 | |
/-
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
@[simp] lemma zero_succAbove {n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := rfl
lemma succ_succAbove_zero {n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 := by simp
/-- `succ` commutes with `succAbove`. -/
@[simp] lemma succ_succAbove_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) :
i.succ.succAbove j.succ = (i.succAbove j).succ := by
obtain h | h := i.lt_or_le (succ j)
· rw [succAbove_of_lt_succ _ _ h, succAbove_succ_of_lt _ _ h]
· rwa [succAbove_of_castSucc_lt _ _ h, succAbove_succ_of_le, succ_castSucc]
/-- `castSucc` commutes with `succAbove`. -/
@[simp]
lemma castSucc_succAbove_castSucc {n : ℕ} {i : Fin (n + 1)} {j : Fin n} :
i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc := by
rcases i.le_or_lt (castSucc j) with (h | h)
· rw [succAbove_of_le_castSucc _ _ h, succAbove_castSucc_of_le _ _ h, succ_castSucc]
· rw [succAbove_of_castSucc_lt _ _ h, succAbove_castSucc_of_lt _ _ h]
/-- `pred` commutes with `succAbove`. -/
lemma pred_succAbove_pred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0)
(hk := succAbove_ne_zero ha hb) :
(a.pred ha).succAbove (b.pred hb) = (a.succAbove b).pred hk := by
simp_rw [← succ_inj (b := pred (succAbove a b) hk), ← succ_succAbove_succ, succ_pred]
/-- `castPred` commutes with `succAbove`. -/
lemma castPred_succAbove_castPred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last (n + 1))
(hb : b ≠ last n) (hk := succAbove_ne_last ha hb) :
(a.castPred ha).succAbove (b.castPred hb) = (a.succAbove b).castPred hk := by
simp_rw [← castSucc_inj (b := (a.succAbove b).castPred hk), ← castSucc_succAbove_castSucc,
castSucc_castPred]
lemma one_succAbove_zero {n : ℕ} : (1 : Fin (n + 2)).succAbove 0 = 0 := by
rfl
/-- By moving `succ` to the outside of this expression, we create opportunities for further
simplification using `succAbove_zero` or `succ_succAbove_zero`. -/
@[simp] lemma succ_succAbove_one {n : ℕ} [NeZero n] (i : Fin (n + 1)) :
i.succ.succAbove 1 = (i.succAbove 0).succ := by
rw [← succ_zero_eq_one']; convert succ_succAbove_succ i 0
@[simp] lemma one_succAbove_succ {n : ℕ} (j : Fin n) :
(1 : Fin (n + 2)).succAbove j.succ = j.succ.succ := by
have := succ_succAbove_succ 0 j; rwa [succ_zero_eq_one, zero_succAbove] at this
@[simp] lemma one_succAbove_one {n : ℕ} : (1 : Fin (n + 3)).succAbove 1 = 2 := by
simpa only [succ_zero_eq_one, val_zero, zero_succAbove, succ_one_eq_two]
using succ_succAbove_succ (0 : Fin (n + 2)) (0 : Fin (n + 2))
end SuccAbove
section PredAbove
/-- `predAbove p i` surjects `i : Fin (n+1)` into `Fin n` by subtracting one if `p < i`. -/
def predAbove (p : Fin n) (i : Fin (n + 1)) : Fin n :=
if h : castSucc p < i
then pred i (Fin.ne_zero_of_lt h)
else castPred i (Fin.ne_of_lt <| Fin.lt_of_le_of_lt (Fin.not_lt.1 h) (castSucc_lt_last _))
lemma predAbove_of_le_castSucc (p : Fin n) (i : Fin (n + 1)) (h : i ≤ castSucc p)
(hi := Fin.ne_of_lt <| Fin.lt_of_le_of_lt h <| castSucc_lt_last _) :
p.predAbove i = i.castPred hi := dif_neg <| Fin.not_lt.2 h
lemma predAbove_of_lt_succ (p : Fin n) (i : Fin (n + 1)) (h : i < succ p)
(hi := Fin.ne_last_of_lt h) : p.predAbove i = i.castPred hi :=
predAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h)
lemma predAbove_of_castSucc_lt (p : Fin n) (i : Fin (n + 1)) (h : castSucc p < i)
(hi := Fin.ne_zero_of_lt h) : p.predAbove i = i.pred hi := dif_pos h
lemma predAbove_of_succ_le (p : Fin n) (i : Fin (n + 1)) (h : succ p ≤ i)
(hi := Fin.ne_of_gt <| Fin.lt_of_lt_of_le (succ_pos _) h) :
p.predAbove i = i.pred hi := predAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h)
lemma predAbove_succ_of_lt (p i : Fin n) (h : i < p) (hi := succ_ne_last_of_lt h) :
p.predAbove (succ i) = (i.succ).castPred hi := by
rw [predAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h)]
lemma predAbove_succ_of_le (p i : Fin n) (h : p ≤ i) : p.predAbove (succ i) = i := by
rw [predAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h), pred_succ]
@[simp] lemma predAbove_succ_self (p : Fin n) : p.predAbove (succ p) = p :=
predAbove_succ_of_le _ _ Fin.le_rfl
lemma predAbove_castSucc_of_lt (p i : Fin n) (h : p < i) (hi := castSucc_ne_zero_of_lt h) :
p.predAbove (castSucc i) = i.castSucc.pred hi := by
rw [predAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h)]
lemma predAbove_castSucc_of_le (p i : Fin n) (h : i ≤ p) : p.predAbove (castSucc i) = i := by
rw [predAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.mpr h), castPred_castSucc]
@[simp] lemma predAbove_castSucc_self (p : Fin n) : p.predAbove (castSucc p) = p :=
predAbove_castSucc_of_le _ _ Fin.le_rfl
lemma predAbove_pred_of_lt (p i : Fin (n + 1)) (h : i < p) (hp := Fin.ne_zero_of_lt h)
(hi := Fin.ne_last_of_lt h) : (pred p hp).predAbove i = castPred i hi := by
rw [predAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h)]
lemma predAbove_pred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hp : p ≠ 0)
(hi := Fin.ne_of_gt <| Fin.lt_of_lt_of_le (Fin.pos_iff_ne_zero.2 hp) h) :
(pred p hp).predAbove i = pred i hi := by rw [predAbove_of_succ_le _ _ (succ_pred _ _ ▸ h)]
lemma predAbove_pred_self (p : Fin (n + 1)) (hp : p ≠ 0) : (pred p hp).predAbove p = pred p hp :=
predAbove_pred_of_le _ _ Fin.le_rfl hp
lemma predAbove_castPred_of_lt (p i : Fin (n + 1)) (h : p < i) (hp := Fin.ne_last_of_lt h)
(hi := Fin.ne_zero_of_lt h) : (castPred p hp).predAbove i = pred i hi := by
rw [predAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h)]
lemma predAbove_castPred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hp : p ≠ last n)
(hi := Fin.ne_of_lt <| Fin.lt_of_le_of_lt h <| Fin.lt_last_iff_ne_last.2 hp) :
(castPred p hp).predAbove i = castPred i hi := by
rw [predAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h)]
lemma predAbove_castPred_self (p : Fin (n + 1)) (hp : p ≠ last n) :
(castPred p hp).predAbove p = castPred p hp := predAbove_castPred_of_le _ _ Fin.le_rfl hp
@[simp] lemma predAbove_right_zero [NeZero n] {i : Fin n} : predAbove (i : Fin n) 0 = 0 := by
cases n
· exact i.elim0
· rw [predAbove_of_le_castSucc _ _ (zero_le _), castPred_zero]
lemma predAbove_zero_succ [NeZero n] {i : Fin n} : predAbove 0 i.succ = i := by
rw [predAbove_succ_of_le _ _ (Fin.zero_le' _)]
@[simp]
lemma succ_predAbove_zero [NeZero n] {j : Fin (n + 1)} (h : j ≠ 0) : succ (predAbove 0 j) = j := by
rcases exists_succ_eq_of_ne_zero h with ⟨k, rfl⟩
rw [predAbove_zero_succ]
@[simp] lemma predAbove_zero_of_ne_zero [NeZero n] {i : Fin (n + 1)} (hi : i ≠ 0) :
predAbove 0 i = i.pred hi := by
obtain ⟨y, rfl⟩ := exists_succ_eq.2 hi; exact predAbove_zero_succ
lemma predAbove_zero [NeZero n] {i : Fin (n + 1)} :
predAbove (0 : Fin n) i = if hi : i = 0 then 0 else i.pred hi := by
split_ifs with hi
· rw [hi, predAbove_right_zero]
· rw [predAbove_zero_of_ne_zero hi]
@[simp] lemma predAbove_right_last {i : Fin (n + 1)} : predAbove i (last (n + 1)) = last n := by
rw [predAbove_of_castSucc_lt _ _ (castSucc_lt_last _), pred_last]
lemma predAbove_last_castSucc {i : Fin (n + 1)} : predAbove (last n) (i.castSucc) = i := by
rw [predAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.mpr (le_last _)), castPred_castSucc]
@[simp] lemma predAbove_last_of_ne_last {i : Fin (n + 2)} (hi : i ≠ last (n + 1)) :
predAbove (last n) i = castPred i hi := by
rw [← exists_castSucc_eq] at hi
rcases hi with ⟨y, rfl⟩
exact predAbove_last_castSucc
lemma predAbove_last_apply {i : Fin (n + 2)} :
predAbove (last n) i = if hi : i = last _ then last _ else i.castPred hi := by
split_ifs with hi
· rw [hi, predAbove_right_last]
· rw [predAbove_last_of_ne_last hi]
/-- Sending `Fin (n+1)` to `Fin n` by subtracting one from anything above `p`
then back to `Fin (n+1)` with a gap around `p` is the identity away from `p`. -/
@[simp]
lemma succAbove_predAbove {p : Fin n} {i : Fin (n + 1)} (h : i ≠ castSucc p) :
p.castSucc.succAbove (p.predAbove i) = i := by
obtain h | h := Fin.lt_or_lt_of_ne h
· rw [predAbove_of_le_castSucc _ _ (Fin.le_of_lt h), succAbove_castPred_of_lt _ _ h]
· rw [predAbove_of_castSucc_lt _ _ h, succAbove_pred_of_lt _ _ h]
/-- Sending `Fin (n+1)` to `Fin n` by subtracting one from anything above `p`
then back to `Fin (n+1)` with a gap around `p.succ` is the identity away from `p.succ`. -/
@[simp]
lemma succ_succAbove_predAbove {n : ℕ} {p : Fin n} {i : Fin (n + 1)} (h : i ≠ p.succ) :
p.succ.succAbove (p.predAbove i) = i := by
obtain h | h := Fin.lt_or_lt_of_ne h
· rw [predAbove_of_le_castSucc _ _ (le_castSucc_iff.2 h),
succAbove_castPred_of_lt _ _ h]
· rw [predAbove_of_castSucc_lt _ _ (Fin.lt_of_le_of_lt (p.castSucc_le_succ) h),
succAbove_pred_of_lt _ _ h]
/-- Sending `Fin n` into `Fin (n + 1)` with a gap at `p`
then back to `Fin n` by subtracting one from anything above `p` is the identity. -/
@[simp]
lemma predAbove_succAbove (p : Fin n) (i : Fin n) : p.predAbove ((castSucc p).succAbove i) = i := by
obtain h | h := p.le_or_lt i
· rw [succAbove_castSucc_of_le _ _ h, predAbove_succ_of_le _ _ h]
· rw [succAbove_castSucc_of_lt _ _ h, predAbove_castSucc_of_le _ _ <| Fin.le_of_lt h]
/-- `succ` commutes with `predAbove`. -/
@[simp] lemma succ_predAbove_succ (a : Fin n) (b : Fin (n + 1)) :
a.succ.predAbove b.succ = (a.predAbove b).succ := by
obtain h | h := Fin.le_or_lt (succ a) b
· rw [predAbove_of_castSucc_lt _ _ h, predAbove_succ_of_le _ _ h, succ_pred]
· rw [predAbove_of_lt_succ _ _ h, predAbove_succ_of_lt _ _ h, succ_castPred_eq_castPred_succ]
/-- `castSucc` commutes with `predAbove`. -/
@[simp] lemma castSucc_predAbove_castSucc {n : ℕ} (a : Fin n) (b : Fin (n + 1)) :
a.castSucc.predAbove b.castSucc = (a.predAbove b).castSucc := by
obtain h | h := a.castSucc.lt_or_le b
· rw [predAbove_of_castSucc_lt _ _ h, predAbove_castSucc_of_lt _ _ h,
castSucc_pred_eq_pred_castSucc]
· rw [predAbove_of_le_castSucc _ _ h, predAbove_castSucc_of_le _ _ h, castSucc_castPred]
end PredAbove
section DivMod
/-- Compute `i / n`, where `n` is a `Nat` and inferred the type of `i`. -/
def divNat (i : Fin (m * n)) : Fin m :=
⟨i / n, Nat.div_lt_of_lt_mul <| Nat.mul_comm m n ▸ i.prop⟩
@[simp]
theorem coe_divNat (i : Fin (m * n)) : (i.divNat : ℕ) = i / n :=
rfl
/-- Compute `i % n`, where `n` is a `Nat` and inferred the type of `i`. -/
def modNat (i : Fin (m * n)) : Fin n := ⟨i % n, Nat.mod_lt _ <| Nat.pos_of_mul_pos_left i.pos⟩
@[simp]
theorem coe_modNat (i : Fin (m * n)) : (i.modNat : ℕ) = i % n :=
rfl
theorem modNat_rev (i : Fin (m * n)) : i.rev.modNat = i.modNat.rev := by
ext
have H₁ : i % n + 1 ≤ n := i.modNat.is_lt
have H₂ : i / n < m := i.divNat.is_lt
simp only [coe_modNat, val_rev]
calc
(m * n - (i + 1)) % n = (m * n - ((i / n) * n + i % n + 1)) % n := by rw [Nat.div_add_mod']
_ = ((m - i / n - 1) * n + (n - (i % n + 1))) % n := by
rw [Nat.mul_sub_right_distrib, Nat.one_mul, Nat.sub_add_sub_cancel _ H₁,
Nat.mul_sub_right_distrib, Nat.sub_sub, Nat.add_assoc]
exact Nat.le_mul_of_pos_left _ <| Nat.le_sub_of_add_le' H₂
_ = n - (i % n + 1) := by
rw [Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt]; exact i.modNat.rev.is_lt
end DivMod
section Rec
/-!
### recursion and induction principles
-/
end Rec
open scoped Relator in
theorem liftFun_iff_succ {α : Type*} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} :
((· < ·) ⇒ r) f f ↔ ∀ i : Fin n, r (f (castSucc i)) (f i.succ) := by
constructor
· intro H i
exact H i.castSucc_lt_succ
· refine fun H i => Fin.induction (fun h ↦ ?_) ?_
· simp [le_def] at h
· intro j ihj hij
rw [← le_castSucc_iff] at hij
obtain hij | hij := (le_def.1 hij).eq_or_lt
· obtain rfl := Fin.ext hij
exact H _
· exact _root_.trans (ihj hij) (H j)
section AddGroup
open Nat Int
/-- Negation on `Fin n` -/
instance neg (n : ℕ) : Neg (Fin n) :=
⟨fun a => ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩⟩
theorem neg_def (a : Fin n) : -a = ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩ := rfl
protected theorem coe_neg (a : Fin n) : ((-a : Fin n) : ℕ) = (n - a) % n :=
rfl
theorem eq_zero (n : Fin 1) : n = 0 := Subsingleton.elim _ _
lemma eq_one_of_ne_zero (i : Fin 2) (hi : i ≠ 0) : i = 1 := by fin_omega
@[deprecated (since := "2025-04-27")]
alias eq_one_of_neq_zero := eq_one_of_ne_zero
@[simp]
theorem coe_neg_one : ↑(-1 : Fin (n + 1)) = n := by
cases n
· simp
rw [Fin.coe_neg, Fin.val_one, Nat.add_one_sub_one, Nat.mod_eq_of_lt]
constructor
theorem last_sub (i : Fin (n + 1)) : last n - i = Fin.rev i :=
Fin.ext <| by rw [coe_sub_iff_le.2 i.le_last, val_last, val_rev, Nat.succ_sub_succ_eq_sub]
theorem add_one_le_of_lt {n : ℕ} {a b : Fin (n + 1)} (h : a < b) : a + 1 ≤ b := by
cases n <;> fin_omega
theorem exists_eq_add_of_le {n : ℕ} {a b : Fin n} (h : a ≤ b) : ∃ k ≤ b, b = a + k := by
obtain ⟨k, hk⟩ : ∃ k : ℕ, (b : ℕ) = a + k := Nat.exists_eq_add_of_le h
have hkb : k ≤ b := by omega
refine ⟨⟨k, hkb.trans_lt b.is_lt⟩, hkb, ?_⟩
simp [Fin.ext_iff, Fin.val_add, ← hk, Nat.mod_eq_of_lt b.is_lt]
theorem exists_eq_add_of_lt {n : ℕ} {a b : Fin (n + 1)} (h : a < b) :
∃ k < b, k + 1 ≤ b ∧ b = a + k + 1 := by
cases n
· omega
obtain ⟨k, hk⟩ : ∃ k : ℕ, (b : ℕ) = a + k + 1 := Nat.exists_eq_add_of_lt h
have hkb : k < b := by omega
refine ⟨⟨k, hkb.trans b.is_lt⟩, hkb, by fin_omega, ?_⟩
simp [Fin.ext_iff, Fin.val_add, ← hk, Nat.mod_eq_of_lt b.is_lt]
lemma pos_of_ne_zero {n : ℕ} {a : Fin (n + 1)} (h : a ≠ 0) :
0 < a :=
Nat.pos_of_ne_zero (val_ne_of_ne h)
lemma sub_succ_le_sub_of_le {n : ℕ} {u v : Fin (n + 2)} (h : u < v) : v - (u + 1) < v - u := by
fin_omega
end AddGroup
@[simp]
theorem coe_natCast_eq_mod (m n : ℕ) [NeZero m] :
((n : Fin m) : ℕ) = n % m :=
rfl
theorem coe_ofNat_eq_mod (m n : ℕ) [NeZero m] :
((ofNat(n) : Fin m) : ℕ) = ofNat(n) % m :=
rfl
section Mul
/-!
### mul
-/
protected theorem mul_one' [NeZero n] (k : Fin n) : k * 1 = k := by
rcases n with - | n
· simp [eq_iff_true_of_subsingleton]
cases n
· simp [fin_one_eq_zero]
simp [Fin.ext_iff, mul_def, mod_eq_of_lt (is_lt k)]
protected theorem one_mul' [NeZero n] (k : Fin n) : (1 : Fin n) * k = k := by
rw [Fin.mul_comm, Fin.mul_one']
protected theorem mul_zero' [NeZero n] (k : Fin n) : k * 0 = 0 := by simp [Fin.ext_iff, mul_def]
protected theorem zero_mul' [NeZero n] (k : Fin n) : (0 : Fin n) * k = 0 := by
simp [Fin.ext_iff, mul_def]
end Mul
end Fin
| Mathlib/Data/Fin/Basic.lean | 1,584 | 1,586 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
@[to_additive (attr := simp)]
theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) :
infEdist (c • x) (c • s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) :
∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by
obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one
let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n)
have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by
by_contra h
have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne'
exact this (infEdist_zero_of_mem h)
refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩
· show ⋃ n, F n = U
refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_
have : ¬x ∈ Uᶜ := by simpa using hx
rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this
have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this
have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) :=
ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one
rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩
simp only [mem_iUnion, mem_Ici, mem_preimage]
exact ⟨n, hn.le⟩
show Monotone F
intro m n hmn x hx
simp only [F, mem_Ici, mem_preimage] at hx ⊢
apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx
theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) :
∃ y ∈ s, infEdist x s = edist x y := by
have A : Continuous fun y => edist x y := continuous_const.edist continuous_id
obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn
exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩
theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) :
∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by
rcases s.eq_empty_or_nonempty with (rfl | hne)
· use 1
simp
obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn
have : 0 < infEdist x t :=
pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩
exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩
end InfEdist
/-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/
/-- The Hausdorff edistance between two sets is the smallest `r` such that each set
is contained in the `r`-neighborhood of the other one -/
irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ :=
(⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s
section HausdorffEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x : α} {s t u : Set α} {Φ : α → β}
/-- The Hausdorff edistance of a set to itself vanishes. -/
@[simp]
theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by
simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero]
exact fun x hx => infEdist_zero_of_mem hx
/-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/
theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by
simp only [hausdorffEdist_def]; apply sup_comm
/-- Bounding the Hausdorff edistance by bounding the edistance of any point
in each set to the other set -/
theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r)
(H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by
simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff]
exact ⟨H1, H2⟩
/-- Bounding the Hausdorff edistance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r)
(H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by
refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_)
· rcases H1 x xs with ⟨y, yt, hy⟩
exact le_trans (infEdist_le_edist_of_mem yt) hy
· rcases H2 x xt with ⟨y, ys, hy⟩
exact le_trans (infEdist_le_edist_of_mem ys) hy
/-- The distance to a set is controlled by the Hausdorff distance. -/
theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by
rw [hausdorffEdist_def]
refine le_trans ?_ le_sup_left
exact le_iSup₂ (α := ℝ≥0∞) x h
/-- If the Hausdorff distance is `< r`, then any point in one of the sets has
a corresponding point at distance `< r` in the other set. -/
theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) :
∃ y ∈ t, edist x y < r :=
infEdist_lt_iff.mp <|
calc
infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h
_ < r := H
/-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance
between `s` and `t`. -/
theorem infEdist_le_infEdist_add_hausdorffEdist :
infEdist x t ≤ infEdist x s + hausdorffEdist s t :=
ENNReal.le_of_forall_pos_le_add fun ε εpos h => by
have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x s < infEdist x s + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0
obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this
have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0
obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ :=
exists_edist_lt_of_hausdorffEdist_lt ys this
calc
infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le
_ = infEdist x s + hausdorffEdist s t + ε := by
simp [ENNReal.add_halves, add_comm, add_left_comm]
/-- The Hausdorff edistance is invariant under isometries. -/
theorem hausdorffEdist_image (h : Isometry Φ) :
hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by
simp only [hausdorffEdist_def, iSup_image, infEdist_image h]
/-- The Hausdorff distance is controlled by the diameter of the union. -/
theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) :
hausdorffEdist s t ≤ diam (s ∪ t) := by
rcases hs with ⟨x, xs⟩
rcases ht with ⟨y, yt⟩
refine hausdorffEdist_le_of_mem_edist ?_ ?_
· intro z hz
exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩
· intro z hz
exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by
rw [hausdorffEdist_def]
simp only [sup_le_iff, iSup_le_iff]
constructor
· show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xs =>
calc
infEdist x u ≤ infEdist x t + hausdorffEdist t u :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist s t + hausdorffEdist t u :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _
· show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xu =>
calc
infEdist x s ≤ infEdist x t + hausdorffEdist t s :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist u t + hausdorffEdist t s :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _
_ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm]
/-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/
theorem hausdorffEdist_zero_iff_closure_eq_closure :
hausdorffEdist s t = 0 ↔ closure s = closure t := by
simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def,
← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff]
/-- The Hausdorff edistance between a set and its closure vanishes. -/
@[simp]
theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure]
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by
refine le_antisymm ?_ ?_
· calc
_ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle
_ = hausdorffEdist s t := by simp [hausdorffEdist_comm]
· calc
_ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle
_ = hausdorffEdist (closure s) t := by simp
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by
simp [@hausdorffEdist_comm _ _ s _]
/-- The Hausdorff edistance between sets or their closures is the same. -/
theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by
simp
/-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/
theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) :
hausdorffEdist s t = 0 ↔ s = t := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq]
/-- The Haudorff edistance to the empty set is infinite. -/
theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by
rcases ne with ⟨x, xs⟩
have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs
simpa using this
/-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/
theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) :
t.Nonempty :=
t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs)
theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) :
(s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by
rcases s.eq_empty_or_nonempty with hs | hs
· rcases t.eq_empty_or_nonempty with ht | ht
· exact Or.inl ⟨hs, ht⟩
· rw [hausdorffEdist_comm] at fin
exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩
· exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩
end HausdorffEdist
-- section
end EMetric
/-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to
`sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞`
formulated in terms of the edistance, and coerce them to `ℝ`.
Then their properties follow readily from the corresponding properties in `ℝ≥0∞`,
modulo some tedious rewriting of inequalities from one to the other. -/
--namespace
namespace Metric
section
variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β}
open EMetric
/-! ### Distance of a point to a set as a function into `ℝ`. -/
/-- The minimal distance of a point to a set -/
def infDist (x : α) (s : Set α) : ℝ :=
ENNReal.toReal (infEdist x s)
theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by
rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf]
· simp only [dist_edist]
· exact fun _ ↦ edist_ne_top _ _
|
/-- The minimal distance is always nonnegative -/
theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 439 | 442 |
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.NumberTheory.LSeries.AbstractFuncEq
import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds
import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
import Mathlib.NumberTheory.LSeries.MellinEqDirichlet
import Mathlib.NumberTheory.LSeries.Basic
import Mathlib.Analysis.Complex.RemovableSingularity
/-!
# Even Hurwitz zeta functions
In this file we study the functions on `ℂ` which are the meromorphic continuation of the following
series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter:
`hurwitzZetaEven a s = 1 / 2 * ∑' n : ℤ, 1 / |n + a| ^ s`
and
`cosZeta a s = ∑' n : ℕ, cos (2 * π * a * n) / |n| ^ s`.
Note that the term for `n = -a` in the first sum is omitted if `a` is an integer, and the term for
`n = 0` is omitted in the second sum (always).
Of course, we cannot *define* these functions by the above formulae (since existence of the
meromorphic continuation is not at all obvious); we in fact construct them as Mellin transforms of
various versions of the Jacobi theta function.
We also define completed versions of these functions with nicer functional equations (satisfying
`completedHurwitzZetaEven a s = Gammaℝ s * hurwitzZetaEven a s`, and similarly for `cosZeta`); and
modified versions with a subscript `0`, which are entire functions differing from the above by
multiples of `1 / s` and `1 / (1 - s)`.
## Main definitions and theorems
* `hurwitzZetaEven` and `cosZeta`: the zeta functions
* `completedHurwitzZetaEven` and `completedCosZeta`: completed variants
* `differentiableAt_hurwitzZetaEven` and `differentiableAt_cosZeta`:
differentiability away from `s = 1`
* `completedHurwitzZetaEven_one_sub`: the functional equation
`completedHurwitzZetaEven a (1 - s) = completedCosZeta a s`
* `hasSum_int_hurwitzZetaEven` and `hasSum_nat_cosZeta`: relation between the zeta functions and
the corresponding Dirichlet series for `1 < re s`.
-/
noncomputable section
open Complex Filter Topology Asymptotics Real Set MeasureTheory
namespace HurwitzZeta
section kernel_defs
/-!
## Definitions and elementary properties of kernels
-/
/-- Even Hurwitz zeta kernel (function whose Mellin transform will be the even part of the
completed Hurwit zeta function). See `evenKernel_def` for the defining formula, and
`hasSum_int_evenKernel` for an expression as a sum over `ℤ`. -/
@[irreducible] def evenKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic
(fun ξ : ℝ ↦ rexp (-π * ξ ^ 2 * x) * re (jacobiTheta₂ (ξ * I * x) (I * x))) 1 by
intro ξ
simp only [ofReal_add, ofReal_one, add_mul, one_mul, jacobiTheta₂_add_left']
have : cexp (-↑π * I * ((I * ↑x) + 2 * (↑ξ * I * ↑x))) = rexp (π * (x + 2 * ξ * x)) := by
ring_nf
simp [I_sq]
rw [this, re_ofReal_mul, ← mul_assoc, ← Real.exp_add]
congr
ring).lift a
lemma evenKernel_def (a x : ℝ) :
↑(evenKernel ↑a x) = cexp (-π * a ^ 2 * x) * jacobiTheta₂ (a * I * x) (I * x) := by
simp [evenKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
/-- For `x ≤ 0` the defining sum diverges, so the kernel is 0. -/
lemma evenKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : evenKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H a' => simp [← ofReal_inj, evenKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- Cosine Hurwitz zeta kernel. See `cosKernel_def` for the defining formula, and
`hasSum_int_cosKernel` for expression as a sum. -/
@[irreducible] def cosKernel (a : UnitAddCircle) (x : ℝ) : ℝ :=
(show Function.Periodic (fun ξ : ℝ ↦ re (jacobiTheta₂ ξ (I * x))) 1 by
intro ξ; simp [jacobiTheta₂_add_left]).lift a
lemma cosKernel_def (a x : ℝ) : ↑(cosKernel ↑a x) = jacobiTheta₂ a (I * x) := by
simp [cosKernel, re_eq_add_conj, jacobiTheta₂_conj, ← mul_two,
mul_div_cancel_right₀ _ (two_ne_zero' ℂ)]
lemma cosKernel_undef (a : UnitAddCircle) {x : ℝ} (hx : x ≤ 0) : cosKernel a x = 0 := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← ofReal_inj, cosKernel_def, jacobiTheta₂_undef _ (by simpa : (I * ↑x).im ≤ 0)]
/-- For `a = 0`, both kernels agree. -/
lemma evenKernel_eq_cosKernel_of_zero : evenKernel 0 = cosKernel 0 := by
ext1 x
simp [← QuotientAddGroup.mk_zero, ← ofReal_inj, evenKernel_def, cosKernel_def]
@[simp]
lemma evenKernel_neg (a : UnitAddCircle) (x : ℝ) : evenKernel (-a) x = evenKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, evenKernel_def, jacobiTheta₂_neg_left]
@[simp]
lemma cosKernel_neg (a : UnitAddCircle) (x : ℝ) : cosKernel (-a) x = cosKernel a x := by
induction a using QuotientAddGroup.induction_on with
| H => simp [← QuotientAddGroup.mk_neg, ← ofReal_inj, cosKernel_def]
lemma continuousOn_evenKernel (a : UnitAddCircle) : ContinuousOn (evenKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (evenKernel a' x : ℂ))
simp only [evenKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ .mul (by fun_prop) ?_)
exact (continuousAt_jacobiTheta₂ (a' * I * x) <| by simpa).comp
(f := fun u : ℝ ↦ (a' * I * u, I * u)) (by fun_prop)
lemma continuousOn_cosKernel (a : UnitAddCircle) : ContinuousOn (cosKernel a) (Ioi 0) := by
induction a using QuotientAddGroup.induction_on with | H a' =>
apply continuous_re.comp_continuousOn (f := fun x ↦ (cosKernel a' x : ℂ))
simp only [cosKernel_def]
refine continuousOn_of_forall_continuousAt (fun x hx ↦ ?_)
exact (continuousAt_jacobiTheta₂ a' <| by simpa).comp
(f := fun u : ℝ ↦ ((a' : ℂ), I * u)) (by fun_prop)
lemma evenKernel_functional_equation (a : UnitAddCircle) (x : ℝ) :
evenKernel a x = 1 / x ^ (1 / 2 : ℝ) * cosKernel a (1 / x) := by
rcases le_or_lt x 0 with hx | hx
· rw [evenKernel_undef _ hx, cosKernel_undef, mul_zero]
exact div_nonpos_of_nonneg_of_nonpos zero_le_one hx
induction a using QuotientAddGroup.induction_on with | H a =>
rw [← ofReal_inj, ofReal_mul, evenKernel_def, cosKernel_def, jacobiTheta₂_functional_equation]
have h1 : I * ↑(1 / x) = -1 / (I * x) := by
push_cast
rw [← div_div, mul_one_div, div_I, neg_one_mul, neg_neg]
have hx' : I * x ≠ 0 := mul_ne_zero I_ne_zero (ofReal_ne_zero.mpr hx.ne')
have h2 : a * I * x / (I * x) = a := by
rw [div_eq_iff hx']
ring
have h3 : 1 / (-I * (I * x)) ^ (1 / 2 : ℂ) = 1 / ↑(x ^ (1 / 2 : ℝ)) := by
rw [neg_mul, ← mul_assoc, I_mul_I, neg_one_mul, neg_neg,ofReal_cpow hx.le, ofReal_div,
ofReal_one, ofReal_ofNat]
have h4 : -π * I * (a * I * x) ^ 2 / (I * x) = - (-π * a ^ 2 * x) := by
rw [mul_pow, mul_pow, I_sq, div_eq_iff hx']
ring
rw [h1, h2, h3, h4, ← mul_assoc, mul_comm (cexp _), mul_assoc _ (cexp _) (cexp _),
← Complex.exp_add, neg_add_cancel, Complex.exp_zero, mul_one, ofReal_div, ofReal_one]
end kernel_defs
section asymp
/-!
## Formulae for the kernels as sums
-/
lemma hasSum_int_evenKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ rexp (-π * (n + a) ^ 2 * t)) (evenKernel a t) := by
rw [← hasSum_ofReal, evenKernel_def]
have (n : ℤ) : cexp (-(π * (n + a) ^ 2 * t)) = cexp (-(π * a ^ 2 * t)) *
jacobiTheta₂_term n (a * I * t) (I * t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp
simpa [this] using (hasSum_jacobiTheta₂_term _ (by simpa)).mul_left _
lemma hasSum_int_cosKernel (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t)) ↑(cosKernel a t) := by
rw [cosKernel_def a t]
have (n : ℤ) : cexp (2 * π * I * a * n) * cexp (-(π * n ^ 2 * t)) =
jacobiTheta₂_term n a (I * ↑t) := by
rw [jacobiTheta₂_term, ← Complex.exp_add]
ring_nf
simp [sub_eq_add_neg]
simpa [this] using hasSum_jacobiTheta₂_term _ (by simpa)
/-- Modified version of `hasSum_int_evenKernel` omitting the constant term at `∞`. -/
lemma hasSum_int_evenKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n + a = 0 then 0 else rexp (-π * (n + a) ^ 2 * t))
(evenKernel a t - if (a : UnitAddCircle) = 0 then 1 else 0) := by
haveI := Classical.propDecidable -- speed up instance search for `if / then / else`
simp_rw [AddCircle.coe_eq_zero_iff, zsmul_one]
split_ifs with h
· obtain ⟨k, rfl⟩ := h
simpa [← Int.cast_add, add_eq_zero_iff_eq_neg]
using hasSum_ite_sub_hasSum (hasSum_int_evenKernel (k : ℝ) ht) (-k)
· suffices ∀ (n : ℤ), n + a ≠ 0 by simpa [this] using hasSum_int_evenKernel a ht
contrapose! h
let ⟨n, hn⟩ := h
exact ⟨-n, by simpa [neg_eq_iff_add_eq_zero]⟩
lemma hasSum_int_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℤ ↦ if n = 0 then 0 else cexp (2 * π * I * a * n) * rexp (-π * n ^ 2 * t))
(↑(cosKernel a t) - 1) := by
simpa using hasSum_ite_sub_hasSum (hasSum_int_cosKernel a ht) 0
lemma hasSum_nat_cosKernel₀ (a : ℝ) {t : ℝ} (ht : 0 < t) :
HasSum (fun n : ℕ ↦ 2 * Real.cos (2 * π * a * (n + 1)) * rexp (-π * (n + 1) ^ 2 * t))
(cosKernel a t - 1) := by
rw [← hasSum_ofReal, ofReal_sub, ofReal_one]
have := (hasSum_int_cosKernel a ht).nat_add_neg
rw [← hasSum_nat_add_iff' 1] at this
simp_rw [Finset.sum_range_one, Nat.cast_zero, neg_zero, Int.cast_zero, zero_pow two_ne_zero,
mul_zero, zero_mul, Complex.exp_zero, Real.exp_zero, ofReal_one, mul_one, Int.cast_neg,
Int.cast_natCast, neg_sq, ← add_mul, add_sub_assoc, ← sub_sub, sub_self, zero_sub,
← sub_eq_add_neg, mul_neg] at this
refine this.congr_fun fun n ↦ ?_
push_cast
rw [Complex.cos, mul_div_cancel₀ _ two_ne_zero]
congr 3 <;> ring
/-!
## Asymptotics of the kernels as `t → ∞`
-/
/-- The function `evenKernel a - L` has exponential decay at `+∞`, where `L = 1` if
`a = 0` and `L = 0` otherwise. -/
lemma isBigO_atTop_evenKernel_sub (a : UnitAddCircle) : ∃ p : ℝ, 0 < p ∧
(evenKernel a · - (if a = 0 then 1 else 0)) =O[atTop] (rexp <| -p * ·) := by
induction a using QuotientAddGroup.induction_on with | H b =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub b
refine ⟨p, hp, (EventuallyEq.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t h
simp [← (hasSum_int_evenKernel b h).tsum_eq, HurwitzKernelBounds.F_int, HurwitzKernelBounds.f_int]
/-- The function `cosKernel a - 1` has exponential decay at `+∞`, for any `a`. -/
lemma isBigO_atTop_cosKernel_sub (a : UnitAddCircle) :
∃ p, 0 < p ∧ IsBigO atTop (cosKernel a · - 1) (fun x ↦ Real.exp (-p * x)) := by
induction a using QuotientAddGroup.induction_on with | H a =>
obtain ⟨p, hp, hp'⟩ := HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub zero_le_one
refine ⟨p, hp, (Eventually.isBigO ?_).trans (hp'.const_mul_left 2)⟩
filter_upwards [eventually_gt_atTop 0] with t ht
simp only [eq_false_intro one_ne_zero, if_false, sub_zero,
← (hasSum_nat_cosKernel₀ a ht).tsum_eq, HurwitzKernelBounds.F_nat]
apply tsum_of_norm_bounded ((HurwitzKernelBounds.summable_f_nat 0 1 ht).hasSum.mul_left 2)
intro n
rw [norm_mul, norm_mul, norm_two, mul_assoc, mul_le_mul_iff_of_pos_left two_pos,
norm_of_nonneg (exp_pos _).le, HurwitzKernelBounds.f_nat, pow_zero, one_mul, Real.norm_eq_abs]
exact mul_le_of_le_one_left (exp_pos _).le (abs_cos_le_one _)
end asymp
section FEPair
/-!
## Construction of a FE-pair
-/
/-- A `WeakFEPair` structure with `f = evenKernel a` and `g = cosKernel a`. -/
def hurwitzEvenFEPair (a : UnitAddCircle) : WeakFEPair ℂ where
f := ofReal ∘ evenKernel a
g := ofReal ∘ cosKernel a
hf_int := (continuous_ofReal.comp_continuousOn (continuousOn_evenKernel a)).locallyIntegrableOn
measurableSet_Ioi
hg_int := (continuous_ofReal.comp_continuousOn (continuousOn_cosKernel a)).locallyIntegrableOn
measurableSet_Ioi
k := 1 / 2
hk := one_half_pos
ε := 1
hε := one_ne_zero
f₀ := if a = 0 then 1 else 0
hf_top r := by
let ⟨v, hv, hv'⟩ := isBigO_atTop_evenKernel_sub a
rw [← isBigO_norm_left] at hv' ⊢
conv at hv' =>
enter [2, x]; rw [← norm_real, ofReal_sub, apply_ite ((↑) : ℝ → ℂ), ofReal_one, ofReal_zero]
exact hv'.trans (isLittleO_exp_neg_mul_rpow_atTop hv _).isBigO
g₀ := 1
hg_top r := by
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_cosKernel_sub a
simpa using isBigO_ofReal_left.mpr <| hp'.trans (isLittleO_exp_neg_mul_rpow_atTop hp r).isBigO
h_feq x hx := by simp [← ofReal_mul, evenKernel_functional_equation, inv_rpow (le_of_lt hx)]
@[simp]
lemma hurwitzEvenFEPair_zero_symm :
(hurwitzEvenFEPair 0).symm = hurwitzEvenFEPair 0 := by
unfold hurwitzEvenFEPair WeakFEPair.symm
congr 1 <;> simp [evenKernel_eq_cosKernel_of_zero]
@[simp]
lemma hurwitzEvenFEPair_neg (a : UnitAddCircle) : hurwitzEvenFEPair (-a) = hurwitzEvenFEPair a := by
unfold hurwitzEvenFEPair
congr 1 <;> simp [Function.comp_def]
/-!
## Definition of the completed even Hurwitz zeta function
-/
/--
The meromorphic function of `s` which agrees with
`1 / 2 * Gamma (s / 2) * π ^ (-s / 2) * ∑' (n : ℤ), 1 / |n + a| ^ s` for `1 < re s`.
-/
def completedHurwitzZetaEven (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ (s / 2)) / 2
/-- The entire function differing from `completedHurwitzZetaEven a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedHurwitzZetaEven₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).Λ₀ (s / 2)) / 2
lemma completedHurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a s =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s - 1 / (1 - s) := by
rw [completedHurwitzZetaEven, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· change completedHurwitzZetaEven₀ a s - (1 / (s / 2)) • (if a = 0 then 1 else 0) / 2 =
completedHurwitzZetaEven₀ a s - (if a = 0 then 1 else 0) / s
rw [smul_eq_mul, mul_comm, mul_div_assoc, div_div, div_mul_cancel₀ _ two_ne_zero, mul_one_div]
· change (1 / (↑(1 / 2 : ℝ) - s / 2)) • 1 / 2 = 1 / (1 - s)
push_cast
rw [smul_eq_mul, mul_one, ← sub_div, div_div, div_mul_cancel₀ _ two_ne_zero]
/--
The meromorphic function of `s` which agrees with
`Gamma (s / 2) * π ^ (-s / 2) * ∑' n : ℕ, cos (2 * π * a * n) / n ^ s` for `1 < re s`.
-/
def completedCosZeta (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ (s / 2)) / 2
/-- The entire function differing from `completedCosZeta a s` by a linear combination of
`1 / s` and `1 / (1 - s)`. -/
def completedCosZeta₀ (a : UnitAddCircle) (s : ℂ) : ℂ :=
((hurwitzEvenFEPair a).symm.Λ₀ (s / 2)) / 2
lemma completedCosZeta_eq (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a s =
completedCosZeta₀ a s - 1 / s - (if a = 0 then 1 else 0) / (1 - s) := by
rw [completedCosZeta, WeakFEPair.Λ, sub_div, sub_div]
congr 1
· rw [completedCosZeta₀, WeakFEPair.symm, hurwitzEvenFEPair, smul_eq_mul, mul_one, div_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ)]
· simp_rw [WeakFEPair.symm, hurwitzEvenFEPair, push_cast, inv_one, smul_eq_mul,
mul_comm _ (if _ then _ else _), mul_div_assoc, div_div, ← sub_div,
div_mul_cancel₀ _ (two_ne_zero' ℂ), mul_one_div]
/-!
## Parity and functional equations
-/
@[simp]
lemma completedHurwitzZetaEven_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven (-a) s = completedHurwitzZetaEven a s := by
simp [completedHurwitzZetaEven]
@[simp]
lemma completedHurwitzZetaEven₀_neg (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ (-a) s = completedHurwitzZetaEven₀ a s := by
simp [completedHurwitzZetaEven₀]
@[simp]
lemma completedCosZeta_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta (-a) s = completedCosZeta a s := by
simp [completedCosZeta]
@[simp]
lemma completedCosZeta₀_neg (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ (-a) s = completedCosZeta₀ a s := by
simp [completedCosZeta₀]
/-- Functional equation for the even Hurwitz zeta function. -/
lemma completedHurwitzZetaEven_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven a (1 - s) = completedCosZeta a s := by
rw [completedHurwitzZetaEven, completedCosZeta, sub_div,
(by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function with poles removed. -/
lemma completedHurwitzZetaEven₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedHurwitzZetaEven₀ a (1 - s) = completedCosZeta₀ a s := by
rw [completedHurwitzZetaEven₀, completedCosZeta₀, sub_div,
(by norm_num : (1 / 2 : ℂ) = ↑(1 / 2 : ℝ)),
(by rfl : (1 / 2 : ℝ) = (hurwitzEvenFEPair a).k),
(hurwitzEvenFEPair a).functional_equation₀ (s / 2),
(by rfl : (hurwitzEvenFEPair a).ε = 1),
one_smul]
/-- Functional equation for the even Hurwitz zeta function (alternative form). -/
lemma completedCosZeta_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta a (1 - s) = completedHurwitzZetaEven a s := by
rw [← completedHurwitzZetaEven_one_sub, sub_sub_cancel]
/-- Functional equation for the even Hurwitz zeta function with poles removed (alternative form). -/
lemma completedCosZeta₀_one_sub (a : UnitAddCircle) (s : ℂ) :
completedCosZeta₀ a (1 - s) = completedHurwitzZetaEven₀ a s := by
rw [← completedHurwitzZetaEven₀_one_sub, sub_sub_cancel]
end FEPair
/-!
## Differentiability and residues
-/
section FEPair
/--
The even Hurwitz completed zeta is differentiable away from `s = 0` and `s = 1` (and also at
`s = 0` if `a ≠ 0`)
-/
lemma differentiableAt_completedHurwitzZetaEven
(a : UnitAddCircle) {s : ℂ} (hs : s ≠ 0 ∨ a ≠ 0) (hs' : s ≠ 1) :
DifferentiableAt ℂ (completedHurwitzZetaEven a) s := by
refine (((hurwitzEvenFEPair a).differentiableAt_Λ ?_ (Or.inl ?_)).comp s
(differentiableAt_id.div_const _)).div_const _
· rcases hs with h | h <;>
simp [hurwitzEvenFEPair, h]
· change s / 2 ≠ ↑(1 / 2 : ℝ)
rw [ofReal_div, ofReal_one, ofReal_ofNat]
exact hs' ∘ (div_left_inj' two_ne_zero).mp
lemma differentiable_completedHurwitzZetaEven₀ (a : UnitAddCircle) :
Differentiable ℂ (completedHurwitzZetaEven₀ a) :=
((hurwitzEvenFEPair a).differentiable_Λ₀.comp (differentiable_id.div_const _)).div_const _
/-- The difference of two completed even Hurwitz zeta functions is differentiable at `s = 1`. -/
lemma differentiableAt_one_completedHurwitzZetaEven_sub_completedHurwitzZetaEven
(a b : UnitAddCircle) :
DifferentiableAt ℂ (fun s ↦ completedHurwitzZetaEven a s - completedHurwitzZetaEven b s) 1 := by
have (s) : completedHurwitzZetaEven a s - completedHurwitzZetaEven b s =
completedHurwitzZetaEven₀ a s - completedHurwitzZetaEven₀ b s -
((if a = 0 then 1 else 0) - (if b = 0 then 1 else 0)) / s := by
simp_rw [completedHurwitzZetaEven_eq, sub_div]
abel
rw [funext this]
refine .sub ?_ <| (differentiable_const _ _).div (differentiable_id _) one_ne_zero
apply DifferentiableAt.sub <;> apply differentiable_completedHurwitzZetaEven₀
lemma differentiableAt_completedCosZeta
(a : UnitAddCircle) {s : ℂ} (hs : s ≠ 0) (hs' : s ≠ 1 ∨ a ≠ 0) :
DifferentiableAt ℂ (completedCosZeta a) s := by
refine (((hurwitzEvenFEPair a).symm.differentiableAt_Λ (Or.inl ?_) ?_).comp s
(differentiableAt_id.div_const _)).div_const _
· exact div_ne_zero_iff.mpr ⟨hs, two_ne_zero⟩
· change s / 2 ≠ ↑(1 / 2 : ℝ) ∨ (if a = 0 then 1 else 0) = 0
refine Or.imp (fun h ↦ ?_) (fun ha ↦ ?_) hs'
· simpa [push_cast] using h ∘ (div_left_inj' two_ne_zero).mp
· simpa
lemma differentiable_completedCosZeta₀ (a : UnitAddCircle) :
Differentiable ℂ (completedCosZeta₀ a) :=
((hurwitzEvenFEPair a).symm.differentiable_Λ₀.comp (differentiable_id.div_const _)).div_const _
private lemma tendsto_div_two_punctured_nhds (a : ℂ) :
Tendsto (fun s : ℂ ↦ s / 2) (𝓝[≠] a) (𝓝[≠] (a / 2)) :=
le_of_eq ((Homeomorph.mulRight₀ _ (inv_ne_zero (two_ne_zero' ℂ))).map_punctured_nhds_eq a)
/-- The residue of `completedHurwitzZetaEven a s` at `s = 1` is equal to `1`. -/
lemma completedHurwitzZetaEven_residue_one (a : UnitAddCircle) :
Tendsto (fun s ↦ (s - 1) * completedHurwitzZetaEven a s) (𝓝[≠] 1) (𝓝 1) := by
have h1 : Tendsto (fun s : ℂ ↦ (s - ↑(1 / 2 : ℝ)) * _) (𝓝[≠] ↑(1 / 2 : ℝ))
(𝓝 ((1 : ℂ) * (1 : ℂ))) := (hurwitzEvenFEPair a).Λ_residue_k
simp only [push_cast, one_mul] at h1
refine (h1.comp <| tendsto_div_two_punctured_nhds 1).congr (fun s ↦ ?_)
rw [completedHurwitzZetaEven, Function.comp_apply, ← sub_div, div_mul_eq_mul_div, mul_div_assoc]
/-- The residue of `completedHurwitzZetaEven a s` at `s = 0` is equal to `-1` if `a = 0`, and `0`
otherwise. -/
lemma completedHurwitzZetaEven_residue_zero (a : UnitAddCircle) :
Tendsto (fun s ↦ s * completedHurwitzZetaEven a s) (𝓝[≠] 0) (𝓝 (if a = 0 then -1 else 0)) := by
have h1 : Tendsto (fun s : ℂ ↦ s * _) (𝓝[≠] 0)
(𝓝 (-(if a = 0 then 1 else 0))) := (hurwitzEvenFEPair a).Λ_residue_zero
have : -(if a = 0 then (1 : ℂ) else 0) = (if a = 0 then -1 else 0) := by { split_ifs <;> simp }
simp only [this, push_cast, one_mul] at h1
refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_)
simp [completedHurwitzZetaEven, div_mul_eq_mul_div, mul_div_assoc]
lemma completedCosZeta_residue_zero (a : UnitAddCircle) :
Tendsto (fun s ↦ s * completedCosZeta a s) (𝓝[≠] 0) (𝓝 (-1)) := by
have h1 : Tendsto (fun s : ℂ ↦ s * _) (𝓝[≠] 0)
(𝓝 (-1)) := (hurwitzEvenFEPair a).symm.Λ_residue_zero
refine (h1.comp <| zero_div (2 : ℂ) ▸ (tendsto_div_two_punctured_nhds 0)).congr (fun s ↦ ?_)
simp [completedCosZeta, div_mul_eq_mul_div, mul_div_assoc]
end FEPair
/-!
## Relation to the Dirichlet series for `1 < re s`
-/
/-- Formula for `completedCosZeta` as a Dirichlet series in the convergence range
(first version, with sum over `ℤ`). -/
lemma hasSum_int_completedCosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ Gammaℝ s * cexp (2 * π * I * a * n) / (↑|n| : ℂ) ^ s / 2)
(completedCosZeta a s) := by
let c (n : ℤ) : ℂ := cexp (2 * π * I * a * n) / 2
have hF t (ht : 0 < t) : HasSum (fun n : ℤ ↦ if n = 0 then 0 else c n * rexp (-π * n ^ 2 * t))
((cosKernel a t - 1) / 2) := by
refine ((hasSum_int_cosKernel₀ a ht).div_const 2).congr_fun fun n ↦ ?_
split_ifs <;> simp [c, div_mul_eq_mul_div]
simp only [← Int.cast_eq_zero (α := ℝ)] at hF
rw [show completedCosZeta a s = mellin (fun t ↦ (cosKernel a t - 1 : ℂ) / 2) (s / 2) by
rw [mellin_div_const, completedCosZeta]
congr 1
refine ((hurwitzEvenFEPair a).symm.hasMellin (?_ : 1 / 2 < (s / 2).re)).2.symm
rwa [div_ofNat_re, div_lt_div_iff_of_pos_right two_pos]]
refine (hasSum_mellin_pi_mul_sq (zero_lt_one.trans hs) hF ?_).congr_fun fun n ↦ ?_
· apply (((summable_one_div_int_add_rpow 0 s.re).mpr hs).div_const 2).of_norm_bounded
intro i
simp only [c, (by { push_cast; ring } : 2 * π * I * a * i = ↑(2 * π * a * i) * I), norm_div,
RCLike.norm_ofNat, norm_norm, Complex.norm_exp_ofReal_mul_I, add_zero, norm_one,
norm_of_nonneg (by positivity : 0 ≤ |(i : ℝ)| ^ s.re), div_right_comm, le_rfl]
· simp [c, ← Int.cast_abs, div_right_comm, mul_div_assoc]
/-- Formula for `completedCosZeta` as a Dirichlet series in the convergence range
(second version, with sum over `ℕ`). -/
lemma hasSum_nat_completedCosZeta (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℕ ↦ if n = 0 then 0 else Gammaℝ s * Real.cos (2 * π * a * n) / (n : ℂ) ^ s)
(completedCosZeta a s) := by
have aux : ((|0| : ℤ) : ℂ) ^ s = 0 := by
rw [abs_zero, Int.cast_zero, zero_cpow (ne_zero_of_one_lt_re hs)]
have hint := (hasSum_int_completedCosZeta a hs).nat_add_neg
rw [aux, div_zero, zero_div, add_zero] at hint
refine hint.congr_fun fun n ↦ ?_
split_ifs with h
· simp only [h, Nat.cast_zero, aux, div_zero, zero_div, neg_zero, zero_add]
· simp only [ofReal_cos, ofReal_mul, ofReal_ofNat, ofReal_natCast, Complex.cos,
show 2 * π * a * n * I = 2 * π * I * a * n by ring, neg_mul, mul_div_assoc,
div_right_comm _ (2 : ℂ), Int.cast_natCast, Nat.abs_cast, Int.cast_neg, mul_neg, abs_neg, ←
mul_add, ← add_div]
/-- Formula for `completedHurwitzZetaEven` as a Dirichlet series in the convergence range. -/
lemma hasSum_int_completedHurwitzZetaEven (a : ℝ) {s : ℂ} (hs : 1 < re s) :
HasSum (fun n : ℤ ↦ Gammaℝ s / (↑|n + a| : ℂ) ^ s / 2) (completedHurwitzZetaEven a s) := by
have hF (t : ℝ) (ht : 0 < t) : HasSum (fun n : ℤ ↦ if n + a = 0 then 0
else (1 / 2 : ℂ) * rexp (-π * (n + a) ^ 2 * t))
((evenKernel a t - (if (a : UnitAddCircle) = 0 then 1 else 0 : ℝ)) / 2) := by
refine (ofReal_sub .. ▸ (hasSum_ofReal.mpr (hasSum_int_evenKernel₀ a ht)).div_const
2).congr_fun fun n ↦ ?_
split_ifs
· rw [ofReal_zero, zero_div]
· rw [mul_comm, mul_one_div]
rw [show completedHurwitzZetaEven a s = mellin (fun t ↦ ((evenKernel (↑a) t : ℂ) -
↑(if (a : UnitAddCircle) = 0 then 1 else 0 : ℝ)) / 2) (s / 2) by
simp_rw [mellin_div_const, apply_ite ofReal, ofReal_one, ofReal_zero]
refine congr_arg (· / 2) ((hurwitzEvenFEPair a).hasMellin (?_ : 1 / 2 < (s / 2).re)).2.symm
rwa [div_ofNat_re, div_lt_div_iff_of_pos_right two_pos]]
refine (hasSum_mellin_pi_mul_sq (zero_lt_one.trans hs) hF ?_).congr_fun fun n ↦ ?_
· simp_rw [← mul_one_div ‖_‖]
apply Summable.mul_left
rwa [summable_one_div_int_add_rpow]
· rw [mul_one_div, div_right_comm]
|
/-!
## The un-completed even Hurwitz zeta
-/
/-- Technical lemma which will give us differentiability of Hurwitz zeta at `s = 0`. -/
lemma differentiableAt_update_of_residue
{Λ : ℂ → ℂ} (hf : ∀ (s : ℂ) (_ : s ≠ 0) (_ : s ≠ 1), DifferentiableAt ℂ Λ s)
{L : ℂ} (h_lim : Tendsto (fun s ↦ s * Λ s) (𝓝[≠] 0) (𝓝 L)) (s : ℂ) (hs' : s ≠ 1) :
DifferentiableAt ℂ (Function.update (fun s ↦ Λ s / Gammaℝ s) 0 (L / 2)) s := by
have claim (t) (ht : t ≠ 0) (ht' : t ≠ 1) : DifferentiableAt ℂ (fun u : ℂ ↦ Λ u / Gammaℝ u) t :=
(hf t ht ht').mul differentiable_Gammaℝ_inv.differentiableAt
have claim2 : Tendsto (fun s : ℂ ↦ Λ s / Gammaℝ s) (𝓝[≠] 0) (𝓝 <| L / 2) := by
refine Tendsto.congr' ?_ (h_lim.div Gammaℝ_residue_zero two_ne_zero)
filter_upwards [self_mem_nhdsWithin] with s (hs : s ≠ 0)
rw [Pi.div_apply, ← div_div, mul_div_cancel_left₀ _ hs]
rcases ne_or_eq s 0 with hs | rfl
· -- Easy case : `s ≠ 0`
refine (claim s hs hs').congr_of_eventuallyEq ?_
filter_upwards [isOpen_compl_singleton.mem_nhds hs] with x hx
simp [Function.update_of_ne hx]
| Mathlib/NumberTheory/LSeries/HurwitzZetaEven.lean | 545 | 565 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.Bochner.Basic
import Mathlib.MeasureTheory.Integral.Bochner.L1
import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/Bochner.lean | 2,048 | 2,092 | |
/-
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
-/
import Mathlib.Probability.ConditionalProbability
import Mathlib.Probability.Kernel.Basic
import Mathlib.Probability.Kernel.Composition.MeasureComp
import Mathlib.Tactic.Peel
import Mathlib.MeasureTheory.MeasurableSpace.Pi
/-!
# Independence with respect to a kernel and a measure
A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel
`κ : Kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`,
for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`,
`κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`.
This notion of independence is a generalization of both independence and conditional independence.
For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condExpKernel` and
`μ` is the ambient measure. For (non-conditional) independence, `κ = Kernel.const Unit μ` and the
measure is the Dirac measure on `Unit`.
The main purpose of this file is to prove only once the properties that hold for both conditional
and non-conditional independence.
## Main definitions
* `ProbabilityTheory.Kernel.iIndepSets`: independence of a family of sets of sets.
Variant for two sets of sets: `ProbabilityTheory.Kernel.IndepSets`.
* `ProbabilityTheory.Kernel.iIndep`: independence of a family of σ-algebras. Variant for two
σ-algebras: `Indep`.
* `ProbabilityTheory.Kernel.iIndepSet`: independence of a family of sets. Variant for two sets:
`ProbabilityTheory.Kernel.IndepSet`.
* `ProbabilityTheory.Kernel.iIndepFun`: independence of a family of functions (random variables).
Variant for two functions: `ProbabilityTheory.Kernel.IndepFun`.
See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these
definitions in the particular case of the usual independence notion.
## Main statements
* `ProbabilityTheory.Kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets,
then the measurable space structures they generate are independent.
* `ProbabilityTheory.Kernel.IndepSets.Indep`: variant with two π-systems.
-/
open Set MeasureTheory MeasurableSpace
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory.Kernel
variable {α Ω ι : Type*}
section Definitions
variable {_mα : MeasurableSpace α}
/-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and
a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`.
It will be used for families of pi_systems. -/
def iIndepSets {_mΩ : MeasurableSpace Ω}
(π : ι → Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop :=
∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i),
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i)
/-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for
any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/
def IndepSets {_mΩ : MeasurableSpace Ω}
(s1 s2 : Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop :=
∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2)
/-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/
def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a
kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`,
`∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/
def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ
/-- A family of sets is independent if the family of measurable space structures they generate is
independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/
def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
iIndep (m := fun i ↦ generateFrom {s i}) κ μ
/-- Two sets are independent if the two measurable space structures they generate are independent.
For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/
def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
Indep (generateFrom {s}) (generateFrom {t}) κ μ
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is independent if the family of measurable space
structures they generate on `Ω` is independent. For a function `g` with codomain having measurable
space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/
def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)]
(f : ∀ x : ι, Ω → β x) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
iIndep (m := fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ
/-- Two functions are independent if the two measurable space structures they generate are
independent. For a function `f` with codomain having measurable space structure `m`, the generated
measurable space structure is `MeasurableSpace.comap f m`. -/
def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (κ : Kernel α Ω)
(μ : Measure α := by volume_tac) : Prop :=
Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ
end Definitions
section ByDefinition
variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ η : Kernel α Ω} {μ : Measure α}
{π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x}
{s1 s2 : Set (Set Ω)}
@[simp] lemma iIndepSets_zero_right : iIndepSets π κ 0 := by simp [iIndepSets]
@[simp] lemma indepSets_zero_right : IndepSets s1 s2 κ 0 := by simp [IndepSets]
@[simp] lemma indepSets_zero_left : IndepSets s1 s2 (0 : Kernel α Ω) μ := by simp [IndepSets]
@[simp] lemma iIndep_zero_right : iIndep m κ 0 := by simp [iIndep]
@[simp] lemma indep_zero_right {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} : Indep m₁ m₂ κ 0 := by simp [Indep]
@[simp] lemma indep_zero_left {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} :
Indep m₁ m₂ (0 : Kernel α Ω) μ := by simp [Indep]
@[simp] lemma iIndepSet_zero_right : iIndepSet s κ 0 := by simp [iIndepSet]
@[simp] lemma indepSet_zero_right {s t : Set Ω} : IndepSet s t κ 0 := by simp [IndepSet]
@[simp] lemma indepSet_zero_left {s t : Set Ω} : IndepSet s t (0 : Kernel α Ω) μ := by
simp [IndepSet]
@[simp] lemma iIndepFun_zero_right {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)}
{f : ∀ x : ι, Ω → β x} : iIndepFun f κ 0 := by simp [iIndepFun]
@[simp] lemma indepFun_zero_right {β γ} [MeasurableSpace β] [MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} : IndepFun f g κ 0 := by simp [IndepFun]
@[simp] lemma indepFun_zero_left {β γ} [MeasurableSpace β] [MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} : IndepFun f g (0 : Kernel α Ω) μ := by simp [IndepFun]
lemma iIndepSets_congr (h : κ =ᵐ[μ] η) : iIndepSets π κ μ ↔ iIndepSets π η μ := by
peel 3
refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;>
· filter_upwards [h, h'] with a ha h'a
simpa [ha] using h'a
alias ⟨iIndepSets.congr, _⟩ := iIndepSets_congr
lemma indepSets_congr (h : κ =ᵐ[μ] η) : IndepSets s1 s2 κ μ ↔ IndepSets s1 s2 η μ := by
peel 4
refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;>
· filter_upwards [h, h'] with a ha h'a
simpa [ha] using h'a
alias ⟨IndepSets.congr, _⟩ := indepSets_congr
lemma iIndep_congr (h : κ =ᵐ[μ] η) : iIndep m κ μ ↔ iIndep m η μ :=
iIndepSets_congr h
alias ⟨iIndep.congr, _⟩ := iIndep_congr
lemma indep_congr {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ η : Kernel α Ω} (h : κ =ᵐ[μ] η) : Indep m₁ m₂ κ μ ↔ Indep m₁ m₂ η μ :=
indepSets_congr h
alias ⟨Indep.congr, _⟩ := indep_congr
lemma iIndepSet_congr (h : κ =ᵐ[μ] η) : iIndepSet s κ μ ↔ iIndepSet s η μ :=
iIndep_congr h
alias ⟨iIndepSet.congr, _⟩ := iIndepSet_congr
lemma indepSet_congr {s t : Set Ω} (h : κ =ᵐ[μ] η) : IndepSet s t κ μ ↔ IndepSet s t η μ :=
indep_congr h
alias ⟨indepSet.congr, _⟩ := indepSet_congr
lemma iIndepFun_congr {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)}
{f : ∀ x : ι, Ω → β x} (h : κ =ᵐ[μ] η) : iIndepFun f κ μ ↔ iIndepFun f η μ :=
iIndep_congr h
alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr
lemma indepFun_congr {β γ} [MeasurableSpace β] [MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} (h : κ =ᵐ[μ] η) : IndepFun f g κ μ ↔ IndepFun f g η μ :=
indep_congr h
alias ⟨IndepFun.congr, _⟩ := indepFun_congr
lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι)
{f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf
lemma iIndepSets.ae_isProbabilityMeasure (h : iIndepSets π κ μ) :
∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := by
filter_upwards [h.meas_biInter ∅ (f := fun _ ↦ Set.univ) (by simp)] with a ha
exact ⟨by simpa using ha⟩
lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) :
∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by
filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha]
lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) :
iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ
lemma iIndep.ae_isProbabilityMeasure (h : iIndep m κ μ) :
∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) :=
h.iIndepSets'.ae_isProbabilityMeasure
lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs
lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by
filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha
simp [← ha]
@[nontriviality, simp]
lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} {κ : Kernel α Ω}
[IsMarkovKernel κ] : iIndepSets m κ μ := by
rintro s f hf
obtain rfl | ⟨i, rfl⟩ : s = ∅ ∨ ∃ i, s = {i} := by
simpa using (subsingleton_of_subsingleton (s := s.toSet)).eq_empty_or_singleton
all_goals simp
@[nontriviality, simp]
lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} {κ : Kernel α Ω}
[IsMarkovKernel κ] : iIndep m κ μ := by simp [iIndep]
@[nontriviality, simp]
lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)}
{f : ∀ i, Ω → β i} [IsMarkovKernel κ] : iIndepFun f κ μ := by
simp [iIndepFun]
protected lemma iIndepFun.iIndep (hf : iIndepFun f κ μ) :
iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf
lemma iIndepFun.ae_isProbabilityMeasure (h : iIndepFun f κ μ) :
∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) :=
h.iIndep.ae_isProbabilityMeasure
lemma iIndepFun.meas_biInter (hf : iIndepFun f κ μ)
(hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs
lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun f κ μ)
(hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) :
∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs
lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
{f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ)
{s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) :
∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht
end ByDefinition
section Indep
variable {_mα : MeasurableSpace α}
@[symm]
theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α}
{s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) :
IndepSets s₂ s₁ κ μ := by
intros t1 t2 ht1 ht2
filter_upwards [h t2 t1 ht2 ht1] with a ha
rwa [Set.inter_comm, mul_comm]
@[symm]
theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} (h : Indep m₁ m₂ κ μ) :
Indep m₂ m₁ κ μ :=
IndepSets.symm h
theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] :
Indep m' ⊥ κ μ := by
intros s t _ ht
rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht
rcases eq_zero_or_isMarkovKernel κ with rfl| h
· simp
refine Filter.Eventually.of_forall (fun a ↦ ?_)
rcases ht with ht | ht
· rw [ht, Set.inter_empty, measure_empty, mul_zero]
· rw [ht, Set.inter_univ, measure_univ, mul_one]
theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] :
Indep ⊥ m' κ μ := (indep_bot_right m').symm
theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) :
IndepSet s ∅ κ μ := by
simp only [IndepSet, generateFrom_singleton_empty]
exact indep_bot_right _
theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) :
IndepSet ∅ s κ μ :=
(indepSet_empty_right s).symm
theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) :
IndepSets s₃ s₂ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2
theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) :
IndepSets s₁ s₃ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2)
theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) :
Indep m₃ m₂ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2
theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) :
Indep m₁ m₃ κ μ :=
fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2)
theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α}
(h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) :
IndepSets (s₁ ∪ s₂) s' κ μ := by
intro t1 t2 ht1 ht2
rcases (Set.mem_union _ _ _).mp ht1 with ht1₁ | ht1₂
· exact h₁ t1 t2 ht1₁ ht2
· exact h₂ t1 t2 ht1₂ ht2
@[simp]
theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ :=
⟨fun h =>
⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left,
indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩,
fun h => IndepSets.union h.left h.right⟩
theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) :
IndepSets (⋃ n, s n) s' κ μ := by
intro t1 t2 ht1 ht2
rw [Set.mem_iUnion] at ht1
obtain ⟨n, ht1⟩ := ht1
exact hyp n t1 t2 ht1 ht2
theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) :
IndepSets (⋃ n ∈ u, s n) s' κ μ := by
intro t1 t2 ht1 ht2
simp_rw [Set.mem_iUnion] at ht1
rcases ht1 with ⟨n, hpn, ht1⟩
exact hyp n hpn t1 t2 ht1 ht2
theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) :
IndepSets (s₁ ∩ s₂) s' κ μ :=
fun t1 t2 ht1 ht2 => h₁ t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2
theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h : ∃ n, IndepSets (s n) s' κ μ) :
IndepSets (⋂ n, s n) s' κ μ := by
intro t1 t2 ht1 ht2; obtain ⟨n, h⟩ := h; exact h t1 t2 (Set.mem_iInter.mp ht1 n) ht2
theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' κ μ) :
IndepSets (⋂ n ∈ u, s n) s' κ μ := by
intro t1 t2 ht1 ht2
rcases h with ⟨n, hn, h⟩
exact h t1 t2 (Set.biInter_subset_of_mem hn ht1) ht2
theorem iIndep_comap_mem_iff {f : ι → Set Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) κ μ ↔ iIndepSet f κ μ := by
simp_rw [← generateFrom_singleton, iIndepSet]
theorem iIndepSets_singleton_iff {s : ι → Set Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
iIndepSets (fun i ↦ {s i}) κ μ ↔
∀ S : Finset ι, ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := by
refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩
filter_upwards [h S] with a ha
have : ∀ i ∈ S, κ a (f i) = κ a (s i) := fun i hi ↦ by rw [hf i hi]
rwa [Finset.prod_congr rfl this, Set.iInter₂_congr hf]
theorem indepSets_singleton_iff {s t : Set Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} :
IndepSets {s} {t} κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t :=
⟨fun h ↦ h s t rfl rfl,
fun h s1 t1 hs1 ht1 ↦ by rwa [Set.mem_singleton_iff.mp hs1, Set.mem_singleton_iff.mp ht1]⟩
end Indep
/-! ### Deducing `Indep` from `iIndep` -/
section FromiIndepToIndep
variable {_mα : MeasurableSpace α}
theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} (h_indep : iIndepSets s κ μ) {i j : ι} (hij : i ≠ j) :
IndepSets (s i) (s j) κ μ := by
classical
intro t₁ t₂ ht₁ ht₂
have hf_m : ∀ x : ι, x ∈ ({i, j} : Finset ι) → ite (x = i) t₁ t₂ ∈ s x := by
intro x hx
rcases Finset.mem_insert.mp hx with hx | hx
· simp [hx, ht₁]
· simp [Finset.mem_singleton.mp hx, hij.symm, ht₂]
have h1 : t₁ = ite (i = i) t₁ t₂ := by simp only [if_true, eq_self_iff_true]
have h2 : t₂ = ite (j = i) t₁ t₂ := by simp only [hij.symm, if_false]
have h_inter : ⋂ (t : ι) (_ : t ∈ ({i, j} : Finset ι)), ite (t = i) t₁ t₂ =
ite (i = i) t₁ t₂ ∩ ite (j = i) t₁ t₂ := by
simp only [Finset.set_biInter_singleton, Finset.set_biInter_insert]
filter_upwards [h_indep {i, j} hf_m] with a h_indep'
have h_prod : (∏ t ∈ ({i, j} : Finset ι), κ a (ite (t = i) t₁ t₂))
= κ a (ite (i = i) t₁ t₂) * κ a (ite (j = i) t₁ t₂) := by
simp only [hij, Finset.prod_singleton, Finset.prod_insert, not_false_iff,
Finset.mem_singleton]
rw [h1]
nth_rw 2 [h2]
nth_rw 4 [h2]
rw [← h_inter, ← h_prod, h_indep']
theorem iIndep.indep {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α}
(h_indep : iIndep m κ μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) κ μ :=
iIndepSets.indepSets h_indep hij
theorem iIndepFun.indepFun {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun f κ μ) {i j : ι}
(hij : i ≠ j) : IndepFun (f i) (f j) κ μ :=
hf_Indep.indep hij
end FromiIndepToIndep
/-!
## π-system lemma
Independence of measurable spaces is equivalent to independence of generating π-systems.
-/
section FromMeasurableSpacesToSetsOfSets
/-! ### Independence of measurable space structures implies independence of generating π-systems -/
variable {_mα : MeasurableSpace α}
theorem iIndep.iIndepSets {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {m : ι → MeasurableSpace Ω}
{s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m κ μ) :
iIndepSets s κ μ :=
fun S f hfs =>
h_indep S fun x hxS =>
((hms x).symm ▸ measurableSet_generateFrom (hfs x hxS) : MeasurableSet[m x] (f x))
theorem Indep.indepSets {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {s1 s2 : Set (Set Ω)}
(h_indep : Indep (generateFrom s1) (generateFrom s2) κ μ) :
IndepSets s1 s2 κ μ :=
fun t1 t2 ht1 ht2 =>
h_indep t1 t2 (measurableSet_generateFrom ht1) (measurableSet_generateFrom ht2)
end FromMeasurableSpacesToSetsOfSets
section FromPiSystemsToMeasurableSpaces
/-! ### Independence of generating π-systems implies independence of measurable space structures -/
variable {_mα : MeasurableSpace α}
theorem IndepSets.indep_aux {m₂ m : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h2 : m₂ ≤ m)
(hp2 : IsPiSystem p2) (hpm2 : m₂ = generateFrom p2) (hyp : IndepSets p1 p2 κ μ) {t1 t2 : Set Ω}
(ht1 : t1 ∈ p1) (ht1m : MeasurableSet[m] t1) (ht2m : MeasurableSet[m₂] t2) :
∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2 := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp
induction t2, ht2m using induction_on_inter hpm2 hp2 with
| empty => simp
| basic u hu => exact hyp t1 u ht1 hu
| compl u hu ihu =>
filter_upwards [ihu] with a ha
rw [← Set.diff_eq, ← Set.diff_self_inter,
measure_diff inter_subset_left (ht1m.inter (h2 _ hu)).nullMeasurableSet (measure_ne_top _ _),
ha, measure_compl (h2 _ hu) (measure_ne_top _ _), measure_univ, ENNReal.mul_sub, mul_one]
exact fun _ _ ↦ measure_ne_top _ _
| iUnion f hfd hfm ihf =>
rw [← ae_all_iff] at ihf
filter_upwards [ihf] with a ha
rw [inter_iUnion, measure_iUnion, measure_iUnion hfd fun i ↦ h2 _ (hfm i)]
· simp only [ENNReal.tsum_mul_left, ha]
· exact hfd.mono fun i j h ↦ (h.inter_left' _).inter_right' _
· exact fun i ↦ .inter ht1m (h2 _ <| hfm i)
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem IndepSets.indep {m1 m2 m : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α}
[IsZeroOrMarkovKernel κ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ m) (h2 : m2 ≤ m) (hp1 : IsPiSystem p1)
(hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2)
(hyp : IndepSets p1 p2 κ μ) :
Indep m1 m2 κ μ := by
rcases eq_zero_or_isMarkovKernel κ with rfl | h
· simp
intros t1 t2 ht1 ht2
induction t1, ht1 using induction_on_inter hpm1 hp1 with
| empty =>
simp only [Set.empty_inter, measure_empty, zero_mul, eq_self_iff_true, Filter.eventually_true]
| basic t ht =>
refine IndepSets.indep_aux h2 hp2 hpm2 hyp ht (h1 _ ?_) ht2
rw [hpm1]
exact measurableSet_generateFrom ht
| compl t ht iht =>
filter_upwards [iht] with a ha
have : tᶜ ∩ t2 = t2 \ (t ∩ t2) := by
rw [Set.inter_comm t, Set.diff_self_inter, Set.diff_eq_compl_inter]
rw [this, Set.inter_comm t t2,
measure_diff Set.inter_subset_left ((h2 _ ht2).inter (h1 _ ht)).nullMeasurableSet
(measure_ne_top (κ a) _),
Set.inter_comm, ha, measure_compl (h1 _ ht) (measure_ne_top (κ a) t), measure_univ,
mul_comm (1 - κ a t), ENNReal.mul_sub (fun _ _ ↦ measure_ne_top (κ a) _), mul_one, mul_comm]
| iUnion f hf_disj hf_meas h =>
rw [← ae_all_iff] at h
filter_upwards [h] with a ha
rw [Set.inter_comm, Set.inter_iUnion, measure_iUnion]
· rw [measure_iUnion hf_disj (fun i ↦ h1 _ (hf_meas i))]
rw [← ENNReal.tsum_mul_right]
congr 1 with i
rw [Set.inter_comm t2, ha i]
· intros i j hij
rw [Function.onFun, Set.inter_comm t2, Set.inter_comm t2]
exact Disjoint.inter_left _ (Disjoint.inter_right _ (hf_disj hij))
· exact fun i ↦ (h2 _ ht2).inter (h1 _ (hf_meas i))
theorem IndepSets.indep' {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ]
{p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s)
(hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 κ μ) :
Indep (generateFrom p1) (generateFrom p2) κ μ :=
hyp.indep (generateFrom_le hp1m) (generateFrom_le hp2m) hp1 hp2 rfl rfl
variable {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α}
theorem indepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)}
{S T : Set ι} (h_indep : iIndepSets s κ μ) (hST : Disjoint S T) :
IndepSets (piiUnionInter s S) (piiUnionInter s T) κ μ := by
rintro t1 t2 ⟨p1, hp1, f1, ht1_m, ht1_eq⟩ ⟨p2, hp2, f2, ht2_m, ht2_eq⟩
classical
let g i := ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ
have h_P_inter : ∀ᵐ a ∂μ, κ a (t1 ∩ t2) = ∏ n ∈ p1 ∪ p2, κ a (g n) := by
have hgm : ∀ i ∈ p1 ∪ p2, g i ∈ s i := by
intro i hi_mem_union
rw [Finset.mem_union] at hi_mem_union
rcases hi_mem_union with hi1 | hi2
· have hi2 : i ∉ p2 := fun hip2 => Set.disjoint_left.mp hST (hp1 hi1) (hp2 hip2)
simp_rw [g, if_pos hi1, if_neg hi2, Set.inter_univ]
exact ht1_m i hi1
· have hi1 : i ∉ p1 := fun hip1 => Set.disjoint_right.mp hST (hp2 hi2) (hp1 hip1)
simp_rw [g, if_neg hi1, if_pos hi2, Set.univ_inter]
exact ht2_m i hi2
have h_p1_inter_p2 :
((⋂ x ∈ p1, f1 x) ∩ ⋂ x ∈ p2, f2 x) =
⋂ i ∈ p1 ∪ p2, ite (i ∈ p1) (f1 i) Set.univ ∩ ite (i ∈ p2) (f2 i) Set.univ := by
ext1 x
simp only [Set.mem_ite_univ_right, Set.mem_inter_iff, Set.mem_iInter, Finset.mem_union]
exact
⟨fun h i _ => ⟨h.1 i, h.2 i⟩, fun h =>
⟨fun i hi => (h i (Or.inl hi)).1 hi, fun i hi => (h i (Or.inr hi)).2 hi⟩⟩
filter_upwards [h_indep _ hgm] with a ha
rw [ht1_eq, ht2_eq, h_p1_inter_p2, ← ha]
filter_upwards [h_P_inter, h_indep p1 ht1_m, h_indep p2 ht2_m, h_indep.ae_isProbabilityMeasure]
with a h_P_inter ha1 ha2 h'
have h_μg : ∀ n, κ a (g n) = (ite (n ∈ p1) (κ a (f1 n)) 1) * (ite (n ∈ p2) (κ a (f2 n)) 1) := by
intro n
dsimp only [g]
split_ifs with h1 h2
· exact absurd rfl (Set.disjoint_iff_forall_ne.mp hST (hp1 h1) (hp2 h2))
all_goals simp only [measure_univ, one_mul, mul_one, Set.inter_univ, Set.univ_inter]
simp_rw [h_P_inter, h_μg, Finset.prod_mul_distrib,
Finset.prod_ite_mem (p1 ∪ p2) p1 (fun x ↦ κ a (f1 x)), Finset.union_inter_cancel_left,
Finset.prod_ite_mem (p1 ∪ p2) p2 (fun x => κ a (f2 x)), Finset.union_inter_cancel_right, ht1_eq,
← ha1, ht2_eq, ← ha2]
theorem iIndepSet.indep_generateFrom_of_disjoint {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (S T : Set ι) (hST : Disjoint S T) :
Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) κ μ := by
classical
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel hs.ae_isProbabilityMeasure hμ
apply Indep.congr (Filter.EventuallyEq.symm η_eq)
rw [← generateFrom_piiUnionInter_singleton_left, ← generateFrom_piiUnionInter_singleton_left]
refine
IndepSets.indep'
(fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht))
(fun t ht => generateFrom_piiUnionInter_le _ ?_ _ _ (measurableSet_generateFrom ht)) ?_ ?_ ?_
· exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k
· exact fun k => generateFrom_le fun t ht => (Set.mem_singleton_iff.1 ht).symm ▸ hsm k
· exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _
· exact isPiSystem_piiUnionInter _ (fun k => IsPiSystem.singleton _) _
· exact indepSets_piiUnionInter_of_disjoint (iIndep.iIndepSets (fun n => rfl) (hs.congr η_eq)) hST
theorem indep_iSup_of_disjoint {m : ι → MeasurableSpace Ω}
(h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m κ μ) {S T : Set ι} (hST : Disjoint S T) :
Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) κ μ := by
classical
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel h_indep.ae_isProbabilityMeasure hμ
apply Indep.congr (Filter.EventuallyEq.symm η_eq)
refine
IndepSets.indep (iSup₂_le fun i _ => h_le i) (iSup₂_le fun i _ => h_le i) ?_ ?_
(generateFrom_piiUnionInter_measurableSet m S).symm
(generateFrom_piiUnionInter_measurableSet m T).symm ?_
· exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _
· exact isPiSystem_piiUnionInter _ (fun n => @isPiSystem_measurableSet Ω (m n)) _
· exact indepSets_piiUnionInter_of_disjoint (h_indep.congr η_eq) hST
theorem indep_iSup_of_directed_le {Ω} {m : ι → MeasurableSpace Ω} {m' m0 : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (h_indep : ∀ i, Indep (m i) m' κ μ)
(h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0) (hm : Directed (· ≤ ·) m) :
Indep (⨆ i, m i) m' κ μ := by
let p : ι → Set (Set Ω) := fun n => { t | MeasurableSet[m n] t }
have hp : ∀ n, IsPiSystem (p n) := fun n => @isPiSystem_measurableSet Ω (m n)
have h_gen_n : ∀ n, m n = generateFrom (p n) := fun n =>
(@generateFrom_measurableSet Ω (m n)).symm
have hp_supr_pi : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp hm
let p' := { t : Set Ω | MeasurableSet[m'] t }
have hp'_pi : IsPiSystem p' := @isPiSystem_measurableSet Ω m'
have h_gen' : m' = generateFrom p' := (@generateFrom_measurableSet Ω m').symm
-- the π-systems defined are independent
have h_pi_system_indep : IndepSets (⋃ n, p n) p' κ μ := by
refine IndepSets.iUnion ?_
conv at h_indep =>
intro i
rw [h_gen_n i, h_gen']
exact fun n => (h_indep n).indepSets
-- now go from π-systems to σ-algebras
refine IndepSets.indep (iSup_le h_le) h_le' hp_supr_pi hp'_pi ?_ h_gen' h_pi_system_indep
exact (generateFrom_iUnion_measurableSet _).symm
theorem iIndepSet.indep_generateFrom_lt [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) :
Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) κ μ := by
convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {i} { j | j < i }
(Set.disjoint_singleton_left.mpr (lt_irrefl _)) using 1
simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton']
theorem iIndepSet.indep_generateFrom_le [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (i : ι) {k : ι} (hk : i < k) :
Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) κ μ := by
convert iIndepSet.indep_generateFrom_of_disjoint hsm hs {k} { j | j ≤ i }
(Set.disjoint_singleton_left.mpr hk.not_le) using 1
simp only [Set.mem_singleton_iff, exists_prop, exists_eq_left, Set.setOf_eq_eq_singleton']
theorem iIndepSet.indep_generateFrom_le_nat {s : ℕ → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s κ μ) (n : ℕ) :
Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) κ μ :=
iIndepSet.indep_generateFrom_le hsm hs _ n.lt_succ_self
theorem indep_iSup_of_monotone [SemilatticeSup ι] {Ω} {m : ι → MeasurableSpace Ω}
{m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ]
(h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0)
(hm : Monotone m) :
Indep (⨆ i, m i) m' κ μ :=
indep_iSup_of_directed_le h_indep h_le h_le' (Monotone.directed_le hm)
theorem indep_iSup_of_antitone [SemilatticeInf ι] {Ω} {m : ι → MeasurableSpace Ω}
{m' m0 : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ]
(h_indep : ∀ i, Indep (m i) m' κ μ) (h_le : ∀ i, m i ≤ m0) (h_le' : m' ≤ m0)
(hm : Antitone m) :
Indep (⨆ i, m i) m' κ μ :=
indep_iSup_of_directed_le h_indep h_le h_le' hm.directed_le
theorem iIndepSets.piiUnionInter_of_not_mem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι}
(hp_ind : iIndepSets π κ μ) (haS : a ∉ S) :
IndepSets (piiUnionInter π S) (π a) κ μ := by
rintro t1 t2 ⟨s, hs_mem, ft1, hft1_mem, ht1_eq⟩ ht2_mem_pia
rw [Finset.coe_subset] at hs_mem
classical
let f := fun n => ite (n = a) t2 (ite (n ∈ s) (ft1 n) Set.univ)
have h_f_mem : ∀ n ∈ insert a s, f n ∈ π n := by
intro n hn_mem_insert
dsimp only [f]
rcases Finset.mem_insert.mp hn_mem_insert with hn_mem | hn_mem
· simp [hn_mem, ht2_mem_pia]
· have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hn_mem)
simp [hn_ne_a, hn_mem, hft1_mem n hn_mem]
have h_f_mem_pi : ∀ n ∈ s, f n ∈ π n := fun x hxS => h_f_mem x (by simp [hxS])
have h_t1 : t1 = ⋂ n ∈ s, f n := by
suffices h_forall : ∀ n ∈ s, f n = ft1 n by
rw [ht1_eq]
ext x
simp_rw [Set.mem_iInter]
conv => lhs; intro i hns; rw [← h_forall i hns]
intro n hnS
have hn_ne_a : n ≠ a := by rintro rfl; exact haS (hs_mem hnS)
simp_rw [f, if_pos hnS, if_neg hn_ne_a]
have h_μ_t1 : ∀ᵐ a' ∂μ, κ a' t1 = ∏ n ∈ s, κ a' (f n) := by
filter_upwards [hp_ind s h_f_mem_pi] with a' ha'
rw [h_t1, ← ha']
have h_t2 : t2 = f a := by simp [f]
have h_μ_inter : ∀ᵐ a' ∂μ, κ a' (t1 ∩ t2) = ∏ n ∈ insert a s, κ a' (f n) := by
have h_t1_inter_t2 : t1 ∩ t2 = ⋂ n ∈ insert a s, f n := by
rw [h_t1, h_t2, Finset.set_biInter_insert, Set.inter_comm]
filter_upwards [hp_ind (insert a s) h_f_mem] with a' ha'
rw [h_t1_inter_t2, ← ha']
have has : a ∉ s := fun has_mem => haS (hs_mem has_mem)
filter_upwards [h_μ_t1, h_μ_inter] with a' ha1 ha2
rw [ha2, Finset.prod_insert has, h_t2, mul_comm, ha1]
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem iIndepSets.iIndep (m : ι → MeasurableSpace Ω)
(h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n))
(h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π κ μ) :
iIndep m κ μ := by
classical
rcases eq_or_ne μ 0 with rfl | hμ
· simp
obtain ⟨η, η_eq, hη⟩ : ∃ (η : Kernel α Ω), κ =ᵐ[μ] η ∧ IsMarkovKernel η :=
exists_ae_eq_isMarkovKernel h_ind.ae_isProbabilityMeasure hμ
apply iIndep.congr (Filter.EventuallyEq.symm η_eq)
intro s f
refine Finset.induction ?_ ?_ s
· simp only [Finset.not_mem_empty, Set.mem_setOf_eq, IsEmpty.forall_iff, implies_true,
Set.iInter_of_empty, Set.iInter_univ, measure_univ, Finset.prod_empty,
Filter.eventually_true, forall_true_left]
· intro a S ha_notin_S h_rec hf_m
have hf_m_S : ∀ x ∈ S, MeasurableSet[m x] (f x) := fun x hx => hf_m x (by simp [hx])
let p := piiUnionInter π S
set m_p := generateFrom p with hS_eq_generate
have h_indep : Indep m_p (m a) η μ := by
have hp : IsPiSystem p := isPiSystem_piiUnionInter π h_pi S
have h_le' : ∀ i, generateFrom (π i) ≤ _mΩ := fun i ↦ (h_generate i).symm.trans_le (h_le i)
have hm_p : m_p ≤ _mΩ := generateFrom_piiUnionInter_le π h_le' S
exact IndepSets.indep hm_p (h_le a) hp (h_pi a) hS_eq_generate (h_generate a)
(iIndepSets.piiUnionInter_of_not_mem (h_ind.congr η_eq) ha_notin_S)
have h := h_indep.symm (f a) (⋂ n ∈ S, f n) (hf_m a (Finset.mem_insert_self a S)) ?_
· filter_upwards [h_rec hf_m_S, h] with a' ha' h'
rwa [Finset.set_biInter_insert, Finset.prod_insert ha_notin_S, ← ha']
· have h_le_p : ∀ i ∈ S, m i ≤ m_p := by
intros n hn
rw [hS_eq_generate, h_generate n]
exact le_generateFrom_piiUnionInter (S : Set ι) hn
have h_S_f : ∀ i ∈ S, MeasurableSet[m_p] (f i) :=
fun i hi ↦ (h_le_p i hi) (f i) (hf_m_S i hi)
exact S.measurableSet_biInter h_S_f
end FromPiSystemsToMeasurableSpaces
section IndepSet
/-! ### Independence of measurable sets
We prove the following equivalences on `IndepSet`, for measurable sets `s, t`.
* `IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t`,
* `IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ`.
-/
variable {_mα : MeasurableSpace α}
theorem iIndepSet_iff_iIndepSets_singleton {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f κ μ ↔ iIndepSets (fun i ↦ {f i}) κ μ :=
⟨iIndep.iIndepSets fun _ ↦ rfl,
iIndepSets.iIndep _ (fun i ↦ generateFrom_le <| by rintro t (rfl : t = _); exact hf _) _
(fun _ ↦ IsPiSystem.singleton _) fun _ ↦ rfl⟩
theorem iIndepSet.meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {f : ι → Set Ω} (h : iIndepSet f κ μ) (s : Finset ι) :
∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) :=
iIndep.iIndepSets (fun _ ↦ rfl) h _ (by simp)
theorem iIndepSet_iff_meas_biInter {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f κ μ ↔ ∀ s, ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) :=
(iIndepSet_iff_iIndepSets_singleton hf).trans iIndepSets_singleton_iff
theorem iIndepSets.iIndepSet_of_mem {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α} {π : ι → Set (Set Ω)} {f : ι → Set Ω}
(hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i)) (hπ : iIndepSets π κ μ) :
iIndepSet f κ μ :=
(iIndepSet_iff_meas_biInter hf).2 fun _t ↦ hπ.meas_biInter _ fun _i _ ↦ hfπ _
variable {s t : Set Ω} (S T : Set (Set Ω))
theorem indepSet_iff_indepSets_singleton {m0 : MeasurableSpace Ω} (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α)
[IsZeroOrMarkovKernel κ] :
IndepSet s t κ μ ↔ IndepSets {s} {t} κ μ :=
⟨Indep.indepSets, fun h =>
IndepSets.indep
(generateFrom_le fun u hu => by rwa [Set.mem_singleton_iff.mp hu])
(generateFrom_le fun u hu => by rwa [Set.mem_singleton_iff.mp hu])
(IsPiSystem.singleton s) (IsPiSystem.singleton t) rfl rfl h⟩
theorem indepSet_iff_measure_inter_eq_mul {_m0 : MeasurableSpace Ω} (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (κ : Kernel α Ω) (μ : Measure α)
[IsZeroOrMarkovKernel κ] :
IndepSet s t κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t :=
(indepSet_iff_indepSets_singleton hs_meas ht_meas κ μ).trans indepSets_singleton_iff
theorem IndepSet.measure_inter_eq_mul {_m0 : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α)
(h : IndepSet s t κ μ) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t :=
Indep.indepSets h _ _ (by simp) (by simp)
theorem IndepSets.indepSet_of_mem {_m0 : MeasurableSpace Ω} (hs : s ∈ S) (ht : t ∈ T)
(hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t)
(κ : Kernel α Ω) (μ : Measure α) [IsZeroOrMarkovKernel κ]
(h_indep : IndepSets S T κ μ) :
IndepSet s t κ μ :=
(indepSet_iff_measure_inter_eq_mul hs_meas ht_meas κ μ).mpr (h_indep s t hs ht)
theorem Indep.indepSet_of_measurableSet {m₁ m₂ _ : MeasurableSpace Ω} {κ : Kernel α Ω}
{μ : Measure α}
(h_indep : Indep m₁ m₂ κ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s)
(ht : MeasurableSet[m₂] t) :
IndepSet s t κ μ := by
refine fun s' t' hs' ht' => h_indep s' t' ?_ ?_
· induction s', hs' using generateFrom_induction with
| hC t ht => exact ht ▸ hs
| empty => exact @MeasurableSet.empty _ m₁
| compl u _ hu => exact hu.compl
| iUnion f _ hf => exact .iUnion hf
· induction t', ht' using generateFrom_induction with
| hC s hs => exact hs ▸ ht
| empty => exact @MeasurableSet.empty _ m₂
| compl u _ hu => exact hu.compl
| iUnion f _ hf => exact .iUnion hf
theorem indep_iff_forall_indepSet (m₁ m₂ : MeasurableSpace Ω) {_m0 : MeasurableSpace Ω}
(κ : Kernel α Ω) (μ : Measure α) :
Indep m₁ m₂ κ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t κ μ :=
⟨fun h => fun _s _t hs ht => h.indepSet_of_measurableSet hs ht, fun h s t hs ht =>
h s t hs ht s t (measurableSet_generateFrom (Set.mem_singleton s))
(measurableSet_generateFrom (Set.mem_singleton t))⟩
end IndepSet
section IndepFun
/-! ### Independence of random variables
-/
variable {β β' γ γ' : Type*} {_mα : MeasurableSpace α} {_mΩ : MeasurableSpace Ω}
{κ : Kernel α Ω} {μ : Measure α} {f : Ω → β} {g : Ω → β'}
theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β}
{mβ' : MeasurableSpace β'} :
IndepFun f g κ μ ↔
∀ s t, MeasurableSet s → MeasurableSet t
→ ∀ᵐ a ∂μ, κ a (f ⁻¹' s ∩ g ⁻¹' t) = κ a (f ⁻¹' s) * κ a (g ⁻¹' t) := by
constructor <;> intro h
· refine fun s t hs ht => h (f ⁻¹' s) (g ⁻¹' t) ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩
· rintro _ _ ⟨s, hs, rfl⟩ ⟨t, ht, rfl⟩; exact h s t hs ht
alias ⟨IndepFun.measure_inter_preimage_eq_mul, _⟩ := indepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*}
(m : ∀ x, MeasurableSpace (β x)) (f : ∀ i, Ω → β i) :
iIndepFun f κ μ ↔
∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)),
∀ᵐ a ∂μ, κ a (⋂ i ∈ S, (f i) ⁻¹' (sets i)) = ∏ i ∈ S, κ a ((f i) ⁻¹' (sets i)) := by
refine ⟨fun h S sets h_meas => h _ fun i hi_mem => ⟨sets i, h_meas i hi_mem, rfl⟩, ?_⟩
intro h S setsΩ h_meas
classical
let setsβ : ∀ i : ι, Set (β i) := fun i =>
dite (i ∈ S) (fun hi_mem => (h_meas i hi_mem).choose) fun _ => Set.univ
have h_measβ : ∀ i ∈ S, MeasurableSet[m i] (setsβ i) := by
intro i hi_mem
simp_rw [setsβ, dif_pos hi_mem]
exact (h_meas i hi_mem).choose_spec.1
have h_preim : ∀ i ∈ S, setsΩ i = f i ⁻¹' setsβ i := by
intro i hi_mem
simp_rw [setsβ, dif_pos hi_mem]
exact (h_meas i hi_mem).choose_spec.2.symm
have h_left_eq : ∀ a, κ a (⋂ i ∈ S, setsΩ i) = κ a (⋂ i ∈ S, (f i) ⁻¹' (setsβ i)) := by
intro a
congr with x
simp_rw [Set.mem_iInter]
constructor <;> intro h i hi_mem <;> specialize h i hi_mem
· rwa [h_preim i hi_mem] at h
· rwa [h_preim i hi_mem]
have h_right_eq : ∀ a, (∏ i ∈ S, κ a (setsΩ i)) = ∏ i ∈ S, κ a ((f i) ⁻¹' (setsβ i)) := by
refine fun a ↦ Finset.prod_congr rfl fun i hi_mem => ?_
rw [h_preim i hi_mem]
filter_upwards [h S h_measβ] with a ha
rw [h_left_eq a, h_right_eq a, ha]
alias ⟨iIndepFun.measure_inter_preimage_eq_mul, _⟩ := iIndepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun.congr' {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{f g : Π i, Ω → β i} (hf : iIndepFun f κ μ)
(h : ∀ i, ∀ᵐ a ∂μ, f i =ᵐ[κ a] g i) :
iIndepFun g κ μ := by
rw [iIndepFun_iff_measure_inter_preimage_eq_mul] at hf ⊢
intro S sets hmeas
have : ∀ᵐ a ∂μ, ∀ i ∈ S, f i =ᵐ[κ a] g i :=
(ae_ball_iff (Finset.countable_toSet S)).2 (fun i hi ↦ h i)
filter_upwards [this, hf S hmeas] with a ha h'a
have A i (hi : i ∈ S) : (κ a) (g i ⁻¹' sets i) = (κ a) (f i ⁻¹' sets i) := by
apply measure_congr
filter_upwards [ha i hi] with ω hω
change (g i ω ∈ sets i) = (f i ω ∈ sets i)
simp [hω]
have B : (κ a) (⋂ i ∈ S, g i ⁻¹' sets i) = (κ a) (⋂ i ∈ S, f i ⁻¹' sets i) := by
apply measure_congr
filter_upwards [(ae_ball_iff (Finset.countable_toSet S)).2 ha] with ω hω
change (ω ∈ ⋂ i ∈ S, g i ⁻¹' sets i) = (ω ∈ ⋂ i ∈ S, f i ⁻¹' sets i)
simp +contextual [hω]
convert h'a using 2 with i hi
exact A i hi
lemma iIndepFun.comp {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f κ μ) (g : ∀ i, β i → γ i) (hg : ∀ i, Measurable (g i)) :
iIndepFun (fun i ↦ g i ∘ f i) κ μ := by
rw [iIndepFun_iff_measure_inter_preimage_eq_mul] at h ⊢
refine fun t s hs ↦ ?_
have := h t (sets := fun i ↦ g i ⁻¹' (s i)) (fun i a ↦ hg i (hs i a))
filter_upwards [this] with a ha
simp_rw [Set.preimage_comp]
exact ha
lemma iIndepFun.comp₀ {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f κ μ) (g : ∀ i, β i → γ i)
(hf : ∀ i, AEMeasurable (f i) (κ ∘ₘ μ)) (hg : ∀ i, AEMeasurable (g i) ((κ ∘ₘ μ).map (f i))) :
iIndepFun (fun i ↦ g i ∘ f i) κ μ := by
have h : iIndepFun (fun i ↦ ((hg i).mk (g i)) ∘ f i) κ μ :=
iIndepFun.comp h (fun i ↦ (hg i).mk (g i)) fun i ↦ (hg i).measurable_mk
have h_ae i := ae_of_ae_map (hf i) (hg i).ae_eq_mk.symm
exact iIndepFun.congr' h fun i ↦ Measure.ae_ae_of_ae_comp (h_ae i)
| theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrMarkovKernel κ] (hf : Measurable f) (hg : Measurable g) :
IndepFun f g κ μ ↔
∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) κ μ := by
refine indepFun_iff_measure_inter_preimage_eq_mul.trans ?_
constructor <;> intro h s t hs ht <;> specialize h s t hs ht
· rwa [indepSet_iff_measure_inter_eq_mul (hf hs) (hg ht) κ μ]
· rwa [← indepSet_iff_measure_inter_eq_mul (hf hs) (hg ht) κ μ]
@[symm]
nonrec theorem IndepFun.symm {_ : MeasurableSpace β} {_ : MeasurableSpace β'}
(hfg : IndepFun f g κ μ) : IndepFun g f κ μ := hfg.symm
theorem IndepFun.congr' {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{f' : Ω → β} {g' : Ω → β'} (hfg : IndepFun f g κ μ)
| Mathlib/Probability/Independence/Kernel.lean | 959 | 973 |
/-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Cast
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Tactic.DeriveFintype
/-!
# Sign function
This file defines the sign function for types with zero and a decidable less-than relation, and
proves some basic theorems about it.
-/
-- Don't generate unnecessary `sizeOf_spec` lemmas which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- The type of signs. -/
inductive SignType
| zero
| neg
| pos
deriving DecidableEq, Inhabited, Fintype
namespace SignType
instance : Zero SignType :=
⟨zero⟩
instance : One SignType :=
⟨pos⟩
instance : Neg SignType :=
⟨fun s =>
match s with
| neg => pos
| zero => zero
| pos => neg⟩
@[simp]
theorem zero_eq_zero : zero = 0 :=
rfl
@[simp]
theorem neg_eq_neg_one : neg = -1 :=
rfl
@[simp]
theorem pos_eq_one : pos = 1 :=
rfl
instance : Mul SignType :=
⟨fun x y =>
match x with
| neg => -y
| zero => zero
| pos => y⟩
/-- The less-than-or-equal relation on signs. -/
protected inductive LE : SignType → SignType → Prop
| of_neg (a) : SignType.LE neg a
| zero : SignType.LE zero zero
| of_pos (a) : SignType.LE a pos
instance : LE SignType :=
⟨SignType.LE⟩
instance LE.decidableRel : DecidableRel SignType.LE := fun a b => by
cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩)
instance decidableEq : DecidableEq SignType := fun a b => by
cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩)
private lemma mul_comm : ∀ (a b : SignType), a * b = b * a := by rintro ⟨⟩ ⟨⟩ <;> rfl
private lemma mul_assoc : ∀ (a b c : SignType), (a * b) * c = a * (b * c) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩ <;> rfl
/- We can define a `Field` instance on `SignType`, but it's not mathematically sensible,
so we only define the `CommGroupWithZero`. -/
instance : CommGroupWithZero SignType where
zero := 0
one := 1
mul := (· * ·)
inv := id
mul_zero a := by cases a <;> rfl
zero_mul a := by cases a <;> rfl
mul_one a := by cases a <;> rfl
one_mul a := by cases a <;> rfl
mul_inv_cancel a ha := by cases a <;> trivial
mul_comm := mul_comm
mul_assoc := mul_assoc
exists_pair_ne := ⟨0, 1, by rintro ⟨_⟩⟩
inv_zero := rfl
private lemma le_antisymm (a b : SignType) (_ : a ≤ b) (_ : b ≤ a) : a = b := by
cases a <;> cases b <;> trivial
private lemma le_trans (a b c : SignType) (_ : a ≤ b) (_ : b ≤ c) : a ≤ c := by
cases a <;> cases b <;> cases c <;> tauto
instance : LinearOrder SignType where
le := (· ≤ ·)
le_refl a := by cases a <;> constructor
le_total a b := by cases a <;> cases b <;> first | left; constructor | right; constructor
le_antisymm := le_antisymm
le_trans := le_trans
toDecidableLE := LE.decidableRel
toDecidableEq := SignType.decidableEq
instance : BoundedOrder SignType where
top := 1
le_top := LE.of_pos
bot := -1
bot_le :=
#adaptation_note /-- https://github.com/leanprover/lean4/pull/6053
Added `by exact`, but don't understand why it was needed. -/
by exact LE.of_neg
instance : HasDistribNeg SignType :=
{ neg_neg := fun x => by cases x <;> rfl
neg_mul := fun x y => by cases x <;> cases y <;> rfl
mul_neg := fun x y => by cases x <;> cases y <;> rfl }
/-- `SignType` is equivalent to `Fin 3`. -/
def fin3Equiv : SignType ≃* Fin 3 where
toFun a :=
match a with
| 0 => ⟨0, by simp⟩
| 1 => ⟨1, by simp⟩
| -1 => ⟨2, by simp⟩
invFun a :=
match a with
| ⟨0, _⟩ => 0
| ⟨1, _⟩ => 1
| ⟨2, _⟩ => -1
left_inv a := by cases a <;> rfl
right_inv a :=
match a with
| ⟨0, _⟩ => by simp
| ⟨1, _⟩ => by simp
| ⟨2, _⟩ => by simp
map_mul' a b := by
cases a <;> cases b <;> rfl
section CaseBashing
theorem nonneg_iff {a : SignType} : 0 ≤ a ↔ a = 0 ∨ a = 1 := by decide +revert
theorem nonneg_iff_ne_neg_one {a : SignType} : 0 ≤ a ↔ a ≠ -1 := by decide +revert
theorem neg_one_lt_iff {a : SignType} : -1 < a ↔ 0 ≤ a := by decide +revert
theorem nonpos_iff {a : SignType} : a ≤ 0 ↔ a = -1 ∨ a = 0 := by decide +revert
theorem nonpos_iff_ne_one {a : SignType} : a ≤ 0 ↔ a ≠ 1 := by decide +revert
theorem lt_one_iff {a : SignType} : a < 1 ↔ a ≤ 0 := by decide +revert
@[simp]
theorem neg_iff {a : SignType} : a < 0 ↔ a = -1 := by decide +revert
@[simp]
theorem le_neg_one_iff {a : SignType} : a ≤ -1 ↔ a = -1 :=
le_bot_iff
@[simp]
theorem pos_iff {a : SignType} : 0 < a ↔ a = 1 := by decide +revert
@[simp]
theorem one_le_iff {a : SignType} : 1 ≤ a ↔ a = 1 :=
top_le_iff
@[simp]
theorem neg_one_le (a : SignType) : -1 ≤ a :=
bot_le
@[simp]
theorem le_one (a : SignType) : a ≤ 1 :=
le_top
@[simp]
theorem not_lt_neg_one (a : SignType) : ¬a < -1 :=
not_lt_bot
@[simp]
theorem not_one_lt (a : SignType) : ¬1 < a :=
not_top_lt
@[simp]
theorem self_eq_neg_iff (a : SignType) : a = -a ↔ a = 0 := by decide +revert
@[simp]
theorem neg_eq_self_iff (a : SignType) : -a = a ↔ a = 0 := by decide +revert
@[simp]
theorem neg_one_lt_one : (-1 : SignType) < 1 :=
bot_lt_top
end CaseBashing
section cast
variable {α : Type*} [Zero α] [One α] [Neg α]
/-- Turn a `SignType` into zero, one, or minus one. This is a coercion instance. -/
@[coe]
def cast : SignType → α
| zero => 0
| pos => 1
| neg => -1
/-- This is a `CoeTail` since the type on the right (trivially) determines the type on the left.
`outParam`-wise it could be a `Coe`, but we don't want to try applying this instance for a
coercion to any `α`.
-/
instance : CoeTail SignType α :=
⟨cast⟩
/-- Casting out of `SignType` respects composition with functions preserving `0, 1, -1`. -/
lemma map_cast' {β : Type*} [One β] [Neg β] [Zero β]
(f : α → β) (h₁ : f 1 = 1) (h₂ : f 0 = 0) (h₃ : f (-1) = -1) (s : SignType) :
f s = s := by
cases s <;> simp only [SignType.cast, h₁, h₂, h₃]
/-- Casting out of `SignType` respects composition with suitable bundled homomorphism types. -/
lemma map_cast {α β F : Type*} [AddGroupWithOne α] [One β] [SubtractionMonoid β]
[FunLike F α β] [AddMonoidHomClass F α β] [OneHomClass F α β] (f : F) (s : SignType) :
f s = s := by
apply map_cast' <;> simp
@[simp]
theorem coe_zero : ↑(0 : SignType) = (0 : α) :=
rfl
@[simp]
theorem coe_one : ↑(1 : SignType) = (1 : α) :=
rfl
@[simp]
theorem coe_neg_one : ↑(-1 : SignType) = (-1 : α) :=
rfl
@[simp, norm_cast]
lemma coe_neg {α : Type*} [One α] [SubtractionMonoid α] (s : SignType) :
(↑(-s) : α) = -↑s := by
cases s <;> simp
/-- Casting `SignType → ℤ → α` is the same as casting directly `SignType → α`. -/
@[simp, norm_cast]
lemma intCast_cast {α : Type*} [AddGroupWithOne α] (s : SignType) : ((s : ℤ) : α) = s :=
map_cast' _ Int.cast_one Int.cast_zero (@Int.cast_one α _ ▸ Int.cast_neg 1) _
end cast
/-- `SignType.cast` as a `MulWithZeroHom`. -/
@[simps]
def castHom {α} [MulZeroOneClass α] [HasDistribNeg α] : SignType →*₀ α where
toFun := cast
map_zero' := rfl
map_one' := rfl
map_mul' x y := by cases x <;> cases y <;> simp [zero_eq_zero, pos_eq_one, neg_eq_neg_one]
theorem univ_eq : (Finset.univ : Finset SignType) = {0, -1, 1} := by
decide
theorem range_eq {α} (f : SignType → α) : Set.range f = {f zero, f neg, f pos} := by
classical rw [← Fintype.coe_image_univ, univ_eq]
classical simp [Finset.coe_insert]
@[simp, norm_cast] lemma coe_mul {α} [MulZeroOneClass α] [HasDistribNeg α] (a b : SignType) :
↑(a * b) = (a : α) * b :=
map_mul SignType.castHom _ _
@[simp, norm_cast] lemma coe_pow {α} [MonoidWithZero α] [HasDistribNeg α] (a : SignType) (k : ℕ) :
↑(a ^ k) = (a : α) ^ k :=
map_pow SignType.castHom _ _
@[simp, norm_cast] lemma coe_zpow {α} [GroupWithZero α] [HasDistribNeg α] (a : SignType) (k : ℤ) :
↑(a ^ k) = (a : α) ^ k :=
map_zpow₀ SignType.castHom _ _
end SignType
-- The lemma `exists_signed_sum` needs explicit universe handling in its statement.
universe u
variable {α : Type u}
open SignType
section Preorder
variable [Zero α] [Preorder α] [DecidableLT α] {a : α}
/-- The sign of an element is 1 if it's positive, -1 if negative, 0 otherwise. -/
def SignType.sign : α →o SignType :=
⟨fun a => if 0 < a then 1 else if a < 0 then -1 else 0, fun a b h => by
dsimp
split_ifs with h₁ h₂ h₃ h₄ _ _ h₂ h₃ <;> try constructor
· cases lt_irrefl 0 (h₁.trans <| h.trans_lt h₃)
· cases h₂ (h₁.trans_le h)
· cases h₄ (h.trans_lt h₃)⟩
theorem sign_apply : sign a = ite (0 < a) 1 (ite (a < 0) (-1) 0) :=
rfl
@[simp]
theorem sign_zero : sign (0 : α) = 0 := by simp [sign_apply]
@[simp]
theorem sign_pos (ha : 0 < a) : sign a = 1 := by rwa [sign_apply, if_pos]
@[simp]
theorem sign_neg (ha : a < 0) : sign a = -1 := by rwa [sign_apply, if_neg <| asymm ha, if_pos]
theorem sign_eq_one_iff : sign a = 1 ↔ 0 < a := by
refine ⟨fun h => ?_, fun h => sign_pos h⟩
by_contra hn
rw [sign_apply, if_neg hn] at h
split_ifs at h
theorem sign_eq_neg_one_iff : sign a = -1 ↔ a < 0 := by
refine ⟨fun h => ?_, fun h => sign_neg h⟩
rw [sign_apply] at h
split_ifs at h
assumption
end Preorder
section LinearOrder
variable [Zero α] [LinearOrder α] {a : α}
/-- `SignType.sign` respects strictly monotone zero-preserving maps. -/
lemma StrictMono.sign_comp {β F : Type*} [Zero β] [Preorder β] [DecidableLT β]
[FunLike F α β] [ZeroHomClass F α β] {f : F} (hf : StrictMono f) (a : α) :
sign (f a) = sign a := by
simp only [sign_apply, ← map_zero f, hf.lt_iff_lt]
@[simp]
theorem sign_eq_zero_iff : sign a = 0 ↔ a = 0 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ sign_zero⟩
rw [sign_apply] at h
split_ifs at h with h_1 h_2
cases h
exact (le_of_not_lt h_1).eq_of_not_lt h_2
theorem sign_ne_zero : sign a ≠ 0 ↔ a ≠ 0 :=
sign_eq_zero_iff.not
@[simp]
theorem sign_nonneg_iff : 0 ≤ sign a ↔ 0 ≤ a := by
| rcases lt_trichotomy 0 a with (h | h | h)
· simp [h, h.le]
· simp [← h]
· simp [h, h.not_le]
| Mathlib/Data/Sign.lean | 357 | 361 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.NAry
import Mathlib.Data.Finset.Slice
import Mathlib.Data.Set.Sups
/-!
# Set family operations
This file defines a few binary operations on `Finset α` for use in set family combinatorics.
## Main declarations
* `Finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`.
* `Finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`.
* `Finset.disjSups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a`
and `b` are disjoint.
* `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`.
* `Finset.compls`: Finset of elements of the form `aᶜ` where `a ∈ s`.
## Notation
We define the following notation in locale `FinsetFamily`:
* `s ⊻ t` for `Finset.sups`
* `s ⊼ t` for `Finset.infs`
* `s ○ t` for `Finset.disjSups s t`
* `s \\ t` for `Finset.diffs`
* `sᶜˢ` for `Finset.compls`
## References
[B. Bollobás, *Combinatorics*][bollobas1986]
-/
open Function
open SetFamily
variable {F α β : Type*}
namespace Finset
section Sups
variable [DecidableEq α] [DecidableEq β]
variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β]
variable (s s₁ s₂ t t₁ t₂ u v : Finset α)
/-- `s ⊻ t` is the finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/
protected def hasSups : HasSups (Finset α) :=
⟨image₂ (· ⊔ ·)⟩
scoped[FinsetFamily] attribute [instance] Finset.hasSups
open FinsetFamily
variable {s t} {a b c : α}
@[simp]
theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)]
variable (s t)
@[simp, norm_cast]
theorem coe_sups : (↑(s ⊻ t) : Set α) = ↑s ⊻ ↑t :=
coe_image₂ _ _ _
theorem card_sups_le : #(s ⊻ t) ≤ #s * #t := card_image₂_le _ _ _
theorem card_sups_iff : #(s ⊻ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊔ x.2 :=
card_image₂_iff
variable {s s₁ s₂ t t₁ t₂ u}
theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t :=
mem_image₂_of_mem
theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ :=
image₂_subset
theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ :=
image₂_subset_left
theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t :=
image₂_subset_right
lemma image_subset_sups_left : b ∈ t → s.image (· ⊔ b) ⊆ s ⊻ t := image_subset_image₂_left
lemma image_subset_sups_right : a ∈ s → t.image (a ⊔ ·) ⊆ s ⊻ t := image_subset_image₂_right
theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) :=
forall_mem_image₂
@[simp]
theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u :=
image₂_subset_iff
@[simp]
theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty :=
Nonempty.image₂
theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
@[simp]
theorem empty_sups : ∅ ⊻ t = ∅ :=
image₂_empty_left
@[simp]
theorem sups_empty : s ⊻ ∅ = ∅ :=
image₂_empty_right
@[simp]
theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
@[simp] lemma singleton_sups : {a} ⊻ t = t.image (a ⊔ ·) := image₂_singleton_left
@[simp] lemma sups_singleton : s ⊻ {b} = s.image (· ⊔ b) := image₂_singleton_right
theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset α) = {a ⊔ b} :=
image₂_singleton
theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t :=
image₂_union_left
theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ :=
image₂_union_right
theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t :=
image₂_inter_subset_left
theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ :=
image₂_inter_subset_right
theorem subset_sups {s t : Set α} :
↑u ⊆ s ⊻ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' :=
subset_set_image₂
lemma image_sups (f : F) (s t : Finset α) : image f (s ⊻ t) = image f s ⊻ image f t :=
image_image₂_distrib <| map_sup f
lemma map_sups (f : F) (hf) (s t : Finset α) :
map ⟨f, hf⟩ (s ⊻ t) = map ⟨f, hf⟩ s ⊻ map ⟨f, hf⟩ t := by
simpa [map_eq_image] using image_sups f s t
lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩
lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed (s : Set α) := sups_subset_iff
@[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set α) := by simp [← coe_inj]
@[simp] lemma univ_sups_univ [Fintype α] : (univ : Finset α) ⊻ univ = univ := by simp
lemma filter_sups_le [DecidableLE α] (s t : Finset α) (a : α) :
{b ∈ s ⊻ t | b ≤ a} = {b ∈ s | b ≤ a} ⊻ {b ∈ t | b ≤ a} := by
simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le]
variable (s t u)
lemma biUnion_image_sup_left : s.biUnion (fun a ↦ t.image (a ⊔ ·)) = s ⊻ t := biUnion_image_left
lemma biUnion_image_sup_right : t.biUnion (fun b ↦ s.image (· ⊔ b)) = s ⊻ t := biUnion_image_right
theorem image_sup_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊔ ·)) = s ⊻ t :=
image_uncurry_product _ _ _
theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc sup_assoc
theorem sups_comm : s ⊻ t = t ⊻ s := image₂_comm sup_comm
theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) :=
image₂_left_comm sup_left_comm
theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t :=
image₂_right_comm sup_right_comm
theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) :=
image₂_image₂_image₂_comm sup_sup_sup_comm
end Sups
section Infs
variable [DecidableEq α] [DecidableEq β]
variable [SemilatticeInf α] [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β]
variable (s s₁ s₂ t t₁ t₂ u v : Finset α)
/-- `s ⊼ t` is the finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/
protected def hasInfs : HasInfs (Finset α) :=
⟨image₂ (· ⊓ ·)⟩
scoped[FinsetFamily] attribute [instance] Finset.hasInfs
open FinsetFamily
variable {s t} {a b c : α}
@[simp]
theorem mem_infs : c ∈ s ⊼ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊓ b = c := by simp [(· ⊼ ·)]
variable (s t)
@[simp, norm_cast]
theorem coe_infs : (↑(s ⊼ t) : Set α) = ↑s ⊼ ↑t :=
coe_image₂ _ _ _
theorem card_infs_le : #(s ⊼ t) ≤ #s * #t := card_image₂_le _ _ _
theorem card_infs_iff : #(s ⊼ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊓ x.2 :=
card_image₂_iff
variable {s s₁ s₂ t t₁ t₂ u}
theorem inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊼ t :=
mem_image₂_of_mem
theorem infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊼ t₁ ⊆ s₂ ⊼ t₂ :=
image₂_subset
theorem infs_subset_left : t₁ ⊆ t₂ → s ⊼ t₁ ⊆ s ⊼ t₂ :=
image₂_subset_left
theorem infs_subset_right : s₁ ⊆ s₂ → s₁ ⊼ t ⊆ s₂ ⊼ t :=
image₂_subset_right
lemma image_subset_infs_left : b ∈ t → s.image (· ⊓ b) ⊆ s ⊼ t := image_subset_image₂_left
lemma image_subset_infs_right : a ∈ s → t.image (a ⊓ ·) ⊆ s ⊼ t := image_subset_image₂_right
theorem forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊼ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊓ b) :=
forall_mem_image₂
@[simp]
theorem infs_subset_iff : s ⊼ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊓ b ∈ u :=
image₂_subset_iff
@[simp]
theorem infs_nonempty : (s ⊼ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
image₂_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.infs : s.Nonempty → t.Nonempty → (s ⊼ t).Nonempty :=
Nonempty.image₂
theorem Nonempty.of_infs_left : (s ⊼ t).Nonempty → s.Nonempty :=
Nonempty.of_image₂_left
theorem Nonempty.of_infs_right : (s ⊼ t).Nonempty → t.Nonempty :=
Nonempty.of_image₂_right
@[simp]
theorem empty_infs : ∅ ⊼ t = ∅ :=
image₂_empty_left
@[simp]
theorem infs_empty : s ⊼ ∅ = ∅ :=
image₂_empty_right
@[simp]
theorem infs_eq_empty : s ⊼ t = ∅ ↔ s = ∅ ∨ t = ∅ :=
image₂_eq_empty_iff
@[simp] lemma singleton_infs : {a} ⊼ t = t.image (a ⊓ ·) := image₂_singleton_left
@[simp] lemma infs_singleton : s ⊼ {b} = s.image (· ⊓ b) := image₂_singleton_right
theorem singleton_infs_singleton : ({a} ⊼ {b} : Finset α) = {a ⊓ b} :=
image₂_singleton
theorem infs_union_left : (s₁ ∪ s₂) ⊼ t = s₁ ⊼ t ∪ s₂ ⊼ t :=
image₂_union_left
theorem infs_union_right : s ⊼ (t₁ ∪ t₂) = s ⊼ t₁ ∪ s ⊼ t₂ :=
image₂_union_right
theorem infs_inter_subset_left : (s₁ ∩ s₂) ⊼ t ⊆ s₁ ⊼ t ∩ s₂ ⊼ t :=
image₂_inter_subset_left
theorem infs_inter_subset_right : s ⊼ (t₁ ∩ t₂) ⊆ s ⊼ t₁ ∩ s ⊼ t₂ :=
image₂_inter_subset_right
theorem subset_infs {s t : Set α} :
↑u ⊆ s ⊼ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊼ t' :=
subset_set_image₂
lemma image_infs (f : F) (s t : Finset α) : image f (s ⊼ t) = image f s ⊼ image f t :=
image_image₂_distrib <| map_inf f
lemma map_infs (f : F) (hf) (s t : Finset α) :
map ⟨f, hf⟩ (s ⊼ t) = map ⟨f, hf⟩ s ⊼ map ⟨f, hf⟩ t := by
simpa [map_eq_image] using image_infs f s t
lemma subset_infs_self : s ⊆ s ⊼ s := fun _a ha ↦ mem_infs.2 ⟨_, ha, _, ha, inf_idem _⟩
lemma infs_self_subset : s ⊼ s ⊆ s ↔ InfClosed (s : Set α) := infs_subset_iff
@[simp] lemma infs_self : s ⊼ s = s ↔ InfClosed (s : Set α) := by simp [← coe_inj]
@[simp] lemma univ_infs_univ [Fintype α] : (univ : Finset α) ⊼ univ = univ := by simp
lemma filter_infs_le [DecidableLE α] (s t : Finset α) (a : α) :
{b ∈ s ⊼ t | a ≤ b} = {b ∈ s | a ≤ b} ⊼ {b ∈ t | a ≤ b} := by
simp only [← coe_inj, coe_filter, coe_infs, ← mem_coe, Set.sep_infs_le]
variable (s t u)
lemma biUnion_image_inf_left : s.biUnion (fun a ↦ t.image (a ⊓ ·)) = s ⊼ t := biUnion_image_left
lemma biUnion_image_inf_right : t.biUnion (fun b ↦ s.image (· ⊓ b)) = s ⊼ t := biUnion_image_right
theorem image_inf_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊓ ·)) = s ⊼ t :=
image_uncurry_product _ _ _
theorem infs_assoc : s ⊼ t ⊼ u = s ⊼ (t ⊼ u) := image₂_assoc inf_assoc
theorem infs_comm : s ⊼ t = t ⊼ s := image₂_comm inf_comm
theorem infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) :=
image₂_left_comm inf_left_comm
theorem infs_right_comm : s ⊼ t ⊼ u = s ⊼ u ⊼ t :=
image₂_right_comm inf_right_comm
theorem infs_infs_infs_comm : s ⊼ t ⊼ (u ⊼ v) = s ⊼ u ⊼ (t ⊼ v) :=
image₂_image₂_image₂_comm inf_inf_inf_comm
end Infs
open FinsetFamily
section DistribLattice
variable [DecidableEq α]
variable [DistribLattice α] (s t u : Finset α)
theorem sups_infs_subset_left : s ⊻ t ⊼ u ⊆ (s ⊻ t) ⊼ (s ⊻ u) :=
image₂_distrib_subset_left sup_inf_left
theorem sups_infs_subset_right : t ⊼ u ⊻ s ⊆ (t ⊻ s) ⊼ (u ⊻ s) :=
image₂_distrib_subset_right sup_inf_right
theorem infs_sups_subset_left : s ⊼ (t ⊻ u) ⊆ s ⊼ t ⊻ s ⊼ u :=
image₂_distrib_subset_left inf_sup_left
theorem infs_sups_subset_right : (t ⊻ u) ⊼ s ⊆ t ⊼ s ⊻ u ⊼ s :=
image₂_distrib_subset_right inf_sup_right
end DistribLattice
section Finset
variable [DecidableEq α]
variable {𝒜 ℬ : Finset (Finset α)} {s t : Finset α}
@[simp] lemma powerset_union (s t : Finset α) : (s ∪ t).powerset = s.powerset ⊻ t.powerset := by
ext u
simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union]
refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂ := u), _, inter_subset_left (s₂ := u), ?_⟩, ?_⟩
· rwa [← union_inter_distrib_right, inter_eq_right]
· rintro ⟨v, hv, w, hw, rfl⟩
exact union_subset_union hv hw
@[simp] lemma powerset_inter (s t : Finset α) : (s ∩ t).powerset = s.powerset ⊼ t.powerset := by
ext u
simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter]
refine ⟨fun h ↦ ⟨_, inter_subset_left (s₂ := u), _, inter_subset_left (s₂ := u), ?_⟩, ?_⟩
· rwa [← inter_inter_distrib_right, inter_eq_right]
· rintro ⟨v, hv, w, hw, rfl⟩
exact inter_subset_inter hv hw
@[simp] lemma powerset_sups_powerset_self (s : Finset α) :
s.powerset ⊻ s.powerset = s.powerset := by simp [← powerset_union]
@[simp] lemma powerset_infs_powerset_self (s : Finset α) :
s.powerset ⊼ s.powerset = s.powerset := by simp [← powerset_inter]
lemma union_mem_sups : s ∈ 𝒜 → t ∈ ℬ → s ∪ t ∈ 𝒜 ⊻ ℬ := sup_mem_sups
lemma inter_mem_infs : s ∈ 𝒜 → t ∈ ℬ → s ∩ t ∈ 𝒜 ⊼ ℬ := inf_mem_infs
end Finset
section DisjSups
variable [DecidableEq α]
variable [SemilatticeSup α] [OrderBot α] [DecidableRel (α := α) Disjoint]
(s s₁ s₂ t t₁ t₂ u : Finset α)
/-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint.
-/
def disjSups : Finset α := {ab ∈ s ×ˢ t | Disjoint ab.1 ab.2}.image fun ab => ab.1 ⊔ ab.2
@[inherit_doc]
scoped[FinsetFamily] infixl:74 " ○ " => Finset.disjSups
open FinsetFamily
variable {s t u} {a b c : α}
@[simp]
theorem mem_disjSups : c ∈ s ○ t ↔ ∃ a ∈ s, ∃ b ∈ t, Disjoint a b ∧ a ⊔ b = c := by
simp [disjSups, and_assoc]
theorem disjSups_subset_sups : s ○ t ⊆ s ⊻ t := by
simp_rw [subset_iff, mem_sups, mem_disjSups]
exact fun c ⟨a, b, ha, hb, _, hc⟩ => ⟨a, b, ha, hb, hc⟩
variable (s t)
theorem card_disjSups_le : #(s ○ t) ≤ #s * #t :=
(card_le_card disjSups_subset_sups).trans <| card_sups_le _ _
variable {s s₁ s₂ t t₁ t₂}
theorem disjSups_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ○ t₁ ⊆ s₂ ○ t₂ :=
image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht
theorem disjSups_subset_left (ht : t₁ ⊆ t₂) : s ○ t₁ ⊆ s ○ t₂ :=
disjSups_subset Subset.rfl ht
theorem disjSups_subset_right (hs : s₁ ⊆ s₂) : s₁ ○ t ⊆ s₂ ○ t :=
disjSups_subset hs Subset.rfl
theorem forall_disjSups_iff {p : α → Prop} :
(∀ c ∈ s ○ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → p (a ⊔ b) := by
simp_rw [mem_disjSups]
refine ⟨fun h a ha b hb hab => h _ ⟨_, ha, _, hb, hab, rfl⟩, ?_⟩
rintro h _ ⟨a, ha, b, hb, hab, rfl⟩
exact h _ ha _ hb hab
@[simp]
theorem disjSups_subset_iff : s ○ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → a ⊔ b ∈ u :=
forall_disjSups_iff
theorem Nonempty.of_disjSups_left : (s ○ t).Nonempty → s.Nonempty := by
simp_rw [Finset.Nonempty, mem_disjSups]
exact fun ⟨_, a, ha, _⟩ => ⟨a, ha⟩
theorem Nonempty.of_disjSups_right : (s ○ t).Nonempty → t.Nonempty := by
simp_rw [Finset.Nonempty, mem_disjSups]
exact fun ⟨_, _, _, b, hb, _⟩ => ⟨b, hb⟩
@[simp]
theorem disjSups_empty_left : ∅ ○ t = ∅ := by simp [disjSups]
@[simp]
theorem disjSups_empty_right : s ○ ∅ = ∅ := by simp [disjSups]
theorem disjSups_singleton : ({a} ○ {b} : Finset α) = if Disjoint a b then {a ⊔ b} else ∅ := by
split_ifs with h <;> simp [disjSups, filter_singleton, h]
theorem disjSups_union_left : (s₁ ∪ s₂) ○ t = s₁ ○ t ∪ s₂ ○ t := by
simp [disjSups, filter_union, image_union]
theorem disjSups_union_right : s ○ (t₁ ∪ t₂) = s ○ t₁ ∪ s ○ t₂ := by
simp [disjSups, filter_union, image_union]
theorem disjSups_inter_subset_left : (s₁ ∩ s₂) ○ t ⊆ s₁ ○ t ∩ s₂ ○ t := by
simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _
theorem disjSups_inter_subset_right : s ○ (t₁ ∩ t₂) ⊆ s ○ t₁ ∩ s ○ t₂ := by
simpa only [disjSups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _
variable (s t)
theorem disjSups_comm : s ○ t = t ○ s := by
aesop (add simp disjoint_comm, simp sup_comm)
instance : @Std.Commutative (Finset α) (· ○ ·) := ⟨disjSups_comm⟩
end DisjSups
open FinsetFamily
section DistribLattice
variable [DecidableEq α]
variable [DistribLattice α] [OrderBot α] [DecidableRel (α := α) Disjoint] (s t u v : Finset α)
theorem disjSups_assoc : ∀ s t u : Finset α, s ○ t ○ u = s ○ (t ○ u) := by
refine (associative_of_commutative_of_le inferInstance ?_).assoc
simp only [le_eq_subset, disjSups_subset_iff, mem_disjSups]
rintro s t u _ ⟨a, ha, b, hb, hab, rfl⟩ c hc habc
rw [disjoint_sup_left] at habc
exact ⟨a, ha, _, ⟨b, hb, c, hc, habc.2, rfl⟩, hab.sup_right habc.1, (sup_assoc ..).symm⟩
instance : @Std.Associative (Finset α) (· ○ ·) := ⟨disjSups_assoc⟩
theorem disjSups_left_comm : s ○ (t ○ u) = t ○ (s ○ u) := by
simp_rw [← disjSups_assoc, disjSups_comm s]
theorem disjSups_right_comm : s ○ t ○ u = s ○ u ○ t := by simp_rw [disjSups_assoc, disjSups_comm]
theorem disjSups_disjSups_disjSups_comm : s ○ t ○ (u ○ v) = s ○ u ○ (t ○ v) := by
simp_rw [← disjSups_assoc, disjSups_right_comm]
end DistribLattice
section Diffs
variable [DecidableEq α]
variable [GeneralizedBooleanAlgebra α] (s s₁ s₂ t t₁ t₂ u : Finset α)
/-- `s \\ t` is the finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. -/
def diffs : Finset α → Finset α → Finset α := image₂ (· \ ·)
@[inherit_doc]
scoped[FinsetFamily] infixl:74 " \\\\ " => Finset.diffs
-- This notation is meant to have higher precedence than `\` and `⊓`, but still within the
-- realm of other binary notation
open FinsetFamily
variable {s t} {a b c : α}
@[simp] lemma mem_diffs : c ∈ s \\ t ↔ ∃ a ∈ s, ∃ b ∈ t, a \ b = c := by simp [(· \\ ·)]
variable (s t)
@[simp, norm_cast] lemma coe_diffs : (↑(s \\ t) : Set α) = Set.image2 (· \ ·) s t :=
coe_image₂ _ _ _
lemma card_diffs_le : #(s \\ t) ≤ #s * #t := card_image₂_le _ _ _
lemma card_diffs_iff : #(s \\ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x ↦ x.1 \ x.2 :=
card_image₂_iff
variable {s s₁ s₂ t t₁ t₂ u}
lemma sdiff_mem_diffs : a ∈ s → b ∈ t → a \ b ∈ s \\ t := mem_image₂_of_mem
lemma diffs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ \\ t₁ ⊆ s₂ \\ t₂ := image₂_subset
lemma diffs_subset_left : t₁ ⊆ t₂ → s \\ t₁ ⊆ s \\ t₂ := image₂_subset_left
lemma diffs_subset_right : s₁ ⊆ s₂ → s₁ \\ t ⊆ s₂ \\ t := image₂_subset_right
lemma image_subset_diffs_left : b ∈ t → s.image (· \ b) ⊆ s \\ t := image_subset_image₂_left
lemma image_subset_diffs_right : a ∈ s → t.image (a \ ·) ⊆ s \\ t := image_subset_image₂_right
lemma forall_mem_diffs {p : α → Prop} : (∀ c ∈ s \\ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a \ b) :=
forall_mem_image₂
@[simp] lemma diffs_subset_iff : s \\ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a \ b ∈ u := image₂_subset_iff
@[simp]
lemma diffs_nonempty : (s \\ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff
| @[aesop safe apply (rule_sets := [finsetNonempty])]
protected lemma Nonempty.diffs : s.Nonempty → t.Nonempty → (s \\ t).Nonempty := Nonempty.image₂
| Mathlib/Data/Finset/Sups.lean | 549 | 550 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
import Mathlib.Data.Sign
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Analysis.RCLike.Basic
/-!
# Real quadratic forms
Sylvester's law of inertia `equivalent_one_neg_one_weighted_sum_squared`:
A real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1 or 0.
When the real quadratic form is nondegenerate we can take the weights to be ±1,
as in `QuadraticForm.equivalent_one_zero_neg_one_weighted_sum_squared`.
-/
namespace QuadraticForm
open Finset SignType
open QuadraticMap
variable {ι : Type*} [Fintype ι]
/-- The isometry between a weighted sum of squares with weights `u` on the
(non-zero) real numbers and the weighted sum of squares with weights `sign ∘ u`. -/
noncomputable def isometryEquivSignWeightedSumSquares (w : ι → ℝ) :
IsometryEquiv (weightedSumSquares ℝ w)
(weightedSumSquares ℝ (fun i ↦ (sign (w i) : ℝ))) := by
let u i := if h : w i = 0 then (1 : ℝˣ) else Units.mk0 (w i) h
have hu : ∀ i : ι, 1 / √|(u i : ℝ)| ≠ 0 := fun i ↦
have : (u i : ℝ) ≠ 0 := (u i).ne_zero
by positivity
have hwu : ∀ i, w i / |(u i : ℝ)| = sign (w i) := fun i ↦ by
by_cases hi : w i = 0 <;> field_simp [hi, u]
convert QuadraticMap.isometryEquivBasisRepr (weightedSumSquares ℝ w)
((Pi.basisFun ℝ ι).unitsSMul fun i => .mk0 _ (hu i))
ext1 v
classical
suffices ∑ i, (w i / |(u i : ℝ)|) * v i ^ 2 = ∑ i, w i * (v i ^ 2 * |(u i : ℝ)|⁻¹) by
simpa [basisRepr_apply, Basis.unitsSMul_apply, ← _root_.sq, mul_pow, ← hwu, Pi.single_apply]
exact sum_congr rfl fun j _ ↦ by ring
/-- **Sylvester's law of inertia**: A nondegenerate real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1, `SignType` version. -/
theorem equivalent_sign_ne_zero_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) (hQ : (associated (R := ℝ) Q).SeparatingLeft) :
∃ w : Fin (Module.finrank ℝ M) → SignType,
(∀ i, w i ≠ 0) ∧ Equivalent Q (weightedSumSquares ℝ fun i ↦ (w i : ℝ)) :=
let ⟨w, ⟨hw₁⟩⟩ := Q.equivalent_weightedSumSquares_units_of_nondegenerate' hQ
⟨sign ∘ ((↑) : ℝˣ → ℝ) ∘ w, fun i => sign_ne_zero.2 (w i).ne_zero,
⟨hw₁.trans (isometryEquivSignWeightedSumSquares (((↑) : ℝˣ → ℝ) ∘ w))⟩⟩
/-- **Sylvester's law of inertia**: A nondegenerate real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1. -/
theorem equivalent_one_neg_one_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) (hQ : (associated (R := ℝ) Q).SeparatingLeft) :
∃ w : Fin (Module.finrank ℝ M) → ℝ,
(∀ i, w i = -1 ∨ w i = 1) ∧ Equivalent Q (weightedSumSquares ℝ w) :=
let ⟨w, hw₀, hw⟩ := Q.equivalent_sign_ne_zero_weighted_sum_squared hQ
⟨(w ·), fun i ↦ by cases hi : w i <;> simp_all, hw⟩
/-- **Sylvester's law of inertia**: A real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1 or 0, `SignType` version. -/
theorem equivalent_signType_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) :
∃ w : Fin (Module.finrank ℝ M) → SignType,
Equivalent Q (weightedSumSquares ℝ fun i ↦ (w i : ℝ)) :=
let ⟨w, ⟨hw₁⟩⟩ := Q.equivalent_weightedSumSquares
⟨sign ∘ w, ⟨hw₁.trans (isometryEquivSignWeightedSumSquares w)⟩⟩
/-- **Sylvester's law of inertia**: A real quadratic form is equivalent to a weighted
sum of squares with the weights being ±1 or 0. -/
theorem equivalent_one_zero_neg_one_weighted_sum_squared {M : Type*} [AddCommGroup M] [Module ℝ M]
[FiniteDimensional ℝ M] (Q : QuadraticForm ℝ M) :
∃ w : Fin (Module.finrank ℝ M) → ℝ,
| (∀ i, w i = -1 ∨ w i = 0 ∨ w i = 1) ∧ Equivalent Q (weightedSumSquares ℝ w) :=
let ⟨w, hw⟩ := Q.equivalent_signType_weighted_sum_squared
⟨(w ·), fun i ↦ by cases h : w i <;> simp [h], hw⟩
end QuadraticForm
| Mathlib/LinearAlgebra/QuadraticForm/Real.lean | 84 | 89 |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Xavier Roblot
-/
import Mathlib.Algebra.Algebra.Hom.Rat
import Mathlib.Analysis.Complex.Polynomial.Basic
import Mathlib.NumberTheory.NumberField.Norm
import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots
import Mathlib.Topology.Instances.Complex
/-!
# Embeddings of number fields
This file defines the embeddings of a number field into an algebraic closed field.
## Main Definitions and Results
* `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and
let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K`
in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`.
* `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are
all of norm one is a root of unity.
* `NumberField.InfinitePlace`: the type of infinite places of a number field `K`.
* `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff
they are equal or complex conjugates.
* `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is
for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and
`‖·‖_w` is the normalized absolute value for `w`.
## Tags
number field, embeddings, places, infinite places
-/
open scoped Finset
namespace NumberField.Embeddings
section Fintype
open Module
variable (K : Type*) [Field K] [NumberField K]
variable (A : Type*) [Field A] [CharZero A]
/-- There are finitely many embeddings of a number field. -/
noncomputable instance : Fintype (K →+* A) :=
Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm
variable [IsAlgClosed A]
/-- The number of embeddings of a number field is equal to its finrank. -/
theorem card : Fintype.card (K →+* A) = finrank ℚ K := by
rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card]
instance : Nonempty (K →+* A) := by
rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A]
exact Module.finrank_pos
end Fintype
section Roots
open Set Polynomial
variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K)
/-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field.
The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of
the minimal polynomial of `x` over `ℚ`. -/
theorem range_eval_eq_rootSet_minpoly :
(range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by
convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1
ext a
exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩
end Roots
section Bounded
open Module Polynomial Set
variable {K : Type*} [Field K] [NumberField K]
variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A]
theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) :
‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by
have hx := Algebra.IsSeparable.isIntegral ℚ x
rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)]
refine coeff_bdd_of_roots_le _ (minpoly.monic hx)
(IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i
classical
rw [← Multiset.mem_toFinset] at hz
obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz
exact h φ
variable (K A)
/-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all
smaller in norm than `B` is finite. -/
theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by
classical
let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2))
have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C)
refine this.subset fun x hx => ?_; simp_rw [mem_iUnion]
have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1
refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩
· rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly]
exact minpoly.natDegree_le x
rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ]
refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _)
rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs]
/-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/
theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) :
∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by
obtain ⟨a, -, b, -, habne, h⟩ :=
@Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ
(by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ))
wlog hlt : b < a
· exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt)
refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩
rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h
refine h.resolve_right fun hp => ?_
specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom
rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx
end Bounded
end NumberField.Embeddings
section Place
variable {K : Type*} [Field K] {A : Type*} [NormedDivisionRing A] [Nontrivial A] (φ : K →+* A)
/-- An embedding into a normed division ring defines a place of `K` -/
def NumberField.place : AbsoluteValue K ℝ :=
(IsAbsoluteValue.toAbsoluteValue (norm : A → ℝ)).comp φ.injective
@[simp]
theorem NumberField.place_apply (x : K) : (NumberField.place φ) x = norm (φ x) := rfl
end Place
namespace NumberField.ComplexEmbedding
open Complex NumberField
open scoped ComplexConjugate
variable {K : Type*} [Field K] {k : Type*} [Field k]
variable (K) in
/--
A (random) lift of the complex embedding `φ : k →+* ℂ` to an extension `K` of `k`.
-/
noncomputable def lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : K →+* ℂ := by
letI := φ.toAlgebra
exact (IsAlgClosed.lift (R := k)).toRingHom
@[simp]
theorem lift_comp_algebraMap [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) :
(lift K φ).comp (algebraMap k K) = φ := by
unfold lift
letI := φ.toAlgebra
rw [AlgHom.toRingHom_eq_coe, AlgHom.comp_algebraMap_of_tower, RingHom.algebraMap_toAlgebra']
@[simp]
theorem lift_algebraMap_apply [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) (x : k) :
lift K φ (algebraMap k K x) = φ x :=
RingHom.congr_fun (lift_comp_algebraMap φ) x
/-- The conjugate of a complex embedding as a complex embedding. -/
abbrev conjugate (φ : K →+* ℂ) : K →+* ℂ := star φ
@[simp]
theorem conjugate_coe_eq (φ : K →+* ℂ) (x : K) : (conjugate φ) x = conj (φ x) := rfl
theorem place_conjugate (φ : K →+* ℂ) : place (conjugate φ) = place φ := by
ext; simp only [place_apply, norm_conj, conjugate_coe_eq]
/-- An embedding into `ℂ` is real if it is fixed by complex conjugation. -/
abbrev IsReal (φ : K →+* ℂ) : Prop := IsSelfAdjoint φ
theorem isReal_iff {φ : K →+* ℂ} : IsReal φ ↔ conjugate φ = φ := isSelfAdjoint_iff
theorem isReal_conjugate_iff {φ : K →+* ℂ} : IsReal (conjugate φ) ↔ IsReal φ :=
IsSelfAdjoint.star_iff
/-- A real embedding as a ring homomorphism from `K` to `ℝ` . -/
def IsReal.embedding {φ : K →+* ℂ} (hφ : IsReal φ) : K →+* ℝ where
toFun x := (φ x).re
map_one' := by simp only [map_one, one_re]
map_mul' := by
simp only [Complex.conj_eq_iff_im.mp (RingHom.congr_fun hφ _), map_mul, mul_re,
mul_zero, tsub_zero, eq_self_iff_true, forall_const]
map_zero' := by simp only [map_zero, zero_re]
map_add' := by simp only [map_add, add_re, eq_self_iff_true, forall_const]
@[simp]
theorem IsReal.coe_embedding_apply {φ : K →+* ℂ} (hφ : IsReal φ) (x : K) :
(hφ.embedding x : ℂ) = φ x := by
apply Complex.ext
· rfl
· rw [ofReal_im, eq_comm, ← Complex.conj_eq_iff_im]
exact RingHom.congr_fun hφ x
lemma IsReal.comp (f : k →+* K) {φ : K →+* ℂ} (hφ : IsReal φ) :
IsReal (φ.comp f) := by ext1 x; simpa using RingHom.congr_fun hφ (f x)
lemma isReal_comp_iff {f : k ≃+* K} {φ : K →+* ℂ} :
IsReal (φ.comp (f : k →+* K)) ↔ IsReal φ :=
⟨fun H ↦ by convert H.comp f.symm.toRingHom; ext1; simp, IsReal.comp _⟩
lemma exists_comp_symm_eq_of_comp_eq [Algebra k K] [IsGalois k K] (φ ψ : K →+* ℂ)
(h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) :
∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm }
use (AlgHom.restrictNormal' ψ' K).symm
ext1 x
exact AlgHom.restrictNormal_commutes ψ' K x
variable [Algebra k K] (φ : K →+* ℂ) (σ : K ≃ₐ[k] K)
/--
`IsConj φ σ` states that `σ : K ≃ₐ[k] K` is the conjugation under the embedding `φ : K →+* ℂ`.
-/
def IsConj : Prop := conjugate φ = φ.comp σ
variable {φ σ}
lemma IsConj.eq (h : IsConj φ σ) (x) : φ (σ x) = star (φ x) := RingHom.congr_fun h.symm x
lemma IsConj.ext {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) (h₂ : IsConj φ σ₂) : σ₁ = σ₂ :=
AlgEquiv.ext fun x ↦ φ.injective ((h₁.eq x).trans (h₂.eq x).symm)
lemma IsConj.ext_iff {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) : σ₁ = σ₂ ↔ IsConj φ σ₂ :=
⟨fun e ↦ e ▸ h₁, h₁.ext⟩
lemma IsConj.isReal_comp (h : IsConj φ σ) : IsReal (φ.comp (algebraMap k K)) := by
ext1 x
simp only [conjugate_coe_eq, RingHom.coe_comp, Function.comp_apply, ← h.eq,
starRingEnd_apply, AlgEquiv.commutes]
lemma isConj_one_iff : IsConj φ (1 : K ≃ₐ[k] K) ↔ IsReal φ := Iff.rfl
alias ⟨_, IsReal.isConjGal_one⟩ := ComplexEmbedding.isConj_one_iff
lemma IsConj.symm (hσ : IsConj φ σ) :
IsConj φ σ.symm := RingHom.ext fun x ↦ by simpa using congr_arg star (hσ.eq (σ.symm x))
lemma isConj_symm : IsConj φ σ.symm ↔ IsConj φ σ :=
⟨IsConj.symm, IsConj.symm⟩
end NumberField.ComplexEmbedding
section InfinitePlace
open NumberField
variable {k : Type*} [Field k] (K : Type*) [Field K] {F : Type*} [Field F]
/-- An infinite place of a number field `K` is a place associated to a complex embedding. -/
def NumberField.InfinitePlace := { w : AbsoluteValue K ℝ // ∃ φ : K →+* ℂ, place φ = w }
instance [NumberField K] : Nonempty (NumberField.InfinitePlace K) := Set.instNonemptyRange _
variable {K}
/-- Return the infinite place defined by a complex embedding `φ`. -/
noncomputable def NumberField.InfinitePlace.mk (φ : K →+* ℂ) : NumberField.InfinitePlace K :=
⟨place φ, ⟨φ, rfl⟩⟩
namespace NumberField.InfinitePlace
open NumberField
instance {K : Type*} [Field K] : FunLike (InfinitePlace K) K ℝ where
coe w x := w.1 x
coe_injective' _ _ h := Subtype.eq (AbsoluteValue.ext fun x => congr_fun h x)
lemma coe_apply {K : Type*} [Field K] (v : InfinitePlace K) (x : K) :
v x = v.1 x := rfl
@[ext]
lemma ext {K : Type*} [Field K] (v₁ v₂ : InfinitePlace K) (h : ∀ k, v₁ k = v₂ k) : v₁ = v₂ :=
Subtype.ext <| AbsoluteValue.ext h
instance : MonoidWithZeroHomClass (InfinitePlace K) K ℝ where
map_mul w _ _ := w.1.map_mul _ _
map_one w := w.1.map_one
map_zero w := w.1.map_zero
instance : NonnegHomClass (InfinitePlace K) K ℝ where
apply_nonneg w _ := w.1.nonneg _
@[simp]
theorem apply (φ : K →+* ℂ) (x : K) : (mk φ) x = ‖φ x‖ := rfl
/-- For an infinite place `w`, return an embedding `φ` such that `w = infinite_place φ` . -/
noncomputable def embedding (w : InfinitePlace K) : K →+* ℂ := w.2.choose
@[simp]
theorem mk_embedding (w : InfinitePlace K) : mk (embedding w) = w := Subtype.ext w.2.choose_spec
@[simp]
theorem mk_conjugate_eq (φ : K →+* ℂ) : mk (ComplexEmbedding.conjugate φ) = mk φ := by
refine DFunLike.ext _ _ (fun x => ?_)
rw [apply, apply, ComplexEmbedding.conjugate_coe_eq, Complex.norm_conj]
theorem norm_embedding_eq (w : InfinitePlace K) (x : K) :
‖(embedding w) x‖ = w x := by
nth_rewrite 2 [← mk_embedding w]
rfl
theorem eq_iff_eq (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x = r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ = r :=
⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩
theorem le_iff_le (x : K) (r : ℝ) : (∀ w : InfinitePlace K, w x ≤ r) ↔ ∀ φ : K →+* ℂ, ‖φ x‖ ≤ r :=
⟨fun hw φ => hw (mk φ), by rintro hφ ⟨w, ⟨φ, rfl⟩⟩; exact hφ φ⟩
theorem pos_iff {w : InfinitePlace K} {x : K} : 0 < w x ↔ x ≠ 0 := AbsoluteValue.pos_iff w.1
@[simp]
theorem mk_eq_iff {φ ψ : K →+* ℂ} : mk φ = mk ψ ↔ φ = ψ ∨ ComplexEmbedding.conjugate φ = ψ := by
constructor
· -- We prove that the map ψ ∘ φ⁻¹ between φ(K) and ℂ is uniform continuous, thus it is either the
-- inclusion or the complex conjugation using `Complex.uniformContinuous_ringHom_eq_id_or_conj`
intro h₀
obtain ⟨j, hiφ⟩ := (φ.injective).hasLeftInverse
let ι := RingEquiv.ofLeftInverse hiφ
have hlip : LipschitzWith 1 (RingHom.comp ψ ι.symm.toRingHom) := by
change LipschitzWith 1 (ψ ∘ ι.symm)
apply LipschitzWith.of_dist_le_mul
intro x y
rw [NNReal.coe_one, one_mul, NormedField.dist_eq, Function.comp_apply, Function.comp_apply,
← map_sub, ← map_sub]
apply le_of_eq
suffices ‖φ (ι.symm (x - y))‖ = ‖ψ (ι.symm (x - y))‖ by
rw [← this, ← RingEquiv.ofLeftInverse_apply hiφ _, RingEquiv.apply_symm_apply ι _]
rfl
exact congrFun (congrArg (↑) h₀) _
cases
Complex.uniformContinuous_ringHom_eq_id_or_conj φ.fieldRange hlip.uniformContinuous with
| inl h =>
left; ext1 x
conv_rhs => rw [← hiφ x]
exact (congrFun h (ι x)).symm
| inr h =>
right; ext1 x
conv_rhs => rw [← hiφ x]
exact (congrFun h (ι x)).symm
· rintro (⟨h⟩ | ⟨h⟩)
· exact congr_arg mk h
· rw [← mk_conjugate_eq]
exact congr_arg mk h
/-- An infinite place is real if it is defined by a real embedding. -/
def IsReal (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ComplexEmbedding.IsReal φ ∧ mk φ = w
/-- An infinite place is complex if it is defined by a complex (ie. not real) embedding. -/
def IsComplex (w : InfinitePlace K) : Prop := ∃ φ : K →+* ℂ, ¬ComplexEmbedding.IsReal φ ∧ mk φ = w
theorem embedding_mk_eq (φ : K →+* ℂ) :
embedding (mk φ) = φ ∨ embedding (mk φ) = ComplexEmbedding.conjugate φ := by
rw [@eq_comm _ _ φ, @eq_comm _ _ (ComplexEmbedding.conjugate φ), ← mk_eq_iff, mk_embedding]
@[simp]
theorem embedding_mk_eq_of_isReal {φ : K →+* ℂ} (h : ComplexEmbedding.IsReal φ) :
embedding (mk φ) = φ := by
have := embedding_mk_eq φ
rwa [ComplexEmbedding.isReal_iff.mp h, or_self] at this
theorem isReal_iff {w : InfinitePlace K} :
IsReal w ↔ ComplexEmbedding.IsReal (embedding w) := by
refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩
rintro ⟨φ, ⟨hφ, rfl⟩⟩
rwa [embedding_mk_eq_of_isReal hφ]
theorem isComplex_iff {w : InfinitePlace K} :
IsComplex w ↔ ¬ComplexEmbedding.IsReal (embedding w) := by
refine ⟨?_, fun h => ⟨embedding w, h, mk_embedding w⟩⟩
rintro ⟨φ, ⟨hφ, rfl⟩⟩
contrapose! hφ
cases mk_eq_iff.mp (mk_embedding (mk φ)) with
| inl h => rwa [h] at hφ
| inr h => rwa [← ComplexEmbedding.isReal_conjugate_iff, h] at hφ
@[simp]
theorem conjugate_embedding_eq_of_isReal {w : InfinitePlace K} (h : IsReal w) :
ComplexEmbedding.conjugate (embedding w) = embedding w :=
ComplexEmbedding.isReal_iff.mpr (isReal_iff.mp h)
@[simp]
theorem not_isReal_iff_isComplex {w : InfinitePlace K} : ¬IsReal w ↔ IsComplex w := by
rw [isComplex_iff, isReal_iff]
@[simp]
theorem not_isComplex_iff_isReal {w : InfinitePlace K} : ¬IsComplex w ↔ IsReal w := by
rw [isComplex_iff, isReal_iff, not_not]
theorem isReal_or_isComplex (w : InfinitePlace K) : IsReal w ∨ IsComplex w := by
rw [← not_isReal_iff_isComplex]; exact em _
theorem ne_of_isReal_isComplex {w w' : InfinitePlace K} (h : IsReal w) (h' : IsComplex w') :
w ≠ w' := fun h_eq ↦ not_isReal_iff_isComplex.mpr h' (h_eq ▸ h)
variable (K) in
theorem disjoint_isReal_isComplex :
Disjoint {(w : InfinitePlace K) | IsReal w} {(w : InfinitePlace K) | IsComplex w} :=
Set.disjoint_iff.2 <| fun _ hw ↦ not_isReal_iff_isComplex.2 hw.2 hw.1
/-- The real embedding associated to a real infinite place. -/
noncomputable def embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) : K →+* ℝ :=
ComplexEmbedding.IsReal.embedding (isReal_iff.mp hw)
@[simp]
theorem embedding_of_isReal_apply {w : InfinitePlace K} (hw : IsReal w) (x : K) :
((embedding_of_isReal hw) x : ℂ) = (embedding w) x :=
ComplexEmbedding.IsReal.coe_embedding_apply (isReal_iff.mp hw) x
theorem norm_embedding_of_isReal {w : InfinitePlace K} (hw : IsReal w) (x : K) :
‖embedding_of_isReal hw x‖ = w x := by
rw [← norm_embedding_eq, ← embedding_of_isReal_apply hw, Complex.norm_real]
@[simp]
theorem isReal_of_mk_isReal {φ : K →+* ℂ} (h : IsReal (mk φ)) :
ComplexEmbedding.IsReal φ := by
contrapose! h
rw [not_isReal_iff_isComplex]
exact ⟨φ, h, rfl⟩
lemma isReal_mk_iff {φ : K →+* ℂ} :
IsReal (mk φ) ↔ ComplexEmbedding.IsReal φ :=
⟨isReal_of_mk_isReal, fun H ↦ ⟨_, H, rfl⟩⟩
lemma isComplex_mk_iff {φ : K →+* ℂ} :
IsComplex (mk φ) ↔ ¬ ComplexEmbedding.IsReal φ :=
not_isReal_iff_isComplex.symm.trans isReal_mk_iff.not
@[simp]
theorem not_isReal_of_mk_isComplex {φ : K →+* ℂ} (h : IsComplex (mk φ)) :
¬ ComplexEmbedding.IsReal φ := by rwa [← isComplex_mk_iff]
open scoped Classical in
/-- The multiplicity of an infinite place, that is the number of distinct complex embeddings that
define it, see `card_filter_mk_eq`. -/
noncomputable def mult (w : InfinitePlace K) : ℕ := if (IsReal w) then 1 else 2
@[simp]
theorem mult_isReal (w : {w : InfinitePlace K // IsReal w}) :
mult w.1 = 1 := by
rw [mult, if_pos w.prop]
@[simp]
theorem mult_isComplex (w : {w : InfinitePlace K // IsComplex w}) :
mult w.1 = 2 := by
rw [mult, if_neg (not_isReal_iff_isComplex.mpr w.prop)]
theorem mult_pos {w : InfinitePlace K} : 0 < mult w := by
rw [mult]
split_ifs <;> norm_num
@[simp]
theorem mult_ne_zero {w : InfinitePlace K} : mult w ≠ 0 := ne_of_gt mult_pos
theorem mult_coe_ne_zero {w : InfinitePlace K} : (mult w : ℝ) ≠ 0 :=
Nat.cast_ne_zero.mpr mult_ne_zero
theorem one_le_mult {w : InfinitePlace K} : (1 : ℝ) ≤ mult w := by
rw [← Nat.cast_one, Nat.cast_le]
exact mult_pos
open scoped Classical in
theorem card_filter_mk_eq [NumberField K] (w : InfinitePlace K) : #{φ | mk φ = w} = mult w := by
conv_lhs =>
congr; congr; ext
rw [← mk_embedding w, mk_eq_iff, ComplexEmbedding.conjugate, star_involutive.eq_iff]
simp_rw [Finset.filter_or, Finset.filter_eq' _ (embedding w),
Finset.filter_eq' _ (ComplexEmbedding.conjugate (embedding w)),
Finset.mem_univ, ite_true, mult]
split_ifs with hw
· rw [ComplexEmbedding.isReal_iff.mp (isReal_iff.mp hw), Finset.union_idempotent,
Finset.card_singleton]
· refine Finset.card_pair ?_
rwa [Ne, eq_comm, ← ComplexEmbedding.isReal_iff, ← isReal_iff]
open scoped Classical in
noncomputable instance NumberField.InfinitePlace.fintype [NumberField K] :
Fintype (InfinitePlace K) := Set.fintypeRange _
open scoped Classical in
@[to_additive]
theorem prod_eq_prod_mul_prod {α : Type*} [CommMonoid α] [NumberField K] (f : InfinitePlace K → α) :
∏ w, f w = (∏ w : {w // IsReal w}, f w.1) * (∏ w : {w // IsComplex w}, f w.1) := by
rw [← Equiv.prod_comp (Equiv.subtypeEquivRight (fun _ ↦ not_isReal_iff_isComplex))]
simp [Fintype.prod_subtype_mul_prod_subtype]
theorem sum_mult_eq [NumberField K] :
∑ w : InfinitePlace K, mult w = Module.finrank ℚ K := by
classical
rw [← Embeddings.card K ℂ, Fintype.card, Finset.card_eq_sum_ones, ← Finset.univ.sum_fiberwise
(fun φ => InfinitePlace.mk φ)]
exact Finset.sum_congr rfl
(fun _ _ => by rw [Finset.sum_const, smul_eq_mul, mul_one, card_filter_mk_eq])
/-- The map from real embeddings to real infinite places as an equiv -/
noncomputable def mkReal :
{ φ : K →+* ℂ // ComplexEmbedding.IsReal φ } ≃ { w : InfinitePlace K // IsReal w } := by
refine (Equiv.ofBijective (fun φ => ⟨mk φ, ?_⟩) ⟨fun φ ψ h => ?_, fun w => ?_⟩)
· exact ⟨φ, φ.prop, rfl⟩
· rwa [Subtype.mk.injEq, mk_eq_iff, ComplexEmbedding.isReal_iff.mp φ.prop, or_self,
← Subtype.ext_iff] at h
· exact ⟨⟨embedding w, isReal_iff.mp w.prop⟩, by simp⟩
/-- The map from nonreal embeddings to complex infinite places -/
noncomputable def mkComplex :
{ φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } → { w : InfinitePlace K // IsComplex w } :=
Subtype.map mk fun φ hφ => ⟨φ, hφ, rfl⟩
@[simp]
theorem mkReal_coe (φ : { φ : K →+* ℂ // ComplexEmbedding.IsReal φ }) :
(mkReal φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl
@[simp]
theorem mkComplex_coe (φ : { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ }) :
(mkComplex φ : InfinitePlace K) = mk (φ : K →+* ℂ) := rfl
section NumberField
variable [NumberField K]
/-- The infinite part of the product formula : for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where
`‖·‖_w` is the normalized absolute value for `w`. -/
theorem prod_eq_abs_norm (x : K) :
∏ w : InfinitePlace K, w x ^ mult w = abs (Algebra.norm ℚ x) := by
classical
convert (congr_arg (‖·‖) (@Algebra.norm_eq_prod_embeddings ℚ _ _ _ _ ℂ _ _ _ _ _ x)).symm
· rw [norm_prod, ← Fintype.prod_equiv RingHom.equivRatAlgHom (fun f => ‖f x‖)
(fun φ => ‖φ x‖) fun _ => by simp [RingHom.equivRatAlgHom_apply]]
rw [← Finset.prod_fiberwise Finset.univ mk (fun φ => ‖φ x‖)]
have (w : InfinitePlace K) (φ) (hφ : φ ∈ ({φ | mk φ = w} : Finset _)) :
‖φ x‖ = w x := by rw [← (Finset.mem_filter.mp hφ).2, apply]
simp_rw [Finset.prod_congr rfl (this _), Finset.prod_const, card_filter_mk_eq]
· rw [eq_ratCast, Rat.cast_abs, ← Real.norm_eq_abs, ← Complex.norm_real, Complex.ofReal_ratCast]
theorem one_le_of_lt_one {w : InfinitePlace K} {a : (𝓞 K)} (ha : a ≠ 0)
(h : ∀ ⦃z⦄, z ≠ w → z a < 1) : 1 ≤ w a := by
suffices (1 : ℝ) ≤ |Algebra.norm ℚ (a : K)| by
contrapose! this
rw [← InfinitePlace.prod_eq_abs_norm, ← Finset.prod_const_one]
refine Finset.prod_lt_prod_of_nonempty (fun _ _ ↦ ?_) (fun z _ ↦ ?_) Finset.univ_nonempty
· exact pow_pos (pos_iff.mpr ((Subalgebra.coe_eq_zero _).not.mpr ha)) _
· refine pow_lt_one₀ (apply_nonneg _ _) ?_ (by rw [mult]; split_ifs <;> norm_num)
by_cases hz : z = w
· rwa [hz]
· exact h hz
rw [← Algebra.coe_norm_int, ← Int.cast_one, ← Int.cast_abs, Rat.cast_intCast, Int.cast_le]
exact Int.one_le_abs (Algebra.norm_ne_zero_iff.mpr ha)
open scoped IntermediateField in
theorem _root_.NumberField.is_primitive_element_of_infinitePlace_lt {x : 𝓞 K}
{w : InfinitePlace K} (h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1)
(h₃ : IsReal w ∨ |(w.embedding x).re| < 1) : ℚ⟮(x : K)⟯ = ⊤ := by
rw [Field.primitive_element_iff_algHom_eq_of_eval ℚ ℂ ?_ _ w.embedding.toRatAlgHom]
· intro ψ hψ
have h : 1 ≤ w x := one_le_of_lt_one h₁ h₂
have main : w = InfinitePlace.mk ψ.toRingHom := by
simp at hψ
rw [← norm_embedding_eq, hψ] at h
contrapose! h
exact h₂ h.symm
rw [(mk_embedding w).symm, mk_eq_iff] at main
cases h₃ with
| inl hw =>
rw [conjugate_embedding_eq_of_isReal hw, or_self] at main
exact congr_arg RingHom.toRatAlgHom main
| inr hw =>
refine congr_arg RingHom.toRatAlgHom (main.resolve_right fun h' ↦ hw.not_le ?_)
have : (embedding w x).im = 0 := by
rw [← Complex.conj_eq_iff_im]
have := RingHom.congr_fun h' x
simp at this
rw [this]
exact hψ.symm
rwa [← norm_embedding_eq, ← Complex.re_add_im (embedding w x), this, Complex.ofReal_zero,
zero_mul, add_zero, Complex.norm_real] at h
· exact fun x ↦ IsAlgClosed.splits_codomain (minpoly ℚ x)
theorem _root_.NumberField.adjoin_eq_top_of_infinitePlace_lt {x : 𝓞 K} {w : InfinitePlace K}
(h₁ : x ≠ 0) (h₂ : ∀ ⦃w'⦄, w' ≠ w → w' x < 1) (h₃ : IsReal w ∨ |(w.embedding x).re| < 1) :
Algebra.adjoin ℚ {(x : K)} = ⊤ := by
rw [← IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.of_finite ℚ _)]
exact congr_arg IntermediateField.toSubalgebra <|
NumberField.is_primitive_element_of_infinitePlace_lt h₁ h₂ h₃
end NumberField
open Fintype Module
variable (K)
section NumberField
variable [NumberField K]
open scoped Classical in
/-- The number of infinite real places of the number field `K`. -/
noncomputable abbrev nrRealPlaces := card { w : InfinitePlace K // IsReal w }
@[deprecated (since := "2024-10-24")] alias NrRealPlaces := nrRealPlaces
open scoped Classical in
/-- The number of infinite complex places of the number field `K`. -/
noncomputable abbrev nrComplexPlaces := card { w : InfinitePlace K // IsComplex w }
@[deprecated (since := "2024-10-24")] alias NrComplexPlaces := nrComplexPlaces
open scoped Classical in
theorem card_real_embeddings :
card { φ : K →+* ℂ // ComplexEmbedding.IsReal φ } = nrRealPlaces K := Fintype.card_congr mkReal
theorem card_eq_nrRealPlaces_add_nrComplexPlaces :
Fintype.card (InfinitePlace K) = nrRealPlaces K + nrComplexPlaces K := by
classical
convert Fintype.card_subtype_or_disjoint (IsReal (K := K)) (IsComplex (K := K))
(disjoint_isReal_isComplex K) using 1
exact (Fintype.card_of_subtype _ (fun w ↦ ⟨fun _ ↦ isReal_or_isComplex w, fun _ ↦ by simp⟩)).symm
open scoped Classical in
theorem card_complex_embeddings :
card { φ : K →+* ℂ // ¬ComplexEmbedding.IsReal φ } = 2 * nrComplexPlaces K := by
suffices ∀ w : { w : InfinitePlace K // IsComplex w },
#{φ : {φ //¬ ComplexEmbedding.IsReal φ} | mkComplex φ = w} = 2 by
rw [Fintype.card, Finset.card_eq_sum_ones, ← Finset.sum_fiberwise _ (fun φ => mkComplex φ)]
simp_rw [Finset.sum_const, this, smul_eq_mul, mul_one, Fintype.card, Finset.card_eq_sum_ones,
Finset.mul_sum, Finset.sum_const, smul_eq_mul, mul_one]
rintro ⟨w, hw⟩
convert card_filter_mk_eq w
· rw [← Fintype.card_subtype, ← Fintype.card_subtype]
refine Fintype.card_congr (Equiv.ofBijective ?_ ⟨fun _ _ h => ?_, fun ⟨φ, hφ⟩ => ?_⟩)
· exact fun ⟨φ, hφ⟩ => ⟨φ.val, by rwa [Subtype.ext_iff] at hφ⟩
· rwa [Subtype.mk_eq_mk, ← Subtype.ext_iff, ← Subtype.ext_iff] at h
· refine ⟨⟨⟨φ, not_isReal_of_mk_isComplex (hφ.symm ▸ hw)⟩, ?_⟩, rfl⟩
rwa [Subtype.ext_iff, mkComplex_coe]
· simp_rw [mult, not_isReal_iff_isComplex.mpr hw, ite_false]
theorem card_add_two_mul_card_eq_rank :
nrRealPlaces K + 2 * nrComplexPlaces K = finrank ℚ K := by
classical
rw [← card_real_embeddings, ← card_complex_embeddings, Fintype.card_subtype_compl,
← Embeddings.card K ℂ, Nat.add_sub_of_le]
exact Fintype.card_subtype_le _
variable {K}
theorem nrComplexPlaces_eq_zero_of_finrank_eq_one (h : finrank ℚ K = 1) :
nrComplexPlaces K = 0 := by linarith [card_add_two_mul_card_eq_rank K]
theorem nrRealPlaces_eq_one_of_finrank_eq_one (h : finrank ℚ K = 1) :
nrRealPlaces K = 1 := by
have := card_add_two_mul_card_eq_rank K
rwa [nrComplexPlaces_eq_zero_of_finrank_eq_one h, h, mul_zero, add_zero] at this
theorem nrRealPlaces_pos_of_odd_finrank (h : Odd (finrank ℚ K)) :
0 < nrRealPlaces K := by
refine Nat.pos_of_ne_zero ?_
by_contra hc
refine (Nat.not_odd_iff_even.mpr ?_) h
rw [← card_add_two_mul_card_eq_rank, hc, zero_add]
exact even_two_mul (nrComplexPlaces K)
/-- The restriction of an infinite place along an embedding. -/
def comap (w : InfinitePlace K) (f : k →+* K) : InfinitePlace k :=
⟨w.1.comp f.injective, w.embedding.comp f,
by { ext x; show _ = w.1 (f x); rw [← w.2.choose_spec]; rfl }⟩
end NumberField
variable {K}
@[simp]
lemma comap_mk (φ : K →+* ℂ) (f : k →+* K) : (mk φ).comap f = mk (φ.comp f) := rfl
lemma comap_id (w : InfinitePlace K) : w.comap (RingHom.id K) = w := rfl
lemma comap_comp (w : InfinitePlace K) (f : F →+* K) (g : k →+* F) :
w.comap (f.comp g) = (w.comap f).comap g := rfl
lemma comap_mk_lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) :
(mk (ComplexEmbedding.lift K φ)).comap (algebraMap k K) = mk φ := by simp
lemma IsReal.comap (f : k →+* K) {w : InfinitePlace K} (hφ : IsReal w) :
IsReal (w.comap f) := by
rw [← mk_embedding w, comap_mk, isReal_mk_iff]
rw [← mk_embedding w, isReal_mk_iff] at hφ
exact hφ.comp f
lemma isReal_comap_iff (f : k ≃+* K) {w : InfinitePlace K} :
IsReal (w.comap (f : k →+* K)) ↔ IsReal w := by
rw [← mk_embedding w, comap_mk, isReal_mk_iff, isReal_mk_iff, ComplexEmbedding.isReal_comp_iff]
lemma comap_surjective [Algebra k K] [Algebra.IsAlgebraic k K] :
Function.Surjective (comap · (algebraMap k K)) := fun w ↦
⟨(mk (ComplexEmbedding.lift K w.embedding)), by simp⟩
lemma mult_comap_le (f : k →+* K) (w : InfinitePlace K) : mult (w.comap f) ≤ mult w := by
rw [mult, mult]
split_ifs with h₁ h₂ h₂
pick_goal 3
· exact (h₁ (h₂.comap _)).elim
all_goals decide
variable [Algebra k K] (σ : K ≃ₐ[k] K) (w : InfinitePlace K)
variable (k K)
lemma card_mono [NumberField k] [NumberField K] :
card (InfinitePlace k) ≤ card (InfinitePlace K) :=
have := Module.Finite.of_restrictScalars_finite ℚ k K
Fintype.card_le_of_surjective _ comap_surjective
variable {k K}
/-- The action of the galois group on infinite places. -/
@[simps! smul_coe_apply]
instance : MulAction (K ≃ₐ[k] K) (InfinitePlace K) where
smul := fun σ w ↦ w.comap σ.symm
one_smul := fun _ ↦ rfl
mul_smul := fun _ _ _ ↦ rfl
lemma smul_eq_comap : σ • w = w.comap σ.symm := rfl
@[simp] lemma smul_apply (x) : (σ • w) x = w (σ.symm x) := rfl
@[simp] lemma smul_mk (φ : K →+* ℂ) : σ • mk φ = mk (φ.comp σ.symm) := rfl
lemma comap_smul {f : F →+* K} : (σ • w).comap f = w.comap (RingHom.comp σ.symm f) := rfl
variable {σ w}
lemma isReal_smul_iff : IsReal (σ • w) ↔ IsReal w := isReal_comap_iff (f := σ.symm.toRingEquiv)
lemma isComplex_smul_iff : IsComplex (σ • w) ↔ IsComplex w := by
rw [← not_isReal_iff_isComplex, ← not_isReal_iff_isComplex, isReal_smul_iff]
lemma ComplexEmbedding.exists_comp_symm_eq_of_comp_eq [IsGalois k K] (φ ψ : K →+* ℂ)
(h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) :
∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm }
use (AlgHom.restrictNormal' ψ' K).symm
ext1 x
exact AlgHom.restrictNormal_commutes ψ' K x
lemma exists_smul_eq_of_comap_eq [IsGalois k K] {w w' : InfinitePlace K}
(h : w.comap (algebraMap k K) = w'.comap (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, σ • w = w' := by
rw [← mk_embedding w, ← mk_embedding w', comap_mk, comap_mk, mk_eq_iff] at h
cases h with
| inl h =>
obtain ⟨σ, hσ⟩ := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq w.embedding w'.embedding h
use σ
rw [← mk_embedding w, ← mk_embedding w', smul_mk, hσ]
| inr h =>
obtain ⟨σ, hσ⟩ := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq
((starRingEnd ℂ).comp (embedding w)) w'.embedding h
use σ
rw [← mk_embedding w, ← mk_embedding w', smul_mk, mk_eq_iff]
exact Or.inr hσ
lemma mem_orbit_iff [IsGalois k K] {w w' : InfinitePlace K} :
w' ∈ MulAction.orbit (K ≃ₐ[k] K) w ↔ w.comap (algebraMap k K) = w'.comap (algebraMap k K) := by
refine ⟨?_, exists_smul_eq_of_comap_eq⟩
rintro ⟨σ, rfl : σ • w = w'⟩
rw [← mk_embedding w, comap_mk, smul_mk, comap_mk]
congr 1; ext1; simp
/-- The orbits of infinite places under the action of the galois group are indexed by
the infinite places of the base field. -/
noncomputable
def orbitRelEquiv [IsGalois k K] :
Quotient (MulAction.orbitRel (K ≃ₐ[k] K) (InfinitePlace K)) ≃ InfinitePlace k := by
refine Equiv.ofBijective (Quotient.lift (comap · (algebraMap k K))
fun _ _ e ↦ (mem_orbit_iff.mp e).symm) ⟨?_, ?_⟩
· rintro ⟨w⟩ ⟨w'⟩ e
exact Quotient.sound (mem_orbit_iff.mpr e.symm)
· intro w
obtain ⟨w', hw⟩ := comap_surjective (K := K) w
exact ⟨⟦w'⟧, hw⟩
lemma orbitRelEquiv_apply_mk'' [IsGalois k K] (w : InfinitePlace K) :
orbitRelEquiv (Quotient.mk'' w) = comap w (algebraMap k K) := rfl
variable (k w)
/--
An infinite place is unramified in a field extension if the restriction has the same multiplicity.
-/
def IsUnramified : Prop := mult (w.comap (algebraMap k K)) = mult w
variable {k}
lemma isUnramified_self : IsUnramified K w := rfl
variable {w}
lemma IsUnramified.eq (h : IsUnramified k w) : mult (w.comap (algebraMap k K)) = mult w := h
lemma isUnramified_iff_mult_le :
IsUnramified k w ↔ mult w ≤ mult (w.comap (algebraMap k K)) := by
rw [IsUnramified, le_antisymm_iff, and_iff_right]
exact mult_comap_le _ _
variable [Algebra k F]
lemma IsUnramified.comap_algHom {w : InfinitePlace F} (h : IsUnramified k w) (f : K →ₐ[k] F) :
IsUnramified k (w.comap (f : K →+* F)) := by
rw [InfinitePlace.isUnramified_iff_mult_le, ← InfinitePlace.comap_comp, f.comp_algebraMap, h.eq]
exact InfinitePlace.mult_comap_le _ _
variable (K)
variable [Algebra K F] [IsScalarTower k K F]
lemma IsUnramified.of_restrictScalars {w : InfinitePlace F} (h : IsUnramified k w) :
IsUnramified K w := by
rw [InfinitePlace.isUnramified_iff_mult_le, ← h.eq, IsScalarTower.algebraMap_eq k K F,
InfinitePlace.comap_comp]
exact InfinitePlace.mult_comap_le _ _
lemma IsUnramified.comap {w : InfinitePlace F} (h : IsUnramified k w) :
IsUnramified k (w.comap (algebraMap K F)) :=
h.comap_algHom (IsScalarTower.toAlgHom k K F)
variable {K}
lemma not_isUnramified_iff :
¬ IsUnramified k w ↔ IsComplex w ∧ IsReal (w.comap (algebraMap k K)) := by
rw [IsUnramified, mult, mult, ← not_isReal_iff_isComplex]
split_ifs with h₁ h₂ h₂ <;>
simp only [not_true_eq_false, false_iff, and_self, forall_true_left, IsEmpty.forall_iff,
not_and, OfNat.one_ne_ofNat, not_false_eq_true, true_iff, OfNat.ofNat_ne_one, h₁, h₂]
exact h₁ (h₂.comap _)
lemma isUnramified_iff :
IsUnramified k w ↔ IsReal w ∨ IsComplex (w.comap (algebraMap k K)) := by
rw [← not_iff_not, not_isUnramified_iff, not_or,
not_isReal_iff_isComplex, not_isComplex_iff_isReal]
variable (k)
lemma IsReal.isUnramified (h : IsReal w) : IsUnramified k w := isUnramified_iff.mpr (Or.inl h)
variable {k}
lemma _root_.NumberField.ComplexEmbedding.IsConj.isUnramified_mk_iff
{φ : K →+* ℂ} (h : ComplexEmbedding.IsConj φ σ) :
IsUnramified k (mk φ) ↔ σ = 1 := by
rw [h.ext_iff, ComplexEmbedding.isConj_one_iff, ← not_iff_not, not_isUnramified_iff,
← not_isReal_iff_isComplex, comap_mk, isReal_mk_iff, isReal_mk_iff, eq_true h.isReal_comp,
and_true]
lemma isUnramified_mk_iff_forall_isConj [IsGalois k K] {φ : K →+* ℂ} :
IsUnramified k (mk φ) ↔ ∀ σ : K ≃ₐ[k] K, ComplexEmbedding.IsConj φ σ → σ = 1 := by
refine ⟨fun H σ hσ ↦ hσ.isUnramified_mk_iff.mp H,
fun H ↦ ?_⟩
by_contra hφ
rw [not_isUnramified_iff] at hφ
rw [comap_mk, isReal_mk_iff, ← not_isReal_iff_isComplex, isReal_mk_iff,
← ComplexEmbedding.isConj_one_iff (k := k)] at hφ
letI := (φ.comp (algebraMap k K)).toAlgebra
letI := φ.toAlgebra
have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl
let φ' : K →ₐ[k] ℂ := { star φ with commutes' := fun r ↦ by simpa using RingHom.congr_fun hφ.2 r }
have : ComplexEmbedding.IsConj φ (AlgHom.restrictNormal' φ' K) :=
(RingHom.ext <| AlgHom.restrictNormal_commutes φ' K).symm
exact hφ.1 (H _ this ▸ this)
local notation "Stab" => MulAction.stabilizer (K ≃ₐ[k] K)
lemma mem_stabilizer_mk_iff (φ : K →+* ℂ) (σ : K ≃ₐ[k] K) :
σ ∈ Stab (mk φ) ↔ σ = 1 ∨ ComplexEmbedding.IsConj φ σ := by
simp only [MulAction.mem_stabilizer_iff, smul_mk, mk_eq_iff]
rw [← ComplexEmbedding.isConj_symm, ComplexEmbedding.conjugate, star_eq_iff_star_eq]
refine or_congr ⟨fun H ↦ ?_, fun H ↦ H ▸ rfl⟩ Iff.rfl
exact congr_arg AlgEquiv.symm
(AlgEquiv.ext (g := AlgEquiv.refl) fun x ↦ φ.injective (RingHom.congr_fun H x))
lemma IsUnramified.stabilizer_eq_bot (h : IsUnramified k w) : Stab w = ⊥ := by
rw [eq_bot_iff, ← mk_embedding w, SetLike.le_def]
simp only [mem_stabilizer_mk_iff, Subgroup.mem_bot, forall_eq_or_imp, true_and]
exact fun σ hσ ↦ hσ.isUnramified_mk_iff.mp ((mk_embedding w).symm ▸ h)
lemma _root_.NumberField.ComplexEmbedding.IsConj.coe_stabilzer_mk
{φ : K →+* ℂ} (h : ComplexEmbedding.IsConj φ σ) :
(Stab (mk φ) : Set (K ≃ₐ[k] K)) = {1, σ} := by
ext
rw [SetLike.mem_coe, mem_stabilizer_mk_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
← h.ext_iff, eq_comm (a := σ)]
variable (k w)
lemma nat_card_stabilizer_eq_one_or_two :
Nat.card (Stab w) = 1 ∨ Nat.card (Stab w) = 2 := by
classical
rw [← SetLike.coe_sort_coe, ← mk_embedding w]
by_cases h : ∃ σ, ComplexEmbedding.IsConj (k := k) (embedding w) σ
· obtain ⟨σ, hσ⟩ := h
simp only [hσ.coe_stabilzer_mk, Nat.card_eq_fintype_card, card_ofFinset, Set.toFinset_singleton]
by_cases 1 = σ
· left; simp [*]
· right; simp [*]
· push_neg at h
left
trans Nat.card ({1} : Set (K ≃ₐ[k] K))
· congr with x
simp only [SetLike.mem_coe, mem_stabilizer_mk_iff, Set.mem_singleton_iff, or_iff_left_iff_imp,
h x, IsEmpty.forall_iff]
· simp
variable {k w}
lemma isUnramified_iff_stabilizer_eq_bot [IsGalois k K] : IsUnramified k w ↔ Stab w = ⊥ := by
rw [← mk_embedding w, isUnramified_mk_iff_forall_isConj]
simp only [eq_bot_iff, SetLike.le_def, mem_stabilizer_mk_iff,
Subgroup.mem_bot, forall_eq_or_imp, true_and]
lemma isUnramified_iff_card_stabilizer_eq_one [IsGalois k K] :
IsUnramified k w ↔ Nat.card (Stab w) = 1 := by
rw [isUnramified_iff_stabilizer_eq_bot, Subgroup.card_eq_one]
lemma not_isUnramified_iff_card_stabilizer_eq_two [IsGalois k K] :
¬ IsUnramified k w ↔ Nat.card (Stab w) = 2 := by
rw [isUnramified_iff_card_stabilizer_eq_one]
obtain (e|e) := nat_card_stabilizer_eq_one_or_two k w <;> rw [e] <;> decide
open scoped Classical in
lemma card_stabilizer [IsGalois k K] :
Nat.card (Stab w) = if IsUnramified k w then 1 else 2 := by
split
· rwa [← isUnramified_iff_card_stabilizer_eq_one]
· rwa [← not_isUnramified_iff_card_stabilizer_eq_two]
lemma even_nat_card_aut_of_not_isUnramified [IsGalois k K] (hw : ¬ IsUnramified k w) :
Even (Nat.card <| K ≃ₐ[k] K) := by
by_cases H : Finite (K ≃ₐ[k] K)
· cases nonempty_fintype (K ≃ₐ[k] K)
rw [even_iff_two_dvd, ← not_isUnramified_iff_card_stabilizer_eq_two.mp hw]
exact Subgroup.card_subgroup_dvd_card (Stab w)
· convert Even.zero
by_contra e
exact H (Nat.finite_of_card_ne_zero e)
lemma even_card_aut_of_not_isUnramified [IsGalois k K] [FiniteDimensional k K]
(hw : ¬ IsUnramified k w) :
Even (Fintype.card <| K ≃ₐ[k] K) :=
Nat.card_eq_fintype_card (α := K ≃ₐ[k] K) ▸ even_nat_card_aut_of_not_isUnramified hw
lemma even_finrank_of_not_isUnramified [IsGalois k K]
(hw : ¬ IsUnramified k w) : Even (finrank k K) := by
by_cases FiniteDimensional k K
· exact IsGalois.card_aut_eq_finrank k K ▸ even_card_aut_of_not_isUnramified hw
· exact finrank_of_not_finite ‹_› ▸ Even.zero
lemma isUnramified_smul_iff :
IsUnramified k (σ • w) ↔ IsUnramified k w := by
rw [isUnramified_iff, isUnramified_iff, isReal_smul_iff, comap_smul,
← AlgEquiv.toAlgHom_toRingHom, AlgHom.comp_algebraMap]
variable (K) in
/-- A infinite place of the base field is unramified in a field extension if every
infinite place over it is unramified. -/
def IsUnramifiedIn (w : InfinitePlace k) : Prop :=
∀ v, comap v (algebraMap k K) = w → IsUnramified k v
lemma isUnramifiedIn_comap [IsGalois k K] {w : InfinitePlace K} :
(w.comap (algebraMap k K)).IsUnramifiedIn K ↔ w.IsUnramified k := by
refine ⟨fun H ↦ H _ rfl, fun H v hv ↦ ?_⟩
obtain ⟨σ, rfl⟩ := exists_smul_eq_of_comap_eq hv
rwa [isUnramified_smul_iff] at H
lemma even_card_aut_of_not_isUnramifiedIn [IsGalois k K] [FiniteDimensional k K]
{w : InfinitePlace k} (hw : ¬ w.IsUnramifiedIn K) :
Even (Fintype.card <| K ≃ₐ[k] K) := by
obtain ⟨v, rfl⟩ := comap_surjective (K := K) w
rw [isUnramifiedIn_comap] at hw
exact even_card_aut_of_not_isUnramified hw
lemma even_finrank_of_not_isUnramifiedIn
[IsGalois k K] {w : InfinitePlace k} (hw : ¬ w.IsUnramifiedIn K) :
Even (finrank k K) := by
obtain ⟨v, rfl⟩ := comap_surjective (K := K) w
rw [isUnramifiedIn_comap] at hw
exact even_finrank_of_not_isUnramified hw
variable (k K)
variable [NumberField K]
open Finset in
open scoped Classical in
lemma card_isUnramified [NumberField k] [IsGalois k K] :
#{w : InfinitePlace K | w.IsUnramified k} =
#{w : InfinitePlace k | w.IsUnramifiedIn K} * finrank k K := by
letI := Module.Finite.of_restrictScalars_finite ℚ k K
rw [← IsGalois.card_aut_eq_finrank,
Finset.card_eq_sum_card_fiberwise (f := (comap · (algebraMap k K)))
(t := {w : InfinitePlace k | w.IsUnramifiedIn K}), ← smul_eq_mul, ← sum_const]
· refine sum_congr rfl (fun w hw ↦ ?_)
obtain ⟨w, rfl⟩ := comap_surjective (K := K) w
simp only [mem_univ, forall_true_left, mem_filter, true_and] at hw
trans #(MulAction.orbit (K ≃ₐ[k] K) w).toFinset
· congr; ext w'
simp only [mem_univ, forall_true_left, filter_congr_decidable, mem_filter, true_and,
Set.mem_toFinset, mem_orbit_iff, @eq_comm _ (comap w' _), and_iff_right_iff_imp]
intro e; rwa [← isUnramifiedIn_comap, ← e]
· rw [← MulAction.card_orbit_mul_card_stabilizer_eq_card_group _ w,
← Nat.card_eq_fintype_card (α := Stab w), card_stabilizer, if_pos,
mul_one, Set.toFinset_card]
rwa [← isUnramifiedIn_comap]
· simp [Set.MapsTo, isUnramifiedIn_comap]
open Finset in
open scoped Classical in
lemma card_isUnramified_compl [NumberField k] [IsGalois k K] :
#({w : InfinitePlace K | w.IsUnramified k} : Finset _)ᶜ =
#({w : InfinitePlace k | w.IsUnramifiedIn K} : Finset _)ᶜ * (finrank k K / 2) := by
letI := Module.Finite.of_restrictScalars_finite ℚ k K
rw [← IsGalois.card_aut_eq_finrank,
Finset.card_eq_sum_card_fiberwise (f := (comap · (algebraMap k K)))
(t := ({w : InfinitePlace k | w.IsUnramifiedIn K}: Finset _)ᶜ), ← smul_eq_mul, ← sum_const]
· refine sum_congr rfl (fun w hw ↦ ?_)
obtain ⟨w, rfl⟩ := comap_surjective (K := K) w
simp only [mem_univ, forall_true_left, compl_filter, not_not, mem_filter, true_and] at hw
trans Finset.card (MulAction.orbit (K ≃ₐ[k] K) w).toFinset
· congr; ext w'
simp only [compl_filter, filter_congr_decidable, mem_filter, mem_univ, true_and,
@eq_comm _ (comap w' _), Set.mem_toFinset, mem_orbit_iff, and_iff_right_iff_imp]
intro e; rwa [← isUnramifiedIn_comap, ← e]
· rw [← MulAction.card_orbit_mul_card_stabilizer_eq_card_group _ w,
← Nat.card_eq_fintype_card (α := Stab w), InfinitePlace.card_stabilizer, if_neg,
Nat.mul_div_cancel _ zero_lt_two, Set.toFinset_card]
rwa [← isUnramifiedIn_comap]
· simp [Set.MapsTo, isUnramifiedIn_comap]
open scoped Classical in
lemma card_eq_card_isUnramifiedIn [NumberField k] [IsGalois k K] :
Fintype.card (InfinitePlace K) =
#{w : InfinitePlace k | w.IsUnramifiedIn K} * finrank k K +
#({w : InfinitePlace k | w.IsUnramifiedIn K} : Finset _)ᶜ * (finrank k K / 2) := by
rw [← card_isUnramified, ← card_isUnramified_compl, Finset.card_add_card_compl]
end NumberField.InfinitePlace
variable (k K F)
variable [Algebra k K] [Algebra k F] [Algebra K F] [IsScalarTower k K F]
/-- A field extension is unramified at infinite places if every infinite place is unramified. -/
| class IsUnramifiedAtInfinitePlaces : Prop where
isUnramified : ∀ w : InfinitePlace K, w.IsUnramified k
instance IsUnramifiedAtInfinitePlaces.id : IsUnramifiedAtInfinitePlaces K K where
isUnramified w := w.isUnramified_self
lemma IsUnramifiedAtInfinitePlaces.trans
[h₁ : IsUnramifiedAtInfinitePlaces k K] [h₂ : IsUnramifiedAtInfinitePlaces K F] :
| Mathlib/NumberTheory/NumberField/Embeddings.lean | 1,059 | 1,066 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
/-!
# The argument of a complex number.
We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π],
such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
while `arg 0` defaults to `0`
-/
open Filter Metric Set
open scoped ComplexConjugate Real Topology
namespace Complex
variable {a x z : ℂ}
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re then Real.arcsin (x.im / ‖x‖)
else if 0 ≤ x.im then Real.arcsin ((-x).im / ‖x‖) + π else Real.arcsin ((-x).im / ‖x‖) - π
theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / ‖x‖ := by
unfold arg; split_ifs <;>
simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1
(abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]
theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / ‖x‖ := by
rw [arg]
split_ifs with h₁ h₂
· rw [Real.cos_arcsin]
field_simp [Real.sqrt_sq, (norm_pos_iff.mpr hx).le, *]
· rw [Real.cos_add_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
· rw [Real.cos_sub_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
@[simp]
theorem norm_mul_exp_arg_mul_I (x : ℂ) : ‖x‖ * exp (arg x * I) = x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· have : ‖x‖ ≠ 0 := norm_ne_zero_iff.mpr hx
apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm ‖x‖]
@[simp]
theorem norm_mul_cos_add_sin_mul_I (x : ℂ) : (‖x‖ * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by
rw [← exp_mul_I, norm_mul_exp_arg_mul_I]
@[simp]
lemma norm_mul_cos_arg (x : ℂ) : ‖x‖ * Real.cos (arg x) = x.re := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x)
@[simp]
| lemma norm_mul_sin_arg (x : ℂ) : ‖x‖ * Real.sin (arg x) = x.im := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x)
| Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean | 63 | 64 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Order.Filter.AtTopBot.Archimedean
import Mathlib.Order.Iterate
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.Algebra.InfiniteSum.Real
import Mathlib.Topology.Instances.EReal.Lemmas
/-!
# A collection of specific limit computations
This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains
important specific limit computations in metric spaces, in ordered rings/fields, and in specific
instances of these such as `ℝ`, `ℝ≥0` and `ℝ≥0∞`.
-/
assert_not_exists Basis NormedSpace
noncomputable section
open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal
variable {α : Type*} {β : Type*} {ι : Type*}
theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop
theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat
theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) :=
tendsto_const_div_atTop_nhds_zero_nat 1
| theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
rw [← NNReal.tendsto_coe]
| Mathlib/Analysis/SpecificLimits/Basic.lean | 39 | 41 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Data.List.Lattice
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Lattice
/-!
# Intervals in ℕ
This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m`
and strictly less than `n`.
## TODO
- Define `Ioo` and `Icc`, state basic lemmas about them.
- Also do the versions for integers?
- One could generalise even further, defining 'locally finite partial orders', for which
`Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model.
- Once the above is done, get rid of `Int.range` (and maybe `List.range'`?).
-/
open Nat
namespace List
/-- `Ico n m` is the list of natural numbers `n ≤ x < m`.
(Ico stands for "interval, closed-open".)
See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well
as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico`
for sets, multisets and finite sets respectively.
-/
def Ico (n m : ℕ) : List ℕ :=
range' n (m - n)
namespace Ico
theorem zero_bot (n : ℕ) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range']
@[simp]
theorem length (n m : ℕ) : length (Ico n m) = m - n := by
dsimp [Ico]
simp [length_range']
theorem pairwise_lt (n m : ℕ) : Pairwise (· < ·) (Ico n m) := by
dsimp [Ico]
simp [pairwise_lt_range']
theorem nodup (n m : ℕ) : Nodup (Ico n m) := by
dsimp [Ico]
simp [nodup_range']
@[simp]
theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m := by
suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m by simp [Ico, this]
omega
theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] := by
simp [Ico, Nat.sub_eq_zero_iff_le.mpr h]
theorem map_add (n m k : ℕ) : (Ico n m).map (k + ·) = Ico (n + k) (m + k) := by
rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k]
theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) :
((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by
rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' h₁]
@[simp]
theorem self_empty {n : ℕ} : Ico n n = [] :=
eq_nil_of_le (le_refl n)
@[simp]
theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n :=
Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le
theorem append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) :
Ico n m ++ Ico m l = Ico n l := by
dsimp only [Ico]
convert range'_append using 2
· rw [Nat.one_mul, Nat.add_sub_cancel' hnm]
· omega
@[simp]
theorem inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] := by
apply eq_nil_iff_forall_not_mem.2
intro a
simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem]
intro _ h₂ h₃
exfalso
exact not_lt_of_ge h₃ h₂
@[simp]
theorem bagInter_consecutive (n m l : Nat) :
@List.bagInter ℕ instBEqOfDecidableEq (Ico n m) (Ico m l) = [] :=
(bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l)
@[simp]
theorem succ_singleton {n : ℕ} : Ico n (n + 1) = [n] := by
dsimp [Ico]
simp [range', Nat.add_sub_cancel_left]
theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = Ico n m ++ [m] := by
rwa [← succ_singleton, append_consecutive]
exact Nat.le_succ _
theorem eq_cons {n m : ℕ} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by
rw [← append_consecutive (Nat.le_succ n) h, succ_singleton]
rfl
@[simp]
theorem pred_singleton {m : ℕ} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by
simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)]
theorem chain'_succ (n m : ℕ) : Chain' (fun a b => b = succ a) (Ico n m) := by
by_cases h : n < m
· rw [eq_cons h]
exact chain_succ_range' _ _ 1
· rw [eq_nil_of_le (le_of_not_gt h)]
trivial
theorem not_mem_top {n m : ℕ} : m ∉ Ico n m := by simp
theorem filter_lt_of_top_le {n m l : ℕ} (hml : m ≤ l) :
((Ico n m).filter fun x => x < l) = Ico n m :=
filter_eq_self.2 fun k hk => by
simp only [(lt_of_lt_of_le (mem.1 hk).2 hml), decide_true]
theorem filter_lt_of_le_bot {n m l : ℕ} (hln : l ≤ n) : ((Ico n m).filter fun x => x < l) = [] :=
filter_eq_nil_iff.2 fun k hk => by
simp only [decide_eq_true_eq, not_lt]
apply le_trans hln
exact (mem.1 hk).1
theorem filter_lt_of_ge {n m l : ℕ} (hlm : l ≤ m) :
((Ico n m).filter fun x => x < l) = Ico n l := by
rcases le_total n l with hnl | hln
· rw [← append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l),
filter_lt_of_le_bot (le_refl l), append_nil]
· rw [eq_nil_of_le hln, filter_lt_of_le_bot hln]
@[simp]
theorem filter_lt (n m l : ℕ) :
((Ico n m).filter fun x => x < l) = Ico n (min m l) := by
rcases le_total m l with hml | hlm
· rw [min_eq_left hml, filter_lt_of_top_le hml]
· rw [min_eq_right hlm, filter_lt_of_ge hlm]
theorem filter_le_of_le_bot {n m l : ℕ} (hln : l ≤ n) :
((Ico n m).filter fun x => l ≤ x) = Ico n m :=
filter_eq_self.2 fun k hk => by
rw [decide_eq_true_eq]
exact le_trans hln (mem.1 hk).1
theorem filter_le_of_top_le {n m l : ℕ} (hml : m ≤ l) : ((Ico n m).filter fun x => l ≤ x) = [] :=
filter_eq_nil_iff.2 fun k hk => by
rw [decide_eq_true_eq]
exact not_le_of_gt (lt_of_lt_of_le (mem.1 hk).2 hml)
theorem filter_le_of_le {n m l : ℕ} (hnl : n ≤ l) :
((Ico n m).filter fun x => l ≤ x) = Ico l m := by
rcases le_total l m with hlm | hml
· rw [← append_consecutive hnl hlm, filter_append, filter_le_of_top_le (le_refl l),
filter_le_of_le_bot (le_refl l), nil_append]
· rw [eq_nil_of_le hml, filter_le_of_top_le hml]
@[simp]
theorem filter_le (n m l : ℕ) : ((Ico n m).filter fun x => l ≤ x) = Ico (max n l) m := by
rcases le_total n l with hnl | hln
· rw [max_eq_right hnl, filter_le_of_le hnl]
· rw [max_eq_left hln, filter_le_of_le_bot hln]
theorem filter_lt_of_succ_bot {n m : ℕ} (hnm : n < m) :
((Ico n m).filter fun x => x < n + 1) = [n] := by
have r : min m (n + 1) = n + 1 := (@inf_eq_right _ _ m (n + 1)).mpr hnm
simp [filter_lt n m (n + 1), r]
@[simp]
theorem filter_le_of_bot {n m : ℕ} (hnm : n < m) : ((Ico n m).filter fun x => x ≤ n) = [n] := by
rw [← filter_lt_of_succ_bot hnm]
exact filter_congr fun _ _ => by
simpa using Nat.lt_succ_iff.symm
/-- For any natural numbers n, a, and b, one of the following holds:
1. n < a
2. n ≥ b
3. n ∈ Ico a b
-/
theorem trichotomy (n a b : ℕ) : n < a ∨ b ≤ n ∨ n ∈ Ico a b := by
by_cases h₁ : n < a
· left
exact h₁
· right
by_cases h₂ : n ∈ Ico a b
· right
exact h₂
· left
simp only [Ico.mem, not_and, not_lt] at *
exact h₂ h₁
end Ico
end List
| Mathlib/Data/List/Intervals.lean | 207 | 210 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Data.Finite.Sum
import Mathlib.RingTheory.FiniteType
import Mathlib.RingTheory.Finiteness.Ideal
import Mathlib.RingTheory.Ideal.Quotient.Operations
import Mathlib.RingTheory.MvPolynomial.Tower
/-!
# Finiteness conditions in commutative algebra
In this file we define several notions of finiteness that are common in commutative algebra.
## Main declarations
- `Module.Finite`, `RingHom.Finite`, `AlgHom.Finite`
all of these express that some object is finitely generated *as module* over some base ring.
- `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType`
all of these express that some object is finitely generated *as algebra* over some base ring.
- `Algebra.FinitePresentation`, `RingHom.FinitePresentation`, `AlgHom.FinitePresentation`
all of these express that some object is finitely presented *as algebra* over some base ring.
-/
open Function (Surjective)
open Polynomial
section ModuleAndAlgebra
universe w₁ w₂ w₃
-- Porting note: `M, N` is never used
variable (R : Type w₁) (A : Type w₂) (B : Type w₃)
/-- An algebra over a commutative semiring is `Algebra.FinitePresentation` if it is the quotient of
a polynomial ring in `n` variables by a finitely generated ideal. -/
class Algebra.FinitePresentation [CommSemiring R] [Semiring A] [Algebra R A] : Prop where
out : ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] A), Surjective f ∧ (RingHom.ker f.toRingHom).FG
namespace Algebra
variable [CommRing R] [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
namespace FiniteType
variable {R A B}
/-- A finitely presented algebra is of finite type. -/
instance of_finitePresentation [FinitePresentation R A] : FiniteType R A := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
apply FiniteType.iff_quotient_mvPolynomial''.2
exact ⟨n, f, hf.1⟩
end FiniteType
namespace FinitePresentation
variable {R A B}
/-- An algebra over a Noetherian ring is finitely generated if and only if it is finitely
presented. -/
theorem of_finiteType [IsNoetherianRing R] : FiniteType R A ↔ FinitePresentation R A := by
refine ⟨fun h => ?_, fun hfp => Algebra.FiniteType.of_finitePresentation⟩
obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.1 h
refine ⟨n, f, hf, ?_⟩
have hnoet : IsNoetherianRing (MvPolynomial (Fin n) R) := by infer_instance
-- Porting note: rewrote code to help typeclass inference
rw [isNoetherianRing_iff] at hnoet
letI : Module (MvPolynomial (Fin n) R) (MvPolynomial (Fin n) R) := Semiring.toModule
convert hnoet.noetherian (RingHom.ker f.toRingHom)
/-- If `e : A ≃ₐ[R] B` and `A` is finitely presented, then so is `B`. -/
theorem equiv [FinitePresentation R A] (e : A ≃ₐ[R] B) : FinitePresentation R B := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
use n, AlgHom.comp (↑e) f
constructor
· rw [AlgHom.coe_comp]
exact Function.Surjective.comp e.surjective hf.1
suffices (RingHom.ker (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom) = RingHom.ker f.toRingHom by
rw [this]
exact hf.2
have hco : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom = RingHom.comp (e.toRingEquiv : A ≃+* B)
f.toRingHom := by
have h : (AlgHom.comp (e : A →ₐ[R] B) f).toRingHom =
e.toAlgHom.toRingHom.comp f.toRingHom := rfl
have h1 : ↑e.toRingEquiv = e.toAlgHom.toRingHom := rfl
rw [h, h1]
rw [RingHom.ker_eq_comap_bot, hco, ← Ideal.comap_comap, ← RingHom.ker_eq_comap_bot,
RingHom.ker_coe_equiv (AlgEquiv.toRingEquiv e), RingHom.ker_eq_comap_bot]
variable (R)
/-- The ring of polynomials in finitely many variables is finitely presented. -/
protected instance mvPolynomial (ι : Type*) [Finite ι] :
FinitePresentation R (MvPolynomial ι R) where
out := by
cases nonempty_fintype ι
let eqv := (MvPolynomial.renameEquiv R <| Fintype.equivFin ι).symm
exact
⟨Fintype.card ι, eqv, eqv.surjective,
((RingHom.injective_iff_ker_eq_bot _).1 eqv.injective).symm ▸ Submodule.fg_bot⟩
/-- `R` is finitely presented as `R`-algebra. -/
instance self : FinitePresentation R R :=
-- Porting note: replaced `PEmpty` with `Empty`
equiv (MvPolynomial.isEmptyAlgEquiv R Empty)
/-- `R[X]` is finitely presented as `R`-algebra. -/
instance polynomial : FinitePresentation R R[X] :=
-- Porting note: replaced `PUnit` with `Unit`
letI := FinitePresentation.mvPolynomial R Unit
equiv (MvPolynomial.pUnitAlgEquiv R)
variable {R}
/-- The quotient of a finitely presented algebra by a finitely generated ideal is finitely
presented. -/
protected theorem quotient {I : Ideal A} (h : I.FG) [FinitePresentation R A] :
FinitePresentation R (A ⧸ I) where
out := by
obtain ⟨n, f, hf⟩ := FinitePresentation.out (R := R) (A := A)
refine ⟨n, (Ideal.Quotient.mkₐ R I).comp f, ?_, ?_⟩
· exact (Ideal.Quotient.mkₐ_surjective R I).comp hf.1
· refine Ideal.fg_ker_comp _ _ hf.2 ?_ hf.1
simp [h]
/-- If `f : A →ₐ[R] B` is surjective with finitely generated kernel and `A` is finitely presented,
then so is `B`. -/
theorem of_surjective {f : A →ₐ[R] B} (hf : Function.Surjective f)
(hker : (RingHom.ker f.toRingHom).FG)
[FinitePresentation R A] : FinitePresentation R B :=
letI : FinitePresentation R (A ⧸ RingHom.ker f) := FinitePresentation.quotient hker
equiv (Ideal.quotientKerAlgEquivOfSurjective hf)
theorem iff :
FinitePresentation R A ↔
∃ (n : _) (I : Ideal (MvPolynomial (Fin n) R)) (_ : (_ ⧸ I) ≃ₐ[R] A), I.FG := by
constructor
· rintro ⟨n, f, hf⟩
exact ⟨n, RingHom.ker f.toRingHom, Ideal.quotientKerAlgEquivOfSurjective hf.1, hf.2⟩
· rintro ⟨n, I, e, hfg⟩
letI := (FinitePresentation.mvPolynomial R _).quotient hfg
exact equiv e
/-- An algebra is finitely presented if and only if it is a quotient of a polynomial ring whose
variables are indexed by a fintype by a finitely generated ideal. -/
theorem iff_quotient_mvPolynomial' :
FinitePresentation R A ↔
∃ (ι : Type*) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] A),
Surjective f ∧ (RingHom.ker f.toRingHom).FG := by
constructor
· rintro ⟨n, f, hfs, hfk⟩
set ulift_var := MvPolynomial.renameEquiv R Equiv.ulift
refine
⟨ULift (Fin n), inferInstance, f.comp ulift_var.toAlgHom, hfs.comp ulift_var.surjective,
Ideal.fg_ker_comp _ _ ?_ hfk ulift_var.surjective⟩
simpa using Submodule.fg_bot
· rintro ⟨ι, hfintype, f, hf⟩
have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι)
use Fintype.card ι, f.comp equiv.symm, hf.1.comp (AlgEquiv.symm equiv).surjective
refine Ideal.fg_ker_comp (S := MvPolynomial ι R) (A := A) _ f ?_ hf.2 equiv.symm.surjective
simpa using Submodule.fg_bot
universe v in
-- Porting note: make universe level explicit to ensure `ι, ι'` has the same universe level
/-- If `A` is a finitely presented `R`-algebra, then `MvPolynomial (Fin n) A` is finitely presented
as `R`-algebra. -/
theorem mvPolynomial_of_finitePresentation [FinitePresentation.{w₁, w₂} R A]
(ι : Type v) [Finite ι] :
FinitePresentation.{w₁, max v w₂} R (MvPolynomial ι A) := by
have hfp : FinitePresentation.{w₁, w₂} R A := inferInstance
rw [iff_quotient_mvPolynomial'] at hfp ⊢
classical
-- Porting note: use the same universe level
obtain ⟨(ι' : Type v), _, f, hf_surj, hf_ker⟩ := hfp
let g := (MvPolynomial.mapAlgHom f).comp (MvPolynomial.sumAlgEquiv R ι ι').toAlgHom
cases nonempty_fintype (ι ⊕ ι')
refine
⟨ι ⊕ ι', by infer_instance, g,
(MvPolynomial.map_surjective f.toRingHom hf_surj).comp (AlgEquiv.surjective _),
Ideal.fg_ker_comp _ _ ?_ ?_ (AlgEquiv.surjective _)⟩
· rw [AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_toRingHom, AlgHom.ker_coe_equiv]
exact Submodule.fg_bot
· rw [AlgHom.toRingHom_eq_coe, MvPolynomial.mapAlgHom_coe_ringHom, MvPolynomial.ker_map]
exact hf_ker.map MvPolynomial.C
| variable (R A B)
/-- If `A` is an `R`-algebra and `S` is an `A`-algebra, both finitely presented, then `S` is
finitely presented as `R`-algebra. -/
theorem trans [Algebra A B] [IsScalarTower R A B] [FinitePresentation R A]
[FinitePresentation A B] : FinitePresentation R B := by
have hfpB : FinitePresentation A B := inferInstance
obtain ⟨n, I, e, hfg⟩ := iff.1 hfpB
letI : FinitePresentation R (MvPolynomial (Fin n) A ⧸ I) :=
(mvPolynomial_of_finitePresentation _).quotient hfg
exact equiv (e.restrictScalars R)
open MvPolynomial
-- TODO: extract out helper lemmas and tidy proof.
@[stacks 0561]
theorem of_restrict_scalars_finitePresentation [Algebra A B] [IsScalarTower R A B]
[FinitePresentation.{w₁, w₃} R B] [FiniteType R A] :
FinitePresentation.{w₂, w₃} A B := by
classical
obtain ⟨n, f, hf, s, hs⟩ := FinitePresentation.out (R := R) (A := B)
| Mathlib/RingTheory/FinitePresentation.lean | 191 | 211 |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn
-/
import Mathlib.Geometry.Manifold.MFDeriv.Defs
import Mathlib.Geometry.Manifold.ContMDiff.Defs
/-!
# Basic properties of the manifold Fréchet derivative
In this file, we show various properties of the manifold Fréchet derivative,
mimicking the API for Fréchet derivatives.
- basic properties of unique differentiability sets
- various general lemmas about the manifold Fréchet derivative
- deducing differentiability from smoothness,
- deriving continuity from differentiability on manifolds,
- congruence lemmas for derivatives on manifolds
- composition lemmas and the chain rule
-/
noncomputable section
assert_not_exists tangentBundleCore
open scoped Topology Manifold
open Set Bundle ChartedSpace
section DerivativesProperties
/-! ### Unique differentiability sets in manifolds -/
variable
{𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
{H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H)
{M : Type*} [TopologicalSpace M] [ChartedSpace H M]
{E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E']
{H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'}
{M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
{E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E'']
{H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''}
{M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M'']
{f f₁ : M → M'} {x : M} {s t : Set M} {g : M' → M''} {u : Set M'}
theorem uniqueMDiffWithinAt_univ : UniqueMDiffWithinAt I univ x := by
unfold UniqueMDiffWithinAt
simp only [preimage_univ, univ_inter]
exact I.uniqueDiffOn _ (mem_range_self _)
variable {I}
theorem uniqueMDiffWithinAt_iff_inter_range {s : Set M} {x : M} :
UniqueMDiffWithinAt I s x ↔
UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ range I)
((extChartAt I x) x) := Iff.rfl
theorem uniqueMDiffWithinAt_iff {s : Set M} {x : M} :
UniqueMDiffWithinAt I s x ↔
UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ (extChartAt I x).target)
((extChartAt I x) x) := by
apply uniqueDiffWithinAt_congr
rw [nhdsWithin_inter, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq]
nonrec theorem UniqueMDiffWithinAt.mono_nhds {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x)
(ht : 𝓝[s] x ≤ 𝓝[t] x) : UniqueMDiffWithinAt I t x :=
hs.mono_nhds <| by simpa only [← map_extChartAt_nhdsWithin] using Filter.map_mono ht
theorem UniqueMDiffWithinAt.mono_of_mem_nhdsWithin {s t : Set M} {x : M}
(hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I t x :=
hs.mono_nhds (nhdsWithin_le_iff.2 ht)
@[deprecated (since := "2024-10-31")]
alias UniqueMDiffWithinAt.mono_of_mem := UniqueMDiffWithinAt.mono_of_mem_nhdsWithin
theorem UniqueMDiffWithinAt.mono (h : UniqueMDiffWithinAt I s x) (st : s ⊆ t) :
UniqueMDiffWithinAt I t x :=
UniqueDiffWithinAt.mono h <| inter_subset_inter (preimage_mono st) (Subset.refl _)
theorem UniqueMDiffWithinAt.inter' (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) :
UniqueMDiffWithinAt I (s ∩ t) x :=
hs.mono_of_mem_nhdsWithin (Filter.inter_mem self_mem_nhdsWithin ht)
theorem UniqueMDiffWithinAt.inter (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝 x) :
UniqueMDiffWithinAt I (s ∩ t) x :=
hs.inter' (nhdsWithin_le_nhds ht)
theorem IsOpen.uniqueMDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueMDiffWithinAt I s x :=
(uniqueMDiffWithinAt_univ I).mono_of_mem_nhdsWithin <| nhdsWithin_le_nhds <| hs.mem_nhds xs
theorem UniqueMDiffOn.inter (hs : UniqueMDiffOn I s) (ht : IsOpen t) : UniqueMDiffOn I (s ∩ t) :=
fun _x hx => UniqueMDiffWithinAt.inter (hs _ hx.1) (ht.mem_nhds hx.2)
theorem IsOpen.uniqueMDiffOn (hs : IsOpen s) : UniqueMDiffOn I s :=
fun _x hx => hs.uniqueMDiffWithinAt hx
theorem uniqueMDiffOn_univ : UniqueMDiffOn I (univ : Set M) :=
isOpen_univ.uniqueMDiffOn
nonrec theorem UniqueMDiffWithinAt.prod {x : M} {y : M'} {s t} (hs : UniqueMDiffWithinAt I s x)
(ht : UniqueMDiffWithinAt I' t y) : UniqueMDiffWithinAt (I.prod I') (s ×ˢ t) (x, y) := by
refine (hs.prod ht).mono ?_
rw [ModelWithCorners.range_prod, ← prod_inter_prod]
rfl
theorem UniqueMDiffOn.prod {s : Set M} {t : Set M'} (hs : UniqueMDiffOn I s)
(ht : UniqueMDiffOn I' t) : UniqueMDiffOn (I.prod I') (s ×ˢ t) := fun x h ↦
(hs x.1 h.1).prod (ht x.2 h.2)
theorem MDifferentiableWithinAt.mono (hst : s ⊆ t) (h : MDifferentiableWithinAt I I' f t x) :
MDifferentiableWithinAt I I' f s x :=
⟨ContinuousWithinAt.mono h.1 hst, DifferentiableWithinAt.mono
h.differentiableWithinAt_writtenInExtChartAt
(inter_subset_inter_left _ (preimage_mono hst))⟩
theorem mdifferentiableWithinAt_univ :
MDifferentiableWithinAt I I' f univ x ↔ MDifferentiableAt I I' f x := by
simp_rw [MDifferentiableWithinAt, MDifferentiableAt, ChartedSpace.LiftPropAt]
theorem mdifferentiableWithinAt_inter (ht : t ∈ 𝓝 x) :
MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by
rw [MDifferentiableWithinAt, MDifferentiableWithinAt,
differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter ht]
theorem mdifferentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) :
MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by
rw [MDifferentiableWithinAt, MDifferentiableWithinAt,
differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter' ht]
theorem MDifferentiableAt.mdifferentiableWithinAt (h : MDifferentiableAt I I' f x) :
MDifferentiableWithinAt I I' f s x :=
MDifferentiableWithinAt.mono (subset_univ _) (mdifferentiableWithinAt_univ.2 h)
theorem MDifferentiableWithinAt.mdifferentiableAt (h : MDifferentiableWithinAt I I' f s x)
(hs : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := by
have : s = univ ∩ s := by rw [univ_inter]
rwa [this, mdifferentiableWithinAt_inter hs, mdifferentiableWithinAt_univ] at h
theorem MDifferentiableOn.mono (h : MDifferentiableOn I I' f t) (st : s ⊆ t) :
MDifferentiableOn I I' f s := fun x hx => (h x (st hx)).mono st
theorem mdifferentiableOn_univ : MDifferentiableOn I I' f univ ↔ MDifferentiable I I' f := by
simp only [MDifferentiableOn, mdifferentiableWithinAt_univ, mfld_simps]; rfl
theorem MDifferentiableOn.mdifferentiableAt (h : MDifferentiableOn I I' f s) (hx : s ∈ 𝓝 x) :
MDifferentiableAt I I' f x :=
(h x (mem_of_mem_nhds hx)).mdifferentiableAt hx
theorem MDifferentiable.mdifferentiableOn (h : MDifferentiable I I' f) :
MDifferentiableOn I I' f s :=
(mdifferentiableOn_univ.2 h).mono (subset_univ _)
theorem mdifferentiableOn_of_locally_mdifferentiableOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ MDifferentiableOn I I' f (s ∩ u)) :
MDifferentiableOn I I' f s := by
intro x xs
rcases h x xs with ⟨t, t_open, xt, ht⟩
exact (mdifferentiableWithinAt_inter (t_open.mem_nhds xt)).1 (ht x ⟨xs, xt⟩)
theorem MDifferentiable.mdifferentiableAt (hf : MDifferentiable I I' f) :
MDifferentiableAt I I' f x :=
hf x
/-!
### Relating differentiability in a manifold and differentiability in the model space
through extended charts
-/
theorem mdifferentiableWithinAt_iff_target_inter {f : M → M'} {s : Set M} {x : M} :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧
DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f)
((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ((extChartAt I x) x) := by
rw [mdifferentiableWithinAt_iff']
refine and_congr Iff.rfl (exists_congr fun f' => ?_)
rw [inter_comm]
simp only [HasFDerivWithinAt, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq]
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart. -/
theorem mdifferentiableWithinAt_iff :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧
DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by
simp_rw [MDifferentiableWithinAt, ChartedSpace.liftPropWithinAt_iff']; rfl
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart. This form states smoothness of `f`
written in such a way that the set is restricted to lie within the domain/codomain of the
corresponding charts.
Even though this expression is more complicated than the one in `mdifferentiableWithinAt_iff`, it is
a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite
using this in the goal.
-/
theorem mdifferentiableWithinAt_iff_target_inter' :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧
DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).target ∩
(extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source))
(extChartAt I x x) := by
simp only [MDifferentiableWithinAt, liftPropWithinAt_iff']
exact and_congr_right fun hc => differentiableWithinAt_congr_nhds <|
hc.nhdsWithin_extChartAt_symm_preimage_inter_range
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in the corresponding extended chart in the target. -/
theorem mdifferentiableWithinAt_iff_target :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧
MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) s x := by
simp_rw [MDifferentiableWithinAt, liftPropWithinAt_iff', ← and_assoc]
have cont :
ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔
ContinuousWithinAt f s x :=
and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt
simp_rw [cont, DifferentiableWithinAtProp, extChartAt, PartialHomeomorph.extend,
PartialEquiv.coe_trans,
ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe,
chartAt_self_eq, PartialHomeomorph.refl_apply]
rfl
theorem mdifferentiableAt_iff_target {x : M} :
MDifferentiableAt I I' f x ↔
ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) x := by
rw [← mdifferentiableWithinAt_univ, ← mdifferentiableWithinAt_univ,
mdifferentiableWithinAt_iff_target, continuousWithinAt_univ]
section IsManifold
variable {e : PartialHomeomorph M H} {e' : PartialHomeomorph M' H'}
open IsManifold
theorem mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas
[IsManifold I 1 M] (he : e ∈ maximalAtlas I 1 M) (hx : x ∈ e.source) :
MDifferentiableWithinAt I I' f s x ↔
MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I)
(e.extend I x) := by
have h2x := hx; rw [← e.extend_source (I := I)] at h2x
simp_rw [MDifferentiableWithinAt,
differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_source he hx,
StructureGroupoid.liftPropWithinAt_self_source,
e.extend_symm_continuousWithinAt_comp_right_iff, differentiableWithinAtProp_self_source,
DifferentiableWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x]
rfl
theorem mdifferentiableWithinAt_iff_source_of_mem_source
[IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) :
MDifferentiableWithinAt I I' f s x' ↔
MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm)
((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') :=
mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx'
theorem mdifferentiableAt_iff_source_of_mem_source
[IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) :
MDifferentiableAt I I' f x' ↔
MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) (range I)
(extChartAt I x x') := by
simp_rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_source_of_mem_source hx',
preimage_univ, univ_inter]
theorem mdifferentiableWithinAt_iff_target_of_mem_source
[IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) s x := by
simp_rw [MDifferentiableWithinAt]
rw [differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_target
(chart_mem_maximalAtlas y) hy,
and_congr_right]
intro hf
simp_rw [StructureGroupoid.liftPropWithinAt_self_target]
simp_rw [((chartAt H' y).continuousAt hy).comp_continuousWithinAt hf]
rw [← extChartAt_source I'] at hy
simp_rw [(continuousAt_extChartAt' hy).comp_continuousWithinAt hf]
rfl
theorem mdifferentiableAt_iff_target_of_mem_source
[IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) :
MDifferentiableAt I I' f x ↔
ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) x := by
rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target_of_mem_source hy,
continuousWithinAt_univ, ← mdifferentiableWithinAt_univ]
variable [IsManifold I 1 M] [IsManifold I' 1 M']
theorem mdifferentiableWithinAt_iff_of_mem_maximalAtlas {x : M} (he : e ∈ maximalAtlas I 1 M)
(he' : e' ∈ maximalAtlas I' 1 M') (hx : x ∈ e.source) (hy : f x ∈ e'.source) :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧
DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm)
((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) :=
differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart he hx he' hy
/-- An alternative formulation of `mdifferentiableWithinAt_iff_of_mem_maximalAtlas`
if the set if `s` lies in `e.source`. -/
theorem mdifferentiableWithinAt_iff_image {x : M} (he : e ∈ maximalAtlas I 1 M)
(he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (hx : x ∈ e.source)
(hy : f x ∈ e'.source) :
MDifferentiableWithinAt I I' f s x ↔
ContinuousWithinAt f s x ∧
DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s)
(e.extend I x) := by
rw [mdifferentiableWithinAt_iff_of_mem_maximalAtlas he he' hx hy, and_congr_right_iff]
refine fun _ => differentiableWithinAt_congr_nhds ?_
simp_rw [nhdsWithin_eq_iff_eventuallyEq, e.extend_symm_preimage_inter_range_eventuallyEq hs hx]
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in any chart containing that point. -/
theorem mdifferentiableWithinAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source)
(hy : f x' ∈ (chartAt H' y).source) :
MDifferentiableWithinAt I I' f s x' ↔
ContinuousWithinAt f s x' ∧
DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') :=
mdifferentiableWithinAt_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x)
(chart_mem_maximalAtlas y) hx hy
/-- One can reformulate smoothness within a set at a point as continuity within this set at this
point, and smoothness in any chart containing that point. Version requiring differentiability
in the target instead of `range I`. -/
theorem mdifferentiableWithinAt_iff_of_mem_source' {x' : M} {y : M'}
(hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) :
MDifferentiableWithinAt I I' f s x' ↔
ContinuousWithinAt f s x' ∧
DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source))
(extChartAt I x x') := by
refine (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans ?_
rw [← extChartAt_source I] at hx
rw [← extChartAt_source I'] at hy
rw [and_congr_right_iff]
set e := extChartAt I x; set e' := extChartAt I' (f x)
refine fun hc => differentiableWithinAt_congr_nhds ?_
rw [← e.image_source_inter_eq', ← map_extChartAt_nhdsWithin_eq_image' hx,
← map_extChartAt_nhdsWithin' hx, inter_comm, nhdsWithin_inter_of_mem]
exact hc (extChartAt_source_mem_nhds' hy)
theorem mdifferentiableAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source)
(hy : f x' ∈ (chartAt H' y).source) :
MDifferentiableAt I I' f x' ↔
ContinuousAt f x' ∧
DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (range I)
(extChartAt I x x') :=
(mdifferentiableWithinAt_iff_of_mem_source hx hy).trans <| by
rw [continuousWithinAt_univ, preimage_univ, univ_inter]
theorem mdifferentiableOn_iff_of_mem_maximalAtlas (he : e ∈ maximalAtlas I 1 M)
(he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) :
MDifferentiableOn I I' f s ↔
ContinuousOn f s ∧
DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := by
simp_rw [ContinuousOn, DifferentiableOn, Set.forall_mem_image, ← forall_and, MDifferentiableOn]
exact forall₂_congr fun x hx => mdifferentiableWithinAt_iff_image he he' hs (hs hx) (h2s hx)
/-- Differentiability on a set is equivalent to differentiability in the extended charts. -/
theorem mdifferentiableOn_iff_of_mem_maximalAtlas' (he : e ∈ maximalAtlas I 1 M)
(he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) :
MDifferentiableOn I I' f s ↔
DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) :=
(mdifferentiableOn_iff_of_mem_maximalAtlas he he' hs h2s).trans <| and_iff_right_of_imp fun h ↦
(e.continuousOn_writtenInExtend_iff hs h2s).1 h.continuousOn
/-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it
into a single chart, the smoothness of `f` on that set can be expressed by purely looking in
these charts.
Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure
that this set lies in `(extChartAt I x).target`. -/
theorem mdifferentiableOn_iff_of_subset_source {x : M} {y : M'} (hs : s ⊆ (chartAt H x).source)
(h2s : MapsTo f s (chartAt H' y).source) :
MDifferentiableOn I I' f s ↔
ContinuousOn f s ∧
DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) :=
mdifferentiableOn_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x)
(chart_mem_maximalAtlas y) hs h2s
/-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it
into a single chart, the smoothness of `f` on that set can be expressed by purely looking in
these charts.
Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure
that this set lies in `(extChartAt I x).target`. -/
theorem mdifferentiableOn_iff_of_subset_source' {x : M} {y : M'} (hs : s ⊆ (extChartAt I x).source)
(h2s : MapsTo f s (extChartAt I' y).source) :
MDifferentiableOn I I' f s ↔
DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := by
rw [extChartAt_source] at hs h2s
exact mdifferentiableOn_iff_of_mem_maximalAtlas' (chart_mem_maximalAtlas x)
(chart_mem_maximalAtlas y) hs h2s
/-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any
extended chart. -/
theorem mdifferentiableOn_iff :
MDifferentiableOn I I' f s ↔
ContinuousOn f s ∧
∀ (x : M) (y : M'),
DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).target ∩
(extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) := by
constructor
· intro h
refine ⟨fun x hx => (h x hx).1, fun x y z hz => ?_⟩
simp only [mfld_simps] at hz
let w := (extChartAt I x).symm z
have : w ∈ s := by simp only [w, hz, mfld_simps]
specialize h w this
have w1 : w ∈ (chartAt H x).source := by simp only [w, hz, mfld_simps]
have w2 : f w ∈ (chartAt H' y).source := by simp only [w, hz, mfld_simps]
convert ((mdifferentiableWithinAt_iff_of_mem_source w1 w2).mp h).2.mono _
· simp only [w, hz, mfld_simps]
· mfld_set_tac
· rintro ⟨hcont, hdiff⟩ x hx
refine differentiableWithinAt_localInvariantProp.liftPropWithinAt_iff.mpr ?_
refine ⟨hcont x hx, ?_⟩
dsimp [DifferentiableWithinAtProp]
convert hdiff x (f x) (extChartAt I x x) (by simp only [hx, mfld_simps]) using 1
mfld_set_tac
/-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any
extended chart in the target. -/
theorem mdifferentiableOn_iff_target :
MDifferentiableOn I I' f s ↔
ContinuousOn f s ∧
∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f)
(s ∩ f ⁻¹' (extChartAt I' y).source) := by
simp only [mdifferentiableOn_iff, ModelWithCorners.source_eq, chartAt_self_eq,
PartialHomeomorph.refl_partialEquiv, PartialEquiv.refl_trans, extChartAt,
PartialHomeomorph.extend, Set.preimage_univ, Set.inter_univ, and_congr_right_iff]
intro h
constructor
· refine fun h' y => ⟨?_, fun x _ => h' x y⟩
have h'' : ContinuousOn _ univ := (ModelWithCorners.continuous I').continuousOn
convert (h''.comp_inter (chartAt H' y).continuousOn_toFun).comp_inter h
simp
· exact fun h' x y => (h' y).2 x 0
/-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/
theorem mdifferentiable_iff :
MDifferentiable I I' f ↔
Continuous f ∧
∀ (x : M) (y : M'),
DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm)
((extChartAt I x).target ∩
(extChartAt I x).symm ⁻¹' (f ⁻¹' (extChartAt I' y).source)) := by
simp [← mdifferentiableOn_univ, mdifferentiableOn_iff, continuous_iff_continuousOn_univ]
/-- One can reformulate smoothness as continuity and smoothness in any extended chart in the
target. -/
theorem mdifferentiable_iff_target :
MDifferentiable I I' f ↔
| Continuous f ∧ ∀ y : M',
MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (f ⁻¹' (extChartAt I' y).source) := by
rw [← mdifferentiableOn_univ, mdifferentiableOn_iff_target]
simp [continuous_iff_continuousOn_univ]
| Mathlib/Geometry/Manifold/MFDeriv/Basic.lean | 453 | 457 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, Yaël Dillies
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic.GCongr.CoreAttrs
import Mathlib.Tactic.Common
import Mathlib.Tactic.Monotonicity.Attr
/-!
# Factorial and variants
This file defines the factorial, along with the ascending and descending variants.
For the proof that the factorial of `n` counts the permutations of an `n`-element set,
see `Fintype.card_perm`.
## Main declarations
* `Nat.factorial`: The factorial.
* `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to
`n + k - 1`.
* `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from
`n - k + 1` to `n`.
-/
namespace Nat
/-- `Nat.factorial n` is the factorial of `n`. -/
def factorial : ℕ → ℕ
| 0 => 1
| succ n => succ n * factorial n
/-- factorial notation `(n)!` for `Nat.factorial n`.
In Lean, names can end with exclamation marks (e.g. `List.get!`), so you cannot write
`n!` in Lean, but must write `(n)!` or `n !` instead. The former is preferred, since
Lean can confuse the `!` in `n !` as the (prefix) boolean negation operation in some
cases.
For numerals the parentheses are not required, so e.g. `0!` or `1!` work fine.
Todo: replace occurrences of `n !` with `(n)!` in Mathlib. -/
scoped notation:10000 n "!" => Nat.factorial n
section Factorial
variable {m n : ℕ}
@[simp] theorem factorial_zero : 0! = 1 :=
rfl
theorem factorial_succ (n : ℕ) : (n + 1)! = (n + 1) * n ! :=
rfl
@[simp] theorem factorial_one : 1! = 1 :=
rfl
@[simp] theorem factorial_two : 2! = 2 :=
rfl
theorem mul_factorial_pred (hn : n ≠ 0) : n * (n - 1)! = n ! :=
Nat.sub_add_cancel (one_le_iff_ne_zero.mpr hn) ▸ rfl
theorem factorial_pos : ∀ n, 0 < n !
| 0 => Nat.zero_lt_one
| succ n => Nat.mul_pos (succ_pos _) (factorial_pos n)
theorem factorial_ne_zero (n : ℕ) : n ! ≠ 0 :=
ne_of_gt (factorial_pos _)
theorem factorial_dvd_factorial {m n} (h : m ≤ n) : m ! ∣ n ! := by
induction h with
| refl => exact Nat.dvd_refl _
| step _ ih => exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _)
theorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ n !
| succ _, _, _, h => Nat.dvd_trans (Nat.dvd_mul_right _ _) (factorial_dvd_factorial h)
@[mono, gcongr]
theorem factorial_le {m n} (h : m ≤ n) : m ! ≤ n ! :=
le_of_dvd (factorial_pos _) (factorial_dvd_factorial h)
theorem factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m ! * (m + 1) ^ n ≤ (m + n)!
| m, 0 => by simp
| m, n + 1 => by
rw [← Nat.add_assoc, factorial_succ, Nat.mul_comm (_ + 1), Nat.pow_succ, ← Nat.mul_assoc]
exact Nat.mul_le_mul factorial_mul_pow_le_factorial (succ_le_succ (le_add_right _ _))
theorem factorial_lt (hn : 0 < n) : n ! < m ! ↔ n < m := by
refine ⟨fun h => not_le.mp fun hmn => Nat.not_le_of_lt h (factorial_le hmn), fun h => ?_⟩
have : ∀ {n}, 0 < n → n ! < (n + 1)! := by
intro k hk
rw [factorial_succ, succ_mul, Nat.lt_add_left_iff_pos]
exact Nat.mul_pos hk k.factorial_pos
induction h generalizing hn with
| refl => exact this hn
| step hnk ih => exact lt_trans (ih hn) <| this <| lt_trans hn <| lt_of_succ_le hnk
@[gcongr]
lemma factorial_lt_of_lt {m n : ℕ} (hn : 0 < n) (h : n < m) : n ! < m ! := (factorial_lt hn).mpr h
@[simp] lemma one_lt_factorial : 1 < n ! ↔ 1 < n := factorial_lt Nat.one_pos
@[simp]
theorem factorial_eq_one : n ! = 1 ↔ n ≤ 1 := by
constructor
· intro h
rw [← not_lt, ← one_lt_factorial, h]
apply lt_irrefl
· rintro (_|_|_) <;> rfl
theorem factorial_inj (hn : 1 < n) : n ! = m ! ↔ n = m := by
refine ⟨fun h => ?_, congr_arg _⟩
obtain hnm | rfl | hnm := lt_trichotomy n m
· rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm
cases lt_irrefl _ hnm
· rfl
rw [← one_lt_factorial, h, one_lt_factorial] at hn
rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm
cases lt_irrefl _ hnm
theorem factorial_inj' (h : 1 < n ∨ 1 < m) : n ! = m ! ↔ n = m := by
obtain hn|hm := h
· exact factorial_inj hn
· rw [eq_comm, factorial_inj hm, eq_comm]
theorem self_le_factorial : ∀ n : ℕ, n ≤ n !
| 0 => Nat.zero_le _
| k + 1 => Nat.le_mul_of_pos_right _ (Nat.one_le_of_lt k.factorial_pos)
theorem lt_factorial_self {n : ℕ} (hi : 3 ≤ n) : n < n ! := by
have : 0 < n := by omega
have hn : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi)
rw [← succ_pred_eq_of_pos ‹0 < n›, factorial_succ]
exact (Nat.lt_mul_iff_one_lt_right (pred n).succ_pos).2
((Nat.lt_of_lt_of_le hn (self_le_factorial _)))
theorem add_factorial_succ_lt_factorial_add_succ {i : ℕ} (n : ℕ) (hi : 2 ≤ i) :
i + (n + 1)! < (i + n + 1)! := by
rw [factorial_succ (i + _), Nat.add_mul, Nat.one_mul]
have := (i + n).self_le_factorial
| refine Nat.add_lt_add_of_lt_of_le (Nat.lt_of_le_of_lt ?_ ((Nat.lt_mul_iff_one_lt_right ?_).2 ?_))
(factorial_le ?_) <;> omega
theorem add_factorial_lt_factorial_add {i n : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ n) :
i + n ! < (i + n)! := by
cases hn
| Mathlib/Data/Nat/Factorial/Basic.lean | 142 | 147 |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps
import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap
import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable
/-!
# Derivative is measurable
In this file we prove that the derivative of any function with complete codomain is a measurable
function. Namely, we prove:
* `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable;
* `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable;
* `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↦ fderiv 𝕜 f x y`
is measurable;
* `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`).
We also show the same results for the right derivative on the real line
(see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same
proof strategy.
We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`,
we show the measurability of `(p : α × E) ↦ fderiv 𝕜 (f p.1) p.2`. This requires additional
assumptions. We give versions of the above statements (appending `with_param` to their names) when
`f` is continuous and `E` is locally compact.
## Implementation
We give a proof that avoids second-countability issues, by expressing the differentiability set
as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points
where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the
linear map `L`, up to `ε r`. It is an open set.
Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different
scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open.
We claim that the differentiability set of `f` is exactly
`D = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`.
In other words, for any `ε > 0`, we require that there is a size `δ` such that, for any two scales
below this size, the function is well approximated by a linear map, common to the two scales.
The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and
unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the
differentiability set is measurable.
To prove the claim, there are two inclusions. One is trivial: if the function is differentiable
at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the
differentiability exactly says that the map is well approximated by `L`). This is proved in
`mem_A_of_differentiable` and `differentiable_set_subset_D`.
For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key
point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to
`A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus
`‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps
`L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is
close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a
linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as
`x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s`
w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is
close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are
close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed.
It follows that the different approximating linear maps that show up form a Cauchy sequence when
`ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`.
With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`.
To show that the derivative itself is measurable, add in the definition of `B` and `D` a set
`K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K`
is exactly the set of points where `f` is differentiable with a derivative in `K`.
## Tags
derivative, measurable function, Borel σ-algebra
-/
noncomputable section
open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace
open scoped Topology
namespace ContinuousLinearMap
variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E]
[NormedAddCommGroup F] [NormedSpace 𝕜 F]
theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E]
[SecondCountableTopologyEither (E →L[𝕜] F) E]
[MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 :=
isBoundedBilinearMap_apply.continuous.measurable
end ContinuousLinearMap
section fderiv
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f : E → F} (K : Set (E →L[𝕜] F))
namespace FDerivMeasurableAux
/-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated
at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that
this is an open set. -/
def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E :=
{ x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r }
/-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map
`L` belonging to `K` (a given set of continuous linear maps) that approximates well the
function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/
def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E :=
⋃ L ∈ K, A f L r ε ∩ A f L s ε
/-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its
main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable,
with a derivative in `K`. -/
def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E :=
⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e)
theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by
rw [Metric.isOpen_iff]
rintro x ⟨r', r'_mem, hr'⟩
obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1
have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩
refine ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, ?_⟩⟩
have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx')
intro y hy z hz
exact hr' y (B hy) z (B hz)
theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by
simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A]
theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by
rintro x ⟨r', r'r, hr'⟩
refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩
linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x]
theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E}
(hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) :
‖f z - f y - L (z - y)‖ ≤ ε * r := by
rcases hx with ⟨r', r'mem, hr'⟩
apply le_of_lt
exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1)
theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) :
∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by
let δ := (ε / 2) / 2
obtain ⟨R, R_pos, hR⟩ :
∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≤ δ * ‖y - x‖ :=
eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity
refine ⟨R, R_pos, fun r hr => ?_⟩
have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1
refine ⟨r, this, fun y hy z hz => ?_⟩
calc
‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ =
‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by
simp only [map_sub]; abel_nf
_ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ :=
norm_sub_le _ _
_ ≤ δ * ‖z - x‖ + δ * ‖y - x‖ :=
add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy))
_ ≤ δ * r + δ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr
_ = (ε / 2) * r := by ring
_ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε]
theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E}
{L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε := by
refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_
intro y ley ylt
rw [div_div, div_le_iff₀' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley
calc
‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by
simp
_ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _
_ ≤ ε * r + ε * r := by
apply add_le_add
· apply le_of_mem_A h₂
| · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self]
· simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le]
· apply le_of_mem_A h₁
· simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self]
· simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le]
_ = 2 * ε * r := by ring
_ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr
_ = 4 * ‖c‖ * ε * ‖y‖ := by ring
/-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/
theorem differentiable_set_subset_D :
{ x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by
intro x hx
rw [D, mem_iInter]
intro e
have : (0 : ℝ) < (1 / 2) ^ e := by positivity
rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩
obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R :=
exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1)
simp only [mem_iUnion, mem_iInter, B, mem_inter_iff]
| Mathlib/Analysis/Calculus/FDeriv/Measurable.lean | 185 | 204 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Uni Marx
-/
import Mathlib.CategoryTheory.Iso
import Mathlib.CategoryTheory.EssentialImage
import Mathlib.CategoryTheory.Types
import Mathlib.CategoryTheory.Opposites
import Mathlib.Data.Rel
/-!
# Basics on the category of relations
We define the category of types `CategoryTheory.RelCat` with binary relations as morphisms.
Associating each function with the relation defined by its graph yields a faithful and
essentially surjective functor `graphFunctor` that also characterizes all isomorphisms
(see `rel_iso_iff`).
By flipping the arguments to a relation, we construct an equivalence `opEquivalence` between
`RelCat` and its opposite.
-/
namespace CategoryTheory
universe u
-- This file is about Lean 3 declaration "Rel".
/-- A type synonym for `Type u`, which carries the category instance for which
morphisms are binary relations. -/
def RelCat :=
Type u
instance RelCat.inhabited : Inhabited RelCat := by unfold RelCat; infer_instance
/-- The category of types with binary relations as morphisms. -/
instance rel : LargeCategory RelCat where
Hom X Y := X → Y → Prop
id _ x y := x = y
comp f g x z := ∃ y, f x y ∧ g y z
namespace RelCat
@[ext] theorem hom_ext {X Y : RelCat} (f g : X ⟶ Y) (h : ∀ a b, f a b ↔ g a b) : f = g :=
funext₂ (fun a b => propext (h a b))
namespace Hom
protected theorem rel_id (X : RelCat) : 𝟙 X = (· = ·) := rfl
protected theorem rel_comp {X Y Z : RelCat} (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = Rel.comp f g := rfl
theorem rel_id_apply₂ (X : RelCat) (x y : X) : (𝟙 X) x y ↔ x = y := by
rw [RelCat.Hom.rel_id]
theorem rel_comp_apply₂ {X Y Z : RelCat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) (z : Z) :
(f ≫ g) x z ↔ ∃ y, f x y ∧ g y z := by rfl
| end Hom
| Mathlib/CategoryTheory/Category/RelCat.lean | 62 | 63 |
/-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Regular.Basic
import Mathlib.GroupTheory.GroupAction.Hom
/-!
# Action of regular elements on a module
We introduce `M`-regular elements, in the context of an `R`-module `M`. The corresponding
predicate is called `IsSMulRegular`.
There are very limited typeclass assumptions on `R` and `M`, but the "mathematical" case of interest
is a commutative ring `R` acting on a module `M`. Since the properties are "multiplicative", there
is no actual requirement of having an addition, but there is a zero in both `R` and `M`.
SMultiplications involving `0` are, of course, all trivial.
The defining property is that an element `a ∈ R` is `M`-regular if the smultiplication map
`M → M`, defined by `m ↦ a • m`, is injective.
This property is the direct generalization to modules of the property `IsLeftRegular` defined in
`Algebra/Regular`. Lemma `isLeftRegular_iff` shows that indeed the two notions
coincide.
-/
variable {R S : Type*} (M : Type*) {a b : R} {s : S}
/-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an
injective map `M → M`. -/
def IsSMulRegular [SMul R M] (c : R) :=
Function.Injective ((c • ·) : M → M)
theorem IsLeftRegular.isSMulRegular [Mul R] {c : R} (h : IsLeftRegular c) : IsSMulRegular R c :=
h
/-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/
theorem isLeftRegular_iff [Mul R] {a : R} : IsLeftRegular a ↔ IsSMulRegular R a :=
Iff.rfl
theorem IsRightRegular.isSMulRegular [Mul R] {c : R} (h : IsRightRegular c) :
IsSMulRegular R (MulOpposite.op c) :=
h
/-- Right-regular multiplication on `R` is equivalent to `Rᵐᵒᵖ`-regularity of `R` itself. -/
theorem isRightRegular_iff [Mul R] {a : R} :
IsRightRegular a ↔ IsSMulRegular R (MulOpposite.op a) :=
Iff.rfl
namespace IsSMulRegular
variable {M}
section SMul
variable [SMul R M] [SMul R S] [SMul S M] [IsScalarTower R S M]
/-- The product of `M`-regular elements is `M`-regular. -/
theorem smul (ra : IsSMulRegular M a) (rs : IsSMulRegular M s) : IsSMulRegular M (a • s) :=
fun _ _ ab => rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _))))
/-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular
element, then `b` is `M`-regular. -/
theorem of_smul (a : R) (ab : IsSMulRegular M (a • s)) : IsSMulRegular M s :=
@Function.Injective.of_comp _ _ _ (fun m : M => a • m) _ fun c d cd => by
dsimp only [Function.comp_def] at cd
rw [← smul_assoc, ← smul_assoc] at cd
exact ab cd
/-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element
is `M`-regular. -/
@[simp]
theorem smul_iff (b : S) (ha : IsSMulRegular M a) : IsSMulRegular M (a • b) ↔ IsSMulRegular M b :=
⟨of_smul _, ha.smul⟩
theorem isLeftRegular [Mul R] {a : R} (h : IsSMulRegular R a) : IsLeftRegular a :=
h
theorem isRightRegular [Mul R] {a : R} (h : IsSMulRegular R (MulOpposite.op a)) :
IsRightRegular a :=
h
theorem mul [Mul R] [IsScalarTower R R M] (ra : IsSMulRegular M a) (rb : IsSMulRegular M b) :
IsSMulRegular M (a * b) :=
ra.smul rb
theorem of_mul [Mul R] [IsScalarTower R R M] (ab : IsSMulRegular M (a * b)) :
IsSMulRegular M b := by
rw [← smul_eq_mul] at ab
exact ab.of_smul _
@[simp]
theorem mul_iff_right [Mul R] [IsScalarTower R R M] (ha : IsSMulRegular M a) :
IsSMulRegular M (a * b) ↔ IsSMulRegular M b :=
⟨of_mul, ha.mul⟩
/-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a`
are `M`-regular. -/
theorem mul_and_mul_iff [Mul R] [IsScalarTower R R M] :
IsSMulRegular M (a * b) ∧ IsSMulRegular M (b * a) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by
refine ⟨?_, ?_⟩
· rintro ⟨ab, ba⟩
exact ⟨ba.of_mul, ab.of_mul⟩
· rintro ⟨ha, hb⟩
exact ⟨ha.mul hb, hb.mul ha⟩
lemma of_injective {N F} [SMul R N] [FunLike F M N] [MulActionHomClass F R M N]
(f : F) {r : R} (h1 : Function.Injective f) (h2 : IsSMulRegular N r) :
IsSMulRegular M r := fun x y h3 => h1 <| h2 <|
(map_smulₛₗ f r x).symm.trans ((congrArg f h3).trans (map_smulₛₗ f r y))
end SMul
section Monoid
variable [Monoid R] [MulAction R M]
variable (M)
/-- One is always `M`-regular. -/
@[simp]
theorem one : IsSMulRegular M (1 : R) := fun a b ab => by
dsimp only [Function.comp_def] at ab
rw [one_smul, one_smul] at ab
assumption
variable {M}
/-- An element of `R` admitting a left inverse is `M`-regular. -/
theorem of_mul_eq_one (h : a * b = 1) : IsSMulRegular M b :=
of_mul (a := a) (by rw [h]; exact one M)
/-- Any power of an `M`-regular element is `M`-regular. -/
theorem pow (n : ℕ) (ra : IsSMulRegular M a) : IsSMulRegular M (a ^ n) := by
induction n with
| zero => rw [pow_zero]; simp only [one]
| succ n hn =>
rw [pow_succ']
exact (ra.smul_iff (a ^ n)).mpr hn
/-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/
theorem pow_iff {n : ℕ} (n0 : 0 < n) : IsSMulRegular M (a ^ n) ↔ IsSMulRegular M a := by
refine ⟨?_, pow n⟩
rw [← Nat.succ_pred_eq_of_pos n0, pow_succ, ← smul_eq_mul]
exact of_smul _
end Monoid
section MonoidSMul
variable [Monoid S] [SMul R M] [SMul R S] [MulAction S M] [IsScalarTower R S M]
/-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/
theorem of_smul_eq_one (h : a • s = 1) : IsSMulRegular M s :=
of_smul a
(by
rw [h]
exact one M)
end MonoidSMul
section MonoidWithZero
variable [MonoidWithZero R] [Zero M] [MulActionWithZero R M]
/-- The element `0` is `M`-regular if and only if `M` is trivial. -/
protected theorem subsingleton (h : IsSMulRegular M (0 : R)) : Subsingleton M :=
⟨fun a b => h (by dsimp only [Function.comp_def]; repeat' rw [MulActionWithZero.zero_smul])⟩
/-- The element `0` is `M`-regular if and only if `M` is trivial. -/
theorem zero_iff_subsingleton : IsSMulRegular M (0 : R) ↔ Subsingleton M :=
⟨fun h => h.subsingleton, fun H a b _ => @Subsingleton.elim _ H a b⟩
/-- The `0` element is not `M`-regular, on a non-trivial module. -/
theorem not_zero_iff : ¬IsSMulRegular M (0 : R) ↔ Nontrivial M := by
| rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff]
push_neg
exact Iff.rfl
/-- The element `0` is `M`-regular when `M` is trivial. -/
| Mathlib/Algebra/Regular/SMul.lean | 177 | 181 |
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Rémy Degenne
-/
import Mathlib.Probability.Process.Stopping
import Mathlib.Tactic.AdaptationNote
/-!
# Hitting time
Given a stochastic process, the hitting time provides the first time the process "hits" some
subset of the state space. The hitting time is a stopping time in the case that the time index is
discrete and the process is adapted (this is true in a far more general setting however we have
only proved it for the discrete case so far).
## Main definition
* `MeasureTheory.hitting`: the hitting time of a stochastic process
## Main results
* `MeasureTheory.hitting_isStoppingTime`: a discrete hitting time of an adapted process is a
stopping time
## Implementation notes
In the definition of the hitting time, we bound the hitting time by an upper and lower bound.
This is to ensure that our result is meaningful in the case we are taking the infimum of an
empty set or the infimum of a set which is unbounded from below. With this, we can talk about
hitting times indexed by the natural numbers or the reals. By taking the bounds to be
`⊤` and `⊥`, we obtain the standard definition in the case that the index is `ℕ∞` or `ℝ≥0∞`.
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ω β ι : Type*} {m : MeasurableSpace Ω}
open scoped Classical in
/-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time
`u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and
before `m` then the hitting time is simply `m`).
The hitting time is a stopping time if the process is adapted and discrete. -/
noncomputable def hitting [Preorder ι] [InfSet ι] (u : ι → Ω → β)
(s : Set β) (n m : ι) : Ω → ι :=
fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s
then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m
open scoped Classical in
theorem hitting_def [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) :
hitting u s n m =
fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m :=
rfl
section Inequalities
variable [ConditionallyCompleteLinearOrder ι] {u : ι → Ω → β} {s : Set β} {n i : ι} {ω : Ω}
/-- This lemma is strictly weaker than `hitting_of_le`. -/
theorem hitting_of_lt {m : ι} (h : m < n) : hitting u s n m ω = m := by
simp_rw [hitting]
have h_not : ¬∃ (j : ι) (_ : j ∈ Set.Icc n m), u j ω ∈ s := by
push_neg
intro j
rw [Set.Icc_eq_empty_of_lt h]
simp only [Set.mem_empty_iff_false, IsEmpty.forall_iff]
simp only [exists_prop] at h_not
simp only [h_not, if_false]
theorem hitting_le {m : ι} (ω : Ω) : hitting u s n m ω ≤ m := by
simp only [hitting]
split_ifs with h
· obtain ⟨j, hj₁, hj₂⟩ := h
change j ∈ {i | u i ω ∈ s} at hj₂
exact (csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter hj₁ hj₂)).trans hj₁.2
· exact le_rfl
theorem not_mem_of_lt_hitting {m k : ι} (hk₁ : k < hitting u s n m ω) (hk₂ : n ≤ k) :
u k ω ∉ s := by
classical
intro h
have hexists : ∃ j ∈ Set.Icc n m, u j ω ∈ s := ⟨k, ⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩
refine not_le.2 hk₁ ?_
simp_rw [hitting, if_pos hexists]
exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩
theorem hitting_eq_end_iff {m : ι} : hitting u s n m ω = m ↔
(∃ j ∈ Set.Icc n m, u j ω ∈ s) → sInf (Set.Icc n m ∩ {i : ι | u i ω ∈ s}) = m := by
classical
rw [hitting, ite_eq_right_iff]
theorem hitting_of_le {m : ι} (hmn : m ≤ n) : hitting u s n m ω = m := by
obtain rfl | h := le_iff_eq_or_lt.1 hmn
· classical
rw [hitting, ite_eq_right_iff, forall_exists_index]
conv => intro; rw [Set.mem_Icc, Set.Icc_self, and_imp, and_imp]
intro i hi₁ hi₂ hi
rw [Set.inter_eq_left.2, csInf_singleton]
exact Set.singleton_subset_iff.2 (le_antisymm hi₂ hi₁ ▸ hi)
· exact hitting_of_lt h
theorem le_hitting {m : ι} (hnm : n ≤ m) (ω : Ω) : n ≤ hitting u s n m ω := by
simp only [hitting]
split_ifs with h
| · refine le_csInf ?_ fun b hb => ?_
· obtain ⟨k, hk_Icc, hk_s⟩ := h
exact ⟨k, hk_Icc, hk_s⟩
· rw [Set.mem_inter_iff] at hb
exact hb.1.1
· exact hnm
theorem le_hitting_of_exists {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) :
n ≤ hitting u s n m ω := by
| Mathlib/Probability/Process/HittingTime.lean | 112 | 120 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import Mathlib.Data.Bool.Basic
import Mathlib.Data.FunLike.Equiv
import Mathlib.Data.Quot
import Mathlib.Data.Subtype
import Mathlib.Logic.Unique
import Mathlib.Tactic.Conv
import Mathlib.Tactic.Simps.Basic
import Mathlib.Tactic.Substs
/-!
# Equivalence between types
In this file we define two types:
* `Equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and
not equality!) to express that various `Type`s or `Sort`s are equivalent.
* `Equiv.Perm α`: the group of permutations `α ≃ α`. More lemmas about `Equiv.Perm` can be found in
`Mathlib.GroupTheory.Perm`.
Then we define
* canonical isomorphisms between various types: e.g.,
- `Equiv.refl α` is the identity map interpreted as `α ≃ α`;
* operations on equivalences: e.g.,
- `Equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`;
- `Equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order
of the arguments!);
* definitions that transfer some instances along an equivalence. By convention, we transfer
instances from right to left.
- `Equiv.inhabited` takes `e : α ≃ β` and `[Inhabited β]` and returns `Inhabited α`;
- `Equiv.unique` takes `e : α ≃ β` and `[Unique β]` and returns `Unique α`;
- `Equiv.decidableEq` takes `e : α ≃ β` and `[DecidableEq β]` and returns `DecidableEq α`.
More definitions of this kind can be found in other files.
E.g., `Mathlib.Algebra.Equiv.TransferInstance` does it for many algebraic type classes like
`Group`, `Module`, etc.
Many more such isomorphisms and operations are defined in `Mathlib.Logic.Equiv.Basic`.
## Tags
equivalence, congruence, bijective map
-/
open Function
universe u v w z
variable {α : Sort u} {β : Sort v} {γ : Sort w}
/-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/
structure Equiv (α : Sort*) (β : Sort _) where
protected toFun : α → β
protected invFun : β → α
protected left_inv : LeftInverse invFun toFun
protected right_inv : RightInverse invFun toFun
@[inherit_doc]
infixl:25 " ≃ " => Equiv
/-- Turn an element of a type `F` satisfying `EquivLike F α β` into an actual
`Equiv`. This is declared as the default coercion from `F` to `α ≃ β`. -/
@[coe]
def EquivLike.toEquiv {F} [EquivLike F α β] (f : F) : α ≃ β where
toFun := f
invFun := EquivLike.inv f
left_inv := EquivLike.left_inv f
right_inv := EquivLike.right_inv f
/-- Any type satisfying `EquivLike` can be cast into `Equiv` via `EquivLike.toEquiv`. -/
instance {F} [EquivLike F α β] : CoeTC F (α ≃ β) :=
⟨EquivLike.toEquiv⟩
/-- `Perm α` is the type of bijections from `α` to itself. -/
abbrev Equiv.Perm (α : Sort*) :=
Equiv α α
namespace Equiv
instance : EquivLike (α ≃ β) α β where
coe := Equiv.toFun
inv := Equiv.invFun
left_inv := Equiv.left_inv
right_inv := Equiv.right_inv
coe_injective' e₁ e₂ h₁ h₂ := by cases e₁; cases e₂; congr
/-- Helper instance when inference gets stuck on following the normal chain
`EquivLike → FunLike`.
TODO: this instance doesn't appear to be necessary: remove it (after benchmarking?)
-/
instance : FunLike (α ≃ β) α β where
coe := Equiv.toFun
coe_injective' := DFunLike.coe_injective
@[simp, norm_cast]
lemma _root_.EquivLike.coe_coe {F} [EquivLike F α β] (e : F) :
((e : α ≃ β) : α → β) = e := rfl
@[simp] theorem coe_fn_mk (f : α → β) (g l r) : (Equiv.mk f g l r : α → β) = f :=
rfl
/-- The map `(r ≃ s) → (r → s)` is injective. -/
theorem coe_fn_injective : @Function.Injective (α ≃ β) (α → β) (fun e => e) :=
DFunLike.coe_injective'
protected theorem coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ :=
@DFunLike.coe_fn_eq _ _ _ _ e₁ e₂
@[ext] theorem ext {f g : Equiv α β} (H : ∀ x, f x = g x) : f = g := DFunLike.ext f g H
protected theorem congr_arg {f : Equiv α β} {x x' : α} : x = x' → f x = f x' :=
DFunLike.congr_arg f
protected theorem congr_fun {f g : Equiv α β} (h : f = g) (x : α) : f x = g x :=
DFunLike.congr_fun h x
@[ext] theorem Perm.ext {σ τ : Equiv.Perm α} (H : ∀ x, σ x = τ x) : σ = τ := Equiv.ext H
protected theorem Perm.congr_arg {f : Equiv.Perm α} {x x' : α} : x = x' → f x = f x' :=
Equiv.congr_arg
protected theorem Perm.congr_fun {f g : Equiv.Perm α} (h : f = g) (x : α) : f x = g x :=
Equiv.congr_fun h x
/-- Any type is equivalent to itself. -/
@[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, fun _ => rfl, fun _ => rfl⟩
instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩
/-- Inverse of an equivalence `e : α ≃ β`. -/
@[symm]
protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : α ≃ β) : β → α := e.symm
initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply)
/-- Restatement of `Equiv.left_inv` in terms of `Function.LeftInverse`. -/
theorem left_inv' (e : α ≃ β) : Function.LeftInverse e.symm e := e.left_inv
/-- Restatement of `Equiv.right_inv` in terms of `Function.RightInverse`. -/
theorem right_inv' (e : α ≃ β) : Function.RightInverse e.symm e := e.right_inv
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
@[trans]
protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩
@[simps]
instance : Trans Equiv Equiv Equiv where
trans := Equiv.trans
@[simp, mfld_simps] theorem toFun_as_coe (e : α ≃ β) : e.toFun = e := rfl
@[simp, mfld_simps] theorem invFun_as_coe (e : α ≃ β) : e.invFun = e.symm := rfl
protected theorem injective (e : α ≃ β) : Injective e := EquivLike.injective e
protected theorem surjective (e : α ≃ β) : Surjective e := EquivLike.surjective e
protected theorem bijective (e : α ≃ β) : Bijective e := EquivLike.bijective e
protected theorem subsingleton (e : α ≃ β) [Subsingleton β] : Subsingleton α :=
e.injective.subsingleton
protected theorem subsingleton.symm (e : α ≃ β) [Subsingleton α] : Subsingleton β :=
e.symm.injective.subsingleton
theorem subsingleton_congr (e : α ≃ β) : Subsingleton α ↔ Subsingleton β :=
⟨fun _ => e.symm.subsingleton, fun _ => e.subsingleton⟩
instance equiv_subsingleton_cod [Subsingleton β] : Subsingleton (α ≃ β) :=
⟨fun _ _ => Equiv.ext fun _ => Subsingleton.elim _ _⟩
instance equiv_subsingleton_dom [Subsingleton α] : Subsingleton (α ≃ β) :=
⟨fun f _ => Equiv.ext fun _ => @Subsingleton.elim _ (Equiv.subsingleton.symm f) _ _⟩
instance permUnique [Subsingleton α] : Unique (Perm α) :=
uniqueOfSubsingleton (Equiv.refl α)
theorem Perm.subsingleton_eq_refl [Subsingleton α] (e : Perm α) : e = Equiv.refl α :=
Subsingleton.elim _ _
protected theorem nontrivial {α β} (e : α ≃ β) [Nontrivial β] : Nontrivial α :=
e.surjective.nontrivial
theorem nontrivial_congr {α β} (e : α ≃ β) : Nontrivial α ↔ Nontrivial β :=
⟨fun _ ↦ e.symm.nontrivial, fun _ ↦ e.nontrivial⟩
/-- Transfer `DecidableEq` across an equivalence. -/
protected def decidableEq (e : α ≃ β) [DecidableEq β] : DecidableEq α :=
e.injective.decidableEq
theorem nonempty_congr (e : α ≃ β) : Nonempty α ↔ Nonempty β := Nonempty.congr e e.symm
protected theorem nonempty (e : α ≃ β) [Nonempty β] : Nonempty α := e.nonempty_congr.mpr ‹_›
/-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/
protected def inhabited [Inhabited β] (e : α ≃ β) : Inhabited α := ⟨e.symm default⟩
/-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/
protected def unique [Unique β] (e : α ≃ β) : Unique α := e.symm.surjective.unique
/-- Equivalence between equal types. -/
protected def cast {α β : Sort _} (h : α = β) : α ≃ β :=
⟨cast h, cast h.symm, fun _ => by cases h; rfl, fun _ => by cases h; rfl⟩
@[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((Equiv.mk f g l r).symm : β → α) = g := rfl
@[simp] theorem coe_refl : (Equiv.refl α : α → α) = id := rfl
/-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when
`synonym α` is semireducible. This makes a mess of `Multiplicative.ofAdd` etc. -/
theorem Perm.coe_subsingleton {α : Type*} [Subsingleton α] (e : Perm α) : (e : α → α) = id := by
rw [Perm.subsingleton_eq_refl e, coe_refl]
@[simp] theorem refl_apply (x : α) : Equiv.refl α x = x := rfl
@[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g : α → γ) = g ∘ f := rfl
@[simp] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl
@[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x
@[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x
@[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply
@[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply
@[simp] lemma _root_.EquivLike.apply_coe_symm_apply {F} [EquivLike F α β] (e : F) (x : β) :
e ((e : α ≃ β).symm x) = x :=
(e : α ≃ β).apply_symm_apply x
@[simp] lemma _root_.EquivLike.coe_symm_apply_apply {F} [EquivLike F α β] (e : F) (x : α) :
(e : α ≃ β).symm (e x) = x :=
(e : α ≃ β).symm_apply_apply x
@[simp] lemma _root_.EquivLike.coe_symm_comp_self {F} [EquivLike F α β] (e : F) :
(e : α ≃ β).symm ∘ e = id :=
(e : α ≃ β).symm_comp_self
@[simp] lemma _root_.EquivLike.self_comp_coe_symm {F} [EquivLike F α β] (e : F) :
e ∘ (e : α ≃ β).symm = id :=
(e : α ≃ β).self_comp_symm
@[simp] theorem symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl
theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f
theorem apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : α ≃ β) : f x = y ↔ x = f.symm y := by
conv_lhs => rw [← apply_symm_apply f y]
rw [apply_eq_iff_eq]
@[simp] theorem cast_apply {α β} (h : α = β) (x : α) : Equiv.cast h x = cast h x := rfl
@[simp] theorem cast_symm {α β} (h : α = β) : (Equiv.cast h).symm = Equiv.cast h.symm := rfl
@[simp] theorem cast_refl {α} (h : α = α := rfl) : Equiv.cast h = Equiv.refl α := rfl
@[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) :
(Equiv.cast h).trans (Equiv.cast h2) = Equiv.cast (h.trans h2) :=
ext fun x => by substs h h2; rfl
theorem cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : Equiv.cast h a = b ↔ HEq a b := by
subst h; simp [coe_refl]
theorem symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y :=
⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
theorem eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x :=
(eq_comm.trans e.symm_apply_eq).trans eq_comm
@[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := rfl
theorem symm_bijective : Function.Bijective (Equiv.symm : (α ≃ β) → β ≃ α) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp] theorem trans_refl (e : α ≃ β) : e.trans (Equiv.refl β) = e := by cases e; rfl
@[simp] theorem refl_symm : (Equiv.refl α).symm = Equiv.refl α := rfl
@[simp] theorem refl_trans (e : α ≃ β) : (Equiv.refl α).trans e = e := by cases e; rfl
@[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = Equiv.refl β := ext <| by simp
@[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = Equiv.refl α := ext <| by simp
theorem trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) := Equiv.ext fun _ => rfl
theorem leftInverse_symm (f : Equiv α β) : LeftInverse f.symm f := f.left_inv
theorem rightInverse_symm (f : Equiv α β) : Function.RightInverse f.symm f := f.right_inv
theorem injective_comp (e : α ≃ β) (f : β → γ) : Injective (f ∘ e) ↔ Injective f :=
EquivLike.injective_comp e f
theorem comp_injective (f : α → β) (e : β ≃ γ) : Injective (e ∘ f) ↔ Injective f :=
EquivLike.comp_injective f e
theorem surjective_comp (e : α ≃ β) (f : β → γ) : Surjective (f ∘ e) ↔ Surjective f :=
EquivLike.surjective_comp e f
theorem comp_surjective (f : α → β) (e : β ≃ γ) : Surjective (e ∘ f) ↔ Surjective f :=
EquivLike.comp_surjective f e
theorem bijective_comp (e : α ≃ β) (f : β → γ) : Bijective (f ∘ e) ↔ Bijective f :=
EquivLike.bijective_comp e f
theorem comp_bijective (f : α → β) (e : β ≃ γ) : Bijective (e ∘ f) ↔ Bijective f :=
EquivLike.comp_bijective f e
/-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ`
is equivalent to the type of equivalences `β ≃ δ`. -/
def equivCongr {δ : Sort*} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) where
toFun ac := (ab.symm.trans ac).trans cd
invFun bd := ab.trans <| bd.trans <| cd.symm
left_inv ac := by ext x; simp only [trans_apply, comp_apply, symm_apply_apply]
right_inv ac := by ext x; simp only [trans_apply, comp_apply, apply_symm_apply]
@[simp] theorem equivCongr_refl {α β} :
(Equiv.refl α).equivCongr (Equiv.refl β) = Equiv.refl (α ≃ β) := by ext; rfl
@[simp] theorem equivCongr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) :
(ab.equivCongr cd).symm = ab.symm.equivCongr cd.symm := by ext; rfl
@[simp] theorem equivCongr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) :
(ab.equivCongr de).trans (bc.equivCongr ef) = (ab.trans bc).equivCongr (de.trans ef) := by
ext; rfl
@[simp] theorem equivCongr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) :
(Equiv.refl α).equivCongr bg e = e.trans bg := rfl
@[simp] theorem equivCongr_refl_right {α β} (ab e : α ≃ β) :
ab.equivCongr (Equiv.refl β) e = ab.symm.trans e := rfl
@[simp] theorem equivCongr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) :
ab.equivCongr cd e x = cd (e (ab.symm x)) := rfl
section permCongr
variable {α' β' : Type*} (e : α' ≃ β')
/-- If `α` is equivalent to `β`, then `Perm α` is equivalent to `Perm β`. -/
def permCongr : Perm α' ≃ Perm β' := equivCongr e e
theorem permCongr_def (p : Equiv.Perm α') : e.permCongr p = (e.symm.trans p).trans e := rfl
@[simp] theorem permCongr_refl : e.permCongr (Equiv.refl _) = Equiv.refl _ := by
simp [permCongr_def]
@[simp] theorem permCongr_symm : e.permCongr.symm = e.symm.permCongr := rfl
@[simp] theorem permCongr_apply (p : Equiv.Perm α') (x) : e.permCongr p x = e (p (e.symm x)) := rfl
theorem permCongr_symm_apply (p : Equiv.Perm β') (x) :
e.permCongr.symm p x = e.symm (p (e x)) := rfl
theorem permCongr_trans (p p' : Equiv.Perm α') :
(e.permCongr p).trans (e.permCongr p') = e.permCongr (p.trans p') := by
ext; simp only [trans_apply, comp_apply, permCongr_apply, symm_apply_apply]
end permCongr
/-- Two empty types are equivalent. -/
def equivOfIsEmpty (α β : Sort*) [IsEmpty α] [IsEmpty β] : α ≃ β :=
⟨isEmptyElim, isEmptyElim, isEmptyElim, isEmptyElim⟩
/-- If `α` is an empty type, then it is equivalent to the `Empty` type. -/
def equivEmpty (α : Sort u) [IsEmpty α] : α ≃ Empty := equivOfIsEmpty α _
/-- If `α` is an empty type, then it is equivalent to the `PEmpty` type in any universe. -/
def equivPEmpty (α : Sort v) [IsEmpty α] : α ≃ PEmpty.{u} := equivOfIsEmpty α _
/-- `α` is equivalent to an empty type iff `α` is empty. -/
def equivEmptyEquiv (α : Sort u) : α ≃ Empty ≃ IsEmpty α :=
⟨fun e => Function.isEmpty e, @equivEmpty α, fun e => ext fun x => (e x).elim, fun _ => rfl⟩
/-- The `Sort` of proofs of a false proposition is equivalent to `PEmpty`. -/
def propEquivPEmpty {p : Prop} (h : ¬p) : p ≃ PEmpty := @equivPEmpty p <| IsEmpty.prop_iff.2 h
/-- If both `α` and `β` have a unique element, then `α ≃ β`. -/
def ofUnique (α β : Sort _) [Unique.{u} α] [Unique.{v} β] : α ≃ β where
toFun := default
invFun := default
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
@[deprecated (since := "2024-12-26")] alias equivOfUnique := ofUnique
/-- If `α` has a unique element, then it is equivalent to any `PUnit`. -/
def equivPUnit (α : Sort u) [Unique α] : α ≃ PUnit.{v} := ofUnique α _
/-- The `Sort` of proofs of a true proposition is equivalent to `PUnit`. -/
def propEquivPUnit {p : Prop} (h : p) : p ≃ PUnit.{0} := @equivPUnit p <| uniqueProp h
/-- `ULift α` is equivalent to `α`. -/
@[simps -fullyApplied apply]
protected def ulift {α : Type v} : ULift.{u} α ≃ α :=
⟨ULift.down, ULift.up, ULift.up_down, ULift.down_up.{v, u}⟩
/-- `PLift α` is equivalent to `α`. -/
@[simps -fullyApplied apply]
protected def plift : PLift α ≃ α := ⟨PLift.down, PLift.up, PLift.up_down, PLift.down_up⟩
/-- equivalence of propositions is the same as iff -/
def ofIff {P Q : Prop} (h : P ↔ Q) : P ≃ Q := ⟨h.mp, h.mpr, fun _ => rfl, fun _ => rfl⟩
/-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁`
is equivalent to the type of maps `α₂ → β₂`. -/
@[simps apply]
def arrowCongr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) where
toFun f := e₂ ∘ f ∘ e₁.symm
invFun f := e₂.symm ∘ f ∘ e₁
left_inv f := funext fun x => by simp only [comp_apply, symm_apply_apply]
right_inv f := funext fun x => by simp only [comp_apply, apply_symm_apply]
theorem arrowCongr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂)
(f : α₁ → β₁) (g : β₁ → γ₁) :
arrowCongr ea ec (g ∘ f) = arrowCongr eb ec g ∘ arrowCongr ea eb f := by
ext; simp only [comp, arrowCongr_apply, eb.symm_apply_apply]
@[simp] theorem arrowCongr_refl {α β : Sort*} :
arrowCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl
@[simp] theorem arrowCongr_trans {α₁ α₂ α₃ β₁ β₂ β₃ : Sort*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrowCongr (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂') := rfl
@[simp] theorem arrowCongr_symm {α₁ α₂ β₁ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrowCongr e₁ e₂).symm = arrowCongr e₁.symm e₂.symm := rfl
/-- A version of `Equiv.arrowCongr` in `Type`, rather than `Sort`.
The `equiv_rw` tactic is not able to use the default `Sort` level `Equiv.arrowCongr`,
because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`.
-/
@[simps! apply]
def arrowCongr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) :=
Equiv.arrowCongr hα hβ
@[simp] theorem arrowCongr'_refl {α β : Type*} :
arrowCongr' (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl
@[simp] theorem arrowCongr'_trans {α₁ α₂ β₁ β₂ α₃ β₃ : Type*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrowCongr' (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr' e₁ e₁').trans (arrowCongr' e₂ e₂') :=
rfl
@[simp] theorem arrowCongr'_symm {α₁ α₂ β₁ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrowCongr' e₁ e₂).symm = arrowCongr' e₁.symm e₂.symm := rfl
/-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/
@[simps! apply] def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrowCongr e e
@[simp] theorem conj_refl : conj (Equiv.refl α) = Equiv.refl (α → α) := rfl
@[simp] theorem conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl
@[simp] theorem conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) :
(e₁.trans e₂).conj = e₁.conj.trans e₂.conj := rfl
-- This should not be a simp lemma as long as `(∘)` is reducible:
-- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using
-- `f₁ := g` and `f₂ := fun x ↦ x`. This causes nontermination.
theorem conj_comp (e : α ≃ β) (f₁ f₂ : α → α) : e.conj (f₁ ∘ f₂) = e.conj f₁ ∘ e.conj f₂ := by
apply arrowCongr_comp
theorem eq_comp_symm {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : f = g ∘ e.symm ↔ f ∘ e = g :=
(e.arrowCongr (Equiv.refl γ)).symm_apply_eq.symm
theorem comp_symm_eq {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : g ∘ e.symm = f ↔ g = f ∘ e :=
(e.arrowCongr (Equiv.refl γ)).eq_symm_apply.symm
theorem eq_symm_comp {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : f = e.symm ∘ g ↔ e ∘ f = g :=
((Equiv.refl γ).arrowCongr e).eq_symm_apply
theorem symm_comp_eq {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : e.symm ∘ g = f ↔ g = e ∘ f :=
((Equiv.refl γ).arrowCongr e).symm_apply_eq
theorem trans_eq_refl_iff_eq_symm {f : α ≃ β} {g : β ≃ α} :
f.trans g = Equiv.refl α ↔ f = g.symm := by
rw [← Equiv.coe_inj, coe_trans, coe_refl, ← eq_symm_comp, comp_id, Equiv.coe_inj]
theorem trans_eq_refl_iff_symm_eq {f : α ≃ β} {g : β ≃ α} :
f.trans g = Equiv.refl α ↔ f.symm = g := by
rw [trans_eq_refl_iff_eq_symm]
exact ⟨fun h ↦ h ▸ rfl, fun h ↦ h ▸ rfl⟩
theorem eq_symm_iff_trans_eq_refl {f : α ≃ β} {g : β ≃ α} :
f = g.symm ↔ f.trans g = Equiv.refl α :=
trans_eq_refl_iff_eq_symm.symm
theorem symm_eq_iff_trans_eq_refl {f : α ≃ β} {g : β ≃ α} :
f.symm = g ↔ f.trans g = Equiv.refl α :=
trans_eq_refl_iff_symm_eq.symm
/-- `PUnit` sorts in any two universes are equivalent. -/
def punitEquivPUnit : PUnit.{v} ≃ PUnit.{w} :=
⟨fun _ => .unit, fun _ => .unit, fun ⟨⟩ => rfl, fun ⟨⟩ => rfl⟩
/-- `Prop` is noncomputably equivalent to `Bool`. -/
noncomputable def propEquivBool : Prop ≃ Bool where
toFun p := @decide p (Classical.propDecidable _)
invFun b := b
left_inv p := by simp [@Bool.decide_iff p (Classical.propDecidable _)]
right_inv b := by cases b <;> simp
section
/-- The sort of maps to `PUnit.{v}` is equivalent to `PUnit.{w}`. -/
def arrowPUnitEquivPUnit (α : Sort*) : (α → PUnit.{v}) ≃ PUnit.{w} :=
⟨fun _ => .unit, fun _ _ => .unit, fun _ => rfl, fun _ => rfl⟩
/-- The equivalence `(∀ i, β i) ≃ β ⋆` when the domain of `β` only contains `⋆` -/
@[simps -fullyApplied]
def piUnique [Unique α] (β : α → Sort*) : (∀ i, β i) ≃ β default where
toFun f := f default
invFun := uniqueElim
left_inv f := by ext i; cases Unique.eq_default i; rfl
right_inv _ := rfl
/-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/
@[simps! -fullyApplied apply symm_apply]
def funUnique (α β) [Unique.{u} α] : (α → β) ≃ β := piUnique _
/-- The sort of maps from `PUnit` is equivalent to the codomain. -/
def punitArrowEquiv (α : Sort*) : (PUnit.{u} → α) ≃ α := funUnique PUnit.{u} α
/-- The sort of maps from `True` is equivalent to the codomain. -/
def trueArrowEquiv (α : Sort*) : (True → α) ≃ α := funUnique _ _
/-- The sort of maps from a type that `IsEmpty` is equivalent to `PUnit`. -/
def arrowPUnitOfIsEmpty (α β : Sort*) [IsEmpty α] : (α → β) ≃ PUnit.{u} where
toFun _ := PUnit.unit
invFun _ := isEmptyElim
left_inv _ := funext isEmptyElim
right_inv _ := rfl
/-- The sort of maps from `Empty` is equivalent to `PUnit`. -/
def emptyArrowEquivPUnit (α : Sort*) : (Empty → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _
/-- The sort of maps from `PEmpty` is equivalent to `PUnit`. -/
def pemptyArrowEquivPUnit (α : Sort*) : (PEmpty → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _
/-- The sort of maps from `False` is equivalent to `PUnit`. -/
def falseArrowEquivPUnit (α : Sort*) : (False → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _
end
section
/-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/
@[simps apply symm_apply]
def psigmaEquivSigma {α} (β : α → Type*) : (Σ' i, β i) ≃ Σ i, β i where
toFun a := ⟨a.1, a.2⟩
invFun a := ⟨a.1, a.2⟩
left_inv _ := rfl
right_inv _ := rfl
/-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/
@[simps apply symm_apply]
def psigmaEquivSigmaPLift {α} (β : α → Sort*) : (Σ' i, β i) ≃ Σ i : PLift α, PLift (β i.down) where
toFun a := ⟨PLift.up a.1, PLift.up a.2⟩
invFun a := ⟨a.1.down, a.2.down⟩
left_inv _ := rfl
right_inv _ := rfl
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and
`Σ' a, β₂ a`. -/
@[simps apply]
def psigmaCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (Σ' a, β₁ a) ≃ Σ' a, β₂ a where
toFun a := ⟨a.1, F a.1 a.2⟩
invFun a := ⟨a.1, (F a.1).symm a.2⟩
left_inv | ⟨a, b⟩ => congr_arg (PSigma.mk a) <| symm_apply_apply (F a) b
right_inv | ⟨a, b⟩ => congr_arg (PSigma.mk a) <| apply_symm_apply (F a) b
theorem psigmaCongrRight_trans {α} {β₁ β₂ β₃ : α → Sort*}
(F : ∀ a, β₁ a ≃ β₂ a) (G : ∀ a, β₂ a ≃ β₃ a) :
(psigmaCongrRight F).trans (psigmaCongrRight G) =
psigmaCongrRight fun a => (F a).trans (G a) := rfl
theorem psigmaCongrRight_symm {α} {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) :
(psigmaCongrRight F).symm = psigmaCongrRight fun a => (F a).symm := rfl
@[simp]
theorem psigmaCongrRight_refl {α} {β : α → Sort*} :
(psigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ' a, β a) := rfl
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and
`Σ a, β₂ a`. -/
@[simps apply]
def sigmaCongrRight {α} {β₁ β₂ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a where
toFun a := ⟨a.1, F a.1 a.2⟩
invFun a := ⟨a.1, (F a.1).symm a.2⟩
left_inv | ⟨a, b⟩ => congr_arg (Sigma.mk a) <| symm_apply_apply (F a) b
right_inv | ⟨a, b⟩ => congr_arg (Sigma.mk a) <| apply_symm_apply (F a) b
theorem sigmaCongrRight_trans {α} {β₁ β₂ β₃ : α → Type*}
(F : ∀ a, β₁ a ≃ β₂ a) (G : ∀ a, β₂ a ≃ β₃ a) :
(sigmaCongrRight F).trans (sigmaCongrRight G) =
sigmaCongrRight fun a => (F a).trans (G a) := rfl
theorem sigmaCongrRight_symm {α} {β₁ β₂ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) :
(sigmaCongrRight F).symm = sigmaCongrRight fun a => (F a).symm := rfl
@[simp]
theorem sigmaCongrRight_refl {α} {β : α → Type*} :
(sigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ a, β a) := rfl
/-- A `PSigma` with `Prop` fibers is equivalent to the subtype. -/
def psigmaEquivSubtype {α : Type v} (P : α → Prop) : (Σ' i, P i) ≃ Subtype P where
toFun x := ⟨x.1, x.2⟩
invFun x := ⟨x.1, x.2⟩
left_inv _ := rfl
right_inv _ := rfl
/-- A `Sigma` with `PLift` fibers is equivalent to the subtype. -/
def sigmaPLiftEquivSubtype {α : Type v} (P : α → Prop) : (Σ i, PLift (P i)) ≃ Subtype P :=
((psigmaEquivSigma _).symm.trans
(psigmaCongrRight fun _ => Equiv.plift)).trans (psigmaEquivSubtype P)
/-- A `Sigma` with `fun i ↦ ULift (PLift (P i))` fibers is equivalent to `{ x // P x }`.
Variant of `sigmaPLiftEquivSubtype`.
-/
def sigmaULiftPLiftEquivSubtype {α : Type v} (P : α → Prop) :
(Σ i, ULift (PLift (P i))) ≃ Subtype P :=
(sigmaCongrRight fun _ => Equiv.ulift).trans (sigmaPLiftEquivSubtype P)
namespace Perm
/-- A family of permutations `Π a, Perm (β a)` generates a permutation `Perm (Σ a, β₁ a)`. -/
abbrev sigmaCongrRight {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) : Perm (Σ a, β a) :=
Equiv.sigmaCongrRight F
@[simp] theorem sigmaCongrRight_trans {α} {β : α → Sort _}
(F : ∀ a, Perm (β a)) (G : ∀ a, Perm (β a)) :
(sigmaCongrRight F).trans (sigmaCongrRight G) = sigmaCongrRight fun a => (F a).trans (G a) :=
Equiv.sigmaCongrRight_trans F G
@[simp] theorem sigmaCongrRight_symm {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) :
(sigmaCongrRight F).symm = sigmaCongrRight fun a => (F a).symm :=
Equiv.sigmaCongrRight_symm F
@[simp] theorem sigmaCongrRight_refl {α} {β : α → Sort _} :
(sigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ a, β a) :=
Equiv.sigmaCongrRight_refl
end Perm
/-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/
@[simps apply] def sigmaCongrLeft {α₁ α₂ : Type*} {β : α₂ → Sort _} (e : α₁ ≃ α₂) :
(Σ a : α₁, β (e a)) ≃ Σ a : α₂, β a where
toFun a := ⟨e a.1, a.2⟩
invFun a := ⟨e.symm a.1, (e.right_inv' a.1).symm ▸ a.2⟩
left_inv := fun ⟨a, b⟩ => by simp
right_inv := fun ⟨a, b⟩ => by simp
/-- Transporting a sigma type through an equivalence of the base -/
def sigmaCongrLeft' {α₁ α₂} {β : α₁ → Sort _} (f : α₁ ≃ α₂) :
(Σ a : α₁, β a) ≃ Σ a : α₂, β (f.symm a) := (sigmaCongrLeft f.symm).symm
/-- Transporting a sigma type through an equivalence of the base and a family of equivalences
of matching fibers -/
def sigmaCongr {α₁ α₂} {β₁ : α₁ → Sort _} {β₂ : α₂ → Sort _} (f : α₁ ≃ α₂)
(F : ∀ a, β₁ a ≃ β₂ (f a)) : Sigma β₁ ≃ Sigma β₂ :=
(sigmaCongrRight F).trans (sigmaCongrLeft f)
/-- `Sigma` type with a constant fiber is equivalent to the product. -/
@[simps (config := { attrs := [`mfld_simps] }) apply symm_apply]
def sigmaEquivProd (α β : Type*) : (Σ _ : α, β) ≃ α × β :=
⟨fun a => ⟨a.1, a.2⟩, fun a => ⟨a.1, a.2⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩
/-- If each fiber of a `Sigma` type is equivalent to a fixed type, then the sigma type
is equivalent to the product. -/
def sigmaEquivProdOfEquiv {α β} {β₁ : α → Sort _} (F : ∀ a, β₁ a ≃ β) : Sigma β₁ ≃ α × β :=
(sigmaCongrRight F).trans (sigmaEquivProd α β)
/-- The dependent product of types is associative up to an equivalence. -/
def sigmaAssoc {α : Type*} {β : α → Type*} (γ : ∀ a : α, β a → Type*) :
(Σ ab : Σ a : α, β a, γ ab.1 ab.2) ≃ Σ a : α, Σ b : β a, γ a b where
toFun x := ⟨x.1.1, ⟨x.1.2, x.2⟩⟩
invFun x := ⟨⟨x.1, x.2.1⟩, x.2.2⟩
left_inv _ := rfl
right_inv _ := rfl
/-- The dependent product of sorts is associative up to an equivalence. -/
def pSigmaAssoc {α : Sort*} {β : α → Sort*} (γ : ∀ a : α, β a → Sort*) :
(Σ' ab : Σ' a : α, β a, γ ab.1 ab.2) ≃ Σ' a : α, Σ' b : β a, γ a b where
toFun x := ⟨x.1.1, ⟨x.1.2, x.2⟩⟩
invFun x := ⟨⟨x.1, x.2.1⟩, x.2.2⟩
left_inv _ := rfl
right_inv _ := rfl
end
variable {p : α → Prop} {q : β → Prop} (e : α ≃ β)
protected lemma forall_congr_right : (∀ a, q (e a)) ↔ ∀ b, q b :=
⟨fun h a ↦ by simpa using h (e.symm a), fun h _ ↦ h _⟩
protected lemma forall_congr_left : (∀ a, p a) ↔ ∀ b, p (e.symm b) :=
e.symm.forall_congr_right.symm
protected lemma forall_congr (h : ∀ a, p a ↔ q (e a)) : (∀ a, p a) ↔ ∀ b, q b :=
e.forall_congr_left.trans (by simp [h])
protected lemma forall_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∀ a, p a) ↔ ∀ b, q b :=
e.forall_congr_left.trans (by simp [h])
protected lemma exists_congr_right : (∃ a, q (e a)) ↔ ∃ b, q b :=
⟨fun ⟨_, h⟩ ↦ ⟨_, h⟩, fun ⟨a, h⟩ ↦ ⟨e.symm a, by simpa using h⟩⟩
protected lemma exists_congr_left : (∃ a, p a) ↔ ∃ b, p (e.symm b) :=
e.symm.exists_congr_right.symm
protected lemma exists_congr (h : ∀ a, p a ↔ q (e a)) : (∃ a, p a) ↔ ∃ b, q b :=
e.exists_congr_left.trans <| by simp [h]
protected lemma exists_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∃ a, p a) ↔ ∃ b, q b :=
e.exists_congr_left.trans <| by simp [h]
protected lemma existsUnique_congr_right : (∃! a, q (e a)) ↔ ∃! b, q b :=
e.exists_congr <| by simpa using fun _ _ ↦ e.forall_congr (by simp)
protected lemma existsUnique_congr_left : (∃! a, p a) ↔ ∃! b, p (e.symm b) :=
e.symm.existsUnique_congr_right.symm
protected lemma existsUnique_congr (h : ∀ a, p a ↔ q (e a)) : (∃! a, p a) ↔ ∃! b, q b :=
e.existsUnique_congr_left.trans <| by simp [h]
protected lemma existsUnique_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∃! a, p a) ↔ ∃! b, q b :=
e.existsUnique_congr_left.trans <| by simp [h]
-- We next build some higher arity versions of `Equiv.forall_congr`.
-- Although they appear to just be repeated applications of `Equiv.forall_congr`,
-- unification of metavariables works better with these versions.
-- In particular, they are necessary in `equiv_rw`.
-- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics,
-- it's rare to have axioms involving more than 3 elements at once.)
protected theorem forall₂_congr {α₁ α₂ β₁ β₂ : Sort*} {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀ {x y}, p x y ↔ q (eα x) (eβ y)) :
(∀ x y, p x y) ↔ ∀ x y, q x y :=
eα.forall_congr fun _ ↦ eβ.forall_congr <| @h _
protected theorem forall₂_congr' {α₁ α₂ β₁ β₂ : Sort*} {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀ {x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) :
(∀ x y, p x y) ↔ ∀ x y, q x y := (Equiv.forall₂_congr eα.symm eβ.symm h.symm).symm
protected theorem forall₃_congr
{α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀ {x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) :
(∀ x y z, p x y z) ↔ ∀ x y z, q x y z :=
Equiv.forall₂_congr _ _ <| Equiv.forall_congr _ <| @h _ _
protected theorem forall₃_congr'
{α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂)
(h : ∀ {x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) :
(∀ x y z, p x y z) ↔ ∀ x y z, q x y z :=
(Equiv.forall₃_congr eα.symm eβ.symm eγ.symm h.symm).symm
/-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/
@[simps apply]
noncomputable def ofBijective (f : α → β) (hf : Bijective f) : α ≃ β where
toFun := f
invFun := surjInv hf.surjective
left_inv := leftInverse_surjInv hf
right_inv := rightInverse_surjInv _
lemma ofBijective_apply_symm_apply (f : α → β) (hf : Bijective f) (x : β) :
f ((ofBijective f hf).symm x) = x :=
(ofBijective f hf).apply_symm_apply x
@[simp]
lemma ofBijective_symm_apply_apply (f : α → β) (hf : Bijective f) (x : α) :
(ofBijective f hf).symm (f x) = x :=
(ofBijective f hf).symm_apply_apply x
end Equiv
namespace Quot
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂)`. -/
protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀ a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) : Quot ra ≃ Quot rb where
toFun := Quot.map e fun a₁ a₂ => (eq a₁ a₂).1
invFun := Quot.map e.symm fun b₁ b₂ h =>
(eq (e.symm b₁) (e.symm b₂)).2
((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)
left_inv := by rintro ⟨a⟩; simp only [Quot.map, Equiv.symm_apply_apply]
right_inv := by rintro ⟨a⟩; simp only [Quot.map, Equiv.apply_symm_apply]
@[simp] theorem congr_mk {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀ a₁ a₂ : α, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) :
Quot.congr e eq (Quot.mk ra a) = Quot.mk rb (e a) := rfl
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congrRight {r r' : α → α → Prop} (eq : ∀ a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) :
Quot r ≃ Quot r' := Quot.congr (Equiv.refl α) eq
/-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α`
by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/
protected def congrLeft {r : α → α → Prop} (e : α ≃ β) :
Quot r ≃ Quot fun b b' => r (e.symm b) (e.symm b') :=
Quot.congr e fun _ _ => by simp only [e.symm_apply_apply]
end Quot
namespace Quotient
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂)`. -/
protected def congr {ra : Setoid α} {rb : Setoid β} (e : α ≃ β)
(eq : ∀ a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) :
Quotient ra ≃ Quotient rb := Quot.congr e eq
@[simp] theorem congr_mk {ra : Setoid α} {rb : Setoid β} (e : α ≃ β)
(eq : ∀ a₁ a₂ : α, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) :
Quotient.congr e eq (Quotient.mk ra a) = Quotient.mk rb (e a) := rfl
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congrRight {r r' : Setoid α}
(eq : ∀ a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) : Quotient r ≃ Quotient r' :=
Quot.congrRight eq
end Quotient
/-- Equivalence between `Fin 0` and `Empty`. -/
def finZeroEquiv : Fin 0 ≃ Empty := .equivEmpty _
/-- Equivalence between `Fin 0` and `PEmpty`. -/
def finZeroEquiv' : Fin 0 ≃ PEmpty.{u} := .equivPEmpty _
/-- Equivalence between `Fin 1` and `Unit`. -/
def finOneEquiv : Fin 1 ≃ Unit := .equivPUnit _
/-- Equivalence between `Fin 2` and `Bool`. -/
def finTwoEquiv : Fin 2 ≃ Bool where
toFun i := i == 1
invFun b := bif b then 1 else 0
left_inv i :=
match i with
| 0 => by simp
| 1 => by simp
right_inv b := by cases b <;> simp
namespace Equiv
variable {α β : Type*}
/-- The left summand of `α ⊕ β` is equivalent to `α`. -/
@[simps]
def sumIsLeft : {x : α ⊕ β // x.isLeft} ≃ α where
toFun x := x.1.getLeft x.2
invFun a := ⟨.inl a, Sum.isLeft_inl⟩
left_inv | ⟨.inl _a, _⟩ => rfl
right_inv _a := rfl
/-- The right summand of `α ⊕ β` is equivalent to `β`. -/
@[simps]
def sumIsRight : {x : α ⊕ β // x.isRight} ≃ β where
toFun x := x.1.getRight x.2
invFun b := ⟨.inr b, Sum.isRight_inr⟩
left_inv | ⟨.inr _b, _⟩ => rfl
right_inv _b := rfl
end Equiv
| Mathlib/Logic/Equiv/Defs.lean | 913 | 914 | |
/-
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.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.MvPolynomial.Rename
/-!
# Degrees of polynomials
This file establishes many results about the degree of a multivariate polynomial.
The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the
variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a
monomial of $P$.
## Main declarations
* `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets
corresponding to each non-zero monomial in `p`.
For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}`
* `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`.
For example if `p = x⁴y+yz` then `degreeOf y p = 1`.
* `MvPolynomial.totalDegree p : ℕ` :
the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.
For example if `p = x⁴y+yz` then `totalDegree p = 5`.
## 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 Degrees
/-! ### `degrees` -/
/-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)
-/
def degrees (p : MvPolynomial σ R) : Multiset σ :=
letI := Classical.decEq σ
p.support.sup fun s : σ →₀ ℕ => toMultiset s
theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) :
p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl
theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by
classical
refine (supDegree_single s a).trans_le ?_
split_ifs
exacts [bot_le, le_rfl]
theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) :
degrees (monomial s a) = toMultiset s := by
classical
exact (supDegree_single s a).trans (if_neg ha)
theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 :=
Multiset.le_zero.1 <| degrees_monomial _ _
theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} :=
le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _
@[simp]
theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} :=
(degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _)
@[simp]
theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by
rw [← C_0]
exact degrees_C 0
@[simp]
theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 :=
degrees_C 1
theorem degrees_add_le [DecidableEq σ] {p q : MvPolynomial σ R} :
(p + q).degrees ≤ p.degrees ⊔ q.degrees := by
simp_rw [degrees_def]; exact supDegree_add_le
theorem degrees_sum_le {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) :
(∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by
simp_rw [degrees_def]; exact supDegree_sum_le
theorem degrees_mul_le {p q : MvPolynomial σ R} : (p * q).degrees ≤ p.degrees + q.degrees := by
classical
simp_rw [degrees_def]
exact supDegree_mul_le (map_add _)
theorem degrees_prod_le {ι : Type*} {s : Finset ι} {f : ι → MvPolynomial σ R} :
(∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by
classical exact supDegree_prod_le (map_zero _) (map_add _)
theorem degrees_pow_le {p : MvPolynomial σ R} {n : ℕ} : (p ^ n).degrees ≤ n • p.degrees := by
simpa using degrees_prod_le (s := .range n) (f := fun _ ↦ p)
@[deprecated (since := "2024-12-28")] alias degrees_add := degrees_add_le
@[deprecated (since := "2024-12-28")] alias degrees_sum := degrees_sum_le
@[deprecated (since := "2024-12-28")] alias degrees_mul := degrees_mul_le
@[deprecated (since := "2024-12-28")] alias degrees_prod := degrees_prod_le
@[deprecated (since := "2024-12-28")] alias degrees_pow := degrees_pow_le
theorem mem_degrees {p : MvPolynomial σ R} {i : σ} :
i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by
classical
simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop]
theorem le_degrees_add_left (h : Disjoint p.degrees q.degrees) : p.degrees ≤ (p + q).degrees := by
classical
apply Finset.sup_le
intro d hd
rw [Multiset.disjoint_iff_ne] at h
obtain rfl | h0 := eq_or_ne d 0
· rw [toMultiset_zero]; apply Multiset.zero_le
· refine Finset.le_sup_of_le (b := d) ?_ le_rfl
rw [mem_support_iff, coeff_add]
suffices q.coeff d = 0 by rwa [this, add_zero, coeff, ← Finsupp.mem_support_iff]
rw [Ne, ← Finsupp.support_eq_empty, ← Ne, ← Finset.nonempty_iff_ne_empty] at h0
obtain ⟨j, hj⟩ := h0
contrapose! h
rw [mem_support_iff] at hd
refine ⟨j, ?_, j, ?_, rfl⟩
all_goals rw [mem_degrees]; refine ⟨d, ?_, hj⟩; assumption
@[deprecated (since := "2024-12-28")] alias le_degrees_add := le_degrees_add_left
lemma le_degrees_add_right (h : Disjoint p.degrees q.degrees) : q.degrees ≤ (p + q).degrees := by
simpa [add_comm] using le_degrees_add_left h.symm
theorem degrees_add_of_disjoint [DecidableEq σ] (h : Disjoint p.degrees q.degrees) :
(p + q).degrees = p.degrees ∪ q.degrees :=
degrees_add_le.antisymm <| Multiset.union_le (le_degrees_add_left h) (le_degrees_add_right h)
lemma degrees_map_le [CommSemiring S] {f : R →+* S} : (map f p).degrees ≤ p.degrees := by
classical exact Finset.sup_mono <| support_map_subset ..
@[deprecated (since := "2024-12-28")] alias degrees_map := degrees_map_le
theorem degrees_rename (f : σ → τ) (φ : MvPolynomial σ R) :
(rename f φ).degrees ⊆ φ.degrees.map f := by
classical
intro i
rw [mem_degrees, Multiset.mem_map]
rintro ⟨d, hd, hi⟩
obtain ⟨x, rfl, hx⟩ := coeff_rename_ne_zero _ _ _ hd
simp only [Finsupp.mapDomain, Finsupp.mem_support_iff] at hi
rw [sum_apply, Finsupp.sum] at hi
contrapose! hi
rw [Finset.sum_eq_zero]
intro j hj
simp only [exists_prop, mem_degrees] at hi
specialize hi j ⟨x, hx, hj⟩
rw [Finsupp.single_apply, if_neg hi]
theorem degrees_map_of_injective [CommSemiring S] (p : MvPolynomial σ R) {f : R →+* S}
(hf : Injective f) : (map f p).degrees = p.degrees := by
simp only [degrees, MvPolynomial.support_map_of_injective _ hf]
theorem degrees_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f) :
degrees (rename f p) = (degrees p).map f := by
classical
simp only [degrees, Multiset.map_finset_sup p.support Finsupp.toMultiset f h,
support_rename_of_injective h, Finset.sup_image]
refine Finset.sup_congr rfl fun x _ => ?_
exact (Finsupp.toMultiset_map _ _).symm
end Degrees
section DegreeOf
/-! ### `degreeOf` -/
/-- `degreeOf n p` gives the highest power of X_n that appears in `p` -/
def degreeOf (n : σ) (p : MvPolynomial σ R) : ℕ :=
letI := Classical.decEq σ
p.degrees.count n
theorem degreeOf_def [DecidableEq σ] (n : σ) (p : MvPolynomial σ R) :
p.degreeOf n = p.degrees.count n := by rw [degreeOf]; convert rfl
theorem degreeOf_eq_sup (n : σ) (f : MvPolynomial σ R) :
degreeOf n f = f.support.sup fun m => m n := by
classical
rw [degreeOf_def, degrees, Multiset.count_finset_sup]
congr
ext
simp only [count_toMultiset]
theorem degreeOf_lt_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} (h : 0 < d) :
degreeOf n f < d ↔ ∀ m : σ →₀ ℕ, m ∈ f.support → m n < d := by
rwa [degreeOf_eq_sup, Finset.sup_lt_iff]
lemma degreeOf_le_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} :
degreeOf n f ≤ d ↔ ∀ m ∈ support f, m n ≤ d := by
rw [degreeOf_eq_sup, Finset.sup_le_iff]
@[simp]
theorem degreeOf_zero (n : σ) : degreeOf n (0 : MvPolynomial σ R) = 0 := by
classical simp only [degreeOf_def, degrees_zero, Multiset.count_zero]
@[simp]
theorem degreeOf_C (a : R) (x : σ) : degreeOf x (C a : MvPolynomial σ R) = 0 := by
classical simp [degreeOf_def, degrees_C]
theorem degreeOf_X [DecidableEq σ] (i j : σ) [Nontrivial R] :
degreeOf i (X j : MvPolynomial σ R) = if i = j then 1 else 0 := by
classical
by_cases c : i = j
· simp only [c, if_true, eq_self_iff_true, degreeOf_def, degrees_X, Multiset.count_singleton]
simp [c, if_false, degreeOf_def, degrees_X]
theorem degreeOf_add_le (n : σ) (f g : MvPolynomial σ R) :
degreeOf n (f + g) ≤ max (degreeOf n f) (degreeOf n g) := by
simp_rw [degreeOf_eq_sup]; exact supDegree_add_le
theorem monomial_le_degreeOf (i : σ) {f : MvPolynomial σ R} {m : σ →₀ ℕ} (h_m : m ∈ f.support) :
m i ≤ degreeOf i f := by
rw [degreeOf_eq_sup i]
apply Finset.le_sup h_m
lemma degreeOf_monomial_eq (s : σ →₀ ℕ) (i : σ) {a : R} (ha : a ≠ 0) :
(monomial s a).degreeOf i = s i := by
classical rw [degreeOf_def, degrees_monomial_eq _ _ ha, Finsupp.count_toMultiset]
-- TODO we can prove equality with `NoZeroDivisors R`
theorem degreeOf_mul_le (i : σ) (f g : MvPolynomial σ R) :
degreeOf i (f * g) ≤ degreeOf i f + degreeOf i g := by
classical
simp only [degreeOf]
convert Multiset.count_le_of_le i degrees_mul_le
rw [Multiset.count_add]
theorem degreeOf_sum_le {ι : Type*} (i : σ) (s : Finset ι) (f : ι → MvPolynomial σ R) :
degreeOf i (∑ j ∈ s, f j) ≤ s.sup fun j => degreeOf i (f j) := by
simp_rw [degreeOf_eq_sup]
exact supDegree_sum_le
-- TODO we can prove equality with `NoZeroDivisors R`
theorem degreeOf_prod_le {ι : Type*} (i : σ) (s : Finset ι) (f : ι → MvPolynomial σ R) :
degreeOf i (∏ j ∈ s, f j) ≤ ∑ j ∈ s, (f j).degreeOf i := by
simp_rw [degreeOf_eq_sup]
exact supDegree_prod_le (by simp only [coe_zero, Pi.zero_apply])
(fun _ _ => by simp only [coe_add, Pi.add_apply])
-- TODO we can prove equality with `NoZeroDivisors R`
theorem degreeOf_pow_le (i : σ) (p : MvPolynomial σ R) (n : ℕ) :
degreeOf i (p ^ n) ≤ n * degreeOf i p := by
simpa using degreeOf_prod_le i (Finset.range n) (fun _ => p)
theorem degreeOf_mul_X_of_ne {i j : σ} (f : MvPolynomial σ R) (h : i ≠ j) :
degreeOf i (f * X j) = degreeOf i f := by
classical
simp only [degreeOf_eq_sup i, support_mul_X, Finset.sup_map]
congr
ext
simp only [Finsupp.single, add_eq_left, addRightEmbedding_apply, coe_mk,
Pi.add_apply, comp_apply, ite_eq_right_iff, Finsupp.coe_add, Pi.single_eq_of_ne h]
@[deprecated (since := "2024-12-01")] alias degreeOf_mul_X_ne := degreeOf_mul_X_of_ne
theorem degreeOf_mul_X_self (j : σ) (f : MvPolynomial σ R) :
degreeOf j (f * X j) ≤ degreeOf j f + 1 := by
classical
simp only [degreeOf]
apply (Multiset.count_le_of_le j degrees_mul_le).trans
simp only [Multiset.count_add, add_le_add_iff_left]
convert Multiset.count_le_of_le j <| degrees_X' j
rw [Multiset.count_singleton_self]
@[deprecated (since := "2024-12-01")] alias degreeOf_mul_X_eq := degreeOf_mul_X_self
theorem degreeOf_mul_X_eq_degreeOf_add_one_iff (j : σ) (f : MvPolynomial σ R) :
degreeOf j (f * X j) = degreeOf j f + 1 ↔ f ≠ 0 := by
refine ⟨fun h => by by_contra ha; simp [ha] at h, fun h => ?_⟩
apply Nat.le_antisymm (degreeOf_mul_X_self j f)
have : (f.support.sup fun m ↦ m j) + 1 = (f.support.sup fun m ↦ (m j + 1)) :=
Finset.comp_sup_eq_sup_comp_of_nonempty @Nat.succ_le_succ (support_nonempty.mpr h)
simp only [degreeOf_eq_sup, support_mul_X, this]
apply Finset.sup_le
intro x hx
simp only [Finset.sup_map, bot_eq_zero', add_pos_iff, zero_lt_one, or_true, Finset.le_sup_iff]
use x
simpa using mem_support_iff.mp hx
theorem degreeOf_C_mul_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(C c * p).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf
convert Multiset.count_le_of_le i degrees_mul_le
simp only [degrees_C, zero_add]
| theorem degreeOf_mul_C_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(p * C c).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf
convert Multiset.count_le_of_le i degrees_mul_le
simp only [degrees_C, add_zero]
| Mathlib/Algebra/MvPolynomial/Degrees.lean | 328 | 332 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Operations
import Mathlib.Order.Basic
import Mathlib.Order.BooleanAlgebra
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.ByContra
import Mathlib.Util.Delaborators
import Mathlib.Tactic.Lift
/-!
# Basic properties of sets
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not
be decidable. The definition is in the module `Mathlib.Data.Set.Defs`.
This file provides some basic definitions related to sets and functions not present in the
definitions file, as well as extra lemmas for functions defined in the definitions file and
`Mathlib.Data.Set.Operations` (empty set, univ, union, intersection, insert, singleton,
set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending
`s` to the corresponding subtype `↥s`.
See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : α → β` is a function,
- `s : Set α` and `s₁ s₂ : Set α` are subsets of `α`
- `t : Set β` is a subset of `β`.
Definitions in the file:
* `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`.
## Notation
* `sᶜ` for the complement of `s`
## Implementation notes
* `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that
the `s.Nonempty` dot notation can be used.
* For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset
-/
assert_not_exists RelIso
/-! ### Set coercion to a type -/
open Function
universe u v
namespace Set
variable {α : Type u} {s t : Set α}
instance instBooleanAlgebra : BooleanAlgebra (Set α) :=
{ (inferInstance : BooleanAlgebra (α → Prop)) with
sup := (· ∪ ·),
le := (· ≤ ·),
lt := fun s t => s ⊆ t ∧ ¬t ⊆ s,
inf := (· ∩ ·),
bot := ∅,
compl := (·ᶜ),
top := univ,
sdiff := (· \ ·) }
instance : HasSSubset (Set α) :=
⟨(· < ·)⟩
@[simp]
theorem top_eq_univ : (⊤ : Set α) = univ :=
rfl
@[simp]
theorem bot_eq_empty : (⊥ : Set α) = ∅ :=
rfl
@[simp]
theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) :=
rfl
@[simp]
theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) :=
rfl
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) :=
rfl
@[simp]
theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) :=
rfl
theorem le_iff_subset : s ≤ t ↔ s ⊆ t :=
Iff.rfl
theorem lt_iff_ssubset : s < t ↔ s ⊂ t :=
Iff.rfl
alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset
alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset
instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) :
CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α s
instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiSetCoe.canLift ι (fun _ => α) s
end Set
section SetCoe
variable {α : Type u}
instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩
theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } :=
rfl
@[simp]
theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } :=
rfl
theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
theorem SetCoe.exists {s : Set α} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 :=
(@SetCoe.exists _ _ fun x => p x.1 x.2).symm
theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 :=
(@SetCoe.forall _ _ fun x => p x.1 x.2).symm
@[simp]
theorem set_coe_cast :
∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩
| _, _, rfl, _, _ => rfl
theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b :=
Subtype.eq
theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
Iff.intro SetCoe.ext fun h => h ▸ rfl
end SetCoe
/-- See also `Subtype.prop` -/
theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s :=
p.prop
/-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/
theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t :=
fun h₁ _ h₂ => by rw [← h₁]; exact h₂
namespace Set
variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α}
instance : Inhabited (Set α) :=
⟨∅⟩
@[trans]
theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by
tauto
theorem setOf_injective : Function.Injective (@setOf α) := injective_id
theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl
/-! ### Lemmas about `mem` and `setOf` -/
theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a :=
Iff.rfl
/-- This lemma is intended for use with `rw` where a membership predicate is needed,
hence the explicit argument and the equality in the reverse direction from normal.
See also `Set.mem_setOf_eq` for the reverse direction applied to an argument. -/
theorem eq_mem_setOf (p : α → Prop) : p = (· ∈ {a | p a}) := rfl
/-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to `simp`. -/
theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a :=
h
theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a :=
Iff.rfl
@[simp]
theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s :=
rfl
theorem setOf_set {s : Set α} : setOf s = s :=
rfl
theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x :=
Iff.rfl
theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a :=
Iff.rfl
theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) :=
bijective_id
theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x :=
Iff.rfl
theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s :=
Iff.rfl
@[simp]
theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a :=
Iff.rfl
theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } :=
rfl
theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } :=
rfl
/-! ### Subset and strict subset relations -/
instance : IsRefl (Set α) (· ⊆ ·) :=
show IsRefl (Set α) (· ≤ ·) by infer_instance
instance : IsTrans (Set α) (· ⊆ ·) :=
show IsTrans (Set α) (· ≤ ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) :=
show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance
instance : IsAntisymm (Set α) (· ⊆ ·) :=
show IsAntisymm (Set α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Set α) (· ⊂ ·) :=
show IsIrrefl (Set α) (· < ·) by infer_instance
instance : IsTrans (Set α) (· ⊂ ·) :=
show IsTrans (Set α) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· < ·) (· < ·) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) :=
show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance
instance : IsAsymm (Set α) (· ⊂ ·) :=
show IsAsymm (Set α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t :=
rfl
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) :=
rfl
@[refl]
theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id
theorem Subset.rfl {s : Set α} : s ⊆ s :=
Subset.refl s
@[trans]
theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h
@[trans]
theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩
theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩
-- an alternative name
theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b :=
Subset.antisymm
theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ :=
@h _
theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s :=
mt <| mem_of_subset_of_mem h
theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by
simp only [subset_def, not_forall, exists_prop]
theorem not_top_subset : ¬⊤ ⊆ s ↔ ∃ a, a ∉ s := by
simp [not_subset]
lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h
/-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/
protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t :=
eq_or_lt_of_le h
theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s :=
not_subset.1 h.2
protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne (Set α) _ s t
theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s :=
⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩
theorem ssubset_iff_exists {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ ∃ x ∈ t, x ∉ s :=
⟨fun h ↦ ⟨h.le, Set.exists_of_ssubset h⟩, fun ⟨h1, h2⟩ ↦ (Set.ssubset_iff_of_subset h1).mpr h2⟩
protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂)
(hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩
protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂)
(hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩
theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) :=
id
theorem not_not_mem : ¬a ∉ s ↔ a ∈ s :=
not_not
/-! ### Non-empty sets -/
theorem nonempty_coe_sort {s : Set α} : Nonempty ↥s ↔ s.Nonempty :=
nonempty_subtype
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s :=
Iff.rfl
theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty :=
⟨x, h⟩
theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅
| ⟨_, hx⟩, hs => hs hx
/-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/
protected noncomputable def Nonempty.some (h : s.Nonempty) : α :=
Classical.choose h
protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s :=
Classical.choose_spec h
theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
hs.imp ht
theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty :=
let ⟨x, xs, xt⟩ := not_subset.1 h
⟨x, xs, xt⟩
theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty :=
nonempty_of_not_subset ht.2
theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty :=
(nonempty_of_ssubset ht).of_diff
theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty :=
hs.imp fun _ => Or.inl
theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty :=
ht.imp fun _ => Or.inr
@[simp]
theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty :=
exists_or
theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty :=
h.imp fun _ => And.right
theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t :=
Iff.rfl
theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by
simp_rw [inter_nonempty]
theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by
simp_rw [inter_nonempty, and_comm]
theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty :=
⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩
@[simp]
theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty
| ⟨x⟩ => ⟨x, trivial⟩
theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) :=
nonempty_subtype.2
theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩
instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) :=
Set.univ_nonempty.to_subtype
-- Redeclare for refined keys
-- `Nonempty (@Subtype _ (@Membership.mem _ (Set _) _ (@Top.top (Set _) _)))`
instance instNonemptyTop [Nonempty α] : Nonempty (⊤ : Set α) :=
inferInstanceAs (Nonempty (univ : Set α))
theorem Nonempty.of_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_›
@[deprecated (since := "2024-11-23")] alias nonempty_of_nonempty_subtype := Nonempty.of_subtype
/-! ### Lemmas about the empty set -/
theorem empty_def : (∅ : Set α) = { _x : α | False } :=
rfl
@[simp]
theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False :=
Iff.rfl
@[simp]
theorem setOf_false : { _a : α | False } = ∅ :=
rfl
@[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl
@[simp]
theorem empty_subset (s : Set α) : ∅ ⊆ s :=
nofun
@[simp]
theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ :=
(Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm
theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s :=
subset_empty_iff.symm
theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ :=
subset_empty_iff.1 h
theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ :=
subset_empty_iff.1
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ :=
eq_empty_of_subset_empty fun x _ => isEmptyElim x
/-- There is exactly one set of a type that is empty. -/
instance uniqueEmpty [IsEmpty α] : Unique (Set α) where
default := ∅
uniq := eq_empty_of_isEmpty
/-- See also `Set.nonempty_iff_ne_empty`. -/
theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by
simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `Set.not_nonempty_iff_eq_empty`. -/
theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty.not_right
/-- See also `nonempty_iff_ne_empty'`. -/
theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by
rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem]
/-- See also `not_nonempty_iff_eq_empty'`. -/
theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty'.not_right
alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx
@[simp]
theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ :=
not_iff_not.1 <| by simpa using nonempty_iff_ne_empty
theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty :=
or_iff_not_imp_left.2 nonempty_iff_ne_empty.2
theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 <| e ▸ h
theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True :=
iff_true_intro fun _ => False.elim
instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) :=
⟨fun x => x.2⟩
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
/-!
### Universal set.
In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`.
Mathematically it is the same as `α` but it has a different type.
-/
@[simp]
theorem setOf_true : { _x : α | True } = univ :=
rfl
@[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl
@[simp]
theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α :=
eq_empty_iff_forall_not_mem.trans
⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩
theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e =>
not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm
@[simp]
theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial
@[simp]
theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ :=
@top_le_iff _ _ _ s
alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff
theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s :=
univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial
theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ :=
eq_univ_iff_forall.2
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by
rintro ⟨x, hx⟩
exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t)
theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α)
| ⟨x⟩ => ⟨x, trivial⟩
theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by
rw [← not_forall, ← eq_univ_iff_forall]
theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} :
¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def]
theorem univ_unique [Unique α] : @Set.univ α = {default} :=
Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default
theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ :=
lt_top_iff_ne_top
instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) :=
⟨⟨∅, univ, empty_ne_univ⟩⟩
/-! ### Lemmas about union -/
theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } :=
rfl
theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b :=
Or.inl
theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b :=
Or.inr
theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b :=
H
theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P)
(H₃ : x ∈ b → P) : P :=
Or.elim H₁ H₂ H₃
@[simp]
theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b :=
Iff.rfl
@[simp]
theorem union_self (a : Set α) : a ∪ a = a :=
ext fun _ => or_self_iff
@[simp]
theorem union_empty (a : Set α) : a ∪ ∅ = a :=
ext fun _ => iff_of_eq (or_false _)
@[simp]
theorem empty_union (a : Set α) : ∅ ∪ a = a :=
ext fun _ => iff_of_eq (false_or _)
theorem union_comm (a b : Set α) : a ∪ b = b ∪ a :=
ext fun _ => or_comm
theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) :=
ext fun _ => or_assoc
instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) :=
⟨union_assoc⟩
instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) :=
⟨union_comm⟩
theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext fun _ => or_left_comm
theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ :=
ext fun _ => or_right_comm
@[simp]
theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s :=
sup_eq_left
@[simp]
theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t :=
sup_eq_right
theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t :=
union_eq_right.mpr h
theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s :=
union_eq_left.mpr h
@[simp]
theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl
@[simp]
theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr
theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ =>
Or.rec (@sr _) (@tr _)
@[simp]
theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
(forall_congr' fun _ => or_imp).trans forall_and
@[gcongr]
theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) :
s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _)
@[gcongr]
theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h Subset.rfl
@[gcongr]
theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union Subset.rfl h
theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_left
theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_right
theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u :=
sup_congr_left ht hu
theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u :=
sup_congr_right hs ht
theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t :=
sup_eq_sup_iff_left
theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u :=
sup_eq_sup_iff_right
@[simp]
theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by
simp only [← subset_empty_iff]
exact union_subset_iff
@[simp]
theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _
@[simp]
theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _
@[simp]
theorem ssubset_union_left_iff : s ⊂ s ∪ t ↔ ¬ t ⊆ s :=
left_lt_sup
@[simp]
theorem ssubset_union_right_iff : t ⊂ s ∪ t ↔ ¬ s ⊆ t :=
right_lt_sup
/-! ### Lemmas about intersection -/
theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } :=
rfl
@[simp, mfld_simps]
theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b :=
Iff.rfl
theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b :=
⟨ha, hb⟩
theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a :=
h.left
theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b :=
h.right
@[simp]
theorem inter_self (a : Set α) : a ∩ a = a :=
ext fun _ => and_self_iff
@[simp]
theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ :=
ext fun _ => iff_of_eq (and_false _)
@[simp]
theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ :=
ext fun _ => iff_of_eq (false_and _)
theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a :=
ext fun _ => and_comm
theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) :=
ext fun _ => and_assoc
instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) :=
⟨inter_assoc⟩
instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) :=
⟨inter_comm⟩
theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext fun _ => and_left_comm
theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ :=
ext fun _ => and_right_comm
@[simp, mfld_simps]
theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left
@[simp]
theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right
theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h =>
⟨rs h, rt h⟩
@[simp]
theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
(forall_congr' fun _ => imp_and).trans forall_and
@[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left
@[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right
@[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf
@[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf
theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s :=
inter_eq_left.mpr
theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t :=
inter_eq_right.mpr
theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u :=
inf_congr_left ht hu
theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u :=
inf_congr_right hs ht
theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u :=
inf_eq_inf_iff_left
theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t :=
inf_eq_inf_iff_right
@[simp, mfld_simps]
theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _
@[simp, mfld_simps]
theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _
@[gcongr]
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) :
s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _)
@[gcongr]
theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
inter_subset_inter H Subset.rfl
@[gcongr]
theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
inter_subset_inter Subset.rfl H
theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s :=
inter_eq_self_of_subset_right subset_union_left
theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t :=
inter_eq_self_of_subset_right subset_union_right
theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} :=
rfl
theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} :=
inter_comm _ _
@[simp]
theorem inter_ssubset_right_iff : s ∩ t ⊂ t ↔ ¬ t ⊆ s :=
inf_lt_right
@[simp]
theorem inter_ssubset_left_iff : s ∩ t ⊂ s ↔ ¬ s ⊆ t :=
inf_lt_left
/-! ### Distributivity laws -/
theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u :=
inf_sup_left _ _ _
theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u :=
inf_sup_right _ _ _
theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left _ _ _
theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right _ _ _
theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) :=
sup_sup_distrib_left _ _ _
theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) :=
sup_sup_distrib_right _ _ _
theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) :=
inf_inf_distrib_left _ _ _
theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) :=
inf_inf_distrib_right _ _ _
theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) :=
sup_sup_sup_comm _ _ _ _
theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) :=
inf_inf_inf_comm _ _ _ _
/-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/
section Sep
variable {p q : α → Prop} {x : α}
theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } :=
⟨xs, px⟩
@[simp]
theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t :=
rfl
@[simp]
theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x :=
Iff.rfl
theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_congr_right_iff]
theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s :=
inter_eq_self_of_subset_right h
@[simp]
theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left
@[simp]
theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_iff_left_iff_imp]
@[simp]
theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by
simp_rw [Set.ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and]
theorem sep_true : { x ∈ s | True } = s :=
inter_univ s
theorem sep_false : { x ∈ s | False } = ∅ :=
inter_empty s
theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ :=
empty_inter {x | p x}
theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } :=
univ_inter {x | p x}
@[simp]
theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } :=
union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p
@[simp]
theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } :=
inter_inter_distrib_right s t {x | p x}
@[simp]
theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } :=
inter_inter_distrib_left s {x | p x} {x | q x}
@[simp]
theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } :=
inter_union_distrib_left s p q
@[simp]
theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } :=
rfl
end Sep
/-- See also `Set.sdiff_inter_right_comm`. -/
lemma inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc ..
/-- See also `Set.inter_diff_assoc`. -/
lemma sdiff_inter_right_comm (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm ..
lemma inter_sdiff_left_comm (s t u : Set α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm ..
theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u :=
sdiff_sup_sdiff_cancel hts hut
/-- A version of `diff_union_diff_cancel` with more general hypotheses. -/
theorem diff_union_diff_cancel' (hi : s ∩ u ⊆ t) (hu : t ⊆ s ∪ u) : (s \ t) ∪ (t \ u) = s \ u :=
sdiff_sup_sdiff_cancel' hi hu
theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h
theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) :=
inf_sdiff_distrib_left _ _ _
theorem inter_diff_distrib_right (s t u : Set α) : (s \ t) ∩ u = (s ∩ u) \ (t ∩ u) :=
inf_sdiff_distrib_right _ _ _
theorem diff_inter_distrib_right (s t r : Set α) : (t ∩ r) \ s = (t \ s) ∩ (r \ s) :=
inf_sdiff
/-! ### Lemmas about complement -/
theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } :=
rfl
theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ :=
h
theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } :=
rfl
theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s :=
h
theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s :=
not_not
@[simp]
theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ :=
inf_compl_eq_bot
@[simp]
theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ :=
compl_inf_eq_bot
@[simp]
theorem compl_empty : (∅ : Set α)ᶜ = univ :=
compl_bot
@[simp]
theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ :=
compl_sup
theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ :=
compl_inf
@[simp]
theorem compl_univ : (univ : Set α)ᶜ = ∅ :=
compl_top
@[simp]
theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ :=
compl_eq_bot
@[simp]
theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ :=
compl_eq_top
theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty :=
compl_univ_iff.not.trans nonempty_iff_ne_empty.symm
lemma inl_compl_union_inr_compl {α β : Type*} {s : Set α} {t : Set β} :
Sum.inl '' sᶜ ∪ Sum.inr '' tᶜ = (Sum.inl '' s ∪ Sum.inr '' t)ᶜ := by
rw [compl_union]
aesop
theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ :=
(ne_univ_iff_exists_not_mem s).symm
theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ :=
ext fun _ => or_iff_not_and_not
theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ :=
ext fun _ => and_iff_not_or_not
@[simp]
theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ :=
eq_univ_iff_forall.2 fun _ => em _
@[simp]
theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self]
theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s :=
@compl_le_iff_compl_le _ s _ _
theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ :=
@le_compl_iff_le_compl _ _ _ t
@[simp]
theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s :=
@compl_le_compl_iff_le (Set α) _ _ _
@[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h
theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t :=
(@isCompl_compl _ u _).le_sup_right_iff_inf_left_le
theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ :=
Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left
theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c :=
forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or
theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t :=
(not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm
/-! ### Lemmas about set difference -/
theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx
theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s :=
h.left
theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t :=
h.right
theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm]
theorem diff_nonempty {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t :=
inter_compl_nonempty_iff
theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le
theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ :=
diff_eq_compl_inter ▸ inter_subset_left
theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u :=
sup_sdiff_cancel' h₁ h₂
theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t :=
sup_sdiff_cancel_right h
theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t :=
Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h
theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s :=
Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h
@[simp]
theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s :=
sup_sdiff_left_self
@[simp]
theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u :=
sup_sdiff
@[simp]
theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ :=
inf_sdiff_self_right
@[simp]
theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s :=
sup_inf_sdiff s t
@[simp]
theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by
rw [union_comm]
exact sup_inf_sdiff _ _
@[simp]
theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s :=
inter_union_diff _ _
@[gcongr]
theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ :=
show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff
@[gcongr]
theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t :=
sdiff_le_sdiff_right ‹s₁ ≤ s₂›
@[gcongr]
theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t :=
sdiff_le_sdiff_left ‹t ≤ u›
theorem diff_subset_diff_iff_subset {r : Set α} (hs : s ⊆ r) (ht : t ⊆ r) :
r \ s ⊆ r \ t ↔ t ⊆ s :=
sdiff_le_sdiff_iff_le hs ht
theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s :=
top_sdiff.symm
@[simp]
theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ :=
bot_sdiff
theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
@[simp]
theorem diff_empty {s : Set α} : s \ ∅ = s :=
sdiff_bot
@[simp]
theorem diff_univ (s : Set α) : s \ univ = ∅ :=
diff_eq_empty.2 (subset_univ s)
theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) :=
sdiff_sdiff_left
-- the following statement contains parentheses to help the reader
theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t :=
sdiff_sdiff_comm
theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u :=
show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff
theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t :=
show s ≤ s \ t ∪ t from le_sdiff_sup
theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s :=
Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _)
theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t :=
show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm
theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u :=
sdiff_inf
theorem diff_inter_diff : s \ t ∩ (s \ u) = s \ (t ∪ u) :=
sdiff_sup.symm
theorem diff_compl : s \ tᶜ = s ∩ t :=
sdiff_compl
theorem compl_diff : (t \ s)ᶜ = s ∪ tᶜ :=
Eq.trans compl_sdiff himp_eq
theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u :=
sdiff_sdiff_right'
theorem inter_diff_right_comm : (s ∩ t) \ u = s \ u ∩ t := by
rw [diff_eq, diff_eq, inter_right_comm]
theorem diff_inter_right_comm : (s \ u) ∩ t = (s ∩ t) \ u := by
rw [diff_eq, diff_eq, inter_right_comm]
@[simp]
theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t :=
sup_sdiff_self _ _
@[simp]
theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t :=
sdiff_sup_self _ _
@[simp]
theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ :=
inf_sdiff_self_left
@[simp]
theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t :=
sdiff_inf_self_right _ _
@[simp]
theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t :=
sdiff_inf_self_left _ _
theorem diff_self {s : Set α} : s \ s = ∅ :=
sdiff_self
theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t :=
sdiff_sdiff_right_self
theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s :=
sdiff_sdiff_eq_self h
theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t :=
sup_eq_sdiff_sup_sdiff_sup_inf
/-! ### Powerset -/
theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h
theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h
@[simp]
theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s :=
Iff.rfl
theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t :=
ext fun _ => subset_inter_iff
@[simp]
theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t :=
⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩
theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2
@[simp]
theorem powerset_nonempty : (𝒫 s).Nonempty :=
⟨∅, fun _ h => empty_subset s h⟩
@[simp]
theorem powerset_empty : 𝒫(∅ : Set α) = {∅} :=
ext fun _ => subset_empty_iff
@[simp]
theorem powerset_univ : 𝒫(univ : Set α) = univ :=
eq_univ_of_forall subset_univ
/-! ### Sets defined as an if-then-else -/
@[deprecated _root_.mem_dite (since := "2025-01-30")]
protected theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) :
(x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h :=
_root_.mem_dite
theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by
simp [mem_dite]
@[simp]
theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t Set.univ ↔ p → x ∈ t :=
mem_dite_univ_right p (fun _ => t) x
theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by
split_ifs <;> simp_all
@[simp]
theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p Set.univ t ↔ ¬p → x ∈ t :=
mem_dite_univ_left p (fun _ => t) x
theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false, not_not]
exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩
@[simp]
theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t ∅ ↔ p ∧ x ∈ t :=
(mem_dite_empty_right p (fun _ => t) x).trans (by simp)
theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false]
exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩
@[simp]
theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t :=
(mem_dite_empty_left p (fun _ => t) x).trans (by simp)
/-! ### If-then-else for sets -/
/-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`.
Defined as `s ∩ t ∪ s' \ t`. -/
protected def ite (t s s' : Set α) : Set α :=
s ∩ t ∪ s' \ t
@[simp]
theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by
rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty]
@[simp]
theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by
rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq]
@[simp]
theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by
rw [← ite_compl, ite_inter_self]
@[simp]
theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t :=
ite_inter_compl_self t s s'
@[simp]
theorem ite_same (t s : Set α) : t.ite s s = s :=
inter_union_diff _ _
@[simp]
theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite]
@[simp]
theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite]
@[simp]
theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite]
@[simp]
theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite]
@[simp]
theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite]
@[simp]
theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite]
theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') :
t.ite s₁ s₁' ⊆ t.ite s₂ s₂' :=
union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h')
theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' :=
union_subset_union inter_subset_left diff_subset
theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' :=
ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right
theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) :
t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by
ext x
simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union]
tauto
theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by
rw [ite_inter_inter, ite_same]
theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) :
t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same]
theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by
simp only [subset_def, ← forall_and]
refine forall_congr' fun x => ?_
by_cases hx : x ∈ t <;> simp [*, Set.ite]
theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) :
t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)]
theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) :
t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by
ext x
by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)]
end Set
open Set
namespace Function
variable {α : Type*} {β : Type*}
theorem Injective.nonempty_apply_iff {f : Set α → Set β} (hf : Injective f) (h2 : f ∅ = ∅)
{s : Set α} : (f s).Nonempty ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, ← h2, nonempty_iff_ne_empty, hf.ne_iff]
end Function
namespace Subsingleton
variable {α : Type*} [Subsingleton α]
theorem eq_univ_of_nonempty {s : Set α} : s.Nonempty → s = univ := fun ⟨x, hx⟩ =>
eq_univ_of_forall fun y => Subsingleton.elim x y ▸ hx
@[elab_as_elim]
theorem set_cases {p : Set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s :=
(s.eq_empty_or_nonempty.elim fun h => h.symm ▸ h0) fun h => (eq_univ_of_nonempty h).symm ▸ h1
theorem mem_iff_nonempty {α : Type*} [Subsingleton α] {s : Set α} {x : α} : x ∈ s ↔ s.Nonempty :=
⟨fun hx => ⟨x, hx⟩, fun ⟨y, hy⟩ => Subsingleton.elim y x ▸ hy⟩
end Subsingleton
/-! ### Decidability instances for sets -/
namespace Set
variable {α : Type u} (s t : Set α) (a b : α)
instance decidableSdiff [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s \ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∉ t))
instance decidableInter [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∩ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∈ t))
instance decidableUnion [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∪ t) :=
inferInstanceAs (Decidable (a ∈ s ∨ a ∈ t))
instance decidableCompl [Decidable (a ∈ s)] : Decidable (a ∈ sᶜ) :=
inferInstanceAs (Decidable (a ∉ s))
instance decidableEmptyset : Decidable (a ∈ (∅ : Set α)) := Decidable.isFalse (by simp)
instance decidableUniv : Decidable (a ∈ univ) := Decidable.isTrue (by simp)
instance decidableInsert [Decidable (a = b)] [Decidable (a ∈ s)] : Decidable (a ∈ insert b s) :=
inferInstanceAs (Decidable (_ ∨ _))
instance decidableSetOf (p : α → Prop) [Decidable (p a)] : Decidable (a ∈ { a | p a }) := by
assumption
end Set
variable {α : Type*} {s t u : Set α}
namespace Equiv
/-- Given a predicate `p : α → Prop`, produces an equivalence between
`Set {a : α // p a}` and `{s : Set α // ∀ a ∈ s, p a}`. -/
protected def setSubtypeComm (p : α → Prop) :
Set {a : α // p a} ≃ {s : Set α // ∀ a ∈ s, p a} where
toFun s := ⟨{a | ∃ h : p a, s ⟨a, h⟩}, fun _ h ↦ h.1⟩
invFun s := {a | a.val ∈ s.val}
left_inv s := by ext a; exact ⟨fun h ↦ h.2, fun h ↦ ⟨a.property, h⟩⟩
right_inv s := by ext; exact ⟨fun h ↦ h.2, fun h ↦ ⟨s.property _ h, h⟩⟩
@[simp]
protected lemma setSubtypeComm_apply (p : α → Prop) (s : Set {a // p a}) :
(Equiv.setSubtypeComm p) s = ⟨{a | ∃ h : p a, ⟨a, h⟩ ∈ s}, fun _ h ↦ h.1⟩ :=
rfl
@[simp]
protected lemma setSubtypeComm_symm_apply (p : α → Prop) (s : {s // ∀ a ∈ s, p a}) :
(Equiv.setSubtypeComm p).symm s = {a | a.val ∈ s.val} :=
rfl
end Equiv
| Mathlib/Data/Set/Basic.lean | 1,499 | 1,499 | |
/-
Copyright (c) 2022 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
/-!
# Indicator function valued in bool
See also `Set.indicator` and `Set.piecewise`.
-/
assert_not_exists RelIso
open Bool
namespace Set
variable {α : Type*} (s : Set α)
/-- `boolIndicator` maps `x` to `true` if `x ∈ s`, else to `false` -/
noncomputable def boolIndicator (x : α) :=
@ite _ (x ∈ s) (Classical.propDecidable _) true false
theorem mem_iff_boolIndicator (x : α) : x ∈ s ↔ s.boolIndicator x = true := by
unfold boolIndicator
split_ifs with h <;> simp [h]
theorem not_mem_iff_boolIndicator (x : α) : x ∉ s ↔ s.boolIndicator x = false := by
unfold boolIndicator
| split_ifs with h <;> simp [h]
theorem preimage_boolIndicator_true : s.boolIndicator ⁻¹' {true} = s :=
| Mathlib/Data/Set/BoolIndicator.lean | 32 | 34 |
/-
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 | 1,573 | 1,577 | |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.BoxIntegral.DivergenceTheorem
import Mathlib.Analysis.BoxIntegral.Integrability
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Equiv
import Mathlib.MeasureTheory.Integral.Prod
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
/-!
# Divergence theorem for Bochner integral
In this file we prove the Divergence theorem for Bochner integral on a box in
`ℝⁿ⁺¹ = Fin (n + 1) → ℝ`. More precisely, we prove the following theorem.
Let `E` be a complete normed space. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is
continuous on a rectangular box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, differentiable on its interior with
derivative `f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹`, and the divergence `fun x ↦ ∑ i, f' x eᵢ i`
is integrable on `[a, b]`, where `eᵢ = Pi.single i 1` is the `i`-th basis vector,
then its integral is equal to the sum of integrals of `f` over the faces of `[a, b]`,
taken with appropriate signs. Moreover, the same
is true if the function is not differentiable at countably many points of the interior of `[a, b]`.
Once we prove the general theorem, we deduce corollaries for functions `ℝ → E` and pairs of
functions `(ℝ × ℝ) → E`.
## Notations
We use the following local notation to make the statement more readable. Note that the documentation
website shows the actual terms, not those abbreviated using local notations.
Porting note (Yury Kudryashov): I disabled some of these notations because I failed to make them
work with Lean 4.
* `ℝⁿ`, `ℝⁿ⁺¹`, `Eⁿ⁺¹`: `Fin n → ℝ`, `Fin (n + 1) → ℝ`, `Fin (n + 1) → E`;
* `face i`: the `i`-th face of the box `[a, b]` as a closed segment in `ℝⁿ`, namely
`[a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]`;
* `e i` : `i`-th basis vector `Pi.single i 1`;
* `frontFace i`, `backFace i`: embeddings `ℝⁿ → ℝⁿ⁺¹` corresponding to the front face
`{x | x i = b i}` and back face `{x | x i = a i}` of the box `[a, b]`, respectively.
They are given by `Fin.insertNth i (b i)` and `Fin.insertNth i (a i)`.
## TODO
* Add a version that assumes existence and integrability of partial derivatives.
* Restore local notations for find another way to make the statements more readable.
## Tags
divergence theorem, Bochner integral
-/
open Set Finset TopologicalSpace Function BoxIntegral MeasureTheory Filter
open scoped Topology Interval
universe u
namespace MeasureTheory
variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E]
section
variable {n : ℕ}
local macro:arg t:term:max noWs "ⁿ" : term => `(Fin n → $t)
local macro:arg t:term:max noWs "ⁿ⁺¹" : term => `(Fin (n + 1) → $t)
local notation "e " i => Pi.single i 1
section
/-!
### Divergence theorem for functions on `ℝⁿ⁺¹ = Fin (n + 1) → ℝ`.
In this section we use the divergence theorem for a Henstock-Kurzweil-like integral
`BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` to prove the divergence
theorem for Bochner integral. The divergence theorem for Bochner integral
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` assumes that the function
itself is continuous on a closed box, differentiable at all but countably many points of its
interior, and the divergence is integrable on the box.
This statement differs from `BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt`
in several aspects.
* We use Bochner integral instead of a Henstock-Kurzweil integral. This modification is done in
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁`. As a side effect
of this change, we need to assume that the divergence is integrable.
* We don't assume differentiability on the boundary of the box. This modification is done in
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂`. To prove it, we
choose an increasing sequence of smaller boxes that cover the interior of the original box, then
apply the previous lemma to these smaller boxes and take the limit of both sides of the equation.
* We assume `a ≤ b` instead of `∀ i, a i < b i`. This is the last step of the proof, and it is done
in the main theorem `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`.
-/
/-- An auxiliary lemma for
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. This is exactly
`BoxIntegral.hasIntegral_GP_divergence_of_forall_hasDerivWithinAt` reformulated for the
Bochner integral. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (I : Box (Fin (n + 1)))
(f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹) (s : Set ℝⁿ⁺¹)
(hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I))
(Hd : ∀ x ∈ (Box.Icc I) \ s, HasFDerivWithinAt f (f' x) (Box.Icc I) x)
(Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Box.Icc I)) :
(∫ x in Box.Icc I, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) -
∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by
wlog hE : CompleteSpace E generalizing
· simp [integral, hE]
simp only [← setIntegral_congr_set (Box.coe_ae_eq_Icc _)]
have A := (Hi.mono_set Box.coe_subset_Icc).hasBoxIntegral ⊥ rfl
have B :=
hasIntegral_GP_divergence_of_forall_hasDerivWithinAt I f f' (s ∩ Box.Icc I)
(hs.mono inter_subset_left) (fun x hx => Hc _ hx.2) fun x hx =>
Hd _ ⟨hx.1, fun h => hx.2 ⟨h, hx.1⟩⟩
rw [continuousOn_pi] at Hc
refine (A.unique B).trans (sum_congr rfl fun i _ => ?_)
refine congr_arg₂ Sub.sub ?_ ?_
· have := Box.continuousOn_face_Icc (Hc i) (Set.right_mem_Icc.2 (I.lower_le_upper i))
have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set
Box.coe_subset_Icc
exact (this.hasBoxIntegral ⊥ rfl).integral_eq
· have := Box.continuousOn_face_Icc (Hc i) (Set.left_mem_Icc.2 (I.lower_le_upper i))
have := (this.integrableOn_compact (μ := volume) (Box.isCompact_Icc _)).mono_set
Box.coe_subset_Icc
exact (this.hasBoxIntegral ⊥ rfl).integral_eq
/-- An auxiliary lemma for
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable`. Compared to the previous
lemma, here we drop the assumption of differentiability on the boundary of the box. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂ (I : Box (Fin (n + 1)))
(f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹)
(s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Box.Icc I))
(Hd : ∀ x ∈ Box.Ioo I \ s, HasFDerivAt f (f' x) x)
(Hi : IntegrableOn (∑ i, f' · (e i) i) (Box.Icc I)) :
(∫ x in Box.Icc I, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in Box.Icc (I.face i), f (i.insertNth (I.upper i) x) i) -
∫ x in Box.Icc (I.face i), f (i.insertNth (I.lower i) x) i) := by
/- Choose a monotone sequence `J k` of subboxes that cover the interior of `I` and prove that
these boxes satisfy the assumptions of the previous lemma. -/
rcases I.exists_seq_mono_tendsto with ⟨J, hJ_sub, hJl, hJu⟩
have hJ_sub' : ∀ k, Box.Icc (J k) ⊆ Box.Icc I := fun k => (hJ_sub k).trans I.Ioo_subset_Icc
have hJ_le : ∀ k, J k ≤ I := fun k => Box.le_iff_Icc.2 (hJ_sub' k)
have HcJ : ∀ k, ContinuousOn f (Box.Icc (J k)) := fun k => Hc.mono (hJ_sub' k)
have HdJ : ∀ (k), ∀ x ∈ (Box.Icc (J k)) \ s, HasFDerivWithinAt f (f' x) (Box.Icc (J k)) x :=
fun k x hx => (Hd x ⟨hJ_sub k hx.1, hx.2⟩).hasFDerivWithinAt
have HiJ : ∀ k, IntegrableOn (∑ i, f' · (e i) i) (Box.Icc (J k)) volume := fun k =>
Hi.mono_set (hJ_sub' k)
-- Apply the previous lemma to `J k`.
have HJ_eq := fun k =>
integral_divergence_of_hasFDerivWithinAt_off_countable_aux₁ (J k) f f' s hs (HcJ k) (HdJ k)
(HiJ k)
-- Note that the LHS of `HJ_eq k` tends to the LHS of the goal as `k → ∞`.
have hI_tendsto :
Tendsto (fun k => ∫ x in Box.Icc (J k), ∑ i, f' x (e i) i) atTop
(𝓝 (∫ x in Box.Icc I, ∑ i, f' x (e i) i)) := by
simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _)] at Hi ⊢
rw [← Box.iUnion_Ioo_of_tendsto J.monotone hJl hJu] at Hi ⊢
exact tendsto_setIntegral_of_monotone (fun k => (J k).measurableSet_Ioo)
(Box.Ioo.comp J).monotone Hi
-- Thus it suffices to prove the same about the RHS.
refine tendsto_nhds_unique_of_eventuallyEq hI_tendsto ?_ (Eventually.of_forall HJ_eq)
clear hI_tendsto
rw [tendsto_pi_nhds] at hJl hJu
/- We'll need to prove a similar statement about the integrals over the front sides and the
integrals over the back sides. In order to avoid repeating ourselves, we formulate a lemma. -/
suffices ∀ (i : Fin (n + 1)) (c : ℕ → ℝ) (d), (∀ k, c k ∈ Icc (I.lower i) (I.upper i)) →
Tendsto c atTop (𝓝 d) →
Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth (c k) x) i) atTop
(𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) by
rw [Box.Icc_eq_pi] at hJ_sub'
refine tendsto_finset_sum _ fun i _ => (this _ _ _ ?_ (hJu _)).sub (this _ _ _ ?_ (hJl _))
exacts [fun k => hJ_sub' k (J k).upper_mem_Icc _ trivial, fun k =>
hJ_sub' k (J k).lower_mem_Icc _ trivial]
intro i c d hc hcd
/- First we prove that the integrals of the restriction of `f` to `{x | x i = d}` over increasing
boxes `((J k).face i).Icc` tend to the desired limit. The proof mostly repeats the one above. -/
have hd : d ∈ Icc (I.lower i) (I.upper i) :=
isClosed_Icc.mem_of_tendsto hcd (Eventually.of_forall hc)
have Hic : ∀ k, IntegrableOn (fun x => f (i.insertNth (c k) x) i) (Box.Icc (I.face i)) := fun k =>
(Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) (hc k)).integrableOn_Icc
have Hid : IntegrableOn (fun x => f (i.insertNth d x) i) (Box.Icc (I.face i)) :=
(Box.continuousOn_face_Icc ((continuous_apply i).comp_continuousOn Hc) hd).integrableOn_Icc
have H :
Tendsto (fun k => ∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i) atTop
(𝓝 <| ∫ x in Box.Icc (I.face i), f (i.insertNth d x) i) := by
have hIoo : (⋃ k, Box.Ioo ((J k).face i)) = Box.Ioo (I.face i) :=
Box.iUnion_Ioo_of_tendsto ((Box.monotone_face i).comp J.monotone)
(tendsto_pi_nhds.2 fun _ => hJl _) (tendsto_pi_nhds.2 fun _ => hJu _)
simp only [IntegrableOn, ← Measure.restrict_congr_set (Box.Ioo_ae_eq_Icc _), ← hIoo] at Hid ⊢
exact tendsto_setIntegral_of_monotone (fun k => ((J k).face i).measurableSet_Ioo)
(Box.Ioo.monotone.comp ((Box.monotone_face i).comp J.monotone)) Hid
/- Thus it suffices to show that the distance between the integrals of the restrictions of `f` to
`{x | x i = c k}` and `{x | x i = d}` over `((J k).face i).Icc` tends to zero as `k → ∞`. Choose
`ε > 0`. -/
refine H.congr_dist (Metric.nhds_basis_closedBall.tendsto_right_iff.2 fun ε εpos => ?_)
have hvol_pos : ∀ J : Box (Fin n), 0 < ∏ j, (J.upper j - J.lower j) := fun J =>
prod_pos fun j hj => sub_pos.2 <| J.lower_lt_upper _
/- Choose `δ > 0` such that for any `x y ∈ I.Icc` at distance at most `δ`, the distance between
`f x` and `f y` is at most `ε / volume (I.face i).Icc`, then the distance between the integrals
is at most `(ε / volume (I.face i).Icc) * volume ((J k).face i).Icc ≤ ε`. -/
rcases Metric.uniformContinuousOn_iff_le.1 (I.isCompact_Icc.uniformContinuousOn_of_continuous Hc)
(ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) (div_pos εpos (hvol_pos (I.face i)))
with ⟨δ, δpos, hδ⟩
refine (hcd.eventually (Metric.ball_mem_nhds _ δpos)).mono fun k hk => ?_
have Hsub : Box.Icc ((J k).face i) ⊆ Box.Icc (I.face i) :=
Box.le_iff_Icc.1 (Box.face_mono (hJ_le _) i)
rw [mem_closedBall_zero_iff, Real.norm_eq_abs, abs_of_nonneg dist_nonneg, dist_eq_norm,
← integral_sub (Hid.mono_set Hsub) ((Hic _).mono_set Hsub)]
calc
‖∫ x in Box.Icc ((J k).face i), f (i.insertNth d x) i - f (i.insertNth (c k) x) i‖ ≤
(ε / ∏ j, ((I.face i).upper j - (I.face i).lower j)) *
(volume (Box.Icc ((J k).face i))).toReal := by
refine norm_setIntegral_le_of_norm_le_const (((J k).face i).measure_Icc_lt_top _)
fun x hx => ?_
rw [← dist_eq_norm]
calc
dist (f (i.insertNth d x) i) (f (i.insertNth (c k) x) i) ≤
dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) :=
dist_le_pi_dist (f (i.insertNth d x)) (f (i.insertNth (c k) x)) i
_ ≤ ε / ∏ j, ((I.face i).upper j - (I.face i).lower j) :=
hδ _ (I.mapsTo_insertNth_face_Icc hd <| Hsub hx) _
(I.mapsTo_insertNth_face_Icc (hc _) <| Hsub hx) ?_
rw [Fin.dist_insertNth_insertNth, dist_self, dist_comm]
exact max_le hk.le δpos.lt.le
_ ≤ ε := by
rw [Box.Icc_def, Real.volume_Icc_pi_toReal ((J k).face i).lower_le_upper,
← le_div_iff₀ (hvol_pos _)]
gcongr
exacts [hvol_pos _, fun _ _ ↦ sub_nonneg.2 (Box.lower_le_upper _ _),
(hJ_sub' _ (J _).upper_mem_Icc).2 _, (hJ_sub' _ (J _).lower_mem_Icc).1 _]
variable (a b : Fin (n + 1) → ℝ)
local notation "face " i => Set.Icc (a ∘ Fin.succAbove i) (b ∘ Fin.succAbove i)
local notation:max "frontFace " i:arg => Fin.insertNth i (b i)
local notation:max "backFace " i:arg => Fin.insertNth i (a i)
/-- **Divergence theorem** for Bochner integral. If `f : ℝⁿ⁺¹ → Eⁿ⁺¹` is continuous on a rectangular
box `[a, b] : Set ℝⁿ⁺¹`, `a ≤ b`, is differentiable on its interior with derivative
`f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹` and the divergence `fun x ↦ ∑ i, f' x eᵢ i` is integrable on `[a, b]`,
where `eᵢ = Pi.single i 1` is the `i`-th basis vector, then its integral is equal to the sum of
integrals of `f` over the faces of `[a, b]`, taken with appropriate signs.
Moreover, the same is true if the function is not differentiable at countably many
points of the interior of `[a, b]`.
We represent both faces `x i = a i` and `x i = b i` as the box
`face i = [a ∘ Fin.succAbove i, b ∘ Fin.succAbove i]` in `ℝⁿ`, where
`Fin.succAbove : Fin n ↪o Fin (n + 1)` is the order embedding with range `{i}ᶜ`. The restrictions
of `f : ℝⁿ⁺¹ → Eⁿ⁺¹` to these faces are given by `f ∘ backFace i` and `f ∘ frontFace i`, where
`backFace i = Fin.insertNth i (a i)` and `frontFace i = Fin.insertNth i (b i)` are embeddings
`ℝⁿ → ℝⁿ⁺¹` that take `y : ℝⁿ` and insert `a i` (resp., `b i`) as `i`-th coordinate. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable (hle : a ≤ b)
(f : ℝⁿ⁺¹ → Eⁿ⁺¹)
(f' : ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] Eⁿ⁺¹)
(s : Set ℝⁿ⁺¹) (hs : s.Countable) (Hc : ContinuousOn f (Icc a b))
(Hd : ∀ x ∈ (Set.pi univ fun i => Ioo (a i) (b i)) \ s, HasFDerivAt f (f' x) x)
(Hi : IntegrableOn (fun x => ∑ i, f' x (e i) i) (Icc a b)) :
(∫ x in Icc a b, ∑ i, f' x (e i) i) =
∑ i : Fin (n + 1),
((∫ x in face i, f (frontFace i x) i) - ∫ x in face i, f (backFace i x) i) := by
rcases em (∃ i, a i = b i) with (⟨i, hi⟩ | hne)
· -- First we sort out the trivial case `∃ i, a i = b i`.
rw [volume_pi, ← setIntegral_congr_set Measure.univ_pi_Ioc_ae_eq_Icc]
have hi' : Ioc (a i) (b i) = ∅ := Ioc_eq_empty hi.not_lt
have : (pi Set.univ fun j => Ioc (a j) (b j)) = ∅ := univ_pi_eq_empty hi'
rw [this, setIntegral_empty, sum_eq_zero]
rintro j -
rcases eq_or_ne i j with (rfl | hne)
· simp [hi]
· rcases Fin.exists_succAbove_eq hne with ⟨i, rfl⟩
have : Icc (a ∘ j.succAbove) (b ∘ j.succAbove) =ᵐ[volume] (∅ : Set ℝⁿ) := by
rw [ae_eq_empty, Real.volume_Icc_pi, prod_eq_zero (Finset.mem_univ i)]
simp [hi]
rw [setIntegral_congr_set this, setIntegral_congr_set this, setIntegral_empty,
setIntegral_empty, sub_self]
· -- In the non-trivial case `∀ i, a i < b i`, we apply a lemma we proved above.
have hlt : ∀ i, a i < b i := fun i => (hle i).lt_of_ne fun hi => hne ⟨i, hi⟩
exact integral_divergence_of_hasFDerivWithinAt_off_countable_aux₂ ⟨a, b, hlt⟩ f f' s hs Hc
Hd Hi
/-- **Divergence theorem** for a family of functions `f : Fin (n + 1) → ℝⁿ⁺¹ → E`. See also
`MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable'` for a version formulated
in terms of a vector-valued function `f : ℝⁿ⁺¹ → Eⁿ⁺¹`. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable' (hle : a ≤ b)
(f : Fin (n + 1) → ℝⁿ⁺¹ → E)
(f' : Fin (n + 1) → ℝⁿ⁺¹ → ℝⁿ⁺¹ →L[ℝ] E) (s : Set ℝⁿ⁺¹)
(hs : s.Countable) (Hc : ∀ i, ContinuousOn (f i) (Icc a b))
(Hd : ∀ x ∈ (pi Set.univ fun i => Ioo (a i) (b i)) \ s, ∀ (i), HasFDerivAt (f i) (f' i x) x)
(Hi : IntegrableOn (fun x => ∑ i, f' i x (e i)) (Icc a b)) :
(∫ x in Icc a b, ∑ i, f' i x (e i)) =
∑ i : Fin (n + 1), ((∫ x in face i, f i (frontFace i x)) -
∫ x in face i, f i (backFace i x)) :=
integral_divergence_of_hasFDerivWithinAt_off_countable a b hle (fun x i => f i x)
(fun x => ContinuousLinearMap.pi fun i => f' i x) s hs (continuousOn_pi.2 Hc)
(fun x hx => hasFDerivAt_pi.2 (Hd x hx)) Hi
end
/-- An auxiliary lemma that is used to specialize the general divergence theorem to spaces that do
not have the form `Fin n → ℝ`. -/
theorem integral_divergence_of_hasFDerivWithinAt_off_countable_of_equiv {F : Type*}
[NormedAddCommGroup F] [NormedSpace ℝ F] [Preorder F] [MeasureSpace F] [BorelSpace F]
(eL : F ≃L[ℝ] ℝⁿ⁺¹) (he_ord : ∀ x y, eL x ≤ eL y ↔ x ≤ y)
(he_vol : MeasurePreserving eL volume volume) (f : Fin (n + 1) → F → E)
(f' : Fin (n + 1) → F → F →L[ℝ] E) (s : Set F) (hs : s.Countable) (a b : F) (hle : a ≤ b)
(Hc : ∀ i, ContinuousOn (f i) (Icc a b))
(Hd : ∀ x ∈ interior (Icc a b) \ s, ∀ (i), HasFDerivAt (f i) (f' i x) x) (DF : F → E)
(hDF : ∀ x, DF x = ∑ i, f' i x (eL.symm <| e i)) (Hi : IntegrableOn DF (Icc a b)) :
∫ x in Icc a b, DF x =
∑ i : Fin (n + 1),
((∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL b i) x)) -
∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL a i) x)) :=
have he_emb : MeasurableEmbedding eL := eL.toHomeomorph.measurableEmbedding
have hIcc : eL ⁻¹' Icc (eL a) (eL b) = Icc a b := by
ext1 x; simp only [Set.mem_preimage, Set.mem_Icc, he_ord]
have hIcc' : Icc (eL a) (eL b) = eL.symm ⁻¹' Icc a b := by rw [← hIcc, eL.symm_preimage_preimage]
calc
∫ x in Icc a b, DF x = ∫ x in Icc a b, ∑ i, f' i x (eL.symm <| e i) := by simp only [hDF]
_ = ∫ x in Icc (eL a) (eL b), ∑ i, f' i (eL.symm x) (eL.symm <| e i) := by
rw [← he_vol.setIntegral_preimage_emb he_emb]
simp only [hIcc, eL.symm_apply_apply]
_ = ∑ i : Fin (n + 1),
((∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL b i) x)) -
∫ x in Icc (eL a ∘ i.succAbove) (eL b ∘ i.succAbove),
f i (eL.symm <| i.insertNth (eL a i) x)) := by
refine integral_divergence_of_hasFDerivWithinAt_off_countable' (eL a) (eL b)
((he_ord _ _).2 hle) (fun i x => f i (eL.symm x))
(fun i x => f' i (eL.symm x) ∘L (eL.symm : ℝⁿ⁺¹ →L[ℝ] F)) (eL.symm ⁻¹' s)
(hs.preimage eL.symm.injective) ?_ ?_ ?_
· exact fun i => (Hc i).comp eL.symm.continuousOn hIcc'.subset
· refine fun x hx i => (Hd (eL.symm x) ⟨?_, hx.2⟩ i).comp x eL.symm.hasFDerivAt
rw [← hIcc]
refine preimage_interior_subset_interior_preimage eL.continuous ?_
simpa only [Set.mem_preimage, eL.apply_symm_apply, ← pi_univ_Icc,
interior_pi_set (@finite_univ (Fin _) _), interior_Icc] using hx.1
· rw [← he_vol.integrableOn_comp_preimage he_emb, hIcc]
simp [← hDF, Function.comp_def, Hi]
end
open scoped Interval
open ContinuousLinearMap (smulRight)
local macro:arg t:term:max noWs "¹" : term => `(Fin 1 → $t)
local macro:arg t:term:max noWs "²" : term => `(Fin 2 → $t)
/-- **Fundamental theorem of calculus, part 2**. This version assumes that `f` is continuous on the
interval and is differentiable off a countable set `s`.
See also
* `intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le` for a version that only assumes right
differentiability of `f`;
* `MeasureTheory.integral_eq_of_hasDerivWithinAt_off_countable` for a version that works both
for `a ≤ b` and `b ≤ a` at the expense of using unordered intervals instead of `Set.Icc`. -/
theorem integral_eq_of_hasDerivWithinAt_off_countable_of_le [CompleteSpace E] (f f' : ℝ → E)
{a b : ℝ} (hle : a ≤ b) {s : Set ℝ} (hs : s.Countable) (Hc : ContinuousOn f (Icc a b))
(Hd : ∀ x ∈ Ioo a b \ s, HasDerivAt f (f' x) x) (Hi : IntervalIntegrable f' volume a b) :
∫ x in a..b, f' x = f b - f a := by
set e : ℝ ≃L[ℝ] ℝ¹ := (ContinuousLinearEquiv.funUnique (Fin 1) ℝ ℝ).symm
have e_symm : ∀ x, e.symm x = x 0 := fun x => rfl
set F' : ℝ → ℝ →L[ℝ] E := fun x => smulRight (1 : ℝ →L[ℝ] ℝ) (f' x)
have hF' : ∀ x y, F' x y = y • f' x := fun x y => rfl
calc
∫ x in a..b, f' x = ∫ x in Icc a b, f' x := by
rw [intervalIntegral.integral_of_le hle, setIntegral_congr_set Ioc_ae_eq_Icc]
_ = ∑ i : Fin 1,
((∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
f (e.symm <| i.insertNth (e b i) x)) -
∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
f (e.symm <| i.insertNth (e a i) x)) := by
simp only [← interior_Icc] at Hd
refine
integral_divergence_of_hasFDerivWithinAt_off_countable_of_equiv e ?_ ?_ (fun _ => f)
(fun _ => F') s hs a b hle (fun _ => Hc) (fun x hx _ => Hd x hx) _ ?_ ?_
· exact fun x y => (OrderIso.funUnique (Fin 1) ℝ).symm.le_iff_le
· exact (volume_preserving_funUnique (Fin 1) ℝ).symm _
· intro x; rw [Fin.sum_univ_one, hF', e_symm, Pi.single_eq_same, one_smul]
· rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hle] at Hi
exact Hi.congr_set_ae Ioc_ae_eq_Icc.symm
_ = f b - f a := by
simp only [e, Fin.sum_univ_one, e_symm]
have : ∀ c : ℝ, const (Fin 0) c = isEmptyElim := fun c => Subsingleton.elim _ _
simp [this, volume_pi, Measure.pi_of_empty fun _ : Fin 0 => volume]
/-- **Fundamental theorem of calculus, part 2**. This version assumes that `f` is continuous on the
interval and is differentiable off a countable set `s`.
See also `intervalIntegral.integral_eq_sub_of_hasDeriv_right` for a version that
only assumes right differentiability of `f`.
-/
theorem integral_eq_of_hasDerivWithinAt_off_countable [CompleteSpace E] (f f' : ℝ → E) {a b : ℝ}
{s : Set ℝ} (hs : s.Countable) (Hc : ContinuousOn f [[a, b]])
(Hd : ∀ x ∈ Ioo (min a b) (max a b) \ s, HasDerivAt f (f' x) x)
(Hi : IntervalIntegrable f' volume a b) : ∫ x in a..b, f' x = f b - f a := by
rcases le_total a b with hab | hab
· simp only [uIcc_of_le hab, min_eq_left hab, max_eq_right hab] at *
exact integral_eq_of_hasDerivWithinAt_off_countable_of_le f f' hab hs Hc Hd Hi
· simp only [uIcc_of_ge hab, min_eq_right hab, max_eq_left hab] at *
rw [intervalIntegral.integral_symm, neg_eq_iff_eq_neg, neg_sub]
exact integral_eq_of_hasDerivWithinAt_off_countable_of_le f f' hab hs Hc Hd Hi.symm
/-- **Divergence theorem** for functions on the plane along rectangles. It is formulated in terms of
two functions `f g : ℝ × ℝ → E` and an integral over `Icc a b = [a.1, b.1] × [a.2, b.2]`, where
`a b : ℝ × ℝ`, `a ≤ b`. When thinking of `f` and `g` as the two coordinates of a single function
`F : ℝ × ℝ → E × E` and when `E = ℝ`, this is the usual statement that the integral of the
divergence of `F` inside the rectangle equals the integral of the normal derivative of `F` along the
boundary.
See also `MeasureTheory.integral2_divergence_prod_of_hasFDerivWithinAt_off_countable` for a
version that does not assume `a ≤ b` and uses iterated interval integral instead of the integral
over `Icc a b`. -/
theorem integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le (f g : ℝ × ℝ → E)
(f' g' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E) (a b : ℝ × ℝ) (hle : a ≤ b) (s : Set (ℝ × ℝ)) (hs : s.Countable)
(Hcf : ContinuousOn f (Icc a b)) (Hcg : ContinuousOn g (Icc a b))
(Hdf : ∀ x ∈ Ioo a.1 b.1 ×ˢ Ioo a.2 b.2 \ s, HasFDerivAt f (f' x) x)
(Hdg : ∀ x ∈ Ioo a.1 b.1 ×ˢ Ioo a.2 b.2 \ s, HasFDerivAt g (g' x) x)
(Hi : IntegrableOn (fun x => f' x (1, 0) + g' x (0, 1)) (Icc a b)) :
(∫ x in Icc a b, f' x (1, 0) + g' x (0, 1)) =
(((∫ x in a.1..b.1, g (x, b.2)) - ∫ x in a.1..b.1, g (x, a.2)) +
∫ y in a.2..b.2, f (b.1, y)) -
∫ y in a.2..b.2, f (a.1, y) :=
let e : (ℝ × ℝ) ≃L[ℝ] ℝ² := (ContinuousLinearEquiv.finTwoArrow ℝ ℝ).symm
calc
(∫ x in Icc a b, f' x (1, 0) + g' x (0, 1)) =
∑ i : Fin 2,
((∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
![f, g] i (e.symm <| i.insertNth (e b i) x)) -
∫ x in Icc (e a ∘ i.succAbove) (e b ∘ i.succAbove),
![f, g] i (e.symm <| i.insertNth (e a i) x)) := by
refine integral_divergence_of_hasFDerivWithinAt_off_countable_of_equiv e ?_ ?_ ![f, g]
![f', g'] s hs a b hle ?_ (fun x hx => ?_) _ ?_ Hi
· exact fun x y => (OrderIso.finTwoArrowIso ℝ).symm.le_iff_le
· exact (volume_preserving_finTwoArrow ℝ).symm _
· exact Fin.forall_fin_two.2 ⟨Hcf, Hcg⟩
· rw [Icc_prod_eq, interior_prod_eq, interior_Icc, interior_Icc] at hx
exact Fin.forall_fin_two.2 ⟨Hdf x hx, Hdg x hx⟩
· intro x; rw [Fin.sum_univ_two]; rfl
_ = ((∫ y in Icc a.2 b.2, f (b.1, y)) - ∫ y in Icc a.2 b.2, f (a.1, y)) +
((∫ x in Icc a.1 b.1, g (x, b.2)) - ∫ x in Icc a.1 b.1, g (x, a.2)) := by
have : ∀ (a b : ℝ¹) (f : ℝ¹ → E),
∫ x in Icc a b, f x = ∫ x in Icc (a 0) (b 0), f fun _ => x := fun a b f ↦ by
convert (((volume_preserving_funUnique (Fin 1) ℝ).symm _).setIntegral_preimage_emb
(MeasurableEquiv.measurableEmbedding _) f _).symm
exact ((OrderIso.funUnique (Fin 1) ℝ).symm.preimage_Icc a b).symm
simp only [Fin.sum_univ_two, this]
rfl
_ = (((∫ x in a.1..b.1, g (x, b.2)) - ∫ x in a.1..b.1, g (x, a.2)) +
∫ y in a.2..b.2, f (b.1, y)) - ∫ y in a.2..b.2, f (a.1, y) := by
simp only [intervalIntegral.integral_of_le hle.1, intervalIntegral.integral_of_le hle.2,
setIntegral_congr_set (Ioc_ae_eq_Icc (α := ℝ) (μ := volume))]
abel
/-- **Divergence theorem** for functions on the plane. It is formulated in terms of two functions
`f g : ℝ × ℝ → E` and iterated integral `∫ x in a₁..b₁, ∫ y in a₂..b₂, _`, where
`a₁ a₂ b₁ b₂ : ℝ`. When thinking of `f` and `g` as the two coordinates of a single function
`F : ℝ × ℝ → E × E` and when `E = ℝ`, this is the usual statement that the integral of the
divergence of `F` inside the rectangle with vertices `(aᵢ, bⱼ)`, `i, j =1,2`, equals the integral of
the normal derivative of `F` along the boundary.
See also `MeasureTheory.integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le`
for a version that uses an integral over `Icc a b`, where `a b : ℝ × ℝ`, `a ≤ b`. -/
theorem integral2_divergence_prod_of_hasFDerivWithinAt_off_countable (f g : ℝ × ℝ → E)
(f' g' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E) (a₁ a₂ b₁ b₂ : ℝ) (s : Set (ℝ × ℝ)) (hs : s.Countable)
(Hcf : ContinuousOn f ([[a₁, b₁]] ×ˢ [[a₂, b₂]]))
(Hcg : ContinuousOn g ([[a₁, b₁]] ×ˢ [[a₂, b₂]]))
(Hdf : ∀ x ∈ Ioo (min a₁ b₁) (max a₁ b₁) ×ˢ Ioo (min a₂ b₂) (max a₂ b₂) \ s,
HasFDerivAt f (f' x) x)
(Hdg : ∀ x ∈ Ioo (min a₁ b₁) (max a₁ b₁) ×ˢ Ioo (min a₂ b₂) (max a₂ b₂) \ s,
HasFDerivAt g (g' x) x)
| (Hi : IntegrableOn (fun x => f' x (1, 0) + g' x (0, 1)) ([[a₁, b₁]] ×ˢ [[a₂, b₂]])) :
(∫ x in a₁..b₁, ∫ y in a₂..b₂, f' (x, y) (1, 0) + g' (x, y) (0, 1)) =
(((∫ x in a₁..b₁, g (x, b₂)) - ∫ x in a₁..b₁, g (x, a₂)) + ∫ y in a₂..b₂, f (b₁, y)) -
∫ y in a₂..b₂, f (a₁, y) := by
wlog h₁ : a₁ ≤ b₁ generalizing a₁ b₁
· specialize this b₁ a₁
rw [uIcc_comm b₁ a₁, min_comm b₁ a₁, max_comm b₁ a₁] at this
simp only [intervalIntegral.integral_symm b₁ a₁]
refine (congr_arg Neg.neg (this Hcf Hcg Hdf Hdg Hi (le_of_not_le h₁))).trans ?_; abel
wlog h₂ : a₂ ≤ b₂ generalizing a₂ b₂
· specialize this b₂ a₂
rw [uIcc_comm b₂ a₂, min_comm b₂ a₂, max_comm b₂ a₂] at this
simp only [intervalIntegral.integral_symm b₂ a₂, intervalIntegral.integral_neg]
refine (congr_arg Neg.neg (this Hcf Hcg Hdf Hdg Hi (le_of_not_le h₂))).trans ?_; abel
simp only [uIcc_of_le h₁, uIcc_of_le h₂, min_eq_left, max_eq_right, h₁, h₂] at Hcf Hcg Hdf Hdg Hi
calc
(∫ x in a₁..b₁, ∫ y in a₂..b₂, f' (x, y) (1, 0) + g' (x, y) (0, 1)) =
∫ x in Icc a₁ b₁, ∫ y in Icc a₂ b₂, f' (x, y) (1, 0) + g' (x, y) (0, 1) := by
simp only [intervalIntegral.integral_of_le, h₁, h₂,
setIntegral_congr_set (Ioc_ae_eq_Icc (α := ℝ) (μ := volume))]
_ = ∫ x in Icc a₁ b₁ ×ˢ Icc a₂ b₂, f' x (1, 0) + g' x (0, 1) := (setIntegral_prod _ Hi).symm
_ = (((∫ x in a₁..b₁, g (x, b₂)) - ∫ x in a₁..b₁, g (x, a₂)) + ∫ y in a₂..b₂, f (b₁, y)) -
∫ y in a₂..b₂, f (a₁, y) := by
rw [Icc_prod_Icc] at *
apply integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le f g f' g'
(a₁, a₂) (b₁, b₂) ⟨h₁, h₂⟩ s <;> assumption
end MeasureTheory
| Mathlib/MeasureTheory/Integral/DivergenceTheorem.lean | 492 | 525 |
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Continuity
import Mathlib.Topology.Algebra.IsUniformGroup.Basic
import Mathlib.Topology.MetricSpace.Algebra
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Normed groups are uniform groups
This file proves lipschitzness of normed group operations and shows that normed groups are uniform
groups.
-/
variable {𝓕 E F : Type*}
open Filter Function Metric Bornology
open scoped ENNReal NNReal Uniformity Pointwise Topology
section SeminormedGroup
variable [SeminormedGroup E] [SeminormedGroup F] {s : Set E} {a b : E} {r : ℝ}
@[to_additive]
instance NormedGroup.to_isIsometricSMul_right : IsIsometricSMul Eᵐᵒᵖ E :=
⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩
@[to_additive]
theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) :
‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right]
@[to_additive (attr := simp)]
theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by
rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul]
@[to_additive (attr := simp)]
theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by
rw [dist_comm, dist_mul_self_right]
@[to_additive (attr := simp)]
theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by
rw [← dist_mul_right _ _ b, div_mul_cancel]
@[to_additive (attr := simp)]
theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by
rw [← dist_mul_right _ _ c, div_mul_cancel]
open Finset
variable [FunLike 𝓕 E F]
/-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that
for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of
(semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/
@[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant
`C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of
(semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."]
theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f :=
LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive]
theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} :
LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by
simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div]
alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le
attribute [to_additive] LipschitzOnWith.norm_div_le
@[to_additive]
theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s)
(ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r :=
(h.norm_div_le ha hb).trans <| by gcongr
@[to_additive]
theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} :
LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by
simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div]
alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le
attribute [to_additive] LipschitzWith.norm_div_le
@[to_additive]
theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f)
(hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r :=
(h.norm_div_le _ _).trans <| by gcongr
/-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that
for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/
@[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C`
such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"]
theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f :=
(MonoidHomClass.lipschitz_of_bound f C h).continuous
@[to_additive]
theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f :=
(MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous
@[to_additive]
theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) :
Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by
simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div]
refine ⟨fun h x => ?_, fun h x y => h _⟩
simpa using h x 1
alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm
attribute [to_additive] MonoidHomClass.isometry_of_norm
section NNNorm
@[to_additive]
theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0)
(h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f :=
@Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h
@[to_additive]
theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0}
(h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f :=
AntilipschitzWith.of_le_mul_dist fun x y => by
simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive LipschitzWith.norm_le_mul]
theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1)
(x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1
@[to_additive LipschitzWith.nnorm_le_mul]
theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1)
(x) : ‖f x‖₊ ≤ K * ‖x‖₊ :=
h.norm_le_mul' hf x
@[to_additive AntilipschitzWith.le_mul_norm]
theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f)
(hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by
simpa only [dist_one_right, hf] using h.le_mul_dist x 1
@[to_additive AntilipschitzWith.le_mul_nnnorm]
theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f)
(hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ :=
h.le_mul_norm' hf x
@[to_additive]
theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0}
(h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ :=
h.le_mul_nnnorm' (map_one f) x
@[to_additive]
theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) :
‖f x‖₊ = ‖x‖₊ :=
Subtype.ext <| hi.norm_map_of_map_one h₁ x
end NNNorm
@[to_additive lipschitzWith_one_norm]
theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by
simpa using LipschitzWith.dist_right (1 : E)
@[to_additive lipschitzWith_one_nnnorm]
theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) :=
lipschitzWith_one_norm'
@[to_additive uniformContinuous_norm]
theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) :=
lipschitzWith_one_norm'.uniformContinuous
@[to_additive uniformContinuous_nnnorm]
theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ :=
uniformContinuous_norm'.subtype_mk _
end SeminormedGroup
section SeminormedCommGroup
variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a₁ a₂ b₁ b₂ : E} {r₁ r₂ : ℝ}
@[to_additive]
instance NormedGroup.to_isIsometricSMul_left : IsIsometricSMul E E :=
⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩
@[to_additive (attr := simp)]
theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by
rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one]
@[to_additive (attr := simp)]
theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by
rw [dist_comm, dist_self_mul_right]
@[to_additive (attr := simp 1001)] -- Increase priority because `simp` can prove this
theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by
rw [div_eq_mul_inv, dist_self_mul_right, norm_inv']
@[to_additive (attr := simp 1001)] -- Increase priority because `simp` can prove this
theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by
rw [dist_comm, dist_self_div_right]
@[to_additive]
theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by
simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂)
@[to_additive]
theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) :
dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ :=
(dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂
@[to_additive]
theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by
simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹
@[to_additive]
theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) :
dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ :=
(dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂
@[to_additive]
theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) :
|dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by
simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using
abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂)
open Finset
@[to_additive]
theorem nndist_mul_mul_le (a₁ a₂ b₁ b₂ : E) :
nndist (a₁ * a₂) (b₁ * b₂) ≤ nndist a₁ b₁ + nndist a₂ b₂ :=
NNReal.coe_le_coe.1 <| dist_mul_mul_le a₁ a₂ b₁ b₂
@[to_additive]
theorem edist_mul_mul_le (a₁ a₂ b₁ b₂ : E) :
edist (a₁ * a₂) (b₁ * b₂) ≤ edist a₁ b₁ + edist a₂ b₂ := by
simp only [edist_nndist]
norm_cast
apply nndist_mul_mul_le
section PseudoEMetricSpace
variable {α E : Type*} [SeminormedCommGroup E] [PseudoEMetricSpace α] {K Kf Kg : ℝ≥0}
{f g : α → E} {s : Set α}
@[to_additive (attr := simp)]
lemma lipschitzWith_inv_iff : LipschitzWith K f⁻¹ ↔ LipschitzWith K f := by simp [LipschitzWith]
@[to_additive (attr := simp)]
lemma antilipschitzWith_inv_iff : AntilipschitzWith K f⁻¹ ↔ AntilipschitzWith K f := by
simp [AntilipschitzWith]
@[to_additive (attr := simp)]
lemma lipschitzOnWith_inv_iff : LipschitzOnWith K f⁻¹ s ↔ LipschitzOnWith K f s := by
simp [LipschitzOnWith]
@[to_additive (attr := simp)]
lemma locallyLipschitz_inv_iff : LocallyLipschitz f⁻¹ ↔ LocallyLipschitz f := by
simp [LocallyLipschitz]
@[to_additive (attr := simp)]
lemma locallyLipschitzOn_inv_iff : LocallyLipschitzOn s f⁻¹ ↔ LocallyLipschitzOn s f := by
simp [LocallyLipschitzOn]
@[to_additive] alias ⟨LipschitzWith.of_inv, LipschitzWith.inv⟩ := lipschitzWith_inv_iff
@[to_additive] alias ⟨AntilipschitzWith.of_inv, AntilipschitzWith.inv⟩ := antilipschitzWith_inv_iff
@[to_additive] alias ⟨LipschitzOnWith.of_inv, LipschitzOnWith.inv⟩ := lipschitzOnWith_inv_iff
@[to_additive] alias ⟨LocallyLipschitz.of_inv, LocallyLipschitz.inv⟩ := locallyLipschitz_inv_iff
@[to_additive]
alias ⟨LocallyLipschitzOn.of_inv, LocallyLipschitzOn.inv⟩ := locallyLipschitzOn_inv_iff
@[to_additive]
lemma LipschitzOnWith.mul (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) :
LipschitzOnWith (Kf + Kg) (fun x ↦ f x * g x) s := fun x hx y hy ↦
calc
edist (f x * g x) (f y * g y) ≤ edist (f x) (f y) + edist (g x) (g y) :=
edist_mul_mul_le _ _ _ _
_ ≤ Kf * edist x y + Kg * edist x y := add_le_add (hf hx hy) (hg hx hy)
_ = (Kf + Kg) * edist x y := (add_mul _ _ _).symm
@[to_additive]
lemma LipschitzWith.mul (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (Kf + Kg) fun x ↦ f x * g x := by
simpa [← lipschitzOnWith_univ] using hf.lipschitzOnWith.mul hg.lipschitzOnWith
@[to_additive]
lemma LocallyLipschitzOn.mul (hf : LocallyLipschitzOn s f) (hg : LocallyLipschitzOn s g) :
LocallyLipschitzOn s fun x ↦ f x * g x := fun x hx ↦ by
obtain ⟨Kf, t, ht, hKf⟩ := hf hx
obtain ⟨Kg, u, hu, hKg⟩ := hg hx
exact ⟨Kf + Kg, t ∩ u, inter_mem ht hu,
(hKf.mono Set.inter_subset_left).mul (hKg.mono Set.inter_subset_right)⟩
@[to_additive]
lemma LocallyLipschitz.mul (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz fun x ↦ f x * g x := by
simpa [← locallyLipschitzOn_univ] using hf.locallyLipschitzOn.mul hg.locallyLipschitzOn
@[to_additive]
lemma LipschitzOnWith.div (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) :
LipschitzOnWith (Kf + Kg) (fun x ↦ f x / g x) s := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
theorem LipschitzWith.div (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (Kf + Kg) fun x => f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
lemma LocallyLipschitzOn.div (hf : LocallyLipschitzOn s f) (hg : LocallyLipschitzOn s g) :
LocallyLipschitzOn s fun x ↦ f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
lemma LocallyLipschitz.div (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz fun x ↦ f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
namespace AntilipschitzWith
@[to_additive]
theorem mul_lipschitzWith (hf : AntilipschitzWith Kf f) (hg : LipschitzWith Kg g) (hK : Kg < Kf⁻¹) :
AntilipschitzWith (Kf⁻¹ - Kg)⁻¹ fun x => f x * g x := by
letI : PseudoMetricSpace α := PseudoEMetricSpace.toPseudoMetricSpace hf.edist_ne_top
refine AntilipschitzWith.of_le_mul_dist fun x y => ?_
rw [NNReal.coe_inv, ← _root_.div_eq_inv_mul]
rw [le_div_iff₀ (NNReal.coe_pos.2 <| tsub_pos_iff_lt.2 hK)]
rw [mul_comm, NNReal.coe_sub hK.le, sub_mul]
calc
↑Kf⁻¹ * dist x y - Kg * dist x y ≤ dist (f x) (f y) - dist (g x) (g y) :=
sub_le_sub (hf.mul_le_dist x y) (hg.dist_le_mul x y)
_ ≤ _ := le_trans (le_abs_self _) (abs_dist_sub_le_dist_mul_mul _ _ _ _)
@[to_additive]
theorem mul_div_lipschitzWith (hf : AntilipschitzWith Kf f) (hg : LipschitzWith Kg (g / f))
(hK : Kg < Kf⁻¹) : AntilipschitzWith (Kf⁻¹ - Kg)⁻¹ g := by
simpa only [Pi.div_apply, mul_div_cancel] using hf.mul_lipschitzWith hg hK
@[to_additive le_mul_norm_sub]
theorem le_mul_norm_div {f : E → F} (hf : AntilipschitzWith K f) (x y : E) :
‖x / y‖ ≤ K * ‖f x / f y‖ := by simp [← dist_eq_norm_div, hf.le_mul_dist x y]
end AntilipschitzWith
end PseudoEMetricSpace
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) SeminormedCommGroup.to_lipschitzMul : LipschitzMul E :=
⟨⟨1 + 1, LipschitzWith.prod_fst.mul LipschitzWith.prod_snd⟩⟩
-- See note [lower instance priority]
/-- A seminormed group is a uniform group, i.e., multiplication and division are uniformly
continuous. -/
@[to_additive "A seminormed group is a uniform additive group, i.e., addition and subtraction are
uniformly continuous."]
instance (priority := 100) SeminormedCommGroup.to_isUniformGroup : IsUniformGroup E :=
⟨(LipschitzWith.prod_fst.div LipschitzWith.prod_snd).uniformContinuous⟩
-- short-circuit type class inference
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) SeminormedCommGroup.toIsTopologicalGroup : IsTopologicalGroup E :=
inferInstance
/-! ### SeparationQuotient -/
namespace SeparationQuotient
@[to_additive instNorm]
instance instMulNorm : Norm (SeparationQuotient E) where
norm := lift Norm.norm fun _ _ h => h.norm_eq_norm'
set_option linter.docPrime false in
@[to_additive (attr := simp) norm_mk]
theorem norm_mk' (p : E) : ‖mk p‖ = ‖p‖ := rfl
@[to_additive]
instance : NormedCommGroup (SeparationQuotient E) where
__ : CommGroup (SeparationQuotient E) := instCommGroup
dist_eq := Quotient.ind₂ dist_eq_norm_div
@[to_additive]
theorem mk_eq_one_iff {p : E} : mk p = 1 ↔ ‖p‖ = 0 := by
rw [← norm_mk', norm_eq_zero']
set_option linter.docPrime false in
@[to_additive (attr := simp) nnnorm_mk]
theorem nnnorm_mk' (p : E) : ‖mk p‖₊ = ‖p‖₊ := rfl
| end SeparationQuotient
@[to_additive]
| Mathlib/Analysis/Normed/Group/Uniform.lean | 388 | 390 |
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Eric Wieser
-/
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.Matrix.Diagonal
import Mathlib.LinearAlgebra.Matrix.DotProduct
import Mathlib.LinearAlgebra.Matrix.Dual
/-!
# Rank of matrices
The rank of a matrix `A` is defined to be the rank of range of the linear map corresponding to `A`.
This definition does not depend on the choice of basis, see `Matrix.rank_eq_finrank_range_toLin`.
## Main declarations
* `Matrix.rank`: the rank of a matrix
* `Matrix.cRank`: the rank of a matrix as a cardinal
* `Matrix.eRank`: the rank of a matrix as a term in `ℕ∞`.
-/
open Matrix
namespace Matrix
open Module Cardinal Set Submodule
universe ul um um₀ un un₀ uo uR
variable {l : Type ul} {m : Type um} {m₀ : Type um₀} {n : Type un} {n₀ : Type un₀} {o : Type uo}
variable {R : Type uR}
section Infinite
variable [Semiring R]
/-- The rank of a matrix, defined as the dimension of its column space, as a cardinal. -/
noncomputable def cRank (A : Matrix m n R) : Cardinal := Module.rank R <| span R <| range Aᵀ
lemma cRank_toNat_eq_finrank (A : Matrix m n R) :
A.cRank.toNat = Module.finrank R (span R (range A.col)) := rfl
lemma lift_cRank_submatrix_le (A : Matrix m n R) (r : m₀ → m) (c : n₀ → n) :
lift.{um} (A.submatrix r c).cRank ≤ lift.{um₀} A.cRank := by
have h : ((A.submatrix r id).submatrix id c).cRank ≤ (A.submatrix r id).cRank :=
Submodule.rank_mono <| span_mono <| by rintro _ ⟨x, rfl⟩; exact ⟨c x, rfl⟩
refine (Cardinal.lift_monotone h).trans ?_
let f : (m → R) →ₗ[R] (m₀ → R) := LinearMap.funLeft R R r
have h_eq : Submodule.map f (span R (range Aᵀ)) = span R (range (A.submatrix r id)ᵀ) := by
rw [LinearMap.map_span, ← image_univ, image_image, transpose_submatrix]
aesop
rw [cRank, ← h_eq]
have hwin := lift_rank_map_le f (span R (range Aᵀ))
simp_rw [← lift_umax] at hwin ⊢
exact hwin
/-- A special case of `lift_cRank_submatrix_le` for when `m₀` and `m` are in the same universe. -/
lemma cRank_submatrix_le {m m₀ : Type um} (A : Matrix m n R) (r : m₀ → m) (c : n₀ → n) :
(A.submatrix r c).cRank ≤ A.cRank := by
simpa using lift_cRank_submatrix_le A r c
lemma cRank_le_card_height [StrongRankCondition R] [Fintype m] (A : Matrix m n R) :
A.cRank ≤ Fintype.card m :=
(Submodule.rank_le (span R (range Aᵀ))).trans <| by rw [rank_fun']
lemma cRank_le_card_width [StrongRankCondition R] [Fintype n] (A : Matrix m n R) :
A.cRank ≤ Fintype.card n :=
(rank_span_le ..).trans <| by simpa using Cardinal.mk_range_le_lift (f := Aᵀ)
/-- The rank of a matrix, defined as the dimension of its column space, as a term in `ℕ∞`. -/
noncomputable def eRank (A : Matrix m n R) : ℕ∞ := A.cRank.toENat
lemma eRank_toNat_eq_finrank (A : Matrix m n R) :
A.eRank.toNat = Module.finrank R (span R (range A.col)) :=
toNat_toENat ..
lemma eRank_submatrix_le (A : Matrix m n R) (r : m₀ → m) (c : n₀ → n) :
(A.submatrix r c).eRank ≤ A.eRank := by
simpa using OrderHom.mono (β := ℕ∞) Cardinal.toENat <| lift_cRank_submatrix_le A r c
lemma eRank_le_card_width [StrongRankCondition R] (A : Matrix m n R) : A.eRank ≤ ENat.card n := by
wlog hfin : Finite n
· simp [ENat.card_eq_top.2 (by simpa using hfin)]
have _ := Fintype.ofFinite n
rw [ENat.card_eq_coe_fintype_card, eRank, toENat_le_nat]
exact A.cRank_le_card_width
lemma eRank_le_card_height [StrongRankCondition R] (A : Matrix m n R) : A.eRank ≤ ENat.card m := by
classical
wlog hfin : Finite m
· simp [ENat.card_eq_top.2 (by simpa using hfin)]
have _ := Fintype.ofFinite m
rw [ENat.card_eq_coe_fintype_card, eRank, toENat_le_nat]
exact A.cRank_le_card_height
end Infinite
variable [Fintype n] [Fintype o]
section CommRing
variable [CommRing R]
/-- The rank of a matrix is the rank of its image. -/
noncomputable def rank (A : Matrix m n R) : ℕ :=
finrank R <| LinearMap.range A.mulVecLin
@[simp]
theorem cRank_one [StrongRankCondition R] [DecidableEq m] :
(cRank (1 : Matrix m m R)) = lift.{uR} #m := by
have := nontrivial_of_invariantBasisNumber R
have h : LinearIndependent R (1 : Matrix m m R)ᵀ := by
convert Pi.linearIndependent_single_one m R
simp [funext_iff, Matrix.one_eq_pi_single]
rw [cRank, rank_span h, ← lift_umax, ← Cardinal.mk_range_eq_of_injective h.injective, lift_id']
@[simp] theorem eRank_one [StrongRankCondition R] [DecidableEq m] :
(eRank (1 : Matrix m m R)) = ENat.card m := by
rw [eRank, cRank_one, toENat_lift, ENat.card]
| @[simp]
theorem rank_one [StrongRankCondition R] [DecidableEq n] :
rank (1 : Matrix n n R) = Fintype.card n := by
rw [rank, mulVecLin_one, LinearMap.range_id, finrank_top, finrank_pi]
@[simp]
| Mathlib/Data/Matrix/Rank.lean | 125 | 130 |
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Yaël Dillies, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Ring.Unbundled.Basic
import Mathlib.Algebra.CharZero.Defs
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.NatCast
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Ring.Defs
import Mathlib.Tactic.Tauto
import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE
/-!
# Ordered rings and semirings
This file develops the basics of ordered (semi)rings.
Each typeclass here comprises
* an algebraic class (`Semiring`, `CommSemiring`, `Ring`, `CommRing`)
* an order class (`PartialOrder`, `LinearOrder`)
* assumptions on how both interact ((strict) monotonicity, canonicity)
For short,
* "`+` respects `≤`" means "monotonicity of addition"
* "`+` respects `<`" means "strict monotonicity of addition"
* "`*` respects `≤`" means "monotonicity of multiplication by a nonnegative number".
* "`*` respects `<`" means "strict monotonicity of multiplication by a positive number".
## Typeclasses
* `OrderedSemiring`: Semiring with a partial order such that `+` and `*` respect `≤`.
* `StrictOrderedSemiring`: Nontrivial semiring with a partial order such that `+` and `*` respects
`<`.
* `OrderedCommSemiring`: Commutative semiring with a partial order such that `+` and `*` respect
`≤`.
* `StrictOrderedCommSemiring`: Nontrivial commutative semiring with a partial order such that `+`
and `*` respect `<`.
* `OrderedRing`: Ring with a partial order such that `+` respects `≤` and `*` respects `<`.
* `OrderedCommRing`: Commutative ring with a partial order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedSemiring`: Nontrivial semiring with a linear order such that `+` respects `≤` and
`*` respects `<`.
* `LinearOrderedCommSemiring`: Nontrivial commutative semiring with a linear order such that `+`
respects `≤` and `*` respects `<`.
* `LinearOrderedRing`: Nontrivial ring with a linear order such that `+` respects `≤` and `*`
respects `<`.
* `LinearOrderedCommRing`: Nontrivial commutative ring with a linear order such that `+` respects
`≤` and `*` respects `<`.
## Hierarchy
The hardest part of proving order lemmas might be to figure out the correct generality and its
corresponding typeclass. Here's an attempt at demystifying it. For each typeclass, we list its
immediate predecessors and what conditions are added to each of them.
* `OrderedSemiring`
- `OrderedAddCommMonoid` & multiplication & `*` respects `≤`
- `Semiring` & partial order structure & `+` respects `≤` & `*` respects `≤`
* `StrictOrderedSemiring`
- `OrderedCancelAddCommMonoid` & multiplication & `*` respects `<` & nontriviality
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommSemiring`
- `OrderedSemiring` & commutativity of multiplication
- `CommSemiring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommSemiring`
- `StrictOrderedSemiring` & commutativity of multiplication
- `OrderedCommSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedRing`
- `OrderedSemiring` & additive inverses
- `OrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedRing`
- `StrictOrderedSemiring` & additive inverses
- `OrderedSemiring` & `+` respects `<` & `*` respects `<` & nontriviality
* `OrderedCommRing`
- `OrderedRing` & commutativity of multiplication
- `OrderedCommSemiring` & additive inverses
- `CommRing` & partial order structure & `+` respects `≤` & `*` respects `<`
* `StrictOrderedCommRing`
- `StrictOrderedCommSemiring` & additive inverses
- `StrictOrderedRing` & commutativity of multiplication
- `OrderedCommRing` & `+` respects `<` & `*` respects `<` & nontriviality
* `LinearOrderedSemiring`
- `StrictOrderedSemiring` & totality of the order
- `LinearOrderedAddCommMonoid` & multiplication & nontriviality & `*` respects `<`
* `LinearOrderedCommSemiring`
- `StrictOrderedCommSemiring` & totality of the order
- `LinearOrderedSemiring` & commutativity of multiplication
* `LinearOrderedRing`
- `StrictOrderedRing` & totality of the order
- `LinearOrderedSemiring` & additive inverses
- `LinearOrderedAddCommGroup` & multiplication & `*` respects `<`
- `Ring` & `IsDomain` & linear order structure
* `LinearOrderedCommRing`
- `StrictOrderedCommRing` & totality of the order
- `LinearOrderedRing` & commutativity of multiplication
- `LinearOrderedCommSemiring` & additive inverses
- `CommRing` & `IsDomain` & linear order structure
-/
assert_not_exists MonoidHom
open Function
universe u
variable {R : Type u}
-- TODO: assume weaker typeclasses
/-- An ordered semiring is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
class IsOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedAddMonoid R, ZeroLEOneClass R where
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
attribute [instance 100] IsOrderedRing.toZeroLEOneClass
/-- A strict ordered semiring is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
class IsStrictOrderedRing (R : Type*) [Semiring R] [PartialOrder R] extends
IsOrderedCancelAddMonoid R, ZeroLEOneClass R, Nontrivial R where
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the left
by a positive element `0 < c` to obtain `c * a < c * b`. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- In a strict ordered semiring, we can multiply an inequality `a < b` on the right
by a positive element `0 < c` to obtain `a * c < b * c`. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
attribute [instance 100] IsStrictOrderedRing.toZeroLEOneClass
attribute [instance 100] IsStrictOrderedRing.toNontrivial
lemma IsOrderedRing.of_mul_nonneg [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] (mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b) :
IsOrderedRing R where
mul_le_mul_of_nonneg_left a b c ab hc := by
simpa only [mul_sub, sub_nonneg] using mul_nonneg _ _ hc (sub_nonneg.2 ab)
mul_le_mul_of_nonneg_right a b c ab hc := by
simpa only [sub_mul, sub_nonneg] using mul_nonneg _ _ (sub_nonneg.2 ab) hc
lemma IsStrictOrderedRing.of_mul_pos [Ring R] [PartialOrder R] [IsOrderedAddMonoid R]
[ZeroLEOneClass R] [Nontrivial R] (mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b) :
IsStrictOrderedRing R where
mul_lt_mul_of_pos_left a b c ab hc := by
simpa only [mul_sub, sub_pos] using mul_pos _ _ hc (sub_pos.2 ab)
mul_lt_mul_of_pos_right a b c ab hc := by
simpa only [sub_mul, sub_pos] using mul_pos _ _ (sub_pos.2 ab) hc
section IsOrderedRing
variable [Semiring R] [PartialOrder R] [IsOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toPosMulMono : PosMulMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_left _ _ _ h x.2
-- see Note [lower instance priority]
instance (priority := 200) IsOrderedRing.toMulPosMono : MulPosMono R where
elim x _ _ h := IsOrderedRing.mul_le_mul_of_nonneg_right _ _ _ h x.2
end IsOrderedRing
/-- Turn an ordered domain into a strict ordered ring. -/
lemma IsOrderedRing.toIsStrictOrderedRing (R : Type*)
[Ring R] [PartialOrder R] [IsOrderedRing R] [NoZeroDivisors R] [Nontrivial R] :
IsStrictOrderedRing R :=
.of_mul_pos fun _ _ ap bp ↦ (mul_nonneg ap.le bp.le).lt_of_ne' (mul_ne_zero ap.ne' bp.ne')
section IsStrictOrderedRing
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R]
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toPosMulStrictMono : PosMulStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_left _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 200) IsStrictOrderedRing.toMulPosStrictMono : MulPosStrictMono R where
elim x _ _ h := IsStrictOrderedRing.mul_lt_mul_of_pos_right _ _ _ h x.prop
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toIsOrderedRing : IsOrderedRing R where
__ := ‹IsStrictOrderedRing R›
mul_le_mul_of_nonneg_left _ _ _ := mul_le_mul_of_nonneg_left
mul_le_mul_of_nonneg_right _ _ _ := mul_le_mul_of_nonneg_right
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toCharZero :
CharZero R where
cast_injective :=
(strictMono_nat_of_lt_succ fun n ↦ by rw [Nat.cast_succ]; apply lt_add_one).injective
-- see Note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.toNoMaxOrder : NoMaxOrder R :=
⟨fun a => ⟨a + 1, lt_add_of_pos_right _ one_pos⟩⟩
end IsStrictOrderedRing
section LinearOrder
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] [ExistsAddOfLE R]
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.noZeroDivisors : NoZeroDivisors R where
eq_zero_or_eq_zero_of_mul_eq_zero {a b} hab := by
contrapose! hab
obtain ha | ha := hab.1.lt_or_lt <;> obtain hb | hb := hab.2.lt_or_lt
exacts [(mul_pos_of_neg_of_neg ha hb).ne', (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne']
-- Note that we can't use `NoZeroDivisors.to_isDomain` since we are merely in a semiring.
-- See note [lower instance priority]
instance (priority := 100) IsStrictOrderedRing.isDomain : IsDomain R where
mul_left_cancel_of_ne_zero {a b c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_left ha).injective h, (strictMono_mul_left_of_pos ha).injective h]
mul_right_cancel_of_ne_zero {b a c} ha h := by
obtain ha | ha := ha.lt_or_lt
exacts [(strictAnti_mul_right ha).injective h, (strictMono_mul_right_of_pos ha).injective h]
end LinearOrder
/-! Note that `OrderDual` does not satisfy any of the ordered ring typeclasses due to the
`zero_le_one` field. -/
set_option linter.deprecated false in
/-- An `OrderedSemiring` is a semiring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedSemiring (R : Type u) extends Semiring R, OrderedAddCommMonoid R where
/-- `0 ≤ 1` in any ordered semiring. -/
protected zero_le_one : (0 : R) ≤ 1
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the left
by a non-negative element `0 ≤ c` to obtain `c * a ≤ c * b`. -/
protected mul_le_mul_of_nonneg_left : ∀ a b c : R, a ≤ b → 0 ≤ c → c * a ≤ c * b
/-- In an ordered semiring, we can multiply an inequality `a ≤ b` on the right
by a non-negative element `0 ≤ c` to obtain `a * c ≤ b * c`. -/
protected mul_le_mul_of_nonneg_right : ∀ a b c : R, a ≤ b → 0 ≤ c → a * c ≤ b * c
set_option linter.deprecated false in
/-- An `OrderedCommSemiring` is a commutative semiring with a partial order such that addition is
monotone and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommSemiring (R : Type u) extends OrderedSemiring R, CommSemiring R where
mul_le_mul_of_nonneg_right a b c ha hc :=
-- parentheses ensure this generates an `optParam` rather than an `autoParam`
(by simpa only [mul_comm] using mul_le_mul_of_nonneg_left a b c ha hc)
set_option linter.deprecated false in
/-- An `OrderedRing` is a ring with a partial order such that addition is monotone and
multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R where
/-- `0 ≤ 1` in any ordered ring. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of non-negative elements is non-negative. -/
protected mul_nonneg : ∀ a b : R, 0 ≤ a → 0 ≤ b → 0 ≤ a * b
set_option linter.deprecated false in
/-- An `OrderedCommRing` is a commutative ring with a partial order such that addition is monotone
and multiplication by a nonnegative number is monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsOrderedRing R]` instead."
(since := "2025-04-10")]
structure OrderedCommRing (R : Type u) extends OrderedRing R, CommRing R
set_option linter.deprecated false in
/-- A `StrictOrderedSemiring` is a nontrivial semiring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedSemiring (R : Type u) extends Semiring R, OrderedCancelAddCommMonoid R,
Nontrivial R where
/-- In a strict ordered semiring, `0 ≤ 1`. -/
protected zero_le_one : (0 : R) ≤ 1
/-- Left multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_left : ∀ a b c : R, a < b → 0 < c → c * a < c * b
/-- Right multiplication by a positive element is strictly monotone. -/
protected mul_lt_mul_of_pos_right : ∀ a b c : R, a < b → 0 < c → a * c < b * c
set_option linter.deprecated false in
/-- A `StrictOrderedCommSemiring` is a commutative semiring with a partial order such that
addition is strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommSemiring (R : Type u) extends StrictOrderedSemiring R, CommSemiring R
set_option linter.deprecated false in
/-- A `StrictOrderedRing` is a ring with a partial order such that addition is strictly monotone
and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedRing (R : Type u) extends Ring R, OrderedAddCommGroup R, Nontrivial R where
/-- In a strict ordered ring, `0 ≤ 1`. -/
protected zero_le_one : 0 ≤ (1 : R)
/-- The product of two positive elements is positive. -/
protected mul_pos : ∀ a b : R, 0 < a → 0 < b → 0 < a * b
set_option linter.deprecated false in
/-- A `StrictOrderedCommRing` is a commutative ring with a partial order such that addition is
strictly monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [PartialOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure StrictOrderedCommRing (R : Type*) extends StrictOrderedRing R, CommRing R
/- It's not entirely clear we should assume `Nontrivial` at this point; it would be reasonable to
explore changing this, but be warned that the instances involving `Domain` may cause typeclass
search loops. -/
set_option linter.deprecated false in
/-- A `LinearOrderedSemiring` is a nontrivial semiring with a linear order such that
addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Semiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedSemiring (R : Type u) extends StrictOrderedSemiring R,
LinearOrderedAddCommMonoid R
set_option linter.deprecated false in
/-- A `LinearOrderedCommSemiring` is a nontrivial commutative semiring with a linear order such
that addition is monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommSemiring (R : Type*) extends StrictOrderedCommSemiring R,
LinearOrderedSemiring R
set_option linter.deprecated false in
/-- A `LinearOrderedRing` is a ring with a linear order such that addition is monotone and
multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[Ring R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedRing (R : Type u) extends StrictOrderedRing R, LinearOrder R
set_option linter.deprecated false in
/-- A `LinearOrderedCommRing` is a commutative ring with a linear order such that addition is
monotone and multiplication by a positive number is strictly monotone. -/
@[deprecated "Use `[CommRing R] [LinearOrder R] [IsStrictOrderedRing R]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommRing (R : Type u) extends LinearOrderedRing R, CommMonoid R
attribute [nolint docBlame]
StrictOrderedSemiring.toOrderedCancelAddCommMonoid
StrictOrderedCommSemiring.toCommSemiring
LinearOrderedSemiring.toLinearOrderedAddCommMonoid
LinearOrderedRing.toLinearOrder
OrderedSemiring.toOrderedAddCommMonoid
OrderedCommSemiring.toCommSemiring
StrictOrderedCommRing.toCommRing
OrderedRing.toOrderedAddCommGroup
OrderedCommRing.toCommRing
StrictOrderedRing.toOrderedAddCommGroup
LinearOrderedCommSemiring.toLinearOrderedSemiring
LinearOrderedCommRing.toCommMonoid
section OrderedRing
variable [Ring R] [PartialOrder R] [IsOrderedRing R] {a b c : R}
lemma one_add_le_one_sub_mul_one_add (h : a + b + b * c ≤ c) : 1 + a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_add_le_one_add_mul_one_sub (h : a + c + b * c ≤ b) : 1 + a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, le_sub_iff_add_le, add_assoc, ← add_assoc a]
gcongr
lemma one_sub_le_one_sub_mul_one_add (h : b + b * c ≤ a + c) : 1 - a ≤ (1 - b) * (1 + c) := by
rw [one_sub_mul, mul_one_add, sub_le_sub_iff, add_assoc, add_comm c]
gcongr
lemma one_sub_le_one_add_mul_one_sub (h : c + b * c ≤ a + b) : 1 - a ≤ (1 + b) * (1 - c) := by
rw [mul_one_sub, one_add_mul, sub_le_sub_iff, add_assoc, add_comm b]
gcongr
end OrderedRing
| Mathlib/Algebra/Order/Ring/Defs.lean | 401 | 402 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.WithBot
/-!
# Degree of univariate polynomials
## Main definitions
* `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥`
* `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0`
* `Polynomial.leadingCoeff`: the leading coefficient of a polynomial
* `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0
* `Polynomial.nextCoeff`: the next coefficient after the leading coefficient
## Main results
* `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : R[X]) : WithBot ℕ :=
p.support.max
/-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/
def natDegree (p : R[X]) : ℕ :=
(degree p).unbotD 0
/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/
def leadingCoeff (p : R[X]) : R :=
coeff p (natDegree p)
/-- a polynomial is `Monic` if its leading coefficient is 1 -/
def Monic (p : R[X]) :=
leadingCoeff p = (1 : R)
theorem Monic.def : Monic p ↔ leadingCoeff p = 1 :=
Iff.rfl
instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance
@[simp]
theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=
hp
theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=
hp
@[simp]
theorem degree_zero : degree (0 : R[X]) = ⊥ :=
rfl
@[simp]
theorem natDegree_zero : natDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=
rfl
@[simp]
theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩
theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not
theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by
let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))
have hn : degree p = some n := Classical.not_not.1 hn
rw [natDegree, hn]; rfl
theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe
theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.natDegree = n := by
obtain rfl|h := eq_or_ne p 0
· simp [hn.ne]
· exact degree_eq_iff_natDegree_eq h
theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by
rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe]
theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n :=
mt natDegree_eq_of_degree_eq_some
@[simp]
theorem degree_le_natDegree : degree p ≤ natDegree p :=
WithBot.giUnbotDBot.gc.le_u_l _
theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) :
natDegree p = natDegree q := by unfold natDegree; rw [h]
theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by
rw [Nat.cast_withBot]
exact Finset.le_sup (mem_support_iff.2 h)
theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) :
f.degree ≤ g.degree :=
Finset.sup_mono h
theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by
by_cases hp : p = 0
· rw [hp, degree_zero]
exact bot_le
· rw [degree_eq_natDegree hp]
exact le_degree_of_ne_zero h
theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n :=
WithBot.unbotD_le_iff (fun _ ↦ bot_le)
theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n :=
WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp))
alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le
theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :
p.natDegree ≤ q.natDegree :=
WithBot.giUnbotDBot.gc.monotone_l hpq
@[simp]
theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by
rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,
WithBot.coe_zero]
theorem degree_C_le : degree (C a) ≤ 0 := by
by_cases h : a = 0
· rw [h, C_0]
exact bot_le
· rw [degree_C h]
theorem degree_C_lt : degree (C a) < 1 :=
degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one
theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le
@[simp]
theorem natDegree_C (a : R) : natDegree (C a) = 0 := by
by_cases ha : a = 0
· have : C a = 0 := by rw [ha, C_0]
rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot]
· rw [natDegree, degree_C ha, WithBot.unbotD_zero]
@[simp]
theorem natDegree_one : natDegree (1 : R[X]) = 0 :=
natDegree_C 1
@[simp]
theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natDegree_C]
@[simp]
theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] :
natDegree (ofNat(n) : R[X]) = 0 :=
natDegree_natCast _
theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by
rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot]
@[simp]
theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]
theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by
simpa only [pow_one] using degree_C_mul_X_pow 1 ha
theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
letI := Classical.decEq R
if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le
else le_of_eq (degree_monomial n h)
theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by
rw [C_mul_X_pow_eq_monomial]
apply degree_monomial_le
theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by
simpa only [pow_one] using degree_C_mul_X_pow_le 1 a
@[simp]
theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp]
theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by
simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha
@[simp]
theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) :
natDegree (monomial i r) = if r = 0 then 0 else i := by
split_ifs with hr
· simp [hr]
· rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr]
theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by
classical
rw [Polynomial.natDegree_monomial]
split_ifs
exacts [Nat.zero_le _, le_rfl]
theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i :=
letI := Classical.decEq R
Eq.trans (natDegree_monomial _ _) (if_neg r0)
theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h =>
mem_support_iff.mp (mem_of_max hn) h
theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by
simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R)
theorem degree_X_le : degree (X : R[X]) ≤ 1 :=
degree_monomial_le _ _
theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 :=
natDegree_le_of_degree_le degree_X_le
theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by
rw [degree_eq_natDegree h]
exact WithBot.succ_coe p.natDegree
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) :=
degree_C one_ne_zero
@[simp]
theorem degree_X : degree (X : R[X]) = 1 :=
degree_monomial _ one_ne_zero
@[simp]
theorem natDegree_X : (X : R[X]).natDegree = 1 :=
natDegree_eq_of_degree_eq_some degree_X
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg]
theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a :=
p.degree_neg.le.trans hp
@[simp]
theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree]
theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m :=
(natDegree_neg p).le.trans hp
@[simp]
theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by
rw [← C_eq_intCast, natDegree_C]
theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by
rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg]
end Ring
section Semiring
variable [Semiring R] {p : R[X]}
/-- The second-highest coefficient, or 0 for constants -/
def nextCoeff (p : R[X]) : R :=
if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1)
lemma nextCoeff_eq_zero :
p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by
simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop
lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by
simp [nextCoeff]
@[simp]
theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by
rw [nextCoeff]
simp
theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) :
nextCoeff p = p.coeff (p.natDegree - 1) := by
rw [nextCoeff, if_neg]
contrapose! hp
simpa
variable {p q : R[X]} {ι : Type*}
theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by
simpa only [degree, ← support_toFinsupp, toFinsupp_add]
using AddMonoidAlgebra.sup_support_add_le _ _ _
theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) :
degree (p + q) ≤ n :=
(degree_add_le p q).trans <| max_le hp hq
theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p + q) ≤ max a b :=
(p.degree_add_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by
rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h]
theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n)
(hq : natDegree q ≤ n) : natDegree (p + q) ≤ n :=
(natDegree_add_le p q).trans <| max_le hp hq
theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p + q) ≤ max m n :=
(p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_›
@[simp]
theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 :=
⟨fun h =>
Classical.by_contradiction fun hp =>
mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)),
fun h => h.symm ▸ leadingCoeff_zero⟩
theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero]
theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by
rw [leadingCoeff_eq_zero, degree_eq_bot]
theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n :=
natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _
theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by
rcases p with ⟨p⟩
simp only [erase_def, degree, coeff, support]
apply sup_mono
rw [Finsupp.support_erase]
apply Finset.erase_subset
theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by
apply lt_of_le_of_ne (degree_erase_le _ _)
rw [degree_eq_natDegree hp, degree, support_erase]
exact fun h => not_mem_erase _ _ (mem_of_max h)
theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by
classical
rw [degree, support_update]
split_ifs
· exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _)
· rw [max_insert, max_comm]
exact le_rfl
theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) :
degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) :=
Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl])
fun a s has ih =>
calc
degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by
rw [Finset.sum_cons]; exact degree_add_le _ _
_ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih
theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by
simpa only [degree, ← support_toFinsupp, toFinsupp_mul]
using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _
theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p * q) ≤ a + b :=
(p.degree_mul_le _).trans <| add_le_add ‹_› ‹_›
theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p
| 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le
| n + 1 =>
calc
degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by
rw [pow_succ]; exact degree_mul_le _ _
_ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _
theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) :
degree (p ^ b) ≤ b * a := by
induction b with
| zero => simp [degree_one_le]
| succ n hn =>
rw [Nat.cast_succ, add_mul, one_mul, pow_succ]
exact degree_mul_le_of_le hn hp
@[simp]
theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by
classical
by_cases ha : a = 0
· simp only [ha, (monomial n).map_zero, leadingCoeff_zero]
· rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial]
simp
theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by
rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial]
theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by
simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1
@[simp]
theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a :=
leadingCoeff_monomial a 0
theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by
simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n
theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by
simpa only [pow_one] using @leadingCoeff_X_pow R _ 1
@[simp]
theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) :=
leadingCoeff_X_pow n
@[simp]
theorem monic_X : Monic (X : R[X]) :=
leadingCoeff_X
theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 :=
leadingCoeff_C 1
@[simp]
theorem monic_one : Monic (1 : R[X]) :=
leadingCoeff_C _
theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) :
p ≠ 0 := by
rintro rfl
simp [Monic] at hp
theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by
nontriviality R
exact hp.ne_zero
theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 :=
haveI := Nontrivial.of_polynomial_ne hne
hp.ne_zero
theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by
apply natDegree_le_of_degree_le
apply le_trans (degree_mul_le p q)
rw [Nat.cast_add]
apply add_le_add <;> apply degree_le_natDegree
theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) :
natDegree (p * q) ≤ m + n :=
natDegree_mul_le.trans <| add_le_add ‹_› ‹_›
theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by
induction n with
| zero => simp
| succ i hi =>
rw [pow_succ, Nat.succ_mul]
apply le_trans natDegree_mul_le (add_le_add_right hi _)
theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) :
natDegree (p ^ n) ≤ n * m :=
natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›)
theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by
rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero]
theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl
theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by
simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le,
not_imp_comm, Nat.cast_withBot]
theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by
simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff,
WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not]
theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le
end Semiring
section NontrivialSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ)
@[simp]
theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by
rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]
@[simp]
theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_X_pow n)
end NontrivialSemiring
section Ring
variable [Ring R] {p q : R[X]}
theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by
simpa only [degree_neg q] using degree_add_le p (-q)
theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p - q) ≤ max a b :=
(p.degree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by
simpa only [← natDegree_neg q] using natDegree_add_le p (-q)
theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p - q) ≤ max m n :=
(p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0)
(hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p :=
have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p :=
monomial_add_erase _ _
have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q :=
monomial_add_erase _ _
have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd]
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0)
calc
degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by
conv =>
lhs
rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]
_ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) :=
(degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _)
_ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 :=
(degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))
theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 :=
natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r
end Ring
end Polynomial
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 1,616 | 1,617 | |
/-
Copyright (c) 2019 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard
-/
import Mathlib.Data.EReal.Basic
deprecated_module (since := "2025-04-13")
| Mathlib/Data/Real/EReal.lean | 473 | 477 | |
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.Topology.MetricSpace.HausdorffDistance
/-!
# Thickenings in pseudo-metric spaces
## Main definitions
* `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space.
* `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric
space.
## Main results
* `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings
* `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings
* `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`,
some `cthickening` of `s` is contained in `t`.
* `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis
of the neighbourhoods of `K`
* `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection
of its closed thickenings of positive radii accumulating at zero.
The same holds for open thickenings.
* `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union
of `closedBall`s of radius `δ` around `x : E`.
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Bornology
universe u v w
variable {ι : Sort*} {α : Type u}
namespace Metric
section Thickening
variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α}
open EMetric
/-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space
consists of those points that are at distance less than `δ` from some point of `E`. -/
def thickening (δ : ℝ) (E : Set α) : Set α :=
{ x : α | infEdist x E < ENNReal.ofReal δ }
theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ :=
Iff.rfl
/-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the
(open) `δ`-thickening of `E` for small enough positive `δ`. -/
lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) :
∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by
obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h
filter_upwards [eventually_lt_nhds ε_pos] with δ hδ
simp only [thickening, mem_setOf_eq, not_lt]
exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le
/-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/
theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) :
thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) :=
rfl
/-- The (open) thickening is an open set. -/
theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) :=
Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio
/-- The (open) thickening of the empty set is empty. -/
@[simp]
theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by
simp only [thickening, setOf_false, infEdist_empty, not_top_lt]
theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ :=
eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt
/-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of
the thickening radius `δ`. -/
@[gcongr]
theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
thickening δ₁ E ⊆ thickening δ₂ E :=
preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle))
/-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is
an increasing function of the subset `E`. -/
theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) :
thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx
theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) :
x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ :=
infEdist_lt_iff
/-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level
set. -/
theorem frontier_thickening_subset (E : Set α) {δ : ℝ} :
frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } :=
frontier_lt_subset_eq continuous_infEdist continuous_const
open scoped Function in -- required for scoped `on` notation
theorem frontier_thickening_disjoint (A : Set α) :
Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by
refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_
rcases le_total r₁ 0 with h₁ | h₁
· simp [thickening_of_nonpos h₁]
refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _)
(frontier_thickening_subset _)
apply_fun ENNReal.toReal at h
rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h
/-- Any set is contained in the complement of the δ-thickening of the complement of its
δ-thickening. -/
lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) :
E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by
intro x x_in_E
simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt]
apply EMetric.le_infEdist.mpr fun y hy ↦ ?_
simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy
simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E
/-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement
of the set. -/
lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) :
thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by
apply compl_subset_compl.mp
simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E
variable {X : Type u} [PseudoMetricSpace X]
theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) :
x ∈ thickening δ E ↔ infDist x E < δ :=
lt_ofReal_iff_toReal_lt (infEdist_ne_top h)
/-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if
it is at distance less than `δ` from some point of `E`. -/
theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by
have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by
rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)]
simp_rw [mem_thickening_iff_exists_edist_lt, key_iff]
@[simp]
theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by
ext
simp [mem_thickening_iff]
theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) :
ball x δ ⊆ thickening δ E :=
Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx)
/-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the
union of balls of radius `δ` centered at points of `E`. -/
theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by
ext x
simp only [mem_iUnion₂, exists_prop]
exact mem_thickening_iff
protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) :
IsBounded (thickening δ E) := by
rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩
· simp
· refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩
calc
dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx
_ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _
end Thickening
section Cthickening
variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α}
open EMetric
/-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space
consists of those points that are at infimum distance at most `δ` from `E`. -/
def cthickening (δ : ℝ) (E : Set α) : Set α :=
{ x : α | infEdist x E ≤ ENNReal.ofReal δ }
@[simp]
theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ :=
Iff.rfl
/-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the
closed `δ`-thickening of `E` for small enough positive `δ`. -/
lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) :
∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by
obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h
filter_upwards [eventually_lt_nhds ε_pos] with δ hδ
simp only [cthickening, mem_setOf_eq, not_le]
exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt
theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E)
(h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E :=
(infEdist_le_edist_of_mem h).trans h'
theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α)
(h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by
apply mem_cthickening_of_edist_le x y δ E h
rw [edist_dist]
exact ENNReal.ofReal_le_ofReal h'
theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) :
cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) :=
rfl
/-- The closed thickening is a closed set. -/
theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) :=
IsClosed.preimage continuous_infEdist isClosed_Iic
/-- The closed thickening of the empty set is empty. -/
@[simp]
theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by
simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff]
theorem cthickening_of_nonpos {δ : ℝ} (hδ : δ ≤ 0) (E : Set α) : cthickening δ E = closure E := by
ext x
simp [mem_closure_iff_infEdist_zero, cthickening, ENNReal.ofReal_eq_zero.2 hδ]
/-- The closed thickening with radius zero is the closure of the set. -/
@[simp]
theorem cthickening_zero (E : Set α) : cthickening 0 E = closure E :=
cthickening_of_nonpos le_rfl E
theorem cthickening_max_zero (δ : ℝ) (E : Set α) : cthickening (max 0 δ) E = cthickening δ E := by
cases le_total δ 0 <;> simp [cthickening_of_nonpos, *]
/-- The closed thickening `Metric.cthickening δ E` of a fixed subset `E` is an increasing function
of the thickening radius `δ`. -/
theorem cthickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
cthickening δ₁ E ⊆ cthickening δ₂ E :=
preimage_mono (Iic_subset_Iic.mpr (ENNReal.ofReal_le_ofReal hle))
@[simp]
theorem cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) {δ : ℝ} (hδ : 0 ≤ δ) :
cthickening δ ({x} : Set α) = closedBall x δ := by
ext y
simp [cthickening, edist_dist, ENNReal.ofReal_le_ofReal_iff hδ]
theorem closedBall_subset_cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) (δ : ℝ) :
closedBall x δ ⊆ cthickening δ ({x} : Set α) := by
rcases lt_or_le δ 0 with (hδ | hδ)
· simp only [closedBall_eq_empty.mpr hδ, empty_subset]
· simp only [cthickening_singleton x hδ, Subset.rfl]
/-- The closed thickening `Metric.cthickening δ E` with a fixed thickening radius `δ` is
an increasing function of the subset `E`. -/
theorem cthickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) :
cthickening δ E₁ ⊆ cthickening δ E₂ := fun _ hx => le_trans (infEdist_anti h) hx
theorem cthickening_subset_thickening {δ₁ : ℝ≥0} {δ₂ : ℝ} (hlt : (δ₁ : ℝ) < δ₂) (E : Set α) :
cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx =>
hx.out.trans_lt ((ENNReal.ofReal_lt_ofReal_iff (lt_of_le_of_lt δ₁.prop hlt)).mpr hlt)
/-- The closed thickening `Metric.cthickening δ₁ E` is contained in the open thickening
`Metric.thickening δ₂ E` if the radius of the latter is positive and larger. -/
theorem cthickening_subset_thickening' {δ₁ δ₂ : ℝ} (δ₂_pos : 0 < δ₂) (hlt : δ₁ < δ₂) (E : Set α) :
cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx =>
lt_of_le_of_lt hx.out ((ENNReal.ofReal_lt_ofReal_iff δ₂_pos).mpr hlt)
/-- The open thickening `Metric.thickening δ E` is contained in the closed thickening
`Metric.cthickening δ E` with the same radius. -/
theorem thickening_subset_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ cthickening δ E := by
intro x hx
rw [thickening, mem_setOf_eq] at hx
exact hx.le
theorem thickening_subset_cthickening_of_le {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) :
thickening δ₁ E ⊆ cthickening δ₂ E :=
(thickening_subset_cthickening δ₁ E).trans (cthickening_mono hle E)
theorem _root_.Bornology.IsBounded.cthickening {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α}
(h : IsBounded E) : IsBounded (cthickening δ E) := by
have : IsBounded (thickening (max (δ + 1) 1) E) := h.thickening
apply this.subset
exact cthickening_subset_thickening' (zero_lt_one.trans_le (le_max_right _ _))
((lt_add_one _).trans_le (le_max_left _ _)) _
protected theorem _root_.IsCompact.cthickening
{α : Type*} [PseudoMetricSpace α] [ProperSpace α] {s : Set α}
(hs : IsCompact s) {r : ℝ} : IsCompact (cthickening r s) :=
isCompact_of_isClosed_isBounded isClosed_cthickening hs.isBounded.cthickening
theorem thickening_subset_interior_cthickening (δ : ℝ) (E : Set α) :
thickening δ E ⊆ interior (cthickening δ E) :=
(subset_interior_iff_isOpen.mpr isOpen_thickening).trans
(interior_mono (thickening_subset_cthickening δ E))
theorem closure_thickening_subset_cthickening (δ : ℝ) (E : Set α) :
closure (thickening δ E) ⊆ cthickening δ E :=
(closure_mono (thickening_subset_cthickening δ E)).trans isClosed_cthickening.closure_subset
/-- The closed thickening of a set contains the closure of the set. -/
theorem closure_subset_cthickening (δ : ℝ) (E : Set α) : closure E ⊆ cthickening δ E := by
rw [← cthickening_of_nonpos (min_le_right δ 0)]
exact cthickening_mono (min_le_left δ 0) E
/-- The (open) thickening of a set contains the closure of the set. -/
theorem closure_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) :
closure E ⊆ thickening δ E := by
rw [← cthickening_zero]
exact cthickening_subset_thickening' δ_pos δ_pos E
/-- A set is contained in its own (open) thickening. -/
theorem self_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : E ⊆ thickening δ E :=
(@subset_closure _ _ E).trans (closure_subset_thickening δ_pos E)
/-- A set is contained in its own closed thickening. -/
theorem self_subset_cthickening {δ : ℝ} (E : Set α) : E ⊆ cthickening δ E :=
subset_closure.trans (closure_subset_cthickening δ E)
theorem thickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : thickening δ E ∈ 𝓝ˢ E :=
isOpen_thickening.mem_nhdsSet.2 <| self_subset_thickening hδ E
theorem cthickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : cthickening δ E ∈ 𝓝ˢ E :=
mem_of_superset (thickening_mem_nhdsSet E hδ) (thickening_subset_cthickening _ _)
@[simp]
theorem thickening_union (δ : ℝ) (s t : Set α) :
thickening δ (s ∪ t) = thickening δ s ∪ thickening δ t := by
simp_rw [thickening, infEdist_union, min_lt_iff, setOf_or]
@[simp]
theorem cthickening_union (δ : ℝ) (s t : Set α) :
cthickening δ (s ∪ t) = cthickening δ s ∪ cthickening δ t := by
simp_rw [cthickening, infEdist_union, min_le_iff, setOf_or]
@[simp]
theorem thickening_iUnion (δ : ℝ) (f : ι → Set α) :
thickening δ (⋃ i, f i) = ⋃ i, thickening δ (f i) := by
simp_rw [thickening, infEdist_iUnion, iInf_lt_iff, setOf_exists]
lemma thickening_biUnion {ι : Type*} (δ : ℝ) (f : ι → Set α) (I : Set ι) :
thickening δ (⋃ i ∈ I, f i) = ⋃ i ∈ I, thickening δ (f i) := by simp only [thickening_iUnion]
theorem ediam_cthickening_le (ε : ℝ≥0) :
EMetric.diam (cthickening ε s) ≤ EMetric.diam s + 2 * ε := by
refine diam_le fun x hx y hy => ENNReal.le_of_forall_pos_le_add fun δ hδ _ => ?_
rw [mem_cthickening_iff, ENNReal.ofReal_coe_nnreal] at hx hy
have hε : (ε : ℝ≥0∞) < ε + δ := ENNReal.coe_lt_coe.2 (lt_add_of_pos_right _ hδ)
replace hx := hx.trans_lt hε
obtain ⟨x', hx', hxx'⟩ := infEdist_lt_iff.mp hx
calc
edist x y ≤ edist x x' + edist y x' := edist_triangle_right _ _ _
_ ≤ ε + δ + (infEdist y s + EMetric.diam s) :=
add_le_add hxx'.le (edist_le_infEdist_add_ediam hx')
_ ≤ ε + δ + (ε + EMetric.diam s) := add_le_add_left (add_le_add_right hy _) _
_ = _ := by rw [two_mul]; ac_rfl
theorem ediam_thickening_le (ε : ℝ≥0) : EMetric.diam (thickening ε s) ≤ EMetric.diam s + 2 * ε :=
(EMetric.diam_mono <| thickening_subset_cthickening _ _).trans <| ediam_cthickening_le _
theorem diam_cthickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) :
diam (cthickening ε s) ≤ diam s + 2 * ε := by
lift ε to ℝ≥0 using hε
refine (toReal_le_add' (ediam_cthickening_le _) ?_ ?_).trans_eq ?_
· exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono (self_subset_cthickening _)
· simp [mul_eq_top]
· simp [diam]
theorem diam_thickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) :
diam (thickening ε s) ≤ diam s + 2 * ε := by
by_cases hs : IsBounded s
· exact (diam_mono (thickening_subset_cthickening _ _) hs.cthickening).trans
(diam_cthickening_le _ hε)
obtain rfl | hε := hε.eq_or_lt
· simp [thickening_of_nonpos, diam_nonneg]
· rw [diam_eq_zero_of_unbounded (mt (IsBounded.subset · <| self_subset_thickening hε _) hs)]
positivity
@[simp]
theorem thickening_closure : thickening δ (closure s) = thickening δ s := by
simp_rw [thickening, infEdist_closure]
@[simp]
theorem cthickening_closure : cthickening δ (closure s) = cthickening δ s := by
simp_rw [cthickening, infEdist_closure]
open ENNReal
theorem _root_.Disjoint.exists_thickenings (hst : Disjoint s t) (hs : IsCompact s)
(ht : IsClosed t) :
∃ δ, 0 < δ ∧ Disjoint (thickening δ s) (thickening δ t) := by
obtain ⟨r, hr, h⟩ := exists_pos_forall_lt_edist hs ht hst
refine ⟨r / 2, half_pos (NNReal.coe_pos.2 hr), ?_⟩
rw [disjoint_iff_inf_le]
rintro z ⟨hzs, hzt⟩
rw [mem_thickening_iff_exists_edist_lt] at hzs hzt
rw [← NNReal.coe_two, ← NNReal.coe_div, ENNReal.ofReal_coe_nnreal] at hzs hzt
obtain ⟨x, hx, hzx⟩ := hzs
obtain ⟨y, hy, hzy⟩ := hzt
refine (h x hx y hy).not_le ?_
calc
edist x y ≤ edist z x + edist z y := edist_triangle_left _ _ _
_ ≤ ↑(r / 2) + ↑(r / 2) := add_le_add hzx.le hzy.le
_ = r := by rw [← ENNReal.coe_add, add_halves]
theorem _root_.Disjoint.exists_cthickenings (hst : Disjoint s t) (hs : IsCompact s)
(ht : IsClosed t) :
∃ δ, 0 < δ ∧ Disjoint (cthickening δ s) (cthickening δ t) := by
obtain ⟨δ, hδ, h⟩ := hst.exists_thickenings hs ht
refine ⟨δ / 2, half_pos hδ, h.mono ?_ ?_⟩ <;>
exact cthickening_subset_thickening' hδ (half_lt_self hδ) _
/-- If `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. -/
theorem _root_.IsCompact.exists_cthickening_subset_open (hs : IsCompact s) (ht : IsOpen t)
(hst : s ⊆ t) :
∃ δ, 0 < δ ∧ cthickening δ s ⊆ t :=
(hst.disjoint_compl_right.exists_cthickenings hs ht.isClosed_compl).imp fun _ h =>
⟨h.1, disjoint_compl_right_iff_subset.1 <| h.2.mono_right <| self_subset_cthickening _⟩
theorem _root_.IsCompact.exists_isCompact_cthickening [LocallyCompactSpace α] (hs : IsCompact s) :
∃ δ, 0 < δ ∧ IsCompact (cthickening δ s) := by
rcases exists_compact_superset hs with ⟨K, K_compact, hK⟩
rcases hs.exists_cthickening_subset_open isOpen_interior hK with ⟨δ, δpos, hδ⟩
refine ⟨δ, δpos, ?_⟩
exact K_compact.of_isClosed_subset isClosed_cthickening (hδ.trans interior_subset)
theorem _root_.IsCompact.exists_thickening_subset_open (hs : IsCompact s) (ht : IsOpen t)
(hst : s ⊆ t) : ∃ δ, 0 < δ ∧ thickening δ s ⊆ t :=
let ⟨δ, h₀, hδ⟩ := hs.exists_cthickening_subset_open ht hst
⟨δ, h₀, (thickening_subset_cthickening _ _).trans hδ⟩
theorem hasBasis_nhdsSet_thickening {K : Set α} (hK : IsCompact K) :
(𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => thickening δ K :=
(hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_thickening_subset_open hU.1 hU.2)
fun _ => thickening_mem_nhdsSet K
theorem hasBasis_nhdsSet_cthickening {K : Set α} (hK : IsCompact K) :
(𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => cthickening δ K :=
(hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_cthickening_subset_open hU.1 hU.2)
fun _ => cthickening_mem_nhdsSet K
theorem cthickening_eq_iInter_cthickening' {δ : ℝ} (s : Set ℝ) (hsδ : s ⊆ Ioi δ)
(hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) :
cthickening δ E = ⋂ ε ∈ s, cthickening ε E := by
apply Subset.antisymm
· exact subset_iInter₂ fun _ hε => cthickening_mono (le_of_lt (hsδ hε)) E
· unfold cthickening
intro x hx
simp only [mem_iInter, mem_setOf_eq] at *
apply ENNReal.le_of_forall_pos_le_add
intro η η_pos _
rcases hs (δ + η) (lt_add_of_pos_right _ (NNReal.coe_pos.mpr η_pos)) with ⟨ε, ⟨hsε, hε⟩⟩
apply ((hx ε hsε).trans (ENNReal.ofReal_le_ofReal hε.2)).trans
rw [ENNReal.coe_nnreal_eq η]
exact ENNReal.ofReal_add_le
theorem cthickening_eq_iInter_cthickening {δ : ℝ} (E : Set α) :
cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), cthickening ε E := by
apply cthickening_eq_iInter_cthickening' (Ioi δ) rfl.subset
simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self]
exact fun _ hε => nonempty_Ioc.mpr hε
theorem cthickening_eq_iInter_thickening' {δ : ℝ} (δ_nn : 0 ≤ δ) (s : Set ℝ) (hsδ : s ⊆ Ioi δ)
(hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) :
cthickening δ E = ⋂ ε ∈ s, thickening ε E := by
refine (subset_iInter₂ fun ε hε => ?_).antisymm ?_
· obtain ⟨ε', -, hε'⟩ := hs ε (hsδ hε)
have ss := cthickening_subset_thickening' (lt_of_le_of_lt δ_nn hε'.1) hε'.1 E
exact ss.trans (thickening_mono hε'.2 E)
· rw [cthickening_eq_iInter_cthickening' s hsδ hs E]
exact iInter₂_mono fun ε _ => thickening_subset_cthickening ε E
theorem cthickening_eq_iInter_thickening {δ : ℝ} (δ_nn : 0 ≤ δ) (E : Set α) :
cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), thickening ε E := by
apply cthickening_eq_iInter_thickening' δ_nn (Ioi δ) rfl.subset
simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self]
exact fun _ hε => nonempty_Ioc.mpr hε
theorem cthickening_eq_iInter_thickening'' (δ : ℝ) (E : Set α) :
cthickening δ E = ⋂ (ε : ℝ) (_ : max 0 δ < ε), thickening ε E := by
rw [← cthickening_max_zero, cthickening_eq_iInter_thickening]
exact le_max_left _ _
/-- The closure of a set equals the intersection of its closed thickenings of positive radii
accumulating at zero. -/
theorem closure_eq_iInter_cthickening' (E : Set α) (s : Set ℝ)
(hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, cthickening δ E := by
by_cases hs₀ : s ⊆ Ioi 0
· rw [← cthickening_zero]
apply cthickening_eq_iInter_cthickening' _ hs₀ hs
obtain ⟨δ, hδs, δ_nonpos⟩ := not_subset.mp hs₀
rw [Set.mem_Ioi, not_lt] at δ_nonpos
apply Subset.antisymm
· exact subset_iInter₂ fun ε _ => closure_subset_cthickening ε E
· rw [← cthickening_of_nonpos δ_nonpos E]
exact biInter_subset_of_mem hδs
/-- The closure of a set equals the intersection of its closed thickenings of positive radii. -/
theorem closure_eq_iInter_cthickening (E : Set α) :
closure E = ⋂ (δ : ℝ) (_ : 0 < δ), cthickening δ E := by
rw [← cthickening_zero]
exact cthickening_eq_iInter_cthickening E
/-- The closure of a set equals the intersection of its open thickenings of positive radii
accumulating at zero. -/
theorem closure_eq_iInter_thickening' (E : Set α) (s : Set ℝ) (hs₀ : s ⊆ Ioi 0)
(hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, thickening δ E := by
rw [← cthickening_zero]
apply cthickening_eq_iInter_thickening' le_rfl _ hs₀ hs
/-- The closure of a set equals the intersection of its (open) thickenings of positive radii. -/
theorem closure_eq_iInter_thickening (E : Set α) :
closure E = ⋂ (δ : ℝ) (_ : 0 < δ), thickening δ E := by
rw [← cthickening_zero]
exact cthickening_eq_iInter_thickening rfl.ge E
/-- The frontier of the closed thickening of a set is contained in an `EMetric.infEdist` level
set. -/
theorem frontier_cthickening_subset (E : Set α) {δ : ℝ} :
frontier (cthickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } :=
frontier_le_subset_eq continuous_infEdist continuous_const
/-- The closed ball of radius `δ` centered at a point of `E` is included in the closed
thickening of `E`. -/
theorem closedBall_subset_cthickening {α : Type*} [PseudoMetricSpace α] {x : α} {E : Set α}
(hx : x ∈ E) (δ : ℝ) : closedBall x δ ⊆ cthickening δ E := by
refine (closedBall_subset_cthickening_singleton _ _).trans (cthickening_subset_of_subset _ ?_)
simpa using hx
theorem cthickening_subset_iUnion_closedBall_of_lt {α : Type*} [PseudoMetricSpace α] (E : Set α)
{δ δ' : ℝ} (hδ₀ : 0 < δ') (hδδ' : δ < δ') : cthickening δ E ⊆ ⋃ x ∈ E, closedBall x δ' := by
refine (cthickening_subset_thickening' hδ₀ hδδ' E).trans fun x hx => ?_
obtain ⟨y, hy₁, hy₂⟩ := mem_thickening_iff.mp hx
exact mem_iUnion₂.mpr ⟨y, hy₁, hy₂.le⟩
/-- The closed thickening of a compact set `E` is the union of the balls `Metric.closedBall x δ`
over `x ∈ E`.
See also `Metric.cthickening_eq_biUnion_closedBall`. -/
theorem _root_.IsCompact.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α]
{δ : ℝ} {E : Set α} (hE : IsCompact E) (hδ : 0 ≤ δ) :
cthickening δ E = ⋃ x ∈ E, closedBall x δ := by
rcases eq_empty_or_nonempty E with (rfl | hne)
· simp only [cthickening_empty, biUnion_empty]
refine Subset.antisymm (fun x hx ↦ ?_)
(iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _)
obtain ⟨y, yE, hy⟩ : ∃ y ∈ E, infEdist x E = edist x y := hE.exists_infEdist_eq_edist hne _
have D1 : edist x y ≤ ENNReal.ofReal δ := (le_of_eq hy.symm).trans hx
have D2 : dist x y ≤ δ := by
rw [edist_dist] at D1
exact (ENNReal.ofReal_le_ofReal_iff hδ).1 D1
exact mem_biUnion yE D2
theorem cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] [ProperSpace α]
(E : Set α) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ closure E, closedBall x δ := by
rcases eq_empty_or_nonempty E with (rfl | hne)
· simp only [cthickening_empty, biUnion_empty, closure_empty]
rw [← cthickening_closure]
refine Subset.antisymm (fun x hx ↦ ?_)
(iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _)
obtain ⟨y, yE, hy⟩ : ∃ y ∈ closure E, infDist x (closure E) = dist x y :=
isClosed_closure.exists_infDist_eq_dist (closure_nonempty_iff.mpr hne) x
replace hy : dist x y ≤ δ :=
(ENNReal.ofReal_le_ofReal_iff hδ).mp
(((congr_arg ENNReal.ofReal hy.symm).le.trans ENNReal.ofReal_toReal_le).trans hx)
exact mem_biUnion yE hy
nonrec theorem _root_.IsClosed.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α]
[ProperSpace α] {E : Set α} (hE : IsClosed E) (hδ : 0 ≤ δ) :
cthickening δ E = ⋃ x ∈ E, closedBall x δ := by
rw [cthickening_eq_biUnion_closedBall E hδ, hE.closure_eq]
/-- For the equality, see `infEdist_cthickening`. -/
theorem infEdist_le_infEdist_cthickening_add :
infEdist x s ≤ infEdist x (cthickening δ s) + ENNReal.ofReal δ := by
refine le_of_forall_lt' fun r h => ?_
simp_rw [← lt_tsub_iff_right, infEdist_lt_iff, mem_cthickening_iff] at h
obtain ⟨y, hy, hxy⟩ := h
exact infEdist_le_edist_add_infEdist.trans_lt
((ENNReal.add_lt_add_of_lt_of_le (hy.trans_lt ENNReal.ofReal_lt_top).ne hxy hy).trans_eq
(tsub_add_cancel_of_le <| le_self_add.trans (lt_tsub_iff_left.1 hxy).le))
/-- For the equality, see `infEdist_thickening`. -/
theorem infEdist_le_infEdist_thickening_add :
infEdist x s ≤ infEdist x (thickening δ s) + ENNReal.ofReal δ :=
infEdist_le_infEdist_cthickening_add.trans <|
add_le_add_right (infEdist_anti <| thickening_subset_cthickening _ _) _
/-- For the equality, see `thickening_thickening`. -/
@[simp]
theorem thickening_thickening_subset (ε δ : ℝ) (s : Set α) :
thickening ε (thickening δ s) ⊆ thickening (ε + δ) s := by
obtain hε | hε := le_total ε 0
· simp only [thickening_of_nonpos hε, empty_subset]
obtain hδ | hδ := le_total δ 0
· simp only [thickening_of_nonpos hδ, thickening_empty, empty_subset]
intro x
simp_rw [mem_thickening_iff_exists_edist_lt, ENNReal.ofReal_add hε hδ]
exact fun ⟨y, ⟨z, hz, hy⟩, hx⟩ =>
⟨z, hz, (edist_triangle _ _ _).trans_lt <| ENNReal.add_lt_add hx hy⟩
/-- For the equality, see `thickening_cthickening`. -/
@[simp]
theorem thickening_cthickening_subset (ε : ℝ) (hδ : 0 ≤ δ) (s : Set α) :
thickening ε (cthickening δ s) ⊆ thickening (ε + δ) s := by
obtain hε | hε := le_total ε 0
· simp only [thickening_of_nonpos hε, empty_subset]
intro x
simp_rw [mem_thickening_iff_exists_edist_lt, mem_cthickening_iff, ← infEdist_lt_iff,
ENNReal.ofReal_add hε hδ]
rintro ⟨y, hy, hxy⟩
exact infEdist_le_edist_add_infEdist.trans_lt
(ENNReal.add_lt_add_of_lt_of_le (hy.trans_lt ENNReal.ofReal_lt_top).ne hxy hy)
/-- For the equality, see `cthickening_thickening`. -/
@[simp]
theorem cthickening_thickening_subset (hε : 0 ≤ ε) (δ : ℝ) (s : Set α) :
cthickening ε (thickening δ s) ⊆ cthickening (ε + δ) s := by
obtain hδ | hδ := le_total δ 0
· simp only [thickening_of_nonpos hδ, cthickening_empty, empty_subset]
intro x
simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ]
exact fun hx => infEdist_le_infEdist_thickening_add.trans (add_le_add_right hx _)
| /-- For the equality, see `cthickening_cthickening`. -/
@[simp]
theorem cthickening_cthickening_subset (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (s : Set α) :
cthickening ε (cthickening δ s) ⊆ cthickening (ε + δ) s := by
intro x
simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ]
exact fun hx => infEdist_le_infEdist_cthickening_add.trans (add_le_add_right hx _)
open scoped Function in -- required for scoped `on` notation
theorem frontier_cthickening_disjoint (A : Set α) :
Pairwise (Disjoint on fun r : ℝ≥0 => frontier (cthickening r A)) := fun r₁ r₂ hr =>
((disjoint_singleton.2 <| by simpa).preimage _).mono (frontier_cthickening_subset _)
(frontier_cthickening_subset _)
| Mathlib/Topology/MetricSpace/Thickening.lean | 619 | 631 |
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Finset.Basic
import Mathlib.ModelTheory.Syntax
import Mathlib.Data.List.ProdSigma
/-!
# Basics on First-Order Semantics
This file defines the interpretations of first-order terms, formulas, sentences, and theories
in a style inspired by the [Flypitch project](https://flypitch.github.io/).
## Main Definitions
- `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at
variables `v`.
- `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded
formula `φ` evaluated at tuples of variables `v` and `xs`.
- `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ`
evaluated at variables `v`.
- `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ`
evaluated in the structure `M`. Also denoted `M ⊨ φ`.
- `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every
sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`.
## Main Results
- Several results in this file show that syntactic constructions such as `relabel`, `castLE`,
`liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas,
sentences, and theories.
## Implementation Notes
- Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder Cardinal
open Structure Cardinal Fin
namespace Term
/-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/
def realize (v : α → M) : ∀ _t : L.Term α, M
| var k => v k
| func f ts => funMap f fun i => (ts i).realize v
@[simp]
theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl
@[simp]
theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) :
realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl
@[simp]
theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} :
(t.relabel g).realize v = t.realize (v ∘ g) := by
induction t with
| var => rfl
| func f ts ih => simp [ih]
@[simp]
theorem realize_liftAt {n n' m : ℕ} {t : L.Term (α ⊕ (Fin n))} {v : α ⊕ (Fin (n + n')) → M} :
(t.liftAt n' m).realize v =
t.realize (v ∘ Sum.map id fun i : Fin _ =>
if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') :=
realize_relabel
@[simp]
theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c :=
funMap_eq_coe_constants
@[simp]
theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} :
(f.apply₁ t).realize v = funMap f ![t.realize v] := by
rw [Functions.apply₁, Term.realize]
refine congr rfl (funext fun i => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} :
(f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by
rw [Functions.apply₂, Term.realize]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a :=
rfl
@[simp]
theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} :
(t.subst tf).realize v = t.realize fun a => (tf a).realize v := by
induction t with
| var => rfl
| func _ _ ih => simp [ih]
theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {f : t.varFinset → β}
{v : β → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) :
(t.restrictVar f).realize v = t.realize v' := by
induction t with
| var => simp [restrictVar, hv']
| func _ _ ih =>
exact congr rfl (funext fun i => ih i ((by simp [Function.comp_apply, hv'])))
/-- A special case of `realize_restrictVar`, included because we can add the `simp` attribute
to it -/
@[simp]
theorem realize_restrictVar' [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s)
{v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v :=
realize_restrictVar _ (by simp)
theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)}
{f : t.varFinsetLeft → β}
{xs : β ⊕ γ → M} (xs' : α → M) (hxs' : ∀ a, xs (Sum.inl (f a)) = xs' a) :
(t.restrictVarLeft f).realize xs = t.realize (Sum.elim xs' (xs ∘ Sum.inr)) := by
induction t with
| var a => cases a <;> simp [restrictVarLeft, hxs']
| func _ _ ih =>
exact congr rfl (funext fun i => ih i (by simp [hxs']))
/-- A special case of `realize_restrictVarLeft`, included because we can add the `simp` attribute
to it -/
@[simp]
theorem realize_restrictVarLeft' [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {s : Set α}
(h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} :
(t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) =
t.realize (Sum.elim v xs) :=
realize_restrictVarLeft _ (by simp)
@[simp]
theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L[[α]].Term β} {v : β → M} :
t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by
induction t with
| var => simp
| @func n f ts ih =>
cases n
· cases f
· simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
· simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants]
rfl
· obtain - | f := f
· simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
· exact isEmptyElim f
@[simp]
theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L.Term (α ⊕ β)} {v : β → M} :
t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by
induction t with
| var ab => rcases ab with a | b <;> simp [Language.con]
| func f ts ih =>
simp only [realize, constantsOn, constantsOnFunc, ih, varsToConstants]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
theorem realize_constantsVarsEquivLeft [L[[α]].Structure M]
[(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (β ⊕ (Fin n))} {v : β → M}
{xs : Fin n → M} :
(constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) =
t.realize (Sum.elim v xs) := by
simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply,
constantsVarsEquiv_apply, relabelEquiv_symm_apply]
refine _root_.trans ?_ realize_constantsToVars
rcongr x
rcases x with (a | (b | i)) <;> simp
end Term
namespace LHom
@[simp]
theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α)
(v : α → M) : (φ.onTerm t).realize v = t.realize v := by
induction t with
| var => rfl
| func f ts ih => simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih]
end LHom
@[simp]
theorem HomClass.realize_term {F : Type*} [FunLike F M N] [HomClass L F M N]
(g : F) {t : L.Term α} {v : α → M} :
t.realize (g ∘ v) = g (t.realize v) := by
induction t
· rfl
· rw [Term.realize, Term.realize, HomClass.map_fun]
refine congr rfl ?_
ext x
simp [*]
variable {n : ℕ}
namespace BoundedFormula
open Term
/-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/
def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop
| _, falsum, _v, _xs => False
| _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs)
| _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs)
| _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs
| _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x)
variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ}
variable {v : α → M} {xs : Fin l → M}
@[simp]
theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False :=
Iff.rfl
@[simp]
theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs :=
Iff.rfl
@[simp]
theorem realize_bdEqual (t₁ t₂ : L.Term (α ⊕ (Fin l))) :
(t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) :=
Iff.rfl
@[simp]
theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by simp [Top.top]
@[simp]
theorem realize_inf : (φ ⊓ ψ).Realize v xs ↔ φ.Realize v xs ∧ ψ.Realize v xs := by
simp [Inf.inf, Realize]
@[simp]
theorem realize_foldr_inf (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊓ ·) ⊤).Realize v xs ↔ ∀ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp [ih]
@[simp]
theorem realize_imp : (φ.imp ψ).Realize v xs ↔ φ.Realize v xs → ψ.Realize v xs := by
simp only [Realize]
@[simp]
theorem realize_rel {k : ℕ} {R : L.Relations k} {ts : Fin k → L.Term _} :
(R.boundedFormula ts).Realize v xs ↔ RelMap R fun i => (ts i).realize (Sum.elim v xs) :=
Iff.rfl
@[simp]
theorem realize_rel₁ {R : L.Relations 1} {t : L.Term _} :
(R.boundedFormula₁ t).Realize v xs ↔ RelMap R ![t.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₁, realize_rel, iff_eq_eq]
refine congr rfl (funext fun _ => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_rel₂ {R : L.Relations 2} {t₁ t₂ : L.Term _} :
(R.boundedFormula₂ t₁ t₂).Realize v xs ↔
RelMap R ![t₁.realize (Sum.elim v xs), t₂.realize (Sum.elim v xs)] := by
rw [Relations.boundedFormula₂, realize_rel, iff_eq_eq]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
@[simp]
theorem realize_sup : (φ ⊔ ψ).Realize v xs ↔ φ.Realize v xs ∨ ψ.Realize v xs := by
simp only [realize, max, realize_not, eq_iff_iff]
tauto
@[simp]
theorem realize_foldr_sup (l : List (L.BoundedFormula α n)) (v : α → M) (xs : Fin n → M) :
(l.foldr (· ⊔ ·) ⊥).Realize v xs ↔ ∃ φ ∈ l, BoundedFormula.Realize φ v xs := by
induction' l with φ l ih
· simp
· simp_rw [List.foldr_cons, realize_sup, ih, List.mem_cons, or_and_right, exists_or,
exists_eq_left]
@[simp]
theorem realize_all : (all θ).Realize v xs ↔ ∀ a : M, θ.Realize v (Fin.snoc xs a) :=
Iff.rfl
@[simp]
theorem realize_ex : θ.ex.Realize v xs ↔ ∃ a : M, θ.Realize v (Fin.snoc xs a) := by
rw [BoundedFormula.ex, realize_not, realize_all, not_forall]
simp_rw [realize_not, Classical.not_not]
@[simp]
theorem realize_iff : (φ.iff ψ).Realize v xs ↔ (φ.Realize v xs ↔ ψ.Realize v xs) := by
simp only [BoundedFormula.iff, realize_inf, realize_imp, and_imp, ← iff_def]
theorem realize_castLE_of_eq {m n : ℕ} (h : m = n) {h' : m ≤ n} {φ : L.BoundedFormula α m}
{v : α → M} {xs : Fin n → M} : (φ.castLE h').Realize v xs ↔ φ.Realize v (xs ∘ Fin.cast h) := by
subst h
simp only [castLE_rfl, cast_refl, OrderIso.coe_refl, Function.comp_id]
theorem realize_mapTermRel_id [L'.Structure M]
{ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin n))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n} {v : α → M}
{v' : β → M} {xs : Fin n → M}
(h1 :
∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs : Fin n → M),
(ft n t).realize (Sum.elim v' xs) = t.realize (Sum.elim v xs))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x) :
(φ.mapTermRel ft fr fun _ => id).Realize v' xs ↔ φ.Realize v xs := by
induction φ with
| falsum => rfl
| equal => simp [mapTermRel, Realize, h1]
| rel => simp [mapTermRel, Realize, h1, h2]
| imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2]
| all _ ih => simp only [mapTermRel, Realize, ih, id]
theorem realize_mapTermRel_add_castLe [L'.Structure M] {k : ℕ}
{ft : ∀ n, L.Term (α ⊕ (Fin n)) → L'.Term (β ⊕ (Fin (k + n)))}
{fr : ∀ n, L.Relations n → L'.Relations n} {n} {φ : L.BoundedFormula α n}
(v : ∀ {n}, (Fin (k + n) → M) → α → M) {v' : β → M} (xs : Fin (k + n) → M)
(h1 :
∀ (n) (t : L.Term (α ⊕ (Fin n))) (xs' : Fin (k + n) → M),
(ft n t).realize (Sum.elim v' xs') = t.realize (Sum.elim (v xs') (xs' ∘ Fin.natAdd _)))
(h2 : ∀ (n) (R : L.Relations n) (x : Fin n → M), RelMap (fr n R) x = RelMap R x)
(hv : ∀ (n) (xs : Fin (k + n) → M) (x : M), @v (n + 1) (snoc xs x : Fin _ → M) = v xs) :
(φ.mapTermRel ft fr fun _ => castLE (add_assoc _ _ _).symm.le).Realize v' xs ↔
φ.Realize (v xs) (xs ∘ Fin.natAdd _) := by
induction φ with
| falsum => rfl
| equal => simp [mapTermRel, Realize, h1]
| rel => simp [mapTermRel, Realize, h1, h2]
| imp _ _ ih1 ih2 => simp [mapTermRel, Realize, ih1, ih2]
| all _ ih => simp [mapTermRel, Realize, ih, hv]
@[simp]
theorem realize_relabel {m n : ℕ} {φ : L.BoundedFormula α n} {g : α → β ⊕ (Fin m)} {v : β → M}
{xs : Fin (m + n) → M} :
(φ.relabel g).Realize v xs ↔
φ.Realize (Sum.elim v (xs ∘ Fin.castAdd n) ∘ g) (xs ∘ Fin.natAdd m) := by
apply realize_mapTermRel_add_castLe <;> simp
theorem realize_liftAt {n n' m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + n') → M}
(hmn : m + n' ≤ n + 1) :
(φ.liftAt n' m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := by
rw [liftAt]
induction φ with
| falsum => simp [mapTermRel, Realize]
| equal => simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
| rel => simp [mapTermRel, Realize, realize_rel, realize_liftAt, Sum.elim_comp_map]
| imp _ _ ih1 ih2 => simp only [mapTermRel, Realize, ih1 hmn, ih2 hmn]
| @all k _ ih3 =>
have h : k + 1 + n' = k + n' + 1 := by rw [add_assoc, add_comm 1 n', ← add_assoc]
simp only [mapTermRel, Realize, realize_castLE_of_eq h, ih3 (hmn.trans k.succ.le_succ)]
refine forall_congr' fun x => iff_eq_eq.mpr (congr rfl (funext (Fin.lastCases ?_ fun i => ?_)))
· simp only [Function.comp_apply, val_last, snoc_last]
refine (congr rfl (Fin.ext ?_)).trans (snoc_last _ _)
split_ifs <;> dsimp; omega
· simp only [Function.comp_apply, Fin.snoc_castSucc]
refine (congr rfl (Fin.ext ?_)).trans (snoc_castSucc _ _ _)
simp only [coe_castSucc, coe_cast]
split_ifs <;> simp
theorem realize_liftAt_one {n m : ℕ} {φ : L.BoundedFormula α n} {v : α → M} {xs : Fin (n + 1) → M}
(hmn : m ≤ n) :
(φ.liftAt 1 m).Realize v xs ↔
φ.Realize v (xs ∘ fun i => if ↑i < m then castSucc i else i.succ) := by
simp [realize_liftAt (add_le_add_right hmn 1), castSucc]
@[simp]
theorem realize_liftAt_one_self {n : ℕ} {φ : L.BoundedFormula α n} {v : α → M}
{xs : Fin (n + 1) → M} : (φ.liftAt 1 n).Realize v xs ↔ φ.Realize v (xs ∘ castSucc) := by
rw [realize_liftAt_one (refl n), iff_eq_eq]
| refine congr rfl (congr rfl (funext fun i => ?_))
rw [if_pos i.is_lt]
@[simp]
theorem realize_subst {φ : L.BoundedFormula α n} {tf : α → L.Term β} {v : β → M} {xs : Fin n → M} :
| Mathlib/ModelTheory/Semantics.lean | 396 | 400 |
/-
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.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Topology.EMetricSpace.Defs
import Mathlib.Topology.UniformSpace.Compact
import Mathlib.Topology.UniformSpace.LocallyUniformConvergence
import Mathlib.Topology.UniformSpace.UniformEmbedding
/-!
# Extended metric spaces
Further results about extended metric spaces.
-/
open Set Filter
universe u v w
variable {α : Type u} {β : Type v} {X : Type*}
open scoped Uniformity Topology NNReal ENNReal Pointwise
variable [PseudoEMetricSpace α]
/-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/
theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) :
edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by
induction n, h using Nat.le_induction with
| base => rw [Finset.Ico_self, Finset.sum_empty, edist_self]
| succ n hle ihn =>
calc
edist (f m) (f (n + 1)) ≤ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _
_ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl
_ = ∑ i ∈ Finset.Ico m (n + 1), _ := by
{ rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp }
/-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/
theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) :
edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) :=
Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (Nat.zero_le n)
/-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ≥0∞}
(hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) :
edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i :=
le_trans (edist_le_Ico_sum_edist f hmn) <|
Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2
/-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced
with an upper estimate. -/
theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞}
(hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) :
edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i :=
Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd
namespace EMetric
theorem isUniformInducing_iff [PseudoEMetricSpace β] {f : α → β} :
IsUniformInducing f ↔ UniformContinuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
isUniformInducing_iff'.trans <| Iff.rfl.and <|
((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by
simp only [subset_def, Prod.forall]; rfl
/-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/
nonrec theorem isUniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} :
IsUniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
(isUniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and isUniformInducing_iff
/-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y`.
In fact, this lemma holds for a `IsUniformInducing` map.
TODO: generalize? -/
theorem controlled_of_isUniformEmbedding [PseudoEMetricSpace β] {f : α → β}
(h : IsUniformEmbedding f) :
(∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ :=
⟨uniformContinuous_iff.1 h.uniformContinuous, (isUniformEmbedding_iff.1 h).2.2⟩
/-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/
protected theorem cauchy_iff {f : Filter α} :
Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by
rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff
/-- A very useful criterion to show that a space is complete is to show that all sequences
which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are
converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to
`0`, which makes it possible to use arguments of converging series, while this is impossible
to do in general for arbitrary Cauchy sequences. -/
theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n)
(H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) →
∃ x, Tendsto u atTop (𝓝 x)) :
CompleteSpace α :=
UniformSpace.complete_of_convergent_controlled_sequences
(fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H
/-- A sequentially complete pseudoemetric space is complete. -/
theorem complete_of_cauchySeq_tendsto :
(∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α :=
UniformSpace.complete_of_cauchySeq_tendsto
/-- Expressing locally uniform convergence on a set using `edist`. -/
theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α}
{p : Filter ι} {s : Set β} :
TendstoLocallyUniformlyOn F f p s ↔
∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by
refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩
rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩
rcases H ε εpos x hx with ⟨t, ht, Ht⟩
exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩
/-- Expressing uniform convergence on a set using `edist`. -/
theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} :
TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by
refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩
rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩
exact (H ε εpos).mono fun n hs x hx => hε (hs x hx)
/-- Expressing locally uniform convergence using `edist`. -/
theorem tendstoLocallyUniformly_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α}
{p : Filter ι} :
TendstoLocallyUniformly F f p ↔
∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by
simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, mem_univ,
forall_const, exists_prop, nhdsWithin_univ]
/-- Expressing uniform convergence using `edist`. -/
theorem tendstoUniformly_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} :
TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε := by
simp only [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff, mem_univ, forall_const]
end EMetric
open EMetric
namespace EMetric
variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α}
theorem inseparable_iff : Inseparable x y ↔ edist x y = 0 := by
simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le']
alias ⟨_root_.Inseparable.edist_eq_zero, _⟩ := EMetric.inseparable_iff
-- see Note [nolint_ge]
/-- In a pseudoemetric space, Cauchy sequences are characterized by the fact that, eventually,
the pseudoedistance between its elements is arbitrarily small -/
theorem cauchySeq_iff [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → edist (u m) (u n) < ε :=
uniformity_basis_edist.cauchySeq_iff
/-- A variation around the emetric characterization of Cauchy sequences -/
theorem cauchySeq_iff' [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ ∀ ε > (0 : ℝ≥0∞), ∃ N, ∀ n ≥ N, edist (u n) (u N) < ε :=
uniformity_basis_edist.cauchySeq_iff'
/-- A variation of the emetric characterization of Cauchy sequences that deals with
`ℝ≥0` upper bounds. -/
theorem cauchySeq_iff_NNReal [Nonempty β] [SemilatticeSup β] {u : β → α} :
CauchySeq u ↔ ∀ ε : ℝ≥0, 0 < ε → ∃ N, ∀ n, N ≤ n → edist (u n) (u N) < ε :=
uniformity_basis_edist_nnreal.cauchySeq_iff'
theorem totallyBounded_iff {s : Set α} :
TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε :=
⟨fun H _ε ε0 => H _ (edist_mem_uniformity ε0), fun H _r ru =>
let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru
let ⟨t, ft, h⟩ := H ε ε0
⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩
theorem totallyBounded_iff' {s : Set α} :
TotallyBounded s ↔ ∀ ε > 0, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε :=
⟨fun H _ε ε0 => (totallyBounded_iff_subset.1 H) _ (edist_mem_uniformity ε0), fun H _r ru =>
let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru
let ⟨t, _, ft, h⟩ := H ε ε0
⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩
section Compact
-- TODO: generalize to metrizable spaces
/-- A compact set in a pseudo emetric space is separable, i.e., it is a subset of the closure of a
countable set. -/
theorem subset_countable_closure_of_compact {s : Set α} (hs : IsCompact s) :
∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by
refine subset_countable_closure_of_almost_dense_set s fun ε hε => ?_
rcases totallyBounded_iff'.1 hs.totallyBounded ε hε with ⟨t, -, htf, hst⟩
exact ⟨t, htf.countable, hst.trans <| iUnion₂_mono fun _ _ => ball_subset_closedBall⟩
end Compact
section SecondCountable
open TopologicalSpace
variable (α) in
/-- A sigma compact pseudo emetric space has second countable topology. -/
instance (priority := 90) secondCountable_of_sigmaCompact [SigmaCompactSpace α] :
SecondCountableTopology α := by
suffices SeparableSpace α by exact UniformSpace.secondCountable_of_separable α
choose T _ hTc hsubT using fun n =>
subset_countable_closure_of_compact (isCompact_compactCovering α n)
refine ⟨⟨⋃ n, T n, countable_iUnion hTc, fun x => ?_⟩⟩
rcases iUnion_eq_univ_iff.1 (iUnion_compactCovering α) x with ⟨n, hn⟩
exact closure_mono (subset_iUnion _ n) (hsubT _ hn)
theorem secondCountable_of_almost_dense_set
(hs : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ ⋃ x ∈ t, closedBall x ε = univ) :
SecondCountableTopology α := by
suffices SeparableSpace α from UniformSpace.secondCountable_of_separable α
have : ∀ ε > 0, ∃ t : Set α, Set.Countable t ∧ univ ⊆ ⋃ x ∈ t, closedBall x ε := by
simpa only [univ_subset_iff] using hs
rcases subset_countable_closure_of_almost_dense_set (univ : Set α) this with ⟨t, -, htc, ht⟩
exact ⟨⟨t, htc, fun x => ht (mem_univ x)⟩⟩
end SecondCountable
end EMetric
variable {γ : Type w} [EMetricSpace γ]
-- see Note [lower instance priority]
/-- An emetric space is separated -/
instance (priority := 100) EMetricSpace.instT0Space : T0Space γ where
t0 _ _ h := eq_of_edist_eq_zero <| inseparable_iff.1 h
/-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x`
and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/
theorem EMetric.isUniformEmbedding_iff' [PseudoEMetricSpace β] {f : γ → β} :
IsUniformEmbedding f ↔
(∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, edist a b < δ → edist (f a) (f b) < ε) ∧
∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, edist (f a) (f b) < ε → edist a b < δ := by
rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff]
/-- If a `PseudoEMetricSpace` is a T₀ space, then it is an `EMetricSpace`. -/
-- TODO: make it an instance?
abbrev EMetricSpace.ofT0PseudoEMetricSpace (α : Type*) [PseudoEMetricSpace α] [T0Space α] :
EMetricSpace α :=
{ ‹PseudoEMetricSpace α› with
eq_of_edist_eq_zero := fun h => (EMetric.inseparable_iff.2 h).eq }
/-- The product of two emetric spaces, with the max distance, is an extended
metric spaces. We make sure that the uniform structure thus constructed is the one
corresponding to the product of uniform spaces, to avoid diamond problems. -/
instance Prod.emetricSpaceMax [EMetricSpace β] : EMetricSpace (γ × β) :=
.ofT0PseudoEMetricSpace _
namespace EMetric
/-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set. -/
theorem countable_closure_of_compact {s : Set γ} (hs : IsCompact s) :
∃ t, t ⊆ s ∧ t.Countable ∧ s = closure t := by
rcases subset_countable_closure_of_compact hs with ⟨t, hts, htc, hsub⟩
exact ⟨t, hts, htc, hsub.antisymm (closure_minimal hts hs.isClosed)⟩
end EMetric
/-!
### Separation quotient
-/
instance [PseudoEMetricSpace X] : EDist (SeparationQuotient X) where
edist := SeparationQuotient.lift₂ edist fun _ _ _ _ hx hy =>
edist_congr (EMetric.inseparable_iff.1 hx) (EMetric.inseparable_iff.1 hy)
@[simp] theorem SeparationQuotient.edist_mk [PseudoEMetricSpace X] (x y : X) :
edist (mk x) (mk y) = edist x y :=
rfl
open SeparationQuotient in
instance [PseudoEMetricSpace X] : EMetricSpace (SeparationQuotient X) :=
@EMetricSpace.ofT0PseudoEMetricSpace (SeparationQuotient X)
{ edist_self := surjective_mk.forall.2 edist_self,
edist_comm := surjective_mk.forall₂.2 edist_comm,
edist_triangle := surjective_mk.forall₃.2 edist_triangle,
toUniformSpace := inferInstance,
uniformity_edist := comap_injective (surjective_mk.prodMap surjective_mk) <| by
simp [comap_mk_uniformity, PseudoEMetricSpace.uniformity_edist] } _
namespace TopologicalSpace
section Compact
open Topology
/-- If a set `s` is separable in a (pseudo extended) metric space, then it admits a countable dense
subset. This is not obvious, as the countable set whose closure covers `s` given by the definition
of separability does not need in general to be contained in `s`. -/
theorem IsSeparable.exists_countable_dense_subset
{s : Set α} (hs : IsSeparable s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by
have : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ s ⊆ ⋃ x ∈ t, closedBall x ε := fun ε ε0 => by
rcases hs with ⟨t, htc, hst⟩
refine ⟨t, htc, hst.trans fun x hx => ?_⟩
rcases mem_closure_iff.1 hx ε ε0 with ⟨y, hyt, hxy⟩
exact mem_iUnion₂.2 ⟨y, hyt, mem_closedBall.2 hxy.le⟩
exact subset_countable_closure_of_almost_dense_set _ this
/-- If a set `s` is separable, then the corresponding subtype is separable in a (pseudo extended)
metric space. This is not obvious, as the countable set whose closure covers `s` does not need in
general to be contained in `s`. -/
theorem IsSeparable.separableSpace {s : Set α} (hs : IsSeparable s) :
SeparableSpace s := by
rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, hst⟩
lift t to Set s using hts
refine ⟨⟨t, countable_of_injective_of_countable_image Subtype.coe_injective.injOn htc, ?_⟩⟩
rwa [IsInducing.subtypeVal.dense_iff, Subtype.forall]
end Compact
end TopologicalSpace
section LebesgueNumberLemma
variable {s : Set α}
theorem lebesgue_number_lemma_of_emetric {ι : Sort*} {c : ι → Set α} (hs : IsCompact s)
(hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma hs hc₁ hc₂
theorem lebesgue_number_lemma_of_emetric_nhds' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s)
(hc : ∀ x hx, c x hx ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ⊆ c y y.2 := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhds' hs hc
theorem lebesgue_number_lemma_of_emetric_nhds {c : α → Set α} (hs : IsCompact s)
(hc : ∀ x ∈ s, c x ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ⊆ c y := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhds hs hc
theorem lebesgue_number_lemma_of_emetric_nhdsWithin' {c : (x : α) → x ∈ s → Set α}
(hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝[s] x) :
∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ∩ s ⊆ c y y.2 := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin' hs hc
theorem lebesgue_number_lemma_of_emetric_nhdsWithin {c : α → Set α} (hs : IsCompact s)
(hc : ∀ x ∈ s, c x ∈ 𝓝[s] x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ∩ s ⊆ c y := by
simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm]
using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin hs hc
theorem lebesgue_number_lemma_of_emetric_sUnion {c : Set (Set α)} (hs : IsCompact s)
(hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t := by
rw [sUnion_eq_iUnion] at hc₂; simpa using lebesgue_number_lemma_of_emetric hs (by simpa) hc₂
end LebesgueNumberLemma
| Mathlib/Topology/EMetricSpace/Basic.lean | 702 | 703 | |
/-
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, Eric Wieser, Joachim Breitner
-/
import Mathlib.GroupTheory.FreeGroup.Basic
/-!
# Free groups structures on arbitrary types
This file defines the notion of free basis of a group, which induces an isomorphism between the
group and the free group generated by the basis.
It also introduced a type class for groups which are free groups, i.e., for which some free basis
exists.
For the explicit construction of free groups, see `GroupTheory/FreeGroup`.
## Main definitions
* `FreeGroupBasis ι G` : a function from `ι` to `G` such that `G` is free over its image.
Equivalently, an isomorphism between `G` and `FreeGroup ι`.
* `IsFreeGroup G` : a typeclass to indicate that `G` is free over some generators
* `Generators G` : given a group satisfying `IsFreeGroup G`, some indexing type over
which `G` is free.
* `IsFreeGroup.of` : the canonical injection of `G`'s generators into `G`
* `IsFreeGroup.lift` : the universal property of the free group
## Main results
* `FreeGroupBasis.isFreeGroup`: a group admitting a free group basis is free.
* `IsFreeGroup.toFreeGroup`: any free group with generators `A` is equivalent to `FreeGroup A`.
* `IsFreeGroup.unique_lift`: the universal property of a free group.
* `FreeGroupBasis.ofUniqueLift`: a group satisfying the universal property of a free group admits
a free group basis.
-/
universe u
open Function Set
noncomputable section
/-- A free group basis `FreeGroupBasis ι G` is a structure recording the isomorphism between a
group `G` and the free group over `ι`. One may think of such a basis as a function from `ι` to `G`
(which is registered through a `FunLike` instance) together with the fact that the morphism induced
by this function from `FreeGroup ι` to `G` is an isomorphism. -/
structure FreeGroupBasis (ι : Type*) (G : Type*) [Group G] where
/-- `FreeGroupBasis.ofRepr` constructs a basis given an equivalence with a free group. -/
ofRepr ::
/-- `repr` is the isomorphism between the group `G` and the free group generated by `ι`. -/
repr : G ≃* FreeGroup ι
/-- A group is free if it admits a free group basis. In the definition, we require the basis to
be in the same universe as `G`, although this property follows from the existence of a basis in
any universe, see `FreeGroupBasis.isFreeGroup`. -/
class IsFreeGroup (G : Type u) [Group G] : Prop where
nonempty_basis : ∃ (ι : Type u), Nonempty (FreeGroupBasis ι G)
namespace FreeGroupBasis
variable {ι ι' G H : Type*} [Group G] [Group H]
/-- A free group basis for `G` over `ι` is associated to a map `ι → G` recording the images of
the generators. -/
instance instFunLike : FunLike (FreeGroupBasis ι G) ι G where
coe b := fun i ↦ b.repr.symm (FreeGroup.of i)
coe_injective' := by
rintro ⟨b⟩ ⟨b'⟩ hbb'
have H : (b.symm : FreeGroup ι →* G) = (b'.symm : FreeGroup ι →* G) := by
ext i; exact congr_fun hbb' i
have : b.symm = b'.symm := by ext x; exact DFunLike.congr_fun H x
rw [ofRepr.injEq, ← MulEquiv.symm_symm b, ← MulEquiv.symm_symm b', this]
@[simp] lemma repr_apply_coe (b : FreeGroupBasis ι G) (i : ι) : b.repr (b i) = FreeGroup.of i := by
change b.repr (b.repr.symm (FreeGroup.of i)) = FreeGroup.of i
simp
/-- The canonical basis of the free group over `X`. -/
def ofFreeGroup (X : Type*) : FreeGroupBasis X (FreeGroup X) := ofRepr (MulEquiv.refl _)
@[simp] lemma ofFreeGroup_apply {X : Type*} (x : X) :
FreeGroupBasis.ofFreeGroup X x = FreeGroup.of x :=
rfl
/-- Reindex a free group basis through a bijection of the indexing sets. -/
protected def reindex (b : FreeGroupBasis ι G) (e : ι ≃ ι') : FreeGroupBasis ι' G :=
ofRepr (b.repr.trans (FreeGroup.freeGroupCongr e))
@[simp] lemma reindex_apply (b : FreeGroupBasis ι G) (e : ι ≃ ι') (x : ι') :
b.reindex e x = b (e.symm x) := rfl
/-- Pushing a free group basis through a group isomorphism. -/
protected def map (b : FreeGroupBasis ι G) (e : G ≃* H) : FreeGroupBasis ι H :=
ofRepr (e.symm.trans b.repr)
@[simp] lemma map_apply (b : FreeGroupBasis ι G) (e : G ≃* H) (x : ι) :
b.map e x = e (b x) := rfl
protected lemma injective (b : FreeGroupBasis ι G) : Injective b :=
b.repr.symm.injective.comp FreeGroup.of_injective
/-- A group admitting a free group basis is a free group. -/
lemma isFreeGroup (b : FreeGroupBasis ι G) : IsFreeGroup G :=
⟨range b, ⟨b.reindex (Equiv.ofInjective (↑b) b.injective)⟩⟩
instance (X : Type*) : IsFreeGroup (FreeGroup X) :=
(ofFreeGroup X).isFreeGroup
/-- Given a free group basis of `G` over `ι`, there is a canonical bijection between maps from `ι`
to a group `H` and morphisms from `G` to `H`. -/
@[simps!]
def lift (b : FreeGroupBasis ι G) : (ι → H) ≃ (G →* H) :=
FreeGroup.lift.trans
{ toFun := fun f => f.comp b.repr.toMonoidHom
invFun := fun f => f.comp b.repr.symm.toMonoidHom
left_inv := fun f => by
ext
simp
right_inv := fun f => by
ext
simp }
/-- If two morphisms on `G` coincide on the elements of a basis, then they coincide. -/
lemma ext_hom (b : FreeGroupBasis ι G) (f g : G →* H) (h : ∀ i, f (b i) = g (b i)) : f = g :=
b.lift.symm.injective <| funext h
/-- If a group satisfies the universal property of a free group with respect to a given type, then
it admits a free group basis based on this type. Here, the universal property is expressed as
in `IsFreeGroup.lift` and its properties. -/
def ofLift {G : Type u} [Group G] (X : Type u) (of : X → G)
(lift : ∀ {H : Type u} [Group H], (X → H) ≃ (G →* H))
(lift_of : ∀ {H : Type u} [Group H], ∀ (f : X → H) (a), lift f (of a) = f a) :
FreeGroupBasis X G where
repr := MulEquiv.symm <| MonoidHom.toMulEquiv (FreeGroup.lift of) (lift FreeGroup.of)
(by
apply FreeGroup.ext_hom; intro x
simp only [MonoidHom.coe_comp, Function.comp_apply, MonoidHom.id_apply, FreeGroup.lift.of,
lift_of])
(by
let lift_symm_of : ∀ {H : Type u} [Group H], ∀ (f : G →* H) (a), lift.symm f a = f (of a) :=
by intro H _ f a; simp [← lift_of (lift.symm f)]
apply lift.symm.injective; ext x
simp only [MonoidHom.coe_comp, Function.comp_apply, MonoidHom.id_apply, FreeGroup.lift.of,
lift_of, lift_symm_of])
/-- If a group satisfies the universal property of a free group with respect to a given type, then
it admits a free group basis based on this type. Here
the universal property is expressed as in `IsFreeGroup.unique_lift`. -/
def ofUniqueLift {G : Type u} [Group G] (X : Type u) (of : X → G)
(h : ∀ {H : Type u} [Group H] (f : X → H), ∃! F : G →* H, ∀ a, F (of a) = f a) :
FreeGroupBasis X G :=
let lift {H : Type u} [Group H] : (X → H) ≃ (G →* H) :=
{ toFun := fun f => Classical.choose (h f)
invFun := fun F => F ∘ of
left_inv := fun f => funext (Classical.choose_spec (h f)).left
right_inv := fun F => ((Classical.choose_spec (h (F ∘ of))).right F fun _ => rfl).symm }
let lift_of {H : Type u} [Group H] (f : X → H) (a : X) : lift f (of a) = f a :=
congr_fun (lift.symm_apply_apply f) a
ofLift X of @lift @lift_of
end FreeGroupBasis
namespace IsFreeGroup
variable (G : Type*) [Group G] [IsFreeGroup G]
/-- A set of generators of a free group, chosen arbitrarily -/
def Generators : Type _ := (IsFreeGroup.nonempty_basis (G := G)).choose
/-- Any free group is isomorphic to "the" free group. -/
irreducible_def mulEquiv : FreeGroup (Generators G) ≃* G :=
(IsFreeGroup.nonempty_basis (G := G)).choose_spec.some.repr.symm
/-- A free group basis of a free group `G`, over the set `Generators G`. -/
def basis : FreeGroupBasis (Generators G) G := FreeGroupBasis.ofRepr (mulEquiv G).symm
/-- Any free group is isomorphic to "the" free group. -/
@[simps!]
def toFreeGroup : G ≃* FreeGroup (Generators G) :=
(mulEquiv G).symm
variable {G}
/-- The canonical injection of G's generators into G -/
def of : Generators G → G :=
(mulEquiv G).toFun ∘ FreeGroup.of
variable {H : Type*} [Group H]
/-- The equivalence between functions on the generators and group homomorphisms from a free group
given by those generators. -/
def lift : (Generators G → H) ≃ (G →* H) :=
(basis G).lift
@[simp]
theorem lift_of (f : Generators G → H) (a : Generators G) : lift f (of a) = f a :=
congr_fun (lift.symm_apply_apply f) a
@[simp]
theorem lift_symm_apply (f : G →* H) (a : Generators G) : (lift.symm f) a = f (of a) :=
rfl
/- Do not register this as an ext lemma, as `Generators G` is not canonical. -/
theorem ext_hom ⦃f g : G →* H⦄ (h : ∀ a : Generators G, f (of a) = g (of a)) : f = g :=
lift.symm.injective (funext h)
/-- The universal property of a free group: A function from the generators of `G` to another
group extends in a unique way to a homomorphism from `G`.
Note that since `IsFreeGroup.lift` is expressed as a bijection, it already
expresses the universal property. -/
theorem unique_lift (f : Generators G → H) : ∃! F : G →* H, ∀ a, F (of a) = f a := by
simpa only [funext_iff] using lift.symm.bijective.existsUnique f
/-- If a group satisfies the universal property of a free group with respect to a given type, then
it is free. Here, the universal property is expressed as in `IsFreeGroup.lift` and its
properties. -/
lemma ofLift {G : Type u} [Group G] (X : Type u) (of : X → G)
(lift : ∀ {H : Type u} [Group H], (X → H) ≃ (G →* H))
(lift_of : ∀ {H : Type u} [Group H], ∀ (f : X → H) (a), lift f (of a) = f a) :
IsFreeGroup G :=
| (FreeGroupBasis.ofLift X of lift lift_of).isFreeGroup
| Mathlib/GroupTheory/FreeGroup/IsFreeGroup.lean | 226 | 227 |
/-
Copyright (c) 2023 Yaël Dillies, Chenyi Li. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chenyi Li, Ziyu Wang, Yaël Dillies
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.InnerProductSpace.Basic
/-!
# Uniformly and strongly convex functions
In this file, we define uniformly convex functions and strongly convex functions.
For a real normed space `E`, a uniformly convex function with modulus `φ : ℝ → ℝ` is a function
`f : E → ℝ` such that `f (t • x + (1 - t) • y) ≤ t • f x + (1 - t) • f y - t * (1 - t) * φ ‖x - y‖`
for all `t ∈ [0, 1]`.
A `m`-strongly convex function is a uniformly convex function with modulus `fun r ↦ m / 2 * r ^ 2`.
If `E` is an inner product space, this is equivalent to `x ↦ f x - m / 2 * ‖x‖ ^ 2` being convex.
## TODO
Prove derivative properties of strongly convex functions.
-/
open Real
variable {E : Type*} [NormedAddCommGroup E]
section NormedSpace
variable [NormedSpace ℝ E] {φ ψ : ℝ → ℝ} {s : Set E} {m : ℝ} {f g : E → ℝ}
/-- A function `f` from a real normed space is uniformly convex with modulus `φ` if
`f (t • x + (1 - t) • y) ≤ t • f x + (1 - t) • f y - t * (1 - t) * φ ‖x - y‖` for all `t ∈ [0, 1]`.
`φ` is usually taken to be a monotone function such that `φ r = 0 ↔ r = 0`. -/
def UniformConvexOn (s : Set E) (φ : ℝ → ℝ) (f : E → ℝ) : Prop :=
Convex ℝ s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y - a * b * φ ‖x - y‖
/-- A function `f` from a real normed space is uniformly concave with modulus `φ` if
`t • f x + (1 - t) • f y + t * (1 - t) * φ ‖x - y‖ ≤ f (t • x + (1 - t) • y)` for all `t ∈ [0, 1]`.
`φ` is usually taken to be a monotone function such that `φ r = 0 ↔ r = 0`. -/
def UniformConcaveOn (s : Set E) (φ : ℝ → ℝ) (f : E → ℝ) : Prop :=
Convex ℝ s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • f x + b • f y + a * b * φ ‖x - y‖ ≤ f (a • x + b • y)
@[simp] lemma uniformConvexOn_zero : UniformConvexOn s 0 f ↔ ConvexOn ℝ s f := by
simp [UniformConvexOn, ConvexOn]
@[simp] lemma uniformConcaveOn_zero : UniformConcaveOn s 0 f ↔ ConcaveOn ℝ s f := by
simp [UniformConcaveOn, ConcaveOn]
protected alias ⟨_, ConvexOn.uniformConvexOn_zero⟩ := uniformConvexOn_zero
protected alias ⟨_, ConcaveOn.uniformConcaveOn_zero⟩ := uniformConcaveOn_zero
lemma UniformConvexOn.mono (hψφ : ψ ≤ φ) (hf : UniformConvexOn s φ f) : UniformConvexOn s ψ f :=
⟨hf.1, fun x hx y hy a b ha hb hab ↦ (hf.2 hx hy ha hb hab).trans <| by gcongr; apply hψφ⟩
lemma UniformConcaveOn.mono (hψφ : ψ ≤ φ) (hf : UniformConcaveOn s φ f) : UniformConcaveOn s ψ f :=
⟨hf.1, fun x hx y hy a b ha hb hab ↦ (hf.2 hx hy ha hb hab).trans' <| by gcongr; apply hψφ⟩
lemma UniformConvexOn.convexOn (hf : UniformConvexOn s φ f) (hφ : 0 ≤ φ) : ConvexOn ℝ s f := by
simpa using hf.mono hφ
lemma UniformConcaveOn.concaveOn (hf : UniformConcaveOn s φ f) (hφ : 0 ≤ φ) : ConcaveOn ℝ s f := by
simpa using hf.mono hφ
lemma UniformConvexOn.strictConvexOn (hf : UniformConvexOn s φ f) (hφ : ∀ r, r ≠ 0 → 0 < φ r) :
StrictConvexOn ℝ s f := by
refine ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ (hf.2 hx hy ha.le hb.le hab).trans_lt <|
sub_lt_self _ ?_⟩
rw [← sub_ne_zero, ← norm_pos_iff] at hxy
have := hφ _ hxy.ne'
positivity
lemma UniformConcaveOn.strictConcaveOn (hf : UniformConcaveOn s φ f) (hφ : ∀ r, r ≠ 0 → 0 < φ r) :
StrictConcaveOn ℝ s f := by
refine ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ (hf.2 hx hy ha.le hb.le hab).trans_lt' <|
lt_add_of_pos_right _ ?_⟩
rw [← sub_ne_zero, ← norm_pos_iff] at hxy
have := hφ _ hxy.ne'
positivity
lemma UniformConvexOn.add (hf : UniformConvexOn s φ f) (hg : UniformConvexOn s ψ g) :
UniformConvexOn s (φ + ψ) (f + g) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩
simpa [mul_add, add_add_add_comm, sub_add_sub_comm]
using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
lemma UniformConcaveOn.add (hf : UniformConcaveOn s φ f) (hg : UniformConcaveOn s ψ g) :
UniformConcaveOn s (φ + ψ) (f + g) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩
simpa [mul_add, add_add_add_comm] using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
lemma UniformConvexOn.neg (hf : UniformConvexOn s φ f) : UniformConcaveOn s φ (-f) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ le_of_neg_le_neg ?_⟩
simpa [add_comm, -neg_le_neg_iff, le_sub_iff_add_le'] using hf.2 hx hy ha hb hab
lemma UniformConcaveOn.neg (hf : UniformConcaveOn s φ f) : UniformConvexOn s φ (-f) := by
refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ le_of_neg_le_neg ?_⟩
simpa [add_comm, -neg_le_neg_iff, ← le_sub_iff_add_le', sub_eq_add_neg, neg_add]
using hf.2 hx hy ha hb hab
lemma UniformConvexOn.sub (hf : UniformConvexOn s φ f) (hg : UniformConcaveOn s ψ g) :
UniformConvexOn s (φ + ψ) (f - g) := by simpa using hf.add hg.neg
lemma UniformConcaveOn.sub (hf : UniformConcaveOn s φ f) (hg : UniformConvexOn s ψ g) :
UniformConcaveOn s (φ + ψ) (f - g) := by simpa using hf.add hg.neg
/-- A function `f` from a real normed space is `m`-strongly convex if it is uniformly convex with
modulus `φ(r) = m / 2 * r ^ 2`.
In an inner product space, this is equivalent to `x ↦ f x - m / 2 * ‖x‖ ^ 2` being convex. -/
def StrongConvexOn (s : Set E) (m : ℝ) : (E → ℝ) → Prop :=
UniformConvexOn s fun r ↦ m / (2 : ℝ) * r ^ 2
/-- A function `f` from a real normed space is `m`-strongly concave if is strongly concave with
modulus `φ(r) = m / 2 * r ^ 2`.
In an inner product space, this is equivalent to `x ↦ f x + m / 2 * ‖x‖ ^ 2` being concave. -/
def StrongConcaveOn (s : Set E) (m : ℝ) : (E → ℝ) → Prop :=
UniformConcaveOn s fun r ↦ m / (2 : ℝ) * r ^ 2
variable {s : Set E} {f : E → ℝ} {m n : ℝ}
nonrec lemma StrongConvexOn.mono (hmn : m ≤ n) (hf : StrongConvexOn s n f) : StrongConvexOn s m f :=
hf.mono fun r ↦ by gcongr
nonrec lemma StrongConcaveOn.mono (hmn : m ≤ n) (hf : StrongConcaveOn s n f) :
StrongConcaveOn s m f := hf.mono fun r ↦ by gcongr
@[simp] lemma strongConvexOn_zero : StrongConvexOn s 0 f ↔ ConvexOn ℝ s f := by
simp [StrongConvexOn, ← Pi.zero_def]
@[simp] lemma strongConcaveOn_zero : StrongConcaveOn s 0 f ↔ ConcaveOn ℝ s f := by
simp [StrongConcaveOn, ← Pi.zero_def]
nonrec lemma StrongConvexOn.strictConvexOn (hf : StrongConvexOn s m f) (hm : 0 < m) :
StrictConvexOn ℝ s f := hf.strictConvexOn fun r hr ↦ by positivity
nonrec lemma StrongConcaveOn.strictConcaveOn (hf : StrongConcaveOn s m f) (hm : 0 < m) :
StrictConcaveOn ℝ s f := hf.strictConcaveOn fun r hr ↦ by positivity
end NormedSpace
section InnerProductSpace
variable [InnerProductSpace ℝ E] {s : Set E} {a b m : ℝ} {x y : E} {f : E → ℝ}
|
private lemma aux_sub (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
a * (f x - m / (2 : ℝ) * ‖x‖ ^ 2) + b * (f y - m / (2 : ℝ) * ‖y‖ ^ 2) +
m / (2 : ℝ) * ‖a • x + b • y‖ ^ 2
= a * f x + b * f y - m / (2 : ℝ) * a * b * ‖x - y‖ ^ 2 := by
rw [norm_add_sq_real, norm_sub_sq_real, norm_smul, norm_smul, real_inner_smul_left,
inner_smul_right, norm_of_nonneg ha, norm_of_nonneg hb, mul_pow, mul_pow]
obtain rfl := eq_sub_of_add_eq hab
| Mathlib/Analysis/Convex/Strong.lean | 150 | 157 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.