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 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Equiv
import Mathlib.Analysis.Calculus.FDeriv.Prod
import Mathlib.Analysis.Calculus.Monotone
import Mathlib.Topology.EMetricSpace.BoundedVariation
/-!
# Almost everywhere differentiability of functions with locally bounded variation
In this file we show that a bounded variation function is differentiable almost everywhere.
This implies that Lipschitz functions from the real line into finite-dimensional vector space
are also differentiable almost everywhere.
## Main definitions and results
* `LocallyBoundedVariationOn.ae_differentiableWithinAt` shows that a bounded variation
function into a finite dimensional real vector space is differentiable almost everywhere.
* `LipschitzOnWith.ae_differentiableWithinAt` is the same result for Lipschitz functions.
We also give several variations around these results.
-/
open scoped NNReal ENNReal Topology
open Set MeasureTheory Filter
variable {α : Type*} [LinearOrder α] {E : Type*} [PseudoEMetricSpace E]
/-! ## -/
variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [FiniteDimensional ℝ V]
namespace LocallyBoundedVariationOn
/-- A bounded variation function into `ℝ` is differentiable almost everywhere. Superseded by
`ae_differentiableWithinAt_of_mem`. -/
theorem ae_differentiableWithinAt_of_mem_real {f : ℝ → ℝ} {s : Set ℝ}
(h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by
obtain ⟨p, q, hp, hq, rfl⟩ : ∃ p q, MonotoneOn p s ∧ MonotoneOn q s ∧ f = p - q :=
h.exists_monotoneOn_sub_monotoneOn
filter_upwards [hp.ae_differentiableWithinAt_of_mem, hq.ae_differentiableWithinAt_of_mem] with
x hxp hxq xs
exact (hxp xs).sub (hxq xs)
/-- A bounded variation function into a finite dimensional product vector space is differentiable
almost everywhere. Superseded by `ae_differentiableWithinAt_of_mem`. -/
theorem ae_differentiableWithinAt_of_mem_pi {ι : Type*} [Fintype ι] {f : ℝ → ι → ℝ} {s : Set ℝ}
(h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by
have A : ∀ i : ι, LipschitzWith 1 fun x : ι → ℝ => x i := fun i => LipschitzWith.eval i
have : ∀ i : ι, ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ (fun x : ℝ => f x i) s x := fun i ↦ by
apply ae_differentiableWithinAt_of_mem_real
exact LipschitzWith.comp_locallyBoundedVariationOn (A i) h
filter_upwards [ae_all_iff.2 this] with x hx xs
exact differentiableWithinAt_pi.2 fun i => hx i xs
/-- A real function into a finite dimensional real vector space with bounded variation on a set
is differentiable almost everywhere in this set. -/
theorem ae_differentiableWithinAt_of_mem {f : ℝ → V} {s : Set ℝ}
(h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by
let A := (Basis.ofVectorSpace ℝ V).equivFun.toContinuousLinearEquiv
suffices H : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ (A ∘ f) s x by
filter_upwards [H] with x hx xs
have : f = (A.symm ∘ A) ∘ f := by
simp only [ContinuousLinearEquiv.symm_comp_self, Function.id_comp]
rw [this]
exact A.symm.differentiableAt.comp_differentiableWithinAt x (hx xs)
apply ae_differentiableWithinAt_of_mem_pi
exact A.lipschitz.comp_locallyBoundedVariationOn h
/-- A real function into a finite dimensional real vector space with bounded variation on a set
is differentiable almost everywhere in this set. -/
theorem ae_differentiableWithinAt {f : ℝ → V} {s : Set ℝ} (h : LocallyBoundedVariationOn f s)
(hs : MeasurableSet s) : ∀ᵐ x ∂volume.restrict s, DifferentiableWithinAt ℝ f s x := by
rw [ae_restrict_iff' hs]
exact h.ae_differentiableWithinAt_of_mem
/-- A real function into a finite dimensional real vector space with bounded variation
is differentiable almost everywhere. -/
theorem ae_differentiableAt {f : ℝ → V} (h : LocallyBoundedVariationOn f univ) :
∀ᵐ x, DifferentiableAt ℝ f x := by
filter_upwards [h.ae_differentiableWithinAt_of_mem] with x hx
rw [differentiableWithinAt_univ] at hx
exact hx (mem_univ _)
end LocallyBoundedVariationOn
/-- A real function into a finite dimensional real vector space which is Lipschitz on a set
is differentiable almost everywhere in this set. For the general Rademacher theorem assuming
that the source space is finite dimensional, see `LipschitzOnWith.ae_differentiableWithinAt_of_mem`.
-/
theorem LipschitzOnWith.ae_differentiableWithinAt_of_mem_real {C : ℝ≥0} {f : ℝ → V} {s : Set ℝ}
(h : LipschitzOnWith C f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x :=
h.locallyBoundedVariationOn.ae_differentiableWithinAt_of_mem
/-- A real function into a finite dimensional real vector space which is Lipschitz on a set
is differentiable almost everywhere in this set. For the general Rademacher theorem assuming
that the source space is finite dimensional, see `LipschitzOnWith.ae_differentiableWithinAt`. -/
theorem LipschitzOnWith.ae_differentiableWithinAt_real {C : ℝ≥0} {f : ℝ → V} {s : Set ℝ}
(h : LipschitzOnWith C f s) (hs : MeasurableSet s) :
∀ᵐ x ∂volume.restrict s, DifferentiableWithinAt ℝ f s x :=
h.locallyBoundedVariationOn.ae_differentiableWithinAt hs
/-- A real Lipschitz function into a finite dimensional real vector space is differentiable
almost everywhere. For the general Rademacher theorem assuming
that the source space is finite dimensional, see `LipschitzWith.ae_differentiableAt`. -/
theorem LipschitzWith.ae_differentiableAt_real {C : ℝ≥0} {f : ℝ → V} (h : LipschitzWith C f) :
∀ᵐ x, DifferentiableAt ℝ f x :=
(h.locallyBoundedVariationOn univ).ae_differentiableAt
| Mathlib/Analysis/BoundedVariation.lean | 750 | 763 | |
/-
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,511 | 1,512 | |
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Quotients
import Mathlib.Order.Filter.Finite
import Mathlib.Order.Filter.Germ.Basic
import Mathlib.Order.Filter.Ultrafilter.Defs
/-!
# Ultraproducts and Łoś's Theorem
## Main Definitions
- `FirstOrder.Language.Ultraproduct.Structure` is the ultraproduct structure on `Filter.Product`.
## Main Results
- Łoś's Theorem: `FirstOrder.Language.Ultraproduct.sentence_realize`. An ultraproduct models a
sentence `φ` if and only if the set of structures in the product that model `φ` is in the
ultrafilter.
## Tags
ultraproduct, Los's theorem
-/
universe u v
variable {α : Type*} (M : α → Type*) (u : Ultrafilter α)
open FirstOrder Filter
open Filter
namespace FirstOrder
namespace Language
open Structure
variable {L : Language.{u, v}} [∀ a, L.Structure (M a)]
namespace Ultraproduct
instance setoidPrestructure : L.Prestructure ((u : Filter α).productSetoid M) :=
{ (u : Filter α).productSetoid M with
toStructure :=
{ funMap := fun {_} f x a => funMap f fun i => x i a
RelMap := fun {_} r x => ∀ᶠ a : α in u, RelMap r fun i => x i a }
fun_equiv := fun {n} f x y xy => by
refine mem_of_superset (iInter_mem.2 xy) fun a ha => ?_
simp only [Set.mem_iInter, Set.mem_setOf_eq] at ha
simp only [Set.mem_setOf_eq, ha]
rel_equiv := fun {n} r x y xy => by
rw [← iff_eq_eq]
refine ⟨fun hx => ?_, fun hy => ?_⟩
· refine mem_of_superset (inter_mem hx (iInter_mem.2 xy)) ?_
rintro a ⟨ha1, ha2⟩
simp only [Set.mem_iInter, Set.mem_setOf_eq] at *
rw [← funext ha2]
exact ha1
· refine mem_of_superset (inter_mem hy (iInter_mem.2 xy)) ?_
rintro a ⟨ha1, ha2⟩
simp only [Set.mem_iInter, Set.mem_setOf_eq] at *
rw [funext ha2]
exact ha1 }
variable {M} {u}
instance «structure» : L.Structure ((u : Filter α).Product M) :=
Language.quotientStructure
theorem funMap_cast {n : ℕ} (f : L.Functions n) (x : Fin n → ∀ a, M a) :
(funMap f fun i => (x i : (u : Filter α).Product M)) =
(fun a => funMap f fun i => x i a : (u : Filter α).Product M) := by
apply funMap_quotient_mk'
theorem term_realize_cast {β : Type*} (x : β → ∀ a, M a) (t : L.Term β) :
(t.realize fun i => (x i : (u : Filter α).Product M)) =
(fun a => t.realize fun i => x i a : (u : Filter α).Product M) := by
convert @Term.realize_quotient_mk' L _ ((u : Filter α).productSetoid M)
(Ultraproduct.setoidPrestructure M u) _ t x using 2
ext a
induction t with
| var => rfl
| func _ _ t_ih => simp only [Term.realize, t_ih]; rfl
variable [∀ a : α, Nonempty (M a)]
theorem boundedFormula_realize_cast {β : Type*} {n : ℕ} (φ : L.BoundedFormula β n)
(x : β → ∀ a, M a) (v : Fin n → ∀ a, M a) :
(φ.Realize (fun i : β => (x i : (u : Filter α).Product M))
(fun i => (v i : (u : Filter α).Product M))) ↔
∀ᶠ a : α in u, φ.Realize (fun i : β => x i a) fun i => v i a := by
letI := (u : Filter α).productSetoid M
induction φ with
| falsum => simp only [BoundedFormula.Realize, eventually_const]
| equal =>
have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a :=
fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl
simp only [BoundedFormula.Realize, h2, term_realize_cast]
erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm,
term_realize_cast, term_realize_cast]
exact Quotient.eq''
| rel =>
have h2 : ∀ a : α, (Sum.elim (fun i : β => x i a) fun i => v i a) = fun i => Sum.elim x v i a :=
fun a => funext fun i => Sum.casesOn i (fun i => rfl) fun i => rfl
simp only [BoundedFormula.Realize, h2]
erw [(Sum.comp_elim ((↑) : (∀ a, M a) → (u : Filter α).Product M) x v).symm]
conv_lhs => enter [2, i]; erw [term_realize_cast]
apply relMap_quotient_mk'
| imp _ _ ih ih' =>
simp only [BoundedFormula.Realize, ih v, ih' v]
rw [Ultrafilter.eventually_imp]
| @all k φ ih =>
simp only [BoundedFormula.Realize]
apply Iff.trans (b := ∀ m : ∀ a : α, M a,
φ.Realize (fun i : β => (x i : (u : Filter α).Product M))
(Fin.snoc (((↑) : (∀ a, M a) → (u : Filter α).Product M) ∘ v)
(m : (u : Filter α).Product M)))
· exact Quotient.forall
have h' :
∀ (m : ∀ a, M a) (a : α),
(fun i : Fin (k + 1) => (Fin.snoc v m : _ → ∀ a, M a) i a) =
Fin.snoc (fun i : Fin k => v i a) (m a) := by
refine fun m a => funext (Fin.reverseInduction ?_ fun i _ => ?_)
· simp only [Fin.snoc_last]
· simp only [Fin.snoc_castSucc]
simp only [← Fin.comp_snoc]
simp only [Function.comp_def, ih, h']
refine ⟨fun h => ?_, fun h m => ?_⟩
· contrapose! h
simp_rw [← Ultrafilter.eventually_not, not_forall] at h
refine
⟨fun a : α =>
Classical.epsilon fun m : M a =>
¬φ.Realize (fun i => x i a) (Fin.snoc (fun i => v i a) m),
?_⟩
rw [← Ultrafilter.eventually_not]
exact Filter.mem_of_superset h fun a ha => Classical.epsilon_spec ha
· rw [Filter.eventually_iff] at *
exact Filter.mem_of_superset h fun a ha => ha (m a)
theorem realize_formula_cast {β : Type*} (φ : L.Formula β) (x : β → ∀ a, M a) :
(φ.Realize fun i => (x i : (u : Filter α).Product M)) ↔
∀ᶠ a : α in u, φ.Realize fun i => x i a := by
simp_rw [Formula.Realize, ← boundedFormula_realize_cast φ x, iff_eq_eq]
exact congr rfl (Subsingleton.elim _ _)
/-- **Łoś's Theorem**: A sentence is true in an ultraproduct if and only if the set of structures
it is true in is in the ultrafilter. -/
theorem sentence_realize (φ : L.Sentence) :
| (u : Filter α).Product M ⊨ φ ↔ ∀ᶠ a : α in u, M a ⊨ φ := by
simp_rw [Sentence.Realize]
rw [← realize_formula_cast φ, iff_eq_eq]
exact congr rfl (Subsingleton.elim _ _)
| Mathlib/ModelTheory/Ultraproducts.lean | 155 | 159 |
/-
Copyright (c) 2019 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Analysis.LocallyConvex.WithSeminorms
import Mathlib.Topology.Algebra.Module.StrongTopology
import Mathlib.Analysis.Normed.Operator.LinearIsometry
import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap
import Mathlib.Tactic.SuppressCompilation
/-!
# Operator norm on the space of continuous linear maps
Define the operator (semi)-norm on the space of continuous (semi)linear maps between (semi)-normed
spaces, and prove its basic properties. In particular, show that this space is itself a semi-normed
space.
Since a lot of elementary properties don't require `‖x‖ = 0 → x = 0` we start setting up the
theory for `SeminormedAddCommGroup`. Later we will specialize to `NormedAddCommGroup` in the
file `NormedSpace.lean`.
Note that most of statements that apply to semilinear maps only hold when the ring homomorphism
is isometric, as expressed by the typeclass `[RingHomIsometric σ]`.
-/
suppress_compilation
open Bornology
open Filter hiding map_smul
open scoped NNReal Topology Uniformity
-- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps
variable {𝕜 𝕜₂ 𝕜₃ E F Fₗ G 𝓕 : Type*}
section SemiNormed
open Metric ContinuousLinearMap
variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup F] [SeminormedAddCommGroup Fₗ]
[SeminormedAddCommGroup G]
variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃]
[NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜 Fₗ] [NormedSpace 𝕜₃ G]
{σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable [FunLike 𝓕 E F]
/-- If `‖x‖ = 0` and `f` is continuous then `‖f x‖ = 0`. -/
theorem norm_image_of_norm_zero [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) (hf : Continuous f) {x : E}
(hx : ‖x‖ = 0) : ‖f x‖ = 0 := by
rw [← mem_closure_zero_iff_norm, ← specializes_iff_mem_closure, ← map_zero f] at *
exact hx.map hf
section
variable [RingHomIsometric σ₁₂]
theorem SemilinearMapClass.bound_of_shell_semi_normed [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕)
{ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖)
(hf : ∀ x, ε / ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) {x : E} (hx : ‖x‖ ≠ 0) :
‖f x‖ ≤ C * ‖x‖ :=
(normSeminorm 𝕜 E).bound_of_shell ((normSeminorm 𝕜₂ F).comp ⟨⟨f, map_add f⟩, map_smulₛₗ f⟩)
ε_pos hc hf hx
/-- A continuous linear map between seminormed spaces is bounded when the field is nontrivially
normed. The continuity ensures boundedness on a ball of some radius `ε`. The nontriviality of the
norm is then used to rescale any element into an element of norm in `[ε/C, ε]`, whose image has a
controlled norm. The norm control for the original element follows by rescaling. -/
theorem SemilinearMapClass.bound_of_continuous [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕)
(hf : Continuous f) : ∃ C, 0 < C ∧ ∀ x : E, ‖f x‖ ≤ C * ‖x‖ :=
let φ : E →ₛₗ[σ₁₂] F := ⟨⟨f, map_add f⟩, map_smulₛₗ f⟩
((normSeminorm 𝕜₂ F).comp φ).bound_of_continuous_normedSpace (continuous_norm.comp hf)
end
namespace ContinuousLinearMap
theorem bound [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) : ∃ C, 0 < C ∧ ∀ x : E, ‖f x‖ ≤ C * ‖x‖ :=
SemilinearMapClass.bound_of_continuous f f.2
section
open Filter
variable (𝕜 E)
/-- Given a unit-length element `x` of a normed space `E` over a field `𝕜`, the natural linear
isometry map from `𝕜` to `E` by taking multiples of `x`. -/
def _root_.LinearIsometry.toSpanSingleton {v : E} (hv : ‖v‖ = 1) : 𝕜 →ₗᵢ[𝕜] E :=
{ LinearMap.toSpanSingleton 𝕜 E v with norm_map' := fun x => by simp [norm_smul, hv] }
variable {𝕜 E}
@[simp]
theorem _root_.LinearIsometry.toSpanSingleton_apply {v : E} (hv : ‖v‖ = 1) (a : 𝕜) :
LinearIsometry.toSpanSingleton 𝕜 E hv a = a • v :=
rfl
@[simp]
theorem _root_.LinearIsometry.coe_toSpanSingleton {v : E} (hv : ‖v‖ = 1) :
(LinearIsometry.toSpanSingleton 𝕜 E hv).toLinearMap = LinearMap.toSpanSingleton 𝕜 E v :=
rfl
end
section OpNorm
open Set Real
/-- The operator norm of a continuous linear map is the inf of all its bounds. -/
def opNorm (f : E →SL[σ₁₂] F) :=
sInf { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ }
instance hasOpNorm : Norm (E →SL[σ₁₂] F) :=
⟨opNorm⟩
theorem norm_def (f : E →SL[σ₁₂] F) : ‖f‖ = sInf { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
rfl
-- So that invocations of `le_csInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty [RingHomIsometric σ₁₂] {f : E →SL[σ₁₂] F} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
theorem bounds_bddBelow {f : E →SL[σ₁₂] F} : BddBelow { c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
theorem isLeast_opNorm [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) :
IsLeast {c | 0 ≤ c ∧ ∀ x, ‖f x‖ ≤ c * ‖x‖} ‖f‖ := by
refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow
simp only [setOf_and, setOf_forall]
refine isClosed_Ici.inter <| isClosed_iInter fun _ ↦ isClosed_le ?_ ?_ <;> continuity
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
theorem opNorm_le_bound (f : E →SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, ‖f x‖ ≤ M * ‖x‖) :
‖f‖ ≤ M :=
csInf_le bounds_bddBelow ⟨hMp, hM⟩
/-- If one controls the norm of every `A x`, `‖x‖ ≠ 0`, then one controls the norm of `A`. -/
theorem opNorm_le_bound' (f : E →SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≤ M)
(hM : ∀ x, ‖x‖ ≠ 0 → ‖f x‖ ≤ M * ‖x‖) : ‖f‖ ≤ M :=
opNorm_le_bound f hMp fun x =>
(ne_or_eq ‖x‖ 0).elim (hM x) fun h => by
simp only [h, mul_zero, norm_image_of_norm_zero f f.2 h, le_refl]
theorem opNorm_le_of_lipschitz {f : E →SL[σ₁₂] F} {K : ℝ≥0} (hf : LipschitzWith K f) : ‖f‖ ≤ K :=
f.opNorm_le_bound K.2 fun x => by
simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0
theorem opNorm_eq_of_bounds {φ : E →SL[σ₁₂] F} {M : ℝ} (M_nonneg : 0 ≤ M)
(h_above : ∀ x, ‖φ x‖ ≤ M * ‖x‖) (h_below : ∀ N ≥ 0, (∀ x, ‖φ x‖ ≤ N * ‖x‖) → M ≤ N) :
‖φ‖ = M :=
le_antisymm (φ.opNorm_le_bound M_nonneg h_above)
((le_csInf_iff ContinuousLinearMap.bounds_bddBelow ⟨M, M_nonneg, h_above⟩).mpr
fun N ⟨N_nonneg, hN⟩ => h_below N N_nonneg hN)
theorem opNorm_neg (f : E →SL[σ₁₂] F) : ‖-f‖ = ‖f‖ := by simp only [norm_def, neg_apply, norm_neg]
theorem opNorm_nonneg (f : E →SL[σ₁₂] F) : 0 ≤ ‖f‖ :=
Real.sInf_nonneg fun _ ↦ And.left
/-- The norm of the `0` operator is `0`. -/
theorem opNorm_zero : ‖(0 : E →SL[σ₁₂] F)‖ = 0 :=
le_antisymm (opNorm_le_bound _ le_rfl fun _ ↦ by simp) (opNorm_nonneg _)
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial
where it is `0`. It means that one can not do better than an inequality in general. -/
theorem norm_id_le : ‖id 𝕜 E‖ ≤ 1 :=
opNorm_le_bound _ zero_le_one fun x => by simp
section
variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃] (f g : E →SL[σ₁₂] F) (h : F →SL[σ₂₃] G)
(x : E)
/-- The fundamental property of the operator norm: `‖f x‖ ≤ ‖f‖ * ‖x‖`. -/
theorem le_opNorm : ‖f x‖ ≤ ‖f‖ * ‖x‖ := (isLeast_opNorm f).1.2 x
theorem dist_le_opNorm (x y : E) : dist (f x) (f y) ≤ ‖f‖ * dist x y := by
simp_rw [dist_eq_norm, ← map_sub, f.le_opNorm]
theorem le_of_opNorm_le_of_le {x} {a b : ℝ} (hf : ‖f‖ ≤ a) (hx : ‖x‖ ≤ b) :
‖f x‖ ≤ a * b :=
(f.le_opNorm x).trans <| by gcongr; exact (opNorm_nonneg f).trans hf
theorem le_opNorm_of_le {c : ℝ} {x} (h : ‖x‖ ≤ c) : ‖f x‖ ≤ ‖f‖ * c :=
f.le_of_opNorm_le_of_le le_rfl h
theorem le_of_opNorm_le {c : ℝ} (h : ‖f‖ ≤ c) (x : E) : ‖f x‖ ≤ c * ‖x‖ :=
f.le_of_opNorm_le_of_le h le_rfl
theorem opNorm_le_iff {f : E →SL[σ₁₂] F} {M : ℝ} (hMp : 0 ≤ M) :
‖f‖ ≤ M ↔ ∀ x, ‖f x‖ ≤ M * ‖x‖ :=
⟨f.le_of_opNorm_le, opNorm_le_bound f hMp⟩
theorem ratio_le_opNorm : ‖f x‖ / ‖x‖ ≤ ‖f‖ :=
div_le_of_le_mul₀ (norm_nonneg _) f.opNorm_nonneg (le_opNorm _ _)
/-- The image of the unit ball under a continuous linear map is bounded. -/
theorem unit_le_opNorm : ‖x‖ ≤ 1 → ‖f x‖ ≤ ‖f‖ :=
mul_one ‖f‖ ▸ f.le_opNorm_of_le
theorem opNorm_le_of_shell {f : E →SL[σ₁₂] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜}
| (hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) : ‖f‖ ≤ C :=
f.opNorm_le_bound' hC fun _ hx => SemilinearMapClass.bound_of_shell_semi_normed f ε_pos hc hf hx
| Mathlib/Analysis/NormedSpace/OperatorNorm/Basic.lean | 225 | 226 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion
import Mathlib.MeasureTheory.Measure.Prod
/-!
# Measure with a given density with respect to another measure
For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`.
On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`.
An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures
`μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to
`ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that
`μ = ν.withDensity f`.
See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`.
-/
open Set hiding restrict restrict_apply
open Filter ENNReal NNReal MeasureTheory.Measure
namespace MeasureTheory
variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α}
/-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the
measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/
noncomputable
def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α :=
Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun _ hs hd =>
lintegral_iUnion hs hd _
@[simp]
theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) :
μ.withDensity f s = ∫⁻ a in s, f a ∂μ :=
Measure.ofMeasurable_apply s hs
theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) :
∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by
let t := toMeasurable (μ.withDensity f) s
calc
∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ :=
lintegral_mono_set (subset_toMeasurable (withDensity μ f) s)
_ = μ.withDensity f t :=
(withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm
_ = μ.withDensity f s := measure_toMeasurable s
/-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample
without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider
the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their
complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal
to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then
* `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then
`∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim.
* `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets
`t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then
`μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`.
One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not
containing `x₀`, and infinite mass to those that contain it. -/
theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) :
μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by
apply le_antisymm ?_ (withDensity_apply_le f s)
let t := toMeasurable μ s
calc
μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s)
_ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s)
_ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s
@[simp]
lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by
ext s hs
rw [withDensity_apply _ hs]
simp
| theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) :
μ.withDensity f = μ.withDensity g := by
refine Measure.ext fun s hs => ?_
rw [withDensity_apply _ hs, withDensity_apply _ hs]
exact lintegral_congr_ae (ae_restrict_of_ae h)
| Mathlib/MeasureTheory/Measure/WithDensity.lean | 83 | 87 |
/-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Kim Morrison
-/
import Mathlib.CategoryTheory.Opposites
/-!
# Morphisms from equations between objects.
When working categorically, sometimes one encounters an equation `h : X = Y` between objects.
Your initial aversion to this is natural and appropriate:
you're in for some trouble, and if there is another way to approach the problem that won't
rely on this equality, it may be worth pursuing.
You have two options:
1. Use the equality `h` as one normally would in Lean (e.g. using `rw` and `subst`).
This may immediately cause difficulties, because in category theory everything is dependently
typed, and equations between objects quickly lead to nasty goals with `eq.rec`.
2. Promote `h` to a morphism using `eqToHom h : X ⟶ Y`, or `eqToIso h : X ≅ Y`.
This file introduces various `simp` lemmas which in favourable circumstances
result in the various `eqToHom` morphisms to drop out at the appropriate moment!
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
open Opposite
variable {C : Type u₁} [Category.{v₁} C]
/-- An equality `X = Y` gives us a morphism `X ⟶ Y`.
It is typically better to use this, rather than rewriting by the equality then using `𝟙 _`
which usually leads to dependent type theory hell.
-/
def eqToHom {X Y : C} (p : X = Y) : X ⟶ Y := by rw [p]; exact 𝟙 _
@[simp]
theorem eqToHom_refl (X : C) (p : X = X) : eqToHom p = 𝟙 X :=
rfl
@[reassoc (attr := simp)]
theorem eqToHom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToHom p ≫ eqToHom q = eqToHom (p.trans q) := by
cases p
cases q
simp
/-- `eqToHom h` is heterogeneously equal to the identity of its domain. -/
lemma eqToHom_heq_id_dom (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 X) := by
subst h; rfl
/-- `eqToHom h` is heterogeneously equal to the identity of its codomain. -/
lemma eqToHom_heq_id_cod (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 Y) := by
subst h; rfl
/-- Two morphisms are conjugate via eqToHom if and only if they are heterogeneously equal.
Note this used to be in the Functor namespace, where it doesn't belong. -/
theorem conj_eqToHom_iff_heq {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : X = Z) :
f = eqToHom h ≫ g ≫ eqToHom h'.symm ↔ HEq f g := by
cases h
cases h'
simp
theorem conj_eqToHom_iff_heq' {C} [Category C] {W X Y Z : C}
(f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : Z = X) :
f = eqToHom h ≫ g ≫ eqToHom h' ↔ HEq f g := conj_eqToHom_iff_heq _ _ _ h'.symm
theorem comp_eqToHom_iff {X Y Y' : C} (p : Y = Y') (f : X ⟶ Y) (g : X ⟶ Y') :
f ≫ eqToHom p = g ↔ f = g ≫ eqToHom p.symm :=
{ mp := fun h => h ▸ by simp
mpr := fun h => by simp [eq_whisker h (eqToHom p)] }
theorem eqToHom_comp_iff {X X' Y : C} (p : X = X') (f : X ⟶ Y) (g : X' ⟶ Y) :
eqToHom p ≫ g = f ↔ g = eqToHom p.symm ≫ f :=
{ mp := fun h => h ▸ by simp
mpr := fun h => h ▸ by simp [whisker_eq _ h] }
theorem eqToHom_comp_heq {C} [Category C] {W X Y : C}
(f : Y ⟶ X) (h : W = Y) : HEq (eqToHom h ≫ f) f := by
rw [← conj_eqToHom_iff_heq _ _ h rfl, eqToHom_refl, Category.comp_id]
@[simp] theorem eqToHom_comp_heq_iff {C} [Category C] {W X Y Z Z' : C}
(f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) :
HEq (eqToHom h ≫ f) g ↔ HEq f g :=
⟨(eqToHom_comp_heq ..).symm.trans, (eqToHom_comp_heq ..).trans⟩
@[simp] theorem heq_eqToHom_comp_iff {C} [Category C] {W X Y Z Z' : C}
(f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) :
HEq g (eqToHom h ≫ f) ↔ HEq g f :=
⟨(·.trans (eqToHom_comp_heq ..)), (·.trans (eqToHom_comp_heq ..).symm)⟩
theorem comp_eqToHom_heq {C} [Category C] {X Y Z : C}
(f : X ⟶ Y) (h : Y = Z) : HEq (f ≫ eqToHom h) f := by
rw [← conj_eqToHom_iff_heq' _ _ rfl h, eqToHom_refl, Category.id_comp]
@[simp] theorem comp_eqToHom_heq_iff {C} [Category C] {W X Y Z Z' : C}
(f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) :
HEq (f ≫ eqToHom h) g ↔ HEq f g :=
⟨(comp_eqToHom_heq ..).symm.trans, (comp_eqToHom_heq ..).trans⟩
@[simp] theorem heq_comp_eqToHom_iff {C} [Category C] {W X Y Z Z' : C}
(f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) :
HEq g (f ≫ eqToHom h) ↔ HEq g f :=
⟨(·.trans (comp_eqToHom_heq ..)), (·.trans (comp_eqToHom_heq ..).symm)⟩
theorem heq_comp {C} [Category C] {X Y Z X' Y' Z' : C}
{f : X ⟶ Y} {g : Y ⟶ Z} {f' : X' ⟶ Y'} {g' : Y' ⟶ Z'}
(eq1 : X = X') (eq2 : Y = Y') (eq3 : Z = Z')
(H1 : HEq f f') (H2 : HEq g g') :
HEq (f ≫ g) (f' ≫ g') := by
cases eq1; cases eq2; cases eq3; cases H1; cases H2; rfl
variable {β : Sort*}
/-- We can push `eqToHom` to the left through families of morphisms. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_naturality {f g : β → C} (z : ∀ b, f b ⟶ g b) {j j' : β} (w : j = j') :
z j ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ z j' := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_hom_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).hom ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').hom := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_inv_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).inv ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').inv := by
cases w
simp
/-- Reducible form of congrArg_mpr_hom_left -/
@[simp]
theorem congrArg_cast_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
cast (congrArg (fun W : C => W ⟶ Z) p.symm) q = eqToHom p ≫ q := by
cases p
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the source object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
(congrArg (fun W : C => W ⟶ Z) p).mpr q = eqToHom p ≫ q := by
cases p
simp
/-- Reducible form of `congrArg_mpr_hom_right` -/
@[simp]
theorem congrArg_cast_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
cast (congrArg (fun W : C => X ⟶ W) q.symm) p = p ≫ eqToHom q.symm := by
cases q
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the target object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
(congrArg (fun W : C => X ⟶ W) q).mpr p = p ≫ eqToHom q.symm := by
cases q
simp
/-- An equality `X = Y` gives us an isomorphism `X ≅ Y`.
It is typically better to use this, rather than rewriting by the equality then using `Iso.refl _`
which usually leads to dependent type theory hell.
-/
def eqToIso {X Y : C} (p : X = Y) : X ≅ Y :=
⟨eqToHom p, eqToHom p.symm, by simp, by simp⟩
@[simp]
theorem eqToIso.hom {X Y : C} (p : X = Y) : (eqToIso p).hom = eqToHom p :=
rfl
@[simp]
theorem eqToIso.inv {X Y : C} (p : X = Y) : (eqToIso p).inv = eqToHom p.symm :=
rfl
@[simp]
theorem eqToIso_refl {X : C} (p : X = X) : eqToIso p = Iso.refl X :=
rfl
@[simp]
theorem eqToIso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToIso p ≪≫ eqToIso q = eqToIso (p.trans q) := by ext; simp
@[simp]
theorem eqToHom_op {X Y : C} (h : X = Y) : (eqToHom h).op = eqToHom (congr_arg op h.symm) := by
cases h
rfl
@[simp]
theorem eqToHom_unop {X Y : Cᵒᵖ} (h : X = Y) :
(eqToHom h).unop = eqToHom (congr_arg unop h.symm) := by
cases h
rfl
instance {X Y : C} (h : X = Y) : IsIso (eqToHom h) :=
(eqToIso h).isIso_hom
@[simp]
theorem inv_eqToHom {X Y : C} (h : X = Y) : inv (eqToHom h) = eqToHom h.symm := by
aesop_cat
variable {D : Type u₂} [Category.{v₂} D]
namespace Functor
/-- Proving equality between functors. This isn't an extensionality lemma,
because usually you don't really want to do this. -/
theorem ext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ X Y f,
F.map f = eqToHom (h_obj X) ≫ G.map f ≫ eqToHom (h_obj Y).symm := by aesop_cat) :
F = G := by
match F, G with
| mk F_pre _ _ , mk G_pre _ _ =>
match F_pre, G_pre with
| Prefunctor.mk F_obj _ , Prefunctor.mk G_obj _ =>
obtain rfl : F_obj = G_obj := by
ext X
apply h_obj
congr
funext X Y f
simpa using h_map X Y f
lemma ext_of_iso {F G : C ⥤ D} (e : F ≅ G) (hobj : ∀ X, F.obj X = G.obj X)
(happ : ∀ X, e.hom.app X = eqToHom (hobj X)) : F = G :=
Functor.ext hobj (fun X Y f => by
rw [← cancel_mono (e.hom.app Y), e.hom.naturality f, happ, happ, Category.assoc,
Category.assoc, eqToHom_trans, eqToHom_refl, Category.comp_id])
/-- Proving equality between functors using heterogeneous equality. -/
theorem hext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ (X Y) (f : X ⟶ Y), HEq (F.map f) (G.map f)) : F = G :=
Functor.ext h_obj fun _ _ f => (conj_eqToHom_iff_heq _ _ (h_obj _) (h_obj _)).2 <| h_map _ _ f
-- Using equalities between functors.
theorem congr_obj {F G : C ⥤ D} (h : F = G) (X) : F.obj X = G.obj X := by rw [h]
@[reassoc]
theorem congr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) :
F.map f = eqToHom (congr_obj h X) ≫ G.map f ≫ eqToHom (congr_obj h Y).symm := by
subst h; simp
theorem congr_inv_of_congr_hom (F G : C ⥤ D) {X Y : C} (e : X ≅ Y) (hX : F.obj X = G.obj X)
(hY : F.obj Y = G.obj Y)
(h₂ : F.map e.hom = eqToHom (by rw [hX]) ≫ G.map e.hom ≫ eqToHom (by rw [hY])) :
F.map e.inv = eqToHom (by rw [hY]) ≫ G.map e.inv ≫ eqToHom (by rw [hX]) := by
simp only [← IsIso.Iso.inv_hom e, Functor.map_inv, h₂, IsIso.inv_comp, inv_eqToHom,
Category.assoc]
section HEq
-- Composition of functors and maps w.r.t. heq
variable {E : Type u₃} [Category.{v₃} E] {F G : C ⥤ D} {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
theorem map_comp_heq (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y) (hz : F.obj Z = G.obj Z)
(hf : HEq (F.map f) (G.map f)) (hg : HEq (F.map g) (G.map g)) :
HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by
rw [F.map_comp, G.map_comp]
| congr
| Mathlib/CategoryTheory/EqToHom.lean | 287 | 288 |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.LocallyConvex.Basic
/-!
# Balanced Core and Balanced Hull
## Main definitions
* `balancedCore`: The largest balanced subset of a set `s`.
* `balancedHull`: The smallest balanced superset of a set `s`.
## Main statements
* `balancedCore_eq_iInter`: Characterization of the balanced core as an intersection over subsets.
* `nhds_basis_closed_balanced`: The closed balanced sets form a basis of the neighborhood filter.
## Implementation details
The balanced core and hull are implemented differently: for the core we take the obvious definition
of the union over all balanced sets that are contained in `s`, whereas for the hull, we take the
union over `r • s`, for `r` the scalars with `‖r‖ ≤ 1`. We show that `balancedHull` has the
defining properties of a hull in `Balanced.balancedHull_subset_of_subset` and `subset_balancedHull`.
For the core we need slightly stronger assumptions to obtain a characterization as an intersection,
this is `balancedCore_eq_iInter`.
## References
* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]
## Tags
balanced
-/
open Set Pointwise Topology Filter
variable {𝕜 E ι : Type*}
section balancedHull
section SeminormedRing
variable [SeminormedRing 𝕜]
section SMul
variable (𝕜) [SMul 𝕜 E] {s t : Set E} {x : E}
/-- The largest balanced subset of `s`. -/
def balancedCore (s : Set E) :=
⋃₀ { t : Set E | Balanced 𝕜 t ∧ t ⊆ s }
/-- Helper definition to prove `balanced_core_eq_iInter` -/
def balancedCoreAux (s : Set E) :=
⋂ (r : 𝕜) (_ : 1 ≤ ‖r‖), r • s
/-- The smallest balanced superset of `s`. -/
def balancedHull (s : Set E) :=
⋃ (r : 𝕜) (_ : ‖r‖ ≤ 1), r • s
variable {𝕜}
theorem balancedCore_subset (s : Set E) : balancedCore 𝕜 s ⊆ s :=
sUnion_subset fun _ ht => ht.2
theorem balancedCore_empty : balancedCore 𝕜 (∅ : Set E) = ∅ :=
eq_empty_of_subset_empty (balancedCore_subset _)
theorem mem_balancedCore_iff : x ∈ balancedCore 𝕜 s ↔ ∃ t, Balanced 𝕜 t ∧ t ⊆ s ∧ x ∈ t := by
simp_rw [balancedCore, mem_sUnion, mem_setOf_eq, and_assoc]
theorem smul_balancedCore_subset (s : Set E) {a : 𝕜} (ha : ‖a‖ ≤ 1) :
a • balancedCore 𝕜 s ⊆ balancedCore 𝕜 s := by
rintro x ⟨y, hy, rfl⟩
rw [mem_balancedCore_iff] at hy
rcases hy with ⟨t, ht1, ht2, hy⟩
exact ⟨t, ⟨ht1, ht2⟩, ht1 a ha (smul_mem_smul_set hy)⟩
theorem balancedCore_balanced (s : Set E) : Balanced 𝕜 (balancedCore 𝕜 s) := fun _ =>
smul_balancedCore_subset s
/-- The balanced core of `t` is maximal in the sense that it contains any balanced subset
`s` of `t`. -/
theorem Balanced.subset_balancedCore_of_subset (hs : Balanced 𝕜 s) (h : s ⊆ t) :
s ⊆ balancedCore 𝕜 t :=
subset_sUnion_of_mem ⟨hs, h⟩
lemma Balanced.balancedCore_eq (h : Balanced 𝕜 s) : balancedCore 𝕜 s = s :=
le_antisymm (balancedCore_subset _) (h.subset_balancedCore_of_subset (subset_refl _))
theorem mem_balancedCoreAux_iff : x ∈ balancedCoreAux 𝕜 s ↔ ∀ r : 𝕜, 1 ≤ ‖r‖ → x ∈ r • s :=
mem_iInter₂
theorem mem_balancedHull_iff : x ∈ balancedHull 𝕜 s ↔ ∃ r : 𝕜, ‖r‖ ≤ 1 ∧ x ∈ r • s := by
simp [balancedHull]
/-- The balanced hull of `s` is minimal in the sense that it is contained in any balanced superset
`t` of `s`. -/
theorem Balanced.balancedHull_subset_of_subset (ht : Balanced 𝕜 t) (h : s ⊆ t) :
balancedHull 𝕜 s ⊆ t := by
intros x hx
obtain ⟨r, hr, y, hy, rfl⟩ := mem_balancedHull_iff.1 hx
exact ht.smul_mem hr (h hy)
@[mono, gcongr]
theorem balancedHull_mono (hst : s ⊆ t) : balancedHull 𝕜 s ⊆ balancedHull 𝕜 t := by
intro x hx
rw [mem_balancedHull_iff] at *
obtain ⟨r, hr₁, hr₂⟩ := hx
use r
exact ⟨hr₁, smul_set_mono hst hr₂⟩
end SMul
section Module
variable [AddCommGroup E] [Module 𝕜 E] {s : Set E}
theorem balancedCore_zero_mem (hs : (0 : E) ∈ s) : (0 : E) ∈ balancedCore 𝕜 s :=
mem_balancedCore_iff.2 ⟨0, balanced_zero, zero_subset.2 hs, Set.zero_mem_zero⟩
theorem balancedCore_nonempty_iff : (balancedCore 𝕜 s).Nonempty ↔ (0 : E) ∈ s :=
⟨fun h => zero_subset.1 <| (zero_smul_set h).superset.trans <|
(balancedCore_balanced s (0 : 𝕜) <| norm_zero.trans_le zero_le_one).trans <|
balancedCore_subset _,
fun h => ⟨0, balancedCore_zero_mem h⟩⟩
lemma Balanced.zero_mem (hs : Balanced 𝕜 s) (hs_nonempty : s.Nonempty) : (0 : E) ∈ s := by
rw [← hs.balancedCore_eq] at hs_nonempty
exact balancedCore_nonempty_iff.mp hs_nonempty
variable (𝕜) in
theorem subset_balancedHull [NormOneClass 𝕜] {s : Set E} : s ⊆ balancedHull 𝕜 s := fun _ hx =>
mem_balancedHull_iff.2 ⟨1, norm_one.le, _, hx, one_smul _ _⟩
theorem balancedHull.balanced (s : Set E) : Balanced 𝕜 (balancedHull 𝕜 s) := by
intro a ha
simp_rw [balancedHull, smul_set_iUnion₂, subset_def, mem_iUnion₂]
rintro x ⟨r, hr, hx⟩
rw [← smul_assoc] at hx
exact ⟨a • r, (norm_mul_le _ _).trans (mul_le_one₀ ha (norm_nonneg r) hr), hx⟩
open Balanced in
theorem balancedHull_add_subset [NormOneClass 𝕜] {t : Set E} :
balancedHull 𝕜 (s + t) ⊆ balancedHull 𝕜 s + balancedHull 𝕜 t :=
balancedHull_subset_of_subset (add (balancedHull.balanced _) (balancedHull.balanced _))
(add_subset_add (subset_balancedHull _) (subset_balancedHull _))
end Module
end SeminormedRing
section NormedField
variable [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E}
@[simp]
theorem balancedCoreAux_empty : balancedCoreAux 𝕜 (∅ : Set E) = ∅ := by
simp_rw [balancedCoreAux, iInter₂_eq_empty_iff, smul_set_empty]
exact fun _ => ⟨1, norm_one.ge, not_mem_empty _⟩
theorem balancedCoreAux_subset (s : Set E) : balancedCoreAux 𝕜 s ⊆ s := fun x hx => by
simpa only [one_smul] using mem_balancedCoreAux_iff.1 hx 1 norm_one.ge
theorem balancedCoreAux_balanced (h0 : (0 : E) ∈ balancedCoreAux 𝕜 s) :
Balanced 𝕜 (balancedCoreAux 𝕜 s) := by
rintro a ha x ⟨y, hy, rfl⟩
obtain rfl | h := eq_or_ne a 0
· simp_rw [zero_smul, h0]
rw [mem_balancedCoreAux_iff] at hy ⊢
intro r hr
have h'' : 1 ≤ ‖a⁻¹ • r‖ := by
rw [norm_smul, norm_inv]
exact one_le_mul_of_one_le_of_one_le ((one_le_inv₀ (norm_pos_iff.mpr h)).2 ha) hr
have h' := hy (a⁻¹ • r) h''
rwa [smul_assoc, mem_inv_smul_set_iff₀ h] at h'
theorem balancedCoreAux_maximal (h : t ⊆ s) (ht : Balanced 𝕜 t) : t ⊆ balancedCoreAux 𝕜 s := by
refine fun x hx => mem_balancedCoreAux_iff.2 fun r hr => ?_
rw [mem_smul_set_iff_inv_smul_mem₀ (norm_pos_iff.mp <| zero_lt_one.trans_le hr)]
refine h (ht.smul_mem ?_ hx)
rw [norm_inv]
exact inv_le_one_of_one_le₀ hr
theorem balancedCore_subset_balancedCoreAux : balancedCore 𝕜 s ⊆ balancedCoreAux 𝕜 s :=
balancedCoreAux_maximal (balancedCore_subset s) (balancedCore_balanced s)
theorem balancedCore_eq_iInter (hs : (0 : E) ∈ s) :
balancedCore 𝕜 s = ⋂ (r : 𝕜) (_ : 1 ≤ ‖r‖), r • s := by
refine balancedCore_subset_balancedCoreAux.antisymm ?_
refine (balancedCoreAux_balanced ?_).subset_balancedCore_of_subset (balancedCoreAux_subset s)
exact balancedCore_subset_balancedCoreAux (balancedCore_zero_mem hs)
theorem subset_balancedCore (ht : (0 : E) ∈ t) (hst : ∀ a : 𝕜, ‖a‖ ≤ 1 → a • s ⊆ t) :
s ⊆ balancedCore 𝕜 t := by
rw [balancedCore_eq_iInter ht]
refine subset_iInter₂ fun a ha ↦ ?_
rw [subset_smul_set_iff₀ (norm_pos_iff.mp <| zero_lt_one.trans_le ha)]
apply hst
rw [norm_inv]
exact inv_le_one_of_one_le₀ ha
end NormedField
end balancedHull
/-! ### Topological properties -/
section Topology
variable [NormedDivisionRing 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E]
[ContinuousSMul 𝕜 E] {U : Set E}
protected theorem IsClosed.balancedCore (hU : IsClosed U) : IsClosed (balancedCore 𝕜 U) := by
by_cases h : (0 : E) ∈ U
· rw [balancedCore_eq_iInter h]
refine isClosed_iInter fun a => ?_
refine isClosed_iInter fun ha => ?_
have ha' := lt_of_lt_of_le zero_lt_one ha
rw [norm_pos_iff] at ha'
| exact isClosedMap_smul_of_ne_zero ha' U hU
· have : balancedCore 𝕜 U = ∅ := by
contrapose! h
exact balancedCore_nonempty_iff.mp h
rw [this]
exact isClosed_empty
-- We don't have a `NontriviallyNormedDivisionRing`, so we use a `NeBot` assumption instead
variable [NeBot (𝓝[≠] (0 : 𝕜))]
theorem balancedCore_mem_nhds_zero (hU : U ∈ 𝓝 (0 : E)) : balancedCore 𝕜 U ∈ 𝓝 (0 : E) := by
-- Getting neighborhoods of the origin for `0 : 𝕜` and `0 : E`
obtain ⟨r, V, hr, hV, hrVU⟩ : ∃ (r : ℝ) (V : Set E),
| Mathlib/Analysis/LocallyConvex/BalancedCoreHull.lean | 227 | 239 |
/-
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.Algebra.Ring.Prod
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Canonical
import Mathlib.Order.Interval.Basic
import Mathlib.Tactic.Positivity.Core
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Interval arithmetic
This file defines arithmetic operations on intervals and prove their correctness. Note that this is
full precision operations. The essentials of float operations can be found
in `Data.FP.Basic`. We have not yet integrated these with the rest of the library.
-/
open Function Set
open scoped Pointwise
universe u
variable {ι α : Type*}
/-! ### One/zero -/
section One
section Preorder
variable [Preorder α] [One α]
@[to_additive]
instance : One (NonemptyInterval α) :=
⟨NonemptyInterval.pure 1⟩
namespace NonemptyInterval
@[to_additive (attr := simp) toProd_zero]
theorem toProd_one : (1 : NonemptyInterval α).toProd = 1 :=
rfl
@[to_additive]
theorem fst_one : (1 : NonemptyInterval α).fst = 1 :=
rfl
@[to_additive]
theorem snd_one : (1 : NonemptyInterval α).snd = 1 :=
rfl
@[to_additive (attr := push_cast, simp)]
theorem coe_one_interval : ((1 : NonemptyInterval α) : Interval α) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem pure_one : pure (1 : α) = 1 :=
rfl
end NonemptyInterval
namespace Interval
@[to_additive (attr := simp)]
theorem pure_one : pure (1 : α) = 1 :=
rfl
@[to_additive] lemma one_ne_bot : (1 : Interval α) ≠ ⊥ := pure_ne_bot
@[to_additive] lemma bot_ne_one : (⊥ : Interval α) ≠ 1 := bot_ne_pure
end Interval
end Preorder
section PartialOrder
variable [PartialOrder α] [One α]
namespace NonemptyInterval
@[to_additive (attr := simp)]
theorem coe_one : ((1 : NonemptyInterval α) : Set α) = 1 :=
coe_pure _
@[to_additive]
theorem one_mem_one : (1 : α) ∈ (1 : NonemptyInterval α) :=
⟨le_rfl, le_rfl⟩
end NonemptyInterval
namespace Interval
@[to_additive (attr := simp)]
theorem coe_one : ((1 : Interval α) : Set α) = 1 :=
Icc_self _
@[to_additive]
theorem one_mem_one : (1 : α) ∈ (1 : Interval α) :=
⟨le_rfl, le_rfl⟩
end Interval
end PartialOrder
end One
/-!
### Addition/multiplication
Note that this multiplication does not apply to `ℚ` or `ℝ`.
-/
section Mul
variable [Preorder α] [Mul α] [MulLeftMono α] [MulRightMono α]
@[to_additive]
instance : Mul (NonemptyInterval α) :=
⟨fun s t => ⟨s.toProd * t.toProd, mul_le_mul' s.fst_le_snd t.fst_le_snd⟩⟩
@[to_additive]
instance : Mul (Interval α) :=
⟨Option.map₂ (· * ·)⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a b : α)
@[to_additive (attr := simp) toProd_add]
theorem toProd_mul : (s * t).toProd = s.toProd * t.toProd :=
rfl
@[to_additive]
theorem fst_mul : (s * t).fst = s.fst * t.fst :=
rfl
@[to_additive]
theorem snd_mul : (s * t).snd = s.snd * t.snd :=
rfl
@[to_additive (attr := simp)]
theorem coe_mul_interval : (↑(s * t) : Interval α) = s * t :=
rfl
@[to_additive (attr := simp)]
theorem pure_mul_pure : pure a * pure b = pure (a * b) :=
rfl
end NonemptyInterval
namespace Interval
variable (s t : Interval α)
@[to_additive (attr := simp)]
theorem bot_mul : ⊥ * t = ⊥ :=
rfl
@[to_additive]
theorem mul_bot : s * ⊥ = ⊥ :=
Option.map₂_none_right _ _
-- simp can already prove `add_bot`
attribute [simp] mul_bot
end Interval
end Mul
/-! ### Powers -/
-- TODO: if `to_additive` gets improved sufficiently, derive this from `hasPow`
instance NonemptyInterval.hasNSMul [AddMonoid α] [Preorder α] [AddLeftMono α]
[AddRightMono α] : SMul ℕ (NonemptyInterval α) :=
⟨fun n s => ⟨(n • s.fst, n • s.snd), nsmul_le_nsmul_right s.fst_le_snd _⟩⟩
section Pow
variable [Monoid α] [Preorder α]
@[to_additive existing]
instance NonemptyInterval.hasPow [MulLeftMono α] [MulRightMono α] :
Pow (NonemptyInterval α) ℕ :=
⟨fun s n => ⟨s.toProd ^ n, pow_le_pow_left' s.fst_le_snd _⟩⟩
namespace NonemptyInterval
variable [MulLeftMono α] [MulRightMono α]
variable (s : NonemptyInterval α) (a : α) (n : ℕ)
@[to_additive (attr := simp) toProd_nsmul]
theorem toProd_pow : (s ^ n).toProd = s.toProd ^ n :=
rfl
@[to_additive]
theorem fst_pow : (s ^ n).fst = s.fst ^ n :=
rfl
@[to_additive]
theorem snd_pow : (s ^ n).snd = s.snd ^ n :=
rfl
@[to_additive (attr := simp)]
theorem pure_pow : pure a ^ n = pure (a ^ n) :=
rfl
end NonemptyInterval
end Pow
namespace NonemptyInterval
@[to_additive]
instance commMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
CommMonoid (NonemptyInterval α) :=
NonemptyInterval.toProd_injective.commMonoid _ toProd_one toProd_mul toProd_pow
end NonemptyInterval
@[to_additive]
instance Interval.mulOneClass [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
MulOneClass (Interval α) where
mul := (· * ·)
one := 1
one_mul s :=
(Option.map₂_coe_left _ _ _).trans <| by
simp_rw [one_mul, ← Function.id_def, Option.map_id, id]
mul_one s :=
(Option.map₂_coe_right _ _ _).trans <| by
simp_rw [mul_one, ← Function.id_def, Option.map_id, id]
@[to_additive]
instance Interval.commMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
CommMonoid (Interval α) :=
{ Interval.mulOneClass with
mul_comm := fun _ _ => Option.map₂_comm mul_comm
mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc }
namespace NonemptyInterval
@[to_additive]
theorem coe_pow_interval [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
(s : NonemptyInterval α) (n : ℕ) :
↑(s ^ n) = (s : Interval α) ^ n :=
map_pow (⟨⟨(↑), coe_one_interval⟩, coe_mul_interval⟩ : NonemptyInterval α →* Interval α) _ _
-- simp can already prove `coe_nsmul_interval`
attribute [simp] coe_pow_interval
end NonemptyInterval
namespace Interval
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] (s : Interval α) {n : ℕ}
@[to_additive]
theorem bot_pow : ∀ {n : ℕ}, n ≠ 0 → (⊥ : Interval α) ^ n = ⊥
| 0, h => (h rfl).elim
| Nat.succ n, _ => mul_bot (⊥ ^ n)
end Interval
/-!
### Semiring structure
When `α` is a canonically `OrderedCommSemiring`, the previous `+` and `*` on `NonemptyInterval α`
form a `CommSemiring`.
-/
section NatCast
variable [Preorder α] [NatCast α]
namespace NonemptyInterval
instance : NatCast (NonemptyInterval α) where
natCast n := pure <| Nat.cast n
theorem fst_natCast (n : ℕ) : (n : NonemptyInterval α).fst = n := rfl
theorem snd_natCast (n : ℕ) : (n : NonemptyInterval α).snd = n := rfl
@[simp]
theorem pure_natCast (n : ℕ) : pure (n : α) = n := rfl
end NonemptyInterval
end NatCast
namespace NonemptyInterval
instance [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α] :
CommSemiring (NonemptyInterval α) :=
NonemptyInterval.toProd_injective.commSemiring _
toProd_zero toProd_one toProd_add toProd_mul (swap toProd_nsmul) toProd_pow (fun _ => rfl)
end NonemptyInterval
/-!
### Subtraction
Subtraction is defined more generally than division so that it applies to `ℕ` (and `OrderedDiv`
is not a thing and probably should not become one).
-/
section Sub
variable [Preorder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] [AddLeftMono α]
instance : Sub (NonemptyInterval α) :=
⟨fun s t => ⟨(s.fst - t.snd, s.snd - t.fst), tsub_le_tsub s.fst_le_snd t.fst_le_snd⟩⟩
instance : Sub (Interval α) :=
⟨Option.map₂ Sub.sub⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) {a b : α}
@[simp]
theorem fst_sub : (s - t).fst = s.fst - t.snd :=
rfl
@[simp]
theorem snd_sub : (s - t).snd = s.snd - t.fst :=
rfl
@[simp]
theorem coe_sub_interval : (↑(s - t) : Interval α) = s - t :=
rfl
theorem sub_mem_sub (ha : a ∈ s) (hb : b ∈ t) : a - b ∈ s - t :=
⟨tsub_le_tsub ha.1 hb.2, tsub_le_tsub ha.2 hb.1⟩
@[simp]
theorem pure_sub_pure (a b : α) : pure a - pure b = pure (a - b) :=
rfl
end NonemptyInterval
namespace Interval
variable (s t : Interval α)
@[simp]
theorem bot_sub : ⊥ - t = ⊥ :=
rfl
@[simp]
theorem sub_bot : s - ⊥ = ⊥ :=
Option.map₂_none_right _ _
end Interval
end Sub
/-!
### Division in ordered groups
Note that this division does not apply to `ℚ` or `ℝ`.
-/
section Div
variable [Preorder α] [CommGroup α] [MulLeftMono α]
@[to_additive existing]
instance : Div (NonemptyInterval α) :=
⟨fun s t => ⟨(s.fst / t.snd, s.snd / t.fst), div_le_div'' s.fst_le_snd t.fst_le_snd⟩⟩
@[to_additive existing]
instance : Div (Interval α) :=
⟨Option.map₂ (· / ·)⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a b : α)
@[to_additive existing (attr := simp)]
theorem fst_div : (s / t).fst = s.fst / t.snd :=
rfl
@[to_additive existing (attr := simp)]
theorem snd_div : (s / t).snd = s.snd / t.fst :=
rfl
@[to_additive existing (attr := simp)]
theorem coe_div_interval : (↑(s / t) : Interval α) = s / t :=
rfl
@[to_additive existing]
theorem div_mem_div (ha : a ∈ s) (hb : b ∈ t) : a / b ∈ s / t :=
⟨div_le_div'' ha.1 hb.2, div_le_div'' ha.2 hb.1⟩
@[to_additive existing (attr := simp)]
theorem pure_div_pure : pure a / pure b = pure (a / b) :=
rfl
end NonemptyInterval
namespace Interval
variable (s t : Interval α)
@[to_additive existing (attr := simp)]
theorem bot_div : ⊥ / t = ⊥ :=
rfl
@[to_additive existing (attr := simp)]
theorem div_bot : s / ⊥ = ⊥ :=
Option.map₂_none_right _ _
end Interval
end Div
/-! ### Negation/inversion -/
section Inv
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α]
@[to_additive]
instance : Inv (NonemptyInterval α) :=
⟨fun s => ⟨(s.snd⁻¹, s.fst⁻¹), inv_le_inv' s.fst_le_snd⟩⟩
@[to_additive]
instance : Inv (Interval α) :=
⟨Option.map Inv.inv⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a : α)
@[to_additive (attr := simp)]
theorem fst_inv : s⁻¹.fst = s.snd⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem snd_inv : s⁻¹.snd = s.fst⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem coe_inv_interval : (↑(s⁻¹) : Interval α) = (↑s)⁻¹ :=
rfl
@[to_additive]
theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ :=
⟨inv_le_inv' ha.2, inv_le_inv' ha.1⟩
@[to_additive (attr := simp)]
theorem inv_pure : (pure a)⁻¹ = pure a⁻¹ :=
rfl
end NonemptyInterval
@[to_additive (attr := simp)]
theorem Interval.inv_bot : (⊥ : Interval α)⁻¹ = ⊥ :=
rfl
end Inv
namespace NonemptyInterval
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : NonemptyInterval α}
@[to_additive]
protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 := by
refine ⟨fun h => ?_, ?_⟩
· rw [NonemptyInterval.ext_iff, Prod.ext_iff] at h
have := (mul_le_mul_iff_of_ge s.fst_le_snd t.fst_le_snd).1 (h.2.trans h.1.symm).le
refine ⟨s.fst, t.fst, ?_, ?_, h.1⟩ <;> apply NonemptyInterval.ext <;> dsimp [pure]
· nth_rw 2 [this.1]
· nth_rw 2 [this.2]
· rintro ⟨b, c, rfl, rfl, h⟩
rw [pure_mul_pure, h, pure_one]
instance subtractionCommMonoid {α : Type u}
[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] :
SubtractionCommMonoid (NonemptyInterval α) :=
{ NonemptyInterval.addCommMonoid with
neg := Neg.neg
sub := Sub.sub
sub_eq_add_neg := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact sub_eq_add_neg _ _
neg_neg := fun s => by apply NonemptyInterval.ext; exact neg_neg _
neg_add_rev := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact neg_add_rev _ _
neg_eq_of_add := fun s t h => by
obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.add_eq_zero_iff.1 h
rw [neg_pure, neg_eq_of_add_eq_zero_right hab]
-- TODO: use a better defeq
zsmul := zsmulRec }
@[to_additive existing NonemptyInterval.subtractionCommMonoid]
instance divisionCommMonoid : DivisionCommMonoid (NonemptyInterval α) :=
{ NonemptyInterval.commMonoid with
inv := Inv.inv
div := (· / ·)
div_eq_mul_inv := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact div_eq_mul_inv _ _
inv_inv := fun s => by apply NonemptyInterval.ext; exact inv_inv _
mul_inv_rev := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact mul_inv_rev _ _
inv_eq_of_mul := fun s t h => by
obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.mul_eq_one_iff.1 h
rw [inv_pure, inv_eq_of_mul_eq_one_right hab] }
end NonemptyInterval
namespace Interval
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : Interval α}
@[to_additive]
protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 := by
cases s
· simp
cases t
· simp
· simp_rw [← NonemptyInterval.coe_mul_interval, ← NonemptyInterval.coe_one_interval,
WithBot.coe_inj, NonemptyInterval.coe_eq_pure]
exact NonemptyInterval.mul_eq_one_iff
instance subtractionCommMonoid {α : Type u}
[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] :
SubtractionCommMonoid (Interval α) :=
{ Interval.addCommMonoid with
neg := Neg.neg
sub := Sub.sub
sub_eq_add_neg := by
rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (sub_eq_add_neg _ _)
neg_neg := by rintro (_ | s) <;> first |rfl|exact congr_arg some (neg_neg _)
neg_add_rev := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (neg_add_rev _ _)
neg_eq_of_add := by
rintro (_ | s) (_ | t) h <;>
first
| cases h
| exact congr_arg some (neg_eq_of_add_eq_zero_right <| Option.some_injective _ h)
-- TODO: use a better defeq
zsmul := zsmulRec }
@[to_additive existing Interval.subtractionCommMonoid]
instance divisionCommMonoid : DivisionCommMonoid (Interval α) :=
{ Interval.commMonoid with
inv := Inv.inv
div := (· / ·)
div_eq_mul_inv := by
rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (div_eq_mul_inv _ _)
inv_inv := by rintro (_ | s) <;> first |rfl|exact congr_arg some (inv_inv _)
mul_inv_rev := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (mul_inv_rev _ _)
inv_eq_of_mul := by
rintro (_ | s) (_ | t) h <;>
first
| cases h
| exact congr_arg some (inv_eq_of_mul_eq_one_right <| Option.some_injective _ h) }
|
end Interval
section Length
variable [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]
namespace NonemptyInterval
| Mathlib/Algebra/Order/Interval/Basic.lean | 571 | 578 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.List.MinMax
import Mathlib.Data.Nat.Order.Lemmas
import Mathlib.Logic.Encodable.Basic
/-!
# Denumerable types
This file defines denumerable (countably infinite) types as a typeclass extending `Encodable`. This
is used to provide explicit encode/decode functions from and to `ℕ`, with the information that those
functions are inverses of each other.
## Implementation notes
This property already has a name, namely `α ≃ ℕ`, but here we are interested in using it as a
typeclass.
-/
assert_not_exists Monoid
variable {α β : Type*}
/-- A denumerable type is (constructively) bijective with `ℕ`. Typeclass equivalent of `α ≃ ℕ`. -/
class Denumerable (α : Type*) extends Encodable α where
/-- `decode` and `encode` are inverses. -/
decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n
open Finset Nat
namespace Denumerable
section
variable [Denumerable α] [Denumerable β]
open Encodable
theorem decode_isSome (α) [Denumerable α] (n : ℕ) : (decode (α := α) n).isSome :=
Option.isSome_iff_exists.2 <| (decode_inv n).imp fun _ => And.left
/-- Returns the `n`-th element of `α` indexed by the decoding. -/
def ofNat (α) [Denumerable α] (n : ℕ) : α :=
Option.get _ (decode_isSome α n)
@[simp]
theorem decode_eq_ofNat (α) [Denumerable α] (n : ℕ) : decode (α := α) n = some (ofNat α n) :=
Option.eq_some_of_isSome _
@[simp]
theorem ofNat_of_decode {n b} (h : decode (α := α) n = some b) : ofNat (α := α) n = b :=
Option.some.inj <| (decode_eq_ofNat _ _).symm.trans h
@[simp]
theorem encode_ofNat (n) : encode (ofNat α n) = n := by
obtain ⟨a, h, e⟩ := decode_inv (α := α) n
rwa [ofNat_of_decode h]
@[simp]
theorem ofNat_encode (a) : ofNat α (encode a) = a :=
ofNat_of_decode (encodek _)
/-- A denumerable type is equivalent to `ℕ`. -/
def eqv (α) [Denumerable α] : α ≃ ℕ :=
⟨encode, ofNat α, ofNat_encode, encode_ofNat⟩
-- See Note [lower instance priority]
instance (priority := 100) : Infinite α :=
Infinite.of_surjective _ (eqv α).surjective
/-- A type equivalent to `ℕ` is denumerable. -/
def mk' {α} (e : α ≃ ℕ) : Denumerable α where
encode := e
decode := some ∘ e.symm
encodek _ := congr_arg some (e.symm_apply_apply _)
decode_inv _ := ⟨_, rfl, e.apply_symm_apply _⟩
/-- Denumerability is conserved by equivalences. This is transitivity of equivalence the denumerable
way. -/
def ofEquiv (α) {β} [Denumerable α] (e : β ≃ α) : Denumerable β :=
{ Encodable.ofEquiv _ e with
decode_inv := fun n => by
simp [decode_ofEquiv, encode_ofEquiv] }
@[simp]
theorem ofEquiv_ofNat (α) {β} [Denumerable α] (e : β ≃ α) (n) :
@ofNat β (ofEquiv _ e) n = e.symm (ofNat α n) := by
letI := ofEquiv _ e
refine ofNat_of_decode ?_
rw [decode_ofEquiv e]
simp
/-- All denumerable types are equivalent. -/
def equiv₂ (α β) [Denumerable α] [Denumerable β] : α ≃ β :=
(eqv α).trans (eqv β).symm
instance nat : Denumerable ℕ :=
⟨fun _ => ⟨_, rfl, rfl⟩⟩
@[simp]
theorem ofNat_nat (n) : ofNat ℕ n = n :=
rfl
/-- If `α` is denumerable, then so is `Option α`. -/
instance option : Denumerable (Option α) :=
⟨fun n => by
cases n with
| zero =>
refine ⟨none, ?_, encode_none⟩
rw [decode_option_zero, Option.mem_def]
| succ n =>
refine ⟨some (ofNat α n), ?_, ?_⟩
· rw [decode_option_succ, decode_eq_ofNat, Option.map_some', Option.mem_def]
rw [encode_some, encode_ofNat]⟩
/-- If `α` and `β` are denumerable, then so is their sum. -/
instance sum : Denumerable (α ⊕ β) :=
⟨fun n => by
suffices ∃ a ∈ @decodeSum α β _ _ n, encodeSum a = bit (bodd n) (div2 n) by simpa [bit_decomp]
simp only [decodeSum, boddDiv2_eq, decode_eq_ofNat, Option.some.injEq, Option.map_some',
Option.mem_def, Sum.exists]
cases bodd n <;> simp [decodeSum, bit, encodeSum, Nat.two_mul]⟩
section Sigma
variable {γ : α → Type*} [∀ a, Denumerable (γ a)]
/-- A denumerable collection of denumerable types is denumerable. -/
instance sigma : Denumerable (Sigma γ) :=
⟨fun n => by simp [decodeSigma]⟩
@[simp]
theorem sigma_ofNat_val (n : ℕ) :
ofNat (Sigma γ) n = ⟨ofNat α (unpair n).1, ofNat (γ _) (unpair n).2⟩ :=
Option.some.inj <| by rw [← decode_eq_ofNat, decode_sigma_val]; simp
end Sigma
/-- If `α` and `β` are denumerable, then so is their product. -/
instance prod : Denumerable (α × β) :=
ofEquiv _ (Equiv.sigmaEquivProd α β).symm
theorem prod_ofNat_val (n : ℕ) :
ofNat (α × β) n = (ofNat α (unpair n).1, ofNat β (unpair n).2) := by simp
@[simp]
theorem prod_nat_ofNat : ofNat (ℕ × ℕ) = unpair := by funext; simp
instance int : Denumerable ℤ :=
Denumerable.mk' Equiv.intEquivNat
instance pnat : Denumerable ℕ+ :=
Denumerable.mk' Equiv.pnatEquivNat
/-- The lift of a denumerable type is denumerable. -/
instance ulift : Denumerable (ULift α) :=
ofEquiv _ Equiv.ulift
/-- The lift of a denumerable type is denumerable. -/
instance plift : Denumerable (PLift α) :=
ofEquiv _ Equiv.plift
/-- If `α` is denumerable, then `α × α` and `α` are equivalent. -/
def pair : α × α ≃ α :=
equiv₂ _ _
end
end Denumerable
|
namespace Nat.Subtype
| Mathlib/Logic/Denumerable.lean | 174 | 175 |
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.Decomposition.RadonNikodym
import Mathlib.MeasureTheory.Measure.Haar.OfBasis
import Mathlib.Probability.Independence.Basic
/-!
# Probability density function
This file defines the probability density function of random variables, by which we mean
measurable functions taking values in a Borel space. The probability density function is defined
as the Radon–Nikodym derivative of the law of `X`. In particular, a measurable function `f`
is said to the probability density function of a random variable `X` if for all measurable
sets `S`, `ℙ(X ∈ S) = ∫ x in S, f x dx`. Probability density functions are one way of describing
the distribution of a random variable, and are useful for calculating probabilities and
finding moments (although the latter is better achieved with moment generating functions).
This file also defines the continuous uniform distribution and proves some properties about
random variables with this distribution.
## Main definitions
* `MeasureTheory.HasPDF` : A random variable `X : Ω → E` is said to `HasPDF` with
respect to the measure `ℙ` on `Ω` and `μ` on `E` if the push-forward measure of `ℙ` along `X`
is absolutely continuous with respect to `μ` and they `HaveLebesgueDecomposition`.
* `MeasureTheory.pdf` : If `X` is a random variable that `HasPDF X ℙ μ`, then `pdf X`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`.
* `MeasureTheory.pdf.IsUniform` : A random variable `X` is said to follow the uniform
distribution if it has a constant probability density function with a compact, non-null support.
## Main results
* `MeasureTheory.pdf.integral_pdf_smul` : Law of the unconscious statistician,
i.e. if a random variable `X : Ω → E` has pdf `f`, then `𝔼(g(X)) = ∫ x, f x • g x dx` for
all measurable `g : E → F`.
* `MeasureTheory.pdf.integral_mul_eq_integral` : A real-valued random variable `X` with
pdf `f` has expectation `∫ x, x * f x dx`.
* `MeasureTheory.pdf.IsUniform.integral_eq` : If `X` follows the uniform distribution with
its pdf having support `s`, then `X` has expectation `(λ s)⁻¹ * ∫ x in s, x dx` where `λ`
is the Lebesgue measure.
## TODO
Ultimately, we would also like to define characteristic functions to describe distributions as
it exists for all random variables. However, to define this, we will need Fourier transforms
which we currently do not have.
-/
open scoped MeasureTheory NNReal ENNReal
open TopologicalSpace MeasureTheory.Measure
noncomputable section
namespace MeasureTheory
variable {Ω E : Type*} [MeasurableSpace E]
/-- A random variable `X : Ω → E` is said to have a probability density function (`HasPDF`)
with respect to the measure `ℙ` on `Ω` and `μ` on `E`
if the push-forward measure of `ℙ` along `X` is absolutely continuous with respect to `μ`
and they have a Lebesgue decomposition (`HaveLebesgueDecomposition`). -/
class HasPDF {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
Prop where
protected aemeasurable' : AEMeasurable X ℙ
protected haveLebesgueDecomposition' : (map X ℙ).HaveLebesgueDecomposition μ
protected absolutelyContinuous' : map X ℙ ≪ μ
section HasPDF
variable {_ : MeasurableSpace Ω} {X Y : Ω → E} {ℙ : Measure Ω} {μ : Measure E}
theorem hasPDF_iff :
HasPDF X ℙ μ ↔ AEMeasurable X ℙ ∧ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ :=
⟨fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩, fun ⟨h₁, h₂, h₃⟩ ↦ ⟨h₁, h₂, h₃⟩⟩
theorem hasPDF_iff_of_aemeasurable (hX : AEMeasurable X ℙ) :
HasPDF X ℙ μ ↔ (map X ℙ).HaveLebesgueDecomposition μ ∧ map X ℙ ≪ μ := by
rw [hasPDF_iff]
simp only [hX, true_and]
variable (X ℙ μ) in
@[measurability]
theorem HasPDF.aemeasurable [HasPDF X ℙ μ] : AEMeasurable X ℙ := HasPDF.aemeasurable' μ
instance HasPDF.haveLebesgueDecomposition [HasPDF X ℙ μ] : (map X ℙ).HaveLebesgueDecomposition μ :=
HasPDF.haveLebesgueDecomposition'
theorem HasPDF.absolutelyContinuous [HasPDF X ℙ μ] : map X ℙ ≪ μ := HasPDF.absolutelyContinuous'
/-- A random variable that `HasPDF` is quasi-measure preserving. -/
theorem HasPDF.quasiMeasurePreserving_of_measurable (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E)
[HasPDF X ℙ μ] (h : Measurable X) : QuasiMeasurePreserving X ℙ μ :=
{ measurable := h
absolutelyContinuous := HasPDF.absolutelyContinuous .. }
theorem HasPDF.congr (hXY : X =ᵐ[ℙ] Y) [hX : HasPDF X ℙ μ] : HasPDF Y ℙ μ :=
⟨(HasPDF.aemeasurable X ℙ μ).congr hXY, ℙ.map_congr hXY ▸ hX.haveLebesgueDecomposition,
ℙ.map_congr hXY ▸ hX.absolutelyContinuous⟩
theorem HasPDF.congr_iff (hXY : X =ᵐ[ℙ] Y) : HasPDF X ℙ μ ↔ HasPDF Y ℙ μ :=
⟨fun _ ↦ HasPDF.congr hXY, fun _ ↦ HasPDF.congr hXY.symm⟩
@[deprecated (since := "2024-10-28")] alias HasPDF.congr' := HasPDF.congr_iff
/-- X `HasPDF` if there is a pdf `f` such that `map X ℙ = μ.withDensity f`. -/
theorem hasPDF_of_map_eq_withDensity (hX : AEMeasurable X ℙ) (f : E → ℝ≥0∞) (hf : AEMeasurable f μ)
(h : map X ℙ = μ.withDensity f) : HasPDF X ℙ μ := by
refine ⟨hX, ?_, ?_⟩ <;> rw [h]
· rw [withDensity_congr_ae hf.ae_eq_mk]
exact haveLebesgueDecomposition_withDensity μ hf.measurable_mk
· exact withDensity_absolutelyContinuous μ f
end HasPDF
/-- If `X` is a random variable, then `pdf X ℙ μ`
is the Radon–Nikodym derivative of the push-forward measure of `ℙ` along `X` with respect to `μ`. -/
def pdf {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :
E → ℝ≥0∞ :=
(map X ℙ).rnDeriv μ
theorem pdf_def {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E} :
pdf X ℙ μ = (map X ℙ).rnDeriv μ := rfl
theorem pdf_of_not_aemeasurable {_ : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
{X : Ω → E} (hX : ¬AEMeasurable X ℙ) : pdf X ℙ μ =ᵐ[μ] 0 := by
rw [pdf_def, map_of_not_aemeasurable hX]
exact rnDeriv_zero μ
theorem pdf_of_not_haveLebesgueDecomposition {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
{μ : Measure E} {X : Ω → E} (h : ¬(map X ℙ).HaveLebesgueDecomposition μ) : pdf X ℙ μ = 0 :=
rnDeriv_of_not_haveLebesgueDecomposition h
theorem aemeasurable_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
(X : Ω → E) (h : ¬pdf X ℙ μ =ᵐ[μ] 0) : AEMeasurable X ℙ := by
contrapose! h
exact pdf_of_not_aemeasurable h
theorem hasPDF_of_pdf_ne_zero {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E} {X : Ω → E}
(hac : map X ℙ ≪ μ) (hpdf : ¬pdf X ℙ μ =ᵐ[μ] 0) : HasPDF X ℙ μ := by
refine ⟨?_, ?_, hac⟩
· exact aemeasurable_of_pdf_ne_zero X hpdf
· contrapose! hpdf
have := pdf_of_not_haveLebesgueDecomposition hpdf
filter_upwards using congrFun this
@[measurability]
theorem measurable_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : Measurable (pdf X ℙ μ) := by
exact measurable_rnDeriv _ _
theorem withDensity_pdf_le_map {_ : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) : μ.withDensity (pdf X ℙ μ) ≤ map X ℙ :=
withDensity_rnDeriv_le _ _
theorem setLIntegral_pdf_le_map {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) (s : Set E) :
∫⁻ x in s, pdf X ℙ μ x ∂μ ≤ map X ℙ s := by
apply (withDensity_apply_le _ s).trans
exact withDensity_pdf_le_map _ _ _ s
theorem map_eq_withDensity_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] :
map X ℙ = μ.withDensity (pdf X ℙ μ) := by
rw [pdf_def, withDensity_rnDeriv_eq _ _ hX.absolutelyContinuous]
theorem map_eq_setLIntegral_pdf {m : MeasurableSpace Ω} (X : Ω → E) (ℙ : Measure Ω)
(μ : Measure E := by volume_tac) [hX : HasPDF X ℙ μ] {s : Set E}
(hs : MeasurableSet s) : map X ℙ s = ∫⁻ x in s, pdf X ℙ μ x ∂μ := by
rw [← withDensity_apply _ hs, map_eq_withDensity_pdf X ℙ μ]
namespace pdf
variable {m : MeasurableSpace Ω} {ℙ : Measure Ω} {μ : Measure E}
protected theorem congr {X Y : Ω → E} (hXY : X =ᵐ[ℙ] Y) : pdf X ℙ μ = pdf Y ℙ μ := by
rw [pdf_def, pdf_def, map_congr hXY]
theorem lintegral_eq_measure_univ {X : Ω → E} [HasPDF X ℙ μ] :
∫⁻ x, pdf X ℙ μ x ∂μ = ℙ Set.univ := by
rw [← setLIntegral_univ, ← map_eq_setLIntegral_pdf X ℙ μ MeasurableSet.univ,
map_apply_of_aemeasurable (HasPDF.aemeasurable X ℙ μ) MeasurableSet.univ, Set.preimage_univ]
theorem eq_of_map_eq_withDensity [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f := by
rw [map_eq_withDensity_pdf X ℙ μ]
apply withDensity_eq_iff (measurable_pdf X ℙ μ).aemeasurable hmf
rw [lintegral_eq_measure_univ]
exact measure_ne_top _ _
theorem eq_of_map_eq_withDensity' [SigmaFinite μ] {X : Ω → E} [HasPDF X ℙ μ] (f : E → ℝ≥0∞)
(hmf : AEMeasurable f μ) : map X ℙ = μ.withDensity f ↔ pdf X ℙ μ =ᵐ[μ] f :=
map_eq_withDensity_pdf X ℙ μ ▸
withDensity_eq_iff_of_sigmaFinite (measurable_pdf X ℙ μ).aemeasurable hmf
nonrec theorem ae_lt_top [IsFiniteMeasure ℙ] {μ : Measure E} {X : Ω → E} :
∀ᵐ x ∂μ, pdf X ℙ μ x < ∞ :=
rnDeriv_lt_top (map X ℙ) μ
nonrec theorem ofReal_toReal_ae_eq [IsFiniteMeasure ℙ] {X : Ω → E} :
(fun x => ENNReal.ofReal (pdf X ℙ μ x).toReal) =ᵐ[μ] pdf X ℙ μ :=
ofReal_toReal_ae_eq ae_lt_top
section IntegralPDFMul
/-- **The Law of the Unconscious Statistician** for nonnegative random variables. -/
theorem lintegral_pdf_mul {X : Ω → E} [HasPDF X ℙ μ] {f : E → ℝ≥0∞}
(hf : AEMeasurable f μ) : ∫⁻ x, pdf X ℙ μ x * f x ∂μ = ∫⁻ x, f (X x) ∂ℙ := by
rw [pdf_def,
← lintegral_map' (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
lintegral_rnDeriv_mul HasPDF.absolutelyContinuous hf]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
theorem integrable_pdf_smul_iff [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) :
Integrable (fun x => (pdf X ℙ μ x).toReal • f x) μ ↔ Integrable (fun x => f (X x)) ℙ := by
rw [← Function.comp_def,
← integrable_map_measure (hf.mono_ac HasPDF.absolutelyContinuous) (HasPDF.aemeasurable X ℙ μ),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integrable_rnDeriv_smul_iff HasPDF.absolutelyContinuous]
rw [withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
/-- **The Law of the Unconscious Statistician**: Given a random variable `X` and a measurable
function `f`, `f ∘ X` is a random variable with expectation `∫ x, pdf X x • f x ∂μ`
where `μ` is a measure on the codomain of `X`. -/
theorem integral_pdf_smul [IsFiniteMeasure ℙ] {X : Ω → E} [HasPDF X ℙ μ] {f : E → F}
(hf : AEStronglyMeasurable f μ) : ∫ x, (pdf X ℙ μ x).toReal • f x ∂μ = ∫ x, f (X x) ∂ℙ := by
rw [← integral_map (HasPDF.aemeasurable X ℙ μ) (hf.mono_ac HasPDF.absolutelyContinuous),
map_eq_withDensity_pdf X ℙ μ, pdf_def, integral_rnDeriv_smul HasPDF.absolutelyContinuous,
withDensity_rnDeriv_eq _ _ HasPDF.absolutelyContinuous]
end IntegralPDFMul
section
|
variable {F : Type*} [MeasurableSpace F] {ν : Measure F} (X : Ω → E) [HasPDF X ℙ μ] {g : E → F}
/-- A random variable that `HasPDF` transformed under a `QuasiMeasurePreserving`
map also `HasPDF` if `(map g (map X ℙ)).HaveLebesgueDecomposition μ`.
| Mathlib/Probability/Density.lean | 239 | 243 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.WSeq.Basic
import Mathlib.Data.WSeq.Defs
import Mathlib.Data.WSeq.Productive
import Mathlib.Data.WSeq.Relation
deprecated_module (since := "2025-04-13")
| Mathlib/Data/Seq/WSeq.lean | 1,115 | 1,116 | |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Module.BigOperators
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Squarefree
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Tactic.ArithMult
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `IsMultiplicative` when `x.Coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function (spelled `moebius` in code).
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero`
* And variants that apply when the equalities only hold on a set `S : Set ℕ` such that
`m ∣ n → n ∈ S → m ∈ S`:
* `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero`
## Notation
All notation is localized in the namespace `ArithmeticFunction`.
The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names.
In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`,
`ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`,
`ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`,
to allow for selective access to these notations.
The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation
`∏ᵖ p ∣ n, f p` when applied to `n`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open Finset
open Nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by
Dirichlet convolution. -/
def ArithmeticFunction [Zero R] :=
ZeroHom ℕ R
instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) :=
inferInstanceAs (Zero (ZeroHom ℕ R))
instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R))
variable {R}
namespace ArithmeticFunction
section Zero
variable [Zero R]
instance : FunLike (ArithmeticFunction R) ℕ R :=
inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R)
@[simp]
theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl
@[simp]
theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _
(ZeroHom.mk f hf) = f := rfl
@[simp]
theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 :=
ZeroHom.map_zero' f
theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g :=
DFunLike.coe_fn_eq
@[simp]
theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 :=
ZeroHom.zero_apply x
@[ext]
theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g :=
ZeroHom.ext h
section One
variable [One R]
instance one : One (ArithmeticFunction R) :=
⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩
theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 :=
rfl
@[simp]
theorem one_one : (1 : ArithmeticFunction R) 1 = 1 :=
rfl
@[simp]
theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 :=
if_neg h
end One
end Zero
/-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline
this in `natCoe` because it gets unfolded too much. -/
@[coe]
def natToArithmeticFunction [AddMonoidWithOne R] :
(ArithmeticFunction ℕ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) :=
⟨natToArithmeticFunction⟩
@[simp]
theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f :=
ext fun _ => cast_id _
@[simp]
theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x :=
rfl
/-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline
this in `intCoe` because it gets unfolded too much. -/
@[coe]
def ofInt [AddGroupWithOne R] :
(ArithmeticFunction ℤ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) :=
⟨ofInt⟩
@[simp]
theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f :=
ext fun _ => Int.cast_id
@[simp]
theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x := rfl
@[simp]
theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} :
((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by
ext
simp
@[simp]
theorem natCoe_one [AddMonoidWithOne R] :
((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
@[simp]
theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) :
ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
section AddMonoid
variable [AddMonoid R]
instance add : Add (ArithmeticFunction R) :=
⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩
@[simp]
theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n :=
rfl
instance instAddMonoid : AddMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.zero R,
ArithmeticFunction.add with
add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _
zero_add := fun _ => ext fun _ => zero_add _
add_zero := fun _ => ext fun _ => add_zero _
nsmul := nsmulRec }
end AddMonoid
instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid,
ArithmeticFunction.one with
natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩
natCast_zero := by ext; simp
natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] }
instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ }
instance [NegZeroClass R] : Neg (ArithmeticFunction R) where
neg f := ⟨fun n => -f n, by simp⟩
instance [AddGroup R] : AddGroup (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with
neg_add_cancel := fun _ => ext fun _ => neg_add_cancel _
zsmul := zsmulRec }
instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) :=
{ show AddGroup (ArithmeticFunction R) by infer_instance with
add_comm := fun _ _ ↦ add_comm _ _ }
section SMul
variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) :=
⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} :
(f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd :=
rfl
end SMul
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [Semiring R] : Mul (ArithmeticFunction R) :=
⟨(· • ·)⟩
@[simp]
theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} :
(f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd :=
rfl
theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp
@[simp, norm_cast]
theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} :
(↑(f * g) : ArithmeticFunction R) = f * g := by
ext n
simp
@[simp, norm_cast]
theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} :
(↑(f * g) : ArithmeticFunction R) = ↑f * g := by
ext n
simp
section Module
variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :
(f * g) • h = f • g • h := by
ext n
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc)
theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff]
simp [y1ne]
end Module
section Semiring
variable [Semiring R]
instance instMonoid : Monoid (ArithmeticFunction R) :=
{ one := One.one
mul := Mul.mul
one_mul := one_smul'
mul_one := fun f => by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro ⟨y₁, y₂⟩ ymem ynmem
have y2ne : y₂ ≠ 1 := by
intro con
simp_all
simp [y2ne]
mul_assoc := mul_smul' }
instance instSemiring : Semiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoidWithOne,
ArithmeticFunction.instMonoid,
ArithmeticFunction.instAddCommMonoid with
zero_mul := fun f => by
ext
simp
mul_zero := fun f => by
ext
simp
left_distrib := fun a b c => by
ext
simp [← sum_add_distrib, mul_add]
right_distrib := fun a b c => by
ext
simp [← sum_add_distrib, add_mul] }
end Semiring
instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
mul_comm := fun f g => by
ext
rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map]
simp [mul_comm] }
instance [CommRing R] : CommRing (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
neg_add_cancel := neg_add_cancel
mul_comm := mul_comm
zsmul := (· • ·) }
instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] :
Module (ArithmeticFunction R) (ArithmeticFunction M) where
one_smul := one_smul'
mul_smul := mul_smul'
smul_add r x y := by
ext
simp only [sum_add_distrib, smul_add, smul_apply, add_apply]
smul_zero r := by
ext
simp only [smul_apply, sum_const_zero, smul_zero, zero_apply]
add_smul r s x := by
ext
simp only [add_smul, sum_add_distrib, smul_apply, add_apply]
zero_smul r := by
ext
simp only [smul_apply, sum_const_zero, zero_smul, zero_apply]
section Zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/
def zeta : ArithmeticFunction ℕ :=
⟨fun x => ite (x = 0) 0 1, rfl⟩
@[inherit_doc]
scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta
@[simp]
theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 :=
rfl
theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 :=
if_neg h
-- Porting note: removed `@[simp]`, LHS not in normal form
theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [MulAction R M]
{f : ArithmeticFunction M} {x : ℕ} :
((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by
rw [smul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.snd
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul]
· rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(↑ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply
theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]
theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_zeta_mul_apply]
theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [← natCoe_nat ζ, coe_mul_zeta_apply]
end Zeta
open ArithmeticFunction
section Pmul
/-- This is the pointwise product of `ArithmeticFunction`s. -/
def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun x => f x * g x, by simp⟩
@[simp]
theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x :=
rfl
theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by
ext
simp [mul_comm]
lemma pmul_assoc [SemigroupWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) :
pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by
ext
simp only [pmul_apply, mul_assoc]
section NonAssocSemiring
variable [NonAssocSemiring R]
@[simp]
theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
@[simp]
theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
end NonAssocSemiring
variable [Semiring R]
/-- This is the pointwise power of `ArithmeticFunction`s. -/
def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R :=
if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩
@[simp]
theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl]
@[simp]
theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by
rw [ppow, dif_neg (Nat.ne_of_gt kpos), coe_mk]
theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ']
induction k <;> simp
theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ]
induction k <;> simp
end Pmul
section Pdiv
/-- This is the pointwise division of `ArithmeticFunction`s. -/
def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩
@[simp]
theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) :
pdiv f g n = f n / g n := rfl
/-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes
values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/
@[simp]
theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) :
pdiv f zeta = f := by
ext n
cases n <;> simp [succ_ne_zero]
end Pdiv
section ProdPrimeFactors
/-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/
def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where
toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p
map_zero' := if_pos rfl
open Batteries.ExtendedBinder
/-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/
scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term
scoped macro_rules (kind := bigproddvd)
| `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n)
@[simp]
theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) :
∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p :=
if_neg hn
end ProdPrimeFactors
/-- Multiplicative functions -/
def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop :=
f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n
namespace IsMultiplicative
section MonoidWithZero
| variable [MonoidWithZero R]
| Mathlib/NumberTheory/ArithmeticFunction.lean | 540 | 540 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Primrec
import Mathlib.Data.Nat.PSub
import Mathlib.Data.PFun
/-!
# The partial recursive functions
The partial recursive functions are defined similarly to the primitive
recursive functions, but now all functions are partial, implemented
using the `Part` monad, and there is an additional operation, called
μ-recursion, which performs unbounded minimization: `μ f` returns the
least natural number `n` for which `f n = 0`, or diverges if such `n` doesn't exist.
## Main definitions
- `Nat.Partrec f`: `f` is partial recursive, for functions `f : ℕ →. ℕ`
- `Partrec f`: `f` is partial recursive, for partial functions between `Primcodable` types
- `Computable f`: `f` is partial recursive, for total functions between `Primcodable` types
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open List (Vector)
open Encodable Denumerable Part
attribute [-simp] not_forall
namespace Nat
section Rfind
variable (p : ℕ →. Bool)
private def lbp (m n : ℕ) : Prop :=
m = n + 1 ∧ ∀ k ≤ n, false ∈ p k
private def wf_lbp (H : ∃ n, true ∈ p n ∧ ∀ k < n, (p k).Dom) : WellFounded (lbp p) :=
⟨by
let ⟨n, pn⟩ := H
suffices ∀ m k, n ≤ k + m → Acc (lbp p) k by exact fun a => this _ _ (Nat.le_add_left _ _)
intro m k kn
induction' m with m IH generalizing k <;> refine ⟨_, fun y r => ?_⟩ <;> rcases r with ⟨rfl, a⟩
· injection mem_unique pn.1 (a _ kn)
· exact IH _ (by rw [Nat.add_right_comm]; exact kn)⟩
variable (H : ∃ n, true ∈ p n ∧ ∀ k < n, (p k).Dom)
/-- Find the smallest `n` satisfying `p n`, where all `p k` for `k < n` are defined as false.
Returns a subtype. -/
def rfindX : { n // true ∈ p n ∧ ∀ m < n, false ∈ p m } :=
suffices ∀ k, (∀ n < k, false ∈ p n) → { n // true ∈ p n ∧ ∀ m < n, false ∈ p m } from
this 0 fun _ => (Nat.not_lt_zero _).elim
@WellFounded.fix _ _ (lbp p) (wf_lbp p H)
(by
intro m IH al
have pm : (p m).Dom := by
rcases H with ⟨n, h₁, h₂⟩
rcases lt_trichotomy m n with (h₃ | h₃ | h₃)
· exact h₂ _ h₃
· rw [h₃]
exact h₁.fst
· injection mem_unique h₁ (al _ h₃)
cases e : (p m).get pm
· suffices ∀ᵉ k ≤ m, false ∈ p k from IH _ ⟨rfl, this⟩ fun n h => this _ (le_of_lt_succ h)
intro n h
rcases h.lt_or_eq_dec with h | h
· exact al _ h
· rw [h]
exact ⟨_, e⟩
· exact ⟨m, ⟨_, e⟩, al⟩)
end Rfind
/-- Find the smallest `n` satisfying `p n`, where all `p k` for `k < n` are defined as false.
Returns a `Part`. -/
def rfind (p : ℕ →. Bool) : Part ℕ :=
⟨_, fun h => (rfindX p h).1⟩
theorem rfind_spec {p : ℕ →. Bool} {n : ℕ} (h : n ∈ rfind p) : true ∈ p n :=
h.snd ▸ (rfindX p h.fst).2.1
theorem rfind_min {p : ℕ →. Bool} {n : ℕ} (h : n ∈ rfind p) : ∀ {m : ℕ}, m < n → false ∈ p m :=
@(h.snd ▸ @((rfindX p h.fst).2.2))
@[simp]
theorem rfind_dom {p : ℕ →. Bool} :
(rfind p).Dom ↔ ∃ n, true ∈ p n ∧ ∀ {m : ℕ}, m < n → (p m).Dom :=
Iff.rfl
theorem rfind_dom' {p : ℕ →. Bool} :
(rfind p).Dom ↔ ∃ n, true ∈ p n ∧ ∀ {m : ℕ}, m ≤ n → (p m).Dom :=
exists_congr fun _ =>
and_congr_right fun pn =>
⟨fun H _ h => (Decidable.eq_or_lt_of_le h).elim (fun e => e.symm ▸ pn.fst) (H _), fun H _ h =>
H (le_of_lt h)⟩
@[simp]
theorem mem_rfind {p : ℕ →. Bool} {n : ℕ} :
n ∈ rfind p ↔ true ∈ p n ∧ ∀ {m : ℕ}, m < n → false ∈ p m :=
⟨fun h => ⟨rfind_spec h, @rfind_min _ _ h⟩, fun ⟨h₁, h₂⟩ => by
let ⟨m, hm⟩ := dom_iff_mem.1 <| (@rfind_dom p).2 ⟨_, h₁, fun {m} mn => (h₂ mn).fst⟩
rcases lt_trichotomy m n with (h | h | h)
· injection mem_unique (h₂ h) (rfind_spec hm)
· rwa [← h]
· injection mem_unique h₁ (rfind_min hm h)⟩
theorem rfind_min' {p : ℕ → Bool} {m : ℕ} (pm : p m) : ∃ n ∈ rfind p, n ≤ m :=
have : true ∈ (p : ℕ →. Bool) m := ⟨trivial, pm⟩
let ⟨n, hn⟩ := dom_iff_mem.1 <| (@rfind_dom p).2 ⟨m, this, fun {_} _ => ⟨⟩⟩
⟨n, hn, not_lt.1 fun h => by injection mem_unique this (rfind_min hn h)⟩
theorem rfind_zero_none (p : ℕ →. Bool) (p0 : p 0 = Part.none) : rfind p = Part.none :=
eq_none_iff.2 fun _ h =>
let ⟨_, _, h₂⟩ := rfind_dom'.1 h.fst
(p0 ▸ h₂ (zero_le _) : (@Part.none Bool).Dom)
/-- Find the smallest `n` satisfying `f n`, where all `f k` for `k < n` are defined as false.
Returns a `Part`. -/
def rfindOpt {α} (f : ℕ → Option α) : Part α :=
(rfind fun n => (f n).isSome).bind fun n => f n
theorem rfindOpt_spec {α} {f : ℕ → Option α} {a} (h : a ∈ rfindOpt f) : ∃ n, a ∈ f n :=
let ⟨n, _, h₂⟩ := mem_bind_iff.1 h
⟨n, mem_coe.1 h₂⟩
theorem rfindOpt_dom {α} {f : ℕ → Option α} : (rfindOpt f).Dom ↔ ∃ n a, a ∈ f n :=
⟨fun h => (rfindOpt_spec ⟨h, rfl⟩).imp fun _ h => ⟨_, h⟩, fun h => by
have h' : ∃ n, (f n).isSome := h.imp fun n => Option.isSome_iff_exists.2
have s := Nat.find_spec h'
have fd : (rfind fun n => (f n).isSome).Dom :=
⟨Nat.find h', by simpa using s.symm, fun _ _ => trivial⟩
refine ⟨fd, ?_⟩
have := rfind_spec (get_mem fd)
simpa using this⟩
theorem rfindOpt_mono {α} {f : ℕ → Option α} (H : ∀ {a m n}, m ≤ n → a ∈ f m → a ∈ f n) {a} :
a ∈ rfindOpt f ↔ ∃ n, a ∈ f n :=
⟨rfindOpt_spec, fun ⟨n, h⟩ => by
have h' := rfindOpt_dom.2 ⟨_, _, h⟩
obtain ⟨k, hk⟩ := rfindOpt_spec ⟨h', rfl⟩
have := (H (le_max_left _ _) h).symm.trans (H (le_max_right _ _) hk)
simp at this; simp [this, get_mem]⟩
/-- `Partrec f` means that the partial function `f : ℕ → ℕ` is partially recursive. -/
inductive Partrec : (ℕ →. ℕ) → Prop
| zero : Partrec (pure 0)
| succ : Partrec succ
| left : Partrec ↑fun n : ℕ => n.unpair.1
| right : Partrec ↑fun n : ℕ => n.unpair.2
| pair {f g} : Partrec f → Partrec g → Partrec fun n => pair <$> f n <*> g n
| comp {f g} : Partrec f → Partrec g → Partrec fun n => g n >>= f
| prec {f g} : Partrec f → Partrec g → Partrec (unpaired fun a n =>
n.rec (f a) fun y IH => do let i ← IH; g (pair a (pair y i)))
| rfind {f} : Partrec f → Partrec fun a => rfind fun n => (fun m => m = 0) <$> f (pair a n)
namespace Partrec
theorem of_eq {f g : ℕ →. ℕ} (hf : Partrec f) (H : ∀ n, f n = g n) : Partrec g :=
(funext H : f = g) ▸ hf
theorem of_eq_tot {f : ℕ →. ℕ} {g : ℕ → ℕ} (hf : Partrec f) (H : ∀ n, g n ∈ f n) : Partrec g :=
hf.of_eq fun n => eq_some_iff.2 (H n)
theorem of_primrec {f : ℕ → ℕ} (hf : Nat.Primrec f) : Partrec f := by
induction hf with
| zero => exact zero
| succ => exact succ
| left => exact left
| right => exact right
| pair _ _ pf pg =>
refine (pf.pair pg).of_eq_tot fun n => ?_
simp [Seq.seq]
| comp _ _ pf pg =>
refine (pf.comp pg).of_eq_tot fun n => (by simp)
| prec _ _ pf pg =>
refine (pf.prec pg).of_eq_tot fun n => ?_
simp only [unpaired, PFun.coe_val, bind_eq_bind]
induction n.unpair.2 with
| zero => simp
| succ m IH =>
simp only [mem_bind_iff, mem_some_iff]
exact ⟨_, IH, rfl⟩
protected theorem some : Partrec some :=
of_primrec Primrec.id
theorem none : Partrec fun _ => none :=
(of_primrec (Nat.Primrec.const 1)).rfind.of_eq fun _ =>
eq_none_iff.2 fun _ ⟨h, _⟩ => by simp at h
theorem prec' {f g h} (hf : Partrec f) (hg : Partrec g) (hh : Partrec h) :
Partrec fun a => (f a).bind fun n => n.rec (g a)
fun y IH => do {let i ← IH; h (Nat.pair a (Nat.pair y i))} :=
((prec hg hh).comp (pair Partrec.some hf)).of_eq fun a =>
ext fun s => by simp [Seq.seq]
theorem ppred : Partrec fun n => ppred n :=
have : Primrec₂ fun n m => if n = Nat.succ m then 0 else 1 :=
(Primrec.ite
| (@PrimrecRel.comp _ _ _ _ _ _ _ _ _ _
Primrec.eq Primrec.fst (_root_.Primrec.succ.comp Primrec.snd))
(_root_.Primrec.const 0) (_root_.Primrec.const 1)).to₂
(of_primrec (Primrec₂.unpaired'.2 this)).rfind.of_eq fun n => by
cases n <;> simp
| Mathlib/Computability/Partrec.lean | 207 | 211 |
/-
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 | 1,181 | 1,181 | |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kim Morrison, Ainsley Pahljina
-/
import Mathlib.RingTheory.Fintype
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Zify
/-!
# The Lucas-Lehmer test for Mersenne primes.
We define `lucasLehmerResidue : Π p : ℕ, ZMod (2^p - 1)`, and
prove `lucasLehmerResidue p = 0 → Prime (mersenne p)`.
We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne
primes using `lucas_lehmer_sufficiency`.
## TODO
- Show reverse implication.
- Speed up the calculations using `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`.
- Find some bigger primes!
## History
This development began as a student project by Ainsley Pahljina,
and was then cleaned up for mathlib by Kim Morrison.
The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro.
This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num`
extension and made to use kernel reductions by Kyle Miller.
-/
assert_not_exists TwoSidedIdeal
/-- The Mersenne numbers, 2^p - 1. -/
def mersenne (p : ℕ) : ℕ :=
2 ^ p - 1
theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦
(Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1
@[simp]
theorem mersenne_lt_mersenne {p q : ℕ} : mersenne p < mersenne q ↔ p < q :=
strictMono_mersenne.lt_iff_lt
@[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne
@[simp]
theorem mersenne_le_mersenne {p q : ℕ} : mersenne p ≤ mersenne q ↔ p ≤ q :=
strictMono_mersenne.le_iff_le
@[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne
@[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl
@[simp] lemma mersenne_odd : ∀ {p : ℕ}, Odd (mersenne p) ↔ p ≠ 0
| 0 => by simp
| p + 1 => by
simpa using Nat.Even.sub_odd (one_le_pow₀ one_le_two)
(even_two.pow_of_ne_zero p.succ_ne_zero) odd_one
@[simp] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0)
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos
/-- Extension for the `positivity` tactic: `mersenne`. -/
@[positivity mersenne _]
def evalMersenne : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℕ), ~q(mersenne $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(mersenne_pos_of_pos $pa))
| _ => pure (.nonnegative q(Nat.zero_le (mersenne $a)))
| _, _, _ => throwError "not mersenne"
end Mathlib.Meta.Positivity
@[simp]
theorem one_lt_mersenne {p : ℕ} : 1 < mersenne p ↔ 1 < p :=
mersenne_lt_mersenne (p := 1)
@[simp]
theorem succ_mersenne (k : ℕ) : mersenne k + 1 = 2 ^ k := by
rw [mersenne, tsub_add_cancel_of_le]
exact one_le_pow₀ (by norm_num)
namespace LucasLehmer
open Nat
/-!
We now define three(!) different versions of the recurrence
`s (i+1) = (s i)^2 - 2`.
These versions take values either in `ℤ`, in `ZMod (2^p - 1)`, or
in `ℤ` but applying `% (2^p - 1)` at each step.
They are each useful at different points in the proof,
so we take a moment setting up the lemmas relating them.
-/
/-- The recurrence `s (i+1) = (s i)^2 - 2` in `ℤ`. -/
def s : ℕ → ℤ
| 0 => 4
| i + 1 => s i ^ 2 - 2
/-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/
def sZMod (p : ℕ) : ℕ → ZMod (2 ^ p - 1)
| 0 => 4
| i + 1 => sZMod p i ^ 2 - 2
/-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `ℤ`. -/
def sMod (p : ℕ) : ℕ → ℤ
| 0 => 4 % (2 ^ p - 1)
| i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1)
theorem mersenne_int_pos {p : ℕ} (hp : p ≠ 0) : (0 : ℤ) < 2 ^ p - 1 :=
sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp
theorem mersenne_int_ne_zero (p : ℕ) (hp : p ≠ 0) : (2 ^ p - 1 : ℤ) ≠ 0 :=
(mersenne_int_pos hp).ne'
theorem sMod_nonneg (p : ℕ) (hp : p ≠ 0) (i : ℕ) : 0 ≤ sMod p i := by
cases i <;> dsimp [sMod]
· exact sup_eq_right.mp rfl
· apply Int.emod_nonneg
exact mersenne_int_ne_zero p hp
theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod]
theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by
rw [← sMod_mod]
refine (Int.emod_lt_abs _ (mersenne_int_ne_zero p hp)).trans_eq ?_
exact abs_of_nonneg (mersenne_int_pos hp).le
theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by
induction i with
| zero => dsimp [s, sZMod]; norm_num
| succ i ih => push_cast [s, sZMod, ih]; rfl
-- These next two don't make good `norm_cast` lemmas.
theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by
have : 1 ≤ b ^ p := Nat.one_le_pow p b w
norm_cast
theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) :=
Int.natCast_pow_pred 2 p (by decide)
theorem sZMod_eq_sMod (p : ℕ) (i : ℕ) : sZMod p i = (sMod p i : ZMod (2 ^ p - 1)) := by
induction i <;> push_cast [← Int.coe_nat_two_pow_pred p, sMod, sZMod, *] <;> rfl
/-- The Lucas-Lehmer residue is `s p (p-2)` in `ZMod (2^p - 1)`. -/
def lucasLehmerResidue (p : ℕ) : ZMod (2 ^ p - 1) :=
sZMod p (p - 2)
theorem residue_eq_zero_iff_sMod_eq_zero (p : ℕ) (w : 1 < p) :
lucasLehmerResidue p = 0 ↔ sMod p (p - 2) = 0 := by
dsimp [lucasLehmerResidue]
rw [sZMod_eq_sMod p]
constructor
· -- We want to use that fact that `0 ≤ s_mod p (p-2) < 2^p - 1`
-- and `lucas_lehmer_residue p = 0 → 2^p - 1 ∣ s_mod p (p-2)`.
intro h
simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says
simp only [ZMod.intCast_zmod_eq_zero_iff_dvd, ofNat_pos, pow_pos, cast_pred,
cast_pow, cast_ofNat] at h
apply Int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h <;> clear h
· exact sMod_nonneg _ (by positivity) _
· exact sMod_lt _ (by positivity) _
· intro h
rw [h]
simp
/-- **Lucas-Lehmer Test**: a Mersenne number `2^p-1` is prime if and only if
the Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero.
-/
def LucasLehmerTest (p : ℕ) : Prop :=
lucasLehmerResidue p = 0
/-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `ℕ+`. -/
def q (p : ℕ) : ℕ+ :=
⟨Nat.minFac (mersenne p), Nat.minFac_pos (mersenne p)⟩
-- It would be nice to define this as (ℤ/qℤ)[x] / (x^2 - 3),
-- obtaining the ring structure for free,
-- but that seems to be more trouble than it's worth;
-- if it were easy to make the definition,
-- cardinality calculations would be somewhat more involved, too.
/-- We construct the ring `X q` as ℤ/qℤ + √3 ℤ/qℤ. -/
def X (q : ℕ+) : Type :=
ZMod q × ZMod q
namespace X
variable {q : ℕ+}
instance : Inhabited (X q) := inferInstanceAs (Inhabited (ZMod q × ZMod q))
instance : Fintype (X q) := inferInstanceAs (Fintype (ZMod q × ZMod q))
instance : DecidableEq (X q) := inferInstanceAs (DecidableEq (ZMod q × ZMod q))
instance : AddCommGroup (X q) := inferInstanceAs (AddCommGroup (ZMod q × ZMod q))
@[ext]
theorem ext {x y : X q} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := by
cases x; cases y; congr
@[simp] theorem zero_fst : (0 : X q).1 = 0 := rfl
@[simp] theorem zero_snd : (0 : X q).2 = 0 := rfl
@[simp]
theorem add_fst (x y : X q) : (x + y).1 = x.1 + y.1 :=
rfl
@[simp]
theorem add_snd (x y : X q) : (x + y).2 = x.2 + y.2 :=
rfl
@[simp]
theorem neg_fst (x : X q) : (-x).1 = -x.1 :=
rfl
@[simp]
theorem neg_snd (x : X q) : (-x).2 = -x.2 :=
rfl
instance : Mul (X q) where mul x y := (x.1 * y.1 + 3 * x.2 * y.2, x.1 * y.2 + x.2 * y.1)
@[simp]
theorem mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 :=
rfl
@[simp]
theorem mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 :=
rfl
instance : One (X q) where one := ⟨1, 0⟩
@[simp]
theorem one_fst : (1 : X q).1 = 1 :=
rfl
@[simp]
theorem one_snd : (1 : X q).2 = 0 :=
rfl
instance : Monoid (X q) :=
{ inferInstanceAs (Mul (X q)), inferInstanceAs (One (X q)) with
mul_assoc := fun x y z => by ext <;> dsimp <;> ring
one_mul := fun x => by ext <;> simp
mul_one := fun x => by ext <;> simp }
instance : NatCast (X q) where
natCast := fun n => ⟨n, 0⟩
@[simp] theorem fst_natCast (n : ℕ) : (n : X q).fst = (n : ZMod q) := rfl
@[simp] theorem snd_natCast (n : ℕ) : (n : X q).snd = (0 : ZMod q) := rfl
@[simp] theorem ofNat_fst (n : ℕ) [n.AtLeastTwo] :
(ofNat(n) : X q).fst = OfNat.ofNat n :=
rfl
@[simp] theorem ofNat_snd (n : ℕ) [n.AtLeastTwo] :
(ofNat(n) : X q).snd = 0 :=
rfl
instance : AddGroupWithOne (X q) :=
{ inferInstanceAs (Monoid (X q)), inferInstanceAs (AddCommGroup (X q)),
inferInstanceAs (NatCast (X q)) with
natCast_zero := by ext <;> simp
natCast_succ := fun _ ↦ by ext <;> simp
intCast := fun n => ⟨n, 0⟩
intCast_ofNat := fun n => by ext <;> simp
intCast_negSucc := fun n => by ext <;> simp }
theorem left_distrib (x y z : X q) : x * (y + z) = x * y + x * z := by
ext <;> dsimp <;> ring
theorem right_distrib (x y z : X q) : (x + y) * z = x * z + y * z := by
ext <;> dsimp <;> ring
instance : Ring (X q) :=
{ inferInstanceAs (AddGroupWithOne (X q)), inferInstanceAs (AddCommGroup (X q)),
inferInstanceAs (Monoid (X q)) with
left_distrib := left_distrib
right_distrib := right_distrib
mul_zero := fun _ ↦ by ext <;> simp
zero_mul := fun _ ↦ by ext <;> simp }
instance : CommRing (X q) :=
{ inferInstanceAs (Ring (X q)) with
mul_comm := fun _ _ ↦ by ext <;> dsimp <;> ring }
instance [Fact (1 < (q : ℕ))] : Nontrivial (X q) :=
⟨⟨0, 1, ne_of_apply_ne Prod.fst zero_ne_one⟩⟩
@[simp]
theorem fst_intCast (n : ℤ) : (n : X q).fst = (n : ZMod q) :=
rfl
@[simp]
theorem snd_intCast (n : ℤ) : (n : X q).snd = (0 : ZMod q) :=
rfl
@[norm_cast]
theorem coe_mul (n m : ℤ) : ((n * m : ℤ) : X q) = (n : X q) * (m : X q) := by ext <;> simp
@[norm_cast]
theorem coe_natCast (n : ℕ) : ((n : ℤ) : X q) = (n : X q) := by ext <;> simp
/-- The cardinality of `X` is `q^2`. -/
theorem card_eq : Fintype.card (X q) = q ^ 2 := by
dsimp [X]
rw [Fintype.card_prod, ZMod.card q, sq]
/-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/
nonrec theorem card_units_lt (w : 1 < q) : Fintype.card (X q)ˣ < q ^ 2 := by
have : Fact (1 < (q : ℕ)) := ⟨w⟩
convert card_units_lt (X q)
rw [card_eq]
/-- We define `ω = 2 + √3`. -/
def ω : X q := (2, 1)
/-- We define `ωb = 2 - √3`, which is the inverse of `ω`. -/
def ωb : X q := (2, -1)
theorem ω_mul_ωb (q : ℕ+) : (ω : X q) * ωb = 1 := by
dsimp [ω, ωb]
ext <;> simp; ring
theorem ωb_mul_ω (q : ℕ+) : (ωb : X q) * ω = 1 := by
rw [mul_comm, ω_mul_ωb]
|
/-- A closed form for the recurrence relation. -/
| Mathlib/NumberTheory/LucasLehmer.lean | 342 | 343 |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Nat.Even
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Nat.Cast.Commute
import Mathlib.Data.Set.Operations
import Mathlib.Logic.Function.Iterate
/-!
# Even and odd elements in rings
This file defines odd elements and proves some general facts about even and odd elements of rings.
As opposed to `Even`, `Odd` does not have a multiplicative counterpart.
## TODO
Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring`
assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved
to `Mathlib.Algebra.Group.Even`.
## See also
`Mathlib.Algebra.Group.Even` for the definition of even elements.
-/
assert_not_exists DenselyOrdered OrderedRing
open MulOpposite
variable {F α β : Type*}
section Monoid
variable [Monoid α] [HasDistribNeg α] {n : ℕ} {a : α}
@[simp] lemma Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by
rintro ⟨c, rfl⟩ a
simp_rw [← two_mul, pow_mul, neg_sq]
lemma Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow]
end Monoid
section DivisionMonoid
variable [DivisionMonoid α] [HasDistribNeg α] {a : α} {n : ℤ}
lemma Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by
rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg]
lemma Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow]
end DivisionMonoid
@[simp] lemma IsSquare.zero [MulZeroClass α] : IsSquare (0 : α) := ⟨0, (mul_zero _).symm⟩
section Semiring
variable [Semiring α] [Semiring β] {a b : α} {m n : ℕ}
lemma even_iff_exists_two_mul : Even a ↔ ∃ b, a = 2 * b := by simp [even_iff_exists_two_nsmul]
lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul]
alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd
lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b :=
even_iff_two_dvd.2 <| ha.two_dvd.trans hab
lemma Dvd.dvd.even (hab : a ∣ b) (ha : Even a) : Even b := ha.trans_dvd hab
@[simp] lemma range_two_mul (α) [NonAssocSemiring α] :
Set.range (fun x : α ↦ 2 * x) = {a | Even a} := by
ext x
simp [eq_comm, two_mul, Even]
@[simp] lemma even_two : Even (2 : α) := ⟨1, by rw [one_add_one_eq_two]⟩
@[simp] lemma Even.mul_left (ha : Even a) (b) : Even (b * a) := ha.map (AddMonoidHom.mulLeft _)
@[simp] lemma Even.mul_right (ha : Even a) (b) : Even (a * b) := ha.map (AddMonoidHom.mulRight _)
lemma even_two_mul (a : α) : Even (2 * a) := ⟨a, two_mul _⟩
lemma Even.pow_of_ne_zero (ha : Even a) : ∀ {n : ℕ}, n ≠ 0 → Even (a ^ n)
| n + 1, _ => by rw [pow_succ]; exact ha.mul_left _
/-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/
def Odd (a : α) : Prop := ∃ k, a = 2 * k + 1
lemma odd_iff_exists_bit1 : Odd a ↔ ∃ b, a = 2 * b + 1 := exists_congr fun b ↦ by rw [two_mul]
alias ⟨Odd.exists_bit1, _⟩ := odd_iff_exists_bit1
@[simp] lemma range_two_mul_add_one (α : Type*) [Semiring α] :
Set.range (fun x : α ↦ 2 * x + 1) = {a | Odd a} := by ext x; simp [Odd, eq_comm]
lemma Even.add_odd : Even a → Odd b → Odd (a + b) := by
rintro ⟨a, rfl⟩ ⟨b, rfl⟩; exact ⟨a + b, by rw [mul_add, ← two_mul, add_assoc]⟩
lemma Even.odd_add (ha : Even a) (hb : Odd b) : Odd (b + a) := add_comm a b ▸ ha.add_odd hb
lemma Odd.add_even (ha : Odd a) (hb : Even b) : Odd (a + b) := add_comm a b ▸ hb.add_odd ha
lemma Odd.add_odd : Odd a → Odd b → Even (a + b) := by
| rintro ⟨a, rfl⟩ ⟨b, rfl⟩
refine ⟨a + b + 1, ?_⟩
| Mathlib/Algebra/Ring/Parity.lean | 106 | 107 |
/-
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, Jeremy Avigad
-/
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Data.Set.Finite.Range
import Mathlib.Data.Set.Lattice
import Mathlib.Topology.Defs.Filter
/-!
# Openness and closedness of a set
This file provides lemmas relating to the predicates `IsOpen` and `IsClosed` of a set endowed with
a topology.
## Implementation notes
Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in
<https://leanprover-community.github.io/theories/topology.html>.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
## Tags
topological space
-/
open Set Filter Topology
universe u v
/-- A constructor for topologies by specifying the closed sets,
and showing that they satisfy the appropriate conditions. -/
def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T)
(sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T)
(union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where
IsOpen X := Xᶜ ∈ T
isOpen_univ := by simp [empty_mem]
isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht
isOpen_sUnion s hs := by
simp only [Set.compl_sUnion]
exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy
section TopologicalSpace
variable {X : Type u} {ι : Sort v} {α : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop}
lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl
@[ext (iff := false)]
protected theorem TopologicalSpace.ext :
∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} :
t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s :=
⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩
theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s :=
rfl
variable [TopologicalSpace X]
theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) :=
isOpen_sUnion (forall_mem_range.2 h)
theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋃ i ∈ s, f i) :=
isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi
theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by
rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩)
lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) :
IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by
refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩
rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter]
exact isOpen_iUnion fun i ↦ h i
@[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by
rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim
theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) (h : ∀ t ∈ s, IsOpen t) :
IsOpen (⋂₀ s) := by
induction s, hs using Set.Finite.induction_on with
| empty => rw [sInter_empty]; exact isOpen_univ
| insert _ _ ih =>
simp only [sInter_insert, forall_mem_insert] at h ⊢
exact h.1.inter (ih h.2)
theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite)
(h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋂ i ∈ s, f i) :=
sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h)
theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) :
IsOpen (⋂ i, s i) :=
(finite_range _).isOpen_sInter (forall_mem_range.2 h)
theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋂ i ∈ s, f i) :=
s.finite_toSet.isOpen_biInter h
@[simp]
theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*]
theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } :=
IsOpen.inter
@[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s :=
⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩
theorem TopologicalSpace.ext_iff_isClosed {X} {t₁ t₂ : TopologicalSpace X} :
t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by
rw [TopologicalSpace.ext_iff, compl_surjective.forall]
simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂]
alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed
theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩
@[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const
@[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const
lemma IsOpen.isLocallyClosed (hs : IsOpen s) : IsLocallyClosed s :=
⟨_, _, hs, isClosed_univ, (inter_univ _).symm⟩
lemma IsClosed.isLocallyClosed (hs : IsClosed s) : IsLocallyClosed s :=
⟨_, _, isOpen_univ, hs, (univ_inter _).symm⟩
theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by
simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter
theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by
simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion
theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) :=
isClosed_sInter <| forall_mem_range.2 h
theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋂ i ∈ s, f i) :=
isClosed_iInter fun i => isClosed_iInter <| h i
@[simp]
theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by
rw [← isOpen_compl_iff, compl_compl]
alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff
theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) :=
IsOpen.inter h₁ h₂.isOpen_compl
theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by
rw [← isOpen_compl_iff] at *
rw [compl_inter]
exact IsOpen.union h₁ h₂
theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) :=
IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂)
theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite)
(h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋃ i ∈ s, f i) := by
simp only [← isOpen_compl_iff, compl_iUnion] at *
exact hs.isOpen_biInter h
lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋃ i ∈ s, f i) :=
s.finite_toSet.isClosed_biUnion h
theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) :
IsClosed (⋃ i, s i) := by
simp only [← isOpen_compl_iff, compl_iUnion] at *
exact isOpen_iInter_of_finite h
theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) :
IsClosed { x | p x → q x } := by
simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq
theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } :=
isOpen_compl_iff.mpr
/-!
### Limits of filters in topological spaces
In this section we define functions that return a limit of a filter (or of a function along a
filter), if it exists, and a random point otherwise. These functions are rarely used in Mathlib,
most of the theorems are written using `Filter.Tendsto`. One of the reasons is that
`Filter.limUnder f g = x` is not equivalent to `Filter.Tendsto g f (𝓝 x)` unless the codomain is a
Hausdorff space and `g` has a limit along `f`.
-/
section lim
/-- If a filter `f` is majorated by some `𝓝 x`, then it is majorated by `𝓝 (Filter.lim f)`. We
formulate this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for
types without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify
this instance with any other instance. -/
theorem le_nhds_lim {f : Filter X} (h : ∃ x, f ≤ 𝓝 x) : f ≤ 𝓝 (@lim _ _ (nonempty_of_exists h) f) :=
Classical.epsilon_spec h
/-- If `g` tends to some `𝓝 x` along `f`, then it tends to `𝓝 (Filter.limUnder f g)`. We formulate
this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for types
without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify this
instance with any other instance. -/
theorem tendsto_nhds_limUnder {f : Filter α} {g : α → X} (h : ∃ x, Tendsto g f (𝓝 x)) :
Tendsto g f (𝓝 (@limUnder _ _ _ (nonempty_of_exists h) f g)) :=
le_nhds_lim h
theorem limUnder_of_not_tendsto [hX : Nonempty X] {f : Filter α} {g : α → X}
(h : ¬ ∃ x, Tendsto g f (𝓝 x)) :
limUnder f g = Classical.choice hX := by
simp_rw [Tendsto] at h
simp_rw [limUnder, lim, Classical.epsilon, Classical.strongIndefiniteDescription, dif_neg h]
end lim
end TopologicalSpace
| Mathlib/Topology/Basic.lean | 273 | 274 | |
/-
Copyright (c) 2021 Kalle Kytölä. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle Kytölä
-/
import Mathlib.MeasureTheory.Measure.FiniteMeasure
import Mathlib.MeasureTheory.Integral.Average
import Mathlib.MeasureTheory.Measure.Prod
/-!
# Probability measures
This file defines the type of probability measures on a given measurable space. When the underlying
space has a topology and the measurable space structure (sigma algebra) is finer than the Borel
sigma algebra, then the type of probability measures is equipped with the topology of convergence
in distribution (weak convergence of measures). The topology of convergence in distribution is the
coarsest topology w.r.t. which for every bounded continuous `ℝ≥0`-valued random variable `X`, the
expected value of `X` depends continuously on the choice of probability measure. This is a special
case of the topology of weak convergence of finite measures.
## Main definitions
The main definitions are
* the type `MeasureTheory.ProbabilityMeasure Ω` with the topology of convergence in
distribution (a.k.a. convergence in law, weak convergence of measures);
* `MeasureTheory.ProbabilityMeasure.toFiniteMeasure`: Interpret a probability measure as
a finite measure;
* `MeasureTheory.FiniteMeasure.normalize`: Normalize a finite measure to a probability measure
(returns junk for the zero measure).
* `MeasureTheory.ProbabilityMeasure.map`: The push-forward `f* μ` of a probability measure
`μ` on `Ω` along a measurable function `f : Ω → Ω'`.
## Main results
* `MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of
probability measures is characterized by the convergence of expected values of all bounded
continuous random variables. This shows that the chosen definition of topology coincides with
the common textbook definition of convergence in distribution, i.e., weak convergence of
measures. A similar characterization by the convergence of expected values (in the
`MeasureTheory.lintegral` sense) of all bounded continuous nonnegative random variables is
`MeasureTheory.ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto`.
* `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`: The convergence of finite
measures to a nonzero limit is characterized by the convergence of the probability-normalized
versions and of the total masses.
* `MeasureTheory.ProbabilityMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the
push-forward of probability measures `f* : ProbabilityMeasure Ω → ProbabilityMeasure Ω'` is
continuous.
* `MeasureTheory.ProbabilityMeasure.t2Space`: The topology of convergence in distribution is
Hausdorff on Borel spaces where indicators of closed sets have continuous decreasing
approximating sequences (in particular on any pseudo-metrizable spaces).
TODO:
* Probability measures form a convex space.
## Implementation notes
The topology of convergence in distribution on `MeasureTheory.ProbabilityMeasure Ω` is inherited
weak convergence of finite measures via the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
Like `MeasureTheory.FiniteMeasure Ω`, the implementation of `MeasureTheory.ProbabilityMeasure Ω`
is directly as a subtype of `MeasureTheory.Measure Ω`, and the coercion to a function is the
composition `ENNReal.toNNReal` and the coercion to function of `MeasureTheory.Measure Ω`.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
convergence in distribution, convergence in law, weak convergence of measures, probability measure
-/
noncomputable section
open Set Filter BoundedContinuousFunction Topology
open scoped ENNReal NNReal
namespace MeasureTheory
section ProbabilityMeasure
/-! ### Probability measures
In this section we define the type of probability measures on a measurable space `Ω`, denoted by
`MeasureTheory.ProbabilityMeasure Ω`.
If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma
algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.ProbabilityMeasure Ω` is
equipped with the topology of weak convergence of measures. Since every probability measure is a
finite measure, this is implemented as the induced topology from the mapping
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`.
-/
/-- Probability measures are defined as the subtype of measures that have the property of being
probability measures (i.e., their total mass is one). -/
def ProbabilityMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ :=
{ μ : Measure Ω // IsProbabilityMeasure μ }
namespace ProbabilityMeasure
variable {Ω : Type*} [MeasurableSpace Ω]
instance [Inhabited Ω] : Inhabited (ProbabilityMeasure Ω) :=
⟨⟨Measure.dirac default, Measure.dirac.isProbabilityMeasure⟩⟩
/-- Coercion from `MeasureTheory.ProbabilityMeasure Ω` to `MeasureTheory.Measure Ω`. -/
@[coe]
def toMeasure : ProbabilityMeasure Ω → Measure Ω := Subtype.val
/-- A probability measure can be interpreted as a measure. -/
instance : Coe (ProbabilityMeasure Ω) (MeasureTheory.Measure Ω) := { coe := toMeasure }
instance (μ : ProbabilityMeasure Ω) : IsProbabilityMeasure (μ : Measure Ω) :=
μ.prop
@[simp, norm_cast] lemma coe_mk (μ : Measure Ω) (hμ) : toMeasure ⟨μ, hμ⟩ = μ := rfl
@[simp]
theorem val_eq_to_measure (ν : ProbabilityMeasure Ω) : ν.val = (ν : Measure Ω) := rfl
theorem toMeasure_injective : Function.Injective ((↑) : ProbabilityMeasure Ω → Measure Ω) :=
Subtype.coe_injective
instance instFunLike : FunLike (ProbabilityMeasure Ω) (Set Ω) ℝ≥0 where
coe μ s := ((μ : Measure Ω) s).toNNReal
coe_injective' μ ν h := toMeasure_injective <| Measure.ext fun s _ ↦ by
simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s
lemma coeFn_def (μ : ProbabilityMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl
lemma coeFn_mk (μ : Measure Ω) (hμ) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl
@[simp, norm_cast]
lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) :
DFunLike.coe (F := ProbabilityMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl
@[simp, norm_cast]
theorem coeFn_univ (ν : ProbabilityMeasure Ω) : ν univ = 1 :=
congr_arg ENNReal.toNNReal ν.prop.measure_univ
theorem coeFn_univ_ne_zero (ν : ProbabilityMeasure Ω) : ν univ ≠ 0 := by
simp only [coeFn_univ, Ne, one_ne_zero, not_false_iff]
/-- A probability measure can be interpreted as a finite measure. -/
def toFiniteMeasure (μ : ProbabilityMeasure Ω) : FiniteMeasure Ω := ⟨μ, inferInstance⟩
@[simp] lemma coeFn_toFiniteMeasure (μ : ProbabilityMeasure Ω) : ⇑μ.toFiniteMeasure = μ := rfl
lemma toFiniteMeasure_apply (μ : ProbabilityMeasure Ω) (s : Set Ω) :
μ.toFiniteMeasure s = μ s := rfl
@[simp]
theorem toMeasure_comp_toFiniteMeasure_eq_toMeasure (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Measure Ω) = (ν : Measure Ω) := rfl
@[simp]
theorem coeFn_comp_toFiniteMeasure_eq_coeFn (ν : ProbabilityMeasure Ω) :
(ν.toFiniteMeasure : Set Ω → ℝ≥0) = (ν : Set Ω → ℝ≥0) := rfl
@[simp]
theorem toFiniteMeasure_apply_eq_apply (ν : ProbabilityMeasure Ω) (s : Set Ω) :
ν.toFiniteMeasure s = ν s := rfl
@[simp]
theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : ProbabilityMeasure Ω) (s : Set Ω) :
(ν s : ℝ≥0∞) = (ν : Measure Ω) s := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn, FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure,
toMeasure_comp_toFiniteMeasure_eq_toMeasure]
@[simp]
theorem null_iff_toMeasure_null (ν : ProbabilityMeasure Ω) (s : Set Ω) :
ν s = 0 ↔ (ν : Measure Ω) s = 0 :=
⟨fun h ↦ by rw [← ennreal_coeFn_eq_coeFn_toMeasure, h, ENNReal.coe_zero],
fun h ↦ congrArg ENNReal.toNNReal h⟩
theorem apply_mono (μ : ProbabilityMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by
rw [← coeFn_comp_toFiniteMeasure_eq_coeFn]
exact MeasureTheory.FiniteMeasure.apply_mono _ h
/-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable)
sets is the limit of the measures of the partial unions. -/
protected lemma tendsto_measure_iUnion_accumulate {ι : Type*} [Preorder ι]
[IsCountablyGenerated (atTop : Filter ι)] {μ : ProbabilityMeasure Ω} {f : ι → Set Ω} :
Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by
simpa [← ennreal_coeFn_eq_coeFn_toMeasure, ENNReal.tendsto_coe]
using tendsto_measure_iUnion_accumulate (μ := μ.toMeasure)
@[simp] theorem apply_le_one (μ : ProbabilityMeasure Ω) (s : Set Ω) : μ s ≤ 1 := by
simpa using apply_mono μ (subset_univ s)
theorem nonempty (μ : ProbabilityMeasure Ω) : Nonempty Ω := by
by_contra maybe_empty
have zero : (μ : Measure Ω) univ = 0 := by
rw [univ_eq_empty_iff.mpr (not_nonempty_iff.mp maybe_empty), measure_empty]
rw [measure_univ] at zero
exact zero_ne_one zero.symm
@[ext]
theorem eq_of_forall_toMeasure_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by
apply toMeasure_injective
ext1 s s_mble
exact h s s_mble
theorem eq_of_forall_apply_eq (μ ν : ProbabilityMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble
simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
@[simp]
theorem mass_toFiniteMeasure (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.mass = 1 :=
μ.coeFn_univ
theorem toFiniteMeasure_nonzero (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure ≠ 0 := by
simp [← FiniteMeasure.mass_nonzero_iff]
/-- The type of probability measures is a measurable space when equipped with the Giry monad. -/
instance : MeasurableSpace (ProbabilityMeasure Ω) := Subtype.instMeasurableSpace
lemma measurableSet_isProbabilityMeasure :
MeasurableSet { μ : Measure Ω | IsProbabilityMeasure μ } := by
suffices { μ : Measure Ω | IsProbabilityMeasure μ } = (fun μ => μ univ) ⁻¹' {1} by
rw [this]
exact Measure.measurable_coe MeasurableSet.univ (measurableSet_singleton 1)
ext _
apply isProbabilityMeasure_iff
/-- The monoidal product is a measurable function from the product of probability spaces over
`α` and `β` into the type of probability spaces over `α × β`. Lemma 4.1 of [A synthetic approach to
Markov kernels, conditional independence and theorems on sufficient statistics][fritz2020]. -/
theorem measurable_prod {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] :
Measurable (fun (μ : ProbabilityMeasure α × ProbabilityMeasure β)
↦ μ.1.toMeasure.prod μ.2.toMeasure) := by
apply Measurable.measure_of_isPiSystem_of_isProbabilityMeasure generateFrom_prod.symm
isPiSystem_prod _
simp only [mem_image2, mem_setOf_eq, forall_exists_index, and_imp]
intros _ u Hu v Hv Heq
simp_rw [← Heq, Measure.prod_prod]
apply Measurable.mul
· exact (Measure.measurable_coe Hu).comp (measurable_subtype_coe.comp measurable_fst)
· exact (Measure.measurable_coe Hv).comp (measurable_subtype_coe.comp measurable_snd)
section convergence_in_distribution
variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
theorem testAgainstNN_lipschitz (μ : ProbabilityMeasure Ω) :
LipschitzWith 1 fun f : Ω →ᵇ ℝ≥0 ↦ μ.toFiniteMeasure.testAgainstNN f :=
μ.mass_toFiniteMeasure ▸ μ.toFiniteMeasure.testAgainstNN_lipschitz
/-- The topology of weak convergence on `MeasureTheory.ProbabilityMeasure Ω`. This is inherited
(induced) from the topology of weak convergence of finite measures via the inclusion
`MeasureTheory.ProbabilityMeasure.toFiniteMeasure`. -/
instance : TopologicalSpace (ProbabilityMeasure Ω) :=
TopologicalSpace.induced toFiniteMeasure inferInstance
theorem toFiniteMeasure_continuous :
Continuous (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) :=
continuous_induced_dom
/-- Probability measures yield elements of the `WeakDual` of bounded continuous nonnegative
functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/
def toWeakDualBCNN : ProbabilityMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) :=
FiniteMeasure.toWeakDualBCNN ∘ toFiniteMeasure
@[simp]
theorem coe_toWeakDualBCNN (μ : ProbabilityMeasure Ω) :
⇑μ.toWeakDualBCNN = μ.toFiniteMeasure.testAgainstNN := rfl
@[simp]
theorem toWeakDualBCNN_apply (μ : ProbabilityMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
μ.toWeakDualBCNN f = (∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal := rfl
theorem toWeakDualBCNN_continuous : Continuous fun μ : ProbabilityMeasure Ω ↦ μ.toWeakDualBCNN :=
FiniteMeasure.toWeakDualBCNN_continuous.comp toFiniteMeasure_continuous
/- Integration of (nonnegative bounded continuous) test functions against Borel probability
measures depends continuously on the measure. -/
theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) :
Continuous fun μ : ProbabilityMeasure Ω ↦ μ.toFiniteMeasure.testAgainstNN f :=
(FiniteMeasure.continuous_testAgainstNN_eval f).comp toFiniteMeasure_continuous
-- The canonical mapping from probability measures to finite measures is an embedding.
theorem toFiniteMeasure_isEmbedding (Ω : Type*) [MeasurableSpace Ω] [TopologicalSpace Ω]
[OpensMeasurableSpace Ω] :
IsEmbedding (toFiniteMeasure : ProbabilityMeasure Ω → FiniteMeasure Ω) where
eq_induced := rfl
injective _μ _ν h := Subtype.eq <| congr_arg FiniteMeasure.toMeasure h
@[deprecated (since := "2024-10-26")]
alias toFiniteMeasure_embedding := toFiniteMeasure_isEmbedding
theorem tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds {δ : Type*} (F : Filter δ)
{μs : δ → ProbabilityMeasure Ω} {μ₀ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ₀) ↔ Tendsto (toFiniteMeasure ∘ μs) F (𝓝 μ₀.toFiniteMeasure) :=
(toFiniteMeasure_isEmbedding Ω).tendsto_nhds_iff
/-- A characterization of weak convergence of probability measures by the condition that the
integrals of every continuous bounded nonnegative function converge to the integral of the function
against the limit measure. -/
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0,
Tendsto (fun i ↦ ∫⁻ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) := by
rw [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds]
exact FiniteMeasure.tendsto_iff_forall_lintegral_tendsto
/-- The characterization of weak convergence of probability measures by the usual (defining)
condition that the integrals of every continuous bounded function converge to the integral of the
function against the limit measure. -/
theorem tendsto_iff_forall_integral_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i ↦ ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
simp [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds,
FiniteMeasure.tendsto_iff_forall_integral_tendsto]
theorem tendsto_iff_forall_integral_rclike_tendsto {γ : Type*} (𝕜 : Type*) [RCLike 𝕜]
{F : Filter γ} {μs : γ → ProbabilityMeasure Ω} {μ : ProbabilityMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ 𝕜,
Tendsto (fun i ↦ ∫ ω, f ω ∂(μs i : Measure Ω)) F (𝓝 (∫ ω, f ω ∂(μ : Measure Ω))) := by
simp [tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds,
FiniteMeasure.tendsto_iff_forall_integral_rclike_tendsto 𝕜]
lemma continuous_integral_boundedContinuousFunction
{α : Type*} [TopologicalSpace α] [MeasurableSpace α] [OpensMeasurableSpace α] (f : α →ᵇ ℝ) :
Continuous fun μ : ProbabilityMeasure α ↦ ∫ x, f x ∂μ := by
rw [continuous_iff_continuousAt]
intro μ
exact continuousAt_of_tendsto_nhds
(ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mp tendsto_id f)
end convergence_in_distribution -- section
section Hausdorff
variable [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [BorelSpace Ω]
variable (Ω)
/-- On topological spaces where indicators of closed sets have decreasing approximating sequences of
continuous functions (`HasOuterApproxClosed`), the topology of convergence in distribution of Borel
probability measures is Hausdorff (`T2Space`). -/
instance t2Space : T2Space (ProbabilityMeasure Ω) := (toFiniteMeasure_isEmbedding Ω).t2Space
end Hausdorff -- section
end ProbabilityMeasure
-- namespace
end ProbabilityMeasure
-- section
section NormalizeFiniteMeasure
/-! ### Normalization of finite measures to probability measures
This section is about normalizing finite measures to probability measures.
The weak convergence of finite measures to nonzero limit measures is characterized by
the convergence of the total mass and the convergence of the normalized probability
measures.
-/
namespace FiniteMeasure
variable {Ω : Type*} [Nonempty Ω] {m0 : MeasurableSpace Ω} (μ : FiniteMeasure Ω)
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
else
{ val := ↑(μ.mass⁻¹ • μ)
property := by
refine ⟨?_⟩
simp only [toMeasure_smul, Measure.coe_smul, Pi.smul_apply, Measure.nnreal_smul_coe_apply,
ENNReal.coe_inv zero, ennreal_mass]
rw [← Ne, ← ENNReal.coe_ne_zero, ennreal_mass] at zero
exact ENNReal.inv_mul_cancel zero μ.prop.measure_univ_lt_top.ne }
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
obtain rfl | h := eq_or_ne μ 0
· simp
have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
simp only [normalize, dif_neg mass_nonzero]
simp [ProbabilityMeasure.coe_mk, toMeasure_smul, mul_inv_cancel_left₀ mass_nonzero, coeFn_def]
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
apply eq_of_forall_apply_eq
intro s _s_mble
rw [μ.self_eq_mass_mul_normalize s, smul_apply, smul_eq_mul,
ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn]
theorem normalize_eq_of_nonzero (nonzero : μ ≠ 0) (s : Set Ω) : μ.normalize s = μ.mass⁻¹ * μ s := by
simp only [μ.self_eq_mass_mul_normalize, μ.mass_nonzero_iff.mpr nonzero, inv_mul_cancel_left₀,
Ne, not_false_iff]
theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) :
μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by
nth_rw 3 [μ.self_eq_mass_smul_normalize]
rw [← smul_assoc]
simp only [μ.mass_nonzero_iff.mpr nonzero, Algebra.id.smul_eq_mul, inv_mul_cancel₀, Ne,
not_false_iff, one_smul]
theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) :
(μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by
ext1 s _s_mble
rw [← μ.normalize.ennreal_coeFn_eq_coeFn_toMeasure s, μ.normalize_eq_of_nonzero nonzero s,
ENNReal.coe_mul, ennreal_coeFn_eq_coeFn_toMeasure]
exact Measure.coe_nnreal_smul_apply _ _ _
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
(μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
apply ProbabilityMeasure.eq_of_forall_apply_eq
intro s _s_mble
rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s]
simp only [ProbabilityMeasure.mass_toFiniteMeasure, inv_one, one_mul, μ.coeFn_toFiniteMeasure]
/-- Averaging with respect to a finite measure is the same as integrating against
`MeasureTheory.FiniteMeasure.normalize`. -/
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
(nonzero : μ ≠ 0) (f : Ω → E) :
average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average]
congr
simp [ENNReal.coe_inv (μ.mass_nonzero_iff.mpr nonzero), ennreal_mass]
variable [TopologicalSpace Ω]
theorem testAgainstNN_eq_mass_mul (f : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN f = μ.mass * μ.normalize.toFiniteMeasure.testAgainstNN f := by
nth_rw 1 [μ.self_eq_mass_smul_normalize]
rw [μ.normalize.toFiniteMeasure.smul_testAgainstNN_apply μ.mass f, smul_eq_mul]
theorem normalize_testAgainstNN (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
μ.normalize.toFiniteMeasure.testAgainstNN f = μ.mass⁻¹ * μ.testAgainstNN f := by
simp [μ.testAgainstNN_eq_mass_mul, inv_mul_cancel_left₀ <| μ.mass_nonzero_iff.mpr nonzero]
variable [OpensMeasurableSpace Ω]
variable {μ}
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
{F : Filter γ} {μs : γ → FiniteMeasure Ω}
(μs_lim : Tendsto (fun i ↦ (μs i).normalize) F (𝓝 μ.normalize))
(mass_lim : Tendsto (fun i ↦ (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i ↦ (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
by_cases h_mass : μ.mass = 0
· simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
eq_self_iff_true] at mass_lim ⊢
exact tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
simp_rw [fun i ↦ (μs i).testAgainstNN_eq_mass_mul f, μ.testAgainstNN_eq_mass_mul f]
rw [ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] at μs_lim
rw [tendsto_iff_forall_testAgainstNN_tendsto] at μs_lim
have lim_pair :
Tendsto (fun i ↦ (⟨(μs i).mass, (μs i).normalize.toFiniteMeasure.testAgainstNN f⟩ : ℝ≥0 × ℝ≥0))
F (𝓝 ⟨μ.mass, μ.normalize.toFiniteMeasure.testAgainstNN f⟩) :=
(Prod.tendsto_iff _ _).mpr ⟨mass_lim, μs_lim f⟩
exact tendsto_mul.comp lim_pair
theorem tendsto_normalize_testAgainstNN_of_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (μs_lim : Tendsto μs F (𝓝 μ)) (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i ↦ (μs i).normalize.toFiniteMeasure.testAgainstNN f) F
(𝓝 (μ.normalize.toFiniteMeasure.testAgainstNN f)) := by
have lim_mass := μs_lim.mass
have aux : {(0 : ℝ≥0)}ᶜ ∈ 𝓝 μ.mass :=
isOpen_compl_singleton.mem_nhds (μ.mass_nonzero_iff.mpr nonzero)
have eventually_nonzero : ∀ᶠ i in F, μs i ≠ 0 := by
simp_rw [← mass_nonzero_iff]
exact lim_mass aux
have eve : ∀ᶠ i in F,
(μs i).normalize.toFiniteMeasure.testAgainstNN f =
(μs i).mass⁻¹ * (μs i).testAgainstNN f := by
filter_upwards [eventually_iff.mp eventually_nonzero]
intro i hi
apply normalize_testAgainstNN _ hi
simp_rw [tendsto_congr' eve, μ.normalize_testAgainstNN nonzero]
have lim_pair :
Tendsto (fun i ↦ (⟨(μs i).mass⁻¹, (μs i).testAgainstNN f⟩ : ℝ≥0 × ℝ≥0)) F
(𝓝 ⟨μ.mass⁻¹, μ.testAgainstNN f⟩) := by
refine (Prod.tendsto_iff _ _).mpr ⟨?_, ?_⟩
· exact (continuousOn_inv₀.continuousAt aux).tendsto.comp lim_mass
· exact tendsto_iff_forall_testAgainstNN_tendsto.mp μs_lim f
exact tendsto_mul.comp lim_pair
/-- If the normalized versions of finite measures converge weakly and their total masses
also converge, then the finite measures themselves converge weakly. -/
theorem tendsto_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (μs_lim : Tendsto (fun i ↦ (μs i).normalize) F (𝓝 μ.normalize))
(mass_lim : Tendsto (fun i ↦ (μs i).mass) F (𝓝 μ.mass)) : Tendsto μs F (𝓝 μ) := by
rw [tendsto_iff_forall_testAgainstNN_tendsto]
exact fun f ↦
tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass μs_lim mass_lim f
/-- If finite measures themselves converge weakly to a nonzero limit measure, then their
normalized versions also converge weakly. -/
theorem tendsto_normalize_of_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
(μs_lim : Tendsto μs F (𝓝 μ)) (nonzero : μ ≠ 0) :
Tendsto (fun i ↦ (μs i).normalize) F (𝓝 μ.normalize) := by
| rw [ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds,
tendsto_iff_forall_testAgainstNN_tendsto]
exact fun f ↦ tendsto_normalize_testAgainstNN_of_tendsto μs_lim nonzero f
/-- The weak convergence of finite measures to a nonzero limit can be characterized by the weak
convergence of both their normalized versions (probability measures) and their total masses. -/
| Mathlib/MeasureTheory/Measure/ProbabilityMeasure.lean | 508 | 513 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.BigOperators.Group.List.Basic
/-!
# Free groups
This file defines free groups over a type. Furthermore, it is shown that the free group construction
is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful
functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`.
## Main definitions
* `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type
`α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`.
* `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`.
* `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`.
* `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G`
given a group `G` and a function `f : α → G`.
## Main statements
* `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word
reduction (also known as Newman's diamond lemma).
* `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type
is isomorphic to the integers.
* The free group construction is an instance of a monad.
## Implementation details
First we introduce the one step reduction relation `FreeGroup.Red.Step`:
`w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans`
and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient
over `FreeGroup.Red.Step`.
For the additive version we introduce the same relation under a different name so that we can
distinguish the quotient types more easily.
## Tags
free group, Newman's diamond lemma, Church-Rosser theorem
-/
open Relation
open scoped List
universe u v w
variable {α : Type u}
attribute [local simp] List.append_eq_has_append
-- Porting note: to_additive.map_namespace is not supported yet
-- worked around it by putting a few extra manual mappings (but not too many all in all)
-- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup
/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/
inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeAddGroup.Red.Step.not
/-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/
@[to_additive FreeAddGroup.Red.Step]
inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeGroup.Red.Step.not
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- Reflexive-transitive closure of `Red.Step` -/
@[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"]
def Red : List (α × Bool) → List (α × Bool) → Prop :=
ReflTransGen Red.Step
@[to_additive (attr := refl)]
theorem Red.refl : Red L L :=
ReflTransGen.refl
@[to_additive (attr := trans)]
theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ :=
ReflTransGen.trans
namespace Red
/-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words
`w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/
@[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there
are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"]
theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length
| _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl
@[to_additive (attr := simp)]
theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by
cases b <;> exact Step.not
@[to_additive (attr := simp)]
theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L :=
@Step.not _ [] _ _ _
@[to_additive (attr := simp)]
theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L :=
@Red.Step.not_rev _ [] _ _ _
@[to_additive]
theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃)
| _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor
@[to_additive]
theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) :=
@Step.append_left _ [x] _ _ H
@[to_additive]
theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃)
| _, _, _, Red.Step.not => by simp
@[to_additive]
theorem not_step_nil : ¬Step [] L := by
generalize h' : [] = L'
intro h
rcases h with - | ⟨L₁, L₂⟩
simp [List.nil_eq_append_iff] at h'
@[to_additive]
theorem Step.cons_left_iff {a : α} {b : Bool} :
Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by
constructor
· generalize hL : ((a, b) :: L₁ : List _) = L
rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all
· rintro (⟨L, h, rfl⟩ | rfl)
· exact Step.cons h
· exact Step.cons_not
@[to_additive]
theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L
| (a, b) => by simp [Step.cons_left_iff, not_step_nil]
@[to_additive]
theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by
simp +contextual [Step.cons_left_iff, iff_def, or_imp]
@[to_additive]
| theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂
| [] => by simp
| p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff]
@[to_additive]
| Mathlib/GroupTheory/FreeGroup/Basic.lean | 151 | 155 |
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Analysis.InnerProductSpace.Adjoint
/-!
# Positive operators
In this file we define positive operators in a Hilbert space. We follow Bourbaki's choice
of requiring self adjointness in the definition.
## Main definitions
* `IsPositive` : a continuous linear map is positive if it is self adjoint and
`∀ x, 0 ≤ re ⟪T x, x⟫`
## Main statements
* `ContinuousLinearMap.IsPositive.conj_adjoint` : if `T : E →L[𝕜] E` is positive,
then for any `S : E →L[𝕜] F`, `S ∘L T ∘L S†` is also positive.
* `ContinuousLinearMap.isPositive_iff_complex` : in a ***complex*** Hilbert space,
checking that `⟪T x, x⟫` is a nonnegative real number for all `x` suffices to prove that
`T` is positive
## References
* [Bourbaki, *Topological Vector Spaces*][bourbaki1987]
## Tags
Positive operator
-/
open InnerProductSpace RCLike ContinuousLinearMap
open scoped InnerProduct ComplexConjugate
namespace ContinuousLinearMap
variable {𝕜 E F : Type*} [RCLike 𝕜]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F]
variable [CompleteSpace E] [CompleteSpace F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- A continuous linear endomorphism `T` of a Hilbert space is **positive** if it is self adjoint
and `∀ x, 0 ≤ re ⟪T x, x⟫`. -/
def IsPositive (T : E →L[𝕜] E) : Prop :=
IsSelfAdjoint T ∧ ∀ x, 0 ≤ T.reApplyInnerSelf x
theorem IsPositive.isSelfAdjoint {T : E →L[𝕜] E} (hT : IsPositive T) : IsSelfAdjoint T :=
hT.1
theorem IsPositive.inner_nonneg_left {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) :
0 ≤ re ⟪T x, x⟫ :=
hT.2 x
theorem IsPositive.inner_nonneg_right {T : E →L[𝕜] E} (hT : IsPositive T) (x : E) :
0 ≤ re ⟪x, T x⟫ := by rw [inner_re_symm]; exact hT.inner_nonneg_left x
theorem isPositive_zero : IsPositive (0 : E →L[𝕜] E) := by
refine ⟨.zero _, fun x => ?_⟩
change 0 ≤ re ⟪_, _⟫
rw [zero_apply, inner_zero_left, ZeroHomClass.map_zero]
theorem isPositive_one : IsPositive (1 : E →L[𝕜] E) :=
| ⟨.one _, fun _ => inner_self_nonneg⟩
theorem IsPositive.add {T S : E →L[𝕜] E} (hT : T.IsPositive) (hS : S.IsPositive) :
(T + S).IsPositive := by
| Mathlib/Analysis/InnerProductSpace/Positive.lean | 71 | 74 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.Order.IsLUB
/-!
# Order topology on a densely ordered set
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
variable {α β : Type*}
section DenselyOrdered
variable [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [DenselyOrdered α] {a b : α}
{s : Set α}
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top
element. -/
theorem closure_Ioi' {a : α} (h : (Ioi a).Nonempty) : closure (Ioi a) = Ici a := by
apply Subset.antisymm
· exact closure_minimal Ioi_subset_Ici_self isClosed_Ici
· rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff]
exact isGLB_Ioi.mem_closure h
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/
@[simp]
theorem closure_Ioi (a : α) [NoMaxOrder α] : closure (Ioi a) = Ici a :=
closure_Ioi' nonempty_Ioi
/-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom
element. -/
theorem closure_Iio' (h : (Iio a).Nonempty) : closure (Iio a) = Iic a :=
closure_Ioi' (α := αᵒᵈ) h
/-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/
@[simp]
theorem closure_Iio (a : α) [NoMinOrder α] : closure (Iio a) = Iic a :=
closure_Iio' nonempty_Iio
/-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ioo {a b : α} (hab : a ≠ b) : closure (Ioo a b) = Icc a b := by
apply Subset.antisymm
· exact closure_minimal Ioo_subset_Icc_self isClosed_Icc
· rcases hab.lt_or_lt with hab | hab
· rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le]
have hab' : (Ioo a b).Nonempty := nonempty_Ioo.2 hab
simp only [insert_subset_iff, singleton_subset_iff]
exact ⟨(isGLB_Ioo hab).mem_closure hab', (isLUB_Ioo hab).mem_closure hab'⟩
· rw [Icc_eq_empty_of_lt hab]
exact empty_subset _
/-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ioc {a b : α} (hab : a ≠ b) : closure (Ioc a b) = Icc a b := by
apply Subset.antisymm
· exact closure_minimal Ioc_subset_Icc_self isClosed_Icc
· apply Subset.trans _ (closure_mono Ioo_subset_Ioc_self)
rw [closure_Ioo hab]
/-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ico {a b : α} (hab : a ≠ b) : closure (Ico a b) = Icc a b := by
apply Subset.antisymm
· exact closure_minimal Ico_subset_Icc_self isClosed_Icc
· apply Subset.trans _ (closure_mono Ioo_subset_Ico_self)
rw [closure_Ioo hab]
@[simp]
theorem interior_Ici' {a : α} (ha : (Iio a).Nonempty) : interior (Ici a) = Ioi a := by
rw [← compl_Iio, interior_compl, closure_Iio' ha, compl_Iic]
theorem interior_Ici [NoMinOrder α] {a : α} : interior (Ici a) = Ioi a :=
interior_Ici' nonempty_Iio
@[simp]
theorem interior_Iic' {a : α} (ha : (Ioi a).Nonempty) : interior (Iic a) = Iio a :=
interior_Ici' (α := αᵒᵈ) ha
theorem interior_Iic [NoMaxOrder α] {a : α} : interior (Iic a) = Iio a :=
interior_Iic' nonempty_Ioi
@[simp]
theorem interior_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} : interior (Icc a b) = Ioo a b := by
rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio]
@[simp]
theorem Icc_mem_nhds_iff [NoMinOrder α] [NoMaxOrder α] {a b x : α} :
Icc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by
rw [← interior_Icc, mem_interior_iff_mem_nhds]
@[simp]
theorem interior_Ico [NoMinOrder α] {a b : α} : interior (Ico a b) = Ioo a b := by
rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio]
@[simp]
theorem Ico_mem_nhds_iff [NoMinOrder α] {a b x : α} : Ico a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by
rw [← interior_Ico, mem_interior_iff_mem_nhds]
@[simp]
theorem interior_Ioc [NoMaxOrder α] {a b : α} : interior (Ioc a b) = Ioo a b := by
rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio]
@[simp]
theorem Ioc_mem_nhds_iff [NoMaxOrder α] {a b x : α} : Ioc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by
rw [← interior_Ioc, mem_interior_iff_mem_nhds]
theorem closure_interior_Icc {a b : α} (h : a ≠ b) : closure (interior (Icc a b)) = Icc a b :=
(closure_minimal interior_subset isClosed_Icc).antisymm <|
calc
Icc a b = closure (Ioo a b) := (closure_Ioo h).symm
_ ⊆ closure (interior (Icc a b)) :=
closure_mono (interior_maximal Ioo_subset_Icc_self isOpen_Ioo)
theorem Ioc_subset_closure_interior (a b : α) : Ioc a b ⊆ closure (interior (Ioc a b)) := by
rcases eq_or_ne a b with (rfl | h)
· simp
· calc
Ioc a b ⊆ Icc a b := Ioc_subset_Icc_self
_ = closure (Ioo a b) := (closure_Ioo h).symm
_ ⊆ closure (interior (Ioc a b)) :=
closure_mono (interior_maximal Ioo_subset_Ioc_self isOpen_Ioo)
theorem Ico_subset_closure_interior (a b : α) : Ico a b ⊆ closure (interior (Ico a b)) := by
simpa only [Ioc_toDual] using
Ioc_subset_closure_interior (OrderDual.toDual b) (OrderDual.toDual a)
@[simp]
theorem frontier_Ici' {a : α} (ha : (Iio a).Nonempty) : frontier (Ici a) = {a} := by
simp [frontier, ha]
theorem frontier_Ici [NoMinOrder α] {a : α} : frontier (Ici a) = {a} :=
frontier_Ici' nonempty_Iio
@[simp]
theorem frontier_Iic' {a : α} (ha : (Ioi a).Nonempty) : frontier (Iic a) = {a} := by
simp [frontier, ha]
theorem frontier_Iic [NoMaxOrder α] {a : α} : frontier (Iic a) = {a} :=
frontier_Iic' nonempty_Ioi
@[simp]
theorem frontier_Ioi' {a : α} (ha : (Ioi a).Nonempty) : frontier (Ioi a) = {a} := by
simp [frontier, closure_Ioi' ha, Iic_diff_Iio, Icc_self]
theorem frontier_Ioi [NoMaxOrder α] {a : α} : frontier (Ioi a) = {a} :=
frontier_Ioi' nonempty_Ioi
@[simp]
theorem frontier_Iio' {a : α} (ha : (Iio a).Nonempty) : frontier (Iio a) = {a} := by
simp [frontier, closure_Iio' ha, Iic_diff_Iio, Icc_self]
theorem frontier_Iio [NoMinOrder α] {a : α} : frontier (Iio a) = {a} :=
frontier_Iio' nonempty_Iio
@[simp]
theorem frontier_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} (h : a ≤ b) :
frontier (Icc a b) = {a, b} := by simp [frontier, h, Icc_diff_Ioo_same]
@[simp]
theorem frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by
rw [frontier, closure_Ioo h.ne, interior_Ioo, Icc_diff_Ioo_same h.le]
@[simp]
theorem frontier_Ico [NoMinOrder α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by
rw [frontier, closure_Ico h.ne, interior_Ico, Icc_diff_Ioo_same h.le]
@[simp]
theorem frontier_Ioc [NoMaxOrder α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by
rw [frontier, closure_Ioc h.ne, interior_Ioc, Icc_diff_Ioo_same h.le]
theorem nhdsWithin_Ioi_neBot' {a b : α} (H₁ : (Ioi a).Nonempty) (H₂ : a ≤ b) :
NeBot (𝓝[Ioi a] b) :=
mem_closure_iff_nhdsWithin_neBot.1 <| by rwa [closure_Ioi' H₁]
theorem nhdsWithin_Ioi_neBot [NoMaxOrder α] {a b : α} (H : a ≤ b) : NeBot (𝓝[Ioi a] b) :=
nhdsWithin_Ioi_neBot' nonempty_Ioi H
theorem nhdsGT_neBot_of_exists_gt {a : α} (H : ∃ b, a < b) : NeBot (𝓝[>] a) :=
nhdsWithin_Ioi_neBot' H (le_refl a)
@[deprecated (since := "2024-12-22")]
alias nhdsWithin_Ioi_self_neBot' := nhdsGT_neBot_of_exists_gt
instance nhdsGT_neBot [NoMaxOrder α] (a : α) : NeBot (𝓝[>] a) := nhdsWithin_Ioi_neBot le_rfl
@[deprecated nhdsGT_neBot (since := "2024-12-22")]
theorem nhdsWithin_Ioi_self_neBot [NoMaxOrder α] (a : α) : NeBot (𝓝[>] a) := nhdsGT_neBot a
theorem nhdsWithin_Iio_neBot' {b c : α} (H₁ : (Iio c).Nonempty) (H₂ : b ≤ c) :
NeBot (𝓝[Iio c] b) :=
mem_closure_iff_nhdsWithin_neBot.1 <| by rwa [closure_Iio' H₁]
theorem nhdsWithin_Iio_neBot [NoMinOrder α] {a b : α} (H : a ≤ b) : NeBot (𝓝[Iio b] a) :=
nhdsWithin_Iio_neBot' nonempty_Iio H
theorem nhdsWithin_Iio_self_neBot' {b : α} (H : (Iio b).Nonempty) : NeBot (𝓝[<] b) :=
nhdsWithin_Iio_neBot' H (le_refl b)
instance nhdsLT_neBot [NoMinOrder α] (a : α) : NeBot (𝓝[<] a) := nhdsWithin_Iio_neBot (le_refl a)
@[deprecated nhdsLT_neBot (since := "2024-12-22")]
theorem nhdsWithin_Iio_self_neBot [NoMinOrder α] (a : α) : NeBot (𝓝[<] a) := nhdsLT_neBot a
theorem right_nhdsWithin_Ico_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ico a b] b) :=
(isLUB_Ico H).nhdsWithin_neBot (nonempty_Ico.2 H)
theorem left_nhdsWithin_Ioc_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioc a b] a) :=
(isGLB_Ioc H).nhdsWithin_neBot (nonempty_Ioc.2 H)
theorem left_nhdsWithin_Ioo_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioo a b] a) :=
(isGLB_Ioo H).nhdsWithin_neBot (nonempty_Ioo.2 H)
theorem right_nhdsWithin_Ioo_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioo a b] b) :=
(isLUB_Ioo H).nhdsWithin_neBot (nonempty_Ioo.2 H)
| theorem comap_coe_nhdsLT_of_Ioo_subset (hb : s ⊆ Iio b) (hs : s.Nonempty → ∃ a < b, Ioo a b ⊆ s) :
comap ((↑) : s → α) (𝓝[<] b) = atTop := by
nontriviality
| Mathlib/Topology/Order/DenselyOrdered.lean | 223 | 225 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Analysis.SumOverResidueClass
/-!
# Convergence of `p`-series
In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`.
The proof is based on the
[Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k`
converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in
`NNReal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove
`summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series.
## Tags
p-series, Cauchy condensation test
-/
/-!
### Schlömilch's generalization of the Cauchy condensation test
In this section we prove the Schlömilch's generalization of the Cauchy condensation test:
for a strictly increasing `u : ℕ → ℕ` with ratio of successive differences bounded and an
antitone `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`, `∑ k, f k` converges if and only if
so does `∑ k, (u (k + 1) - u k) * f (u k)`. Instead of giving a monolithic proof, we split it
into a series of lemmas with explicit estimates of partial sums of each series in terms of the
partial sums of the other series.
-/
/--
A sequence `u` has the property that its ratio of successive differences is bounded
when there is a positive real number `C` such that, for all n ∈ ℕ,
(u (n + 2) - u (n + 1)) ≤ C * (u (n + 1) - u n)
-/
def SuccDiffBounded (C : ℕ) (u : ℕ → ℕ) : Prop :=
∀ n : ℕ, u (n + 2) - u (n + 1) ≤ C • (u (n + 1) - u n)
namespace Finset
variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedAddMonoid M]
{f : ℕ → M} {u : ℕ → ℕ}
theorem le_sum_schlomilch' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ Ico (u 0) (u n), f k) ≤ ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
induction n with
| zero => simp
| succ n ihn =>
suffices (∑ k ∈ Ico (u n) (u (n + 1)), f k) ≤ (u (n + 1) - u n) • f (u n) by
rw [sum_range_succ, ← sum_Ico_consecutive]
· exact add_le_add ihn this
exacts [hu n.zero_le, hu n.le_succ]
have : ∀ k ∈ Ico (u n) (u (n + 1)), f k ≤ f (u n) := fun k hk =>
hf (Nat.succ_le_of_lt (h_pos n)) (mem_Ico.mp hk).1
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ Ico 1 (2 ^ n), f k) ≤ ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by
convert le_sum_schlomilch' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_right_mono₀ one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
theorem le_sum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ range (u n), f k) ≤
∑ k ∈ range (u 0), f k + ∑ k ∈ range n, (u (k + 1) - u k) • f (u k) := by
convert add_le_add_left (le_sum_schlomilch' hf h_pos hu n) (∑ k ∈ range (u 0), f k)
rw [← sum_range_add_sum_Ico _ (hu n.zero_le)]
theorem le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range (2 ^ n), f k) ≤ f 0 + ∑ k ∈ range n, 2 ^ k • f (2 ^ k) := by
convert add_le_add_left (le_sum_condensed' hf n) (f 0)
rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, zero_add]
theorem sum_schlomilch_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : Monotone u) (n : ℕ) :
(∑ k ∈ range n, (u (k + 1) - u k) • f (u (k + 1))) ≤ ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by
induction n with
| zero => simp
| succ n ihn =>
suffices (u (n + 1) - u n) • f (u (n + 1)) ≤ ∑ k ∈ Ico (u n + 1) (u (n + 1) + 1), f k by
rw [sum_range_succ, ← sum_Ico_consecutive]
exacts [add_le_add ihn this,
(add_le_add_right (hu n.zero_le) _ : u 0 + 1 ≤ u n + 1),
add_le_add_right (hu n.le_succ) _]
have : ∀ k ∈ Ico (u n + 1) (u (n + 1) + 1), f (u (n + 1)) ≤ f k := fun k hk =>
hf (Nat.lt_of_le_of_lt (Nat.succ_le_of_lt (h_pos n)) <| (Nat.lt_succ_of_le le_rfl).trans_le
(mem_Ico.mp hk).1) (Nat.le_of_lt_succ <| (mem_Ico.mp hk).2)
convert sum_le_sum this
simp [pow_succ, mul_two]
theorem sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range n, 2 ^ k • f (2 ^ (k + 1))) ≤ ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by
convert sum_schlomilch_le' hf (fun n => pow_pos zero_lt_two n)
(fun m n hm => pow_right_mono₀ one_le_two hm) n using 2
simp [pow_succ, mul_two, two_mul]
theorem sum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) (n : ℕ) :
∑ k ∈ range (n + 1), (u (k + 1) - u k) • f (u k) ≤
(u 1 - u 0) • f (u 0) + C • ∑ k ∈ Ico (u 0 + 1) (u n + 1), f k := by
rw [sum_range_succ', add_comm]
gcongr
suffices ∑ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤
C • ∑ k ∈ range n, ((u (k + 1) - u k) • f (u (k + 1))) by
refine this.trans (nsmul_le_nsmul_right ?_ _)
exact sum_schlomilch_le' hf h_pos hu n
have : ∀ k ∈ range n, (u (k + 2) - u (k + 1)) • f (u (k + 1)) ≤
C • ((u (k + 1) - u k) • f (u (k + 1))) := by
intro k _
rw [smul_smul]
gcongr
· exact h_nonneg (u (k + 1))
exact mod_cast h_succ_diff k
convert sum_le_sum this
simp [smul_sum]
theorem sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k ∈ range (n + 1), 2 ^ k • f (2 ^ k)) ≤ f 1 + 2 • ∑ k ∈ Ico 2 (2 ^ n + 1), f k := by
convert add_le_add_left (nsmul_le_nsmul_right (sum_condensed_le' hf n) 2) (f 1)
simp [sum_range_succ', add_comm, pow_succ', mul_nsmul', sum_nsmul]
end Finset
namespace ENNReal
open Filter Finset
variable {u : ℕ → ℕ} {f : ℕ → ℝ≥0∞}
open NNReal in
theorem le_tsum_schlomilch (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu : StrictMono u) :
∑' k , f k ≤ ∑ k ∈ range (u 0), f k + ∑' k : ℕ, (u (k + 1) - u k) * f (u k) := by
rw [ENNReal.tsum_eq_iSup_nat' hu.tendsto_atTop]
refine iSup_le fun n =>
(Finset.le_sum_schlomilch hf h_pos hu.monotone n).trans (add_le_add_left ?_ _)
have (k : ℕ) : (u (k + 1) - u k : ℝ≥0∞) = (u (k + 1) - (u k : ℕ) : ℕ) := by
simp [NNReal.coe_sub (Nat.cast_le (α := ℝ≥0).mpr <| (hu k.lt_succ_self).le)]
simp only [nsmul_eq_mul, this]
apply ENNReal.sum_le_tsum
theorem le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
∑' k, f k ≤ f 0 + ∑' k : ℕ, 2 ^ k * f (2 ^ k) := by
rw [ENNReal.tsum_eq_iSup_nat' (Nat.tendsto_pow_atTop_atTop_of_one_lt _root_.one_lt_two)]
refine iSup_le fun n => (Finset.le_sum_condensed hf n).trans (add_le_add_left ?_ _)
simp only [nsmul_eq_mul, Nat.cast_pow, Nat.cast_two]
apply ENNReal.sum_le_tsum
theorem tsum_schlomilch_le {C : ℕ} (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(h_nonneg : ∀ n, 0 ≤ f n) (hu : Monotone u) (h_succ_diff : SuccDiffBounded C u) :
∑' k : ℕ, (u (k + 1) - u k) * f (u k) ≤ (u 1 - u 0) * f (u 0) + C * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id)]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(mul_le_mul_of_nonneg_left (ENNReal.sum_le_tsum <| Finset.Ico (u 0 + 1) (u n + 1)) ?_) _)
· simpa using Finset.sum_schlomilch_le hf h_pos h_nonneg hu h_succ_diff n
· exact zero_le _
theorem tsum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) :
(∑' k : ℕ, 2 ^ k * f (2 ^ k)) ≤ f 1 + 2 * ∑' k, f k := by
rw [ENNReal.tsum_eq_iSup_nat' (tendsto_atTop_mono Nat.le_succ tendsto_id), two_mul, ← two_nsmul]
refine
iSup_le fun n =>
le_trans ?_
(add_le_add_left
(nsmul_le_nsmul_right (ENNReal.sum_le_tsum <| Finset.Ico 2 (2 ^ n + 1)) _) _)
simpa using Finset.sum_condensed_le hf n
end ENNReal
namespace NNReal
open Finset
open ENNReal in
/-- for a series of `NNReal` version. -/
theorem summable_schlomilch_iff {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ≥0}
(hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m)
(h_pos : ∀ n, 0 < u n) (hu_strict : StrictMono u)
(hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : ℕ => (u (k + 1) - (u k : ℝ≥0)) * f (u k)) ↔ Summable f := by
simp only [← tsum_coe_ne_top_iff_summable, Ne, not_iff_not, ENNReal.coe_mul]
constructor <;> intro h
· replace hf : ∀ m n, 1 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn)
have h_nonneg : ∀ n, 0 ≤ (f n : ℝ≥0∞) := fun n =>
ENNReal.coe_le_coe.2 (f n).2
obtain hC := tsum_schlomilch_le hf h_pos h_nonneg hu_strict.monotone h_succ_diff
simpa [add_eq_top, mul_ne_top, mul_eq_top, hC_nonzero] using eq_top_mono hC h
· replace hf : ∀ m n, 0 < m → m ≤ n → (f n : ℝ≥0∞) ≤ f m := fun m n hm hmn =>
ENNReal.coe_le_coe.2 (hf hm hmn)
have : ∑ k ∈ range (u 0), (f k : ℝ≥0∞) ≠ ∞ := sum_ne_top.2 fun a _ => coe_ne_top
simpa [h, add_eq_top, this] using le_tsum_schlomilch hf h_pos hu_strict
open ENNReal in
theorem summable_condensed_iff {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(Summable fun k : ℕ => (2 : ℝ≥0) ^ k * f (2 ^ k)) ↔ Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff hf (pow_pos zero_lt_two) (pow_right_strictMono₀ _root_.one_lt_two)
two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
end NNReal
open NNReal in
/-- for series of nonnegative real numbers. -/
theorem summable_schlomilch_iff_of_nonneg {C : ℕ} {u : ℕ → ℕ} {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (h_pos : ∀ n, 0 < u n)
(hu_strict : StrictMono u) (hC_nonzero : C ≠ 0) (h_succ_diff : SuccDiffBounded C u) :
(Summable fun k : ℕ => (u (k + 1) - (u k : ℝ)) * f (u k)) ↔ Summable f := by
lift f to ℕ → ℝ≥0 using h_nonneg
simp only [NNReal.coe_le_coe] at *
have (k : ℕ) : (u (k + 1) - (u k : ℝ)) = ((u (k + 1) : ℝ≥0) - (u k : ℝ≥0) : ℝ≥0) := by
have := Nat.cast_le (α := ℝ≥0).mpr <| (hu_strict k.lt_succ_self).le
simp [NNReal.coe_sub this]
simp_rw [this]
exact_mod_cast NNReal.summable_schlomilch_iff hf h_pos hu_strict hC_nonzero h_succ_diff
/-- Cauchy condensation test for antitone series of nonnegative real numbers. -/
theorem summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(h_mono : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(Summable fun k : ℕ => (2 : ℝ) ^ k * f (2 ^ k)) ↔ Summable f := by
have h_succ_diff : SuccDiffBounded 2 (2 ^ ·) := by
intro n
simp [pow_succ, mul_two, two_mul]
convert summable_schlomilch_iff_of_nonneg h_nonneg h_mono (pow_pos zero_lt_two)
(pow_right_strictMono₀ one_lt_two) two_ne_zero h_succ_diff
simp [pow_succ, mul_two, two_mul]
section p_series
/-!
### Convergence of the `p`-series
In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if
and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the
Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if
and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with
common ratio `2 ^ {1 - p}`. -/
namespace Real
open Filter
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_rpow_inv {p : ℝ} :
Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by
rcases le_or_lt 0 p with hp | hp
/- Cauchy condensation test applies only to antitone sequences, so we consider the
cases `0 ≤ p` and `p < 0` separately. -/
· rw [← summable_condensed_iff_of_nonneg]
· simp_rw [Nat.cast_pow, Nat.cast_two, ← rpow_natCast, ← rpow_mul zero_lt_two.le, mul_comm _ p,
rpow_mul zero_lt_two.le, rpow_natCast, ← inv_pow, ← mul_pow,
summable_geometric_iff_norm_lt_one]
nth_rw 1 [← rpow_one 2]
rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs,
abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le]
norm_num
· intro n
positivity
· intro m n hm hmn
gcongr
-- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges.
· suffices ¬Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) by
have : ¬1 < p := fun hp₁ => hp.not_le (zero_le_one.trans hp₁.le)
simpa only [this, iff_false]
intro h
obtain ⟨k : ℕ, hk₁ : ((k : ℝ) ^ p)⁻¹ < 1, hk₀ : k ≠ 0⟩ :=
((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and
(eventually_cofinite_ne 0)).exists
apply hk₀
rw [← pos_iff_ne_zero, ← @Nat.cast_pos ℝ] at hk₀
simpa [inv_lt_one₀ (rpow_pos_of_pos hk₀ _), one_lt_rpow_iff_of_pos hk₀, hp,
hp.not_lt, hk₀] using hk₁
@[simp]
theorem summable_nat_rpow {p : ℝ} : Summable (fun n => (n : ℝ) ^ p : ℕ → ℝ) ↔ p < -1 := by
rcases neg_surjective p with ⟨p, rfl⟩
simp [rpow_neg]
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
theorem summable_one_div_nat_rpow {p : ℝ} :
Summable (fun n => 1 / (n : ℝ) ^ p : ℕ → ℝ) ↔ 1 < p := by
simp
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp]
theorem summable_nat_pow_inv {p : ℕ} :
Summable (fun n => ((n : ℝ) ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p := by
| simp only [← rpow_natCast, summable_nat_rpow_inv, Nat.one_lt_cast]
/-- Test for convergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
| Mathlib/Analysis/PSeries.lean | 306 | 308 |
/-
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.Shift.CommShift
/-!
# Functors from a category to a category with a shift
Given a category `C`, and a category `D` equipped with a shift by a monoid `A`,
we define a structure `SingleFunctors C D A` which contains the data of
functors `functor a : C ⥤ D` for all `a : A` and isomorphisms
`shiftIso n a a' h : functor a' ⋙ shiftFunctor D n ≅ functor a`
whenever `n + a = a'`. These isomorphisms should satisfy certain compatibilities
with respect to the shift on `D`.
This notion is similar to `Functor.ShiftSequence` which can be used in order to
attach shifted versions of a homological functor `D ⥤ C` with `D` a
triangulated category and `C` an abelian category. However, the definition
`SingleFunctors` is for functors in the other direction: it is meant to
ease the formalization of the compatibilities with shifts of the
functors `C ⥤ CochainComplex C ℤ` (or `C ⥤ DerivedCategory C` (TODO))
which sends an object `X : C` to a complex where `X` sits in a single degree.
-/
open CategoryTheory Category ZeroObject Limits
variable (C D E E' : Type*) [Category C] [Category D] [Category E] [Category E']
(A : Type*) [AddMonoid A] [HasShift D A] [HasShift E A] [HasShift E' A]
namespace CategoryTheory
/-- The type of families of functors `A → C ⥤ D` which are compatible with
the shift by `A` on the category `D`. -/
structure SingleFunctors where
/-- a family of functors `C ⥤ D` indexed by the elements of the additive monoid `A` -/
functor (a : A) : C ⥤ D
/-- the isomorphism `functor a' ⋙ shiftFunctor D n ≅ functor a` when `n + a = a'` -/
shiftIso (n a a' : A) (ha' : n + a = a') : functor a' ⋙ shiftFunctor D n ≅ functor a
/-- `shiftIso 0` is the obvious isomorphism. -/
shiftIso_zero (a : A) :
shiftIso 0 a a (zero_add a) = isoWhiskerLeft _ (shiftFunctorZero D A)
/-- `shiftIso (m + n)` is determined by `shiftIso m` and `shiftIso n`. -/
shiftIso_add (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') :
shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) =
isoWhiskerLeft _ (shiftFunctorAdd D m n) ≪≫ (Functor.associator _ _ _).symm ≪≫
isoWhiskerRight (shiftIso m a' a'' ha'') _ ≪≫ shiftIso n a a' ha'
variable {C D E A}
variable (F G H : SingleFunctors C D A)
namespace SingleFunctors
lemma shiftIso_add_hom_app (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X =
(shiftFunctorAdd D m n).hom.app ((F.functor a'').obj X) ≫
((F.shiftIso m a' a'' ha'').hom.app X)⟦n⟧' ≫
(F.shiftIso n a a' ha').hom.app X := by
simp [F.shiftIso_add n m a a' a'' ha' ha'']
lemma shiftIso_add_inv_app (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X =
(F.shiftIso n a a' ha').inv.app X ≫
((F.shiftIso m a' a'' ha'').inv.app X)⟦n⟧' ≫
(shiftFunctorAdd D m n).inv.app ((F.functor a'').obj X) := by
simp [F.shiftIso_add n m a a' a'' ha' ha'']
lemma shiftIso_add' (n m mn : A) (hnm : m + n = mn) (a a' a'' : A)
(ha' : n + a = a') (ha'' : m + a' = a'') :
F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc]) =
isoWhiskerLeft _ (shiftFunctorAdd' D m n mn hnm) ≪≫ (Functor.associator _ _ _).symm ≪≫
isoWhiskerRight (F.shiftIso m a' a'' ha'') _ ≪≫ F.shiftIso n a a' ha' := by
subst hnm
rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftIso_add]
lemma shiftIso_add'_hom_app (n m mn : A) (hnm : m + n = mn) (a a' a'' : A)
(ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X =
(shiftFunctorAdd' D m n mn hnm).hom.app ((F.functor a'').obj X) ≫
((F.shiftIso m a' a'' ha'').hom.app X)⟦n⟧' ≫ (F.shiftIso n a a' ha').hom.app X := by
simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha'']
| lemma shiftIso_add'_inv_app (n m mn : A) (hnm : m + n = mn) (a a' a'' : A)
(ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).inv.app X =
(F.shiftIso n a a' ha').inv.app X ≫
((F.shiftIso m a' a'' ha'').inv.app X)⟦n⟧' ≫
(shiftFunctorAdd' D m n mn hnm).inv.app ((F.functor a'').obj X) := by
simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha'']
| Mathlib/CategoryTheory/Shift/SingleFunctors.lean | 85 | 91 |
/-
Copyright (c) 2022 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth
-/
import Mathlib.MeasureTheory.Function.L1Space.AEEqFun
import Mathlib.MeasureTheory.Function.LpSpace.Complete
import Mathlib.MeasureTheory.Function.LpSpace.Indicator
/-!
# Density of simple functions
Show that each `Lᵖ` Borel measurable function can be approximated in `Lᵖ` norm
by a sequence of simple functions.
## Main definitions
* `MeasureTheory.Lp.simpleFunc`, the type of `Lp` simple functions
* `coeToLp`, the embedding of `Lp.simpleFunc E p μ` into `Lp E p μ`
## Main results
* `tendsto_approxOn_Lp_eLpNorm` (Lᵖ convergence): If `E` is a `NormedAddCommGroup` and `f` is
measurable and `MemLp` (for `p < ∞`), then the simple functions
`SimpleFunc.approxOn f hf s 0 h₀ n` may be considered as elements of `Lp E p μ`, and they tend
in Lᵖ to `f`.
* `Lp.simpleFunc.isDenseEmbedding`: the embedding `coeToLp` of the `Lp` simple functions into
`Lp` is dense.
* `Lp.simpleFunc.induction`, `Lp.induction`, `MemLp.induction`, `Integrable.induction`: to prove
a predicate for all elements of one of these classes of functions, it suffices to check that it
behaves correctly on simple functions.
## TODO
For `E` finite-dimensional, simple functions `α →ₛ E` are dense in L^∞ -- prove this.
## Notations
* `α →ₛ β` (local notation): the type of simple functions `α → β`.
* `α →₁ₛ[μ] E`: the type of `L1` simple functions `α → β`.
-/
noncomputable section
open Set Function Filter TopologicalSpace ENNReal EMetric Finset
open scoped Topology ENNReal MeasureTheory
variable {α β ι E F 𝕜 : Type*}
namespace MeasureTheory
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
/-! ### Lp approximation by simple functions -/
section Lp
variable [MeasurableSpace β] [MeasurableSpace E] [NormedAddCommGroup E] [NormedAddCommGroup F]
{q : ℝ} {p : ℝ≥0∞}
theorem nnnorm_approxOn_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E}
{y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (x : β) (n : ℕ) :
‖approxOn f hf s y₀ h₀ n x - f x‖₊ ≤ ‖f x - y₀‖₊ := by
have := edist_approxOn_le hf h₀ x n
rw [edist_comm y₀] at this
simp only [edist_nndist, nndist_eq_nnnorm] at this
exact mod_cast this
theorem norm_approxOn_y₀_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E}
{y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (x : β) (n : ℕ) :
‖approxOn f hf s y₀ h₀ n x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ := by
simpa [enorm, edist_eq_enorm_sub, ← ENNReal.coe_add, norm_sub_rev]
using edist_approxOn_y0_le hf h₀ x n
theorem norm_approxOn_zero_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E}
(h₀ : (0 : E) ∈ s) [SeparableSpace s] (x : β) (n : ℕ) :
‖approxOn f hf s 0 h₀ n x‖ ≤ ‖f x‖ + ‖f x‖ := by
simpa [enorm, edist_eq_enorm_sub, ← ENNReal.coe_add, norm_sub_rev]
using edist_approxOn_y0_le hf h₀ x n
theorem tendsto_approxOn_Lp_eLpNorm [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f)
{s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (hp_ne_top : p ≠ ∞) {μ : Measure β}
(hμ : ∀ᵐ x ∂μ, f x ∈ closure s) (hi : eLpNorm (fun x => f x - y₀) p μ < ∞) :
Tendsto (fun n => eLpNorm (⇑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) := by
by_cases hp_zero : p = 0
· simpa only [hp_zero, eLpNorm_exponent_zero] using tendsto_const_nhds
have hp : 0 < p.toReal := toReal_pos hp_zero hp_ne_top
suffices Tendsto (fun n => ∫⁻ x, ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal ∂μ) atTop (𝓝 0) by
simp only [eLpNorm_eq_lintegral_rpow_enorm hp_zero hp_ne_top]
convert continuous_rpow_const.continuousAt.tendsto.comp this
simp [zero_rpow_of_pos (_root_.inv_pos.mpr hp)]
-- We simply check the conditions of the Dominated Convergence Theorem:
-- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable
have hF_meas n : Measurable fun x => ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal := by
simpa only [← edist_eq_enorm_sub] using
(approxOn f hf s y₀ h₀ n).measurable_bind (fun y x => edist y (f x) ^ p.toReal) fun y =>
(measurable_edist_right.comp hf).pow_const p.toReal
-- (2) The functions "`p`-th power of distance between `f` and the approximation" are uniformly
-- bounded, at any given point, by `fun x => ‖f x - y₀‖ ^ p.toReal`
have h_bound n :
(fun x ↦ ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal) ≤ᵐ[μ] (‖f · - y₀‖ₑ ^ p.toReal) :=
.of_forall fun x => rpow_le_rpow (coe_mono (nnnorm_approxOn_le hf h₀ x n)) toReal_nonneg
-- (3) The bounding function `fun x => ‖f x - y₀‖ ^ p.toReal` has finite integral
have h_fin : (∫⁻ a : β, ‖f a - y₀‖ₑ ^ p.toReal ∂μ) ≠ ⊤ :=
(lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_zero hp_ne_top hi).ne
-- (4) The functions "`p`-th power of distance between `f` and the approximation" tend pointwise
-- to zero
have h_lim :
∀ᵐ a : β ∂μ, Tendsto (‖approxOn f hf s y₀ h₀ · a - f a‖ₑ ^ p.toReal) atTop (𝓝 0) := by
filter_upwards [hμ] with a ha
have : Tendsto (fun n => (approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) :=
(tendsto_approxOn hf h₀ ha).sub tendsto_const_nhds
convert continuous_rpow_const.continuousAt.tendsto.comp (tendsto_coe.mpr this.nnnorm)
simp [zero_rpow_of_pos hp]
-- Then we apply the Dominated Convergence Theorem
simpa using tendsto_lintegral_of_dominated_convergence _ hF_meas h_bound h_fin h_lim
theorem memLp_approxOn [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
(hf : MemLp f p μ) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s]
(hi₀ : MemLp (fun _ => y₀) p μ) (n : ℕ) : MemLp (approxOn f fmeas s y₀ h₀ n) p μ := by
refine ⟨(approxOn f fmeas s y₀ h₀ n).aestronglyMeasurable, ?_⟩
suffices eLpNorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ < ⊤ by
have : MemLp (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ :=
⟨(approxOn f fmeas s y₀ h₀ n - const β y₀).aestronglyMeasurable, this⟩
convert eLpNorm_add_lt_top this hi₀
ext x
simp
have hf' : MemLp (fun x => ‖f x - y₀‖) p μ := by
have h_meas : Measurable fun x => ‖f x - y₀‖ := by
simp only [← dist_eq_norm]
exact (continuous_id.dist continuous_const).measurable.comp fmeas
refine ⟨h_meas.aemeasurable.aestronglyMeasurable, ?_⟩
rw [eLpNorm_norm]
convert eLpNorm_add_lt_top hf hi₀.neg with x
simp [sub_eq_add_neg]
have : ∀ᵐ x ∂μ, ‖approxOn f fmeas s y₀ h₀ n x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ := by
filter_upwards with x
convert norm_approxOn_y₀_le fmeas h₀ x n using 1
rw [Real.norm_eq_abs, abs_of_nonneg]
positivity
calc
eLpNorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ ≤
eLpNorm (fun x => ‖f x - y₀‖ + ‖f x - y₀‖) p μ :=
eLpNorm_mono_ae this
_ < ⊤ := eLpNorm_add_lt_top hf' hf'
theorem tendsto_approxOn_range_Lp_eLpNorm [BorelSpace E] {f : β → E} (hp_ne_top : p ≠ ∞)
{μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)]
(hf : eLpNorm f p μ < ∞) :
Tendsto (fun n => eLpNorm (⇑(approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) - f) p μ)
atTop (𝓝 0) := by
refine tendsto_approxOn_Lp_eLpNorm fmeas _ hp_ne_top ?_ ?_
· filter_upwards with x using subset_closure (by simp)
· simpa using hf
theorem memLp_approxOn_range [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
[SeparableSpace (range f ∪ {0} : Set E)] (hf : MemLp f p μ) (n : ℕ) :
MemLp (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) p μ :=
memLp_approxOn fmeas hf (y₀ := 0) (by simp) MemLp.zero n
theorem tendsto_approxOn_range_Lp [BorelSpace E] {f : β → E} [hp : Fact (1 ≤ p)] (hp_ne_top : p ≠ ∞)
{μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)]
(hf : MemLp f p μ) :
Tendsto
(fun n =>
(memLp_approxOn_range fmeas hf n).toLp (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n))
atTop (𝓝 (hf.toLp f)) := by
simpa only [Lp.tendsto_Lp_iff_tendsto_eLpNorm''] using
tendsto_approxOn_range_Lp_eLpNorm hp_ne_top fmeas hf.2
/-- Any function in `ℒp` can be approximated by a simple function if `p < ∞`. -/
theorem _root_.MeasureTheory.MemLp.exists_simpleFunc_eLpNorm_sub_lt {E : Type*}
[NormedAddCommGroup E] {f : β → E} {μ : Measure β} (hf : MemLp f p μ) (hp_ne_top : p ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ g : β →ₛ E, eLpNorm (f - ⇑g) p μ < ε ∧ MemLp g p μ := by
borelize E
let f' := hf.1.mk f
rsuffices ⟨g, hg, g_mem⟩ : ∃ g : β →ₛ E, eLpNorm (f' - ⇑g) p μ < ε ∧ MemLp g p μ
· refine ⟨g, ?_, g_mem⟩
suffices eLpNorm (f - ⇑g) p μ = eLpNorm (f' - ⇑g) p μ by rwa [this]
apply eLpNorm_congr_ae
filter_upwards [hf.1.ae_eq_mk] with x hx
simpa only [Pi.sub_apply, sub_left_inj] using hx
have hf' : MemLp f' p μ := hf.ae_eq hf.1.ae_eq_mk
have f'meas : Measurable f' := hf.1.measurable_mk
have : SeparableSpace (range f' ∪ {0} : Set E) :=
StronglyMeasurable.separableSpace_range_union_singleton hf.1.stronglyMeasurable_mk
rcases ((tendsto_approxOn_range_Lp_eLpNorm hp_ne_top f'meas hf'.2).eventually <|
gt_mem_nhds hε.bot_lt).exists with ⟨n, hn⟩
rw [← eLpNorm_neg, neg_sub] at hn
exact ⟨_, hn, memLp_approxOn_range f'meas hf' _⟩
end Lp
/-! ### L1 approximation by simple functions -/
section Integrable
variable [MeasurableSpace β]
variable [MeasurableSpace E] [NormedAddCommGroup E]
theorem tendsto_approxOn_L1_enorm [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f)
{s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] {μ : Measure β}
(hμ : ∀ᵐ x ∂μ, f x ∈ closure s) (hi : HasFiniteIntegral (fun x => f x - y₀) μ) :
Tendsto (fun n => ∫⁻ x, ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ∂μ) atTop (𝓝 0) := by
simpa [eLpNorm_one_eq_lintegral_enorm] using
tendsto_approxOn_Lp_eLpNorm hf h₀ one_ne_top hμ
(by simpa [eLpNorm_one_eq_lintegral_enorm] using hi)
@[deprecated (since := "2025-01-21")] alias tendsto_approxOn_L1_nnnorm := tendsto_approxOn_L1_enorm
theorem integrable_approxOn [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
(hf : Integrable f μ) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s]
(hi₀ : Integrable (fun _ => y₀) μ) (n : ℕ) : Integrable (approxOn f fmeas s y₀ h₀ n) μ := by
rw [← memLp_one_iff_integrable] at hf hi₀ ⊢
exact memLp_approxOn fmeas hf h₀ hi₀ n
theorem tendsto_approxOn_range_L1_enorm [OpensMeasurableSpace E] {f : β → E} {μ : Measure β}
[SeparableSpace (range f ∪ {0} : Set E)] (fmeas : Measurable f) (hf : Integrable f μ) :
Tendsto (fun n => ∫⁻ x, ‖approxOn f fmeas (range f ∪ {0}) 0 (by simp) n x - f x‖ₑ ∂μ) atTop
(𝓝 0) := by
apply tendsto_approxOn_L1_enorm fmeas
· filter_upwards with x using subset_closure (by simp)
· simpa using hf.2
@[deprecated (since := "2025-01-21")]
alias tendsto_approxOn_range_L1_nnnorm := tendsto_approxOn_range_L1_enorm
theorem integrable_approxOn_range [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
[SeparableSpace (range f ∪ {0} : Set E)] (hf : Integrable f μ) (n : ℕ) :
Integrable (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) μ :=
integrable_approxOn fmeas hf _ (integrable_zero _ _ _) n
end Integrable
section SimpleFuncProperties
variable [MeasurableSpace α]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable {μ : Measure α} {p : ℝ≥0∞}
/-!
### Properties of simple functions in `Lp` spaces
A simple function `f : α →ₛ E` into a normed group `E` verifies, for a measure `μ`:
- `MemLp f 0 μ` and `MemLp f ∞ μ`, since `f` is a.e.-measurable and bounded,
- for `0 < p < ∞`,
`MemLp f p μ ↔ Integrable f μ ↔ f.FinMeasSupp μ ↔ ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞`.
-/
theorem exists_forall_norm_le (f : α →ₛ F) : ∃ C, ∀ x, ‖f x‖ ≤ C :=
exists_forall_le (f.map fun x => ‖x‖)
theorem memLp_zero (f : α →ₛ E) (μ : Measure α) : MemLp f 0 μ :=
memLp_zero_iff_aestronglyMeasurable.mpr f.aestronglyMeasurable
theorem memLp_top (f : α →ₛ E) (μ : Measure α) : MemLp f ∞ μ :=
let ⟨C, hfC⟩ := f.exists_forall_norm_le
memLp_top_of_bound f.aestronglyMeasurable C <| Eventually.of_forall hfC
protected theorem eLpNorm'_eq {p : ℝ} (f : α →ₛ F) (μ : Measure α) :
eLpNorm' f p μ = (∑ y ∈ f.range, ‖y‖ₑ ^ p * μ (f ⁻¹' {y})) ^ (1 / p) := by
have h_map : (‖f ·‖ₑ ^ p) = f.map (‖·‖ₑ ^ p) := by simp; rfl
rw [eLpNorm'_eq_lintegral_enorm, h_map, lintegral_eq_lintegral, map_lintegral]
theorem measure_preimage_lt_top_of_memLp (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) (f : α →ₛ E)
(hf : MemLp f p μ) (y : E) (hy_ne : y ≠ 0) : μ (f ⁻¹' {y}) < ∞ := by
have hp_pos_real : 0 < p.toReal := ENNReal.toReal_pos hp_pos hp_ne_top
have hf_eLpNorm := MemLp.eLpNorm_lt_top hf
rw [eLpNorm_eq_eLpNorm' hp_pos hp_ne_top, f.eLpNorm'_eq, one_div,
← @ENNReal.lt_rpow_inv_iff _ _ p.toReal⁻¹ (by simp [hp_pos_real]),
@ENNReal.top_rpow_of_pos p.toReal⁻¹⁻¹ (by simp [hp_pos_real]),
ENNReal.sum_lt_top] at hf_eLpNorm
by_cases hyf : y ∈ f.range
swap
· suffices h_empty : f ⁻¹' {y} = ∅ by
rw [h_empty, measure_empty]; exact ENNReal.coe_lt_top
ext1 x
rw [Set.mem_preimage, Set.mem_singleton_iff, mem_empty_iff_false, iff_false]
refine fun hxy => hyf ?_
rw [mem_range, Set.mem_range]
exact ⟨x, hxy⟩
specialize hf_eLpNorm y hyf
rw [ENNReal.mul_lt_top_iff] at hf_eLpNorm
cases hf_eLpNorm with
| inl hf_eLpNorm => exact hf_eLpNorm.2
| inr hf_eLpNorm =>
cases hf_eLpNorm with
| inl hf_eLpNorm =>
| refine absurd ?_ hy_ne
simpa [hp_pos_real] using hf_eLpNorm
| inr hf_eLpNorm => simp [hf_eLpNorm]
theorem memLp_of_finite_measure_preimage (p : ℝ≥0∞) {f : α →ₛ E}
(hf : ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞) : MemLp f p μ := by
by_cases hp0 : p = 0
· rw [hp0, memLp_zero_iff_aestronglyMeasurable]; exact f.aestronglyMeasurable
by_cases hp_top : p = ∞
· rw [hp_top]; exact memLp_top f μ
refine ⟨f.aestronglyMeasurable, ?_⟩
rw [eLpNorm_eq_eLpNorm' hp0 hp_top, f.eLpNorm'_eq]
refine ENNReal.rpow_lt_top_of_nonneg (by simp) (ENNReal.sum_lt_top.mpr fun y _ => ?_).ne
by_cases hy0 : y = 0
· simp [hy0, ENNReal.toReal_pos hp0 hp_top]
· refine ENNReal.mul_lt_top ?_ (hf y hy0)
exact ENNReal.rpow_lt_top_of_nonneg ENNReal.toReal_nonneg ENNReal.coe_ne_top
theorem memLp_iff {f : α →ₛ E} (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp f p μ ↔ ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞ :=
⟨fun h => measure_preimage_lt_top_of_memLp hp_pos hp_ne_top f h, fun h =>
memLp_of_finite_measure_preimage p h⟩
theorem integrable_iff {f : α →ₛ E} : Integrable f μ ↔ ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞ :=
memLp_one_iff_integrable.symm.trans <| memLp_iff one_ne_zero ENNReal.coe_ne_top
theorem memLp_iff_integrable {f : α →ₛ E} (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) :
| Mathlib/MeasureTheory/Function/SimpleFuncDenseLp.lean | 296 | 322 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Analysis.Convex.Between
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
import Mathlib.Analysis.Normed.Affine.Isometry
/-!
# Angles between points
This file defines unoriented angles in Euclidean affine spaces.
## Main definitions
* `EuclideanGeometry.angle`, with notation `∠`, is the undirected angle determined by three
points.
## TODO
Prove the triangle inequality for the angle.
-/
noncomputable section
open Real RealInnerProductSpace
namespace EuclideanGeometry
open InnerProductGeometry
variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] {p p₀ : P}
/-- The undirected angle at `p₂` between the line segments to `p₁` and
`p₃`. If either of those points equals `p₂`, this is π/2. Use
`open scoped EuclideanGeometry` to access the `∠ p₁ p₂ p₃`
notation. -/
nonrec def angle (p₁ p₂ p₃ : P) : ℝ :=
angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂)
@[inherit_doc] scoped notation "∠" => EuclideanGeometry.angle
theorem continuousAt_angle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) :
ContinuousAt (fun y : P × P × P => ∠ y.1 y.2.1 y.2.2) x := by
let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1)
have hf1 : (f x).1 ≠ 0 := by simp [f, hx12]
have hf2 : (f x).2 ≠ 0 := by simp [f, hx32]
exact (InnerProductGeometry.continuousAt_angle hf1 hf2).comp (by fun_prop)
@[simp]
theorem _root_.AffineIsometry.angle_map {V₂ P₂ : Type*} [NormedAddCommGroup V₂]
[InnerProductSpace ℝ V₂] [MetricSpace P₂] [NormedAddTorsor V₂ P₂]
(f : P →ᵃⁱ[ℝ] P₂) (p₁ p₂ p₃ : P) : ∠ (f p₁) (f p₂) (f p₃) = ∠ p₁ p₂ p₃ := by
simp_rw [angle, ← AffineIsometry.map_vsub, LinearIsometry.angle_map]
@[simp, norm_cast]
theorem _root_.AffineSubspace.angle_coe {s : AffineSubspace ℝ P} (p₁ p₂ p₃ : s) :
haveI : Nonempty s := ⟨p₁⟩
∠ (p₁ : P) (p₂ : P) (p₃ : P) = ∠ p₁ p₂ p₃ :=
haveI : Nonempty s := ⟨p₁⟩
s.subtypeₐᵢ.angle_map p₁ p₂ p₃
/-- Angles are translation invariant -/
@[simp]
theorem angle_const_vadd (v : V) (p₁ p₂ p₃ : P) : ∠ (v +ᵥ p₁) (v +ᵥ p₂) (v +ᵥ p₃) = ∠ p₁ p₂ p₃ :=
(AffineIsometryEquiv.constVAdd ℝ P v).toAffineIsometry.angle_map _ _ _
/-- Angles are translation invariant -/
@[simp]
theorem angle_vadd_const (v₁ v₂ v₃ : V) (p : P) : ∠ (v₁ +ᵥ p) (v₂ +ᵥ p) (v₃ +ᵥ p) = ∠ v₁ v₂ v₃ :=
(AffineIsometryEquiv.vaddConst ℝ p).toAffineIsometry.angle_map _ _ _
/-- Angles are translation invariant -/
@[simp]
theorem angle_const_vsub (p p₁ p₂ p₃ : P) : ∠ (p -ᵥ p₁) (p -ᵥ p₂) (p -ᵥ p₃) = ∠ p₁ p₂ p₃ :=
(AffineIsometryEquiv.constVSub ℝ p).toAffineIsometry.angle_map _ _ _
/-- Angles are translation invariant -/
@[simp]
theorem angle_vsub_const (p₁ p₂ p₃ p : P) : ∠ (p₁ -ᵥ p) (p₂ -ᵥ p) (p₃ -ᵥ p) = ∠ p₁ p₂ p₃ :=
(AffineIsometryEquiv.vaddConst ℝ p).symm.toAffineIsometry.angle_map _ _ _
/-- Angles in a vector space are translation invariant -/
@[simp]
theorem angle_add_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ + v) (v₂ + v) (v₃ + v) = ∠ v₁ v₂ v₃ :=
angle_vadd_const _ _ _ _
/-- Angles in a vector space are translation invariant -/
@[simp]
theorem angle_const_add (v : V) (v₁ v₂ v₃ : V) : ∠ (v + v₁) (v + v₂) (v + v₃) = ∠ v₁ v₂ v₃ :=
angle_const_vadd _ _ _ _
/-- Angles in a vector space are translation invariant -/
@[simp]
theorem angle_sub_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ - v) (v₂ - v) (v₃ - v) = ∠ v₁ v₂ v₃ := by
simpa only [vsub_eq_sub] using angle_vsub_const v₁ v₂ v₃ v
/-- Angles in a vector space are invariant to inversion -/
@[simp]
theorem angle_const_sub (v : V) (v₁ v₂ v₃ : V) : ∠ (v - v₁) (v - v₂) (v - v₃) = ∠ v₁ v₂ v₃ := by
simpa only [vsub_eq_sub] using angle_const_vsub v v₁ v₂ v₃
/-- Angles in a vector space are invariant to inversion -/
@[simp]
theorem angle_neg (v₁ v₂ v₃ : V) : ∠ (-v₁) (-v₂) (-v₃) = ∠ v₁ v₂ v₃ := by
simpa only [zero_sub] using angle_const_sub 0 v₁ v₂ v₃
/-- The angle at a point does not depend on the order of the other two
points. -/
nonrec theorem angle_comm (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ = ∠ p₃ p₂ p₁ :=
angle_comm _ _
/-- The angle at a point is nonnegative. -/
nonrec theorem angle_nonneg (p₁ p₂ p₃ : P) : 0 ≤ ∠ p₁ p₂ p₃ :=
angle_nonneg _ _
/-- The angle at a point is at most π. -/
nonrec theorem angle_le_pi (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ ≤ π :=
angle_le_pi _ _
/-- The angle ∠AAB at a point is always `π / 2`. -/
@[simp] lemma angle_self_left (p₀ p : P) : ∠ p₀ p₀ p = π / 2 := by
unfold angle
rw [vsub_self]
exact angle_zero_left _
/-- The angle ∠ABB at a point is always `π / 2`. -/
@[simp] lemma angle_self_right (p₀ p : P) : ∠ p p₀ p₀ = π / 2 := by rw [angle_comm, angle_self_left]
/-- The angle ∠ABA at a point is `0`, unless `A = B`. -/
theorem angle_self_of_ne (h : p ≠ p₀) : ∠ p p₀ p = 0 := angle_self <| vsub_ne_zero.2 h
/-- If the angle ∠ABC at a point is π, the angle ∠BAC is 0. -/
theorem angle_eq_zero_of_angle_eq_pi_left {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₁ p₃ = 0 := by
unfold angle at h
rw [angle_eq_pi_iff] at h
rcases h with ⟨hp₁p₂, ⟨r, ⟨hr, hpr⟩⟩⟩
unfold angle
rw [angle_eq_zero_iff]
rw [← neg_vsub_eq_vsub_rev, neg_ne_zero] at hp₁p₂
use hp₁p₂, -r + 1, add_pos (neg_pos_of_neg hr) zero_lt_one
rw [add_smul, ← neg_vsub_eq_vsub_rev p₁ p₂, smul_neg]
simp [← hpr]
/-- If the angle ∠ABC at a point is π, the angle ∠BCA is 0. -/
theorem angle_eq_zero_of_angle_eq_pi_right {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) :
∠ p₂ p₃ p₁ = 0 := by
rw [angle_comm] at h
exact angle_eq_zero_of_angle_eq_pi_left h
/-- If ∠BCD = π, then ∠ABC = ∠ABD. -/
theorem angle_eq_angle_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) :
∠ p₁ p₂ p₃ = ∠ p₁ p₂ p₄ := by
unfold angle at *
rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, hpr⟩⟩⟩
rw [eq_comm]
convert angle_smul_right_of_pos (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) (add_pos (neg_pos_of_neg hr) zero_lt_one)
rw [add_smul, ← neg_vsub_eq_vsub_rev p₂ p₃, smul_neg, neg_smul, ← hpr]
simp
/-- If ∠BCD = π, then ∠ACB + ∠ACD = π. -/
nonrec theorem angle_add_angle_eq_pi_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) :
∠ p₁ p₃ p₂ + ∠ p₁ p₃ p₄ = π := by
unfold angle at h
rw [angle_comm p₁ p₃ p₂, angle_comm p₁ p₃ p₄]
unfold angle
exact angle_add_angle_eq_pi_of_angle_eq_pi _ h
/-- **Vertical Angles Theorem**: angles opposite each other, formed by two intersecting straight
lines, are equal. -/
theorem angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi {p₁ p₂ p₃ p₄ p₅ : P} (hapc : ∠ p₁ p₅ p₃ = π)
(hbpd : ∠ p₂ p₅ p₄ = π) : ∠ p₁ p₅ p₂ = ∠ p₃ p₅ p₄ := by
linarith [angle_add_angle_eq_pi_of_angle_eq_pi p₁ hbpd, angle_comm p₄ p₅ p₁,
angle_add_angle_eq_pi_of_angle_eq_pi p₄ hapc, angle_comm p₄ p₅ p₃]
/-- If ∠ABC = π then dist A B ≠ 0. -/
theorem left_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₂ ≠ 0 := by
by_contra heq
rw [dist_eq_zero] at heq
rw [heq, angle_self_left] at h
exact Real.pi_ne_zero (by linarith)
/-- If ∠ABC = π then dist C B ≠ 0. -/
theorem right_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₃ p₂ ≠ 0 :=
left_dist_ne_zero_of_angle_eq_pi <| (angle_comm _ _ _).trans h
/-- If ∠ABC = π, then (dist A C) = (dist A B) + (dist B C). -/
theorem dist_eq_add_dist_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) :
dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right]
exact norm_sub_eq_add_norm_of_angle_eq_pi h
/-- If A ≠ B and C ≠ B then ∠ABC = π if and only if (dist A C) = (dist A B) + (dist B C). -/
theorem dist_eq_add_dist_iff_angle_eq_pi {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) :
dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ ↔ ∠ p₁ p₂ p₃ = π := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right]
exact
norm_sub_eq_add_norm_iff_angle_eq_pi (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he)) fun he =>
hp₃p₂ (vsub_eq_zero_iff_eq.1 he)
/-- If ∠ABC = 0, then (dist A C) = abs ((dist A B) - (dist B C)). -/
theorem dist_eq_abs_sub_dist_of_angle_eq_zero {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = 0) :
dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right]
exact norm_sub_eq_abs_sub_norm_of_angle_eq_zero h
/-- If A ≠ B and C ≠ B then ∠ABC = 0 if and only if (dist A C) = abs ((dist A B) - (dist B C)). -/
theorem dist_eq_abs_sub_dist_iff_angle_eq_zero {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) :
dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| ↔ ∠ p₁ p₂ p₃ = 0 := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right]
exact
norm_sub_eq_abs_sub_norm_iff_angle_eq_zero (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he))
fun he => hp₃p₂ (vsub_eq_zero_iff_eq.1 he)
/-- If M is the midpoint of the segment AB, then ∠AMB = π. -/
theorem angle_midpoint_eq_pi (p₁ p₂ : P) (hp₁p₂ : p₁ ≠ p₂) : ∠ p₁ (midpoint ℝ p₁ p₂) p₂ = π := by
simp only [angle, left_vsub_midpoint, invOf_eq_inv, right_vsub_midpoint, inv_pos, zero_lt_two,
angle_smul_right_of_pos, angle_smul_left_of_pos]
rw [← neg_vsub_eq_vsub_rev p₁ p₂]
apply angle_self_neg_of_nonzero
simpa only [ne_eq, vsub_eq_zero_iff_eq]
/-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B
then ∠CMA = π / 2. -/
theorem angle_left_midpoint_eq_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₃ p₁ = dist p₃ p₂) :
∠ p₃ (midpoint ℝ p₁ p₂) p₁ = π / 2 := by
let m : P := midpoint ℝ p₁ p₂
have h1 : p₃ -ᵥ p₁ = p₃ -ᵥ m - (p₁ -ᵥ m) := (vsub_sub_vsub_cancel_right p₃ p₁ m).symm
have h2 : p₃ -ᵥ p₂ = p₃ -ᵥ m + (p₁ -ᵥ m) := by
rw [left_vsub_midpoint, ← midpoint_vsub_right, vsub_add_vsub_cancel]
rw [dist_eq_norm_vsub V p₃ p₁, dist_eq_norm_vsub V p₃ p₂, h1, h2] at h
exact (norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (p₃ -ᵥ m) (p₁ -ᵥ m)).mp h.symm
/-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B
then ∠CMB = π / 2. -/
theorem angle_right_midpoint_eq_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₃ p₁ = dist p₃ p₂) :
∠ p₃ (midpoint ℝ p₁ p₂) p₂ = π / 2 := by
rw [midpoint_comm p₁ p₂, angle_left_midpoint_eq_pi_div_two_of_dist_eq h.symm]
/-- If the second of three points is strictly between the other two, the angle at that point
is π. -/
theorem _root_.Sbtw.angle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₁ p₂ p₃ = π := by
rw [angle, angle_eq_pi_iff]
rcases h with ⟨⟨r, ⟨hr0, hr1⟩, hp₂⟩, hp₂p₁, hp₂p₃⟩
refine ⟨vsub_ne_zero.2 hp₂p₁.symm, -(1 - r) / r, ?_⟩
have hr0' : r ≠ 0 := by
rintro rfl
rw [← hp₂] at hp₂p₁
simp at hp₂p₁
have hr1' : r ≠ 1 := by
rintro rfl
rw [← hp₂] at hp₂p₃
simp at hp₂p₃
replace hr0 := hr0.lt_of_ne hr0'.symm
replace hr1 := hr1.lt_of_ne hr1'
refine ⟨div_neg_of_neg_of_pos (Left.neg_neg_iff.2 (sub_pos.2 hr1)) hr0, ?_⟩
rw [← hp₂, AffineMap.lineMap_apply, vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, vsub_self,
zero_sub, smul_neg, smul_smul, div_mul_cancel₀ _ hr0', neg_smul, neg_neg, sub_eq_iff_eq_add, ←
add_smul, sub_add_cancel, one_smul]
/-- If the second of three points is strictly between the other two, the angle at that point
(reversed) is π. -/
theorem _root_.Sbtw.angle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₃ p₂ p₁ = π := by
rw [← h.angle₁₂₃_eq_pi, angle_comm]
/-- The angle between three points is π if and only if the second point is strictly between the
other two. -/
theorem angle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by
refine ⟨?_, fun h => h.angle₁₂₃_eq_pi⟩
rw [angle, angle_eq_pi_iff]
rintro ⟨hp₁p₂, r, hr, hp₃p₂⟩
refine ⟨⟨1 / (1 - r), ⟨div_nonneg zero_le_one (sub_nonneg.2 (hr.le.trans zero_le_one)),
(div_le_one (sub_pos.2 (hr.trans zero_lt_one))).2 ((le_sub_self_iff 1).2 hr.le)⟩, ?_⟩,
(vsub_ne_zero.1 hp₁p₂).symm, ?_⟩
· rw [← eq_vadd_iff_vsub_eq] at hp₃p₂
rw [AffineMap.lineMap_apply, hp₃p₂, vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev p₂ p₁, smul_neg, ←
neg_smul, smul_add, smul_smul, ← add_smul, eq_comm, eq_vadd_iff_vsub_eq]
convert (one_smul ℝ (p₂ -ᵥ p₁)).symm
field_simp [(sub_pos.2 (hr.trans zero_lt_one)).ne.symm]
ring
· rw [ne_comm, ← @vsub_ne_zero V, hp₃p₂, smul_ne_zero_iff]
exact ⟨hr.ne, hp₁p₂⟩
/-- If the second of three points is weakly between the other two, and not equal to the first,
the angle at the first point is zero. -/
theorem _root_.Wbtw.angle₂₁₃_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₁ : p₂ ≠ p₁) :
∠ p₂ p₁ p₃ = 0 := by
rw [angle, angle_eq_zero_iff]
rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩
have hr0' : r ≠ 0 := by
rintro rfl
simp at hp₂p₁
replace hr0 := hr0.lt_of_ne hr0'.symm
refine ⟨vsub_ne_zero.2 hp₂p₁, r⁻¹, inv_pos.2 hr0, ?_⟩
rw [AffineMap.lineMap_apply, vadd_vsub_assoc, vsub_self, add_zero, smul_smul,
inv_mul_cancel₀ hr0', one_smul]
/-- If the second of three points is strictly between the other two, the angle at the first point
is zero. -/
theorem _root_.Sbtw.angle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₂ p₁ p₃ = 0 :=
h.wbtw.angle₂₁₃_eq_zero_of_ne h.ne_left
/-- If the second of three points is weakly between the other two, and not equal to the first,
the angle at the first point (reversed) is zero. -/
theorem _root_.Wbtw.angle₃₁₂_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₁ : p₂ ≠ p₁) :
∠ p₃ p₁ p₂ = 0 := by rw [← h.angle₂₁₃_eq_zero_of_ne hp₂p₁, angle_comm]
/-- If the second of three points is strictly between the other two, the angle at the first point
(reversed) is zero. -/
theorem _root_.Sbtw.angle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₃ p₁ p₂ = 0 :=
h.wbtw.angle₃₁₂_eq_zero_of_ne h.ne_left
/-- If the second of three points is weakly between the other two, and not equal to the third,
the angle at the third point is zero. -/
theorem _root_.Wbtw.angle₂₃₁_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₃ : p₂ ≠ p₃) :
∠ p₂ p₃ p₁ = 0 :=
h.symm.angle₂₁₃_eq_zero_of_ne hp₂p₃
/-- If the second of three points is strictly between the other two, the angle at the third point
is zero. -/
theorem _root_.Sbtw.angle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₂ p₃ p₁ = 0 :=
h.wbtw.angle₂₃₁_eq_zero_of_ne h.ne_right
/-- If the second of three points is weakly between the other two, and not equal to the third,
the angle at the third point (reversed) is zero. -/
theorem _root_.Wbtw.angle₁₃₂_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₃ : p₂ ≠ p₃) :
∠ p₁ p₃ p₂ = 0 :=
h.symm.angle₃₁₂_eq_zero_of_ne hp₂p₃
/-- If the second of three points is strictly between the other two, the angle at the third point
(reversed) is zero. -/
theorem _root_.Sbtw.angle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₁ p₃ p₂ = 0 :=
h.wbtw.angle₁₃₂_eq_zero_of_ne h.ne_right
/-- The angle between three points is zero if and only if one of the first and third points is
weakly between the other two, and not equal to the second. -/
theorem angle_eq_zero_iff_ne_and_wbtw {p₁ p₂ p₃ : P} :
∠ p₁ p₂ p₃ = 0 ↔ p₁ ≠ p₂ ∧ Wbtw ℝ p₂ p₁ p₃ ∨ p₃ ≠ p₂ ∧ Wbtw ℝ p₂ p₃ p₁ := by
constructor
· rw [angle, angle_eq_zero_iff]
rintro ⟨hp₁p₂, r, hr0, hp₃p₂⟩
rcases le_or_lt 1 r with (hr1 | hr1)
· refine Or.inl ⟨vsub_ne_zero.1 hp₁p₂, r⁻¹, ⟨(inv_pos.2 hr0).le, inv_le_one_of_one_le₀ hr1⟩, ?_⟩
rw [AffineMap.lineMap_apply, hp₃p₂, smul_smul, inv_mul_cancel₀ hr0.ne.symm, one_smul,
vsub_vadd]
· refine Or.inr ⟨?_, r, ⟨hr0.le, hr1.le⟩, ?_⟩
· rw [← @vsub_ne_zero V, hp₃p₂, smul_ne_zero_iff]
exact ⟨hr0.ne.symm, hp₁p₂⟩
· rw [AffineMap.lineMap_apply, ← hp₃p₂, vsub_vadd]
· rintro (⟨hp₁p₂, h⟩ | ⟨hp₃p₂, h⟩)
· exact h.angle₂₁₃_eq_zero_of_ne hp₁p₂
· exact h.angle₃₁₂_eq_zero_of_ne hp₃p₂
/-- The angle between three points is zero if and only if one of the first and third points is
strictly between the other two, or those two points are equal but not equal to the second. -/
theorem angle_eq_zero_iff_eq_and_ne_or_sbtw {p₁ p₂ p₃ : P} :
∠ p₁ p₂ p₃ = 0 ↔ p₁ = p₃ ∧ p₁ ≠ p₂ ∨ Sbtw ℝ p₂ p₁ p₃ ∨ Sbtw ℝ p₂ p₃ p₁ := by
rw [angle_eq_zero_iff_ne_and_wbtw]
by_cases hp₁p₂ : p₁ = p₂; · simp [hp₁p₂]
by_cases hp₁p₃ : p₁ = p₃; · simp [hp₁p₃]
by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂]
simp [hp₁p₂, hp₁p₃, Ne.symm hp₁p₃, Sbtw, hp₃p₂]
/-- Three points are collinear if and only if the first or third point equals the second or the
angle between them is 0 or π. -/
theorem collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi {p₁ p₂ p₃ : P} :
Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ p₁ = p₂ ∨ p₃ = p₂ ∨ ∠ p₁ p₂ p₃ = 0 ∨ ∠ p₁ p₂ p₃ = π := by
refine ⟨fun h => ?_, fun h => ?_⟩
· replace h := h.wbtw_or_wbtw_or_wbtw
by_cases h₁₂ : p₁ = p₂
· exact Or.inl h₁₂
by_cases h₃₂ : p₃ = p₂
· exact Or.inr (Or.inl h₃₂)
rw [or_iff_right h₁₂, or_iff_right h₃₂]
rcases h with (h | h | h)
· exact Or.inr (angle_eq_pi_iff_sbtw.2 ⟨h, Ne.symm h₁₂, Ne.symm h₃₂⟩)
· exact Or.inl (h.angle₃₁₂_eq_zero_of_ne h₃₂)
· exact Or.inl (h.angle₂₃₁_eq_zero_of_ne h₁₂)
· rcases h with (rfl | rfl | h | h)
· simpa using collinear_pair ℝ p₁ p₃
· simpa using collinear_pair ℝ p₁ p₃
· rw [angle_eq_zero_iff_ne_and_wbtw] at h
rcases h with (⟨-, h⟩ | ⟨-, h⟩)
· rw [Set.insert_comm]
exact h.collinear
· rw [Set.insert_comm, Set.pair_comm]
exact h.collinear
· rw [angle_eq_pi_iff_sbtw] at h
exact h.wbtw.collinear
/-- If the angle between three points is 0, they are collinear. -/
theorem collinear_of_angle_eq_zero {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = 0) :
Collinear ℝ ({p₁, p₂, p₃} : Set P) :=
collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi.2 <| Or.inr <| Or.inr <| Or.inl h
/-- If the angle between three points is π, they are collinear. -/
theorem collinear_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) :
Collinear ℝ ({p₁, p₂, p₃} : Set P) :=
collinear_iff_eq_or_eq_or_angle_eq_zero_or_angle_eq_pi.2 <| Or.inr <| Or.inr <| Or.inr h
/-- If three points are not collinear, the angle between them is nonzero. -/
theorem angle_ne_zero_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) :
∠ p₁ p₂ p₃ ≠ 0 :=
mt collinear_of_angle_eq_zero h
/-- If three points are not collinear, the angle between them is not π. -/
theorem angle_ne_pi_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) :
∠ p₁ p₂ p₃ ≠ π :=
mt collinear_of_angle_eq_pi h
/-- If three points are not collinear, the angle between them is positive. -/
theorem angle_pos_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) :
0 < ∠ p₁ p₂ p₃ :=
(angle_nonneg _ _ _).lt_of_ne (angle_ne_zero_of_not_collinear h).symm
/-- If three points are not collinear, the angle between them is less than π. -/
theorem angle_lt_pi_of_not_collinear {p₁ p₂ p₃ : P} (h : ¬Collinear ℝ ({p₁, p₂, p₃} : Set P)) :
∠ p₁ p₂ p₃ < π :=
| (angle_le_pi _ _ _).lt_of_ne <| angle_ne_pi_of_not_collinear h
/-- The cosine of the angle between three points is 1 if and only if the angle is 0. -/
nonrec theorem cos_eq_one_iff_angle_eq_zero {p₁ p₂ p₃ : P} :
Real.cos (∠ p₁ p₂ p₃) = 1 ↔ ∠ p₁ p₂ p₃ = 0 :=
cos_eq_one_iff_angle_eq_zero
/-- The cosine of the angle between three points is 0 if and only if the angle is π / 2. -/
nonrec theorem cos_eq_zero_iff_angle_eq_pi_div_two {p₁ p₂ p₃ : P} :
Real.cos (∠ p₁ p₂ p₃) = 0 ↔ ∠ p₁ p₂ p₃ = π / 2 :=
cos_eq_zero_iff_angle_eq_pi_div_two
/-- The cosine of the angle between three points is -1 if and only if the angle is π. -/
nonrec theorem cos_eq_neg_one_iff_angle_eq_pi {p₁ p₂ p₃ : P} :
Real.cos (∠ p₁ p₂ p₃) = -1 ↔ ∠ p₁ p₂ p₃ = π :=
cos_eq_neg_one_iff_angle_eq_pi
/-- The sine of the angle between three points is 0 if and only if the angle is 0 or π. -/
nonrec theorem sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi {p₁ p₂ p₃ : P} :
Real.sin (∠ p₁ p₂ p₃) = 0 ↔ ∠ p₁ p₂ p₃ = 0 ∨ ∠ p₁ p₂ p₃ = π :=
sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi
/-- The sine of the angle between three points is 1 if and only if the angle is π / 2. -/
nonrec theorem sin_eq_one_iff_angle_eq_pi_div_two {p₁ p₂ p₃ : P} :
| Mathlib/Geometry/Euclidean/Angle/Unoriented/Affine.lean | 424 | 447 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Data.Nat.ModEq
/-!
# Congruences modulo an integer
This file defines the equivalence relation `a ≡ b [ZMOD n]` on the integers, similarly to how
`Data.Nat.ModEq` defines them for the natural numbers. The notation is short for `n.ModEq a b`,
which is defined to be `a % n = b % n` for integers `a b n`.
## Tags
modeq, congruence, mod, MOD, modulo, integers
-/
namespace Int
/-- `a ≡ b [ZMOD n]` when `a % n = b % n`. -/
def ModEq (n a b : ℤ) :=
a % n = b % n
@[inherit_doc]
notation:50 a " ≡ " b " [ZMOD " n "]" => ModEq n a b
variable {m n a b c d : ℤ}
instance : Decidable (ModEq n a b) := decEq (a % n) (b % n)
namespace ModEq
@[refl, simp]
protected theorem refl (a : ℤ) : a ≡ a [ZMOD n] :=
@rfl _ _
protected theorem rfl : a ≡ a [ZMOD n] :=
ModEq.refl _
instance : IsRefl _ (ModEq n) :=
⟨ModEq.refl⟩
@[symm]
protected theorem symm : a ≡ b [ZMOD n] → b ≡ a [ZMOD n] :=
Eq.symm
@[trans]
protected theorem trans : a ≡ b [ZMOD n] → b ≡ c [ZMOD n] → a ≡ c [ZMOD n] :=
Eq.trans
instance : IsTrans ℤ (ModEq n) where
trans := @Int.ModEq.trans n
protected theorem eq : a ≡ b [ZMOD n] → a % n = b % n := id
end ModEq
theorem modEq_comm : a ≡ b [ZMOD n] ↔ b ≡ a [ZMOD n] := ⟨ModEq.symm, ModEq.symm⟩
theorem natCast_modEq_iff {a b n : ℕ} : a ≡ b [ZMOD n] ↔ a ≡ b [MOD n] := by
unfold ModEq Nat.ModEq; rw [← Int.ofNat_inj]; simp [natCast_mod]
theorem modEq_zero_iff_dvd : a ≡ 0 [ZMOD n] ↔ n ∣ a := by
rw [ModEq, zero_emod, dvd_iff_emod_eq_zero]
theorem _root_.Dvd.dvd.modEq_zero_int (h : n ∣ a) : a ≡ 0 [ZMOD n] :=
modEq_zero_iff_dvd.2 h
theorem _root_.Dvd.dvd.zero_modEq_int (h : n ∣ a) : 0 ≡ a [ZMOD n] :=
h.modEq_zero_int.symm
theorem modEq_iff_dvd : a ≡ b [ZMOD n] ↔ n ∣ b - a := by
rw [ModEq, eq_comm]
simp [emod_eq_emod_iff_emod_sub_eq_zero, dvd_iff_emod_eq_zero]
theorem modEq_iff_add_fac {a b n : ℤ} : a ≡ b [ZMOD n] ↔ ∃ t, b = a + n * t := by
rw [modEq_iff_dvd]
exact exists_congr fun t => sub_eq_iff_eq_add'
alias ⟨ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd
theorem mod_modEq (a n) : a % n ≡ a [ZMOD n] :=
emod_emod _ _
@[simp]
theorem neg_modEq_neg : -a ≡ -b [ZMOD n] ↔ a ≡ b [ZMOD n] := by
simp only [modEq_iff_dvd, (by omega : -b - -a = -(b - a)), Int.dvd_neg]
@[simp]
theorem modEq_neg : a ≡ b [ZMOD -n] ↔ a ≡ b [ZMOD n] := by simp [modEq_iff_dvd]
namespace ModEq
protected theorem of_dvd (d : m ∣ n) (h : a ≡ b [ZMOD n]) : a ≡ b [ZMOD m] :=
modEq_iff_dvd.2 <| d.trans h.dvd
protected theorem mul_left' (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD c * n] := by
obtain hc | rfl | hc := lt_trichotomy c 0
· rw [← neg_modEq_neg, ← modEq_neg, ← Int.neg_mul, ← Int.neg_mul, ← Int.neg_mul]
simp only [ModEq, mul_emod_mul_of_pos _ _ (neg_pos.2 hc), h.eq]
· simp only [Int.zero_mul, ModEq.rfl]
· simp only [ModEq, mul_emod_mul_of_pos _ _ hc, h.eq]
protected theorem mul_right' (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n * c] := by
rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left'
@[gcongr]
protected theorem add (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a + c ≡ b + d [ZMOD n] :=
modEq_iff_dvd.2 <| by convert Int.dvd_add h₁.dvd h₂.dvd using 1; omega
@[gcongr] protected theorem add_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c + a ≡ c + b [ZMOD n] :=
ModEq.rfl.add h
@[gcongr] protected theorem add_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a + c ≡ b + c [ZMOD n] :=
h.add ModEq.rfl
protected theorem add_left_cancel (h₁ : a ≡ b [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) :
c ≡ d [ZMOD n] :=
have : d - c = b + d - (a + c) - (b - a) := by omega
modEq_iff_dvd.2 <| by
rw [this]
exact Int.dvd_sub h₂.dvd h₁.dvd
protected theorem add_left_cancel' (c : ℤ) (h : c + a ≡ c + b [ZMOD n]) : a ≡ b [ZMOD n] :=
ModEq.rfl.add_left_cancel h
protected theorem add_right_cancel (h₁ : c ≡ d [ZMOD n]) (h₂ : a + c ≡ b + d [ZMOD n]) :
a ≡ b [ZMOD n] := by
rw [add_comm a, add_comm b] at h₂
exact h₁.add_left_cancel h₂
protected theorem add_right_cancel' (c : ℤ) (h : a + c ≡ b + c [ZMOD n]) : a ≡ b [ZMOD n] :=
ModEq.rfl.add_right_cancel h
@[gcongr] protected theorem neg (h : a ≡ b [ZMOD n]) : -a ≡ -b [ZMOD n] :=
h.add_left_cancel (by simp_rw [← sub_eq_add_neg, sub_self]; rfl)
@[gcongr]
protected theorem sub (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a - c ≡ b - d [ZMOD n] := by
rw [sub_eq_add_neg, sub_eq_add_neg]
exact h₁.add h₂.neg
@[gcongr] protected theorem sub_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c - a ≡ c - b [ZMOD n] :=
ModEq.rfl.sub h
@[gcongr] protected theorem sub_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a - c ≡ b - c [ZMOD n] :=
h.sub ModEq.rfl
@[gcongr] protected theorem mul_left (c : ℤ) (h : a ≡ b [ZMOD n]) : c * a ≡ c * b [ZMOD n] :=
h.mul_left'.of_dvd <| dvd_mul_left _ _
@[gcongr] protected theorem mul_right (c : ℤ) (h : a ≡ b [ZMOD n]) : a * c ≡ b * c [ZMOD n] :=
h.mul_right'.of_dvd <| dvd_mul_right _ _
@[gcongr]
protected theorem mul (h₁ : a ≡ b [ZMOD n]) (h₂ : c ≡ d [ZMOD n]) : a * c ≡ b * d [ZMOD n] :=
(h₂.mul_left _).trans (h₁.mul_right _)
@[gcongr] protected theorem pow (m : ℕ) (h : a ≡ b [ZMOD n]) : a ^ m ≡ b ^ m [ZMOD n] := by
induction' m with d hd; · rfl
rw [pow_succ, pow_succ]
exact hd.mul h
lemma of_mul_left (m : ℤ) (h : a ≡ b [ZMOD m * n]) : a ≡ b [ZMOD n] := by
rw [modEq_iff_dvd] at *; exact (dvd_mul_left n m).trans h
lemma of_mul_right (m : ℤ) : a ≡ b [ZMOD n * m] → a ≡ b [ZMOD n] :=
mul_comm m n ▸ of_mul_left _
/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c`. -/
theorem cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [ZMOD m]) :
a ≡ b [ZMOD m / gcd m c] := by
letI d := gcd m c
rw [modEq_iff_dvd] at h ⊢
refine Int.dvd_of_dvd_mul_right_of_gcd_one (?_ : m / d ∣ c / d * (b - a)) ?_
· rw [mul_comm, ← Int.mul_ediv_assoc (b - a) gcd_dvd_right, Int.sub_mul]
exact Int.ediv_dvd_ediv gcd_dvd_left h
· rw [gcd_div gcd_dvd_left gcd_dvd_right, natAbs_natCast,
Nat.div_self (gcd_pos_of_ne_zero_left c hm.ne')]
/-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c`. -/
theorem cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [ZMOD m]) : a ≡ b [ZMOD m / gcd m c] :=
cancel_right_div_gcd hm <| by simpa [mul_comm] using h
theorem of_div (h : a / c ≡ b / c [ZMOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) :
a ≡ b [ZMOD m] := by convert h.mul_left' <;> rwa [Int.mul_ediv_cancel']
end ModEq
theorem modEq_one : a ≡ b [ZMOD 1] :=
modEq_of_dvd (one_dvd _)
theorem modEq_sub (a b : ℤ) : a ≡ b [ZMOD a - b] :=
(modEq_of_dvd dvd_rfl).symm
@[simp]
theorem modEq_zero_iff : a ≡ b [ZMOD 0] ↔ a = b := by rw [ModEq, emod_zero, emod_zero]
@[simp]
theorem add_modEq_left : n + a ≡ a [ZMOD n] := ModEq.symm <| modEq_iff_dvd.2 <| by simp
@[simp]
theorem add_modEq_right : a + n ≡ a [ZMOD n] := ModEq.symm <| modEq_iff_dvd.2 <| by simp
theorem modEq_and_modEq_iff_modEq_mul {a b m n : ℤ} (hmn : m.natAbs.Coprime n.natAbs) :
a ≡ b [ZMOD m] ∧ a ≡ b [ZMOD n] ↔ a ≡ b [ZMOD m * n] :=
⟨fun h => by
rw [modEq_iff_dvd, modEq_iff_dvd] at h
rw [modEq_iff_dvd, ← natAbs_dvd, ← dvd_natAbs, natCast_dvd_natCast, natAbs_mul]
refine hmn.mul_dvd_of_dvd_of_dvd ?_ ?_ <;>
rw [← natCast_dvd_natCast, natAbs_dvd, dvd_natAbs] <;>
tauto,
fun h => ⟨h.of_mul_right _, h.of_mul_left _⟩⟩
theorem gcd_a_modEq (a b : ℕ) : (a : ℤ) * Nat.gcdA a b ≡ Nat.gcd a b [ZMOD b] := by
rw [← add_zero ((a : ℤ) * _), Nat.gcd_eq_gcd_ab]
exact (dvd_mul_right _ _).zero_modEq_int.add_left _
theorem modEq_add_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a + n * c ≡ b [ZMOD n] :=
calc
a + n * c ≡ b + n * c [ZMOD n] := ha.add_right _
_ ≡ b + 0 [ZMOD n] := (dvd_mul_right _ _).modEq_zero_int.add_left _
_ ≡ b [ZMOD n] := by rw [add_zero]
theorem modEq_sub_fac {a b n : ℤ} (c : ℤ) (ha : a ≡ b [ZMOD n]) : a - n * c ≡ b [ZMOD n] := by
convert Int.modEq_add_fac (-c) ha using 1; rw [Int.mul_neg, sub_eq_add_neg]
| theorem modEq_add_fac_self {a t n : ℤ} : a + n * t ≡ a [ZMOD n] :=
modEq_add_fac _ ModEq.rfl
| Mathlib/Data/Int/ModEq.lean | 233 | 234 |
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Analysis.Calculus.ContDiff.Bounds
import Mathlib.Analysis.Calculus.IteratedDeriv.Defs
import Mathlib.Analysis.Calculus.LineDeriv.Basic
import Mathlib.Analysis.LocallyConvex.WithSeminorms
import Mathlib.Analysis.Normed.Group.ZeroAtInfty
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Analysis.SpecialFunctions.JapaneseBracket
import Mathlib.Topology.Algebra.UniformFilterBasis
import Mathlib.Tactic.MoveAdd
/-!
# Schwartz space
This file defines the Schwartz space. Usually, the Schwartz space is defined as the set of smooth
functions $f : ℝ^n → ℂ$ such that there exists $C_{αβ} > 0$ with $$|x^α ∂^β f(x)| < C_{αβ}$$ for
all $x ∈ ℝ^n$ and for all multiindices $α, β$.
In mathlib, we use a slightly different approach and define the Schwartz space as all
smooth functions `f : E → F`, where `E` and `F` are real normed vector spaces such that for all
natural numbers `k` and `n` we have uniform bounds `‖x‖^k * ‖iteratedFDeriv ℝ n f x‖ < C`.
This approach completely avoids using partial derivatives as well as polynomials.
We construct the topology on the Schwartz space by a family of seminorms, which are the best
constants in the above estimates. The abstract theory of topological vector spaces developed in
`SeminormFamily.moduleFilterBasis` and `WithSeminorms.toLocallyConvexSpace` turns the
Schwartz space into a locally convex topological vector space.
## Main definitions
* `SchwartzMap`: The Schwartz space is the space of smooth functions such that all derivatives
decay faster than any power of `‖x‖`.
* `SchwartzMap.seminorm`: The family of seminorms as described above
* `SchwartzMap.compCLM`: Composition with a function on the right as a continuous linear map
`𝓢(E, F) →L[𝕜] 𝓢(D, F)`, provided that the function is temperate and grows polynomially near
infinity
* `SchwartzMap.fderivCLM`: The differential as a continuous linear map
`𝓢(E, F) →L[𝕜] 𝓢(E, E →L[ℝ] F)`
* `SchwartzMap.derivCLM`: The one-dimensional derivative as a continuous linear map
`𝓢(ℝ, F) →L[𝕜] 𝓢(ℝ, F)`
* `SchwartzMap.integralCLM`: Integration as a continuous linear map `𝓢(ℝ, F) →L[ℝ] F`
## Main statements
* `SchwartzMap.instIsUniformAddGroup` and `SchwartzMap.instLocallyConvexSpace`: The Schwartz space
is a locally convex topological vector space.
* `SchwartzMap.one_add_le_sup_seminorm_apply`: For a Schwartz function `f` there is a uniform bound
on `(1 + ‖x‖) ^ k * ‖iteratedFDeriv ℝ n f x‖`.
## Implementation details
The implementation of the seminorms is taken almost literally from `ContinuousLinearMap.opNorm`.
## Notation
* `𝓢(E, F)`: The Schwartz space `SchwartzMap E F` localized in `SchwartzSpace`
## Tags
Schwartz space, tempered distributions
-/
noncomputable section
open scoped Nat NNReal ContDiff
variable {𝕜 𝕜' D E F G V : Type*}
variable [NormedAddCommGroup E] [NormedSpace ℝ E]
variable [NormedAddCommGroup F] [NormedSpace ℝ F]
variable (E F)
/-- A function is a Schwartz function if it is smooth and all derivatives decay faster than
any power of `‖x‖`. -/
structure SchwartzMap where
toFun : E → F
smooth' : ContDiff ℝ ∞ toFun
decay' : ∀ k n : ℕ, ∃ C : ℝ, ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n toFun x‖ ≤ C
/-- A function is a Schwartz function if it is smooth and all derivatives decay faster than
any power of `‖x‖`. -/
scoped[SchwartzMap] notation "𝓢(" E ", " F ")" => SchwartzMap E F
variable {E F}
namespace SchwartzMap
instance instFunLike : FunLike 𝓢(E, F) E F where
coe f := f.toFun
coe_injective' f g h := by cases f; cases g; congr
/-- All derivatives of a Schwartz function are rapidly decaying. -/
theorem decay (f : 𝓢(E, F)) (k n : ℕ) :
∃ C : ℝ, 0 < C ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ C := by
rcases f.decay' k n with ⟨C, hC⟩
exact ⟨max C 1, by positivity, fun x => (hC x).trans (le_max_left _ _)⟩
/-- Every Schwartz function is smooth. -/
theorem smooth (f : 𝓢(E, F)) (n : ℕ∞) : ContDiff ℝ n f :=
f.smooth'.of_le (mod_cast le_top)
/-- Every Schwartz function is continuous. -/
@[continuity]
protected theorem continuous (f : 𝓢(E, F)) : Continuous f :=
(f.smooth 0).continuous
instance instContinuousMapClass : ContinuousMapClass 𝓢(E, F) E F where
map_continuous := SchwartzMap.continuous
/-- Every Schwartz function is differentiable. -/
protected theorem differentiable (f : 𝓢(E, F)) : Differentiable ℝ f :=
(f.smooth 1).differentiable rfl.le
/-- Every Schwartz function is differentiable at any point. -/
protected theorem differentiableAt (f : 𝓢(E, F)) {x : E} : DifferentiableAt ℝ f x :=
f.differentiable.differentiableAt
@[ext]
theorem ext {f g : 𝓢(E, F)} (h : ∀ x, (f : E → F) x = g x) : f = g :=
DFunLike.ext f g h
section IsBigO
open Asymptotics Filter
variable (f : 𝓢(E, F))
/-- Auxiliary lemma, used in proving the more general result `isBigO_cocompact_rpow`. -/
theorem isBigO_cocompact_zpow_neg_nat (k : ℕ) :
f =O[cocompact E] fun x => ‖x‖ ^ (-k : ℤ) := by
obtain ⟨d, _, hd'⟩ := f.decay k 0
simp only [norm_iteratedFDeriv_zero] at hd'
simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith]
refine ⟨d, Filter.Eventually.filter_mono Filter.cocompact_le_cofinite ?_⟩
refine (Filter.eventually_cofinite_ne 0).mono fun x hx => ?_
rw [Real.norm_of_nonneg (zpow_nonneg (norm_nonneg _) _), zpow_neg, ← div_eq_mul_inv, le_div_iff₀']
exacts [hd' x, zpow_pos (norm_pos_iff.mpr hx) _]
theorem isBigO_cocompact_rpow [ProperSpace E] (s : ℝ) :
f =O[cocompact E] fun x => ‖x‖ ^ s := by
let k := ⌈-s⌉₊
have hk : -(k : ℝ) ≤ s := neg_le.mp (Nat.le_ceil (-s))
refine (isBigO_cocompact_zpow_neg_nat f k).trans ?_
suffices (fun x : ℝ => x ^ (-k : ℤ)) =O[atTop] fun x : ℝ => x ^ s
from this.comp_tendsto tendsto_norm_cocompact_atTop
simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith]
refine ⟨1, (Filter.eventually_ge_atTop 1).mono fun x hx => ?_⟩
rw [one_mul, Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans hx) _),
Real.norm_of_nonneg (zpow_nonneg (zero_le_one.trans hx) _), ← Real.rpow_intCast, Int.cast_neg,
Int.cast_natCast]
exact Real.rpow_le_rpow_of_exponent_le hx hk
theorem isBigO_cocompact_zpow [ProperSpace E] (k : ℤ) :
f =O[cocompact E] fun x => ‖x‖ ^ k := by
simpa only [Real.rpow_intCast] using isBigO_cocompact_rpow f k
end IsBigO
section Aux
theorem bounds_nonempty (k n : ℕ) (f : 𝓢(E, F)) :
∃ c : ℝ, c ∈ { c : ℝ | 0 ≤ c ∧ ∀ x : E, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } :=
let ⟨M, hMp, hMb⟩ := f.decay k n
⟨M, le_of_lt hMp, hMb⟩
theorem bounds_bddBelow (k n : ℕ) (f : 𝓢(E, F)) :
BddBelow { c | 0 ≤ c ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
theorem decay_add_le_aux (k n : ℕ) (f g : 𝓢(E, F)) (x : E) :
‖x‖ ^ k * ‖iteratedFDeriv ℝ n ((f : E → F) + (g : E → F)) x‖ ≤
‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ + ‖x‖ ^ k * ‖iteratedFDeriv ℝ n g x‖ := by
rw [← mul_add]
refine mul_le_mul_of_nonneg_left ?_ (by positivity)
rw [iteratedFDeriv_add_apply (f.smooth _).contDiffAt (g.smooth _).contDiffAt]
exact norm_add_le _ _
theorem decay_neg_aux (k n : ℕ) (f : 𝓢(E, F)) (x : E) :
‖x‖ ^ k * ‖iteratedFDeriv ℝ n (-f : E → F) x‖ = ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ := by
rw [iteratedFDeriv_neg_apply, norm_neg]
variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
theorem decay_smul_aux (k n : ℕ) (f : 𝓢(E, F)) (c : 𝕜) (x : E) :
‖x‖ ^ k * ‖iteratedFDeriv ℝ n (c • (f : E → F)) x‖ =
‖c‖ * ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ := by
rw [mul_comm ‖c‖, mul_assoc, iteratedFDeriv_const_smul_apply (f.smooth _).contDiffAt,
norm_smul c (iteratedFDeriv ℝ n (⇑f) x)]
end Aux
section SeminormAux
/-- Helper definition for the seminorms of the Schwartz space. -/
protected def seminormAux (k n : ℕ) (f : 𝓢(E, F)) : ℝ :=
sInf { c | 0 ≤ c ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c }
theorem seminormAux_nonneg (k n : ℕ) (f : 𝓢(E, F)) : 0 ≤ f.seminormAux k n :=
le_csInf (bounds_nonempty k n f) fun _ ⟨hx, _⟩ => hx
theorem le_seminormAux (k n : ℕ) (f : 𝓢(E, F)) (x : E) :
‖x‖ ^ k * ‖iteratedFDeriv ℝ n (⇑f) x‖ ≤ f.seminormAux k n :=
le_csInf (bounds_nonempty k n f) fun _ ⟨_, h⟩ => h x
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
theorem seminormAux_le_bound (k n : ℕ) (f : 𝓢(E, F)) {M : ℝ} (hMp : 0 ≤ M)
(hM : ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ M) : f.seminormAux k n ≤ M :=
csInf_le (bounds_bddBelow k n f) ⟨hMp, hM⟩
end SeminormAux
/-! ### Algebraic properties -/
section SMul
variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] [NormedField 𝕜'] [NormedSpace 𝕜' F]
[SMulCommClass ℝ 𝕜' F]
instance instSMul : SMul 𝕜 𝓢(E, F) :=
⟨fun c f =>
{ toFun := c • (f : E → F)
smooth' := (f.smooth _).const_smul c
decay' := fun k n => by
refine ⟨f.seminormAux k n * (‖c‖ + 1), fun x => ?_⟩
have hc : 0 ≤ ‖c‖ := by positivity
refine le_trans ?_ ((mul_le_mul_of_nonneg_right (f.le_seminormAux k n x) hc).trans ?_)
· apply Eq.le
rw [mul_comm _ ‖c‖, ← mul_assoc]
exact decay_smul_aux k n f c x
· apply mul_le_mul_of_nonneg_left _ (f.seminormAux_nonneg k n)
linarith }⟩
@[simp]
theorem smul_apply {f : 𝓢(E, F)} {c : 𝕜} {x : E} : (c • f) x = c • f x :=
rfl
instance instIsScalarTower [SMul 𝕜 𝕜'] [IsScalarTower 𝕜 𝕜' F] : IsScalarTower 𝕜 𝕜' 𝓢(E, F) :=
⟨fun a b f => ext fun x => smul_assoc a b (f x)⟩
instance instSMulCommClass [SMulCommClass 𝕜 𝕜' F] : SMulCommClass 𝕜 𝕜' 𝓢(E, F) :=
⟨fun a b f => ext fun x => smul_comm a b (f x)⟩
theorem seminormAux_smul_le (k n : ℕ) (c : 𝕜) (f : 𝓢(E, F)) :
(c • f).seminormAux k n ≤ ‖c‖ * f.seminormAux k n := by
refine
(c • f).seminormAux_le_bound k n (mul_nonneg (norm_nonneg _) (seminormAux_nonneg _ _ _))
fun x => (decay_smul_aux k n f c x).le.trans ?_
rw [mul_assoc]
exact mul_le_mul_of_nonneg_left (f.le_seminormAux k n x) (norm_nonneg _)
instance instNSMul : SMul ℕ 𝓢(E, F) :=
⟨fun c f =>
{ toFun := c • (f : E → F)
smooth' := (f.smooth _).const_smul c
decay' := by simpa [← Nat.cast_smul_eq_nsmul ℝ] using ((c : ℝ) • f).decay' }⟩
instance instZSMul : SMul ℤ 𝓢(E, F) :=
⟨fun c f =>
{ toFun := c • (f : E → F)
smooth' := (f.smooth _).const_smul c
decay' := by simpa [← Int.cast_smul_eq_zsmul ℝ] using ((c : ℝ) • f).decay' }⟩
end SMul
section Zero
instance instZero : Zero 𝓢(E, F) :=
⟨{ toFun := fun _ => 0
smooth' := contDiff_const
decay' := fun _ _ => ⟨1, fun _ => by simp⟩ }⟩
instance instInhabited : Inhabited 𝓢(E, F) :=
⟨0⟩
theorem coe_zero : DFunLike.coe (0 : 𝓢(E, F)) = (0 : E → F) :=
rfl
@[simp]
theorem coeFn_zero : ⇑(0 : 𝓢(E, F)) = (0 : E → F) :=
rfl
@[simp]
theorem zero_apply {x : E} : (0 : 𝓢(E, F)) x = 0 :=
rfl
theorem seminormAux_zero (k n : ℕ) : (0 : 𝓢(E, F)).seminormAux k n = 0 :=
le_antisymm (seminormAux_le_bound k n _ rfl.le fun _ => by simp [Pi.zero_def])
(seminormAux_nonneg _ _ _)
end Zero
section Neg
instance instNeg : Neg 𝓢(E, F) :=
⟨fun f =>
⟨-f, (f.smooth _).neg, fun k n =>
⟨f.seminormAux k n, fun x => (decay_neg_aux k n f x).le.trans (f.le_seminormAux k n x)⟩⟩⟩
end Neg
section Add
instance instAdd : Add 𝓢(E, F) :=
⟨fun f g =>
⟨f + g, (f.smooth _).add (g.smooth _), fun k n =>
⟨f.seminormAux k n + g.seminormAux k n, fun x =>
(decay_add_le_aux k n f g x).trans
(add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x))⟩⟩⟩
@[simp]
theorem add_apply {f g : 𝓢(E, F)} {x : E} : (f + g) x = f x + g x :=
rfl
theorem seminormAux_add_le (k n : ℕ) (f g : 𝓢(E, F)) :
(f + g).seminormAux k n ≤ f.seminormAux k n + g.seminormAux k n :=
(f + g).seminormAux_le_bound k n
(add_nonneg (seminormAux_nonneg _ _ _) (seminormAux_nonneg _ _ _)) fun x =>
(decay_add_le_aux k n f g x).trans <|
add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x)
end Add
section Sub
instance instSub : Sub 𝓢(E, F) :=
⟨fun f g =>
⟨f - g, (f.smooth _).sub (g.smooth _), by
intro k n
refine ⟨f.seminormAux k n + g.seminormAux k n, fun x => ?_⟩
refine le_trans ?_ (add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x))
rw [sub_eq_add_neg]
rw [← decay_neg_aux k n g x]
convert decay_add_le_aux k n f (-g) x⟩⟩
-- exact fails with deterministic timeout
@[simp]
theorem sub_apply {f g : 𝓢(E, F)} {x : E} : (f - g) x = f x - g x :=
rfl
end Sub
section AddCommGroup
instance instAddCommGroup : AddCommGroup 𝓢(E, F) :=
DFunLike.coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
variable (E F)
/-- Coercion as an additive homomorphism. -/
def coeHom : 𝓢(E, F) →+ E → F where
toFun f := f
map_zero' := coe_zero
map_add' _ _ := rfl
variable {E F}
theorem coe_coeHom : (coeHom E F : 𝓢(E, F) → E → F) = DFunLike.coe :=
rfl
theorem coeHom_injective : Function.Injective (coeHom E F) := by
rw [coe_coeHom]
exact DFunLike.coe_injective
end AddCommGroup
section Module
variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
instance instModule : Module 𝕜 𝓢(E, F) :=
coeHom_injective.module 𝕜 (coeHom E F) fun _ _ => rfl
end Module
section Seminorms
/-! ### Seminorms on Schwartz space -/
variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
variable (𝕜)
/-- The seminorms of the Schwartz space given by the best constants in the definition of
`𝓢(E, F)`. -/
protected def seminorm (k n : ℕ) : Seminorm 𝕜 𝓢(E, F) :=
Seminorm.ofSMulLE (SchwartzMap.seminormAux k n) (seminormAux_zero k n) (seminormAux_add_le k n)
(seminormAux_smul_le k n)
/-- If one controls the seminorm for every `x`, then one controls the seminorm. -/
theorem seminorm_le_bound (k n : ℕ) (f : 𝓢(E, F)) {M : ℝ} (hMp : 0 ≤ M)
(hM : ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ M) : SchwartzMap.seminorm 𝕜 k n f ≤ M :=
f.seminormAux_le_bound k n hMp hM
/-- If one controls the seminorm for every `x`, then one controls the seminorm.
Variant for functions `𝓢(ℝ, F)`. -/
theorem seminorm_le_bound' (k n : ℕ) (f : 𝓢(ℝ, F)) {M : ℝ} (hMp : 0 ≤ M)
(hM : ∀ x, |x| ^ k * ‖iteratedDeriv n f x‖ ≤ M) : SchwartzMap.seminorm 𝕜 k n f ≤ M := by
refine seminorm_le_bound 𝕜 k n f hMp ?_
simpa only [Real.norm_eq_abs, norm_iteratedFDeriv_eq_norm_iteratedDeriv]
/-- The seminorm controls the Schwartz estimate for any fixed `x`. -/
theorem le_seminorm (k n : ℕ) (f : 𝓢(E, F)) (x : E) :
‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ SchwartzMap.seminorm 𝕜 k n f :=
f.le_seminormAux k n x
/-- The seminorm controls the Schwartz estimate for any fixed `x`.
Variant for functions `𝓢(ℝ, F)`. -/
theorem le_seminorm' (k n : ℕ) (f : 𝓢(ℝ, F)) (x : ℝ) :
|x| ^ k * ‖iteratedDeriv n f x‖ ≤ SchwartzMap.seminorm 𝕜 k n f := by
have := le_seminorm 𝕜 k n f x
rwa [← Real.norm_eq_abs, ← norm_iteratedFDeriv_eq_norm_iteratedDeriv]
theorem norm_iteratedFDeriv_le_seminorm (f : 𝓢(E, F)) (n : ℕ) (x₀ : E) :
‖iteratedFDeriv ℝ n f x₀‖ ≤ (SchwartzMap.seminorm 𝕜 0 n) f := by
have := SchwartzMap.le_seminorm 𝕜 0 n f x₀
rwa [pow_zero, one_mul] at this
theorem norm_pow_mul_le_seminorm (f : 𝓢(E, F)) (k : ℕ) (x₀ : E) :
‖x₀‖ ^ k * ‖f x₀‖ ≤ (SchwartzMap.seminorm 𝕜 k 0) f := by
have := SchwartzMap.le_seminorm 𝕜 k 0 f x₀
rwa [norm_iteratedFDeriv_zero] at this
theorem norm_le_seminorm (f : 𝓢(E, F)) (x₀ : E) : ‖f x₀‖ ≤ (SchwartzMap.seminorm 𝕜 0 0) f := by
have := norm_pow_mul_le_seminorm 𝕜 f 0 x₀
rwa [pow_zero, one_mul] at this
variable (E F)
/-- The family of Schwartz seminorms. -/
def _root_.schwartzSeminormFamily : SeminormFamily 𝕜 𝓢(E, F) (ℕ × ℕ) :=
fun m => SchwartzMap.seminorm 𝕜 m.1 m.2
@[simp]
theorem schwartzSeminormFamily_apply (n k : ℕ) :
schwartzSeminormFamily 𝕜 E F (n, k) = SchwartzMap.seminorm 𝕜 n k :=
rfl
@[simp]
theorem schwartzSeminormFamily_apply_zero :
schwartzSeminormFamily 𝕜 E F 0 = SchwartzMap.seminorm 𝕜 0 0 :=
rfl
variable {𝕜 E F}
/-- A more convenient version of `le_sup_seminorm_apply`.
The set `Finset.Iic m` is the set of all pairs `(k', n')` with `k' ≤ m.1` and `n' ≤ m.2`.
Note that the constant is far from optimal. -/
theorem one_add_le_sup_seminorm_apply {m : ℕ × ℕ} {k n : ℕ} (hk : k ≤ m.1) (hn : n ≤ m.2)
(f : 𝓢(E, F)) (x : E) :
(1 + ‖x‖) ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤
2 ^ m.1 * (Finset.Iic m).sup (fun m => SchwartzMap.seminorm 𝕜 m.1 m.2) f := by
rw [add_comm, add_pow]
simp only [one_pow, mul_one, Finset.sum_congr, Finset.sum_mul]
norm_cast
rw [← Nat.sum_range_choose m.1]
push_cast
rw [Finset.sum_mul]
have hk' : Finset.range (k + 1) ⊆ Finset.range (m.1 + 1) := by
rwa [Finset.range_subset, add_le_add_iff_right]
refine le_trans (Finset.sum_le_sum_of_subset_of_nonneg hk' fun _ _ _ => by positivity) ?_
gcongr ∑ _i ∈ Finset.range (m.1 + 1), ?_ with i hi
move_mul [(Nat.choose k i : ℝ), (Nat.choose m.1 i : ℝ)]
gcongr
· apply (le_seminorm 𝕜 i n f x).trans
apply Seminorm.le_def.1
exact Finset.le_sup_of_le (Finset.mem_Iic.2 <|
Prod.mk_le_mk.2 ⟨Finset.mem_range_succ_iff.mp hi, hn⟩) le_rfl
· exact mod_cast Nat.choose_le_choose i hk
end Seminorms
section Topology
/-! ### The topology on the Schwartz space -/
variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
variable (𝕜 E F)
instance instTopologicalSpace : TopologicalSpace 𝓢(E, F) :=
(schwartzSeminormFamily ℝ E F).moduleFilterBasis.topology'
theorem _root_.schwartz_withSeminorms : WithSeminorms (schwartzSeminormFamily 𝕜 E F) := by
have A : WithSeminorms (schwartzSeminormFamily ℝ E F) := ⟨rfl⟩
rw [SeminormFamily.withSeminorms_iff_nhds_eq_iInf] at A ⊢
rw [A]
rfl
variable {𝕜 E F}
instance instContinuousSMul : ContinuousSMul 𝕜 𝓢(E, F) := by
rw [(schwartz_withSeminorms 𝕜 E F).withSeminorms_eq]
exact (schwartzSeminormFamily 𝕜 E F).moduleFilterBasis.continuousSMul
instance instIsTopologicalAddGroup : IsTopologicalAddGroup 𝓢(E, F) :=
(schwartzSeminormFamily ℝ E F).addGroupFilterBasis.isTopologicalAddGroup
instance instUniformSpace : UniformSpace 𝓢(E, F) :=
(schwartzSeminormFamily ℝ E F).addGroupFilterBasis.uniformSpace
instance instIsUniformAddGroup : IsUniformAddGroup 𝓢(E, F) :=
(schwartzSeminormFamily ℝ E F).addGroupFilterBasis.isUniformAddGroup
@[deprecated (since := "2025-03-31")] alias instUniformAddGroup :=
SchwartzMap.instIsUniformAddGroup
instance instLocallyConvexSpace : LocallyConvexSpace ℝ 𝓢(E, F) :=
(schwartz_withSeminorms ℝ E F).toLocallyConvexSpace
instance instFirstCountableTopology : FirstCountableTopology 𝓢(E, F) :=
(schwartz_withSeminorms ℝ E F).firstCountableTopology
end Topology
section TemperateGrowth
/-! ### Functions of temperate growth -/
/-- A function is called of temperate growth if it is smooth and all iterated derivatives are
polynomially bounded. -/
def _root_.Function.HasTemperateGrowth (f : E → F) : Prop :=
ContDiff ℝ ∞ f ∧ ∀ n : ℕ, ∃ (k : ℕ) (C : ℝ), ∀ x, ‖iteratedFDeriv ℝ n f x‖ ≤ C * (1 + ‖x‖) ^ k
theorem _root_.Function.HasTemperateGrowth.norm_iteratedFDeriv_le_uniform_aux {f : E → F}
(hf_temperate : f.HasTemperateGrowth) (n : ℕ) :
∃ (k : ℕ) (C : ℝ), 0 ≤ C ∧ ∀ N ≤ n, ∀ x : E, ‖iteratedFDeriv ℝ N f x‖ ≤ C * (1 + ‖x‖) ^ k := by
choose k C f using hf_temperate.2
use (Finset.range (n + 1)).sup k
let C' := max (0 : ℝ) ((Finset.range (n + 1)).sup' (by simp) C)
have hC' : 0 ≤ C' := by simp only [C', le_refl, Finset.le_sup'_iff, true_or, le_max_iff]
use C', hC'
intro N hN x
rw [← Finset.mem_range_succ_iff] at hN
refine le_trans (f N x) (mul_le_mul ?_ ?_ (by positivity) hC')
· simp only [C', Finset.le_sup'_iff, le_max_iff]
right
exact ⟨N, hN, rfl.le⟩
gcongr
· simp
exact Finset.le_sup hN
lemma _root_.Function.HasTemperateGrowth.of_fderiv {f : E → F}
(h'f : Function.HasTemperateGrowth (fderiv ℝ f)) (hf : Differentiable ℝ f) {k : ℕ} {C : ℝ}
(h : ∀ x, ‖f x‖ ≤ C * (1 + ‖x‖) ^ k) :
Function.HasTemperateGrowth f := by
refine ⟨contDiff_succ_iff_fderiv.2 ⟨hf, by simp, h'f.1⟩ , fun n ↦ ?_⟩
rcases n with rfl|m
· exact ⟨k, C, fun x ↦ by simpa using h x⟩
· rcases h'f.2 m with ⟨k', C', h'⟩
refine ⟨k', C', ?_⟩
simpa [iteratedFDeriv_succ_eq_comp_right] using h'
lemma _root_.Function.HasTemperateGrowth.zero :
Function.HasTemperateGrowth (fun _ : E ↦ (0 : F)) := by
refine ⟨contDiff_const, fun n ↦ ⟨0, 0, fun x ↦ ?_⟩⟩
simp only [iteratedFDeriv_zero_fun, Pi.zero_apply, norm_zero, forall_const]
positivity
lemma _root_.Function.HasTemperateGrowth.const (c : F) :
Function.HasTemperateGrowth (fun _ : E ↦ c) :=
.of_fderiv (by simpa using .zero) (differentiable_const c) (k := 0) (C := ‖c‖) (fun x ↦ by simp)
lemma _root_.ContinuousLinearMap.hasTemperateGrowth (f : E →L[ℝ] F) :
Function.HasTemperateGrowth f := by
apply Function.HasTemperateGrowth.of_fderiv ?_ f.differentiable (k := 1) (C := ‖f‖) (fun x ↦ ?_)
· have : fderiv ℝ f = fun _ ↦ f := by ext1 v; simp only [ContinuousLinearMap.fderiv]
simpa [this] using .const _
· exact (f.le_opNorm x).trans (by simp [mul_add])
variable [NormedAddCommGroup D] [MeasurableSpace D]
open MeasureTheory Module
open scoped ENNReal
/-- A measure `μ` has temperate growth if there is an `n : ℕ` such that `(1 + ‖x‖) ^ (- n)` is
`μ`-integrable. -/
class _root_.MeasureTheory.Measure.HasTemperateGrowth (μ : Measure D) : Prop where
exists_integrable : ∃ (n : ℕ), Integrable (fun x ↦ (1 + ‖x‖) ^ (- (n : ℝ))) μ
open Classical in
/-- An integer exponent `l` such that `(1 + ‖x‖) ^ (-l)` is integrable if `μ` has
temperate growth. -/
def _root_.MeasureTheory.Measure.integrablePower (μ : Measure D) : ℕ :=
if h : μ.HasTemperateGrowth then h.exists_integrable.choose else 0
lemma integrable_pow_neg_integrablePower
(μ : Measure D) [h : μ.HasTemperateGrowth] :
Integrable (fun x ↦ (1 + ‖x‖) ^ (- (μ.integrablePower : ℝ))) μ := by
simpa [Measure.integrablePower, h] using h.exists_integrable.choose_spec
instance _root_.MeasureTheory.Measure.IsFiniteMeasure.instHasTemperateGrowth {μ : Measure D}
[h : IsFiniteMeasure μ] : μ.HasTemperateGrowth := ⟨⟨0, by simp⟩⟩
variable [NormedSpace ℝ D] [FiniteDimensional ℝ D] [BorelSpace D] in
instance _root_.MeasureTheory.Measure.IsAddHaarMeasure.instHasTemperateGrowth {μ : Measure D}
[h : μ.IsAddHaarMeasure] : μ.HasTemperateGrowth :=
⟨⟨finrank ℝ D + 1, by apply integrable_one_add_norm; norm_num⟩⟩
/-- Pointwise inequality to control `x ^ k * f` in terms of `1 / (1 + x) ^ l` if one controls both
`f` (with a bound `C₁`) and `x ^ (k + l) * f` (with a bound `C₂`). This will be used to check
integrability of `x ^ k * f x` when `f` is a Schwartz function, and to control explicitly its
integral in terms of suitable seminorms of `f`. -/
lemma pow_mul_le_of_le_of_pow_mul_le {C₁ C₂ : ℝ} {k l : ℕ} {x f : ℝ} (hx : 0 ≤ x) (hf : 0 ≤ f)
(h₁ : f ≤ C₁) (h₂ : x ^ (k + l) * f ≤ C₂) :
x ^ k * f ≤ 2 ^ l * (C₁ + C₂) * (1 + x) ^ (- (l : ℝ)) := by
have : 0 ≤ C₂ := le_trans (by positivity) h₂
have : 2 ^ l * (C₁ + C₂) * (1 + x) ^ (- (l : ℝ)) = ((1 + x) / 2) ^ (-(l : ℝ)) * (C₁ + C₂) := by
rw [Real.div_rpow (by linarith) zero_le_two]
simp [div_eq_inv_mul, ← Real.rpow_neg_one, ← Real.rpow_mul]
ring
rw [this]
rcases le_total x 1 with h'x|h'x
· gcongr
· apply (pow_le_one₀ hx h'x).trans
apply Real.one_le_rpow_of_pos_of_le_one_of_nonpos
· linarith
· linarith
· simp
· linarith
· calc
x ^ k * f = x ^ (-(l : ℝ)) * (x ^ (k + l) * f) := by
rw [← Real.rpow_natCast, ← Real.rpow_natCast, ← mul_assoc, ← Real.rpow_add (by linarith)]
simp
_ ≤ ((1 + x) / 2) ^ (-(l : ℝ)) * (C₁ + C₂) := by
apply mul_le_mul _ _ (by positivity) (by positivity)
· exact Real.rpow_le_rpow_of_nonpos (by linarith) (by linarith) (by simp)
· exact h₂.trans (by linarith)
variable [BorelSpace D] [SecondCountableTopology D] in
/-- Given a function such that `f` and `x ^ (k + l) * f` are bounded for a suitable `l`, then
`x ^ k * f` is integrable. The bounds are not relevant for the integrability conclusion, but they
are relevant for bounding the integral in `integral_pow_mul_le_of_le_of_pow_mul_le`. We formulate
the two lemmas with the same set of assumptions for ease of applications. -/
-- We redeclare `E` here to avoid the `NormedSpace ℝ E` typeclass available throughout this file.
lemma integrable_of_le_of_pow_mul_le
{E : Type*} [NormedAddCommGroup E]
{μ : Measure D} [μ.HasTemperateGrowth] {f : D → E} {C₁ C₂ : ℝ} {k : ℕ}
(hf : ∀ x, ‖f x‖ ≤ C₁) (h'f : ∀ x, ‖x‖ ^ (k + μ.integrablePower) * ‖f x‖ ≤ C₂)
(h''f : AEStronglyMeasurable f μ) :
Integrable (fun x ↦ ‖x‖ ^ k * ‖f x‖) μ := by
apply ((integrable_pow_neg_integrablePower μ).const_mul (2 ^ μ.integrablePower * (C₁ + C₂))).mono'
· exact AEStronglyMeasurable.mul (aestronglyMeasurable_id.norm.pow _) h''f.norm
· filter_upwards with v
simp only [norm_mul, norm_pow, norm_norm]
apply pow_mul_le_of_le_of_pow_mul_le (norm_nonneg _) (norm_nonneg _) (hf v) (h'f v)
/-- Given a function such that `f` and `x ^ (k + l) * f` are bounded for a suitable `l`, then
one can bound explicitly the integral of `x ^ k * f`. -/
-- We redeclare `E` here to avoid the `NormedSpace ℝ E` typeclass available throughout this file.
lemma integral_pow_mul_le_of_le_of_pow_mul_le
{E : Type*} [NormedAddCommGroup E]
{μ : Measure D} [μ.HasTemperateGrowth] {f : D → E} {C₁ C₂ : ℝ} {k : ℕ}
(hf : ∀ x, ‖f x‖ ≤ C₁) (h'f : ∀ x, ‖x‖ ^ (k + μ.integrablePower) * ‖f x‖ ≤ C₂) :
∫ x, ‖x‖ ^ k * ‖f x‖ ∂μ ≤ 2 ^ μ.integrablePower *
(∫ x, (1 + ‖x‖) ^ (- (μ.integrablePower : ℝ)) ∂μ) * (C₁ + C₂) := by
rw [← integral_const_mul, ← integral_mul_const]
apply integral_mono_of_nonneg
· filter_upwards with v using by positivity
· exact ((integrable_pow_neg_integrablePower μ).const_mul _).mul_const _
filter_upwards with v
exact (pow_mul_le_of_le_of_pow_mul_le (norm_nonneg _) (norm_nonneg _) (hf v) (h'f v)).trans
(le_of_eq (by ring))
/-- For any `HasTemperateGrowth` measure and `p`, there exists an integer power `k` such that
`(1 + ‖x‖) ^ (-k)` is in `L^p`. -/
theorem _root_.MeasureTheory.Measure.HasTemperateGrowth.exists_eLpNorm_lt_top (p : ℝ≥0∞)
{μ : Measure D} (hμ : μ.HasTemperateGrowth) :
∃ k : ℕ, eLpNorm (fun x ↦ (1 + ‖x‖) ^ (-k : ℝ)) p μ < ⊤ := by
cases p with
| top => exact ⟨0, eLpNormEssSup_lt_top_of_ae_bound (C := 1) (by simp)⟩
| coe p =>
cases eq_or_ne (p : ℝ≥0∞) 0 with
| inl hp => exact ⟨0, by simp [hp]⟩
| inr hp =>
have h_one_add (x : D) : 0 < 1 + ‖x‖ := lt_add_of_pos_of_le zero_lt_one (norm_nonneg x)
have hp_pos : 0 < (p : ℝ) := by simpa [zero_lt_iff] using hp
rcases hμ.exists_integrable with ⟨l, hl⟩
let k := ⌈(l / p : ℝ)⌉₊
have hlk : l ≤ k * (p : ℝ) := by simpa [div_le_iff₀ hp_pos] using Nat.le_ceil (l / p : ℝ)
use k
suffices HasFiniteIntegral (fun x ↦ ((1 + ‖x‖) ^ (-(k * p) : ℝ))) μ by
rw [hasFiniteIntegral_iff_enorm] at this
rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top hp ENNReal.coe_ne_top]
simp only [ENNReal.coe_toReal]
refine Eq.subst (motive := (∫⁻ x, · x ∂μ < ⊤)) (funext fun x ↦ ?_) this
rw [← neg_mul, Real.rpow_mul (h_one_add x).le]
exact Real.enorm_rpow_of_nonneg (Real.rpow_nonneg (h_one_add x).le _) NNReal.zero_le_coe
refine hl.hasFiniteIntegral.mono' (ae_of_all μ fun x ↦ ?_)
rw [Real.norm_of_nonneg (Real.rpow_nonneg (h_one_add x).le _)]
gcongr
simp
end TemperateGrowth
section CLM
/-! ### Construction of continuous linear maps between Schwartz spaces -/
variable [NormedField 𝕜] [NormedField 𝕜']
variable [NormedAddCommGroup D] [NormedSpace ℝ D]
variable [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E]
variable [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedSpace 𝕜' G] [SMulCommClass ℝ 𝕜' G]
variable {σ : 𝕜 →+* 𝕜'}
/-- Create a semilinear map between Schwartz spaces.
Note: This is a helper definition for `mkCLM`. -/
def mkLM (A : (D → E) → F → G) (hadd : ∀ (f g : 𝓢(D, E)) (x), A (f + g) x = A f x + A g x)
(hsmul : ∀ (a : 𝕜) (f : 𝓢(D, E)) (x), A (a • f) x = σ a • A f x)
(hsmooth : ∀ f : 𝓢(D, E), ContDiff ℝ ∞ (A f))
(hbound : ∀ n : ℕ × ℕ, ∃ (s : Finset (ℕ × ℕ)) (C : ℝ), 0 ≤ C ∧ ∀ (f : 𝓢(D, E)) (x : F),
‖x‖ ^ n.fst * ‖iteratedFDeriv ℝ n.snd (A f) x‖ ≤ C * s.sup (schwartzSeminormFamily 𝕜 D E) f) :
𝓢(D, E) →ₛₗ[σ] 𝓢(F, G) where
toFun f :=
{ toFun := A f
smooth' := hsmooth f
decay' := by
intro k n
rcases hbound ⟨k, n⟩ with ⟨s, C, _, h⟩
exact ⟨C * (s.sup (schwartzSeminormFamily 𝕜 D E)) f, h f⟩ }
map_add' f g := ext (hadd f g)
map_smul' a f := ext (hsmul a f)
/-- Create a continuous semilinear map between Schwartz spaces.
For an example of using this definition, see `fderivCLM`. -/
def mkCLM [RingHomIsometric σ] (A : (D → E) → F → G)
(hadd : ∀ (f g : 𝓢(D, E)) (x), A (f + g) x = A f x + A g x)
(hsmul : ∀ (a : 𝕜) (f : 𝓢(D, E)) (x), A (a • f) x = σ a • A f x)
(hsmooth : ∀ f : 𝓢(D, E), ContDiff ℝ ∞ (A f))
(hbound : ∀ n : ℕ × ℕ, ∃ (s : Finset (ℕ × ℕ)) (C : ℝ), 0 ≤ C ∧ ∀ (f : 𝓢(D, E)) (x : F),
‖x‖ ^ n.fst * ‖iteratedFDeriv ℝ n.snd (A f) x‖ ≤ C * s.sup (schwartzSeminormFamily 𝕜 D E) f) :
𝓢(D, E) →SL[σ] 𝓢(F, G) where
cont := by
change Continuous (mkLM A hadd hsmul hsmooth hbound : 𝓢(D, E) →ₛₗ[σ] 𝓢(F, G))
refine
Seminorm.continuous_from_bounded (schwartz_withSeminorms 𝕜 D E)
(schwartz_withSeminorms 𝕜' F G) _ fun n => ?_
rcases hbound n with ⟨s, C, hC, h⟩
refine ⟨s, ⟨C, hC⟩, fun f => ?_⟩
exact (mkLM A hadd hsmul hsmooth hbound f).seminorm_le_bound 𝕜' n.1 n.2 (by positivity) (h f)
toLinearMap := mkLM A hadd hsmul hsmooth hbound
/-- Define a continuous semilinear map from Schwartz space to a normed space. -/
def mkCLMtoNormedSpace [RingHomIsometric σ] (A : 𝓢(D, E) → G)
(hadd : ∀ (f g : 𝓢(D, E)), A (f + g) = A f + A g)
(hsmul : ∀ (a : 𝕜) (f : 𝓢(D, E)), A (a • f) = σ a • A f)
(hbound : ∃ (s : Finset (ℕ × ℕ)) (C : ℝ), 0 ≤ C ∧ ∀ (f : 𝓢(D, E)),
‖A f‖ ≤ C * s.sup (schwartzSeminormFamily 𝕜 D E) f) :
𝓢(D, E) →SL[σ] G :=
letI f : 𝓢(D, E) →ₛₗ[σ] G :=
{ toFun := (A ·)
map_add' := hadd
map_smul' := hsmul }
{ toLinearMap := f
cont := by
change Continuous (LinearMap.mk _ _)
apply Seminorm.cont_withSeminorms_normedSpace G (schwartz_withSeminorms 𝕜 D E)
rcases hbound with ⟨s, C, hC, h⟩
exact ⟨s, ⟨C, hC⟩, h⟩ }
end CLM
section EvalCLM
variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
/-- The map applying a vector to Hom-valued Schwartz function as a continuous linear map. -/
protected def evalCLM (m : E) : 𝓢(E, E →L[ℝ] F) →L[𝕜] 𝓢(E, F) :=
mkCLM (fun f x => f x m) (fun _ _ _ => rfl) (fun _ _ _ => rfl)
(fun f => ContDiff.clm_apply f.2 contDiff_const) <| by
rintro ⟨k, n⟩
use {(k, n)}, ‖m‖, norm_nonneg _
intro f x
simp only [Finset.sup_singleton, schwartzSeminormFamily_apply]
calc
‖x‖ ^ k * ‖iteratedFDeriv ℝ n (f · m) x‖ ≤ ‖x‖ ^ k * (‖m‖ * ‖iteratedFDeriv ℝ n f x‖) := by
gcongr
exact norm_iteratedFDeriv_clm_apply_const (f.smooth _).contDiffAt le_rfl
_ ≤ ‖m‖ * SchwartzMap.seminorm 𝕜 k n f := by
move_mul [‖m‖]
gcongr
apply le_seminorm
end EvalCLM
section Multiplication
variable [NontriviallyNormedField 𝕜] [NormedAlgebra ℝ 𝕜]
[NormedAddCommGroup D] [NormedSpace ℝ D]
[NormedAddCommGroup G] [NormedSpace ℝ G]
[NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [NormedSpace 𝕜 G]
/-- The map `f ↦ (x ↦ B (f x) (g x))` as a continuous `𝕜`-linear map on Schwartz space,
where `B` is a continuous `𝕜`-linear map and `g` is a function of temperate growth. -/
def bilinLeftCLM (B : E →L[𝕜] F →L[𝕜] G) {g : D → F} (hg : g.HasTemperateGrowth) :
𝓢(D, E) →L[𝕜] 𝓢(D, G) := by
refine mkCLM (fun f x => B (f x) (g x))
(fun _ _ _ => by
simp only [map_add, add_left_inj, Pi.add_apply, eq_self_iff_true,
ContinuousLinearMap.add_apply])
(fun _ _ _ => by
simp only [smul_apply, map_smul, ContinuousLinearMap.coe_smul', Pi.smul_apply,
RingHom.id_apply])
(fun f => (B.bilinearRestrictScalars ℝ).isBoundedBilinearMap.contDiff.comp
(f.smooth'.prodMk hg.1)) ?_
rintro ⟨k, n⟩
rcases hg.norm_iteratedFDeriv_le_uniform_aux n with ⟨l, C, hC, hgrowth⟩
use
Finset.Iic (l + k, n), ‖B‖ * ((n : ℝ) + (1 : ℝ)) * n.choose (n / 2) * (C * 2 ^ (l + k)),
by positivity
intro f x
have hxk : 0 ≤ ‖x‖ ^ k := by positivity
simp_rw [← ContinuousLinearMap.bilinearRestrictScalars_apply_apply ℝ B]
have hnorm_mul :=
ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear (B.bilinearRestrictScalars ℝ)
f.smooth' hg.1 x (n := n) (mod_cast le_top)
refine le_trans (mul_le_mul_of_nonneg_left hnorm_mul hxk) ?_
rw [ContinuousLinearMap.norm_bilinearRestrictScalars]
move_mul [← ‖B‖]
simp_rw [mul_assoc ‖B‖]
gcongr _ * ?_
rw [Finset.mul_sum]
have : (∑ _x ∈ Finset.range (n + 1), (1 : ℝ)) = n + 1 := by simp
simp_rw [mul_assoc ((n : ℝ) + 1)]
rw [← this, Finset.sum_mul]
refine Finset.sum_le_sum fun i hi => ?_
simp only [one_mul]
move_mul [(Nat.choose n i : ℝ), (Nat.choose n (n / 2) : ℝ)]
gcongr ?_ * ?_
swap
· norm_cast
exact i.choose_le_middle n
specialize hgrowth (n - i) (by simp only [tsub_le_self]) x
refine le_trans (mul_le_mul_of_nonneg_left hgrowth (by positivity)) ?_
move_mul [C]
gcongr ?_ * C
rw [Finset.mem_range_succ_iff] at hi
change i ≤ (l + k, n).snd at hi
refine le_trans ?_ (one_add_le_sup_seminorm_apply le_rfl hi f x)
rw [pow_add]
move_mul [(1 + ‖x‖) ^ l]
gcongr
simp
end Multiplication
section Comp
variable (𝕜)
variable [RCLike 𝕜]
variable [NormedAddCommGroup D] [NormedSpace ℝ D]
variable [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
/-- Composition with a function on the right is a continuous linear map on Schwartz space
provided that the function is temperate and growths polynomially near infinity. -/
def compCLM {g : D → E} (hg : g.HasTemperateGrowth)
(hg_upper : ∃ (k : ℕ) (C : ℝ), ∀ x, ‖x‖ ≤ C * (1 + ‖g x‖) ^ k) : 𝓢(E, F) →L[𝕜] 𝓢(D, F) := by
refine mkCLM (fun f x => f (g x))
(fun _ _ _ => by simp only [add_left_inj, Pi.add_apply, eq_self_iff_true]) (fun _ _ _ => rfl)
(fun f => f.smooth'.comp hg.1) ?_
rintro ⟨k, n⟩
rcases hg.norm_iteratedFDeriv_le_uniform_aux n with ⟨l, C, hC, hgrowth⟩
rcases hg_upper with ⟨kg, Cg, hg_upper'⟩
have hCg : 1 ≤ 1 + Cg := by
refine le_add_of_nonneg_right ?_
specialize hg_upper' 0
rw [norm_zero] at hg_upper'
exact nonneg_of_mul_nonneg_left hg_upper' (by positivity)
let k' := kg * (k + l * n)
use Finset.Iic (k', n), (1 + Cg) ^ (k + l * n) * ((C + 1) ^ n * n ! * 2 ^ k'), by positivity
intro f x
let seminorm_f := ((Finset.Iic (k', n)).sup (schwartzSeminormFamily 𝕜 _ _)) f
have hg_upper'' : (1 + ‖x‖) ^ (k + l * n) ≤ (1 + Cg) ^ (k + l * n) * (1 + ‖g x‖) ^ k' := by
rw [pow_mul, ← mul_pow]
gcongr
rw [add_mul]
refine add_le_add ?_ (hg_upper' x)
nth_rw 1 [← one_mul (1 : ℝ)]
gcongr
apply one_le_pow₀
simp only [le_add_iff_nonneg_right, norm_nonneg]
have hbound :
∀ i, i ≤ n → ‖iteratedFDeriv ℝ i f (g x)‖ ≤ 2 ^ k' * seminorm_f / (1 + ‖g x‖) ^ k' := by
intro i hi
have hpos : 0 < (1 + ‖g x‖) ^ k' := by positivity
rw [le_div_iff₀' hpos]
change i ≤ (k', n).snd at hi
exact one_add_le_sup_seminorm_apply le_rfl hi _ _
have hgrowth' : ∀ N : ℕ, 1 ≤ N → N ≤ n →
‖iteratedFDeriv ℝ N g x‖ ≤ ((C + 1) * (1 + ‖x‖) ^ l) ^ N := by
intro N hN₁ hN₂
refine (hgrowth N hN₂ x).trans ?_
rw [mul_pow]
have hN₁' := (lt_of_lt_of_le zero_lt_one hN₁).ne'
gcongr
· exact le_trans (by simp [hC]) (le_self_pow₀ (by simp [hC]) hN₁')
· refine le_self_pow₀ (one_le_pow₀ ?_) hN₁'
simp only [le_add_iff_nonneg_right, norm_nonneg]
have := norm_iteratedFDeriv_comp_le f.smooth' hg.1 (mod_cast le_top) x hbound hgrowth'
have hxk : ‖x‖ ^ k ≤ (1 + ‖x‖) ^ k :=
pow_le_pow_left₀ (norm_nonneg _) (by simp only [zero_le_one, le_add_iff_nonneg_left]) _
refine le_trans (mul_le_mul hxk this (by positivity) (by positivity)) ?_
have rearrange :
(1 + ‖x‖) ^ k *
(n ! * (2 ^ k' * seminorm_f / (1 + ‖g x‖) ^ k') * ((C + 1) * (1 + ‖x‖) ^ l) ^ n) =
(1 + ‖x‖) ^ (k + l * n) / (1 + ‖g x‖) ^ k' *
((C + 1) ^ n * n ! * 2 ^ k' * seminorm_f) := by
rw [mul_pow, pow_add, ← pow_mul]
ring
rw [rearrange]
have hgxk' : 0 < (1 + ‖g x‖) ^ k' := by positivity
rw [← div_le_iff₀ hgxk'] at hg_upper''
have hpos : (0 : ℝ) ≤ (C + 1) ^ n * n ! * 2 ^ k' * seminorm_f := by
have : 0 ≤ seminorm_f := apply_nonneg _ _
positivity
refine le_trans (mul_le_mul_of_nonneg_right hg_upper'' hpos) ?_
rw [← mul_assoc]
@[simp] lemma compCLM_apply {g : D → E} (hg : g.HasTemperateGrowth)
(hg_upper : ∃ (k : ℕ) (C : ℝ), ∀ x, ‖x‖ ≤ C * (1 + ‖g x‖) ^ k) (f : 𝓢(E, F)) :
compCLM 𝕜 hg hg_upper f = f ∘ g := rfl
/-- Composition with a function on the right is a continuous linear map on Schwartz space
provided that the function is temperate and antilipschitz. -/
def compCLMOfAntilipschitz {K : ℝ≥0} {g : D → E}
(hg : g.HasTemperateGrowth) (h'g : AntilipschitzWith K g) :
𝓢(E, F) →L[𝕜] 𝓢(D, F) := by
refine compCLM 𝕜 hg ⟨1, K * max 1 ‖g 0‖, fun x ↦ ?_⟩
calc
‖x‖ ≤ K * ‖g x - g 0‖ := by
rw [← dist_zero_right, ← dist_eq_norm]
apply h'g.le_mul_dist
_ ≤ K * (‖g x‖ + ‖g 0‖) := by
gcongr
exact norm_sub_le _ _
_ ≤ K * (‖g x‖ + max 1 ‖g 0‖) := by
gcongr
exact le_max_right _ _
_ ≤ (K * max 1 ‖g 0‖ : ℝ) * (1 + ‖g x‖) ^ 1 := by
simp only [mul_add, add_comm (K * ‖g x‖), pow_one, mul_one, add_le_add_iff_left]
gcongr
exact le_mul_of_one_le_right (by positivity) (le_max_left _ _)
@[simp] lemma compCLMOfAntilipschitz_apply {K : ℝ≥0} {g : D → E} (hg : g.HasTemperateGrowth)
(h'g : AntilipschitzWith K g) (f : 𝓢(E, F)) :
compCLMOfAntilipschitz 𝕜 hg h'g f = f ∘ g := rfl
/-- Composition with a continuous linear equiv on the right is a continuous linear map on
Schwartz space. -/
def compCLMOfContinuousLinearEquiv (g : D ≃L[ℝ] E) :
𝓢(E, F) →L[𝕜] 𝓢(D, F) :=
compCLMOfAntilipschitz 𝕜 (g.toContinuousLinearMap.hasTemperateGrowth) g.antilipschitz
@[simp] lemma compCLMOfContinuousLinearEquiv_apply (g : D ≃L[ℝ] E) (f : 𝓢(E, F)) :
compCLMOfContinuousLinearEquiv 𝕜 g f = f ∘ g := rfl
end Comp
section Derivatives
/-! ### Derivatives of Schwartz functions -/
variable (𝕜)
variable [RCLike 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F]
/-- The Fréchet derivative on Schwartz space as a continuous `𝕜`-linear map. -/
def fderivCLM : 𝓢(E, F) →L[𝕜] 𝓢(E, E →L[ℝ] F) :=
mkCLM (fderiv ℝ) (fun f g _ => fderiv_add f.differentiableAt g.differentiableAt)
(fun a f _ => fderiv_const_smul f.differentiableAt a)
(fun f => (contDiff_succ_iff_fderiv.mp f.smooth').2.2) fun ⟨k, n⟩ =>
⟨{⟨k, n + 1⟩}, 1, zero_le_one, fun f x => by
simpa only [schwartzSeminormFamily_apply, Seminorm.comp_apply, Finset.sup_singleton,
one_smul, norm_iteratedFDeriv_fderiv, one_mul] using f.le_seminorm 𝕜 k (n + 1) x⟩
@[simp]
theorem fderivCLM_apply (f : 𝓢(E, F)) (x : E) : fderivCLM 𝕜 f x = fderiv ℝ f x :=
rfl
/-- The 1-dimensional derivative on Schwartz space as a continuous `𝕜`-linear map. -/
def derivCLM : 𝓢(ℝ, F) →L[𝕜] 𝓢(ℝ, F) :=
mkCLM deriv (fun f g _ => deriv_add f.differentiableAt g.differentiableAt)
(fun a f _ => deriv_const_smul a f.differentiableAt)
(fun f => (contDiff_succ_iff_deriv.mp f.smooth').2.2) fun ⟨k, n⟩ =>
⟨{⟨k, n + 1⟩}, 1, zero_le_one, fun f x => by
simpa only [Real.norm_eq_abs, Finset.sup_singleton, schwartzSeminormFamily_apply, one_mul,
norm_iteratedFDeriv_eq_norm_iteratedDeriv, ← iteratedDeriv_succ'] using
f.le_seminorm' 𝕜 k (n + 1) x⟩
@[simp]
theorem derivCLM_apply (f : 𝓢(ℝ, F)) (x : ℝ) : derivCLM 𝕜 f x = deriv f x :=
rfl
/-- The partial derivative (or directional derivative) in the direction `m : E` as a
continuous linear map on Schwartz space. -/
def pderivCLM (m : E) : 𝓢(E, F) →L[𝕜] 𝓢(E, F) :=
(SchwartzMap.evalCLM m).comp (fderivCLM 𝕜)
@[simp]
theorem pderivCLM_apply (m : E) (f : 𝓢(E, F)) (x : E) : pderivCLM 𝕜 m f x = fderiv ℝ f x m :=
rfl
theorem pderivCLM_eq_lineDeriv (m : E) (f : 𝓢(E, F)) (x : E) :
pderivCLM 𝕜 m f x = lineDeriv ℝ f x m := by
simp only [pderivCLM_apply, f.differentiableAt.lineDeriv_eq_fderiv]
/-- The iterated partial derivative (or directional derivative) as a continuous linear map on
Schwartz space. -/
def iteratedPDeriv {n : ℕ} : (Fin n → E) → 𝓢(E, F) →L[𝕜] 𝓢(E, F) :=
Nat.recOn n (fun _ => ContinuousLinearMap.id 𝕜 _) fun _ rec x =>
(pderivCLM 𝕜 (x 0)).comp (rec (Fin.tail x))
@[simp]
theorem iteratedPDeriv_zero (m : Fin 0 → E) (f : 𝓢(E, F)) : iteratedPDeriv 𝕜 m f = f :=
rfl
@[simp]
theorem iteratedPDeriv_one (m : Fin 1 → E) (f : 𝓢(E, F)) :
iteratedPDeriv 𝕜 m f = pderivCLM 𝕜 (m 0) f :=
rfl
theorem iteratedPDeriv_succ_left {n : ℕ} (m : Fin (n + 1) → E) (f : 𝓢(E, F)) :
iteratedPDeriv 𝕜 m f = pderivCLM 𝕜 (m 0) (iteratedPDeriv 𝕜 (Fin.tail m) f) :=
rfl
theorem iteratedPDeriv_succ_right {n : ℕ} (m : Fin (n + 1) → E) (f : 𝓢(E, F)) :
iteratedPDeriv 𝕜 m f = iteratedPDeriv 𝕜 (Fin.init m) (pderivCLM 𝕜 (m (Fin.last n)) f) := by
induction n with
| zero =>
rw [iteratedPDeriv_zero, iteratedPDeriv_one]
rfl
-- The proof is `∂^{n + 2} = ∂ ∂^{n + 1} = ∂ ∂^n ∂ = ∂^{n+1} ∂`
| succ n IH =>
have hmzero : Fin.init m 0 = m 0 := by simp only [Fin.init_def, Fin.castSucc_zero]
have hmtail : Fin.tail m (Fin.last n) = m (Fin.last n.succ) := by
simp only [Fin.tail_def, Fin.succ_last]
calc
_ = pderivCLM 𝕜 (m 0) (iteratedPDeriv 𝕜 _ f) := iteratedPDeriv_succ_left _ _ _
_ = pderivCLM 𝕜 (m 0) ((iteratedPDeriv 𝕜 _) ((pderivCLM 𝕜 _) f)) := by
congr 1
exact IH _
_ = _ := by
simp only [hmtail, iteratedPDeriv_succ_left, hmzero, Fin.tail_init_eq_init_tail]
theorem iteratedPDeriv_eq_iteratedFDeriv {n : ℕ} {m : Fin n → E} {f : 𝓢(E, F)} {x : E} :
iteratedPDeriv 𝕜 m f x = iteratedFDeriv ℝ n f x m := by
induction n generalizing x with
| zero => simp
| succ n ih =>
simp only [iteratedPDeriv_succ_left, iteratedFDeriv_succ_apply_left]
rw [← fderiv_continuousMultilinear_apply_const_apply]
· simp [← ih]
· exact f.smooth'.differentiable_iteratedFDeriv (mod_cast ENat.coe_lt_top n) x
end Derivatives
section Integration
/-! ### Integration -/
open Real Complex Filter MeasureTheory MeasureTheory.Measure Module
variable [RCLike 𝕜]
variable [NormedAddCommGroup D] [NormedSpace ℝ D]
variable [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedSpace 𝕜 V]
variable [MeasurableSpace D]
variable {μ : Measure D} [hμ : HasTemperateGrowth μ]
attribute [local instance 101] secondCountableTopologyEither_of_left
variable (𝕜 μ) in
lemma integral_pow_mul_iteratedFDeriv_le (f : 𝓢(D, V)) (k n : ℕ) :
∫ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ∂μ ≤ 2 ^ μ.integrablePower *
(∫ x, (1 + ‖x‖) ^ (- (μ.integrablePower : ℝ)) ∂μ) *
(SchwartzMap.seminorm 𝕜 0 n f + SchwartzMap.seminorm 𝕜 (k + μ.integrablePower) n f) :=
integral_pow_mul_le_of_le_of_pow_mul_le (norm_iteratedFDeriv_le_seminorm ℝ _ _)
(le_seminorm ℝ _ _ _)
variable [BorelSpace D] [SecondCountableTopology D]
variable (μ) in
lemma integrable_pow_mul_iteratedFDeriv
(f : 𝓢(D, V))
(k n : ℕ) : Integrable (fun x ↦ ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖) μ :=
integrable_of_le_of_pow_mul_le (norm_iteratedFDeriv_le_seminorm ℝ _ _) (le_seminorm ℝ _ _ _)
((f.smooth ⊤).continuous_iteratedFDeriv (mod_cast le_top)).aestronglyMeasurable
variable (μ) in
lemma integrable_pow_mul (f : 𝓢(D, V))
(k : ℕ) : Integrable (fun x ↦ ‖x‖ ^ k * ‖f x‖) μ := by
convert integrable_pow_mul_iteratedFDeriv μ f k 0 with x
simp
lemma integrable (f : 𝓢(D, V)) : Integrable f μ :=
(f.integrable_pow_mul μ 0).mono f.continuous.aestronglyMeasurable
(Eventually.of_forall (fun _ ↦ by simp))
variable (𝕜 μ) in
/-- The integral as a continuous linear map from Schwartz space to the codomain. -/
def integralCLM : 𝓢(D, V) →L[𝕜] V := by
refine mkCLMtoNormedSpace (∫ x, · x ∂μ)
(fun f g ↦ integral_add f.integrable g.integrable) (integral_smul · ·) ?_
rcases hμ.exists_integrable with ⟨n, h⟩
let m := (n, 0)
use Finset.Iic m, 2 ^ n * ∫ x : D, (1 + ‖x‖) ^ (- (n : ℝ)) ∂μ
refine ⟨by positivity, fun f ↦ (norm_integral_le_integral_norm f).trans ?_⟩
have h' : ∀ x, ‖f x‖ ≤ (1 + ‖x‖) ^ (-(n : ℝ)) *
(2 ^ n * ((Finset.Iic m).sup (fun m' => SchwartzMap.seminorm 𝕜 m'.1 m'.2) f)) := by
intro x
rw [rpow_neg (by positivity), ← div_eq_inv_mul, le_div_iff₀' (by positivity), rpow_natCast]
simpa using one_add_le_sup_seminorm_apply (m := m) (k := n) (n := 0) le_rfl le_rfl f x
apply (integral_mono (by simpa using f.integrable_pow_mul μ 0) _ h').trans
· rw [integral_mul_const, ← mul_assoc, mul_comm (2 ^ n)]
rfl
apply h.mul_const
variable (𝕜) in
@[simp]
lemma integralCLM_apply (f : 𝓢(D, V)) : integralCLM 𝕜 μ f = ∫ x, f x ∂μ := by rfl
end Integration
section BoundedContinuousFunction
/-! ### Inclusion into the space of bounded continuous functions -/
open scoped BoundedContinuousFunction
instance instBoundedContinuousMapClass : BoundedContinuousMapClass 𝓢(E, F) E F where
__ := instContinuousMapClass
map_bounded := fun f ↦ ⟨2 * (SchwartzMap.seminorm ℝ 0 0) f,
(BoundedContinuousFunction.dist_le_two_norm' (norm_le_seminorm ℝ f))⟩
/-- Schwartz functions as bounded continuous functions -/
def toBoundedContinuousFunction (f : 𝓢(E, F)) : E →ᵇ F :=
BoundedContinuousFunction.ofNormedAddCommGroup f (SchwartzMap.continuous f)
(SchwartzMap.seminorm ℝ 0 0 f) (norm_le_seminorm ℝ f)
@[simp]
| theorem toBoundedContinuousFunction_apply (f : 𝓢(E, F)) (x : E) :
f.toBoundedContinuousFunction x = f x :=
rfl
| Mathlib/Analysis/Distribution/SchwartzSpace.lean | 1,151 | 1,154 |
/-
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.Abs
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
/-!
# `min` and `max` in linearly ordered groups.
-/
section
variable {α : Type*} [Group α] [LinearOrder α] [MulLeftMono α]
-- TODO: This duplicates `oneLePart_div_leOnePart`
@[to_additive (attr := simp)]
theorem max_one_div_max_inv_one_eq_self (a : α) : max a 1 / max a⁻¹ 1 = a := by
rcases le_total a 1 with (h | h) <;> simp [h]
alias max_zero_sub_eq_self := max_zero_sub_max_neg_zero_eq_self
@[to_additive]
lemma max_inv_one (a : α) : max a⁻¹ 1 = a⁻¹ * max a 1 := by
rw [eq_inv_mul_iff_mul_eq, ← eq_div_iff_mul_eq', max_one_div_max_inv_one_eq_self]
end
section LinearOrderedCommGroup
variable {α : Type*} [CommGroup α] [LinearOrder α] [IsOrderedMonoid α]
@[to_additive min_neg_neg]
theorem min_inv_inv' (a b : α) : min a⁻¹ b⁻¹ = (max a b)⁻¹ :=
Eq.symm <| (@Monotone.map_max α αᵒᵈ _ _ Inv.inv a b) fun _ _ =>
inv_le_inv_iff.mpr
@[to_additive max_neg_neg]
theorem max_inv_inv' (a b : α) : max a⁻¹ b⁻¹ = (min a b)⁻¹ :=
Eq.symm <| (@Monotone.map_min α αᵒᵈ _ _ Inv.inv a b) fun _ _ =>
inv_le_inv_iff.mpr
@[to_additive min_sub_sub_right]
theorem min_div_div_right' (a b c : α) : min (a / c) (b / c) = min a b / c := by
simpa only [div_eq_mul_inv] using min_mul_mul_right a b c⁻¹
@[to_additive max_sub_sub_right]
theorem max_div_div_right' (a b c : α) : max (a / c) (b / c) = max a b / c := by
simpa only [div_eq_mul_inv] using max_mul_mul_right a b c⁻¹
@[to_additive min_sub_sub_left]
theorem min_div_div_left' (a b c : α) : min (a / b) (a / c) = a / max b c := by
simp only [div_eq_mul_inv, min_mul_mul_left, min_inv_inv']
@[to_additive max_sub_sub_left]
theorem max_div_div_left' (a b c : α) : max (a / b) (a / c) = a / min b c := by
simp only [div_eq_mul_inv, max_mul_mul_left, max_inv_inv']
end LinearOrderedCommGroup
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]
theorem max_sub_max_le_max (a b c d : α) : max a b - max c d ≤ max (a - c) (b - d) := by
simp only [sub_le_iff_le_add, max_le_iff]; constructor
· calc
a = a - c + c := (sub_add_cancel a c).symm
_ ≤ max (a - c) (b - d) + max c d := add_le_add (le_max_left _ _) (le_max_left _ _)
· calc
b = b - d + d := (sub_add_cancel b d).symm
_ ≤ max (a - c) (b - d) + max c d := add_le_add (le_max_right _ _) (le_max_right _ _)
theorem abs_max_sub_max_le_max (a b c d : α) : |max a b - max c d| ≤ max |a - c| |b - d| := by
refine abs_sub_le_iff.2 ⟨?_, ?_⟩
· exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _))
· rw [abs_sub_comm a c, abs_sub_comm b d]
exact (max_sub_max_le_max _ _ _ _).trans (max_le_max (le_abs_self _) (le_abs_self _))
theorem abs_min_sub_min_le_max (a b c d : α) : |min a b - min c d| ≤ max |a - c| |b - d| := by
simpa only [max_neg_neg, neg_sub_neg, abs_sub_comm] using
abs_max_sub_max_le_max (-a) (-b) (-c) (-d)
theorem abs_max_sub_max_le_abs (a b c : α) : |max a c - max b c| ≤ |a - b| := by
simpa only [sub_self, abs_zero, max_eq_left (abs_nonneg (a - b))]
using abs_max_sub_max_le_max a c b c
end LinearOrderedAddCommGroup
| Mathlib/Algebra/Order/Group/MinMax.lean | 96 | 100 | |
/-
Copyright (c) 2020 Nicolò Cavalleri. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Patrick Massot, Floris van Doorn
-/
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps
import Mathlib.Topology.FiberBundle.Basic
/-!
# Vector bundles
In this file we define (topological) vector bundles.
Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let
`E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a
topological vector space over `R`.
To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the
following properties:
* The bundle trivializations in the trivialization atlas should be continuous linear equivs in the
fibers;
* For any two trivializations `e`, `e'` in the atlas the transition function considered as a map
from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator
norm topology on `F →L[R] F`.
If these conditions are satisfied, we register the typeclass `VectorBundle R F E`.
We define constructions on vector bundles like pullbacks and direct sums in other files.
## Main Definitions
* `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base
set.
* `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the
(continuous) linear fiberwise equivalences a trivialization induces.
* They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt`
and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined
everywhere, since they are extended using the zero function.
* `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only
makes sense on the intersection of their base sets, but is extended outside it using the identity.
* Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over
possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous
(semi)linear map between the chosen fibers of those bundles.
## Implementation notes
The implementation choices in the vector bundle definition are discussed in the "Implementation
notes" section of `Mathlib.Topology.FiberBundle.Basic`.
## Tags
Vector bundle
-/
noncomputable section
open Bundle Set Topology
variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*)
section TopologicalVectorSpace
variable {F E}
variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B]
/-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
namespace Pretrivialization
variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 :=
Pretrivialization.IsLinear.linear b hb
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A fiberwise linear inverse to `e`. -/
@[simps!]
protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by
refine IsLinearMap.mk' (e.symm b) ?_
by_cases hb : b ∈ e.baseSet
· exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦
congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear
· rw [e.coe_symm_of_not_mem hb]
exact (0 : F →ₗ[R] E b).isLinear
/-- A pretrivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
@[simps -fullyApplied]
def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F where
toFun y := (e ⟨b, y⟩).2
invFun := e.symm b
left_inv := e.symm_apply_apply_mk hb
right_inv v := by simp_rw [e.apply_mk_symm hb v]
map_add' v w := (e.linear R hb).map_add v w
map_smul' c v := (e.linear R hb).map_smul c v
open Classical in
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0
variable {R}
open Classical in
theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [Pretrivialization.linearMapAt]
split_ifs <;> rfl
theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
open Classical in
theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).left_inv y
theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by
rw [e.linearMapAt_def_of_mem hb]
exact (e.linearEquivAt R b hb).right_inv y
end Pretrivialization
variable [TopologicalSpace (TotalSpace F E)]
/-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with
respect to given module structures on its fibers and the model fiber. -/
protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2
namespace Trivialization
variable (e : Trivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b}
protected theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) :
IsLinearMap R fun y : E b => (e ⟨b, y⟩).2 :=
Trivialization.IsLinear.linear b hb
instance toPretrivialization.isLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)]
[∀ x, Module R (E x)] [e.IsLinear R] : e.toPretrivialization.IsLinear R :=
{ (‹_› : e.IsLinear R) with }
variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
/-- A trivialization for a vector bundle defines linear equivalences between the
fibers and the model space. -/
def linearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) :
E b ≃ₗ[R] F :=
e.toPretrivialization.linearEquivAt R b hb
variable {R}
@[simp]
theorem linearEquivAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : E b) : e.linearEquivAt R b hb v = (e ⟨b, v⟩).2 :=
rfl
@[simp]
theorem linearEquivAt_symm_apply (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (v : F) : (e.linearEquivAt R b hb).symm v = e.symm b v :=
rfl
variable (R) in
/-- A fiberwise linear inverse to `e`. -/
protected def symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b :=
e.toPretrivialization.symmₗ R b
theorem coe_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.symmₗ R b) = e.symm b :=
rfl
variable (R) in
/-- A fiberwise linear map equal to `e` on `e.baseSet`. -/
protected def linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F :=
e.toPretrivialization.linearMapAt R b
open Classical in
theorem coe_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) :
⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 :=
e.toPretrivialization.coe_linearMapAt b
theorem coe_linearMapAt_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by
simp_rw [coe_linearMapAt, if_pos hb]
open Classical in
theorem linearMapAt_apply (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) :
e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by
rw [coe_linearMapAt]
theorem linearMapAt_def_of_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb :=
dif_pos hb
theorem linearMapAt_def_of_not_mem (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 :=
dif_neg hb
theorem symmₗ_linearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y :=
e.toPretrivialization.symmₗ_linearMapAt hb y
theorem linearMapAt_symmₗ (e : Trivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet)
(y : F) : e.linearMapAt R b (e.symmₗ R b y) = y :=
e.toPretrivialization.linearMapAt_symmₗ hb y
variable (R) in
open Classical in
/-- A coordinate change function between two trivializations, as a continuous linear equivalence.
Defined to be the identity when `b` does not lie in the base set of both trivializations. -/
def coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] (b : B) :
F ≃L[R] F :=
{ toLinearEquiv := if hb : b ∈ e.baseSet ∩ e'.baseSet
then (e.linearEquivAt R b (hb.1 :)).symm.trans (e'.linearEquivAt R b hb.2)
else LinearEquiv.refl R F
continuous_toFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
refine (e'.continuousOn.comp_continuous ?_ ?_).snd
· exact e.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y =>
mk_mem_prod hb.1 (mem_univ y)
· exact fun y => e'.mem_source.mpr hb.2
· rw [dif_neg hb]
exact continuous_id
continuous_invFun := by
by_cases hb : b ∈ e.baseSet ∩ e'.baseSet
· rw [dif_pos hb]
refine (e.continuousOn.comp_continuous ?_ ?_).snd
· exact e'.continuousOn_symm.comp_continuous (Continuous.prodMk_right b) fun y =>
mk_mem_prod hb.2 (mem_univ y)
exact fun y => e.mem_source.mpr hb.1
· rw [dif_neg hb]
exact continuous_id }
theorem coe_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) :
⇑(coordChangeL R e e' b) = (e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) :=
congr_arg (fun f : F ≃ₗ[R] F ↦ ⇑f) (dif_pos hb)
theorem coe_coordChangeL' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) :
(coordChangeL R e e' b).toLinearEquiv =
(e.linearEquivAt R b hb.1).symm.trans (e'.linearEquivAt R b hb.2) :=
LinearEquiv.coe_injective (coe_coordChangeL _ _ hb)
theorem symm_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e'.baseSet ∩ e.baseSet) : (e.coordChangeL R e' b).symm = e'.coordChangeL R e b := by
apply ContinuousLinearEquiv.toLinearEquiv_injective
rw [coe_coordChangeL' e' e hb, (coordChangeL R e e' b).symm_toLinearEquiv,
coe_coordChangeL' e e' hb.symm, LinearEquiv.trans_symm, LinearEquiv.symm_symm]
theorem coordChangeL_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
coordChangeL R e e' b y = (e' ⟨b, e.symm b y⟩).2 :=
congr_fun (coe_coordChangeL e e' hb) y
theorem mk_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
(b, coordChangeL R e e' b y) = e' ⟨b, e.symm b y⟩ := by
ext
· rw [e.mk_symm hb.1 y, e'.coe_fst', e.proj_symm_apply' hb.1]
rw [e.proj_symm_apply' hb.1]
exact hb.2
· exact e.coordChangeL_apply e' hb y
theorem apply_symm_apply_eq_coordChangeL (e e' : Trivialization F (π F E)) [e.IsLinear R]
[e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) (v : F) :
e' (e.toPartialHomeomorph.symm (b, v)) = (b, e.coordChangeL R e' b v) := by
rw [e.mk_coordChangeL e' hb, e.mk_symm hb.1]
/-- A version of `Trivialization.coordChangeL_apply` that fully unfolds `coordChange`. The
right-hand side is ugly, but has good definitional properties for specifically defined
trivializations. -/
theorem coordChangeL_apply' (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R] {b : B}
(hb : b ∈ e.baseSet ∩ e'.baseSet) (y : F) :
coordChangeL R e e' b y = (e' (e.toPartialHomeomorph.symm (b, y))).2 := by
rw [e.coordChangeL_apply e' hb, e.mk_symm hb.1]
theorem coordChangeL_symm_apply (e e' : Trivialization F (π F E)) [e.IsLinear R] [e'.IsLinear R]
{b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) :
⇑(coordChangeL R e e' b).symm =
(e'.linearEquivAt R b hb.2).symm.trans (e.linearEquivAt R b hb.1) :=
congr_arg LinearEquiv.invFun (dif_pos hb)
end Trivialization
end TopologicalVectorSpace
section
namespace Bundle
/-- The zero section of a vector bundle -/
def zeroSection [∀ x, Zero (E x)] : B → TotalSpace F E := (⟨·, 0⟩)
@[simp, mfld_simps]
theorem zeroSection_proj [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).proj = x :=
rfl
@[simp, mfld_simps]
theorem zeroSection_snd [∀ x, Zero (E x)] (x : B) : (zeroSection F E x).2 = 0 :=
rfl
end Bundle
open Bundle
variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [TopologicalSpace (TotalSpace F E)]
[∀ x, TopologicalSpace (E x)] [FiberBundle F E]
/-- The space `Bundle.TotalSpace F E` (for `E : B → Type*` such that each `E x` is a topological
vector space) has a topological vector space structure with fiber `F` (denoted with
`VectorBundle R F E`) if around every point there is a fiber bundle trivialization which is linear
in the fibers. -/
class VectorBundle : Prop where
trivialization_linear' : ∀ (e : Trivialization F (π F E)) [MemTrivializationAtlas e], e.IsLinear R
continuousOn_coordChange' :
∀ (e e' : Trivialization F (π F E)) [MemTrivializationAtlas e] [MemTrivializationAtlas e'],
ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F)
(e.baseSet ∩ e'.baseSet)
variable {F E}
instance (priority := 100) trivialization_linear [VectorBundle R F E] (e : Trivialization F (π F E))
[MemTrivializationAtlas e] : e.IsLinear R :=
VectorBundle.trivialization_linear' e
theorem continuousOn_coordChange [VectorBundle R F E] (e e' : Trivialization F (π F E))
[MemTrivializationAtlas e] [MemTrivializationAtlas e'] :
ContinuousOn (fun b => Trivialization.coordChangeL R e e' b : B → F →L[R] F)
(e.baseSet ∩ e'.baseSet) :=
VectorBundle.continuousOn_coordChange' e e'
namespace Trivialization
/-- Forward map of `Trivialization.continuousLinearEquivAt` (only propositionally equal),
defined everywhere (`0` outside domain). -/
@[simps -fullyApplied apply]
def continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : E b →L[R] F :=
{ e.linearMapAt R b with
toFun := e.linearMapAt R b -- given explicitly to help `simps`
cont := by
rw [e.coe_linearMapAt b]
classical
refine continuous_if_const _ (fun hb => ?_) fun _ => continuous_zero
exact (e.continuousOn.comp_continuous (FiberBundle.totalSpaceMk_isInducing F E b).continuous
fun x => e.mem_source.mpr hb).snd }
/-- Backwards map of `Trivialization.continuousLinearEquivAt`, defined everywhere. -/
@[simps -fullyApplied apply]
def symmL (e : Trivialization F (π F E)) [e.IsLinear R] (b : B) : F →L[R] E b :=
{ e.symmₗ R b with
toFun := e.symm b -- given explicitly to help `simps`
cont := by
by_cases hb : b ∈ e.baseSet
· rw [(FiberBundle.totalSpaceMk_isInducing F E b).continuous_iff]
exact e.continuousOn_symm.comp_continuous (.prodMk_right _) fun x ↦
mk_mem_prod hb (mem_univ x)
· refine continuous_zero.congr fun x => (e.symm_apply_of_not_mem hb x).symm }
variable {R}
theorem symmL_continuousLinearMapAt (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : E b) : e.symmL R b (e.continuousLinearMapAt R b y) = y :=
e.symmₗ_linearMapAt hb y
theorem continuousLinearMapAt_symmL (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) (y : F) : e.continuousLinearMapAt R b (e.symmL R b y) = y :=
e.linearMapAt_symmₗ hb y
variable (R) in
/-- In a vector bundle, a trivialization in the fiber (which is a priori only linear)
is in fact a continuous linear equiv between the fibers and the model fiber. -/
@[simps -fullyApplied apply symm_apply]
def continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) : E b ≃L[R] F :=
{ e.toPretrivialization.linearEquivAt R b hb with
toFun := fun y => (e ⟨b, y⟩).2 -- given explicitly to help `simps`
invFun := e.symm b -- given explicitly to help `simps`
continuous_toFun := (e.continuousOn.comp_continuous
(FiberBundle.totalSpaceMk_isInducing F E b).continuous fun _ => e.mem_source.mpr hb).snd
continuous_invFun := (e.symmL R b).continuous }
theorem coe_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) :
(e.continuousLinearEquivAt R b hb : E b → F) = e.continuousLinearMapAt R b :=
(e.coe_linearMapAt_of_mem hb).symm
theorem symm_continuousLinearEquivAt_eq (e : Trivialization F (π F E)) [e.IsLinear R] {b : B}
(hb : b ∈ e.baseSet) : ((e.continuousLinearEquivAt R b hb).symm : F → E b) = e.symmL R b :=
rfl
@[simp]
theorem continuousLinearEquivAt_apply' (e : Trivialization F (π F E)) [e.IsLinear R]
(x : TotalSpace F E) (hx : x ∈ e.source) :
e.continuousLinearEquivAt R x.proj (e.mem_source.1 hx) x.2 = (e x).2 := rfl
variable (R)
theorem apply_eq_prod_continuousLinearEquivAt (e : Trivialization F (π F E)) [e.IsLinear R] (b : B)
(hb : b ∈ e.baseSet) (z : E b) : e ⟨b, z⟩ = (b, e.continuousLinearEquivAt R b hb z) := by
ext
· refine e.coe_fst ?_
rw [e.source_eq]
exact hb
· simp only [coe_coe, continuousLinearEquivAt_apply]
protected theorem zeroSection (e : Trivialization F (π F E)) [e.IsLinear R] {x : B}
(hx : x ∈ e.baseSet) : e (zeroSection F E x) = (x, 0) := by
simp_rw [zeroSection, e.apply_eq_prod_continuousLinearEquivAt R x hx 0, map_zero]
variable {R}
theorem symm_apply_eq_mk_continuousLinearEquivAt_symm (e : Trivialization F (π F E)) [e.IsLinear R]
(b : B) (hb : b ∈ e.baseSet) (z : F) :
e.toPartialHomeomorph.symm ⟨b, z⟩ = ⟨b, (e.continuousLinearEquivAt R b hb).symm z⟩ := by
have h : (b, z) ∈ e.target := by
rw [e.target_eq]
exact ⟨hb, mem_univ _⟩
apply e.injOn (e.map_target h)
· simpa only [e.source_eq, mem_preimage]
· simp_rw [e.right_inv h, coe_coe, e.apply_eq_prod_continuousLinearEquivAt R b hb,
ContinuousLinearEquiv.apply_symm_apply]
theorem comp_continuousLinearEquivAt_eq_coord_change (e e' : Trivialization F (π F E))
[e.IsLinear R] [e'.IsLinear R] {b : B} (hb : b ∈ e.baseSet ∩ e'.baseSet) :
(e.continuousLinearEquivAt R b hb.1).symm.trans (e'.continuousLinearEquivAt R b hb.2) =
coordChangeL R e e' b := by
ext v
rw [coordChangeL_apply e e' hb]
rfl
end Trivialization
/-! ### Constructing vector bundles -/
variable (B F)
/-- Analogous construction of `FiberBundleCore` for vector bundles. This
construction gives a way to construct vector bundles from a structure registering how
trivialization changes act on fibers. -/
structure VectorBundleCore (ι : Type*) where
baseSet : ι → Set B
isOpen_baseSet : ∀ i, IsOpen (baseSet i)
indexAt : B → ι
mem_baseSet_at : ∀ x, x ∈ baseSet (indexAt x)
coordChange : ι → ι → B → F →L[R] F
coordChange_self : ∀ i, ∀ x ∈ baseSet i, ∀ v, coordChange i i x v = v
continuousOn_coordChange : ∀ i j, ContinuousOn (coordChange i j) (baseSet i ∩ baseSet j)
coordChange_comp : ∀ i j k, ∀ x ∈ baseSet i ∩ baseSet j ∩ baseSet k, ∀ v,
(coordChange j k x) (coordChange i j x v) = coordChange i k x v
/-- The trivial vector bundle core, in which all the changes of coordinates are the
identity. -/
def trivialVectorBundleCore (ι : Type*) [Inhabited ι] : VectorBundleCore R B F ι where
baseSet _ := univ
isOpen_baseSet _ := isOpen_univ
indexAt := default
mem_baseSet_at x := mem_univ x
coordChange _ _ _ := ContinuousLinearMap.id R F
coordChange_self _ _ _ _ := rfl
coordChange_comp _ _ _ _ _ _ := rfl
continuousOn_coordChange _ _ := continuousOn_const
instance (ι : Type*) [Inhabited ι] : Inhabited (VectorBundleCore R B F ι) :=
⟨trivialVectorBundleCore R B F ι⟩
namespace VectorBundleCore
variable {R B F} {ι : Type*}
variable (Z : VectorBundleCore R B F ι)
/-- Natural identification to a `FiberBundleCore`. -/
@[simps (config := mfld_cfg)]
def toFiberBundleCore : FiberBundleCore ι B F :=
{ Z with
coordChange := fun i j b => Z.coordChange i j b
continuousOn_coordChange := fun i j =>
isBoundedBilinearMap_apply.continuous.comp_continuousOn
((Z.continuousOn_coordChange i j).prodMap continuousOn_id) }
-- TODO: restore coercion?
-- instance toFiberBundleCoreCoe : Coe (VectorBundleCore R B F ι) (FiberBundleCore ι B F) :=
-- ⟨toFiberBundleCore⟩
theorem coordChange_linear_comp (i j k : ι) :
∀ x ∈ Z.baseSet i ∩ Z.baseSet j ∩ Z.baseSet k,
(Z.coordChange j k x).comp (Z.coordChange i j x) = Z.coordChange i k x :=
fun x hx => by
ext v
exact Z.coordChange_comp i j k x hx v
/-- The index set of a vector bundle core, as a convenience function for dot notation -/
@[nolint unusedArguments]
def Index := ι
/-- The base space of a vector bundle core, as a convenience function for dot notation -/
@[nolint unusedArguments, reducible]
def Base := B
/-- The fiber of a vector bundle core, as a convenience function for dot notation and
typeclass inference -/
@[nolint unusedArguments]
def Fiber : B → Type _ :=
Z.toFiberBundleCore.Fiber
instance topologicalSpaceFiber (x : B) : TopologicalSpace (Z.Fiber x) :=
Z.toFiberBundleCore.topologicalSpaceFiber x
instance addCommGroupFiber (x : B) : AddCommGroup (Z.Fiber x) :=
inferInstanceAs (AddCommGroup F)
instance moduleFiber (x : B) : Module R (Z.Fiber x) :=
inferInstanceAs (Module R F)
/-- The projection from the total space of a fiber bundle core, on its base. -/
@[reducible, simp, mfld_simps]
protected def proj : TotalSpace F Z.Fiber → B :=
TotalSpace.proj
/-- The total space of the vector bundle, as a convenience function for dot notation.
It is by definition equal to `Bundle.TotalSpace F Z.Fiber`. -/
@[nolint unusedArguments, reducible]
protected def TotalSpace :=
Bundle.TotalSpace F Z.Fiber
/-- Local homeomorphism version of the trivialization change. -/
def trivChange (i j : ι) : PartialHomeomorph (B × F) (B × F) :=
Z.toFiberBundleCore.trivChange i j
@[simp, mfld_simps]
theorem mem_trivChange_source (i j : ι) (p : B × F) :
p ∈ (Z.trivChange i j).source ↔ p.1 ∈ Z.baseSet i ∩ Z.baseSet j :=
Z.toFiberBundleCore.mem_trivChange_source i j p
/-- Topological structure on the total space of a vector bundle created from core, designed so
that all the local trivialization are continuous. -/
instance toTopologicalSpace : TopologicalSpace Z.TotalSpace :=
Z.toFiberBundleCore.toTopologicalSpace
variable (b : B) (a : F)
@[simp, mfld_simps]
theorem coe_coordChange (i j : ι) : Z.toFiberBundleCore.coordChange i j b = Z.coordChange i j b :=
rfl
/-- One of the standard local trivializations of a vector bundle constructed from core, taken by
considering this in particular as a fiber bundle constructed from core. -/
def localTriv (i : ι) : Trivialization F (π F Z.Fiber) :=
Z.toFiberBundleCore.localTriv i
@[simp, mfld_simps]
theorem localTriv_apply {i : ι} (p : Z.TotalSpace) :
(Z.localTriv i) p = ⟨p.1, Z.coordChange (Z.indexAt p.1) i p.1 p.2⟩ :=
rfl
/-- The standard local trivializations of a vector bundle constructed from core are linear. -/
instance localTriv.isLinear (i : ι) : (Z.localTriv i).IsLinear R where
linear x _ :=
{ map_add := fun _ _ => by simp only [map_add, localTriv_apply, mfld_simps]
map_smul := fun _ _ => by simp only [map_smul, localTriv_apply, mfld_simps] }
variable (i j : ι)
@[simp, mfld_simps]
theorem mem_localTriv_source (p : Z.TotalSpace) : p ∈ (Z.localTriv i).source ↔ p.1 ∈ Z.baseSet i :=
Iff.rfl
@[simp, mfld_simps]
theorem baseSet_at : Z.baseSet i = (Z.localTriv i).baseSet :=
rfl
@[simp, mfld_simps]
theorem mem_localTriv_target (p : B × F) :
p ∈ (Z.localTriv i).target ↔ p.1 ∈ (Z.localTriv i).baseSet :=
Z.toFiberBundleCore.mem_localTriv_target i p
@[simp, mfld_simps]
theorem localTriv_symm_fst (p : B × F) :
(Z.localTriv i).toPartialHomeomorph.symm p = ⟨p.1, Z.coordChange i (Z.indexAt p.1) p.1 p.2⟩ :=
rfl
@[simp, mfld_simps]
theorem localTriv_symm_apply {b : B} (hb : b ∈ Z.baseSet i) (v : F) :
(Z.localTriv i).symm b v = Z.coordChange i (Z.indexAt b) b v := by
apply (Z.localTriv i).symm_apply hb v
@[simp, mfld_simps]
theorem localTriv_coordChange_eq {b : B} (hb : b ∈ Z.baseSet i ∩ Z.baseSet j) (v : F) :
(Z.localTriv i).coordChangeL R (Z.localTriv j) b v = Z.coordChange i j b v := by
rw [Trivialization.coordChangeL_apply', localTriv_symm_fst, localTriv_apply, coordChange_comp]
exacts [⟨⟨hb.1, Z.mem_baseSet_at b⟩, hb.2⟩, hb]
/-- Preferred local trivialization of a vector bundle constructed from core, at a given point, as
a bundle trivialization -/
def localTrivAt (b : B) : Trivialization F (π F Z.Fiber) :=
Z.localTriv (Z.indexAt b)
@[simp, mfld_simps]
theorem localTrivAt_def : Z.localTriv (Z.indexAt b) = Z.localTrivAt b :=
rfl
@[simp, mfld_simps]
theorem mem_source_at : (⟨b, a⟩ : Z.TotalSpace) ∈ (Z.localTrivAt b).source := by
rw [localTrivAt, mem_localTriv_source]
exact Z.mem_baseSet_at b
@[simp, mfld_simps]
theorem localTrivAt_apply (p : Z.TotalSpace) : Z.localTrivAt p.1 p = ⟨p.1, p.2⟩ :=
Z.toFiberBundleCore.localTrivAt_apply p
@[simp, mfld_simps]
theorem localTrivAt_apply_mk (b : B) (a : F) : Z.localTrivAt b ⟨b, a⟩ = ⟨b, a⟩ :=
Z.localTrivAt_apply _
@[simp, mfld_simps]
theorem mem_localTrivAt_baseSet : b ∈ (Z.localTrivAt b).baseSet :=
Z.toFiberBundleCore.mem_localTrivAt_baseSet b
instance fiberBundle : FiberBundle F Z.Fiber :=
Z.toFiberBundleCore.fiberBundle
instance vectorBundle : VectorBundle R F Z.Fiber where
trivialization_linear' := by
rintro _ ⟨i, rfl⟩
apply localTriv.isLinear
continuousOn_coordChange' := by
rintro _ _ ⟨i, rfl⟩ ⟨i', rfl⟩
refine (Z.continuousOn_coordChange i i').congr fun b hb => ?_
ext v
exact Z.localTriv_coordChange_eq i i' hb v
/-- The projection on the base of a vector bundle created from core is continuous -/
@[continuity]
theorem continuous_proj : Continuous Z.proj :=
Z.toFiberBundleCore.continuous_proj
/-- The projection on the base of a vector bundle created from core is an open map -/
theorem isOpenMap_proj : IsOpenMap Z.proj :=
Z.toFiberBundleCore.isOpenMap_proj
variable {i j}
@[simp, mfld_simps]
theorem localTriv_continuousLinearMapAt {b : B} (hb : b ∈ Z.baseSet i) :
(Z.localTriv i).continuousLinearMapAt R b = Z.coordChange (Z.indexAt b) i b := by
ext1 v
rw [(Z.localTriv i).continuousLinearMapAt_apply R, (Z.localTriv i).coe_linearMapAt_of_mem]
exacts [rfl, hb]
@[simp, mfld_simps]
theorem trivializationAt_continuousLinearMapAt {b₀ b : B}
(hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) :
(trivializationAt F Z.Fiber b₀).continuousLinearMapAt R b =
Z.coordChange (Z.indexAt b) (Z.indexAt b₀) b :=
Z.localTriv_continuousLinearMapAt hb
@[simp, mfld_simps]
theorem localTriv_symmL {b : B} (hb : b ∈ Z.baseSet i) :
(Z.localTriv i).symmL R b = Z.coordChange i (Z.indexAt b) b := by
ext1 v
rw [(Z.localTriv i).symmL_apply R, (Z.localTriv i).symm_apply]
exacts [rfl, hb]
@[simp, mfld_simps]
theorem trivializationAt_symmL {b₀ b : B} (hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet) :
(trivializationAt F Z.Fiber b₀).symmL R b = Z.coordChange (Z.indexAt b₀) (Z.indexAt b) b :=
Z.localTriv_symmL hb
@[simp, mfld_simps]
theorem trivializationAt_coordChange_eq {b₀ b₁ b : B}
(hb : b ∈ (trivializationAt F Z.Fiber b₀).baseSet ∩ (trivializationAt F Z.Fiber b₁).baseSet)
(v : F) :
(trivializationAt F Z.Fiber b₀).coordChangeL R (trivializationAt F Z.Fiber b₁) b v =
Z.coordChange (Z.indexAt b₀) (Z.indexAt b₁) b v :=
Z.localTriv_coordChange_eq _ _ hb v
end VectorBundleCore
end
/-! ### Vector prebundle -/
section
variable [NontriviallyNormedField R] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)]
[NormedAddCommGroup F] [NormedSpace R F] [TopologicalSpace B] [∀ x, TopologicalSpace (E x)]
open TopologicalSpace
open VectorBundle
/-- This structure permits to define a vector bundle when trivializations are given as local
equivalences but there is not yet a topology on the total space or the fibers.
| The total space is hence given a topology in such a way that there is a fiber bundle structure for
which the partial equivalences are also partial homeomorphisms and hence vector bundle
trivializations. The topology on the fibers is induced from the one on the total space.
| Mathlib/Topology/VectorBundle/Basic.lean | 725 | 728 |
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.Order.Floor.Semiring
import Mathlib.Data.Nat.Log
/-!
# Integer logarithms in a field with respect to a natural base
This file defines two `ℤ`-valued analogs of the logarithm of `r : R` with base `b : ℕ`:
* `Int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `↑b^k ≤ r`.
* `Int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r ≤ ↑b^k`.
Note that `Int.log` gives the position of the left-most non-zero digit:
```lean
#eval (Int.log 10 (0.09 : ℚ), Int.log 10 (0.10 : ℚ), Int.log 10 (0.11 : ℚ))
-- (-2, -1, -1)
#eval (Int.log 10 (9 : ℚ), Int.log 10 (10 : ℚ), Int.log 10 (11 : ℚ))
-- (0, 1, 1)
```
which means it can be used for computing digit expansions
```lean
import Data.Fin.VecNotation
import Mathlib.Data.Rat.Floor
def digits (b : ℕ) (q : ℚ) (n : ℕ) : ℕ :=
⌊q * ((b : ℚ) ^ (n - Int.log b q))⌋₊ % b
#eval digits 10 (1/7) ∘ ((↑) : Fin 8 → ℕ)
-- ![1, 4, 2, 8, 5, 7, 1, 4]
```
## Main results
* For `Int.log`:
* `Int.zpow_log_le_self`, `Int.lt_zpow_succ_log_self`: the bounds formed by `Int.log`,
`(b : R) ^ log b r ≤ r < (b : R) ^ (log b r + 1)`.
* `Int.zpow_log_gi`: the galois coinsertion between `zpow` and `Int.log`.
* For `Int.clog`:
* `Int.zpow_pred_clog_lt_self`, `Int.self_le_zpow_clog`: the bounds formed by `Int.clog`,
`(b : R) ^ (clog b r - 1) < r ≤ (b : R) ^ clog b r`.
* `Int.clog_zpow_gi`: the galois insertion between `Int.clog` and `zpow`.
* `Int.neg_log_inv_eq_clog`, `Int.neg_clog_inv_eq_log`: the link between the two definitions.
-/
assert_not_exists Finset
variable {R : Type*} [Semifield R] [LinearOrder R] [IsStrictOrderedRing R] [FloorSemiring R]
namespace Int
/-- The greatest power of `b` such that `b ^ log b r ≤ r`. -/
def log (b : ℕ) (r : R) : ℤ :=
if 1 ≤ r then Nat.log b ⌊r⌋₊ else -Nat.clog b ⌈r⁻¹⌉₊
omit [IsStrictOrderedRing R] in
theorem log_of_one_le_right (b : ℕ) {r : R} (hr : 1 ≤ r) : log b r = Nat.log b ⌊r⌋₊ :=
if_pos hr
theorem log_of_right_le_one (b : ℕ) {r : R} (hr : r ≤ 1) : log b r = -Nat.clog b ⌈r⁻¹⌉₊ := by
obtain rfl | hr := hr.eq_or_lt
· rw [log, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right,
Int.ofNat_zero, neg_zero]
· exact if_neg hr.not_le
@[simp, norm_cast]
theorem log_natCast (b : ℕ) (n : ℕ) : log b (n : R) = Nat.log b n := by
cases n
· simp [log_of_right_le_one]
· rw [log_of_one_le_right, Nat.floor_natCast]
| simp
@[simp]
theorem log_ofNat (b : ℕ) (n : ℕ) [n.AtLeastTwo] :
log b (ofNat(n) : R) = Nat.log b ofNat(n) :=
| Mathlib/Data/Int/Log.lean | 74 | 78 |
/-
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 =>
show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by
rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm]
theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n)
| 1, b => by simp [one_add]
| bit0 a, 1 => congr_arg bit0 (add_one a)
| bit1 a, 1 => congr_arg bit1 (add_one a)
| bit0 _, bit0 _ => rfl
| bit0 a, bit1 b => congr_arg bit0 (add_succ a b)
| bit1 _, bit0 _ => rfl
| bit1 a, bit1 b => congr_arg bit1 (add_succ a b)
theorem bit0_of_bit0 : ∀ n, n + n = bit0 n
| 1 => rfl
| bit0 p => congr_arg bit0 (bit0_of_bit0 p)
| bit1 p => show bit0 (succ (p + p)) = _ by rw [bit0_of_bit0 p, succ]
theorem bit1_of_bit1 (n : PosNum) : (n + n) + 1 = bit1 n :=
show (n + n) + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ]
@[norm_cast]
theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n
| 1 => (mul_one _).symm
| bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib]
| bit1 p =>
(add_to_nat (bit0 (m * p)) m).trans <|
show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib]
theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ)
| 1 => Nat.zero_lt_one
| bit0 p =>
let h := to_nat_pos p
add_pos h h
| bit1 _p => Nat.succ_pos _
theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n :=
show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by
intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h
theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by
induction' m with m IH m IH <;> intro n <;> obtain - | n | n := n <;> unfold cmp <;>
try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl
theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop)
| 1, 1 => rfl
| bit0 a, 1 =>
let h : (1 : ℕ) ≤ a := to_nat_pos a
Nat.add_le_add h h
| bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a
| 1, bit0 b =>
let h : (1 : ℕ) ≤ b := to_nat_pos b
Nat.add_le_add h h
| 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b
| bit0 a, bit0 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.add_lt_add this this
· rw [this]
· exact Nat.add_lt_add this this
| bit0 a, bit1 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.le_succ_of_le (Nat.add_lt_add this this)
· rw [this]
apply Nat.lt_succ_self
· exact cmp_to_nat_lemma this
| bit1 a, bit0 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact cmp_to_nat_lemma this
· rw [this]
apply Nat.lt_succ_self
· exact Nat.le_succ_of_le (Nat.add_lt_add this this)
| bit1 a, bit1 b => by
dsimp [cmp]
have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this
· exact Nat.succ_lt_succ (Nat.add_lt_add this this)
· rw [this]
· exact Nat.succ_lt_succ (Nat.add_lt_add this this)
@[norm_cast]
theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n :=
show (m : ℕ) < n ↔ cmp m n = Ordering.lt from
match cmp m n, cmp_to_nat m n with
| Ordering.lt, h => by simp only at h; simp [h]
| Ordering.eq, h => by simp only at h; simp [h, lt_irrefl]
| Ordering.gt, h => by simp [not_lt_of_gt h]
@[norm_cast]
theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by
rw [← not_lt]; exact not_congr lt_to_nat
end PosNum
namespace Num
variable {α : Type*}
open PosNum
theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl
theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl
theorem add_one : ∀ n : Num, n + 1 = succ n
| 0 => rfl
| pos p => by cases p <;> rfl
theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n)
| 0, n => by simp [zero_add]
| pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ']
| pos _, pos _ => congr_arg pos (PosNum.add_succ _ _)
theorem bit0_of_bit0 : ∀ n : Num, n + n = n.bit0
| 0 => rfl
| pos p => congr_arg pos p.bit0_of_bit0
theorem bit1_of_bit1 : ∀ n : Num, (n + n) + 1 = n.bit1
| 0 => rfl
| pos p => congr_arg pos p.bit1_of_bit1
@[simp]
theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat']
theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) :=
Nat.binaryRec_eq _ _ (.inl rfl)
@[simp]
theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl
theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0
| 0 => rfl
| pos _n => rfl
theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 :=
@(Nat.binaryRec (by simp [zero_add]) fun b n ih => by
cases b
| · erw [ofNat'_bit true n, ofNat'_bit]
simp only [← bit1_of_bit1, ← bit0_of_bit0, cond]
· rw [show n.bit true + 1 = (n + 1).bit false by simp [Nat.bit, mul_add],
| Mathlib/Data/Num/Lemmas.lean | 216 | 218 |
/-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow
-/
import Mathlib.LinearAlgebra.Basis.Basic
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
/-!
# Sesquilinear maps
This files provides properties about sesquilinear maps and forms. The maps considered are of the
form `M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M`, where `I₁ : R₁ →+* R` and `I₂ : R₂ →+* R` are ring homomorphisms and
`M₁` is a module over `R₁`, `M₂` is a module over `R₂` and `M` is a module over `R`.
Sesquilinear forms are the special case that `M₁ = M₂`, `M = R₁ = R₂ = R`, and `I₁ = RingHom.id R`.
Taking additionally `I₂ = RingHom.id R`, then one obtains bilinear forms.
Sesquilinear maps are a special case of the bilinear maps defined in `BilinearMap.lean` and `many`
basic lemmas about construction and elementary calculations are found there.
## Main declarations
* `IsOrtho`: states that two vectors are orthogonal with respect to a sesquilinear map
* `IsSymm`, `IsAlt`: states that a sesquilinear form is symmetric and alternating, respectively
* `orthogonalBilin`: provides the orthogonal complement with respect to sesquilinear form
## References
* <https://en.wikipedia.org/wiki/Sesquilinear_form#Over_arbitrary_rings>
## Tags
Sesquilinear form, Sesquilinear map,
-/
variable {R R₁ R₂ R₃ M M₁ M₂ M₃ Mₗ₁ Mₗ₁' Mₗ₂ Mₗ₂' K K₁ K₂ V V₁ V₂ n : Type*}
namespace LinearMap
/-! ### Orthogonal vectors -/
section CommRing
-- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps
variable [CommSemiring R] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] [CommSemiring R₂]
[AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid M] [Module R M]
{I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R}
/-- The proposition that two elements of a sesquilinear map space are orthogonal -/
def IsOrtho (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x : M₁) (y : M₂) : Prop :=
B x y = 0
theorem isOrtho_def {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} {x y} : B.IsOrtho x y ↔ B x y = 0 :=
Iff.rfl
theorem isOrtho_zero_left (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B (0 : M₁) x := by
dsimp only [IsOrtho]
rw [map_zero B, zero_apply]
theorem isOrtho_zero_right (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B x (0 : M₂) :=
map_zero (B x)
theorem isOrtho_flip {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {x y} : B.IsOrtho x y ↔ B.flip.IsOrtho y x := by
simp_rw [isOrtho_def, flip_apply]
open scoped Function in -- required for scoped `on` notation
/-- A set of vectors `v` is orthogonal with respect to some bilinear map `B` if and only
if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use
`BilinForm.isOrtho` -/
def IsOrthoᵢ (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) (v : n → M₁) : Prop :=
Pairwise (B.IsOrtho on v)
theorem isOrthoᵢ_def {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {v : n → M₁} :
B.IsOrthoᵢ v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 :=
Iff.rfl
theorem isOrthoᵢ_flip (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) {v : n → M₁} :
B.IsOrthoᵢ v ↔ B.flip.IsOrthoᵢ v := by
simp_rw [isOrthoᵢ_def]
constructor <;> exact fun h i j hij ↦ h j i hij.symm
end CommRing
section Field
variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁]
[Field K₂] [AddCommGroup V₂] [Module K₂ V₂]
{I₁ : K₁ →+* K} {I₂ : K₂ →+* K} {I₁' : K₁ →+* K} {J₁ : K →+* K} {J₂ : K →+* K}
-- todo: this also holds for [CommRing R] [IsDomain R] when J₁ is invertible
theorem ortho_smul_left {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₁} (ha : a ≠ 0) :
IsOrtho B x y ↔ IsOrtho B (a • x) y := by
dsimp only [IsOrtho]
constructor <;> intro H
· rw [map_smulₛₗ₂, H, smul_zero]
· rw [map_smulₛₗ₂, smul_eq_zero] at H
rcases H with H | H
· rw [map_eq_zero I₁] at H
trivial
· exact H
-- todo: this also holds for [CommRing R] [IsDomain R] when J₂ is invertible
theorem ortho_smul_right {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₂} {ha : a ≠ 0} :
IsOrtho B x y ↔ IsOrtho B x (a • y) := by
dsimp only [IsOrtho]
constructor <;> intro H
· rw [map_smulₛₗ, H, smul_zero]
· rw [map_smulₛₗ, smul_eq_zero] at H
rcases H with H | H
· simp only [map_eq_zero] at H
exfalso
exact ha H
· exact H
/-- A set of orthogonal vectors `v` with respect to some sesquilinear map `B` is linearly
independent if for all `i`, `B (v i) (v i) ≠ 0`. -/
theorem linearIndependent_of_isOrthoᵢ {B : V₁ →ₛₗ[I₁] V₁ →ₛₗ[I₁'] V} {v : n → V₁}
(hv₁ : B.IsOrthoᵢ v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K₁ v := by
classical
rw [linearIndependent_iff']
intro s w hs i hi
have : B (s.sum fun i : n ↦ w i • v i) (v i) = 0 := by rw [hs, map_zero, zero_apply]
have hsum : (s.sum fun j : n ↦ I₁ (w j) • B (v j) (v i)) = I₁ (w i) • B (v i) (v i) := by
apply Finset.sum_eq_single_of_mem i hi
intro j _hj hij
rw [isOrthoᵢ_def.1 hv₁ _ _ hij, smul_zero]
simp_rw [B.map_sum₂, map_smulₛₗ₂, hsum] at this
apply (map_eq_zero I₁).mp
exact (smul_eq_zero.mp this).elim _root_.id (hv₂ i · |>.elim)
end Field
/-! ### Reflexive bilinear maps -/
|
section Reflexive
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁]
[Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M}
/-- The proposition that a sesquilinear map is reflexive -/
def IsRefl (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop :=
∀ x y, B x y = 0 → B y x = 0
namespace IsRefl
| Mathlib/LinearAlgebra/SesquilinearForm.lean | 137 | 149 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Data.Finset.Attach
import Mathlib.Data.Finset.Disjoint
import Mathlib.Data.Finset.Erase
import Mathlib.Data.Finset.Filter
import Mathlib.Data.Finset.Range
import Mathlib.Data.Finset.SDiff
import Mathlib.Data.Multiset.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.Directed
import Mathlib.Order.Interval.Set.Defs
import Mathlib.Data.Set.SymmDiff
/-!
# Basic lemmas on finite sets
This file contains lemmas on the interaction of various definitions on the `Finset` type.
For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`.
## Main declarations
### Main definitions
* `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element
satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate.
### Equivalences between finsets
* The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there
for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that
`s ≃ t`.
TODO: examples
## Tags
finite sets, finset
-/
-- Assert that we define `Finset` without the material on `List.sublists`.
-- Note that we cannot use `List.sublists` itself as that is defined very early.
assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid
open Multiset Subtype Function
universe u
variable {α : Type*} {β : Type*} {γ : Type*}
namespace Finset
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
set_option linter.deprecated false in
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) :
SizeOf.sizeOf x < SizeOf.sizeOf s := by
cases s
dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf]
rw [Nat.add_comm]
refine lt_trans ?_ (Nat.lt_succ_self _)
exact Multiset.sizeOf_lt_sizeOf_of_mem hx
/-! ### Lattice structure -/
section Lattice
variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α}
/-! #### union -/
@[simp]
theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t :=
ext fun a => by simp
@[simp]
theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by
simp only [disjoint_left, mem_union, or_imp, forall_and]
@[simp]
theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by
simp only [disjoint_right, mem_union, or_imp, forall_and]
/-! #### inter -/
theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty :=
not_disjoint_iff.trans <| by simp [Finset.Nonempty]
alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter
theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by
rw [← not_disjoint_iff_nonempty_inter]
exact em _
omit [DecidableEq α] in
theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) :
Disjoint s t ↔ s = ∅ :=
disjoint_of_le_iff_left_eq_bot h
lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} :
s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by
simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _),
not_disjoint_iff_nonempty_inter]
end Lattice
instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance
instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le
/-! ### erase -/
section Erase
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
@[simp]
theorem erase_empty (a : α) : erase ∅ a = ∅ :=
rfl
protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty :=
(hs.exists_ne a).imp <| by aesop
@[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by
simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)]
refine ⟨?_, fun hs ↦ hs.exists_ne a⟩
rintro ⟨b, hb, hba⟩
exact ⟨_, hb, _, ha, hba⟩
@[simp]
theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by
ext x
simp
@[simp]
theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a :=
ext fun x => by
simp +contextual only [mem_erase, mem_insert, and_congr_right_iff,
false_or, iff_self, imp_true_iff]
theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by
rw [erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) :
erase (insert a s) b = insert a (erase s b) :=
ext fun x => by
have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h
simp only [mem_erase, mem_insert, and_or_left, this]
theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) :
erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by
simp only [cons_eq_insert, erase_insert_of_ne hb]
@[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s :=
ext fun x => by
simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and]
apply or_iff_right_of_imp
rintro rfl
exact h
lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by
aesop
lemma insert_erase_invOn :
Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} :=
⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩
theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s :=
calc
s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _
_ = _ := insert_erase h
theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by
refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩
obtain ⟨a, ht, hs⟩ := not_subset.1 h.2
exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩
theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s :=
ssubset_iff_exists_subset_erase.2
⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩
theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by
rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by
simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp]
exact forall_congr' fun x => forall_swap
theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s :=
subset_insert_iff.1 <| Subset.rfl
theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) :=
subset_insert_iff.2 <| Subset.rfl
theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by
rw [subset_insert_iff, erase_eq_of_not_mem h]
theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by
rw [← subset_insert_iff, insert_eq_of_mem h]
theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a :=
fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h]
end Erase
lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) :
∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by
classical
obtain ⟨a, ha, b, hb, hab⟩ := hs
have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩
refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;>
simp [insert_erase this, insert_erase ha, *]
/-! ### sdiff -/
section Sdiff
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by
ext; aesop
-- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`,
-- or instead add `Finset.union_singleton`/`Finset.singleton_union`?
theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ {a} = erase s a := by
ext
rw [mem_erase, mem_sdiff, mem_singleton, and_comm]
-- This lemma matches `Finset.insert_eq` in functionality.
theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} :=
(sdiff_singleton_eq_erase _ _).symm
theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by
simp_rw [erase_eq, disjoint_sdiff_comm]
lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by
rw [disjoint_erase_comm, erase_insert ha]
lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by
rw [← disjoint_erase_comm, erase_insert ha]
theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by
rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right]
exact ⟨not_mem_erase _ _, hst⟩
theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by
rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left]
exact ⟨not_mem_erase _ _, hst⟩
theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by
simp only [erase_eq, inter_sdiff_assoc]
@[simp]
theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by
simpa only [inter_comm t] using inter_erase a t s
theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by
simp_rw [erase_eq, sdiff_right_comm]
theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by
rw [erase_inter, inter_erase]
theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by
simp_rw [erase_eq, union_sdiff_distrib]
theorem insert_inter_distrib (s t : Finset α) (a : α) :
insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left]
theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by
simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm]
theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by
rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha]
theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by
rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha]
theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by
simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)]
theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by
simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib,
inter_comm]
theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) :
insert x (s \ insert x t) = s \ t := by
rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)]
theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by
rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq,
union_comm]
theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by
rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq]
theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by
rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff]
--TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra`
theorem sdiff_disjoint : Disjoint (t \ s) s :=
disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2
theorem disjoint_sdiff : Disjoint s (t \ s) :=
sdiff_disjoint.symm
theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) :=
disjoint_of_subset_right inter_subset_right sdiff_disjoint
end Sdiff
/-! ### attach -/
@[simp]
theorem attach_empty : attach (∅ : Finset α) = ∅ :=
rfl
@[simp]
theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by
simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff
@[simp]
theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by
simp [eq_empty_iff_forall_not_mem]
/-! ### filter -/
section Filter
variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α}
theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by
classical
ext x
simp only [mem_singleton, forall_eq, mem_filter]
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) :
filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) :=
eq_of_veq <| Multiset.filter_cons_of_pos s.val hp
theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) :
filter p (cons a s ha) = filter p s :=
eq_of_veq <| Multiset.filter_cons_of_neg s.val hp
theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] :
Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by
constructor <;> simp +contextual [disjoint_left]
theorem disjoint_filter_filter' (s t : Finset α)
{p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) :
Disjoint (s.filter p) (t.filter q) := by
simp_rw [disjoint_left, mem_filter]
rintro a ⟨_, hp⟩ ⟨_, hq⟩
rw [Pi.disjoint_iff] at h
simpa [hp, hq] using h a
theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop)
[DecidablePred p] [∀ x, Decidable (¬p x)] :
Disjoint (s.filter p) (t.filter fun a => ¬p a) :=
disjoint_filter_filter' s t disjoint_compl_right
theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) :
filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) :=
eq_of_veq <| Multiset.filter_add _ _ _
theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) :
filter p (cons a s ha) =
if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by
split_ifs with h
· rw [filter_cons_of_pos _ _ _ ha h]
· rw [filter_cons_of_neg _ _ _ ha h]
section
variable [DecidableEq α]
theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p :=
ext fun _ => by simp only [mem_filter, mem_union, or_and_right]
theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x :=
ext fun x => by simp [mem_filter, mem_union, ← and_or_left]
theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] :
(s.filter fun i => i ∈ t) = s ∩ t :=
ext fun i => by simp [mem_filter, mem_inter]
theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by
ext
simp [mem_filter, mem_inter, and_assoc]
theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by
ext
simp only [mem_inter, mem_filter, and_right_comm]
theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by
rw [inter_comm, filter_inter, inter_comm]
theorem filter_insert (a : α) (s : Finset α) :
filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by
ext x
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by
ext x
simp only [and_assoc, mem_filter, iff_self, mem_erase]
theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q :=
ext fun _ => by simp [mem_filter, mem_union, and_or_left]
theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q :=
ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc]
theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p :=
ext fun a => by
simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or,
Bool.not_eq_true, and_or_left, and_not_self, or_false]
lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] :
s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by
rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)]
theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ :=
ext fun _ => by simp [mem_sdiff, mem_filter]
theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) :
∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by
classical
refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩
· simp [filter_union_right, em]
· intro x
simp
· intro x
simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp]
intro hx hx₂
exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩
-- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing
-- on, e.g. `x ∈ s.filter (Eq b)`.
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq'` with the equality the other way.
-/
theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) :
s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by
split_ifs with h
· ext
simp only [mem_filter, mem_singleton, decide_eq_true_eq]
refine ⟨fun h => h.2.symm, ?_⟩
rintro rfl
exact ⟨h, rfl⟩
· ext
simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq]
rintro m rfl
exact h m
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq` with the equality the other way.
-/
theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) :
(s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b)
theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) :
(s.filter fun a => b ≠ a) = s.erase b := by
ext
simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not]
tauto
theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b)
theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) :
s.filter p ∪ s.filter q = s :=
(filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial
theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) :
(s.filter p ∪ s.filter fun a => ¬p a) = s :=
filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p
end
end Filter
/-! ### range -/
section Range
open Nat
variable {n m l : ℕ}
@[simp]
theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by
convert filter_eq (range n) m using 2
· ext
rw [eq_comm]
· simp
end Range
end Finset
/-! ### dedup on list and multiset -/
namespace Multiset
variable [DecidableEq α] {s t : Multiset α}
@[simp]
theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by
ext; simp
@[simp]
theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 :=
Finset.val_inj.symm.trans Multiset.dedup_eq_zero
@[simp]
theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by
simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty
@[simp]
theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] :
Multiset.toFinset (s.filter p) = s.toFinset.filter p := by
ext; simp
end Multiset
namespace List
variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β}
{s : Finset α} {t : Set β} {t' : Finset β}
@[simp]
theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by
ext
simp
@[simp]
theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by
ext
simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff
@[simp]
theorem toFinset_filter (s : List α) (p : α → Bool) :
(s.filter p).toFinset = s.toFinset.filter (p ·) := by
ext; simp [List.mem_filter]
end List
namespace Finset
section ToList
@[simp]
theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ :=
Multiset.toList_eq_nil.trans val_eq_zero
theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by simp
@[simp]
theorem toList_empty : (∅ : Finset α).toList = [] :=
toList_eq_nil.mpr rfl
theorem Nonempty.toList_ne_nil {s : Finset α} (hs : s.Nonempty) : s.toList ≠ [] :=
mt toList_eq_nil.mp hs.ne_empty
theorem Nonempty.not_empty_toList {s : Finset α} (hs : s.Nonempty) : ¬s.toList.isEmpty :=
mt empty_toList.mp hs.ne_empty
end ToList
/-! ### choose -/
section Choose
variable (p : α → Prop) [DecidablePred p] (l : Finset α)
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the corresponding subtype. -/
def chooseX (hp : ∃! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } :=
Multiset.chooseX p l.val hp
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the ambient type. -/
def choose (hp : ∃! a, a ∈ l ∧ p a) : α :=
chooseX p l hp
theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
end Finset
namespace Equiv
variable [DecidableEq α] {s t : Finset α}
open Finset
/-- The disjoint union of finsets is a sum -/
def Finset.union (s t : Finset α) (h : Disjoint s t) :
s ⊕ t ≃ (s ∪ t : Finset α) :=
Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm
@[simp]
theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) :
Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ :=
rfl
@[simp]
theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) :
Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ :=
rfl
/-- The type of dependent functions on the disjoint union of finsets `s ∪ t` is equivalent to the
type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/
def piFinsetUnion {ι} [DecidableEq ι] (α : ι → Type*) {s t : Finset ι} (h : Disjoint s t) :
((∀ i : s, α i) × ∀ i : t, α i) ≃ ∀ i : (s ∪ t : Finset ι), α i :=
let e := Equiv.Finset.union s t h
sumPiEquivProdPi (fun b ↦ α (e b)) |>.symm.trans (.piCongrLeft (fun i : ↥(s ∪ t) ↦ α i) e)
/-- A finset is equivalent to its coercion as a set. -/
def _root_.Finset.equivToSet (s : Finset α) : s ≃ s.toSet where
toFun a := ⟨a.1, mem_coe.2 a.2⟩
invFun a := ⟨a.1, mem_coe.1 a.2⟩
left_inv := fun _ ↦ rfl
right_inv := fun _ ↦ rfl
end Equiv
namespace Multiset
variable [DecidableEq α]
@[simp]
lemma toFinset_replicate (n : ℕ) (a : α) :
(replicate n a).toFinset = if n = 0 then ∅ else {a} := by
ext x
simp only [mem_toFinset, Finset.mem_singleton, mem_replicate]
split_ifs with hn <;> simp [hn]
end Multiset
| Mathlib/Data/Finset/Basic.lean | 2,709 | 2,711 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.AffineMap
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.Normed.Module.Convex
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Topology.Instances.RealVectorSpace
import Mathlib.Topology.LocallyConstant.Basic
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or
`‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `ℝ`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with
right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`).
* `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is
strictly differentiable. (This is a corollary of the mean value inequality.)
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace ℝ F]
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by
change Icc a b ⊆ { x | f x ≤ B x }
set s := { x | f x ≤ B x } ∩ Icc a b
have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB
have : IsClosed s := by
simp only [s, inter_comm]
exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le'
apply this.Icc_subset_of_forall_exists_gt ha
rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy
rcases hxB.lt_or_eq with hxB | hxB
· -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy))
have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x :=
A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB)
have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this
exact this.mono fun y => le_of_lt
· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩
specialize hf' x xab r hfr
have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z :=
(hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici
(Ioi_mem_nhds hrB)
obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y :=
hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists
refine ⟨z, ?_, hz⟩
have := (hfz.trans hzB).le
rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
-- `bound` actually says `liminf (f z - f x) / (z - x) ≤ B' x`
(bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by
have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≤ B x + r * (x - a) := fun x hx r hr => by
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound
· rwa [sub_self, mul_zero, add_zero]
· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
· intro x hx
exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r)
· intro x _ _
rw [mul_one]
exact (lt_add_iff_pos_right _).2 hr
exact hx
intro x hx
have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 :=
continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
|
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
| Mathlib/Analysis/Calculus/MeanValue.lean | 156 | 175 |
/-
Copyright (c) 2023 Richard M. Hill. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Richard M. Hill
-/
import Mathlib.RingTheory.PowerSeries.Trunc
import Mathlib.RingTheory.PowerSeries.Inverse
import Mathlib.RingTheory.Derivation.Basic
/-!
# Definitions
In this file we define an operation `derivative` (formal differentiation)
on the ring of formal power series in one variable (over an arbitrary commutative semiring).
Under suitable assumptions, we prove that two power series are equal if their derivatives
are equal and their constant terms are equal. This will give us a simple tool for proving
power series identities. For example, one can easily prove the power series identity
$\exp ( \log (1+X)) = 1+X$ by differentiating twice.
## Main Definition
- `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation.
This is abbreviated `d⁄dX R`.
-/
namespace PowerSeries
open Polynomial Derivation Nat
section CommutativeSemiring
variable {R} [CommSemiring R]
/--
The formal derivative of a power series in one variable.
This is defined here as a function, but will be packaged as a
derivation `derivative` on `R⟦X⟧`.
-/
noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff R (n + 1) f * (n + 1)
theorem coeff_derivativeFun (f : R⟦X⟧) (n : ℕ) :
coeff R n f.derivativeFun = coeff R (n + 1) f * (n + 1) := by
rw [derivativeFun, coeff_mk]
theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by
ext
rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative]
theorem derivativeFun_add (f g : R⟦X⟧) :
derivativeFun (f + g) = derivativeFun f + derivativeFun g := by
ext
rw [coeff_derivativeFun, map_add, map_add, coeff_derivativeFun,
coeff_derivativeFun, add_mul]
theorem derivativeFun_C (r : R) : derivativeFun (C R r) = 0 := by
ext n
-- Note that `map_zero` didn't get picked up, apparently due to a missing `FunLike.coe`
rw [coeff_derivativeFun, coeff_succ_C, zero_mul, (coeff R n).map_zero]
| theorem trunc_derivativeFun (f : R⟦X⟧) (n : ℕ) :
trunc n f.derivativeFun = derivative (trunc (n + 1) f) := by
ext d
rw [coeff_trunc]
split_ifs with h
· have : d + 1 < n + 1 := succ_lt_succ_iff.2 h
rw [coeff_derivativeFun, coeff_derivative, coeff_trunc, if_pos this]
· have : ¬d + 1 < n + 1 := by rwa [succ_lt_succ_iff]
rw [coeff_derivative, coeff_trunc, if_neg this, zero_mul]
| Mathlib/RingTheory/PowerSeries/Derivative.lean | 60 | 68 |
/-
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.Algebra.Group.Basic
import Mathlib.Algebra.GroupWithZero.NeZero
import Mathlib.Logic.Unique
import Mathlib.Tactic.Conv
/-!
# Groups with an adjoined zero element
This file describes structures that are not usually studied on their own right in mathematics,
namely a special sort of monoid: apart from a distinguished “zero element” they form a group,
or in other words, they are groups with an adjoined zero element.
Examples are:
* division rings;
* the value monoid of a multiplicative valuation;
* in particular, the non-negative real numbers.
## Main definitions
Various lemmas about `GroupWithZero` and `CommGroupWithZero`.
To reduce import dependencies, the type-classes themselves are in
`Algebra.GroupWithZero.Defs`.
## Implementation details
As is usual in mathlib, we extend the inverse function to the zero element,
and require `0⁻¹ = 0`.
-/
assert_not_exists DenselyOrdered
open Function
variable {M₀ G₀ : Type*}
section
section MulZeroClass
variable [MulZeroClass M₀] {a b : M₀}
theorem left_ne_zero_of_mul : a * b ≠ 0 → a ≠ 0 :=
mt fun h => mul_eq_zero_of_left h b
theorem right_ne_zero_of_mul : a * b ≠ 0 → b ≠ 0 :=
mt (mul_eq_zero_of_right a)
theorem ne_zero_and_ne_zero_of_mul (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 :=
⟨left_ne_zero_of_mul h, right_ne_zero_of_mul h⟩
theorem mul_eq_zero_of_ne_zero_imp_eq_zero {a b : M₀} (h : a ≠ 0 → b = 0) : a * b = 0 := by
have : Decidable (a = 0) := Classical.propDecidable (a = 0)
exact if ha : a = 0 then by rw [ha, zero_mul] else by rw [h ha, mul_zero]
/-- To match `one_mul_eq_id`. -/
theorem zero_mul_eq_const : ((0 : M₀) * ·) = Function.const _ 0 :=
funext zero_mul
/-- To match `mul_one_eq_id`. -/
theorem mul_zero_eq_const : (· * (0 : M₀)) = Function.const _ 0 :=
funext mul_zero
end MulZeroClass
section Mul
variable [Mul M₀] [Zero M₀] [NoZeroDivisors M₀] {a b : M₀}
theorem eq_zero_of_mul_self_eq_zero (h : a * a = 0) : a = 0 :=
(eq_zero_or_eq_zero_of_mul_eq_zero h).elim id id
@[field_simps]
theorem mul_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 :=
mt eq_zero_or_eq_zero_of_mul_eq_zero <| not_or.mpr ⟨ha, hb⟩
end Mul
namespace NeZero
instance mul [Zero M₀] [Mul M₀] [NoZeroDivisors M₀] {x y : M₀} [NeZero x] [NeZero y] :
NeZero (x * y) :=
⟨mul_ne_zero out out⟩
end NeZero
end
section
variable [MulZeroOneClass M₀]
/-- In a monoid with zero, if zero equals one, then zero is the only element. -/
theorem eq_zero_of_zero_eq_one (h : (0 : M₀) = 1) (a : M₀) : a = 0 := by
rw [← mul_one a, ← h, mul_zero]
/-- In a monoid with zero, if zero equals one, then zero is the unique element.
Somewhat arbitrarily, we define the default element to be `0`.
All other elements will be provably equal to it, but not necessarily definitionally equal. -/
def uniqueOfZeroEqOne (h : (0 : M₀) = 1) : Unique M₀ where
default := 0
uniq := eq_zero_of_zero_eq_one h
/-- In a monoid with zero, zero equals one if and only if all elements of that semiring
are equal. -/
theorem subsingleton_iff_zero_eq_one : (0 : M₀) = 1 ↔ Subsingleton M₀ :=
⟨fun h => haveI := uniqueOfZeroEqOne h; inferInstance, fun h => @Subsingleton.elim _ h _ _⟩
alias ⟨subsingleton_of_zero_eq_one, _⟩ := subsingleton_iff_zero_eq_one
theorem eq_of_zero_eq_one (h : (0 : M₀) = 1) (a b : M₀) : a = b :=
@Subsingleton.elim _ (subsingleton_of_zero_eq_one h) a b
/-- In a monoid with zero, either zero and one are nonequal, or zero is the only element. -/
theorem zero_ne_one_or_forall_eq_0 : (0 : M₀) ≠ 1 ∨ ∀ a : M₀, a = 0 :=
not_or_of_imp eq_zero_of_zero_eq_one
end
section
variable [MulZeroOneClass M₀] [Nontrivial M₀] {a b : M₀}
theorem left_ne_zero_of_mul_eq_one (h : a * b = 1) : a ≠ 0 :=
left_ne_zero_of_mul <| ne_zero_of_eq_one h
theorem right_ne_zero_of_mul_eq_one (h : a * b = 1) : b ≠ 0 :=
right_ne_zero_of_mul <| ne_zero_of_eq_one h
end
section MonoidWithZero
variable [MonoidWithZero M₀] {a : M₀} {n : ℕ}
@[simp] lemma zero_pow : ∀ {n : ℕ}, n ≠ 0 → (0 : M₀) ^ n = 0
| n + 1, _ => by rw [pow_succ, mul_zero]
lemma zero_pow_eq (n : ℕ) : (0 : M₀) ^ n = if n = 0 then 1 else 0 := by
split_ifs with h
· rw [h, pow_zero]
· rw [zero_pow h]
lemma zero_pow_eq_one₀ [Nontrivial M₀] : (0 : M₀) ^ n = 1 ↔ n = 0 := by
rw [zero_pow_eq, one_ne_zero.ite_eq_left_iff]
lemma pow_eq_zero_of_le : ∀ {m n}, m ≤ n → a ^ m = 0 → a ^ n = 0
| _, _, Nat.le.refl, ha => ha
| _, _, Nat.le.step hmn, ha => by rw [pow_succ, pow_eq_zero_of_le hmn ha, zero_mul]
lemma ne_zero_pow (hn : n ≠ 0) (ha : a ^ n ≠ 0) : a ≠ 0 := by rintro rfl; exact ha <| zero_pow hn
@[simp]
lemma zero_pow_eq_zero [Nontrivial M₀] : (0 : M₀) ^ n = 0 ↔ n ≠ 0 :=
⟨by rintro h rfl; simp at h, zero_pow⟩
lemma pow_mul_eq_zero_of_le {a b : M₀} {m n : ℕ} (hmn : m ≤ n)
(h : a ^ m * b = 0) : a ^ n * b = 0 := by
rw [show n = n - m + m by omega, pow_add, mul_assoc, h]
simp
variable [NoZeroDivisors M₀]
lemma pow_eq_zero : ∀ {n}, a ^ n = 0 → a = 0
| 0, ha => by simpa using congr_arg (a * ·) ha
| n + 1, ha => by rw [pow_succ, mul_eq_zero] at ha; exact ha.elim pow_eq_zero id
@[simp] lemma pow_eq_zero_iff (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 :=
⟨pow_eq_zero, by rintro rfl; exact zero_pow hn⟩
| Mathlib/Algebra/GroupWithZero/Basic.lean | 176 | 176 | |
/-
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, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {α β G M : Type*}
section ite
variable [Pow α β]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup α]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * ·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [← mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : ℕ}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"]
lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b ↔ b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b ↔ a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_left
@[to_additive]
theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not
@[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right
@[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_ne_self
@[to_additive]
theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_left
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid α] {a b c d : α}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G → G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G → G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G → G) :=
inv_involutive.injective
@[to_additive (attr := simp)]
theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b :=
inv_injective.eq_iff
@[to_additive]
theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ :=
⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩
variable (G)
@[to_additive]
theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G :=
inv_involutive.comp_self
@[to_additive]
theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
@[to_additive]
theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by
rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c :=
(mul_div_assoc _ _ _).symm
@[to_additive]
theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv]
@[to_additive]
theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div]
end DivInvMonoid
section DivInvOneMonoid
variable [DivInvOneMonoid G]
@[to_additive (attr := simp)]
theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv]
@[to_additive]
theorem one_div_one : (1 : G) / 1 = 1 :=
div_one _
end DivInvOneMonoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c d : α}
attribute [local simp] mul_assoc div_eq_mul_inv
@[to_additive]
theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ :=
(inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_left h, one_div]
@[to_additive]
theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_right h, one_div]
@[to_additive]
theorem eq_of_div_eq_one (h : a / b = 1) : a = b :=
inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv]
@[to_additive]
lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 :=
mt eq_of_div_eq_one
variable (a b c)
@[to_additive]
theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp
@[to_additive]
theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp
@[to_additive (attr := simp)]
theorem inv_div : (a / b)⁻¹ = b / a := by simp
@[to_additive]
theorem one_div_div : 1 / (a / b) = b / a := by simp
@[to_additive]
theorem one_div_one_div : 1 / (1 / a) = a := by simp
@[to_additive]
theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c :=
inv_inj.symm.trans <| by simp only [inv_div]
@[to_additive]
instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α :=
{ DivisionMonoid.toDivInvMonoid with
inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm }
@[to_additive (attr := simp)]
lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹
| 0 => by rw [pow_zero, pow_zero, inv_one]
| n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev]
-- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`.
@[to_additive zsmul_zero, simp]
lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1
| (n : ℕ) => by rw [zpow_natCast, one_pow]
| .negSucc n => by rw [zpow_negSucc, one_pow, inv_one]
@[to_additive (attr := simp) neg_zsmul]
lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹
| (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _
| 0 => by simp
| Int.negSucc n => by
rw [zpow_negSucc, inv_inv, ← zpow_natCast]
rfl
@[to_additive neg_one_zsmul_add]
lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by
simp only [zpow_neg, zpow_one, mul_inv_rev]
@[to_additive zsmul_neg]
lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow]
| .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow]
@[to_additive (attr := simp) zsmul_neg']
lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg]
@[to_additive nsmul_zero_sub]
lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow]
@[to_additive zsmul_zero_sub]
lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow]
variable {a b c}
@[to_additive (attr := simp)]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
inv_injective.eq_iff' inv_one
@[to_additive (attr := simp)]
theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 :=
eq_comm.trans inv_eq_one
@[to_additive]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
inv_eq_one.not
@[to_additive]
theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by
rw [← one_div_one_div a, h, one_div_one_div]
-- Note that `mul_zsmul` and `zpow_mul` have the primes swapped
-- when additivised since their argument order,
-- and therefore the more "natural" choice of lemma, is reversed.
@[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ), (n : ℕ) => by
rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast]
rfl
| (m : ℕ), .negSucc n => by
rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj,
← zpow_natCast]
| .negSucc m, (n : ℕ) => by
rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow,
inv_inj, ← zpow_natCast]
| .negSucc m, .negSucc n => by
rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ←
zpow_natCast]
rfl
@[to_additive mul_zsmul]
lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul]
@[to_additive]
theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul']
variable (a b c)
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp
@[to_additive (attr := simp)]
theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp
@[to_additive]
theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by
simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] (a b c d : α)
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive neg_add]
theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp
@[to_additive]
theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp
@[to_additive]
theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp
@[to_additive]
theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp
@[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp
@[to_additive]
theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp
@[to_additive]
theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp
@[to_additive]
theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp
@[to_additive]
theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp
@[to_additive]
theorem div_right_comm : a / b / c = a / c / b := by simp
@[to_additive, field_simps]
theorem div_div : a / b / c = a / (b * c) := by simp
@[to_additive]
theorem div_mul : a / b * c = a / (b / c) := by simp
@[to_additive]
theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp
@[to_additive]
theorem mul_div_right_comm : a * b / c = a / c * b := by simp
@[to_additive]
theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp
@[to_additive, field_simps]
theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp
@[to_additive]
theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp
@[to_additive]
theorem mul_comm_div : a / b * c = a * (c / b) := by simp
@[to_additive]
theorem div_mul_comm : a / b * c = c / b * a := by simp
@[to_additive]
theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp
@[to_additive]
theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp
@[to_additive]
theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp
@[to_additive]
theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp
@[to_additive]
theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp
@[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n
| (n : ℕ) => by simp_rw [zpow_natCast, mul_pow]
| .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow]
@[to_additive nsmul_sub]
lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_pow, inv_pow]
@[to_additive zsmul_sub]
lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_zpow, inv_zpow]
attribute [field_simps] div_pow div_zpow
end DivisionCommMonoid
section Group
variable [Group G] {a b c d : G} {n : ℤ}
@[to_additive (attr := simp)]
theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right]
@[to_additive]
theorem mul_left_surjective (a : G) : Surjective (a * ·) :=
fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩
@[to_additive]
theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦
⟨x * a⁻¹, inv_mul_cancel_right x a⟩
@[to_additive]
theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm]
@[to_additive]
theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm]
@[to_additive]
theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h]
@[to_additive]
theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h]
@[to_additive]
theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h]
@[to_additive]
theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ :=
⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩
@[to_additive]
theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by
rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv]
/-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by
rw [mul_eq_one_iff_inv_eq, eq_comm]
/-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by
rw [mul_eq_one_iff_eq_inv, eq_comm]
@[to_additive]
theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 :=
mul_eq_one_iff_eq_inv.symm
@[to_additive]
theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 :=
mul_eq_one_iff_inv_eq.symm
@[to_additive]
theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b :=
⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩
@[to_additive]
theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c :=
⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩
@[to_additive]
theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c :=
⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩
@[to_additive]
theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b :=
⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩
@[to_additive]
theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv]
@[to_additive]
theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj]
@[to_additive (attr := simp)]
theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by
rw [mul_inv_eq_one, mul_eq_left]
@[to_additive]
theorem div_left_injective : Function.Injective fun a ↦ a / b := by
-- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`.
simp only [div_eq_mul_inv]
exact fun a a' h ↦ mul_left_injective b⁻¹ h
@[to_additive]
theorem div_right_injective : Function.Injective fun a ↦ b / a := by
-- FIXME see above
simp only [div_eq_mul_inv]
exact fun a a' h ↦ inv_injective (mul_right_injective b h)
@[to_additive (attr := simp)]
lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right]
@[to_additive (attr := simp)]
theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by
rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right]
@[to_additive eq_sub_of_add_eq]
theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h]
@[to_additive sub_eq_of_eq_add]
theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h]
@[to_additive]
theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h]
@[to_additive]
theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h]
@[to_additive (attr := simp)]
theorem div_right_inj : a / b = a / c ↔ b = c :=
div_right_injective.eq_iff
@[to_additive (attr := simp)]
theorem div_left_inj : b / a = c / a ↔ b = c := by
rw [div_eq_mul_inv, div_eq_mul_inv]
exact mul_left_inj _
@[to_additive (attr := simp)]
theorem div_mul_div_cancel (a b c : G) : a / b * (b / c) = a / c := by
rw [← mul_div_assoc, div_mul_cancel]
@[to_additive (attr := simp)]
theorem div_div_div_cancel_right (a b c : G) : a / c / (b / c) = a / b := by
rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel]
@[to_additive]
theorem div_eq_one : a / b = 1 ↔ a = b :=
⟨eq_of_div_eq_one, fun h ↦ by rw [h, div_self']⟩
alias ⟨_, div_eq_one_of_eq⟩ := div_eq_one
alias ⟨_, sub_eq_zero_of_eq⟩ := sub_eq_zero
@[to_additive]
theorem div_ne_one : a / b ≠ 1 ↔ a ≠ b :=
not_congr div_eq_one
@[to_additive (attr := simp)]
theorem div_eq_self : a / b = a ↔ b = 1 := by rw [div_eq_mul_inv, mul_eq_left, inv_eq_one]
@[to_additive eq_sub_iff_add_eq]
theorem eq_div_iff_mul_eq' : a = b / c ↔ a * c = b := by rw [div_eq_mul_inv, eq_mul_inv_iff_mul_eq]
@[to_additive]
theorem div_eq_iff_eq_mul : a / b = c ↔ a = c * b := by rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul]
@[to_additive]
theorem eq_iff_eq_of_div_eq_div (H : a / b = c / d) : a = b ↔ c = d := by
rw [← div_eq_one, H, div_eq_one]
@[to_additive]
theorem leftInverse_div_mul_left (c : G) : Function.LeftInverse (fun x ↦ x / c) fun x ↦ x * c :=
fun x ↦ mul_div_cancel_right x c
@[to_additive]
theorem leftInverse_mul_left_div (c : G) : Function.LeftInverse (fun x ↦ x * c) fun x ↦ x / c :=
fun x ↦ div_mul_cancel x c
@[to_additive]
theorem leftInverse_mul_right_inv_mul (c : G) :
Function.LeftInverse (fun x ↦ c * x) fun x ↦ c⁻¹ * x :=
fun x ↦ mul_inv_cancel_left c x
@[to_additive]
theorem leftInverse_inv_mul_mul_right (c : G) :
Function.LeftInverse (fun x ↦ c⁻¹ * x) fun x ↦ c * x :=
fun x ↦ inv_mul_cancel_left c x
@[to_additive (attr := simp) natAbs_nsmul_eq_zero]
lemma pow_natAbs_eq_one : a ^ n.natAbs = 1 ↔ a ^ n = 1 := by cases n <;> simp
@[to_additive sub_nsmul]
lemma pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ :=
eq_mul_inv_of_mul_eq <| by rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_neg]
theorem inv_pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by
rw [pow_sub a⁻¹ h, inv_pow, inv_pow, inv_inv]
@[to_additive add_one_zsmul]
lemma zpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a
| (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ]
| -1 => by simp [Int.add_left_neg]
| .negSucc (n + 1) => by
rw [zpow_negSucc, pow_succ', mul_inv_rev, inv_mul_cancel_right]
rw [Int.negSucc_eq, Int.neg_add, Int.neg_add_cancel_right]
exact zpow_negSucc _ _
@[to_additive sub_one_zsmul]
lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
calc
a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := (mul_inv_cancel_right _ _).symm
_ = a ^ n * a⁻¹ := by rw [← zpow_add_one, Int.sub_add_cancel]
@[to_additive add_zsmul]
lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by
induction n with
| hz => simp
| hp n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc]
| hn n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc]
@[to_additive one_add_zsmul]
lemma zpow_one_add (a : G) (n : ℤ) : a ^ (1 + n) = a * a ^ n := by rw [zpow_add, zpow_one]
@[to_additive add_zsmul_self]
lemma mul_self_zpow (a : G) (n : ℤ) : a * a ^ n = a ^ (n + 1) := by
rw [Int.add_comm, zpow_add, zpow_one]
@[to_additive add_self_zsmul]
lemma mul_zpow_self (a : G) (n : ℤ) : a ^ n * a = a ^ (n + 1) := (zpow_add_one ..).symm
@[to_additive sub_zsmul] lemma zpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by
rw [Int.sub_eq_add_neg, zpow_add, zpow_neg]
@[to_additive natCast_sub_natCast_zsmul]
lemma zpow_natCast_sub_natCast (a : G) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by
simpa [div_eq_mul_inv] using zpow_sub a m n
@[to_additive natCast_sub_one_zsmul]
lemma zpow_natCast_sub_one (a : G) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by
simpa [div_eq_mul_inv] using zpow_sub a n 1
@[to_additive one_sub_natCast_zsmul]
lemma zpow_one_sub_natCast (a : G) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by
simpa [div_eq_mul_inv] using zpow_sub a 1 n
@[to_additive] lemma zpow_mul_comm (a : G) (m n : ℤ) : a ^ m * a ^ n = a ^ n * a ^ m := by
rw [← zpow_add, Int.add_comm, zpow_add]
theorem zpow_eq_zpow_emod {x : G} (m : ℤ) {n : ℤ} (h : x ^ n = 1) :
x ^ m = x ^ (m % n) :=
calc
x ^ m = x ^ (m % n + n * (m / n)) := by rw [Int.emod_add_ediv]
_ = x ^ (m % n) := by simp [zpow_add, zpow_mul, h]
theorem zpow_eq_zpow_emod' {x : G} (m : ℤ) {n : ℕ} (h : x ^ n = 1) :
x ^ m = x ^ (m % (n : ℤ)) := zpow_eq_zpow_emod m (by simpa)
@[to_additive (attr := simp)]
lemma zpow_iterate (k : ℤ) : ∀ n : ℕ, (fun x : G ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp [Int.pow_zero]
| n + 1 => by ext; simp [zpow_iterate, Int.pow_succ', zpow_mul]
/-- To show a property of all powers of `g` it suffices to show it is closed under multiplication
by `g` and `g⁻¹` on the left. For subgroups generated by more than one element, see
`Subgroup.closure_induction_left`. -/
@[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under
addition by `g` and `-g` on the left. For additive subgroups generated by more than one element, see
`AddSubgroup.closure_induction_left`."]
lemma zpow_induction_left {g : G} {P : G → Prop} (h_one : P (1 : G))
(h_mul : ∀ a, P a → P (g * a)) (h_inv : ∀ a, P a → P (g⁻¹ * a)) (n : ℤ) : P (g ^ n) := by
induction n with
| hz => rwa [zpow_zero]
| hp n ih =>
rw [Int.add_comm, zpow_add, zpow_one]
exact h_mul _ ih
| hn n ih =>
rw [Int.sub_eq_add_neg, Int.add_comm, zpow_add, zpow_neg_one]
exact h_inv _ ih
/-- To show a property of all powers of `g` it suffices to show it is closed under multiplication
by `g` and `g⁻¹` on the right. For subgroups generated by more than one element, see
`Subgroup.closure_induction_right`. -/
@[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under
addition by `g` and `-g` on the right. For additive subgroups generated by more than one element,
see `AddSubgroup.closure_induction_right`."]
lemma zpow_induction_right {g : G} {P : G → Prop} (h_one : P (1 : G))
(h_mul : ∀ a, P a → P (a * g)) (h_inv : ∀ a, P a → P (a * g⁻¹)) (n : ℤ) : P (g ^ n) := by
induction n with
| hz => rwa [zpow_zero]
| hp n ih =>
rw [zpow_add_one]
exact h_mul _ ih
| hn n ih =>
rw [zpow_sub_one]
exact h_inv _ ih
end Group
section CommGroup
variable [CommGroup G] {a b c d : G}
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive]
theorem div_eq_of_eq_mul' {a b c : G} (h : a = b * c) : a / b = c := by
rw [h, div_eq_mul_inv, mul_comm, inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem mul_div_mul_left_eq_div (a b c : G) : c * a / (c * b) = a / b := by
rw [div_eq_mul_inv, mul_inv_rev, mul_comm b⁻¹ c⁻¹, mul_comm c a, mul_assoc, ← mul_assoc c,
mul_inv_cancel, one_mul, div_eq_mul_inv]
@[to_additive eq_sub_of_add_eq']
theorem eq_div_of_mul_eq'' (h : c * a = b) : a = b / c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_div_eq' (h : a / b = c) : a = b * c := by simp [h.symm]
@[to_additive]
theorem mul_eq_of_eq_div' (h : b = c / a) : a * b = c := by
rw [h, div_eq_mul_inv, mul_comm c, mul_inv_cancel_left]
@[to_additive sub_sub_self]
theorem div_div_self' (a b : G) : a / (a / b) = b := by simp
@[to_additive]
theorem div_eq_div_mul_div (a b c : G) : a / b = c / b * (a / c) := by simp [mul_left_comm c]
@[to_additive (attr := simp)]
theorem div_div_cancel (a b : G) : a / (a / b) = b :=
div_div_self' a b
@[to_additive (attr := simp)]
theorem div_div_cancel_left (a b : G) : a / b / a = b⁻¹ := by simp
@[to_additive eq_sub_iff_add_eq']
theorem eq_div_iff_mul_eq'' : a = b / c ↔ c * a = b := by rw [eq_div_iff_mul_eq', mul_comm]
@[to_additive]
theorem div_eq_iff_eq_mul' : a / b = c ↔ a = b * c := by rw [div_eq_iff_eq_mul, mul_comm]
@[to_additive (attr := simp)]
theorem mul_div_cancel_left (a b : G) : a * b / a = b := by rw [div_eq_inv_mul, inv_mul_cancel_left]
@[to_additive (attr := simp)]
theorem mul_div_cancel (a b : G) : a * (b / a) = b := by
rw [← mul_div_assoc, mul_div_cancel_left]
@[to_additive (attr := simp)]
theorem div_mul_cancel_left (a b : G) : a / (a * b) = b⁻¹ := by rw [← inv_div, mul_div_cancel_left]
-- This lemma is in the `simp` set under the name `mul_inv_cancel_comm_assoc`,
-- along with the additive version `add_neg_cancel_comm_assoc`,
-- defined in `Algebra.Group.Commute`
@[to_additive]
theorem mul_mul_inv_cancel'_right (a b : G) : a * (b * a⁻¹) = b := by
rw [← div_eq_mul_inv, mul_div_cancel a b]
@[to_additive (attr := simp)]
theorem mul_mul_div_cancel (a b c : G) : a * c * (b / c) = a * b := by
rw [mul_assoc, mul_div_cancel]
@[to_additive (attr := simp)]
theorem div_mul_mul_cancel (a b c : G) : a / c * (b * c) = a * b := by
rw [mul_left_comm, div_mul_cancel, mul_comm]
@[to_additive (attr := simp)]
theorem div_mul_div_cancel' (a b c : G) : a / b * (c / a) = c / b := by
rw [mul_comm]; apply div_mul_div_cancel
@[to_additive (attr := simp)]
theorem mul_div_div_cancel (a b c : G) : a * b / (a / c) = b * c := by
rw [← div_mul, mul_div_cancel_left]
@[to_additive (attr := simp)]
theorem div_div_div_cancel_left (a b c : G) : c / a / (c / b) = b / a := by
rw [← inv_div b c, div_inv_eq_mul, mul_comm, div_mul_div_cancel]
@[to_additive]
theorem div_eq_div_iff_mul_eq_mul : a / b = c / d ↔ a * d = c * b := by
rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, eq_comm, div_eq_iff_eq_mul']
simp only [mul_comm, eq_comm]
@[to_additive]
theorem div_eq_div_iff_div_eq_div : a / b = c / d ↔ a / c = b / d := by
rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, div_eq_iff_eq_mul', mul_div_assoc]
end CommGroup
section multiplicative
variable [Monoid β] (p r : α → α → Prop) [IsTotal α r] (f : α → α → β)
@[to_additive additive_of_symmetric_of_isTotal]
lemma multiplicative_of_symmetric_of_isTotal
(hsymm : Symmetric p) (hf_swap : ∀ {a b}, p a b → f a b * f b a = 1)
(hmul : ∀ {a b c}, r a b → r b c → p a b → p b c → p a c → f a c = f a b * f b c)
{a b c : α} (pab : p a b) (pbc : p b c) (pac : p a c) : f a c = f a b * f b c := by
have hmul' : ∀ {b c}, r b c → p a b → p b c → p a c → f a c = f a b * f b c := by
intros b c rbc pab pbc pac
obtain rab | rba := total_of r a b
· exact hmul rab rbc pab pbc pac
rw [← one_mul (f a c), ← hf_swap pab, mul_assoc]
obtain rac | rca := total_of r a c
· rw [hmul rba rac (hsymm pab) pac pbc]
· rw [hmul rbc rca pbc (hsymm pac) (hsymm pab), mul_assoc, hf_swap (hsymm pac), mul_one]
obtain rbc | rcb := total_of r b c
· exact hmul' rbc pab pbc pac
· rw [hmul' rcb pac (hsymm pbc) pab, mul_assoc, hf_swap (hsymm pbc), mul_one]
/-- If a binary function from a type equipped with a total relation `r` to a monoid is
anti-symmetric (i.e. satisfies `f a b * f b a = 1`), in order to show it is multiplicative
(i.e. satisfies `f a c = f a b * f b c`), we may assume `r a b` and `r b c` are satisfied.
We allow restricting to a subset specified by a predicate `p`. -/
@[to_additive additive_of_isTotal "If a binary function from a type equipped with a total relation
`r` to an additive monoid is anti-symmetric (i.e. satisfies `f a b + f b a = 0`), in order to show
it is additive (i.e. satisfies `f a c = f a b + f b c`), we may assume `r a b` and `r b c` are
satisfied. We allow restricting to a subset specified by a predicate `p`."]
theorem multiplicative_of_isTotal (p : α → Prop) (hswap : ∀ {a b}, p a → p b → f a b * f b a = 1)
(hmul : ∀ {a b c}, r a b → r b c → p a → p b → p c → f a c = f a b * f b c) {a b c : α}
(pa : p a) (pb : p b) (pc : p c) : f a c = f a b * f b c := by
apply multiplicative_of_symmetric_of_isTotal (fun a b => p a ∧ p b) r f fun _ _ => And.symm
· simp_rw [and_imp]; exact @hswap
· exact fun rab rbc pab _pbc pac => hmul rab rbc pab.1 pab.2 pac.2
exacts [⟨pa, pb⟩, ⟨pb, pc⟩, ⟨pa, pc⟩]
end multiplicative
/-- An auxiliary lemma that can be used to prove `⇑(f ^ n) = ⇑f^[n]`. -/
@[to_additive]
lemma hom_coe_pow {F : Type*} [Monoid F] (c : F → M → M) (h1 : c 1 = id)
(hmul : ∀ f g, c (f * g) = c f ∘ c g) (f : F) : ∀ n, c (f ^ n) = (c f)^[n]
| 0 => by
rw [pow_zero, h1]
rfl
| n + 1 => by rw [pow_succ, iterate_succ, hmul, hom_coe_pow c h1 hmul f n]
| Mathlib/Algebra/Group/Basic.lean | 1,316 | 1,316 | |
/-
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.DirectSum.LinearMap
import Mathlib.Algebra.Lie.InvariantForm
import Mathlib.Algebra.Lie.Weights.Cartan
import Mathlib.Algebra.Lie.Weights.Linear
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.LinearAlgebra.PID
/-!
# The trace and Killing forms of a Lie algebra.
Let `L` be a Lie algebra with coefficients in a commutative ring `R`. Suppose `M` is a finite, free
`R`-module and we have a representation `φ : L → End M`. This data induces a natural bilinear form
`B` on `L`, called the trace form associated to `M`; it is defined as `B(x, y) = Tr (φ x) (φ y)`.
In the special case that `M` is `L` itself and `φ` is the adjoint representation, the trace form
is known as the Killing form.
We define the trace / Killing form in this file and prove some basic properties.
## Main definitions
* `LieModule.traceForm`: a finite, free representation of a Lie algebra `L` induces a bilinear form
on `L` called the trace Form.
* `LieModule.traceForm_eq_zero_of_isNilpotent`: the trace form induced by a nilpotent
representation of a Lie algebra vanishes.
* `killingForm`: the adjoint representation of a (finite, free) Lie algebra `L` induces a bilinear
form on `L` via the trace form construction.
-/
variable (R K L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L]
[AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
local notation "φ" => LieModule.toEnd R L M
open LinearMap (trace)
open Set Module
namespace LieModule
/-- A finite, free representation of a Lie algebra `L` induces a bilinear form on `L` called
the trace Form. See also `killingForm`. -/
noncomputable def traceForm : LinearMap.BilinForm R L :=
((LinearMap.mul _ _).compl₁₂ (φ).toLinearMap (φ).toLinearMap).compr₂ (trace R M)
lemma traceForm_apply_apply (x y : L) :
traceForm R L M x y = trace R _ (φ x ∘ₗ φ y) :=
rfl
lemma traceForm_comm (x y : L) : traceForm R L M x y = traceForm R L M y x :=
LinearMap.trace_mul_comm R (φ x) (φ y)
lemma traceForm_isSymm : LinearMap.IsSymm (traceForm R L M) := LieModule.traceForm_comm R L M
@[simp] lemma traceForm_flip : LinearMap.flip (traceForm R L M) = traceForm R L M :=
Eq.symm <| LinearMap.ext₂ <| traceForm_comm R L M
/-- The trace form of a Lie module is compatible with the action of the Lie algebra.
See also `LieModule.traceForm_apply_lie_apply'`. -/
lemma traceForm_apply_lie_apply (x y z : L) :
traceForm R L M ⁅x, y⁆ z = traceForm R L M x ⁅y, z⁆ := by
calc traceForm R L M ⁅x, y⁆ z
= trace R _ (φ ⁅x, y⁆ ∘ₗ φ z) := by simp only [traceForm_apply_apply]
_ = trace R _ ((φ x * φ y - φ y * φ x) * φ z) := ?_
_ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ y * (φ x * φ z)) := ?_
_ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ x * (φ z * φ y)) := ?_
_ = traceForm R L M x ⁅y, z⁆ := ?_
· simp only [LieHom.map_lie, Ring.lie_def, ← Module.End.mul_eq_comp]
· simp only [sub_mul, mul_sub, map_sub, mul_assoc]
· simp only [LinearMap.trace_mul_cycle' R (φ x) (φ z) (φ y)]
· simp only [traceForm_apply_apply, LieHom.map_lie, Ring.lie_def, mul_sub, map_sub,
← Module.End.mul_eq_comp]
/-- Given a representation `M` of a Lie algebra `L`, the action of any `x : L` is skew-adjoint wrt
the trace form. -/
lemma traceForm_apply_lie_apply' (x y z : L) :
traceForm R L M ⁅x, y⁆ z = - traceForm R L M y ⁅x, z⁆ :=
calc traceForm R L M ⁅x, y⁆ z
= - traceForm R L M ⁅y, x⁆ z := by rw [← lie_skew x y, map_neg, LinearMap.neg_apply]
_ = - traceForm R L M y ⁅x, z⁆ := by rw [traceForm_apply_lie_apply]
lemma traceForm_lieInvariant : (traceForm R L M).lieInvariant L := by
intro x y z
rw [← lie_skew, map_neg, LinearMap.neg_apply, LieModule.traceForm_apply_lie_apply R L M]
/-- This lemma justifies the terminology "invariant" for trace forms. -/
@[simp] lemma lie_traceForm_eq_zero (x : L) : ⁅x, traceForm R L M⁆ = 0 := by
ext y z
rw [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply,
LinearMap.zero_apply, traceForm_apply_lie_apply', sub_self]
@[simp] lemma traceForm_eq_zero_of_isNilpotent [IsReduced R] [IsNilpotent L M] :
| traceForm R L M = 0 := by
ext x y
simp only [traceForm_apply_apply, LinearMap.zero_apply, ← isNilpotent_iff_eq_zero]
apply LinearMap.isNilpotent_trace_of_isNilpotent
exact isNilpotent_toEnd_of_isNilpotent₂ R L M x y
| Mathlib/Algebra/Lie/TraceForm.lean | 98 | 103 |
/-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yaël Dillies, Moritz Doll
-/
import Mathlib.Algebra.Order.Pi
import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.LocallyConvex.Basic
import Mathlib.Data.Real.Pointwise
/-!
# Seminorms
This file defines seminorms.
A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and
subadditive. They are closely related to convex sets, and a topological vector space is locally
convex if and only if its topology is induced by a family of seminorms.
## Main declarations
For a module over a normed ring:
* `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and
subadditive.
* `normSeminorm 𝕜 E`: The norm on `E` as a seminorm.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
seminorm, locally convex, LCTVS
-/
assert_not_exists balancedCore
open NormedField Set Filter
open scoped NNReal Pointwise Topology Uniformity
variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F ι : Type*}
/-- A seminorm on a module over a normed ring is a function to the reals that is positive
semidefinite, positive homogeneous, and subadditive. -/
structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends
AddGroupSeminorm E where
/-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar
and the original seminorm. -/
smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x
attribute [nolint docBlame] Seminorm.toAddGroupSeminorm
/-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`.
You should extend this class when you extend `Seminorm`. -/
class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E]
[SMul 𝕜 E] [FunLike F E ℝ] : Prop extends AddGroupSeminormClass F E ℝ where
/-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar
and the original seminorm. -/
map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x
export SeminormClass (map_smul_eq_mul)
section Of
/-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a
`SeminormedRing 𝕜`. -/
def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ)
(add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) :
Seminorm 𝕜 E where
toFun := f
map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul]
add_le' := add_le
smul' := smul
neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul]
/-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0`
and an inequality for the scalar multiplication. -/
def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0)
(add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) :
Seminorm 𝕜 E :=
Seminorm.of f add_le fun r x => by
refine le_antisymm (smul_le r x) ?_
by_cases h : r = 0
· simp [h, map_zero]
rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))]
rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)]
specialize smul_le r⁻¹ (r • x)
rw [norm_inv] at smul_le
convert smul_le
simp [h]
end Of
namespace Seminorm
section SeminormedRing
variable [SeminormedRing 𝕜]
section AddGroup
variable [AddGroup E]
section SMul
variable [SMul 𝕜 E]
instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where
coe f := f.toFun
coe_injective' f g h := by
rcases f with ⟨⟨_⟩⟩
rcases g with ⟨⟨_⟩⟩
congr
instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where
map_zero f := f.map_zero'
map_add_le_add f := f.add_le'
map_neg_eq_map f := f.neg'
map_smul_eq_mul f := f.smul'
@[ext]
theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q :=
DFunLike.ext p q h
instance instZero : Zero (Seminorm 𝕜 E) :=
⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with
smul' := fun _ _ => (mul_zero _).symm }⟩
@[simp]
theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 :=
rfl
@[simp]
theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 :=
rfl
instance : Inhabited (Seminorm 𝕜 E) :=
⟨0⟩
variable (p : Seminorm 𝕜 E) (x : E) (r : ℝ)
/-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/
instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where
smul r p :=
{ r • p.toAddGroupSeminorm with
toFun := fun x => r • p x
smul' := fun _ _ => by
simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul]
rw [map_smul_eq_mul, mul_left_comm] }
instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0]
[IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] :
IsScalarTower R R' (Seminorm 𝕜 E) where
smul_assoc r a p := ext fun x => smul_assoc r a (p x)
theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) :
⇑(r • p) = r • ⇑p :=
rfl
@[simp]
theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E)
(x : E) : (r • p) x = r • p x :=
rfl
instance instAdd : Add (Seminorm 𝕜 E) where
add p q :=
{ p.toAddGroupSeminorm + q.toAddGroupSeminorm with
toFun := fun x => p x + q x
smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] }
theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q :=
rfl
@[simp]
theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x :=
rfl
instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl
instance instAddCommMonoid : AddCommMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.addCommMonoid _ rfl coe_add fun _ _ => by rfl
instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) :=
PartialOrder.lift _ DFunLike.coe_injective
instance instIsOrderedCancelAddMonoid : IsOrderedCancelAddMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.isOrderedCancelAddMonoid _ rfl coe_add fun _ _ => rfl
instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] :
MulAction R (Seminorm 𝕜 E) :=
DFunLike.coe_injective.mulAction _ (by intros; rfl)
variable (𝕜 E)
/-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/
@[simps]
def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where
toFun := (↑)
map_zero' := coe_zero
map_add' := coe_add
theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) :=
show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective
variable {𝕜 E}
instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0]
[IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) :=
(coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl)
instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] :
Module R (Seminorm 𝕜 E) :=
(coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl)
instance instSup : Max (Seminorm 𝕜 E) where
max p q :=
{ p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with
toFun := p ⊔ q
smul' := fun x v =>
(congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <|
(mul_max_of_nonneg _ _ <| norm_nonneg x).symm }
@[simp]
theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) :=
rfl
theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x :=
rfl
theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) :
r • (p ⊔ q) = r • p ⊔ r • q :=
have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by
simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using
mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg
ext fun _ => real.smul_max _ _
@[simp, norm_cast]
theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q :=
Iff.rfl
@[simp, norm_cast]
theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q :=
Iff.rfl
theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x :=
Iff.rfl
theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x :=
@Pi.lt_def _ _ _ p q
instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) :=
Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup
end SMul
end AddGroup
section Module
variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃]
variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃]
variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃]
variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃]
variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ]
/-- Composition of a seminorm with a linear map is a seminorm. -/
def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E :=
{ p.toAddGroupSeminorm.comp f.toAddMonoidHom with
toFun := fun x => p (f x)
-- Porting note: the `simp only` below used to be part of the `rw`.
-- I'm not sure why this change was needed, and am worried by it!
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` to `map_smulₛₗ _`
smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] }
theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f :=
rfl
@[simp]
theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) :=
rfl
@[simp]
theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p :=
ext fun _ => rfl
@[simp]
theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 :=
ext fun _ => map_zero p
@[simp]
theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 :=
ext fun _ => rfl
theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃)
(f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f :=
ext fun _ => rfl
theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) :
(p + q).comp f = p.comp f + q.comp f :=
ext fun _ => rfl
theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) :
p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _
theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) :
(c • p).comp f = c • p.comp f :=
ext fun _ => rfl
theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f :=
fun _ => hp _
/-- The composition as an `AddMonoidHom`. -/
@[simps]
def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where
toFun := fun p => p.comp f
map_zero' := zero_comp f
map_add' := fun p q => add_comp p q f
instance instOrderBot : OrderBot (Seminorm 𝕜 E) where
bot := 0
bot_le := apply_nonneg
@[simp]
theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 :=
rfl
theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 :=
rfl
theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) :
a • p ≤ b • q := by
simp_rw [le_def]
intro x
exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b)
theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) :
s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by
induction' s using Finset.cons_induction_on with a s ha ih
· rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply]
norm_cast
· rw [Finset.sup_cons, Finset.sup_cons, coe_sup, Pi.sup_apply, NNReal.coe_max, NNReal.coe_mk, ih]
theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) :
∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩
rw [finset_sup_apply]
exact ⟨i, hi, congr_arg _ hix⟩
theorem zero_or_exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) :
s.sup p x = 0 ∨ ∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.eq_empty_or_nonempty s with (rfl|hs)
· left; rfl
· right; exact exists_apply_eq_finset_sup p hs x
theorem finset_sup_smul (p : ι → Seminorm 𝕜 E) (s : Finset ι) (C : ℝ≥0) :
s.sup (C • p) = C • s.sup p := by
ext x
rw [smul_apply, finset_sup_apply, finset_sup_apply]
symm
exact congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.mul_finset_sup C s (fun i ↦ ⟨p i x, apply_nonneg _ _⟩))
theorem finset_sup_le_sum (p : ι → Seminorm 𝕜 E) (s : Finset ι) : s.sup p ≤ ∑ i ∈ s, p i := by
classical
refine Finset.sup_le_iff.mpr ?_
intro i hi
rw [Finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left]
exact bot_le
theorem finset_sup_apply_le {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a)
(h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a := by
lift a to ℝ≥0 using ha
rw [finset_sup_apply, NNReal.coe_le_coe]
exact Finset.sup_le h
theorem le_finset_sup_apply {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {i : ι}
(hi : i ∈ s) : p i x ≤ s.sup p x :=
(Finset.le_sup hi : p i ≤ s.sup p) x
theorem finset_sup_apply_lt {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 < a)
(h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a := by
lift a to ℝ≥0 using ha.le
rw [finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff]
· exact h
· exact NNReal.coe_pos.mpr ha
theorem norm_sub_map_le_sub (p : Seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) :=
abs_sub_map_le_sub p x y
end Module
end SeminormedRing
section SeminormedCommRing
variable [SeminormedRing 𝕜] [SeminormedCommRing 𝕜₂]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
variable [AddCommGroup E] [AddCommGroup E₂] [Module 𝕜 E] [Module 𝕜₂ E₂]
theorem comp_smul (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) :
p.comp (c • f) = ‖c‖₊ • p.comp f :=
ext fun _ => by
rw [comp_apply, smul_apply, LinearMap.smul_apply, map_smul_eq_mul, NNReal.smul_def, coe_nnnorm,
smul_eq_mul, comp_apply]
theorem comp_smul_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) :
p.comp (c • f) x = ‖c‖ * p (f x) :=
map_smul_eq_mul p _ _
end SeminormedCommRing
section NormedField
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {p q : Seminorm 𝕜 E} {x : E}
/-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/
theorem bddBelow_range_add : BddBelow (range fun u => p u + q (x - u)) :=
⟨0, by
rintro _ ⟨x, rfl⟩
dsimp; positivity⟩
noncomputable instance instInf : Min (Seminorm 𝕜 E) where
min p q :=
{ p.toAddGroupSeminorm ⊓ q.toAddGroupSeminorm with
toFun := fun x => ⨅ u : E, p u + q (x - u)
smul' := by
intro a x
obtain rfl | ha := eq_or_ne a 0
· rw [norm_zero, zero_mul, zero_smul]
refine
ciInf_eq_of_forall_ge_of_forall_gt_exists_lt
(fun i => by positivity)
fun x hx => ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩
simp_rw [Real.mul_iInf_of_nonneg (norm_nonneg a), mul_add, ← map_smul_eq_mul p, ←
map_smul_eq_mul q, smul_sub]
refine
Function.Surjective.iInf_congr ((a⁻¹ • ·) : E → E)
(fun u => ⟨a • u, inv_smul_smul₀ ha u⟩) fun u => ?_
rw [smul_inv_smul₀ ha] }
@[simp]
theorem inf_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x - u) :=
rfl
noncomputable instance instLattice : Lattice (Seminorm 𝕜 E) :=
{ Seminorm.instSemilatticeSup with
inf := (· ⊓ ·)
inf_le_left := fun p q x =>
ciInf_le_of_le bddBelow_range_add x <| by
simp only [sub_self, map_zero, add_zero]; rfl
inf_le_right := fun p q x =>
ciInf_le_of_le bddBelow_range_add 0 <| by
simp only [sub_self, map_zero, zero_add, sub_zero]; rfl
le_inf := fun a _ _ hab hac _ =>
le_ciInf fun _ => (le_map_add_map_sub a _ _).trans <| add_le_add (hab _) (hac _) }
theorem smul_inf [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) :
r • (p ⊓ q) = r • p ⊓ r • q := by
ext
simp_rw [smul_apply, inf_apply, smul_apply, ← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def,
smul_eq_mul, Real.mul_iInf_of_nonneg (NNReal.coe_nonneg _), mul_add]
section Classical
open Classical in
/-- We define the supremum of an arbitrary subset of `Seminorm 𝕜 E` as follows:
* if `s` is `BddAbove` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded
above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a
seminorm.
* otherwise, we take the zero seminorm `⊥`.
There are two things worth mentioning here:
* First, it is not trivial at first that `s` being bounded above *by a function* implies
being bounded above *as a seminorm*. We show this in `Seminorm.bddAbove_iff` by using
that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make
the case disjunction on `BddAbove ((↑) '' s : Set (E → ℝ))` and not `BddAbove s`.
* Since the pointwise `Sup` already gives `0` at points where a family of functions is
not bounded above, one could hope that just using the pointwise `Sup` would work here, without the
need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can
give a function which does *not* satisfy the seminorm axioms (typically sub-additivity).
-/
noncomputable instance instSupSet : SupSet (Seminorm 𝕜 E) where
sSup s :=
if h : BddAbove ((↑) '' s : Set (E → ℝ)) then
{ toFun := ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ)
map_zero' := by
rw [iSup_apply, ← @Real.iSup_const_zero s]
congr!
rename_i _ _ _ i
exact map_zero i.1
add_le' := fun x y => by
rcases h with ⟨q, hq⟩
obtain rfl | h := s.eq_empty_or_nonempty
· simp [Real.iSup_of_isEmpty]
haveI : Nonempty ↑s := h.coe_sort
simp only [iSup_apply]
refine ciSup_le fun i =>
((i : Seminorm 𝕜 E).add_le' x y).trans <| add_le_add
-- Porting note: `f` is provided to force `Subtype.val` to appear.
-- A type ascription on `_` would have also worked, but would have been more verbose.
(le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun x) ⟨q x, ?_⟩ i)
(le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun y) ⟨q y, ?_⟩ i)
<;> rw [mem_upperBounds, forall_mem_range]
<;> exact fun j => hq (mem_image_of_mem _ j.2) _
neg' := fun x => by
simp only [iSup_apply]
congr! 2
rename_i _ _ _ i
exact i.1.neg' _
smul' := fun a x => by
simp only [iSup_apply]
rw [← smul_eq_mul,
Real.smul_iSup_of_nonneg (norm_nonneg a) fun i : s => (i : Seminorm 𝕜 E) x]
congr!
rename_i _ _ _ i
exact i.1.smul' a x }
else ⊥
protected theorem coe_sSup_eq' {s : Set <| Seminorm 𝕜 E}
(hs : BddAbove ((↑) '' s : Set (E → ℝ))) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) :=
congr_arg _ (dif_pos hs)
protected theorem bddAbove_iff {s : Set <| Seminorm 𝕜 E} :
BddAbove s ↔ BddAbove ((↑) '' s : Set (E → ℝ)) :=
⟨fun ⟨q, hq⟩ => ⟨q, forall_mem_image.2 fun _ hp => hq hp⟩, fun H =>
⟨sSup s, fun p hp x => by
dsimp
rw [Seminorm.coe_sSup_eq' H, iSup_apply]
rcases H with ⟨q, hq⟩
exact
le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩⟩⟩
protected theorem bddAbove_range_iff {ι : Sort*} {p : ι → Seminorm 𝕜 E} :
BddAbove (range p) ↔ ∀ x, BddAbove (range fun i ↦ p i x) := by
rw [Seminorm.bddAbove_iff, ← range_comp, bddAbove_range_pi]; rfl
protected theorem coe_sSup_eq {s : Set <| Seminorm 𝕜 E} (hs : BddAbove s) :
↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) :=
Seminorm.coe_sSup_eq' (Seminorm.bddAbove_iff.mp hs)
protected theorem coe_iSup_eq {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) :
↑(⨆ i, p i) = ⨆ i, ((p i : Seminorm 𝕜 E) : E → ℝ) := by
rw [← sSup_range, Seminorm.coe_sSup_eq hp]
exact iSup_range' (fun p : Seminorm 𝕜 E => (p : E → ℝ)) p
protected theorem sSup_apply {s : Set (Seminorm 𝕜 E)} (hp : BddAbove s) {x : E} :
(sSup s) x = ⨆ p : s, (p : E → ℝ) x := by
rw [Seminorm.coe_sSup_eq hp, iSup_apply]
protected theorem iSup_apply {ι : Sort*} {p : ι → Seminorm 𝕜 E}
(hp : BddAbove (range p)) {x : E} : (⨆ i, p i) x = ⨆ i, p i x := by
rw [Seminorm.coe_iSup_eq hp, iSup_apply]
protected theorem sSup_empty : sSup (∅ : Set (Seminorm 𝕜 E)) = ⊥ := by
ext
rw [Seminorm.sSup_apply bddAbove_empty, Real.iSup_of_isEmpty]
rfl
private theorem isLUB_sSup (s : Set (Seminorm 𝕜 E)) (hs₁ : BddAbove s) (hs₂ : s.Nonempty) :
IsLUB s (sSup s) := by
refine ⟨fun p hp x => ?_, fun p hp x => ?_⟩ <;> haveI : Nonempty ↑s := hs₂.coe_sort <;>
dsimp <;> rw [Seminorm.coe_sSup_eq hs₁, iSup_apply]
· rcases hs₁ with ⟨q, hq⟩
exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq i.2 x⟩ ⟨p, hp⟩
· exact ciSup_le fun q => hp q.2 x
/-- `Seminorm 𝕜 E` is a conditionally complete lattice.
Note that, while `inf`, `sup` and `sSup` have good definitional properties (corresponding to
the instances given here for `Inf`, `Sup` and `SupSet` respectively), `sInf s` is just
defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you
need to use `sInf` on seminorms, then you should probably provide a more workable definition first,
but this is unlikely to happen so we keep the "bad" definition for now. -/
noncomputable instance instConditionallyCompleteLattice :
ConditionallyCompleteLattice (Seminorm 𝕜 E) :=
conditionallyCompleteLatticeOfLatticeOfsSup (Seminorm 𝕜 E) Seminorm.isLUB_sSup
end Classical
end NormedField
/-! ### Seminorm ball -/
section SeminormedRing
variable [SeminormedRing 𝕜]
| section AddCommGroup
variable [AddCommGroup E]
| Mathlib/Analysis/Seminorm.lean | 593 | 595 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Properties of inner product spaces
This file proves many basic properties of inner product spaces (real or complex).
## Main results
- `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants).
- `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many
variants).
- `inner_eq_sum_norm_sq_div_four`: the polarization identity.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap (BilinForm)
variable {𝕜 E F : Type*} [RCLike 𝕜]
section BasicProperties_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local postfix:90 "†" => starRingEnd _
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ :=
InnerProductSpace.conj_inner_symm _ _
theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ :=
@inner_conj_symm ℝ _ _ _ _ x y
theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by
rw [← inner_conj_symm]
exact star_eq_zero
@[simp]
theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp
theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
InnerProductSpace.add_left _ _ _
theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by
rw [← inner_conj_symm, inner_add_left, RingHom.map_add]
simp only [inner_conj_symm]
theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re]
theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im]
section Algebra
variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 𝕜] [Module 𝕝 E]
[IsScalarTower 𝕝 𝕜 E] [StarModule 𝕝 𝕜]
/-- See `inner_smul_left` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r† • ⟪x, y⟫ := by
rw [← algebraMap_smul 𝕜 r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply,
← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul]
/-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star
(eg `ℕ`, `ℤ`, `ℚ≥0`, `ℚ`, `ℝ`). -/
lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial]
/-- See `inner_smul_right` for the common special when `𝕜 = 𝕝`. -/
lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : ⟪x, r • y⟫ = r • ⟪x, y⟫ := by
rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply,
star_smul, star_star, ← starRingEnd_apply, inner_conj_symm]
end Algebra
/-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/
theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
inner_smul_left_eq_star_smul ..
theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_left _ _ _
theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_left, conj_ofReal, Algebra.smul_def]
/-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/
theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
inner_smul_right_eq_smul ..
theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_right _ _ _
theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by
rw [inner_smul_right, Algebra.smul_def]
/-- The inner product as a sesquilinear form.
Note that in the case `𝕜 = ℝ` this is a bilinear form. -/
@[simps!]
def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=
LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫)
(fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _)
(fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _
/-- The real inner product as a bilinear form.
Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/
@[simps!]
def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip
/-- An inner product with a sum on the left. -/
theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ :=
map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _
/-- An inner product with a sum on the right. -/
theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) :
⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ :=
map_sum (LinearMap.flip sesqFormOfInner x) _ _
/-- An inner product with a sum on the left, `Finsupp` version. -/
protected theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by
convert sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_left, Finsupp.sum, smul_eq_mul]
/-- An inner product with a sum on the right, `Finsupp` version. -/
protected theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by
convert inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x
simp only [inner_smul_right, Finsupp.sum, smul_eq_mul]
protected theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by
simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul]
protected theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*}
[∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E)
(l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by
simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul]
@[simp]
theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by
rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul]
theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by
simp only [inner_zero_left, AddMonoidHom.map_zero]
@[simp]
theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by
rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero]
theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by
simp only [inner_zero_right, AddMonoidHom.map_zero]
theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=
PreInnerProductSpace.toCore.re_inner_nonneg x
theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ :=
@inner_self_nonneg ℝ F _ _ _ x
@[simp]
theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im (𝕜 := 𝕜) x)
theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by
rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow]
theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by
conv_rhs => rw [← inner_self_ofReal_re]
symm
exact norm_of_nonneg inner_self_nonneg
theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by
rw [← inner_self_re_eq_norm]
exact inner_self_ofReal_re _
theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ :=
@inner_self_ofReal_norm ℝ F _ _ _ x
theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj]
@[simp]
theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by
rw [← neg_one_smul 𝕜 x, inner_smul_left]
simp
@[simp]
theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by
rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm]
theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp
theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _
theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by
simp [sub_eq_add_neg, inner_add_left]
theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by
simp [sub_eq_add_neg, inner_add_right]
theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by
rw [← inner_conj_symm, mul_comm]
exact re_eq_norm_of_mul_conj (inner y x)
/-- Expand `⟪x + y, x + y⟫` -/
theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_add_left, inner_add_right]; ring
/-- Expand `⟪x + y, x + y⟫_ℝ` -/
theorem real_inner_add_add_self (x y : F) :
⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_add_add_self, this, add_left_inj]
ring
-- Expand `⟪x - y, x - y⟫`
theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by
simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `⟪x - y, x - y⟫_ℝ` -/
theorem real_inner_sub_sub_self (x y : F) :
⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl
simp only [inner_sub_sub_self, this, add_left_inj]
ring
/-- Parallelogram law -/
theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by
simp only [inner_add_add_self, inner_sub_sub_self]
ring
/-- **Cauchy–Schwarz inequality**. -/
theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
letI cd : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
InnerProductSpace.Core.inner_mul_inner_self_le x y
/-- Cauchy–Schwarz inequality for real inner products. -/
theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=
calc
⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by
rw [real_inner_comm y, ← norm_mul]
exact le_abs_self _
_ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y
end BasicProperties_Seminormed
section BasicProperties
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
export InnerProductSpace (norm_sq_eq_re_inner)
@[simp]
theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by
rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero]
theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
variable (𝕜)
theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]
theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)]
variable {𝕜}
@[simp]
theorem re_inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by
rw [← norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero]
@[simp]
lemma re_inner_self_pos {x : E} : 0 < re ⟪x, x⟫ ↔ x ≠ 0 := by
simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (𝕜 := 𝕜) (x := x).not
@[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos
@[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos
open scoped InnerProductSpace in
theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := re_inner_self_nonpos (𝕜 := ℝ)
open scoped InnerProductSpace in
theorem real_inner_self_pos {x : F} : 0 < ⟪x, x⟫_ℝ ↔ x ≠ 0 := re_inner_self_pos (𝕜 := ℝ)
/-- A family of vectors is linearly independent if they are nonzero
and orthogonal. -/
theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0)
(ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by
rw [linearIndependent_iff']
intro s g hg i hi
have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by
rw [inner_sum]
symm
convert Finset.sum_eq_single (M := 𝕜) i ?_ ?_
· rw [inner_smul_right]
· intro j _hj hji
rw [inner_smul_right, ho hji.symm, mul_zero]
· exact fun h => False.elim (h hi)
simpa [hg, hz] using h'
end BasicProperties
section Norm_Seminormed
open scoped InnerProductSpace
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "IK" => @RCLike.I 𝕜 _
theorem norm_eq_sqrt_re_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) :=
calc
‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm
_ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_re_inner _)
@[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner
theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ :=
@norm_eq_sqrt_re_inner ℝ _ _ _ _ x
theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by
rw [@norm_eq_sqrt_re_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫),
sqrt_mul_self inner_self_nonneg]
theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by
rw [pow_two, inner_self_eq_norm_mul_norm]
theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by
have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x
simpa using h
theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by
rw [pow_two, real_inner_self_eq_norm_mul_norm]
/-- Expand the square -/
theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜]
rw [inner_add_add_self, two_mul]
simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add]
rw [← inner_conj_symm, conj_re]
alias norm_add_pow_two := norm_add_sq
/-- Expand the square -/
theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by
have h := @norm_add_sq ℝ _ _ _ _ x y
simpa using h
alias norm_add_pow_two_real := norm_add_sq_real
/-- Expand the square -/
theorem norm_add_mul_self (x y : E) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_add_sq _ _
/-- Expand the square -/
theorem norm_add_mul_self_real (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_add_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Expand the square -/
theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by
rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg,
sub_eq_add_neg]
alias norm_sub_pow_two := norm_sub_sq
/-- Expand the square -/
theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 :=
@norm_sub_sq ℝ _ _ _ _ _ _
alias norm_sub_pow_two_real := norm_sub_sq_real
/-- Expand the square -/
theorem norm_sub_mul_self (x y : E) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by
repeat' rw [← sq (M := ℝ)]
exact norm_sub_sq _ _
/-- Expand the square -/
theorem norm_sub_mul_self_real (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by
have h := @norm_sub_mul_self ℝ _ _ _ _ x y
simpa using h
/-- Cauchy–Schwarz inequality with norm -/
theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by
rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜) x, norm_eq_sqrt_re_inner (𝕜 := 𝕜) y]
letI : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore
exact InnerProductSpace.Core.norm_inner_le_norm x y
theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ :=
norm_inner_le_norm x y
theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=
le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ :=
(Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=
le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)
lemma inner_eq_zero_of_left {x : E} (y : E) (h : ‖x‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [← norm_eq_zero]
refine le_antisymm ?_ (by positivity)
exact norm_inner_le_norm _ _ |>.trans <| by simp [h]
lemma inner_eq_zero_of_right (x : E) {y : E} (h : ‖y‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by
rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h]
variable (𝕜)
include 𝕜 in
theorem parallelogram_law_with_norm (x y : E) :
‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by
simp only [← @inner_self_eq_norm_mul_norm 𝕜]
rw [← re.map_add, parallelogram_law, two_mul, two_mul]
simp only [re.map_add]
include 𝕜 in
theorem parallelogram_law_with_nnnorm (x y : E) :
‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) :=
Subtype.ext <| parallelogram_law_with_norm 𝕜 x y
variable {𝕜}
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := by
rw [@norm_add_mul_self 𝕜]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := by
rw [@norm_sub_mul_self 𝕜]
ring
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 := by
rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜]
ring
/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/
theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) :
im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 := by
simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re]
ring
/-- Polarization identity: The inner product, in terms of the norm. -/
theorem inner_eq_sum_norm_sq_div_four (x y : E) :
⟪x, y⟫ = ((‖x + y‖ : 𝕜) ^ 2 - (‖x - y‖ : 𝕜) ^ 2 +
((‖x - IK • y‖ : 𝕜) ^ 2 - (‖x + IK • y‖ : 𝕜) ^ 2) * IK) / 4 := by
rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,
im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four]
push_cast
simp only [sq, ← mul_div_right_comm, ← add_div]
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y
/-- Polarization identity: The real inner product, in terms of the norm. -/
theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=
re_to_real.symm.trans <|
re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y
/-- Pythagorean theorem, if-and-only-if vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by
rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_eq_left, mul_eq_zero]
norm_num
/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/
theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x + y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by
rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := by
rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_eq_left, mul_eq_zero]
apply Or.inr
simp only [h, zero_re']
/-- Pythagorean theorem, vector inner product form. -/
theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector
inner product form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by
rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_eq_left, neg_eq_zero,
mul_eq_zero]
norm_num
/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square
roots. -/
theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x - y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by
rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq,
eq_comm] <;> positivity
/-- Pythagorean theorem, subtracting vectors, vector inner product
form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- The sum and difference of two vectors are orthogonal if and only
if they have the same norm. -/
theorem real_inner_add_sub_eq_zero_iff (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ := by
conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]
simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x,
sub_eq_zero, re_to_real]
constructor
· intro h
rw [add_comm] at h
linarith
· intro h
linarith
/-- Given two orthogonal vectors, their sum and difference have equal norms. -/
theorem norm_sub_eq_norm_add {v w : E} (h : ⟪v, w⟫ = 0) : ‖w - v‖ = ‖w + v‖ := by
rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)]
simp only [h, ← @inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re',
zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm,
zero_add]
/-- The real inner product of two vectors, divided by the product of their
norms, has absolute value at most 1. -/
theorem abs_real_inner_div_norm_mul_norm_le_one (x y : F) : |⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| ≤ 1 := by
rw [abs_div, abs_mul, abs_norm, abs_norm]
exact div_le_one_of_le₀ (abs_real_inner_le_norm x y) (by positivity)
/-- The inner product of a vector with a multiple of itself. -/
theorem real_inner_smul_self_left (x : F) (r : ℝ) : ⟪r • x, x⟫_ℝ = r * (‖x‖ * ‖x‖) := by
rw [real_inner_smul_left, ← real_inner_self_eq_norm_mul_norm]
/-- The inner product of a vector with a multiple of itself. -/
theorem real_inner_smul_self_right (x : F) (r : ℝ) : ⟪x, r • x⟫_ℝ = r * (‖x‖ * ‖x‖) := by
rw [inner_smul_right, ← real_inner_self_eq_norm_mul_norm]
/-- The inner product of two weighted sums, where the weights in each
sum add to 0, in terms of the norms of pairwise differences. -/
theorem inner_sum_smul_sum_smul_of_sum_eq_zero {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ}
(v₁ : ι₁ → F) (h₁ : ∑ i ∈ s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ}
(v₂ : ι₂ → F) (h₂ : ∑ i ∈ s₂, w₂ i = 0) :
⟪∑ i₁ ∈ s₁, w₁ i₁ • v₁ i₁, ∑ i₂ ∈ s₂, w₂ i₂ • v₂ i₂⟫_ℝ =
(-∑ i₁ ∈ s₁, ∑ i₂ ∈ s₂, w₁ i₁ * w₂ i₂ * (‖v₁ i₁ - v₂ i₂‖ * ‖v₁ i₁ - v₂ i₂‖)) / 2 := by
simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, ← div_sub_div_same,
← div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib,
Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul, h₁, h₂, zero_mul,
mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div,
Finset.sum_div, mul_div_assoc, mul_assoc]
end Norm_Seminormed
section Norm
open scoped InnerProductSpace
variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
variable {ι : Type*}
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- Formula for the distance between the images of two nonzero points under an inversion with center
zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general
point. -/
theorem dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) :
dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y :=
calc
dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) =
√(‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) := by
rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]
_ = √((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) :=
congr_arg sqrt <| by
field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right,
Real.norm_of_nonneg (mul_self_nonneg _)]
ring
_ = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := by
rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
theorem norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : E} {r : 𝕜} (hx : x ≠ 0)
(hr : r ≠ 0) : ‖⟪x, r • x⟫‖ / (‖x‖ * ‖r • x‖) = 1 := by
have hx' : ‖x‖ ≠ 0 := by simp [hx]
have hr' : ‖r‖ ≠ 0 := by simp [hr]
rw [inner_smul_right, norm_mul, ← inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul]
rw [← mul_assoc, ← div_div, mul_div_cancel_right₀ _ hx', ← div_div, mul_comm,
mul_div_cancel_right₀ _ hr', div_self hx']
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
theorem abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : F} {r : ℝ}
(hx : x ≠ 0) (hr : r ≠ 0) : |⟪x, r • x⟫_ℝ| / (‖x‖ * ‖r • x‖) = 1 :=
norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of a nonzero vector with a positive multiple of
itself, divided by the product of their norms, has value 1. -/
theorem real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul {x : F} {r : ℝ} (hx : x ≠ 0)
(hr : 0 < r) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = 1 := by
rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|,
mul_assoc, abs_of_nonneg hr.le, div_self]
exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
/-- The inner product of a nonzero vector with a negative multiple of
itself, divided by the product of their norms, has value -1. -/
theorem real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul {x : F} {r : ℝ} (hx : x ≠ 0)
(hr : r < 0) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = -1 := by
rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|,
mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self]
exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
theorem norm_inner_eq_norm_tfae (x y : E) :
List.TFAE [‖⟪x, y⟫‖ = ‖x‖ * ‖y‖,
x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫) • x,
x = 0 ∨ ∃ r : 𝕜, y = r • x,
x = 0 ∨ y ∈ 𝕜 ∙ x] := by
tfae_have 1 → 2 := by
refine fun h => or_iff_not_imp_left.2 fun hx₀ => ?_
have : ‖x‖ ^ 2 ≠ 0 := pow_ne_zero _ (norm_ne_zero_iff.2 hx₀)
rw [← sq_eq_sq₀, mul_pow, ← mul_right_inj' this, eq_comm, ← sub_eq_zero, ← mul_sub] at h <;>
try positivity
simp only [@norm_sq_eq_re_inner 𝕜] at h
letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore
erw [← InnerProductSpace.Core.cauchy_schwarz_aux (𝕜 := 𝕜) (F := E)] at h
rw [InnerProductSpace.Core.normSq_eq_zero, sub_eq_zero] at h
rw [div_eq_inv_mul, mul_smul, h, inv_smul_smul₀]
rwa [inner_self_ne_zero]
tfae_have 2 → 3 := fun h => h.imp_right fun h' => ⟨_, h'⟩
tfae_have 3 → 1 := by
rintro (rfl | ⟨r, rfl⟩) <;>
simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm,
sq, mul_left_comm]
tfae_have 3 ↔ 4 := by simp only [Submodule.mem_span_singleton, eq_comm]
tfae_finish
/-- If the inner product of two vectors is equal to the product of their norms, then the two vectors
are multiples of each other. One form of the equality case for Cauchy-Schwarz.
Compare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
theorem norm_inner_eq_norm_iff {x y : E} (hx₀ : x ≠ 0) (hy₀ : y ≠ 0) :
‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :=
calc
‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ x = 0 ∨ ∃ r : 𝕜, y = r • x :=
(@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 2
_ ↔ ∃ r : 𝕜, y = r • x := or_iff_right hx₀
_ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :=
⟨fun ⟨r, h⟩ => ⟨r, fun hr₀ => hy₀ <| h.symm ▸ smul_eq_zero.2 <| Or.inl hr₀, h⟩,
fun ⟨r, _hr₀, h⟩ => ⟨r, h⟩⟩
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
theorem norm_inner_div_norm_mul_norm_eq_one_iff (x y : E) :
‖⟪x, y⟫ / (‖x‖ * ‖y‖)‖ = 1 ↔ x ≠ 0 ∧ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x := by
constructor
· intro h
have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h
have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h
refine ⟨hx₀, (norm_inner_eq_norm_iff hx₀ hy₀).1 <| eq_of_div_eq_one ?_⟩
simpa using h
· rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩
simp only [norm_div, norm_mul, norm_ofReal, abs_norm]
exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
theorem abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
|⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r ≠ 0 ∧ y = r • x :=
@norm_inner_div_norm_mul_norm_eq_one_iff ℝ F _ _ _ x y
theorem inner_eq_norm_mul_iff_div {x y : E} (h₀ : x ≠ 0) :
⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ / ‖x‖ : 𝕜) • x = y := by
have h₀' := h₀
rw [← norm_ne_zero_iff, Ne, ← @ofReal_eq_zero 𝕜] at h₀'
constructor <;> intro h
· have : x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫ : 𝕜) • x :=
((@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 1).1 (by simp [h])
rw [this.resolve_left h₀, h]
simp [norm_smul, inner_self_ofReal_norm, mul_div_cancel_right₀ _ h₀']
· conv_lhs => rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K]
field_simp [sq, mul_left_comm]
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
theorem inner_eq_norm_mul_iff {x y : E} :
⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ : 𝕜) • x = (‖x‖ : 𝕜) • y := by
rcases eq_or_ne x 0 with (rfl | h₀)
· simp
· rw [inner_eq_norm_mul_iff_div h₀, div_eq_inv_mul, mul_smul, inv_smul_eq_iff₀]
rwa [Ne, ofReal_eq_zero, norm_eq_zero]
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
theorem inner_eq_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ = ‖x‖ * ‖y‖ ↔ ‖y‖ • x = ‖x‖ • y :=
inner_eq_norm_mul_iff
/-- The inner product of two vectors, divided by the product of their
norms, has value 1 if and only if they are nonzero and one is
a positive multiple of the other. -/
theorem real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x := by
constructor
· intro h
have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h
have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h
refine ⟨hx₀, ‖y‖ / ‖x‖, div_pos (norm_pos_iff.2 hy₀) (norm_pos_iff.2 hx₀), ?_⟩
exact ((inner_eq_norm_mul_iff_div hx₀).1 (eq_of_div_eq_one h)).symm
· rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩
exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr
/-- The inner product of two vectors, divided by the product of their
norms, has value -1 if and only if they are nonzero and one is
a negative multiple of the other. -/
theorem real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :
⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = -1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x := by
rw [← neg_eq_iff_eq_neg, ← neg_div, ← inner_neg_right, ← norm_neg y,
real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective ℝ _).exists]
refine Iff.rfl.and (exists_congr fun r => ?_)
rw [neg_pos, neg_smul, neg_inj]
/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of
the equality case for Cauchy-Schwarz. -/
theorem inner_eq_one_iff_of_norm_one {x y : E} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :
⟪x, y⟫ = 1 ↔ x = y := by
convert inner_eq_norm_mul_iff (𝕜 := 𝕜) (E := E) using 2 <;> simp [hx, hy]
theorem inner_lt_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ‖y‖ • x ≠ ‖x‖ • y :=
calc
⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ ≠ ‖x‖ * ‖y‖ :=
⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩
_ ↔ ‖y‖ • x ≠ ‖x‖ • y := not_congr inner_eq_norm_mul_iff_real
/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are
distinct. One form of the equality case for Cauchy-Schwarz. -/
theorem inner_lt_one_iff_real_of_norm_one {x y : F} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :
⟪x, y⟫_ℝ < 1 ↔ x ≠ y := by convert inner_lt_norm_mul_iff_real (F := F) <;> simp [hx, hy]
/-- The sphere of radius `r = ‖y‖` is tangent to the plane `⟪x, y⟫ = ‖y‖ ^ 2` at `x = y`. -/
theorem eq_of_norm_le_re_inner_eq_norm_sq {x y : E} (hle : ‖x‖ ≤ ‖y‖) (h : re ⟪x, y⟫ = ‖y‖ ^ 2) :
x = y := by
suffices H : re ⟪x - y, x - y⟫ ≤ 0 by rwa [re_inner_self_nonpos, sub_eq_zero] at H
have H₁ : ‖x‖ ^ 2 ≤ ‖y‖ ^ 2 := by gcongr
have H₂ : re ⟪y, x⟫ = ‖y‖ ^ 2 := by rwa [← inner_conj_symm, conj_re]
simpa [inner_sub_left, inner_sub_right, ← norm_sq_eq_re_inner, h, H₂] using H₁
end Norm
section RCLike
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
/-- A field `𝕜` satisfying `RCLike` is itself a `𝕜`-inner product space. -/
instance RCLike.innerProductSpace : InnerProductSpace 𝕜 𝕜 where
inner x y := y * conj x
norm_sq_eq_re_inner x := by simp only [inner, mul_conj, ← ofReal_pow, ofReal_re]
conj_inner_symm x y := by simp only [mul_comm, map_mul, starRingEnd_self_apply]
add_left x y z := by simp only [mul_add, map_add]
smul_left x y z := by simp only [mul_comm (conj z), mul_assoc, smul_eq_mul, map_mul]
@[simp]
theorem RCLike.inner_apply (x y : 𝕜) : ⟪x, y⟫ = y * conj x :=
rfl
/-- A version of `RCLike.inner_apply` that swaps the order of multiplication. -/
theorem RCLike.inner_apply' (x y : 𝕜) : ⟪x, y⟫ = conj x * y := mul_comm _ _
end RCLike
section RCLikeToReal
open scoped InnerProductSpace
| variable {G : Type*}
variable (𝕜 E)
variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E]
| Mathlib/Analysis/InnerProductSpace/Basic.lean | 829 | 831 |
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Finset.Prod
import Mathlib.Order.Hom.WithTopBot
import Mathlib.Order.Interval.Set.UnorderedInterval
/-!
# Locally finite orders
This file defines locally finite orders.
A locally finite order is an order for which all bounded intervals are finite. This allows to make
sense of `Icc`/`Ico`/`Ioc`/`Ioo` as lists, multisets, or finsets.
Further, if the order is bounded above (resp. below), then we can also make sense of the
"unbounded" intervals `Ici`/`Ioi` (resp. `Iic`/`Iio`).
Many theorems about these intervals can be found in `Mathlib.Order.Interval.Finset.Basic`.
## Examples
Naturally occurring locally finite orders are `ℕ`, `ℤ`, `ℕ+`, `Fin n`, `α × β` the product of two
locally finite orders, `α →₀ β` the finitely supported functions to a locally finite order `β`...
## Main declarations
In a `LocallyFiniteOrder`,
* `Finset.Icc`: Closed-closed interval as a finset.
* `Finset.Ico`: Closed-open interval as a finset.
* `Finset.Ioc`: Open-closed interval as a finset.
* `Finset.Ioo`: Open-open interval as a finset.
* `Finset.uIcc`: Unordered closed interval as a finset.
In a `LocallyFiniteOrderTop`,
* `Finset.Ici`: Closed-infinite interval as a finset.
* `Finset.Ioi`: Open-infinite interval as a finset.
In a `LocallyFiniteOrderBot`,
* `Finset.Iic`: Infinite-open interval as a finset.
* `Finset.Iio`: Infinite-closed interval as a finset.
## Instances
A `LocallyFiniteOrder` instance can be built
* for a subtype of a locally finite order. See `Subtype.locallyFiniteOrder`.
* for the product of two locally finite orders. See `Prod.locallyFiniteOrder`.
* for any fintype (but not as an instance). See `Fintype.toLocallyFiniteOrder`.
* from a definition of `Finset.Icc` alone. See `LocallyFiniteOrder.ofIcc`.
* by pulling back `LocallyFiniteOrder β` through an order embedding `f : α →o β`. See
`OrderEmbedding.locallyFiniteOrder`.
Instances for concrete types are proved in their respective files:
* `ℕ` is in `Order.Interval.Finset.Nat`
* `ℤ` is in `Data.Int.Interval`
* `ℕ+` is in `Data.PNat.Interval`
* `Fin n` is in `Order.Interval.Finset.Fin`
* `Finset α` is in `Data.Finset.Interval`
* `Σ i, α i` is in `Data.Sigma.Interval`
Along, you will find lemmas about the cardinality of those finite intervals.
## TODO
Provide the `LocallyFiniteOrder` instance for `α ×ₗ β` where `LocallyFiniteOrder α` and
`Fintype β`.
Provide the `LocallyFiniteOrder` instance for `α →₀ β` where `β` is locally finite. Provide the
`LocallyFiniteOrder` instance for `Π₀ i, β i` where all the `β i` are locally finite.
From `LinearOrder α`, `NoMaxOrder α`, `LocallyFiniteOrder α`, we can also define an
order isomorphism `α ≃ ℕ` or `α ≃ ℤ`, depending on whether we have `OrderBot α` or
`NoMinOrder α` and `Nonempty α`. When `OrderBot α`, we can match `a : α` to `#(Iio a)`.
We can provide `SuccOrder α` from `LinearOrder α` and `LocallyFiniteOrder α` using
```lean
lemma exists_min_greater [LinearOrder α] [LocallyFiniteOrder α] {x ub : α} (hx : x < ub) :
∃ lub, x < lub ∧ ∀ y, x < y → lub ≤ y := by
-- very non golfed
have h : (Finset.Ioc x ub).Nonempty := ⟨ub, Finset.mem_Ioc.2 ⟨hx, le_rfl⟩⟩
use Finset.min' (Finset.Ioc x ub) h
constructor
· exact (Finset.mem_Ioc.mp <| Finset.min'_mem _ h).1
rintro y hxy
obtain hy | hy := le_total y ub
· refine Finset.min'_le (Ioc x ub) y ?_
simp [*] at *
· exact (Finset.min'_le _ _ (Finset.mem_Ioc.2 ⟨hx, le_rfl⟩)).trans hy
```
Note that the converse is not true. Consider `{-2^z | z : ℤ} ∪ {2^z | z : ℤ}`. Any element has a
successor (and actually a predecessor as well), so it is a `SuccOrder`, but it's not locally finite
as `Icc (-1) 1` is infinite.
-/
open Finset Function
/-- This is a mixin class describing a locally finite order,
that is, is an order where bounded intervals are finite.
When you don't care too much about definitional equality, you can use `LocallyFiniteOrder.ofIcc` or
`LocallyFiniteOrder.ofFiniteIcc` to build a locally finite order from just `Finset.Icc`. -/
class LocallyFiniteOrder (α : Type*) [Preorder α] where
/-- Left-closed right-closed interval -/
finsetIcc : α → α → Finset α
/-- Left-closed right-open interval -/
finsetIco : α → α → Finset α
/-- Left-open right-closed interval -/
finsetIoc : α → α → Finset α
/-- Left-open right-open interval -/
finsetIoo : α → α → Finset α
/-- `x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b` -/
finset_mem_Icc : ∀ a b x : α, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b
/-- `x ∈ finsetIco a b ↔ a ≤ x ∧ x < b` -/
finset_mem_Ico : ∀ a b x : α, x ∈ finsetIco a b ↔ a ≤ x ∧ x < b
/-- `x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b` -/
finset_mem_Ioc : ∀ a b x : α, x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b
/-- `x ∈ finsetIoo a b ↔ a < x ∧ x < b` -/
finset_mem_Ioo : ∀ a b x : α, x ∈ finsetIoo a b ↔ a < x ∧ x < b
/-- This mixin class describes an order where all intervals bounded below are finite. This is
slightly weaker than `LocallyFiniteOrder` + `OrderTop` as it allows empty types. -/
class LocallyFiniteOrderTop (α : Type*) [Preorder α] where
/-- Left-open right-infinite interval -/
finsetIoi : α → Finset α
/-- Left-closed right-infinite interval -/
finsetIci : α → Finset α
/-- `x ∈ finsetIci a ↔ a ≤ x` -/
finset_mem_Ici : ∀ a x : α, x ∈ finsetIci a ↔ a ≤ x
/-- `x ∈ finsetIoi a ↔ a < x` -/
finset_mem_Ioi : ∀ a x : α, x ∈ finsetIoi a ↔ a < x
/-- This mixin class describes an order where all intervals bounded above are finite. This is
slightly weaker than `LocallyFiniteOrder` + `OrderBot` as it allows empty types. -/
class LocallyFiniteOrderBot (α : Type*) [Preorder α] where
/-- Left-infinite right-open interval -/
finsetIio : α → Finset α
/-- Left-infinite right-closed interval -/
finsetIic : α → Finset α
/-- `x ∈ finsetIic a ↔ x ≤ a` -/
finset_mem_Iic : ∀ a x : α, x ∈ finsetIic a ↔ x ≤ a
/-- `x ∈ finsetIio a ↔ x < a` -/
finset_mem_Iio : ∀ a x : α, x ∈ finsetIio a ↔ x < a
/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `DecidableLE` but
only `Preorder`. -/
def LocallyFiniteOrder.ofIcc' (α : Type*) [Preorder α] [DecidableLE α]
(finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) :
LocallyFiniteOrder α where
finsetIcc := finsetIcc
finsetIco a b := {x ∈ finsetIcc a b | ¬b ≤ x}
finsetIoc a b := {x ∈ finsetIcc a b | ¬x ≤ a}
finsetIoo a b := {x ∈ finsetIcc a b | ¬x ≤ a ∧ ¬b ≤ x}
finset_mem_Icc := mem_Icc
finset_mem_Ico a b x := by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_not_le]
finset_mem_Ioc a b x := by rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_not_le]
finset_mem_Ioo a b x := by
rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_not_le, lt_iff_le_not_le]
/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrder.ofIcc'`, this one requires `PartialOrder` but only
`DecidableEq`. -/
def LocallyFiniteOrder.ofIcc (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) :
LocallyFiniteOrder α where
finsetIcc := finsetIcc
finsetIco a b := {x ∈ finsetIcc a b | x ≠ b}
finsetIoc a b := {x ∈ finsetIcc a b | a ≠ x}
finsetIoo a b := {x ∈ finsetIcc a b | a ≠ x ∧ x ≠ b}
finset_mem_Icc := mem_Icc
finset_mem_Ico a b x := by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_and_ne]
finset_mem_Ioc a b x := by rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_and_ne]
finset_mem_Ioo a b x := by
rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_and_ne, lt_iff_le_and_ne]
/-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderTop.ofIci`, this one requires `DecidableLE` but
only `Preorder`. -/
def LocallyFiniteOrderTop.ofIci' (α : Type*) [Preorder α] [DecidableLE α]
(finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) :
LocallyFiniteOrderTop α where
finsetIci := finsetIci
finsetIoi a := {x ∈ finsetIci a | ¬x ≤ a}
finset_mem_Ici := mem_Ici
finset_mem_Ioi a x := by rw [mem_filter, mem_Ici, lt_iff_le_not_le]
/-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderTop.ofIci'`, this one requires `PartialOrder` but
only `DecidableEq`. -/
def LocallyFiniteOrderTop.ofIci (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) :
LocallyFiniteOrderTop α where
finsetIci := finsetIci
finsetIoi a := {x ∈ finsetIci a | a ≠ x}
finset_mem_Ici := mem_Ici
finset_mem_Ioi a x := by rw [mem_filter, mem_Ici, lt_iff_le_and_ne]
/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderBot.ofIic`, this one requires `DecidableLE` but
only `Preorder`. -/
def LocallyFiniteOrderBot.ofIic' (α : Type*) [Preorder α] [DecidableLE α]
(finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) :
LocallyFiniteOrderBot α where
finsetIic := finsetIic
finsetIio a := {x ∈ finsetIic a | ¬a ≤ x}
finset_mem_Iic := mem_Iic
finset_mem_Iio a x := by rw [mem_filter, mem_Iic, lt_iff_le_not_le]
/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderBot.ofIic'`, this one requires `PartialOrder` but
only `DecidableEq`. -/
def LocallyFiniteOrderBot.ofIic (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) :
LocallyFiniteOrderBot α where
finsetIic := finsetIic
finsetIio a := {x ∈ finsetIic a | x ≠ a}
finset_mem_Iic := mem_Iic
finset_mem_Iio a x := by rw [mem_filter, mem_Iic, lt_iff_le_and_ne]
variable {α β : Type*}
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrder [Preorder α] [IsEmpty α] : LocallyFiniteOrder α where
finsetIcc := isEmptyElim
finsetIco := isEmptyElim
finsetIoc := isEmptyElim
finsetIoo := isEmptyElim
finset_mem_Icc := isEmptyElim
finset_mem_Ico := isEmptyElim
finset_mem_Ioc := isEmptyElim
finset_mem_Ioo := isEmptyElim
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrderTop [Preorder α] [IsEmpty α] :
LocallyFiniteOrderTop α where
finsetIci := isEmptyElim
finsetIoi := isEmptyElim
finset_mem_Ici := isEmptyElim
finset_mem_Ioi := isEmptyElim
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrderBot [Preorder α] [IsEmpty α] :
LocallyFiniteOrderBot α where
finsetIic := isEmptyElim
finsetIio := isEmptyElim
finset_mem_Iic := isEmptyElim
finset_mem_Iio := isEmptyElim
/-! ### Intervals as finsets -/
namespace Finset
section Preorder
variable [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] {a b x : α}
/-- The finset $[a, b]$ of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a
finset. -/
def Icc (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIcc a b
/-- The finset $[a, b)$ of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a
finset. -/
def Ico (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIco a b
/-- The finset $(a, b]$ of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a
finset. -/
def Ioc (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIoc a b
/-- The finset $(a, b)$ of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a
finset. -/
def Ioo (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIoo a b
@[simp]
theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b :=
LocallyFiniteOrder.finset_mem_Icc a b x
@[simp]
theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b :=
LocallyFiniteOrder.finset_mem_Ico a b x
@[simp]
theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b :=
LocallyFiniteOrder.finset_mem_Ioc a b x
@[simp]
theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b :=
LocallyFiniteOrder.finset_mem_Ioo a b x
@[simp, norm_cast]
theorem coe_Icc (a b : α) : (Icc a b : Set α) = Set.Icc a b :=
Set.ext fun _ => mem_Icc
@[simp, norm_cast]
theorem coe_Ico (a b : α) : (Ico a b : Set α) = Set.Ico a b :=
Set.ext fun _ => mem_Ico
@[simp, norm_cast]
theorem coe_Ioc (a b : α) : (Ioc a b : Set α) = Set.Ioc a b :=
Set.ext fun _ => mem_Ioc
@[simp, norm_cast]
theorem coe_Ioo (a b : α) : (Ioo a b : Set α) = Set.Ioo a b :=
Set.ext fun _ => mem_Ioo
@[simp]
theorem _root_.Fintype.card_Icc (a b : α) [Fintype (Set.Icc a b)] :
Fintype.card (Set.Icc a b) = #(Icc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ico (a b : α) [Fintype (Set.Ico a b)] :
Fintype.card (Set.Ico a b) = #(Ico a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ioc (a b : α) [Fintype (Set.Ioc a b)] :
Fintype.card (Set.Ioc a b) = #(Ioc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ioo (a b : α) [Fintype (Set.Ioo a b)] :
Fintype.card (Set.Ioo a b) = #(Ioo a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] {a x : α}
/-- The finset $[a, ∞)$ of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a finset. -/
def Ici (a : α) : Finset α :=
LocallyFiniteOrderTop.finsetIci a
/-- The finset $(a, ∞)$ of elements `x` such that `a < x`. Basically `Set.Ioi a` as a finset. -/
def Ioi (a : α) : Finset α :=
LocallyFiniteOrderTop.finsetIoi a
@[simp]
theorem mem_Ici : x ∈ Ici a ↔ a ≤ x :=
LocallyFiniteOrderTop.finset_mem_Ici _ _
@[simp]
theorem mem_Ioi : x ∈ Ioi a ↔ a < x :=
LocallyFiniteOrderTop.finset_mem_Ioi _ _
@[simp, norm_cast]
theorem coe_Ici (a : α) : (Ici a : Set α) = Set.Ici a :=
Set.ext fun _ => mem_Ici
@[simp, norm_cast]
theorem coe_Ioi (a : α) : (Ioi a : Set α) = Set.Ioi a :=
Set.ext fun _ => mem_Ioi
@[simp]
theorem _root_.Fintype.card_Ici (a : α) [Fintype (Set.Ici a)] :
Fintype.card (Set.Ici a) = #(Ici a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ioi (a : α) [Fintype (Set.Ioi a)] :
Fintype.card (Set.Ioi a) = #(Ioi a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] {a x : α}
/-- The finset $(-∞, b]$ of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a finset. -/
def Iic (b : α) : Finset α :=
LocallyFiniteOrderBot.finsetIic b
/-- The finset $(-∞, b)$ of elements `x` such that `x < b`. Basically `Set.Iio b` as a finset. -/
def Iio (b : α) : Finset α :=
LocallyFiniteOrderBot.finsetIio b
@[simp]
theorem mem_Iic : x ∈ Iic a ↔ x ≤ a :=
LocallyFiniteOrderBot.finset_mem_Iic _ _
@[simp]
theorem mem_Iio : x ∈ Iio a ↔ x < a :=
LocallyFiniteOrderBot.finset_mem_Iio _ _
@[simp, norm_cast]
theorem coe_Iic (a : α) : (Iic a : Set α) = Set.Iic a :=
Set.ext fun _ => mem_Iic
@[simp, norm_cast]
theorem coe_Iio (a : α) : (Iio a : Set α) = Set.Iio a :=
Set.ext fun _ => mem_Iio
@[simp]
theorem _root_.Fintype.card_Iic (a : α) [Fintype (Set.Iic a)] :
Fintype.card (Set.Iic a) = #(Iic a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Iio (a : α) [Fintype (Set.Iio a)] :
Fintype.card (Set.Iio a) = #(Iio a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
end LocallyFiniteOrderBot
section OrderTop
variable [LocallyFiniteOrder α] [OrderTop α] {a x : α}
-- See note [lower priority instance]
instance (priority := 100) _root_.LocallyFiniteOrder.toLocallyFiniteOrderTop :
LocallyFiniteOrderTop α where
finsetIci b := Icc b ⊤
finsetIoi b := Ioc b ⊤
finset_mem_Ici a x := by rw [mem_Icc, and_iff_left le_top]
finset_mem_Ioi a x := by rw [mem_Ioc, and_iff_left le_top]
theorem Ici_eq_Icc (a : α) : Ici a = Icc a ⊤ :=
rfl
theorem Ioi_eq_Ioc (a : α) : Ioi a = Ioc a ⊤ :=
rfl
end OrderTop
section OrderBot
variable [OrderBot α] [LocallyFiniteOrder α] {b x : α}
-- See note [lower priority instance]
instance (priority := 100) LocallyFiniteOrder.toLocallyFiniteOrderBot :
LocallyFiniteOrderBot α where
finsetIic := Icc ⊥
finsetIio := Ico ⊥
finset_mem_Iic a x := by rw [mem_Icc, and_iff_right bot_le]
finset_mem_Iio a x := by rw [mem_Ico, and_iff_right bot_le]
theorem Iic_eq_Icc : Iic = Icc (⊥ : α) :=
rfl
theorem Iio_eq_Ico : Iio = Ico (⊥ : α) :=
rfl
end OrderBot
end Preorder
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] {a b x : α}
/-- `Finset.uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.
Note that we define it more generally in a lattice as `Finset.Icc (a ⊓ b) (a ⊔ b)`. In a
product type, `Finset.uIcc` corresponds to the bounding box of the two elements. -/
def uIcc (a b : α) : Finset α :=
Icc (a ⊓ b) (a ⊔ b)
@[inherit_doc]
scoped[FinsetInterval] notation "[[" a ", " b "]]" => Finset.uIcc a b
@[simp]
theorem mem_uIcc : x ∈ uIcc a b ↔ a ⊓ b ≤ x ∧ x ≤ a ⊔ b :=
mem_Icc
@[simp, norm_cast]
theorem coe_uIcc (a b : α) : (Finset.uIcc a b : Set α) = Set.uIcc a b :=
coe_Icc _ _
@[simp]
theorem _root_.Fintype.card_uIcc (a b : α) [Fintype (Set.uIcc a b)] :
Fintype.card (Set.uIcc a b) = #(uIcc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp [Set.uIcc]
end Lattice
end Finset
namespace Mathlib.Meta
open Lean Elab Term Meta Batteries.ExtendedBinder
/-- Elaborate set builder notation for `Finset`.
* `{x ≤ a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Iic a)` if the expected type
is `Finset ?α`.
* `{x ≥ a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Ici a)` if the expected type
is `Finset ?α`.
* `{x < a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Iio a)` if the expected type
is `Finset ?α`.
* `{x > a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Ioi a)` if the expected type
is `Finset ?α`.
See also
* `Data.Set.Defs` for the `Set` builder notation elaborator that this elaborator partly overrides.
* `Data.Finset.Basic` for the `Finset` builder notation elaborator partly overriding this one for
syntax of the form `{x ∈ s | p x}`.
* `Data.Fintype.Basic` for the `Finset` builder notation elaborator handling syntax of the form
`{x | p x}`, `{x : α | p x}`, `{x ∉ s | p x}`, `{x ≠ a | p x}`.
TODO: Write a delaborator
-/
@[term_elab setBuilder]
def elabFinsetBuilderIxx : TermElab
| `({ $x:ident ≤ $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Iic $a))) expectedType?
| `({ $x:ident ≥ $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Ici $a))) expectedType?
| `({ $x:ident < $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Iio $a))) expectedType?
| `({ $x:ident > $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Ioi $a))) expectedType?
| _, _ => throwUnsupportedSyntax
end Mathlib.Meta
/-! ### Finiteness of `Set` intervals -/
namespace Set
section Preorder
variable [Preorder α] [LocallyFiniteOrder α] (a b : α)
instance instFintypeIcc : Fintype (Icc a b) := .ofFinset (Finset.Icc a b) fun _ => Finset.mem_Icc
instance instFintypeIco : Fintype (Ico a b) := .ofFinset (Finset.Ico a b) fun _ => Finset.mem_Ico
instance instFintypeIoc : Fintype (Ioc a b) := .ofFinset (Finset.Ioc a b) fun _ => Finset.mem_Ioc
instance instFintypeIoo : Fintype (Ioo a b) := .ofFinset (Finset.Ioo a b) fun _ => Finset.mem_Ioo
theorem finite_Icc : (Icc a b).Finite :=
(Icc a b).toFinite
theorem finite_Ico : (Ico a b).Finite :=
(Ico a b).toFinite
theorem finite_Ioc : (Ioc a b).Finite :=
(Ioc a b).toFinite
theorem finite_Ioo : (Ioo a b).Finite :=
(Ioo a b).toFinite
end Preorder
section OrderTop
variable [Preorder α] [LocallyFiniteOrderTop α] (a : α)
instance instFintypeIci : Fintype (Ici a) := .ofFinset (Finset.Ici a) fun _ => Finset.mem_Ici
instance instFintypeIoi : Fintype (Ioi a) := .ofFinset (Finset.Ioi a) fun _ => Finset.mem_Ioi
theorem finite_Ici : (Ici a).Finite :=
(Ici a).toFinite
theorem finite_Ioi : (Ioi a).Finite :=
(Ioi a).toFinite
end OrderTop
section OrderBot
variable [Preorder α] [LocallyFiniteOrderBot α] (b : α)
instance instFintypeIic : Fintype (Iic b) := .ofFinset (Finset.Iic b) fun _ => Finset.mem_Iic
instance instFintypeIio : Fintype (Iio b) := .ofFinset (Finset.Iio b) fun _ => Finset.mem_Iio
theorem finite_Iic : (Iic b).Finite :=
(Iic b).toFinite
theorem finite_Iio : (Iio b).Finite :=
(Iio b).toFinite
end OrderBot
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] (a b : α)
instance fintypeUIcc : Fintype (uIcc a b) :=
Fintype.ofFinset (Finset.uIcc a b) fun _ => Finset.mem_uIcc
@[simp]
theorem finite_interval : (uIcc a b).Finite := (uIcc _ _).toFinite
end Lattice
end Set
/-! ### Instances -/
open Finset
section Preorder
variable [Preorder α] [Preorder β]
/-- A noncomputable constructor from the finiteness of all closed intervals. -/
noncomputable def LocallyFiniteOrder.ofFiniteIcc (h : ∀ a b : α, (Set.Icc a b).Finite) :
LocallyFiniteOrder α :=
@LocallyFiniteOrder.ofIcc' α _ (Classical.decRel _) (fun a b => (h a b).toFinset) fun a b x => by
rw [Set.Finite.mem_toFinset, Set.mem_Icc]
/-- A fintype is a locally finite order.
This is not an instance as it would not be defeq to better instances such as
`Fin.locallyFiniteOrder`.
-/
abbrev Fintype.toLocallyFiniteOrder [Fintype α] [DecidableLT α] [DecidableLE α] :
LocallyFiniteOrder α where
finsetIcc a b := (Set.Icc a b).toFinset
finsetIco a b := (Set.Ico a b).toFinset
finsetIoc a b := (Set.Ioc a b).toFinset
finsetIoo a b := (Set.Ioo a b).toFinset
finset_mem_Icc a b x := by simp only [Set.mem_toFinset, Set.mem_Icc]
finset_mem_Ico a b x := by simp only [Set.mem_toFinset, Set.mem_Ico]
finset_mem_Ioc a b x := by simp only [Set.mem_toFinset, Set.mem_Ioc]
finset_mem_Ioo a b x := by simp only [Set.mem_toFinset, Set.mem_Ioo]
instance : Subsingleton (LocallyFiniteOrder α) :=
Subsingleton.intro fun h₀ h₁ => by
obtain ⟨h₀_finset_Icc, h₀_finset_Ico, h₀_finset_Ioc, h₀_finset_Ioo,
h₀_finset_mem_Icc, h₀_finset_mem_Ico, h₀_finset_mem_Ioc, h₀_finset_mem_Ioo⟩ := h₀
obtain ⟨h₁_finset_Icc, h₁_finset_Ico, h₁_finset_Ioc, h₁_finset_Ioo,
h₁_finset_mem_Icc, h₁_finset_mem_Ico, h₁_finset_mem_Ioc, h₁_finset_mem_Ioo⟩ := h₁
have hIcc : h₀_finset_Icc = h₁_finset_Icc := by
ext a b x
rw [h₀_finset_mem_Icc, h₁_finset_mem_Icc]
have hIco : h₀_finset_Ico = h₁_finset_Ico := by
ext a b x
rw [h₀_finset_mem_Ico, h₁_finset_mem_Ico]
have hIoc : h₀_finset_Ioc = h₁_finset_Ioc := by
ext a b x
rw [h₀_finset_mem_Ioc, h₁_finset_mem_Ioc]
have hIoo : h₀_finset_Ioo = h₁_finset_Ioo := by
ext a b x
rw [h₀_finset_mem_Ioo, h₁_finset_mem_Ioo]
simp_rw [hIcc, hIco, hIoc, hIoo]
instance : Subsingleton (LocallyFiniteOrderTop α) :=
Subsingleton.intro fun h₀ h₁ => by
obtain ⟨h₀_finset_Ioi, h₀_finset_Ici, h₀_finset_mem_Ici, h₀_finset_mem_Ioi⟩ := h₀
obtain ⟨h₁_finset_Ioi, h₁_finset_Ici, h₁_finset_mem_Ici, h₁_finset_mem_Ioi⟩ := h₁
have hIci : h₀_finset_Ici = h₁_finset_Ici := by
ext a b
rw [h₀_finset_mem_Ici, h₁_finset_mem_Ici]
have hIoi : h₀_finset_Ioi = h₁_finset_Ioi := by
ext a b
rw [h₀_finset_mem_Ioi, h₁_finset_mem_Ioi]
simp_rw [hIci, hIoi]
instance : Subsingleton (LocallyFiniteOrderBot α) :=
Subsingleton.intro fun h₀ h₁ => by
obtain ⟨h₀_finset_Iio, h₀_finset_Iic, h₀_finset_mem_Iic, h₀_finset_mem_Iio⟩ := h₀
obtain ⟨h₁_finset_Iio, h₁_finset_Iic, h₁_finset_mem_Iic, h₁_finset_mem_Iio⟩ := h₁
have hIic : h₀_finset_Iic = h₁_finset_Iic := by
ext a b
rw [h₀_finset_mem_Iic, h₁_finset_mem_Iic]
have hIio : h₀_finset_Iio = h₁_finset_Iio := by
ext a b
rw [h₀_finset_mem_Iio, h₁_finset_mem_Iio]
simp_rw [hIic, hIio]
-- Should this be called `LocallyFiniteOrder.lift`?
/-- Given an order embedding `α ↪o β`, pulls back the `LocallyFiniteOrder` on `β` to `α`. -/
protected noncomputable def OrderEmbedding.locallyFiniteOrder [LocallyFiniteOrder β] (f : α ↪o β) :
LocallyFiniteOrder α where
finsetIcc a b := (Icc (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIco a b := (Ico (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIoc a b := (Ioc (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIoo a b := (Ioo (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finset_mem_Icc a b x := by rw [mem_preimage, mem_Icc, f.le_iff_le, f.le_iff_le]
finset_mem_Ico a b x := by rw [mem_preimage, mem_Ico, f.le_iff_le, f.lt_iff_lt]
finset_mem_Ioc a b x := by rw [mem_preimage, mem_Ioc, f.lt_iff_lt, f.le_iff_le]
finset_mem_Ioo a b x := by rw [mem_preimage, mem_Ioo, f.lt_iff_lt, f.lt_iff_lt]
/-! ### `OrderDual` -/
open OrderDual
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] (a b : α)
/-- Note we define `Icc (toDual a) (toDual b)` as `Icc α _ _ b a` (which has type `Finset α` not
`Finset αᵒᵈ`!) instead of `(Icc b a).map toDual.toEmbedding` as this means the
following is defeq:
```
lemma this : (Icc (toDual (toDual a)) (toDual (toDual b)) :) = (Icc a b :) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrder : LocallyFiniteOrder αᵒᵈ where
finsetIcc a b := @Icc α _ _ (ofDual b) (ofDual a)
finsetIco a b := @Ioc α _ _ (ofDual b) (ofDual a)
finsetIoc a b := @Ico α _ _ (ofDual b) (ofDual a)
finsetIoo a b := @Ioo α _ _ (ofDual b) (ofDual a)
finset_mem_Icc _ _ _ := (mem_Icc (α := α)).trans and_comm
finset_mem_Ico _ _ _ := (mem_Ioc (α := α)).trans and_comm
finset_mem_Ioc _ _ _ := (mem_Ico (α := α)).trans and_comm
finset_mem_Ioo _ _ _ := (mem_Ioo (α := α)).trans and_comm
lemma Finset.Icc_orderDual_def (a b : αᵒᵈ) :
Icc a b = (Icc (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ico_orderDual_def (a b : αᵒᵈ) :
Ico a b = (Ioc (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ioc_orderDual_def (a b : αᵒᵈ) :
Ioc a b = (Ico (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ioo_orderDual_def (a b : αᵒᵈ) :
Ioo a b = (Ioo (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Icc_toDual : Icc (toDual a) (toDual b) = (Icc b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ico_toDual : Ico (toDual a) (toDual b) = (Ioc b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioc_toDual : Ioc (toDual a) (toDual b) = (Ico b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioo_toDual : Ioo (toDual a) (toDual b) = (Ioo b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Icc_ofDual (a b : αᵒᵈ) :
Icc (ofDual a) (ofDual b) = (Icc b a).map ofDual.toEmbedding := map_refl.symm
lemma Finset.Ico_ofDual (a b : αᵒᵈ) :
Ico (ofDual a) (ofDual b) = (Ioc b a).map ofDual.toEmbedding := map_refl.symm
lemma Finset.Ioc_ofDual (a b : αᵒᵈ) :
Ioc (ofDual a) (ofDual b) = (Ico b a).map ofDual.toEmbedding := map_refl.symm
lemma Finset.Ioo_ofDual (a b : αᵒᵈ) :
Ioo (ofDual a) (ofDual b) = (Ioo b a).map ofDual.toEmbedding := map_refl.symm
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α]
/-- Note we define `Iic (toDual a)` as `Ici a` (which has type `Finset α` not `Finset αᵒᵈ`!)
instead of `(Ici a).map toDual.toEmbedding` as this means the following is defeq:
```
lemma this : (Iic (toDual (toDual a)) :) = (Iic a :) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrderBot : LocallyFiniteOrderBot αᵒᵈ where
finsetIic a := @Ici α _ _ (ofDual a)
finsetIio a := @Ioi α _ _ (ofDual a)
finset_mem_Iic _ _ := mem_Ici (α := α)
finset_mem_Iio _ _ := mem_Ioi (α := α)
lemma Iic_orderDual_def (a : αᵒᵈ) : Iic a = (Ici (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Iio_orderDual_def (a : αᵒᵈ) : Iio a = (Ioi (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Iic_toDual (a : α) : Iic (toDual a) = (Ici a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Iio_toDual (a : α) : Iio (toDual a) = (Ioi a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ici_ofDual (a : αᵒᵈ) : Ici (ofDual a) = (Iic a).map ofDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioi_ofDual (a : αᵒᵈ) : Ioi (ofDual a) = (Iio a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrderTop
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderBot α]
/-- Note we define `Ici (toDual a)` as `Iic a` (which has type `Finset α` not `Finset αᵒᵈ`!)
instead of `(Iic a).map toDual.toEmbedding` as this means the following is defeq:
```
lemma this : (Ici (toDual (toDual a)) :) = (Ici a :) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrderTop : LocallyFiniteOrderTop αᵒᵈ where
finsetIci a := @Iic α _ _ (ofDual a)
finsetIoi a := @Iio α _ _ (ofDual a)
finset_mem_Ici _ _ := mem_Iic (α := α)
finset_mem_Ioi _ _ := mem_Iio (α := α)
lemma Ici_orderDual_def (a : αᵒᵈ) : Ici a = (Iic (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Ioi_orderDual_def (a : αᵒᵈ) : Ioi a = (Iio (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ici_toDual (a : α) : Ici (toDual a) = (Iic a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioi_toDual (a : α) : Ioi (toDual a) = (Iio a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Iic_ofDual (a : αᵒᵈ) : Iic (ofDual a) = (Ici a).map ofDual.toEmbedding :=
map_refl.symm
lemma Finset.Iio_ofDual (a : αᵒᵈ) : Iio (ofDual a) = (Ioi a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrderTop
/-! ### `Prod` -/
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)]
instance Prod.instLocallyFiniteOrder : LocallyFiniteOrder (α × β) :=
LocallyFiniteOrder.ofIcc' (α × β) (fun x y ↦ Icc x.1 y.1 ×ˢ Icc x.2 y.2) fun a b x => by
rw [mem_product, mem_Icc, mem_Icc, and_and_and_comm, le_def, le_def]
lemma Finset.Icc_prod_def (x y : α × β) : Icc x y = Icc x.1 y.1 ×ˢ Icc x.2 y.2 := rfl
lemma Finset.Icc_product_Icc (a₁ a₂ : α) (b₁ b₂ : β) :
Icc a₁ a₂ ×ˢ Icc b₁ b₂ = Icc (a₁, b₁) (a₂, b₂) := rfl
lemma Finset.card_Icc_prod (x y : α × β) : #(Icc x y) = #(Icc x.1 y.1) * #(Icc x.2 y.2) :=
card_product ..
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderTop β] [DecidableLE (α × β)]
instance Prod.instLocallyFiniteOrderTop : LocallyFiniteOrderTop (α × β) :=
LocallyFiniteOrderTop.ofIci' (α × β) (fun x => Ici x.1 ×ˢ Ici x.2) fun a x => by
rw [mem_product, mem_Ici, mem_Ici, le_def]
lemma Finset.Ici_prod_def (x : α × β) : Ici x = Ici x.1 ×ˢ Ici x.2 := rfl
lemma Finset.Ici_product_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) := rfl
lemma Finset.card_Ici_prod (x : α × β) : #(Ici x) = #(Ici x.1) * #(Ici x.2) :=
card_product _ _
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] [LocallyFiniteOrderBot β] [DecidableLE (α × β)]
instance Prod.instLocallyFiniteOrderBot : LocallyFiniteOrderBot (α × β) :=
LocallyFiniteOrderBot.ofIic' (α × β) (fun x ↦ Iic x.1 ×ˢ Iic x.2) fun a x ↦ by
rw [mem_product, mem_Iic, mem_Iic, le_def]
lemma Finset.Iic_prod_def (x : α × β) : Iic x = Iic x.1 ×ˢ Iic x.2 := rfl
lemma Finset.Iic_product_Iic (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) := rfl
lemma Finset.card_Iic_prod (x : α × β) : #(Iic x) = #(Iic x.1) * #(Iic x.2) := card_product ..
end LocallyFiniteOrderBot
end Preorder
section Lattice
variable [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)]
lemma Finset.uIcc_prod_def (x y : α × β) : uIcc x y = uIcc x.1 y.1 ×ˢ uIcc x.2 y.2 := rfl
lemma Finset.uIcc_product_uIcc (a₁ a₂ : α) (b₁ b₂ : β) :
uIcc a₁ a₂ ×ˢ uIcc b₁ b₂ = uIcc (a₁, b₁) (a₂, b₂) := rfl
lemma Finset.card_uIcc_prod (x y : α × β) : #(uIcc x y) = #(uIcc x.1 y.1) * #(uIcc x.2 y.2) :=
card_product ..
end Lattice
/-!
#### `WithTop`, `WithBot`
Adding a `⊤` to a locally finite `OrderTop` keeps it locally finite.
Adding a `⊥` to a locally finite `OrderBot` keeps it locally finite.
-/
namespace WithTop
/-- Given a finset on `α`, lift it to being a finset on `WithTop α`
using `WithTop.some` and then insert `⊤`. -/
def insertTop : Finset α ↪o Finset (WithTop α) :=
OrderEmbedding.ofMapLEIff
(fun s => cons ⊤ (s.map Embedding.coeWithTop) <| by simp)
(fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset])
@[simp]
theorem some_mem_insertTop {s : Finset α} {a : α} : ↑a ∈ insertTop s ↔ a ∈ s := by
simp [insertTop]
@[simp]
theorem top_mem_insertTop {s : Finset α} : ⊤ ∈ insertTop s := by
simp [insertTop]
variable (α) [PartialOrder α] [OrderTop α] [LocallyFiniteOrder α]
instance locallyFiniteOrder : LocallyFiniteOrder (WithTop α) where
finsetIcc a b :=
match a, b with
| ⊤, ⊤ => {⊤}
| ⊤, (b : α) => ∅
| (a : α), ⊤ => insertTop (Ici a)
| (a : α), (b : α) => (Icc a b).map Embedding.coeWithTop
finsetIco a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => (Ici a).map Embedding.coeWithTop
| (a : α), (b : α) => (Ico a b).map Embedding.coeWithTop
finsetIoc a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => insertTop (Ioi a)
| (a : α), (b : α) => (Ioc a b).map Embedding.coeWithTop
finsetIoo a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => (Ioi a).map Embedding.coeWithTop
| (a : α), (b : α) => (Ioo a b).map Embedding.coeWithTop
finset_mem_Icc a b x := by
cases a <;> cases b <;> cases x <;> simp
finset_mem_Ico a b x := by
cases a <;> cases b <;> cases x <;> simp
finset_mem_Ioc a b x := by
cases a <;> cases b <;> cases x <;> simp
finset_mem_Ioo a b x := by
cases a <;> cases b <;> cases x <;> simp
variable (a b : α)
theorem Icc_coe_top : Icc (a : WithTop α) ⊤ = insertNone (Ici a) :=
rfl
theorem Icc_coe_coe : Icc (a : WithTop α) b = (Icc a b).map Embedding.some :=
rfl
theorem Ico_coe_top : Ico (a : WithTop α) ⊤ = (Ici a).map Embedding.some :=
rfl
theorem Ico_coe_coe : Ico (a : WithTop α) b = (Ico a b).map Embedding.some :=
rfl
theorem Ioc_coe_top : Ioc (a : WithTop α) ⊤ = insertNone (Ioi a) :=
rfl
theorem Ioc_coe_coe : Ioc (a : WithTop α) b = (Ioc a b).map Embedding.some :=
rfl
theorem Ioo_coe_top : Ioo (a : WithTop α) ⊤ = (Ioi a).map Embedding.some :=
rfl
theorem Ioo_coe_coe : Ioo (a : WithTop α) b = (Ioo a b).map Embedding.some :=
rfl
end WithTop
namespace WithBot
/-- Given a finset on `α`, lift it to being a finset on `WithBot α`
using `WithBot.some` and then insert `⊥`. -/
def insertBot : Finset α ↪o Finset (WithBot α) :=
OrderEmbedding.ofMapLEIff
(fun s => cons ⊥ (s.map Embedding.coeWithBot) <| by simp)
(fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset])
@[simp]
theorem some_mem_insertBot {s : Finset α} {a : α} : ↑a ∈ insertBot s ↔ a ∈ s := by
simp [insertBot]
@[simp]
theorem bot_mem_insertBot {s : Finset α} : ⊥ ∈ insertBot s := by
simp [insertBot]
variable (α) [PartialOrder α] [OrderBot α] [LocallyFiniteOrder α]
instance instLocallyFiniteOrder : LocallyFiniteOrder (WithBot α) :=
OrderDual.instLocallyFiniteOrder (α := WithTop αᵒᵈ)
variable (a b : α)
theorem Icc_bot_coe : Icc (⊥ : WithBot α) b = insertNone (Iic b) :=
rfl
theorem Icc_coe_coe : Icc (a : WithBot α) b = (Icc a b).map Embedding.some :=
rfl
theorem Ico_bot_coe : Ico (⊥ : WithBot α) b = insertNone (Iio b) :=
rfl
theorem Ico_coe_coe : Ico (a : WithBot α) b = (Ico a b).map Embedding.some :=
rfl
theorem Ioc_bot_coe : Ioc (⊥ : WithBot α) b = (Iic b).map Embedding.some :=
rfl
theorem Ioc_coe_coe : Ioc (a : WithBot α) b = (Ioc a b).map Embedding.some :=
rfl
theorem Ioo_bot_coe : Ioo (⊥ : WithBot α) b = (Iio b).map Embedding.some :=
rfl
theorem Ioo_coe_coe : Ioo (a : WithBot α) b = (Ioo a b).map Embedding.some :=
rfl
end WithBot
namespace OrderIso
variable [Preorder α] [Preorder β]
/-! #### Transfer locally finite orders across order isomorphisms -/
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrder` across an `OrderIso`. -/
abbrev locallyFiniteOrder [LocallyFiniteOrder β] (f : α ≃o β) : LocallyFiniteOrder α where
finsetIcc a b := (Icc (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIco a b := (Ico (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIoc a b := (Ioc (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIoo a b := (Ioo (f a) (f b)).map f.symm.toEquiv.toEmbedding
finset_mem_Icc := by simp
finset_mem_Ico := by simp
finset_mem_Ioc := by simp
finset_mem_Ioo := by simp
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrderTop` across an `OrderIso`. -/
abbrev locallyFiniteOrderTop [LocallyFiniteOrderTop β] (f : α ≃o β) : LocallyFiniteOrderTop α where
finsetIci a := (Ici (f a)).map f.symm.toEquiv.toEmbedding
finsetIoi a := (Ioi (f a)).map f.symm.toEquiv.toEmbedding
finset_mem_Ici := by simp
finset_mem_Ioi := by simp
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrderBot` across an `OrderIso`. -/
abbrev locallyFiniteOrderBot [LocallyFiniteOrderBot β] (f : α ≃o β) : LocallyFiniteOrderBot α where
finsetIic a := (Iic (f a)).map f.symm.toEquiv.toEmbedding
finsetIio a := (Iio (f a)).map f.symm.toEquiv.toEmbedding
finset_mem_Iic := by simp
finset_mem_Iio := by simp
end OrderIso
/-! #### Subtype of a locally finite order -/
variable [Preorder α] (p : α → Prop) [DecidablePred p]
instance Subtype.instLocallyFiniteOrder [LocallyFiniteOrder α] :
LocallyFiniteOrder (Subtype p) where
finsetIcc a b := (Icc (a : α) b).subtype p
finsetIco a b := (Ico (a : α) b).subtype p
finsetIoc a b := (Ioc (a : α) b).subtype p
finsetIoo a b := (Ioo (a : α) b).subtype p
finset_mem_Icc a b x := by simp_rw [Finset.mem_subtype, mem_Icc, Subtype.coe_le_coe]
finset_mem_Ico a b x := by
simp_rw [Finset.mem_subtype, mem_Ico, Subtype.coe_le_coe, Subtype.coe_lt_coe]
finset_mem_Ioc a b x := by
simp_rw [Finset.mem_subtype, mem_Ioc, Subtype.coe_le_coe, Subtype.coe_lt_coe]
finset_mem_Ioo a b x := by simp_rw [Finset.mem_subtype, mem_Ioo, Subtype.coe_lt_coe]
instance Subtype.instLocallyFiniteOrderTop [LocallyFiniteOrderTop α] :
LocallyFiniteOrderTop (Subtype p) where
finsetIci a := (Ici (a : α)).subtype p
finsetIoi a := (Ioi (a : α)).subtype p
finset_mem_Ici a x := by simp_rw [Finset.mem_subtype, mem_Ici, Subtype.coe_le_coe]
finset_mem_Ioi a x := by simp_rw [Finset.mem_subtype, mem_Ioi, Subtype.coe_lt_coe]
instance Subtype.instLocallyFiniteOrderBot [LocallyFiniteOrderBot α] :
LocallyFiniteOrderBot (Subtype p) where
finsetIic a := (Iic (a : α)).subtype p
finsetIio a := (Iio (a : α)).subtype p
finset_mem_Iic a x := by simp_rw [Finset.mem_subtype, mem_Iic, Subtype.coe_le_coe]
finset_mem_Iio a x := by simp_rw [Finset.mem_subtype, mem_Iio, Subtype.coe_lt_coe]
namespace Finset
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] (a b : Subtype p)
theorem subtype_Icc_eq : Icc a b = (Icc (a : α) b).subtype p :=
rfl
theorem subtype_Ico_eq : Ico a b = (Ico (a : α) b).subtype p :=
rfl
theorem subtype_Ioc_eq : Ioc a b = (Ioc (a : α) b).subtype p :=
rfl
theorem subtype_Ioo_eq : Ioo a b = (Ioo (a : α) b).subtype p :=
rfl
theorem map_subtype_embedding_Icc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Icc a b).map (Embedding.subtype p) = (Icc a b : Finset α) := by
rw [subtype_Icc_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Icc] at hx
exact hp hx.1 hx.2 a.prop b.prop
theorem map_subtype_embedding_Ico (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Ico a b).map (Embedding.subtype p) = (Ico a b : Finset α) := by
rw [subtype_Ico_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ico] at hx
exact hp hx.1 hx.2.le a.prop b.prop
theorem map_subtype_embedding_Ioc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Ioc a b).map (Embedding.subtype p) = (Ioc a b : Finset α) := by
rw [subtype_Ioc_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ioc] at hx
exact hp hx.1.le hx.2 a.prop b.prop
theorem map_subtype_embedding_Ioo (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x):
(Ioo a b).map (Embedding.subtype p) = (Ioo a b : Finset α) := by
rw [subtype_Ioo_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ioo] at hx
exact hp hx.1.le hx.2.le a.prop b.prop
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] (a : Subtype p)
theorem subtype_Ici_eq : Ici a = (Ici (a : α)).subtype p :=
rfl
theorem subtype_Ioi_eq : Ioi a = (Ioi (a : α)).subtype p :=
rfl
theorem map_subtype_embedding_Ici (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) :
(Ici a).map (Embedding.subtype p) = (Ici a : Finset α) := by
rw [subtype_Ici_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ici.1 hx) a.prop
theorem map_subtype_embedding_Ioi (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) :
(Ioi a).map (Embedding.subtype p) = (Ioi a : Finset α) := by
rw [subtype_Ioi_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ioi.1 hx).le a.prop
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] (a : Subtype p)
theorem subtype_Iic_eq : Iic a = (Iic (a : α)).subtype p :=
rfl
theorem subtype_Iio_eq : Iio a = (Iio (a : α)).subtype p :=
rfl
theorem map_subtype_embedding_Iic (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) :
(Iic a).map (Embedding.subtype p) = (Iic a : Finset α) := by
rw [subtype_Iic_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iic.1 hx) a.prop
theorem map_subtype_embedding_Iio (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) :
(Iio a).map (Embedding.subtype p) = (Iio a : Finset α) := by
rw [subtype_Iio_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iio.1 hx).le a.prop
end LocallyFiniteOrderBot
end Finset
section Finite
variable {α : Type*} {s : Set α}
theorem BddBelow.finite_of_bddAbove [Preorder α] [LocallyFiniteOrder α]
{s : Set α} (h₀ : BddBelow s) (h₁ : BddAbove s) :
s.Finite :=
let ⟨a, ha⟩ := h₀
let ⟨b, hb⟩ := h₁
(Set.finite_Icc a b).subset fun _x hx ↦ ⟨ha hx, hb hx⟩
theorem Set.finite_iff_bddAbove [SemilatticeSup α] [LocallyFiniteOrder α] [OrderBot α] :
s.Finite ↔ BddAbove s :=
⟨fun h ↦ ⟨h.toFinset.sup id, fun _ hx ↦ Finset.le_sup (f := id) ((Finite.mem_toFinset h).mpr hx)⟩,
fun ⟨m, hm⟩ ↦ (Set.finite_Icc ⊥ m).subset (fun _ hx ↦ ⟨bot_le, hm hx⟩)⟩
theorem Set.finite_iff_bddBelow [SemilatticeInf α] [LocallyFiniteOrder α] [OrderTop α] :
s.Finite ↔ BddBelow s :=
finite_iff_bddAbove (α := αᵒᵈ)
theorem Set.finite_iff_bddBelow_bddAbove [Nonempty α] [Lattice α] [LocallyFiniteOrder α] :
s.Finite ↔ BddBelow s ∧ BddAbove s := by
obtain (rfl | hs) := s.eq_empty_or_nonempty
· simp only [Set.finite_empty, bddBelow_empty, bddAbove_empty, and_self]
exact ⟨fun h ↦ ⟨⟨h.toFinset.inf' ((Finite.toFinset_nonempty h).mpr hs) id,
fun x hx ↦ Finset.inf'_le id ((Finite.mem_toFinset h).mpr hx)⟩,
⟨h.toFinset.sup' ((Finite.toFinset_nonempty h).mpr hs) id, fun x hx ↦ Finset.le_sup' id
((Finite.mem_toFinset h).mpr hx)⟩⟩,
fun ⟨h₀, h₁⟩ ↦ BddBelow.finite_of_bddAbove h₀ h₁⟩
end Finite
/-! We make the instances below low priority
so when alternative constructions are available they are preferred. -/
variable {y : α}
instance (priority := low) [Preorder α] [DecidableLE α] [LocallyFiniteOrder α] :
LocallyFiniteOrderTop { x : α // x ≤ y } where
finsetIoi a := Finset.Ioc a ⟨y, by rfl⟩
finsetIci a := Finset.Icc a ⟨y, by rfl⟩
finset_mem_Ici a b := by
simp only [Finset.mem_Icc, and_iff_left_iff_imp]
exact fun _ => b.property
finset_mem_Ioi a b := by
simp only [Finset.mem_Ioc, and_iff_left_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableLT α] [LocallyFiniteOrder α] :
LocallyFiniteOrderTop { x : α // x < y } where
finsetIoi a := (Finset.Ioo ↑a y).subtype _
finsetIci a := (Finset.Ico ↑a y).subtype _
finset_mem_Ici a b := by
simp only [Finset.mem_subtype, Finset.mem_Ico, Subtype.coe_le_coe, and_iff_left_iff_imp]
exact fun _ => b.property
finset_mem_Ioi a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_left_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableLE α] [LocallyFiniteOrder α] :
LocallyFiniteOrderBot { x : α // y ≤ x } where
| finsetIio a := Finset.Ico ⟨y, by rfl⟩ a
finsetIic a := Finset.Icc ⟨y, by rfl⟩ a
finset_mem_Iic a b := by
simp only [Finset.mem_Icc, and_iff_right_iff_imp]
exact fun _ => b.property
finset_mem_Iio a b := by
simp only [Finset.mem_Ico, and_iff_right_iff_imp]
exact fun _ => b.property
| Mathlib/Order/Interval/Finset/Defs.lean | 1,254 | 1,262 |
/-
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, Floris van Doorn
-/
import Mathlib.Analysis.Calculus.ContDiff.Defs
import Mathlib.Analysis.Calculus.ContDiff.FaaDiBruno
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Mul
/-!
# Higher differentiability of composition
We prove that the composition of `C^n` functions is `C^n`.
We also expand the API around `C^n` functions.
## Main results
* `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`.
Similar results are given for `C^n` functions on domains.
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞` and `⊤ : WithTop ℕ∞` with `ω`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open scoped NNReal Nat ContDiff
universe u uE uF uG
attribute [local instance 1001]
NormedAddCommGroup.toAddCommGroup AddCommGroup.toAddCommMonoid
open Set Fin Filter Function
open scoped Topology
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF}
[NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s t : Set E} {f : E → F}
{g : F → G} {x x₀ : E} {b : E × F → G} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Constants -/
section constants
theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) :
iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↦ c) s = 0 := by
induction n with
| zero =>
ext1
simp [iteratedFDerivWithin_succ_eq_comp_left, iteratedFDerivWithin_zero_eq_comp, comp_def]
| succ n IH =>
rw [iteratedFDerivWithin_succ_eq_comp_left, IH]
simp only [Pi.zero_def, comp_def, fderivWithin_const, map_zero]
@[simp]
theorem iteratedFDerivWithin_zero_fun {i : ℕ} :
iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s = 0 := by
cases i with
| zero => ext; simp
| succ i => apply iteratedFDerivWithin_succ_const
@[simp]
theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 :=
funext fun x ↦ by simp only [← iteratedFDerivWithin_univ, iteratedFDerivWithin_zero_fun]
theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) :=
analyticOnNhd_const.contDiff
/-- Constants are `C^∞`. -/
theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c :=
analyticOnNhd_const.contDiff
theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s :=
contDiff_const.contDiffOn
theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x :=
contDiff_const.contDiffAt
theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x :=
contDiffAt_const.contDiffWithinAt
@[nontriviality]
theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const
@[nontriviality]
theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const
@[nontriviality]
theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const
@[nontriviality]
theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const
theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) (s : Set E) :
iteratedFDerivWithin 𝕜 n (fun _ : E ↦ c) s = 0 := by
cases n with
| zero => contradiction
| succ n => exact iteratedFDerivWithin_succ_const n c
theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) :
(iteratedFDeriv 𝕜 n fun _ : E ↦ c) = 0 := by
simp only [← iteratedFDerivWithin_univ, iteratedFDerivWithin_const_of_ne hn]
theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) :
(iteratedFDeriv 𝕜 (n + 1) fun _ : E ↦ c) = 0 :=
iteratedFDeriv_const_of_ne (by simp) _
theorem contDiffWithinAt_singleton : ContDiffWithinAt 𝕜 n f {x} x :=
(contDiffWithinAt_const (c := f x)).congr (by simp) rfl
end constants
/-! ### Smoothness of linear functions -/
section linear
/-- Unbundled bounded linear functions are `C^n`. -/
theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f :=
(ContinuousLinearMap.analyticOnNhd hf.toContinuousLinearMap univ).contDiff
theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f :=
f.isBoundedLinearMap.contDiff
theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
f.toContinuousLinearMap.contDiff
theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
/-- The identity is `C^n`. -/
theorem contDiff_id : ContDiff 𝕜 n (id : E → E) :=
IsBoundedLinearMap.id.contDiff
theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x :=
contDiff_id.contDiffWithinAt
theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x :=
contDiff_id.contDiffAt
theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s :=
contDiff_id.contDiffOn
/-- Bilinear functions are `C^n`. -/
theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b :=
(hb.toContinuousLinearMap.analyticOnNhd_bilinear _).contDiff
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor
series whose `k`-th term is given by `g ∘ (p k)`. -/
theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp {n : WithTop ℕ∞} (g : F →L[𝕜] G)
(hf : HasFTaylorSeriesUpToOn n f p s) :
HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where
zero_eq x hx := congr_arg g (hf.zero_eq x hx)
fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx)
cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm)
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
refine ⟨u, hu, _, hp.continuousLinearMap_comp g, fun i ↦ ?_⟩
change AnalyticOn 𝕜
(fun x ↦ (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin i ↦ E) F G g) (p x i)) u
apply AnalyticOnNhd.comp_analyticOn _ (h'p i) (Set.mapsTo_univ _ _)
exact ContinuousLinearMap.analyticOnNhd _ _
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
exact ⟨u, hu, _, hp.continuousLinearMap_comp g⟩
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
ContDiffWithinAt.continuousLinearMap_comp g hf
/-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/
theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g
/-- Composition by continuous linear maps on the left preserves `C^n` functions. -/
theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n fun x => g (f x) :=
contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf)
/-- The iterated derivative within a set of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by
rcases hf.contDiffOn' hi (by simp) with ⟨U, hU, hxU, hfU⟩
rw [← iteratedFDerivWithin_inter_open hU hxU, ← iteratedFDerivWithin_inter_open (f := f) hU hxU]
rw [insert_eq_of_mem hx] at hfU
exact .symm <| (hfU.ftaylorSeriesWithin (hs.inter hU)).continuousLinearMap_comp g
|>.eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter hU) ⟨hx, hxU⟩
/-- The iterated derivative of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffAt 𝕜 n f x) {i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by
simp only [← iteratedFDerivWithin_univ]
exact g.iteratedFDerivWithin_comp_left hf.contDiffWithinAt uniqueDiffOn_univ (mem_univ x) hi
/-- The iterated derivative within a set of the composition with a linear equiv on the left is
obtained by applying the linear equiv to the iterated derivative. This is true without
differentiability assumptions. -/
theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_left (g : F ≃L[𝕜] G) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by
induction' i with i IH generalizing x
· ext1 m
simp only [iteratedFDerivWithin_zero_apply, comp_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, coe_coe]
· ext1 m
rw [iteratedFDerivWithin_succ_apply_left]
have Z : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (g ∘ f) s) s x =
fderivWithin 𝕜 (g.continuousMultilinearMapCongrRight (fun _ : Fin i => E) ∘
iteratedFDerivWithin 𝕜 i f s) s x :=
fderivWithin_congr' (@IH) hx
simp_rw [Z]
rw [(g.continuousMultilinearMapCongrRight fun _ : Fin i => E).comp_fderivWithin (hs x hx)]
simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply,
ContinuousLinearEquiv.continuousMultilinearMapCongrRight_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, EmbeddingLike.apply_eq_iff_eq]
rw [iteratedFDerivWithin_succ_apply_left]
/-- Composition with a linear isometry on the left preserves the norm of the iterated
derivative within a set. -/
theorem LinearIsometry.norm_iteratedFDerivWithin_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : i ≤ n) :
‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by
have :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.toContinuousLinearMap.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
g.toContinuousLinearMap.iteratedFDerivWithin_comp_left hf hs hx hi
rw [this]
apply LinearIsometry.norm_compContinuousMultilinearMap
/-- Composition with a linear isometry on the left preserves the norm of the iterated
derivative. -/
theorem LinearIsometry.norm_iteratedFDeriv_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G)
(hf : ContDiffAt 𝕜 n f x) {i : ℕ} (hi : i ≤ n) :
‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by
simp only [← iteratedFDerivWithin_univ]
exact g.norm_iteratedFDerivWithin_comp_left hf.contDiffWithinAt uniqueDiffOn_univ (mem_univ x) hi
/-- Composition with a linear isometry equiv on the left preserves the norm of the iterated
derivative within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) :
‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by
have :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_left f hs hx i
rw [this]
apply LinearIsometry.norm_compContinuousMultilinearMap g.toLinearIsometry
/-- Composition with a linear isometry equiv on the left preserves the norm of the iterated
derivative. -/
theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (x : E)
(i : ℕ) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by
rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ]
apply g.norm_iteratedFDerivWithin_comp_left f uniqueDiffOn_univ (mem_univ x) i
/-- Composition by continuous linear equivs on the left respects higher differentiability at a
point in a domain. -/
theorem ContinuousLinearEquiv.comp_contDiffWithinAt_iff (e : F ≃L[𝕜] G) :
ContDiffWithinAt 𝕜 n (e ∘ f) s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H => by
simpa only [Function.comp_def, e.symm.coe_coe, e.symm_apply_apply] using
H.continuousLinearMap_comp (e.symm : G →L[𝕜] F),
fun H => H.continuousLinearMap_comp (e : F →L[𝕜] G)⟩
/-- Composition by continuous linear equivs on the left respects higher differentiability at a
point. -/
theorem ContinuousLinearEquiv.comp_contDiffAt_iff (e : F ≃L[𝕜] G) :
ContDiffAt 𝕜 n (e ∘ f) x ↔ ContDiffAt 𝕜 n f x := by
simp only [← contDiffWithinAt_univ, e.comp_contDiffWithinAt_iff]
/-- Composition by continuous linear equivs on the left respects higher differentiability on
domains. -/
theorem ContinuousLinearEquiv.comp_contDiffOn_iff (e : F ≃L[𝕜] G) :
ContDiffOn 𝕜 n (e ∘ f) s ↔ ContDiffOn 𝕜 n f s := by
simp [ContDiffOn, e.comp_contDiffWithinAt_iff]
/-- Composition by continuous linear equivs on the left respects higher differentiability. -/
theorem ContinuousLinearEquiv.comp_contDiff_iff (e : F ≃L[𝕜] G) :
ContDiff 𝕜 n (e ∘ f) ↔ ContDiff 𝕜 n f := by
simp only [← contDiffOn_univ, e.comp_contDiffOn_iff]
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor
series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/
theorem HasFTaylorSeriesUpToOn.compContinuousLinearMap
(hf : HasFTaylorSeriesUpToOn n f p s) (g : G →L[𝕜] E) :
HasFTaylorSeriesUpToOn n (f ∘ g) (fun x k => (p (g x) k).compContinuousLinearMap fun _ => g)
(g ⁻¹' s) := by
let A : ∀ m : ℕ, (E[×m]→L[𝕜] F) → G[×m]→L[𝕜] F := fun m h => h.compContinuousLinearMap fun _ => g
have hA : ∀ m, IsBoundedLinearMap 𝕜 (A m) := fun m =>
isBoundedLinearMap_continuousMultilinearMap_comp_linear g
constructor
· intro x hx
simp only [(hf.zero_eq (g x) hx).symm, Function.comp_apply]
change (p (g x) 0 fun _ : Fin 0 => g 0) = p (g x) 0 0
rw [ContinuousLinearMap.map_zero]
rfl
· intro m hm x hx
convert (hA m).hasFDerivAt.comp_hasFDerivWithinAt x
((hf.fderivWithin m hm (g x) hx).comp x g.hasFDerivWithinAt (Subset.refl _))
ext y v
change p (g x) (Nat.succ m) (g ∘ cons y v) = p (g x) m.succ (cons (g y) (g ∘ v))
rw [comp_cons]
· intro m hm
exact (hA m).continuous.comp_continuousOn <| (hf.cont m hm).comp g.continuous.continuousOn <|
Subset.refl _
/-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on
a domain. -/
theorem ContDiffWithinAt.comp_continuousLinearMap {x : G} (g : G →L[𝕜] E)
(hf : ContDiffWithinAt 𝕜 n f s (g x)) : ContDiffWithinAt 𝕜 n (f ∘ g) (g ⁻¹' s) x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g, ?_⟩
· refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu
exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _)
· intro i
change AnalyticOn 𝕜 (fun x ↦
ContinuousMultilinearMap.compContinuousLinearMapL (fun _ ↦ g) (p (g x) i)) (⇑g ⁻¹' u)
apply AnalyticOn.comp _ _ (Set.mapsTo_univ _ _)
· exact ContinuousLinearEquiv.analyticOn _ _
· exact (h'p i).comp (g.analyticOn _) (mapsTo_preimage _ _)
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g⟩
refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu
exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _)
/-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/
theorem ContDiffOn.comp_continuousLinearMap (hf : ContDiffOn 𝕜 n f s) (g : G →L[𝕜] E) :
ContDiffOn 𝕜 n (f ∘ g) (g ⁻¹' s) := fun x hx => (hf (g x) hx).comp_continuousLinearMap g
/-- Composition by continuous linear maps on the right preserves `C^n` functions. -/
theorem ContDiff.comp_continuousLinearMap {f : E → F} {g : G →L[𝕜] E} (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n (f ∘ g) :=
contDiffOn_univ.1 <| ContDiffOn.comp_continuousLinearMap (contDiffOn_univ.2 hf) _
/-- The iterated derivative within a set of the composition with a linear map on the right is
obtained by composing the iterated derivative with the linear map. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_right {f : E → F} (g : G →L[𝕜] E)
(hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (h's : UniqueDiffOn 𝕜 (g ⁻¹' s)) {x : G}
(hx : g x ∈ s) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g :=
((((hf.of_le hi).ftaylorSeriesWithin hs).compContinuousLinearMap
g).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl h's hx).symm
/-- The iterated derivative within a set of the composition with a linear equiv on the right is
obtained by composing the iterated derivative with the linear equiv. -/
theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_right (g : G ≃L[𝕜] E) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) :
iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := by
induction' i with i IH generalizing x
· ext1
simp only [iteratedFDerivWithin_zero_apply, comp_apply,
ContinuousMultilinearMap.compContinuousLinearMap_apply]
· ext1 m
simp only [ContinuousMultilinearMap.compContinuousLinearMap_apply,
ContinuousLinearEquiv.coe_coe, iteratedFDerivWithin_succ_apply_left]
have : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s)) (g ⁻¹' s) x =
fderivWithin 𝕜
(ContinuousLinearEquiv.continuousMultilinearMapCongrLeft _ (fun _x : Fin i => g) ∘
(iteratedFDerivWithin 𝕜 i f s ∘ g)) (g ⁻¹' s) x :=
fderivWithin_congr' (@IH) hx
rw [this, ContinuousLinearEquiv.comp_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx)]
simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply,
ContinuousLinearEquiv.continuousMultilinearMapCongrLeft_apply,
ContinuousMultilinearMap.compContinuousLinearMap_apply]
rw [ContinuousLinearEquiv.comp_right_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx),
ContinuousLinearMap.coe_comp', coe_coe, comp_apply, tail_def, tail_def]
/-- The iterated derivative of the composition with a linear map on the right is
obtained by composing the iterated derivative with the linear map. -/
theorem ContinuousLinearMap.iteratedFDeriv_comp_right (g : G →L[𝕜] E) {f : E → F}
(hf : ContDiff 𝕜 n f) (x : G) {i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (f ∘ g) x =
(iteratedFDeriv 𝕜 i f (g x)).compContinuousLinearMap fun _ => g := by
simp only [← iteratedFDerivWithin_univ]
exact g.iteratedFDerivWithin_comp_right hf.contDiffOn uniqueDiffOn_univ uniqueDiffOn_univ
(mem_univ _) hi
/-- Composition with a linear isometry on the right preserves the norm of the iterated derivative
within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) :
‖iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x‖ = ‖iteratedFDerivWithin 𝕜 i f s (g x)‖ := by
have : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g :=
g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_right f hs hx i
rw [this, ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv]
/-- Composition with a linear isometry on the right preserves the norm of the iterated derivative
within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (x : G)
(i : ℕ) : ‖iteratedFDeriv 𝕜 i (f ∘ g) x‖ = ‖iteratedFDeriv 𝕜 i f (g x)‖ := by
simp only [← iteratedFDerivWithin_univ]
apply g.norm_iteratedFDerivWithin_comp_right f uniqueDiffOn_univ (mem_univ (g x)) i
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point in a domain. -/
theorem ContinuousLinearEquiv.contDiffWithinAt_comp_iff (e : G ≃L[𝕜] E) :
ContDiffWithinAt 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ ContDiffWithinAt 𝕜 n f s x := by
constructor
· intro H
simpa [← preimage_comp, Function.comp_def] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G)
· intro H
rw [← e.apply_symm_apply x, ← e.coe_coe] at H
exact H.comp_continuousLinearMap _
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point. -/
theorem ContinuousLinearEquiv.contDiffAt_comp_iff (e : G ≃L[𝕜] E) :
ContDiffAt 𝕜 n (f ∘ e) (e.symm x) ↔ ContDiffAt 𝕜 n f x := by
rw [← contDiffWithinAt_univ, ← contDiffWithinAt_univ, ← preimage_univ]
exact e.contDiffWithinAt_comp_iff
/-- Composition by continuous linear equivs on the right respects higher differentiability on
domains. -/
theorem ContinuousLinearEquiv.contDiffOn_comp_iff (e : G ≃L[𝕜] E) :
ContDiffOn 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => by simpa [Function.comp_def] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G),
fun H => H.comp_continuousLinearMap (e : G →L[𝕜] E)⟩
/-- Composition by continuous linear equivs on the right respects higher differentiability. -/
theorem ContinuousLinearEquiv.contDiff_comp_iff (e : G ≃L[𝕜] E) :
ContDiff 𝕜 n (f ∘ e) ↔ ContDiff 𝕜 n f := by
rw [← contDiffOn_univ, ← contDiffOn_univ, ← preimage_univ]
exact e.contDiffOn_comp_iff
end linear
/-! ### The Cartesian product of two C^n functions is C^n. -/
section prod
/-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian
product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/
theorem HasFTaylorSeriesUpToOn.prodMk {n : WithTop ℕ∞}
(hf : HasFTaylorSeriesUpToOn n f p s) {g : E → G}
{q : E → FormalMultilinearSeries 𝕜 E G} (hg : HasFTaylorSeriesUpToOn n g q s) :
HasFTaylorSeriesUpToOn n (fun y => (f y, g y)) (fun y k => (p y k).prod (q y k)) s := by
set L := fun m => ContinuousMultilinearMap.prodL 𝕜 (fun _ : Fin m => E) F G
constructor
· intro x hx; rw [← hf.zero_eq x hx, ← hg.zero_eq x hx]; rfl
· intro m hm x hx
convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x
((hf.fderivWithin m hm x hx).prodMk (hg.fderivWithin m hm x hx))
· intro m hm
exact (L m).continuous.comp_continuousOn ((hf.cont m hm).prodMk (hg.cont m hm))
@[deprecated (since := "2025-03-09")]
alias HasFTaylorSeriesUpToOn.prod := HasFTaylorSeriesUpToOn.prodMk
/-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/
theorem ContDiffWithinAt.prodMk {s : Set E} {f : E → F} {g : E → G}
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
ContDiffWithinAt 𝕜 n (fun x : E => (f x, g x)) s x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
obtain ⟨v, hv, q, hq, h'q⟩ := hg
refine ⟨u ∩ v, Filter.inter_mem hu hv, _,
(hp.mono inter_subset_left).prodMk (hq.mono inter_subset_right), fun i ↦ ?_⟩
change AnalyticOn 𝕜 (fun x ↦ ContinuousMultilinearMap.prodL _ _ _ _ (p x i, q x i)) (u ∩ v)
apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn _ (Set.mapsTo_univ _ _)
exact ((h'p i).mono inter_subset_left).prod ((h'q i).mono inter_subset_right)
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
rcases hg m hm with ⟨v, hv, q, hq⟩
exact ⟨u ∩ v, Filter.inter_mem hu hv, _,
(hp.mono inter_subset_left).prodMk (hq.mono inter_subset_right)⟩
@[deprecated (since := "2025-03-09")]
alias ContDiffWithinAt.prod := ContDiffWithinAt.prodMk
/-- The cartesian product of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.prodMk {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x : E => (f x, g x)) s := fun x hx =>
(hf x hx).prodMk (hg x hx)
@[deprecated (since := "2025-03-09")]
alias ContDiffOn.prod := ContDiffOn.prodMk
/-- The cartesian product of `C^n` functions at a point is `C^n`. -/
theorem ContDiffAt.prodMk {f : E → F} {g : E → G} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x : E => (f x, g x)) x :=
contDiffWithinAt_univ.1 <| hf.contDiffWithinAt.prodMk hg.contDiffWithinAt
@[deprecated (since := "2025-03-09")]
alias ContDiffAt.prod := ContDiffAt.prodMk
/-- The cartesian product of `C^n` functions is `C^n`. -/
theorem ContDiff.prodMk {f : E → F} {g : E → G} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x : E => (f x, g x) :=
contDiffOn_univ.1 <| hf.contDiffOn.prodMk hg.contDiffOn
@[deprecated (since := "2025-03-09")]
alias ContDiff.prod := ContDiff.prodMk
end prod
section comp
/-!
### Composition of `C^n` functions
We show that the composition of `C^n` functions is `C^n`. One way to do this would be to
use the following simple inductive proof. Assume it is done for `n`.
Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e.,
that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so
it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix
multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to
`x ↦ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done.
There are two difficulties in this proof.
The first one is that it is an induction over all Banach
spaces. In Lean, this is only possible if they belong to a fixed universe. One could formalize this
by first proving the statement in this case, and then extending the result to general universes
by embedding all the spaces we consider in a common universe through `ULift`.
The second one is that it does not work cleanly for analytic maps: for this case, we need to
exhibit a whole sequence of derivatives which are all analytic, not just finitely many of them, so
an induction is never enough at a finite step.
Both these difficulties can be overcome with some cost. However, we choose a different path: we
write down an explicit formula for the `n`-th derivative of `g ∘ f` in terms of derivatives of
`g` and `f` (this is the formula of Faa-Di Bruno) and use this formula to get a suitable Taylor
expansion for `g ∘ f`. Writing down the formula of Faa-Di Bruno is not easy as the formula is quite
intricate, but it is also useful for other purposes and once available it makes the proof here
essentially trivial.
-/
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (st : MapsTo f s t) :
ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
match n with
| ω =>
have h'f : ContDiffWithinAt 𝕜 ω f s x := hf
obtain ⟨u, hu, p, hp, h'p⟩ := h'f
obtain ⟨v, hv, q, hq, h'q⟩ := hg
let w := insert x s ∩ (u ∩ f ⁻¹' v)
have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
have wu : w ⊆ u := fun y hy => hy.2.1
refine ⟨w, ?_, fun y ↦ (q (f y)).taylorComp (p y), hq.comp (hp.mono wu) wv, ?_⟩
· apply inter_mem self_mem_nhdsWithin (inter_mem hu ?_)
apply (continuousWithinAt_insert_self.2 hf.continuousWithinAt).preimage_mem_nhdsWithin'
apply nhdsWithin_mono _ _ hv
simp only [image_insert_eq]
apply insert_subset_insert
exact image_subset_iff.mpr st
· have : AnalyticOn 𝕜 f w := by
have : AnalyticOn 𝕜 (fun y ↦ (continuousMultilinearCurryFin0 𝕜 E F).symm (f y)) w :=
((h'p 0).mono wu).congr fun y hy ↦ (hp.zero_eq' (wu hy)).symm
have : AnalyticOn 𝕜 (fun y ↦ (continuousMultilinearCurryFin0 𝕜 E F)
((continuousMultilinearCurryFin0 𝕜 E F).symm (f y))) w :=
AnalyticOnNhd.comp_analyticOn (LinearIsometryEquiv.analyticOnNhd _ _ ) this
(mapsTo_univ _ _)
simpa using this
exact analyticOn_taylorComp h'q (fun n ↦ (h'p n).mono wu) this wv
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
rcases hg m hm with ⟨v, hv, q, hq⟩
let w := insert x s ∩ (u ∩ f ⁻¹' v)
have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
have wu : w ⊆ u := fun y hy => hy.2.1
refine ⟨w, ?_, fun y ↦ (q (f y)).taylorComp (p y), hq.comp (hp.mono wu) wv⟩
apply inter_mem self_mem_nhdsWithin (inter_mem hu ?_)
apply (continuousWithinAt_insert_self.2 hf.continuousWithinAt).preimage_mem_nhdsWithin'
apply nhdsWithin_mono _ _ hv
simp only [image_insert_eq]
apply insert_subset_insert
exact image_subset_iff.mpr st
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
(hf : ContDiffOn 𝕜 n f s) (st : MapsTo f s t) : ContDiffOn 𝕜 n (g ∘ f) s :=
fun x hx ↦ ContDiffWithinAt.comp x (hg (f x) (st hx)) (hf x hx) st
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp_inter
{s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
(hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) :=
hg.comp (hf.mono inter_subset_left) inter_subset_right
@[deprecated (since := "2024-10-30")] alias ContDiffOn.comp' := ContDiffOn.comp_inter
/-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/
theorem ContDiff.comp_contDiffOn {s : Set E} {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g)
(hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s :=
(contDiffOn_univ.2 hg).comp hf (mapsTo_univ _ _)
theorem ContDiffOn.comp_contDiff {s : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g s)
(hf : ContDiff 𝕜 n f) (hs : ∀ x, f x ∈ s) : ContDiff 𝕜 n (g ∘ f) := by
rw [← contDiffOn_univ] at *
exact hg.comp hf fun x _ => hs x
theorem ContDiffOn.image_comp_contDiff {s : Set E} {g : F → G} {f : E → F}
(hg : ContDiffOn 𝕜 n g (f '' s)) (hf : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n (g ∘ f) s :=
hg.comp hf.contDiffOn (s.mapsTo_image f)
/-- The composition of `C^n` functions is `C^n`. -/
theorem ContDiff.comp {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n (g ∘ f) :=
contDiffOn_univ.1 <| ContDiffOn.comp (contDiffOn_univ.2 hg) (contDiffOn_univ.2 hf) (subset_univ _)
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp_of_eq {s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x) (st : MapsTo f s t)
(hy : f x = y) :
ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp x hf st
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_mem_nhdsWithin_image
{s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : t ∈ 𝓝[f '' s] f x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
(hg.mono_of_mem_nhdsWithin hs).comp x hf (subset_preimage_image f s)
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_mem_nhdsWithin_image_of_eq
{s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : t ∈ 𝓝[f '' s] f x) (hy : f x = y) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp_of_mem_nhdsWithin_image x hf hs
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp_inter {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x :=
hg.comp x (hf.mono inter_subset_left) inter_subset_right
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp_inter_of_eq {s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F}
(x : E) (hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x) (hy : f x = y) :
ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x := by
subst hy; exact hg.comp_inter x hf
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_preimage_mem_nhdsWithin
{s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : f ⁻¹' t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
(hg.comp_inter x hf).mono_of_mem_nhdsWithin (inter_mem self_mem_nhdsWithin hs)
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_preimage_mem_nhdsWithin_of_eq
{s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : f ⁻¹' t ∈ 𝓝[s] x) (hy : f x = y) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp_of_preimage_mem_nhdsWithin x hf hs
theorem ContDiffAt.comp_contDiffWithinAt (x : E) (hg : ContDiffAt 𝕜 n g (f x))
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
hg.comp x hf (mapsTo_univ _ _)
theorem ContDiffAt.comp_contDiffWithinAt_of_eq {y : F} (x : E) (hg : ContDiffAt 𝕜 n g y)
(hf : ContDiffWithinAt 𝕜 n f s x) (hy : f x = y) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp_contDiffWithinAt x hf
/-- The composition of `C^n` functions at points is `C^n`. -/
nonrec theorem ContDiffAt.comp (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
hg.comp x hf (mapsTo_univ _ _)
theorem ContDiff.comp_contDiffWithinAt {g : F → G} {f : E → F} (h : ContDiff 𝕜 n g)
(hf : ContDiffWithinAt 𝕜 n f t x) : ContDiffWithinAt 𝕜 n (g ∘ f) t x :=
haveI : ContDiffWithinAt 𝕜 n g univ (f x) := h.contDiffAt.contDiffWithinAt
this.comp x hf (subset_univ _)
theorem ContDiff.comp_contDiffAt {g : F → G} {f : E → F} (x : E) (hg : ContDiff 𝕜 n g)
(hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x :=
hg.comp_contDiffWithinAt hf
theorem iteratedFDerivWithin_comp_of_eventually_mem {t : Set F}
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(ht : UniqueDiffOn 𝕜 t) (hs : UniqueDiffOn 𝕜 s) (hxs : x ∈ s) (hst : ∀ᶠ y in 𝓝[s] x, f y ∈ t)
{i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(ftaylorSeriesWithin 𝕜 g t (f x)).taylorComp (ftaylorSeriesWithin 𝕜 f s x) i := by
obtain ⟨u, hxu, huo, hfu, hgu⟩ : ∃ u, x ∈ u ∧ IsOpen u ∧
HasFTaylorSeriesUpToOn i f (ftaylorSeriesWithin 𝕜 f s) (s ∩ u) ∧
HasFTaylorSeriesUpToOn i g (ftaylorSeriesWithin 𝕜 g t) (f '' (s ∩ u)) := by
have hxt : f x ∈ t := hst.self_of_nhdsWithin hxs
have hf_tendsto : Tendsto f (𝓝[s] x) (𝓝[t] (f x)) :=
tendsto_nhdsWithin_iff.mpr ⟨hf.continuousWithinAt, hst⟩
have H₁ : ∀ᶠ u in (𝓝[s] x).smallSets,
HasFTaylorSeriesUpToOn i f (ftaylorSeriesWithin 𝕜 f s) u :=
hf.eventually_hasFTaylorSeriesUpToOn hs hxs hi
have H₂ : ∀ᶠ u in (𝓝[s] x).smallSets,
HasFTaylorSeriesUpToOn i g (ftaylorSeriesWithin 𝕜 g t) (f '' u) :=
hf_tendsto.image_smallSets.eventually (hg.eventually_hasFTaylorSeriesUpToOn ht hxt hi)
rcases (nhdsWithin_basis_open _ _).smallSets.eventually_iff.mp (H₁.and H₂)
with ⟨u, ⟨hxu, huo⟩, hu⟩
exact ⟨u, hxu, huo, hu (by simp [inter_comm])⟩
exact .symm <| (hgu.comp hfu (mapsTo_image _ _)).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl
(hs.inter huo) ⟨hxs, hxu⟩ |>.trans <| iteratedFDerivWithin_inter_open huo hxu
theorem iteratedFDerivWithin_comp {t : Set F} (hg : ContDiffWithinAt 𝕜 n g t (f x))
(hf : ContDiffWithinAt 𝕜 n f s x) (ht : UniqueDiffOn 𝕜 t) (hs : UniqueDiffOn 𝕜 s)
(hx : x ∈ s) (hst : MapsTo f s t) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(ftaylorSeriesWithin 𝕜 g t (f x)).taylorComp (ftaylorSeriesWithin 𝕜 f s x) i :=
iteratedFDerivWithin_comp_of_eventually_mem hg hf ht hs hx (eventually_mem_nhdsWithin.mono hst) hi
theorem iteratedFDeriv_comp (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x)
{i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (g ∘ f) x =
(ftaylorSeries 𝕜 g (f x)).taylorComp (ftaylorSeries 𝕜 f x) i := by
simp only [← iteratedFDerivWithin_univ, ← ftaylorSeriesWithin_univ]
exact iteratedFDerivWithin_comp hg.contDiffWithinAt hf.contDiffWithinAt
uniqueDiffOn_univ uniqueDiffOn_univ (mem_univ _) (mapsTo_univ _ _) hi
end comp
/-!
### Smoothness of projections
-/
/-- The first projection in a product is `C^∞`. -/
theorem contDiff_fst : ContDiff 𝕜 n (Prod.fst : E × F → E) :=
IsBoundedLinearMap.contDiff IsBoundedLinearMap.fst
/-- Postcomposing `f` with `Prod.fst` is `C^n` -/
theorem ContDiff.fst {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).1 :=
contDiff_fst.comp hf
/-- Precomposing `f` with `Prod.fst` is `C^n` -/
theorem ContDiff.fst' {f : E → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.1 :=
hf.comp contDiff_fst
/-- The first projection on a domain in a product is `C^∞`. -/
theorem contDiffOn_fst {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.fst : E × F → E) s :=
ContDiff.contDiffOn contDiff_fst
theorem ContDiffOn.fst {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (f x).1) s :=
contDiff_fst.comp_contDiffOn hf
/-- The first projection at a point in a product is `C^∞`. -/
theorem contDiffAt_fst {p : E × F} : ContDiffAt 𝕜 n (Prod.fst : E × F → E) p :=
contDiff_fst.contDiffAt
/-- Postcomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/
theorem ContDiffAt.fst {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (f x).1) x :=
contDiffAt_fst.comp x hf
/-- Precomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/
theorem ContDiffAt.fst' {f : E → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x : E × F => f x.1) (x, y) :=
ContDiffAt.comp (x, y) hf contDiffAt_fst
/-- Precomposing `f` with `Prod.fst` is `C^n` at `x : E × F` -/
theorem ContDiffAt.fst'' {f : E → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.1) :
ContDiffAt 𝕜 n (fun x : E × F => f x.1) x :=
hf.comp x contDiffAt_fst
/-- The first projection within a domain at a point in a product is `C^∞`. -/
theorem contDiffWithinAt_fst {s : Set (E × F)} {p : E × F} :
ContDiffWithinAt 𝕜 n (Prod.fst : E × F → E) s p :=
contDiff_fst.contDiffWithinAt
/-- The second projection in a product is `C^∞`. -/
theorem contDiff_snd : ContDiff 𝕜 n (Prod.snd : E × F → F) :=
IsBoundedLinearMap.contDiff IsBoundedLinearMap.snd
/-- Postcomposing `f` with `Prod.snd` is `C^n` -/
theorem ContDiff.snd {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).2 :=
contDiff_snd.comp hf
/-- Precomposing `f` with `Prod.snd` is `C^n` -/
theorem ContDiff.snd' {f : F → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.2 :=
hf.comp contDiff_snd
/-- The second projection on a domain in a product is `C^∞`. -/
theorem contDiffOn_snd {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.snd : E × F → F) s :=
ContDiff.contDiffOn contDiff_snd
theorem ContDiffOn.snd {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (f x).2) s :=
contDiff_snd.comp_contDiffOn hf
/-- The second projection at a point in a product is `C^∞`. -/
theorem contDiffAt_snd {p : E × F} : ContDiffAt 𝕜 n (Prod.snd : E × F → F) p :=
contDiff_snd.contDiffAt
/-- Postcomposing `f` with `Prod.snd` is `C^n` at `x` -/
theorem ContDiffAt.snd {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (f x).2) x :=
contDiffAt_snd.comp x hf
/-- Precomposing `f` with `Prod.snd` is `C^n` at `(x, y)` -/
theorem ContDiffAt.snd' {f : F → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f y) :
ContDiffAt 𝕜 n (fun x : E × F => f x.2) (x, y) :=
ContDiffAt.comp (x, y) hf contDiffAt_snd
/-- Precomposing `f` with `Prod.snd` is `C^n` at `x : E × F` -/
theorem ContDiffAt.snd'' {f : F → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.2) :
ContDiffAt 𝕜 n (fun x : E × F => f x.2) x :=
hf.comp x contDiffAt_snd
/-- The second projection within a domain at a point in a product is `C^∞`. -/
theorem contDiffWithinAt_snd {s : Set (E × F)} {p : E × F} :
ContDiffWithinAt 𝕜 n (Prod.snd : E × F → F) s p :=
contDiff_snd.contDiffWithinAt
section NAry
variable {E₁ E₂ E₃ : Type*}
variable [NormedAddCommGroup E₁] [NormedAddCommGroup E₂] [NormedAddCommGroup E₃]
[NormedSpace 𝕜 E₁] [NormedSpace 𝕜 E₂] [NormedSpace 𝕜 E₃]
theorem ContDiff.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} (hg : ContDiff 𝕜 n g)
(hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x) :=
hg.comp <| hf₁.prodMk hf₂
theorem ContDiffAt.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {x : F}
(hg : ContDiffAt 𝕜 n g (f₁ x, f₂ x))
(hf₁ : ContDiffAt 𝕜 n f₁ x) (hf₂ : ContDiffAt 𝕜 n f₂ x) :
ContDiffAt 𝕜 n (fun x => g (f₁ x, f₂ x)) x :=
hg.comp x (hf₁.prodMk hf₂)
theorem ContDiffAt.comp₂_contDiffWithinAt {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂}
{s : Set F} {x : F} (hg : ContDiffAt 𝕜 n g (f₁ x, f₂ x))
(hf₁ : ContDiffWithinAt 𝕜 n f₁ s x) (hf₂ : ContDiffWithinAt 𝕜 n f₂ s x) :
ContDiffWithinAt 𝕜 n (fun x => g (f₁ x, f₂ x)) s x :=
hg.comp_contDiffWithinAt x (hf₁.prodMk hf₂)
@[deprecated (since := "2024-10-30")]
alias ContDiffAt.comp_contDiffWithinAt₂ := ContDiffAt.comp₂_contDiffWithinAt
theorem ContDiff.comp₂_contDiffAt {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {x : F}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiffAt 𝕜 n f₁ x) (hf₂ : ContDiffAt 𝕜 n f₂ x) :
ContDiffAt 𝕜 n (fun x => g (f₁ x, f₂ x)) x :=
hg.contDiffAt.comp₂ hf₁ hf₂
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffAt₂ := ContDiff.comp₂_contDiffAt
theorem ContDiff.comp₂_contDiffWithinAt {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂}
{s : Set F} {x : F} (hg : ContDiff 𝕜 n g)
(hf₁ : ContDiffWithinAt 𝕜 n f₁ s x) (hf₂ : ContDiffWithinAt 𝕜 n f₂ s x) :
ContDiffWithinAt 𝕜 n (fun x => g (f₁ x, f₂ x)) s x :=
hg.contDiffAt.comp_contDiffWithinAt x (hf₁.prodMk hf₂)
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffWithinAt₂ := ContDiff.comp₂_contDiffWithinAt
theorem ContDiff.comp₂_contDiffOn {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {s : Set F}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) :
ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x)) s :=
hg.comp_contDiffOn <| hf₁.prodMk hf₂
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffOn₂ := ContDiff.comp₂_contDiffOn
theorem ContDiff.comp₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) (hf₃ : ContDiff 𝕜 n f₃) :
ContDiff 𝕜 n fun x => g (f₁ x, f₂ x, f₃ x) :=
hg.comp₂ hf₁ <| hf₂.prodMk hf₃
theorem ContDiff.comp₃_contDiffOn {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃}
{s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s)
(hf₃ : ContDiffOn 𝕜 n f₃ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x, f₃ x)) s :=
hg.comp₂_contDiffOn hf₁ <| hf₂.prodMk hf₃
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffOn₃ := ContDiff.comp₃_contDiffOn
end NAry
section SpecificBilinearMaps
theorem ContDiff.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} (hg : ContDiff 𝕜 n g)
(hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (g x).comp (f x) :=
isBoundedBilinearMap_comp.contDiff.comp₂ (g := fun p => p.1.comp p.2) hg hf
theorem ContDiffOn.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X}
(hg : ContDiffOn 𝕜 n g s) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (g x).comp (f x)) s :=
(isBoundedBilinearMap_comp (E := E) (F := F) (G := G)).contDiff.comp₂_contDiffOn hg hf
theorem ContDiffAt.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {x : X}
(hg : ContDiffAt 𝕜 n g x) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (g x).comp (f x)) x :=
(isBoundedBilinearMap_comp (E := E) (G := G)).contDiff.comp₂_contDiffAt hg hf
theorem ContDiffWithinAt.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X} {x : X}
(hg : ContDiffWithinAt 𝕜 n g s x) (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (fun x => (g x).comp (f x)) s x :=
(isBoundedBilinearMap_comp (E := E) (G := G)).contDiff.comp₂_contDiffWithinAt hg hf
theorem ContDiff.clm_apply {f : E → F →L[𝕜] G} {g : E → F} (hf : ContDiff 𝕜 n f)
(hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x) (g x) :=
isBoundedBilinearMap_apply.contDiff.comp₂ hf hg
theorem ContDiffOn.clm_apply {f : E → F →L[𝕜] G} {g : E → F} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x) (g x)) s :=
isBoundedBilinearMap_apply.contDiff.comp₂_contDiffOn hf hg
theorem ContDiffAt.clm_apply {f : E → F →L[𝕜] G} {g : E → F} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => (f x) (g x)) x :=
isBoundedBilinearMap_apply.contDiff.comp₂_contDiffAt hf hg
theorem ContDiffWithinAt.clm_apply {f : E → F →L[𝕜] G} {g : E → F}
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
ContDiffWithinAt 𝕜 n (fun x => (f x) (g x)) s x :=
isBoundedBilinearMap_apply.contDiff.comp₂_contDiffWithinAt hf hg
theorem ContDiff.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} (hf : ContDiff 𝕜 n f)
(hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x).smulRight (g x) :=
isBoundedBilinearMap_smulRight.contDiff.comp₂ (g := fun p => p.1.smulRight p.2) hf hg
theorem ContDiffOn.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x).smulRight (g x)) s :=
(isBoundedBilinearMap_smulRight (E := F)).contDiff.comp₂_contDiffOn hf hg
theorem ContDiffAt.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => (f x).smulRight (g x)) x :=
(isBoundedBilinearMap_smulRight (E := F)).contDiff.comp₂_contDiffAt hf hg
theorem ContDiffWithinAt.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G}
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
ContDiffWithinAt 𝕜 n (fun x => (f x).smulRight (g x)) s x :=
(isBoundedBilinearMap_smulRight (E := F)).contDiff.comp₂_contDiffWithinAt hf hg
end SpecificBilinearMaps
section ClmApplyConst
/-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDerivWithin`. -/
theorem iteratedFDerivWithin_clm_apply_const_apply
{s : Set E} (hs : UniqueDiffOn 𝕜 s) {c : E → F →L[𝕜] G}
(hc : ContDiffOn 𝕜 n c s) {i : ℕ} (hi : i ≤ n) {x : E} (hx : x ∈ s) {u : F} {m : Fin i → E} :
(iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s x) m = (iteratedFDerivWithin 𝕜 i c s x) m u := by
induction i generalizing x with
| zero => simp
| succ i ih =>
replace hi : (i : WithTop ℕ∞) < n := lt_of_lt_of_le (by norm_cast; simp) hi
have h_deriv_apply : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s) s :=
(hc.clm_apply contDiffOn_const).differentiableOn_iteratedFDerivWithin hi hs
have h_deriv : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i c s) s :=
hc.differentiableOn_iteratedFDerivWithin hi hs
simp only [iteratedFDerivWithin_succ_apply_left]
rw [← fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv_apply x hx)]
rw [fderivWithin_congr' (fun x hx ↦ ih hi.le hx) hx]
rw [fderivWithin_clm_apply (hs x hx) (h_deriv.continuousMultilinear_apply_const _ x hx)
(differentiableWithinAt_const u)]
rw [fderivWithin_const_apply]
simp only [ContinuousLinearMap.flip_apply, ContinuousLinearMap.comp_zero, zero_add]
rw [fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv x hx)]
/-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDeriv`. -/
theorem iteratedFDeriv_clm_apply_const_apply
{c : E → F →L[𝕜] G} (hc : ContDiff 𝕜 n c)
{i : ℕ} (hi : i ≤ n) {x : E} {u : F} {m : Fin i → E} :
(iteratedFDeriv 𝕜 i (fun y ↦ (c y) u) x) m = (iteratedFDeriv 𝕜 i c x) m u := by
simp only [← iteratedFDerivWithin_univ]
exact iteratedFDerivWithin_clm_apply_const_apply uniqueDiffOn_univ hc.contDiffOn hi (mem_univ _)
end ClmApplyConst
/-- The natural equivalence `(E × F) × G ≃ E × (F × G)` is smooth.
Warning: if you think you need this lemma, it is likely that you can simplify your proof by
reformulating the lemma that you're applying next using the tips in
Note [continuity lemma statement]
-/
theorem contDiff_prodAssoc {n : WithTop ℕ∞} : ContDiff 𝕜 n <| Equiv.prodAssoc E F G :=
(LinearIsometryEquiv.prodAssoc 𝕜 E F G).contDiff
/-- The natural equivalence `E × (F × G) ≃ (E × F) × G` is smooth.
Warning: see remarks attached to `contDiff_prodAssoc`
-/
theorem contDiff_prodAssoc_symm {n : WithTop ℕ∞} : ContDiff 𝕜 n <| (Equiv.prodAssoc E F G).symm :=
(LinearIsometryEquiv.prodAssoc 𝕜 E F G).symm.contDiff
/-! ### Bundled derivatives are smooth -/
section bundled
/-- One direction of `contDiffWithinAt_succ_iff_hasFDerivWithinAt`, but where all derivatives are
taken within the same set. Version for partial derivatives / functions with parameters. If `f x` is
a `C^n+1` family of functions and `g x` is a `C^n` family of points, then the derivative of `f x` at
`g x` depends in a `C^n` way on `x`. We give a general version of this fact relative to sets which
may not have unique derivatives, in the following form. If `f : E × F → G` is `C^n+1` at
`(x₀, g(x₀))` in `(s ∪ {x₀}) × t ⊆ E × F` and `g : E → F` is `C^n` at `x₀` within some set `s ⊆ E`,
then there is a function `f' : E → F →L[𝕜] G` that is `C^n` at `x₀` within `s` such that for all `x`
sufficiently close to `x₀` within `s ∪ {x₀}` the function `y ↦ f x y` has derivative `f' x` at `g x`
within `t ⊆ F`. For convenience, we return an explicit set of `x`'s where this holds that is a
subset of `s ∪ {x₀}`. We need one additional condition, namely that `t` is a neighborhood of
`g(x₀)` within `g '' s`. -/
theorem ContDiffWithinAt.hasFDerivWithinAt_nhds {f : E → F → G} {g : E → F} {t : Set F} (hn : n ≠ ∞)
{x₀ : E} (hf : ContDiffWithinAt 𝕜 (n + 1) (uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 n g s x₀) (hgt : t ∈ 𝓝[g '' s] g x₀) :
∃ v ∈ 𝓝[insert x₀ s] x₀, v ⊆ insert x₀ s ∧ ∃ f' : E → F →L[𝕜] G,
(∀ x ∈ v, HasFDerivWithinAt (f x) (f' x) t (g x)) ∧
ContDiffWithinAt 𝕜 n (fun x => f' x) s x₀ := by
have hst : insert x₀ s ×ˢ t ∈ 𝓝[(fun x => (x, g x)) '' s] (x₀, g x₀) := by
refine nhdsWithin_mono _ ?_ (nhdsWithin_prod self_mem_nhdsWithin hgt)
simp_rw [image_subset_iff, mk_preimage_prod, preimage_id', subset_inter_iff, subset_insert,
true_and, subset_preimage_image]
obtain ⟨v, hv, hvs, f_an, f', hvf', hf'⟩ :=
(contDiffWithinAt_succ_iff_hasFDerivWithinAt' hn).mp hf
refine
⟨(fun z => (z, g z)) ⁻¹' v ∩ insert x₀ s, ?_, inter_subset_right, fun z =>
(f' (z, g z)).comp (ContinuousLinearMap.inr 𝕜 E F), ?_, ?_⟩
· refine inter_mem ?_ self_mem_nhdsWithin
have := mem_of_mem_nhdsWithin (mem_insert _ _) hv
refine mem_nhdsWithin_insert.mpr ⟨this, ?_⟩
refine (continuousWithinAt_id.prodMk hg.continuousWithinAt).preimage_mem_nhdsWithin' ?_
rw [← nhdsWithin_le_iff] at hst hv ⊢
exact (hst.trans <| nhdsWithin_mono _ <| subset_insert _ _).trans hv
· intro z hz
have := hvf' (z, g z) hz.1
refine this.comp _ (hasFDerivAt_prodMk_right _ _).hasFDerivWithinAt ?_
exact mapsTo'.mpr (image_prodMk_subset_prod_right hz.2)
· exact (hf'.continuousLinearMap_comp <| (ContinuousLinearMap.compL 𝕜 F (E × F) G).flip
(ContinuousLinearMap.inr 𝕜 E F)).comp_of_mem_nhdsWithin_image x₀
(contDiffWithinAt_id.prodMk hg) hst
/-- The most general lemma stating that `x ↦ fderivWithin 𝕜 (f x) t (g x)` is `C^n`
at a point within a set.
To show that `x ↦ D_yf(x,y)g(x)` (taken within `t`) is `C^m` at `x₀` within `s`, we require that
* `f` is `C^n` at `(x₀, g(x₀))` within `(s ∪ {x₀}) × t` for `n ≥ m+1`.
* `g` is `C^m` at `x₀` within `s`;
* Derivatives are unique at `g(x)` within `t` for `x` sufficiently close to `x₀` within `s ∪ {x₀}`;
* `t` is a neighborhood of `g(x₀)` within `g '' s`; -/
theorem ContDiffWithinAt.fderivWithin'' {f : E → F → G} {g : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀)
(ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n)
(hgt : t ∈ 𝓝[g '' s] g x₀) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
have : ∀ k : ℕ, k ≤ m → ContDiffWithinAt 𝕜 k (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
intro k hkm
obtain ⟨v, hv, -, f', hvf', hf'⟩ :=
(hf.of_le <| (add_le_add_right hkm 1).trans hmn).hasFDerivWithinAt_nhds (by simp)
(hg.of_le hkm) hgt
refine hf'.congr_of_eventuallyEq_insert ?_
filter_upwards [hv, ht]
exact fun y hy h2y => (hvf' y hy).fderivWithin h2y
match m with
| ω =>
obtain rfl : n = ω := by simpa using hmn
obtain ⟨v, hv, -, f', hvf', hf'⟩ := hf.hasFDerivWithinAt_nhds (by simp) hg hgt
refine hf'.congr_of_eventuallyEq_insert ?_
filter_upwards [hv, ht]
exact fun y hy h2y => (hvf' y hy).fderivWithin h2y
| ∞ =>
rw [contDiffWithinAt_infty]
exact fun k ↦ this k (by exact_mod_cast le_top)
| (m : ℕ) => exact this _ le_rfl
/-- A special case of `ContDiffWithinAt.fderivWithin''` where we require that `s ⊆ g⁻¹(t)`. -/
theorem ContDiffWithinAt.fderivWithin' {f : E → F → G} {g : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀)
(ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n)
(hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ :=
hf.fderivWithin'' hg ht hmn <| mem_of_superset self_mem_nhdsWithin <| image_subset_iff.mpr hst
/-- A special case of `ContDiffWithinAt.fderivWithin'` where we require that `x₀ ∈ s` and there
are unique derivatives everywhere within `t`. -/
protected theorem ContDiffWithinAt.fderivWithin {f : E → F → G} {g : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s)
(hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
rw [← insert_eq_self.mpr hx₀] at hf
refine hf.fderivWithin' hg ?_ hmn hst
rw [insert_eq_self.mpr hx₀]
exact eventually_of_mem self_mem_nhdsWithin fun x hx => ht _ (hst hx)
/-- `x ↦ fderivWithin 𝕜 (f x) t (g x) (k x)` is smooth at a point within a set. -/
theorem ContDiffWithinAt.fderivWithin_apply {f : E → F → G} {g k : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀) (ht : UniqueDiffOn 𝕜 t)
(hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x) (k x)) s x₀ :=
(contDiff_fst.clm_apply contDiff_snd).contDiffAt.comp_contDiffWithinAt x₀
((hf.fderivWithin hg ht hmn hx₀ hst).prodMk hk)
/-- `fderivWithin 𝕜 f s` is smooth at `x₀` within `s`. -/
theorem ContDiffWithinAt.fderivWithin_right (hf : ContDiffWithinAt 𝕜 n f s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (fderivWithin 𝕜 f s) s x₀ :=
ContDiffWithinAt.fderivWithin
(ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s)
contDiffWithinAt_id hs hmn hx₀s (by rw [preimage_id'])
/-- `x ↦ fderivWithin 𝕜 f s x (k x)` is smooth at `x₀` within `s`. -/
theorem ContDiffWithinAt.fderivWithin_right_apply
{f : F → G} {k : F → F} {s : Set F} {x₀ : F}
(hf : ContDiffWithinAt 𝕜 n f s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 f s x (k x)) s x₀ :=
ContDiffWithinAt.fderivWithin_apply
(ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s)
contDiffWithinAt_id hk hs hmn hx₀s (by rw [preimage_id'])
-- TODO: can we make a version of `ContDiffWithinAt.fderivWithin` for iterated derivatives?
theorem ContDiffWithinAt.iteratedFDerivWithin_right {i : ℕ} (hf : ContDiffWithinAt 𝕜 n f s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + i ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (iteratedFDerivWithin 𝕜 i f s) s x₀ := by
induction' i with i hi generalizing m
· simp only [CharP.cast_eq_zero, add_zero] at hmn
exact (hf.of_le hmn).continuousLinearMap_comp
((continuousMultilinearCurryFin0 𝕜 E F).symm : _ →L[𝕜] E [×0]→L[𝕜] F)
· rw [Nat.cast_succ, add_comm _ 1, ← add_assoc] at hmn
exact ((hi hmn).fderivWithin_right hs le_rfl hx₀s).continuousLinearMap_comp
((continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (i+1) ↦ E) F).symm :
_ →L[𝕜] E [×(i+1)]→L[𝕜] F)
@[deprecated (since := "2025-01-15")]
alias ContDiffWithinAt.iteratedFderivWithin_right := ContDiffWithinAt.iteratedFDerivWithin_right
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth at `x₀`. -/
protected theorem ContDiffAt.fderiv {f : E → F → G} {g : E → F}
(hf : ContDiffAt 𝕜 n (Function.uncurry f) (x₀, g x₀)) (hg : ContDiffAt 𝕜 m g x₀)
(hmn : m + 1 ≤ n) : ContDiffAt 𝕜 m (fun x => fderiv 𝕜 (f x) (g x)) x₀ := by
simp_rw [← fderivWithin_univ]
refine (ContDiffWithinAt.fderivWithin hf.contDiffWithinAt hg.contDiffWithinAt uniqueDiffOn_univ
hmn (mem_univ x₀) ?_).contDiffAt univ_mem
rw [preimage_univ]
/-- `fderiv 𝕜 f` is smooth at `x₀`. -/
theorem ContDiffAt.fderiv_right (hf : ContDiffAt 𝕜 n f x₀) (hmn : m + 1 ≤ n) :
ContDiffAt 𝕜 m (fderiv 𝕜 f) x₀ :=
ContDiffAt.fderiv (ContDiffAt.comp (x₀, x₀) hf contDiffAt_snd) contDiffAt_id hmn
theorem ContDiffAt.iteratedFDeriv_right {i : ℕ} (hf : ContDiffAt 𝕜 n f x₀)
(hmn : m + i ≤ n) : ContDiffAt 𝕜 m (iteratedFDeriv 𝕜 i f) x₀ := by
rw [← iteratedFDerivWithin_univ, ← contDiffWithinAt_univ] at *
exact hf.iteratedFDerivWithin_right uniqueDiffOn_univ hmn trivial
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth. -/
protected theorem ContDiff.fderiv {f : E → F → G} {g : E → F}
(hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hnm : n + 1 ≤ m) :
ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) :=
contDiff_iff_contDiffAt.mpr fun _ => hf.contDiffAt.fderiv hg.contDiffAt hnm
/-- `fderiv 𝕜 f` is smooth. -/
theorem ContDiff.fderiv_right (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≤ n) :
ContDiff 𝕜 m (fderiv 𝕜 f) :=
contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.fderiv_right hmn
theorem ContDiff.iteratedFDeriv_right {i : ℕ} (hf : ContDiff 𝕜 n f)
(hmn : m + i ≤ n) : ContDiff 𝕜 m (iteratedFDeriv 𝕜 i f) :=
contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.iteratedFDeriv_right hmn
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is continuous. -/
theorem Continuous.fderiv {f : E → F → G} {g : E → F}
(hf : ContDiff 𝕜 n <| Function.uncurry f) (hg : Continuous g) (hn : 1 ≤ n) :
Continuous fun x => fderiv 𝕜 (f x) (g x) :=
(hf.fderiv (contDiff_zero.mpr hg) hn).continuous
/-- `x ↦ fderiv 𝕜 (f x) (g x) (k x)` is smooth. -/
theorem ContDiff.fderiv_apply {f : E → F → G} {g k : E → F}
(hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hk : ContDiff 𝕜 n k)
(hnm : n + 1 ≤ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) (k x) :=
(hf.fderiv hg hnm).clm_apply hk
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
theorem contDiffOn_fderivWithin_apply {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E →L[𝕜] F) p.2) (s ×ˢ univ) :=
((hf.fderivWithin hs hmn).comp contDiffOn_fst (prod_subset_preimage_fst _ _)).clm_apply
contDiffOn_snd
/-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is
continuous. -/
theorem ContDiffOn.continuousOn_fderivWithin_apply (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) :
ContinuousOn (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E → F) p.2) (s ×ˢ univ) :=
(contDiffOn_fderivWithin_apply (m := 0) hf hs hn).continuousOn
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
theorem ContDiff.contDiff_fderiv_apply {f : E → F} (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≤ n) :
ContDiff 𝕜 m fun p : E × E => (fderiv 𝕜 f p.1 : E →L[𝕜] F) p.2 := by
rw [← contDiffOn_univ] at hf ⊢
rw [← fderivWithin_univ, ← univ_prod_univ]
exact contDiffOn_fderivWithin_apply hf uniqueDiffOn_univ hmn
end bundled
section deriv
/-!
### One dimension
All results up to now have been expressed in terms of the general Fréchet derivative `fderiv`. For
maps defined on the field, the one-dimensional derivative `deriv` is often easier to use. In this
paragraph, we reformulate some higher smoothness results in terms of `deriv`.
-/
variable {f₂ : 𝕜 → F} {s₂ : Set 𝕜}
open ContinuousLinearMap (smulRight)
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (formulated with `derivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_derivWithin (hs : UniqueDiffOn 𝕜 s₂) :
ContDiffOn 𝕜 (n + 1) f₂ s₂ ↔
DifferentiableOn 𝕜 f₂ s₂ ∧ (n = ω → AnalyticOn 𝕜 f₂ s₂) ∧
ContDiffOn 𝕜 n (derivWithin f₂ s₂) s₂ := by
rw [contDiffOn_succ_iff_fderivWithin hs, and_congr_right_iff]
intro _
constructor
· rintro ⟨h', h⟩
refine ⟨h', ?_⟩
have : derivWithin f₂ s₂ = (fun u : 𝕜 →L[𝕜] F => u 1) ∘ fderivWithin 𝕜 f₂ s₂ := by
ext x; rfl
simp_rw [this]
apply ContDiff.comp_contDiffOn _ h
exact (isBoundedBilinearMap_apply.isBoundedLinearMap_left _).contDiff
· rintro ⟨h', h⟩
refine ⟨h', ?_⟩
have : fderivWithin 𝕜 f₂ s₂ = smulRight (1 : 𝕜 →L[𝕜] 𝕜) ∘ derivWithin f₂ s₂ := by
ext x; simp [derivWithin]
simp only [this]
apply ContDiff.comp_contDiffOn _ h
have : IsBoundedBilinearMap 𝕜 fun _ : (𝕜 →L[𝕜] 𝕜) × F => _ := isBoundedBilinearMap_smulRight
exact (this.isBoundedLinearMap_right _).contDiff
theorem contDiffOn_infty_iff_derivWithin (hs : UniqueDiffOn 𝕜 s₂) :
ContDiffOn 𝕜 ∞ f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 ∞ (derivWithin f₂ s₂) s₂ := by
rw [show ∞ = ∞ + 1 by rfl, contDiffOn_succ_iff_derivWithin hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_derivWithin := contDiffOn_infty_iff_derivWithin
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (formulated with `deriv`) is `C^n`. -/
theorem contDiffOn_succ_iff_deriv_of_isOpen (hs : IsOpen s₂) :
ContDiffOn 𝕜 (n + 1) f₂ s₂ ↔
DifferentiableOn 𝕜 f₂ s₂ ∧ (n = ω → AnalyticOn 𝕜 f₂ s₂) ∧
ContDiffOn 𝕜 n (deriv f₂) s₂ := by
rw [contDiffOn_succ_iff_derivWithin hs.uniqueDiffOn]
exact Iff.rfl.and (Iff.rfl.and (contDiffOn_congr fun _ => derivWithin_of_isOpen hs))
theorem contDiffOn_infty_iff_deriv_of_isOpen (hs : IsOpen s₂) :
ContDiffOn 𝕜 ∞ f₂ s₂ ↔ DifferentiableOn 𝕜 f₂ s₂ ∧ ContDiffOn 𝕜 ∞ (deriv f₂) s₂ := by
rw [show ∞ = ∞ + 1 by rfl, contDiffOn_succ_iff_deriv_of_isOpen hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_deriv_of_isOpen := contDiffOn_infty_iff_deriv_of_isOpen
protected theorem ContDiffOn.derivWithin (hf : ContDiffOn 𝕜 n f₂ s₂) (hs : UniqueDiffOn 𝕜 s₂)
(hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (derivWithin f₂ s₂) s₂ :=
((contDiffOn_succ_iff_derivWithin hs).1 (hf.of_le hmn)).2.2
theorem ContDiffOn.deriv_of_isOpen (hf : ContDiffOn 𝕜 n f₂ s₂) (hs : IsOpen s₂) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (deriv f₂) s₂ :=
(hf.derivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (derivWithin_of_isOpen hs hx).symm
theorem ContDiffOn.continuousOn_derivWithin (h : ContDiffOn 𝕜 n f₂ s₂) (hs : UniqueDiffOn 𝕜 s₂)
(hn : 1 ≤ n) : ContinuousOn (derivWithin f₂ s₂) s₂ := by
rw [show (1 : WithTop ℕ∞) = 0 + 1 from rfl] at hn
exact ((contDiffOn_succ_iff_derivWithin hs).1 (h.of_le hn)).2.2.continuousOn
theorem ContDiffOn.continuousOn_deriv_of_isOpen (h : ContDiffOn 𝕜 n f₂ s₂) (hs : IsOpen s₂)
(hn : 1 ≤ n) : ContinuousOn (deriv f₂) s₂ := by
rw [show (1 : WithTop ℕ∞) = 0 + 1 from rfl] at hn
exact ((contDiffOn_succ_iff_deriv_of_isOpen hs).1 (h.of_le hn)).2.2.continuousOn
/-- A function is `C^(n + 1)` if and only if it is differentiable,
and its derivative (formulated in terms of `deriv`) is `C^n`. -/
theorem contDiff_succ_iff_deriv :
ContDiff 𝕜 (n + 1) f₂ ↔ Differentiable 𝕜 f₂ ∧ (n = ω → AnalyticOn 𝕜 f₂ univ) ∧
ContDiff 𝕜 n (deriv f₂) := by
simp only [← contDiffOn_univ, contDiffOn_succ_iff_deriv_of_isOpen, isOpen_univ,
differentiableOn_univ]
theorem contDiff_one_iff_deriv :
ContDiff 𝕜 1 f₂ ↔ Differentiable 𝕜 f₂ ∧ Continuous (deriv f₂) := by
rw [show (1 : WithTop ℕ∞) = 0 + 1 from rfl, contDiff_succ_iff_deriv]
simp
theorem contDiff_infty_iff_deriv :
ContDiff 𝕜 ∞ f₂ ↔ Differentiable 𝕜 f₂ ∧ ContDiff 𝕜 ∞ (deriv f₂) := by
rw [show (∞ : WithTop ℕ∞) = ∞ + 1 from rfl, contDiff_succ_iff_deriv]
simp
@[deprecated (since := "2024-11-27")] alias contDiff_top_iff_deriv := contDiff_infty_iff_deriv
theorem ContDiff.continuous_deriv (h : ContDiff 𝕜 n f₂) (hn : 1 ≤ n) : Continuous (deriv f₂) := by
rw [show (1 : WithTop ℕ∞) = 0 + 1 from rfl] at hn
exact (contDiff_succ_iff_deriv.mp (h.of_le hn)).2.2.continuous
theorem ContDiff.iterate_deriv :
∀ (n : ℕ) {f₂ : 𝕜 → F}, ContDiff 𝕜 ∞ f₂ → ContDiff 𝕜 ∞ (deriv^[n] f₂)
| 0, _, hf => hf
| n + 1, _, hf => ContDiff.iterate_deriv n (contDiff_infty_iff_deriv.mp hf).2
theorem ContDiff.iterate_deriv' (n : ℕ) :
∀ (k : ℕ) {f₂ : 𝕜 → F}, ContDiff 𝕜 (n + k : ℕ) f₂ → ContDiff 𝕜 n (deriv^[k] f₂)
| 0, _, hf => hf
| k + 1, _, hf => ContDiff.iterate_deriv' _ k (contDiff_succ_iff_deriv.mp hf).2.2
end deriv
| Mathlib/Analysis/Calculus/ContDiff/Basic.lean | 1,508 | 1,511 | |
/-
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
rw [(monic_X_add_C r).natDegree_pow, natDegree_X_add_C, mul_one]
theorem Monic.eq_one_of_isUnit (hm : Monic p) (hpu : IsUnit p) : p = 1 := by
nontriviality R
obtain ⟨q, h⟩ := hpu.exists_right_inv
have := hm.natDegree_mul' (right_ne_zero_of_mul_eq_one h)
rw [h, natDegree_one, eq_comm, add_eq_zero] at this
exact hm.natDegree_eq_zero_iff_eq_one.mp this.1
theorem Monic.isUnit_iff (hm : p.Monic) : IsUnit p ↔ p = 1 :=
⟨hm.eq_one_of_isUnit, fun h => h.symm ▸ isUnit_one⟩
theorem eq_of_monic_of_associated (hp : p.Monic) (hq : q.Monic) (hpq : Associated p q) : p = q := by
obtain ⟨u, rfl⟩ := hpq
rw [(hp.of_mul_monic_left hq).eq_one_of_isUnit u.isUnit, mul_one]
end Semiring
section CommSemiring
variable [CommSemiring R] {p : R[X]}
theorem monic_multiset_prod_of_monic (t : Multiset ι) (f : ι → R[X]) (ht : ∀ i ∈ t, Monic (f i)) :
Monic (t.map f).prod := by
revert ht
refine t.induction_on ?_ ?_; · simp
intro a t ih ht
rw [Multiset.map_cons, Multiset.prod_cons]
exact (ht _ (Multiset.mem_cons_self _ _)).mul (ih fun _ hi => ht _ (Multiset.mem_cons_of_mem hi))
theorem monic_prod_of_monic (s : Finset ι) (f : ι → R[X]) (hs : ∀ i ∈ s, Monic (f i)) :
Monic (∏ i ∈ s, f i) :=
monic_multiset_prod_of_monic s.1 f hs
theorem monic_finprod_of_monic (α : Type*) (f : α → R[X])
(hf : ∀ i ∈ Function.mulSupport f, Monic (f i)) :
Monic (finprod f) := by
classical
rw [finprod_def]
split_ifs
· exact monic_prod_of_monic _ _ fun a ha => hf a ((Set.Finite.mem_toFinset _).mp ha)
· exact monic_one
theorem Monic.nextCoeff_multiset_prod (t : Multiset ι) (f : ι → R[X]) (h : ∀ i ∈ t, Monic (f i)) :
nextCoeff (t.map f).prod = (t.map fun i => nextCoeff (f i)).sum := by
revert h
refine Multiset.induction_on t ?_ fun a t ih ht => ?_
· simp only [Multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, Multiset.map_zero,
Multiset.prod_zero, Multiset.sum_zero, not_false_iff, forall_true_iff]
rw [← C_1]
rw [nextCoeff_C_eq_zero]
· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons,
Monic.nextCoeff_mul, ih]
exacts [fun i hi => ht i (Multiset.mem_cons_of_mem hi), ht a (Multiset.mem_cons_self _ _),
monic_multiset_prod_of_monic _ _ fun b bs => ht _ (Multiset.mem_cons_of_mem bs)]
theorem Monic.nextCoeff_prod (s : Finset ι) (f : ι → R[X]) (h : ∀ i ∈ s, Monic (f i)) :
nextCoeff (∏ i ∈ s, f i) = ∑ i ∈ s, nextCoeff (f i) :=
Monic.nextCoeff_multiset_prod s.1 f h
variable [NoZeroDivisors R] {p q : R[X]}
lemma irreducible_of_monic (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f = 1 ∨ g = 1 := by
refine
⟨fun h f g hf hg hp => (h.2 hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h =>
⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg =>
(h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp
(isUnit_of_mul_eq_one f _)
(isUnit_of_mul_eq_one g _)⟩⟩
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic]
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic]
· rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one,
mul_comm, ← hfg]
lemma Monic.irreducible_iff_natDegree (hp : p.Monic) :
Irreducible p ↔
p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f.natDegree = 0 ∨ g.natDegree = 0 := by
by_cases hp1 : p = 1; · simp [hp1]
rw [irreducible_of_monic hp hp1, and_iff_right hp1]
refine forall₄_congr fun a b ha hb => ?_
rw [ha.natDegree_eq_zero_iff_eq_one, hb.natDegree_eq_zero_iff_eq_one]
lemma Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧
∀ f g : R[X], f.Monic → g.Monic → f * g = p → g.natDegree ∉ Ioc 0 (p.natDegree / 2) := by
simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two]
apply and_congr_right'
constructor <;> intro h f g hf hg he <;> subst he
· rw [hf.natDegree_mul hg, add_le_add_iff_right]
exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne'
· simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h
contrapose! h
obtain hl | hl := le_total f.natDegree g.natDegree
· exact ⟨g, f, hg, hf, mul_comm g f, h.1, add_le_add_left hl _⟩
· exact ⟨f, g, hf, hg, rfl, h.2, add_le_add_right hl _⟩
/-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check
one divisor at a time. -/
lemma Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by
rw [hp.irreducible_iff_natDegree', and_iff_right hp1]
constructor
· rintro h g hg hdg ⟨f, rfl⟩
exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg
· rintro h f g - hg rfl hdg
exact h g hg hdg (dvd_mul_left g f)
lemma Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) :
¬Irreducible p ↔ ∃ c₁ c₂, p.coeff 0 = c₁ * c₂ ∧ p.coeff 1 = c₁ + c₂ := by
cases subsingleton_or_nontrivial R
· simp [natDegree_of_subsingleton] at hnd
rw [hm.irreducible_iff_natDegree', and_iff_right, hnd]
· push_neg
constructor
· rintro ⟨a, b, ha, hb, rfl, hdb⟩
simp only [zero_lt_two, Nat.div_self, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb
have hda := hnd
rw [ha.natDegree_mul hb, hdb] at hda
use a.coeff 0, b.coeff 0, mul_coeff_zero a b
simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb
· rintro ⟨c₁, c₂, hmul, hadd⟩
refine
⟨X + C c₁, X + C c₂, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩
· rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ,
Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1]
ring
· rw [mem_Ioc, natDegree_X_add_C _]
simp
· rintro rfl
simp [natDegree_one] at hnd
end CommSemiring
section Semiring
variable [Semiring R]
@[simp]
theorem Monic.natDegree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).natDegree = P.natDegree := by
refine le_antisymm natDegree_map_le (le_natDegree_of_ne_zero ?_)
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
@[simp]
theorem Monic.degree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).degree = P.degree := by
by_cases hP : P = 0
· simp [hP]
· refine le_antisymm degree_map_le ?_
rw [degree_eq_natDegree hP]
refine le_degree_of_ne_zero ?_
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
section Injective
open Function
variable [Semiring S] {f : R →+* S}
theorem degree_map_eq_of_injective (hf : Injective f) (p : R[X]) : degree (p.map f) = degree p :=
letI := Classical.decEq R
if h : p = 0 then by simp [h]
else
degree_map_eq_of_leadingCoeff_ne_zero _
(by rw [← f.map_zero]; exact mt hf.eq_iff.1 (mt leadingCoeff_eq_zero.1 h))
theorem natDegree_map_eq_of_injective (hf : Injective f) (p : R[X]) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map_eq_of_injective hf p)
theorem leadingCoeff_map' (hf : Injective f) (p : R[X]) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
unfold leadingCoeff
rw [coeff_map, natDegree_map_eq_of_injective hf p]
theorem nextCoeff_map (hf : Injective f) (p : R[X]) : (p.map f).nextCoeff = f p.nextCoeff := by
unfold nextCoeff
rw [natDegree_map_eq_of_injective hf]
split_ifs <;> simp [*]
theorem leadingCoeff_of_injective (hf : Injective f) (p : R[X]) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
delta leadingCoeff
rw [coeff_map f, natDegree_map_eq_of_injective hf p]
theorem monic_of_injective (hf : Injective f) {p : R[X]} (hp : (p.map f).Monic) : p.Monic := by
apply hf
rw [← leadingCoeff_of_injective hf, hp.leadingCoeff, f.map_one]
theorem _root_.Function.Injective.monic_map_iff (hf : Injective f) {p : R[X]} :
p.Monic ↔ (p.map f).Monic :=
⟨Monic.map _, Polynomial.monic_of_injective hf⟩
end Injective
end Semiring
section Ring
variable [Ring R] {p : R[X]}
theorem monic_X_sub_C (x : R) : Monic (X - C x) := by
simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p < n) : Monic (X ^ n - p) := by
simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) < n by rwa [← degree_neg p] at H)
/-- `X ^ n - a` is monic. -/
theorem monic_X_pow_sub_C {R : Type u} [Ring R] (a : R) {n : ℕ} (h : n ≠ 0) :
(X ^ n - C a).Monic := by
simpa only [map_neg, ← sub_eq_add_neg] using monic_X_pow_add_C (-a) h
theorem not_isUnit_X_pow_sub_one (R : Type*) [Ring R] [Nontrivial R] (n : ℕ) :
¬IsUnit (X ^ n - 1 : R[X]) := by
intro h
rcases eq_or_ne n 0 with (rfl | hn)
· simp at h
apply hn
rw [← @natDegree_one R, ← (monic_X_pow_sub_C _ hn).eq_one_of_isUnit h, natDegree_X_pow_sub_C]
lemma Monic.comp_X_sub_C {p : R[X]} (hp : p.Monic) (r : R) : (p.comp (X - C r)).Monic := by
simpa using hp.comp_X_add_C (-r)
theorem Monic.sub_of_left {p q : R[X]} (hp : Monic p) (hpq : degree q < degree p) :
Monic (p - q) := by
rw [sub_eq_add_neg]
apply hp.add_of_left
rwa [degree_neg]
theorem Monic.sub_of_right {p q : R[X]} (hq : q.leadingCoeff = -1) (hpq : degree p < degree q) :
Monic (p - q) := by
have : (-q).coeff (-q).natDegree = 1 := by
rw [natDegree_neg, coeff_neg, show q.coeff q.natDegree = -1 from hq, neg_neg]
rw [sub_eq_add_neg]
apply Monic.add_of_right this
rwa [degree_neg]
end Ring
section NonzeroSemiring
|
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem not_monic_zero : ¬Monic (0 : R[X]) :=
not_monic_zero_iff.mp zero_ne_one
| Mathlib/Algebra/Polynomial/Monic.lean | 470 | 475 |
/-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Kim Morrison
-/
import Mathlib.CategoryTheory.Opposites
/-!
# Morphisms from equations between objects.
When working categorically, sometimes one encounters an equation `h : X = Y` between objects.
Your initial aversion to this is natural and appropriate:
you're in for some trouble, and if there is another way to approach the problem that won't
rely on this equality, it may be worth pursuing.
You have two options:
1. Use the equality `h` as one normally would in Lean (e.g. using `rw` and `subst`).
This may immediately cause difficulties, because in category theory everything is dependently
typed, and equations between objects quickly lead to nasty goals with `eq.rec`.
2. Promote `h` to a morphism using `eqToHom h : X ⟶ Y`, or `eqToIso h : X ≅ Y`.
This file introduces various `simp` lemmas which in favourable circumstances
result in the various `eqToHom` morphisms to drop out at the appropriate moment!
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
open Opposite
variable {C : Type u₁} [Category.{v₁} C]
/-- An equality `X = Y` gives us a morphism `X ⟶ Y`.
It is typically better to use this, rather than rewriting by the equality then using `𝟙 _`
which usually leads to dependent type theory hell.
-/
def eqToHom {X Y : C} (p : X = Y) : X ⟶ Y := by rw [p]; exact 𝟙 _
@[simp]
theorem eqToHom_refl (X : C) (p : X = X) : eqToHom p = 𝟙 X :=
rfl
@[reassoc (attr := simp)]
theorem eqToHom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToHom p ≫ eqToHom q = eqToHom (p.trans q) := by
cases p
cases q
simp
/-- `eqToHom h` is heterogeneously equal to the identity of its domain. -/
lemma eqToHom_heq_id_dom (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 X) := by
subst h; rfl
/-- `eqToHom h` is heterogeneously equal to the identity of its codomain. -/
lemma eqToHom_heq_id_cod (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 Y) := by
subst h; rfl
/-- Two morphisms are conjugate via eqToHom if and only if they are heterogeneously equal.
Note this used to be in the Functor namespace, where it doesn't belong. -/
theorem conj_eqToHom_iff_heq {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : X = Z) :
f = eqToHom h ≫ g ≫ eqToHom h'.symm ↔ HEq f g := by
cases h
cases h'
simp
theorem conj_eqToHom_iff_heq' {C} [Category C] {W X Y Z : C}
(f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : Z = X) :
f = eqToHom h ≫ g ≫ eqToHom h' ↔ HEq f g := conj_eqToHom_iff_heq _ _ _ h'.symm
theorem comp_eqToHom_iff {X Y Y' : C} (p : Y = Y') (f : X ⟶ Y) (g : X ⟶ Y') :
f ≫ eqToHom p = g ↔ f = g ≫ eqToHom p.symm :=
{ mp := fun h => h ▸ by simp
mpr := fun h => by simp [eq_whisker h (eqToHom p)] }
theorem eqToHom_comp_iff {X X' Y : C} (p : X = X') (f : X ⟶ Y) (g : X' ⟶ Y) :
eqToHom p ≫ g = f ↔ g = eqToHom p.symm ≫ f :=
{ mp := fun h => h ▸ by simp
mpr := fun h => h ▸ by simp [whisker_eq _ h] }
theorem eqToHom_comp_heq {C} [Category C] {W X Y : C}
(f : Y ⟶ X) (h : W = Y) : HEq (eqToHom h ≫ f) f := by
rw [← conj_eqToHom_iff_heq _ _ h rfl, eqToHom_refl, Category.comp_id]
@[simp] theorem eqToHom_comp_heq_iff {C} [Category C] {W X Y Z Z' : C}
(f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) :
HEq (eqToHom h ≫ f) g ↔ HEq f g :=
⟨(eqToHom_comp_heq ..).symm.trans, (eqToHom_comp_heq ..).trans⟩
@[simp] theorem heq_eqToHom_comp_iff {C} [Category C] {W X Y Z Z' : C}
(f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) :
HEq g (eqToHom h ≫ f) ↔ HEq g f :=
⟨(·.trans (eqToHom_comp_heq ..)), (·.trans (eqToHom_comp_heq ..).symm)⟩
theorem comp_eqToHom_heq {C} [Category C] {X Y Z : C}
(f : X ⟶ Y) (h : Y = Z) : HEq (f ≫ eqToHom h) f := by
rw [← conj_eqToHom_iff_heq' _ _ rfl h, eqToHom_refl, Category.id_comp]
@[simp] theorem comp_eqToHom_heq_iff {C} [Category C] {W X Y Z Z' : C}
(f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) :
HEq (f ≫ eqToHom h) g ↔ HEq f g :=
⟨(comp_eqToHom_heq ..).symm.trans, (comp_eqToHom_heq ..).trans⟩
@[simp] theorem heq_comp_eqToHom_iff {C} [Category C] {W X Y Z Z' : C}
(f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) :
HEq g (f ≫ eqToHom h) ↔ HEq g f :=
⟨(·.trans (comp_eqToHom_heq ..)), (·.trans (comp_eqToHom_heq ..).symm)⟩
theorem heq_comp {C} [Category C] {X Y Z X' Y' Z' : C}
{f : X ⟶ Y} {g : Y ⟶ Z} {f' : X' ⟶ Y'} {g' : Y' ⟶ Z'}
(eq1 : X = X') (eq2 : Y = Y') (eq3 : Z = Z')
(H1 : HEq f f') (H2 : HEq g g') :
HEq (f ≫ g) (f' ≫ g') := by
cases eq1; cases eq2; cases eq3; cases H1; cases H2; rfl
variable {β : Sort*}
/-- We can push `eqToHom` to the left through families of morphisms. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_naturality {f g : β → C} (z : ∀ b, f b ⟶ g b) {j j' : β} (w : j = j') :
z j ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ z j' := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_hom_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).hom ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').hom := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_inv_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).inv ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').inv := by
cases w
simp
/-- Reducible form of congrArg_mpr_hom_left -/
@[simp]
theorem congrArg_cast_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
cast (congrArg (fun W : C => W ⟶ Z) p.symm) q = eqToHom p ≫ q := by
cases p
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the source object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
(congrArg (fun W : C => W ⟶ Z) p).mpr q = eqToHom p ≫ q := by
cases p
simp
/-- Reducible form of `congrArg_mpr_hom_right` -/
@[simp]
theorem congrArg_cast_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
cast (congrArg (fun W : C => X ⟶ W) q.symm) p = p ≫ eqToHom q.symm := by
cases q
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the target object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
(congrArg (fun W : C => X ⟶ W) q).mpr p = p ≫ eqToHom q.symm := by
cases q
simp
/-- An equality `X = Y` gives us an isomorphism `X ≅ Y`.
It is typically better to use this, rather than rewriting by the equality then using `Iso.refl _`
which usually leads to dependent type theory hell.
-/
def eqToIso {X Y : C} (p : X = Y) : X ≅ Y :=
⟨eqToHom p, eqToHom p.symm, by simp, by simp⟩
@[simp]
theorem eqToIso.hom {X Y : C} (p : X = Y) : (eqToIso p).hom = eqToHom p :=
rfl
@[simp]
theorem eqToIso.inv {X Y : C} (p : X = Y) : (eqToIso p).inv = eqToHom p.symm :=
rfl
@[simp]
theorem eqToIso_refl {X : C} (p : X = X) : eqToIso p = Iso.refl X :=
rfl
@[simp]
theorem eqToIso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToIso p ≪≫ eqToIso q = eqToIso (p.trans q) := by ext; simp
@[simp]
theorem eqToHom_op {X Y : C} (h : X = Y) : (eqToHom h).op = eqToHom (congr_arg op h.symm) := by
cases h
rfl
@[simp]
theorem eqToHom_unop {X Y : Cᵒᵖ} (h : X = Y) :
(eqToHom h).unop = eqToHom (congr_arg unop h.symm) := by
cases h
rfl
instance {X Y : C} (h : X = Y) : IsIso (eqToHom h) :=
(eqToIso h).isIso_hom
@[simp]
theorem inv_eqToHom {X Y : C} (h : X = Y) : inv (eqToHom h) = eqToHom h.symm := by
aesop_cat
variable {D : Type u₂} [Category.{v₂} D]
namespace Functor
/-- Proving equality between functors. This isn't an extensionality lemma,
because usually you don't really want to do this. -/
theorem ext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ X Y f,
F.map f = eqToHom (h_obj X) ≫ G.map f ≫ eqToHom (h_obj Y).symm := by aesop_cat) :
F = G := by
match F, G with
| mk F_pre _ _ , mk G_pre _ _ =>
match F_pre, G_pre with
| Prefunctor.mk F_obj _ , Prefunctor.mk G_obj _ =>
obtain rfl : F_obj = G_obj := by
ext X
apply h_obj
congr
funext X Y f
simpa using h_map X Y f
lemma ext_of_iso {F G : C ⥤ D} (e : F ≅ G) (hobj : ∀ X, F.obj X = G.obj X)
(happ : ∀ X, e.hom.app X = eqToHom (hobj X)) : F = G :=
Functor.ext hobj (fun X Y f => by
rw [← cancel_mono (e.hom.app Y), e.hom.naturality f, happ, happ, Category.assoc,
Category.assoc, eqToHom_trans, eqToHom_refl, Category.comp_id])
/-- Proving equality between functors using heterogeneous equality. -/
theorem hext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ (X Y) (f : X ⟶ Y), HEq (F.map f) (G.map f)) : F = G :=
Functor.ext h_obj fun _ _ f => (conj_eqToHom_iff_heq _ _ (h_obj _) (h_obj _)).2 <| h_map _ _ f
-- Using equalities between functors.
theorem congr_obj {F G : C ⥤ D} (h : F = G) (X) : F.obj X = G.obj X := by rw [h]
@[reassoc]
theorem congr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) :
F.map f = eqToHom (congr_obj h X) ≫ G.map f ≫ eqToHom (congr_obj h Y).symm := by
subst h; simp
theorem congr_inv_of_congr_hom (F G : C ⥤ D) {X Y : C} (e : X ≅ Y) (hX : F.obj X = G.obj X)
(hY : F.obj Y = G.obj Y)
(h₂ : F.map e.hom = eqToHom (by rw [hX]) ≫ G.map e.hom ≫ eqToHom (by rw [hY])) :
F.map e.inv = eqToHom (by rw [hY]) ≫ G.map e.inv ≫ eqToHom (by rw [hX]) := by
simp only [← IsIso.Iso.inv_hom e, Functor.map_inv, h₂, IsIso.inv_comp, inv_eqToHom,
Category.assoc]
section HEq
-- Composition of functors and maps w.r.t. heq
variable {E : Type u₃} [Category.{v₃} E] {F G : C ⥤ D} {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
theorem map_comp_heq (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y) (hz : F.obj Z = G.obj Z)
(hf : HEq (F.map f) (G.map f)) (hg : HEq (F.map g) (G.map g)) :
HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by
rw [F.map_comp, G.map_comp]
congr
theorem map_comp_heq' (hobj : ∀ X : C, F.obj X = G.obj X)
(hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) :
HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by
rw [Functor.hext hobj fun _ _ => hmap]
theorem precomp_map_heq (H : E ⥤ C) (hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) {X Y : E}
(f : X ⟶ Y) : HEq ((H ⋙ F).map f) ((H ⋙ G).map f) :=
hmap _
theorem postcomp_map_heq (H : D ⥤ E) (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y)
(hmap : HEq (F.map f) (G.map f)) : HEq ((F ⋙ H).map f) ((G ⋙ H).map f) := by
dsimp
congr
theorem postcomp_map_heq' (H : D ⥤ E) (hobj : ∀ X : C, F.obj X = G.obj X)
(hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) :
HEq ((F ⋙ H).map f) ((G ⋙ H).map f) := by rw [Functor.hext hobj fun _ _ => hmap]
theorem hcongr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) : HEq (F.map f) (G.map f) := by
rw [h]
end HEq
end Functor
/-- This is not always a good idea as a `@[simp]` lemma,
as we lose the ability to use results that interact with `F`,
e.g. the naturality of a natural transformation.
In some files it may be appropriate to use `attribute [local simp] eqToHom_map`, however.
-/
theorem eqToHom_map (F : C ⥤ D) {X Y : C} (p : X = Y) :
F.map (eqToHom p) = eqToHom (congr_arg F.obj p) := by cases p; simp
@[reassoc (attr := simp)]
| theorem eqToHom_map_comp (F : C ⥤ D) {X Y Z : C} (p : X = Y) (q : Y = Z) :
F.map (eqToHom p) ≫ F.map (eqToHom q) = F.map (eqToHom <| p.trans q) := by aesop_cat
/-- See the note on `eqToHom_map` regarding using this as a `simp` lemma.
| Mathlib/CategoryTheory/EqToHom.lean | 324 | 327 |
/-
Copyright (c) 2022 Matej Penciak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Matej Penciak, Moritz Doll, Fabien Clery
-/
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
/-!
# The Symplectic Group
This file defines the symplectic group and proves elementary properties.
## Main Definitions
* `Matrix.J`: the canonical `2n × 2n` skew-symmetric matrix
* `symplecticGroup`: the group of symplectic matrices
## TODO
* Every symplectic matrix has determinant 1.
* For `n = 1` the symplectic group coincides with the special linear group.
-/
open Matrix
variable {l R : Type*}
namespace Matrix
variable (l) [DecidableEq l] (R) [CommRing R]
section JMatrixLemmas
/-- The matrix defining the canonical skew-symmetric bilinear form. -/
def J : Matrix (l ⊕ l) (l ⊕ l) R :=
Matrix.fromBlocks 0 (-1) 1 0
@[simp]
theorem J_transpose : (J l R)ᵀ = -J l R := by
rw [J, fromBlocks_transpose, ← neg_one_smul R (fromBlocks _ _ _ _ : Matrix (l ⊕ l) (l ⊕ l) R),
fromBlocks_smul, Matrix.transpose_zero, Matrix.transpose_one, transpose_neg]
simp [fromBlocks]
variable [Fintype l]
theorem J_squared : J l R * J l R = -1 := by
rw [J, fromBlocks_multiply]
simp only [Matrix.zero_mul, Matrix.neg_mul, zero_add, neg_zero, Matrix.one_mul, add_zero]
rw [← neg_zero, ← Matrix.fromBlocks_neg, ← fromBlocks_one]
theorem J_inv : (J l R)⁻¹ = -J l R := by
refine Matrix.inv_eq_right_inv ?_
rw [Matrix.mul_neg, J_squared]
exact neg_neg 1
theorem J_det_mul_J_det : det (J l R) * det (J l R) = 1 := by
rw [← det_mul, J_squared, ← one_smul R (-1 : Matrix _ _ R), smul_neg, ← neg_smul, det_smul,
Fintype.card_sum, det_one, mul_one]
apply Even.neg_one_pow
exact Even.add_self _
theorem isUnit_det_J : IsUnit (det (J l R)) :=
isUnit_iff_exists_inv.mpr ⟨det (J l R), J_det_mul_J_det _ _⟩
end JMatrixLemmas
variable [Fintype l]
/-- The group of symplectic matrices over a ring `R`. -/
def symplecticGroup : Submonoid (Matrix (l ⊕ l) (l ⊕ l) R) where
carrier := { A | A * J l R * Aᵀ = J l R }
mul_mem' {a b} ha hb := by
simp only [Set.mem_setOf_eq, transpose_mul] at *
rw [← Matrix.mul_assoc, a.mul_assoc, a.mul_assoc, hb]
exact ha
one_mem' := by simp
end Matrix
namespace SymplecticGroup
variable [DecidableEq l] [Fintype l] [CommRing R]
open Matrix
theorem mem_iff {A : Matrix (l ⊕ l) (l ⊕ l) R} :
A ∈ symplecticGroup l R ↔ A * J l R * Aᵀ = J l R := by simp [symplecticGroup]
instance coeMatrix : Coe (symplecticGroup l R) (Matrix (l ⊕ l) (l ⊕ l) R) :=
⟨Subtype.val⟩
section SymplecticJ
variable (l) (R)
theorem J_mem : J l R ∈ symplecticGroup l R := by
rw [mem_iff, J, fromBlocks_multiply, fromBlocks_transpose, fromBlocks_multiply]
simp
/-- The canonical skew-symmetric matrix as an element in the symplectic group. -/
def symJ : symplecticGroup l R :=
⟨J l R, J_mem l R⟩
variable {l} {R}
@[simp]
theorem coe_J : ↑(symJ l R) = J l R := rfl
end SymplecticJ
variable {A : Matrix (l ⊕ l) (l ⊕ l) R}
theorem neg_mem (h : A ∈ symplecticGroup l R) : -A ∈ symplecticGroup l R := by
rw [mem_iff] at h ⊢
simp [h]
theorem symplectic_det (hA : A ∈ symplecticGroup l R) : IsUnit <| det A := by
rw [isUnit_iff_exists_inv]
use A.det
refine (isUnit_det_J l R).mul_left_cancel ?_
rw [mul_one]
rw [mem_iff] at hA
apply_fun det at hA
simp only [det_mul, det_transpose] at hA
rw [mul_comm A.det, mul_assoc] at hA
exact hA
theorem transpose_mem (hA : A ∈ symplecticGroup l R) : Aᵀ ∈ symplecticGroup l R := by
rw [mem_iff] at hA ⊢
rw [transpose_transpose]
have huA := symplectic_det hA
have huAT : IsUnit Aᵀ.det := by
rw [Matrix.det_transpose]
exact huA
calc
Aᵀ * J l R * A = (-Aᵀ) * (J l R)⁻¹ * A := by
rw [J_inv]
simp
_ = (-Aᵀ) * (A * J l R * Aᵀ)⁻¹ * A := by rw [hA]
_ = -(Aᵀ * (Aᵀ⁻¹ * (J l R)⁻¹)) * A⁻¹ * A := by
simp only [Matrix.mul_inv_rev, Matrix.mul_assoc, Matrix.neg_mul]
_ = -(J l R)⁻¹ := by
rw [mul_nonsing_inv_cancel_left _ _ huAT, nonsing_inv_mul_cancel_right _ _ huA]
_ = J l R := by simp [J_inv]
@[simp]
theorem transpose_mem_iff : Aᵀ ∈ symplecticGroup l R ↔ A ∈ symplecticGroup l R :=
⟨fun hA => by simpa using transpose_mem hA, transpose_mem⟩
theorem mem_iff' : A ∈ symplecticGroup l R ↔ Aᵀ * J l R * A = J l R := by
rw [← transpose_mem_iff, mem_iff, transpose_transpose]
instance hasInv : Inv (symplecticGroup l R) where
| inv A := ⟨(-J l R) * (A : Matrix (l ⊕ l) (l ⊕ l) R)ᵀ * J l R,
mul_mem (mul_mem (neg_mem <| J_mem _ _) <| transpose_mem A.2) <| J_mem _ _⟩
theorem coe_inv (A : symplecticGroup l R) : (↑A⁻¹ : Matrix _ _ _) = (-J l R) * (↑A)ᵀ * J l R := rfl
theorem inv_left_mul_aux (hA : A ∈ symplecticGroup l R) : -(J l R * Aᵀ * J l R * A) = 1 :=
calc
-(J l R * Aᵀ * J l R * A) = (-J l R) * (Aᵀ * J l R * A) := by
simp only [Matrix.mul_assoc, Matrix.neg_mul]
_ = (-J l R) * J l R := by
rw [mem_iff'] at hA
rw [hA]
_ = (-1 : R) • (J l R * J l R) := by simp only [Matrix.neg_mul, neg_smul, one_smul]
_ = (-1 : R) • (-1 : Matrix _ _ _) := by rw [J_squared]
_ = 1 := by simp only [neg_smul_neg, one_smul]
theorem coe_inv' (A : symplecticGroup l R) : (↑A⁻¹ : Matrix (l ⊕ l) (l ⊕ l) R) = (↑A)⁻¹ := by
| Mathlib/LinearAlgebra/SymplecticGroup.lean | 154 | 170 |
/-
Copyright (c) 2023 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson, Boris Bolvig Kjær, Jon Eugster, Sina Hazratpour, Nima Rasekh
-/
import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPreregular
import Mathlib.Topology.Category.CompHaus.EffectiveEpi
import Mathlib.Topology.Category.Stonean.Limits
/-!
# Effective epimorphisms in `Stonean`
This file proves that `EffectiveEpi`, `Epi` and `Surjective` are all equivalent in `Stonean`.
As a consequence we deduce from the material in
`Mathlib.Topology.Category.CompHausLike.EffectiveEpi` that `Stonean` is `Preregular`
and `Precoherent`.
We also prove that for a finite family of morphisms in `Stonean` with fixed
target, the conditions jointly surjective, jointly epimorphic and effective epimorphic are all
equivalent.
-/
universe u
open CategoryTheory Limits CompHausLike
namespace Stonean
open List in
theorem effectiveEpi_tfae
{B X : Stonean.{u}} (π : X ⟶ B) :
TFAE
[ EffectiveEpi π
, Epi π
, Function.Surjective π
] := by
tfae_have 1 → 2 := fun _ ↦ inferInstance
tfae_have 2 ↔ 3 := epi_iff_surjective π
tfae_have 3 → 1 := fun hπ ↦ ⟨⟨effectiveEpiStruct π hπ⟩⟩
tfae_finish
instance : Stonean.toCompHaus.PreservesEffectiveEpis where
preserves f h :=
((CompHaus.effectiveEpi_tfae (Stonean.toCompHaus.map f)).out 0 2).mpr
(((Stonean.effectiveEpi_tfae f).out 0 2).mp h)
instance : Stonean.toCompHaus.ReflectsEffectiveEpis where
reflects f h :=
((Stonean.effectiveEpi_tfae f).out 0 2).mpr
(((CompHaus.effectiveEpi_tfae (Stonean.toCompHaus.map f)).out 0 2).mp h)
/--
An effective presentation of an `X : CompHaus` with respect to the inclusion functor from `Stonean`
-/
noncomputable def stoneanToCompHausEffectivePresentation (X : CompHaus) :
Stonean.toCompHaus.EffectivePresentation X where
p := X.presentation
f := CompHaus.presentation.π X
effectiveEpi := ((CompHaus.effectiveEpi_tfae _).out 0 1).mpr (inferInstance : Epi _)
instance : Stonean.toCompHaus.EffectivelyEnough where
presentation X := ⟨stoneanToCompHausEffectivePresentation X⟩
instance : Preregular Stonean := Stonean.toCompHaus.reflects_preregular
example : Precoherent Stonean.{u} := inferInstance
-- TODO: prove this for `Type*`
open List in
theorem effectiveEpiFamily_tfae
{α : Type} [Finite α] {B : Stonean.{u}}
(X : α → Stonean.{u}) (π : (a : α) → (X a ⟶ B)) :
TFAE
[ EffectiveEpiFamily X π
, Epi (Sigma.desc π)
, ∀ b : B, ∃ (a : α) (x : X a), π a x = b
] := by
tfae_have 2 → 1
| _ => by
simpa [← effectiveEpi_desc_iff_effectiveEpiFamily, (effectiveEpi_tfae (Sigma.desc π)).out 0 1]
tfae_have 1 → 2 := fun _ ↦ inferInstance
tfae_have 3 ↔ 1 := by
erw [((CompHaus.effectiveEpiFamily_tfae
(fun a ↦ Stonean.toCompHaus.obj (X a)) (fun a ↦ Stonean.toCompHaus.map (π a))).out 2 0 : )]
exact ⟨fun h ↦ Stonean.toCompHaus.finite_effectiveEpiFamily_of_map _ _ h,
fun _ ↦ inferInstance⟩
tfae_finish
theorem effectiveEpiFamily_of_jointly_surjective
{α : Type} [Finite α] {B : Stonean.{u}}
(X : α → Stonean.{u}) (π : (a : α) → (X a ⟶ B))
(surj : ∀ b : B, ∃ (a : α) (x : X a), π a x = b) :
EffectiveEpiFamily X π :=
((effectiveEpiFamily_tfae X π).out 2 0).mp surj
end Stonean
| Mathlib/Topology/Category/Stonean/EffectiveEpi.lean | 103 | 121 | |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import Mathlib.Data.DFinsupp.Submonoid
import Mathlib.Data.Finsupp.ToDFinsupp
import Mathlib.LinearAlgebra.Finsupp.SumProd
import Mathlib.LinearAlgebra.LinearIndependent.Lemmas
/-!
# Properties of the module `Π₀ i, M i`
Given an indexed collection of `R`-modules `M i`, the `R`-module structure on `Π₀ i, M i`
is defined in `Mathlib.Data.DFinsupp.Module`.
In this file we define `LinearMap` versions of various maps:
* `DFinsupp.lsingle a : M →ₗ[R] Π₀ i, M i`: `DFinsupp.single a` as a linear map;
* `DFinsupp.lmk s : (Π i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i`: `DFinsupp.mk` as a linear map;
* `DFinsupp.lapply i : (Π₀ i, M i) →ₗ[R] M`: the map `fun f ↦ f i` as a linear map;
* `DFinsupp.lsum`: `DFinsupp.sum` or `DFinsupp.liftAddHom` as a `LinearMap`.
## Implementation notes
This file should try to mirror `LinearAlgebra.Finsupp` where possible. The API of `Finsupp` is
much more developed, but many lemmas in that file should be eligible to copy over.
## Tags
function with finite support, module, linear algebra
-/
variable {ι : Type*} {R : Type*} {S : Type*} {M : ι → Type*} {N : Type*}
namespace DFinsupp
variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
variable [AddCommMonoid N] [Module R N]
section DecidableEq
variable [DecidableEq ι]
/-- `DFinsupp.mk` as a `LinearMap`. -/
def lmk (s : Finset ι) : (∀ i : (↑s : Set ι), M i) →ₗ[R] Π₀ i, M i where
toFun := mk s
map_add' _ _ := mk_add
map_smul' c x := mk_smul c x
/-- `DFinsupp.single` as a `LinearMap` -/
def lsingle (i) : M i →ₗ[R] Π₀ i, M i :=
{ DFinsupp.singleAddHom _ _ with
toFun := single i
map_smul' := single_smul }
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere. -/
theorem lhom_ext ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i x, φ (single i x) = ψ (single i x)) : φ = ψ :=
LinearMap.toAddMonoidHom_injective <| addHom_ext h
/-- Two `R`-linear maps from `Π₀ i, M i` which agree on each `single i x` agree everywhere.
See note [partially-applied ext lemmas].
After applying this lemma, if `M = R` then it suffices to verify
`φ (single a 1) = ψ (single a 1)`. -/
@[ext 1100]
theorem lhom_ext' ⦃φ ψ : (Π₀ i, M i) →ₗ[R] N⦄ (h : ∀ i, φ.comp (lsingle i) = ψ.comp (lsingle i)) :
φ = ψ :=
lhom_ext fun i => LinearMap.congr_fun (h i)
theorem lmk_apply (s : Finset ι) (x) : (lmk s : _ →ₗ[R] Π₀ i, M i) x = mk s x :=
rfl
@[simp]
theorem lsingle_apply (i : ι) (x : M i) : (lsingle i : (M i) →ₗ[R] _) x = single i x :=
rfl
end DecidableEq
/-- Interpret `fun (f : Π₀ i, M i) ↦ f i` as a linear map. -/
def lapply (i : ι) : (Π₀ i, M i) →ₗ[R] M i where
toFun f := f i
map_add' f g := add_apply f g i
map_smul' c f := smul_apply c f i
@[simp]
theorem lapply_apply (i : ι) (f : Π₀ i, M i) : (lapply i : (Π₀ i, M i) →ₗ[R] _) f = f i :=
rfl
theorem injective_pi_lapply : Function.Injective (LinearMap.pi (R := R) <| lapply (M := M)) :=
fun _ _ h ↦ ext fun _ ↦ congr_fun h _
@[simp]
theorem lapply_comp_lsingle_same [DecidableEq ι] (i : ι) :
lapply i ∘ₗ lsingle i = (.id : M i →ₗ[R] M i) := by ext; simp
@[simp]
theorem lapply_comp_lsingle_of_ne [DecidableEq ι] (i i' : ι) (h : i ≠ i') :
lapply i ∘ₗ lsingle i' = (0 : M i' →ₗ[R] M i) := by ext; simp [h.symm]
section Lsum
variable (S)
variable [DecidableEq ι]
instance {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S)
{σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) (M₂ : Type*)
[AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module S M₂] :
EquivLike (LinearEquiv σ M M₂) M M₂ :=
inferInstance
/-- The `DFinsupp` version of `Finsupp.lsum`.
See note [bundled maps over different rings] for why separate `R` and `S` semirings are used. -/
@[simps]
def lsum [Semiring S] [Module S N] [SMulCommClass R S N] :
(∀ i, M i →ₗ[R] N) ≃ₗ[S] (Π₀ i, M i) →ₗ[R] N where
toFun F :=
{ toFun := sumAddHom fun i => (F i).toAddMonoidHom
map_add' := (DFinsupp.liftAddHom fun (i : ι) => (F i).toAddMonoidHom).map_add
map_smul' := fun c f => by
dsimp
apply DFinsupp.induction f
· rw [smul_zero, AddMonoidHom.map_zero, smul_zero]
· intro a b f _ _ hf
rw [smul_add, AddMonoidHom.map_add, AddMonoidHom.map_add, smul_add, hf, ← single_smul,
sumAddHom_single, sumAddHom_single, LinearMap.toAddMonoidHom_coe,
LinearMap.map_smul] }
invFun F i := F.comp (lsingle i)
left_inv F := by
ext
simp
right_inv F := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
map_add' F G := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
map_smul' c F := by
refine DFinsupp.lhom_ext' (fun i ↦ ?_)
ext
simp
/-- While `simp` can prove this, it is often convenient to avoid unfolding `lsum` into `sumAddHom`
with `DFinsupp.lsum_apply_apply`. -/
theorem lsum_single [Semiring S] [Module S N] [SMulCommClass R S N] (F : ∀ i, M i →ₗ[R] N) (i)
(x : M i) : lsum S F (single i x) = F i x := by
simp
theorem lsum_lsingle [Semiring S] [∀ i, Module S (M i)] [∀ i, SMulCommClass R S (M i)] :
lsum S (lsingle (R := R) (M := M)) = .id :=
lhom_ext (lsum_single _ _)
theorem iSup_range_lsingle : ⨆ i, LinearMap.range (lsingle (R := R) (M := M) i) = ⊤ :=
top_le_iff.mp fun m _ ↦ by
rw [← LinearMap.id_apply (R := R) m, ← lsum_lsingle ℕ]
exact dfinsuppSumAddHom_mem _ _ _ fun i _ ↦ Submodule.mem_iSup_of_mem i ⟨_, rfl⟩
end Lsum
/-! ### Bundled versions of `DFinsupp.mapRange`
The names should match the equivalent bundled `Finsupp.mapRange` definitions.
-/
section mapRange
variable {β β₁ β₂ : ι → Type*}
section AddCommMonoid
variable [∀ i, AddCommMonoid (β i)] [∀ i, AddCommMonoid (β₁ i)] [∀ i, AddCommMonoid (β₂ i)]
variable [∀ i, Module R (β i)] [∀ i, Module R (β₁ i)] [∀ i, Module R (β₂ i)]
lemma mker_mapRangeAddMonoidHom (f : ∀ i, β₁ i →+ β₂ i) :
AddMonoidHom.mker (mapRange.addMonoidHom f) =
(AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mker (f i))).comap coeFnAddMonoidHom := by
ext
simp [AddSubmonoid.pi, DFinsupp.ext_iff]
lemma mrange_mapRangeAddMonoidHom (f : ∀ i, β₁ i →+ β₂ i) :
AddMonoidHom.mrange (mapRange.addMonoidHom f) =
(AddSubmonoid.pi Set.univ (fun i ↦ AddMonoidHom.mrange (f i))).comap coeFnAddMonoidHom := by
classical
ext x
simp only [AddSubmonoid.mem_comap, mapRange.addMonoidHom_apply, coeFnAddMonoidHom_apply]
refine ⟨fun ⟨y, hy⟩ i hi ↦ ?_, fun h ↦ ?_⟩
| · simp [← hy]
· choose g hg using fun i => h i (Set.mem_univ _)
use DFinsupp.mk x.support (g ·)
ext i
simp only [Finset.coe_sort_coe, mapRange.addMonoidHom_apply, mapRange_apply]
| Mathlib/LinearAlgebra/DFinsupp.lean | 190 | 194 |
/-
Copyright (c) 2023 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.RepresentationTheory.GroupCohomology.Basic
import Mathlib.RepresentationTheory.Invariants
/-!
# The low-degree cohomology of a `k`-linear `G`-representation
Let `k` be a commutative ring and `G` a group. This file gives simple expressions for
the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2.
In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be
the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is
unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract
cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries.
We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`.
Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`,
we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an
element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the
scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The
multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case;
unfortunately `@[to_additive]` can't deal with scalar actions.
The file also contains an identification between the definitions in
`RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and
`groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`.
## Main definitions
* `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`.
* `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo
1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`).
* `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo
2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`).
* `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the
representation on `A` is trivial.
* `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism
`groupCohomology A n ≅ groupCohomology.Hn A`.
## TODO
* The relationship between `H2` and group extensions
* The inflation-restriction exact sequence
* Nonabelian group cohomology
-/
universe v u
noncomputable section
open CategoryTheory Limits Representation
variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G)
namespace groupCohomology
section Cochains
/-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `A` as a `k`-module. -/
def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A :=
LinearEquiv.funUnique (Fin 0 → G) k A
/-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G, A)` as a `k`-module. -/
def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A :=
LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm
/-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G², A)` as a `k`-module. -/
def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A :=
LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm
/-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic
to `Fun(G³, A)` as a `k`-module. -/
def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A :=
LinearEquiv.funCongrLeft k A <| ((Fin.consEquiv _).symm.trans
((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm
end Cochains
section Differentials
/-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/
@[simps]
def dZero : A →ₗ[k] G → A where
toFun m g := A.ρ g m - m
map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl
map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub]
theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by
ext x
simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, funext_iff]
rfl
@[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by
ext
simp only [dZero_apply, isTrivial_apply, sub_self, LinearMap.zero_apply, Pi.zero_apply]
lemma dZero_comp_subtype : dZero A ∘ₗ A.ρ.invariants.subtype = 0 := by
ext ⟨x, hx⟩ g
replace hx := hx g
rw [← sub_eq_zero] at hx
exact hx
/-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends
`(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
@[simps]
def dOne : (G → A) →ₗ[k] G × G → A where
toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1
map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm]
map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub]
/-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a
`k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends
`(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/
@[simps]
def dTwo : (G × G → A) →ₗ[k] G × G × G → A where
toFun f g :=
A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1)
map_add' x y :=
funext fun g => by
dsimp
rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm,
add_sub_assoc, add_sub_assoc]
map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub]
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `dZero` gives a simpler expression for the 0th differential: that is, the following
square commutes:
```
C⁰(G, A) ---d⁰---> C¹(G, A)
| |
| |
| |
v v
A ---- dZero ---> Fun(G, A)
```
where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively.
-/
theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) =
oneCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 0 1).hom := by
ext x y
show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _
simp_rw [Fin.val_eq_zero, zero_add, pow_one, neg_smul, one_smul,
Finset.sum_singleton, sub_eq_add_neg]
rcongr i <;> exact Fin.elim0 i
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `dOne` gives a simpler expression for the 1st differential: that is, the following
square commutes:
```
C¹(G, A) ---d¹-----> C²(G, A)
| |
| |
| |
v v
Fun(G, A) -dOne-> Fun(G × G, A)
```
where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively.
-/
theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A =
twoCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 1 2).hom := by
ext x y
show A.ρ y.1 (x _) - x _ + x _ = _ + _
rw [Fin.sum_univ_two]
simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one,
Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc]
rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl
/-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma
says `dTwo` gives a simpler expression for the 2nd differential: that is, the following
square commutes:
```
C²(G, A) -------d²-----> C³(G, A)
| |
| |
| |
v v
Fun(G × G, A) --dTwo--> Fun(G × G × G, A)
```
where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively.
-/
theorem dTwo_comp_eq :
dTwo A ∘ₗ twoCochainsLequiv A =
threeCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 2 3).hom := by
ext x y
show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _
dsimp
rw [Fin.sum_univ_three]
simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul,
one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one]
rcongr i <;> fin_cases i <;> rfl
theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by
ext x g
simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub,
map_mul, Module.End.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self]
rfl
theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by
show (ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A)).hom = _
have h1 := congr_arg ModuleCat.ofHom (dOne_comp_eq A)
have h2 := congr_arg ModuleCat.ofHom (dTwo_comp_eq A)
simp only [ModuleCat.ofHom_comp, ModuleCat.ofHom_comp, ← LinearEquiv.toModuleIso_hom] at h1 h2
simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, ModuleCat.ofHom_hom,
ModuleCat.hom_ofHom, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc,
zero_comp, comp_zero, ModuleCat.hom_zero]
open ShortComplex
/-- The (exact) short complex `A.ρ.invariants ⟶ A ⟶ (G → A)`. -/
def shortComplexH0 : ShortComplex (ModuleCat k) :=
moduleCatMk _ _ (dZero_comp_subtype A)
/-- The short complex `A --dZero--> Fun(G, A) --dOne--> Fun(G × G, A)`. -/
def shortComplexH1 : ShortComplex (ModuleCat k) :=
moduleCatMk (dZero A) (dOne A) (dOne_comp_dZero A)
/-- The short complex `Fun(G, A) --dOne--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)`. -/
def shortComplexH2 : ShortComplex (ModuleCat k) :=
moduleCatMk (dOne A) (dTwo A) (dTwo_comp_dOne A)
end Differentials
section Cocycles
/-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map
`Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A)
/-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map
`Fun(G × G, A) → Fun(G × G × G, A)` sending
`(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/
def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A)
variable {A}
instance : FunLike (oneCocycles A) G A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem oneCocycles.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : oneCocycles A) : G → A) = f := rfl
@[simp]
theorem oneCocycles.val_eq_coe (f : oneCocycles A) : f.1 = f := rfl
@[ext]
theorem oneCocycles_ext {f₁ f₂ : oneCocycles A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ h
theorem mem_oneCocycles_def (f : G → A) :
f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 :=
LinearMap.mem_ker.trans <| by
rw [funext_iff]
simp only [dOne_apply, Pi.zero_apply, Prod.forall]
theorem mem_oneCocycles_iff (f : G → A) :
f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by
simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm]
@[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f 1 = 0 := by
have := (mem_oneCocycles_def f).1 f.2 1 1
simpa only [map_one, Module.End.one_apply, mul_one, sub_self, zero_add] using this
@[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) :
A.ρ g (f g⁻¹) = - f g := by
rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_cancel g,
(mem_oneCocycles_iff f).1 f.2 g g⁻¹]
theorem dZero_apply_mem_oneCocycles (x : A) :
dZero A x ∈ oneCocycles A :=
congr($(dOne_comp_dZero A) x)
theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) :
f (g * h) = f g + f h := by
rw [(mem_oneCocycles_iff f).1 f.2, isTrivial_apply A.ρ g (f h), add_comm]
theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) :
f ∘ Additive.ofMul ∈ oneCocycles A :=
(mem_oneCocycles_iff _).2 fun g h => by
simp only [Function.comp_apply, ofMul_mul, map_add,
oneCocycles_map_mul_of_isTrivial, isTrivial_apply A.ρ g (f (Additive.ofMul h)),
add_comm (f (Additive.ofMul g))]
variable (A) in
/-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the
group homs `G → A`. -/
@[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] :
oneCocycles A ≃ₗ[k] Additive G →+ A where
toFun f :=
{ toFun := f ∘ Additive.toMul
map_zero' := oneCocycles_map_one f
map_add' := oneCocycles_map_mul_of_isTrivial f }
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f :=
{ val := f
property := mem_oneCocycles_of_addMonoidHom f }
left_inv f := by ext; rfl
right_inv f := by ext; rfl
instance : FunLike (twoCocycles A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem twoCocycles.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : twoCocycles A) : G × G → A) = f := rfl
@[simp]
theorem twoCocycles.val_eq_coe (f : twoCocycles A) : f.1 = f := rfl
@[ext]
theorem twoCocycles_ext {f₁ f₂ : twoCocycles A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ (Prod.forall.mpr h)
theorem mem_twoCocycles_def (f : G × G → A) :
f ∈ twoCocycles A ↔ ∀ g h j : G,
A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 :=
LinearMap.mem_ker.trans <| by
rw [funext_iff]
simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall]
theorem mem_twoCocycles_iff (f : G × G → A) :
f ∈ twoCocycles A ↔ ∀ g h j : G,
f (g * h, j) + f (g, h) =
A.ρ g (f (h, j)) + f (g, h * j) := by
simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm,
add_comm (f (_ * _, _))]
theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) :
f (1, g) = f (1, 1) := by
have := ((mem_twoCocycles_iff f).1 f.2 1 1 g).symm
simpa only [map_one, Module.End.one_apply, one_mul, add_right_inj, this]
theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) :
f (g, 1) = A.ρ g (f (1, 1)) := by
have := (mem_twoCocycles_iff f).1 f.2 g 1 1
simpa only [mul_one, add_left_inj, this]
lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) :
A.ρ g (f (g⁻¹, g)) - f (g, g⁻¹)
= f (1, 1) - f (g, 1) := by
have := (mem_twoCocycles_iff f).1 f.2 g g⁻¹ g
simp only [mul_inv_cancel, inv_mul_cancel, twoCocycles_map_one_fst _ g]
at this
exact sub_eq_sub_iff_add_eq_add.2 this.symm
theorem dOne_apply_mem_twoCocycles (x : G → A) :
dOne A x ∈ twoCocycles A :=
congr($(dTwo_comp_dOne A) x)
end Cocycles
section Coboundaries
/-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map
`A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/
def oneCoboundaries : Submodule k (G → A) :=
LinearMap.range (dZero A)
/-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map
`Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/
def twoCoboundaries : Submodule k (G × G → A) :=
LinearMap.range (dOne A)
variable {A}
instance : FunLike (oneCoboundaries A) G A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem oneCoboundaries.coe_mk (f : G → A) (hf) :
((⟨f, hf⟩ : oneCoboundaries A) : G → A) = f := rfl
@[simp]
theorem oneCoboundaries.val_eq_coe (f : oneCoboundaries A) : f.1 = f := rfl
@[ext]
theorem oneCoboundaries_ext {f₁ f₂ : oneCoboundaries A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ :=
DFunLike.ext f₁ f₂ h
variable (A) in
lemma oneCoboundaries_le_oneCocycles : oneCoboundaries A ≤ oneCocycles A := by
rintro _ ⟨x, rfl⟩
exact dZero_apply_mem_oneCocycles x
variable (A) in
/-- Natural inclusion `B¹(G, A) →ₗ[k] Z¹(G, A)`. -/
abbrev oneCoboundariesToOneCocycles : oneCoboundaries A →ₗ[k] oneCocycles A :=
Submodule.inclusion (oneCoboundaries_le_oneCocycles A)
@[simp]
lemma oneCoboundariesToOneCocycles_apply (x : oneCoboundaries A) :
oneCoboundariesToOneCocycles A x = x.1 := rfl
theorem oneCoboundaries_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] :
oneCoboundaries A = ⊥ := by
simp_rw [oneCoboundaries, dZero_eq_zero]
exact LinearMap.range_eq_bot.2 rfl
instance : FunLike (twoCoboundaries A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩
@[simp]
theorem twoCoboundaries.coe_mk (f : G × G → A) (hf) :
((⟨f, hf⟩ : twoCoboundaries A) : G × G → A) = f := rfl
@[simp]
theorem twoCoboundaries.val_eq_coe (f : twoCoboundaries A) : f.1 = f := rfl
@[ext]
theorem twoCoboundaries_ext {f₁ f₂ : twoCoboundaries A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) :
f₁ = f₂ :=
DFunLike.ext f₁ f₂ (Prod.forall.mpr h)
variable (A) in
lemma twoCoboundaries_le_twoCocycles : twoCoboundaries A ≤ twoCocycles A := by
rintro _ ⟨x, rfl⟩
exact dOne_apply_mem_twoCocycles x
variable (A) in
/-- Natural inclusion `B²(G, A) →ₗ[k] Z²(G, A)`. -/
abbrev twoCoboundariesToTwoCocycles : twoCoboundaries A →ₗ[k] twoCocycles A :=
Submodule.inclusion (twoCoboundaries_le_twoCocycles A)
@[simp]
lemma twoCoboundariesToTwoCocycles_apply (x : twoCoboundaries A) :
twoCoboundariesToTwoCocycles A x = x.1 := rfl
end Coboundaries
section IsCocycle
section
variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A]
/-- A function `f : G → A` satisfies the 1-cocycle condition if
`f(gh) = g • f(h) + f(g)` for all `g, h : G`. -/
def IsOneCocycle (f : G → A) : Prop := ∀ g h : G, f (g * h) = g • f h + f g
/-- A function `f : G × G → A` satisfies the 2-cocycle condition if
`f(gh, j) + f(g, h) = g • f(h, j) + f(g, hj)` for all `g, h : G`. -/
def IsTwoCocycle (f : G × G → A) : Prop :=
∀ g h j : G, f (g * h, j) + f (g, h) = g • (f (h, j)) + f (g, h * j)
end
section
variable {G A : Type*} [Monoid G] [AddCommGroup A] [MulAction G A]
theorem map_one_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) :
f 1 = 0 := by
simpa only [mul_one, one_smul, left_eq_add] using hf 1 1
theorem map_one_fst_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) :
f (1, g) = f (1, 1) := by
simpa only [one_smul, one_mul, mul_one, add_right_inj] using (hf 1 1 g).symm
theorem map_one_snd_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) :
f (g, 1) = g • f (1, 1) := by
simpa only [mul_one, add_left_inj] using hf g 1 1
end
section
variable {G A : Type*} [Group G] [AddCommGroup A] [MulAction G A]
@[scoped simp] theorem map_inv_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) (g : G) :
g • f g⁻¹ = - f g := by
rw [← add_eq_zero_iff_eq_neg, ← map_one_of_isOneCocycle hf, ← mul_inv_cancel g, hf g g⁻¹]
theorem smul_map_inv_sub_map_inv_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) :
g • f (g⁻¹, g) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by
have := hf g g⁻¹ g
simp only [mul_inv_cancel, inv_mul_cancel, map_one_fst_of_isTwoCocycle hf g] at this
exact sub_eq_sub_iff_add_eq_add.2 this.symm
end
end IsCocycle
section IsCoboundary
variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A]
/-- A function `f : G → A` satisfies the 1-coboundary condition if there's `x : A` such that
`g • x - x = f(g)` for all `g : G`. -/
def IsOneCoboundary (f : G → A) : Prop := ∃ x : A, ∀ g : G, g • x - x = f g
/-- A function `f : G × G → A` satisfies the 2-coboundary condition if there's `x : G → A` such
that `g • x(h) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/
def IsTwoCoboundary (f : G × G → A) : Prop :=
∃ x : G → A, ∀ g h : G, g • x h - x (g * h) + x g = f (g, h)
end IsCoboundary
section ofDistribMulAction
variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A]
[DistribMulAction G A] [SMulCommClass G k A]
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G → A` satisfying the 1-cocycle condition, produces a 1-cocycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def oneCocyclesOfIsOneCocycle {f : G → A} (hf : IsOneCocycle f) :
oneCocycles (Rep.ofDistribMulAction k G A) :=
⟨f, (mem_oneCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩
theorem isOneCocycle_of_mem_oneCocycles
(f : G → A) (hf : f ∈ oneCocycles (Rep.ofDistribMulAction k G A)) :
IsOneCocycle f :=
fun _ _ => (mem_oneCocycles_iff (A := Rep.ofDistribMulAction k G A) f).1 hf _ _
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G → A` satisfying the 1-coboundary condition, produces a 1-coboundary for the representation
on `A` induced by the `DistribMulAction`. -/
@[simps]
def oneCoboundariesOfIsOneCoboundary {f : G → A} (hf : IsOneCoboundary f) :
oneCoboundaries (Rep.ofDistribMulAction k G A) :=
⟨f, hf.choose, funext hf.choose_spec⟩
theorem isOneCoboundary_of_mem_oneCoboundaries
(f : G → A) (hf : f ∈ oneCoboundaries (Rep.ofDistribMulAction k G A)) :
IsOneCoboundary f := by
rcases hf with ⟨a, rfl⟩
exact ⟨a, fun _ => rfl⟩
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G × G → A` satisfying the 2-cocycle condition, produces a 2-cocycle for the representation on
`A` induced by the `DistribMulAction`. -/
@[simps]
def twoCocyclesOfIsTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) :
twoCocycles (Rep.ofDistribMulAction k G A) :=
⟨f, (mem_twoCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩
theorem isTwoCocycle_of_mem_twoCocycles
(f : G × G → A) (hf : f ∈ twoCocycles (Rep.ofDistribMulAction k G A)) :
IsTwoCocycle f := (mem_twoCocycles_iff (A := Rep.ofDistribMulAction k G A) f).1 hf
/-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function
`f : G × G → A` satisfying the 2-coboundary condition, produces a 2-coboundary for the
representation on `A` induced by the `DistribMulAction`. -/
@[simps]
def twoCoboundariesOfIsTwoCoboundary {f : G × G → A} (hf : IsTwoCoboundary f) :
twoCoboundaries (Rep.ofDistribMulAction k G A) :=
⟨f, hf.choose,funext fun g ↦ hf.choose_spec g.1 g.2⟩
theorem isTwoCoboundary_of_mem_twoCoboundaries
(f : G × G → A) (hf : f ∈ twoCoboundaries (Rep.ofDistribMulAction k G A)) :
IsTwoCoboundary f := by
rcases hf with ⟨a, rfl⟩
exact ⟨a, fun _ _ => rfl⟩
end ofDistribMulAction
/-! The next few sections, until the section `Cohomology`, are a multiplicative copy of the
previous few sections beginning with `IsCocycle`. Unfortunately `@[to_additive]` doesn't work with
scalar actions. -/
section IsMulCocycle
section
variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M]
/-- A function `f : G → M` satisfies the multiplicative 1-cocycle condition if
`f(gh) = g • f(h) * f(g)` for all `g, h : G`. -/
def IsMulOneCocycle (f : G → M) : Prop := ∀ g h : G, f (g * h) = g • f h * f g
/-- A function `f : G × G → M` satisfies the multiplicative 2-cocycle condition if
`f(gh, j) * f(g, h) = g • f(h, j) * f(g, hj)` for all `g, h : G`. -/
def IsMulTwoCocycle (f : G × G → M) : Prop :=
∀ g h j : G, f (g * h, j) * f (g, h) = g • (f (h, j)) * f (g, h * j)
end
section
variable {G M : Type*} [Monoid G] [CommGroup M] [MulAction G M]
theorem map_one_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) :
f 1 = 1 := by
simpa only [mul_one, one_smul, left_eq_mul] using hf 1 1
theorem map_one_fst_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) :
f (1, g) = f (1, 1) := by
simpa only [one_smul, one_mul, mul_one, mul_right_inj] using (hf 1 1 g).symm
theorem map_one_snd_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) :
f (g, 1) = g • f (1, 1) := by
simpa only [mul_one, mul_left_inj] using hf g 1 1
end
section
variable {G M : Type*} [Group G] [CommGroup M] [MulAction G M]
@[scoped simp] theorem map_inv_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) (g : G) :
g • f g⁻¹ = (f g)⁻¹ := by
rw [← mul_eq_one_iff_eq_inv, ← map_one_of_isMulOneCocycle hf, ← mul_inv_cancel g, hf g g⁻¹]
theorem smul_map_inv_div_map_inv_of_isMulTwoCocycle
{f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) :
g • f (g⁻¹, g) / f (g, g⁻¹) = f (1, 1) / f (g, 1) := by
have := hf g g⁻¹ g
simp only [mul_inv_cancel, inv_mul_cancel, map_one_fst_of_isMulTwoCocycle hf g] at this
| exact div_eq_div_iff_mul_eq_mul.2 this.symm
end
end IsMulCocycle
| Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean | 617 | 621 |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Nat.Even
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Nat.Cast.Commute
import Mathlib.Data.Set.Operations
import Mathlib.Logic.Function.Iterate
/-!
# Even and odd elements in rings
This file defines odd elements and proves some general facts about even and odd elements of rings.
As opposed to `Even`, `Odd` does not have a multiplicative counterpart.
## TODO
Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring`
assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved
to `Mathlib.Algebra.Group.Even`.
## See also
`Mathlib.Algebra.Group.Even` for the definition of even elements.
-/
assert_not_exists DenselyOrdered OrderedRing
open MulOpposite
variable {F α β : Type*}
section Monoid
variable [Monoid α] [HasDistribNeg α] {n : ℕ} {a : α}
@[simp] lemma Even.neg_pow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by
rintro ⟨c, rfl⟩ a
simp_rw [← two_mul, pow_mul, neg_sq]
lemma Even.neg_one_pow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow]
end Monoid
section DivisionMonoid
variable [DivisionMonoid α] [HasDistribNeg α] {a : α} {n : ℤ}
lemma Even.neg_zpow : Even n → ∀ a : α, (-a) ^ n = a ^ n := by
rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg]
lemma Even.neg_one_zpow (h : Even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow]
end DivisionMonoid
@[simp] lemma IsSquare.zero [MulZeroClass α] : IsSquare (0 : α) := ⟨0, (mul_zero _).symm⟩
section Semiring
variable [Semiring α] [Semiring β] {a b : α} {m n : ℕ}
lemma even_iff_exists_two_mul : Even a ↔ ∃ b, a = 2 * b := by simp [even_iff_exists_two_nsmul]
lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul]
alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd
lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b :=
even_iff_two_dvd.2 <| ha.two_dvd.trans hab
lemma Dvd.dvd.even (hab : a ∣ b) (ha : Even a) : Even b := ha.trans_dvd hab
| Mathlib/Algebra/Ring/Parity.lean | 72 | 72 | |
/-
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.Data.Finset.Pi
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Finset.Sum
import Mathlib.Data.Set.Finite.Basic
/-!
# Preimage of a `Finset` under an injective map.
-/
assert_not_exists Finset.sum
open Set Function
universe u v w x
variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace Finset
section Preimage
/-- Preimage of `s : Finset β` under a map `f` injective on `f ⁻¹' s` as a `Finset`. -/
noncomputable def preimage (s : Finset β) (f : α → β) (hf : Set.InjOn f (f ⁻¹' ↑s)) : Finset α :=
(s.finite_toSet.preimage hf).toFinset
@[simp]
theorem mem_preimage {f : α → β} {s : Finset β} {hf : Set.InjOn f (f ⁻¹' ↑s)} {x : α} :
x ∈ preimage s f hf ↔ f x ∈ s :=
Set.Finite.mem_toFinset _
@[simp, norm_cast]
theorem coe_preimage {f : α → β} (s : Finset β) (hf : Set.InjOn f (f ⁻¹' ↑s)) :
(↑(preimage s f hf) : Set α) = f ⁻¹' ↑s :=
Set.Finite.coe_toFinset _
@[simp]
theorem preimage_empty {f : α → β} : preimage ∅ f (by simp [InjOn]) = ∅ :=
Finset.coe_injective (by simp)
@[simp]
theorem preimage_univ {f : α → β} [Fintype α] [Fintype β] (hf) : preimage univ f hf = univ :=
Finset.coe_injective (by simp)
@[simp]
theorem preimage_inter [DecidableEq α] [DecidableEq β] {f : α → β} {s t : Finset β}
(hs : Set.InjOn f (f ⁻¹' ↑s)) (ht : Set.InjOn f (f ⁻¹' ↑t)) :
(preimage (s ∩ t) f fun _ hx₁ _ hx₂ =>
hs (mem_of_mem_inter_left hx₁) (mem_of_mem_inter_left hx₂)) =
preimage s f hs ∩ preimage t f ht :=
Finset.coe_injective (by simp)
@[simp]
theorem preimage_union [DecidableEq α] [DecidableEq β] {f : α → β} {s t : Finset β} (hst) :
preimage (s ∪ t) f hst =
(preimage s f fun _ hx₁ _ hx₂ => hst (mem_union_left _ hx₁) (mem_union_left _ hx₂)) ∪
preimage t f fun _ hx₁ _ hx₂ => hst (mem_union_right _ hx₁) (mem_union_right _ hx₂) :=
Finset.coe_injective (by simp)
@[simp]
theorem preimage_compl' [DecidableEq α] [DecidableEq β] [Fintype α] [Fintype β] {f : α → β}
(s : Finset β) (hfc : InjOn f (f ⁻¹' ↑sᶜ)) (hf : InjOn f (f ⁻¹' ↑s)) :
preimage sᶜ f hfc = (preimage s f hf)ᶜ :=
Finset.coe_injective (by simp)
-- Not `@[simp]` since `simp` can't figure out `hf`; `simp`-normal form is `preimage_compl'`.
theorem preimage_compl [DecidableEq α] [DecidableEq β] [Fintype α] [Fintype β] {f : α → β}
(s : Finset β) (hf : Function.Injective f) :
preimage sᶜ f hf.injOn = (preimage s f hf.injOn)ᶜ :=
preimage_compl' _ _ _
@[simp]
lemma preimage_map (f : α ↪ β) (s : Finset α) : (s.map f).preimage f f.injective.injOn = s :=
coe_injective <| by simp only [coe_preimage, coe_map, Set.preimage_image_eq _ f.injective]
theorem monotone_preimage {f : α → β} (h : Injective f) :
Monotone fun s => preimage s f h.injOn := fun _ _ H _ hx =>
mem_preimage.2 (H <| mem_preimage.1 hx)
theorem image_subset_iff_subset_preimage [DecidableEq β] {f : α → β} {s : Finset α} {t : Finset β}
(hf : Set.InjOn f (f ⁻¹' ↑t)) : s.image f ⊆ t ↔ s ⊆ t.preimage f hf :=
image_subset_iff.trans <| by simp only [subset_iff, mem_preimage]
theorem map_subset_iff_subset_preimage {f : α ↪ β} {s : Finset α} {t : Finset β} :
s.map f ⊆ t ↔ s ⊆ t.preimage f f.injective.injOn := by
classical rw [map_eq_image, image_subset_iff_subset_preimage]
lemma card_preimage (s : Finset β) (f : α → β) (hf) [DecidablePred (· ∈ Set.range f)] :
(s.preimage f hf).card = {x ∈ s | x ∈ Set.range f}.card :=
card_nbij f (by simp) (by simpa) (fun b hb ↦ by aesop)
theorem image_preimage [DecidableEq β] (f : α → β) (s : Finset β) [∀ x, Decidable (x ∈ Set.range f)]
| (hf : Set.InjOn f (f ⁻¹' ↑s)) : image f (preimage s f hf) = {x ∈ s | x ∈ Set.range f} :=
Finset.coe_inj.1 <| by
simp only [coe_image, coe_preimage, coe_filter, Set.image_preimage_eq_inter_range,
← Set.sep_mem_eq]; rfl
| Mathlib/Data/Finset/Preimage.lean | 97 | 101 |
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll, Thomas Zhu, Mario Carneiro
-/
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
/-!
# The Jacobi Symbol
We define the Jacobi symbol and prove its main properties.
## Main definitions
We define the Jacobi symbol, `jacobiSym a b`, for integers `a` and natural numbers `b`
as the product over the prime factors `p` of `b` of the Legendre symbols `legendreSym p a`.
This agrees with the mathematical definition when `b` is odd.
The prime factors are obtained via `Nat.factors`. Since `Nat.factors 0 = []`,
this implies in particular that `jacobiSym a 0 = 1` for all `a`.
## Main statements
We prove the main properties of the Jacobi symbol, including the following.
* Multiplicativity in both arguments (`jacobiSym.mul_left`, `jacobiSym.mul_right`)
* The value of the symbol is `1` or `-1` when the arguments are coprime
(`jacobiSym.eq_one_or_neg_one`)
* The symbol vanishes if and only if `b ≠ 0` and the arguments are not coprime
(`jacobiSym.eq_zero_iff_not_coprime`)
* If the symbol has the value `-1`, then `a : ZMod b` is not a square
(`ZMod.nonsquare_of_jacobiSym_eq_neg_one`); the converse holds when `b = p` is a prime
(`ZMod.nonsquare_iff_jacobiSym_eq_neg_one`); in particular, in this case `a` is a
square mod `p` when the symbol has the value `1` (`ZMod.isSquare_of_jacobiSym_eq_one`).
* Quadratic reciprocity (`jacobiSym.quadratic_reciprocity`,
`jacobiSym.quadratic_reciprocity_one_mod_four`,
`jacobiSym.quadratic_reciprocity_three_mod_four`)
* The supplementary laws for `a = -1`, `a = 2`, `a = -2` (`jacobiSym.at_neg_one`,
`jacobiSym.at_two`, `jacobiSym.at_neg_two`)
* The symbol depends on `a` only via its residue class mod `b` (`jacobiSym.mod_left`)
and on `b` only via its residue class mod `4*a` (`jacobiSym.mod_right`)
* A `csimp` rule for `jacobiSym` and `legendreSym` that evaluates `J(a | b)` efficiently by
reducing to the case `0 ≤ a < b` and `a`, `b` odd, and then swaps `a`, `b` and recurses using
quadratic reciprocity.
## Notations
We define the notation `J(a | b)` for `jacobiSym a b`, localized to `NumberTheorySymbols`.
## Tags
Jacobi symbol, quadratic reciprocity
-/
section Jacobi
/-!
### Definition of the Jacobi symbol
We define the Jacobi symbol $\Bigl(\frac{a}{b}\Bigr)$ for integers `a` and natural numbers `b`
as the product of the Legendre symbols $\Bigl(\frac{a}{p}\Bigr)$, where `p` runs through the
prime divisors (with multiplicity) of `b`, as provided by `b.factors`. This agrees with the
Jacobi symbol when `b` is odd and gives less meaningful values when it is not (e.g., the symbol
is `1` when `b = 0`). This is called `jacobiSym a b`.
We define localized notation (locale `NumberTheorySymbols`) `J(a | b)` for the Jacobi
symbol `jacobiSym a b`.
-/
open Nat ZMod
-- Since we need the fact that the factors are prime, we use `List.pmap`.
/-- The Jacobi symbol of `a` and `b` -/
def jacobiSym (a : ℤ) (b : ℕ) : ℤ :=
(b.primeFactorsList.pmap (fun p pp => @legendreSym p ⟨pp⟩ a) fun _ pf =>
prime_of_mem_primeFactorsList pf).prod
-- Notation for the Jacobi symbol.
@[inherit_doc]
scoped[NumberTheorySymbols] notation "J(" a " | " b ")" => jacobiSym a b
open NumberTheorySymbols
/-!
### Properties of the Jacobi symbol
-/
namespace jacobiSym
/-- The symbol `J(a | 0)` has the value `1`. -/
@[simp]
theorem zero_right (a : ℤ) : J(a | 0) = 1 := by
simp only [jacobiSym, primeFactorsList_zero, List.prod_nil, List.pmap]
/-- The symbol `J(a | 1)` has the value `1`. -/
@[simp]
theorem one_right (a : ℤ) : J(a | 1) = 1 := by
simp only [jacobiSym, primeFactorsList_one, List.prod_nil, List.pmap]
/-- The Legendre symbol `legendreSym p a` with an integer `a` and a prime number `p`
is the same as the Jacobi symbol `J(a | p)`. -/
theorem legendreSym.to_jacobiSym (p : ℕ) [fp : Fact p.Prime] (a : ℤ) :
legendreSym p a = J(a | p) := by
simp only [jacobiSym, primeFactorsList_prime fp.1, List.prod_cons, List.prod_nil, mul_one,
List.pmap]
/-- The Jacobi symbol is multiplicative in its second argument. -/
theorem mul_right' (a : ℤ) {b₁ b₂ : ℕ} (hb₁ : b₁ ≠ 0) (hb₂ : b₂ ≠ 0) :
J(a | b₁ * b₂) = J(a | b₁) * J(a | b₂) := by
rw [jacobiSym, ((perm_primeFactorsList_mul hb₁ hb₂).pmap _).prod_eq, List.pmap_append,
List.prod_append]
pick_goal 2
· exact fun p hp =>
(List.mem_append.mp hp).elim prime_of_mem_primeFactorsList prime_of_mem_primeFactorsList
· rfl
/-- The Jacobi symbol is multiplicative in its second argument. -/
theorem mul_right (a : ℤ) (b₁ b₂ : ℕ) [NeZero b₁] [NeZero b₂] :
J(a | b₁ * b₂) = J(a | b₁) * J(a | b₂) :=
mul_right' a (NeZero.ne b₁) (NeZero.ne b₂)
/-- The Jacobi symbol takes only the values `0`, `1` and `-1`. -/
theorem trichotomy (a : ℤ) (b : ℕ) : J(a | b) = 0 ∨ J(a | b) = 1 ∨ J(a | b) = -1 :=
((MonoidHom.mrange (@SignType.castHom ℤ _ _).toMonoidHom).copy {0, 1, -1} <| by
rw [Set.pair_comm]
exact (SignType.range_eq SignType.castHom).symm).list_prod_mem
(by
intro _ ha'
rcases List.mem_pmap.mp ha' with ⟨p, hp, rfl⟩
haveI : Fact p.Prime := ⟨prime_of_mem_primeFactorsList hp⟩
exact quadraticChar_isQuadratic (ZMod p) a)
/-- The symbol `J(1 | b)` has the value `1`. -/
@[simp]
theorem one_left (b : ℕ) : J(1 | b) = 1 :=
List.prod_eq_one fun z hz => by
let ⟨p, hp, he⟩ := List.mem_pmap.1 hz
rw [← he, legendreSym.at_one]
/-- The Jacobi symbol is multiplicative in its first argument. -/
theorem mul_left (a₁ a₂ : ℤ) (b : ℕ) : J(a₁ * a₂ | b) = J(a₁ | b) * J(a₂ | b) := by
simp_rw [jacobiSym, List.pmap_eq_map_attach, legendreSym.mul _ _ _]
exact List.prod_map_mul (α := ℤ) (l := (primeFactorsList b).attach)
(f := fun x ↦ @legendreSym x {out := prime_of_mem_primeFactorsList x.2} a₁)
(g := fun x ↦ @legendreSym x {out := prime_of_mem_primeFactorsList x.2} a₂)
/-- The symbol `J(a | b)` vanishes iff `a` and `b` are not coprime (assuming `b ≠ 0`). -/
theorem eq_zero_iff_not_coprime {a : ℤ} {b : ℕ} [NeZero b] : J(a | b) = 0 ↔ a.gcd b ≠ 1 :=
List.prod_eq_zero_iff.trans
(by
rw [List.mem_pmap, Int.gcd_eq_natAbs, Ne, Prime.not_coprime_iff_dvd]
simp_rw [legendreSym.eq_zero_iff _ _, intCast_zmod_eq_zero_iff_dvd,
mem_primeFactorsList (NeZero.ne b), ← Int.natCast_dvd, Int.natCast_dvd_natCast, exists_prop,
and_assoc, _root_.and_comm])
/-- The symbol `J(a | b)` is nonzero when `a` and `b` are coprime. -/
protected theorem ne_zero {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) ≠ 0 := by
rcases eq_zero_or_neZero b with hb | _
· rw [hb, zero_right]
exact one_ne_zero
· contrapose! h; exact eq_zero_iff_not_coprime.1 h
/-- The symbol `J(a | b)` vanishes if and only if `b ≠ 0` and `a` and `b` are not coprime. -/
theorem eq_zero_iff {a : ℤ} {b : ℕ} : J(a | b) = 0 ↔ b ≠ 0 ∧ a.gcd b ≠ 1 :=
⟨fun h => by
rcases eq_or_ne b 0 with hb | hb
· rw [hb, zero_right] at h; cases h
exact ⟨hb, mt jacobiSym.ne_zero <| Classical.not_not.2 h⟩, fun ⟨hb, h⟩ => by
rw [← neZero_iff] at hb; exact eq_zero_iff_not_coprime.2 h⟩
/-- The symbol `J(0 | b)` vanishes when `b > 1`. -/
theorem zero_left {b : ℕ} (hb : 1 < b) : J(0 | b) = 0 :=
(@eq_zero_iff_not_coprime 0 b ⟨ne_zero_of_lt hb⟩).mpr <| by
rw [Int.gcd_zero_left, Int.natAbs_natCast]; exact hb.ne'
/-- The symbol `J(a | b)` takes the value `1` or `-1` if `a` and `b` are coprime. -/
theorem eq_one_or_neg_one {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) = 1 ∨ J(a | b) = -1 :=
(trichotomy a b).resolve_left <| jacobiSym.ne_zero h
/-- We have that `J(a^e | b) = J(a | b)^e`. -/
theorem pow_left (a : ℤ) (e b : ℕ) : J(a ^ e | b) = J(a | b) ^ e :=
Nat.recOn e (by rw [_root_.pow_zero, _root_.pow_zero, one_left]) fun _ ih => by
rw [_root_.pow_succ, _root_.pow_succ, mul_left, ih]
/-- We have that `J(a | b^e) = J(a | b)^e`. -/
theorem pow_right (a : ℤ) (b e : ℕ) : J(a | b ^ e) = J(a | b) ^ e := by
| induction e with
| zero => rw [Nat.pow_zero, _root_.pow_zero, one_right]
| succ e ih =>
| Mathlib/NumberTheory/LegendreSymbol/JacobiSymbol.lean | 196 | 198 |
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.Measure.MeasureSpace
import Mathlib.MeasureTheory.Measure.Regular
import Mathlib.Topology.Sets.Compacts
/-!
# Contents
In this file we work with *contents*. A content `λ` is a function from a certain class of subsets
(such as the compact subsets) to `ℝ≥0` that is
* additive: If `K₁` and `K₂` are disjoint sets in the domain of `λ`,
then `λ(K₁ ∪ K₂) = λ(K₁) + λ(K₂)`;
* subadditive: If `K₁` and `K₂` are in the domain of `λ`, then `λ(K₁ ∪ K₂) ≤ λ(K₁) + λ(K₂)`;
* monotone: If `K₁ ⊆ K₂` are in the domain of `λ`, then `λ(K₁) ≤ λ(K₂)`.
We show that:
* Given a content `λ` on compact sets, let us define a function `λ*` on open sets, by letting
`λ* U` be the supremum of `λ K` for `K` included in `U`. This is a countably subadditive map that
vanishes at `∅`. In Halmos (1950) this is called the *inner content* `λ*` of `λ`, and formalized
as `innerContent`.
* Given an inner content, we define an outer measure `μ*`, by letting `μ* E` be the infimum of
`λ* U` over the open sets `U` containing `E`. This is indeed an outer measure. It is formalized
as `outerMeasure`.
* Restricting this outer measure to Borel sets gives a regular measure `μ`.
We define bundled contents as `Content`.
In this file we only work on contents on compact sets, and inner contents on open sets, and both
contents and inner contents map into the extended nonnegative reals. However, in other applications
other choices can be made, and it is not a priori clear what the best interface should be.
## Main definitions
For `μ : Content G`, we define
* `μ.innerContent` : the inner content associated to `μ`.
* `μ.outerMeasure` : the outer measure associated to `μ`.
* `μ.measure` : the Borel measure associated to `μ`.
These definitions are given for spaces which are R₁.
The resulting measure `μ.measure` is always outer regular by design.
When the space is locally compact, `μ.measure` is also regular.
## References
* Paul Halmos (1950), Measure Theory, §53
* <https://en.wikipedia.org/wiki/Content_(measure_theory)>
-/
universe u v w
noncomputable section
open Set TopologicalSpace
open NNReal ENNReal MeasureTheory
namespace MeasureTheory
variable {G : Type w} [TopologicalSpace G]
/-- A content is an additive function on compact sets taking values in `ℝ≥0`. It is a device
from which one can define a measure. -/
structure Content (G : Type w) [TopologicalSpace G] where
/-- The underlying additive function -/
toFun : Compacts G → ℝ≥0
mono' : ∀ K₁ K₂ : Compacts G, (K₁ : Set G) ⊆ K₂ → toFun K₁ ≤ toFun K₂
sup_disjoint' :
∀ K₁ K₂ : Compacts G, Disjoint (K₁ : Set G) K₂ → IsClosed (K₁ : Set G) → IsClosed (K₂ : Set G)
→ toFun (K₁ ⊔ K₂) = toFun K₁ + toFun K₂
sup_le' : ∀ K₁ K₂ : Compacts G, toFun (K₁ ⊔ K₂) ≤ toFun K₁ + toFun K₂
instance : Inhabited (Content G) :=
⟨{ toFun := fun _ => 0
mono' := by simp
sup_disjoint' := by simp
sup_le' := by simp }⟩
namespace Content
instance : FunLike (Content G) (Compacts G) ℝ≥0∞ where
coe μ s := μ.toFun s
coe_injective' := by
rintro ⟨μ, _, _⟩ ⟨v, _, _⟩ h; congr!; ext s : 1; exact ENNReal.coe_injective <| congr_fun h s
variable (μ : Content G)
@[simp] lemma toFun_eq_toNNReal_apply (K : Compacts G) : μ.toFun K = (μ K).toNNReal := rfl
@[simp]
lemma mk_apply (toFun : Compacts G → ℝ≥0) (mono' sup_disjoint' sup_le') (K : Compacts G) :
mk toFun mono' sup_disjoint' sup_le' K = toFun K := rfl
@[simp] lemma apply_ne_top {K : Compacts G} : μ K ≠ ∞ := coe_ne_top
@[deprecated toFun_eq_toNNReal_apply (since := "2025-02-11")]
theorem apply_eq_coe_toFun (K : Compacts G) : μ K = μ.toFun K :=
rfl
|
theorem mono (K₁ K₂ : Compacts G) (h : (K₁ : Set G) ⊆ K₂) : μ K₁ ≤ μ K₂ := by
simpa using μ.mono' _ _ h
| Mathlib/MeasureTheory/Measure/Content.lean | 102 | 105 |
/-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.Order.Group.Multiset
import Mathlib.Data.Setoid.Basic
import Mathlib.Data.Vector.Basic
import Mathlib.Logic.Nontrivial.Basic
import Mathlib.Tactic.ApplyFun
/-!
# Symmetric powers
This file defines symmetric powers of a type. The nth symmetric power
consists of homogeneous n-tuples modulo permutations by the symmetric
group.
The special case of 2-tuples is called the symmetric square, which is
addressed in more detail in `Data.Sym.Sym2`.
TODO: This was created as supporting material for `Sym2`; it
needs a fleshed-out interface.
## Tags
symmetric powers
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Function
/-- The nth symmetric power is n-tuples up to permutation. We define it
as a subtype of `Multiset` since these are well developed in the
library. We also give a definition `Sym.sym'` in terms of vectors, and we
show these are equivalent in `Sym.symEquivSym'`.
-/
def Sym (α : Type*) (n : ℕ) :=
{ s : Multiset α // Multiset.card s = n }
/-- The canonical map to `Multiset α` that forgets that `s` has length `n` -/
@[coe] def Sym.toMultiset {α : Type*} {n : ℕ} (s : Sym α n) : Multiset α :=
s.1
instance Sym.hasCoe (α : Type*) (n : ℕ) : CoeOut (Sym α n) (Multiset α) :=
⟨Sym.toMultiset⟩
-- The following instance should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance {α : Type*} {n : ℕ} [DecidableEq α] : DecidableEq (Sym α n) :=
inferInstanceAs <| DecidableEq <| Subtype _
/-- This is the `List.Perm` setoid lifted to `Vector`.
See note [reducible non-instances].
-/
abbrev List.Vector.Perm.isSetoid (α : Type*) (n : ℕ) : Setoid (Vector α n) :=
(List.isSetoid α).comap Subtype.val
attribute [local instance] Vector.Perm.isSetoid
-- Copy over the `DecidableRel` instance across the definition.
-- (Although `List.Vector.Perm.isSetoid` is an `abbrev`, `List.isSetoid` is not.)
instance {α : Type*} {n : ℕ} [DecidableEq α] :
DecidableRel (· ≈ · : List.Vector α n → List.Vector α n → Prop) :=
fun _ _ => List.decidablePerm _ _
namespace Sym
variable {α β : Type*} {n n' m : ℕ} {s : Sym α n} {a b : α}
theorem coe_injective : Injective ((↑) : Sym α n → Multiset α) :=
Subtype.coe_injective
@[simp, norm_cast]
theorem coe_inj {s₁ s₂ : Sym α n} : (s₁ : Multiset α) = s₂ ↔ s₁ = s₂ :=
coe_injective.eq_iff
@[ext] theorem ext {s₁ s₂ : Sym α n} (h : (s₁ : Multiset α) = ↑s₂) : s₁ = s₂ :=
coe_injective h
@[simp]
theorem val_eq_coe (s : Sym α n) : s.1 = ↑s :=
rfl
/-- Construct an element of the `n`th symmetric power from a multiset of cardinality `n`.
-/
@[match_pattern]
abbrev mk (m : Multiset α) (h : Multiset.card m = n) : Sym α n :=
⟨m, h⟩
/-- The unique element in `Sym α 0`. -/
@[match_pattern]
def nil : Sym α 0 :=
⟨0, Multiset.card_zero⟩
@[simp]
theorem coe_nil : ↑(@Sym.nil α) = (0 : Multiset α) :=
rfl
/-- Inserts an element into the term of `Sym α n`, increasing the length by one.
-/
@[match_pattern]
def cons (a : α) (s : Sym α n) : Sym α n.succ :=
⟨a ::ₘ s.1, by rw [Multiset.card_cons, s.2]⟩
@[inherit_doc]
infixr:67 " ::ₛ " => cons
@[simp]
theorem cons_inj_right (a : α) (s s' : Sym α n) : a ::ₛ s = a ::ₛ s' ↔ s = s' :=
Subtype.ext_iff.trans <| (Multiset.cons_inj_right _).trans Subtype.ext_iff.symm
@[simp]
theorem cons_inj_left (a a' : α) (s : Sym α n) : a ::ₛ s = a' ::ₛ s ↔ a = a' :=
Subtype.ext_iff.trans <| Multiset.cons_inj_left _
theorem cons_swap (a b : α) (s : Sym α n) : a ::ₛ b ::ₛ s = b ::ₛ a ::ₛ s :=
Subtype.ext <| Multiset.cons_swap a b s.1
theorem coe_cons (s : Sym α n) (a : α) : (a ::ₛ s : Multiset α) = a ::ₘ s :=
rfl
/-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth
symmetric power.
-/
def ofVector : List.Vector α n → Sym α n :=
fun x => ⟨↑x.val, (Multiset.coe_card _).trans x.2⟩
/-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth
symmetric power.
-/
instance : Coe (List.Vector α n) (Sym α n) where coe x := ofVector x
@[simp]
theorem ofVector_nil : ↑(Vector.nil : List.Vector α 0) = (Sym.nil : Sym α 0) :=
rfl
@[simp]
theorem ofVector_cons (a : α) (v : List.Vector α n) :
↑(Vector.cons a v) = a ::ₛ (↑v : Sym α n) := by
cases v
rfl
@[simp]
theorem card_coe : Multiset.card (s : Multiset α) = n := s.prop
/-- `α ∈ s` means that `a` appears as one of the factors in `s`.
-/
instance : Membership α (Sym α n) :=
⟨fun s a => a ∈ s.1⟩
instance decidableMem [DecidableEq α] (a : α) (s : Sym α n) : Decidable (a ∈ s) :=
s.1.decidableMem _
@[simp, norm_cast] lemma coe_mk (s : Multiset α) (h : Multiset.card s = n) : mk s h = s := rfl
@[simp]
theorem mem_mk (a : α) (s : Multiset α) (h : Multiset.card s = n) : a ∈ mk s h ↔ a ∈ s :=
Iff.rfl
lemma «forall» {p : Sym α n → Prop} :
(∀ s : Sym α n, p s) ↔ ∀ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by
simp [Sym]
lemma «exists» {p : Sym α n → Prop} :
(∃ s : Sym α n, p s) ↔ ∃ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by
simp [Sym]
@[simp]
theorem not_mem_nil (a : α) : ¬ a ∈ (nil : Sym α 0) :=
Multiset.not_mem_zero a
@[simp]
theorem mem_cons : a ∈ b ::ₛ s ↔ a = b ∨ a ∈ s :=
Multiset.mem_cons
@[simp]
theorem mem_coe : a ∈ (s : Multiset α) ↔ a ∈ s :=
Iff.rfl
theorem mem_cons_of_mem (h : a ∈ s) : a ∈ b ::ₛ s :=
Multiset.mem_cons_of_mem h
theorem mem_cons_self (a : α) (s : Sym α n) : a ∈ a ::ₛ s :=
Multiset.mem_cons_self a s.1
theorem cons_of_coe_eq (a : α) (v : List.Vector α n) : a ::ₛ (↑v : Sym α n) = ↑(a ::ᵥ v) :=
Subtype.ext <| by
cases v
rfl
open scoped List in
theorem sound {a b : List.Vector α n} (h : a.val ~ b.val) : (↑a : Sym α n) = ↑b :=
Subtype.ext <| Quotient.sound h
/-- `erase s a h` is the sym that subtracts 1 from the
multiplicity of `a` if a is present in the sym. -/
def erase [DecidableEq α] (s : Sym α (n + 1)) (a : α) (h : a ∈ s) : Sym α n :=
⟨s.val.erase a, (Multiset.card_erase_of_mem h).trans <| s.property.symm ▸ n.pred_succ⟩
@[simp]
theorem erase_mk [DecidableEq α] (m : Multiset α)
(hc : Multiset.card m = n + 1) (a : α) (h : a ∈ m) :
(mk m hc).erase a h =mk (m.erase a)
(by rw [Multiset.card_erase_of_mem h, hc, Nat.add_one, Nat.pred_succ]) :=
rfl
@[simp]
theorem coe_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) :
(s.erase a h : Multiset α) = Multiset.erase s a :=
rfl
@[simp]
theorem cons_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : a ::ₛ s.erase a h = s :=
coe_injective <| Multiset.cons_erase h
@[simp]
theorem erase_cons_head [DecidableEq α] (s : Sym α n) (a : α)
(h : a ∈ a ::ₛ s := mem_cons_self a s) : (a ::ₛ s).erase a h = s :=
coe_injective <| Multiset.erase_cons_head a s.1
/-- Another definition of the nth symmetric power, using vectors modulo permutations. (See `Sym`.)
-/
def Sym' (α : Type*) (n : ℕ) :=
Quotient (Vector.Perm.isSetoid α n)
/-- This is `cons` but for the alternative `Sym'` definition.
-/
def cons' {α : Type*} {n : ℕ} : α → Sym' α n → Sym' α (Nat.succ n) := fun a =>
Quotient.map (Vector.cons a) fun ⟨_, _⟩ ⟨_, _⟩ h => List.Perm.cons _ h
@[inherit_doc]
scoped notation a " :: " b => cons' a b
/-- Multisets of cardinality n are equivalent to length-n vectors up to permutations.
-/
def symEquivSym' {α : Type*} {n : ℕ} : Sym α n ≃ Sym' α n :=
Equiv.subtypeQuotientEquivQuotientSubtype _ _ (fun _ => by rfl) fun _ _ => by rfl
theorem cons_equiv_eq_equiv_cons (α : Type*) (n : ℕ) (a : α) (s : Sym α n) :
(a::symEquivSym' s) = symEquivSym' (a ::ₛ s) := by
rcases s with ⟨⟨l⟩, _⟩
rfl
instance instZeroSym : Zero (Sym α 0) :=
⟨⟨0, rfl⟩⟩
@[simp] theorem toMultiset_zero : toMultiset (0 : Sym α 0) = 0 := rfl
instance : EmptyCollection (Sym α 0) :=
⟨0⟩
theorem eq_nil_of_card_zero (s : Sym α 0) : s = nil :=
Subtype.ext <| Multiset.card_eq_zero.1 s.2
instance uniqueZero : Unique (Sym α 0) :=
⟨⟨nil⟩, eq_nil_of_card_zero⟩
/-- `replicate n a` is the sym containing only `a` with multiplicity `n`. -/
def replicate (n : ℕ) (a : α) : Sym α n :=
⟨Multiset.replicate n a, Multiset.card_replicate _ _⟩
theorem replicate_succ {a : α} {n : ℕ} : replicate n.succ a = a ::ₛ replicate n a :=
rfl
theorem coe_replicate : (replicate n a : Multiset α) = Multiset.replicate n a :=
rfl
theorem val_replicate : (replicate n a).val = Multiset.replicate n a := by
rw [val_eq_coe, coe_replicate]
@[simp]
theorem mem_replicate : b ∈ replicate n a ↔ n ≠ 0 ∧ b = a :=
Multiset.mem_replicate
theorem eq_replicate_iff : s = replicate n a ↔ ∀ b ∈ s, b = a := by
rw [Subtype.ext_iff, val_replicate, Multiset.eq_replicate]
exact and_iff_right s.2
theorem exists_mem (s : Sym α n.succ) : ∃ a, a ∈ s :=
Multiset.card_pos_iff_exists_mem.1 <| s.2.symm ▸ n.succ_pos
theorem exists_cons_of_mem {s : Sym α (n + 1)} {a : α} (h : a ∈ s) : ∃ t, s = a ::ₛ t := by
obtain ⟨m, h⟩ := Multiset.exists_cons_of_mem h
have : Multiset.card m = n := by
apply_fun Multiset.card at h
rw [s.2, Multiset.card_cons, add_left_inj] at h
exact h.symm
use ⟨m, this⟩
apply Subtype.ext
exact h
theorem exists_eq_cons_of_succ (s : Sym α n.succ) : ∃ (a : α) (s' : Sym α n), s = a ::ₛ s' := by
obtain ⟨a, ha⟩ := exists_mem s
classical exact ⟨a, s.erase a ha, (cons_erase ha).symm⟩
theorem eq_replicate {a : α} {n : ℕ} {s : Sym α n} : s = replicate n a ↔ ∀ b ∈ s, b = a :=
Subtype.ext_iff.trans <| Multiset.eq_replicate.trans <| and_iff_right s.prop
theorem eq_replicate_of_subsingleton [Subsingleton α] (a : α) {n : ℕ} (s : Sym α n) :
s = replicate n a :=
eq_replicate.2 fun _ _ => Subsingleton.elim _ _
instance [Subsingleton α] (n : ℕ) : Subsingleton (Sym α n) :=
⟨by
cases n
· simp [eq_iff_true_of_subsingleton]
· intro s s'
obtain ⟨b, -⟩ := exists_mem s
rw [eq_replicate_of_subsingleton b s', eq_replicate_of_subsingleton b s]⟩
instance inhabitedSym [Inhabited α] (n : ℕ) : Inhabited (Sym α n) :=
⟨replicate n default⟩
instance inhabitedSym' [Inhabited α] (n : ℕ) : Inhabited (Sym' α n) :=
⟨Quotient.mk' (List.Vector.replicate n default)⟩
| instance (n : ℕ) [IsEmpty α] : IsEmpty (Sym α n.succ) :=
⟨fun s => by
obtain ⟨a, -⟩ := exists_mem s
| Mathlib/Data/Sym/Basic.lean | 321 | 323 |
/-
Copyright (c) 2023 Alex Keizer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Keizer
-/
import Mathlib.Data.Vector.Basic
import Mathlib.Data.Vector.Snoc
/-!
This file establishes a set of normalization lemmas for `map`/`mapAccumr` operations on vectors
-/
variable {α β γ ζ σ σ₁ σ₂ φ : Type*} {n : ℕ} {s : σ} {s₁ : σ₁} {s₂ : σ₂}
namespace List
namespace Vector
/-!
## Fold nested `mapAccumr`s into one
-/
section Fold
section Unary
variable (xs : Vector α n) (f₁ : β → σ₁ → σ₁ × γ) (f₂ : α → σ₂ → σ₂ × β)
@[simp]
theorem mapAccumr_mapAccumr :
mapAccumr f₁ (mapAccumr f₂ xs s₂).snd s₁
= let m := (mapAccumr (fun x s =>
let r₂ := f₂ x s.snd
let r₁ := f₁ r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs using Vector.revInductionOn generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr_map {s : σ₁} (f₂ : α → β) :
(mapAccumr f₁ (map f₂ xs) s) = (mapAccumr (fun x s => f₁ (f₂ x) s) xs s) := by
induction xs using Vector.revInductionOn generalizing s <;> simp_all
@[simp]
theorem map_mapAccumr {s : σ₂} (f₁ : β → γ) :
(map f₁ (mapAccumr f₂ xs s).snd) = (mapAccumr (fun x s =>
let r := (f₂ x s); (r.fst, f₁ r.snd)
) xs s).snd := by
induction xs using Vector.revInductionOn generalizing s <;> simp_all
@[simp]
theorem map_map (f₁ : β → γ) (f₂ : α → β) :
map f₁ (map f₂ xs) = map (fun x => f₁ <| f₂ x) xs := by
induction xs <;> simp_all
theorem map_pmap {p : α → Prop} (f₁ : β → γ) (f₂ : (a : α) → p a → β) (H : ∀ x ∈ xs.toList, p x):
map f₁ (pmap f₂ xs H) = pmap (fun x hx => f₁ <| f₂ x hx) xs H := by
induction xs <;> simp_all
theorem pmap_map {p : β → Prop} (f₁ : (b : β) → p b → γ) (f₂ : α → β)
(H : ∀ x ∈ (xs.map f₂).toList, p x):
pmap f₁ (map f₂ xs) H = pmap (fun x hx => f₁ (f₂ x) hx) xs (by simpa using H) := by
induction xs <;> simp_all
end Unary
section Binary
variable (xs : Vector α n) (ys : Vector β n)
@[simp]
theorem mapAccumr₂_mapAccumr_left (f₁ : γ → β → σ₁ → σ₁ × ζ) (f₂ : α → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ (mapAccumr f₂ xs s₂).snd ys s₁)
= let m := (mapAccumr₂ (fun x y s =>
let r₂ := f₂ x s.snd
let r₁ := f₁ r₂.snd y s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs ys (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem map₂_map_left (f₁ : γ → β → ζ) (f₂ : α → γ) :
map₂ f₁ (map f₂ xs) ys = map₂ (fun x y => f₁ (f₂ x) y) xs ys := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr_right (f₁ : α → γ → σ₁ → σ₁ × ζ) (f₂ : β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ xs (mapAccumr f₂ ys s₂).snd s₁)
= let m := (mapAccumr₂ (fun x y s =>
let r₂ := f₂ y s.snd
let r₁ := f₁ x r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs ys (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem map₂_map_right (f₁ : α → γ → ζ) (f₂ : β → γ) :
map₂ f₁ xs (map f₂ ys) = map₂ (fun x y => f₁ x (f₂ y)) xs ys := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr_mapAccumr₂ (f₁ : γ → σ₁ → σ₁ × ζ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr f₁ (mapAccumr₂ f₂ xs ys s₂).snd s₁)
= let m := mapAccumr₂ (fun x y s =>
let r₂ := f₂ x y s.snd
let r₁ := f₁ r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem map_map₂ (f₁ : γ → ζ) (f₂ : α → β → γ) :
map f₁ (map₂ f₂ xs ys) = map₂ (fun x y => f₁ <| f₂ x y) xs ys := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_left_left (f₁ : γ → α → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ (mapAccumr₂ f₂ xs ys s₂).snd xs s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ r₂.snd x s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_left_right
(f₁ : γ → β → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ (mapAccumr₂ f₂ xs ys s₂).snd ys s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ r₂.snd y s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_right_left (f₁ : α → γ → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ xs (mapAccumr₂ f₂ xs ys s₂).snd s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ x r₂.snd s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_right_right (f₁ : β → γ → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ ys (mapAccumr₂ f₂ xs ys s₂).snd s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ y r₂.snd s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
end Binary
end Fold
/-!
## Bisimulations
We can prove two applications of `mapAccumr` equal by providing a bisimulation relation that relates
the initial states.
That is, by providing a relation `R : σ₁ → σ₁ → Prop` such that `R s₁ s₂` implies that `R` also
relates any pair of states reachable by applying `f₁` to `s₁` and `f₂` to `s₂`, with any possible
input values.
-/
section Bisim
variable {xs : Vector α n}
theorem mapAccumr_bisim {f₁ : α → σ₁ → σ₁ × β} {f₂ : α → σ₂ → σ₂ × β} {s₁ : σ₁} {s₂ : σ₂}
(R : σ₁ → σ₂ → Prop) (h₀ : R s₁ s₂)
(hR : ∀ {s q} a, R s q → R (f₁ a s).1 (f₂ a q).1 ∧ (f₁ a s).2 = (f₂ a q).2) :
R (mapAccumr f₁ xs s₁).fst (mapAccumr f₂ xs s₂).fst
∧ (mapAccumr f₁ xs s₁).snd = (mapAccumr f₂ xs s₂).snd := by
induction xs using Vector.revInductionOn generalizing s₁ s₂
next => exact ⟨h₀, rfl⟩
next xs x ih =>
rcases (hR x h₀) with ⟨hR, _⟩
simp only [mapAccumr_snoc, ih hR, true_and]
congr 1
theorem mapAccumr_bisim_tail {f₁ : α → σ₁ → σ₁ × β} {f₂ : α → σ₂ → σ₂ × β} {s₁ : σ₁} {s₂ : σ₂}
(h : ∃ R : σ₁ → σ₂ → Prop, R s₁ s₂ ∧
∀ {s q} a, R s q → R (f₁ a s).1 (f₂ a q).1 ∧ (f₁ a s).2 = (f₂ a q).2) :
(mapAccumr f₁ xs s₁).snd = (mapAccumr f₂ xs s₂).snd := by
rcases h with ⟨R, h₀, hR⟩
exact (mapAccumr_bisim R h₀ hR).2
theorem mapAccumr₂_bisim {ys : Vector β n} {f₁ : α → β → σ₁ → σ₁ × γ}
{f₂ : α → β → σ₂ → σ₂ × γ} {s₁ : σ₁} {s₂ : σ₂}
(R : σ₁ → σ₂ → Prop) (h₀ : R s₁ s₂)
(hR : ∀ {s q} a b, R s q → R (f₁ a b s).1 (f₂ a b q).1 ∧ (f₁ a b s).2 = (f₂ a b q).2) :
R (mapAccumr₂ f₁ xs ys s₁).1 (mapAccumr₂ f₂ xs ys s₂).1
∧ (mapAccumr₂ f₁ xs ys s₁).2 = (mapAccumr₂ f₂ xs ys s₂).2 := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂
next => exact ⟨h₀, rfl⟩
next xs ys x y ih =>
rcases (hR x y h₀) with ⟨hR, _⟩
simp only [mapAccumr₂_snoc, ih hR, true_and]
congr 1
theorem mapAccumr₂_bisim_tail {ys : Vector β n} {f₁ : α → β → σ₁ → σ₁ × γ}
{f₂ : α → β → σ₂ → σ₂ × γ} {s₁ : σ₁} {s₂ : σ₂}
(h : ∃ R : σ₁ → σ₂ → Prop, R s₁ s₂ ∧
∀ {s q} a b, R s q → R (f₁ a b s).1 (f₂ a b q).1 ∧ (f₁ a b s).2 = (f₂ a b q).2) :
(mapAccumr₂ f₁ xs ys s₁).2 = (mapAccumr₂ f₂ xs ys s₂).2 := by
rcases h with ⟨R, h₀, hR⟩
exact (mapAccumr₂_bisim R h₀ hR).2
end Bisim
/-!
## Redundant state optimization
The following section are collection of rewrites to simplify, or even get rid, redundant
accumulation state
-/
section RedundantState
variable {xs : Vector α n} {ys : Vector β n}
protected theorem map_eq_mapAccumr {f : α → β} :
map f xs = (mapAccumr (fun x (_ : Unit) ↦ ((), f x)) xs ()).snd := by
induction xs using Vector.revInductionOn <;> simp_all
/--
If there is a set of states that is closed under `f`, and such that `f` produces that same output
for all states in this set, then the state is not actually needed.
Hence, then we can rewrite `mapAccumr` into just `map`.
-/
theorem mapAccumr_eq_map {f : α → σ → σ × β} {s₀ : σ} (S : Set σ) (h₀ : s₀ ∈ S)
(closure : ∀ a s, s ∈ S → (f a s).1 ∈ S)
(out : ∀ a s s', s ∈ S → s' ∈ S → (f a s).2 = (f a s').2) :
(mapAccumr f xs s₀).snd = map (f · s₀ |>.snd) xs := by
rw [Vector.map_eq_mapAccumr]
apply mapAccumr_bisim_tail
use fun s _ => s ∈ S, h₀
exact @fun s _q a h => ⟨closure a s h, out a s s₀ h h₀⟩
protected theorem map₂_eq_mapAccumr₂ {f : α → β → γ} :
map₂ f xs ys = (mapAccumr₂ (fun x y (_ : Unit) ↦ ((), f x y)) xs ys ()).snd := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
/--
If there is a set of states that is closed under `f`, and such that `f` produces that same output
for all states in this set, then the state is not actually needed.
Hence, then we can rewrite `mapAccumr₂` into just `map₂`.
-/
theorem mapAccumr₂_eq_map₂ {f : α → β → σ → σ × γ} {s₀ : σ} (S : Set σ) (h₀ : s₀ ∈ S)
(closure : ∀ a b s, s ∈ S → (f a b s).1 ∈ S)
(out : ∀ a b s s', s ∈ S → s' ∈ S → (f a b s).2 = (f a b s').2) :
(mapAccumr₂ f xs ys s₀).snd = map₂ (f · · s₀ |>.snd) xs ys := by
rw [Vector.map₂_eq_mapAccumr₂]
apply mapAccumr₂_bisim_tail
use fun s _ => s ∈ S, h₀
exact @fun s _q a b h => ⟨closure a b s h, out a b s s₀ h h₀⟩
/--
If an accumulation function `f`, given an initial state `s`, produces `s` as its output state
for all possible input bits, then the state is redundant and can be optimized out.
-/
@[simp]
theorem mapAccumr_eq_map_of_constant_state (f : α → σ → σ × β) (s : σ) (h : ∀ a, (f a s).fst = s) :
mapAccumr f xs s = (s, (map (fun x => (f x s).snd) xs)) := by
induction xs using revInductionOn <;> simp_all
/--
If an accumulation function `f`, given an initial state `s`, produces `s` as its output state
for all possible input bits, then the state is redundant and can be optimized out.
-/
@[simp]
theorem mapAccumr₂_eq_map₂_of_constant_state (f : α → β → σ → σ × γ) (s : σ)
(h : ∀ a b, (f a b s).fst = s) :
mapAccumr₂ f xs ys s = (s, (map₂ (fun x y => (f x y s).snd) xs ys)) := by
induction xs, ys using revInductionOn₂ <;> simp_all
/--
If an accumulation function `f`, produces the same output bits regardless of accumulation state,
then the state is redundant and can be optimized out.
-/
@[simp]
theorem mapAccumr_eq_map_of_unused_state (f : α → σ → σ × β) (s : σ)
(h : ∀ a s s', (f a s).snd = (f a s').snd) :
(mapAccumr f xs s).snd = (map (fun x => (f x s).snd) xs) :=
mapAccumr_eq_map (fun _ => true) rfl (fun _ _ _ => rfl) (fun a s s' _ _ => h a s s')
/--
If an accumulation function `f`, produces the same output bits regardless of accumulation state,
then the state is redundant and can be optimized out.
-/
@[simp]
theorem mapAccumr₂_eq_map₂_of_unused_state (f : α → β → σ → σ × γ) (s : σ)
(h : ∀ a b s s', (f a b s).snd = (f a b s').snd) :
(mapAccumr₂ f xs ys s).snd = (map₂ (fun x y => (f x y s).snd) xs ys) :=
mapAccumr₂_eq_map₂ (fun _ => true) rfl (fun _ _ _ _ => rfl) (fun a b s s' _ _ => h a b s s')
/-- If `f` takes a pair of states, but always returns the same value for both elements of the
pair, then we can simplify to just a single element of state.
-/
@[simp]
theorem mapAccumr_redundant_pair (f : α → (σ × σ) → (σ × σ) × β)
(h : ∀ x s, (f x (s, s)).fst.fst = (f x (s, s)).fst.snd) :
(mapAccumr f xs (s, s)).snd = (mapAccumr (fun x (s : σ) =>
(f x (s, s) |>.fst.fst, f x (s, s) |>.snd)
) xs s).snd :=
mapAccumr_bisim_tail <| by
use fun (s₁, s₂) s => s₂ = s ∧ s₁ = s
simp_all
/-- If `f` takes a pair of states, but always returns the same value for both elements of the
pair, then we can simplify to just a single element of state.
-/
@[simp]
theorem mapAccumr₂_redundant_pair (f : α → β → (σ × σ) → (σ × σ) × γ)
(h : ∀ x y s, let s' := (f x y (s, s)).fst; s'.fst = s'.snd) :
(mapAccumr₂ f xs ys (s, s)).snd = (mapAccumr₂ (fun x y (s : σ) =>
(f x y (s, s) |>.fst.fst, f x y (s, s) |>.snd)
) xs ys s).snd :=
mapAccumr₂_bisim_tail <| by
use fun (s₁, s₂) s => s₂ = s ∧ s₁ = s
simp_all
end RedundantState
/-!
## Unused input optimizations
-/
section UnusedInput
variable {xs : Vector α n} {ys : Vector β n}
/--
If `f` returns the same output and next state for every value of it's first argument, then
`xs : Vector` is ignored, and we can rewrite `mapAccumr₂` into `map`.
-/
@[simp]
theorem mapAccumr₂_unused_input_left [Inhabited α] (f : α → β → σ → σ × γ)
(h : ∀ a b s, f default b s = f a b s) :
mapAccumr₂ f xs ys s = mapAccumr (fun b s => f default b s) ys s := by
induction xs, ys using Vector.revInductionOn₂ generalizing s with
| nil => rfl
| | snoc xs ys x y ih => simp [h x y s, ih]
/--
If `f` returns the same output and next state for every value of it's second argument, then
`ys : Vector` is ignored, and we can rewrite `mapAccumr₂` into `map`.
-/
| Mathlib/Data/Vector/MapLemmas.lean | 354 | 359 |
/-
Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.RingTheory.DedekindDomain.Ideal
import Mathlib.RingTheory.Valuation.ExtendToLocalization
import Mathlib.Topology.Algebra.Valued.ValuedField
import Mathlib.Topology.Algebra.Valued.WithVal
/-!
# Adic valuations on Dedekind domains
Given a Dedekind domain `R` of Krull dimension 1 and a maximal ideal `v` of `R`, we define the
`v`-adic valuation on `R` and its extension to the field of fractions `K` of `R`.
We prove several properties of this valuation, including the existence of uniformizers.
We define the completion of `K` with respect to the `v`-adic valuation, denoted
`v.adicCompletion`, and its ring of integers, denoted `v.adicCompletionIntegers`.
## Main definitions
- `IsDedekindDomain.HeightOneSpectrum.intValuation v` is the `v`-adic valuation on `R`.
- `IsDedekindDomain.HeightOneSpectrum.valuation v` is the `v`-adic valuation on `K`.
- `IsDedekindDomain.HeightOneSpectrum.adicCompletion v` is the completion of `K` with respect
to its `v`-adic valuation.
- `IsDedekindDomain.HeightOneSpectrum.adicCompletionIntegers v` is the ring of integers of
`v.adicCompletion`.
## Main results
- `IsDedekindDomain.HeightOneSpectrum.intValuation_le_one` : The `v`-adic valuation on `R` is
bounded above by 1.
- `IsDedekindDomain.HeightOneSpectrum.intValuation_lt_one_iff_dvd` : The `v`-adic valuation of
`r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`.
- `IsDedekindDomain.HeightOneSpectrum.intValuation_le_pow_iff_dvd` : The `v`-adic valuation of
`r ∈ R` is less than or equal to `Multiplicative.ofAdd (-n)` if and only if `vⁿ` divides the
ideal `(r)`.
- `IsDedekindDomain.HeightOneSpectrum.intValuation_exists_uniformizer` : There exists `π ∈ R`
with `v`-adic valuation `Multiplicative.ofAdd (-1)`.
- `IsDedekindDomain.HeightOneSpectrum.valuation_of_mk'` : The `v`-adic valuation of `r/s ∈ K`
is the valuation of `r` divided by the valuation of `s`.
- `IsDedekindDomain.HeightOneSpectrum.valuation_of_algebraMap` : The `v`-adic valuation on `K`
extends the `v`-adic valuation on `R`.
- `IsDedekindDomain.HeightOneSpectrum.valuation_exists_uniformizer` : There exists `π ∈ K` with
`v`-adic valuation `Multiplicative.ofAdd (-1)`.
## Implementation notes
We are only interested in Dedekind domains with Krull dimension 1.
## References
* [G. J. Janusz, *Algebraic Number Fields*][janusz1996]
* [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic]
* [J. Neukirch, *Algebraic Number Theory*][Neukirch1992]
## Tags
dedekind domain, dedekind ring, adic valuation
-/
noncomputable section
open scoped Multiplicative
open Multiplicative IsDedekindDomain
variable {R : Type*} [CommRing R] [IsDedekindDomain R] {K S : Type*} [Field K] [CommSemiring S]
[Algebra R K] [IsFractionRing R K] (v : HeightOneSpectrum R)
namespace IsDedekindDomain.HeightOneSpectrum
/-! ### Adic valuations on the Dedekind domain R -/
open scoped Classical in
/-- The additive `v`-adic valuation of `r ∈ R` is the exponent of `v` in the factorization of the
ideal `(r)`, if `r` is nonzero, or infinity, if `r = 0`. `intValuationDef` is the corresponding
multiplicative valuation. -/
def intValuationDef (r : R) : ℤₘ₀ :=
if r = 0 then 0
else
↑(Multiplicative.ofAdd
(-(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {r} : Ideal R)).factors : ℤ))
theorem intValuationDef_if_pos {r : R} (hr : r = 0) : v.intValuationDef r = 0 :=
if_pos hr
@[simp]
theorem intValuationDef_zero : v.intValuationDef 0 = 0 :=
if_pos rfl
open scoped Classical in
theorem intValuationDef_if_neg {r : R} (hr : r ≠ 0) :
v.intValuationDef r =
Multiplicative.ofAdd
(-(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {r} : Ideal R)).factors : ℤ) :=
if_neg hr
/-- Nonzero elements have nonzero adic valuation. -/
theorem intValuation_ne_zero (x : R) (hx : x ≠ 0) : v.intValuationDef x ≠ 0 := by
rw [intValuationDef, if_neg hx]
exact WithZero.coe_ne_zero
/-- Nonzero divisors have nonzero valuation. -/
theorem intValuation_ne_zero' (x : nonZeroDivisors R) : v.intValuationDef x ≠ 0 :=
v.intValuation_ne_zero x (nonZeroDivisors.coe_ne_zero x)
/-- Nonzero divisors have valuation greater than zero. -/
theorem intValuation_zero_le (x : nonZeroDivisors R) : 0 < v.intValuationDef x := by
rw [v.intValuationDef_if_neg (nonZeroDivisors.coe_ne_zero x)]
exact WithZero.zero_lt_coe _
/-- The `v`-adic valuation on `R` is bounded above by 1. -/
theorem intValuation_le_one (x : R) : v.intValuationDef x ≤ 1 := by
rw [intValuationDef]
by_cases hx : x = 0
· rw [if_pos hx]; exact WithZero.zero_le 1
· rw [if_neg hx, ← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_le_coe, ofAdd_le,
Right.neg_nonpos_iff]
exact Int.natCast_nonneg _
/-- The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. -/
theorem intValuation_lt_one_iff_dvd (r : R) :
v.intValuationDef r < 1 ↔ v.asIdeal ∣ Ideal.span {r} := by
classical
rw [intValuationDef]
split_ifs with hr
· simp [hr]
· rw [← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_lt_coe, ofAdd_lt, neg_lt_zero, ←
Int.ofNat_zero, Int.ofNat_lt, zero_lt_iff]
have h : (Ideal.span {r} : Ideal R) ≠ 0 := by
rw [Ne, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]
exact hr
apply Associates.count_ne_zero_iff_dvd h (by apply v.irreducible)
/-- The `v`-adic valuation of `r ∈ R` is less than `Multiplicative.ofAdd (-n)` if and only if
`vⁿ` divides the ideal `(r)`. -/
theorem intValuation_le_pow_iff_dvd (r : R) (n : ℕ) :
v.intValuationDef r ≤ Multiplicative.ofAdd (-(n : ℤ)) ↔ v.asIdeal ^ n ∣ Ideal.span {r} := by
classical
rw [intValuationDef]
split_ifs with hr
· simp_rw [hr, Ideal.dvd_span_singleton, zero_le', Submodule.zero_mem]
· rw [WithZero.coe_le_coe, ofAdd_le, neg_le_neg_iff, Int.ofNat_le, Ideal.dvd_span_singleton, ←
Associates.le_singleton_iff,
Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hr)
(by apply v.associates_irreducible)]
/-- The `v`-adic valuation of `0 : R` equals 0. -/
theorem intValuation.map_zero' : v.intValuationDef 0 = 0 :=
v.intValuationDef_if_pos (Eq.refl 0)
/-- The `v`-adic valuation of `1 : R` equals 1. -/
theorem intValuation.map_one' : v.intValuationDef 1 = 1 := by
classical
rw [v.intValuationDef_if_neg (zero_ne_one.symm : (1 : R) ≠ 0), Ideal.span_singleton_one, ←
Ideal.one_eq_top, Associates.mk_one, Associates.factors_one,
Associates.count_zero (by apply v.associates_irreducible), Int.ofNat_zero, neg_zero, ofAdd_zero,
WithZero.coe_one]
/-- The `v`-adic valuation of a product equals the product of the valuations. -/
theorem intValuation.map_mul' (x y : R) :
v.intValuationDef (x * y) = v.intValuationDef x * v.intValuationDef y := by
classical
simp only [intValuationDef]
by_cases hx : x = 0
· rw [hx, zero_mul, if_pos (Eq.refl _), zero_mul]
· by_cases hy : y = 0
| · rw [hy, mul_zero, if_pos (Eq.refl _), mul_zero]
· rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithZero.coe_mul, WithZero.coe_inj, ←
ofAdd_add, ← Ideal.span_singleton_mul_span_singleton, ← Associates.mk_mul_mk, ← neg_add,
Associates.count_mul (by apply Associates.mk_ne_zero'.mpr hx)
(by apply Associates.mk_ne_zero'.mpr hy) (by apply v.associates_irreducible)]
rfl
theorem intValuation.le_max_iff_min_le {a b c : ℕ} :
Multiplicative.ofAdd (-c : ℤ) ≤
max (Multiplicative.ofAdd (-a : ℤ)) (Multiplicative.ofAdd (-b : ℤ)) ↔
min a b ≤ c := by
rw [le_max_iff, ofAdd_le, ofAdd_le, neg_le_neg_iff, neg_le_neg_iff, Int.ofNat_le, Int.ofNat_le, ←
| Mathlib/RingTheory/DedekindDomain/AdicValuation.lean | 164 | 175 |
/-
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 | 2,084 | 2,085 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.InitialSeg
import Mathlib.SetTheory.Ordinal.Basic
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Ordinal
universe u v w
namespace Ordinal
variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance instAddLeftReflectLE :
AddLeftReflectLE Ordinal.{u} where
elim c a b := by
refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_
have H₁ a : f (Sum.inl a) = Sum.inl a := by
simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a
have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by
generalize hx : f (Sum.inr a) = x
obtain x | x := x
· rw [← H₁, f.inj] at hx
contradiction
· exact ⟨x, rfl⟩
choose g hg using H₂
refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le
rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr]
instance : IsLeftCancelAdd Ordinal where
add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h
@[deprecated add_left_cancel_iff (since := "2024-12-11")]
protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c :=
add_left_cancel_iff
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩
instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} :=
⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩
instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} :=
⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn₂ a b fun α r _ β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
open Classical in
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o := by
classical
exact if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b := by
classical
exact if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by
classical
exact if h : ∃ a, o = succ a then by obtain ⟨a, e⟩ := h; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor.
TODO: deprecate this in favor of `Order.IsSuccLimit`. -/
def IsLimit (o : Ordinal) : Prop :=
IsSuccLimit o
theorem isLimit_iff {o} : IsLimit o ↔ o ≠ 0 ∧ IsSuccPrelimit o := by
simp [IsLimit, IsSuccLimit]
theorem IsLimit.isSuccPrelimit {o} (h : IsLimit o) : IsSuccPrelimit o :=
IsSuccLimit.isSuccPrelimit h
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
IsSuccLimit.succ_lt h
theorem isSuccPrelimit_zero : IsSuccPrelimit (0 : Ordinal) := isSuccPrelimit_bot
theorem not_zero_isLimit : ¬IsLimit 0 :=
not_isSuccLimit_bot
theorem not_succ_isLimit (o) : ¬IsLimit (succ o) :=
not_isSuccLimit_succ o
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
IsSuccLimit.succ_lt_iff h
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
@[simp]
theorem lift_isLimit (o : Ordinal.{v}) : IsLimit (lift.{u,v} o) ↔ IsLimit o :=
liftInitialSeg.isSuccLimit_apply_iff
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
IsSuccLimit.bot_lt h
theorem IsLimit.ne_zero {o : Ordinal} (h : IsLimit o) : o ≠ 0 :=
h.pos.ne'
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.succ_lt h.pos
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.succ_lt (IsLimit.nat_lt h n)
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := by
simpa [eq_comm] using isMin_or_mem_range_succ_or_isSuccLimit o
theorem isLimit_of_not_succ_of_ne_zero {o : Ordinal} (h : ¬∃ a, o = succ a) (h' : o ≠ 0) :
IsLimit o := ((zero_or_succ_or_limit o).resolve_left h').resolve_left h
-- TODO: this is an iff with `IsSuccPrelimit`
theorem IsLimit.sSup_Iio {o : Ordinal} (h : IsLimit o) : sSup (Iio o) = o := by
apply (csSup_le' (fun a ha ↦ le_of_lt ha)).antisymm
apply le_of_forall_lt
intro a ha
exact (lt_succ a).trans_le (le_csSup bddAbove_Iio (h.succ_lt ha))
theorem IsLimit.iSup_Iio {o : Ordinal} (h : IsLimit o) : ⨆ a : Iio o, a.1 = o := by
rw [← sSup_eq_iSup', h.sSup_Iio]
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {motive : Ordinal → Sort*} (o : Ordinal)
(zero : motive 0) (succ : ∀ o, motive o → motive (succ o))
(isLimit : ∀ o, IsLimit o → (∀ o' < o, motive o') → motive o) : motive o := by
refine SuccOrder.limitRecOn o (fun a ha ↦ ?_) (fun a _ ↦ succ a) isLimit
convert zero
simpa using ha
@[simp]
theorem limitRecOn_zero {motive} (H₁ H₂ H₃) : @limitRecOn motive 0 H₁ H₂ H₃ = H₁ :=
SuccOrder.limitRecOn_isMin _ _ _ isMin_bot
@[simp]
theorem limitRecOn_succ {motive} (o H₁ H₂ H₃) :
@limitRecOn motive (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn motive o H₁ H₂ H₃) :=
SuccOrder.limitRecOn_succ ..
@[simp]
theorem limitRecOn_limit {motive} (o H₁ H₂ H₃ h) :
@limitRecOn motive o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn motive x H₁ H₂ H₃ :=
SuccOrder.limitRecOn_of_isSuccLimit ..
/-- Bounded recursion on ordinals. Similar to `limitRecOn`, with the assumption `o < l`
added to all cases. The final term's domain is the ordinals below `l`. -/
@[elab_as_elim]
def boundedLimitRecOn {l : Ordinal} (lLim : l.IsLimit) {motive : Iio l → Sort*} (o : Iio l)
(zero : motive ⟨0, lLim.pos⟩)
(succ : (o : Iio l) → motive o → motive ⟨succ o, lLim.succ_lt o.2⟩)
(isLimit : (o : Iio l) → IsLimit o → (Π o' < o, motive o') → motive o) : motive o :=
limitRecOn (motive := fun p ↦ (h : p < l) → motive ⟨p, h⟩) o.1 (fun _ ↦ zero)
(fun o ih h ↦ succ ⟨o, _⟩ <| ih <| (lt_succ o).trans h)
(fun _o ho ih _ ↦ isLimit _ ho fun _o' h ↦ ih _ h _) o.2
@[simp]
theorem boundedLimitRec_zero {l} (lLim : l.IsLimit) {motive} (H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨0, lLim.pos⟩ H₁ H₂ H₃ = H₁ := by
rw [boundedLimitRecOn, limitRecOn_zero]
@[simp]
theorem boundedLimitRec_succ {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃) :
@boundedLimitRecOn l lLim motive ⟨succ o.1, lLim.succ_lt o.2⟩ H₁ H₂ H₃ = H₂ o
(@boundedLimitRecOn l lLim motive o H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_succ]
rfl
theorem boundedLimitRec_limit {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃ oLim) :
@boundedLimitRecOn l lLim motive o H₁ H₂ H₃ = H₃ o oLim (fun x _ ↦
@boundedLimitRecOn l lLim motive x H₁ H₂ H₃) := by
rw [boundedLimitRecOn, limitRecOn_limit]
rfl
instance orderTopToTypeSucc (o : Ordinal) : OrderTop (succ o).toType :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
theorem enum_succ_eq_top {o : Ordinal} :
enum (α := (succ o).toType) (· < ·) ⟨o, type_toType _ ▸ lt_succ o⟩ = ⊤ :=
rfl
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r ⟨succ (typein r x), h _ (typein_lt_type r x)⟩
convert enum_lt_enum.mpr _
· rw [enum_typein]
· rw [Subtype.mk_lt_mk, lt_succ_iff]
theorem toType_noMax_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.toType :=
⟨has_succ_of_type_succ_lt (type_toType _ ▸ ho)⟩
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r ⟨succ (typein r x), hr.succ_lt (typein_lt_type r x)⟩, ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r, Subtype.mk_lt_mk]
apply lt_succ
@[simp]
theorem typein_ordinal (o : Ordinal.{u}) :
@typein Ordinal (· < ·) _ o = Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enum r).symm).symm
theorem mk_Iio_ordinal (o : Ordinal.{u}) :
#(Iio o) = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← typein_ordinal]
rfl
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.succ_lt h))
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
theorem IsNormal.id_le {f} (H : IsNormal f) : id ≤ f :=
H.strictMono.id_le
theorem IsNormal.le_apply {f} (H : IsNormal f) {a} : a ≤ f a :=
H.strictMono.le_apply
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
H.le_apply.le_iff_eq
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h _ pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
induction b using limitRecOn with
| zero =>
obtain ⟨x, px⟩ := p0
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| succ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| isLimit S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (ho : IsLimit o) : IsLimit (f o) := by
rw [isLimit_iff, isSuccPrelimit_iff_succ_lt]
use (H.lt_iff.2 ho.pos).ne_bot
intro a ha
obtain ⟨b, hb, hab⟩ := (H.limit_lt ho).1 ha
rw [← succ_le_iff] at hab
apply hab.trans_lt
rwa [H.lt_iff]
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) :
a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h _ l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ ⟨_, l⟩) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; rcases enum _ ⟨_, l⟩ with x | x <;> intro this
· cases this (enum s ⟨0, h.pos⟩)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.succ_lt (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
theorem isNormal_add_right (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
theorem isLimit_add (a) {b} : IsLimit b → IsLimit (a + b) :=
(isNormal_add_right a).isLimit
alias IsLimit.add := isLimit_add
/-! ### Subtraction on ordinals -/
/-- The set in the definition of subtraction is nonempty. -/
private theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
protected theorem sub_ne_zero_iff_lt {a b : Ordinal} : a - b ≠ 0 ↔ b < a := by
simpa using Ordinal.sub_eq_zero_iff_le.not
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
theorem le_sub_of_add_le {a b c : Ordinal} (h : b + c ≤ a) : c ≤ a - b := by
rw [← add_le_add_iff_left b]
exact h.trans (le_add_sub a b)
theorem sub_lt_of_lt_add {a b c : Ordinal} (h : a < b + c) (hc : 0 < c) : a - b < c := by
obtain hab | hba := lt_or_le a b
· rwa [Ordinal.sub_eq_zero_iff_le.2 hab.le]
· rwa [sub_lt_of_le hba]
theorem lt_add_iff {a b c : Ordinal} (hc : c ≠ 0) : a < b + c ↔ ∃ d < c, a ≤ b + d := by
use fun h ↦ ⟨_, sub_lt_of_lt_add h hc.bot_lt, le_add_sub a b⟩
rintro ⟨d, hd, ha⟩
exact ha.trans_lt (add_lt_add_left hd b)
theorem add_le_iff {a b c : Ordinal} (hb : b ≠ 0) : a + b ≤ c ↔ ∀ d < b, a + d < c := by
simpa using (lt_add_iff hb).not
@[deprecated add_le_iff (since := "2024-12-08")]
theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) :
a + b ≤ c :=
(add_le_iff hb.ne').2 h
theorem isLimit_sub {a b} (ha : IsLimit a) (h : b < a) : IsLimit (a - b) := by
rw [isLimit_iff, Ordinal.sub_ne_zero_iff_lt, isSuccPrelimit_iff_succ_lt]
refine ⟨h, fun c hc ↦ ?_⟩
rw [lt_sub] at hc ⊢
rw [add_succ]
exact ha.succ_lt hc
/-! ### Multiplication of ordinals -/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
| instance monoid : Monoid Ordinal.{u} where
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 586 | 586 |
/-
Copyright (c) 2020 Zhangir Azerbayev. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Zhangir Azerbayev
-/
import Mathlib.GroupTheory.Perm.Sign
import Mathlib.LinearAlgebra.LinearIndependent.Defs
import Mathlib.LinearAlgebra.Multilinear.Basis
/-!
# Alternating Maps
We construct the bundled function `AlternatingMap`, which extends `MultilinearMap` with all the
arguments of the same type.
## Main definitions
* `AlternatingMap R M N ι` is the space of `R`-linear alternating maps from `ι → M` to `N`.
* `f.map_eq_zero_of_eq` expresses that `f` is zero when two inputs are equal.
* `f.map_swap` expresses that `f` is negated when two inputs are swapped.
* `f.map_perm` expresses how `f` varies by a sign change under a permutation of its inputs.
* An `AddCommMonoid`, `AddCommGroup`, and `Module` structure over `AlternatingMap`s that
matches the definitions over `MultilinearMap`s.
* `MultilinearMap.domDomCongr`, for permuting the elements within a family.
* `MultilinearMap.alternatization`, which makes an alternating map out of a non-alternating one.
* `AlternatingMap.curryLeft`, for binding the leftmost argument of an alternating map indexed
by `Fin n.succ`.
## Implementation notes
`AlternatingMap` is defined in terms of `map_eq_zero_of_eq`, as this is easier to work with than
using `map_swap` as a definition, and does not require `Neg N`.
`AlternatingMap`s are provided with a coercion to `MultilinearMap`, along with a set of
`norm_cast` lemmas that act on the algebraic structure:
* `AlternatingMap.coe_add`
* `AlternatingMap.coe_zero`
* `AlternatingMap.coe_sub`
* `AlternatingMap.coe_neg`
* `AlternatingMap.coe_smul`
-/
-- semiring / add_comm_monoid
variable {R : Type*} [Semiring R]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable {N : Type*} [AddCommMonoid N] [Module R N]
variable {P : Type*} [AddCommMonoid P] [Module R P]
-- semiring / add_comm_group
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {N' : Type*} [AddCommGroup N'] [Module R N']
variable {ι ι' ι'' : Type*}
section
variable (R M N ι)
/-- An alternating map from `ι → M` to `N`, denoted `M [⋀^ι]→ₗ[R] N`,
is a multilinear map that vanishes when two of its arguments are equal. -/
structure AlternatingMap extends MultilinearMap R (fun _ : ι => M) N where
/-- The map is alternating: if `v` has two equal coordinates, then `f v = 0`. -/
map_eq_zero_of_eq' : ∀ (v : ι → M) (i j : ι), v i = v j → i ≠ j → toFun v = 0
@[inherit_doc]
notation M " [⋀^" ι "]→ₗ[" R "] " N:100 => AlternatingMap R M N ι
end
/-- The multilinear map associated to an alternating map -/
add_decl_doc AlternatingMap.toMultilinearMap
namespace AlternatingMap
variable (f f' : M [⋀^ι]→ₗ[R] N)
variable (g g₂ : M [⋀^ι]→ₗ[R] N')
variable (g' : M' [⋀^ι]→ₗ[R] N')
variable (v : ι → M) (v' : ι → M')
open Function
/-! Basic coercion simp lemmas, largely copied from `RingHom` and `MultilinearMap` -/
section Coercions
instance instFunLike : FunLike (M [⋀^ι]→ₗ[R] N) (ι → M) N where
coe f := f.toFun
coe_injective' f g h := by
rcases f with ⟨⟨_, _, _⟩, _⟩
rcases g with ⟨⟨_, _, _⟩, _⟩
congr
initialize_simps_projections AlternatingMap (toFun → apply)
@[simp]
theorem toFun_eq_coe : f.toFun = f :=
rfl
@[simp]
theorem coe_mk (f : MultilinearMap R (fun _ : ι => M) N) (h) :
⇑(⟨f, h⟩ : M [⋀^ι]→ₗ[R] N) = f :=
rfl
protected theorem congr_fun {f g : M [⋀^ι]→ₗ[R] N} (h : f = g) (x : ι → M) : f x = g x :=
congr_arg (fun h : M [⋀^ι]→ₗ[R] N => h x) h
protected theorem congr_arg (f : M [⋀^ι]→ₗ[R] N) {x y : ι → M} (h : x = y) : f x = f y :=
congr_arg (fun x : ι → M => f x) h
theorem coe_injective : Injective ((↑) : M [⋀^ι]→ₗ[R] N → (ι → M) → N) :=
DFunLike.coe_injective
@[norm_cast]
theorem coe_inj {f g : M [⋀^ι]→ₗ[R] N} : (f : (ι → M) → N) = g ↔ f = g :=
coe_injective.eq_iff
@[ext]
theorem ext {f f' : M [⋀^ι]→ₗ[R] N} (H : ∀ x, f x = f' x) : f = f' :=
DFunLike.ext _ _ H
attribute [coe] AlternatingMap.toMultilinearMap
instance coe : Coe (M [⋀^ι]→ₗ[R] N) (MultilinearMap R (fun _ : ι => M) N) :=
⟨fun x => x.toMultilinearMap⟩
@[simp, norm_cast]
theorem coe_multilinearMap : ⇑(f : MultilinearMap R (fun _ : ι => M) N) = f :=
rfl
theorem coe_multilinearMap_injective :
Function.Injective ((↑) : M [⋀^ι]→ₗ[R] N → MultilinearMap R (fun _ : ι => M) N) :=
fun _ _ h => ext <| MultilinearMap.congr_fun h
theorem coe_multilinearMap_mk (f : (ι → M) → N) (h₁ h₂ h₃) :
((⟨⟨f, h₁, h₂⟩, h₃⟩ : M [⋀^ι]→ₗ[R] N) : MultilinearMap R (fun _ : ι => M) N) =
⟨f, @h₁, @h₂⟩ := by
simp
end Coercions
/-!
### Simp-normal forms of the structure fields
These are expressed in terms of `⇑f` instead of `f.toFun`.
-/
@[simp]
theorem map_update_add [DecidableEq ι] (i : ι) (x y : M) :
f (update v i (x + y)) = f (update v i x) + f (update v i y) :=
f.map_update_add' v i x y
@[deprecated (since := "2024-11-03")] protected alias map_add := map_update_add
@[simp]
theorem map_update_sub [DecidableEq ι] (i : ι) (x y : M') :
g' (update v' i (x - y)) = g' (update v' i x) - g' (update v' i y) :=
g'.toMultilinearMap.map_update_sub v' i x y
@[deprecated (since := "2024-11-03")] protected alias map_sub := map_update_sub
@[simp]
theorem map_update_neg [DecidableEq ι] (i : ι) (x : M') :
g' (update v' i (-x)) = -g' (update v' i x) :=
g'.toMultilinearMap.map_update_neg v' i x
@[deprecated (since := "2024-11-03")] protected alias map_neg := map_update_neg
@[simp]
theorem map_update_smul [DecidableEq ι] (i : ι) (r : R) (x : M) :
f (update v i (r • x)) = r • f (update v i x) :=
f.map_update_smul' v i r x
@[deprecated (since := "2024-11-03")] protected alias map_smul := map_update_smul
@[simp]
theorem map_eq_zero_of_eq (v : ι → M) {i j : ι} (h : v i = v j) (hij : i ≠ j) : f v = 0 :=
f.map_eq_zero_of_eq' v i j h hij
theorem map_coord_zero {m : ι → M} (i : ι) (h : m i = 0) : f m = 0 :=
f.toMultilinearMap.map_coord_zero i h
@[simp]
theorem map_update_zero [DecidableEq ι] (m : ι → M) (i : ι) : f (update m i 0) = 0 :=
f.toMultilinearMap.map_update_zero m i
@[simp]
theorem map_zero [Nonempty ι] : f 0 = 0 :=
f.toMultilinearMap.map_zero
theorem map_eq_zero_of_not_injective (v : ι → M) (hv : ¬Function.Injective v) : f v = 0 := by
rw [Function.Injective] at hv
push_neg at hv
rcases hv with ⟨i₁, i₂, heq, hne⟩
exact f.map_eq_zero_of_eq v heq hne
/-!
### Algebraic structure inherited from `MultilinearMap`
`AlternatingMap` carries the same `AddCommMonoid`, `AddCommGroup`, and `Module` structure
as `MultilinearMap`
-/
section SMul
variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N]
instance smul : SMul S (M [⋀^ι]→ₗ[R] N) :=
⟨fun c f =>
{ c • (f : MultilinearMap R (fun _ : ι => M) N) with
map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] }⟩
@[simp]
theorem smul_apply (c : S) (m : ι → M) : (c • f) m = c • f m :=
rfl
@[norm_cast]
theorem coe_smul (c : S) : ↑(c • f) = c • (f : MultilinearMap R (fun _ : ι => M) N) :=
rfl
theorem coeFn_smul (c : S) (f : M [⋀^ι]→ₗ[R] N) : ⇑(c • f) = c • ⇑f :=
rfl
instance isCentralScalar [DistribMulAction Sᵐᵒᵖ N] [IsCentralScalar S N] :
IsCentralScalar S (M [⋀^ι]→ₗ[R] N) :=
⟨fun _ _ => ext fun _ => op_smul_eq_smul _ _⟩
end SMul
/-- The cartesian product of two alternating maps, as an alternating map. -/
@[simps!]
def prod (f : M [⋀^ι]→ₗ[R] N) (g : M [⋀^ι]→ₗ[R] P) : M [⋀^ι]→ₗ[R] (N × P) :=
{ f.toMultilinearMap.prod g.toMultilinearMap with
map_eq_zero_of_eq' := fun _ _ _ h hne =>
Prod.ext (f.map_eq_zero_of_eq _ h hne) (g.map_eq_zero_of_eq _ h hne) }
@[simp]
theorem coe_prod (f : M [⋀^ι]→ₗ[R] N) (g : M [⋀^ι]→ₗ[R] P) :
(f.prod g : MultilinearMap R (fun _ : ι => M) (N × P)) = MultilinearMap.prod f g :=
rfl
/-- Combine a family of alternating maps with the same domain and codomains `N i` into an
alternating map taking values in the space of functions `Π i, N i`. -/
@[simps!]
def pi {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)]
(f : ∀ i, M [⋀^ι]→ₗ[R] N i) : M [⋀^ι]→ₗ[R] (∀ i, N i) :=
{ MultilinearMap.pi fun a => (f a).toMultilinearMap with
map_eq_zero_of_eq' := fun _ _ _ h hne => funext fun a => (f a).map_eq_zero_of_eq _ h hne }
@[simp]
theorem coe_pi {ι' : Type*} {N : ι' → Type*} [∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)]
(f : ∀ i, M [⋀^ι]→ₗ[R] N i) :
(pi f : MultilinearMap R (fun _ : ι => M) (∀ i, N i)) = MultilinearMap.pi fun a => f a :=
rfl
/-- Given an alternating `R`-multilinear map `f` taking values in `R`, `f.smul_right z` is the map
sending `m` to `f m • z`. -/
@[simps!]
def smulRight {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂]
[Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) : M₁ [⋀^ι]→ₗ[R] M₂ :=
{ f.toMultilinearMap.smulRight z with
map_eq_zero_of_eq' := fun v i j h hne => by simp [f.map_eq_zero_of_eq v h hne] }
@[simp]
theorem coe_smulRight {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁] [AddCommMonoid M₂]
[Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) :
(f.smulRight z : MultilinearMap R (fun _ : ι => M₁) M₂) = MultilinearMap.smulRight f z :=
rfl
instance add : Add (M [⋀^ι]→ₗ[R] N) :=
⟨fun a b =>
{ (a + b : MultilinearMap R (fun _ : ι => M) N) with
map_eq_zero_of_eq' := fun v i j h hij => by
simp [a.map_eq_zero_of_eq v h hij, b.map_eq_zero_of_eq v h hij] }⟩
@[simp]
theorem add_apply : (f + f') v = f v + f' v :=
rfl
@[norm_cast]
theorem coe_add : (↑(f + f') : MultilinearMap R (fun _ : ι => M) N) = f + f' :=
rfl
instance zero : Zero (M [⋀^ι]→ₗ[R] N) :=
⟨{ (0 : MultilinearMap R (fun _ : ι => M) N) with
map_eq_zero_of_eq' := fun _ _ _ _ _ => by simp }⟩
@[simp]
theorem zero_apply : (0 : M [⋀^ι]→ₗ[R] N) v = 0 :=
rfl
@[norm_cast]
theorem coe_zero : ((0 : M [⋀^ι]→ₗ[R] N) : MultilinearMap R (fun _ : ι => M) N) = 0 :=
rfl
@[simp]
theorem mk_zero :
mk (0 : MultilinearMap R (fun _ : ι ↦ M) N) (0 : M [⋀^ι]→ₗ[R] N).2 = 0 :=
rfl
instance inhabited : Inhabited (M [⋀^ι]→ₗ[R] N) :=
⟨0⟩
instance addCommMonoid : AddCommMonoid (M [⋀^ι]→ₗ[R] N) :=
coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => coeFn_smul _ _
instance neg : Neg (M [⋀^ι]→ₗ[R] N') :=
⟨fun f =>
{ -(f : MultilinearMap R (fun _ : ι => M) N') with
map_eq_zero_of_eq' := fun v i j h hij => by simp [f.map_eq_zero_of_eq v h hij] }⟩
@[simp]
theorem neg_apply (m : ι → M) : (-g) m = -g m :=
rfl
@[norm_cast]
theorem coe_neg : ((-g : M [⋀^ι]→ₗ[R] N') : MultilinearMap R (fun _ : ι => M) N') = -g :=
rfl
instance sub : Sub (M [⋀^ι]→ₗ[R] N') :=
⟨fun f g =>
{ (f - g : MultilinearMap R (fun _ : ι => M) N') with
map_eq_zero_of_eq' := fun v i j h hij => by
simp [f.map_eq_zero_of_eq v h hij, g.map_eq_zero_of_eq v h hij] }⟩
@[simp]
theorem sub_apply (m : ι → M) : (g - g₂) m = g m - g₂ m :=
rfl
@[norm_cast]
theorem coe_sub : (↑(g - g₂) : MultilinearMap R (fun _ : ι => M) N') = g - g₂ :=
rfl
instance addCommGroup : AddCommGroup (M [⋀^ι]→ₗ[R] N') :=
coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => coeFn_smul _ _) fun _ _ => coeFn_smul _ _
section DistribMulAction
variable {S : Type*} [Monoid S] [DistribMulAction S N] [SMulCommClass R S N]
instance distribMulAction : DistribMulAction S (M [⋀^ι]→ₗ[R] N) where
one_smul _ := ext fun _ => one_smul _ _
mul_smul _ _ _ := ext fun _ => mul_smul _ _ _
smul_zero _ := ext fun _ => smul_zero _
smul_add _ _ _ := ext fun _ => smul_add _ _ _
end DistribMulAction
section Module
variable {S : Type*} [Semiring S] [Module S N] [SMulCommClass R S N]
/-- The space of multilinear maps over an algebra over `R` is a module over `R`, for the pointwise
addition and scalar multiplication. -/
instance module : Module S (M [⋀^ι]→ₗ[R] N) where
add_smul _ _ _ := ext fun _ => add_smul _ _ _
zero_smul _ := ext fun _ => zero_smul _ _
instance noZeroSMulDivisors [NoZeroSMulDivisors S N] :
NoZeroSMulDivisors S (M [⋀^ι]→ₗ[R] N) :=
coe_injective.noZeroSMulDivisors _ rfl coeFn_smul
end Module
section
variable (R M N)
/-- The natural equivalence between linear maps from `M` to `N`
and `1`-multilinear alternating maps from `M` to `N`. -/
@[simps!]
def ofSubsingleton [Subsingleton ι] (i : ι) : (M →ₗ[R] N) ≃ (M [⋀^ι]→ₗ[R] N) where
toFun f := ⟨MultilinearMap.ofSubsingleton R M N i f, fun _ _ _ _ ↦ absurd (Subsingleton.elim _ _)⟩
invFun f := (MultilinearMap.ofSubsingleton R M N i).symm f
left_inv _ := rfl
right_inv _ := coe_multilinearMap_injective <|
(MultilinearMap.ofSubsingleton R M N i).apply_symm_apply _
variable (ι) {N}
/-- The constant map is alternating when `ι` is empty. -/
@[simps -fullyApplied]
def constOfIsEmpty [IsEmpty ι] (m : N) : M [⋀^ι]→ₗ[R] N :=
{ MultilinearMap.constOfIsEmpty R _ m with
toFun := Function.const _ m
map_eq_zero_of_eq' := fun _ => isEmptyElim }
end
/-- Restrict the codomain of an alternating map to a submodule. -/
@[simps]
def codRestrict (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N) (h : ∀ v, f v ∈ p) :
M [⋀^ι]→ₗ[R] p :=
{ f.toMultilinearMap.codRestrict p h with
toFun := fun v => ⟨f v, h v⟩
map_eq_zero_of_eq' := fun _ _ _ hv hij => Subtype.ext <| map_eq_zero_of_eq _ _ hv hij }
end AlternatingMap
/-!
### Composition with linear maps
-/
namespace LinearMap
variable {S : Type*} {N₂ : Type*} [AddCommMonoid N₂] [Module R N₂]
/-- Composing an alternating map with a linear map on the left gives again an alternating map. -/
def compAlternatingMap (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) : M [⋀^ι]→ₗ[R] N₂ where
__ := g.compMultilinearMap (f : MultilinearMap R (fun _ : ι => M) N)
map_eq_zero_of_eq' v i j h hij := by simp [f.map_eq_zero_of_eq v h hij]
@[simp]
theorem coe_compAlternatingMap (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) :
⇑(g.compAlternatingMap f) = g ∘ f :=
rfl
@[simp]
theorem compAlternatingMap_apply (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) (m : ι → M) :
g.compAlternatingMap f m = g (f m) :=
rfl
@[simp]
theorem compAlternatingMap_zero (g : N →ₗ[R] N₂) :
g.compAlternatingMap (0 : M [⋀^ι]→ₗ[R] N) = 0 :=
AlternatingMap.ext fun _ => map_zero g
@[simp]
theorem zero_compAlternatingMap (f : M [⋀^ι]→ₗ[R] N) :
(0 : N →ₗ[R] N₂).compAlternatingMap f = 0 := rfl
@[simp]
theorem compAlternatingMap_add (g : N →ₗ[R] N₂) (f₁ f₂ : M [⋀^ι]→ₗ[R] N) :
g.compAlternatingMap (f₁ + f₂) = g.compAlternatingMap f₁ + g.compAlternatingMap f₂ :=
AlternatingMap.ext fun _ => map_add g _ _
@[simp]
theorem add_compAlternatingMap (g₁ g₂ : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N) :
(g₁ + g₂).compAlternatingMap f = g₁.compAlternatingMap f + g₂.compAlternatingMap f := rfl
@[simp]
theorem compAlternatingMap_smul [Monoid S] [DistribMulAction S N] [DistribMulAction S N₂]
[SMulCommClass R S N] [SMulCommClass R S N₂] [CompatibleSMul N N₂ S R]
(g : N →ₗ[R] N₂) (s : S) (f : M [⋀^ι]→ₗ[R] N) :
g.compAlternatingMap (s • f) = s • g.compAlternatingMap f :=
AlternatingMap.ext fun _ => g.map_smul_of_tower _ _
@[simp]
theorem smul_compAlternatingMap [Monoid S] [DistribMulAction S N₂] [SMulCommClass R S N₂]
(g : N →ₗ[R] N₂) (s : S) (f : M [⋀^ι]→ₗ[R] N) :
(s • g).compAlternatingMap f = s • g.compAlternatingMap f := rfl
variable (S) in
/-- `LinearMap.compAlternatingMap` as an `S`-linear map. -/
@[simps]
def compAlternatingMapₗ [Semiring S] [Module S N] [Module S N₂]
[SMulCommClass R S N] [SMulCommClass R S N₂] [LinearMap.CompatibleSMul N N₂ S R]
(g : N →ₗ[R] N₂) :
(M [⋀^ι]→ₗ[R] N) →ₗ[S] (M [⋀^ι]→ₗ[R] N₂) where
toFun := g.compAlternatingMap
map_add' := g.compAlternatingMap_add
map_smul' := g.compAlternatingMap_smul
theorem smulRight_eq_comp {R M₁ M₂ ι : Type*} [CommSemiring R] [AddCommMonoid M₁]
[AddCommMonoid M₂] [Module R M₁] [Module R M₂] (f : M₁ [⋀^ι]→ₗ[R] R) (z : M₂) :
f.smulRight z = (LinearMap.id.smulRight z).compAlternatingMap f :=
rfl
@[simp]
theorem subtype_compAlternatingMap_codRestrict (f : M [⋀^ι]→ₗ[R] N) (p : Submodule R N)
(h) : p.subtype.compAlternatingMap (f.codRestrict p h) = f :=
AlternatingMap.ext fun _ => rfl
@[simp]
theorem compAlternatingMap_codRestrict (g : N →ₗ[R] N₂) (f : M [⋀^ι]→ₗ[R] N)
(p : Submodule R N₂) (h) :
(g.codRestrict p h).compAlternatingMap f =
(g.compAlternatingMap f).codRestrict p fun v => h (f v) :=
AlternatingMap.ext fun _ => rfl
end LinearMap
namespace AlternatingMap
variable {M₂ : Type*} [AddCommMonoid M₂] [Module R M₂]
variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃]
/-- Composing an alternating map with the same linear map on each argument gives again an
alternating map. -/
def compLinearMap (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) : M₂ [⋀^ι]→ₗ[R] N :=
{ (f : MultilinearMap R (fun _ : ι => M) N).compLinearMap fun _ => g with
map_eq_zero_of_eq' := fun _ _ _ h hij => f.map_eq_zero_of_eq _ (LinearMap.congr_arg h) hij }
theorem coe_compLinearMap (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) :
⇑(f.compLinearMap g) = f ∘ (g ∘ ·) :=
rfl
@[simp]
theorem compLinearMap_apply (f : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) (v : ι → M₂) :
f.compLinearMap g v = f fun i => g (v i) :=
rfl
/-- Composing an alternating map twice with the same linear map in each argument is
the same as composing with their composition. -/
theorem compLinearMap_assoc (f : M [⋀^ι]→ₗ[R] N) (g₁ : M₂ →ₗ[R] M) (g₂ : M₃ →ₗ[R] M₂) :
(f.compLinearMap g₁).compLinearMap g₂ = f.compLinearMap (g₁ ∘ₗ g₂) :=
rfl
@[simp]
theorem zero_compLinearMap (g : M₂ →ₗ[R] M) : (0 : M [⋀^ι]→ₗ[R] N).compLinearMap g = 0 := by
ext
simp only [compLinearMap_apply, zero_apply]
@[simp]
theorem add_compLinearMap (f₁ f₂ : M [⋀^ι]→ₗ[R] N) (g : M₂ →ₗ[R] M) :
(f₁ + f₂).compLinearMap g = f₁.compLinearMap g + f₂.compLinearMap g := by
ext
simp only [compLinearMap_apply, add_apply]
@[simp]
theorem compLinearMap_zero [Nonempty ι] (f : M [⋀^ι]→ₗ[R] N) :
f.compLinearMap (0 : M₂ →ₗ[R] M) = 0 := by
ext
simp_rw [compLinearMap_apply, LinearMap.zero_apply, ← Pi.zero_def, map_zero, zero_apply]
/-- Composing an alternating map with the identity linear map in each argument. -/
@[simp]
theorem compLinearMap_id (f : M [⋀^ι]→ₗ[R] N) : f.compLinearMap LinearMap.id = f :=
ext fun _ => rfl
/-- Composing with a surjective linear map is injective. -/
theorem compLinearMap_injective (f : M₂ →ₗ[R] M) (hf : Function.Surjective f) :
Function.Injective fun g : M [⋀^ι]→ₗ[R] N => g.compLinearMap f := fun g₁ g₂ h =>
ext fun x => by
simpa [Function.surjInv_eq hf] using AlternatingMap.ext_iff.mp h (Function.surjInv hf ∘ x)
theorem compLinearMap_inj (f : M₂ →ₗ[R] M) (hf : Function.Surjective f)
(g₁ g₂ : M [⋀^ι]→ₗ[R] N) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ :=
(compLinearMap_injective _ hf).eq_iff
section DomLcongr
variable (ι R N)
variable (S : Type*) [Semiring S] [Module S N] [SMulCommClass R S N]
/-- Construct a linear equivalence between maps from a linear equivalence between domains. -/
@[simps apply]
def domLCongr (e : M ≃ₗ[R] M₂) : M [⋀^ι]→ₗ[R] N ≃ₗ[S] (M₂ [⋀^ι]→ₗ[R] N) where
toFun f := f.compLinearMap e.symm
invFun g := g.compLinearMap e
map_add' _ _ := rfl
map_smul' _ _ := rfl
left_inv f := AlternatingMap.ext fun _ => f.congr_arg <| funext fun _ => e.symm_apply_apply _
right_inv f := AlternatingMap.ext fun _ => f.congr_arg <| funext fun _ => e.apply_symm_apply _
@[simp]
theorem domLCongr_refl : domLCongr R N ι S (LinearEquiv.refl R M) = LinearEquiv.refl S _ :=
LinearEquiv.ext fun _ => AlternatingMap.ext fun _ => rfl
@[simp]
theorem domLCongr_symm (e : M ≃ₗ[R] M₂) : (domLCongr R N ι S e).symm = domLCongr R N ι S e.symm :=
rfl
theorem domLCongr_trans (e : M ≃ₗ[R] M₂) (f : M₂ ≃ₗ[R] M₃) :
(domLCongr R N ι S e).trans (domLCongr R N ι S f) = domLCongr R N ι S (e.trans f) :=
rfl
end DomLcongr
/-- Composing an alternating map with the same linear equiv on each argument gives the zero map
if and only if the alternating map is the zero map. -/
@[simp]
theorem compLinearEquiv_eq_zero_iff (f : M [⋀^ι]→ₗ[R] N) (g : M₂ ≃ₗ[R] M) :
f.compLinearMap (g : M₂ →ₗ[R] M) = 0 ↔ f = 0 :=
(domLCongr R N ι ℕ g.symm).map_eq_zero_iff
variable (f f' : M [⋀^ι]→ₗ[R] N)
variable (g g₂ : M [⋀^ι]→ₗ[R] N')
variable (g' : M' [⋀^ι]→ₗ[R] N')
variable (v : ι → M) (v' : ι → M')
open Function
/-!
### Other lemmas from `MultilinearMap`
-/
section
theorem map_update_sum {α : Type*} [DecidableEq ι] (t : Finset α) (i : ι) (g : α → M) (m : ι → M) :
f (update m i (∑ a ∈ t, g a)) = ∑ a ∈ t, f (update m i (g a)) :=
f.toMultilinearMap.map_update_sum t i g m
end
/-!
### Theorems specific to alternating maps
Various properties of reordered and repeated inputs which follow from
`AlternatingMap.map_eq_zero_of_eq`.
-/
theorem map_update_self [DecidableEq ι] {i j : ι} (hij : i ≠ j) :
f (Function.update v i (v j)) = 0 :=
f.map_eq_zero_of_eq _ (by rw [Function.update_self, Function.update_of_ne hij.symm]) hij
theorem map_update_update [DecidableEq ι] {i j : ι} (hij : i ≠ j) (m : M) :
f (Function.update (Function.update v i m) j m) = 0 :=
f.map_eq_zero_of_eq _
(by rw [Function.update_self, Function.update_of_ne hij, Function.update_self]) hij
theorem map_swap_add [DecidableEq ι] {i j : ι} (hij : i ≠ j) :
f (v ∘ Equiv.swap i j) + f v = 0 := by
rw [Equiv.comp_swap_eq_update]
convert f.map_update_update v hij (v i + v j)
simp [f.map_update_self _ hij, f.map_update_self _ hij.symm,
Function.update_comm hij (v i + v j) (v _) v, Function.update_comm hij.symm (v i) (v i) v]
theorem map_add_swap [DecidableEq ι] {i j : ι} (hij : i ≠ j) :
f v + f (v ∘ Equiv.swap i j) = 0 := by
rw [add_comm]
exact f.map_swap_add v hij
theorem map_swap [DecidableEq ι] {i j : ι} (hij : i ≠ j) : g (v ∘ Equiv.swap i j) = -g v :=
eq_neg_of_add_eq_zero_left <| g.map_swap_add v hij
theorem map_perm [DecidableEq ι] [Fintype ι] (v : ι → M) (σ : Equiv.Perm ι) :
g (v ∘ σ) = Equiv.Perm.sign σ • g v := by
induction σ using Equiv.Perm.swap_induction_on' with
| one => simp
| mul_swap s x y hxy hI => simp_all [← Function.comp_assoc, g.map_swap]
theorem map_congr_perm [DecidableEq ι] [Fintype ι] (σ : Equiv.Perm ι) :
g v = Equiv.Perm.sign σ • g (v ∘ σ) := by
rw [g.map_perm, smul_smul]
simp
section DomDomCongr
/-- Transfer the arguments to a map along an equivalence between argument indices.
This is the alternating version of `MultilinearMap.domDomCongr`. -/
@[simps]
def domDomCongr (σ : ι ≃ ι') (f : M [⋀^ι]→ₗ[R] N) : M [⋀^ι']→ₗ[R] N :=
{ f.toMultilinearMap.domDomCongr σ with
toFun := fun v => f (v ∘ σ)
map_eq_zero_of_eq' := fun v i j hv hij =>
f.map_eq_zero_of_eq (v ∘ σ) (i := σ.symm i) (j := σ.symm j)
(by simpa using hv) (σ.symm.injective.ne hij) }
@[simp]
theorem domDomCongr_refl (f : M [⋀^ι]→ₗ[R] N) : f.domDomCongr (Equiv.refl ι) = f := rfl
theorem domDomCongr_trans (σ₁ : ι ≃ ι') (σ₂ : ι' ≃ ι'') (f : M [⋀^ι]→ₗ[R] N) :
f.domDomCongr (σ₁.trans σ₂) = (f.domDomCongr σ₁).domDomCongr σ₂ :=
rfl
@[simp]
theorem domDomCongr_zero (σ : ι ≃ ι') : (0 : M [⋀^ι]→ₗ[R] N).domDomCongr σ = 0 :=
rfl
|
@[simp]
theorem domDomCongr_add (σ : ι ≃ ι') (f g : M [⋀^ι]→ₗ[R] N) :
| Mathlib/LinearAlgebra/Alternating/Basic.lean | 667 | 669 |
/-
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.Option.NAry
import Mathlib.Data.Seq.Computation
import Mathlib.Tactic.ApplyFun
import Mathlib.Data.List.Basic
/-!
# Possibly infinite lists
This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`.
-/
namespace Stream'
universe u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`.
-/
def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
/-- `Seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def Seq (α : Type u) : Type u :=
{ f : Stream' (Option α) // f.IsSeq }
/-- `Seq1 α` is the type of nonempty sequences. -/
def Seq1 (α) :=
α × Seq α
namespace Seq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : Seq α :=
⟨Stream'.const none, fun {_} _ => rfl⟩
instance : Inhabited (Seq α) :=
⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : Seq α) : Seq α :=
⟨some a::s.1, by
rintro (n | _) h
· contradiction
· exact s.2 h⟩
@[simp]
theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val :=
rfl
/-- Get the nth element of a sequence (if it exists) -/
def get? : Seq α → ℕ → Option α :=
Subtype.val
@[simp]
theorem val_eq_get (s : Seq α) (n : ℕ) : s.val n = s.get? n := by
rfl
@[simp]
theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f :=
rfl
@[simp]
theorem get?_nil (n : ℕ) : (@nil α).get? n = none :=
rfl
@[simp]
theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a :=
rfl
@[simp]
theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n :=
rfl
@[ext]
protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t :=
Subtype.eq <| funext h
theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h =>
⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero],
Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩
theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_right_injective (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def TerminatedAt (s : Seq α) (n : ℕ) : Prop :=
s.get? n = none
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) :=
decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def Terminates (s : Seq α) : Prop :=
∃ n : ℕ, s.TerminatedAt n
theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by
simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self]
/-- Functorial action of the functor `Option (α × _)` -/
@[simp]
def omap (f : β → γ) : Option (α × β) → Option (α × γ)
| none => none
| some (a, b) => some (a, f b)
/-- Get the first element of a sequence -/
def head (s : Seq α) : Option α :=
get? s 0
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : Seq α) : Seq α :=
⟨s.1.tail, fun n' => by
obtain ⟨f, al⟩ := s
exact al n'⟩
/-- member definition for `Seq` -/
protected def Mem (s : Seq α) (a : α) :=
some a ∈ s.1
instance : Membership α (Seq α) :=
⟨Seq.Mem⟩
theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n :=
le_stable
/-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.get? = some aₘ` for `m ≤ n`.
-/
theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ :=
have : s.get? n ≠ none := by simp [s_nth_eq_some]
have : s.get? m ≠ none := mt (s.le_stable m_le_n) this
Option.ne_none_iff_exists'.mp this
theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s
| ⟨_, _⟩ => Stream'.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s
| ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨_, _⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h
@[simp]
theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩
@[simp]
theorem get?_mem {s : Seq α} {n : ℕ} {x : α} (h : s.get? n = .some x) : x ∈ s := ⟨n, h.symm⟩
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : Seq α) : Option (Seq1 α) :=
(fun a' => (a', s.tail)) <$> get? s 0
theorem destruct_eq_none {s : Seq α} : destruct s = none → s = nil := by
dsimp [destruct]
induction' f0 : get? s 0 <;> intro h
· apply Subtype.eq
funext n
induction' n with n IH
exacts [f0, s.2 IH]
· contradiction
theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by
dsimp [destruct]
induction' f0 : get? s 0 with a' <;> intro h
· contradiction
· obtain ⟨f, al⟩ := s
injections _ h1 h2
rw [← h2]
apply Subtype.eq
dsimp [tail, cons]
rw [h1] at f0
rw [← f0]
exact (Stream'.eta f).symm
@[simp]
theorem destruct_nil : destruct (nil : Seq α) = none :=
rfl
@[simp]
theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ => by
unfold cons destruct Functor.map
apply congr_arg fun s => some (a, s)
apply Subtype.eq; dsimp [tail]
-- Porting note: needed universe annotation to avoid universe issues
theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by
unfold destruct head; cases get? s 0 <;> rfl
@[simp]
theorem head_nil : head (nil : Seq α) = none :=
rfl
@[simp]
theorem head_cons (a : α) (s) : head (cons a s) = some a := by
rw [head_eq_destruct, destruct_cons, Option.map_eq_map, Option.map_some']
@[simp]
theorem tail_nil : tail (nil : Seq α) = nil :=
rfl
@[simp]
theorem tail_cons (a : α) (s) : tail (cons a s) = s := by
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [tail, cons]
@[simp]
theorem get?_tail (s : Seq α) (n) : get? (tail s) n = get? s (n + 1) :=
rfl
/-- Recursion principle for sequences, compare with `List.recOn`. -/
@[cases_eliminator]
def recOn {motive : Seq α → Sort v} (s : Seq α) (nil : motive nil)
(cons : ∀ x s, motive (cons x s)) :
motive s := by
rcases H : destruct s with - | v
· rw [destruct_eq_none H]
apply nil
· obtain ⟨a, s'⟩ := v
rw [destruct_eq_cons H]
apply cons
@[simp]
theorem cons_ne_nil {x : α} {s : Seq α} : (cons x s) ≠ .nil := by
intro h
apply_fun head at h
simp at h
@[simp]
theorem nil_ne_cons {x : α} {s : Seq α} : .nil ≠ (cons x s) := cons_ne_nil.symm
theorem cons_eq_cons {x x' : α} {s s' : Seq α} :
(cons x s = cons x' s') ↔ (x = x' ∧ s = s') := by
constructor
· intro h
constructor
· apply_fun head at h
simpa using h
· apply_fun tail at h
simpa using h
· intro ⟨_, _⟩
congr
theorem head_eq_some {s : Seq α} {x : α} (h : s.head = some x) :
s = cons x s.tail := by
cases s <;> simp at h
simpa [cons_eq_cons]
theorem head_eq_none {s : Seq α} (h : s.head = none) : s = nil := by
cases s
· rfl
· simp at h
@[simp]
theorem head_eq_none_iff {s : Seq α} : s.head = none ↔ s = nil := by
constructor
· apply head_eq_none
· intro h
simp [h]
theorem mem_rec_on {C : Seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) : C s := by
obtain ⟨k, e⟩ := M; unfold Stream'.get at e
induction' k with k IH generalizing s
· have TH : s = cons a (tail s) := by
apply destruct_eq_cons
unfold destruct get? Functor.map
rw [← e]
rfl
rw [TH]
apply h1 _ _ (Or.inl rfl)
cases s with
| nil => injection e
| cons b s' =>
have h_eq : (cons b s').val (Nat.succ k) = s'.val k := by cases s' using Subtype.recOn; rfl
rw [h_eq] at e
apply h1 _ _ (Or.inr (IH e))
/-- Corecursor over pairs of `Option` values -/
def Corec.f (f : β → Option (α × β)) : Option β → Option α × Option β
| none => (none, none)
| some b =>
match f b with
| none => (none, none)
| some (a, b') => (some a, some b')
/-- Corecursor for `Seq α` as a coinductive type. Iterates `f` to produce new elements
of the sequence until `none` is obtained. -/
def corec (f : β → Option (α × β)) (b : β) : Seq α := by
refine ⟨Stream'.corec' (Corec.f f) (some b), fun {n} h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (some b)).2 n = none
revert h; generalize some b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = none → (Corec.f f (Corec.f f o).2).1 = none
rcases o with - | b <;> intro h
· rfl
dsimp [Corec.f] at h
dsimp [Corec.f]
revert h; rcases h₁ : f b with - | s <;> intro h
· rfl
· obtain ⟨a, b'⟩ := s
contradiction
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
@[simp]
theorem corec_eq (f : β → Option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) := by
dsimp [corec, destruct, get]
rw [show Stream'.corec' (Corec.f f) (some b) 0 = (Corec.f f (some b)).1 from rfl]
dsimp [Corec.f]
induction' h : f b with s; · rfl
obtain ⟨a, b'⟩ := s; dsimp [Corec.f]
apply congr_arg fun b' => some (a, b')
apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
theorem corec_nil (f : β → Option (α × β)) (b : β)
(h : f b = .none) : corec f b = nil := by
apply destruct_eq_none
simp [h]
theorem corec_cons {f : β → Option (α × β)} {b : β} {x : α} {s : β}
(h : f b = .some (x, s)) : corec f b = cons x (corec f s) := by
apply destruct_eq_cons
simp [h]
section Bisim
variable (R : Seq α → Seq α → Prop)
local infixl:50 " ~ " => R
/-- Bisimilarity relation over `Option` of `Seq1 α` -/
def BisimO : Option (Seq1 α) → Option (Seq1 α) → Prop
| none, none => True
| some (a, s), some (a', s') => a = a' ∧ R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- a relation is bisimilar if it meets the `BisimO` test -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Seq α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
exact
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ => by
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s using Subtype.recOn; rfl,
by cases s' using Subtype.recOn; rfl, r⟩) this
have := bisim r; revert r this
cases s <;> cases s'
· intro r _
constructor
· rfl
· assumption
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_cons, destruct_cons] at this
rw [head_cons, head_cons, tail_cons, tail_cons]
obtain ⟨h1, h2⟩ := this
constructor
· rw [h1]
· exact h2
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
theorem coinduction :
∀ {s₁ s₂ : Seq α},
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Seq α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| _, _, hh, ht =>
Subtype.eq (Stream'.coinduction hh fun β fr => ht β fun s => fr s.1)
theorem coinduction2 (s) (f g : Seq α → Seq β)
(H :
∀ s,
BisimO (fun s1 s2 : Seq β => ∃ s : Seq α, s1 = f s ∧ s2 = g s) (destruct (f s))
(destruct (g s))) :
f s = g s := by
refine eq_of_bisim (fun s1 s2 => ∃ s, s1 = f s ∧ s2 = g s) ?_ ⟨s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨s, h1, h2⟩
rw [h1, h2]; apply H
/-- Embed a list as a sequence -/
@[coe]
def ofList (l : List α) : Seq α :=
⟨(l[·]?), fun {n} h => by
rw [List.getElem?_eq_none_iff] at h ⊢
exact h.trans (Nat.le_succ n)⟩
instance coeList : Coe (List α) (Seq α) :=
⟨ofList⟩
@[simp]
theorem ofList_nil : ofList [] = (nil : Seq α) :=
rfl
@[simp]
theorem ofList_get? (l : List α) (n : ℕ) : (ofList l).get? n = l[n]? :=
rfl
@[deprecated (since := "2025-02-21")]
alias ofList_get := ofList_get?
@[simp]
theorem ofList_cons (a : α) (l : List α) : ofList (a::l) = cons a (ofList l) := by
ext1 (_ | n) <;> simp
theorem ofList_injective : Function.Injective (ofList : List α → _) :=
fun _ _ h => List.ext_getElem? fun _ => congr_fun (Subtype.ext_iff.1 h) _
/-- Embed an infinite stream as a sequence -/
@[coe]
def ofStream (s : Stream' α) : Seq α :=
⟨s.map some, fun {n} h => by contradiction⟩
instance coeStream : Coe (Stream' α) (Seq α) :=
⟨ofStream⟩
section MLList
/-- Embed a `MLList α` as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic `MLList`s created by meta constructions. -/
def ofMLList : MLList Id α → Seq α :=
corec fun l =>
match l.uncons with
| .none => none
| .some (a, l') => some (a, l')
instance coeMLList : Coe (MLList Id α) (Seq α) :=
⟨ofMLList⟩
/-- Translate a sequence into a `MLList`. -/
unsafe def toMLList : Seq α → MLList Id α
| s =>
match destruct s with
| none => .nil
| some (a, s') => .cons a (toMLList s')
end MLList
/-- Translate a sequence to a list. This function will run forever if
run on an infinite sequence. -/
unsafe def forceToList (s : Seq α) : List α :=
(toMLList s).force
/-- The sequence of natural numbers some 0, some 1, ... -/
def nats : Seq ℕ :=
Stream'.nats
@[simp]
theorem nats_get? (n : ℕ) : nats.get? n = some n :=
rfl
/-- Append two sequences. If `s₁` is infinite, then `s₁ ++ s₂ = s₁`,
otherwise it puts `s₂` at the location of the `nil` in `s₁`. -/
def append (s₁ s₂ : Seq α) : Seq α :=
@corec α (Seq α × Seq α)
(fun ⟨s₁, s₂⟩ =>
match destruct s₁ with
| none => omap (fun s₂ => (nil, s₂)) (destruct s₂)
| some (a, s₁') => some (a, s₁', s₂))
(s₁, s₂)
/-- Map a function over a sequence. -/
def map (f : α → β) : Seq α → Seq β
| ⟨s, al⟩ =>
⟨s.map (Option.map f), fun {n} => by
dsimp [Stream'.map, Stream'.get]
induction' e : s n with e <;> intro
· rw [al e]
assumption
· contradiction⟩
/-- Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of `nil`, the first element is never
generated.) -/
def join : Seq (Seq1 α) → Seq α :=
corec fun S =>
match destruct S with
| none => none
| some ((a, s), S') =>
some
(a,
match destruct s with
| none => S'
| some s' => cons s' S')
/-- Remove the first `n` elements from the sequence. -/
def drop (s : Seq α) : ℕ → Seq α
| 0 => s
| n + 1 => tail (drop s n)
/-- Take the first `n` elements of the sequence (producing a list) -/
def take : ℕ → Seq α → List α
| 0, _ => []
| n + 1, s =>
match destruct s with
| none => []
| some (x, r) => List.cons x (take n r)
/-- Split a sequence at `n`, producing a finite initial segment
and an infinite tail. -/
def splitAt : ℕ → Seq α → List α × Seq α
| 0, s => ([], s)
| n + 1, s =>
match destruct s with
| none => ([], nil)
| some (x, s') =>
let (l, r) := splitAt n s'
(List.cons x l, r)
/-- Folds a sequence using `f`, producing a sequence of intermediate values, i.e.
`[init, f init s.head, f (f init s.head) s.tail.head, ...]`. -/
def fold (s : Seq α) (init : β) (f : β → α → β) : Seq β :=
let f : β × Seq α → Option (β × (β × Seq α)) := fun (acc, x) =>
match destruct x with
| none => .none
| some (x, s) => .some (f acc x, f acc x, s)
cons init <| corec f (init, s)
section ZipWith
/-- Combine two sequences with a function -/
def zipWith (f : α → β → γ) (s₁ : Seq α) (s₂ : Seq β) : Seq γ :=
⟨fun n => Option.map₂ f (s₁.get? n) (s₂.get? n), fun {_} hn =>
Option.map₂_eq_none_iff.2 <| (Option.map₂_eq_none_iff.1 hn).imp s₁.2 s₂.2⟩
@[simp]
theorem get?_zipWith (f : α → β → γ) (s s' n) :
(zipWith f s s').get? n = Option.map₂ f (s.get? n) (s'.get? n) :=
rfl
end ZipWith
/-- Pair two sequences into a sequence of pairs -/
def zip : Seq α → Seq β → Seq (α × β) :=
zipWith Prod.mk
@[simp]
theorem get?_zip (s : Seq α) (t : Seq β) (n : ℕ) :
get? (zip s t) n = Option.map₂ Prod.mk (get? s n) (get? t n) :=
get?_zipWith _ _ _ _
/-- Separate a sequence of pairs into two sequences -/
def unzip (s : Seq (α × β)) : Seq α × Seq β :=
(map Prod.fst s, map Prod.snd s)
/-- Enumerate a sequence by tagging each element with its index. -/
def enum (s : Seq α) : Seq (ℕ × α) :=
Seq.zip nats s
@[simp]
theorem get?_enum (s : Seq α) (n : ℕ) : get? (enum s) n = Option.map (Prod.mk n) (get? s n) :=
get?_zip _ _ _
@[simp]
theorem enum_nil : enum (nil : Seq α) = nil :=
rfl
/-- The length of a terminating sequence. -/
def length (s : Seq α) (h : s.Terminates) : ℕ :=
Nat.find h
/-- Convert a sequence which is known to terminate into a list -/
def toList (s : Seq α) (h : s.Terminates) : List α :=
take (length s h) s
/-- Convert a sequence which is known not to terminate into a stream -/
def toStream (s : Seq α) (h : ¬s.Terminates) : Stream' α := fun n =>
Option.get _ <| not_terminates_iff.1 h n
/-- Convert a sequence into either a list or a stream depending on whether
it is finite or infinite. (Without decidability of the infiniteness predicate,
this is not constructively possible.) -/
def toListOrStream (s : Seq α) [Decidable s.Terminates] : List α ⊕ Stream' α :=
if h : s.Terminates then Sum.inl (toList s h) else Sum.inr (toStream s h)
@[simp]
theorem nil_append (s : Seq α) : append nil s = s := by
apply coinduction2; intro s
dsimp [append]; rw [corec_eq]
dsimp [append]
cases s
· trivial
· rw [destruct_cons]
dsimp
exact ⟨rfl, _, rfl, rfl⟩
@[simp]
theorem take_nil {n : ℕ} : (nil (α := α)).take n = List.nil := by
cases n <;> rfl
@[simp]
theorem take_zero {s : Seq α} : s.take 0 = [] := by
cases s <;> rfl
@[simp]
theorem take_succ_cons {n : ℕ} {x : α} {s : Seq α} :
(cons x s).take (n + 1) = x :: s.take n := by
rfl
@[simp]
theorem getElem?_take : ∀ (n k : ℕ) (s : Seq α),
(s.take k)[n]? = if n < k then s.get? n else none
| n, 0, s => by simp [take]
| n, k+1, s => by
rw [take]
cases h : destruct s with
| none =>
simp [destruct_eq_none h]
| some a =>
match a with
| (x, r) =>
rw [destruct_eq_cons h]
match n with
| 0 => simp
| | n+1 =>
simp [List.getElem?_cons_succ, Nat.add_lt_add_iff_right, getElem?_take]
theorem get?_mem_take {s : Seq α} {m n : ℕ} (h_mn : m < n) {x : α}
(h_get : s.get? m = .some x) : x ∈ s.take n := by
induction m generalizing n s with
| zero =>
obtain ⟨l, hl⟩ := Nat.exists_add_one_eq.mpr h_mn
rw [← hl, take, head_eq_some h_get]
simp
| succ k ih =>
obtain ⟨l, hl⟩ := Nat.exists_eq_add_of_lt h_mn
subst hl
have : ∃ y, s.get? 0 = .some y := by
apply ge_stable _ _ h_get
simp
| Mathlib/Data/Seq/Seq.lean | 668 | 683 |
/-
Copyright (c) 2024 Josha Dekker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Josha Dekker, Devon Tuma, Kexing Ying
-/
import Mathlib.Probability.Notation
import Mathlib.Probability.Density
import Mathlib.Probability.ConditionalProbability
import Mathlib.Probability.ProbabilityMassFunction.Constructions
/-!
# Uniform distributions and probability mass functions
This file defines two related notions of uniform distributions, which will be unified in the future.
# Uniform distributions
Defines the uniform distribution for any set with finite measure.
## Main definitions
* `IsUniform X s ℙ μ` : A random variable `X` has uniform distribution on `s` under `ℙ` if the
push-forward measure agrees with the rescaled restricted measure `μ`.
# Uniform probability mass functions
This file defines a number of uniform `PMF` distributions from various inputs,
uniformly drawing from the corresponding object.
## Main definitions
`PMF.uniformOfFinset` gives each element in the set equal probability,
with `0` probability for elements not in the set.
`PMF.uniformOfFintype` gives all elements equal probability,
equal to the inverse of the size of the `Fintype`.
`PMF.ofMultiset` draws randomly from the given `Multiset`, treating duplicate values as distinct.
Each probability is given by the count of the element divided by the size of the `Multiset`
## TODO
* Refactor the `PMF` definitions to come from a `uniformMeasure` on a `Finset`/`Fintype`/`Multiset`.
-/
open scoped Finset MeasureTheory NNReal ENNReal
-- TODO: We can't `open ProbabilityTheory` without opening the `ProbabilityTheory` locale :(
open TopologicalSpace MeasureTheory.Measure PMF
noncomputable section
namespace MeasureTheory
variable {E : Type*} [MeasurableSpace E] {μ : Measure E}
namespace pdf
variable {Ω : Type*}
variable {_ : MeasurableSpace Ω} {ℙ : Measure Ω}
/-- A random variable `X` has uniform distribution on `s` if its push-forward measure is
`(μ s)⁻¹ • μ.restrict s`. -/
def IsUniform (X : Ω → E) (s : Set E) (ℙ : Measure Ω) (μ : Measure E := by volume_tac) :=
map X ℙ = ProbabilityTheory.cond μ s
namespace IsUniform
theorem aemeasurable {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) : AEMeasurable X ℙ := by
dsimp [IsUniform, ProbabilityTheory.cond] at hu
by_contra h
rw [map_of_not_aemeasurable h] at hu
apply zero_ne_one' ℝ≥0∞
calc
0 = (0 : Measure E) Set.univ := rfl
_ = _ := by rw [hu, smul_apply, restrict_apply MeasurableSet.univ,
Set.univ_inter, smul_eq_mul, ENNReal.inv_mul_cancel hns hnt]
theorem absolutelyContinuous {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) : map X ℙ ≪ μ := by
rw [hu]; exact ProbabilityTheory.cond_absolutelyContinuous
theorem measure_preimage {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) {A : Set E} (hA : MeasurableSet A) :
ℙ (X ⁻¹' A) = μ (s ∩ A) / μ s := by
rwa [← map_apply_of_aemeasurable (hu.aemeasurable hns hnt) hA, hu, ProbabilityTheory.cond_apply',
ENNReal.div_eq_inv_mul]
theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ :=
⟨by
have : X ⁻¹' Set.univ = Set.univ := Set.preimage_univ
rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ,
ENNReal.div_self hns hnt]⟩
theorem toMeasurable_iff {X : Ω → E} {s : Set E} :
IsUniform X (toMeasurable μ s) ℙ μ ↔ IsUniform X s ℙ μ := by
unfold IsUniform
rw [ProbabilityTheory.cond_toMeasurable_eq]
protected theorem toMeasurable {X : Ω → E} {s : Set E} (hu : IsUniform X s ℙ μ) :
IsUniform X (toMeasurable μ s) ℙ μ := by
unfold IsUniform at *
rwa [ProbabilityTheory.cond_toMeasurable_eq]
theorem hasPDF {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
(hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
let t := toMeasurable μ s
apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (t.indicator ((μ t)⁻¹ • 1)) <|
(measurable_one.aemeasurable.const_smul (μ t)⁻¹).indicator (measurableSet_toMeasurable μ s)
rw [hu, withDensity_indicator (measurableSet_toMeasurable μ s), withDensity_smul _ measurable_one,
withDensity_one, restrict_toMeasurable hnt, measure_toMeasurable, ProbabilityTheory.cond]
theorem pdf_eq_zero_of_measure_eq_zero_or_top {X : Ω → E} {s : Set E}
(hu : IsUniform X s ℙ μ) (hμs : μ s = 0 ∨ μ s = ∞) : pdf X ℙ μ =ᵐ[μ] 0 := by
rcases hμs with H|H
· simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_zero, restrict_eq_zero.mpr H,
smul_zero] at hu
simp [pdf, hu]
· simp only [IsUniform, ProbabilityTheory.cond, H, ENNReal.inv_top, zero_smul] at hu
simp [pdf, hu]
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
(hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
by_cases hnt : μ s = ∞
· simp [pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inr hnt), hnt]
by_cases hns : μ s = 0
· filter_upwards [measure_zero_iff_ae_nmem.mp hns,
pdf_eq_zero_of_measure_eq_zero_or_top hu (Or.inl hns)] with x hx h'x
simp [hx, h'x, hns]
have : HasPDF X ℙ μ := hasPDF hns hnt hu
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
apply (eq_of_map_eq_withDensity _ _).mp
· rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one,
ProbabilityTheory.cond]
· exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
theorem pdf_toReal_ae_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s)
(hX : IsUniform X s ℙ μ) :
(fun x => (pdf X ℙ μ x).toReal) =ᵐ[μ] fun x =>
(s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x).toReal :=
Filter.EventuallyEq.fun_comp (pdf_eq hms hX) ENNReal.toReal
variable {X : Ω → ℝ} {s : Set ℝ}
theorem mul_pdf_integrable (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
by_cases hnt : volume s = 0 ∨ volume s = ∞
· have I : Integrable (fun x ↦ x * ENNReal.toReal (0)) := by simp
apply I.congr
filter_upwards [pdf_eq_zero_of_measure_eq_zero_or_top huX hnt] with x hx
simp [hx]
simp only [not_or] at hnt
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hnt.1 hnt.2 huX
constructor
· exact aestronglyMeasurable_id.mul
(measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
refine hasFiniteIntegral_mul (pdf_eq hcs.measurableSet huX) ?_
set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
have : ∀ x, ‖x‖ₑ * s.indicator ind x = s.indicator (fun x => ‖x‖ₑ * ind x) x := fun x =>
(s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm
simp only [ind, this, lintegral_indicator hcs.measurableSet, mul_one, Algebra.id.smul_eq_mul,
Pi.one_apply, Pi.smul_apply]
rw [lintegral_mul_const _ measurable_enorm]
exact ENNReal.mul_ne_top (setLIntegral_lt_top_of_isCompact hnt.2 hcs continuous_nnnorm).ne
(ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hnt.1)).ne
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
rw [← smul_eq_mul, ← integral_smul_measure]
dsimp only [IsUniform, ProbabilityTheory.cond] at huX
rw [← huX]
by_cases hX : AEMeasurable X ℙ
· exact (integral_map hX aestronglyMeasurable_id).symm
· rw [map_of_not_aemeasurable hX, integral_zero_measure, integral_non_aestronglyMeasurable]
rwa [aestronglyMeasurable_iff_aemeasurable]
end IsUniform
variable {X : Ω → E}
lemma IsUniform.cond {s : Set E} :
IsUniform (id : E → E) s (ProbabilityTheory.cond μ s) μ := by
unfold IsUniform
rw [Measure.map_id]
/-- The density of the uniform measure on a set with respect to itself. This allows us to abstract
away the choice of random variable and probability space. -/
def uniformPDF (s : Set E) (x : E) (μ : Measure E := by volume_tac) : ℝ≥0∞ :=
s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) x
/-- Check that indeed any uniform random variable has the uniformPDF. -/
lemma uniformPDF_eq_pdf {s : Set E} (hs : MeasurableSet s) (hu : pdf.IsUniform X s ℙ μ) :
(fun x ↦ uniformPDF s x μ) =ᵐ[μ] pdf X ℙ μ := by
unfold uniformPDF
exact Filter.EventuallyEq.trans (pdf.IsUniform.pdf_eq hs hu).symm (ae_eq_refl _)
open scoped Classical in
| /-- Alternative way of writing the uniformPDF. -/
lemma uniformPDF_ite {s : Set E} {x : E} :
uniformPDF s x μ = if x ∈ s then (μ s)⁻¹ else 0 := by
unfold uniformPDF
unfold Set.indicator
| Mathlib/Probability/Distributions/Uniform.lean | 197 | 201 |
/-
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.Sum.Basic
import Mathlib.Logic.Equiv.Option
import Mathlib.Logic.Equiv.Sum
import Mathlib.Logic.Function.Conjugate
import Mathlib.Tactic.CC
import Mathlib.Tactic.Lift
/-!
# Equivalence between types
In this file we continue the work on equivalences begun in `Mathlib/Logic/Equiv/Defs.lean`, defining
a lot of equivalences between various types and operations on these equivalences.
More definitions of this kind can be found in other files.
E.g., `Mathlib/Algebra/Equiv/TransferInstance.lean` does it for many algebraic type classes like
`Group`, `Module`, etc.
## Tags
equivalence, congruence, bijective map
-/
universe u v w z
open Function
-- Unless required to be `Type*`, all variables in this file are `Sort*`
variable {α α₁ α₂ β β₁ β₂ γ δ : Sort*}
namespace Equiv
/-- The product over `Option α` of `β a` is the binary product of the
product over `α` of `β (some α)` and `β none` -/
@[simps]
def piOptionEquivProd {α} {β : Option α → Type*} :
(∀ a : Option α, β a) ≃ β none × ∀ a : α, β (some a) where
toFun f := (f none, fun a => f (some a))
invFun x a := Option.casesOn a x.fst x.snd
left_inv f := funext fun a => by cases a <;> rfl
right_inv x := by simp
section subtypeCongr
/-- Combines an `Equiv` between two subtypes with an `Equiv` between their complements to form a
permutation. -/
def subtypeCongr {α} {p q : α → Prop} [DecidablePred p] [DecidablePred q]
(e : { x // p x } ≃ { x // q x }) (f : { x // ¬p x } ≃ { x // ¬q x }) : Perm α :=
(sumCompl p).symm.trans ((sumCongr e f).trans (sumCompl q))
variable {ε : Type*} {p : ε → Prop} [DecidablePred p]
variable (ep ep' : Perm { a // p a }) (en en' : Perm { a // ¬p a })
/-- Combining permutations on `ε` that permute only inside or outside the subtype
split induced by `p : ε → Prop` constructs a permutation on `ε`. -/
def Perm.subtypeCongr : Equiv.Perm ε :=
permCongr (sumCompl p) (sumCongr ep en)
theorem Perm.subtypeCongr.apply (a : ε) : ep.subtypeCongr en a =
if h : p a then (ep ⟨a, h⟩ : ε) else en ⟨a, h⟩ := by
by_cases h : p a <;> simp [Perm.subtypeCongr, h]
@[simp]
theorem Perm.subtypeCongr.left_apply {a : ε} (h : p a) : ep.subtypeCongr en a = ep ⟨a, h⟩ := by
simp [Perm.subtypeCongr.apply, h]
@[simp]
theorem Perm.subtypeCongr.left_apply_subtype (a : { a // p a }) : ep.subtypeCongr en a = ep a :=
Perm.subtypeCongr.left_apply ep en a.property
@[simp]
theorem Perm.subtypeCongr.right_apply {a : ε} (h : ¬p a) : ep.subtypeCongr en a = en ⟨a, h⟩ := by
simp [Perm.subtypeCongr.apply, h]
@[simp]
theorem Perm.subtypeCongr.right_apply_subtype (a : { a // ¬p a }) : ep.subtypeCongr en a = en a :=
Perm.subtypeCongr.right_apply ep en a.property
@[simp]
theorem Perm.subtypeCongr.refl :
Perm.subtypeCongr (Equiv.refl { a // p a }) (Equiv.refl { a // ¬p a }) = Equiv.refl ε := by
ext x
by_cases h : p x <;> simp [h]
@[simp]
theorem Perm.subtypeCongr.symm : (ep.subtypeCongr en).symm = Perm.subtypeCongr ep.symm en.symm := by
ext x
by_cases h : p x
· have : p (ep.symm ⟨x, h⟩) := Subtype.property _
simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this]
· have : ¬p (en.symm ⟨x, h⟩) := Subtype.property (en.symm _)
simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this]
@[simp]
theorem Perm.subtypeCongr.trans :
(ep.subtypeCongr en).trans (ep'.subtypeCongr en')
= Perm.subtypeCongr (ep.trans ep') (en.trans en') := by
ext x
by_cases h : p x
· have : p (ep ⟨x, h⟩) := Subtype.property _
simp [Perm.subtypeCongr.apply, h, this]
· have : ¬p (en ⟨x, h⟩) := Subtype.property (en _)
simp [Perm.subtypeCongr.apply, h, symm_apply_eq, this]
end subtypeCongr
section subtypePreimage
variable (p : α → Prop) [DecidablePred p] (x₀ : { a // p a } → β)
/-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`,
the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}`
is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/
@[simps]
def subtypePreimage : { x : α → β // x ∘ Subtype.val = x₀ } ≃ ({ a // ¬p a } → β) where
toFun (x : { x : α → β // x ∘ Subtype.val = x₀ }) a := (x : α → β) a
invFun x := ⟨fun a => if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩, funext fun ⟨_, h⟩ => dif_pos h⟩
left_inv := fun ⟨x, hx⟩ =>
Subtype.val_injective <|
funext fun a => by
dsimp only
split_ifs
· rw [← hx]; rfl
· rfl
right_inv x :=
funext fun ⟨a, h⟩ =>
show dite (p a) _ _ = _ by
dsimp only
rw [dif_neg h]
theorem subtypePreimage_symm_apply_coe_pos (x : { a // ¬p a } → β) (a : α) (h : p a) :
((subtypePreimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ :=
dif_pos h
theorem subtypePreimage_symm_apply_coe_neg (x : { a // ¬p a } → β) (a : α) (h : ¬p a) :
((subtypePreimage p x₀).symm x : α → β) a = x ⟨a, h⟩ :=
dif_neg h
end subtypePreimage
section
/-- A family of equivalences `∀ a, β₁ a ≃ β₂ a` generates an equivalence between `∀ a, β₁ a` and
`∀ a, β₂ a`. -/
@[simps]
def piCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (∀ a, β₁ a) ≃ (∀ a, β₂ a) :=
⟨Pi.map fun a ↦ F a, Pi.map fun a ↦ (F a).symm, fun H => funext <| by simp,
fun H => funext <| by simp⟩
/-- Given `φ : α → β → Sort*`, we have an equivalence between `∀ a b, φ a b` and `∀ b a, φ a b`.
This is `Function.swap` as an `Equiv`. -/
@[simps apply]
def piComm (φ : α → β → Sort*) : (∀ a b, φ a b) ≃ ∀ b a, φ a b :=
⟨swap, swap, fun _ => rfl, fun _ => rfl⟩
@[simp]
theorem piComm_symm {φ : α → β → Sort*} : (piComm φ).symm = (piComm <| swap φ) :=
rfl
/-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent
to the type of dependent functions of two arguments (i.e., functions to the space of functions).
This is `Sigma.curry` and `Sigma.uncurry` together as an equiv. -/
def piCurry {α} {β : α → Type*} (γ : ∀ a, β a → Type*) :
(∀ x : Σ i, β i, γ x.1 x.2) ≃ ∀ a b, γ a b where
toFun := Sigma.curry
invFun := Sigma.uncurry
left_inv := Sigma.uncurry_curry
right_inv := Sigma.curry_uncurry
-- `simps` overapplies these but `simps -fullyApplied` under-applies them
@[simp] theorem piCurry_apply {α} {β : α → Type*} (γ : ∀ a, β a → Type*)
(f : ∀ x : Σ i, β i, γ x.1 x.2) :
piCurry γ f = Sigma.curry f :=
rfl
@[simp] theorem piCurry_symm_apply {α} {β : α → Type*} (γ : ∀ a, β a → Type*) (f : ∀ a b, γ a b) :
(piCurry γ).symm f = Sigma.uncurry f :=
rfl
end
section prodCongr
variable {α₁ α₂ β₁ β₂ : Type*} (e : α₁ → β₁ ≃ β₂)
-- See also `Equiv.ofPreimageEquiv`.
/-- A family of equivalences between fibers gives an equivalence between domains. -/
@[simps!]
def ofFiberEquiv {α β γ} {f : α → γ} {g : β → γ}
(e : ∀ c, { a // f a = c } ≃ { b // g b = c }) : α ≃ β :=
(sigmaFiberEquiv f).symm.trans <| (Equiv.sigmaCongrRight e).trans (sigmaFiberEquiv g)
theorem ofFiberEquiv_map {α β γ} {f : α → γ} {g : β → γ}
(e : ∀ c, { a // f a = c } ≃ { b // g b = c }) (a : α) : g (ofFiberEquiv e a) = f a :=
(_ : { b // g b = _ }).property
end prodCongr
section
open Sum
/-- An equivalence that separates out the 0th fiber of `(Σ (n : ℕ), f n)`. -/
def sigmaNatSucc (f : ℕ → Type u) : (Σ n, f n) ≃ f 0 ⊕ Σ n, f (n + 1) :=
⟨fun x =>
@Sigma.casesOn ℕ f (fun _ => f 0 ⊕ Σ n, f (n + 1)) x fun n =>
@Nat.casesOn (fun i => f i → f 0 ⊕ Σ n : ℕ, f (n + 1)) n (fun x : f 0 => Sum.inl x)
fun (n : ℕ) (x : f n.succ) => Sum.inr ⟨n, x⟩,
Sum.elim (Sigma.mk 0) (Sigma.map Nat.succ fun _ => id), by rintro ⟨n | n, x⟩ <;> rfl, by
rintro (x | ⟨n, x⟩) <;> rfl⟩
end
section
open Sum Nat
/-- The set of natural numbers is equivalent to `ℕ ⊕ PUnit`. -/
def natEquivNatSumPUnit : ℕ ≃ ℕ ⊕ PUnit where
toFun n := Nat.casesOn n (inr PUnit.unit) inl
invFun := Sum.elim Nat.succ fun _ => 0
left_inv n := by cases n <;> rfl
right_inv := by rintro (_ | _) <;> rfl
/-- `ℕ ⊕ PUnit` is equivalent to `ℕ`. -/
def natSumPUnitEquivNat : ℕ ⊕ PUnit ≃ ℕ :=
natEquivNatSumPUnit.symm
/-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/
def intEquivNatSumNat : ℤ ≃ ℕ ⊕ ℕ where
toFun z := Int.casesOn z inl inr
invFun := Sum.elim Int.ofNat Int.negSucc
left_inv := by rintro (m | n) <;> rfl
right_inv := by rintro (m | n) <;> rfl
end
/-- If `α` is equivalent to `β`, then `Unique α` is equivalent to `Unique β`. -/
def uniqueCongr (e : α ≃ β) : Unique α ≃ Unique β where
toFun h := @Equiv.unique _ _ h e.symm
invFun h := @Equiv.unique _ _ h e
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- If `α` is equivalent to `β`, then `IsEmpty α` is equivalent to `IsEmpty β`. -/
theorem isEmpty_congr (e : α ≃ β) : IsEmpty α ↔ IsEmpty β :=
⟨fun h => @Function.isEmpty _ _ h e.symm, fun h => @Function.isEmpty _ _ h e⟩
protected theorem isEmpty (e : α ≃ β) [IsEmpty β] : IsEmpty α :=
e.isEmpty_congr.mpr ‹_›
section
open Subtype
/-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent
at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`.
For the statement where `α = β`, that is, `e : perm α`, see `Perm.subtypePerm`. -/
@[simps apply]
def subtypeEquiv {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) :
{ a : α // p a } ≃ { b : β // q b } where
toFun a := ⟨e a, (h _).mp a.property⟩
invFun b := ⟨e.symm b, (h _).mpr ((e.apply_symm_apply b).symm ▸ b.property)⟩
left_inv a := Subtype.ext <| by simp
right_inv b := Subtype.ext <| by simp
lemma coe_subtypeEquiv_eq_map {X Y} {p : X → Prop} {q : Y → Prop} (e : X ≃ Y)
(h : ∀ x, p x ↔ q (e x)) : ⇑(e.subtypeEquiv h) = Subtype.map e (h · |>.mp) :=
rfl
@[simp]
theorem subtypeEquiv_refl {p : α → Prop} (h : ∀ a, p a ↔ p (Equiv.refl _ a) := fun _ => Iff.rfl) :
(Equiv.refl α).subtypeEquiv h = Equiv.refl { a : α // p a } := by
ext
rfl
-- We use `as_aux_lemma` here to avoid creating large proof terms when using `simp`
@[simp]
theorem subtypeEquiv_symm {p : α → Prop} {q : β → Prop} (e : α ≃ β) (h : ∀ a : α, p a ↔ q (e a)) :
(e.subtypeEquiv h).symm =
e.symm.subtypeEquiv (by as_aux_lemma =>
intro a
convert (h <| e.symm a).symm
exact (e.apply_symm_apply a).symm) :=
rfl
@[simp]
theorem subtypeEquiv_trans {p : α → Prop} {q : β → Prop} {r : γ → Prop} (e : α ≃ β) (f : β ≃ γ)
(h : ∀ a : α, p a ↔ q (e a)) (h' : ∀ b : β, q b ↔ r (f b)) :
(e.subtypeEquiv h).trans (f.subtypeEquiv h')
= (e.trans f).subtypeEquiv (by as_aux_lemma => exact fun a => (h a).trans (h' <| e a)) :=
rfl
/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to
`{x // q x}`. -/
@[simps!]
def subtypeEquivRight {p q : α → Prop} (e : ∀ x, p x ↔ q x) : { x // p x } ≃ { x // q x } :=
subtypeEquiv (Equiv.refl _) e
lemma subtypeEquivRight_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x)
(z : { x // p x }) : subtypeEquivRight e z = ⟨z, (e z.1).mp z.2⟩ := rfl
lemma subtypeEquivRight_symm_apply {p q : α → Prop} (e : ∀ x, p x ↔ q x)
(z : { x // q x }) : (subtypeEquivRight e).symm z = ⟨z, (e z.1).mpr z.2⟩ := rfl
/-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent
to the subtype `{b // p b}`. -/
def subtypeEquivOfSubtype {p : β → Prop} (e : α ≃ β) : { a : α // p (e a) } ≃ { b : β // p b } :=
subtypeEquiv e <| by simp
/-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent
to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/
def subtypeEquivOfSubtype' {p : α → Prop} (e : α ≃ β) :
{ a : α // p a } ≃ { b : β // p (e.symm b) } :=
e.symm.subtypeEquivOfSubtype.symm
/-- If two predicates are equal, then the corresponding subtypes are equivalent. -/
def subtypeEquivProp {p q : α → Prop} (h : p = q) : Subtype p ≃ Subtype q :=
subtypeEquiv (Equiv.refl α) fun _ => h ▸ Iff.rfl
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This
version allows the “inner” predicate to depend on `h : p a`. -/
@[simps]
def subtypeSubtypeEquivSubtypeExists (p : α → Prop) (q : Subtype p → Prop) :
Subtype q ≃ { a : α // ∃ h : p a, q ⟨a, h⟩ } :=
⟨fun a =>
⟨a.1, a.1.2, by
rcases a with ⟨⟨a, hap⟩, haq⟩
exact haq⟩,
fun a => ⟨⟨a, a.2.fst⟩, a.2.snd⟩, fun ⟨⟨_, _⟩, _⟩ => rfl, fun ⟨_, _, _⟩ => rfl⟩
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/
@[simps!]
def subtypeSubtypeEquivSubtypeInter {α : Type u} (p q : α → Prop) :
{ x : Subtype p // q x.1 } ≃ Subtype fun x => p x ∧ q x :=
(subtypeSubtypeEquivSubtypeExists p _).trans <|
subtypeEquivRight fun x => @exists_prop (q x) (p x)
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
@[simps!]
def subtypeSubtypeEquivSubtype {α} {p q : α → Prop} (h : ∀ {x}, q x → p x) :
{ x : Subtype p // q x.1 } ≃ Subtype q :=
(subtypeSubtypeEquivSubtypeInter p _).trans <| subtypeEquivRight fun _ => and_iff_right_of_imp h
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
@[simps apply symm_apply]
def subtypeUnivEquiv {α} {p : α → Prop} (h : ∀ x, p x) : Subtype p ≃ α :=
⟨fun x => x, fun x => ⟨x, h x⟩, fun _ => Subtype.eq rfl, fun _ => rfl⟩
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtypeSigmaEquiv {α} (p : α → Type v) (q : α → Prop) : { y : Sigma p // q y.1 } ≃ Σ x :
Subtype q, p x.1 :=
⟨fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun x => ⟨⟨x.1.1, x.2⟩, x.1.2⟩, fun _ => rfl,
fun _ => rfl⟩
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigmaSubtypeEquivOfSubset {α} (p : α → Type v) (q : α → Prop) (h : ∀ x, p x → q x) :
(Σ x : Subtype q, p x) ≃ Σ x : α, p x :=
(subtypeSigmaEquiv p q).symm.trans <| subtypeUnivEquiv fun x => h x.1 x.2
/-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then
`Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/
def sigmaSubtypeFiberEquiv {α β : Type*} (f : α → β) (p : β → Prop) (h : ∀ x, p (f x)) :
(Σ y : Subtype p, { x : α // f x = y }) ≃ α :=
calc
_ ≃ Σy : β, { x : α // f x = y } := sigmaSubtypeEquivOfSubset _ p fun _ ⟨x, h'⟩ => h' ▸ h x
_ ≃ α := sigmaFiberEquiv f
/-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent
to `{x // p x}`. -/
def sigmaSubtypeFiberEquivSubtype {α β : Type*} (f : α → β) {p : α → Prop} {q : β → Prop}
(h : ∀ x, p x ↔ q (f x)) : (Σ y : Subtype q, { x : α // f x = y }) ≃ Subtype p :=
calc
(Σy : Subtype q, { x : α // f x = y }) ≃ Σy :
Subtype q, { x : Subtype p // Subtype.mk (f x) ((h x).1 x.2) = y } := by {
apply sigmaCongrRight
intro y
apply Equiv.symm
refine (subtypeSubtypeEquivSubtypeExists _ _).trans (subtypeEquivRight ?_)
intro x
exact ⟨fun ⟨hp, h'⟩ => congr_arg Subtype.val h', fun h' => ⟨(h x).2 (h'.symm ▸ y.2),
Subtype.eq h'⟩⟩ }
_ ≃ Subtype p := sigmaFiberEquiv fun x : Subtype p => (⟨f x, (h x).1 x.property⟩ : Subtype q)
/-- A sigma type over an `Option` is equivalent to the sigma set over the original type,
if the fiber is empty at none. -/
def sigmaOptionEquivOfSome {α} (p : Option α → Type v) (h : p none → False) :
(Σ x : Option α, p x) ≃ Σ x : α, p (some x) :=
haveI h' : ∀ x, p x → x.isSome := by
intro x
cases x
· intro n
exfalso
exact h n
· intro _
exact rfl
(sigmaSubtypeEquivOfSubset _ _ h').symm.trans (sigmaCongrLeft' (optionIsSomeEquiv α))
/-- The `Pi`-type `∀ i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the
`Sigma` type such that for all `i` we have `(f i).fst = i`. -/
def piEquivSubtypeSigma (ι) (π : ι → Type*) :
(∀ i, π i) ≃ { f : ι → Σ i, π i // ∀ i, (f i).1 = i } where
toFun := fun f => ⟨fun i => ⟨i, f i⟩, fun _ => rfl⟩
invFun := fun f i => by rw [← f.2 i]; exact (f.1 i).2
left_inv := fun _ => funext fun _ => rfl
right_inv := fun ⟨f, hf⟩ =>
Subtype.eq <| funext fun i =>
Sigma.eq (hf i).symm <| eq_of_heq <| rec_heq_of_heq _ <| by simp
/-- The type of functions `f : ∀ a, β a` such that for all `a` we have `p a (f a)` is equivalent
to the type of functions `∀ a, {b : β a // p a b}`. -/
def subtypePiEquivPi {β : α → Sort v} {p : ∀ a, β a → Prop} :
{ f : ∀ a, β a // ∀ a, p a (f a) } ≃ ∀ a, { b : β a // p a b } where
toFun := fun f a => ⟨f.1 a, f.2 a⟩
invFun := fun f => ⟨fun a => (f a).1, fun a => (f a).2⟩
left_inv := by
rintro ⟨f, h⟩
rfl
right_inv := by
rintro f
funext a
exact Subtype.ext_val rfl
end
section subtypeEquivCodomain
variable {X Y : Sort*} [DecidableEq X] {x : X}
/-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x`
is equivalent to the codomain `Y`. -/
def subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) :
{ g : X → Y // g ∘ (↑) = f } ≃ Y :=
(subtypePreimage _ f).trans <|
@funUnique { x' // ¬x' ≠ x } _ <|
show Unique { x' // ¬x' ≠ x } from
@Equiv.unique _ _
(show Unique { x' // x' = x } from {
default := ⟨x, rfl⟩, uniq := fun ⟨_, h⟩ => Subtype.val_injective h })
(subtypeEquivRight fun _ => not_not)
@[simp]
theorem coe_subtypeEquivCodomain (f : { x' // x' ≠ x } → Y) :
(subtypeEquivCodomain f : _ → Y) =
fun g : { g : X → Y // g ∘ (↑) = f } => (g : X → Y) x :=
rfl
@[simp]
theorem subtypeEquivCodomain_apply (f : { x' // x' ≠ x } → Y) (g) :
subtypeEquivCodomain f g = (g : X → Y) x :=
rfl
theorem coe_subtypeEquivCodomain_symm (f : { x' // x' ≠ x } → Y) :
((subtypeEquivCodomain f).symm : Y → _) = fun y =>
⟨fun x' => if h : x' ≠ x then f ⟨x', h⟩ else y, by
funext x'
simp only [ne_eq, dite_not, comp_apply, Subtype.coe_eta, dite_eq_ite, ite_eq_right_iff]
intro w
exfalso
exact x'.property w⟩ :=
rfl
@[simp]
theorem subtypeEquivCodomain_symm_apply (f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) :
((subtypeEquivCodomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y :=
rfl
theorem subtypeEquivCodomain_symm_apply_eq (f : { x' // x' ≠ x } → Y) (y : Y) :
((subtypeEquivCodomain f).symm y : X → Y) x = y :=
dif_neg (not_not.mpr rfl)
theorem subtypeEquivCodomain_symm_apply_ne
(f : { x' // x' ≠ x } → Y) (y : Y) (x' : X) (h : x' ≠ x) :
((subtypeEquivCodomain f).symm y : X → Y) x' = f ⟨x', h⟩ :=
dif_pos h
end subtypeEquivCodomain
instance : CanLift (α → β) (α ≃ β) (↑) Bijective where prf f hf := ⟨ofBijective f hf, rfl⟩
section
variable {α' β' : Type*} (e : Perm α') {p : β' → Prop} [DecidablePred p] (f : α' ≃ Subtype p)
/-- Extend the domain of `e : Equiv.Perm α` to one that is over `β` via `f : α → Subtype p`,
where `p : β → Prop`, permuting only the `b : β` that satisfy `p b`.
This can be used to extend the domain across a function `f : α → β`,
keeping everything outside of `Set.range f` fixed. For this use-case `Equiv` given by `f` can
be constructed by `Equiv.of_leftInverse'` or `Equiv.of_leftInverse` when there is a known
inverse, or `Equiv.ofInjective` in the general case.
-/
def Perm.extendDomain : Perm β' :=
(permCongr f e).subtypeCongr (Equiv.refl _)
@[simp]
theorem Perm.extendDomain_apply_image (a : α') : e.extendDomain f (f a) = f (e a) := by
simp [Perm.extendDomain]
theorem Perm.extendDomain_apply_subtype {b : β'} (h : p b) :
e.extendDomain f b = f (e (f.symm ⟨b, h⟩)) := by
simp [Perm.extendDomain, h]
theorem Perm.extendDomain_apply_not_subtype {b : β'} (h : ¬p b) : e.extendDomain f b = b := by
simp [Perm.extendDomain, h]
@[simp]
theorem Perm.extendDomain_refl : Perm.extendDomain (Equiv.refl _) f = Equiv.refl _ := by
simp [Perm.extendDomain]
@[simp]
theorem Perm.extendDomain_symm : (e.extendDomain f).symm = Perm.extendDomain e.symm f :=
rfl
theorem Perm.extendDomain_trans (e e' : Perm α') :
(e.extendDomain f).trans (e'.extendDomain f) = Perm.extendDomain (e.trans e') f := by
simp [Perm.extendDomain, permCongr_trans]
end
/-- Subtype of the quotient is equivalent to the quotient of the subtype. Let `α` be a setoid with
equivalence relation `~`. Let `p₂` be a predicate on the quotient type `α/~`, and `p₁` be the lift
of this predicate to `α`: `p₁ a ↔ p₂ ⟦a⟧`. Let `~₂` be the restriction of `~` to `{x // p₁ x}`.
Then `{x // p₂ x}` is equivalent to the quotient of `{x // p₁ x}` by `~₂`. -/
def subtypeQuotientEquivQuotientSubtype (p₁ : α → Prop) {s₁ : Setoid α} {s₂ : Setoid (Subtype p₁)}
(p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : Subtype p₁, s₂.r x y ↔ s₁.r x y) : {x // p₂ x} ≃ Quotient s₂ where
toFun a :=
Quotient.hrecOn a.1 (fun a h => ⟦⟨a, (hp₂ _).2 h⟩⟧)
(fun a b hab => hfunext (by rw [Quotient.sound hab]) fun _ _ _ =>
heq_of_eq (Quotient.sound ((h _ _).2 hab)))
a.2
invFun a :=
Quotient.liftOn a (fun a => (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : { x // p₂ x })) fun _ _ hab =>
Subtype.ext_val (Quotient.sound ((h _ _).1 hab))
left_inv := by exact fun ⟨a, ha⟩ => Quotient.inductionOn a (fun b hb => rfl) ha
right_inv a := by exact Quotient.inductionOn a fun ⟨a, ha⟩ => rfl
@[simp]
theorem subtypeQuotientEquivQuotientSubtype_mk (p₁ : α → Prop)
[s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : Subtype p₁, s₂ x y ↔ (x : α) ≈ y)
(x hx) : subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h ⟨⟦x⟧, hx⟩ = ⟦⟨x, (hp₂ _).2 hx⟩⟧ :=
rfl
@[simp]
theorem subtypeQuotientEquivQuotientSubtype_symm_mk (p₁ : α → Prop)
[s₁ : Setoid α] [s₂ : Setoid (Subtype p₁)] (p₂ : Quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : Subtype p₁, s₂ x y ↔ (x : α) ≈ y) (x) :
(subtypeQuotientEquivQuotientSubtype p₁ p₂ hp₂ h).symm ⟦x⟧ = ⟨⟦x⟧, (hp₂ _).1 x.property⟩ :=
rfl
section Swap
variable [DecidableEq α]
/-- A helper function for `Equiv.swap`. -/
def swapCore (a b r : α) : α :=
if r = a then b else if r = b then a else r
theorem swapCore_self (r a : α) : swapCore a a r = r := by
unfold swapCore
split_ifs <;> simp [*]
theorem swapCore_swapCore (r a b : α) : swapCore a b (swapCore a b r) = r := by
unfold swapCore; split_ifs <;> cc
theorem swapCore_comm (r a b : α) : swapCore a b r = swapCore b a r := by
unfold swapCore; split_ifs <;> cc
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : α) : Perm α :=
⟨swapCore a b, swapCore a b, fun r => swapCore_swapCore r a b,
fun r => swapCore_swapCore r a b⟩
@[simp]
theorem swap_self (a : α) : swap a a = Equiv.refl _ :=
ext fun r => swapCore_self r a
theorem swap_comm (a b : α) : swap a b = swap b a :=
ext fun r => swapCore_comm r _ _
theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp]
theorem swap_apply_left (a b : α) : swap a b a = b :=
if_pos rfl
@[simp]
theorem swap_apply_right (a b : α) : swap a b b = a := by
by_cases h : b = a <;> simp [swap_apply_def, h]
theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x := by
simp +contextual [swap_apply_def]
theorem eq_or_eq_of_swap_apply_ne_self {a b x : α} (h : swap a b x ≠ x) : x = a ∨ x = b := by
contrapose! h
exact swap_apply_of_ne_of_ne h.1 h.2
@[simp]
theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = Equiv.refl _ :=
ext fun _ => swapCore_swapCore _ _ _
@[simp]
theorem symm_swap (a b : α) : (swap a b).symm = swap a b :=
rfl
@[simp]
theorem swap_eq_refl_iff {x y : α} : swap x y = Equiv.refl _ ↔ x = y := by
refine ⟨fun h => (Equiv.refl _).injective ?_, fun h => h ▸ swap_self _⟩
rw [← h, swap_apply_left, h, refl_apply]
theorem swap_comp_apply {a b x : α} (π : Perm α) :
π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x := by
cases π
rfl
theorem swap_eq_update (i j : α) : (Equiv.swap i j : α → α) = update (update id j i) i j :=
funext fun x => by rw [update_apply _ i j, update_apply _ j i, Equiv.swap_apply_def, id]
theorem comp_swap_eq_update (i j : α) (f : α → β) :
f ∘ Equiv.swap i j = update (update f j (f i)) i (f j) := by
rw [swap_eq_update, comp_update, comp_update, comp_id]
@[simp]
theorem symm_trans_swap_trans [DecidableEq β] (a b : α) (e : α ≃ β) :
(e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=
Equiv.ext fun x => by
have : ∀ a, e.symm x = a ↔ x = e a := fun a => by
rw [@eq_comm _ (e.symm x)]
constructor <;> intros <;> simp_all
simp only [trans_apply, swap_apply_def, this]
split_ifs <;> simp
@[simp]
theorem trans_swap_trans_symm [DecidableEq β] (a b : β) (e : α ≃ β) :
(e.trans (swap a b)).trans e.symm = swap (e.symm a) (e.symm b) :=
symm_trans_swap_trans a b e.symm
@[simp]
theorem swap_apply_self (i j a : α) : swap i j (swap i j a) = a := by
rw [← Equiv.trans_apply, Equiv.swap_swap, Equiv.refl_apply]
/-- A function is invariant to a swap if it is equal at both elements -/
theorem apply_swap_eq_self {v : α → β} {i j : α} (hv : v i = v j) (k : α) :
v (swap i j k) = v k := by
by_cases hi : k = i
· rw [hi, swap_apply_left, hv]
by_cases hj : k = j
· rw [hj, swap_apply_right, hv]
rw [swap_apply_of_ne_of_ne hi hj]
theorem swap_apply_eq_iff {x y z w : α} : swap x y z = w ↔ z = swap x y w := by
rw [apply_eq_iff_eq_symm_apply, symm_swap]
theorem swap_apply_ne_self_iff {a b x : α} : swap a b x ≠ x ↔ a ≠ b ∧ (x = a ∨ x = b) := by
by_cases hab : a = b
· simp [hab]
by_cases hax : x = a
· simp [hax, eq_comm]
by_cases hbx : x = b
· simp [hbx]
simp [hab, hax, hbx, swap_apply_of_ne_of_ne]
namespace Perm
@[simp]
theorem sumCongr_swap_refl {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : α) :
Equiv.Perm.sumCongr (Equiv.swap i j) (Equiv.refl β) = Equiv.swap (Sum.inl i) (Sum.inl j) := by
ext x
cases x
· simp only [Equiv.sumCongr_apply, Sum.map, coe_refl, comp_id, Sum.elim_inl, comp_apply,
swap_apply_def, Sum.inl.injEq]
split_ifs <;> rfl
· simp [Sum.map, swap_apply_of_ne_of_ne]
@[simp]
theorem sumCongr_refl_swap {α β : Sort _} [DecidableEq α] [DecidableEq β] (i j : β) :
Equiv.Perm.sumCongr (Equiv.refl α) (Equiv.swap i j) = Equiv.swap (Sum.inr i) (Sum.inr j) := by
ext x
cases x
· simp [Sum.map, swap_apply_of_ne_of_ne]
· simp only [Equiv.sumCongr_apply, Sum.map, coe_refl, comp_id, Sum.elim_inr, comp_apply,
swap_apply_def, Sum.inr.injEq]
split_ifs <;> rfl
end Perm
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def setValue (f : α ≃ β) (a : α) (b : β) : α ≃ β :=
(swap a (f.symm b)).trans f
@[simp]
theorem setValue_eq (f : α ≃ β) (a : α) (b : β) : setValue f a b a = b := by
simp [setValue, swap_apply_left]
end Swap
end Equiv
namespace Function.Involutive
/-- Convert an involutive function `f` to a permutation with `toFun = invFun = f`. -/
def toPerm (f : α → α) (h : Involutive f) : Equiv.Perm α :=
⟨f, f, h.leftInverse, h.rightInverse⟩
@[simp]
theorem coe_toPerm {f : α → α} (h : Involutive f) : (h.toPerm f : α → α) = f :=
rfl
@[simp]
theorem toPerm_symm {f : α → α} (h : Involutive f) : (h.toPerm f).symm = h.toPerm f :=
rfl
theorem toPerm_involutive {f : α → α} (h : Involutive f) : Involutive (h.toPerm f) :=
h
theorem symm_eq_self_of_involutive (f : Equiv.Perm α) (h : Involutive f) : f.symm = f :=
DFunLike.coe_injective (h.leftInverse_iff.mp f.left_inv)
end Function.Involutive
theorem PLift.eq_up_iff_down_eq {x : PLift α} {y : α} : x = PLift.up y ↔ x.down = y :=
Equiv.plift.eq_symm_apply
theorem Function.Injective.map_swap [DecidableEq α] [DecidableEq β] {f : α → β}
(hf : Function.Injective f) (x y z : α) :
f (Equiv.swap x y z) = Equiv.swap (f x) (f y) (f z) := by
conv_rhs => rw [Equiv.swap_apply_def]
split_ifs with h₁ h₂
· rw [hf h₁, Equiv.swap_apply_left]
· rw [hf h₂, Equiv.swap_apply_right]
· rw [Equiv.swap_apply_of_ne_of_ne (mt (congr_arg f) h₁) (mt (congr_arg f) h₂)]
namespace Equiv
section
/-- Transport dependent functions through an equivalence of the base space.
-/
@[simps apply, simps -isSimp symm_apply]
def piCongrLeft' (P : α → Sort*) (e : α ≃ β) : (∀ a, P a) ≃ ∀ b, P (e.symm b) where
toFun f x := f (e.symm x)
invFun f x := (e.symm_apply_apply x).ndrec (f (e x))
left_inv f := funext fun x =>
(by rintro _ rfl; rfl : ∀ {y} (h : y = x), h.ndrec (f y) = f x) (e.symm_apply_apply x)
right_inv f := funext fun x =>
(by rintro _ rfl; rfl : ∀ {y} (h : y = x), (congr_arg e.symm h).ndrec (f y) = f x)
(e.apply_symm_apply x)
/-- Note: the "obvious" statement `(piCongrLeft' P e).symm g a = g (e a)` doesn't typecheck: the
LHS would have type `P a` while the RHS would have type `P (e.symm (e a))`. For that reason,
we have to explicitly substitute along `e.symm (e a) = a` in the statement of this lemma. -/
add_decl_doc Equiv.piCongrLeft'_symm_apply
/-- This lemma is impractical to state in the dependent case. -/
@[simp]
theorem piCongrLeft'_symm (P : Sort*) (e : α ≃ β) :
(piCongrLeft' (fun _ => P) e).symm = piCongrLeft' _ e.symm := by ext; simp [piCongrLeft']
/-- Note: the "obvious" statement `(piCongrLeft' P e).symm g a = g (e a)` doesn't typecheck: the
LHS would have type `P a` while the RHS would have type `P (e.symm (e a))`. This lemma is a way
around it in the case where `a` is of the form `e.symm b`, so we can use `g b` instead of
`g (e (e.symm b))`. -/
@[simp]
lemma piCongrLeft'_symm_apply_apply (P : α → Sort*) (e : α ≃ β) (g : ∀ b, P (e.symm b)) (b : β) :
(piCongrLeft' P e).symm g (e.symm b) = g b := by
rw [piCongrLeft'_symm_apply, ← heq_iff_eq, rec_heq_iff_heq]
exact congr_arg_heq _ (e.apply_symm_apply _)
end
section
variable (P : β → Sort w) (e : α ≃ β)
/-- Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
-/
def piCongrLeft : (∀ a, P (e a)) ≃ ∀ b, P b :=
(piCongrLeft' P e.symm).symm
/-- Note: the "obvious" statement `(piCongrLeft P e) f b = f (e.symm b)` doesn't typecheck: the
LHS would have type `P b` while the RHS would have type `P (e (e.symm b))`. For that reason,
we have to explicitly substitute along `e (e.symm b) = b` in the statement of this lemma. -/
@[simp]
lemma piCongrLeft_apply (f : ∀ a, P (e a)) (b : β) :
(piCongrLeft P e) f b = e.apply_symm_apply b ▸ f (e.symm b) :=
rfl
@[simp]
lemma piCongrLeft_symm_apply (g : ∀ b, P b) (a : α) :
(piCongrLeft P e).symm g a = g (e a) :=
piCongrLeft'_apply P e.symm g a
/-- Note: the "obvious" statement `(piCongrLeft P e) f b = f (e.symm b)` doesn't typecheck: the
LHS would have type `P b` while the RHS would have type `P (e (e.symm b))`. This lemma is a way
around it in the case where `b` is of the form `e a`, so we can use `f a` instead of
`f (e.symm (e a))`. -/
lemma piCongrLeft_apply_apply (f : ∀ a, P (e a)) (a : α) :
(piCongrLeft P e) f (e a) = f a :=
piCongrLeft'_symm_apply_apply P e.symm f a
open Sum
lemma piCongrLeft_apply_eq_cast {P : β → Sort v} {e : α ≃ β}
(f : (a : α) → P (e a)) (b : β) :
piCongrLeft P e f b = cast (congr_arg P (e.apply_symm_apply b)) (f (e.symm b)) :=
Eq.rec_eq_cast _ _
theorem piCongrLeft_sumInl {ι ι' ι''} (π : ι'' → Type*) (e : ι ⊕ ι' ≃ ι'') (f : ∀ i, π (e (inl i)))
(g : ∀ i, π (e (inr i))) (i : ι) :
piCongrLeft π e (sumPiEquivProdPi (fun x => π (e x)) |>.symm (f, g)) (e (inl i)) = f i := by
simp_rw [piCongrLeft_apply_eq_cast, sumPiEquivProdPi_symm_apply,
sum_rec_congr _ _ _ (e.symm_apply_apply (inl i)), cast_cast, cast_eq]
theorem piCongrLeft_sumInr {ι ι' ι''} (π : ι'' → Type*) (e : ι ⊕ ι' ≃ ι'') (f : ∀ i, π (e (inl i)))
(g : ∀ i, π (e (inr i))) (j : ι') :
piCongrLeft π e (sumPiEquivProdPi (fun x => π (e x)) |>.symm (f, g)) (e (inr j)) = g j := by
simp_rw [piCongrLeft_apply_eq_cast, sumPiEquivProdPi_symm_apply,
sum_rec_congr _ _ _ (e.symm_apply_apply (inr j)), cast_cast, cast_eq]
@[deprecated (since := "2025-02-21")] alias piCongrLeft_sum_inl := piCongrLeft_sumInl
@[deprecated (since := "2025-02-21")] alias piCongrLeft_sum_inr := piCongrLeft_sumInr
end
section
variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ a : α, W a ≃ Z (h₁ a))
/-- Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibers.
-/
def piCongr : (∀ a, W a) ≃ ∀ b, Z b :=
(Equiv.piCongrRight h₂).trans (Equiv.piCongrLeft _ h₁)
@[simp]
theorem coe_piCongr_symm : ((h₁.piCongr h₂).symm :
(∀ b, Z b) → ∀ a, W a) = fun f a => (h₂ a).symm (f (h₁ a)) :=
rfl
theorem piCongr_symm_apply (f : ∀ b, Z b) :
(h₁.piCongr h₂).symm f = fun a => (h₂ a).symm (f (h₁ a)) :=
rfl
@[simp]
theorem piCongr_apply_apply (f : ∀ a, W a) (a : α) : h₁.piCongr h₂ f (h₁ a) = h₂ a (f a) := by
simp only [piCongr, piCongrRight, trans_apply, coe_fn_mk, piCongrLeft_apply_apply, Pi.map_apply]
end
section
variable {W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : ∀ b : β, W (h₁.symm b) ≃ Z b)
/-- Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibres.
-/
def piCongr' : (∀ a, W a) ≃ ∀ b, Z b :=
(piCongr h₁.symm fun b => (h₂ b).symm).symm
@[simp]
theorem coe_piCongr' :
(h₁.piCongr' h₂ : (∀ a, W a) → ∀ b, Z b) = fun f b => h₂ b <| f <| h₁.symm b :=
rfl
theorem piCongr'_apply (f : ∀ a, W a) : h₁.piCongr' h₂ f = fun b => h₂ b <| f <| h₁.symm b :=
rfl
@[simp]
theorem piCongr'_symm_apply_symm_apply (f : ∀ b, Z b) (b : β) :
(h₁.piCongr' h₂).symm f (h₁.symm b) = (h₂ b).symm (f b) := by
simp [piCongr', piCongr_apply_apply]
end
/-- Transport dependent functions through an equality of sets. -/
@[simps!] def piCongrSet {α} {W : α → Sort w} {s t : Set α} (h : s = t) :
(∀ i : {i // i ∈ s}, W i) ≃ (∀ i : {i // i ∈ t}, W i) where
toFun f i := f ⟨i, h ▸ i.2⟩
invFun f i := f ⟨i, h.symm ▸ i.2⟩
left_inv f := rfl
right_inv f := rfl
section BinaryOp
variable {α₁ β₁ : Type*} (e : α₁ ≃ β₁) (f : α₁ → α₁ → α₁)
theorem semiconj_conj (f : α₁ → α₁) : Semiconj e f (e.conj f) := fun x => by simp
theorem semiconj₂_conj : Semiconj₂ e f (e.arrowCongr e.conj f) := fun x y => by simp [arrowCongr]
instance [Std.Associative f] : Std.Associative (e.arrowCongr (e.arrowCongr e) f) :=
(e.semiconj₂_conj f).isAssociative_right e.surjective
instance [Std.IdempotentOp f] : Std.IdempotentOp (e.arrowCongr (e.arrowCongr e) f) :=
(e.semiconj₂_conj f).isIdempotent_right e.surjective
end BinaryOp
section ULift
@[simp]
theorem ulift_symm_down {α} (x : α) : (Equiv.ulift.{u, v}.symm x).down = x :=
rfl
end ULift
end Equiv
theorem Function.Injective.swap_apply
[DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y z : α) :
Equiv.swap (f x) (f y) (f z) = f (Equiv.swap x y z) := by
by_cases hx : z = x
· simp [hx]
by_cases hy : z = y
· simp [hy]
rw [Equiv.swap_apply_of_ne_of_ne hx hy, Equiv.swap_apply_of_ne_of_ne (hf.ne hx) (hf.ne hy)]
theorem Function.Injective.swap_comp
[DecidableEq α] [DecidableEq β] {f : α → β} (hf : Function.Injective f) (x y : α) :
Equiv.swap (f x) (f y) ∘ f = f ∘ Equiv.swap x y :=
funext fun _ => hf.swap_apply _ _ _
/-- To give an equivalence between two subsingleton types, it is sufficient to give any two
functions between them. -/
def equivOfSubsingletonOfSubsingleton [Subsingleton α] [Subsingleton β] (f : α → β) (g : β → α) :
α ≃ β where
toFun := f
invFun := g
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
/-- A nonempty subsingleton type is (noncomputably) equivalent to `PUnit`. -/
noncomputable def Equiv.punitOfNonemptyOfSubsingleton [h : Nonempty α] [Subsingleton α] :
α ≃ PUnit :=
equivOfSubsingletonOfSubsingleton (fun _ => PUnit.unit) fun _ => h.some
/-- `Unique (Unique α)` is equivalent to `Unique α`. -/
def uniqueUniqueEquiv : Unique (Unique α) ≃ Unique α :=
equivOfSubsingletonOfSubsingleton (fun h => h.default) fun h =>
{ default := h, uniq := fun _ => Subsingleton.elim _ _ }
/-- If `Unique β`, then `Unique α` is equivalent to `α ≃ β`. -/
def uniqueEquivEquivUnique (α : Sort u) (β : Sort v) [Unique β] : Unique α ≃ (α ≃ β) :=
equivOfSubsingletonOfSubsingleton (fun _ => Equiv.ofUnique _ _) Equiv.unique
namespace Function
variable {α' : Sort*}
theorem update_comp_equiv [DecidableEq α'] [DecidableEq α] (f : α → β)
(g : α' ≃ α) (a : α) (v : β) :
update f a v ∘ g = update (f ∘ g) (g.symm a) v := by
rw [← update_comp_eq_of_injective _ g.injective, g.apply_symm_apply]
theorem update_apply_equiv_apply [DecidableEq α'] [DecidableEq α] (f : α → β)
(g : α' ≃ α) (a : α) (v : β) (a' : α') : update f a v (g a') = update (f ∘ g) (g.symm a) v a' :=
congr_fun (update_comp_equiv f g a v) a'
theorem piCongrLeft'_update [DecidableEq α] [DecidableEq β] (P : α → Sort*) (e : α ≃ β)
(f : ∀ a, P a) (b : β) (x : P (e.symm b)) :
e.piCongrLeft' P (update f (e.symm b) x) = update (e.piCongrLeft' P f) b x := by
ext b'
rcases eq_or_ne b' b with (rfl | h) <;> simp_all
theorem piCongrLeft'_symm_update [DecidableEq α] [DecidableEq β] (P : α → Sort*) (e : α ≃ β)
(f : ∀ b, P (e.symm b)) (b : β) (x : P (e.symm b)) :
(e.piCongrLeft' P).symm (update f b x) = update ((e.piCongrLeft' P).symm f) (e.symm b) x := by
simp [(e.piCongrLeft' P).symm_apply_eq, piCongrLeft'_update]
end Function
| Mathlib/Logic/Equiv/Basic.lean | 1,984 | 1,984 | |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.BigOperators.Group.List.Basic
/-!
# Free groups
This file defines free groups over a type. Furthermore, it is shown that the free group construction
is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful
functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`.
## Main definitions
* `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type
`α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`.
* `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`.
* `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`.
* `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G`
given a group `G` and a function `f : α → G`.
## Main statements
* `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word
reduction (also known as Newman's diamond lemma).
* `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type
is isomorphic to the integers.
* The free group construction is an instance of a monad.
## Implementation details
First we introduce the one step reduction relation `FreeGroup.Red.Step`:
`w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans`
and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient
over `FreeGroup.Red.Step`.
For the additive version we introduce the same relation under a different name so that we can
distinguish the quotient types more easily.
## Tags
free group, Newman's diamond lemma, Church-Rosser theorem
-/
open Relation
open scoped List
universe u v w
variable {α : Type u}
attribute [local simp] List.append_eq_has_append
-- Porting note: to_additive.map_namespace is not supported yet
-- worked around it by putting a few extra manual mappings (but not too many all in all)
-- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup
/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/
inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeAddGroup.Red.Step.not
/-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/
@[to_additive FreeAddGroup.Red.Step]
inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeGroup.Red.Step.not
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- Reflexive-transitive closure of `Red.Step` -/
@[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"]
def Red : List (α × Bool) → List (α × Bool) → Prop :=
ReflTransGen Red.Step
@[to_additive (attr := refl)]
theorem Red.refl : Red L L :=
ReflTransGen.refl
@[to_additive (attr := trans)]
theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ :=
ReflTransGen.trans
namespace Red
/-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words
`w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/
@[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there
are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"]
theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length
| _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl
@[to_additive (attr := simp)]
theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by
cases b <;> exact Step.not
@[to_additive (attr := simp)]
theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L :=
@Step.not _ [] _ _ _
@[to_additive (attr := simp)]
theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L :=
@Red.Step.not_rev _ [] _ _ _
@[to_additive]
theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃)
| _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor
@[to_additive]
theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) :=
@Step.append_left _ [x] _ _ H
@[to_additive]
theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃)
| _, _, _, Red.Step.not => by simp
@[to_additive]
theorem not_step_nil : ¬Step [] L := by
generalize h' : [] = L'
intro h
rcases h with - | ⟨L₁, L₂⟩
simp [List.nil_eq_append_iff] at h'
@[to_additive]
theorem Step.cons_left_iff {a : α} {b : Bool} :
Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by
constructor
· generalize hL : ((a, b) :: L₁ : List _) = L
rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all
· rintro (⟨L, h, rfl⟩ | rfl)
· exact Step.cons h
· exact Step.cons_not
@[to_additive]
theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L
| (a, b) => by simp [Step.cons_left_iff, not_step_nil]
@[to_additive]
theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by
simp +contextual [Step.cons_left_iff, iff_def, or_imp]
@[to_additive]
theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂
| [] => by simp
| p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff]
@[to_additive]
theorem Step.diamond_aux :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2},
L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ →
L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅
| [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp
| [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by
injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩
| (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by
injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩
| (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H =>
let ⟨H1, H2⟩ := List.cons.inj H
match Step.diamond_aux H2 with
| Or.inl H3 => Or.inl <| by simp [H1, H3]
| Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩
@[to_additive]
theorem Step.diamond :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)},
Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅
| _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H
@[to_additive]
theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ :=
ReflTransGen.single
/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma. -/
@[to_additive
"**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma."]
theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ :=
Relation.church_rosser fun _ b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩
@[to_additive]
theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) :=
ReflTransGen.lift (List.cons p) fun _ _ => Step.cons
@[to_additive]
theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ :=
Iff.intro
(by
generalize eq₁ : (p :: L₁ : List _) = LL₁
generalize eq₂ : (p :: L₂ : List _) = LL₂
intro h
induction h using Relation.ReflTransGen.head_induction_on generalizing L₁ L₂ with
| refl =>
subst_vars
cases eq₂
constructor
| head h₁₂ h ih =>
subst_vars
obtain ⟨a, b⟩ := p
rw [Step.cons_left_iff] at h₁₂
rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl)
· exact (ih rfl rfl).head h₁₂
· exact (cons_cons h).tail Step.cons_not_rev)
cons_cons
@[to_additive]
theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂
| [] => Iff.rfl
| p :: L => by simp [append_append_left_iff L, cons_cons_iff]
@[to_additive]
theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) :=
(h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂)
@[to_additive]
theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ :=
Iff.intro
(by
generalize eq : L₁ ++ L₂ = L₁₂
intro h
induction h generalizing L₁ L₂ with
| refl => exact ⟨_, _, eq.symm, by rfl, by rfl⟩
| tail hLL' h ih =>
obtain @⟨s, e, a, b⟩ := h
rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩)
· have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e :=
by simp
rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩
exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩
· have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) :=
by simp
rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩
exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩)
fun ⟨_, _, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄
/-- The empty word `[]` only reduces to itself. -/
@[to_additive "The empty word `[]` only reduces to itself."]
theorem nil_iff : Red [] L ↔ L = [] :=
reflTransGen_iff_eq fun _ => Red.not_step_nil
/-- A letter only reduces to itself. -/
@[to_additive "A letter only reduces to itself."]
theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] :=
reflTransGen_iff_eq fun _ => not_step_singleton
/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces
to `x⁻¹` -/
@[to_additive
"If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w`
reduces to `-x`."]
theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] :=
Iff.intro
(fun h => by
have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h
have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev
let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂
rw [singleton_iff] at h₁
subst L'
assumption)
fun h => (cons_cons h).tail Step.cons_not
@[to_additive]
theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) :
Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by
apply reflTransGen_iff_eq
generalize eq : [(x1, not b1), (x2, b2)] = L'
intro L h'
cases h'
simp only [List.cons_eq_append_iff, List.cons.injEq, Prod.mk.injEq, and_false,
List.nil_eq_append_iff, exists_const, or_self, or_false, List.cons_ne_nil] at eq
rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩
simp at h
/-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then
`w₁` reduces to `x⁻¹yw₂`. -/
@[to_additive "If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁` reduces
to `y + w₂`, then `w₁` reduces to `-x + y + w₂`."]
theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2))
(H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by
have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2
rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩
· simp [nil_iff] at h₁
· cases eq
show Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂)
apply append_append _ h₂
have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁
have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red
rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩
rw [red_iff_irreducible H1] at h₁
rwa [h₁] at h₂
open List -- for <+ notation
@[to_additive]
theorem Step.sublist (H : Red.Step L₁ L₂) : L₂ <+ L₁ := by
cases H; simp
/-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/
@[to_additive "If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of
`w₁`."]
protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ :=
@reflTransGen_of_transitive_reflexive
_ (fun a b => b <+ a) _ _ _
(fun l => List.Sublist.refl l)
(fun _a _b _c hab hbc => List.Sublist.trans hbc hab)
(fun _ _ => Red.Step.sublist)
@[to_additive]
theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length :=
h.sublist.length_le
@[to_additive]
theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)},
Step L₁ L₂ → sizeOf L₂ < sizeOf L₁
| _, _, @Step.not _ L1 L2 x b => by
induction L1 with
| nil =>
dsimp
omega
| cons hd tl ih =>
dsimp
exact Nat.add_lt_add_left ih _
@[to_additive]
theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by
induction h with
| refl => exact ⟨0, rfl⟩
| tail _h₁₂ h₂₃ ih =>
rcases ih with ⟨n, eq⟩
exists 1 + n
simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc]
@[to_additive]
theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ :=
h₂₁.sublist.antisymm h₁₂.sublist
end Red
@[to_additive FreeAddGroup.equivalence_join_red]
theorem equivalence_join_red : Equivalence (Join (@Red α)) :=
equivalence_join_reflTransGen fun _ b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩
@[to_additive FreeAddGroup.join_red_of_step]
theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ :=
join_of_single reflexive_reflTransGen h.to_red
@[to_additive FreeAddGroup.eqvGen_step_iff_join_red]
theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ :=
Iff.intro
(fun h =>
have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step
equivalence_join_red.eqvGen_iff.1 this)
(join_of_equivalence (Relation.EqvGen.is_equivalence _) fun _ _ =>
reflTransGen_of_equivalence (Relation.EqvGen.is_equivalence _) EqvGen.rel)
end FreeGroup
/--
If `α` is a type, then `FreeGroup α` is the free group generated by `α`.
This is a group equipped with a function `FreeGroup.of : α → FreeGroup α` which has
the following universal property: if `G` is any group, and `f : α → G` is any function,
then this function is the composite of `FreeGroup.of` and a unique group homomorphism
`FreeGroup.lift f : FreeGroup α →* G`.
A typical element of `FreeGroup α` is a formal product of
elements of `α` and their formal inverses, quotient by reduction.
For example if `x` and `y` are terms of type `α` then `x⁻¹ * y * y * x * y⁻¹` is a
"typical" element of `FreeGroup α`. In particular if `α` is empty
then `FreeGroup α` is isomorphic to the trivial group, and if `α` has one term
then `FreeGroup α` is isomorphic to `Multiplicative ℤ`.
If `α` has two or more terms then `FreeGroup α` is not commutative.
-/
@[to_additive
"
If `α` is a type, then `FreeAddGroup α` is the free additive group generated by `α`.
This is a group equipped with a function `FreeAddGroup.of : α → FreeAddGroup α` which has
the following universal property: if `G` is any group, and `f : α → G` is any function,
then this function is the composite of `FreeAddGroup.of` and a unique group homomorphism
`FreeAddGroup.lift f : FreeAddGroup α →+ G`.
A typical element of `FreeAddGroup α` is a formal sum of
elements of `α` and their formal inverses, quotient by reduction.
For example if `x` and `y` are terms of type `α` then `-x + y + y + x + -y` is a
\"typical\" element of `FreeAddGroup α`. In particular if `α` is empty
then `FreeAddGroup α` is isomorphic to the trivial group, and if `α` has one term
then `FreeAddGroup α` is isomorphic to `ℤ`.
If `α` has two or more terms then `FreeAddGroup α` is not commutative.
"]
def FreeGroup (α : Type u) : Type u :=
Quot <| @FreeGroup.Red.Step α
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- The canonical map from `List (α × Bool)` to the free group on `α`. -/
@[to_additive "The canonical map from `List (α × Bool)` to the free additive group on `α`."]
def mk (L : List (α × Bool)) : FreeGroup α :=
Quot.mk Red.Step L
@[to_additive (attr := simp)]
theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L :=
rfl
@[to_additive (attr := simp)]
theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β)
(H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L :=
rfl
@[to_additive (attr := simp)]
theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β)
(H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L :=
rfl
open scoped Relator in
@[to_additive (attr := simp)]
theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool))
(H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) :=
rfl
@[to_additive]
instance : One (FreeGroup α) :=
⟨mk []⟩
@[to_additive]
theorem one_eq_mk : (1 : FreeGroup α) = mk [] :=
rfl
@[to_additive]
instance : Inhabited (FreeGroup α) :=
⟨1⟩
@[to_additive]
instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance
@[to_additive]
instance : Mul (FreeGroup α) :=
⟨fun x y =>
Quot.liftOn x
(fun L₁ =>
Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H =>
Quot.sound <| Red.Step.append_left H)
fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩
@[to_additive (attr := simp)]
theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) :=
rfl
/-- Transform a word representing a free group element into a word representing its inverse. -/
@[to_additive "Transform a word representing a free group element into a word representing its
negative."]
def invRev (w : List (α × Bool)) : List (α × Bool) :=
(List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse
@[to_additive (attr := simp)]
theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev]
@[to_additive (attr := simp)]
theorem invRev_invRev : invRev (invRev L₁) = L₁ := by
simp [invRev, List.map_reverse, Function.comp_def]
@[to_additive (attr := simp)]
theorem invRev_empty : invRev ([] : List (α × Bool)) = [] :=
rfl
@[to_additive (attr := simp)]
theorem invRev_append : invRev (L₁ ++ L₂) = invRev L₂ ++ invRev L₁ := by simp [invRev]
@[to_additive]
theorem invRev_cons {a : (α × Bool)} : invRev (a :: L) = invRev L ++ invRev [a] := by
simp [invRev]
@[to_additive]
theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev
@[to_additive]
theorem invRev_injective : Function.Injective (@invRev α) :=
invRev_involutive.injective
@[to_additive]
theorem invRev_surjective : Function.Surjective (@invRev α) :=
invRev_involutive.surjective
@[to_additive]
theorem invRev_bijective : Function.Bijective (@invRev α) :=
invRev_involutive.bijective
@[to_additive]
instance : Inv (FreeGroup α) :=
⟨Quot.map invRev
(by
intro a b h
cases h
simp [invRev])⟩
@[to_additive (attr := simp)]
theorem inv_mk : (mk L)⁻¹ = mk (invRev L) :=
rfl
@[to_additive]
theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) :
Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by
obtain ⟨a, b, x, y⟩ := h
simp [FreeGroup.invRev]
@[to_additive]
theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) :=
Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h
@[to_additive (attr := simp)]
theorem Red.step_invRev_iff :
Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ :=
⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩
@[to_additive (attr := simp)]
theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ :=
⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩
@[to_additive]
instance : Group (FreeGroup α) where
mul := (· * ·)
one := 1
inv := Inv.inv
mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp
one_mul := by rintro ⟨L⟩; rfl
mul_one := by rintro ⟨L⟩; simp [one_eq_mk]
inv_mul_cancel := by
rintro ⟨L⟩
exact
List.recOn L rfl fun ⟨x, b⟩ tl ih =>
Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih
@[to_additive (attr := simp)]
theorem pow_mk (n : ℕ) : mk L ^ n = mk (List.flatten <| List.replicate n L) :=
match n with
| 0 => rfl
| n + 1 => by rw [pow_succ', pow_mk, mul_mk, List.replicate_succ, List.flatten_cons]
/-- `of` is the canonical injection from the type to the free group over that type by sending each
element to the equivalence class of the letter that is the element. -/
@[to_additive "`of` is the canonical injection from the type to the free group over that type
by sending each element to the equivalence class of the letter that is the element."]
def of (x : α) : FreeGroup α :=
mk [(x, true)]
@[to_additive]
theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ :=
calc
mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro Quot.eqvGen_exact Quot.eqvGen_sound
_ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red
/-- The canonical map from the type to the free group is an injection. -/
@[to_additive "The canonical map from the type to the additive free group is an injection."]
theorem of_injective : Function.Injective (@of α) := fun _ _ H => by
let ⟨L₁, hx, hy⟩ := Red.exact.1 H
simp [Red.singleton_iff] at hx hy; aesop
section lift
variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α}
/-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/
@[to_additive "Given `f : α → β` with `β` an additive group, the canonical map
`List (α × Bool) → β`"]
def Lift.aux : List (α × Bool) → β := fun L =>
List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹
@[to_additive]
theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by
obtain @⟨_, _, _, b⟩ := H; cases b <;> simp [Lift.aux]
/-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism
from the free group over `α` to `β` -/
@[to_additive (attr := simps symm_apply)
"If `β` is an additive group, then any function from `α` to `β` extends uniquely to an
additive group homomorphism from the free additive group over `α` to `β`"]
def lift : (α → β) ≃ (FreeGroup α →* β) where
toFun f :=
MonoidHom.mk' (Quot.lift (Lift.aux f) fun _ _ => Red.Step.lift) <| by
rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux]
invFun g := g ∘ of
left_inv f := List.prod_singleton
right_inv g :=
MonoidHom.ext <| by
rintro ⟨L⟩
exact List.recOn L
(g.map_one.symm)
(by
rintro ⟨x, _ | _⟩ t (ih : _ = g (mk t))
· show _ = g ((of x)⁻¹ * mk t)
simpa [Lift.aux] using ih
· show _ = g (of x * mk t)
simpa [Lift.aux] using ih)
variable {f}
@[to_additive (attr := simp)]
theorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) :=
rfl
@[to_additive (attr := simp)]
theorem lift.of {x} : lift f (of x) = f x :=
List.prod_singleton
@[to_additive]
theorem lift.unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} :
g x = FreeGroup.lift f x :=
DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x
/-- Two homomorphisms out of a free group are equal if they are equal on generators.
See note [partially-applied ext lemmas]. -/
@[to_additive (attr := ext) "Two homomorphisms out of a free additive group are equal if they are
equal on generators. See note [partially-applied ext lemmas]."]
theorem ext_hom {G : Type*} [Group G] (f g : FreeGroup α →* G) (h : ∀ a, f (of a) = g (of a)) :
f = g :=
lift.symm.injective <| funext h
@[to_additive]
theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) :=
lift.apply_symm_apply (MonoidHom.id _)
@[to_additive]
theorem lift.of_eq (x : FreeGroup α) : lift FreeGroup.of x = x :=
DFunLike.congr_fun (lift_of_eq_id α) x
@[to_additive]
theorem lift.range_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by
rintro _ ⟨⟨L⟩, rfl⟩
exact List.recOn L s.one_mem fun ⟨x, b⟩ tl ih ↦
Bool.recOn b (by simpa using s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih)
(by simpa using s.mul_mem (H ⟨x, rfl⟩) ih)
@[to_additive]
theorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by
apply le_antisymm (lift.range_le Subgroup.subset_closure)
rw [Subgroup.closure_le]
rintro _ ⟨a, rfl⟩
exact ⟨FreeGroup.of a, by simp only [lift.of]⟩
/-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the
set of generators equals `⊤`. -/
@[to_additive (attr := simp)]
theorem closure_range_of (α) :
Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by
rw [← lift.range_eq_closure, lift_of_eq_id]
exact MonoidHom.range_eq_top.2 Function.surjective_id
end lift
section Map
variable {β : Type v} (f : α → β) {x y : FreeGroup α}
/-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over
`α` to the free group over `β`. -/
@[to_additive "Any function from `α` to `β` extends uniquely to an additive group homomorphism from
the additive free group over `α` to the additive free group over `β`."]
def map : FreeGroup α →* FreeGroup β :=
MonoidHom.mk'
(Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp)
(by rintro ⟨L₁⟩ ⟨L₂⟩; simp)
variable {f}
@[to_additive (attr := simp)]
theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) :=
rfl
@[to_additive (attr := simp)]
theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id']
@[to_additive (attr := simp)]
theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x :=
map.id x
@[to_additive]
theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) :
map g (map f x) = map (g ∘ f) x := by
rcases x with ⟨L⟩; simp [Function.comp_def]
@[to_additive (attr := simp)]
theorem map.of {x} : map f (of x) = of (f x) :=
rfl
@[to_additive]
theorem map.unique (g : FreeGroup α →* FreeGroup β)
(hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) :
∀ {x}, g x = map f x := by
rintro ⟨L⟩
exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) =>
Bool.recOn b
(show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) =
FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by
simp [g.map_mul, g.map_inv, hg, ih])
(show g (FreeGroup.of x * FreeGroup.mk t) =
FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih])
@[to_additive]
theorem map_eq_lift : map f x = lift (of ∘ f) x :=
Eq.symm <| map.unique _ fun x => by simp
/-- Equivalent types give rise to multiplicatively equivalent free groups.
The converse can be found in `Mathlib.GroupTheory.FreeGroup.GeneratorEquiv`, as
`Equiv.ofFreeGroupEquiv`. -/
@[to_additive (attr := simps apply)
"Equivalent types give rise to additively equivalent additive free groups."]
def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where
toFun := map e
invFun := map e.symm
left_inv x := by simp [Function.comp, map.comp]
right_inv x := by simp [Function.comp, map.comp]
map_mul' := MonoidHom.map_mul _
@[to_additive (attr := simp)]
theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ :=
MulEquiv.ext map.id
@[to_additive (attr := simp)]
theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm :=
rfl
@[to_additive]
theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) :
(freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) :=
MulEquiv.ext <| map.comp _ _
end Map
section Prod
variable [Group α] (x y : FreeGroup α)
/-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the
free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/
@[to_additive "If `α` is an additive group, then any function from `α` to `α` extends uniquely to an
additive homomorphism from the additive free group over `α` to `α`."]
def prod : FreeGroup α →* α :=
lift id
variable {x y}
@[to_additive (attr := simp)]
theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) :=
rfl
@[to_additive (attr := simp)]
theorem prod.of {x : α} : prod (of x) = x :=
lift.of
@[to_additive]
theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x :=
lift.unique g hg
end Prod
@[to_additive]
theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by
rw [← lift.unique (prod.comp (map f)) (by simp), MonoidHom.coe_comp, Function.comp_apply]
section Sum
variable [AddGroup α] (x y : FreeGroup α)
/-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the
free group over `α` to `α`. This is the additive version of `Prod`. -/
def sum : α :=
@prod (Multiplicative _) _ x
variable {x y}
@[simp]
theorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) :=
rfl
@[simp]
theorem sum.of {x : α} : sum (of x) = x :=
@prod.of _ (_) _
-- note: there are no bundled homs with different notation in the domain and codomain, so we copy
-- these manually
@[simp]
theorem sum.map_mul : sum (x * y) = sum x + sum y :=
(@prod (Multiplicative _) _).map_mul _ _
@[simp]
theorem sum.map_one : sum (1 : FreeGroup α) = 0 :=
(@prod (Multiplicative _) _).map_one
@[simp]
theorem sum.map_inv : sum x⁻¹ = -sum x :=
(prod : FreeGroup (Multiplicative α) →* Multiplicative α).map_inv _
end Sum
/-- The bijection between the free group on the empty type, and a type with one element. -/
@[to_additive "The bijection between the additive free group on the empty type, and a type with one
| element."]
| Mathlib/GroupTheory/FreeGroup/Basic.lean | 818 | 818 |
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Sébastien Gouëzel
-/
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Measure.Doubling
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
/-!
# Relationship between the Haar and Lebesgue measures
We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in
`MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`.
We deduce basic properties of any Haar measure on a finite dimensional real vector space:
* `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the
absolute value of its determinant.
* `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure
of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the
determinant of `f`.
* `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the
measure of `s` multiplied by the absolute value of the determinant of `f`.
* `addHaar_submodule` : a strict submodule has measure `0`.
* `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`.
* `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_sphere`: spheres have zero measure.
This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`.
This measure is called `AlternatingMap.measure`. Its main property is
`ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned
by vectors `v₁, ..., vₙ` is given by `|ω v|`.
We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has
density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in
`tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for
small `r`, see `eventually_nonempty_inter_smul_of_density_one`.
Statements on integrals of functions with respect to an additive Haar measure can be found in
`MeasureTheory.Measure.Haar.NormedSpace`.
-/
assert_not_exists MeasureTheory.integral
open TopologicalSpace Set Filter Metric Bornology
open scoped ENNReal Pointwise Topology NNReal
/-- The interval `[0,1]` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where
carrier := Icc 0 1
isCompact' := isCompact_Icc
interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]
universe u
/-- The set `[0,1]^ι` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] :
PositiveCompacts (ι → ℝ) where
carrier := pi univ fun _ => Icc 0 1
isCompact' := isCompact_univ_pi fun _ => isCompact_Icc
interior_nonempty' := by
simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,
imp_true_iff, zero_lt_one]
/-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/
theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] :
(Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι :=
SetLike.coe_injective <| by
refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm)
· classical convert parallelepiped_single (ι := ι) 1
· exact zero_le_one
/-- A parallelepiped can be expressed on the standard basis. -/
theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E]
[NormedSpace ℝ E] (b : Basis ι ℝ E) :
b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm
b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by
classical
rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map]
congr with x
simp [Pi.single_apply]
open MeasureTheory MeasureTheory.Measure
theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F]
[NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E]
[BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F]
(b : Basis ι ℝ E) (f : E ≃L[ℝ] F) :
map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by
have : IsAddHaarMeasure (map f b.addHaar) :=
AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous
rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable
(PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map]
erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self]
namespace MeasureTheory
open Measure TopologicalSpace.PositiveCompacts Module
/-!
### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`.
-/
/-- The Haar measure equals the Lebesgue measure on `ℝ`. -/
theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by
convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01]
/-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/
theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] :
addHaarMeasure (piIcc01 ι) = volume := by
convert (addHaarMeasure_unique volume (piIcc01 ι)).symm
simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk,
Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero]
theorem isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] :
IsAddHaarMeasure (volume : Measure (ι → ℝ)) :=
inferInstance
namespace Measure
/-!
### Strict subspaces have zero measure
-/
open scoped Function -- required for scoped `on` notation
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/
theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
by_contra h
apply lt_irrefl ∞
calc
∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm
_ = ∑' n : ℕ, μ ({u n} + s) := by
congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add]
_ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by
simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's
_ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range]
_ < ∞ := (hu.add sb).measure_lt_top
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. -/
theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by
apply le_antisymm _ (zero_le _)
calc
μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by
conv_lhs => rw [← iUnion_inter_closedBall_nat s 0]
exact measure_iUnion_le _
_ = 0 := by simp only [H, tsum_zero]
intro R
apply addHaar_eq_zero_of_disjoint_translates_aux μ u
(isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall)
refine pairwise_disjoint_mono hs fun n => ?_
exact add_subset_add Subset.rfl inter_subset_left
/-- A strict vector subspace has measure zero. -/
theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E]
[BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E)
(hs : s ≠ ⊤) : μ s = 0 := by
obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by
simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs
obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩
have A : IsBounded (range fun n : ℕ => c ^ n • x) :=
have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) :=
(tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x
isBounded_range_of_tendsto _ this
apply addHaar_eq_zero_of_disjoint_translates μ _ A _
(Submodule.closed_of_finiteDimensional s).measurableSet
intro m n hmn
simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage,
SetLike.mem_coe]
intro y hym hyn
have A : (c ^ n - c ^ m) • x ∈ s := by
convert s.sub_mem hym hyn using 1
simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub]
have H : c ^ n - c ^ m ≠ 0 := by
simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti₀ cpos cone).injective.ne hmn.symm
have : x ∈ s := by
convert s.smul_mem (c ^ n - c ^ m)⁻¹ A
rw [smul_smul, inv_mul_cancel₀ H, one_smul]
exact hx this
/-- A strict affine subspace has measure zero. -/
theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
(s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by
rcases s.eq_bot_or_nonempty with (rfl | hne)
· rw [AffineSubspace.bot_coe, measure_empty]
rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs
rcases hne with ⟨x, hx : x ∈ s⟩
simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg,
image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs
/-!
### Applying a linear map rescales Haar measure by the determinant
We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue
measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real
vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a
linear equiv maps Haar measure to Haar measure.
-/
theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ}
(hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] :
Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by
cases nonempty_fintype ι
/- We have already proved the result for the Lebesgue product measure, using matrices.
We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/
have := addHaarMeasure_unique μ (piIcc01 ι)
rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul,
Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) :
Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by
-- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using
-- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`.
let ι := Fin (finrank ℝ E)
haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance
have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι]
have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this
-- next line is to avoid `g` getting reduced by `simp`.
obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩
have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e
rw [← gdet] at hf ⊢
have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by
ext x
simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp,
LinearEquiv.symm_apply_apply, hg]
simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp]
have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional
have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g
have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional
rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable]
haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm
have ecomp : e.symm ∘ e = id := by
ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply]
rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul,
map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id]
/-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s :=
calc
μ (f ⁻¹' s) = Measure.map f μ s :=
((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply
s).symm
_ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl
/-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E}
(hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s :=
addHaar_preimage_linearMap μ hf s
/-- The preimage of a set `s` under a linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by
have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero
convert addHaar_preimage_linearMap μ A s
simp only [LinearEquiv.det_coe_symm]
/-- The preimage of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s :=
addHaar_preimage_linearEquiv μ _ s
/-- The image of a set `s` under a linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by
rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf)
· let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv
change μ (g '' s) = _
rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv]
congr
· simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero]
have : μ (LinearMap.range f) = 0 :=
addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne
exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _)
/-- The image of a set `s` under a continuous linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
addHaar_image_linearMap μ _ s
/-- The image of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s
theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) :
QuasiMeasurePreserving f μ μ := by
refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]
exact smul_absolutelyContinuous
theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) :
QuasiMeasurePreserving f μ μ :=
LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf
/-!
### Basic properties of Haar measures on real vector spaces
-/
theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) :
Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by
let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E)
change Measure.map f μ = _
have hf : LinearMap.det f ≠ 0 := by
simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one]
intro h
exact hr (pow_eq_zero h)
simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one]
theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) :
QuasiMeasurePreserving (r • ·) μ μ := by
refine ⟨measurable_const_smul r, ?_⟩
rw [map_addHaar_smul μ hr]
exact smul_absolutelyContinuous
@[simp]
theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) :
μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s :=
calc
μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s :=
((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by
rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul]
/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/
@[simp]
theorem addHaar_smul (r : ℝ) (s : Set E) :
μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
rcases ne_or_eq r 0 with (h | rfl)
· rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv]
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp only [measure_empty, mul_zero, smul_set_empty]
rw [zero_smul_set hs, ← singleton_zero]
by_cases h : finrank ℝ E = 0
· haveI : Subsingleton E := finrank_zero_iff.1 h
simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs,
pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))]
· haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h)
simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff,
zero_pow, measure_singleton]
theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) :
μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by
rw [addHaar_smul, abs_pow, abs_of_nonneg hr]
variable {μ} {s : Set E}
-- Note: We might want to rename this once we acquire the lemma corresponding to
-- `MeasurableSet.const_smul`
theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) :
NullMeasurableSet (r • s) μ := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simp
obtain rfl | hr := eq_or_ne r 0
· simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _
obtain ⟨t, ht, hst⟩ := hs
refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩
rw [← measure_symmDiff_eq_zero_iff] at hst ⊢
rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero]
variable (μ)
@[simp]
theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) :
μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s :=
calc
μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by
simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
simp only [image_add_right, measure_preimage_add_right, addHaar_smul]
/-! We don't need to state `map_addHaar_neg` here, because it has already been proved for
general Haar measures on general commutative groups. -/
/-! ### Measure of balls -/
theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E]
(μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by
have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball]
rw [this, measure_preimage_add]
theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ.real (ball x r) = μ.real (ball (0 : E) r) := by
simp [measureReal_def, addHaar_ball_center]
theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (closedBall (0 : E) r) := by
have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall]
rw [this, measure_preimage_add]
theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ.real (closedBall x r) = μ.real (closedBall (0 : E) r) := by
simp [measureReal_def, addHaar_closedBall_center]
theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
have : ball (0 : E) (r * s) = r • ball (0 : E) s := by
simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow]
theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul_of_pos μ x hr, mul_one]
theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
rcases hr.eq_or_lt with (rfl | h)
· simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul,
ENNReal.ofReal_zero, ball_zero]
· exact addHaar_ball_mul_of_pos μ x h s
theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul μ x hr, mul_one]
theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow]
theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr]
simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow]
/-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball.
Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard
form. -/
theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by
rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one]
theorem addHaar_real_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (closedBall 0 1) := by
simp only [measureReal_def, addHaar_closedBall' μ x hr, ENNReal.toReal_mul, mul_eq_mul_right_iff,
ENNReal.toReal_ofReal_eq_iff]
left
positivity
theorem addHaar_unitClosedBall_eq_addHaar_unitBall :
μ (closedBall (0 : E) 1) = μ (ball 0 1) := by
apply le_antisymm _ (measure_mono ball_subset_closedBall)
have A : Tendsto
(fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall (0 : E) 1)) (𝓝[<] 1)
(𝓝 (ENNReal.ofReal ((1 : ℝ) ^ finrank ℝ E) * μ (closedBall (0 : E) 1))) := by
refine ENNReal.Tendsto.mul ?_ (by simp) tendsto_const_nhds (by simp)
exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _)
simp only [one_pow, one_mul, ENNReal.ofReal_one] at A
refine le_of_tendsto A ?_
filter_upwards [Ioo_mem_nhdsLT zero_lt_one] with r hr
rw [← addHaar_closedBall' μ (0 : E) hr.1.le]
exact measure_mono (closedBall_subset_ball hr.2)
@[deprecated (since := "2024-12-01")]
alias addHaar_closed_unit_ball_eq_addHaar_unit_ball := addHaar_unitClosedBall_eq_addHaar_unitBall
theorem addHaar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [addHaar_closedBall' μ x hr, addHaar_unitClosedBall_eq_addHaar_unitBall]
theorem addHaar_real_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (ball 0 1) := by
simp [addHaar_real_closedBall' μ x hr, measureReal_def,
addHaar_unitClosedBall_eq_addHaar_unitBall]
theorem addHaar_closedBall_eq_addHaar_ball [Nontrivial E] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (ball x r) := by
by_cases h : r < 0
· rw [Metric.closedBall_eq_empty.mpr h, Metric.ball_eq_empty.mpr h.le]
push_neg at h
rw [addHaar_closedBall μ x h, addHaar_ball μ x h]
theorem addHaar_real_closedBall_eq_addHaar_real_ball [Nontrivial E] (x : E) (r : ℝ) :
μ.real (closedBall x r) = μ.real (ball x r) := by
simp [measureReal_def, addHaar_closedBall_eq_addHaar_ball μ x r]
theorem addHaar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 := by
rcases hr.lt_or_lt with (h | h)
· simp only [empty_diff, measure_empty, ← closedBall_diff_ball, closedBall_eq_empty.2 h]
· rw [← closedBall_diff_ball,
measure_diff ball_subset_closedBall measurableSet_ball.nullMeasurableSet
measure_ball_lt_top.ne,
addHaar_ball_of_pos μ _ h, addHaar_closedBall μ _ h.le, tsub_self]
theorem addHaar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 := by
rcases eq_or_ne r 0 with (rfl | h)
· rw [sphere_zero, measure_singleton]
· exact addHaar_sphere_of_ne_zero μ x h
theorem addHaar_singleton_add_smul_div_singleton_add_smul {r : ℝ} (hr : r ≠ 0) (x y : E)
(s t : Set E) : μ ({x} + r • s) / μ ({y} + r • t) = μ s / μ t :=
calc
μ ({x} + r • s) / μ ({y} + r • t) = ENNReal.ofReal (|r| ^ finrank ℝ E) * μ s *
(ENNReal.ofReal (|r| ^ finrank ℝ E) * μ t)⁻¹ := by
simp only [div_eq_mul_inv, addHaar_smul, image_add_left, measure_preimage_add, abs_pow,
singleton_add]
_ = ENNReal.ofReal (|r| ^ finrank ℝ E) * (ENNReal.ofReal (|r| ^ finrank ℝ E))⁻¹ *
(μ s * (μ t)⁻¹) := by
rw [ENNReal.mul_inv]
· ring
· simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne, true_or]
· simp only [ENNReal.ofReal_ne_top, true_or, Ne, not_false_iff]
_ = μ s / μ t := by
rw [ENNReal.mul_inv_cancel, one_mul, div_eq_mul_inv]
· simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne]
· simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff]
instance (priority := 100) isUnifLocDoublingMeasureOfIsAddHaarMeasure :
IsUnifLocDoublingMeasure μ := by
refine ⟨⟨(2 : ℝ≥0) ^ finrank ℝ E, ?_⟩⟩
filter_upwards [self_mem_nhdsWithin] with r hr x
rw [addHaar_closedBall_mul μ x zero_le_two (le_of_lt hr), addHaar_closedBall_center μ x,
ENNReal.ofReal, Real.toNNReal_pow zero_le_two]
simp only [Real.toNNReal_ofNat, le_refl]
section
/-!
### The Lebesgue measure associated to an alternating map
-/
variable {ι G : Type*} [Fintype ι] [DecidableEq ι] [NormedAddCommGroup G] [NormedSpace ℝ G]
[MeasurableSpace G] [BorelSpace G]
theorem addHaar_parallelepiped (b : Basis ι ℝ G) (v : ι → G) :
b.addHaar (parallelepiped v) = ENNReal.ofReal |b.det v| := by
have : FiniteDimensional ℝ G := FiniteDimensional.of_fintype_basis b
have A : parallelepiped v = b.constr ℕ v '' parallelepiped b := by
rw [image_parallelepiped]
exact congr_arg _ <| funext fun i ↦ (b.constr_basis ℕ v i).symm
rw [A, addHaar_image_linearMap, b.addHaar_self, mul_one, ← LinearMap.det_toMatrix b,
← Basis.toMatrix_eq_toMatrix_constr, Basis.det_apply]
variable [FiniteDimensional ℝ G] {n : ℕ} [_i : Fact (finrank ℝ G = n)]
/-- The Lebesgue measure associated to an alternating map. It gives measure `|ω v|` to the
parallelepiped spanned by the vectors `v₁, ..., vₙ`. Note that it is not always a Haar measure,
as it can be zero, but it is always locally finite and translation invariant. -/
noncomputable irreducible_def _root_.AlternatingMap.measure (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) :
Measure G :=
‖ω (finBasisOfFinrankEq ℝ G _i.out)‖₊ • (finBasisOfFinrankEq ℝ G _i.out).addHaar
theorem _root_.AlternatingMap.measure_parallelepiped (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ)
(v : Fin n → G) : ω.measure (parallelepiped v) = ENNReal.ofReal |ω v| := by
conv_rhs => rw [ω.eq_smul_basis_det (finBasisOfFinrankEq ℝ G _i.out)]
simp only [addHaar_parallelepiped, AlternatingMap.measure, coe_nnreal_smul_apply,
AlternatingMap.smul_apply, Algebra.id.smul_eq_mul, abs_mul, ENNReal.ofReal_mul (abs_nonneg _),
← Real.enorm_eq_ofReal_abs, enorm]
instance (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) : IsAddLeftInvariant ω.measure := by
rw [AlternatingMap.measure]; infer_instance
instance (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) : IsLocallyFiniteMeasure ω.measure := by
rw [AlternatingMap.measure]; infer_instance
end
/-!
### Density points
Besicovitch covering theorem ensures that, for any locally finite measure on a finite-dimensional
real vector space, almost every point of a set `s` is a density point, i.e.,
`μ (s ∩ closedBall x r) / μ (closedBall x r)` tends to `1` as `r` tends to `0`
(see `Besicovitch.ae_tendsto_measure_inter_div`).
When `μ` is a Haar measure, one can deduce the same property for any rescaling sequence of sets,
of the form `{x} + r • t` where `t` is a set with positive finite measure, instead of the sequence
of closed balls.
We argue first for the dual property, i.e., if `s` has density `0` at `x`, then
`μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)` tends to `0`. First when `t` is contained in the ball
of radius `1`, in `tendsto_addHaar_inter_smul_zero_of_density_zero_aux1`,
(by arguing by inclusion). Then when `t` is bounded, reducing to the previous one by rescaling, in
`tendsto_addHaar_inter_smul_zero_of_density_zero_aux2`.
Then for a general set `t`, by cutting it into a bounded part and a part with small measure, in
`tendsto_addHaar_inter_smul_zero_of_density_zero`.
Going to the complement, one obtains the desired property at points of density `1`, first when
`s` is measurable in `tendsto_addHaar_inter_smul_one_of_density_one_aux`, and then without this
assumption in `tendsto_addHaar_inter_smul_one_of_density_one` by applying the previous lemma to
the measurable hull `toMeasurable μ s`
-/
theorem tendsto_addHaar_inter_smul_zero_of_density_zero_aux1 (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)
(u : Set E) (h'u : μ u ≠ 0) (t_bound : t ⊆ closedBall 0 1) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) (𝓝[>] 0) (𝓝 0) := by
have A : Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0) := by
apply
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds h
(Eventually.of_forall fun b => zero_le _)
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
rw [← affinity_unitClosedBall rpos.le, singleton_add, ← image_vadd]
gcongr
have B :
Tendsto (fun r : ℝ => μ (closedBall x r) / μ ({x} + r • u)) (𝓝[>] 0)
(𝓝 (μ (closedBall x 1) / μ ({x} + u))) := by
apply tendsto_const_nhds.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
have : closedBall x r = {x} + r • closedBall (0 : E) 1 := by
simp only [_root_.smul_closedBall, Real.norm_of_nonneg rpos.le, zero_le_one, add_zero,
mul_one, singleton_add_closedBall, smul_zero]
simp only [this, addHaar_singleton_add_smul_div_singleton_add_smul μ rpos.ne']
simp only [addHaar_closedBall_center, image_add_left, measure_preimage_add, singleton_add]
have C : Tendsto (fun r : ℝ =>
μ (s ∩ ({x} + r • t)) / μ (closedBall x r) * (μ (closedBall x r) / μ ({x} + r • u)))
(𝓝[>] 0) (𝓝 (0 * (μ (closedBall x 1) / μ ({x} + u)))) := by
apply ENNReal.Tendsto.mul A _ B (Or.inr ENNReal.zero_ne_top)
simp [ENNReal.div_eq_top, h'u, measure_closedBall_lt_top.ne]
simp only [zero_mul] at C
apply C.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
calc
μ (s ∩ ({x} + r • t)) / μ (closedBall x r) * (μ (closedBall x r) / μ ({x} + r • u)) =
μ (closedBall x r) * (μ (closedBall x r))⁻¹ * (μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) :=
by simp only [div_eq_mul_inv]; ring
_ = μ (s ∩ ({x} + r • t)) / μ ({x} + r • u) := by
rw [ENNReal.mul_inv_cancel (measure_closedBall_pos μ x rpos).ne'
measure_closedBall_lt_top.ne,
one_mul]
theorem tendsto_addHaar_inter_smul_zero_of_density_zero_aux2 (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)
(u : Set E) (h'u : μ u ≠ 0) (R : ℝ) (Rpos : 0 < R) (t_bound : t ⊆ closedBall 0 R) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • u)) (𝓝[>] 0) (𝓝 0) := by
set t' := R⁻¹ • t with ht'
set u' := R⁻¹ • u with hu'
have A : Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t')) / μ ({x} + r • u')) (𝓝[>] 0) (𝓝 0) := by
apply tendsto_addHaar_inter_smul_zero_of_density_zero_aux1 μ s x h t' u'
· simp only [u', h'u, (pow_pos Rpos _).ne', abs_nonpos_iff, addHaar_smul, not_false_iff,
ENNReal.ofReal_eq_zero, inv_eq_zero, inv_pow, Ne, or_self_iff, mul_eq_zero]
· refine (smul_set_mono t_bound).trans_eq ?_
rw [smul_closedBall _ _ Rpos.le, smul_zero, Real.norm_of_nonneg (inv_nonneg.2 Rpos.le),
inv_mul_cancel₀ Rpos.ne']
have B : Tendsto (fun r : ℝ => R * r) (𝓝[>] 0) (𝓝[>] (R * 0)) := by
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
· exact (tendsto_const_nhds.mul tendsto_id).mono_left nhdsWithin_le_nhds
· filter_upwards [self_mem_nhdsWithin]
intro r rpos
rw [mul_zero]
exact mul_pos Rpos rpos
rw [mul_zero] at B
apply (A.comp B).congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r -
have T : (R * r) • t' = r • t := by
rw [mul_comm, ht', smul_smul, mul_assoc, mul_inv_cancel₀ Rpos.ne', mul_one]
have U : (R * r) • u' = r • u := by
rw [mul_comm, hu', smul_smul, mul_assoc, mul_inv_cancel₀ Rpos.ne', mul_one]
dsimp
rw [T, U]
/-- Consider a point `x` at which a set `s` has density zero, with respect to closed balls. Then it
also has density zero with respect to any measurable set `t`: the proportion of points in `s`
belonging to a rescaled copy `{x} + r • t` of `t` tends to zero as `r` tends to zero. -/
theorem tendsto_addHaar_inter_smul_zero_of_density_zero (s : Set E) (x : E)
(h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0)) (t : Set E)
(ht : MeasurableSet t) (h''t : μ t ≠ ∞) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 0) := by
refine tendsto_order.2 ⟨fun a' ha' => (ENNReal.not_lt_zero ha').elim, fun ε (εpos : 0 < ε) => ?_⟩
rcases eq_or_ne (μ t) 0 with (h't | h't)
· filter_upwards with r
suffices H : μ (s ∩ ({x} + r • t)) = 0 by
rw [H]; simpa only [ENNReal.zero_div] using εpos
apply le_antisymm _ (zero_le _)
calc
μ (s ∩ ({x} + r • t)) ≤ μ ({x} + r • t) := measure_mono inter_subset_right
_ = 0 := by
simp only [h't, addHaar_smul, image_add_left, measure_preimage_add, singleton_add,
mul_zero]
obtain ⟨n, npos, hn⟩ : ∃ n : ℕ, 0 < n ∧ μ (t \ closedBall 0 n) < ε / 2 * μ t := by
have A :
Tendsto (fun n : ℕ => μ (t \ closedBall 0 n)) atTop
(𝓝 (μ (⋂ n : ℕ, t \ closedBall 0 n))) := by
have N : ∃ n : ℕ, μ (t \ closedBall 0 n) ≠ ∞ :=
⟨0, ((measure_mono diff_subset).trans_lt h''t.lt_top).ne⟩
refine tendsto_measure_iInter_atTop
(fun n ↦ (ht.diff measurableSet_closedBall).nullMeasurableSet) (fun m n hmn ↦ ?_) N
exact diff_subset_diff Subset.rfl (closedBall_subset_closedBall (Nat.cast_le.2 hmn))
have : ⋂ n : ℕ, t \ closedBall 0 n = ∅ := by
simp_rw [diff_eq, ← inter_iInter, iInter_eq_compl_iUnion_compl, compl_compl,
iUnion_closedBall_nat, compl_univ, inter_empty]
simp only [this, measure_empty] at A
| have I : 0 < ε / 2 * μ t := ENNReal.mul_pos (ENNReal.half_pos εpos.ne').ne' h't
exact (Eventually.and (Ioi_mem_atTop 0) ((tendsto_order.1 A).2 _ I)).exists
have L :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) / μ ({x} + r • t)) (𝓝[>] 0)
(𝓝 0) :=
tendsto_addHaar_inter_smul_zero_of_density_zero_aux2 μ s x h _ t h't n (Nat.cast_pos.2 npos)
inter_subset_right
filter_upwards [(tendsto_order.1 L).2 _ (ENNReal.half_pos εpos.ne'), self_mem_nhdsWithin]
rintro r hr (rpos : 0 < r)
have I :
μ (s ∩ ({x} + r • t)) ≤
μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ ({x} + r • (t \ closedBall 0 n)) :=
calc
μ (s ∩ ({x} + r • t)) =
μ (s ∩ ({x} + r • (t ∩ closedBall 0 n)) ∪ s ∩ ({x} + r • (t \ closedBall 0 n))) := by
rw [← inter_union_distrib_left, ← add_union, ← smul_set_union, inter_union_diff]
_ ≤ μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ (s ∩ ({x} + r • (t \ closedBall 0 n))) :=
measure_union_le _ _
_ ≤ μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ ({x} + r • (t \ closedBall 0 n)) := by
gcongr; apply inter_subset_right
calc
μ (s ∩ ({x} + r • t)) / μ ({x} + r • t) ≤
(μ (s ∩ ({x} + r • (t ∩ closedBall 0 n))) + μ ({x} + r • (t \ closedBall 0 n))) /
μ ({x} + r • t) := by gcongr
_ < ε / 2 + ε / 2 := by
rw [ENNReal.add_div]
apply ENNReal.add_lt_add hr _
rwa [addHaar_singleton_add_smul_div_singleton_add_smul μ rpos.ne',
ENNReal.div_lt_iff (Or.inl h't) (Or.inl h''t)]
_ = ε := ENNReal.add_halves _
theorem tendsto_addHaar_inter_smul_one_of_density_one_aux (s : Set E) (hs : MeasurableSet s)
(x : E) (h : Tendsto (fun r => μ (s ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1))
(t : Set E) (ht : MeasurableSet t) (h't : μ t ≠ 0) (h''t : μ t ≠ ∞) :
Tendsto (fun r : ℝ => μ (s ∩ ({x} + r • t)) / μ ({x} + r • t)) (𝓝[>] 0) (𝓝 1) := by
have I : ∀ u v, μ u ≠ 0 → μ u ≠ ∞ → MeasurableSet v →
μ u / μ u - μ (vᶜ ∩ u) / μ u = μ (v ∩ u) / μ u := by
intro u v uzero utop vmeas
simp_rw [div_eq_mul_inv]
rw [← ENNReal.sub_mul]; swap
· simp only [uzero, ENNReal.inv_eq_top, imp_true_iff, Ne, not_false_iff]
congr 1
rw [inter_comm _ u, inter_comm _ u, eq_comm]
exact ENNReal.eq_sub_of_add_eq' utop (measure_inter_add_diff u vmeas)
have L : Tendsto (fun r => μ (sᶜ ∩ closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 0) := by
have A : Tendsto (fun r => μ (closedBall x r) / μ (closedBall x r)) (𝓝[>] 0) (𝓝 1) := by
apply tendsto_const_nhds.congr' _
filter_upwards [self_mem_nhdsWithin]
intro r hr
rw [div_eq_mul_inv, ENNReal.mul_inv_cancel]
· exact (measure_closedBall_pos μ _ hr).ne'
· exact measure_closedBall_lt_top.ne
have B := ENNReal.Tendsto.sub A h (Or.inl ENNReal.one_ne_top)
simp only [tsub_self] at B
apply B.congr' _
filter_upwards [self_mem_nhdsWithin]
rintro r (rpos : 0 < r)
| Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean | 726 | 782 |
/-
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.SmoothSeries
import Mathlib.Analysis.Calculus.BumpFunction.InnerProduct
import Mathlib.Analysis.Convolution
import Mathlib.Analysis.InnerProductSpace.EuclideanDist
import Mathlib.Data.Set.Pointwise.Support
import Mathlib.MeasureTheory.Measure.Haar.NormedSpace
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Bump functions in finite-dimensional vector spaces
Let `E` be a finite-dimensional real normed vector space. We show that any open set `s` in `E` is
exactly the support of a smooth function taking values in `[0, 1]`,
in `IsOpen.exists_smooth_support_eq`.
Then we use this construction to construct bump functions with nice behavior, by convolving
the indicator function of `closedBall 0 1` with a function as above with `s = ball 0 D`.
-/
noncomputable section
open Set Metric TopologicalSpace Function Asymptotics MeasureTheory Module
ContinuousLinearMap Filter MeasureTheory.Measure Bornology
open scoped Pointwise Topology NNReal Convolution ContDiff
variable {E : Type*} [NormedAddCommGroup E]
section
variable [NormedSpace ℝ E] [FiniteDimensional ℝ E]
/-- If a set `s` is a neighborhood of `x`, then there exists a smooth function `f` taking
values in `[0, 1]`, supported in `s` and with `f x = 1`. -/
theorem exists_smooth_tsupport_subset {s : Set E} {x : E} (hs : s ∈ 𝓝 x) :
∃ f : E → ℝ,
tsupport f ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ∞ f ∧ range f ⊆ Icc 0 1 ∧ f x = 1 := by
obtain ⟨d : ℝ, d_pos : 0 < d, hd : Euclidean.closedBall x d ⊆ s⟩ :=
Euclidean.nhds_basis_closedBall.mem_iff.1 hs
let c : ContDiffBump (toEuclidean x) :=
{ rIn := d / 2
rOut := d
rIn_pos := half_pos d_pos
rIn_lt_rOut := half_lt_self d_pos }
let f : E → ℝ := c ∘ toEuclidean
have f_supp : f.support ⊆ Euclidean.ball x d := by
intro y hy
have : toEuclidean y ∈ Function.support c := by
simpa only [Function.mem_support, Function.comp_apply, Ne] using hy
rwa [c.support_eq] at this
have f_tsupp : tsupport f ⊆ Euclidean.closedBall x d := by
rw [tsupport, ← Euclidean.closure_ball _ d_pos.ne']
exact closure_mono f_supp
refine ⟨f, f_tsupp.trans hd, ?_, ?_, ?_, ?_⟩
· refine isCompact_of_isClosed_isBounded isClosed_closure ?_
have : IsBounded (Euclidean.closedBall x d) := Euclidean.isCompact_closedBall.isBounded
refine this.subset (Euclidean.isClosed_closedBall.closure_subset_iff.2 ?_)
exact f_supp.trans Euclidean.ball_subset_closedBall
· apply c.contDiff.comp
exact ContinuousLinearEquiv.contDiff _
· rintro t ⟨y, rfl⟩
exact ⟨c.nonneg, c.le_one⟩
· apply c.one_of_mem_closedBall
apply mem_closedBall_self
exact (half_pos d_pos).le
/-- Given an open set `s` in a finite-dimensional real normed vector space, there exists a smooth
function with values in `[0, 1]` whose support is exactly `s`. -/
theorem IsOpen.exists_smooth_support_eq {s : Set E} (hs : IsOpen s) :
∃ f : E → ℝ, f.support = s ∧ ContDiff ℝ ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := by
/- For any given point `x` in `s`, one can construct a smooth function with support in `s` and
nonzero at `x`. By second-countability, it follows that we may cover `s` with the supports of
countably many such functions, say `g i`.
Then `∑ i, r i • g i` will be the desired function if `r i` is a sequence of positive numbers
tending quickly enough to zero. Indeed, this ensures that, for any `k ≤ i`, the `k`-th
derivative of `r i • g i` is bounded by a prescribed (summable) sequence `u i`. From this, the
summability of the series and of its successive derivatives follows. -/
rcases eq_empty_or_nonempty s with (rfl | h's)
· exact
⟨fun _ => 0, Function.support_zero, contDiff_const, by
simp only [range_const, singleton_subset_iff, left_mem_Icc, zero_le_one]⟩
let ι := { f : E → ℝ // f.support ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ∞ f ∧ range f ⊆ Icc 0 1 }
obtain ⟨T, T_count, hT⟩ : ∃ T : Set ι, T.Countable ∧ ⋃ f ∈ T, support (f : E → ℝ) = s := by
have : ⋃ f : ι, (f : E → ℝ).support = s := by
refine Subset.antisymm (iUnion_subset fun f => f.2.1) ?_
intro x hx
rcases exists_smooth_tsupport_subset (hs.mem_nhds hx) with ⟨f, hf⟩
let g : ι := ⟨f, (subset_tsupport f).trans hf.1, hf.2.1, hf.2.2.1, hf.2.2.2.1⟩
have : x ∈ support (g : E → ℝ) := by
simp only [g, hf.2.2.2.2, Subtype.coe_mk, mem_support, Ne, one_ne_zero,
not_false_iff]
exact mem_iUnion_of_mem _ this
simp_rw [← this]
apply isOpen_iUnion_countable
rintro ⟨f, hf⟩
exact hf.2.2.1.continuous.isOpen_support
obtain ⟨g0, hg⟩ : ∃ g0 : ℕ → ι, T = range g0 := by
apply Countable.exists_eq_range T_count
rcases eq_empty_or_nonempty T with (rfl | hT)
· simp only [ι, iUnion_false, iUnion_empty] at hT
simp only [← hT, mem_empty_iff_false, iUnion_of_empty, iUnion_empty, Set.not_nonempty_empty]
at h's
· exact hT
let g : ℕ → E → ℝ := fun n => (g0 n).1
have g_s : ∀ n, support (g n) ⊆ s := fun n => (g0 n).2.1
have s_g : ∀ x ∈ s, ∃ n, x ∈ support (g n) := fun x hx ↦ by
rw [← hT] at hx
obtain ⟨i, iT, hi⟩ : ∃ i ∈ T, x ∈ support (i : E → ℝ) := by
simpa only [mem_iUnion, exists_prop] using hx
rw [hg, mem_range] at iT
rcases iT with ⟨n, hn⟩
rw [← hn] at hi
exact ⟨n, hi⟩
have g_smooth : ∀ n, ContDiff ℝ ∞ (g n) := fun n => (g0 n).2.2.2.1
have g_comp_supp : ∀ n, HasCompactSupport (g n) := fun n => (g0 n).2.2.1
have g_nonneg : ∀ n x, 0 ≤ g n x := fun n x => ((g0 n).2.2.2.2 (mem_range_self x)).1
obtain ⟨δ, δpos, c, δc, c_lt⟩ :
∃ δ : ℕ → ℝ≥0, (∀ i : ℕ, 0 < δ i) ∧ ∃ c : NNReal, HasSum δ c ∧ c < 1 :=
NNReal.exists_pos_sum_of_countable one_ne_zero ℕ
have : ∀ n : ℕ, ∃ r : ℝ, 0 < r ∧ ∀ i ≤ n, ∀ x, ‖iteratedFDeriv ℝ i (r • g n) x‖ ≤ δ n := by
intro n
have : ∀ i, ∃ R, ∀ x, ‖iteratedFDeriv ℝ i (fun x => g n x) x‖ ≤ R := by
intro i
have : BddAbove (range fun x => ‖iteratedFDeriv ℝ i (fun x : E => g n x) x‖) := by
apply ((g_smooth n).continuous_iteratedFDeriv
(mod_cast le_top)).norm.bddAbove_range_of_hasCompactSupport
apply HasCompactSupport.comp_left _ norm_zero
apply (g_comp_supp n).iteratedFDeriv
rcases this with ⟨R, hR⟩
exact ⟨R, fun x => hR (mem_range_self _)⟩
choose R hR using this
let M := max (((Finset.range (n + 1)).image R).max' (by simp)) 1
have δnpos : 0 < δ n := δpos n
have IR : ∀ i ≤ n, R i ≤ M := by
intro i hi
refine le_trans ?_ (le_max_left _ _)
apply Finset.le_max'
apply Finset.mem_image_of_mem
simp only [Finset.mem_range]
omega
refine ⟨M⁻¹ * δ n, by positivity, fun i hi x => ?_⟩
calc
‖iteratedFDeriv ℝ i ((M⁻¹ * δ n) • g n) x‖ = ‖(M⁻¹ * δ n) • iteratedFDeriv ℝ i (g n) x‖ := by
rw [iteratedFDeriv_const_smul_apply]
exact (g_smooth n).contDiffAt.of_le (mod_cast le_top)
_ = M⁻¹ * δ n * ‖iteratedFDeriv ℝ i (g n) x‖ := by
rw [norm_smul _ (iteratedFDeriv ℝ i (g n) x), Real.norm_of_nonneg]; positivity
_ ≤ M⁻¹ * δ n * M := by gcongr; exact (hR i x).trans (IR i hi)
_ = δ n := by field_simp
choose r rpos hr using this
have S : ∀ x, Summable fun n => (r n • g n) x := fun x ↦ by
refine .of_nnnorm_bounded _ δc.summable fun n => ?_
rw [← NNReal.coe_le_coe, coe_nnnorm]
simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) x
refine ⟨fun x => ∑' n, (r n • g n) x, ?_, ?_, ?_⟩
· apply Subset.antisymm
· intro x hx
simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, mem_support, Ne] at hx
contrapose! hx
have : ∀ n, g n x = 0 := by
intro n
contrapose! hx
exact g_s n hx
simp only [this, mul_zero, tsum_zero]
· intro x hx
obtain ⟨n, hn⟩ : ∃ n, x ∈ support (g n) := s_g x hx
have I : 0 < r n * g n x := mul_pos (rpos n) (lt_of_le_of_ne (g_nonneg n x) (Ne.symm hn))
exact ne_of_gt ((S x).tsum_pos (fun i => mul_nonneg (rpos i).le (g_nonneg i x)) n I)
· refine
contDiff_tsum_of_eventually (fun n => (g_smooth n).const_smul (r n))
(fun k _ => (NNReal.hasSum_coe.2 δc).summable) ?_
intro i _
simp only [Nat.cofinite_eq_atTop, Pi.smul_apply, Algebra.id.smul_eq_mul,
Filter.eventually_atTop]
exact ⟨i, fun n hn x => hr _ _ hn _⟩
· rintro - ⟨y, rfl⟩
refine ⟨tsum_nonneg fun n => mul_nonneg (rpos n).le (g_nonneg n y), le_trans ?_ c_lt.le⟩
have A : HasSum (fun n => (δ n : ℝ)) c := NNReal.hasSum_coe.2 δc
simp only [Pi.smul_apply, smul_eq_mul, NNReal.val_eq_coe, ← A.tsum_eq]
apply Summable.tsum_le_tsum _ (S y) A.summable
intro n
apply (le_abs_self _).trans
simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) y
end
section
namespace ExistsContDiffBumpBase
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces.
It is the characteristic function of the closed unit ball. -/
def φ : E → ℝ :=
(closedBall (0 : E) 1).indicator fun _ => (1 : ℝ)
variable [NormedSpace ℝ E] [FiniteDimensional ℝ E]
section HelperDefinitions
variable (E)
theorem u_exists :
∃ u : E → ℝ,
ContDiff ℝ ∞ u ∧ (∀ x, u x ∈ Icc (0 : ℝ) 1) ∧ support u = ball 0 1 ∧ ∀ x, u (-x) = u x := by
have A : IsOpen (ball (0 : E) 1) := isOpen_ball
obtain ⟨f, f_support, f_smooth, f_range⟩ :
∃ f : E → ℝ, f.support = ball (0 : E) 1 ∧ ContDiff ℝ ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 :=
A.exists_smooth_support_eq
have B : ∀ x, f x ∈ Icc (0 : ℝ) 1 := fun x => f_range (mem_range_self x)
refine ⟨fun x => (f x + f (-x)) / 2, ?_, ?_, ?_, ?_⟩
· exact (f_smooth.add (f_smooth.comp contDiff_neg)).div_const _
· intro x
simp only [mem_Icc]
constructor
· linarith [(B x).1, (B (-x)).1]
· linarith [(B x).2, (B (-x)).2]
· refine support_eq_iff.2 ⟨fun x hx => ?_, fun x hx => ?_⟩
· apply ne_of_gt
have : 0 < f x := by
apply lt_of_le_of_ne (B x).1 (Ne.symm _)
rwa [← f_support] at hx
linarith [(B (-x)).1]
· have I1 : x ∉ support f := by rwa [f_support]
have I2 : -x ∉ support f := by
rw [f_support]
simpa using hx
simp only [mem_support, Classical.not_not] at I1 I2
simp only [I1, I2, add_zero, zero_div]
· intro x; simp only [add_comm, neg_neg]
variable {E} in
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces,
which is smooth, symmetric, and with support equal to the unit ball. -/
def u (x : E) : ℝ :=
Classical.choose (u_exists E) x
theorem u_smooth : ContDiff ℝ ∞ (u : E → ℝ) :=
(Classical.choose_spec (u_exists E)).1
theorem u_continuous : Continuous (u : E → ℝ) :=
(u_smooth E).continuous
theorem u_support : support (u : E → ℝ) = ball 0 1 :=
(Classical.choose_spec (u_exists E)).2.2.1
theorem u_compact_support : HasCompactSupport (u : E → ℝ) := by
rw [hasCompactSupport_def, u_support, closure_ball (0 : E) one_ne_zero]
exact isCompact_closedBall _ _
variable {E}
theorem u_nonneg (x : E) : 0 ≤ u x :=
((Classical.choose_spec (u_exists E)).2.1 x).1
theorem u_le_one (x : E) : u x ≤ 1 :=
((Classical.choose_spec (u_exists E)).2.1 x).2
theorem u_neg (x : E) : u (-x) = u x :=
(Classical.choose_spec (u_exists E)).2.2.2 x
variable [MeasurableSpace E] [BorelSpace E]
local notation "μ" => MeasureTheory.Measure.addHaar
variable (E) in
theorem u_int_pos : 0 < ∫ x : E, u x ∂μ := by
refine (integral_pos_iff_support_of_nonneg u_nonneg ?_).mpr ?_
· exact (u_continuous E).integrable_of_hasCompactSupport (u_compact_support E)
· rw [u_support]; exact measure_ball_pos _ _ zero_lt_one
/-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces,
which is smooth, symmetric, with support equal to the ball of radius `D` and integral `1`. -/
def w (D : ℝ) (x : E) : ℝ :=
((∫ x : E, u x ∂μ) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x)
theorem w_def (D : ℝ) :
(w D : E → ℝ) = fun x => ((∫ x : E, u x ∂μ) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x) := by
ext1 x; rfl
theorem w_nonneg (D : ℝ) (x : E) : 0 ≤ w D x := by
apply mul_nonneg _ (u_nonneg _)
apply inv_nonneg.2
apply mul_nonneg (u_int_pos E).le
norm_cast
apply pow_nonneg (abs_nonneg D)
theorem w_mul_φ_nonneg (D : ℝ) (x y : E) : 0 ≤ w D y * φ (x - y) :=
mul_nonneg (w_nonneg D y) (indicator_nonneg (by simp only [zero_le_one, imp_true_iff]) _)
variable (E)
theorem w_integral {D : ℝ} (Dpos : 0 < D) : ∫ x : E, w D x ∂μ = 1 := by
simp_rw [w, integral_smul]
rw [integral_comp_inv_smul_of_nonneg μ (u : E → ℝ) Dpos.le, abs_of_nonneg Dpos.le, mul_comm]
field_simp [(u_int_pos E).ne']
theorem w_support {D : ℝ} (Dpos : 0 < D) : support (w D : E → ℝ) = ball 0 D := by
have B : D • ball (0 : E) 1 = ball 0 D := by
rw [smul_unitBall Dpos.ne', Real.norm_of_nonneg Dpos.le]
have C : D ^ finrank ℝ E ≠ 0 := by
norm_cast
exact pow_ne_zero _ Dpos.ne'
simp only [w_def, Algebra.id.smul_eq_mul, support_mul, support_inv, univ_inter,
support_comp_inv_smul₀ Dpos.ne', u_support, B, support_const (u_int_pos E).ne', support_const C,
abs_of_nonneg Dpos.le]
theorem w_compact_support {D : ℝ} (Dpos : 0 < D) : HasCompactSupport (w D : E → ℝ) := by
rw [hasCompactSupport_def, w_support E Dpos, closure_ball (0 : E) Dpos.ne']
exact isCompact_closedBall _ _
variable {E}
| /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces.
It is the convolution between a smooth function of integral `1` supported in the ball of radius `D`,
| Mathlib/Analysis/Calculus/BumpFunction/FiniteDimension.lean | 319 | 320 |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Geometry.RingedSpace.PresheafedSpace.Gluing
import Mathlib.AlgebraicGeometry.Cover.Open
/-!
# Gluing Schemes
Given a family of gluing data of schemes, we may glue them together.
## Main definitions
* `AlgebraicGeometry.Scheme.GlueData`: A structure containing the family of gluing data.
* `AlgebraicGeometry.Scheme.GlueData.glued`: The glued scheme.
This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API
can be used.
* `AlgebraicGeometry.Scheme.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`.
* `AlgebraicGeometry.Scheme.GlueData.isoCarrier`: The isomorphism between the underlying space
of the glued scheme and the gluing of the underlying topological spaces.
* `AlgebraicGeometry.Scheme.OpenCover.gluedCover`: The glue data associated with an open cover.
* `AlgebraicGeometry.Scheme.OpenCover.fromGlued`: The canonical morphism
`𝒰.gluedCover.glued ⟶ X`. This has an `is_iso` instance.
* `AlgebraicGeometry.Scheme.OpenCover.glueMorphisms`: We may glue a family of compatible
morphisms defined on an open cover of a scheme.
## Main results
* `AlgebraicGeometry.Scheme.GlueData.ι_isOpenImmersion`: The map `ι i : U i ⟶ glued`
is an open immersion for each `i : J`.
* `AlgebraicGeometry.Scheme.GlueData.ι_jointly_surjective` : The underlying maps of
`ι i : U i ⟶ glued` are jointly surjective.
* `AlgebraicGeometry.Scheme.GlueData.vPullbackConeIsLimit` : `V i j` is the pullback
(intersection) of `U i` and `U j` over the glued space.
* `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff` : `ι i x = ι j y` if and only if they coincide
when restricted to `V i i`.
* `AlgebraicGeometry.Scheme.GlueData.isOpen_iff` : A subset of the glued scheme is open iff
all its preimages in `U i` are open.
## Implementation details
All the hard work is done in `AlgebraicGeometry/PresheafedSpace/Gluing.lean` where we glue
presheafed spaces, sheafed spaces, and locally ringed spaces.
-/
noncomputable section
universe u
open TopologicalSpace CategoryTheory Opposite Topology
open CategoryTheory.Limits AlgebraicGeometry.PresheafedSpace
open CategoryTheory.GlueData
namespace AlgebraicGeometry
namespace Scheme
/-- A family of gluing data consists of
1. An index type `J`
2. A scheme `U i` for each `i : J`.
3. A scheme `V i j` for each `i j : J`.
(Note that this is `J × J → Scheme` rather than `J → J → Scheme` to connect to the
limits library easier.)
4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`.
5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`.
such that
6. `f i i` is an isomorphism.
7. `t i i` is the identity.
8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some
`t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`.
9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`.
We can then glue the schemes `U i` together by identifying `V i j` with `V j i`, such
that the `U i`'s are open subschemes of the glued space.
-/
structure GlueData extends CategoryTheory.GlueData Scheme where
f_open : ∀ i j, IsOpenImmersion (f i j)
attribute [instance] GlueData.f_open
namespace GlueData
variable (D : GlueData.{u})
local notation "𝖣" => D.toGlueData
/-- The glue data of locally ringed spaces associated to a family of glue data of schemes. -/
abbrev toLocallyRingedSpaceGlueData : LocallyRingedSpace.GlueData :=
{ f_open := D.f_open
toGlueData := 𝖣.mapGlueData forgetToLocallyRingedSpace }
instance (i j : 𝖣.J) :
LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.f i j) := by
apply GlueData.f_open
instance (i j : 𝖣.J) :
SheafedSpace.IsOpenImmersion
(D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toGlueData.f i j) := by
apply GlueData.f_open
instance (i j : 𝖣.J) :
PresheafedSpace.IsOpenImmersion
(D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toGlueData.f
i j) := by
apply GlueData.f_open
instance (i : 𝖣.J) :
LocallyRingedSpace.IsOpenImmersion ((D.toLocallyRingedSpaceGlueData).toGlueData.ι i) := by
apply LocallyRingedSpace.GlueData.ι_isOpenImmersion
/-- (Implementation). The glued scheme of a glue data.
This should not be used outside this file. Use `AlgebraicGeometry.Scheme.GlueData.glued` instead. -/
def gluedScheme : Scheme := by
apply LocallyRingedSpace.IsOpenImmersion.scheme
D.toLocallyRingedSpaceGlueData.toGlueData.glued
intro x
obtain ⟨i, y, rfl⟩ := D.toLocallyRingedSpaceGlueData.ι_jointly_surjective x
refine ⟨_, ((D.U i).affineCover.map y).toLRSHom ≫
D.toLocallyRingedSpaceGlueData.toGlueData.ι i, ?_⟩
constructor
· simp only [LocallyRingedSpace.comp_toShHom, SheafedSpace.comp_base, TopCat.hom_comp,
ContinuousMap.coe_comp, Set.range_comp]
refine Set.mem_image_of_mem _ ?_
exact (D.U i).affineCover.covers y
· infer_instance
instance : CreatesColimit 𝖣.diagram.multispan forgetToLocallyRingedSpace :=
createsColimitOfFullyFaithfulOfIso D.gluedScheme
(HasColimit.isoOfNatIso (𝖣.diagramIso forgetToLocallyRingedSpace).symm)
instance : PreservesColimit (𝖣.diagram.multispan) forgetToTop :=
inferInstanceAs (PreservesColimit (𝖣.diagram).multispan (forgetToLocallyRingedSpace ⋙
LocallyRingedSpace.forgetToSheafedSpace ⋙ SheafedSpace.forget CommRingCat))
instance : HasMulticoequalizer 𝖣.diagram :=
hasColimit_of_created _ forgetToLocallyRingedSpace
/-- The glued scheme of a glued space. -/
abbrev glued : Scheme :=
𝖣.glued
/-- The immersion from `D.U i` into the glued space. -/
abbrev ι (i : D.J) : D.U i ⟶ D.glued :=
𝖣.ι i
/-- The gluing as sheafed spaces is isomorphic to the gluing as presheafed spaces. -/
abbrev isoLocallyRingedSpace :
D.glued.toLocallyRingedSpace ≅ D.toLocallyRingedSpaceGlueData.toGlueData.glued :=
𝖣.gluedIso forgetToLocallyRingedSpace
theorem ι_isoLocallyRingedSpace_inv (i : D.J) :
D.toLocallyRingedSpaceGlueData.toGlueData.ι i ≫
D.isoLocallyRingedSpace.inv = (𝖣.ι i).toLRSHom :=
𝖣.ι_gluedIso_inv forgetToLocallyRingedSpace i
instance ι_isOpenImmersion (i : D.J) : IsOpenImmersion (𝖣.ι i) := by
rw [IsOpenImmersion, ← D.ι_isoLocallyRingedSpace_inv]; infer_instance
theorem ι_jointly_surjective (x : 𝖣.glued.carrier) :
∃ (i : D.J) (y : (D.U i).carrier), (D.ι i).base y = x :=
𝖣.ι_jointly_surjective (forgetToTop ⋙ forget TopCat) x
/-- Promoted to higher priority to short circuit simplifier. -/
@[simp (high), reassoc]
theorem glue_condition (i j : D.J) : D.t i j ≫ D.f j i ≫ D.ι j = D.f i j ≫ D.ι i :=
𝖣.glue_condition i j
/-- The pullback cone spanned by `V i j ⟶ U i` and `V i j ⟶ U j`.
This is a pullback diagram (`vPullbackConeIsLimit`). -/
def vPullbackCone (i j : D.J) : PullbackCone (D.ι i) (D.ι j) :=
PullbackCone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp)
/-- The following diagram is a pullback, i.e. `Vᵢⱼ` is the intersection of `Uᵢ` and `Uⱼ` in `X`.
```
Vᵢⱼ ⟶ Uᵢ
| |
↓ ↓
Uⱼ ⟶ X
```
-/
def vPullbackConeIsLimit (i j : D.J) : IsLimit (D.vPullbackCone i j) :=
𝖣.vPullbackConeIsLimitOfMap forgetToLocallyRingedSpace i j
(D.toLocallyRingedSpaceGlueData.vPullbackConeIsLimit _ _)
local notation "D_" => TopCat.GlueData.toGlueData <|
D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData
/-- The underlying topological space of the glued scheme is isomorphic to the gluing of the
underlying spaces -/
def isoCarrier :
D.glued.carrier ≅ (D_).glued := by
refine (PresheafedSpace.forget _).mapIso ?_ ≪≫
GlueData.gluedIso _ (PresheafedSpace.forget.{_, _, u} _)
refine SheafedSpace.forgetToPresheafedSpace.mapIso ?_ ≪≫
SheafedSpace.GlueData.isoPresheafedSpace _
refine LocallyRingedSpace.forgetToSheafedSpace.mapIso ?_ ≪≫
LocallyRingedSpace.GlueData.isoSheafedSpace _
exact Scheme.GlueData.isoLocallyRingedSpace _
@[simp]
theorem ι_isoCarrier_inv (i : D.J) :
(D_).ι i ≫ D.isoCarrier.inv = (D.ι i).base := by
delta isoCarrier
rw [Iso.trans_inv, GlueData.ι_gluedIso_inv_assoc, Functor.mapIso_inv, Iso.trans_inv,
Functor.mapIso_inv, Iso.trans_inv, SheafedSpace.forgetToPresheafedSpace_map, forget_map,
forget_map, ← PresheafedSpace.comp_base, ← Category.assoc,
D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.ι_isoPresheafedSpace_inv i]
erw [← Category.assoc, D.toLocallyRingedSpaceGlueData.ι_isoSheafedSpace_inv i]
change (_ ≫ D.isoLocallyRingedSpace.inv).base = _
rw [D.ι_isoLocallyRingedSpace_inv i]
/-- An equivalence relation on `Σ i, D.U i` that holds iff `𝖣.ι i x = 𝖣.ι j y`.
See `AlgebraicGeometry.Scheme.GlueData.ι_eq_iff`. -/
def Rel (a b : Σ i, ((D.U i).carrier : Type _)) : Prop :=
∃ x : (D.V (a.1, b.1)).carrier, (D.f _ _).base x = a.2 ∧ (D.t _ _ ≫ D.f _ _).base x = b.2
theorem ι_eq_iff (i j : D.J) (x : (D.U i).carrier) (y : (D.U j).carrier) :
(𝖣.ι i).base x = (𝖣.ι j).base y ↔ D.Rel ⟨i, x⟩ ⟨j, y⟩ := by
refine Iff.trans ?_
(TopCat.GlueData.ι_eq_iff_rel
D.toLocallyRingedSpaceGlueData.toSheafedSpaceGlueData.toPresheafedSpaceGlueData.toTopGlueData
i j x y)
rw [← ((TopCat.mono_iff_injective D.isoCarrier.inv).mp _).eq_iff, ← ConcreteCategory.comp_apply]
· simp_rw [← D.ι_isoCarrier_inv]
rfl -- `rfl` was not needed before https://github.com/leanprover-community/mathlib4/pull/13170
· infer_instance
theorem isOpen_iff (U : Set D.glued.carrier) : IsOpen U ↔ ∀ i, IsOpen ((D.ι i).base ⁻¹' U) := by
rw [← (TopCat.homeoOfIso D.isoCarrier.symm).isOpen_preimage, TopCat.GlueData.isOpen_iff]
apply forall_congr'
intro i
rw [← Set.preimage_comp, ← ι_isoCarrier_inv]
rfl
/-- The open cover of the glued space given by the glue data. -/
@[simps -isSimp]
def openCover (D : Scheme.GlueData) : OpenCover D.glued where
J := D.J
obj := D.U
map := D.ι
f x := (D.ι_jointly_surjective x).choose
covers x := ⟨_, (D.ι_jointly_surjective x).choose_spec.choose_spec⟩
end GlueData
namespace Cover
variable {X : Scheme.{u}} (𝒰 : OpenCover.{u} X)
/-- (Implementation) the transition maps in the glue data associated with an open cover. -/
def gluedCoverT' (x y z : 𝒰.J) :
pullback (pullback.fst (𝒰.map x) (𝒰.map y)) (pullback.fst (𝒰.map x) (𝒰.map z)) ⟶
pullback (pullback.fst (𝒰.map y) (𝒰.map z)) (pullback.fst (𝒰.map y) (𝒰.map x)) := by
refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_
refine ?_ ≫ (pullbackSymmetry _ _).hom
refine ?_ ≫ (pullbackRightPullbackFstIso _ _ _).inv
refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_
· simp [pullback.condition]
· simp
@[simp, reassoc]
theorem gluedCoverT'_fst_fst (x y z : 𝒰.J) :
𝒰.gluedCoverT' x y z ≫ pullback.fst _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ ≫ pullback.snd _ _ := by
delta gluedCoverT'; simp
@[simp, reassoc]
theorem gluedCoverT'_fst_snd (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ pullback.fst _ _ ≫ pullback.snd _ _ =
pullback.snd _ _ ≫ pullback.snd _ _ := by
delta gluedCoverT'; simp
@[simp, reassoc]
theorem gluedCoverT'_snd_fst (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ ≫ pullback.snd _ _ := by
delta gluedCoverT'; simp
@[simp, reassoc]
theorem gluedCoverT'_snd_snd (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ pullback.snd _ _ ≫ pullback.snd _ _ =
pullback.fst _ _ ≫ pullback.fst _ _ := by
delta gluedCoverT'; simp
theorem glued_cover_cocycle_fst (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.fst _ _ =
pullback.fst _ _ := by
apply pullback.hom_ext <;> simp
theorem glued_cover_cocycle_snd (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y ≫ pullback.snd _ _ =
pullback.snd _ _ := by
apply pullback.hom_ext <;> simp [pullback.condition]
theorem glued_cover_cocycle (x y z : 𝒰.J) :
gluedCoverT' 𝒰 x y z ≫ gluedCoverT' 𝒰 y z x ≫ gluedCoverT' 𝒰 z x y = 𝟙 _ := by
apply pullback.hom_ext <;> simp_rw [Category.id_comp, Category.assoc]
· apply glued_cover_cocycle_fst
· apply glued_cover_cocycle_snd
/-- The glue data associated with an open cover.
The canonical isomorphism `𝒰.gluedCover.glued ⟶ X` is provided by `𝒰.fromGlued`. -/
@[simps]
def gluedCover : Scheme.GlueData.{u} where
J := 𝒰.J
U := 𝒰.obj
V := fun ⟨x, y⟩ => pullback (𝒰.map x) (𝒰.map y)
f _ _ := pullback.fst _ _
f_id _ := inferInstance
t _ _ := (pullbackSymmetry _ _).hom
t_id x := by simp
t' x y z := gluedCoverT' 𝒰 x y z
t_fac x y z := by apply pullback.hom_ext <;> simp
-- The `cocycle` field could have been `by tidy` but lean timeouts.
cocycle x y z := glued_cover_cocycle 𝒰 x y z
f_open _ := inferInstance
/-- The canonical morphism from the gluing of an open cover of `X` into `X`.
This is an isomorphism, as witnessed by an `IsIso` instance. -/
def fromGlued : 𝒰.gluedCover.glued ⟶ X := by
fapply Multicoequalizer.desc
· exact fun x => 𝒰.map x
rintro ⟨x, y⟩
change pullback.fst _ _ ≫ _ = ((pullbackSymmetry _ _).hom ≫ pullback.fst _ _) ≫ _
simpa using pullback.condition
@[simp, reassoc]
theorem ι_fromGlued (x : 𝒰.J) : 𝒰.gluedCover.ι x ≫ 𝒰.fromGlued = 𝒰.map x :=
Multicoequalizer.π_desc _ _ _ _ _
theorem fromGlued_injective : Function.Injective 𝒰.fromGlued.base := by
intro x y h
obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x
obtain ⟨j, y, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective y
rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] at h
simp_rw [← Scheme.comp_base] at h
rw [ι_fromGlued, ι_fromGlued] at h
let e :=
(TopCat.pullbackConeIsLimit _ _).conePointUniqueUpToIso
(isLimitOfHasPullbackOfPreservesLimit Scheme.forgetToTop (𝒰.map i) (𝒰.map j))
rw [𝒰.gluedCover.ι_eq_iff]
use e.hom ⟨⟨x, y⟩, h⟩
constructor
· erw [← ConcreteCategory.comp_apply e.hom,
IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.left]
rfl
· erw [← ConcreteCategory.comp_apply e.hom, pullbackSymmetry_hom_comp_fst,
IsLimit.conePointUniqueUpToIso_hom_comp _ _ WalkingCospan.right]
rfl
instance fromGlued_stalk_iso (x : 𝒰.gluedCover.glued.carrier) :
IsIso (𝒰.fromGlued.stalkMap x) := by
obtain ⟨i, x, rfl⟩ := 𝒰.gluedCover.ι_jointly_surjective x
have := stalkMap_congr_hom _ _ (𝒰.ι_fromGlued i) x
rw [stalkMap_comp, ← IsIso.eq_comp_inv] at this
rw [this]
infer_instance
theorem fromGlued_open_map : IsOpenMap 𝒰.fromGlued.base := by
intro U hU
rw [isOpen_iff_forall_mem_open]
intro x hx
rw [𝒰.gluedCover.isOpen_iff] at hU
use 𝒰.fromGlued.base '' U ∩ Set.range (𝒰.map (𝒰.f x)).base
use Set.inter_subset_left
constructor
· rw [← Set.image_preimage_eq_inter_range]
apply (show IsOpenImmersion (𝒰.map (𝒰.f x)) from inferInstance).base_open.isOpenMap
convert hU (𝒰.f x) using 1
simp only [← ι_fromGlued, gluedCover_U, comp_coeBase, TopCat.hom_comp, ContinuousMap.coe_comp,
Set.preimage_comp]
congr! 1
exact Set.preimage_image_eq _ 𝒰.fromGlued_injective
· exact ⟨hx, 𝒰.covers x⟩
theorem fromGlued_isOpenEmbedding : IsOpenEmbedding 𝒰.fromGlued.base :=
.of_continuous_injective_isOpenMap (by fun_prop) 𝒰.fromGlued_injective 𝒰.fromGlued_open_map
instance : Epi 𝒰.fromGlued.base := by
rw [TopCat.epi_iff_surjective]
intro x
obtain ⟨y, h⟩ := 𝒰.covers x
use (𝒰.gluedCover.ι (𝒰.f x)).base y
rw [← ConcreteCategory.comp_apply]
rw [← 𝒰.ι_fromGlued (𝒰.f x)] at h
exact h
instance fromGlued_open_immersion : IsOpenImmersion 𝒰.fromGlued :=
IsOpenImmersion.of_stalk_iso _ 𝒰.fromGlued_isOpenEmbedding
instance : IsIso 𝒰.fromGlued :=
let F := Scheme.forgetToLocallyRingedSpace ⋙ LocallyRingedSpace.forgetToSheafedSpace ⋙
SheafedSpace.forgetToPresheafedSpace
have : IsIso (F.map (fromGlued 𝒰)) := by
change IsIso 𝒰.fromGlued.toPshHom
apply PresheafedSpace.IsOpenImmersion.to_iso
isIso_of_reflects_iso _ F
/-- Given an open cover of `X`, and a morphism `𝒰.obj x ⟶ Y` for each open subscheme in the cover,
such that these morphisms are compatible in the intersection (pullback), we may glue the morphisms
together into a morphism `X ⟶ Y`.
Note:
If `X` is exactly (defeq to) the gluing of `U i`, then using `Multicoequalizer.desc` suffices.
-/
def glueMorphisms {Y : Scheme} (f : ∀ x, 𝒰.obj x ⟶ Y)
(hf : ∀ x y, pullback.fst (𝒰.map x) (𝒰.map y) ≫ f x = pullback.snd _ _ ≫ f y) :
X ⟶ Y := by
refine inv 𝒰.fromGlued ≫ ?_
fapply Multicoequalizer.desc
· exact f
rintro ⟨i, j⟩
change pullback.fst _ _ ≫ f i = (_ ≫ _) ≫ f j
| simp [pullbackSymmetry_hom_comp_fst]
exact hf i j
| Mathlib/AlgebraicGeometry/Gluing.lean | 420 | 422 |
/-
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.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Nat
/-!
# Double countings
This file gathers a few double counting arguments.
## Bipartite graphs
In a bipartite graph (considered as a relation `r : α → β → Prop`), we can bound the number of edges
between `s : Finset α` and `t : Finset β` by the minimum/maximum of edges over all `a ∈ s` times the
size of `s`. Similarly for `t`. Combining those two yields inequalities between the sizes of `s`
and `t`.
* `bipartiteBelow`: `s.bipartiteBelow r b` are the elements of `s` below `b` wrt to `r`. Its size
is the number of edges of `b` in `s`.
* `bipartiteAbove`: `t.bipartite_Above r a` are the elements of `t` above `a` wrt to `r`. Its size
is the number of edges of `a` in `t`.
* `card_mul_le_card_mul`, `card_mul_le_card_mul'`: Double counting the edges of a bipartite graph
from below and from above.
* `card_mul_eq_card_mul`: Equality combination of the previous.
## Implementation notes
For the formulation of double-counting arguments where a bipartite graph is considered as a
bipartite simple graph `G : SimpleGraph V`, see `Mathlib.Combinatorics.SimpleGraph.Bipartite`.
-/
assert_not_exists Field
open Finset Function Relator
variable {R α β : Type*}
/-! ### Bipartite graph -/
namespace Finset
section Bipartite
variable (r : α → β → Prop) (s : Finset α) (t : Finset β) (a : α) (b : β)
[DecidablePred (r a)] [∀ a, Decidable (r a b)] {m n : ℕ}
/-- Elements of `s` which are "below" `b` according to relation `r`. -/
def bipartiteBelow : Finset α := {a ∈ s | r a b}
/-- Elements of `t` which are "above" `a` according to relation `r`. -/
def bipartiteAbove : Finset β := {b ∈ t | r a b}
theorem bipartiteBelow_swap : t.bipartiteBelow (swap r) a = t.bipartiteAbove r a := rfl
theorem bipartiteAbove_swap : s.bipartiteAbove (swap r) b = s.bipartiteBelow r b := rfl
@[simp, norm_cast]
theorem coe_bipartiteBelow : s.bipartiteBelow r b = ({a ∈ s | r a b} : Set α) := coe_filter _ _
@[simp, norm_cast]
theorem coe_bipartiteAbove : t.bipartiteAbove r a = ({b ∈ t | r a b} : Set β) := coe_filter _ _
variable {s t a b}
@[simp]
theorem mem_bipartiteBelow {a : α} : a ∈ s.bipartiteBelow r b ↔ a ∈ s ∧ r a b := mem_filter
@[simp]
theorem mem_bipartiteAbove {b : β} : b ∈ t.bipartiteAbove r a ↔ b ∈ t ∧ r a b := mem_filter
@[to_additive]
theorem prod_prod_bipartiteAbove_eq_prod_prod_bipartiteBelow
[CommMonoid R] (f : α → β → R) [∀ a b, Decidable (r a b)] :
∏ a ∈ s, ∏ b ∈ t.bipartiteAbove r a, f a b = ∏ b ∈ t, ∏ a ∈ s.bipartiteBelow r b, f a b := by
simp_rw [bipartiteAbove, bipartiteBelow, prod_filter]
exact prod_comm
theorem sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow [∀ a b, Decidable (r a b)] :
(∑ a ∈ s, #(t.bipartiteAbove r a)) = ∑ b ∈ t, #(s.bipartiteBelow r b) := by
simp_rw [card_eq_sum_ones, sum_sum_bipartiteAbove_eq_sum_sum_bipartiteBelow]
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {m n : R}
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS
is an upper bound. -/
theorem card_nsmul_le_card_nsmul [∀ a b, Decidable (r a b)]
(hm : ∀ a ∈ s, m ≤ #(t.bipartiteAbove r a))
(hn : ∀ b ∈ t, #(s.bipartiteBelow r b) ≤ n) : #s • m ≤ #t • n :=
calc
_ ≤ ∑ a ∈ s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm
_ = ∑ b ∈ t, (#(s.bipartiteBelow r b) : R) := by
norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow]
_ ≤ _ := t.sum_le_card_nsmul _ _ hn
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS
is an upper bound. -/
theorem card_nsmul_le_card_nsmul' [∀ a b, Decidable (r a b)]
(hn : ∀ b ∈ t, n ≤ #(s.bipartiteBelow r b))
(hm : ∀ a ∈ s, #(t.bipartiteAbove r a) ≤ m) : #t • n ≤ #s • m :=
| card_nsmul_le_card_nsmul (swap r) hn hm
end OrderedSemiring
section StrictOrderedSemiring
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] (r : α → β → Prop)
{s : Finset α} {t : Finset β} (a b) {m n : R}
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a strict lower bound on the number of edges while
| Mathlib/Combinatorics/Enumerative/DoubleCounting.lean | 110 | 120 |
/-
Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Abhimanyu Pallavi Sudhir
-/
import Mathlib.Order.Filter.FilterProduct
import Mathlib.Analysis.SpecificLimits.Basic
/-!
# Construction of the hyperreal numbers as an ultraproduct of real sequences.
-/
open Filter Germ Topology
/-- Hyperreal numbers on the ultrafilter extending the cofinite filter -/
def Hyperreal : Type :=
Germ (hyperfilter ℕ : Filter ℕ) ℝ deriving Inhabited
namespace Hyperreal
@[inherit_doc] notation "ℝ*" => Hyperreal
noncomputable instance : Field ℝ* :=
inferInstanceAs (Field (Germ _ _))
noncomputable instance : LinearOrder ℝ* :=
inferInstanceAs (LinearOrder (Germ _ _))
instance : IsStrictOrderedRing ℝ* :=
inferInstanceAs (IsStrictOrderedRing (Germ _ _))
/-- Natural embedding `ℝ → ℝ*`. -/
@[coe] def ofReal : ℝ → ℝ* := const
noncomputable instance : CoeTC ℝ ℝ* := ⟨ofReal⟩
@[simp, norm_cast]
theorem coe_eq_coe {x y : ℝ} : (x : ℝ*) = y ↔ x = y :=
Germ.const_inj
theorem coe_ne_coe {x y : ℝ} : (x : ℝ*) ≠ y ↔ x ≠ y :=
coe_eq_coe.not
@[simp, norm_cast]
theorem coe_eq_zero {x : ℝ} : (x : ℝ*) = 0 ↔ x = 0 :=
coe_eq_coe
@[simp, norm_cast]
theorem coe_eq_one {x : ℝ} : (x : ℝ*) = 1 ↔ x = 1 :=
coe_eq_coe
@[norm_cast]
theorem coe_ne_zero {x : ℝ} : (x : ℝ*) ≠ 0 ↔ x ≠ 0 :=
coe_ne_coe
@[norm_cast]
theorem coe_ne_one {x : ℝ} : (x : ℝ*) ≠ 1 ↔ x ≠ 1 :=
coe_ne_coe
@[simp, norm_cast]
theorem coe_one : ↑(1 : ℝ) = (1 : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_zero : ↑(0 : ℝ) = (0 : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_inv (x : ℝ) : ↑x⁻¹ = (x⁻¹ : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_neg (x : ℝ) : ↑(-x) = (-x : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_add (x y : ℝ) : ↑(x + y) = (x + y : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] :
((ofNat(n) : ℝ) : ℝ*) = OfNat.ofNat n :=
rfl
@[simp, norm_cast]
theorem coe_mul (x y : ℝ) : ↑(x * y) = (x * y : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_div (x y : ℝ) : ↑(x / y) = (x / y : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_sub (x y : ℝ) : ↑(x - y) = (x - y : ℝ*) :=
rfl
@[simp, norm_cast]
theorem coe_le_coe {x y : ℝ} : (x : ℝ*) ≤ y ↔ x ≤ y :=
Germ.const_le_iff
@[simp, norm_cast]
theorem coe_lt_coe {x y : ℝ} : (x : ℝ*) < y ↔ x < y :=
Germ.const_lt_iff
@[simp, norm_cast]
theorem coe_nonneg {x : ℝ} : 0 ≤ (x : ℝ*) ↔ 0 ≤ x :=
coe_le_coe
@[simp, norm_cast]
theorem coe_pos {x : ℝ} : 0 < (x : ℝ*) ↔ 0 < x :=
coe_lt_coe
@[simp, norm_cast]
theorem coe_abs (x : ℝ) : ((|x| : ℝ) : ℝ*) = |↑x| :=
const_abs x
@[simp, norm_cast]
theorem coe_max (x y : ℝ) : ((max x y : ℝ) : ℝ*) = max ↑x ↑y :=
Germ.const_max _ _
@[simp, norm_cast]
theorem coe_min (x y : ℝ) : ((min x y : ℝ) : ℝ*) = min ↑x ↑y :=
Germ.const_min _ _
/-- Construct a hyperreal number from a sequence of real numbers. -/
def ofSeq (f : ℕ → ℝ) : ℝ* := (↑f : Germ (hyperfilter ℕ : Filter ℕ) ℝ)
theorem ofSeq_surjective : Function.Surjective ofSeq := Quot.exists_rep
theorem ofSeq_lt_ofSeq {f g : ℕ → ℝ} : ofSeq f < ofSeq g ↔ ∀ᶠ n in hyperfilter ℕ, f n < g n :=
Germ.coe_lt
/-- A sample infinitesimal hyperreal -/
noncomputable def epsilon : ℝ* :=
ofSeq fun n => n⁻¹
/-- A sample infinite hyperreal -/
noncomputable def omega : ℝ* := ofSeq Nat.cast
@[inherit_doc] scoped notation "ε" => Hyperreal.epsilon
@[inherit_doc] scoped notation "ω" => Hyperreal.omega
@[simp]
theorem inv_omega : ω⁻¹ = ε :=
rfl
@[simp]
theorem inv_epsilon : ε⁻¹ = ω :=
@inv_inv _ _ ω
theorem omega_pos : 0 < ω :=
Germ.coe_pos.2 <| Nat.hyperfilter_le_atTop <| (eventually_gt_atTop 0).mono fun _ ↦
Nat.cast_pos.2
theorem epsilon_pos : 0 < ε :=
inv_pos_of_pos omega_pos
theorem epsilon_ne_zero : ε ≠ 0 :=
epsilon_pos.ne'
theorem omega_ne_zero : ω ≠ 0 :=
omega_pos.ne'
theorem epsilon_mul_omega : ε * ω = 1 :=
@inv_mul_cancel₀ _ _ ω omega_ne_zero
theorem lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) :
∀ {r : ℝ}, 0 < r → ofSeq f < (r : ℝ*) := fun hr ↦
ofSeq_lt_ofSeq.2 <| (hf.eventually <| gt_mem_nhds hr).filter_mono Nat.hyperfilter_le_atTop
theorem neg_lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) :
∀ {r : ℝ}, 0 < r → (-r : ℝ*) < ofSeq f := fun hr =>
have hg := hf.neg
neg_lt_of_neg_lt (by rw [neg_zero] at hg; exact lt_of_tendsto_zero_of_pos hg hr)
theorem gt_of_tendsto_zero_of_neg {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) :
∀ {r : ℝ}, r < 0 → (r : ℝ*) < ofSeq f := fun {r} hr => by
rw [← neg_neg r, coe_neg]; exact neg_lt_of_tendsto_zero_of_pos hf (neg_pos.mpr hr)
theorem epsilon_lt_pos (x : ℝ) : 0 < x → ε < x :=
lt_of_tendsto_zero_of_pos tendsto_inverse_atTop_nhds_zero_nat
/-- Standard part predicate -/
def IsSt (x : ℝ*) (r : ℝ) :=
∀ δ : ℝ, 0 < δ → (r - δ : ℝ*) < x ∧ x < r + δ
open scoped Classical in
/-- Standard part function: like a "round" to ℝ instead of ℤ -/
noncomputable def st : ℝ* → ℝ := fun x => if h : ∃ r, IsSt x r then Classical.choose h else 0
/-- A hyperreal number is infinitesimal if its standard part is 0 -/
def Infinitesimal (x : ℝ*) :=
IsSt x 0
/-- A hyperreal number is positive infinite if it is larger than all real numbers -/
def InfinitePos (x : ℝ*) :=
∀ r : ℝ, ↑r < x
/-- A hyperreal number is negative infinite if it is smaller than all real numbers -/
def InfiniteNeg (x : ℝ*) :=
∀ r : ℝ, x < r
/-- A hyperreal number is infinite if it is infinite positive or infinite negative -/
def Infinite (x : ℝ*) :=
| InfinitePos x ∨ InfiniteNeg x
/-!
### Some facts about `st`
| Mathlib/Data/Real/Hyperreal.lean | 206 | 209 |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ι α β : Type*}
section LinearOrderedSemifield
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d e : α} {m n : ℤ}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iff₀ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b :=
div_lt_div_iff₀ b0 d0
@[deprecated div_le_div_iff₀ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b :=
div_le_div_iff₀ b0 d0
@[deprecated div_le_div₀ (since := "2024-11-12")]
theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d :=
div_le_div₀ hc hac hd hbd
@[deprecated div_lt_div₀ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀ hac hbd c0 d0
@[deprecated div_lt_div₀' (since := "2024-11-12")]
theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by
simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁
theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff₀ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff₀ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff₀ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff₀ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by
simpa using inv_le_comm₀ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_comm₀ ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by
simpa using le_inv_comm₀ ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by
simpa using lt_inv_comm₀ ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr
| Mathlib/Algebra/Order/Field/Basic.lean | 104 | 104 | |
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Emily Riehl
-/
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Functor.TwoSquare
import Mathlib.CategoryTheory.HomCongr
import Mathlib.Tactic.ApplyFun
/-!
# Mate of natural transformations
This file establishes the bijection between the 2-cells
```
L₁ R₁
C --→ D C ←-- D
G ↓ ↗ ↓ H G ↓ ↘ ↓ H
E --→ F E ←-- F
L₂ R₂
```
where `L₁ ⊣ R₁` and `L₂ ⊣ R₂`. The corresponding natural transformations are called mates.
This bijection includes a number of interesting cases as specializations. For instance, in the
special case where `G,H` are identity functors then the bijection preserves and reflects
isomorphisms (i.e. we have bijections`(L₂ ⟶ L₁) ≃ (R₁ ⟶ R₂)`, and if either side is an iso then the
other side is as well). This demonstrates that adjoints to a given functor are unique up to
isomorphism (since if `L₁ ≅ L₂` then we deduce `R₁ ≅ R₂`).
Another example arises from considering the square representing that a functor `H` preserves
products, in particular the morphism `HA ⨯ H- ⟶ H(A ⨯ -)`. Then provided `(A ⨯ -)` and `HA ⨯ -`
have left adjoints (for instance if the relevant categories are cartesian closed), the transferred
natural transformation is the exponential comparison morphism: `H(A ^ -) ⟶ HA ^ H-`.
Furthermore if `H` has a left adjoint `L`, this morphism is an isomorphism iff its mate
`L(HA ⨯ -) ⟶ A ⨯ L-` is an isomorphism, see
https://ncatlab.org/nlab/show/Frobenius+reciprocity#InCategoryTheory.
This also relates to Grothendieck's yoga of six operations, though this is not spelled out in
mathlib: https://ncatlab.org/nlab/show/six+operations.
-/
universe v₁ v₂ v₃ v₄ v₅ v₆ v₇ v₈ v₉ u₁ u₂ u₃ u₄ u₅ u₆ u₇ u₈ u₉
namespace CategoryTheory
open Category Functor Adjunction NatTrans TwoSquare
section mateEquiv
variable {C : Type u₁} {D : Type u₂} {E : Type u₃} {F : Type u₄}
variable [Category.{v₁} C] [Category.{v₂} D] [Category.{v₃} E] [Category.{v₄} F]
variable {G : C ⥤ E} {H : D ⥤ F} {L₁ : C ⥤ D} {R₁ : D ⥤ C} {L₂ : E ⥤ F} {R₂ : F ⥤ E}
variable (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂)
/-- Suppose we have a square of functors (where the top and bottom are adjunctions `L₁ ⊣ R₁`
and `L₂ ⊣ R₂` respectively).
```
C ↔ D
G ↓ ↓ H
E ↔ F
```
Then we have a bijection between natural transformations `G ⋙ L₂ ⟶ L₁ ⋙ H` and
`R₁ ⋙ G ⟶ H ⋙ R₂`. This can be seen as a bijection of the 2-cells:
```
L₁ R₁
C --→ D C ←-- D
G ↓ ↗ ↓ H G ↓ ↘ ↓ H
E --→ F E ←-- F
L₂ R₂
```
Note that if one of the transformations is an iso, it does not imply the other is an iso.
-/
@[simps]
def mateEquiv : TwoSquare G L₁ L₂ H ≃ TwoSquare R₁ H G R₂ where
toFun α := .mk _ _ _ _ <|
whiskerLeft (R₁ ⋙ G) adj₂.unit ≫
whiskerRight (whiskerLeft R₁ α.natTrans) R₂ ≫
whiskerRight adj₁.counit (H ⋙ R₂)
invFun β := .mk _ _ _ _ <|
whiskerRight adj₁.unit (G ⋙ L₂) ≫
whiskerRight (whiskerLeft L₁ β.natTrans) L₂ ≫
whiskerLeft (L₁ ⋙ H) adj₂.counit
left_inv α := by
ext
unfold whiskerRight whiskerLeft
simp only [comp_obj, id_obj, Functor.comp_map, comp_app, map_comp, assoc, counit_naturality,
counit_naturality_assoc, left_triangle_components_assoc]
rw [← assoc, ← Functor.comp_map, α.natTrans.naturality, Functor.comp_map, assoc, ← H.map_comp,
left_triangle_components, map_id]
simp only [comp_obj, comp_id]
right_inv β := by
ext
unfold whiskerLeft whiskerRight
simp only [comp_obj, id_obj, Functor.comp_map, comp_app, map_comp, assoc,
unit_naturality_assoc, right_triangle_components_assoc]
rw [← assoc, ← Functor.comp_map, assoc, ← β.natTrans.naturality, ← assoc, Functor.comp_map,
← G.map_comp, right_triangle_components, map_id, id_comp]
/-- A component of a transposed version of the mates correspondence. -/
theorem mateEquiv_counit (α : TwoSquare G L₁ L₂ H) (d : D) :
L₂.map ((mateEquiv adj₁ adj₂ α).app _) ≫ adj₂.counit.app _ =
α.app _ ≫ H.map (adj₁.counit.app d) := by simp
/-- A component of a transposed version of the inverse mates correspondence. -/
theorem mateEquiv_counit_symm (α : TwoSquare R₁ H G R₂) (d : D) :
L₂.map (α.app _) ≫ adj₂.counit.app _ =
((mateEquiv adj₁ adj₂).symm α).app _ ≫ H.map (adj₁.counit.app d) := by
conv_lhs => rw [← (mateEquiv adj₁ adj₂).right_inv α]
exact (mateEquiv_counit adj₁ adj₂ ((mateEquiv adj₁ adj₂).symm α) d)
/- A component of a transposed version of the mates correspondence. -/
theorem unit_mateEquiv (α : TwoSquare G L₁ L₂ H) (c : C) :
G.map (adj₁.unit.app c) ≫ (mateEquiv adj₁ adj₂ α).app _ =
adj₂.unit.app _ ≫ R₂.map (α.app _) := by
dsimp [mateEquiv]
rw [← adj₂.unit_naturality_assoc]
slice_lhs 2 3 =>
rw [← R₂.map_comp, ← Functor.comp_map G L₂, α.naturality]
rw [R₂.map_comp]
slice_lhs 3 4 =>
rw [← R₂.map_comp, Functor.comp_map L₁ H, ← H.map_comp, left_triangle_components]
simp only [comp_obj, map_id, comp_id]
/-- A component of a transposed version of the inverse mates correspondence. -/
theorem unit_mateEquiv_symm (α : TwoSquare R₁ H G R₂) (c : C) :
G.map (adj₁.unit.app c) ≫ α.app _ =
adj₂.unit.app _ ≫ R₂.map (((mateEquiv adj₁ adj₂).symm α).app _) := by
conv_lhs => rw [← (mateEquiv adj₁ adj₂).right_inv α]
exact (unit_mateEquiv adj₁ adj₂ ((mateEquiv adj₁ adj₂).symm α) c)
end mateEquiv
section mateEquivVComp
variable {A : Type u₁} {B : Type u₂} {C : Type u₃} {D : Type u₄} {E : Type u₅} {F : Type u₆}
variable [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C]
variable [Category.{v₄} D] [Category.{v₅} E] [Category.{v₆} F]
variable {G₁ : A ⥤ C} {G₂ : C ⥤ E} {H₁ : B ⥤ D} {H₂ : D ⥤ F}
variable {L₁ : A ⥤ B} {R₁ : B ⥤ A} {L₂ : C ⥤ D} {R₂ : D ⥤ C} {L₃ : E ⥤ F} {R₃ : F ⥤ E}
variable (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂) (adj₃ : L₃ ⊣ R₃)
/-- The mates equivalence commutes with vertical composition. -/
theorem mateEquiv_vcomp (α : TwoSquare G₁ L₁ L₂ H₁) (β : TwoSquare G₂ L₂ L₃ H₂) :
(mateEquiv adj₁ adj₃) (α ≫ₕ β) = (mateEquiv adj₁ adj₂ α) ≫ᵥ (mateEquiv adj₂ adj₃ β) := by
unfold hComp vComp mateEquiv
ext b
simp only [comp_obj, Equiv.coe_fn_mk, whiskerLeft_comp, whiskerLeft_twice, whiskerRight_comp,
assoc, comp_app, whiskerLeft_app, whiskerRight_app, associator_hom_app, map_id,
associator_inv_app, id_obj, Functor.comp_map, id_comp, whiskerRight_twice, comp_id]
slice_rhs 1 4 => rw [← assoc, ← assoc, ← unit_naturality (adj₃)]
rw [L₃.map_comp, R₃.map_comp]
slice_rhs 2 4 =>
rw [← R₃.map_comp, ← R₃.map_comp, ← assoc, ← L₃.map_comp, ← G₂.map_comp, ← G₂.map_comp]
rw [← Functor.comp_map G₂ L₃, β.naturality]
rw [(L₂ ⋙ H₂).map_comp, R₃.map_comp, R₃.map_comp]
slice_rhs 4 5 =>
rw [← R₃.map_comp, Functor.comp_map L₂ _, ← Functor.comp_map _ L₂, ← H₂.map_comp]
rw [adj₂.counit.naturality]
simp only [comp_obj, Functor.comp_map, map_comp, id_obj, Functor.id_map, assoc]
slice_rhs 4 5 =>
rw [← R₃.map_comp, ← H₂.map_comp, ← Functor.comp_map _ L₂, adj₂.counit.naturality]
simp only [comp_obj, id_obj, Functor.id_map, map_comp, assoc]
slice_rhs 3 4 =>
rw [← R₃.map_comp, ← H₂.map_comp, left_triangle_components]
simp only [map_id, id_comp]
end mateEquivVComp
section mateEquivHComp
variable {A : Type u₁} {B : Type u₂} {C : Type u₃} {D : Type u₄} {E : Type u₅} {F : Type u₆}
variable [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C]
variable [Category.{v₄} D] [Category.{v₅} E] [Category.{v₆} F]
variable {G : A ⥤ D} {H : B ⥤ E} {K : C ⥤ F}
variable {L₁ : A ⥤ B} {R₁ : B ⥤ A} {L₂ : D ⥤ E} {R₂ : E ⥤ D}
variable {L₃ : B ⥤ C} {R₃ : C ⥤ B} {L₄ : E ⥤ F} {R₄ : F ⥤ E}
variable (adj₁ : L₁ ⊣ R₁) (adj₂ : L₂ ⊣ R₂) (adj₃ : L₃ ⊣ R₃) (adj₄ : L₄ ⊣ R₄)
/-- The mates equivalence commutes with horizontal composition of squares. -/
theorem mateEquiv_hcomp (α : TwoSquare G L₁ L₂ H) (β : TwoSquare H L₃ L₄ K) :
(mateEquiv (adj₁.comp adj₃) (adj₂.comp adj₄)) (α ≫ᵥ β) =
(mateEquiv adj₃ adj₄ β) ≫ₕ (mateEquiv adj₁ adj₂ α) := by
unfold vComp hComp mateEquiv Adjunction.comp
ext c
dsimp
simp only [comp_id, map_comp, id_comp, assoc]
slice_rhs 2 4 =>
rw [← R₂.map_comp, ← R₂.map_comp, ← assoc, ← unit_naturality (adj₄)]
rw [R₂.map_comp, L₄.map_comp, R₄.map_comp, R₂.map_comp]
slice_rhs 4 5 =>
rw [← R₂.map_comp, ← R₄.map_comp, ← Functor.comp_map _ L₄ , β.naturality]
simp only [comp_obj, Functor.comp_map, map_comp, assoc]
end mateEquivHComp
section mateEquivSquareComp
variable {A : Type u₁} {B : Type u₂} {C : Type u₃}
variable {D : Type u₄} {E : Type u₅} {F : Type u₆}
| variable {X : Type u₇} {Y : Type u₈} {Z : Type u₉}
variable [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C]
variable [Category.{v₄} D] [Category.{v₅} E] [Category.{v₆} F]
variable [Category.{v₇} X] [Category.{v₈} Y] [Category.{v₉} Z]
| Mathlib/CategoryTheory/Adjunction/Mates.lean | 205 | 208 |
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import Mathlib.Order.ConditionallyCompleteLattice.Indexed
import Mathlib.Order.Filter.IsBounded
import Mathlib.Order.Hom.CompleteLattice
/-!
# liminfs and limsups of functions and filters
Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete
lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`.
Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ.
Then there is no guarantee that the quantity above really decreases (the value of the `sup`
beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything.
So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has
to use a less tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
open Filter Set Function
variable {α β γ ι ι' : Type*}
namespace Filter
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α}
/-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def limsSup (f : Filter α) : α :=
sInf { a | ∀ᶠ n in f, n ≤ a }
/-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def limsInf (f : Filter α) : α :=
sSup { a | ∀ᶠ n in f, a ≤ n }
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (u : β → α) (f : Filter β) : α :=
limsSup (map u f)
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (u : β → α) (f : Filter β) : α :=
limsInf (map u f)
/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum
of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/
def blimsup (u : β → α) (f : Filter β) (p : β → Prop) :=
sInf { a | ∀ᶠ x in f, p x → u x ≤ a }
/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum
of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/
def bliminf (u : β → α) (f : Filter β) (p : β → Prop) :=
sSup { a | ∀ᶠ x in f, p x → a ≤ u x }
section
variable {f : Filter β} {u : β → α} {p : β → Prop}
theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } :=
rfl
theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } :=
rfl
theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } :=
rfl
theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } :=
rfl
lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) :
liminf (u ∘ v) f = liminf u (map v f) := rfl
lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) :
limsup (u ∘ v) f = limsup u (map v f) := rfl
end
@[simp]
theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by
simp [blimsup_eq, limsup_eq]
@[simp]
theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by
simp [bliminf_eq, liminf_eq]
lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by
simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq]
lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) :=
blimsup_eq_limsup (α := αᵒᵈ)
theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by
rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val]
theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) :=
blimsup_eq_limsup_subtype (α := αᵒᵈ)
theorem limsSup_le_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a :=
csInf_le hf h
theorem le_limsInf_of_le {f : Filter α} {a}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f :=
le_csSup hf h
theorem limsup_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a :=
csInf_le hf h
theorem le_liminf_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f :=
le_csSup hf h
theorem le_limsSup_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f :=
le_csInf hf h
theorem limsInf_le_of_le {f : Filter α} {a}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a :=
csSup_le hf h
theorem le_limsup_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f :=
le_csInf hf h
theorem liminf_le_of_le {f : Filter β} {u : β → α} {a}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a :=
csSup_le hf h
theorem limsInf_le_limsSup {f : Filter α} [NeBot f]
(h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault)
(h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsSup f :=
liminf_le_of_le h₂ fun a₀ ha₀ =>
le_limsup_of_le h₁ fun a₁ ha₁ =>
show a₀ ≤ a₁ from
let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists
le_trans hb₀ hb₁
theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α}
(h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault)
(h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ limsup u f :=
limsInf_le_limsSup h h'
theorem limsSup_le_limsSup {f g : Filter α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g :=
csInf_le_csInf hf hg h
theorem limsInf_le_limsInf {f g : Filter α}
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g :=
csSup_le_csSup hg hf h
theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) :
limsup u f ≤ limsup v f :=
limsSup_le_limsSup hu hv fun _ => h.trans
theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) :
liminf u f ≤ liminf v f :=
limsup_le_limsup (β := βᵒᵈ) h hv hu
theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g)
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) :
limsSup f ≤ limsSup g :=
limsSup_le_limsSup hf hg fun _ ha => h ha
theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f)
(hf : f.IsBounded (· ≥ ·) := by isBoundedDefault)
(hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) :
limsInf f ≤ limsInf g :=
limsInf_le_limsInf hf hg fun _ ha => h ha
theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g)
{u : α → β}
(hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault)
(hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
limsup u f ≤ limsup u g :=
limsSup_le_limsSup_of_le (map_mono h) hf hg
theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f)
{u : α → β}
(hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault)
(hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) :
liminf u f ≤ liminf u g :=
limsInf_le_limsInf_of_le (map_mono h) hf hg
lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by
simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs
lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s :=
limsSup_principal_eq_csSup (α := αᵒᵈ) h hs
lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by
rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range]
lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by
rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range]
theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by
rw [limsup_eq]
congr with b
exact eventually_congr (h.mono fun x hx => by simp [hx])
theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
blimsup u f p = blimsup v f p := by
simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h
theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
bliminf u f p = bliminf v f p :=
blimsup_congr (α := αᵒᵈ) h
theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f :=
limsup_congr (β := βᵒᵈ) h
@[simp]
theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : limsup (fun _ => b) f = b := by
simpa only [limsup_eq, eventually_const] using csInf_Ici
@[simp]
theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f]
(b : β) : liminf (fun _ => b) f = b :=
limsup_const (β := βᵒᵈ) b
theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by
simp_rw [liminf_eq, hv.eventually_iff]
congr
ext x
simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists,
exists_prop]
theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
liminf f v = sSup univ := by
simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq]
theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) :
limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) :=
HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv
theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι}
{p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) :
limsup f v = sInf univ :=
HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i
@[simp]
theorem liminf_nat_add (f : ℕ → α) (k : ℕ) :
liminf (fun i => f (i + k)) atTop = liminf f atTop := by
rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat]
@[simp]
theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop :=
@liminf_nat_add αᵒᵈ _ f k
end ConditionallyCompleteLattice
section CompleteLattice
variable [CompleteLattice α]
@[simp]
theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ :=
bot_unique <| sInf_le <| by simp
@[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup]
@[simp]
theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ :=
top_unique <| le_sSup <| by simp
@[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf]
@[simp]
theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ :=
top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _
@[simp]
theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ :=
bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _
@[simp]
theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by
simp [blimsup_eq]
@[simp]
theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by
simp [bliminf_eq]
/-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/
@[simp]
theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by
rw [limsup_eq, eq_bot_iff]
exact sInf_le (Eventually.of_forall fun _ => le_rfl)
/-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/
@[simp]
theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) :=
limsup_const_bot (α := αᵒᵈ)
theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) :
limsSup f = ⨅ (i) (_ : p i), sSup (s i) :=
le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩)
(le_sInf fun _ ha =>
let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha
iInf₂_le_of_le _ hi <| sSup_le ha)
theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α}
(h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) :=
HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h
theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s :=
f.basis_sets.limsSup_eq_iInf_sSup
theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s :=
limsSup_eq_iInf_sSup (α := αᵒᵈ)
theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n :=
limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u))
theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f :=
le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u))
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
(f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i :=
(atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl
theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by
simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add]
theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a :=
(h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id]
lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by
simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s
lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by
simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s
@[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by
rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range]
@[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by
rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range]
theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by
simp only [blimsup_eq]
congr with a
refine eventually_congr (h.mono fun b hb => ?_)
rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu]
rw [hb hu]
theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q :=
blimsup_congr' (α := αᵒᵈ) h
lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(hf : f.HasBasis p s) {q : β → Prop} :
blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by
simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and,
mem_setOf_eq]
theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} :
blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by
simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm]
theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} :
blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by
simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true]
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
limsup_eq_iInf_iSup (α := αᵒᵈ)
theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i :=
@limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u
theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) :=
@limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _
theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α}
(h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a :=
HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h
theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} :
bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b :=
@blimsup_eq_iInf_biSup αᵒᵈ β _ f p u
theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} :
bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j :=
@blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u
theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by
apply le_antisymm
· rw [limsup_eq]
refine sInf_le_sInf fun x hx => ?_
rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩
filter_upwards [I_mem_F] with i hi
exact hI ▸ le_sSup (mem_image_of_mem _ hi)
· refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_
rintro _ ⟨_, h, rfl⟩
exact h
theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) :
liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) :=
@Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a
theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by
rw [liminf_eq]
refine sSup_le fun b hb => ?_
have hbx : ∃ᶠ _ in f, b ≤ x := by
revert h
rw [← not_imp_not, not_frequently, not_frequently]
exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax))
exact hbx.exists.choose_spec
theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β}
(h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f :=
liminf_le_of_frequently_le' (β := βᵒᵈ) h
/-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any
`a : α` is a fixed point. -/
@[simp]
theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) :
f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by
rw [limsup_eq_iInf_iSup_of_nat', map_iInf]
simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f,
← Nat.add_succ]
conv_rhs => rw [iInf_split _ (0 < ·)]
simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf]
refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_
simp only [zero_add, Function.comp_apply, iSup_le_iff]
exact fun i => le_iSup (fun i => f^[i] a) (i + 1)
/-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any
`a : α` is a fixed point. -/
theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) :
f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop :=
(CompleteLatticeHom.dual f).apply_limsup_iterate _
variable {f g : Filter β} {p q : β → Prop} {u v : β → α}
theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q :=
sInf_le_sInf fun a ha => ha.mono <| by tauto
theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p :=
sSup_le_sSup fun a ha => ha.mono <| by tauto
theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx')
theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
mono_blimsup' <| Eventually.of_forall h
theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx')
theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p :=
mono_bliminf' <| Eventually.of_forall h
theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p :=
sSup_le_sSup fun _ ha => ha.filter_mono h
theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p :=
sInf_le_sInf fun _ ha => ha.filter_mono h
theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q :=
le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
@[simp]
theorem bliminf_sup_le_inf_aux_left :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p :=
blimsup_and_le_inf.trans inf_le_left
@[simp]
theorem bliminf_sup_le_inf_aux_right :
(blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q :=
blimsup_and_le_inf.trans inf_le_right
theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
blimsup_and_le_inf (α := αᵒᵈ)
@[simp]
theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_left.trans bliminf_sup_le_and
@[simp]
theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x :=
le_sup_right.trans bliminf_sup_le_and
/-- See also `Filter.blimsup_or_eq_sup`. -/
theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto)
@[simp]
theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_left.trans blimsup_sup_le_or
@[simp]
theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x :=
le_sup_right.trans blimsup_sup_le_or
/-- See also `Filter.bliminf_or_eq_inf`. -/
theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q :=
blimsup_sup_le_or (α := αᵒᵈ)
@[simp]
theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p :=
bliminf_or_le_inf.trans inf_le_left
@[simp]
theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q :=
bliminf_or_le_inf.trans inf_le_right
theorem _root_.OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) :
e (blimsup u f p) = blimsup (e ∘ u) f p := by
simp only [blimsup_eq, map_sInf, Function.comp_apply, e.image_eq_preimage,
Set.preimage_setOf_eq, e.le_symm_apply]
theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) :
e (bliminf u f p) = bliminf (e ∘ u) f p :=
e.dual.apply_blimsup
theorem _root_.sSupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) :
g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by
simp only [blimsup_eq_iInf_biSup, Function.comp]
refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_
simp only [_root_.map_iSup, le_refl]
theorem _root_.sInfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) :
bliminf (g ∘ u) f p ≤ g (bliminf u f p) :=
(sInfHom.dual g).apply_blimsup_le
end CompleteLattice
section CompleteDistribLattice
variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α}
lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by
refine le_antisymm ?_
(sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right))
simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff]
intro a ha b hb
exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩
lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g :=
limsup_sup_filter (α := αᵒᵈ)
@[simp]
theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by
simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or]
@[simp]
theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q :=
blimsup_or_eq_sup (α := αᵒᵈ)
@[simp]
lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by
simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true]
@[simp]
lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f :=
blimsup_sup_not (α := αᵒᵈ)
@[simp]
lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by
simpa only [not_not] using blimsup_sup_not (p := (¬p ·))
@[simp]
lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f :=
blimsup_not_sup (α := αᵒᵈ)
lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by
rw [← blimsup_sup_not (p := (· ∈ s))]
refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;>
filter_upwards with _ h using by simp [h]
lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} :
liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) :=
limsup_piecewise (α := αᵒᵈ)
theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by
simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq]
congr; ext s; congr; ext hs; congr
exact (biSup_const (nonempty_of_mem hs)).symm
theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f :=
sup_limsup (α := αᵒᵈ) a
theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by
simp only [liminf_eq_iSup_iInf]
rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [iInf₂_sup_eq, sup_comm (a := a)]
theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f :=
sup_liminf (α := αᵒᵈ) a
end CompleteDistribLattice
section CompleteBooleanAlgebra
variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α)
theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by
simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply]
theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by
simp only [limsup_eq_iInf_iSup, sdiff_eq]
rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)]
simp_rw [inf_comm, inf_iSup₂_eq, inf_comm]
theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by
simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf]
theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, liminf_compl, comp_def, compl_inf, compl_compl, sup_limsup]
theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by
rw [← compl_inj_iff]
simp only [sdiff_eq, limsup_compl, comp_def, compl_inf, compl_compl, sup_liminf]
end CompleteBooleanAlgebra
section SetLattice
variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α}
lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by
simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter]
using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩
lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by
simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply,
mem_liminf_iff_eventually_mem]
theorem cofinite.blimsup_set_eq :
blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by
simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop]
ext x
refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h
· simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop]
exact ⟨{x}ᶜ, by simpa using h, by simp⟩
· exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩
theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by
rw [← compl_inj_iff]
simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup,
cofinite.blimsup_set_eq]
rfl
/-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s`
infinitely often. -/
theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by
simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and]
/-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s`
finitely often. -/
theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by
simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and]
theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop}
(hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) :
∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
rw [blimsup_eq_iInf_biSup] at hx
simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx
choose g hg hg' using hx
refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩
· exact hg' (b i) (hl.mem_of_mem i.2)
· exact hg (b i) (hl.mem_of_mem i.2)
theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β}
(hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α}
(hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by
obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx
exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩
end SetLattice
section ConditionallyCompleteLinearOrder
theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault)
(h : a < limsSup f) : ∃ᶠ n in f, a < n := by
contrapose! h
simp only [not_frequently, not_lt] at h
exact limsSup_le_of_le hf h
theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α}
(hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault)
(h : limsInf f < a) : ∃ᶠ n in f, n < a :=
frequently_lt_of_lt_limsSup (α := OrderDual α) hf h
theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : b < liminf u f)
(hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) :
∀ᶠ a in f, b < u a := by
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by
simp_rw [exists_prop]
exact exists_lt_of_lt_csSup hu h
exact hc.mono fun x hx => lt_of_lt_of_le hbc hx
theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β}
{b : β} (h : limsup u f < b)
(hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) :
∀ᶠ a in f, u a < b :=
eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α]
/-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, eventually we have `u b < x + ε`. -/
theorem eventually_lt_add_pos_of_limsup_le [Preorder β] [AddZeroClass α] [AddLeftStrictMono α]
{x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x)
(hε : 0 < ε) :
∀ᶠ b : β in atTop, u b < x + ε :=
| eventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x hε)) hu_bdd
| Mathlib/Order/LiminfLimsup.lean | 783 | 784 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kim Morrison
-/
import Mathlib.Algebra.Group.Indicator
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Tactic.FastInstance
import Mathlib.Algebra.Group.Equiv.Defs
/-!
# Type of functions with finite support
For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`)
of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere
on `α` except on a finite set.
Functions with finite support are used (at least) in the following parts of the library:
* `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`;
* polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use
`Finsupp` under the hood;
* the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to
define linearly independent family `LinearIndependent`) is defined as a map
`Finsupp.linearCombination : (ι → M) → (ι →₀ R) →ₗ[R] M`.
Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined
in a different way in the library:
* `Multiset α ≃+ α →₀ ℕ`;
* `FreeAbelianGroup α ≃+ α →₀ ℤ`.
Most of the theory assumes that the range is a commutative additive monoid. This gives us the big
sum operator as a powerful way to construct `Finsupp` elements, which is defined in
`Mathlib.Algebra.BigOperators.Finsupp.Basic`.
Many constructions based on `α →₀ M` are `def`s rather than `abbrev`s to avoid reusing unwanted type
class instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have
non-pointwise multiplication.
## Main declarations
* `Finsupp`: The type of finitely supported functions from `α` to `β`.
* `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`.
* `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`.
* `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding.
* `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`.
## Notations
This file adds `α →₀ M` as a global notation for `Finsupp α M`.
We also use the following convention for `Type*` variables in this file
* `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp`
somewhere in the statement;
* `ι` : an auxiliary index type;
* `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used
for a (semi)module over a (semi)ring.
* `G`, `H`: groups (commutative or not, multiplicative or additive);
* `R`, `S`: (semi)rings.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* Expand the list of definitions and important lemmas to the module docstring.
-/
assert_not_exists CompleteLattice Submonoid
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
/-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that
`f x = 0` for all but finitely many `x`. -/
structure Finsupp (α : Type*) (M : Type*) [Zero M] where
/-- The support of a finitely supported function (aka `Finsupp`). -/
support : Finset α
/-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/
toFun : α → M
/-- The witness that the support of a `Finsupp` is indeed the exact locus where its
underlying function is nonzero. -/
mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0
@[inherit_doc]
infixr:25 " →₀ " => Finsupp
namespace Finsupp
/-! ### Basic declarations about `Finsupp` -/
section Basic
variable [Zero M]
instance instFunLike : FunLike (α →₀ M) α M :=
⟨toFun, by
rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g)
congr
ext a
exact (hf _).trans (hg _).symm⟩
@[ext]
theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g :=
DFunLike.ext _ _ h
lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff
@[simp, norm_cast]
theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f :=
rfl
instance instZero : Zero (α →₀ M) :=
⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩
@[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl
theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 :=
rfl
@[simp]
theorem support_zero : (0 : α →₀ M).support = ∅ :=
rfl
instance instInhabited : Inhabited (α →₀ M) :=
⟨0⟩
@[simp]
theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 :=
@(f.mem_support_toFun)
@[simp, norm_cast]
theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support :=
Set.ext fun _x => mem_support_iff.symm
theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 :=
not_iff_comm.1 mem_support_iff.symm
@[simp, norm_cast]
theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq]
theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x :=
⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ =>
ext fun a => by
classical
exact if h : a ∈ f.support then h₂ a h else by
have hf : f a = 0 := not_mem_support_iff.1 h
have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h
rw [hf, hg]⟩
@[simp]
theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 :=
mod_cast @Function.support_eq_empty_iff _ _ _ f
theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by
simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne]
theorem card_support_eq_zero {f : α →₀ M} : #f.support = 0 ↔ f = 0 := by simp
instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g =>
decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm
theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) :=
f.fun_support_eq.symm ▸ f.support.finite_toSet
theorem support_subset_iff {s : Set α} {f : α →₀ M} :
↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by
simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm
/-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`.
(All functions on a finite type are finitely supported.) -/
@[simps]
def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where
toFun := (⇑)
invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _
left_inv _f := ext fun _x => rfl
right_inv _f := rfl
@[simp]
theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f :=
equivFunOnFinite.symm_apply_apply f
@[simp]
lemma coe_equivFunOnFinite_symm {α} [Finite α] (f : α → M) : ⇑(equivFunOnFinite.symm f) = f := rfl
/--
If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`.
-/
@[simps!]
noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M :=
Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M)
@[ext]
theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g :=
ext fun a => by rwa [Unique.eq_default a]
end Basic
/-! ### Declarations about `onFinset` -/
section OnFinset
variable [Zero M]
/-- `Finsupp.onFinset s f hf` is the finsupp function representing `f` restricted to the finset `s`.
The function must be `0` outside of `s`. Use this when the set needs to be filtered anyways,
otherwise a better set representation is often available. -/
def onFinset (s : Finset α) (f : α → M) (hf : ∀ a, f a ≠ 0 → a ∈ s) : α →₀ M where
support :=
haveI := Classical.decEq M
{a ∈ s | f a ≠ 0}
toFun := f
mem_support_toFun := by classical simpa
@[simp, norm_cast] lemma coe_onFinset (s : Finset α) (f : α → M) (hf) : onFinset s f hf = f := rfl
@[simp]
theorem onFinset_apply {s : Finset α} {f : α → M} {hf a} : (onFinset s f hf : α →₀ M) a = f a :=
rfl
@[simp]
theorem support_onFinset_subset {s : Finset α} {f : α → M} {hf} :
(onFinset s f hf).support ⊆ s := by
classical convert filter_subset (f · ≠ 0) s
theorem mem_support_onFinset {s : Finset α} {f : α → M} (hf : ∀ a : α, f a ≠ 0 → a ∈ s) {a : α} :
a ∈ (Finsupp.onFinset s f hf).support ↔ f a ≠ 0 := by
rw [Finsupp.mem_support_iff, Finsupp.onFinset_apply]
theorem support_onFinset [DecidableEq M] {s : Finset α} {f : α → M}
(hf : ∀ a : α, f a ≠ 0 → a ∈ s) :
(Finsupp.onFinset s f hf).support = {a ∈ s | f a ≠ 0} := by
dsimp [onFinset]; congr
end OnFinset
section OfSupportFinite
variable [Zero M]
/-- The natural `Finsupp` induced by the function `f` given that it has finite support. -/
noncomputable def ofSupportFinite (f : α → M) (hf : (Function.support f).Finite) : α →₀ M where
support := hf.toFinset
toFun := f
mem_support_toFun _ := hf.mem_toFinset
theorem ofSupportFinite_coe {f : α → M} {hf : (Function.support f).Finite} :
(ofSupportFinite f hf : α → M) = f :=
rfl
instance instCanLift : CanLift (α → M) (α →₀ M) (⇑) fun f => (Function.support f).Finite where
prf f hf := ⟨ofSupportFinite f hf, rfl⟩
end OfSupportFinite
/-! ### Declarations about `mapRange` -/
section MapRange
variable [Zero M] [Zero N] [Zero P]
/-- The composition of `f : M → N` and `g : α →₀ M` is `mapRange f hf g : α →₀ N`,
which is well-defined when `f 0 = 0`.
This preserves the structure on `f`, and exists in various bundled forms for when `f` is itself
bundled (defined in `Mathlib/Data/Finsupp/Basic.lean`):
* `Finsupp.mapRange.equiv`
* `Finsupp.mapRange.zeroHom`
* `Finsupp.mapRange.addMonoidHom`
* `Finsupp.mapRange.addEquiv`
* `Finsupp.mapRange.linearMap`
* `Finsupp.mapRange.linearEquiv`
-/
def mapRange (f : M → N) (hf : f 0 = 0) (g : α →₀ M) : α →₀ N :=
onFinset g.support (f ∘ g) fun a => by
rw [mem_support_iff, not_imp_not]; exact fun H => (congr_arg f H).trans hf
@[simp]
theorem mapRange_apply {f : M → N} {hf : f 0 = 0} {g : α →₀ M} {a : α} :
mapRange f hf g a = f (g a) :=
rfl
@[simp]
theorem mapRange_zero {f : M → N} {hf : f 0 = 0} : mapRange f hf (0 : α →₀ M) = 0 :=
ext fun _ => by simp only [hf, zero_apply, mapRange_apply]
@[simp]
theorem mapRange_id (g : α →₀ M) : mapRange id rfl g = g :=
ext fun _ => rfl
theorem mapRange_comp (f : N → P) (hf : f 0 = 0) (f₂ : M → N) (hf₂ : f₂ 0 = 0) (h : (f ∘ f₂) 0 = 0)
(g : α →₀ M) : mapRange (f ∘ f₂) h g = mapRange f hf (mapRange f₂ hf₂ g) :=
ext fun _ => rfl
@[simp]
lemma mapRange_mapRange (e₁ : N → P) (e₂ : M → N) (he₁ he₂) (f : α →₀ M) :
mapRange e₁ he₁ (mapRange e₂ he₂ f) = mapRange (e₁ ∘ e₂) (by simp [*]) f := ext fun _ ↦ rfl
theorem support_mapRange {f : M → N} {hf : f 0 = 0} {g : α →₀ M} :
(mapRange f hf g).support ⊆ g.support :=
support_onFinset_subset
theorem support_mapRange_of_injective {e : M → N} (he0 : e 0 = 0) (f : ι →₀ M)
(he : Function.Injective e) : (Finsupp.mapRange e he0 f).support = f.support := by
| ext
simp only [Finsupp.mem_support_iff, Ne, Finsupp.mapRange_apply]
exact he.ne_iff' he0
| Mathlib/Data/Finsupp/Defs.lean | 323 | 325 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
-/
import Mathlib.MeasureTheory.Integral.Lebesgue.Basic
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving
import Mathlib.MeasureTheory.Integral.Lebesgue.Norm
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/Lebesgue.lean | 1,597 | 1,603 | |
/-
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.Resolution
import Mathlib.CategoryTheory.Localization.Opposite
import Mathlib.CategoryTheory.GuitartExact.Opposite
/-!
# Derivability structures
Let `Φ : LocalizerMorphism W₁ W₂` be a localizer morphism, i.e. `W₁ : MorphismProperty C₁`,
`W₂ : MorphismProperty C₂`, and `Φ.functor : C₁ ⥤ C₂` is a functors which maps `W₁` to `W₂`.
Following the definition introduced by Bruno Kahn and Georges Maltsiniotis in
[Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008],
we say that `Φ` is a right derivability structure if `Φ` has right resolutions and
the following 2-square is Guitart exact, where `L₁ : C₁ ⥤ D₁` and `L₂ : C₂ ⥤ D₂` are
localization functors for `W₁` and `W₂`, and `F : D₁ ⥤ D₂` is the induced functor
on the localized categories:
```
Φ.functor
C₁ ⥤ C₂
| |
L₁| | L₂
v v
D₁ ⥤ D₂
F
```
## Implementation details
In the field `guitartExact'` of the structure `LocalizerMorphism.IsRightDerivabilityStructure`,
The condition that the square is Guitart exact is stated for the localization functors
of the constructed categories (`W₁.Q` and `W₂.Q`).
The lemma `LocalizerMorphism.isRightDerivabilityStructure_iff` show that it does
not depend of the choice of the localization functors.
## TODO
* Construct derived functors using derivability structures
* Construct the injective derivability structure in order to derive functor from
the bounded below homotopy category in an abelian category with enough injectives
* Construct the projective derivability structure in order to derive functor from
the bounded above homotopy category in an abelian category with enough projectives
* Construct the flat derivability structure on the bounded above homotopy category
of categories of modules (and categories of sheaves of modules)
* Define the product derivability structure and formalize derived functors of
functors in several variables
## References
* [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008]
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
open Category Localization
variable {C₁ : Type u₁} {C₂ : Type u₂} [Category.{v₁} C₁] [Category.{v₂} C₂]
{W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂}
namespace LocalizerMorphism
variable (Φ : LocalizerMorphism W₁ W₂)
/-- A localizer morphism `Φ : LocalizerMorphism W₁ W₂` is a right derivability
structure if it has right resolutions and the 2-square where the left and right functors
are localizations functors for `W₁` and `W₂` are Guitart exact. -/
class IsRightDerivabilityStructure : Prop where
hasRightResolutions : Φ.HasRightResolutions := by infer_instance
/-- Do not use this field directly: use the more general
`guitartExact_of_isRightDerivabilityStructure` instead,
see also the lemma `isRightDerivabilityStructure_iff`. -/
guitartExact' : TwoSquare.GuitartExact ((Φ.catCommSq W₁.Q W₂.Q).iso).hom
attribute [instance] IsRightDerivabilityStructure.hasRightResolutions
IsRightDerivabilityStructure.guitartExact'
variable {D₁ D₂ : Type*} [Category D₁] [Category D₂] (L₁ : C₁ ⥤ D₁) (L₂ : C₂ ⥤ D₂)
[L₁.IsLocalization W₁] [L₂.IsLocalization W₂] (F : D₁ ⥤ D₂)
lemma isRightDerivabilityStructure_iff [Φ.HasRightResolutions] (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ F) :
Φ.IsRightDerivabilityStructure ↔ TwoSquare.GuitartExact e.hom := by
have : Φ.IsRightDerivabilityStructure ↔
TwoSquare.GuitartExact ((Φ.catCommSq W₁.Q W₂.Q).iso).hom :=
⟨fun h => h.guitartExact', fun h => ⟨inferInstance, h⟩⟩
rw [this]
let e' := (Φ.catCommSq W₁.Q W₂.Q).iso
let E₁ := Localization.uniq W₁.Q L₁ W₁
let E₂ := Localization.uniq W₂.Q L₂ W₂
let e₁ : W₁.Q ⋙ E₁.functor ≅ L₁ := compUniqFunctor W₁.Q L₁ W₁
let e₂ : W₂.Q ⋙ E₂.functor ≅ L₂ := compUniqFunctor W₂.Q L₂ W₂
let e'' : (Φ.functor ⋙ W₂.Q) ⋙ E₂.functor ≅ (W₁.Q ⋙ E₁.functor) ⋙ F :=
Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e₂ ≪≫ e ≪≫ isoWhiskerRight e₁.symm F
let e''' : Φ.localizedFunctor W₁.Q W₂.Q ⋙ E₂.functor ≅ E₁.functor ⋙ F :=
liftNatIso W₁.Q W₁ _ _ _ _ e''
have : TwoSquare.vComp' e'.hom e'''.hom e₁ e₂ = e.hom := by
ext X₁
rw [TwoSquare.vComp'_app, liftNatIso_hom, liftNatTrans_app]
simp only [Functor.comp_obj, Iso.trans_hom, isoWhiskerLeft_hom, isoWhiskerRight_hom,
Iso.symm_hom, NatTrans.comp_app, Functor.associator_hom_app, whiskerLeft_app,
whiskerRight_app, id_comp, assoc, e'']
dsimp [Lifting.iso]
rw [F.map_id, id_comp, ← F.map_comp, Iso.inv_hom_id_app, F.map_id, comp_id,
← Functor.map_comp_assoc]
erw [show (CatCommSq.iso Φ.functor W₁.Q W₂.Q (localizedFunctor Φ W₁.Q W₂.Q)).hom =
(Lifting.iso W₁.Q W₁ _ _).inv by rfl, Iso.inv_hom_id_app]
| simp
rw [← TwoSquare.GuitartExact.vComp'_iff_of_equivalences e'.hom E₁ E₂ e''' e₁ e₂, this]
| Mathlib/CategoryTheory/Localization/DerivabilityStructure/Basic.lean | 112 | 114 |
/-
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 :=
| Mathlib/Data/Fin/Basic.lean | 1,220 | 1,222 |
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann, Kyle Miller, Mario Carneiro
-/
import Mathlib.Data.Finset.NatAntidiagonal
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Data.Nat.BinaryRec
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Zify
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Fibonacci Numbers
This file defines the fibonacci series, proves results about it and introduces
methods to compute it quickly.
-/
/-!
# The Fibonacci Sequence
## Summary
Definition of the Fibonacci sequence `F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`.
## Main Definitions
- `Nat.fib` returns the stream of Fibonacci numbers.
## Main Statements
- `Nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.`.
- `Nat.fib_gcd`: `fib n` is a strong divisibility sequence.
- `Nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `Nat.choose` along an antidiagonal.
- `Nat.fib_succ_eq_succ_sum`: shows that `F₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1`.
- `Nat.fib_two_mul` and `Nat.fib_two_mul_add_one` are the basis for an efficient algorithm to
compute `fib` (see `Nat.fastFib`).
## Implementation Notes
For efficiency purposes, the sequence is defined using `Stream.iterate`.
## Tags
fib, fibonacci
-/
namespace Nat
/-- Implementation of the fibonacci sequence satisfying
`fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`.
*Note:* We use a stream iterator for better performance when compared to the naive recursive
implementation.
-/
@[pp_nodot]
def fib (n : ℕ) : ℕ :=
((fun p : ℕ × ℕ => (p.snd, p.fst + p.snd))^[n] (0, 1)).fst
@[simp]
theorem fib_zero : fib 0 = 0 :=
rfl
@[simp]
theorem fib_one : fib 1 = 1 :=
rfl
@[simp]
theorem fib_two : fib 2 = 1 :=
rfl
/-- Shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.` -/
theorem fib_add_two {n : ℕ} : fib (n + 2) = fib n + fib (n + 1) := by
simp [fib, Function.iterate_succ_apply']
lemma fib_add_one : ∀ {n}, n ≠ 0 → fib (n + 1) = fib (n - 1) + fib n
| _n + 1, _ => fib_add_two
theorem fib_le_fib_succ {n : ℕ} : fib n ≤ fib (n + 1) := by cases n <;> simp [fib_add_two]
@[mono]
theorem fib_mono : Monotone fib :=
monotone_nat_of_le_succ fun _ => fib_le_fib_succ
@[simp] lemma fib_eq_zero : ∀ {n}, fib n = 0 ↔ n = 0
| 0 => Iff.rfl
| 1 => Iff.rfl
| n + 2 => by simp [fib_add_two, fib_eq_zero]
@[simp] lemma fib_pos {n : ℕ} : 0 < fib n ↔ 0 < n := by simp [pos_iff_ne_zero]
theorem fib_add_two_sub_fib_add_one {n : ℕ} : fib (n + 2) - fib (n + 1) = fib n := by
rw [fib_add_two, add_tsub_cancel_right]
theorem fib_lt_fib_succ {n : ℕ} (hn : 2 ≤ n) : fib n < fib (n + 1) := by
rcases exists_add_of_le hn with ⟨n, rfl⟩
rw [← tsub_pos_iff_lt, add_comm 2, add_right_comm, fib_add_two, add_tsub_cancel_right, fib_pos]
exact succ_pos n
/-- `fib (n + 2)` is strictly monotone. -/
theorem fib_add_two_strictMono : StrictMono fun n => fib (n + 2) := by
refine strictMono_nat_of_lt_succ fun n => ?_
rw [add_right_comm]
exact fib_lt_fib_succ (self_le_add_left _ _)
lemma fib_strictMonoOn : StrictMonoOn fib (Set.Ici 2)
| _m + 2, _, _n + 2, _, hmn => fib_add_two_strictMono <| lt_of_add_lt_add_right hmn
lemma fib_lt_fib {m : ℕ} (hm : 2 ≤ m) : ∀ {n}, fib m < fib n ↔ m < n
| 0 => by simp [hm]
| 1 => by simp [hm]
| n + 2 => fib_strictMonoOn.lt_iff_lt hm <| by simp
theorem le_fib_self {n : ℕ} (five_le_n : 5 ≤ n) : n ≤ fib n := by
induction' five_le_n with n five_le_n IH
· -- 5 ≤ fib 5
rfl
· -- n + 1 ≤ fib (n + 1) for 5 ≤ n
rw [succ_le_iff]
calc
n ≤ fib n := IH
_ < fib (n + 1) := fib_lt_fib_succ (le_trans (by decide) five_le_n)
lemma le_fib_add_one : ∀ n, n ≤ fib n + 1
| 0 => zero_le_one
| 1 => one_le_two
| 2 => le_rfl
| 3 => le_rfl
| 4 => le_rfl
| _n + 5 => (le_fib_self le_add_self).trans <| le_succ _
/-- Subsequent Fibonacci numbers are coprime,
see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/
theorem fib_coprime_fib_succ (n : ℕ) : Nat.Coprime (fib n) (fib (n + 1)) := by
induction' n with n ih
· simp
· simp only [fib_add_two, coprime_add_self_right, Coprime, ih.symm]
/-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/
theorem fib_add (m n : ℕ) : fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) := by
induction' n with n ih generalizing m
· simp
· specialize ih (m + 1)
rw [add_assoc m 1 n, add_comm 1 n] at ih
simp only [fib_add_two, succ_eq_add_one, ih]
ring
theorem fib_two_mul (n : ℕ) : fib (2 * n) = fib n * (2 * fib (n + 1) - fib n) := by
cases n
· simp
· rw [two_mul, ← add_assoc, fib_add, fib_add_two, two_mul]
simp only [← add_assoc, add_tsub_cancel_right]
ring
theorem fib_two_mul_add_one (n : ℕ) : fib (2 * n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 := by
rw [two_mul, fib_add]
ring
theorem fib_two_mul_add_two (n : ℕ) :
fib (2 * n + 2) = fib (n + 1) * (2 * fib n + fib (n + 1)) := by
rw [fib_add_two, fib_two_mul, fib_two_mul_add_one]
have : fib n ≤ 2 * fib (n + 1) :=
le_trans fib_le_fib_succ (mul_comm 2 _ ▸ Nat.le_mul_of_pos_right _ two_pos)
zify [this]
ring
/-- Computes `(Nat.fib n, Nat.fib (n + 1))` using the binary representation of `n`.
Supports `Nat.fastFib`. -/
def fastFibAux : ℕ → ℕ × ℕ :=
Nat.binaryRec (fib 0, fib 1) fun b _ p =>
if b then (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2))
else (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2)
/-- Computes `Nat.fib n` using the binary representation of `n`.
Proved to be equal to `Nat.fib` in `Nat.fast_fib_eq`. -/
def fastFib (n : ℕ) : ℕ :=
(fastFibAux n).1
theorem fast_fib_aux_bit_ff (n : ℕ) :
fastFibAux (bit false n) =
let p := fastFibAux n
(p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2) := by
rw [fastFibAux, binaryRec_eq]
· rfl
· simp
theorem fast_fib_aux_bit_tt (n : ℕ) :
fastFibAux (bit true n) =
let p := fastFibAux n
(p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2)) := by
rw [fastFibAux, binaryRec_eq]
· rfl
· simp
theorem fast_fib_aux_eq (n : ℕ) : fastFibAux n = (fib n, fib (n + 1)) := by
refine Nat.binaryRec ?_ ?_ n
· simp [fastFibAux]
· rintro (_|_) n' ih <;>
simp only [fast_fib_aux_bit_ff, fast_fib_aux_bit_tt, congr_arg Prod.fst ih,
congr_arg Prod.snd ih, Prod.mk_inj] <;>
simp [bit, fib_two_mul, fib_two_mul_add_one, fib_two_mul_add_two]
theorem fast_fib_eq (n : ℕ) : fastFib n = fib n := by rw [fastFib, fast_fib_aux_eq]
| theorem gcd_fib_add_self (m n : ℕ) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) := by
rcases Nat.eq_zero_or_pos n with rfl | h
| Mathlib/Data/Nat/Fib/Basic.lean | 211 | 212 |
/-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Algebra.Ring.Int.Units
import Mathlib.GroupTheory.Coprod.Basic
import Mathlib.GroupTheory.Complement
/-!
## HNN Extensions of Groups
This file defines the HNN extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`,
subgroups `A` and `B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such
that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical map
from `G` into the `HNNExtension`. This construction is named after Graham Higman, Bernhard Neumann
and Hanna Neumann.
## Main definitions
- `HNNExtension G A B φ` : The HNN Extension of a group `G`, where `A` and `B` are subgroups and `φ`
is an isomorphism between `A` and `B`.
- `HNNExtension.of` : The canonical embedding of `G` into `HNNExtension G A B φ`.
- `HNNExtension.t` : The stable letter of the HNN extension.
- `HNNExtension.lift` : Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t`
- `HNNExtension.of_injective` : The canonical embedding `G →* HNNExtension G A B φ` is injective.
- `HNNExtension.ReducedWord.toList_eq_nil_of_mem_of_range` : Britton's Lemma. If an element of
`G` is represented by a reduced word, then this reduced word does not contain `t`.
-/
assert_not_exists Field
open Monoid Coprod Multiplicative Subgroup Function
/-- The relation we quotient the coproduct by to form an `HNNExtension`. -/
def HNNExtension.con (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) :
Con (G ∗ Multiplicative ℤ) :=
conGen (fun x y => ∃ (a : A),
x = inr (ofAdd 1) * inl (a : G) ∧
y = inl (φ a : G) * inr (ofAdd 1))
/-- The HNN Extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`, subgroups `A` and
`B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such that for
any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical
map from `G` into the `HNNExtension`. -/
def HNNExtension (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) : Type _ :=
(HNNExtension.con G A B φ).Quotient
variable {G : Type*} [Group G] {A B : Subgroup G} {φ : A ≃* B} {H : Type*}
[Group H] {M : Type*} [Monoid M]
instance : Group (HNNExtension G A B φ) := by
delta HNNExtension; infer_instance
namespace HNNExtension
/-- The canonical embedding `G →* HNNExtension G A B φ` -/
def of : G →* HNNExtension G A B φ :=
(HNNExtension.con G A B φ).mk'.comp inl
/-- The stable letter of the `HNNExtension` -/
def t : HNNExtension G A B φ :=
(HNNExtension.con G A B φ).mk'.comp inr (ofAdd 1)
theorem t_mul_of (a : A) :
t * (of (a : G) : HNNExtension G A B φ) = of (φ a : G) * t :=
(Con.eq _).2 <| ConGen.Rel.of _ _ <| ⟨a, by simp⟩
theorem of_mul_t (b : B) :
(of (b : G) : HNNExtension G A B φ) * t = t * of (φ.symm b : G) := by
rw [t_mul_of]; simp
theorem equiv_eq_conj (a : A) :
(of (φ a : G) : HNNExtension G A B φ) = t * of (a : G) * t⁻¹ := by
rw [t_mul_of]; simp
theorem equiv_symm_eq_conj (b : B) :
(of (φ.symm b : G) : HNNExtension G A B φ) = t⁻¹ * of (b : G) * t := by
rw [mul_assoc, of_mul_t]; simp
theorem inv_t_mul_of (b : B) :
t⁻¹ * (of (b : G) : HNNExtension G A B φ) = of (φ.symm b : G) * t⁻¹ := by
rw [equiv_symm_eq_conj]; simp
theorem of_mul_inv_t (a : A) :
(of (a : G) : HNNExtension G A B φ) * t⁻¹ = t⁻¹ * of (φ a : G) := by
rw [equiv_eq_conj]; simp [mul_assoc]
/-- Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t` -/
def lift (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) :
HNNExtension G A B φ →* H :=
Con.lift _ (Coprod.lift f (zpowersHom H x)) (Con.conGen_le <| by
rintro _ _ ⟨a, rfl, rfl⟩
simp [hx])
@[simp]
theorem lift_t (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) :
lift f x hx t = x := by
delta HNNExtension; simp [lift, t]
@[simp]
theorem lift_of (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) (g : G) :
lift f x hx (of g) = f g := by
delta HNNExtension; simp [lift, of]
@[ext high]
theorem hom_ext {f g : HNNExtension G A B φ →* M}
(hg : f.comp of = g.comp of) (ht : f t = g t) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
Coprod.hom_ext hg (MonoidHom.ext_mint ht)
@[elab_as_elim]
theorem induction_on {motive : HNNExtension G A B φ → Prop}
(x : HNNExtension G A B φ) (of : ∀ g, motive (of g))
(t : motive t) (mul : ∀ x y, motive x → motive y → motive (x * y))
(inv : ∀ x, motive x → motive x⁻¹) : motive x := by
let S : Subgroup (HNNExtension G A B φ) :=
{ carrier := setOf motive
one_mem' := by simpa using of 1
mul_mem' := mul _ _
inv_mem' := inv _ }
let f : HNNExtension G A B φ →* S :=
lift (HNNExtension.of.codRestrict S of)
⟨HNNExtension.t, t⟩ (by intro a; ext; simp [equiv_eq_conj, mul_assoc])
have hf : S.subtype.comp f = MonoidHom.id _ :=
hom_ext (by ext; simp [f]) (by simp [f])
show motive (MonoidHom.id _ x)
rw [← hf]
exact (f x).2
variable (A B φ)
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is `φ` when `u = 1` and `φ⁻¹` when `u = -1`. `toSubgroup u` is the subgroup
such that for any `a ∈ toSubgroup u`, `t ^ (u : ℤ) * a = toSubgroupEquiv a * t ^ (u : ℤ)`. -/
def toSubgroup (u : ℤˣ) : Subgroup G :=
if u = 1 then A else B
@[simp]
theorem toSubgroup_one : toSubgroup A B 1 = A := rfl
@[simp]
theorem toSubgroup_neg_one : toSubgroup A B (-1) = B := rfl
variable {A B}
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is the group ismorphism from `toSubgroup A B u` to `toSubgroup A B (-u)`.
It is defined to be `φ` when `u = 1` and `φ⁻¹` when `u = -1`. -/
def toSubgroupEquiv (u : ℤˣ) : toSubgroup A B u ≃* toSubgroup A B (-u) :=
if hu : u = 1 then hu ▸ φ else by
convert φ.symm <;>
cases Int.units_eq_one_or u <;> simp_all
@[simp]
theorem toSubgroupEquiv_one : toSubgroupEquiv φ 1 = φ := rfl
@[simp]
theorem toSubgroupEquiv_neg_one : toSubgroupEquiv φ (-1) = φ.symm := rfl
@[simp]
theorem toSubgroupEquiv_neg_apply (u : ℤˣ) (a : toSubgroup A B u) :
(toSubgroupEquiv φ (-u) (toSubgroupEquiv φ u a) : G) = a := by
rcases Int.units_eq_one_or u with rfl | rfl
· simp [toSubgroup]
· simp only [toSubgroup_neg_one, toSubgroupEquiv_neg_one, SetLike.coe_eq_coe]
exact φ.apply_symm_apply a
namespace NormalWord
variable (G A B)
/-- To put word in the HNN Extension into a normal form, we must choose an element of each right
coset of both `A` and `B`, such that the chosen element of the subgroup itself is `1`. -/
structure TransversalPair : Type _ where
/-- The transversal of each subgroup -/
set : ℤˣ → Set G
/-- We have exactly one element of each coset of the subgroup -/
compl : ∀ u, IsComplement (toSubgroup A B u : Subgroup G) (set u)
instance TransversalPair.nonempty : Nonempty (TransversalPair G A B) := by
choose t ht using fun u ↦ (toSubgroup A B u).exists_isComplement_right 1
exact ⟨⟨t, fun i ↦ (ht i).1⟩⟩
/-- A reduced word is a `head`, which is an element of `G`, followed by the product list of pairs.
There should also be no sequences of the form `t^u * g * t^-u`, where `g` is in
`toSubgroup A B u` This is a less strict condition than required for `NormalWord`. -/
structure ReducedWord : Type _ where
/-- Every `ReducedWord` is the product of an element of the group and a word made up
of letters each of which is in the transversal. `head` is that element of the base group. -/
head : G
/-- The list of pairs `(ℤˣ × G)`, where each pair `(u, g)` represents the element `t^u * g` of
`HNNExtension G A B φ` -/
toList : List (ℤˣ × G)
/-- There are no sequences of the form `t^u * g * t^-u` where `g ∈ toSubgroup A B u` -/
chain : toList.Chain' (fun a b => a.2 ∈ toSubgroup A B a.1 → a.1 = b.1)
/-- The empty reduced word. -/
@[simps]
def ReducedWord.empty : ReducedWord G A B :=
{ head := 1
toList := []
chain := List.chain'_nil }
variable {G A B}
/-- The product of a `ReducedWord` as an element of the `HNNExtension` -/
def ReducedWord.prod : ReducedWord G A B → HNNExtension G A B φ :=
fun w => of w.head * (w.toList.map (fun x => t ^ (x.1 : ℤ) * of x.2)).prod
/-- Given a `TransversalPair`, we can make a normal form for words in the `HNNExtension G A B φ`.
The normal form is a `head`, which is an element of `G`, followed by the product list of pairs,
`t ^ u * g`, where `u` is `1` or `-1` and `g` is the chosen element of its right coset of
`toSubgroup A B u`. There should also be no sequences of the form `t^u * g * t^-u`
where `g ∈ toSubgroup A B u` -/
structure _root_.HNNExtension.NormalWord (d : TransversalPair G A B) : Type _
extends ReducedWord G A B where
/-- Every element `g : G` in the list is the chosen element of its coset -/
mem_set : ∀ (u : ℤˣ) (g : G), (u, g) ∈ toList → g ∈ d.set u
variable {d : TransversalPair G A B}
@[ext]
theorem ext {w w' : NormalWord d}
(h1 : w.head = w'.head) (h2 : w.toList = w'.toList) : w = w' := by
rcases w with ⟨⟨⟩, _⟩; cases w'; simp_all
/-- The empty word -/
@[simps]
def empty : NormalWord d :=
{ head := 1
toList := []
mem_set := by simp
chain := List.chain'_nil }
/-- The `NormalWord` representing an element `g` of the group `G`, which is just the element `g`
itself. -/
@[simps]
def ofGroup (g : G) : NormalWord d :=
{ head := g
toList := []
mem_set := by simp
chain := List.chain'_nil }
instance : Inhabited (NormalWord d) := ⟨empty⟩
instance : MulAction G (NormalWord d) :=
{ smul := fun g w => { w with head := g * w.head }
one_smul := by simp [instHSMul]
mul_smul := by simp [instHSMul, mul_assoc] }
theorem group_smul_def (g : G) (w : NormalWord d) :
g • w = { w with head := g * w.head } := rfl
@[simp]
theorem group_smul_head (g : G) (w : NormalWord d) : (g • w).head = g * w.head := rfl
@[simp]
theorem group_smul_toList (g : G) (w : NormalWord d) : (g • w).toList = w.toList := rfl
instance : FaithfulSMul G (NormalWord d) := ⟨by simp [group_smul_def]⟩
/-- A constructor to append an element `g` of `G` and `u : ℤˣ` to a word `w` with sufficient
hypotheses that no normalization or cancellation need take place for the result to be in normal form
-/
@[simps]
def cons (g : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u → u = u') :
NormalWord d :=
{ head := g,
toList := (u, w.head) :: w.toList,
mem_set := by
intro u' g' h'
simp only [List.mem_cons, Prod.mk.injEq] at h'
rcases h' with ⟨rfl, rfl⟩ | h'
· exact h1
· exact w.mem_set _ _ h'
chain := by
refine List.chain'_cons'.2 ⟨?_, w.chain⟩
rintro ⟨u', g'⟩ hu' hw1
exact h2 _ (by simp_all) hw1 }
/-- A recursor to induct on a `NormalWord`, by proving the property is preserved under `cons` -/
@[elab_as_elim]
def consRecOn {motive : NormalWord d → Sort*} (w : NormalWord d)
(ofGroup : ∀ g, motive (ofGroup g))
(cons : ∀ (g : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?,
w.head ∈ toSubgroup A B u → u = u'),
motive w → motive (cons g u w h1 h2)) : motive w := by
rcases w with ⟨⟨g, l, chain⟩, mem_set⟩
induction l generalizing g with
| nil => exact ofGroup _
| cons a l ih =>
exact cons g a.1
{ head := a.2
toList := l
mem_set := fun _ _ h => mem_set _ _ (List.mem_cons_of_mem _ h),
chain := (List.chain'_cons'.1 chain).2 }
(mem_set a.1 a.2 List.mem_cons_self)
(by simpa using (List.chain'_cons'.1 chain).1)
(ih _ _ _)
@[simp]
theorem consRecOn_ofGroup {motive : NormalWord d → Sort*}
(g : G) (ofGroup : ∀ g, motive (ofGroup g))
(cons : ∀ (g : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?, w.head
∈ toSubgroup A B u → u = u'),
motive w → motive (cons g u w h1 h2)) :
consRecOn (.ofGroup g) ofGroup cons = ofGroup g := rfl
@[simp]
theorem consRecOn_cons {motive : NormalWord d → Sort*}
(g : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u → u = u')
(ofGroup : ∀ g, motive (ofGroup g))
(cons : ∀ (g : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?,
w.head ∈ toSubgroup A B u → u = u'),
motive w → motive (cons g u w h1 h2)) :
consRecOn (.cons g u w h1 h2) ofGroup cons = cons g u w h1 h2
(consRecOn w ofGroup cons) := rfl
@[simp]
theorem smul_cons (g₁ g₂ : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u → u = u') :
g₁ • cons g₂ u w h1 h2 = cons (g₁ * g₂) u w h1 h2 :=
rfl
@[simp]
theorem smul_ofGroup (g₁ g₂ : G) :
g₁ • (ofGroup g₂ : NormalWord d) = ofGroup (g₁ * g₂) := rfl
variable (d)
/-- The action of `t^u` on `ofGroup g`. The normal form will be
`a * t^u * g'` where `a ∈ toSubgroup A B (-u)` -/
noncomputable def unitsSMulGroup (u : ℤˣ) (g : G) :
(toSubgroup A B (-u)) × d.set u :=
let g' := (d.compl u).equiv g
(toSubgroupEquiv φ u g'.1, g'.2)
theorem unitsSMulGroup_snd (u : ℤˣ) (g : G) :
(unitsSMulGroup φ d u g).2 = ((d.compl u).equiv g).2 := by
rcases Int.units_eq_one_or u with rfl | rfl <;> rfl
variable {d}
/-- `Cancels u w` is a predicate expressing whether `t^u` cancels with some occurrence
of `t^-u` when we multiply `t^u` by `w`. -/
def Cancels (u : ℤˣ) (w : NormalWord d) : Prop :=
(w.head ∈ (toSubgroup A B u : Subgroup G)) ∧ w.toList.head?.map Prod.fst = some (-u)
/-- Multiplying `t^u` by `w` in the special case where cancellation happens -/
def unitsSMulWithCancel (u : ℤˣ) (w : NormalWord d) : Cancels u w → NormalWord d :=
consRecOn w
(by simp [Cancels, ofGroup]; tauto)
(fun g _ w _ _ _ can =>
(toSubgroupEquiv φ u ⟨g, can.1⟩ : G) • w)
/-- Multiplying `t^u` by a `NormalWord`, `w` and putting the result in normal form. -/
noncomputable def unitsSMul (u : ℤˣ) (w : NormalWord d) : NormalWord d :=
letI := Classical.dec
if h : Cancels u w
then unitsSMulWithCancel φ u w h
else let g' := unitsSMulGroup φ d u w.head
cons g'.1 u ((g'.2 * w.head⁻¹ : G) • w)
(by simp)
(by
simp only [g', group_smul_toList, Option.mem_def, Option.map_eq_some_iff, Prod.exists,
exists_and_right, exists_eq_right, group_smul_head, inv_mul_cancel_right,
forall_exists_index, unitsSMulGroup]
simp only [Cancels, Option.map_eq_some_iff, Prod.exists, exists_and_right, exists_eq_right,
not_and, not_exists] at h
intro u' x hx hmem
have : w.head ∈ toSubgroup A B u := by
have := (d.compl u).rightCosetEquivalence_equiv_snd w.head
rw [RightCosetEquivalence, rightCoset_eq_iff, mul_mem_cancel_left hmem] at this
simp_all
have := h this x
simp_all [Int.units_ne_iff_eq_neg])
/-- A condition for not cancelling whose hypothese are the same as those of the `cons` function. -/
theorem not_cancels_of_cons_hyp (u : ℤˣ) (w : NormalWord d)
(h2 : ∀ u' ∈ Option.map Prod.fst w.toList.head?,
w.head ∈ toSubgroup A B u → u = u') :
¬ Cancels u w := by
simp only [Cancels, Option.map_eq_some_iff, Prod.exists,
exists_and_right, exists_eq_right, not_and, not_exists]
intro hw x hx
rw [hx] at h2
simpa using h2 (-u) rfl hw
theorem unitsSMul_cancels_iff (u : ℤˣ) (w : NormalWord d) :
Cancels (-u) (unitsSMul φ u w) ↔ ¬ Cancels u w := by
by_cases h : Cancels u w
· simp only [unitsSMul, h, dite_true, not_true_eq_false, iff_false]
induction w using consRecOn with
| ofGroup => simp [Cancels, unitsSMulWithCancel]
| cons g u' w h1 h2 _ =>
intro hc
apply not_cancels_of_cons_hyp _ _ h2
simp only [Cancels, cons_head, cons_toList, List.head?_cons,
Option.map_some', Option.some.injEq] at h
cases h.2
simpa [Cancels, unitsSMulWithCancel,
Subgroup.mul_mem_cancel_left] using hc
· simp only [unitsSMul, dif_neg h]
simpa [Cancels] using h
theorem unitsSMul_neg (u : ℤˣ) (w : NormalWord d) :
unitsSMul φ (-u) (unitsSMul φ u w) = w := by
rw [unitsSMul]
split_ifs with hcan
· have hncan : ¬ Cancels u w := (unitsSMul_cancels_iff _ _ _).1 hcan
unfold unitsSMul
simp only [dif_neg hncan]
simp [unitsSMulWithCancel, unitsSMulGroup, (d.compl u).equiv_snd_eq_inv_mul,
-SetLike.coe_sort_coe]
· have hcan2 : Cancels u w := not_not.1 (mt (unitsSMul_cancels_iff _ _ _).2 hcan)
unfold unitsSMul at hcan ⊢
simp only [dif_pos hcan2] at hcan ⊢
cases w using consRecOn with
| ofGroup => simp [Cancels] at hcan2
| cons g u' w h1 h2 ih =>
clear ih
simp only [unitsSMulGroup, SetLike.coe_sort_coe, unitsSMulWithCancel, id_eq, consRecOn_cons,
group_smul_head, IsComplement.equiv_mul_left, map_mul, Submonoid.coe_mul, coe_toSubmonoid,
toSubgroupEquiv_neg_apply, mul_inv_rev]
cases hcan2.2
have : ((d.compl (-u)).equiv w.head).1 = 1 :=
(d.compl (-u)).equiv_fst_eq_one_of_mem_of_one_mem _ h1
apply NormalWord.ext
· -- This used to `simp [this]` before https://github.com/leanprover/lean4/pull/2644
dsimp
conv_lhs => erw [IsComplement.equiv_mul_left]
rw [map_mul, Submonoid.coe_mul, toSubgroupEquiv_neg_apply, this]
simp
· -- The next two lines were not needed before https://github.com/leanprover/lean4/pull/2644
dsimp
conv_lhs => erw [IsComplement.equiv_mul_left]
simp [mul_assoc, Units.ext_iff, (d.compl (-u)).equiv_snd_eq_inv_mul, this,
-SetLike.coe_sort_coe]
/-- the equivalence given by multiplication on the left by `t` -/
@[simps]
noncomputable def unitsSMulEquiv : NormalWord d ≃ NormalWord d :=
{ toFun := unitsSMul φ 1
invFun := unitsSMul φ (-1),
left_inv := fun _ => by rw [unitsSMul_neg]
right_inv := fun w => by convert unitsSMul_neg _ _ w; simp }
theorem unitsSMul_one_group_smul (g : A) (w : NormalWord d) :
unitsSMul φ 1 ((g : G) • w) = (φ g : G) • (unitsSMul φ 1 w) := by
unfold unitsSMul
have : Cancels 1 ((g : G) • w) ↔ Cancels 1 w := by
simp [Cancels, Subgroup.mul_mem_cancel_left]
by_cases hcan : Cancels 1 w
· simp [unitsSMulWithCancel, dif_pos (this.2 hcan), dif_pos hcan]
cases w using consRecOn
· simp [Cancels] at hcan
· simp only [smul_cons, consRecOn_cons, mul_smul]
rw [← mul_smul, ← Subgroup.coe_mul, ← map_mul φ]
rfl
· rw [dif_neg (mt this.1 hcan), dif_neg hcan]
simp [← mul_smul, mul_assoc, unitsSMulGroup]
-- This used to be the end of the proof before https://github.com/leanprover/lean4/pull/2644
dsimp
congr 1
· conv_lhs => erw [IsComplement.equiv_mul_left]
simp_rw [toSubgroup_one]
simp only [SetLike.coe_sort_coe, map_mul, Subgroup.coe_mul]
conv_lhs => erw [IsComplement.equiv_mul_left]
rfl
noncomputable instance : MulAction (HNNExtension G A B φ) (NormalWord d) :=
MulAction.ofEndHom <| (MulAction.toEndHom (M := Equiv.Perm (NormalWord d))).comp
(HNNExtension.lift (MulAction.toPermHom _ _) (unitsSMulEquiv φ) <| by
intro a
ext : 1
simp [unitsSMul_one_group_smul])
@[simp]
theorem prod_group_smul (g : G) (w : NormalWord d) :
(g • w).prod φ = of g * (w.prod φ) := by
simp [ReducedWord.prod, smul_def, mul_assoc]
theorem of_smul_eq_smul (g : G) (w : NormalWord d) :
(of g : HNNExtension G A B φ) • w = g • w := by
simp [instHSMul, SMul.smul, MulAction.toEndHom]
theorem t_smul_eq_unitsSMul (w : NormalWord d) :
(t : HNNExtension G A B φ) • w = unitsSMul φ 1 w := by
simp [instHSMul, SMul.smul, MulAction.toEndHom]
theorem t_pow_smul_eq_unitsSMul (u : ℤˣ) (w : NormalWord d) :
(t ^ (u : ℤ) : HNNExtension G A B φ) • w = unitsSMul φ u w := by
rcases Int.units_eq_one_or u with (rfl | rfl) <;>
| simp [instHSMul, SMul.smul, MulAction.toEndHom, Equiv.Perm.inv_def]
@[simp]
theorem prod_cons (g : G) (u : ℤˣ) (w : NormalWord d) (h1 : w.head ∈ d.set u)
| Mathlib/GroupTheory/HNNExtension.lean | 502 | 505 |
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Gabin Kolly
-/
import Mathlib.Data.Finite.Sum
import Mathlib.Data.Fintype.Order
import Mathlib.ModelTheory.FinitelyGenerated
import Mathlib.ModelTheory.Quotients
import Mathlib.Order.DirectedInverseSystem
/-!
# Direct Limits of First-Order Structures
This file constructs the direct limit of a directed system of first-order embeddings.
## Main Definitions
- `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of
first-order embeddings between the structures indexed by `G`.
- `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps
from the components to another module that respect the directed system structure give rise to
a unique map out of the direct limit.
- `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of
isomorphic direct systems.
-/
universe v w w' u₁ u₂
open FirstOrder
namespace FirstOrder
namespace Language
open Structure Set
variable {L : Language} {ι : Type v} [Preorder ι]
variable {G : ι → Type w} [∀ i, L.Structure (G i)]
variable (f : ∀ i j, i ≤ j → G i ↪[L] G j)
namespace DirectedSystem
alias map_self := DirectedSystem.map_self'
alias map_map := DirectedSystem.map_map'
variable {G' : ℕ → Type w} [∀ i, L.Structure (G' i)] (f' : ∀ n : ℕ, G' n ↪[L] G' (n + 1))
/-- Given a chain of embeddings of structures indexed by `ℕ`, defines a `DirectedSystem` by
composing them. -/
def natLERec (m n : ℕ) (h : m ≤ n) : G' m ↪[L] G' n :=
Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _)
@[simp]
theorem coe_natLERec (m n : ℕ) (h : m ≤ n) :
(natLERec f' m n h : G' m → G' n) = Nat.leRecOn h (@fun k => f' k) := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h
ext x
induction' k with k ih
· -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [natLERec, Nat.leRecOn_self, Embedding.refl_apply, Nat.leRecOn_self]
· -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, ← natLERec,
Embedding.comp_apply, ih]
instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h :=
⟨fun _ _ => congr (congr rfl (Nat.leRecOn_self _)) rfl,
fun _ _ _ hij hjk => by simp [Nat.leRecOn_trans hij hjk]⟩
end DirectedSystem
set_option linter.unusedVariables false in
/-- Alias for `Σ i, G i`.
Instead of `Σ i, G i`, we use the alias `Language.Structure.Sigma` which depends on `f`.
This way, Lean can infer what `L` and `f` are in the `Setoid` instance.
Otherwise we have a "cannot find synthesization order" error.
See also the discussion at
https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting
-/
@[nolint unusedArguments]
protected abbrev Structure.Sigma (f : ∀ i j, i ≤ j → G i ↪[L] G j) := Σ i, G i
local notation "Σˣ" => Structure.Sigma
/-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/
abbrev Structure.Sigma.mk (i : ι) (x : G i) : Σˣ f := ⟨i, x⟩
namespace DirectLimit
/-- Raises a family of elements in the `Σ`-type to the same level along the embeddings. -/
def unify {α : Type*} (x : α → Σˣ f) (i : ι) (h : i ∈ upperBounds (range (Sigma.fst ∘ x)))
(a : α) : G i :=
f (x a).1 i (h (mem_range_self a)) (x a).2
variable [DirectedSystem G fun i j h => f i j h]
@[simp]
theorem unify_sigma_mk_self {α : Type*} {i : ι} {x : α → G i} :
(unify f (fun a => .mk f i (x a)) i fun _ ⟨_, hj⟩ =>
_root_.trans (le_of_eq hj.symm) (refl _)) = x := by
ext a
rw [unify]
apply DirectedSystem.map_self
theorem comp_unify {α : Type*} {x : α → Σˣ f} {i j : ι} (ij : i ≤ j)
(h : i ∈ upperBounds (range (Sigma.fst ∘ x))) :
f i j ij ∘ unify f x i h = unify f x j
fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by
ext a
simp [unify, DirectedSystem.map_map]
end DirectLimit
variable (G)
namespace DirectLimit
/-- The directed limit glues together the structures along the embeddings. -/
| def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ι (· ≤ ·)] : Setoid (Σˣ f) where
r := fun ⟨i, x⟩ ⟨j, y⟩ => ∃ (k : ι) (ik : i ≤ k) (jk : j ≤ k), f i k ik x = f j k jk y
iseqv :=
⟨fun ⟨i, _⟩ => ⟨i, refl i, refl i, rfl⟩, @fun ⟨_, _⟩ ⟨_, _⟩ ⟨k, ik, jk, h⟩ =>
⟨k, jk, ik, h.symm⟩,
@fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, z⟩ ⟨ij, hiij, hjij, hij⟩ ⟨jk, hjjk, hkjk, hjk⟩ => by
| Mathlib/ModelTheory/DirectLimit.lean | 121 | 126 |
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.Dual
import Mathlib.Analysis.InnerProductSpace.Orientation
import Mathlib.Data.Complex.FiniteDimensional
import Mathlib.Data.Complex.Orientation
import Mathlib.Tactic.LinearCombination
/-!
# Oriented two-dimensional real inner product spaces
This file defines constructions specific to the geometry of an oriented two-dimensional real inner
product space `E`.
## Main declarations
* `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`).
Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram
they span. (But mathlib does not yet have a construction of oriented area, and in fact the
construction of oriented area should pass through `ω`.)
* `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`).
This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined,
in such a way that this automorphism is equal to rotation by 90 degrees.
* `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]`
for `E`.
* `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the
inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`,
the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles
(`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the
oriented angle from `x` to `y`.
## Main results
* `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x`
* `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if
and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0`
* `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y`
* `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete
interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner
product space `ℂ`
* `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`,
`Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`,
expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete
interpretations on `ℂ`
## Implementation notes
Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be
defined locally in each file which uses them, since otherwise one would need a more cumbersome
notation which mentions the orientation explicitly (something like `ω[o]`). Write
```
local notation "ω" => o.areaForm
local notation "J" => o.rightAngleRotation
```
-/
noncomputable section
open scoped RealInnerProductSpace ComplexConjugate
open Module
lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K]
[AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V :=
.of_fact_finrank_eq_succ 1
attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)]
(o : Orientation ℝ E (Fin 2))
namespace Orientation
/-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual
notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they
span. -/
irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by
let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ :=
AlternatingMap.constLinearEquivOfIsEmpty.symm
let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ :=
LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap
exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm
local notation "ω" => o.areaForm
theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm]
@[simp]
theorem areaForm_apply_self (x : E) : ω x x = 0 := by
rw [areaForm_to_volumeForm]
refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1)
· simp
· norm_num
theorem areaForm_swap (x y : E) : ω x y = -ω y x := by
simp only [areaForm_to_volumeForm]
convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1)
· ext i
fin_cases i <;> rfl
· norm_num
@[simp]
theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by
ext x y
simp [areaForm_to_volumeForm]
/-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/
def areaForm' : E →L[ℝ] E →L[ℝ] ℝ :=
LinearMap.toContinuousLinearMap
(↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm)
@[simp]
theorem areaForm'_apply (x : E) :
o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) :=
rfl
theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y]
theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y]
theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by
rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal]
· simp [Fin.prod_univ_succ]
intro i j hij
fin_cases i <;> fin_cases j
· simp_all
· simpa using h
· simpa [real_inner_comm] using h
· simp_all
theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y =
o.areaForm (φ.symm x) (φ.symm y) := by
have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by
ext i
fin_cases i <;> rfl
simp [areaForm_to_volumeForm, volumeForm_map, this]
/-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/
theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) :
o.areaForm (φ x) (φ y) = o.areaForm x y := by
convert o.areaForm_map φ (φ x) (φ y)
· symm
rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ
rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin]
· simp
· simp
/-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an
oriented real inner product space of dimension 2. -/
irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E :=
let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ :=
(InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm
↑to_dual.symm ∘ₗ ω
@[simp]
theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by
simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm,
LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply,
LinearIsometryEquiv.coe_toLinearEquiv]
rw [InnerProductSpace.toDual_symm_apply]
norm_cast
@[simp]
theorem inner_rightAngleRotationAux₁_right (x y : E) :
⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by
rw [real_inner_comm]
simp [o.areaForm_swap y x]
/-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an
oriented real inner product space of dimension 2. -/
def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E :=
{ o.rightAngleRotationAux₁ with
norm_map' := fun x => by
refine le_antisymm ?_ ?_
· rcases eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h | h
· rw [← h]
positivity
refine le_of_mul_le_mul_right ?_ h
rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left]
exact o.areaForm_le x (o.rightAngleRotationAux₁ x)
· let K : Submodule ℝ E := ℝ ∙ x
have : Nontrivial Kᗮ := by
apply nontrivial_of_finrank_pos (R := ℝ)
have : finrank ℝ K ≤ Finset.card {x} := by
rw [← Set.toFinset_singleton]
exact finrank_span_le_card ({x} : Set E)
have : Finset.card {x} = 1 := Finset.card_singleton x
have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal
have : finrank ℝ E = 2 := Fact.out
omega
obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0
have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2
have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h)
refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖)
rw [← o.abs_areaForm_of_orthogonal hw']
rw [← o.inner_rightAngleRotationAux₁_left x w]
exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w }
@[simp]
theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) :
o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by
apply ext_inner_left ℝ
intro y
have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ :=
LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x
rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this,
inner_neg_right]
/-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation
`J`). This automorphism squares to -1. We will define rotations in such a way that this
automorphism is equal to rotation by 90 degrees. -/
irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E :=
LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁)
(by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂])
local notation "J" => o.rightAngleRotation
@[simp]
theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by
rw [rightAngleRotation]
exact o.inner_rightAngleRotationAux₁_left x y
@[simp]
theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by
rw [rightAngleRotation]
exact o.inner_rightAngleRotationAux₁_right x y
@[simp]
theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by
rw [rightAngleRotation]
exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x
@[simp]
theorem rightAngleRotation_symm :
LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by
rw [rightAngleRotation]
exact LinearIsometryEquiv.toLinearIsometry_injective rfl
theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp
theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp
theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by
simp [o.inner_rightAngleRotation_swap x y]
theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ :=
LinearIsometryEquiv.inner_map_map J x y
@[simp]
theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by
rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg]
@[simp]
theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by
rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation]
theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp
@[simp]
theorem rightAngleRotation_trans_rightAngleRotation :
LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp
theorem rightAngleRotation_neg_orientation (x : E) :
(-o).rightAngleRotation x = -o.rightAngleRotation x := by
apply ext_inner_right ℝ
intro y
rw [inner_rightAngleRotation_left]
simp
@[simp]
theorem rightAngleRotation_trans_neg_orientation :
(-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) :=
LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation
theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x =
φ (o.rightAngleRotation (φ.symm x)) := by
apply ext_inner_right ℝ
intro y
rw [inner_rightAngleRotation_left]
trans ⟪J (φ.symm x), φ.symm y⟫
· simp [o.areaForm_map]
trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫
· rw [φ.inner_map_map]
· simp
/-- `J` commutes with any positively-oriented isometric automorphism. -/
theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by
convert (o.rightAngleRotation_map φ (φ x)).symm
· simp
· symm
rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ
rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin]
theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation =
(φ.symm.trans o.rightAngleRotation).trans φ :=
LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ
/-- `J` commutes with any positively-oriented isometric automorphism. -/
theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) :
LinearIsometryEquiv.trans J φ = φ.trans J :=
LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ
/-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`,
`![x, J x]` forms an (orthogonal) basis for `E`. -/
def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E :=
@basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x]
(linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx])
(by
intro i j hij
fin_cases i <;> fin_cases j <;> simp_all))
(@Fact.out (finrank ℝ E = 2)).symm
@[simp]
theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) :
⇑(o.basisRightAngleRotation x hx) = ![x, J x] :=
coe_basisOfLinearIndependentOfCardEqFinrank _ _
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See
`Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.) -/
theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) :
⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by
by_cases ha : a = 0
· simp [ha]
apply (o.basisRightAngleRotation a ha).ext
intro i
fin_cases i
· simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm]
· simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x]
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/
theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) :
⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ :=
congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x)
theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by
simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See
`Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/
theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by
by_cases ha : a = 0
· simp [ha]
apply (o.basisRightAngleRotation a ha).ext
intro i
fin_cases i
· simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x]
· simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm]
/-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/
theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y :=
congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x)
theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) :
0 ≤ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by
by_cases hx : x = 0
· simp [hx]
constructor
· let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0
let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1
suffices ↑0 ≤ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by
rw [← (o.basisRightAngleRotation x hx).sum_repr y]
simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero,
Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self,
map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one,
Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right,
mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right,
real_inner_self_eq_norm_sq, zero_smul, one_smul]
exact this
rintro ⟨ha, hb⟩
have hx' : 0 < ‖x‖ := by simpa using hx
have ha' : 0 ≤ a := nonneg_of_mul_nonneg_left ha (by positivity)
have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb
exact (SameRay.sameRay_nonneg_smul_right x ha').add_right <| by simp [hb']
· intro h
obtain ⟨r, hr, rfl⟩ := h.exists_nonneg_left hx
simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ,
areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true, and_true]
positivity
/-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its
real part is the inner product and its imaginary part is `Orientation.areaForm`.
On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/
def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ :=
LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ +
LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω
theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I :=
rfl
theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by
simp only [kahler_apply_apply]
rw [real_inner_comm, areaForm_swap]
simp [Complex.conj_ofReal]
@[simp]
theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by
simp [kahler_apply_apply, real_inner_self_eq_norm_sq]
@[simp]
theorem kahler_rightAngleRotation_left (x y : E) :
o.kahler (J x) y = -Complex.I * o.kahler x y := by
simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left,
o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul]
linear_combination ω x y * Complex.I_sq
@[simp]
theorem kahler_rightAngleRotation_right (x y : E) :
o.kahler x (J y) = Complex.I * o.kahler x y := by
simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right,
o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul]
linear_combination -ω x y * Complex.I_sq
-- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'`
theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by
simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right]
linear_combination -o.kahler x y * Complex.I_sq
theorem kahler_comp_rightAngleRotation' (x y : E) :
-(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by
linear_combination -o.kahler x y * Complex.I_sq
@[simp]
theorem kahler_neg_orientation (x y : E) : (-o).kahler x y = conj (o.kahler x y) := by
simp [kahler_apply_apply, Complex.conj_ofReal]
theorem kahler_mul (a x y : E) : o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y := by
trans ((‖a‖ ^ 2 :) : ℂ) * o.kahler x y
· apply Complex.ext
· simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re,
Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul]
rw [real_inner_comm a x, o.areaForm_swap x a]
linear_combination o.inner_mul_inner_add_areaForm_mul_areaForm a x y
· simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re,
Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul]
rw [real_inner_comm a x, o.areaForm_swap x a]
linear_combination o.inner_mul_areaForm_sub a x y
· norm_cast
theorem normSq_kahler (x y : E) : Complex.normSq (o.kahler x y) = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by
simpa [kahler_apply_apply, Complex.normSq, sq] using o.inner_sq_add_areaForm_sq x y
theorem norm_kahler (x y : E) : ‖o.kahler x y‖ = ‖x‖ * ‖y‖ := by
rw [← sq_eq_sq₀, Complex.sq_norm]
· linear_combination o.normSq_kahler x y
· positivity
· positivity
@[deprecated (since := "2025-02-17")] alias abs_kahler := norm_kahler
theorem eq_zero_or_eq_zero_of_kahler_eq_zero {x y : E} (hx : o.kahler x y = 0) : x = 0 ∨ y = 0 := by
have : ‖x‖ * ‖y‖ = 0 := by simpa [hx] using (o.norm_kahler x y).symm
rcases eq_zero_or_eq_zero_of_mul_eq_zero this with h | h
· left
simpa using h
· right
simpa using h
theorem kahler_eq_zero_iff (x y : E) : o.kahler x y = 0 ↔ x = 0 ∨ y = 0 := by
refine ⟨o.eq_zero_or_eq_zero_of_kahler_eq_zero, ?_⟩
rintro (rfl | rfl) <;> simp
theorem kahler_ne_zero {x y : E} (hx : x ≠ 0) (hy : y ≠ 0) : o.kahler x y ≠ 0 := by
apply mt o.eq_zero_or_eq_zero_of_kahler_eq_zero
tauto
theorem kahler_ne_zero_iff (x y : E) : o.kahler x y ≠ 0 ↔ x ≠ 0 ∧ y ≠ 0 := by
refine ⟨?_, fun h => o.kahler_ne_zero h.1 h.2⟩
contrapose
simp only [not_and_or, Classical.not_not, kahler_apply_apply, Complex.real_smul]
rintro (rfl | rfl) <;> simp
theorem kahler_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) :
(Orientation.map (Fin 2) φ.toLinearEquiv o).kahler x y = o.kahler (φ.symm x) (φ.symm y) := by
simp [kahler_apply_apply, areaForm_map]
/-- The bilinear map `kahler` is invariant under pullback by a positively-oriented isometric
automorphism. -/
theorem kahler_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E)
(hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) :
o.kahler (φ x) (φ y) = o.kahler x y := by
simp [kahler_apply_apply, o.areaForm_comp_linearIsometryEquiv φ hφ]
end Orientation
namespace Complex
attribute [local instance] Complex.finrank_real_complex_fact
@[simp]
protected theorem areaForm (w z : ℂ) : Complex.orientation.areaForm w z = (conj w * z).im := by
| let o := Complex.orientation
simp only [o, o.areaForm_to_volumeForm,
o.volumeForm_robust Complex.orthonormalBasisOneI rfl, Basis.det_apply, Matrix.det_fin_two,
| Mathlib/Analysis/InnerProductSpace/TwoDim.lean | 517 | 519 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Aesop
import Mathlib.Order.BoundedOrder.Lattice
/-!
# Disjointness and complements
This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate.
## Main declarations
* `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element.
* `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element.
* `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a
non distributive lattice, an element can have several complements.
* `ComplementedLattice α`: Typeclass stating that any element of a lattice has a complement.
-/
open Function
variable {α : Type*}
section Disjoint
section PartialOrderBot
variable [PartialOrder α] [OrderBot α] {a b c d : α}
/-- Two elements of a lattice are disjoint if their inf is the bottom element.
(This generalizes disjoint sets, viewed as members of the subset lattice.)
Note that we define this without reference to `⊓`, as this allows us to talk about orders where
the infimum is not unique, or where implementing `Inf` would require additional `Decidable`
arguments. -/
def Disjoint (a b : α) : Prop :=
∀ ⦃x⦄, x ≤ a → x ≤ b → x ≤ ⊥
@[simp]
theorem disjoint_of_subsingleton [Subsingleton α] : Disjoint a b :=
fun x _ _ ↦ le_of_eq (Subsingleton.elim x ⊥)
theorem disjoint_comm : Disjoint a b ↔ Disjoint b a :=
forall_congr' fun _ ↦ forall_swap
@[symm]
theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b → Disjoint b a :=
disjoint_comm.1
theorem symmetric_disjoint : Symmetric (Disjoint : α → α → Prop) :=
Disjoint.symm
@[simp]
theorem disjoint_bot_left : Disjoint ⊥ a := fun _ hbot _ ↦ hbot
@[simp]
theorem disjoint_bot_right : Disjoint a ⊥ := fun _ _ hbot ↦ hbot
theorem Disjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Disjoint b d → Disjoint a c :=
fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans h₂)
theorem Disjoint.mono_left (h : a ≤ b) : Disjoint b c → Disjoint a c :=
Disjoint.mono h le_rfl
theorem Disjoint.mono_right : b ≤ c → Disjoint a c → Disjoint a b :=
Disjoint.mono le_rfl
@[simp]
theorem disjoint_self : Disjoint a a ↔ a = ⊥ :=
⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩
/- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to
`Disjoint.eq_bot` -/
alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self
theorem Disjoint.ne (ha : a ≠ ⊥) (hab : Disjoint a b) : a ≠ b :=
fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab
theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≤ b) : a = ⊥ :=
eq_bot_iff.2 <| hab le_rfl h
theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≤ a → b = ⊥ :=
hab.symm.eq_bot_of_le
lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = ⊥ ∧ b = ⊥ := by aesop
lemma Disjoint.ne_iff (hab : Disjoint a b) : a ≠ b ↔ a ≠ ⊥ ∨ b ≠ ⊥ :=
hab.eq_iff.not.trans not_and_or
theorem disjoint_of_le_iff_left_eq_bot (h : a ≤ b) :
Disjoint a b ↔ a = ⊥ :=
⟨fun hd ↦ hd.eq_bot_of_le h, fun h ↦ h ▸ disjoint_bot_left⟩
end PartialOrderBot
section PartialBoundedOrder
variable [PartialOrder α] [BoundedOrder α] {a : α}
@[simp]
theorem disjoint_top : Disjoint a ⊤ ↔ a = ⊥ :=
⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩
@[simp]
theorem top_disjoint : Disjoint ⊤ a ↔ a = ⊥ :=
⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩
end PartialBoundedOrder
section SemilatticeInfBot
variable [SemilatticeInf α] [OrderBot α] {a b c : α}
theorem disjoint_iff_inf_le : Disjoint a b ↔ a ⊓ b ≤ ⊥ :=
⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩
theorem disjoint_iff : Disjoint a b ↔ a ⊓ b = ⊥ :=
disjoint_iff_inf_le.trans le_bot_iff
theorem Disjoint.le_bot : Disjoint a b → a ⊓ b ≤ ⊥ :=
disjoint_iff_inf_le.mp
theorem Disjoint.eq_bot : Disjoint a b → a ⊓ b = ⊥ :=
bot_unique ∘ Disjoint.le_bot
theorem disjoint_assoc : Disjoint (a ⊓ b) c ↔ Disjoint a (b ⊓ c) := by
rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc]
theorem disjoint_left_comm : Disjoint a (b ⊓ c) ↔ Disjoint b (a ⊓ c) := by
simp_rw [disjoint_iff_inf_le, inf_left_comm]
theorem disjoint_right_comm : Disjoint (a ⊓ b) c ↔ Disjoint (a ⊓ c) b := by
simp_rw [disjoint_iff_inf_le, inf_right_comm]
variable (c)
theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a ⊓ c) b :=
h.mono_left inf_le_left
theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c ⊓ a) b :=
h.mono_left inf_le_right
theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b ⊓ c) :=
h.mono_right inf_le_left
theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c ⊓ b) :=
h.mono_right inf_le_right
variable {c}
theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a ⊓ b) c) (hle : a ≤ c) : Disjoint a b :=
disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle
theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a ⊓ b) c) (hle : b ≤ c) : Disjoint a b :=
disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle
end SemilatticeInfBot
theorem Disjoint.right_lt_sup_of_left_ne_bot [SemilatticeSup α] [OrderBot α] {a b : α}
(h : Disjoint a b) (ha : a ≠ ⊥) : b < a ⊔ b :=
le_sup_right.lt_of_ne fun eq ↦ ha (le_bot_iff.mp <| h le_rfl <| sup_eq_right.mp eq.symm)
section DistribLatticeBot
variable [DistribLattice α] [OrderBot α] {a b c : α}
@[simp]
theorem disjoint_sup_left : Disjoint (a ⊔ b) c ↔ Disjoint a c ∧ Disjoint b c := by
simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff]
@[simp]
theorem disjoint_sup_right : Disjoint a (b ⊔ c) ↔ Disjoint a b ∧ Disjoint a c := by
simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff]
theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ⊔ b) c :=
disjoint_sup_left.2 ⟨ha, hb⟩
theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b ⊔ c) :=
disjoint_sup_right.2 ⟨hb, hc⟩
theorem Disjoint.left_le_of_le_sup_right (h : a ≤ b ⊔ c) (hd : Disjoint a c) : a ≤ b :=
le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right
theorem Disjoint.left_le_of_le_sup_left (h : a ≤ c ⊔ b) (hd : Disjoint a c) : a ≤ b :=
hd.left_le_of_le_sup_right <| by rwa [sup_comm]
end DistribLatticeBot
end Disjoint
section Codisjoint
section PartialOrderTop
variable [PartialOrder α] [OrderTop α] {a b c d : α}
/-- Two elements of a lattice are codisjoint if their sup is the top element.
Note that we define this without reference to `⊔`, as this allows us to talk about orders where
the supremum is not unique, or where implement `Sup` would require additional `Decidable`
arguments. -/
def Codisjoint (a b : α) : Prop :=
∀ ⦃x⦄, a ≤ x → b ≤ x → ⊤ ≤ x
theorem codisjoint_comm : Codisjoint a b ↔ Codisjoint b a :=
forall_congr' fun _ ↦ forall_swap
@[deprecated (since := "2024-11-23")] alias Codisjoint_comm := codisjoint_comm
@[symm]
theorem Codisjoint.symm ⦃a b : α⦄ : Codisjoint a b → Codisjoint b a :=
codisjoint_comm.1
theorem symmetric_codisjoint : Symmetric (Codisjoint : α → α → Prop) :=
Codisjoint.symm
@[simp]
theorem codisjoint_top_left : Codisjoint ⊤ a := fun _ htop _ ↦ htop
@[simp]
theorem codisjoint_top_right : Codisjoint a ⊤ := fun _ _ htop ↦ htop
theorem Codisjoint.mono (h₁ : a ≤ b) (h₂ : c ≤ d) : Codisjoint a c → Codisjoint b d :=
fun h _ ha hc ↦ h (h₁.trans ha) (h₂.trans hc)
theorem Codisjoint.mono_left (h : a ≤ b) : Codisjoint a c → Codisjoint b c :=
Codisjoint.mono h le_rfl
theorem Codisjoint.mono_right : b ≤ c → Codisjoint a b → Codisjoint a c :=
Codisjoint.mono le_rfl
@[simp]
theorem codisjoint_self : Codisjoint a a ↔ a = ⊤ :=
⟨fun hd ↦ top_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ h.symm.trans_le ha⟩
/- TODO: Rename `Codisjoint.eq_top` to `Codisjoint.sup_eq` and `Codisjoint.eq_top_of_self` to
`Codisjoint.eq_top` -/
alias ⟨Codisjoint.eq_top_of_self, _⟩ := codisjoint_self
theorem Codisjoint.ne (ha : a ≠ ⊤) (hab : Codisjoint a b) : a ≠ b :=
fun h ↦ ha <| codisjoint_self.1 <| by rwa [← h] at hab
theorem Codisjoint.eq_top_of_le (hab : Codisjoint a b) (h : b ≤ a) : a = ⊤ :=
eq_top_iff.2 <| hab le_rfl h
theorem Codisjoint.eq_top_of_ge (hab : Codisjoint a b) : a ≤ b → b = ⊤ :=
hab.symm.eq_top_of_le
lemma Codisjoint.eq_iff (hab : Codisjoint a b) : a = b ↔ a = ⊤ ∧ b = ⊤ := by aesop
lemma Codisjoint.ne_iff (hab : Codisjoint a b) : a ≠ b ↔ a ≠ ⊤ ∨ b ≠ ⊤ :=
hab.eq_iff.not.trans not_and_or
end PartialOrderTop
section PartialBoundedOrder
variable [PartialOrder α] [BoundedOrder α] {a b : α}
@[simp]
theorem codisjoint_bot : Codisjoint a ⊥ ↔ a = ⊤ :=
⟨fun h ↦ top_unique <| h le_rfl bot_le, fun h _ ha _ ↦ h.symm.trans_le ha⟩
@[simp]
theorem bot_codisjoint : Codisjoint ⊥ a ↔ a = ⊤ :=
⟨fun h ↦ top_unique <| h bot_le le_rfl, fun h _ _ ha ↦ h.symm.trans_le ha⟩
lemma Codisjoint.ne_bot_of_ne_top (h : Codisjoint a b) (ha : a ≠ ⊤) : b ≠ ⊥ := by
rintro rfl; exact ha <| by simpa using h
lemma Codisjoint.ne_bot_of_ne_top' (h : Codisjoint a b) (hb : b ≠ ⊤) : a ≠ ⊥ := by
rintro rfl; exact hb <| by simpa using h
end PartialBoundedOrder
section SemilatticeSupTop
variable [SemilatticeSup α] [OrderTop α] {a b c : α}
theorem codisjoint_iff_le_sup : Codisjoint a b ↔ ⊤ ≤ a ⊔ b :=
@disjoint_iff_inf_le αᵒᵈ _ _ _ _
theorem codisjoint_iff : Codisjoint a b ↔ a ⊔ b = ⊤ :=
@disjoint_iff αᵒᵈ _ _ _ _
theorem Codisjoint.top_le : Codisjoint a b → ⊤ ≤ a ⊔ b :=
@Disjoint.le_bot αᵒᵈ _ _ _ _
theorem Codisjoint.eq_top : Codisjoint a b → a ⊔ b = ⊤ :=
@Disjoint.eq_bot αᵒᵈ _ _ _ _
theorem codisjoint_assoc : Codisjoint (a ⊔ b) c ↔ Codisjoint a (b ⊔ c) :=
@disjoint_assoc αᵒᵈ _ _ _ _ _
theorem codisjoint_left_comm : Codisjoint a (b ⊔ c) ↔ Codisjoint b (a ⊔ c) :=
@disjoint_left_comm αᵒᵈ _ _ _ _ _
theorem codisjoint_right_comm : Codisjoint (a ⊔ b) c ↔ Codisjoint (a ⊔ c) b :=
@disjoint_right_comm αᵒᵈ _ _ _ _ _
variable (c)
theorem Codisjoint.sup_left (h : Codisjoint a b) : Codisjoint (a ⊔ c) b :=
h.mono_left le_sup_left
theorem Codisjoint.sup_left' (h : Codisjoint a b) : Codisjoint (c ⊔ a) b :=
h.mono_left le_sup_right
theorem Codisjoint.sup_right (h : Codisjoint a b) : Codisjoint a (b ⊔ c) :=
h.mono_right le_sup_left
theorem Codisjoint.sup_right' (h : Codisjoint a b) : Codisjoint a (c ⊔ b) :=
h.mono_right le_sup_right
variable {c}
theorem Codisjoint.of_codisjoint_sup_of_le (h : Codisjoint (a ⊔ b) c) (hle : c ≤ a) :
Codisjoint a b :=
@Disjoint.of_disjoint_inf_of_le αᵒᵈ _ _ _ _ _ h hle
theorem Codisjoint.of_codisjoint_sup_of_le' (h : Codisjoint (a ⊔ b) c) (hle : c ≤ b) :
Codisjoint a b :=
@Disjoint.of_disjoint_inf_of_le' αᵒᵈ _ _ _ _ _ h hle
end SemilatticeSupTop
section DistribLatticeTop
variable [DistribLattice α] [OrderTop α] {a b c : α}
@[simp]
theorem codisjoint_inf_left : Codisjoint (a ⊓ b) c ↔ Codisjoint a c ∧ Codisjoint b c := by
simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff]
@[simp]
theorem codisjoint_inf_right : Codisjoint a (b ⊓ c) ↔ Codisjoint a b ∧ Codisjoint a c := by
simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff]
theorem Codisjoint.inf_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⊓ b) c :=
codisjoint_inf_left.2 ⟨ha, hb⟩
theorem Codisjoint.inf_right (hb : Codisjoint a b) (hc : Codisjoint a c) : Codisjoint a (b ⊓ c) :=
codisjoint_inf_right.2 ⟨hb, hc⟩
theorem Codisjoint.left_le_of_le_inf_right (h : a ⊓ b ≤ c) (hd : Codisjoint b c) : a ≤ c :=
@Disjoint.left_le_of_le_sup_right αᵒᵈ _ _ _ _ _ h hd.symm
theorem Codisjoint.left_le_of_le_inf_left (h : b ⊓ a ≤ c) (hd : Codisjoint b c) : a ≤ c :=
hd.left_le_of_le_inf_right <| by rwa [inf_comm]
end DistribLatticeTop
end Codisjoint
open OrderDual
theorem Disjoint.dual [PartialOrder α] [OrderBot α] {a b : α} :
Disjoint a b → Codisjoint (toDual a) (toDual b) :=
id
theorem Codisjoint.dual [PartialOrder α] [OrderTop α] {a b : α} :
Codisjoint a b → Disjoint (toDual a) (toDual b) :=
id
@[simp]
theorem disjoint_toDual_iff [PartialOrder α] [OrderTop α] {a b : α} :
Disjoint (toDual a) (toDual b) ↔ Codisjoint a b :=
Iff.rfl
@[simp]
theorem disjoint_ofDual_iff [PartialOrder α] [OrderBot α] {a b : αᵒᵈ} :
Disjoint (ofDual a) (ofDual b) ↔ Codisjoint a b :=
Iff.rfl
@[simp]
theorem codisjoint_toDual_iff [PartialOrder α] [OrderBot α] {a b : α} :
Codisjoint (toDual a) (toDual b) ↔ Disjoint a b :=
Iff.rfl
@[simp]
theorem codisjoint_ofDual_iff [PartialOrder α] [OrderTop α] {a b : αᵒᵈ} :
Codisjoint (ofDual a) (ofDual b) ↔ Disjoint a b :=
Iff.rfl
section DistribLattice
variable [DistribLattice α] [BoundedOrder α] {a b c : α}
theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≤ c := by
rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right]
exact inf_le_inf_right _ le_sup_left
end DistribLattice
section IsCompl
/-- Two elements `x` and `y` are complements of each other if `x ⊔ y = ⊤` and `x ⊓ y = ⊥`. -/
structure IsCompl [PartialOrder α] [BoundedOrder α] (x y : α) : Prop where
/-- If `x` and `y` are to be complementary in an order, they should be disjoint. -/
protected disjoint : Disjoint x y
/-- If `x` and `y` are to be complementary in an order, they should be codisjoint. -/
protected codisjoint : Codisjoint x y
theorem isCompl_iff [PartialOrder α] [BoundedOrder α] {a b : α} :
IsCompl a b ↔ Disjoint a b ∧ Codisjoint a b :=
⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩
namespace IsCompl
section BoundedPartialOrder
variable [PartialOrder α] [BoundedOrder α] {x y : α}
@[symm]
protected theorem symm (h : IsCompl x y) : IsCompl y x :=
⟨h.1.symm, h.2.symm⟩
lemma _root_.isCompl_comm : IsCompl x y ↔ IsCompl y x := ⟨IsCompl.symm, IsCompl.symm⟩
theorem dual (h : IsCompl x y) : IsCompl (toDual x) (toDual y) :=
⟨h.2, h.1⟩
theorem ofDual {a b : αᵒᵈ} (h : IsCompl a b) : IsCompl (ofDual a) (ofDual b) :=
⟨h.2, h.1⟩
end BoundedPartialOrder
section BoundedLattice
variable [Lattice α] [BoundedOrder α] {x y : α}
theorem of_le (h₁ : x ⊓ y ≤ ⊥) (h₂ : ⊤ ≤ x ⊔ y) : IsCompl x y :=
⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr h₂⟩
theorem of_eq (h₁ : x ⊓ y = ⊥) (h₂ : x ⊔ y = ⊤) : IsCompl x y :=
⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr h₂⟩
theorem inf_eq_bot (h : IsCompl x y) : x ⊓ y = ⊥ :=
h.disjoint.eq_bot
theorem sup_eq_top (h : IsCompl x y) : x ⊔ y = ⊤ :=
h.codisjoint.eq_top
end BoundedLattice
variable [DistribLattice α] [BoundedOrder α] {a b x y z : α}
theorem inf_left_le_of_le_sup_right (h : IsCompl x y) (hle : a ≤ b ⊔ y) : a ⊓ x ≤ b :=
calc
a ⊓ x ≤ (b ⊔ y) ⊓ x := inf_le_inf hle le_rfl
_ = b ⊓ x ⊔ y ⊓ x := inf_sup_right _ _ _
_ = b ⊓ x := by rw [h.symm.inf_eq_bot, sup_bot_eq]
_ ≤ b := inf_le_left
theorem le_sup_right_iff_inf_left_le {a b} (h : IsCompl x y) : a ≤ b ⊔ y ↔ a ⊓ x ≤ b :=
⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩
theorem inf_left_eq_bot_iff (h : IsCompl y z) : x ⊓ y = ⊥ ↔ x ≤ z := by
rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq]
theorem inf_right_eq_bot_iff (h : IsCompl y z) : x ⊓ z = ⊥ ↔ x ≤ y :=
h.symm.inf_left_eq_bot_iff
theorem disjoint_left_iff (h : IsCompl y z) : Disjoint x y ↔ x ≤ z := by
rw [disjoint_iff]
exact h.inf_left_eq_bot_iff
theorem disjoint_right_iff (h : IsCompl y z) : Disjoint x z ↔ x ≤ y :=
h.symm.disjoint_left_iff
theorem le_left_iff (h : IsCompl x y) : z ≤ x ↔ Disjoint z y :=
h.disjoint_right_iff.symm
theorem le_right_iff (h : IsCompl x y) : z ≤ y ↔ Disjoint z x :=
h.symm.le_left_iff
theorem left_le_iff (h : IsCompl x y) : x ≤ z ↔ Codisjoint z y :=
h.dual.le_left_iff
theorem right_le_iff (h : IsCompl x y) : y ≤ z ↔ Codisjoint z x :=
h.symm.left_le_iff
protected theorem Antitone {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') (hx : x ≤ x') : y' ≤ y :=
h'.right_le_iff.2 <| h.symm.codisjoint.mono_right hx
theorem right_unique (hxy : IsCompl x y) (hxz : IsCompl x z) : y = z :=
le_antisymm (hxz.Antitone hxy <| le_refl x) (hxy.Antitone hxz <| le_refl x)
theorem left_unique (hxz : IsCompl x z) (hyz : IsCompl y z) : x = y :=
hxz.symm.right_unique hyz.symm
theorem sup_inf {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊔ x') (y ⊓ y') :=
of_eq
(by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm,
h'.inf_eq_bot, inf_bot_eq])
(by rw [sup_inf_left, sup_comm x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq,
sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq])
theorem inf_sup {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x ⊓ x') (y ⊔ y') :=
(h.symm.sup_inf h'.symm).symm
end IsCompl
namespace Prod
variable {β : Type*} [PartialOrder α] [PartialOrder β]
protected theorem disjoint_iff [OrderBot α] [OrderBot β] {x y : α × β} :
Disjoint x y ↔ Disjoint x.1 y.1 ∧ Disjoint x.2 y.2 := by
constructor
· intro h
refine ⟨fun a hx hy ↦ (@h (a, ⊥) ⟨hx, ?_⟩ ⟨hy, ?_⟩).1,
fun b hx hy ↦ (@h (⊥, b) ⟨?_, hx⟩ ⟨?_, hy⟩).2⟩
all_goals exact bot_le
· rintro ⟨ha, hb⟩ z hza hzb
exact ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩
protected theorem codisjoint_iff [OrderTop α] [OrderTop β] {x y : α × β} :
Codisjoint x y ↔ Codisjoint x.1 y.1 ∧ Codisjoint x.2 y.2 :=
@Prod.disjoint_iff αᵒᵈ βᵒᵈ _ _ _ _ _ _
protected theorem isCompl_iff [BoundedOrder α] [BoundedOrder β] {x y : α × β} :
IsCompl x y ↔ IsCompl x.1 y.1 ∧ IsCompl x.2 y.2 := by
simp_rw [isCompl_iff, Prod.disjoint_iff, Prod.codisjoint_iff, and_and_and_comm]
end Prod
section
variable [Lattice α] [BoundedOrder α] {a b x : α}
@[simp]
theorem isCompl_toDual_iff : IsCompl (toDual a) (toDual b) ↔ IsCompl a b :=
⟨IsCompl.ofDual, IsCompl.dual⟩
@[simp]
theorem isCompl_ofDual_iff {a b : αᵒᵈ} : IsCompl (ofDual a) (ofDual b) ↔ IsCompl a b :=
| ⟨IsCompl.dual, IsCompl.ofDual⟩
| Mathlib/Order/Disjoint.lean | 540 | 541 |
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.HasseDeriv
/-!
# Taylor expansions of polynomials
## Main declarations
* `Polynomial.taylor`: the Taylor expansion of the polynomial `f` at `r`
* `Polynomial.taylor_coeff`: the `k`th coefficient of `taylor r f` is
`(Polynomial.hasseDeriv k f).eval r`
* `Polynomial.eq_zero_of_hasseDeriv_eq_zero`:
the identity principle: a polynomial is 0 iff all its Hasse derivatives are zero
-/
noncomputable section
namespace Polynomial
variable {R : Type*} [Semiring R] (r : R) (f : R[X])
/-- The Taylor expansion of a polynomial `f` at `r`. -/
def taylor (r : R) : R[X] →ₗ[R] R[X] where
toFun f := f.comp (X + C r)
map_add' _ _ := add_comp
map_smul' c f := by simp only [smul_eq_C_mul, C_mul_comp, RingHom.id_apply]
theorem taylor_apply : taylor r f = f.comp (X + C r) :=
rfl
@[simp]
theorem taylor_X : taylor r X = X + C r := by simp only [taylor_apply, X_comp]
@[simp]
theorem taylor_C (x : R) : taylor r (C x) = C x := by simp only [taylor_apply, C_comp]
@[simp]
theorem taylor_zero' : taylor (0 : R) = LinearMap.id := by
ext
simp only [taylor_apply, add_zero, comp_X, map_zero, LinearMap.id_comp,
Function.comp_apply, LinearMap.coe_comp]
theorem taylor_zero (f : R[X]) : taylor 0 f = f := by rw [taylor_zero', LinearMap.id_apply]
@[simp]
theorem taylor_one : taylor r (1 : R[X]) = C 1 := by rw [← C_1, taylor_C]
@[simp]
theorem taylor_monomial (i : ℕ) (k : R) : taylor r (monomial i k) = C k * (X + C r) ^ i := by
simp [taylor_apply]
/-- The `k`th coefficient of `Polynomial.taylor r f` is `(Polynomial.hasseDeriv k f).eval r`. -/
theorem taylor_coeff (n : ℕ) : (taylor r f).coeff n = (hasseDeriv n f).eval r :=
show (lcoeff R n).comp (taylor r) f = (leval r).comp (hasseDeriv n) f by
congr 1; clear! f; ext i
simp only [leval_apply, mul_one, one_mul, eval_monomial, LinearMap.comp_apply, coeff_C_mul,
hasseDeriv_monomial, taylor_apply, monomial_comp, C_1, (commute_X (C r)).add_pow i,
map_sum]
simp only [lcoeff_apply, ← C_eq_natCast, mul_assoc, ← C_pow, ← C_mul, coeff_mul_C,
(Nat.cast_commute _ _).eq, coeff_X_pow, boole_mul, Finset.sum_ite_eq, Finset.mem_range]
split_ifs with h; · rfl
push_neg at h; rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero]
@[simp]
theorem taylor_coeff_zero : (taylor r f).coeff 0 = f.eval r := by
rw [taylor_coeff, hasseDeriv_zero, LinearMap.id_apply]
@[simp]
theorem taylor_coeff_one : (taylor r f).coeff 1 = f.derivative.eval r := by
rw [taylor_coeff, hasseDeriv_one]
@[simp]
theorem natDegree_taylor (p : R[X]) (r : R) : natDegree (taylor r p) = natDegree p := by
refine map_natDegree_eq_natDegree _ ?_
nontriviality R
intro n c c0
simp [taylor_monomial, natDegree_C_mul_of_mul_ne_zero, natDegree_pow_X_add_C, c0]
@[simp]
theorem taylor_mul {R} [CommSemiring R] (r : R) (p q : R[X]) :
taylor r (p * q) = taylor r p * taylor r q := by simp only [taylor_apply, mul_comp]
/-- `Polynomial.taylor` as an `AlgHom` for commutative semirings -/
@[simps!]
def taylorAlgHom {R} [CommSemiring R] (r : R) : R[X] →ₐ[R] R[X] :=
AlgHom.ofLinearMap (taylor r) (taylor_one r) (taylor_mul r)
theorem taylor_taylor {R} [CommSemiring R] (f : R[X]) (r s : R) :
taylor r (taylor s f) = taylor (r + s) f := by
simp only [taylor_apply, comp_assoc, map_add, add_comp, X_comp, C_comp, C_add, add_assoc]
theorem taylor_eval {R} [CommSemiring R] (r : R) (f : R[X]) (s : R) :
(taylor r f).eval s = f.eval (s + r) := by
simp only [taylor_apply, eval_comp, eval_C, eval_X, eval_add]
theorem taylor_eval_sub {R} [CommRing R] (r : R) (f : R[X]) (s : R) :
(taylor r f).eval (s - r) = f.eval s := by rw [taylor_eval, sub_add_cancel]
theorem taylor_injective {R} [CommRing R] (r : R) : Function.Injective (taylor r) := by
intro f g h
apply_fun taylor (-r) at h
simpa only [taylor_apply, comp_assoc, add_comp, X_comp, C_comp, C_neg, neg_add_cancel_right,
comp_X] using h
theorem eq_zero_of_hasseDeriv_eq_zero {R} [CommRing R] (f : R[X]) (r : R)
(h : ∀ k, (hasseDeriv k f).eval r = 0) : f = 0 := by
apply taylor_injective r
rw [LinearMap.map_zero]
ext k
simp only [taylor_coeff, h, coeff_zero]
/-- Taylor's formula. -/
theorem sum_taylor_eq {R} [CommRing R] (f : R[X]) (r : R) :
((taylor r f).sum fun i a => C a * (X - C r) ^ i) = f := by
rw [← comp_eq_sum_left, sub_eq_add_neg, ← C_neg, ← taylor_apply, taylor_taylor, neg_add_cancel,
taylor_zero]
theorem eval_add_of_sq_eq_zero {A} [CommSemiring A] (p : Polynomial A) (x y : A) (hy : y ^ 2 = 0) :
p.eval (x + y) = p.eval x + p.derivative.eval x * y := by
rw [add_comm, ← Polynomial.taylor_eval,
Polynomial.eval_eq_sum_range' ((Nat.lt_succ_self _).trans (Nat.lt_succ_self _)),
Finset.sum_range_succ', Finset.sum_range_succ']
simp [pow_succ, mul_assoc, ← pow_two, hy, add_comm (eval x p)]
end Polynomial
| Mathlib/Algebra/Polynomial/Taylor.lean | 146 | 149 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Thomas Browning
-/
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Data.SetLike.Fintype
import Mathlib.GroupTheory.PGroup
import Mathlib.GroupTheory.NoncommPiCoprod
/-!
# Sylow theorems
The Sylow theorems are the following results for every finite group `G` and every prime number `p`.
* There exists a Sylow `p`-subgroup of `G`.
* All Sylow `p`-subgroups of `G` are conjugate to each other.
* Let `nₚ` be the number of Sylow `p`-subgroups of `G`, then `nₚ` divides the index of the Sylow
`p`-subgroup, `nₚ ≡ 1 [MOD p]`, and `nₚ` is equal to the index of the normalizer of the Sylow
`p`-subgroup in `G`.
## Main definitions
* `Sylow p G` : The type of Sylow `p`-subgroups of `G`.
## Main statements
* `Sylow.exists_subgroup_card_pow_prime`: A generalization of Sylow's first theorem:
For every prime power `pⁿ` dividing the cardinality of `G`,
there exists a subgroup of `G` of order `pⁿ`.
* `IsPGroup.exists_le_sylow`: A generalization of Sylow's first theorem:
Every `p`-subgroup is contained in a Sylow `p`-subgroup.
* `Sylow.card_eq_multiplicity`: The cardinality of a Sylow subgroup is `p ^ n`
where `n` is the multiplicity of `p` in the group order.
* `Sylow.isPretransitive_of_finite`: a generalization of Sylow's second theorem:
If the number of Sylow `p`-subgroups is finite, then all Sylow `p`-subgroups are conjugate.
* `card_sylow_modEq_one`: a generalization of Sylow's third theorem:
If the number of Sylow `p`-subgroups is finite, then it is congruent to `1` modulo `p`.
-/
open MulAction Subgroup
section InfiniteSylow
variable (p : ℕ) (G : Type*) [Group G]
/-- A Sylow `p`-subgroup is a maximal `p`-subgroup. -/
structure Sylow extends Subgroup G where
isPGroup' : IsPGroup p toSubgroup
is_maximal' : ∀ {Q : Subgroup G}, IsPGroup p Q → toSubgroup ≤ Q → Q = toSubgroup
variable {p} {G}
namespace Sylow
attribute [coe] toSubgroup
instance : CoeOut (Sylow p G) (Subgroup G) :=
⟨toSubgroup⟩
@[ext]
theorem ext {P Q : Sylow p G} (h : (P : Subgroup G) = Q) : P = Q := by cases P; cases Q; congr
instance : SetLike (Sylow p G) G where
coe := (↑)
coe_injective' _ _ h := ext (SetLike.coe_injective h)
instance : SubgroupClass (Sylow p G) G where
mul_mem := Subgroup.mul_mem _
one_mem _ := Subgroup.one_mem _
inv_mem := Subgroup.inv_mem _
/-- A `p`-subgroup with index indivisible by `p` is a Sylow subgroup. -/
def _root_.IsPGroup.toSylow [Fact p.Prime] {P : Subgroup G}
(hP1 : IsPGroup p P) (hP2 : ¬ p ∣ P.index) : Sylow p G :=
{ P with
isPGroup' := hP1
is_maximal' := by
intro Q hQ hPQ
have : P.FiniteIndex := ⟨fun h ↦ hP2 (h ▸ (dvd_zero p))⟩
obtain ⟨k, hk⟩ := (hQ.to_quotient (P.normalCore.subgroupOf Q)).exists_card_eq
have h := hk ▸ Nat.Prime.coprime_pow_of_not_dvd (m := k) Fact.out hP2
exact le_antisymm (Subgroup.relindex_eq_one.mp
(Nat.eq_one_of_dvd_coprimes h (Subgroup.relindex_dvd_index_of_le hPQ)
(Subgroup.relindex_dvd_of_le_left Q P.normalCore_le))) hPQ }
@[simp] theorem _root_.IsPGroup.toSylow_coe [Fact p.Prime] {P : Subgroup G}
(hP1 : IsPGroup p P) (hP2 : ¬ p ∣ P.index) : (hP1.toSylow hP2) = P :=
rfl
@[simp] theorem _root_.IsPGroup.mem_toSylow [Fact p.Prime] {P : Subgroup G}
(hP1 : IsPGroup p P) (hP2 : ¬ p ∣ P.index) {g : G} : g ∈ hP1.toSylow hP2 ↔ g ∈ P :=
.rfl
/-- A subgroup with cardinality `p ^ n` is a Sylow subgroup
where `n` is the multiplicity of `p` in the group order. -/
def ofCard [Finite G] {p : ℕ} [Fact p.Prime] (H : Subgroup G)
(card_eq : Nat.card H = p ^ (Nat.card G).factorization p) : Sylow p G :=
(IsPGroup.of_card card_eq).toSylow (by
rw [← mul_dvd_mul_iff_left (Nat.card_pos (α := H)).ne', card_mul_index, card_eq, ← pow_succ]
exact Nat.pow_succ_factorization_not_dvd Nat.card_pos.ne' Fact.out)
@[simp, norm_cast]
theorem coe_ofCard [Finite G] {p : ℕ} [Fact p.Prime] (H : Subgroup G)
(card_eq : Nat.card H = p ^ (Nat.card G).factorization p) : ofCard H card_eq = H :=
rfl
variable (P : Sylow p G)
variable {K : Type*} [Group K] (ϕ : K →* G) {N : Subgroup G}
/-- The preimage of a Sylow subgroup under a p-group-kernel homomorphism is a Sylow subgroup. -/
def comapOfKerIsPGroup (hϕ : IsPGroup p ϕ.ker) (h : P ≤ ϕ.range) : Sylow p K :=
{ P.1.comap ϕ with
isPGroup' := P.2.comap_of_ker_isPGroup ϕ hϕ
is_maximal' := fun {Q} hQ hle => by
show Q = P.1.comap ϕ
rw [← P.3 (hQ.map ϕ) (le_trans (ge_of_eq (map_comap_eq_self h)) (map_mono hle))]
exact (comap_map_eq_self ((P.1.ker_le_comap ϕ).trans hle)).symm }
@[simp]
theorem coe_comapOfKerIsPGroup (hϕ : IsPGroup p ϕ.ker) (h : P ≤ ϕ.range) :
P.comapOfKerIsPGroup ϕ hϕ h = P.comap ϕ :=
rfl
/-- The preimage of a Sylow subgroup under an injective homomorphism is a Sylow subgroup. -/
def comapOfInjective (hϕ : Function.Injective ϕ) (h : P ≤ ϕ.range) : Sylow p K :=
P.comapOfKerIsPGroup ϕ (IsPGroup.ker_isPGroup_of_injective hϕ) h
@[simp]
theorem coe_comapOfInjective (hϕ : Function.Injective ϕ) (h : P ≤ ϕ.range) :
P.comapOfInjective ϕ hϕ h = P.comap ϕ :=
rfl
/-- A sylow subgroup of G is also a sylow subgroup of a subgroup of G. -/
protected def subtype (h : P ≤ N) : Sylow p N :=
P.comapOfInjective N.subtype Subtype.coe_injective (by rwa [range_subtype])
@[simp]
theorem coe_subtype (h : P ≤ N) : P.subtype h = subgroupOf P N :=
rfl
theorem subtype_injective {P Q : Sylow p G} {hP : P ≤ N} {hQ : Q ≤ N}
(h : P.subtype hP = Q.subtype hQ) : P = Q := by
rw [SetLike.ext_iff] at h ⊢
exact fun g => ⟨fun hg => (h ⟨g, hP hg⟩).mp hg, fun hg => (h ⟨g, hQ hg⟩).mpr hg⟩
end Sylow
/-- A generalization of **Sylow's first theorem**.
Every `p`-subgroup is contained in a Sylow `p`-subgroup. -/
theorem IsPGroup.exists_le_sylow {P : Subgroup G} (hP : IsPGroup p P) : ∃ Q : Sylow p G, P ≤ Q :=
Exists.elim
(zorn_le_nonempty₀ { Q : Subgroup G | IsPGroup p Q }
(fun c hc1 hc2 Q hQ =>
⟨{ carrier := ⋃ R : c, R
one_mem' := ⟨Q, ⟨⟨Q, hQ⟩, rfl⟩, Q.one_mem⟩
inv_mem' := fun {_} ⟨_, ⟨R, rfl⟩, hg⟩ => ⟨R, ⟨R, rfl⟩, R.1.inv_mem hg⟩
mul_mem' := fun {_} _ ⟨_, ⟨R, rfl⟩, hg⟩ ⟨_, ⟨S, rfl⟩, hh⟩ =>
(hc2.total R.2 S.2).elim (fun T => ⟨S, ⟨S, rfl⟩, S.1.mul_mem (T hg) hh⟩) fun T =>
⟨R, ⟨R, rfl⟩, R.1.mul_mem hg (T hh)⟩ },
fun ⟨g, _, ⟨S, rfl⟩, hg⟩ => by
refine Exists.imp (fun k hk => ?_) (hc1 S.2 ⟨g, hg⟩)
rwa [Subtype.ext_iff, coe_pow] at hk ⊢, fun M hM _ hg => ⟨M, ⟨⟨M, hM⟩, rfl⟩, hg⟩⟩)
P hP)
fun {Q} h => ⟨⟨Q, h.2.prop, h.2.eq_of_ge⟩, h.1⟩
namespace Sylow
instance nonempty : Nonempty (Sylow p G) :=
nonempty_of_exists IsPGroup.of_bot.exists_le_sylow
noncomputable instance inhabited : Inhabited (Sylow p G) :=
Classical.inhabited_of_nonempty nonempty
theorem exists_comap_eq_of_ker_isPGroup {H : Type*} [Group H] (P : Sylow p H) {f : H →* G}
(hf : IsPGroup p f.ker) : ∃ Q : Sylow p G, Q.comap f = P :=
Exists.imp (fun Q hQ => P.3 (Q.2.comap_of_ker_isPGroup f hf) (map_le_iff_le_comap.mp hQ))
(P.2.map f).exists_le_sylow
theorem exists_comap_eq_of_injective {H : Type*} [Group H] (P : Sylow p H) {f : H →* G}
(hf : Function.Injective f) : ∃ Q : Sylow p G, Q.comap f = P :=
P.exists_comap_eq_of_ker_isPGroup (IsPGroup.ker_isPGroup_of_injective hf)
theorem exists_comap_subtype_eq {H : Subgroup G} (P : Sylow p H) :
∃ Q : Sylow p G, Q.comap H.subtype = P :=
P.exists_comap_eq_of_injective Subtype.coe_injective
/-- If the kernel of `f : H →* G` is a `p`-group,
then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/
theorem finite_of_ker_is_pGroup {H : Type*} [Group H] {f : H →* G}
(hf : IsPGroup p f.ker) [Finite (Sylow p G)] : Finite (Sylow p H) :=
let h_exists := fun P : Sylow p H => P.exists_comap_eq_of_ker_isPGroup hf
let g : Sylow p H → Sylow p G := fun P => Classical.choose (h_exists P)
have hg : ∀ P : Sylow p H, (g P).1.comap f = P := fun P => Classical.choose_spec (h_exists P)
Finite.of_injective g fun P Q h => ext (by rw [← hg, h]; exact (h_exists Q).choose_spec)
/-- If `f : H →* G` is injective, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/
theorem finite_of_injective {H : Type*} [Group H] {f : H →* G}
(hf : Function.Injective f) [Finite (Sylow p G)] : Finite (Sylow p H) :=
finite_of_ker_is_pGroup (IsPGroup.ker_isPGroup_of_injective hf)
/-- If `H` is a subgroup of `G`, then `Finite (Sylow p G)` implies `Finite (Sylow p H)`. -/
instance (H : Subgroup G) [Finite (Sylow p G)] : Finite (Sylow p H) :=
finite_of_injective H.subtype_injective
open Pointwise
/-- `Subgroup.pointwiseMulAction` preserves Sylow subgroups. -/
instance pointwiseMulAction {α : Type*} [Group α] [MulDistribMulAction α G] :
MulAction α (Sylow p G) where
smul g P :=
⟨g • P.toSubgroup, P.2.map _, fun {Q} hQ hS =>
inv_smul_eq_iff.mp
(P.3 (hQ.map _) fun s hs =>
(congr_arg (· ∈ g⁻¹ • Q) (inv_smul_smul g s)).mp
(smul_mem_pointwise_smul (g • s) g⁻¹ Q (hS (smul_mem_pointwise_smul s g P hs))))⟩
one_smul P := ext (one_smul α P.toSubgroup)
mul_smul g h P := ext (mul_smul g h P.toSubgroup)
theorem pointwise_smul_def {α : Type*} [Group α] [MulDistribMulAction α G] {g : α}
{P : Sylow p G} : ↑(g • P) = g • (P : Subgroup G) :=
rfl
instance mulAction : MulAction G (Sylow p G) :=
compHom _ MulAut.conj
theorem smul_def {g : G} {P : Sylow p G} : g • P = MulAut.conj g • P :=
rfl
theorem coe_subgroup_smul {g : G} {P : Sylow p G} :
↑(g • P) = MulAut.conj g • (P : Subgroup G) :=
rfl
theorem coe_smul {g : G} {P : Sylow p G} : ↑(g • P) = MulAut.conj g • (P : Set G) :=
rfl
theorem smul_le {P : Sylow p G} {H : Subgroup G} (hP : P ≤ H) (h : H) : ↑(h • P) ≤ H :=
Subgroup.conj_smul_le_of_le hP h
theorem smul_subtype {P : Sylow p G} {H : Subgroup G} (hP : P ≤ H) (h : H) :
h • P.subtype hP = (h • P).subtype (smul_le hP h) :=
ext (Subgroup.conj_smul_subgroupOf hP h)
theorem smul_eq_iff_mem_normalizer {g : G} {P : Sylow p G} :
g • P = P ↔ g ∈ P.normalizer := by
rw [eq_comm, SetLike.ext_iff, ← inv_mem_iff (G := G) (H := normalizer P.toSubgroup),
mem_normalizer_iff, inv_inv]
exact
forall_congr' fun h =>
iff_congr Iff.rfl
⟨fun ⟨a, b, c⟩ => c ▸ by simpa [mul_assoc] using b,
fun hh => ⟨(MulAut.conj g)⁻¹ h, hh, MulAut.apply_inv_self G (MulAut.conj g) h⟩⟩
theorem smul_eq_of_normal {g : G} {P : Sylow p G} [h : P.Normal] :
g • P = P := by simp only [smul_eq_iff_mem_normalizer, P.normalizer_eq_top, mem_top]
end Sylow
theorem Subgroup.sylow_mem_fixedPoints_iff (H : Subgroup G) {P : Sylow p G} :
P ∈ fixedPoints H (Sylow p G) ↔ H ≤ P.normalizer := by
simp_rw [SetLike.le_def, ← Sylow.smul_eq_iff_mem_normalizer]; exact Subtype.forall
theorem IsPGroup.inf_normalizer_sylow {P : Subgroup G} (hP : IsPGroup p P) (Q : Sylow p G) :
P ⊓ Q.normalizer = P ⊓ Q :=
le_antisymm
(le_inf inf_le_left
(sup_eq_right.mp
(Q.3 (hP.to_inf_left.to_sup_of_normal_right' Q.2 inf_le_right) le_sup_right)))
(inf_le_inf_left P le_normalizer)
theorem IsPGroup.sylow_mem_fixedPoints_iff {P : Subgroup G} (hP : IsPGroup p P) {Q : Sylow p G} :
Q ∈ fixedPoints P (Sylow p G) ↔ P ≤ Q := by
rw [P.sylow_mem_fixedPoints_iff, ← inf_eq_left, hP.inf_normalizer_sylow, inf_eq_left]
/-- A generalization of **Sylow's second theorem**.
If the number of Sylow `p`-subgroups is finite, then all Sylow `p`-subgroups are conjugate. -/
instance Sylow.isPretransitive_of_finite [hp : Fact p.Prime] [Finite (Sylow p G)] :
IsPretransitive G (Sylow p G) :=
⟨fun P Q => by
classical
have H := fun {R : Sylow p G} {S : orbit G P} =>
calc
S ∈ fixedPoints R (orbit G P) ↔ S.1 ∈ fixedPoints R (Sylow p G) :=
forall_congr' fun a => Subtype.ext_iff
_ ↔ R.1 ≤ S := R.2.sylow_mem_fixedPoints_iff
_ ↔ S.1.1 = R := ⟨fun h => R.3 S.1.2 h, ge_of_eq⟩
suffices Set.Nonempty (fixedPoints Q (orbit G P)) by
exact Exists.elim this fun R hR => by
rw [← Sylow.ext (H.mp hR)]
exact R.2
apply Q.2.nonempty_fixed_point_of_prime_not_dvd_card
refine fun h => hp.out.not_dvd_one (Nat.modEq_zero_iff_dvd.mp ?_)
calc
1 = Nat.card (fixedPoints P (orbit G P)) := ?_
_ ≡ Nat.card (orbit G P) [MOD p] := (P.2.card_modEq_card_fixedPoints (orbit G P)).symm
_ ≡ 0 [MOD p] := Nat.modEq_zero_iff_dvd.mpr h
rw [← Nat.card_unique (α := ({⟨P, mem_orbit_self P⟩} : Set (orbit G P))), eq_comm]
congr
rw [Set.eq_singleton_iff_unique_mem]
exact ⟨H.mpr rfl, fun R h => Subtype.ext (Sylow.ext (H.mp h))⟩⟩
variable (p) (G)
/-- A generalization of **Sylow's third theorem**.
If the number of Sylow `p`-subgroups is finite, then it is congruent to `1` modulo `p`. -/
theorem card_sylow_modEq_one [Fact p.Prime] [Finite (Sylow p G)] :
Nat.card (Sylow p G) ≡ 1 [MOD p] := by
refine Sylow.nonempty.elim fun P : Sylow p G => ?_
have : fixedPoints P.1 (Sylow p G) = {P} :=
Set.ext fun Q : Sylow p G =>
calc
Q ∈ fixedPoints P (Sylow p G) ↔ P.1 ≤ Q := P.2.sylow_mem_fixedPoints_iff
_ ↔ Q.1 = P.1 := ⟨P.3 Q.2, ge_of_eq⟩
_ ↔ Q ∈ {P} := Sylow.ext_iff.symm.trans Set.mem_singleton_iff.symm
have : Nat.card (fixedPoints P.1 (Sylow p G)) = 1 := by simp [this]
exact (P.2.card_modEq_card_fixedPoints (Sylow p G)).trans (by rw [this])
theorem not_dvd_card_sylow [hp : Fact p.Prime] [Finite (Sylow p G)] : ¬p ∣ Nat.card (Sylow p G) :=
fun h =>
hp.1.ne_one
(Nat.dvd_one.mp
((Nat.modEq_iff_dvd' zero_le_one).mp
((Nat.modEq_zero_iff_dvd.mpr h).symm.trans (card_sylow_modEq_one p G))))
variable {p} {G}
namespace Sylow
/-- Sylow subgroups are isomorphic -/
nonrec def equivSMul (P : Sylow p G) (g : G) : P ≃* (g • P : Sylow p G) :=
equivSMul (MulAut.conj g) P.toSubgroup
/-- Sylow subgroups are isomorphic -/
noncomputable def equiv [Fact p.Prime] [Finite (Sylow p G)] (P Q : Sylow p G) : P ≃* Q := by
rw [← Classical.choose_spec (exists_smul_eq G P Q)]
exact P.equivSMul (Classical.choose (exists_smul_eq G P Q))
@[simp]
theorem orbit_eq_top [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) : orbit G P = ⊤ :=
top_le_iff.mp fun Q _ => exists_smul_eq G P Q
theorem stabilizer_eq_normalizer (P : Sylow p G) :
stabilizer G P = P.normalizer := by
ext; simp [smul_eq_iff_mem_normalizer]
theorem conj_eq_normalizer_conj_of_mem_centralizer [Fact p.Prime] [Finite (Sylow p G)]
(P : Sylow p G) (x g : G) (hx : x ∈ centralizer P)
(hy : g⁻¹ * x * g ∈ centralizer P) :
∃ n ∈ P.normalizer, g⁻¹ * x * g = n⁻¹ * x * n := by
have h1 : P ≤ centralizer (zpowers x : Set G) := by rwa [le_centralizer_iff, zpowers_le]
have h2 : ↑(g • P) ≤ centralizer (zpowers x : Set G) := by
rw [le_centralizer_iff, zpowers_le]
rintro - ⟨z, hz, rfl⟩
specialize hy z hz
rwa [← mul_assoc, ← eq_mul_inv_iff_mul_eq, mul_assoc, mul_assoc, mul_assoc, ← mul_assoc,
eq_inv_mul_iff_mul_eq, ← mul_assoc, ← mul_assoc] at hy
obtain ⟨h, hh⟩ :=
exists_smul_eq (centralizer (zpowers x : Set G)) ((g • P).subtype h2) (P.subtype h1)
simp_rw [smul_subtype, Subgroup.smul_def, smul_smul] at hh
refine ⟨h * g, smul_eq_iff_mem_normalizer.mp (subtype_injective hh), ?_⟩
rw [← mul_assoc, Commute.right_comm (h.prop x (mem_zpowers x)), mul_inv_rev, inv_mul_cancel_right]
theorem conj_eq_normalizer_conj_of_mem [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G)
[_hP : IsMulCommutative P] (x g : G) (hx : x ∈ P) (hy : g⁻¹ * x * g ∈ P) :
∃ n ∈ P.normalizer, g⁻¹ * x * g = n⁻¹ * x * n :=
P.conj_eq_normalizer_conj_of_mem_centralizer x g
(P.le_centralizer hx) (P.le_centralizer hy)
/-- Sylow `p`-subgroups are in bijection with cosets of the normalizer of a Sylow `p`-subgroup -/
noncomputable def equivQuotientNormalizer [Fact p.Prime] [Finite (Sylow p G)]
(P : Sylow p G) : Sylow p G ≃ G ⧸ P.normalizer :=
calc
Sylow p G ≃ (⊤ : Set (Sylow p G)) := (Equiv.Set.univ (Sylow p G)).symm
_ ≃ orbit G P := Equiv.setCongr P.orbit_eq_top.symm
_ ≃ G ⧸ stabilizer G P := orbitEquivQuotientStabilizer G P
_ ≃ G ⧸ P.normalizer := by rw [P.stabilizer_eq_normalizer]
instance [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) :
Finite (G ⧸ P.normalizer) :=
Finite.of_equiv (Sylow p G) P.equivQuotientNormalizer
theorem card_eq_card_quotient_normalizer [Fact p.Prime] [Finite (Sylow p G)]
(P : Sylow p G) : Nat.card (Sylow p G) = Nat.card (G ⧸ P.normalizer) :=
Nat.card_congr P.equivQuotientNormalizer
@[deprecated (since := "2024-11-07")]
alias _root_.card_sylow_eq_card_quotient_normalizer := card_eq_card_quotient_normalizer
theorem card_eq_index_normalizer [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) :
Nat.card (Sylow p G) = P.normalizer.index :=
P.card_eq_card_quotient_normalizer
@[deprecated (since := "2024-11-07")]
alias _root_.card_sylow_eq_index_normalizer := card_eq_index_normalizer
theorem card_dvd_index [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) :
Nat.card (Sylow p G) ∣ P.index :=
((congr_arg _ P.card_eq_index_normalizer).mp dvd_rfl).trans
(index_dvd_of_le le_normalizer)
@[deprecated (since := "2024-11-07")]
alias _root_.card_sylow_dvd_index := card_dvd_index
/-- Auxiliary lemma for `Sylow.not_dvd_index` which is strictly stronger. -/
private theorem not_dvd_index_aux [hp : Fact p.Prime] (P : Sylow p G) [P.Normal]
[P.FiniteIndex] : ¬ p ∣ P.index := by
intro h
rw [P.index_eq_card] at h
obtain ⟨x, hx⟩ := exists_prime_orderOf_dvd_card' (G := G ⧸ (P : Subgroup G)) p h
have h := IsPGroup.of_card (((Nat.card_zpowers x).trans hx).trans (pow_one p).symm)
let Q := (zpowers x).comap (QuotientGroup.mk' (P : Subgroup G))
have hQ : IsPGroup p Q := by
apply h.comap_of_ker_isPGroup
rw [QuotientGroup.ker_mk']
exact P.2
replace hp := mt orderOf_eq_one_iff.mpr (ne_of_eq_of_ne hx hp.1.ne_one)
rw [← zpowers_eq_bot, ← Ne, ← bot_lt_iff_ne_bot, ←
comap_lt_comap_of_surjective (QuotientGroup.mk'_surjective _), MonoidHom.comap_bot,
QuotientGroup.ker_mk'] at hp
exact hp.ne' (P.3 hQ hp.le)
/-- A Sylow p-subgroup has index indivisible by `p`, assuming [N(P) : P] < ∞. -/
theorem not_dvd_index' [hp : Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G)
(hP : P.relindex P.normalizer ≠ 0) : ¬ p ∣ P.index := by
rw [← relindex_mul_index le_normalizer, ← card_eq_index_normalizer]
haveI : (P.subtype le_normalizer).Normal :=
Subgroup.normal_in_normalizer
haveI : (P.subtype le_normalizer).FiniteIndex := ⟨hP⟩
replace hP := not_dvd_index_aux (P.subtype le_normalizer)
exact hp.1.not_dvd_mul hP (not_dvd_card_sylow p G)
@[deprecated (since := "2024-11-03")]
alias _root_.not_dvd_index_sylow := not_dvd_index'
/-- A Sylow p-subgroup has index indivisible by `p`. -/
theorem not_dvd_index [Fact p.Prime] [Finite (Sylow p G)] (P : Sylow p G) [P.FiniteIndex] :
¬ p ∣ P.index :=
P.not_dvd_index' Nat.card_pos.ne'
@[deprecated (since := "2024-11-03")]
alias _root_.not_dvd_index_sylow' := not_dvd_index
section mapSurjective
variable [Finite G] {G' : Type*} [Group G'] {f : G →* G'} (hf : Function.Surjective f)
/-- Surjective group homomorphisms map Sylow subgroups to Sylow subgroups. -/
def mapSurjective [Fact p.Prime] (P : Sylow p G) : Sylow p G' :=
{ P.1.map f with
isPGroup' := P.2.map f
is_maximal' := fun hQ hPQ ↦ ((P.2.map f).toSylow
(fun h ↦ P.not_dvd_index (h.trans (P.index_map_dvd hf)))).3 hQ hPQ }
@[simp] theorem coe_mapSurjective [Fact p.Prime] (P : Sylow p G) : P.mapSurjective hf = P.map f :=
rfl
theorem mapSurjective_surjective (p : ℕ) [Fact p.Prime] :
Function.Surjective (Sylow.mapSurjective hf : Sylow p G → Sylow p G') := by
have : Finite G' := Finite.of_surjective f hf
intro P
let Q₀ : Sylow p (P.comap f) := Sylow.nonempty.some
let Q : Subgroup G := Q₀.map (P.comap f).subtype
have hPQ : Q.map f ≤ P := Subgroup.map_le_iff_le_comap.mpr (Subgroup.map_subtype_le Q₀.1)
have hpQ : IsPGroup p Q := Q₀.2.map (P.comap f).subtype
have hQ : ¬ p ∣ Q.index := by
rw [Subgroup.index_map_subtype Q₀.1, P.index_comap_of_surjective hf]
exact Nat.Prime.not_dvd_mul Fact.out Q₀.not_dvd_index P.not_dvd_index
use hpQ.toSylow hQ
rw [Sylow.ext_iff, Sylow.coe_mapSurjective, eq_comm]
exact ((hpQ.map f).toSylow (fun h ↦ hQ (h.trans (Q.index_map_dvd hf)))).3 P.2 hPQ
end mapSurjective
/-- **Frattini's Argument**: If `N` is a normal subgroup of `G`, and if `P` is a Sylow `p`-subgroup
| of `N`, then `N_G(P) ⊔ N = G`. -/
theorem normalizer_sup_eq_top {p : ℕ} [Fact p.Prime] {N : Subgroup G} [N.Normal]
[Finite (Sylow p N)] (P : Sylow p N) :
(P.map N.subtype).normalizer ⊔ N = ⊤ := by
| Mathlib/GroupTheory/Sylow.lean | 477 | 480 |
/-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.GroupTheory.CoprodI
import Mathlib.GroupTheory.Coprod.Basic
import Mathlib.GroupTheory.Complement
/-!
## Pushouts of Monoids and Groups
This file defines wide pushouts of monoids and groups and proves some properties
of the amalgamated product of groups (i.e. the special case where all the maps
in the diagram are injective).
## Main definitions
- `Monoid.PushoutI`: the pushout of a diagram of monoids indexed by a type `ι`
- `Monoid.PushoutI.base`: the map from the amalgamating monoid to the pushout
- `Monoid.PushoutI.of`: the map from each Monoid in the family to the pushout
- `Monoid.PushoutI.lift`: the universal property used to define homomorphisms out of the pushout.
- `Monoid.PushoutI.NormalWord`: a normal form for words in the pushout
- `Monoid.PushoutI.of_injective`: if all the maps in the diagram are injective in a pushout of
groups then so is `of`
- `Monoid.PushoutI.Reduced.eq_empty_of_mem_range`: For any word `w` in the coproduct,
if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then
`w` itself is not in the image of the base monoid.
## References
* The normal form theorem follows these [notes](https://webspace.maths.qmul.ac.uk/i.m.chiswell/ggt/lecture_notes/lecture2.pdf)
from Queen Mary University
## Tags
amalgamated product, pushout, group
-/
namespace Monoid
open CoprodI Subgroup Coprod Function List
variable {ι : Type*} {G : ι → Type*} {H : Type*} {K : Type*} [Monoid K]
/-- The relation we quotient by to form the pushout -/
def PushoutI.con [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) :
Con (Coprod (CoprodI G) H) :=
conGen (fun x y : Coprod (CoprodI G) H =>
∃ i x', x = inl (of (φ i x')) ∧ y = inr x')
/-- The indexed pushout of monoids, which is the pushout in the category of monoids,
or the category of groups. -/
def PushoutI [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Type _ :=
(PushoutI.con φ).Quotient
namespace PushoutI
section Monoid
variable [∀ i, Monoid (G i)] [Monoid H] {φ : ∀ i, H →* G i}
protected instance mul : Mul (PushoutI φ) := by
delta PushoutI; infer_instance
protected instance one : One (PushoutI φ) := by
delta PushoutI; infer_instance
instance monoid : Monoid (PushoutI φ) :=
{ Con.monoid _ with
toMul := PushoutI.mul
toOne := PushoutI.one }
/-- The map from each indexing group into the pushout -/
def of (i : ι) : G i →* PushoutI φ :=
(Con.mk' _).comp <| inl.comp CoprodI.of
variable (φ) in
/-- The map from the base monoid into the pushout -/
def base : H →* PushoutI φ :=
(Con.mk' _).comp inr
theorem of_comp_eq_base (i : ι) : (of i).comp (φ i) = (base φ) := by
ext x
apply (Con.eq _).2
refine ConGen.Rel.of _ _ ?_
simp only [MonoidHom.comp_apply, Set.mem_iUnion, Set.mem_range]
exact ⟨_, _, rfl, rfl⟩
variable (φ) in
theorem of_apply_eq_base (i : ι) (x : H) : of i (φ i x) = base φ x := by
| rw [← MonoidHom.comp_apply, of_comp_eq_base]
| Mathlib/GroupTheory/PushoutI.lean | 96 | 97 |
/-
Copyright (c) 2023 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Richard M. Hill
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Module.AEval
import Mathlib.RingTheory.Adjoin.Polynomial
import Mathlib.RingTheory.Derivation.Basic
/-!
# Derivations of univariate polynomials
In this file we prove that an `R`-derivation of `Polynomial R` is determined by its value on `X`.
We also provide a constructor `Polynomial.mkDerivation` that
builds a derivation from its value on `X`, and a linear equivalence
`Polynomial.mkDerivationEquiv` between `A` and `Derivation (Polynomial R) A`.
-/
noncomputable section
namespace Polynomial
section CommSemiring
variable {R A : Type*} [CommSemiring R]
/-- `Polynomial.derivative` as a derivation. -/
@[simps]
def derivative' : Derivation R R[X] R[X] where
toFun := derivative
map_add' _ _ := derivative_add
map_smul' := derivative_smul
map_one_eq_zero' := derivative_one
leibniz' f g := by simp [mul_comm, add_comm, derivative_mul]
variable [AddCommMonoid A] [Module R A] [Module (Polynomial R) A]
@[simp]
theorem derivation_C (D : Derivation R R[X] A) (a : R) : D (C a) = 0 :=
D.map_algebraMap a
@[simp]
theorem C_smul_derivation_apply (D : Derivation R R[X] A) (a : R) (f : R[X]) :
C a • D f = a • D f := by
have : C a • D f = D (C a * f) := by simp
rw [this, C_mul', D.map_smul]
| @[ext]
theorem derivation_ext {D₁ D₂ : Derivation R R[X] A} (h : D₁ X = D₂ X) : D₁ = D₂ :=
Derivation.ext fun f => Derivation.eqOn_adjoin (Set.eqOn_singleton.2 h) <| by
| Mathlib/Algebra/Polynomial/Derivation.lean | 49 | 51 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland
-/
import Mathlib.Algebra.Ring.Semiconj
import Mathlib.Algebra.Ring.Units
import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Data.Bracket
/-!
# Semirings and rings
This file gives lemmas about semirings, rings and domains.
This is analogous to `Mathlib.Algebra.Group.Basic`,
the difference being that the former is about `+` and `*` separately, while
the present file is about their interaction.
For the definitions of semirings and rings see `Mathlib.Algebra.Ring.Defs`.
-/
universe u
variable {R : Type u}
open Function
namespace Commute
@[simp]
theorem add_right [Distrib R] {a b c : R} : Commute a b → Commute a c → Commute a (b + c) :=
SemiconjBy.add_right
-- for some reason mathport expected `Semiring` instead of `Distrib`?
@[simp]
theorem add_left [Distrib R] {a b c : R} : Commute a c → Commute b c → Commute (a + b) c :=
SemiconjBy.add_left
-- for some reason mathport expected `Semiring` instead of `Distrib`?
/-- Representation of a difference of two squares of commuting elements as a product. -/
theorem mul_self_sub_mul_self_eq [NonUnitalNonAssocRing R] {a b : R} (h : Commute a b) :
a * a - b * b = (a + b) * (a - b) := by
rw [add_mul, mul_sub, mul_sub, h.eq, sub_add_sub_cancel]
theorem mul_self_sub_mul_self_eq' [NonUnitalNonAssocRing R] {a b : R} (h : Commute a b) :
a * a - b * b = (a - b) * (a + b) := by
rw [mul_add, sub_mul, sub_mul, h.eq, sub_add_sub_cancel]
theorem mul_self_eq_mul_self_iff [NonUnitalNonAssocRing R] [NoZeroDivisors R] {a b : R}
(h : Commute a b) : a * a = b * b ↔ a = b ∨ a = -b := by
rw [← sub_eq_zero, h.mul_self_sub_mul_self_eq, mul_eq_zero, or_comm, sub_eq_zero,
add_eq_zero_iff_eq_neg]
section
variable [Mul R] [HasDistribNeg R] {a b : R}
theorem neg_right : Commute a b → Commute a (-b) :=
SemiconjBy.neg_right
@[simp]
theorem neg_right_iff : Commute a (-b) ↔ Commute a b :=
SemiconjBy.neg_right_iff
theorem neg_left : Commute a b → Commute (-a) b :=
SemiconjBy.neg_left
@[simp]
theorem neg_left_iff : Commute (-a) b ↔ Commute a b :=
SemiconjBy.neg_left_iff
end
section
variable [MulOneClass R] [HasDistribNeg R]
theorem neg_one_right (a : R) : Commute a (-1) :=
SemiconjBy.neg_one_right a
theorem neg_one_left (a : R) : Commute (-1) a :=
SemiconjBy.neg_one_left a
end
section
variable [NonUnitalNonAssocRing R] {a b c : R}
@[simp]
theorem sub_right : Commute a b → Commute a c → Commute a (b - c) :=
SemiconjBy.sub_right
@[simp]
theorem sub_left : Commute a c → Commute b c → Commute (a - b) c :=
SemiconjBy.sub_left
end
section Ring
variable [Ring R] {a b : R}
protected lemma sq_sub_sq (h : Commute a b) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by
rw [sq, sq, h.mul_self_sub_mul_self_eq]
variable [NoZeroDivisors R]
protected lemma sq_eq_sq_iff_eq_or_eq_neg (h : Commute a b) : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := by
rw [← sub_eq_zero, h.sq_sub_sq, mul_eq_zero, add_eq_zero_iff_eq_neg, sub_eq_zero, or_comm]
end Ring
end Commute
section HasDistribNeg
variable (R)
variable [Monoid R] [HasDistribNeg R]
lemma neg_one_pow_eq_or : ∀ n : ℕ, (-1 : R) ^ n = 1 ∨ (-1 : R) ^ n = -1
| 0 => Or.inl (pow_zero _)
| n + 1 => (neg_one_pow_eq_or n).symm.imp
(fun h ↦ by rw [pow_succ, h, neg_one_mul, neg_neg])
(fun h ↦ by rw [pow_succ, h, one_mul])
variable {R}
lemma neg_pow (a : R) (n : ℕ) : (-a) ^ n = (-1) ^ n * a ^ n :=
neg_one_mul a ▸ (Commute.neg_one_left a).mul_pow n
lemma neg_pow' (a : R) (n : ℕ) : (-a) ^ n = a ^ n * (-1) ^ n :=
mul_neg_one a ▸ (Commute.neg_one_right a).mul_pow n
lemma neg_sq (a : R) : (-a) ^ 2 = a ^ 2 := by simp [sq]
lemma neg_one_sq : (-1 : R) ^ 2 = 1 := by simp [neg_sq, one_pow]
alias neg_pow_two := neg_sq
alias neg_one_pow_two := neg_one_sq
end HasDistribNeg
section Ring
variable [Ring R] {a : R} {n : ℕ}
@[simp] lemma neg_one_pow_mul_eq_zero_iff : (-1) ^ n * a = 0 ↔ a = 0 := by
rcases neg_one_pow_eq_or R n with h | h <;> simp [h]
@[simp] lemma mul_neg_one_pow_eq_zero_iff : a * (-1) ^ n = 0 ↔ a = 0 := by
obtain h | h := neg_one_pow_eq_or R n <;> simp [h]
lemma neg_one_pow_eq_pow_mod_two (n : ℕ) : (-1 : R) ^ n = (-1) ^ (n % 2) := by
rw [← Nat.mod_add_div n 2, pow_add, pow_mul]; simp [sq]
variable [NoZeroDivisors R]
@[simp] lemma sq_eq_one_iff : a ^ 2 = 1 ↔ a = 1 ∨ a = -1 := by
rw [← (Commute.one_right a).sq_eq_sq_iff_eq_or_eq_neg, one_pow]
lemma sq_ne_one_iff : a ^ 2 ≠ 1 ↔ a ≠ 1 ∧ a ≠ -1 := sq_eq_one_iff.not.trans not_or
end Ring
/-- Representation of a difference of two squares in a commutative ring as a product. -/
theorem mul_self_sub_mul_self [NonUnitalNonAssocCommRing R] (a b : R) :
a * a - b * b = (a + b) * (a - b) :=
(Commute.all a b).mul_self_sub_mul_self_eq
theorem mul_self_sub_one [NonAssocRing R] (a : R) : a * a - 1 = (a + 1) * (a - 1) := by
rw [← (Commute.one_right a).mul_self_sub_mul_self_eq, mul_one]
theorem mul_self_eq_mul_self_iff [NonUnitalNonAssocCommRing R] [NoZeroDivisors R] {a b : R} :
a * a = b * b ↔ a = b ∨ a = -b :=
(Commute.all a b).mul_self_eq_mul_self_iff
theorem mul_self_eq_one_iff [NonAssocRing R] [NoZeroDivisors R] {a : R} :
a * a = 1 ↔ a = 1 ∨ a = -1 := by
rw [← (Commute.one_right a).mul_self_eq_mul_self_iff, mul_one]
section CommRing
variable [CommRing R]
lemma sq_sub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := (Commute.all a b).sq_sub_sq
alias pow_two_sub_pow_two := sq_sub_sq
lemma sub_sq (a b : R) : (a - b) ^ 2 = a ^ 2 - 2 * a * b + b ^ 2 := by
rw [sub_eq_add_neg, add_sq, neg_sq, mul_neg, ← sub_eq_add_neg]
alias sub_pow_two := sub_sq
lemma sub_sq' (a b : R) : (a - b) ^ 2 = a ^ 2 + b ^ 2 - 2 * a * b := by
rw [sub_eq_add_neg, add_sq', neg_sq, mul_neg, ← sub_eq_add_neg]
lemma sub_sq_comm (a b : R) : (a - b) ^ 2 = (b - a) ^ 2 := by
rw [sub_sq', mul_right_comm, add_comm, sub_sq']
variable [NoZeroDivisors R] {a b : R}
lemma sq_eq_sq_iff_eq_or_eq_neg : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b :=
(Commute.all a b).sq_eq_sq_iff_eq_or_eq_neg
lemma eq_or_eq_neg_of_sq_eq_sq (a b : R) : a ^ 2 = b ^ 2 → a = b ∨ a = -b :=
sq_eq_sq_iff_eq_or_eq_neg.1
-- Copies of the above CommRing lemmas for `Units R`.
namespace Units
protected lemma sq_eq_sq_iff_eq_or_eq_neg {a b : Rˣ} : a ^ 2 = b ^ 2 ↔ a = b ∨ a = -b := by
simp_rw [Units.ext_iff, val_pow_eq_pow_val, sq_eq_sq_iff_eq_or_eq_neg, Units.val_neg]
protected lemma eq_or_eq_neg_of_sq_eq_sq (a b : Rˣ) (h : a ^ 2 = b ^ 2) : a = b ∨ a = -b :=
Units.sq_eq_sq_iff_eq_or_eq_neg.1 h
end Units
end CommRing
namespace Units
/-- In the unit group of an integral domain, a unit is its own inverse iff the unit is one or
one's additive inverse. -/
theorem inv_eq_self_iff [Ring R] [NoZeroDivisors R] (u : Rˣ) : u⁻¹ = u ↔ u = 1 ∨ u = -1 := by
| rw [inv_eq_iff_mul_eq_one]
simp only [Units.ext_iff]
| Mathlib/Algebra/Ring/Commute.lean | 224 | 225 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Johan Commelin
-/
import Mathlib.Algebra.Algebra.RestrictScalars
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.Module.Rat
import Mathlib.GroupTheory.MonoidLocalization.Basic
import Mathlib.LinearAlgebra.TensorProduct.Tower
/-!
# The tensor product of R-algebras
This file provides results about the multiplicative structure on `A ⊗[R] B` when `R` is a
commutative (semi)ring and `A` and `B` are both `R`-algebras. On these tensor products,
multiplication is characterized by `(a₁ ⊗ₜ b₁) * (a₂ ⊗ₜ b₂) = (a₁ * a₂) ⊗ₜ (b₁ * b₂)`.
## Main declarations
- `LinearMap.baseChange A f` is the `A`-linear map `A ⊗ f`, for an `R`-linear map `f`.
- `Algebra.TensorProduct.semiring`: the ring structure on `A ⊗[R] B` for two `R`-algebras `A`, `B`.
- `Algebra.TensorProduct.leftAlgebra`: the `S`-algebra structure on `A ⊗[R] B`, for when `A` is
additionally an `S` algebra.
- the structure isomorphisms
* `Algebra.TensorProduct.lid : R ⊗[R] A ≃ₐ[R] A`
* `Algebra.TensorProduct.rid : A ⊗[R] R ≃ₐ[S] A` (usually used with `S = R` or `S = A`)
* `Algebra.TensorProduct.comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A`
* `Algebra.TensorProduct.assoc : ((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C))`
- `Algebra.TensorProduct.liftEquiv`: a universal property for the tensor product of algebras.
## References
* [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995]
-/
assert_not_exists Equiv.Perm.cycleType
suppress_compilation
open scoped TensorProduct
open TensorProduct
namespace LinearMap
open TensorProduct
/-!
### The base-change of a linear map of `R`-modules to a linear map of `A`-modules
-/
section Semiring
variable {R A B M N P : Type*} [CommSemiring R]
variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [Module R M] [Module R N] [Module R P]
variable (r : R) (f g : M →ₗ[R] N)
variable (A) in
/-- `baseChange A f` for `f : M →ₗ[R] N` is the `A`-linear map `A ⊗[R] M →ₗ[A] A ⊗[R] N`.
This "base change" operation is also known as "extension of scalars". -/
def baseChange (f : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] A ⊗[R] N :=
AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) f
@[simp]
theorem baseChange_tmul (a : A) (x : M) : f.baseChange A (a ⊗ₜ x) = a ⊗ₜ f x :=
rfl
theorem baseChange_eq_ltensor : (f.baseChange A : A ⊗ M → A ⊗ N) = f.lTensor A :=
rfl
@[simp]
theorem baseChange_add : (f + g).baseChange A = f.baseChange A + g.baseChange A := by
ext
-- Porting note: added `-baseChange_tmul`
simp [baseChange_eq_ltensor, -baseChange_tmul]
@[simp]
theorem baseChange_zero : baseChange A (0 : M →ₗ[R] N) = 0 := by
ext
simp [baseChange_eq_ltensor]
@[simp]
theorem baseChange_smul : (r • f).baseChange A = r • f.baseChange A := by
ext
simp [baseChange_tmul]
@[simp]
lemma baseChange_id : (.id : M →ₗ[R] M).baseChange A = .id := by
ext; simp
lemma baseChange_comp (g : N →ₗ[R] P) :
(g ∘ₗ f).baseChange A = g.baseChange A ∘ₗ f.baseChange A := by
ext; simp
variable (R M) in
@[simp]
lemma baseChange_one : (1 : Module.End R M).baseChange A = 1 := baseChange_id
lemma baseChange_mul (f g : Module.End R M) :
(f * g).baseChange A = f.baseChange A * g.baseChange A := by
ext; simp
variable (R A M N)
/-- `baseChange A e` for `e : M ≃ₗ[R] N` is the `A`-linear map `A ⊗[R] M ≃ₗ[A] A ⊗[R] N`. -/
| def _root_.LinearEquiv.baseChange (e : M ≃ₗ[R] N) : A ⊗[R] M ≃ₗ[A] A ⊗[R] N :=
AlgebraTensorModule.congr (.refl _ _) e
| Mathlib/RingTheory/TensorProduct/Basic.lean | 113 | 115 |
/-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Data.List.FinRange
import Mathlib.Data.List.Perm.Basic
import Mathlib.Data.List.Lex
import Mathlib.Data.List.Induction
/-! # sublists
`List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list.
This file contains basic results on this function.
-/
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
open Nat
namespace List
/-! ### sublists -/
@[simp]
theorem sublists'_nil : sublists' (@nil α) = [[]] :=
rfl
@[simp]
theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] :=
rfl
/-- Auxiliary helper definition for `sublists'` -/
def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) :=
r₁.foldl (init := r₂) fun r l => r ++ [a :: l]
theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)),
sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray)
(fun r l => r.push (a :: l))).toList := by
intro r₁ r₂
rw [sublists'Aux, Array.foldl_toList]
have := List.foldl_hom Array.toList (g₁ := fun r l => r.push (a :: l))
(g₂ := fun r l => r ++ [a :: l]) (l := r₁) (init := r₂.toArray) (by simp)
simpa using this
theorem sublists'_eq_sublists'Aux (l : List α) :
sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by
simp only [sublists', sublists'Aux_eq_array_foldl]
rw [← List.foldr_hom Array.toList]
· intros _ _; congr
theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)),
sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ :=
List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by
rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl]
simp [sublists'Aux]
@[simp 900]
theorem sublists'_cons (a : α) (l : List α) :
sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by
simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map]
@[simp]
theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by
induction' t with a t IH generalizing s
· simp only [sublists'_nil, mem_singleton]
exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩
simp only [sublists'_cons, mem_append, IH, mem_map]
constructor <;> intro h
· rcases h with (h | ⟨s, h, rfl⟩)
· exact sublist_cons_of_sublist _ h
· exact h.cons_cons _
· obtain - | ⟨-, h⟩ | ⟨-, h⟩ := h
· exact Or.inl h
· exact Or.inr ⟨_, h, rfl⟩
@[simp]
theorem length_sublists' : ∀ l : List α, length (sublists' l) = 2 ^ length l
| [] => rfl
| a :: l => by
simp +arith only [sublists'_cons, length_append, length_sublists' l,
length_map, length, Nat.pow_succ']
@[simp]
theorem sublists_nil : sublists (@nil α) = [[]] :=
rfl
@[simp]
theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] :=
rfl
/-- Auxiliary helper function for `sublists` -/
def sublistsAux (a : α) (r : List (List α)) : List (List α) :=
r.foldl (init := []) fun r l => r ++ [l, a :: l]
theorem sublistsAux_eq_array_foldl :
sublistsAux = fun (a : α) (r : List (List α)) =>
(r.toArray.foldl (init := #[])
fun r l => (r.push l).push (a :: l)).toList := by
funext a r
simp only [sublistsAux, Array.foldl_toList, Array.mkEmpty]
have := foldl_hom Array.toList (g₁ := fun r l => (r.push l).push (a :: l))
(g₂ := fun r l => r ++ [l, a :: l]) (l := r) (init := #[]) (by simp)
simpa using this
theorem sublistsAux_eq_flatMap :
sublistsAux = fun (a : α) (r : List (List α)) => r.flatMap fun l => [l, a :: l] :=
funext fun a => funext fun r =>
List.reverseRecOn r
(by simp [sublistsAux])
(fun r l ih => by
rw [flatMap_append, ← ih, flatMap_singleton, sublistsAux, foldl_append]
simp [sublistsAux])
@[csimp] theorem sublists_eq_sublistsFast : @sublists = @sublistsFast := by
ext α l : 2
trans l.foldr sublistsAux [[]]
· rw [sublistsAux_eq_flatMap, sublists]
· simp only [sublistsFast, sublistsAux_eq_array_foldl, Array.foldr_toList]
rw [← foldr_hom Array.toList]
· intros _ _; congr
theorem sublists_append (l₁ l₂ : List α) :
sublists (l₁ ++ l₂) = (sublists l₂) >>= (fun x => (sublists l₁).map (· ++ x)) := by
simp only [sublists, foldr_append]
induction l₁ with
| nil => simp
| cons a l₁ ih =>
rw [foldr_cons, ih]
simp [List.flatMap, flatten_flatten, Function.comp_def]
theorem sublists_cons (a : α) (l : List α) :
sublists (a :: l) = sublists l >>= (fun x => [x, a :: x]) :=
show sublists ([a] ++ l) = _ by
rw [sublists_append]
simp only [sublists_singleton, map_cons, bind_eq_flatMap, nil_append, cons_append, map_nil]
@[simp]
theorem sublists_concat (l : List α) (a : α) :
sublists (l ++ [a]) = sublists l ++ map (fun x => x ++ [a]) (sublists l) := by
rw [sublists_append, sublists_singleton, bind_eq_flatMap, flatMap_cons, flatMap_cons, flatMap_nil,
map_id'' append_nil, append_nil]
theorem sublists_reverse (l : List α) : sublists (reverse l) = map reverse (sublists' l) := by
induction' l with hd tl ih <;> [rfl;
simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton,
map_eq_map, bind_eq_flatMap, map_map, flatMap_cons, append_nil, flatMap_nil,
Function.comp_def]]
theorem sublists_eq_sublists' (l : List α) : sublists l = map reverse (sublists' (reverse l)) := by
rw [← sublists_reverse, reverse_reverse]
theorem sublists'_reverse (l : List α) : sublists' (reverse l) = map reverse (sublists l) := by
simp only [sublists_eq_sublists', map_map, map_id'' reverse_reverse, Function.comp_def]
theorem sublists'_eq_sublists (l : List α) : sublists' l = map reverse (sublists (reverse l)) := by
rw [← sublists'_reverse, reverse_reverse]
@[simp]
theorem mem_sublists {s t : List α} : s ∈ sublists t ↔ s <+ t := by
rw [← reverse_sublist, ← mem_sublists', sublists'_reverse,
mem_map_of_injective reverse_injective]
@[simp]
theorem length_sublists (l : List α) : length (sublists l) = 2 ^ length l := by
simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse]
theorem map_pure_sublist_sublists (l : List α) : map pure l <+ sublists l := by
induction' l using reverseRecOn with l a ih <;> simp only [map, map_append, sublists_concat]
· simp only [sublists_nil, sublist_cons_self]
exact ((append_sublist_append_left _).2 <|
singleton_sublist.2 <| mem_map.2 ⟨[], mem_sublists.2 (nil_sublist _), by rfl⟩).trans
((append_sublist_append_right _).2 ih)
/-! ### sublistsLen -/
/-- Auxiliary function to construct the list of all sublists of a given length. Given an
integer `n`, a list `l`, a function `f` and an auxiliary list `L`, it returns the list made of
`f` applied to all sublists of `l` of length `n`, concatenated with `L`. -/
def sublistsLenAux : ℕ → List α → (List α → β) → List β → List β
| 0, _, f, r => f [] :: r
| _ + 1, [], _, r => r
| n + 1, a :: l, f, r => sublistsLenAux (n + 1) l f (sublistsLenAux n l (f ∘ List.cons a) r)
/-- The list of all sublists of a list `l` that are of length `n`. For instance, for
`l = [0, 1, 2, 3]` and `n = 2`, one gets
`[[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]]`. -/
def sublistsLen (n : ℕ) (l : List α) : List (List α) :=
sublistsLenAux n l id []
theorem sublistsLenAux_append :
∀ (n : ℕ) (l : List α) (f : List α → β) (g : β → γ) (r : List β) (s : List γ),
sublistsLenAux n l (g ∘ f) (r.map g ++ s) = (sublistsLenAux n l f r).map g ++ s
| 0, l, f, g, r, s => by unfold sublistsLenAux; simp
| _ + 1, [], _, _, _, _ => rfl
| n + 1, a :: l, f, g, r, s => by
unfold sublistsLenAux
simp only [show (g ∘ f) ∘ List.cons a = g ∘ f ∘ List.cons a by rfl, sublistsLenAux_append,
sublistsLenAux_append]
theorem sublistsLenAux_eq (l : List α) (n) (f : List α → β) (r) :
sublistsLenAux n l f r = (sublistsLen n l).map f ++ r := by
rw [sublistsLen, ← sublistsLenAux_append]; rfl
theorem sublistsLenAux_zero (l : List α) (f : List α → β) (r) :
sublistsLenAux 0 l f r = f [] :: r := by cases l <;> rfl
@[simp]
theorem sublistsLen_zero (l : List α) : sublistsLen 0 l = [[]] :=
sublistsLenAux_zero _ _ _
@[simp]
theorem sublistsLen_succ_nil (n) : sublistsLen (n + 1) (@nil α) = [] :=
rfl
@[simp]
theorem sublistsLen_succ_cons (n) (a : α) (l) :
sublistsLen (n + 1) (a :: l) = sublistsLen (n + 1) l ++ (sublistsLen n l).map (cons a) := by
rw [sublistsLen, sublistsLenAux, sublistsLenAux_eq, sublistsLenAux_eq, map_id,
append_nil]; rfl
theorem sublistsLen_one (l : List α) : sublistsLen 1 l = l.reverse.map ([·]) :=
l.rec (by rw [sublistsLen_succ_nil, reverse_nil, map_nil]) fun a s ih ↦ by
rw [sublistsLen_succ_cons, ih, reverse_cons, map_append, sublistsLen_zero]; rfl
@[simp]
theorem length_sublistsLen :
∀ (n) (l : List α), length (sublistsLen n l) = Nat.choose (length l) n
| 0, l => by simp
| _ + 1, [] => by simp
| n + 1, a :: l => by
rw [sublistsLen_succ_cons, length_append, length_sublistsLen (n+1) l,
length_map, length_sublistsLen n l, length_cons, Nat.choose_succ_succ, Nat.add_comm]
theorem sublistsLen_sublist_sublists' :
∀ (n) (l : List α), sublistsLen n l <+ sublists' l
| 0, l => by simp
| _ + 1, [] => nil_sublist _
| n + 1, a :: l => by
rw [sublistsLen_succ_cons, sublists'_cons]
exact (sublistsLen_sublist_sublists' _ _).append ((sublistsLen_sublist_sublists' _ _).map _)
theorem sublistsLen_sublist_of_sublist (n) {l₁ l₂ : List α} (h : l₁ <+ l₂) :
sublistsLen n l₁ <+ sublistsLen n l₂ := by
induction' n with n IHn generalizing l₁ l₂; · simp
induction h with
| slnil => rfl
| cons a _ IH =>
refine IH.trans ?_
rw [sublistsLen_succ_cons]
apply sublist_append_left
| cons₂ a s IH => simpa only [sublistsLen_succ_cons] using IH.append ((IHn s).map _)
theorem length_of_sublistsLen :
∀ {n} {l l' : List α}, l' ∈ sublistsLen n l → length l' = n
| 0, l, l', h => by simp_all
| n + 1, a :: l, l', h => by
rw [sublistsLen_succ_cons, mem_append, mem_map] at h
rcases h with (h | ⟨l', h, rfl⟩)
· exact length_of_sublistsLen h
· exact congr_arg (· + 1) (length_of_sublistsLen h)
theorem mem_sublistsLen_self {l l' : List α} (h : l' <+ l) :
l' ∈ sublistsLen (length l') l := by
induction h with
| slnil => simp
| @cons l₁ l₂ a s IH =>
rcases l₁ with - | ⟨b, l₁⟩
· simp
· rw [length, sublistsLen_succ_cons]
exact mem_append_left _ IH
| cons₂ a s IH =>
rw [length, sublistsLen_succ_cons]
exact mem_append_right _ (mem_map.2 ⟨_, IH, rfl⟩)
@[simp]
theorem mem_sublistsLen {n} {l l' : List α} :
l' ∈ sublistsLen n l ↔ l' <+ l ∧ length l' = n :=
⟨fun h =>
⟨mem_sublists'.1 ((sublistsLen_sublist_sublists' _ _).subset h), length_of_sublistsLen h⟩,
fun ⟨h₁, h₂⟩ => h₂ ▸ mem_sublistsLen_self h₁⟩
theorem sublistsLen_of_length_lt {n} {l : List α} (h : l.length < n) : sublistsLen n l = [] :=
eq_nil_iff_forall_not_mem.mpr fun _ =>
mem_sublistsLen.not.mpr fun ⟨hs, hl⟩ => (h.trans_eq hl.symm).not_le (Sublist.length_le hs)
@[simp]
theorem sublistsLen_length : ∀ l : List α, sublistsLen l.length l = [l]
| [] => rfl
| a :: l => by
simp only [length, sublistsLen_succ_cons, sublistsLen_length, map,
sublistsLen_of_length_lt (lt_succ_self _), nil_append]
open Function
theorem Pairwise.sublists' {R} :
∀ {l : List α}, Pairwise R l → Pairwise (Lex (swap R)) (sublists' l)
| _, Pairwise.nil => pairwise_singleton _ _
| _, @Pairwise.cons _ _ a l H₁ H₂ => by
simp only [sublists'_cons, pairwise_append, pairwise_map, mem_sublists', mem_map, exists_imp,
and_imp]
refine ⟨H₂.sublists', H₂.sublists'.imp fun l₁ => Lex.cons l₁, ?_⟩
rintro l₁ sl₁ x l₂ _ rfl
rcases l₁ with - | ⟨b, l₁⟩; · constructor
exact Lex.rel (H₁ _ <| sl₁.subset mem_cons_self)
theorem pairwise_sublists {R} {l : List α} (H : Pairwise R l) :
Pairwise (Lex R on reverse) (sublists l) := by
have := (pairwise_reverse.2 H).sublists'
rwa [sublists'_reverse, pairwise_map] at this
@[simp]
theorem nodup_sublists {l : List α} : Nodup (sublists l) ↔ Nodup l :=
⟨fun h => (h.sublist (map_pure_sublist_sublists _)).of_map _, fun h =>
(pairwise_sublists h).imp @fun l₁ l₂ h => by simpa using h.to_ne⟩
@[simp]
theorem nodup_sublists' {l : List α} : Nodup (sublists' l) ↔ Nodup l := by
rw [sublists'_eq_sublists, nodup_map_iff reverse_injective, nodup_sublists, nodup_reverse]
protected alias ⟨Nodup.of_sublists, Nodup.sublists⟩ := nodup_sublists
protected alias ⟨Nodup.of_sublists', _⟩ := nodup_sublists'
theorem nodup_sublistsLen (n : ℕ) {l : List α} (h : Nodup l) : (sublistsLen n l).Nodup := by
have : Pairwise (· ≠ ·) l.sublists' := Pairwise.imp
(fun h => Lex.to_ne (by convert h using 3; simp [swap, eq_comm])) h.sublists'
exact this.sublist (sublistsLen_sublist_sublists' _ _)
theorem sublists_map (f : α → β) : ∀ (l : List α),
sublists (map f l) = map (map f) (sublists l)
| [] => by simp
| a::l => by
rw [map_cons, sublists_cons, bind_eq_flatMap, sublists_map f l, sublists_cons,
bind_eq_flatMap, map_eq_flatMap, map_eq_flatMap]
induction sublists l <;> simp [*]
theorem sublists'_map (f : α → β) : ∀ (l : List α),
sublists' (map f l) = map (map f) (sublists' l)
| [] => by simp
| a::l => by simp [map_cons, sublists'_cons, sublists'_map f l, Function.comp]
theorem sublists_perm_sublists' (l : List α) : sublists l ~ sublists' l := by
rw [← finRange_map_get l, sublists_map, sublists'_map]
apply Perm.map
apply (perm_ext_iff_of_nodup _ _).mpr
· simp
· exact nodup_sublists.mpr (nodup_finRange _)
· exact (nodup_sublists'.mpr (nodup_finRange _))
theorem sublists_cons_perm_append (a : α) (l : List α) :
sublists (a :: l) ~ sublists l ++ map (cons a) (sublists l) :=
Perm.trans (sublists_perm_sublists' _) <| by
rw [sublists'_cons]
exact Perm.append (sublists_perm_sublists' _).symm (Perm.map _ (sublists_perm_sublists' _).symm)
theorem revzip_sublists (l : List α) : ∀ l₁ l₂, (l₁, l₂) ∈ revzip l.sublists → l₁ ++ l₂ ~ l := by
rw [revzip]
induction' l using List.reverseRecOn with l' a ih
· intro l₁ l₂ h
simp? at h says
simp only [sublists_nil, reverse_cons, reverse_nil, nil_append, zip_cons_cons, zip_nil_right,
mem_cons, Prod.mk.injEq, not_mem_nil, or_false] at h
simp [h]
· intro l₁ l₂ h
rw [sublists_concat, reverse_append, zip_append (by simp), ← map_reverse, zip_map_right,
zip_map_left] at *
simp only [Prod.mk_inj, mem_map, mem_append, Prod.map_apply, Prod.exists] at h
rcases h with (⟨l₁, l₂', h, rfl, rfl⟩ | ⟨l₁', l₂, h, rfl, rfl⟩)
· rw [← append_assoc]
exact (ih _ _ h).append_right _
· rw [append_assoc]
apply (perm_append_comm.append_left _).trans
rw [← append_assoc]
exact (ih _ _ h).append_right _
theorem revzip_sublists' (l : List α) : ∀ l₁ l₂, (l₁, l₂) ∈ revzip l.sublists' → l₁ ++ l₂ ~ l := by
rw [revzip]
induction' l with a l IH <;> intro l₁ l₂ h
· simp_all only [sublists'_nil, reverse_cons, reverse_nil, nil_append, zip_cons_cons,
zip_nil_right, mem_singleton, Prod.mk.injEq, append_nil, Perm.refl]
· rw [sublists'_cons, reverse_append, zip_append, ← map_reverse, zip_map_right, zip_map_left] at *
<;> [simp only [mem_append, mem_map, Prod.map_apply, id_eq, Prod.mk.injEq, Prod.exists,
exists_eq_right_right] at h; simp]
rcases h with (⟨l₁, l₂', h, rfl, rfl⟩ | ⟨l₁', h, rfl⟩)
· exact perm_middle.trans ((IH _ _ h).cons _)
· exact (IH _ _ h).cons _
theorem range_bind_sublistsLen_perm (l : List α) :
((List.range (l.length + 1)).flatMap fun n => sublistsLen n l) ~ sublists' l := by
induction' l with h tl l_ih
· simp [range_succ]
· simp_rw [range_succ_eq_map, length, flatMap_cons, flatMap_map, sublistsLen_succ_cons,
sublists'_cons, List.sublistsLen_zero, List.singleton_append]
| refine ((flatMap_append_perm (range (tl.length + 1)) _ _).symm.cons _).trans ?_
simp_rw [← List.map_flatMap, ← cons_append]
rw [← List.singleton_append, ← List.sublistsLen_zero tl]
refine Perm.append ?_ (l_ih.map _)
| Mathlib/Data/List/Sublists.lean | 399 | 402 |
/-
Copyright (c) 2022 Rémy Degenne, Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Kexing Ying
-/
import Mathlib.MeasureTheory.Function.Egorov
import Mathlib.MeasureTheory.Function.LpSpace.Complete
/-!
# Convergence in measure
We define convergence in measure which is one of the many notions of convergence in probability.
A sequence of functions `f` is said to converge in measure to some function `g`
if for all `ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i`
converges along some given filter `l`.
Convergence in measure is most notably used in the formulation of the weak law of large numbers
and is also useful in theorems such as the Vitali convergence theorem. This file provides some
basic lemmas for working with convergence in measure and establishes some relations between
convergence in measure and other notions of convergence.
## Main definitions
* `MeasureTheory.TendstoInMeasure (μ : Measure α) (f : ι → α → E) (g : α → E)`: `f` converges
in `μ`-measure to `g`.
## Main results
* `MeasureTheory.tendstoInMeasure_of_tendsto_ae`: convergence almost everywhere in a finite
measure space implies convergence in measure.
* `MeasureTheory.TendstoInMeasure.exists_seq_tendsto_ae`: if `f` is a sequence of functions
which converges in measure to `g`, then `f` has a subsequence which convergence almost
everywhere to `g`.
* `MeasureTheory.exists_seq_tendstoInMeasure_atTop_iff`: for a sequence of functions `f`,
convergence in measure is equivalent to the fact that every subsequence has another subsequence
that converges almost surely.
* `MeasureTheory.tendstoInMeasure_of_tendsto_eLpNorm`: convergence in Lp implies convergence
in measure.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory Topology
namespace MeasureTheory
variable {α ι κ E : Type*} {m : MeasurableSpace α} {μ : Measure α}
/-- A sequence of functions `f` is said to converge in measure to some function `g` if for all
`ε > 0`, the measure of the set `{x | ε ≤ dist (f i x) (g x)}` tends to 0 as `i` converges along
some given filter `l`. -/
def TendstoInMeasure [Dist E] {_ : MeasurableSpace α} (μ : Measure α) (f : ι → α → E) (l : Filter ι)
(g : α → E) : Prop :=
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ dist (f i x) (g x) }) l (𝓝 0)
theorem tendstoInMeasure_iff_norm [SeminormedAddCommGroup E] {l : Filter ι} {f : ι → α → E}
{g : α → E} :
TendstoInMeasure μ f l g ↔
∀ ε, 0 < ε → Tendsto (fun i => μ { x | ε ≤ ‖f i x - g x‖ }) l (𝓝 0) := by
simp_rw [TendstoInMeasure, dist_eq_norm]
theorem tendstoInMeasure_iff_tendsto_toNNReal [Dist E] [IsFiniteMeasure μ]
{f : ι → α → E} {l : Filter ι} {g : α → E} :
TendstoInMeasure μ f l g ↔
∀ ε, 0 < ε → Tendsto (fun i => (μ { x | ε ≤ dist (f i x) (g x) }).toNNReal) l (𝓝 0) := by
have hfin ε i : μ { x | ε ≤ dist (f i x) (g x) } ≠ ⊤ :=
measure_ne_top μ {x | ε ≤ dist (f i x) (g x)}
refine ⟨fun h ε hε ↦ ?_, fun h ε hε ↦ ?_⟩
· have hf : (fun i => (μ { x | ε ≤ dist (f i x) (g x) }).toNNReal) =
ENNReal.toNNReal ∘ (fun i => (μ { x | ε ≤ dist (f i x) (g x) })) := rfl
rw [hf, ENNReal.tendsto_toNNReal_iff' (hfin ε)]
exact h ε hε
· rw [← ENNReal.tendsto_toNNReal_iff ENNReal.zero_ne_top (hfin ε)]
exact h ε hε
lemma TendstoInMeasure.mono [Dist E] {f : ι → α → E} {g : α → E} {u v : Filter ι} (huv : v ≤ u)
(hg : TendstoInMeasure μ f u g) : TendstoInMeasure μ f v g :=
fun ε hε => (hg ε hε).mono_left huv
lemma TendstoInMeasure.comp [Dist E] {f : ι → α → E} {g : α → E} {u : Filter ι}
{v : Filter κ} {ns : κ → ι} (hg : TendstoInMeasure μ f u g) (hns : Tendsto ns v u) :
TendstoInMeasure μ (f ∘ ns) v g := fun ε hε ↦ (hg ε hε).comp hns
namespace TendstoInMeasure
variable [Dist E] {l : Filter ι} {f f' : ι → α → E} {g g' : α → E}
protected theorem congr' (h_left : ∀ᶠ i in l, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' := by
intro ε hε
suffices
(fun i => μ { x | ε ≤ dist (f' i x) (g' x) }) =ᶠ[l] fun i => μ { x | ε ≤ dist (f i x) (g x) } by
rw [tendsto_congr' this]
exact h_tendsto ε hε
filter_upwards [h_left] with i h_ae_eq
refine measure_congr ?_
filter_upwards [h_ae_eq, h_right] with x hxf hxg
rw [eq_iff_iff]
change ε ≤ dist (f' i x) (g' x) ↔ ε ≤ dist (f i x) (g x)
rw [hxg, hxf]
protected theorem congr (h_left : ∀ i, f i =ᵐ[μ] f' i) (h_right : g =ᵐ[μ] g')
(h_tendsto : TendstoInMeasure μ f l g) : TendstoInMeasure μ f' l g' :=
TendstoInMeasure.congr' (Eventually.of_forall h_left) h_right h_tendsto
theorem congr_left (h : ∀ i, f i =ᵐ[μ] f' i) (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f' l g :=
h_tendsto.congr h EventuallyEq.rfl
theorem congr_right (h : g =ᵐ[μ] g') (h_tendsto : TendstoInMeasure μ f l g) :
TendstoInMeasure μ f l g' :=
h_tendsto.congr (fun _ => EventuallyEq.rfl) h
end TendstoInMeasure
section ExistsSeqTendstoAe
variable [MetricSpace E]
variable {f : ℕ → α → E} {g : α → E}
/-- Auxiliary lemma for `tendstoInMeasure_of_tendsto_ae`. -/
theorem tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable [IsFiniteMeasure μ]
(hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
refine fun ε hε => ENNReal.tendsto_atTop_zero.mpr fun δ hδ => ?_
by_cases hδi : δ = ∞
· simp only [hδi, imp_true_iff, le_top, exists_const]
lift δ to ℝ≥0 using hδi
rw [gt_iff_lt, ENNReal.coe_pos, ← NNReal.coe_pos] at hδ
obtain ⟨t, _, ht, hunif⟩ := tendstoUniformlyOn_of_ae_tendsto' hf hg hfg hδ
rw [ENNReal.ofReal_coe_nnreal] at ht
rw [Metric.tendstoUniformlyOn_iff] at hunif
obtain ⟨N, hN⟩ := eventually_atTop.1 (hunif ε hε)
refine ⟨N, fun n hn => ?_⟩
suffices { x : α | ε ≤ dist (f n x) (g x) } ⊆ t from (measure_mono this).trans ht
rw [← Set.compl_subset_compl]
intro x hx
rw [Set.mem_compl_iff, Set.nmem_setOf_iff, dist_comm, not_le]
exact hN n hn x hx
/-- Convergence a.e. implies convergence in measure in a finite measure space. -/
theorem tendstoInMeasure_of_tendsto_ae [IsFiniteMeasure μ] (hf : ∀ n, AEStronglyMeasurable (f n) μ)
(hfg : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoInMeasure μ f atTop g := by
have hg : AEStronglyMeasurable g μ := aestronglyMeasurable_of_tendsto_ae _ hf hfg
refine TendstoInMeasure.congr (fun i => (hf i).ae_eq_mk.symm) hg.ae_eq_mk.symm ?_
refine tendstoInMeasure_of_tendsto_ae_of_stronglyMeasurable
(fun i => (hf i).stronglyMeasurable_mk) hg.stronglyMeasurable_mk ?_
have hf_eq_ae : ∀ᵐ x ∂μ, ∀ n, (hf n).mk (f n) x = f n x :=
ae_all_iff.mpr fun n => (hf n).ae_eq_mk.symm
filter_upwards [hf_eq_ae, hg.ae_eq_mk, hfg] with x hxf hxg hxfg
rw [← hxg, funext fun n => hxf n]
exact hxfg
namespace ExistsSeqTendstoAe
theorem exists_nat_measure_lt_two_inv (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) :
∃ N, ∀ m ≥ N, μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f m x) (g x) } ≤ (2⁻¹ : ℝ≥0∞) ^ n := by
specialize hfg ((2⁻¹ : ℝ) ^ n) (by simp only [Real.rpow_natCast, inv_pos, zero_lt_two, pow_pos])
rw [ENNReal.tendsto_atTop_zero] at hfg
exact hfg ((2 : ℝ≥0∞)⁻¹ ^ n) (pos_iff_ne_zero.mpr fun h_zero => by simpa using pow_eq_zero h_zero)
/-- Given a sequence of functions `f` which converges in measure to `g`,
`seqTendstoAeSeqAux` is a sequence such that
`∀ m ≥ seqTendstoAeSeqAux n, μ {x | 2⁻¹ ^ n ≤ dist (f m x) (g x)} ≤ 2⁻¹ ^ n`. -/
noncomputable def seqTendstoAeSeqAux (hfg : TendstoInMeasure μ f atTop g) (n : ℕ) :=
Classical.choose (exists_nat_measure_lt_two_inv hfg n)
/-- Transformation of `seqTendstoAeSeqAux` to makes sure it is strictly monotone. -/
noncomputable def seqTendstoAeSeq (hfg : TendstoInMeasure μ f atTop g) : ℕ → ℕ
| 0 => seqTendstoAeSeqAux hfg 0
| n + 1 => max (seqTendstoAeSeqAux hfg (n + 1)) (seqTendstoAeSeq hfg n + 1)
theorem seqTendstoAeSeq_succ (hfg : TendstoInMeasure μ f atTop g) {n : ℕ} :
seqTendstoAeSeq hfg (n + 1) =
max (seqTendstoAeSeqAux hfg (n + 1)) (seqTendstoAeSeq hfg n + 1) := by
rw [seqTendstoAeSeq]
theorem seqTendstoAeSeq_spec (hfg : TendstoInMeasure μ f atTop g) (n k : ℕ)
(hn : seqTendstoAeSeq hfg n ≤ k) :
μ { x | (2 : ℝ)⁻¹ ^ n ≤ dist (f k x) (g x) } ≤ (2 : ℝ≥0∞)⁻¹ ^ n := by
cases n
· exact Classical.choose_spec (exists_nat_measure_lt_two_inv hfg 0) k hn
· exact Classical.choose_spec
(exists_nat_measure_lt_two_inv hfg _) _ (le_trans (le_max_left _ _) hn)
theorem seqTendstoAeSeq_strictMono (hfg : TendstoInMeasure μ f atTop g) :
StrictMono (seqTendstoAeSeq hfg) := by
refine strictMono_nat_of_lt_succ fun n => ?_
rw [seqTendstoAeSeq_succ]
exact lt_of_lt_of_le (lt_add_one <| seqTendstoAeSeq hfg n) (le_max_right _ _)
end ExistsSeqTendstoAe
/-- If `f` is a sequence of functions which converges in measure to `g`, then there exists a
subsequence of `f` which converges a.e. to `g`. -/
theorem TendstoInMeasure.exists_seq_tendsto_ae (hfg : TendstoInMeasure μ f atTop g) :
∃ ns : ℕ → ℕ, StrictMono ns ∧ ∀ᵐ x ∂μ, Tendsto (fun i => f (ns i) x) atTop (𝓝 (g x)) := by
/- Since `f` tends to `g` in measure, it has a subsequence `k ↦ f (ns k)` such that
`μ {|f (ns k) - g| ≥ 2⁻ᵏ} ≤ 2⁻ᵏ` for all `k`. Defining
`s := ⋂ k, ⋃ i ≥ k, {|f (ns k) - g| ≥ 2⁻ᵏ}`, we see that `μ s = 0` by the
first Borel-Cantelli lemma.
On the other hand, as `s` is precisely the set for which `f (ns k)`
doesn't converge to `g`, `f (ns k)` converges almost everywhere to `g` as required. -/
have h_lt_ε_real : ∀ (ε : ℝ) (_ : 0 < ε), ∃ k : ℕ, 2 * (2 : ℝ)⁻¹ ^ k < ε := by
intro ε hε
obtain ⟨k, h_k⟩ : ∃ k : ℕ, (2 : ℝ)⁻¹ ^ k < ε := exists_pow_lt_of_lt_one hε (by norm_num)
refine ⟨k + 1, (le_of_eq ?_).trans_lt h_k⟩
rw [pow_add]; ring
set ns := ExistsSeqTendstoAe.seqTendstoAeSeq hfg
use ns
let S := fun k => { x | (2 : ℝ)⁻¹ ^ k ≤ dist (f (ns k) x) (g x) }
have hμS_le : ∀ k, μ (S k) ≤ (2 : ℝ≥0∞)⁻¹ ^ k :=
fun k => ExistsSeqTendstoAe.seqTendstoAeSeq_spec hfg k (ns k) le_rfl
set s := Filter.atTop.limsup S with hs
have hμs : μ s = 0 := by
refine measure_limsup_atTop_eq_zero (ne_top_of_le_ne_top ?_ (ENNReal.tsum_le_tsum hμS_le))
simpa only [ENNReal.tsum_geometric, ENNReal.one_sub_inv_two, inv_inv] using ENNReal.ofNat_ne_top
have h_tendsto : ∀ x ∈ sᶜ, Tendsto (fun i => f (ns i) x) atTop (𝓝 (g x)) := by
refine fun x hx => Metric.tendsto_atTop.mpr fun ε hε => ?_
rw [hs, limsup_eq_iInf_iSup_of_nat] at hx
simp only [S, Set.iSup_eq_iUnion, Set.iInf_eq_iInter, Set.compl_iInter, Set.compl_iUnion,
Set.mem_iUnion, Set.mem_iInter, Set.mem_compl_iff, Set.mem_setOf_eq, not_le] at hx
obtain ⟨N, hNx⟩ := hx
obtain ⟨k, hk_lt_ε⟩ := h_lt_ε_real ε hε
refine ⟨max N (k - 1), fun n hn_ge => lt_of_le_of_lt ?_ hk_lt_ε⟩
specialize hNx n ((le_max_left _ _).trans hn_ge)
have h_inv_n_le_k : (2 : ℝ)⁻¹ ^ n ≤ 2 * (2 : ℝ)⁻¹ ^ k := by
rw [mul_comm, ← inv_mul_le_iff₀' (zero_lt_two' ℝ)]
conv_lhs =>
congr
rw [← pow_one (2 : ℝ)⁻¹]
rw [← pow_add, add_comm]
exact pow_le_pow_of_le_one (one_div (2 : ℝ) ▸ one_half_pos.le)
(inv_le_one_of_one_le₀ one_le_two)
| ((le_tsub_add.trans (add_le_add_right (le_max_right _ _) 1)).trans
(add_le_add_right hn_ge 1))
exact le_trans hNx.le h_inv_n_le_k
rw [ae_iff]
refine ⟨ExistsSeqTendstoAe.seqTendstoAeSeq_strictMono hfg, measure_mono_null (fun x => ?_) hμs⟩
| Mathlib/MeasureTheory/Function/ConvergenceInMeasure.lean | 237 | 241 |
/-
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.Algebra.Group.Pi.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Limits.Shapes.Images
import Mathlib.CategoryTheory.IsomorphismClasses
import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects
/-!
# Zero morphisms and zero objects
A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space,
and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra
structure, not merely a property.)
A category "has a zero object" if it has an object which is both initial and terminal. Having a
zero object provides zero morphisms, as the unique morphisms factoring through the zero object.
## References
* https://en.wikipedia.org/wiki/Zero_morphism
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
noncomputable section
universe w v v' u u'
open CategoryTheory
open CategoryTheory.Category
namespace CategoryTheory.Limits
variable (C : Type u) [Category.{v} C]
variable (D : Type u') [Category.{v'} D]
/-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space,
and compositions of zero morphisms with anything give the zero morphism. -/
class HasZeroMorphisms where
/-- Every morphism space has zero -/
[zero : ∀ X Y : C, Zero (X ⟶ Y)]
/-- `f` composed with `0` is `0` -/
comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by aesop_cat
/-- `0` composed with `f` is `0` -/
zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by aesop_cat
attribute [instance] HasZeroMorphisms.zero
variable {C}
@[simp]
theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} :
f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) :=
HasZeroMorphisms.comp_zero f Z
@[simp]
theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} :
(0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) :=
HasZeroMorphisms.zero_comp X f
instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where
zero := by aesop_cat
instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where
zero X Y := by repeat (constructor)
namespace HasZeroMorphisms
/-- This lemma will be immediately superseded by `ext`, below. -/
private theorem ext_aux (I J : HasZeroMorphisms C)
(w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by
have : I.zero = J.zero := by
funext X Y
specialize w X Y
apply congrArg Zero.mk w
cases I; cases J
congr
· apply proof_irrel_heq
· apply proof_irrel_heq
/-- If you're tempted to use this lemma "in the wild", you should probably
carefully consider whether you've made a mistake in allowing two
instances of `HasZeroMorphisms` to exist at all.
See, particularly, the note on `zeroMorphismsOfZeroObject` below.
-/
theorem ext (I J : HasZeroMorphisms C) : I = J := by
apply ext_aux
intro X Y
have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by
apply I.zero_comp X (J.zero Y Y).zero
have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by
apply J.comp_zero (I.zero X Y).zero Y
rw [← this, ← that]
instance : Subsingleton (HasZeroMorphisms C) :=
⟨ext⟩
end HasZeroMorphisms
open Opposite HasZeroMorphisms
instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where
zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩
comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop)
zero_comp X {Y Z} (f : Y ⟶ Z) :=
congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X))
section
variable [HasZeroMorphisms C]
@[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl
@[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl
theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by
rw [← zero_comp, cancel_mono] at h
exact h
theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by
rw [← comp_zero, cancel_epi] at h
exact h
theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) :
f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero]
theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 :=
fun h => w (eq_zero_of_image_eq_zero h)
end
section
variable [HasZeroMorphisms D]
instance : HasZeroMorphisms (C ⥤ D) where
zero F G := ⟨{ app := fun _ => 0 }⟩
comp_zero := fun η H => by
ext X; dsimp; apply comp_zero
zero_comp := fun F {G H} η => by
ext X; dsimp; apply zero_comp
@[simp]
theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl
end
namespace IsZero
variable [HasZeroMorphisms C]
theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 :=
o.eq_of_src _ _
theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 :=
o.eq_of_tgt _ _
theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 :=
⟨fun h => h.eq_of_src _ _, fun h =>
⟨fun Y => ⟨⟨⟨0⟩, fun f => by
rw [← id_comp f, ← id_comp (0 : X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩,
fun Y => ⟨⟨⟨0⟩, fun f => by
rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩
theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X :=
(iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp))
theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y :=
(iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp))
theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by
subst h
apply of_mono_zero X Y
theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by
subst h
apply of_epi_zero X Y
theorem iff_isSplitMono_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsZero X ↔ f = 0 := by
rw [iff_id_eq_zero]
constructor
· intro h
rw [← Category.id_comp f, h, zero_comp]
· intro h
rw [← IsSplitMono.id f]
simp only [h, zero_comp]
theorem iff_isSplitEpi_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsZero Y ↔ f = 0 := by
rw [iff_id_eq_zero]
constructor
· intro h
rw [← Category.comp_id f, h, comp_zero]
· intro h
rw [← IsSplitEpi.id f]
simp [h]
theorem of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (i : IsZero Y) : IsZero X := by
have hf := i.eq_zero_of_tgt f
subst hf
exact IsZero.of_mono_zero X Y
theorem of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (i : IsZero X) : IsZero Y := by
have hf := i.eq_zero_of_src f
subst hf
exact IsZero.of_epi_zero X Y
end IsZero
/-- A category with a zero object has zero morphisms.
It is rarely a good idea to use this. Many categories that have a zero object have zero
morphisms for some other reason, for example from additivity. Library code that uses
`zeroMorphismsOfZeroObject` will then be incompatible with these categories because
the `HasZeroMorphisms` instances will not be definitionally equal. For this reason library
code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already
asks for an instance of `HasZeroObjects`. -/
def IsZero.hasZeroMorphisms {O : C} (hO : IsZero O) : HasZeroMorphisms C where
zero X Y := { zero := hO.from_ X ≫ hO.to_ Y }
zero_comp X {Y Z} f := by
change (hO.from_ X ≫ hO.to_ Y) ≫ f = hO.from_ X ≫ hO.to_ Z
rw [Category.assoc]
congr
apply hO.eq_of_src
comp_zero {X Y} f Z := by
change f ≫ (hO.from_ Y ≫ hO.to_ Z) = hO.from_ X ≫ hO.to_ Z
rw [← Category.assoc]
congr
apply hO.eq_of_tgt
namespace HasZeroObject
variable [HasZeroObject C]
open ZeroObject
/-- A category with a zero object has zero morphisms.
It is rarely a good idea to use this. Many categories that have a zero object have zero
morphisms for some other reason, for example from additivity. Library code that uses
`zeroMorphismsOfZeroObject` will then be incompatible with these categories because
the `has_zero_morphisms` instances will not be definitionally equal. For this reason library
code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already
asks for an instance of `HasZeroObjects`. -/
def zeroMorphismsOfZeroObject : HasZeroMorphisms C where
zero X _ := { zero := (default : X ⟶ 0) ≫ default }
zero_comp X {Y Z} f := by
change ((default : X ⟶ 0) ≫ default) ≫ f = (default : X ⟶ 0) ≫ default
rw [Category.assoc]
congr
simp only [eq_iff_true_of_subsingleton]
comp_zero {X Y} f Z := by
change f ≫ (default : Y ⟶ 0) ≫ default = (default : X ⟶ 0) ≫ default
rw [← Category.assoc]
congr
simp only [eq_iff_true_of_subsingleton]
section HasZeroMorphisms
variable [HasZeroMorphisms C]
@[simp]
theorem zeroIsoIsInitial_hom {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).hom = 0 := by ext
@[simp]
theorem zeroIsoIsInitial_inv {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).inv = 0 := by ext
@[simp]
theorem zeroIsoIsTerminal_hom {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).hom = 0 := by ext
@[simp]
theorem zeroIsoIsTerminal_inv {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).inv = 0 := by ext
@[simp]
theorem zeroIsoInitial_hom [HasInitial C] : zeroIsoInitial.hom = (0 : 0 ⟶ ⊥_ C) := by ext
@[simp]
theorem zeroIsoInitial_inv [HasInitial C] : zeroIsoInitial.inv = (0 : ⊥_ C ⟶ 0) := by ext
@[simp]
theorem zeroIsoTerminal_hom [HasTerminal C] : zeroIsoTerminal.hom = (0 : 0 ⟶ ⊤_ C) := by ext
@[simp]
theorem zeroIsoTerminal_inv [HasTerminal C] : zeroIsoTerminal.inv = (0 : ⊤_ C ⟶ 0) := by ext
end HasZeroMorphisms
open ZeroObject
instance {B : Type*} [Category B] : HasZeroObject (B ⥤ C) :=
(((CategoryTheory.Functor.const B).obj (0 : C)).isZero fun _ => isZero_zero _).hasZeroObject
end HasZeroObject
open ZeroObject
variable {D}
@[simp]
theorem IsZero.map [HasZeroObject D] [HasZeroMorphisms D] {F : C ⥤ D} (hF : IsZero F) {X Y : C}
(f : X ⟶ Y) : F.map f = 0 :=
(hF.obj _).eq_of_src _ _
@[simp]
theorem _root_.CategoryTheory.Functor.zero_obj [HasZeroObject D] (X : C) :
IsZero ((0 : C ⥤ D).obj X) :=
(isZero_zero _).obj _
@[simp]
theorem _root_.CategoryTheory.zero_map [HasZeroObject D] [HasZeroMorphisms D] {X Y : C}
(f : X ⟶ Y) : (0 : C ⥤ D).map f = 0 :=
(isZero_zero _).map _
section
variable [HasZeroObject C] [HasZeroMorphisms C]
open ZeroObject
| Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean | 324 | 324 | |
/-
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
@[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
@[simp]
lemma fromCols_toCols (A : Matrix m (n₁ ⊕ n₂) R) :
fromCols A.toCols₁ A.toCols₂ = A := by
ext i (j | j) <;> simp
@[deprecated (since := "2024-12-11")] alias fromColumns_toColumns := fromCols_toCols
@[simp]
lemma fromRows_toRows (A : Matrix (m₁ ⊕ m₂) n R) : fromRows A.toRows₁ A.toRows₂ = A := by
ext (i | i) j <;> simp
lemma fromRows_inj : Function.Injective2 (@fromRows R m₁ m₂ n) := by
intros x1 x2 y1 y2
simp [← Matrix.ext_iff]
lemma fromCols_inj : Function.Injective2 (@fromCols R m n₁ n₂) := by
intros x1 x2 y1 y2
simp only [funext_iff, ← Matrix.ext_iff]
aesop
@[deprecated (since := "2024-12-11")] alias fromColumns_inj := fromCols_inj
lemma fromCols_ext_iff (A₁ : Matrix m n₁ R) (A₂ : Matrix m n₂ R) (B₁ : Matrix m n₁ R)
(B₂ : Matrix m n₂ R) :
fromCols A₁ A₂ = fromCols B₁ B₂ ↔ A₁ = B₁ ∧ A₂ = B₂ := fromCols_inj.eq_iff
@[deprecated (since := "2024-12-11")] alias fromColumns_ext_iff := fromCols_ext_iff
lemma fromRows_ext_iff (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) (B₁ : Matrix m₁ n R)
(B₂ : Matrix m₂ n R) :
fromRows A₁ A₂ = fromRows B₁ B₂ ↔ A₁ = B₁ ∧ A₂ = B₂ := fromRows_inj.eq_iff
/-- A column partitioned matrix when transposed gives a row partitioned matrix with columns of the
initial matrix transposed to become rows. -/
lemma transpose_fromCols (A₁ : Matrix m n₁ R) (A₂ : Matrix m n₂ R) :
transpose (fromCols A₁ A₂) = fromRows (transpose A₁) (transpose A₂) := by
ext (i | i) j <;> simp
@[deprecated (since := "2024-12-11")] alias transpose_fromColumns := transpose_fromCols
/-- A row partitioned matrix when transposed gives a column partitioned matrix with rows of the
initial matrix transposed to become columns. -/
lemma transpose_fromRows (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) :
transpose (fromRows A₁ A₂) = fromCols (transpose A₁) (transpose A₂) := by
ext i (j | j) <;> simp
section Neg
variable [Neg R]
/-- Negating a matrix partitioned by rows is equivalent to negating each of the rows. -/
@[simp]
lemma fromRows_neg (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) :
-fromRows A₁ A₂ = fromRows (-A₁) (-A₂) := by
ext (i | i) j <;> simp
/-- Negating a matrix partitioned by columns is equivalent to negating each of the columns. -/
@[simp]
lemma fromCols_neg (A₁ : Matrix n m₁ R) (A₂ : Matrix n m₂ R) :
-fromCols A₁ A₂ = fromCols (-A₁) (-A₂) := by
ext i (j | j) <;> simp
@[deprecated (since := "2024-12-11")] alias fromColumns_neg := fromCols_neg
end Neg
@[simp]
lemma fromCols_fromRows_eq_fromBlocks (B₁₁ : Matrix m₁ n₁ R) (B₁₂ : Matrix m₁ n₂ R)
(B₂₁ : Matrix m₂ n₁ R) (B₂₂ : Matrix m₂ n₂ R) :
fromCols (fromRows B₁₁ B₂₁) (fromRows B₁₂ B₂₂) = fromBlocks B₁₁ B₁₂ B₂₁ B₂₂ := by
ext (_ | _) (_ | _) <;> simp
@[deprecated (since := "2024-12-11")]
alias fromColumns_fromRows_eq_fromBlocks := fromCols_fromRows_eq_fromBlocks
@[simp]
lemma fromRows_fromCols_eq_fromBlocks (B₁₁ : Matrix m₁ n₁ R) (B₁₂ : Matrix m₁ n₂ R)
(B₂₁ : Matrix m₂ n₁ R) (B₂₂ : Matrix m₂ n₂ R) :
fromRows (fromCols B₁₁ B₁₂) (fromCols B₂₁ B₂₂) = fromBlocks B₁₁ B₁₂ B₂₁ B₂₂ := by
ext (_ | _) (_ | _) <;> simp
@[deprecated (since := "2024-12-11")]
alias fromRows_fromColumn_eq_fromBlocks := fromRows_fromCols_eq_fromBlocks
section Semiring
variable [Semiring R]
@[simp]
lemma fromRows_mulVec [Fintype n] (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) (v : n → R) :
fromRows A₁ A₂ *ᵥ v = Sum.elim (A₁ *ᵥ v) (A₂ *ᵥ v) := by
ext (_ | _) <;> rfl
@[simp]
lemma vecMul_fromCols [Fintype m] (B₁ : Matrix m n₁ R) (B₂ : Matrix m n₂ R) (v : m → R) :
v ᵥ* fromCols B₁ B₂ = Sum.elim (v ᵥ* B₁) (v ᵥ* B₂) := by
ext (_ | _) <;> rfl
@[deprecated (since := "2024-12-11")] alias vecMul_fromColumns := vecMul_fromCols
@[simp]
lemma sumElim_vecMul_fromRows [Fintype m₁] [Fintype m₂] (B₁ : Matrix m₁ n R) (B₂ : Matrix m₂ n R)
(v₁ : m₁ → R) (v₂ : m₂ → R) :
Sum.elim v₁ v₂ ᵥ* fromRows B₁ B₂ = v₁ ᵥ* B₁ + v₂ ᵥ* B₂ := by
ext
simp [Matrix.vecMul, fromRows, dotProduct]
@[deprecated (since := "2025-02-21")] alias sum_elim_vecMul_fromRows := sumElim_vecMul_fromRows
@[simp]
lemma fromCols_mulVec_sumElim [Fintype n₁] [Fintype n₂]
(A₁ : Matrix m n₁ R) (A₂ : Matrix m n₂ R) (v₁ : n₁ → R) (v₂ : n₂ → R) :
fromCols A₁ A₂ *ᵥ Sum.elim v₁ v₂ = A₁ *ᵥ v₁ + A₂ *ᵥ v₂ := by
ext
simp [Matrix.mulVec, fromCols]
@[deprecated (since := "2025-02-21")] alias fromCols_mulVec_sum_elim := fromCols_mulVec_sumElim
@[deprecated (since := "2024-12-11")] alias fromColumns_mulVec_sum_elim := fromCols_mulVec_sumElim
@[simp]
lemma fromRows_mul [Fintype n] (A₁ : Matrix m₁ n R) (A₂ : Matrix m₂ n R) (B : Matrix n m R) :
fromRows A₁ A₂ * B = fromRows (A₁ * B) (A₂ * B) := by
ext (_ | _) _ <;> simp [mul_apply]
@[simp]
| lemma mul_fromCols [Fintype n] (A : Matrix m n R) (B₁ : Matrix n n₁ R) (B₂ : Matrix n n₂ R) :
A * fromCols B₁ B₂ = fromCols (A * B₁) (A * B₂) := by
ext _ (_ | _) <;> simp [mul_apply]
@[deprecated (since := "2024-12-11")] alias mul_fromColumns := mul_fromCols
| Mathlib/Data/Matrix/ColumnRowPartitioned.lean | 241 | 246 |
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.Constructions
/-!
# Neighborhoods and continuity relative to a subset
This file develops API on the relative versions
* `nhdsWithin` of `nhds`
* `ContinuousOn` of `Continuous`
* `ContinuousWithinAt` of `ContinuousAt`
related to continuity, which are defined in previous definition files.
Their basic properties studied in this file include the relationships between
these restricted notions and the corresponding notions for the subtype
equipped with the subspace topology.
## Notation
* `𝓝 x`: the filter of neighborhoods of a point `x`;
* `𝓟 s`: the principal filter of a set `s`;
* `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`.
-/
open Set Filter Function Topology Filter
variable {α β γ δ : Type*}
variable [TopologicalSpace α]
/-!
## Properties of the neighborhood-within filter
-/
@[simp]
theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a :=
bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl
@[simp]
theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x :=
Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x }
theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x :=
eventually_inf_principal
theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s :=
frequently_inf_principal.trans <| by simp only [and_comm]
theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} :
z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by
simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff]
@[simp]
theorem eventually_eventually_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by
refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩
simp only [eventually_nhdsWithin_iff] at h ⊢
exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs
@[simp]
theorem eventually_mem_nhdsWithin_iff {x : α} {s t : Set α} :
(∀ᶠ x' in 𝓝[s] x, t ∈ 𝓝[s] x') ↔ t ∈ 𝓝[s] x :=
eventually_eventually_nhdsWithin
theorem nhdsWithin_eq (a : α) (s : Set α) :
𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) :=
((nhds_basis_opens a).inf_principal s).eq_biInf
@[simp] lemma nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by
rw [nhdsWithin, principal_univ, inf_top_eq]
theorem nhdsWithin_hasBasis {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {a : α}
(h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t :=
h.inf_principal t
theorem nhdsWithin_basis_open (a : α) (t : Set α) :
(𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t :=
nhdsWithin_hasBasis (nhds_basis_opens a) t
theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by
simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff
theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t :=
(nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff
theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) :
s \ t ∈ 𝓝[tᶜ] x :=
diff_mem_inf_principal_compl hs t
theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) :
s \ t' ∈ 𝓝[t \ t'] x := by
rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc]
exact inter_mem_inf hs (mem_principal_self _)
theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) :
t ∈ 𝓝 a := by
rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩
exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw
theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t :=
eventually_inf_principal
theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by
simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and]
theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t :=
set_eventuallyEq_iff_inf_principal.symm
theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x :=
set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal
theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t)
(hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) :
π ⁻¹' s ∈ 𝓝[t] a := by
lift a to t using h
replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs
rwa [← map_nhds_subtype_val, mem_map]
theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a :=
mem_inf_of_left h
theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a :=
mem_inf_of_right (mem_principal_self s)
theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s :=
self_mem_nhdsWithin
theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a :=
inter_mem self_mem_nhdsWithin (mem_inf_of_left h)
theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a :=
le_inf (pure_le_nhds a) (le_principal_iff.2 ha)
theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t :=
pure_le_nhdsWithin ha ht
theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α}
(h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x :=
mem_of_mem_nhdsWithin hx h
theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) :
Tendsto (fun _ : β => a) l (𝓝[s] a) :=
tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha
theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) :
𝓝[s] a = 𝓝[s ∩ t] a :=
le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h)))
(inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left))
theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a :=
nhdsWithin_restrict'' s <| mem_inf_of_left h
theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) :
𝓝[s] a = 𝓝[s ∩ t] a :=
nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀)
theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a :=
nhdsWithin_le_iff.mpr h
theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by
rw [← nhdsWithin_univ]
apply nhdsWithin_le_of_mem
exact univ_mem
theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) :
𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂]
theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s)
(h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by
rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂]
@[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a :=
inf_eq_left.trans le_principal_iff
theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a :=
nhdsWithin_eq_nhds.2 <| h.mem_nhds ha
theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t)
(ht : IsOpen t)
(hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) :
π ⁻¹' s ∈ 𝓝 a := by
rw [← ht.nhdsWithin_eq h]
exact preimage_nhdsWithin_coinduced' h hs
@[simp]
theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq]
theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by
delta nhdsWithin
rw [← inf_sup_left, sup_principal]
theorem nhds_eq_nhdsWithin_sup_nhdsWithin (b : α) {I₁ I₂ : Set α} (hI : Set.univ = I₁ ∪ I₂) :
nhds b = nhdsWithin b I₁ ⊔ nhdsWithin b I₂ := by
rw [← nhdsWithin_univ b, hI, nhdsWithin_union]
/-- If `L` and `R` are neighborhoods of `b` within sets whose union is `Set.univ`, then
`L ∪ R` is a neighborhood of `b`. -/
theorem union_mem_nhds_of_mem_nhdsWithin {b : α}
{I₁ I₂ : Set α} (h : Set.univ = I₁ ∪ I₂)
{L : Set α} (hL : L ∈ nhdsWithin b I₁)
{R : Set α} (hR : R ∈ nhdsWithin b I₂) : L ∪ R ∈ nhds b := by
rw [← nhdsWithin_univ b, h, nhdsWithin_union]
exact ⟨mem_of_superset hL (by simp), mem_of_superset hR (by simp)⟩
/-- Writing a punctured neighborhood filter as a sup of left and right filters. -/
lemma punctured_nhds_eq_nhdsWithin_sup_nhdsWithin [LinearOrder α] {x : α} :
𝓝[≠] x = 𝓝[<] x ⊔ 𝓝[>] x := by
rw [← Iio_union_Ioi, nhdsWithin_union]
/-- Obtain a "predictably-sided" neighborhood of `b` from two one-sided neighborhoods. -/
theorem nhds_of_Ici_Iic [LinearOrder α] {b : α}
{L : Set α} (hL : L ∈ 𝓝[≤] b)
{R : Set α} (hR : R ∈ 𝓝[≥] b) : L ∩ Iic b ∪ R ∩ Ici b ∈ 𝓝 b :=
union_mem_nhds_of_mem_nhdsWithin Iic_union_Ici.symm
(inter_mem hL self_mem_nhdsWithin) (inter_mem hR self_mem_nhdsWithin)
theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) :
𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := by
induction I, hI using Set.Finite.induction_on with
| empty => simp
| insert _ _ hT => simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert]
theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) :
𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by
rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS]
theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) :
𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by
rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range]
theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by
delta nhdsWithin
rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem]
|
theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by
delta nhdsWithin
| Mathlib/Topology/ContinuousOn.lean | 247 | 249 |
/-
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.GroupTheory.Perm.Cycle.Type
import Mathlib.GroupTheory.Perm.Option
import Mathlib.Logic.Equiv.Fin.Rotate
import Mathlib.Logic.Equiv.Fintype
/-!
# Permutations of `Fin n`
-/
assert_not_exists LinearMap
open Equiv
/-- Permutations of `Fin (n + 1)` are equivalent to fixing a single
`Fin (n + 1)` and permuting the remaining with a `Perm (Fin n)`.
The fixed `Fin (n + 1)` is swapped with `0`. -/
def Equiv.Perm.decomposeFin {n : ℕ} : Perm (Fin n.succ) ≃ Fin n.succ × Perm (Fin n) :=
((Equiv.permCongr <| finSuccEquiv n).trans Equiv.Perm.decomposeOption).trans
(Equiv.prodCongr (finSuccEquiv n).symm (Equiv.refl _))
@[simp]
theorem Equiv.Perm.decomposeFin_symm_of_refl {n : ℕ} (p : Fin (n + 1)) :
Equiv.Perm.decomposeFin.symm (p, Equiv.refl _) = swap 0 p := by
simp [Equiv.Perm.decomposeFin, Equiv.permCongr_def]
@[simp]
theorem Equiv.Perm.decomposeFin_symm_of_one {n : ℕ} (p : Fin (n + 1)) :
Equiv.Perm.decomposeFin.symm (p, 1) = swap 0 p :=
Equiv.Perm.decomposeFin_symm_of_refl p
@[simp]
theorem Equiv.Perm.decomposeFin_symm_apply_zero {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) :
Equiv.Perm.decomposeFin.symm (p, e) 0 = p := by simp [Equiv.Perm.decomposeFin]
@[simp]
theorem Equiv.Perm.decomposeFin_symm_apply_succ {n : ℕ} (e : Perm (Fin n)) (p : Fin (n + 1))
(x : Fin n) : Equiv.Perm.decomposeFin.symm (p, e) x.succ = swap 0 p (e x).succ := by
refine Fin.cases ?_ ?_ p
· simp [Equiv.Perm.decomposeFin, EquivFunctor.map]
· intro i
by_cases h : i = e x
· simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map]
· simp [h, Equiv.Perm.decomposeFin, EquivFunctor.map, swap_apply_def, Ne.symm h]
@[simp]
theorem Equiv.Perm.decomposeFin_symm_apply_one {n : ℕ} (e : Perm (Fin (n + 1))) (p : Fin (n + 2)) :
Equiv.Perm.decomposeFin.symm (p, e) 1 = swap 0 p (e 0).succ := by
rw [← Fin.succ_zero_eq_one, Equiv.Perm.decomposeFin_symm_apply_succ e p 0]
@[simp]
theorem Equiv.Perm.decomposeFin.symm_sign {n : ℕ} (p : Fin (n + 1)) (e : Perm (Fin n)) :
Perm.sign (Equiv.Perm.decomposeFin.symm (p, e)) = ite (p = 0) 1 (-1) * Perm.sign e := by
refine Fin.cases ?_ ?_ p <;> simp [Equiv.Perm.decomposeFin]
/-- The set of all permutations of `Fin (n + 1)` can be constructed by augmenting the set of
permutations of `Fin n` by each element of `Fin (n + 1)` in turn. -/
theorem Finset.univ_perm_fin_succ {n : ℕ} :
@Finset.univ (Perm <| Fin n.succ) _ =
(Finset.univ : Finset <| Fin n.succ × Perm (Fin n)).map
Equiv.Perm.decomposeFin.symm.toEmbedding :=
(Finset.univ_map_equiv_to_embedding _).symm
section CycleRange
/-! ### `cycleRange` section
Define the permutations `Fin.cycleRange i`, the cycle `(0 1 2 ... i)`.
-/
open Equiv.Perm
theorem finRotate_succ_eq_decomposeFin {n : ℕ} :
finRotate n.succ = decomposeFin.symm (1, finRotate n) := by
ext i
cases n; · simp
refine Fin.cases ?_ (fun i => ?_) i
· simp
rw [coe_finRotate, decomposeFin_symm_apply_succ, if_congr i.succ_eq_last_succ rfl rfl]
split_ifs with h
· simp [h]
· rw [Fin.val_succ, Function.Injective.map_swap Fin.val_injective, Fin.val_succ, coe_finRotate,
if_neg h, Fin.val_zero, Fin.val_one,
swap_apply_of_ne_of_ne (Nat.succ_ne_zero _) (Nat.succ_succ_ne_one _)]
@[simp]
theorem sign_finRotate (n : ℕ) : Perm.sign (finRotate (n + 1)) = (-1) ^ n := by
induction n with
| zero => simp
| succ n ih =>
rw [finRotate_succ_eq_decomposeFin]
simp [ih, pow_succ]
@[simp]
theorem support_finRotate {n : ℕ} : support (finRotate (n + 2)) = Finset.univ := by
ext
simp
theorem support_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : support (finRotate n) = Finset.univ := by
obtain ⟨m, rfl⟩ := exists_add_of_le h
rw [add_comm, support_finRotate]
theorem isCycle_finRotate {n : ℕ} : IsCycle (finRotate (n + 2)) := by
refine ⟨0, by simp, fun x hx' => ⟨x, ?_⟩⟩
clear hx'
obtain ⟨x, hx⟩ := x
rw [zpow_natCast, Fin.ext_iff, Fin.val_mk]
induction' x with x ih; · rfl
rw [pow_succ', Perm.mul_apply, coe_finRotate_of_ne_last, ih (lt_trans x.lt_succ_self hx)]
rw [Ne, Fin.ext_iff, ih (lt_trans x.lt_succ_self hx), Fin.val_last]
exact ne_of_lt (Nat.lt_of_succ_lt_succ hx)
theorem isCycle_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : IsCycle (finRotate n) := by
obtain ⟨m, rfl⟩ := exists_add_of_le h
rw [add_comm]
exact isCycle_finRotate
@[simp]
theorem cycleType_finRotate {n : ℕ} : cycleType (finRotate (n + 2)) = {n + 2} := by
rw [isCycle_finRotate.cycleType, support_finRotate, ← Fintype.card, Fintype.card_fin]
theorem cycleType_finRotate_of_le {n : ℕ} (h : 2 ≤ n) : cycleType (finRotate n) = {n} := by
obtain ⟨m, rfl⟩ := exists_add_of_le h
rw [add_comm, cycleType_finRotate]
namespace Fin
/-- `Fin.cycleRange i` is the cycle `(0 1 2 ... i)` leaving `(i+1 ... (n-1))` unchanged. -/
def cycleRange {n : ℕ} (i : Fin n) : Perm (Fin n) :=
(finRotate (i + 1)).extendDomain
(Equiv.ofLeftInverse' (Fin.castLEEmb (Nat.succ_le_of_lt i.is_lt)) (↑)
(by
intro x
ext
simp))
theorem cycleRange_of_gt {n : ℕ} {i j : Fin n} (h : i < j) : cycleRange i j = j := by
rw [cycleRange, ofLeftInverse'_eq_ofInjective,
← Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding,
viaFintypeEmbedding_apply_not_mem_range]
simpa
theorem cycleRange_of_le {n : ℕ} [NeZero n] {i j : Fin n} (h : j ≤ i) :
cycleRange i j = if j = i then 0 else j + 1 := by
cases n
· subsingleton
have : j = (Fin.castLE (Nat.succ_le_of_lt i.is_lt))
⟨j, lt_of_le_of_lt h (Nat.lt_succ_self i)⟩ := by simp
ext
rw [this, cycleRange, ofLeftInverse'_eq_ofInjective, ←
Function.Embedding.toEquivRange_eq_ofInjective, ← viaFintypeEmbedding, ← coe_castLEEmb,
viaFintypeEmbedding_apply_image, coe_castLEEmb, coe_castLE, coe_finRotate]
simp only [Fin.ext_iff, val_last, val_mk, val_zero, Fin.eta, castLE_mk]
split_ifs with heq
· rfl
· rw [Fin.val_add_one_of_lt]
exact lt_of_lt_of_le (lt_of_le_of_ne h (mt (congr_arg _) heq)) (le_last i)
theorem coe_cycleRange_of_le {n : ℕ} {i j : Fin n} (h : j ≤ i) :
(cycleRange i j : ℕ) = if j = i then 0 else (j : ℕ) + 1 := by
rcases n with - | n
· exact absurd le_rfl i.pos.not_le
rw [cycleRange_of_le h]
split_ifs with h'
· rfl
exact
val_add_one_of_lt
(calc
(j : ℕ) < i := Fin.lt_iff_val_lt_val.mp (lt_of_le_of_ne h h')
_ ≤ n := Nat.lt_succ_iff.mp i.2)
theorem cycleRange_of_lt {n : ℕ} [NeZero n] {i j : Fin n} (h : j < i) : cycleRange i j = j + 1 := by
rw [cycleRange_of_le h.le, if_neg h.ne]
theorem coe_cycleRange_of_lt {n : ℕ} {i j : Fin n} (h : j < i) :
(cycleRange i j : ℕ) = j + 1 := by rw [coe_cycleRange_of_le h.le, if_neg h.ne]
theorem cycleRange_of_eq {n : ℕ} [NeZero n] {i j : Fin n} (h : j = i) : cycleRange i j = 0 := by
rw [cycleRange_of_le h.le, if_pos h]
@[simp]
theorem cycleRange_self {n : ℕ} [NeZero n] (i : Fin n) : cycleRange i i = 0 :=
cycleRange_of_eq rfl
theorem cycleRange_apply {n : ℕ} [NeZero n] (i j : Fin n) :
cycleRange i j = if j < i then j + 1 else if j = i then 0 else j := by
split_ifs with h₁ h₂
· exact cycleRange_of_lt h₁
· exact cycleRange_of_eq h₂
· exact cycleRange_of_gt (lt_of_le_of_ne (le_of_not_gt h₁) (Ne.symm h₂))
@[simp]
theorem cycleRange_zero (n : ℕ) [NeZero n] : cycleRange (0 : Fin n) = 1 := by
ext j
rcases (Fin.zero_le' j).eq_or_lt with rfl | hj
· simp
· rw [cycleRange_of_gt hj, one_apply]
@[simp]
theorem cycleRange_last (n : ℕ) : cycleRange (last n) = finRotate (n + 1) := by
ext i
rw [coe_cycleRange_of_le (le_last _), coe_finRotate]
@[simp]
theorem cycleRange_mk_zero {n : ℕ} (h : 0 < n) : cycleRange ⟨0, h⟩ = 1 :=
have : NeZero n := .of_pos h
cycleRange_zero n
@[deprecated (since := "2025-01-28")]
alias cycleRange_zero' := cycleRange_mk_zero
@[simp]
theorem sign_cycleRange {n : ℕ} (i : Fin n) : Perm.sign (cycleRange i) = (-1) ^ (i : ℕ) := by
simp [cycleRange]
@[simp]
theorem succAbove_cycleRange {n : ℕ} (i j : Fin n) :
i.succ.succAbove (i.cycleRange j) = swap 0 i.succ j.succ := by
cases n
· rcases j with ⟨_, ⟨⟩⟩
rcases lt_trichotomy j i with (hlt | heq | hgt)
· have : castSucc (j + 1) = j.succ := by
ext
rw [coe_castSucc, val_succ, Fin.val_add_one_of_lt (lt_of_lt_of_le hlt i.le_last)]
rw [Fin.cycleRange_of_lt hlt, Fin.succAbove_of_castSucc_lt, this, swap_apply_of_ne_of_ne]
· apply Fin.succ_ne_zero
· exact (Fin.succ_injective _).ne hlt.ne
· rw [Fin.lt_iff_val_lt_val]
simpa [this] using hlt
· rw [heq, Fin.cycleRange_self, Fin.succAbove_of_castSucc_lt, swap_apply_right, Fin.castSucc_zero]
· rw [Fin.castSucc_zero]
apply Fin.succ_pos
· rw [Fin.cycleRange_of_gt hgt, Fin.succAbove_of_le_castSucc, swap_apply_of_ne_of_ne]
· apply Fin.succ_ne_zero
· apply (Fin.succ_injective _).ne hgt.ne.symm
· simpa [Fin.le_iff_val_le_val] using hgt
@[simp]
theorem cycleRange_succAbove {n : ℕ} (i : Fin (n + 1)) (j : Fin n) :
i.cycleRange (i.succAbove j) = j.succ := by
rcases lt_or_ge (castSucc j) i with h | h
· rw [Fin.succAbove_of_castSucc_lt _ _ h, Fin.cycleRange_of_lt h, Fin.coeSucc_eq_succ]
· rw [Fin.succAbove_of_le_castSucc _ _ h, Fin.cycleRange_of_gt (Fin.le_castSucc_iff.mp h)]
@[simp]
theorem cycleRange_symm_zero {n : ℕ} [NeZero n] (i : Fin n) : i.cycleRange.symm 0 = i :=
| i.cycleRange.injective (by simp)
| Mathlib/GroupTheory/Perm/Fin.lean | 252 | 253 |
/-
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.Data.PFun
import Mathlib.Data.Part
/-!
# Image of a `Finset α` under a partially defined function
In this file we define `Part.toFinset` and `Finset.pimage`. We also prove some trivial lemmas about
these definitions.
## Tags
finite set, image, partial function
-/
variable {α β : Type*}
namespace Part
/-- Convert an `o : Part α` with decidable `Part.Dom o` to `Finset α`. -/
def toFinset (o : Part α) [Decidable o.Dom] : Finset α :=
o.toOption.toFinset
@[simp]
theorem mem_toFinset {o : Part α} [Decidable o.Dom] {x : α} : x ∈ o.toFinset ↔ x ∈ o := by
simp [toFinset]
@[simp]
theorem toFinset_none [Decidable (none : Part α).Dom] : none.toFinset = (∅ : Finset α) := by
simp [toFinset]
@[simp]
theorem toFinset_some {a : α} [Decidable (some a).Dom] : (some a).toFinset = {a} := by
simp [toFinset]
@[simp]
theorem coe_toFinset (o : Part α) [Decidable o.Dom] : (o.toFinset : Set α) = { x | x ∈ o } :=
Set.ext fun _ => mem_toFinset
end Part
namespace Finset
variable [DecidableEq β] {f g : α →. β} [∀ x, Decidable (f x).Dom] [∀ x, Decidable (g x).Dom]
{s t : Finset α} {b : β}
/-- Image of `s : Finset α` under a partially defined function `f : α →. β`. -/
def pimage (f : α →. β) [∀ x, Decidable (f x).Dom] (s : Finset α) : Finset β :=
s.biUnion fun x => (f x).toFinset
@[simp]
theorem mem_pimage : b ∈ s.pimage f ↔ ∃ a ∈ s, b ∈ f a := by
simp [pimage]
@[simp, norm_cast]
theorem coe_pimage : (s.pimage f : Set β) = f.image s :=
Set.ext fun _ => mem_pimage
@[simp]
| theorem pimage_some (s : Finset α) (f : α → β) [∀ x, Decidable (Part.some <| f x).Dom] :
(s.pimage fun x => Part.some (f x)) = s.image f := by
| Mathlib/Data/Finset/PImage.lean | 66 | 67 |
/-
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.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Regular.Pow
import Mathlib.Data.Finsupp.Antidiagonal
import Mathlib.Order.SymmDiff
/-!
# Multivariate polynomials
This file defines polynomial rings over a base ring (or even semiring),
with variables from a general type `σ` (which could be infinite).
## Important definitions
Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary
type. This file creates the type `MvPolynomial σ R`, which mathematicians
might denote $R[X_i : i \in σ]$. It is the type of multivariate
(a.k.a. multivariable) polynomials, with variables
corresponding to the terms in `σ`, and coefficients in `R`.
### Notation
In the definitions below, we use the following 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`
+ `a : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
### Definitions
* `MvPolynomial σ R` : the type of polynomials with variables of type `σ` and coefficients
in the commutative semiring `R`
* `monomial s a` : the monomial which mathematically would be denoted `a * X^s`
* `C a` : the constant polynomial with value `a`
* `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`.
* `coeff s p` : the coefficient of `s` in `p`.
## Implementation notes
Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite
support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`.
The definition of `MvPolynomial σ R` is `(σ →₀ ℕ) →₀ R`; here `σ →₀ ℕ` denotes the space of all
monomials in the variables, and the function to `R` sends a monomial to its coefficient in
the polynomial being represented.
## Tags
polynomial, multivariate polynomial, multivariable polynomial
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
open scoped Pointwise
universe u v w x
variable {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x}
/-- Multivariate polynomial, where `σ` is the index set of the variables and
`R` is the coefficient ring -/
def MvPolynomial (σ : Type*) (R : Type*) [CommSemiring R] :=
AddMonoidAlgebra R (σ →₀ ℕ)
namespace MvPolynomial
-- Porting note: because of `MvPolynomial.C` and `MvPolynomial.X` this linter throws
-- tons of warnings in this file, and it's easier to just disable them globally in the file
variable {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
section Instances
instance decidableEqMvPolynomial [CommSemiring R] [DecidableEq σ] [DecidableEq R] :
DecidableEq (MvPolynomial σ R) :=
Finsupp.instDecidableEq
instance commSemiring [CommSemiring R] : CommSemiring (MvPolynomial σ R) :=
AddMonoidAlgebra.commSemiring
instance inhabited [CommSemiring R] : Inhabited (MvPolynomial σ R) :=
⟨0⟩
instance distribuMulAction [Monoid R] [CommSemiring S₁] [DistribMulAction R S₁] :
DistribMulAction R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.distribMulAction
instance smulZeroClass [CommSemiring S₁] [SMulZeroClass R S₁] :
SMulZeroClass R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulZeroClass
instance faithfulSMul [CommSemiring S₁] [SMulZeroClass R S₁] [FaithfulSMul R S₁] :
FaithfulSMul R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.faithfulSMul
instance module [Semiring R] [CommSemiring S₁] [Module R S₁] : Module R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.module
instance isScalarTower [CommSemiring S₂] [SMul R S₁] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[IsScalarTower R S₁ S₂] : IsScalarTower R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.isScalarTower
instance smulCommClass [CommSemiring S₂] [SMulZeroClass R S₂] [SMulZeroClass S₁ S₂]
[SMulCommClass R S₁ S₂] : SMulCommClass R S₁ (MvPolynomial σ S₂) :=
AddMonoidAlgebra.smulCommClass
instance isCentralScalar [CommSemiring S₁] [SMulZeroClass R S₁] [SMulZeroClass Rᵐᵒᵖ S₁]
[IsCentralScalar R S₁] : IsCentralScalar R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isCentralScalar
instance algebra [CommSemiring R] [CommSemiring S₁] [Algebra R S₁] :
Algebra R (MvPolynomial σ S₁) :=
AddMonoidAlgebra.algebra
instance isScalarTower_right [CommSemiring S₁] [DistribSMul R S₁] [IsScalarTower R S₁ S₁] :
IsScalarTower R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.isScalarTower_self _
instance smulCommClass_right [CommSemiring S₁] [DistribSMul R S₁] [SMulCommClass R S₁ S₁] :
SMulCommClass R (MvPolynomial σ S₁) (MvPolynomial σ S₁) :=
AddMonoidAlgebra.smulCommClass_self _
/-- If `R` is a subsingleton, then `MvPolynomial σ R` has a unique element -/
instance unique [CommSemiring R] [Subsingleton R] : Unique (MvPolynomial σ R) :=
AddMonoidAlgebra.unique
end Instances
variable [CommSemiring R] [CommSemiring S₁] {p q : MvPolynomial σ R}
/-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/
def monomial (s : σ →₀ ℕ) : R →ₗ[R] MvPolynomial σ R :=
AddMonoidAlgebra.lsingle s
theorem one_def : (1 : MvPolynomial σ R) = monomial 0 1 := rfl
theorem single_eq_monomial (s : σ →₀ ℕ) (a : R) : Finsupp.single s a = monomial s a :=
rfl
theorem mul_def : p * q = p.sum fun m a => q.sum fun n b => monomial (m + n) (a * b) :=
AddMonoidAlgebra.mul_def
/-- `C a` is the constant polynomial with value `a` -/
def C : R →+* MvPolynomial σ R :=
{ singleZeroRingHom with toFun := monomial 0 }
variable (R σ)
@[simp]
theorem algebraMap_eq : algebraMap R (MvPolynomial σ R) = C :=
rfl
variable {R σ}
/-- `X n` is the degree `1` monomial $X_n$. -/
def X (n : σ) : MvPolynomial σ R :=
monomial (Finsupp.single n 1) 1
theorem monomial_left_injective {r : R} (hr : r ≠ 0) :
Function.Injective fun s : σ →₀ ℕ => monomial s r :=
Finsupp.single_left_injective hr
@[simp]
theorem monomial_left_inj {s t : σ →₀ ℕ} {r : R} (hr : r ≠ 0) :
monomial s r = monomial t r ↔ s = t :=
Finsupp.single_left_inj hr
theorem C_apply : (C a : MvPolynomial σ R) = monomial 0 a :=
rfl
@[simp]
theorem C_0 : C 0 = (0 : MvPolynomial σ R) := map_zero _
@[simp]
theorem C_1 : C 1 = (1 : MvPolynomial σ R) :=
rfl
theorem C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by
-- Porting note: this `show` feels like defeq abuse, but I can't find the appropriate lemmas
show AddMonoidAlgebra.single _ _ * AddMonoidAlgebra.single _ _ = AddMonoidAlgebra.single _ _
simp [C_apply, single_mul_single]
@[simp]
theorem C_add : (C (a + a') : MvPolynomial σ R) = C a + C a' :=
Finsupp.single_add _ _ _
@[simp]
theorem C_mul : (C (a * a') : MvPolynomial σ R) = C a * C a' :=
C_mul_monomial.symm
@[simp]
theorem C_pow (a : R) (n : ℕ) : (C (a ^ n) : MvPolynomial σ R) = C a ^ n :=
map_pow _ _ _
theorem C_injective (σ : Type*) (R : Type*) [CommSemiring R] :
Function.Injective (C : R → MvPolynomial σ R) :=
Finsupp.single_injective _
theorem C_surjective {R : Type*} [CommSemiring R] (σ : Type*) [IsEmpty σ] :
Function.Surjective (C : R → MvPolynomial σ R) := by
refine fun p => ⟨p.toFun 0, Finsupp.ext fun a => ?_⟩
simp only [C_apply, ← single_eq_monomial, (Finsupp.ext isEmptyElim (α := σ) : a = 0),
single_eq_same]
rfl
@[simp]
theorem C_inj {σ : Type*} (R : Type*) [CommSemiring R] (r s : R) :
(C r : MvPolynomial σ R) = C s ↔ r = s :=
(C_injective σ R).eq_iff
@[simp] lemma C_eq_zero : (C a : MvPolynomial σ R) = 0 ↔ a = 0 := by rw [← map_zero C, C_inj]
lemma C_ne_zero : (C a : MvPolynomial σ R) ≠ 0 ↔ a ≠ 0 :=
C_eq_zero.ne
instance nontrivial_of_nontrivial (σ : Type*) (R : Type*) [CommSemiring R] [Nontrivial R] :
Nontrivial (MvPolynomial σ R) :=
inferInstanceAs (Nontrivial <| AddMonoidAlgebra R (σ →₀ ℕ))
instance infinite_of_infinite (σ : Type*) (R : Type*) [CommSemiring R] [Infinite R] :
Infinite (MvPolynomial σ R) :=
Infinite.of_injective C (C_injective _ _)
instance infinite_of_nonempty (σ : Type*) (R : Type*) [Nonempty σ] [CommSemiring R]
[Nontrivial R] : Infinite (MvPolynomial σ R) :=
Infinite.of_injective ((fun s : σ →₀ ℕ => monomial s 1) ∘ Finsupp.single (Classical.arbitrary σ))
<| (monomial_left_injective one_ne_zero).comp (Finsupp.single_injective _)
theorem C_eq_coe_nat (n : ℕ) : (C ↑n : MvPolynomial σ R) = n := by
induction n <;> simp [*]
theorem C_mul' : MvPolynomial.C a * p = a • p :=
(Algebra.smul_def a p).symm
theorem smul_eq_C_mul (p : MvPolynomial σ R) (a : R) : a • p = C a * p :=
C_mul'.symm
theorem C_eq_smul_one : (C a : MvPolynomial σ R) = a • (1 : MvPolynomial σ R) := by
rw [← C_mul', mul_one]
theorem smul_monomial {S₁ : Type*} [SMulZeroClass S₁ R] (r : S₁) :
r • monomial s a = monomial s (r • a) :=
Finsupp.smul_single _ _ _
theorem X_injective [Nontrivial R] : Function.Injective (X : σ → MvPolynomial σ R) :=
(monomial_left_injective one_ne_zero).comp (Finsupp.single_left_injective one_ne_zero)
@[simp]
theorem X_inj [Nontrivial R] (m n : σ) : X m = (X n : MvPolynomial σ R) ↔ m = n :=
X_injective.eq_iff
theorem monomial_pow : monomial s a ^ e = monomial (e • s) (a ^ e) :=
AddMonoidAlgebra.single_pow e
@[simp]
theorem monomial_mul {s s' : σ →₀ ℕ} {a b : R} :
monomial s a * monomial s' b = monomial (s + s') (a * b) :=
AddMonoidAlgebra.single_mul_single
variable (σ R)
/-- `fun s ↦ monomial s 1` as a homomorphism. -/
def monomialOneHom : Multiplicative (σ →₀ ℕ) →* MvPolynomial σ R :=
AddMonoidAlgebra.of _ _
variable {σ R}
@[simp]
theorem monomialOneHom_apply : monomialOneHom R σ s = (monomial s 1 : MvPolynomial σ R) :=
rfl
theorem X_pow_eq_monomial : X n ^ e = monomial (Finsupp.single n e) (1 : R) := by
simp [X, monomial_pow]
theorem monomial_add_single : monomial (s + Finsupp.single n e) a = monomial s a * X n ^ e := by
rw [X_pow_eq_monomial, monomial_mul, mul_one]
theorem monomial_single_add : monomial (Finsupp.single n e + s) a = X n ^ e * monomial s a := by
rw [X_pow_eq_monomial, monomial_mul, one_mul]
theorem C_mul_X_pow_eq_monomial {s : σ} {a : R} {n : ℕ} :
C a * X s ^ n = monomial (Finsupp.single s n) a := by
rw [← zero_add (Finsupp.single s n), monomial_add_single, C_apply]
theorem C_mul_X_eq_monomial {s : σ} {a : R} : C a * X s = monomial (Finsupp.single s 1) a := by
rw [← C_mul_X_pow_eq_monomial, pow_one]
@[simp]
theorem monomial_zero {s : σ →₀ ℕ} : monomial s (0 : R) = 0 :=
Finsupp.single_zero _
@[simp]
theorem monomial_zero' : (monomial (0 : σ →₀ ℕ) : R → MvPolynomial σ R) = C :=
rfl
@[simp]
theorem monomial_eq_zero {s : σ →₀ ℕ} {b : R} : monomial s b = 0 ↔ b = 0 :=
Finsupp.single_eq_zero
@[simp]
theorem sum_monomial_eq {A : Type*} [AddCommMonoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A}
(w : b u 0 = 0) : sum (monomial u r) b = b u r :=
Finsupp.sum_single_index w
@[simp]
theorem sum_C {A : Type*} [AddCommMonoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) :
sum (C a) b = b 0 a :=
sum_monomial_eq w
theorem monomial_sum_one {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) :
(monomial (∑ i ∈ s, f i) 1 : MvPolynomial σ R) = ∏ i ∈ s, monomial (f i) 1 :=
map_prod (monomialOneHom R σ) (fun i => Multiplicative.ofAdd (f i)) s
theorem monomial_sum_index {α : Type*} (s : Finset α) (f : α → σ →₀ ℕ) (a : R) :
monomial (∑ i ∈ s, f i) a = C a * ∏ i ∈ s, monomial (f i) 1 := by
rw [← monomial_sum_one, C_mul', ← (monomial _).map_smul, smul_eq_mul, mul_one]
theorem monomial_finsupp_sum_index {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → σ →₀ ℕ)
(a : R) : monomial (f.sum g) a = C a * f.prod fun a b => monomial (g a b) 1 :=
monomial_sum_index _ _ _
theorem monomial_eq_monomial_iff {α : Type*} (a₁ a₂ : α →₀ ℕ) (b₁ b₂ : R) :
monomial a₁ b₁ = monomial a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 :=
Finsupp.single_eq_single_iff _ _ _ _
theorem monomial_eq : monomial s a = C a * (s.prod fun n e => X n ^ e : MvPolynomial σ R) := by
simp only [X_pow_eq_monomial, ← monomial_finsupp_sum_index, Finsupp.sum_single]
@[simp]
lemma prod_X_pow_eq_monomial : ∏ x ∈ s.support, X x ^ s x = monomial s (1 : R) := by
simp only [monomial_eq, map_one, one_mul, Finsupp.prod]
@[elab_as_elim]
theorem induction_on_monomial {motive : MvPolynomial σ R → Prop}
(C : ∀ a, motive (C a))
(mul_X : ∀ p n, motive p → motive (p * X n)) : ∀ s a, motive (monomial s a) := by
intro s a
apply @Finsupp.induction σ ℕ _ _ s
· show motive (monomial 0 a)
exact C a
· intro n e p _hpn _he ih
have : ∀ e : ℕ, motive (monomial p a * X n ^ e) := by
intro e
induction e with
| zero => simp [ih]
| succ e e_ih => simp [ih, pow_succ, (mul_assoc _ _ _).symm, mul_X, e_ih]
simp [add_comm, monomial_add_single, this]
/-- Analog of `Polynomial.induction_on'`.
To prove something about mv_polynomials,
it suffices to show the condition is closed under taking sums,
and it holds for monomials. -/
@[elab_as_elim]
theorem induction_on' {P : MvPolynomial σ R → Prop} (p : MvPolynomial σ R)
(monomial : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a))
(add : ∀ p q : MvPolynomial σ R, P p → P q → P (p + q)) : P p :=
Finsupp.induction p
(suffices P (MvPolynomial.monomial 0 0) by rwa [monomial_zero] at this
show P (MvPolynomial.monomial 0 0) from monomial 0 0)
fun _ _ _ _ha _hb hPf => add _ _ (monomial _ _) hPf
/--
Similar to `MvPolynomial.induction_on` but only a weak form of `h_add` is required.
In particular, this version only requires us to show
that `motive` is closed under addition of nontrivial monomials not present in the support.
-/
@[elab_as_elim]
theorem monomial_add_induction_on {motive : MvPolynomial σ R → Prop} (p : MvPolynomial σ R)
(C : ∀ a, motive (C a))
(monomial_add :
∀ (a : σ →₀ ℕ) (b : R) (f : MvPolynomial σ R),
a ∉ f.support → b ≠ 0 → motive f → motive ((monomial a b) + f)) :
motive p :=
Finsupp.induction p (C_0.rec <| C 0) monomial_add
@[deprecated (since := "2025-03-11")]
alias induction_on''' := monomial_add_induction_on
/--
Similar to `MvPolynomial.induction_on` but only a yet weaker form of `h_add` is required.
In particular, this version only requires us to show
that `motive` is closed under addition of monomials not present in the support
for which `motive` is already known to hold.
-/
theorem induction_on'' {motive : MvPolynomial σ R → Prop} (p : MvPolynomial σ R)
(C : ∀ a, motive (C a))
(monomial_add :
∀ (a : σ →₀ ℕ) (b : R) (f : MvPolynomial σ R),
a ∉ f.support → b ≠ 0 → motive f → motive (monomial a b) →
motive ((monomial a b) + f))
(mul_X : ∀ (p : MvPolynomial σ R) (n : σ), motive p → motive (p * MvPolynomial.X n)) :
motive p :=
monomial_add_induction_on p C fun a b f ha hb hf =>
monomial_add a b f ha hb hf <| induction_on_monomial C mul_X a b
/--
Analog of `Polynomial.induction_on`.
If a property holds for any constant polynomial
and is preserved under addition and multiplication by variables
then it holds for all multivariate polynomials.
-/
@[recursor 5]
theorem induction_on {motive : MvPolynomial σ R → Prop} (p : MvPolynomial σ R)
(C : ∀ a, motive (C a))
(add : ∀ p q, motive p → motive q → motive (p + q))
(mul_X : ∀ p n, motive p → motive (p * X n)) : motive p :=
induction_on'' p C (fun a b f _ha _hb hf hm => add (monomial a b) f hm hf) mul_X
theorem ringHom_ext {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by
refine AddMonoidAlgebra.ringHom_ext' ?_ ?_
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): this has high priority, but Lean still chooses `RingHom.ext`, why?
-- probably because of the type synonym
· ext x
exact hC _
· apply Finsupp.mulHom_ext'; intros x
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `Finsupp.mulHom_ext'` needs to have increased priority
apply MonoidHom.ext_mnat
exact hX _
/-- See note [partially-applied ext lemmas]. -/
@[ext 1100]
theorem ringHom_ext' {A : Type*} [Semiring A] {f g : MvPolynomial σ R →+* A}
(hC : f.comp C = g.comp C) (hX : ∀ i, f (X i) = g (X i)) : f = g :=
ringHom_ext (RingHom.ext_iff.1 hC) hX
theorem hom_eq_hom [Semiring S₂] (f g : MvPolynomial σ R →+* S₂) (hC : f.comp C = g.comp C)
(hX : ∀ n : σ, f (X n) = g (X n)) (p : MvPolynomial σ R) : f p = g p :=
RingHom.congr_fun (ringHom_ext' hC hX) p
theorem is_id (f : MvPolynomial σ R →+* MvPolynomial σ R) (hC : f.comp C = C)
(hX : ∀ n : σ, f (X n) = X n) (p : MvPolynomial σ R) : f p = p :=
hom_eq_hom f (RingHom.id _) hC hX p
@[ext 1100]
theorem algHom_ext' {A B : Type*} [CommSemiring A] [CommSemiring B] [Algebra R A] [Algebra R B]
{f g : MvPolynomial σ A →ₐ[R] B}
(h₁ :
f.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)) =
g.comp (IsScalarTower.toAlgHom R A (MvPolynomial σ A)))
(h₂ : ∀ i, f (X i) = g (X i)) : f = g :=
AlgHom.coe_ringHom_injective (MvPolynomial.ringHom_ext' (congr_arg AlgHom.toRingHom h₁) h₂)
@[ext 1200]
theorem algHom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : MvPolynomial σ R →ₐ[R] A}
(hf : ∀ i : σ, f (X i) = g (X i)) : f = g :=
AddMonoidAlgebra.algHom_ext' (mulHom_ext' fun X : σ => MonoidHom.ext_mnat (hf X))
@[simp]
theorem algHom_C {A : Type*} [Semiring A] [Algebra R A] (f : MvPolynomial σ R →ₐ[R] A) (r : R) :
f (C r) = algebraMap R A r :=
f.commutes r
@[simp]
theorem adjoin_range_X : Algebra.adjoin R (range (X : σ → MvPolynomial σ R)) = ⊤ := by
set S := Algebra.adjoin R (range (X : σ → MvPolynomial σ R))
refine top_unique fun p hp => ?_; clear hp
induction p using MvPolynomial.induction_on with
| C => exact S.algebraMap_mem _
| add p q hp hq => exact S.add_mem hp hq
| mul_X p i hp => exact S.mul_mem hp (Algebra.subset_adjoin <| mem_range_self _)
@[ext]
theorem linearMap_ext {M : Type*} [AddCommMonoid M] [Module R M] {f g : MvPolynomial σ R →ₗ[R] M}
(h : ∀ s, f ∘ₗ monomial s = g ∘ₗ monomial s) : f = g :=
Finsupp.lhom_ext' h
section Support
/-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/
def support (p : MvPolynomial σ R) : Finset (σ →₀ ℕ) :=
Finsupp.support p
theorem finsupp_support_eq_support (p : MvPolynomial σ R) : Finsupp.support p = p.support :=
rfl
theorem support_monomial [h : Decidable (a = 0)] :
(monomial s a).support = if a = 0 then ∅ else {s} := by
rw [← Subsingleton.elim (Classical.decEq R a 0) h]
rfl
theorem support_monomial_subset : (monomial s a).support ⊆ {s} :=
support_single_subset
theorem support_add [DecidableEq σ] : (p + q).support ⊆ p.support ∪ q.support :=
Finsupp.support_add
theorem support_X [Nontrivial R] : (X n : MvPolynomial σ R).support = {Finsupp.single n 1} := by
classical rw [X, support_monomial, if_neg]; exact one_ne_zero
theorem support_X_pow [Nontrivial R] (s : σ) (n : ℕ) :
(X s ^ n : MvPolynomial σ R).support = {Finsupp.single s n} := by
classical
rw [X_pow_eq_monomial, support_monomial, if_neg (one_ne_zero' R)]
@[simp]
theorem support_zero : (0 : MvPolynomial σ R).support = ∅ :=
rfl
theorem support_smul {S₁ : Type*} [SMulZeroClass S₁ R] {a : S₁} {f : MvPolynomial σ R} :
(a • f).support ⊆ f.support :=
Finsupp.support_smul
theorem support_sum {α : Type*} [DecidableEq σ] {s : Finset α} {f : α → MvPolynomial σ R} :
(∑ x ∈ s, f x).support ⊆ s.biUnion fun x => (f x).support :=
Finsupp.support_finset_sum
end Support
section Coeff
/-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/
def coeff (m : σ →₀ ℕ) (p : MvPolynomial σ R) : R :=
@DFunLike.coe ((σ →₀ ℕ) →₀ R) _ _ _ p m
@[simp]
theorem mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by
simp [support, coeff]
theorem not_mem_support_iff {p : MvPolynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 :=
by simp
theorem sum_def {A} [AddCommMonoid A] {p : MvPolynomial σ R} {b : (σ →₀ ℕ) → R → A} :
p.sum b = ∑ m ∈ p.support, b m (p.coeff m) := by simp [support, Finsupp.sum, coeff]
theorem support_mul [DecidableEq σ] (p q : MvPolynomial σ R) :
(p * q).support ⊆ p.support + q.support :=
AddMonoidAlgebra.support_mul p q
@[ext]
theorem ext (p q : MvPolynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q :=
Finsupp.ext
@[simp]
theorem coeff_add (m : σ →₀ ℕ) (p q : MvPolynomial σ R) : coeff m (p + q) = coeff m p + coeff m q :=
add_apply p q m
@[simp]
theorem coeff_smul {S₁ : Type*} [SMulZeroClass S₁ R] (m : σ →₀ ℕ) (C : S₁) (p : MvPolynomial σ R) :
coeff m (C • p) = C • coeff m p :=
smul_apply C p m
@[simp]
theorem coeff_zero (m : σ →₀ ℕ) : coeff m (0 : MvPolynomial σ R) = 0 :=
rfl
@[simp]
theorem coeff_zero_X (i : σ) : coeff 0 (X i : MvPolynomial σ R) = 0 :=
single_eq_of_ne fun h => by cases Finsupp.single_eq_zero.1 h
/-- `MvPolynomial.coeff m` but promoted to an `AddMonoidHom`. -/
@[simps]
def coeffAddMonoidHom (m : σ →₀ ℕ) : MvPolynomial σ R →+ R where
toFun := coeff m
map_zero' := coeff_zero m
map_add' := coeff_add m
variable (R) in
/-- `MvPolynomial.coeff m` but promoted to a `LinearMap`. -/
@[simps]
def lcoeff (m : σ →₀ ℕ) : MvPolynomial σ R →ₗ[R] R where
toFun := coeff m
map_add' := coeff_add m
map_smul' := coeff_smul m
theorem coeff_sum {X : Type*} (s : Finset X) (f : X → MvPolynomial σ R) (m : σ →₀ ℕ) :
coeff m (∑ x ∈ s, f x) = ∑ x ∈ s, coeff m (f x) :=
map_sum (@coeffAddMonoidHom R σ _ _) _ s
theorem monic_monomial_eq (m) :
monomial m (1 : R) = (m.prod fun n e => X n ^ e : MvPolynomial σ R) := by simp [monomial_eq]
@[simp]
theorem coeff_monomial [DecidableEq σ] (m n) (a) :
coeff m (monomial n a : MvPolynomial σ R) = if n = m then a else 0 :=
Finsupp.single_apply
@[simp]
theorem coeff_C [DecidableEq σ] (m) (a) :
coeff m (C a : MvPolynomial σ R) = if 0 = m then a else 0 :=
Finsupp.single_apply
lemma eq_C_of_isEmpty [IsEmpty σ] (p : MvPolynomial σ R) :
p = C (p.coeff 0) := by
obtain ⟨x, rfl⟩ := C_surjective σ p
simp
theorem coeff_one [DecidableEq σ] (m) : coeff m (1 : MvPolynomial σ R) = if 0 = m then 1 else 0 :=
coeff_C m 1
@[simp]
theorem coeff_zero_C (a) : coeff 0 (C a : MvPolynomial σ R) = a :=
single_eq_same
@[simp]
theorem coeff_zero_one : coeff 0 (1 : MvPolynomial σ R) = 1 :=
coeff_zero_C 1
theorem coeff_X_pow [DecidableEq σ] (i : σ) (m) (k : ℕ) :
coeff m (X i ^ k : MvPolynomial σ R) = if Finsupp.single i k = m then 1 else 0 := by
have := coeff_monomial m (Finsupp.single i k) (1 : R)
rwa [@monomial_eq _ _ (1 : R) (Finsupp.single i k) _, C_1, one_mul, Finsupp.prod_single_index]
at this
exact pow_zero _
theorem coeff_X' [DecidableEq σ] (i : σ) (m) :
coeff m (X i : MvPolynomial σ R) = if Finsupp.single i 1 = m then 1 else 0 := by
rw [← coeff_X_pow, pow_one]
@[simp]
theorem coeff_X (i : σ) : coeff (Finsupp.single i 1) (X i : MvPolynomial σ R) = 1 := by
classical rw [coeff_X', if_pos rfl]
@[simp]
theorem coeff_C_mul (m) (a : R) (p : MvPolynomial σ R) : coeff m (C a * p) = a * coeff m p := by
classical
rw [mul_def, sum_C]
· simp +contextual [sum_def, coeff_sum]
simp
theorem coeff_mul [DecidableEq σ] (p q : MvPolynomial σ R) (n : σ →₀ ℕ) :
coeff n (p * q) = ∑ x ∈ Finset.antidiagonal n, coeff x.1 p * coeff x.2 q :=
AddMonoidAlgebra.mul_apply_antidiagonal p q _ _ Finset.mem_antidiagonal
@[simp]
theorem coeff_mul_monomial (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff (m + s) (p * monomial s r) = coeff m p * r :=
AddMonoidAlgebra.mul_single_apply_aux p _ _ _ _ fun _a _ => add_left_inj _
@[simp]
theorem coeff_monomial_mul (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff (s + m) (monomial s r * p) = r * coeff m p :=
AddMonoidAlgebra.single_mul_apply_aux p _ _ _ _ fun _a _ => add_right_inj _
@[simp]
theorem coeff_mul_X (m) (s : σ) (p : MvPolynomial σ R) :
coeff (m + Finsupp.single s 1) (p * X s) = coeff m p :=
(coeff_mul_monomial _ _ _ _).trans (mul_one _)
@[simp]
theorem coeff_X_mul (m) (s : σ) (p : MvPolynomial σ R) :
coeff (Finsupp.single s 1 + m) (X s * p) = coeff m p :=
(coeff_monomial_mul _ _ _ _).trans (one_mul _)
lemma coeff_single_X_pow [DecidableEq σ] (s s' : σ) (n n' : ℕ) :
(X (R := R) s ^ n).coeff (Finsupp.single s' n')
= if s = s' ∧ n = n' ∨ n = 0 ∧ n' = 0 then 1 else 0 := by
simp only [coeff_X_pow, single_eq_single_iff]
@[simp]
lemma coeff_single_X [DecidableEq σ] (s s' : σ) (n : ℕ) :
(X s).coeff (R := R) (Finsupp.single s' n) = if n = 1 ∧ s = s' then 1 else 0 := by
simpa [eq_comm, and_comm] using coeff_single_X_pow s s' 1 n
@[simp]
theorem support_mul_X (s : σ) (p : MvPolynomial σ R) :
(p * X s).support = p.support.map (addRightEmbedding (Finsupp.single s 1)) :=
AddMonoidAlgebra.support_mul_single p _ (by simp) _
@[simp]
theorem support_X_mul (s : σ) (p : MvPolynomial σ R) :
(X s * p).support = p.support.map (addLeftEmbedding (Finsupp.single s 1)) :=
AddMonoidAlgebra.support_single_mul p _ (by simp) _
@[simp]
theorem support_smul_eq {S₁ : Type*} [Semiring S₁] [Module S₁ R] [NoZeroSMulDivisors S₁ R] {a : S₁}
(h : a ≠ 0) (p : MvPolynomial σ R) : (a • p).support = p.support :=
Finsupp.support_smul_eq h
theorem support_sdiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) :
p.support \ q.support ⊆ (p + q).support := by
intro m hm
simp only [Classical.not_not, mem_support_iff, Finset.mem_sdiff, Ne] at hm
simp [hm.2, hm.1]
open scoped symmDiff in
theorem support_symmDiff_support_subset_support_add [DecidableEq σ] (p q : MvPolynomial σ R) :
p.support ∆ q.support ⊆ (p + q).support := by
rw [symmDiff_def, Finset.sup_eq_union]
apply Finset.union_subset
· exact support_sdiff_support_subset_support_add p q
· rw [add_comm]
exact support_sdiff_support_subset_support_add q p
theorem coeff_mul_monomial' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff m (p * monomial s r) = if s ≤ m then coeff (m - s) p * r else 0 := by
classical
split_ifs with h
· conv_rhs => rw [← coeff_mul_monomial _ s]
congr with t
rw [tsub_add_cancel_of_le h]
· contrapose! h
rw [← mem_support_iff] at h
obtain ⟨j, -, rfl⟩ : ∃ j ∈ support p, j + s = m := by
simpa [Finset.mem_add]
using Finset.add_subset_add_left support_monomial_subset <| support_mul _ _ h
exact le_add_left le_rfl
theorem coeff_monomial_mul' (m) (s : σ →₀ ℕ) (r : R) (p : MvPolynomial σ R) :
coeff m (monomial s r * p) = if s ≤ m then r * coeff (m - s) p else 0 := by
-- note that if we allow `R` to be non-commutative we will have to duplicate the proof above.
rw [mul_comm, mul_comm r]
exact coeff_mul_monomial' _ _ _ _
theorem coeff_mul_X' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) :
coeff m (p * X s) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by
refine (coeff_mul_monomial' _ _ _ _).trans ?_
simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero,
mul_one]
theorem coeff_X_mul' [DecidableEq σ] (m) (s : σ) (p : MvPolynomial σ R) :
coeff m (X s * p) = if s ∈ m.support then coeff (m - Finsupp.single s 1) p else 0 := by
refine (coeff_monomial_mul' _ _ _ _).trans ?_
simp_rw [Finsupp.single_le_iff, Finsupp.mem_support_iff, Nat.succ_le_iff, pos_iff_ne_zero,
one_mul]
theorem eq_zero_iff {p : MvPolynomial σ R} : p = 0 ↔ ∀ d, coeff d p = 0 := by
rw [MvPolynomial.ext_iff]
simp only [coeff_zero]
theorem ne_zero_iff {p : MvPolynomial σ R} : p ≠ 0 ↔ ∃ d, coeff d p ≠ 0 := by
rw [Ne, eq_zero_iff]
push_neg
rfl
@[simp]
theorem X_ne_zero [Nontrivial R] (s : σ) :
X (R := R) s ≠ 0 := by
rw [ne_zero_iff]
use Finsupp.single s 1
simp only [coeff_X, ne_eq, one_ne_zero, not_false_eq_true]
@[simp]
theorem support_eq_empty {p : MvPolynomial σ R} : p.support = ∅ ↔ p = 0 :=
Finsupp.support_eq_empty
@[simp]
lemma support_nonempty {p : MvPolynomial σ R} : p.support.Nonempty ↔ p ≠ 0 := by
rw [Finset.nonempty_iff_ne_empty, ne_eq, support_eq_empty]
theorem exists_coeff_ne_zero {p : MvPolynomial σ R} (h : p ≠ 0) : ∃ d, coeff d p ≠ 0 :=
ne_zero_iff.mp h
theorem C_dvd_iff_dvd_coeff (r : R) (φ : MvPolynomial σ R) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := by
constructor
· rintro ⟨φ, rfl⟩ c
rw [coeff_C_mul]
apply dvd_mul_right
· intro h
choose C hc using h
classical
let c' : (σ →₀ ℕ) → R := fun i => if i ∈ φ.support then C i else 0
let ψ : MvPolynomial σ R := ∑ i ∈ φ.support, monomial i (c' i)
use ψ
apply MvPolynomial.ext
intro i
simp only [ψ, c', coeff_C_mul, coeff_sum, coeff_monomial, Finset.sum_ite_eq']
split_ifs with hi
· rw [hc]
· rw [not_mem_support_iff] at hi
rwa [mul_zero]
@[simp] lemma isRegular_X : IsRegular (X n : MvPolynomial σ R) := by
suffices IsLeftRegular (X n : MvPolynomial σ R) from
⟨this, this.right_of_commute <| Commute.all _⟩
intro P Q (hPQ : (X n) * P = (X n) * Q)
ext i
rw [← coeff_X_mul i n P, hPQ, coeff_X_mul i n Q]
@[simp] lemma isRegular_X_pow (k : ℕ) : IsRegular (X n ^ k : MvPolynomial σ R) := isRegular_X.pow k
@[simp] lemma isRegular_prod_X (s : Finset σ) :
IsRegular (∏ n ∈ s, X n : MvPolynomial σ R) :=
IsRegular.prod fun _ _ ↦ isRegular_X
/-- The finset of nonzero coefficients of a multivariate polynomial. -/
def coeffs (p : MvPolynomial σ R) : Finset R :=
letI := Classical.decEq R
Finset.image p.coeff p.support
@[simp]
lemma coeffs_zero : coeffs (0 : MvPolynomial σ R) = ∅ :=
rfl
lemma coeffs_one : coeffs (1 : MvPolynomial σ R) ⊆ {1} := by
classical
rw [coeffs, Finset.image_subset_iff]
simp_all [coeff_one]
@[nontriviality]
lemma coeffs_eq_empty_of_subsingleton [Subsingleton R] (p : MvPolynomial σ R) : p.coeffs = ∅ := by
simpa [coeffs] using Subsingleton.eq_zero p
@[simp]
lemma coeffs_one_of_nontrivial [Nontrivial R] : coeffs (1 : MvPolynomial σ R) = {1} := by
apply Finset.Subset.antisymm coeffs_one
simp only [coeffs, Finset.singleton_subset_iff, Finset.mem_image]
exact ⟨0, by simp⟩
lemma mem_coeffs_iff {p : MvPolynomial σ R} {c : R} :
c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by
simp [coeffs, eq_comm, (Finset.mem_image)]
lemma coeff_mem_coeffs {p : MvPolynomial σ R} (m : σ →₀ ℕ)
(h : p.coeff m ≠ 0) : p.coeff m ∈ p.coeffs :=
letI := Classical.decEq R
Finset.mem_image_of_mem p.coeff (mem_support_iff.mpr h)
lemma zero_not_mem_coeffs (p : MvPolynomial σ R) : 0 ∉ p.coeffs := by
intro hz
obtain ⟨n, hnsupp, hn⟩ := mem_coeffs_iff.mp hz
exact (mem_support_iff.mp hnsupp) hn.symm
end Coeff
section ConstantCoeff
/-- `constantCoeff p` returns the constant term of the polynomial `p`, defined as `coeff 0 p`.
This is a ring homomorphism.
-/
def constantCoeff : MvPolynomial σ R →+* R where
toFun := coeff 0
map_one' := by simp [AddMonoidAlgebra.one_def]
map_mul' := by classical simp [coeff_mul, Finsupp.support_single_ne_zero]
map_zero' := coeff_zero _
map_add' := coeff_add _
theorem constantCoeff_eq : (constantCoeff : MvPolynomial σ R → R) = coeff 0 :=
rfl
variable (σ) in
@[simp]
theorem constantCoeff_C (r : R) : constantCoeff (C r : MvPolynomial σ R) = r := by
classical simp [constantCoeff_eq]
variable (R) in
@[simp]
theorem constantCoeff_X (i : σ) : constantCoeff (X i : MvPolynomial σ R) = 0 := by
simp [constantCoeff_eq]
@[simp]
theorem constantCoeff_smul {R : Type*} [SMulZeroClass R S₁] (a : R) (f : MvPolynomial σ S₁) :
constantCoeff (a • f) = a • constantCoeff f :=
rfl
theorem constantCoeff_monomial [DecidableEq σ] (d : σ →₀ ℕ) (r : R) :
| constantCoeff (monomial d r) = if d = 0 then r else 0 := by
rw [constantCoeff_eq, coeff_monomial]
variable (σ R)
@[simp]
theorem constantCoeff_comp_C : constantCoeff.comp (C : R →+* MvPolynomial σ R) = RingHom.id R := by
ext x
exact constantCoeff_C σ x
theorem constantCoeff_comp_algebraMap :
constantCoeff.comp (algebraMap R (MvPolynomial σ R)) = RingHom.id R :=
constantCoeff_comp_C _ _
end ConstantCoeff
section AsSum
| Mathlib/Algebra/MvPolynomial/Basic.lean | 862 | 879 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Algebra.MonoidAlgebra.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Algebra.Ring.Action.Rat
import Mathlib.Data.Finset.Sort
import Mathlib.Tactic.FastInstance
/-!
# Theory of univariate polynomials
This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds
a semiring structure on it, and gives basic definitions that are expanded in other files in this
directory.
## Main definitions
* `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map.
* `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism.
* `X` is the polynomial `X`, i.e., `monomial 1 1`.
* `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied
to coefficients of the polynomial `p`.
* `p.erase n` is the polynomial `p` in which one removes the `c X^n` term.
There are often two natural variants of lemmas involving sums, depending on whether one acts on the
polynomials, or on the function. The naming convention is that one adds `index` when acting on
the polynomials. For instance,
* `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`;
* `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`.
* Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`.
## Implementation
Polynomials are defined using `R[ℕ]`, where `R` is a semiring.
The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity
`X * p = p * X`. The relationship to `R[ℕ]` is through a structure
to make polynomials irreducible from the point of view of the kernel. Most operations
are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two
exceptions that we make semireducible:
* The zero polynomial, so that its coefficients are definitionally equal to `0`.
* The scalar action, to permit typeclass search to unfold it to resolve potential instance
diamonds.
The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is
done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial
gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The
equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should
in general not be used once the basic API for polynomials is constructed.
-/
noncomputable section
/-- `Polynomial R` is the type of univariate polynomials over `R`,
denoted as `R[X]` within the `Polynomial` namespace.
Polynomials should be seen as (semi-)rings with the additional constructor `X`.
The embedding from `R` is called `C`. -/
structure Polynomial (R : Type*) [Semiring R] where ofFinsupp ::
toFinsupp : AddMonoidAlgebra R ℕ
@[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R
open AddMonoidAlgebra Finset
open Finsupp hiding single
open Function hiding Commute
namespace Polynomial
universe u
variable {R : Type u} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
theorem forall_iff_forall_finsupp (P : R[X] → Prop) :
(∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ :=
⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩
theorem exists_iff_exists_finsupp (P : R[X] → Prop) :
(∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ :=
⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩
@[simp]
theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl
/-! ### Conversions to and from `AddMonoidAlgebra`
Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping
it, we have to copy across all the arithmetic operators manually, along with the lemmas about how
they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`.
-/
section AddMonoidAlgebra
private irreducible_def add : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a + b⟩
private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X]
| ⟨a⟩ => ⟨-a⟩
private irreducible_def mul : R[X] → R[X] → R[X]
| ⟨a⟩, ⟨b⟩ => ⟨a * b⟩
instance zero : Zero R[X] :=
⟨⟨0⟩⟩
instance one : One R[X] :=
⟨⟨1⟩⟩
instance add' : Add R[X] :=
⟨add⟩
instance neg' {R : Type u} [Ring R] : Neg R[X] :=
⟨neg⟩
instance sub {R : Type u} [Ring R] : Sub R[X] :=
⟨fun a b => a + -b⟩
instance mul' : Mul R[X] :=
⟨mul⟩
-- If the private definitions are accidentally exposed, simplify them away.
@[simp] theorem add_eq_add : add p q = p + q := rfl
@[simp] theorem mul_eq_mul : mul p q = p * q := rfl
instance instNSMul : SMul ℕ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where
smul r p := ⟨r • p.toFinsupp⟩
smul_zero a := congr_arg ofFinsupp (smul_zero a)
instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] :
NoZeroSMulDivisors S R[X] where
eq_zero_or_eq_zero_of_smul_eq_zero eq :=
(eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp)
-- to avoid a bug in the `ring` tactic
instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p
@[simp]
theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 :=
rfl
@[simp]
theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 :=
rfl
@[simp]
theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ :=
show _ = add _ _ by rw [add_def]
@[simp]
theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ :=
show _ = neg _ by rw [neg_def]
@[simp]
theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by
rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg]
rfl
@[simp]
theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ :=
show _ = mul _ _ by rw [mul_def]
@[simp]
theorem ofFinsupp_nsmul (a : ℕ) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by
change _ = npowRec n _
induction n with
| zero => simp [npowRec]
| succ n n_ih => simp [npowRec, n_ih, pow_succ]
@[simp]
theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 :=
rfl
@[simp]
theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 :=
rfl
@[simp]
theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_add]
@[simp]
theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by
cases a
rw [← ofFinsupp_neg]
@[simp]
theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) :
(a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by
rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add]
rfl
@[simp]
theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by
cases a
cases b
rw [← ofFinsupp_mul]
@[simp]
theorem toFinsupp_nsmul (a : ℕ) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
@[simp]
theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by
cases a
rw [← ofFinsupp_pow]
theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S}
(ha : IsSMulRegular R a) : IsSMulRegular R[X] a
| ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h)
theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) :=
fun ⟨_x⟩ ⟨_y⟩ => congr_arg _
@[simp]
theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b :=
toFinsupp_injective.eq_iff
@[simp]
theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by
rw [← toFinsupp_zero, toFinsupp_inj]
@[simp]
theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by
rw [← toFinsupp_one, toFinsupp_inj]
/-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/
theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b :=
iff_of_eq (ofFinsupp.injEq _ _)
@[simp]
theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by
rw [← ofFinsupp_zero, ofFinsupp_inj]
@[simp]
theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj]
instance inhabited : Inhabited R[X] :=
⟨0⟩
instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n
@[simp]
theorem ofFinsupp_natCast (n : ℕ) : (⟨n⟩ : R[X]) = n := rfl
@[simp]
theorem toFinsupp_natCast (n : ℕ) : (n : R[X]).toFinsupp = n := rfl
@[simp]
theorem ofFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (⟨ofNat(n)⟩ : R[X]) = ofNat(n) := rfl
@[simp]
theorem toFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).toFinsupp = ofNat(n) := rfl
instance semiring : Semiring R[X] :=
fast_instance% Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero
toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_nsmul _ _) toFinsupp_pow
fun _ => rfl
instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] :=
fast_instance% Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] :=
fast_instance% Function.Injective.distribMulAction
⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul
instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where
eq_of_smul_eq_smul {_s₁ _s₂} h :=
eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩)
instance module {S} [Semiring S] [Module S R] : Module S R[X] :=
fast_instance% Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩
toFinsupp_injective toFinsupp_smul
instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] :
SMulCommClass S₁ S₂ R[X] :=
⟨by
rintro m n ⟨f⟩
simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩
instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R]
[IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] :=
⟨by
rintro _ _ ⟨⟩
simp_rw [← ofFinsupp_smul, smul_assoc]⟩
instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] :
IsScalarTower α K[X] K[X] :=
⟨by
rintro _ ⟨⟩ ⟨⟩
simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩
instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] :
IsCentralScalar S R[X] :=
⟨by
rintro _ ⟨⟩
simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩
instance unique [Subsingleton R] : Unique R[X] :=
{ Polynomial.inhabited with
uniq := by
rintro ⟨x⟩
apply congr_arg ofFinsupp
simp [eq_iff_true_of_subsingleton] }
variable (R)
/-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps apply symm_apply]
def toFinsuppIso : R[X] ≃+* R[ℕ] where
toFun := toFinsupp
invFun := ofFinsupp
left_inv := fun ⟨_p⟩ => rfl
right_inv _p := rfl
map_mul' := toFinsupp_mul
map_add' := toFinsupp_add
instance [DecidableEq R] : DecidableEq R[X] :=
@Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq)
/-- Linear isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps!]
def toFinsuppIsoLinear : R[X] ≃ₗ[R] R[ℕ] where
__ := toFinsuppIso R
map_smul' _ _ := rfl
end AddMonoidAlgebra
theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) :
(⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ :=
map_sum (toFinsuppIso R).symm f s
theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) :
(∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp :=
map_sum (toFinsuppIso R) f s
/-- The set of all `n` such that `X^n` has a non-zero coefficient. -/
def support : R[X] → Finset ℕ
| ⟨p⟩ => p.support
@[simp]
theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support]
theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support]
@[simp]
theorem support_zero : (0 : R[X]).support = ∅ :=
rfl
@[simp]
theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by
rcases p with ⟨⟩
simp [support]
@[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 :=
Finset.nonempty_iff_ne_empty.trans support_eq_empty.not
theorem card_support_eq_zero : #p.support = 0 ↔ p = 0 := by simp
/-- `monomial s a` is the monomial `a * X^s` -/
def monomial (n : ℕ) : R →ₗ[R] R[X] where
toFun t := ⟨Finsupp.single n t⟩
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp`.
map_add' x y := by simp; rw [ofFinsupp_add]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [← ofFinsupp_smul]`.
map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single']
@[simp]
theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by
simp [monomial]
@[simp]
theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by
simp [monomial]
@[simp]
theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 :=
(monomial n).map_zero
-- This is not a `simp` lemma as `monomial_zero_left` is more general.
theorem monomial_zero_one : monomial 0 (1 : R) = 1 :=
rfl
-- TODO: can't we just delete this one?
theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s :=
(monomial n).map_add _ _
theorem monomial_mul_monomial (n m : ℕ) (r s : R) :
monomial n r * monomial m s = monomial (n + m) (r * s) :=
toFinsupp_injective <| by
simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single]
@[simp]
theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by
induction k with
| zero => simp [pow_zero, monomial_zero_one]
| succ k ih => simp [pow_succ, ih, monomial_mul_monomial, mul_add, add_comm]
theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) :
a • monomial n b = monomial n (a • b) :=
toFinsupp_injective <| AddMonoidAlgebra.smul_single _ _ _
theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) :=
(toFinsuppIso R).symm.injective.comp (single_injective n)
@[simp]
theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 :=
LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n)
theorem monomial_eq_monomial_iff {m n : ℕ} {a b : R} :
monomial m a = monomial n b ↔ m = n ∧ a = b ∨ a = 0 ∧ b = 0 := by
rw [← toFinsupp_inj, toFinsupp_monomial, toFinsupp_monomial, Finsupp.single_eq_single_iff]
theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by
simpa [support] using Finsupp.support_add
/-- `C a` is the constant polynomial `a`.
`C` is provided as a ring homomorphism.
-/
def C : R →+* R[X] :=
{ monomial 0 with
map_one' := by simp [monomial_zero_one]
map_mul' := by simp [monomial_mul_monomial]
map_zero' := by simp }
@[simp]
theorem monomial_zero_left (a : R) : monomial 0 a = C a :=
rfl
@[simp]
theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a :=
rfl
theorem C_0 : C (0 : R) = 0 := by simp
theorem C_1 : C (1 : R) = 1 :=
rfl
theorem C_mul : C (a * b) = C a * C b :=
C.map_mul a b
theorem C_add : C (a + b) = C a + C b :=
C.map_add a b
@[simp]
theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) :=
smul_monomial _ _ r
theorem C_pow : C (a ^ n) = C a ^ n :=
C.map_pow a n
theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) :=
map_natCast C n
@[simp]
theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, zero_add]
@[simp]
theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by
simp only [← monomial_zero_left, monomial_mul_monomial, add_zero]
/-- `X` is the polynomial variable (aka indeterminate). -/
def X : R[X] :=
monomial 1 1
theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X :=
rfl
theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by
induction n with
| zero => simp [monomial_zero_one]
| succ n ih => rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one]
@[simp]
theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) :=
rfl
theorem X_ne_C [Nontrivial R] (a : R) : X ≠ C a := by
intro he
simpa using monomial_eq_monomial_iff.1 he
/-- `X` commutes with everything, even when the coefficients are noncommutative. -/
theorem X_mul : X * p = p * X := by
rcases p with ⟨⟩
simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq]
ext
simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm]
theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by
induction n with
| zero => simp
| succ n ih =>
conv_lhs => rw [pow_succ]
rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ]
/-- Prefer putting constants to the left of `X`.
This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/
@[simp]
theorem X_mul_C (r : R) : X * C r = C r * X :=
X_mul
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/
@[simp]
theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n :=
X_pow_mul
theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by
rw [mul_assoc, X_pow_mul, ← mul_assoc]
/-- Prefer putting constants to the left of `X ^ n`.
This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/
@[simp]
theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n :=
X_pow_mul_assoc
theorem commute_X (p : R[X]) : Commute X p :=
X_mul
theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p :=
X_pow_mul
@[simp]
theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by
rw [X, monomial_mul_monomial, mul_one]
@[simp]
theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) :
monomial n r * X ^ k = monomial (n + k) r := by
induction k with
| zero => simp
| succ k ih => simp [ih, pow_succ, ← mul_assoc, add_assoc]
@[simp]
theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by
rw [X_mul, monomial_mul_X]
@[simp]
theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by
rw [X_pow_mul, monomial_mul_X_pow]
/-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/
def coeff : R[X] → ℕ → R
| ⟨p⟩ => p
@[simp]
theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff]
theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by
rintro ⟨p⟩ ⟨q⟩
simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq]
@[simp]
theorem coeff_inj : p.coeff = q.coeff ↔ p = q :=
coeff_injective.eq_iff
theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl
theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by
simp [coeff, Finsupp.single_apply]
@[simp]
theorem coeff_monomial_same (n : ℕ) (c : R) : (monomial n c).coeff n = c :=
Finsupp.single_eq_same
theorem coeff_monomial_of_ne {m n : ℕ} (c : R) (h : n ≠ m) : (monomial n c).coeff m = 0 :=
Finsupp.single_eq_of_ne h
@[simp]
theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 :=
rfl
theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by
simp_rw [eq_comm (a := n) (b := 0)]
exact coeff_monomial
@[simp]
theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by
simp [coeff_one]
@[simp]
theorem coeff_X_one : coeff (X : R[X]) 1 = 1 :=
coeff_monomial
@[simp]
theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 :=
coeff_monomial
@[simp]
theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial]
theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 :=
coeff_monomial
theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by
rw [coeff_X, if_neg hn.symm]
@[simp]
theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by
rcases p with ⟨⟩
simp
theorem not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp
theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by
convert coeff_monomial (a := a) (m := n) (n := 0) using 2
simp [eq_comm]
@[simp]
theorem coeff_C_zero : coeff (C a) 0 = a :=
coeff_monomial
theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h]
@[simp]
lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C]
@[simp]
theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by
simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero]
@[simp]
theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) 0 = ofNat(a) :=
coeff_monomial
@[simp]
theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] :
coeff (ofNat(a) : R[X]) (n + 1) = 0 := by
rw [← Nat.cast_ofNat]
simp [-Nat.cast_ofNat]
theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a
| 0 => mul_one _
| n + 1 => by
rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one]
@[simp high]
theorem toFinsupp_C_mul_X_pow (a : R) (n : ℕ) :
Polynomial.toFinsupp (C a * X ^ n) = Finsupp.single n a := by
rw [C_mul_X_pow_eq_monomial, toFinsupp_monomial]
theorem C_mul_X_eq_monomial : C a * X = monomial 1 a := by rw [← C_mul_X_pow_eq_monomial, pow_one]
@[simp high]
theorem toFinsupp_C_mul_X (a : R) : Polynomial.toFinsupp (C a * X) = Finsupp.single 1 a := by
rw [C_mul_X_eq_monomial, toFinsupp_monomial]
theorem C_injective : Injective (C : R → R[X]) :=
monomial_injective 0
@[simp]
theorem C_inj : C a = C b ↔ a = b :=
C_injective.eq_iff
@[simp]
theorem C_eq_zero : C a = 0 ↔ a = 0 :=
C_injective.eq_iff' (map_zero C)
theorem C_ne_zero : C a ≠ 0 ↔ a ≠ 0 :=
C_eq_zero.not
theorem subsingleton_iff_subsingleton : Subsingleton R[X] ↔ Subsingleton R :=
⟨@Injective.subsingleton _ _ _ C_injective, by
intro
infer_instance⟩
theorem Nontrivial.of_polynomial_ne (h : p ≠ q) : Nontrivial R :=
(subsingleton_or_nontrivial R).resolve_left fun _hI => h <| Subsingleton.elim _ _
theorem forall_eq_iff_forall_eq : (∀ f g : R[X], f = g) ↔ ∀ a b : R, a = b := by
simpa only [← subsingleton_iff] using subsingleton_iff_subsingleton
theorem ext_iff {p q : R[X]} : p = q ↔ ∀ n, coeff p n = coeff q n := by
rcases p with ⟨f : ℕ →₀ R⟩
rcases q with ⟨g : ℕ →₀ R⟩
simpa [coeff] using DFunLike.ext_iff (f := f) (g := g)
@[ext]
theorem ext {p q : R[X]} : (∀ n, coeff p n = coeff q n) → p = q :=
ext_iff.2
/-- Monomials generate the additive monoid of polynomials. -/
theorem addSubmonoid_closure_setOf_eq_monomial :
AddSubmonoid.closure { p : R[X] | ∃ n a, p = monomial n a } = ⊤ := by
apply top_unique
rw [← AddSubmonoid.map_equiv_top (toFinsuppIso R).symm.toAddEquiv, ←
Finsupp.add_closure_setOf_eq_single, AddMonoidHom.map_mclosure]
refine AddSubmonoid.closure_mono (Set.image_subset_iff.2 ?_)
rintro _ ⟨n, a, rfl⟩
exact ⟨n, a, Polynomial.ofFinsupp_single _ _⟩
theorem addHom_ext {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n a, f (monomial n a) = g (monomial n a)) : f = g :=
AddMonoidHom.eq_of_eqOn_denseM addSubmonoid_closure_setOf_eq_monomial <| by
rintro p ⟨n, a, rfl⟩
exact h n a
@[ext high]
theorem addHom_ext' {M : Type*} [AddZeroClass M] {f g : R[X] →+ M}
(h : ∀ n, f.comp (monomial n).toAddMonoidHom = g.comp (monomial n).toAddMonoidHom) : f = g :=
addHom_ext fun n => DFunLike.congr_fun (h n)
@[ext high]
theorem lhom_ext' {M : Type*} [AddCommMonoid M] [Module R M] {f g : R[X] →ₗ[R] M}
(h : ∀ n, f.comp (monomial n) = g.comp (monomial n)) : f = g :=
LinearMap.toAddMonoidHom_injective <| addHom_ext fun n => LinearMap.congr_fun (h n)
-- this has the same content as the subsingleton
theorem eq_zero_of_eq_zero (h : (0 : R) = (1 : R)) (p : R[X]) : p = 0 := by
rw [← one_smul R p, ← h, zero_smul]
section Fewnomials
theorem support_monomial (n) {a : R} (H : a ≠ 0) : (monomial n a).support = singleton n := by
rw [← ofFinsupp_single, support]; exact Finsupp.support_single_ne_zero _ H
theorem support_monomial' (n) (a : R) : (monomial n a).support ⊆ singleton n := by
rw [← ofFinsupp_single, support]
exact Finsupp.support_single_subset
theorem support_C {a : R} (h : a ≠ 0) : (C a).support = singleton 0 :=
support_monomial 0 h
theorem support_C_subset (a : R) : (C a).support ⊆ singleton 0 :=
support_monomial' 0 a
theorem support_C_mul_X {c : R} (h : c ≠ 0) : Polynomial.support (C c * X) = singleton 1 := by
rw [C_mul_X_eq_monomial, support_monomial 1 h]
theorem support_C_mul_X' (c : R) : Polynomial.support (C c * X) ⊆ singleton 1 := by
simpa only [C_mul_X_eq_monomial] using support_monomial' 1 c
theorem support_C_mul_X_pow (n : ℕ) {c : R} (h : c ≠ 0) :
Polynomial.support (C c * X ^ n) = singleton n := by
rw [C_mul_X_pow_eq_monomial, support_monomial n h]
theorem support_C_mul_X_pow' (n : ℕ) (c : R) : Polynomial.support (C c * X ^ n) ⊆ singleton n := by
simpa only [C_mul_X_pow_eq_monomial] using support_monomial' n c
open Finset
theorem support_binomial' (k m : ℕ) (x y : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m) ⊆ {k, m} :=
support_add.trans
(union_subset
((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m})))
((support_C_mul_X_pow' m y).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_singleton_self m)))))
theorem support_trinomial' (k m n : ℕ) (x y z : R) :
Polynomial.support (C x * X ^ k + C y * X ^ m + C z * X ^ n) ⊆ {k, m, n} :=
support_add.trans
(union_subset
(support_add.trans
(union_subset
((support_C_mul_X_pow' k x).trans (singleton_subset_iff.mpr (mem_insert_self k {m, n})))
((support_C_mul_X_pow' m y).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_self m {n}))))))
((support_C_mul_X_pow' n z).trans
(singleton_subset_iff.mpr (mem_insert_of_mem (mem_insert_of_mem (mem_singleton_self n))))))
end Fewnomials
theorem X_pow_eq_monomial (n) : X ^ n = monomial n (1 : R) := by
induction n with
| zero => rw [pow_zero, monomial_zero_one]
| succ n hn => rw [pow_succ, hn, X, monomial_mul_monomial, one_mul]
@[simp high]
theorem toFinsupp_X_pow (n : ℕ) : (X ^ n).toFinsupp = Finsupp.single n (1 : R) := by
rw [X_pow_eq_monomial, toFinsupp_monomial]
theorem smul_X_eq_monomial {n} : a • X ^ n = monomial n (a : R) := by
rw [X_pow_eq_monomial, smul_monomial, smul_eq_mul, mul_one]
theorem support_X_pow (H : ¬(1 : R) = 0) (n : ℕ) : (X ^ n : R[X]).support = singleton n := by
convert support_monomial n H
exact X_pow_eq_monomial n
theorem support_X_empty (H : (1 : R) = 0) : (X : R[X]).support = ∅ := by
rw [X, H, monomial_zero_right, support_zero]
theorem support_X (H : ¬(1 : R) = 0) : (X : R[X]).support = singleton 1 := by
rw [← pow_one X, support_X_pow H 1]
theorem monomial_left_inj {a : R} (ha : a ≠ 0) {i j : ℕ} :
monomial i a = monomial j a ↔ i = j := by
simp only [← ofFinsupp_single, ofFinsupp.injEq, Finsupp.single_left_inj ha]
theorem binomial_eq_binomial {k l m n : ℕ} {u v : R} (hu : u ≠ 0) (hv : v ≠ 0) :
C u * X ^ k + C v * X ^ l = C u * X ^ m + C v * X ^ n ↔
k = m ∧ l = n ∨ u = v ∧ k = n ∧ l = m ∨ u + v = 0 ∧ k = l ∧ m = n := by
simp_rw [C_mul_X_pow_eq_monomial, ← toFinsupp_inj, toFinsupp_add, toFinsupp_monomial]
exact Finsupp.single_add_single_eq_single_add_single hu hv
theorem natCast_mul (n : ℕ) (p : R[X]) : (n : R[X]) * p = n • p :=
(nsmul_eq_mul _ _).symm
/-- Summing the values of a function applied to the coefficients of a polynomial -/
def sum {S : Type*} [AddCommMonoid S] (p : R[X]) (f : ℕ → R → S) : S :=
∑ n ∈ p.support, f n (p.coeff n)
theorem sum_def {S : Type*} [AddCommMonoid S] (p : R[X]) (f : ℕ → R → S) :
p.sum f = ∑ n ∈ p.support, f n (p.coeff n) :=
rfl
theorem sum_eq_of_subset {S : Type*} [AddCommMonoid S] {p : R[X]} (f : ℕ → R → S)
(hf : ∀ i, f i 0 = 0) {s : Finset ℕ} (hs : p.support ⊆ s) :
p.sum f = ∑ n ∈ s, f n (p.coeff n) :=
Finsupp.sum_of_support_subset _ hs f (fun i _ ↦ hf i)
/-- Expressing the product of two polynomials as a double sum. -/
theorem mul_eq_sum_sum :
p * q = ∑ i ∈ p.support, q.sum fun j a => (monomial (i + j)) (p.coeff i * a) := by
apply toFinsupp_injective
rcases p with ⟨⟩; rcases q with ⟨⟩
simp_rw [sum, coeff, toFinsupp_sum, support, toFinsupp_mul, toFinsupp_monomial,
AddMonoidAlgebra.mul_def, Finsupp.sum]
@[simp]
theorem sum_zero_index {S : Type*} [AddCommMonoid S] (f : ℕ → R → S) : (0 : R[X]).sum f = 0 := by
simp [sum]
@[simp]
theorem sum_monomial_index {S : Type*} [AddCommMonoid S] {n : ℕ} (a : R) (f : ℕ → R → S)
(hf : f n 0 = 0) : (monomial n a : R[X]).sum f = f n a :=
Finsupp.sum_single_index hf
@[simp]
theorem sum_C_index {a} {β} [AddCommMonoid β] {f : ℕ → R → β} (h : f 0 0 = 0) :
(C a).sum f = f 0 a :=
sum_monomial_index a f h
-- the assumption `hf` is only necessary when the ring is trivial
@[simp]
theorem sum_X_index {S : Type*} [AddCommMonoid S] {f : ℕ → R → S} (hf : f 1 0 = 0) :
(X : R[X]).sum f = f 1 1 :=
sum_monomial_index 1 f hf
theorem sum_add_index {S : Type*} [AddCommMonoid S] (p q : R[X]) (f : ℕ → R → S)
(hf : ∀ i, f i 0 = 0) (h_add : ∀ a b₁ b₂, f a (b₁ + b₂) = f a b₁ + f a b₂) :
(p + q).sum f = p.sum f + q.sum f := by
rw [show p + q = ⟨p.toFinsupp + q.toFinsupp⟩ from add_def p q]
exact Finsupp.sum_add_index (fun i _ ↦ hf i) (fun a _ b₁ b₂ ↦ h_add a b₁ b₂)
theorem sum_add' {S : Type*} [AddCommMonoid S] (p : R[X]) (f g : ℕ → R → S) :
p.sum (f + g) = p.sum f + p.sum g := by simp [sum_def, Finset.sum_add_distrib]
theorem sum_add {S : Type*} [AddCommMonoid S] (p : R[X]) (f g : ℕ → R → S) :
(p.sum fun n x => f n x + g n x) = p.sum f + p.sum g :=
sum_add' _ _ _
theorem sum_smul_index {S : Type*} [AddCommMonoid S] (p : R[X]) (b : R) (f : ℕ → R → S)
(hf : ∀ i, f i 0 = 0) : (b • p).sum f = p.sum fun n a => f n (b * a) :=
Finsupp.sum_smul_index hf
theorem sum_smul_index' {S T : Type*} [DistribSMul T R] [AddCommMonoid S] (p : R[X]) (b : T)
(f : ℕ → R → S) (hf : ∀ i, f i 0 = 0) : (b • p).sum f = p.sum fun n a => f n (b • a) :=
Finsupp.sum_smul_index' hf
protected theorem smul_sum {S T : Type*} [AddCommMonoid S] [DistribSMul T S] (p : R[X]) (b : T)
(f : ℕ → R → S) : b • p.sum f = p.sum fun n a => b • f n a :=
Finsupp.smul_sum
@[simp]
theorem sum_monomial_eq : ∀ p : R[X], (p.sum fun n a => monomial n a) = p
| ⟨_p⟩ => (ofFinsupp_sum _ _).symm.trans (congr_arg _ <| Finsupp.sum_single _)
theorem sum_C_mul_X_pow_eq (p : R[X]) : (p.sum fun n a => C a * X ^ n) = p := by
simp_rw [C_mul_X_pow_eq_monomial, sum_monomial_eq]
@[elab_as_elim]
protected theorem induction_on {motive : R[X] → Prop} (p : R[X]) (C : ∀ a, motive (C a))
(add : ∀ p q, motive p → motive q → motive (p + q))
(monomial : ∀ (n : ℕ) (a : R),
motive (Polynomial.C a * X ^ n) → motive (Polynomial.C a * X ^ (n + 1))) : motive p := by
have A : ∀ {n : ℕ} {a}, motive (Polynomial.C a * X ^ n) := by
intro n a
induction n with
| zero => rw [pow_zero, mul_one]; exact C a
| succ n ih => exact monomial _ _ ih
have B : ∀ s : Finset ℕ, motive (s.sum fun n : ℕ => Polynomial.C (p.coeff n) * X ^ n) := by
apply Finset.induction
· convert C 0
exact C_0.symm
· intro n s ns ih
rw [sum_insert ns]
exact add _ _ A ih
rw [← sum_C_mul_X_pow_eq p, Polynomial.sum]
exact B (support p)
/-- To prove something about polynomials,
it suffices to show the condition is closed under taking sums,
and it holds for monomials.
-/
@[elab_as_elim]
protected theorem induction_on' {motive : R[X] → Prop} (p : R[X])
(add : ∀ p q, motive p → motive q → motive (p + q))
(monomial : ∀ (n : ℕ) (a : R), motive (monomial n a)) : motive p :=
Polynomial.induction_on p (monomial 0) add fun n a _h =>
by rw [C_mul_X_pow_eq_monomial]; exact monomial _ _
/-- `erase p n` is the polynomial `p` in which the `X^n` term has been erased. -/
irreducible_def erase (n : ℕ) : R[X] → R[X]
| ⟨p⟩ => ⟨p.erase n⟩
@[simp]
theorem toFinsupp_erase (p : R[X]) (n : ℕ) : toFinsupp (p.erase n) = p.toFinsupp.erase n := by
rcases p with ⟨⟩
simp only [erase_def]
@[simp]
theorem ofFinsupp_erase (p : R[ℕ]) (n : ℕ) :
(⟨p.erase n⟩ : R[X]) = (⟨p⟩ : R[X]).erase n := by
rcases p with ⟨⟩
simp only [erase_def]
@[simp]
theorem support_erase (p : R[X]) (n : ℕ) : support (p.erase n) = (support p).erase n := by
rcases p with ⟨⟩
simp only [support, erase_def, Finsupp.support_erase]
theorem monomial_add_erase (p : R[X]) (n : ℕ) : monomial n (coeff p n) + p.erase n = p :=
toFinsupp_injective <| by
rcases p with ⟨⟩
rw [toFinsupp_add, toFinsupp_monomial, toFinsupp_erase, coeff]
exact Finsupp.single_add_erase _ _
theorem coeff_erase (p : R[X]) (n i : ℕ) :
(p.erase n).coeff i = if i = n then 0 else p.coeff i := by
rcases p with ⟨⟩
simp only [erase_def, coeff]
exact ite_congr rfl (fun _ => rfl) (fun _ => rfl)
@[simp]
theorem erase_zero (n : ℕ) : (0 : R[X]).erase n = 0 :=
toFinsupp_injective <| by simp
@[simp]
theorem erase_monomial {n : ℕ} {a : R} : erase n (monomial n a) = 0 :=
toFinsupp_injective <| by simp
@[simp]
theorem erase_same (p : R[X]) (n : ℕ) : coeff (p.erase n) n = 0 := by simp [coeff_erase]
@[simp]
theorem erase_ne (p : R[X]) (n i : ℕ) (h : i ≠ n) : coeff (p.erase n) i = coeff p i := by
simp [coeff_erase, h]
section Update
/-- Replace the coefficient of a `p : R[X]` at a given degree `n : ℕ`
by a given value `a : R`. If `a = 0`, this is equal to `p.erase n`
If `p.natDegree < n` and `a ≠ 0`, this increases the degree to `n`. -/
def update (p : R[X]) (n : ℕ) (a : R) : R[X] :=
Polynomial.ofFinsupp (p.toFinsupp.update n a)
theorem coeff_update (p : R[X]) (n : ℕ) (a : R) :
(p.update n a).coeff = Function.update p.coeff n a := by
ext
cases p
simp only [coeff, update, Function.update_apply, coe_update]
theorem coeff_update_apply (p : R[X]) (n : ℕ) (a : R) (i : ℕ) :
(p.update n a).coeff i = if i = n then a else p.coeff i := by
rw [coeff_update, Function.update_apply]
@[simp]
theorem coeff_update_same (p : R[X]) (n : ℕ) (a : R) : (p.update n a).coeff n = a := by
rw [p.coeff_update_apply, if_pos rfl]
theorem coeff_update_ne (p : R[X]) {n : ℕ} (a : R) {i : ℕ} (h : i ≠ n) :
(p.update n a).coeff i = p.coeff i := by rw [p.coeff_update_apply, if_neg h]
@[simp]
theorem update_zero_eq_erase (p : R[X]) (n : ℕ) : p.update n 0 = p.erase n := by
ext
rw [coeff_update_apply, coeff_erase]
theorem support_update (p : R[X]) (n : ℕ) (a : R) [Decidable (a = 0)] :
support (p.update n a) = if a = 0 then p.support.erase n else insert n p.support := by
classical
cases p
simp only [support, update, Finsupp.support_update]
congr
theorem support_update_zero (p : R[X]) (n : ℕ) : support (p.update n 0) = p.support.erase n := by
rw [update_zero_eq_erase, support_erase]
theorem support_update_ne_zero (p : R[X]) (n : ℕ) {a : R} (ha : a ≠ 0) :
support (p.update n a) = insert n p.support := by classical rw [support_update, if_neg ha]
end Update
/-- The finset of nonzero coefficients of a polynomial. -/
def coeffs (p : R[X]) : Finset R :=
letI := Classical.decEq R
Finset.image (fun n => p.coeff n) p.support
@[simp]
theorem coeffs_zero : coeffs (0 : R[X]) = ∅ :=
rfl
theorem mem_coeffs_iff {p : R[X]} {c : R} : c ∈ p.coeffs ↔ ∃ n ∈ p.support, c = p.coeff n := by
simp [coeffs, eq_comm, (Finset.mem_image)]
theorem coeffs_one : coeffs (1 : R[X]) ⊆ {1} := by
classical
simp_rw [coeffs, Finset.image_subset_iff]
simp_all [coeff_one]
theorem coeff_mem_coeffs (p : R[X]) (n : ℕ) (h : p.coeff n ≠ 0) : p.coeff n ∈ p.coeffs := by
classical
simp only [coeffs, exists_prop, mem_support_iff, Finset.mem_image, Ne]
exact ⟨n, h, rfl⟩
theorem coeffs_monomial (n : ℕ) {c : R} (hc : c ≠ 0) : (monomial n c).coeffs = {c} := by
rw [coeffs, support_monomial n hc]
simp
end Semiring
section CommSemiring
variable [CommSemiring R]
instance commSemiring : CommSemiring R[X] :=
fast_instance% { Function.Injective.commSemigroup toFinsupp toFinsupp_injective toFinsupp_mul with
toSemiring := Polynomial.semiring }
end CommSemiring
section Ring
variable [Ring R]
instance instZSMul : SMul ℤ R[X] where
smul r p := ⟨r • p.toFinsupp⟩
@[simp]
theorem ofFinsupp_zsmul (a : ℤ) (b) :
(⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) :=
rfl
@[simp]
theorem toFinsupp_zsmul (a : ℤ) (b : R[X]) :
(a • b).toFinsupp = a • b.toFinsupp :=
rfl
instance instIntCast : IntCast R[X] where intCast n := ofFinsupp n
@[simp]
theorem ofFinsupp_intCast (z : ℤ) : (⟨z⟩ : R[X]) = z := rfl
@[simp]
theorem toFinsupp_intCast (z : ℤ) : (z : R[X]).toFinsupp = z := rfl
instance ring : Ring R[X] :=
fast_instance% Function.Injective.ring toFinsupp toFinsupp_injective (toFinsupp_zero (R := R))
toFinsupp_one toFinsupp_add
toFinsupp_mul toFinsupp_neg toFinsupp_sub (fun _ _ => toFinsupp_nsmul _ _)
(fun _ _ => toFinsupp_zsmul _ _) toFinsupp_pow (fun _ => rfl) fun _ => rfl
@[simp]
theorem coeff_neg (p : R[X]) (n : ℕ) : coeff (-p) n = -coeff p n := by
rcases p with ⟨⟩
rw [← ofFinsupp_neg, coeff, coeff, Finsupp.neg_apply]
@[simp]
theorem coeff_sub (p q : R[X]) (n : ℕ) : coeff (p - q) n = coeff p n - coeff q n := by
rcases p with ⟨⟩
rcases q with ⟨⟩
rw [← ofFinsupp_sub, coeff, coeff, coeff, Finsupp.sub_apply]
@[simp]
theorem monomial_neg (n : ℕ) (a : R) : monomial n (-a) = -monomial n a := by
rw [eq_neg_iff_add_eq_zero, ← monomial_add, neg_add_cancel, monomial_zero_right]
theorem monomial_sub (n : ℕ) : monomial n (a - b) = monomial n a - monomial n b := by
rw [sub_eq_add_neg, monomial_add, monomial_neg, sub_eq_add_neg]
@[simp]
theorem support_neg {p : R[X]} : (-p).support = p.support := by
rcases p with ⟨⟩
rw [← ofFinsupp_neg, support, support, Finsupp.support_neg]
theorem C_eq_intCast (n : ℤ) : C (n : R) = n := by simp
theorem C_neg : C (-a) = -C a :=
RingHom.map_neg C a
theorem C_sub : C (a - b) = C a - C b :=
RingHom.map_sub C a b
end Ring
instance commRing [CommRing R] : CommRing R[X] :=
--TODO: add reference to library note in PR https://github.com/leanprover-community/mathlib4/pull/7432
{ toRing := Polynomial.ring
mul_comm := mul_comm }
section NonzeroSemiring
variable [Semiring R]
instance nontrivial [Nontrivial R] : Nontrivial R[X] := by
have h : Nontrivial R[ℕ] := by infer_instance
rcases h.exists_pair_ne with ⟨x, y, hxy⟩
refine ⟨⟨⟨x⟩, ⟨y⟩, ?_⟩⟩
simp [hxy]
@[simp]
theorem X_ne_zero [Nontrivial R] : (X : R[X]) ≠ 0 :=
mt (congr_arg fun p => coeff p 1) (by simp)
end NonzeroSemiring
section DivisionSemiring
variable [DivisionSemiring R]
lemma nnqsmul_eq_C_mul (q : ℚ≥0) (f : R[X]) : q • f = Polynomial.C (q : R) * f := by
rw [← NNRat.smul_one_eq_cast, ← Polynomial.smul_C, C_1, smul_one_mul]
end DivisionSemiring
section DivisionRing
variable [DivisionRing R]
theorem qsmul_eq_C_mul (a : ℚ) (f : R[X]) : a • f = Polynomial.C (a : R) * f := by
rw [← Rat.smul_one_eq_cast, ← Polynomial.smul_C, C_1, smul_one_mul]
end DivisionRing
@[simp]
theorem nontrivial_iff [Semiring R] : Nontrivial R[X] ↔ Nontrivial R :=
⟨fun h =>
let ⟨_r, _s, hrs⟩ := @exists_pair_ne _ h
Nontrivial.of_polynomial_ne hrs,
fun h => @Polynomial.nontrivial _ _ h⟩
section repr
variable [Semiring R]
protected instance repr [Repr R] [DecidableEq R] : Repr R[X] :=
⟨fun p prec =>
let termPrecAndReprs : List (WithTop ℕ × Lean.Format) :=
List.map (fun
| 0 => (max_prec, "C " ++ reprArg (coeff p 0))
| 1 => if coeff p 1 = 1
then (⊤, "X")
else (70, "C " ++ reprArg (coeff p 1) ++ " * X")
| n =>
if coeff p n = 1
then (80, "X ^ " ++ Nat.repr n)
else (70, "C " ++ reprArg (coeff p n) ++ " * X ^ " ++ Nat.repr n))
(p.support.sort (· ≤ ·))
match termPrecAndReprs with
| [] => "0"
| [(tprec, t)] => if prec ≥ tprec then Lean.Format.paren t else t
| ts =>
-- multiple terms, use `+` precedence
(if prec ≥ 65 then Lean.Format.paren else id)
(Lean.Format.fill
(Lean.Format.joinSep (ts.map Prod.snd) (" +" ++ Lean.Format.line)))⟩
end repr
end Polynomial
| Mathlib/Algebra/Polynomial/Basic.lean | 1,213 | 1,215 | |
/-
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.SpecificFunctions
/-!
# Differentiability of models with corners and (extended) charts
In this file, we analyse the differentiability of charts, models with corners and extended charts.
We show that
* models with corners are differentiable
* charts are differentiable on their source
* `mdifferentiableOn_extChartAt`: `extChartAt` is differentiable on its source
Suppose a partial homeomorphism `e` is differentiable. This file shows
* `PartialHomeomorph.MDifferentiable.mfderiv`: its derivative is a continuous linear equivalence
* `PartialHomeomorph.MDifferentiable.mfderiv_bijective`: its derivative is bijective;
there are also spelling with trivial kernel and full range
In particular, (extended) charts have bijective differential.
## Tags
charts, differentiable, bijective
-/
noncomputable section
open scoped Manifold ContDiff
open Bundle Set Topology
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'']
section ModelWithCorners
namespace ModelWithCorners
/- In general, the model with corner `I` is implicit in most theorems in differential geometry, but
this section is about `I` as a map, not as a parameter. Therefore, we make it explicit. -/
variable (I)
/-! #### Model with corners -/
protected theorem hasMFDerivAt {x} : HasMFDerivAt I 𝓘(𝕜, E) I x (ContinuousLinearMap.id _ _) :=
⟨I.continuousAt, (hasFDerivWithinAt_id _ _).congr' I.rightInvOn (mem_range_self _)⟩
protected theorem hasMFDerivWithinAt {s x} :
HasMFDerivWithinAt I 𝓘(𝕜, E) I s x (ContinuousLinearMap.id _ _) :=
I.hasMFDerivAt.hasMFDerivWithinAt
protected theorem mdifferentiableWithinAt {s x} : MDifferentiableWithinAt I 𝓘(𝕜, E) I s x :=
I.hasMFDerivWithinAt.mdifferentiableWithinAt
protected theorem mdifferentiableAt {x} : MDifferentiableAt I 𝓘(𝕜, E) I x :=
I.hasMFDerivAt.mdifferentiableAt
protected theorem mdifferentiableOn {s} : MDifferentiableOn I 𝓘(𝕜, E) I s := fun _ _ =>
I.mdifferentiableWithinAt
protected theorem mdifferentiable : MDifferentiable I 𝓘(𝕜, E) I := fun _ => I.mdifferentiableAt
theorem hasMFDerivWithinAt_symm {x} (hx : x ∈ range I) :
HasMFDerivWithinAt 𝓘(𝕜, E) I I.symm (range I) x (ContinuousLinearMap.id _ _) :=
⟨I.continuousWithinAt_symm,
(hasFDerivWithinAt_id _ _).congr' (fun _y hy => I.rightInvOn hy.1) ⟨hx, mem_range_self _⟩⟩
theorem mdifferentiableOn_symm : MDifferentiableOn 𝓘(𝕜, E) I I.symm (range I) := fun _x hx =>
(I.hasMFDerivWithinAt_symm hx).mdifferentiableWithinAt
theorem mdifferentiableWithinAt_symm {z : E} (hz : z ∈ range I) :
MDifferentiableWithinAt 𝓘(𝕜, E) I I.symm (range I) z :=
I.mdifferentiableOn_symm z hz
end ModelWithCorners
end ModelWithCorners
section Charts
variable [IsManifold I 1 M] [IsManifold I' 1 M']
[IsManifold I'' 1 M''] {e : PartialHomeomorph M H}
theorem mdifferentiableAt_atlas (h : e ∈ atlas H M) {x : M} (hx : x ∈ e.source) :
MDifferentiableAt I I e x := by
rw [mdifferentiableAt_iff]
refine ⟨(e.continuousOn x hx).continuousAt (e.open_source.mem_nhds hx), ?_⟩
have mem :
I ((chartAt H x : M → H) x) ∈ I.symm ⁻¹' ((chartAt H x).symm ≫ₕ e).source ∩ range I := by
simp only [hx, mfld_simps]
have : (chartAt H x).symm.trans e ∈ contDiffGroupoid 1 I :=
HasGroupoid.compatible (chart_mem_atlas H x) h
have A :
ContDiffOn 𝕜 1 (I ∘ (chartAt H x).symm.trans e ∘ I.symm)
(I.symm ⁻¹' ((chartAt H x).symm.trans e).source ∩ range I) :=
this.1
have B := A.differentiableOn le_rfl (I ((chartAt H x : M → H) x)) mem
simp only [mfld_simps] at B
rw [inter_comm, differentiableWithinAt_inter] at B
· simpa only [mfld_simps]
· apply IsOpen.mem_nhds ((PartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1
theorem mdifferentiableOn_atlas (h : e ∈ atlas H M) : MDifferentiableOn I I e e.source :=
fun _x hx => (mdifferentiableAt_atlas h hx).mdifferentiableWithinAt
theorem mdifferentiableAt_atlas_symm (h : e ∈ atlas H M) {x : H} (hx : x ∈ e.target) :
MDifferentiableAt I I e.symm x := by
rw [mdifferentiableAt_iff]
refine ⟨(e.continuousOn_symm x hx).continuousAt (e.open_target.mem_nhds hx), ?_⟩
have mem : I x ∈ I.symm ⁻¹' (e.symm ≫ₕ chartAt H (e.symm x)).source ∩ range I := by
simp only [hx, mfld_simps]
have : e.symm.trans (chartAt H (e.symm x)) ∈ contDiffGroupoid 1 I :=
HasGroupoid.compatible h (chart_mem_atlas H _)
have A :
ContDiffOn 𝕜 1 (I ∘ e.symm.trans (chartAt H (e.symm x)) ∘ I.symm)
(I.symm ⁻¹' (e.symm.trans (chartAt H (e.symm x))).source ∩ range I) :=
this.1
have B := A.differentiableOn le_rfl (I x) mem
simp only [mfld_simps] at B
rw [inter_comm, differentiableWithinAt_inter] at B
· simpa only [mfld_simps]
· apply IsOpen.mem_nhds ((PartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1
theorem mdifferentiableOn_atlas_symm (h : e ∈ atlas H M) : MDifferentiableOn I I e.symm e.target :=
fun _x hx => (mdifferentiableAt_atlas_symm h hx).mdifferentiableWithinAt
theorem mdifferentiable_of_mem_atlas (h : e ∈ atlas H M) : e.MDifferentiable I I :=
⟨mdifferentiableOn_atlas h, mdifferentiableOn_atlas_symm h⟩
theorem mdifferentiable_chart (x : M) : (chartAt H x).MDifferentiable I I :=
mdifferentiable_of_mem_atlas (chart_mem_atlas _ _)
end Charts
/-! ### Differentiable partial homeomorphisms -/
namespace PartialHomeomorph.MDifferentiable
variable {e : PartialHomeomorph M M'} (he : e.MDifferentiable I I') {e' : PartialHomeomorph M' M''}
include he
nonrec theorem symm : e.symm.MDifferentiable I' I := he.symm
protected theorem mdifferentiableAt {x : M} (hx : x ∈ e.source) : MDifferentiableAt I I' e x :=
(he.1 x hx).mdifferentiableAt (e.open_source.mem_nhds hx)
theorem mdifferentiableAt_symm {x : M'} (hx : x ∈ e.target) : MDifferentiableAt I' I e.symm x :=
(he.2 x hx).mdifferentiableAt (e.open_target.mem_nhds hx)
theorem symm_comp_deriv {x : M} (hx : x ∈ e.source) :
(mfderiv I' I e.symm (e x)).comp (mfderiv I I' e x) =
ContinuousLinearMap.id 𝕜 (TangentSpace I x) := by
have : mfderiv I I (e.symm ∘ e) x = (mfderiv I' I e.symm (e x)).comp (mfderiv I I' e x) :=
mfderiv_comp x (he.mdifferentiableAt_symm (e.map_source hx)) (he.mdifferentiableAt hx)
rw [← this]
have : mfderiv I I (_root_.id : M → M) x = ContinuousLinearMap.id _ _ := mfderiv_id
rw [← this]
apply Filter.EventuallyEq.mfderiv_eq
have : e.source ∈ 𝓝 x := e.open_source.mem_nhds hx
exact Filter.mem_of_superset this (by mfld_set_tac)
theorem comp_symm_deriv {x : M'} (hx : x ∈ e.target) :
(mfderiv I I' e (e.symm x)).comp (mfderiv I' I e.symm x) =
ContinuousLinearMap.id 𝕜 (TangentSpace I' x) :=
he.symm.symm_comp_deriv hx
/-- The derivative of a differentiable partial homeomorphism, as a continuous linear equivalence
| between the tangent spaces at `x` and `e x`. -/
protected def mfderiv (he : e.MDifferentiable I I') {x : M} (hx : x ∈ e.source) :
TangentSpace I x ≃L[𝕜] TangentSpace I' (e x) :=
{ mfderiv I I' e x with
| Mathlib/Geometry/Manifold/MFDeriv/Atlas.lean | 172 | 175 |
/-
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.Option.NAry
import Mathlib.Data.Seq.Computation
import Mathlib.Tactic.ApplyFun
import Mathlib.Data.List.Basic
/-!
# Possibly infinite lists
This file provides a `Seq α` type representing possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`.
-/
namespace Stream'
universe u v w
/-
coinductive seq (α : Type u) : Type u
| nil : seq α
| cons : α → seq α → seq α
-/
/-- A stream `s : Option α` is a sequence if `s.get n = none` implies `s.get (n + 1) = none`.
-/
def IsSeq {α : Type u} (s : Stream' (Option α)) : Prop :=
∀ {n : ℕ}, s n = none → s (n + 1) = none
/-- `Seq α` is the type of possibly infinite lists (referred here as sequences).
It is encoded as an infinite stream of options such that if `f n = none`, then
`f m = none` for all `m ≥ n`. -/
def Seq (α : Type u) : Type u :=
{ f : Stream' (Option α) // f.IsSeq }
/-- `Seq1 α` is the type of nonempty sequences. -/
def Seq1 (α) :=
α × Seq α
namespace Seq
variable {α : Type u} {β : Type v} {γ : Type w}
/-- The empty sequence -/
def nil : Seq α :=
⟨Stream'.const none, fun {_} _ => rfl⟩
instance : Inhabited (Seq α) :=
⟨nil⟩
/-- Prepend an element to a sequence -/
def cons (a : α) (s : Seq α) : Seq α :=
⟨some a::s.1, by
rintro (n | _) h
· contradiction
· exact s.2 h⟩
@[simp]
theorem val_cons (s : Seq α) (x : α) : (cons x s).val = some x::s.val :=
rfl
/-- Get the nth element of a sequence (if it exists) -/
def get? : Seq α → ℕ → Option α :=
Subtype.val
@[simp]
theorem val_eq_get (s : Seq α) (n : ℕ) : s.val n = s.get? n := by
rfl
@[simp]
theorem get?_mk (f hf) : @get? α ⟨f, hf⟩ = f :=
rfl
@[simp]
theorem get?_nil (n : ℕ) : (@nil α).get? n = none :=
rfl
@[simp]
theorem get?_cons_zero (a : α) (s : Seq α) : (cons a s).get? 0 = some a :=
rfl
@[simp]
theorem get?_cons_succ (a : α) (s : Seq α) (n : ℕ) : (cons a s).get? (n + 1) = s.get? n :=
rfl
@[ext]
protected theorem ext {s t : Seq α} (h : ∀ n : ℕ, s.get? n = t.get? n) : s = t :=
Subtype.eq <| funext h
theorem cons_injective2 : Function.Injective2 (cons : α → Seq α → Seq α) := fun x y s t h =>
⟨by rw [← Option.some_inj, ← get?_cons_zero, h, get?_cons_zero],
Seq.ext fun n => by simp_rw [← get?_cons_succ x s n, h, get?_cons_succ]⟩
theorem cons_left_injective (s : Seq α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_right_injective (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
/-- A sequence has terminated at position `n` if the value at position `n` equals `none`. -/
def TerminatedAt (s : Seq α) (n : ℕ) : Prop :=
s.get? n = none
/-- It is decidable whether a sequence terminates at a given position. -/
instance terminatedAtDecidable (s : Seq α) (n : ℕ) : Decidable (s.TerminatedAt n) :=
decidable_of_iff' (s.get? n).isNone <| by unfold TerminatedAt; cases s.get? n <;> simp
/-- A sequence terminates if there is some position `n` at which it has terminated. -/
def Terminates (s : Seq α) : Prop :=
∃ n : ℕ, s.TerminatedAt n
theorem not_terminates_iff {s : Seq α} : ¬s.Terminates ↔ ∀ n, (s.get? n).isSome := by
simp only [Terminates, TerminatedAt, ← Ne.eq_def, Option.ne_none_iff_isSome, not_exists, iff_self]
/-- Functorial action of the functor `Option (α × _)` -/
@[simp]
def omap (f : β → γ) : Option (α × β) → Option (α × γ)
| none => none
| some (a, b) => some (a, f b)
/-- Get the first element of a sequence -/
def head (s : Seq α) : Option α :=
get? s 0
/-- Get the tail of a sequence (or `nil` if the sequence is `nil`) -/
def tail (s : Seq α) : Seq α :=
⟨s.1.tail, fun n' => by
obtain ⟨f, al⟩ := s
exact al n'⟩
/-- member definition for `Seq` -/
protected def Mem (s : Seq α) (a : α) :=
some a ∈ s.1
instance : Membership α (Seq α) :=
⟨Seq.Mem⟩
theorem le_stable (s : Seq α) {m n} (h : m ≤ n) : s.get? m = none → s.get? n = none := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
/-- If a sequence terminated at position `n`, it also terminated at `m ≥ n`. -/
theorem terminated_stable : ∀ (s : Seq α) {m n : ℕ}, m ≤ n → s.TerminatedAt m → s.TerminatedAt n :=
le_stable
/-- If `s.get? n = some aₙ` for some value `aₙ`, then there is also some value `aₘ` such
that `s.get? = some aₘ` for `m ≤ n`.
-/
theorem ge_stable (s : Seq α) {aₙ : α} {n m : ℕ} (m_le_n : m ≤ n)
(s_nth_eq_some : s.get? n = some aₙ) : ∃ aₘ : α, s.get? m = some aₘ :=
have : s.get? n ≠ none := by simp [s_nth_eq_some]
have : s.get? m ≠ none := mt (s.le_stable m_le_n) this
Option.ne_none_iff_exists'.mp this
theorem not_mem_nil (a : α) : a ∉ @nil α := fun ⟨_, (h : some a = none)⟩ => by injection h
theorem mem_cons (a : α) : ∀ s : Seq α, a ∈ cons a s
| ⟨_, _⟩ => Stream'.mem_cons (some a) _
theorem mem_cons_of_mem (y : α) {a : α} : ∀ {s : Seq α}, a ∈ s → a ∈ cons y s
| ⟨_, _⟩ => Stream'.mem_cons_of_mem (some y)
theorem eq_or_mem_of_mem_cons {a b : α} : ∀ {s : Seq α}, a ∈ cons b s → a = b ∨ a ∈ s
| ⟨_, _⟩, h => (Stream'.eq_or_mem_of_mem_cons h).imp_left fun h => by injection h
@[simp]
theorem mem_cons_iff {a b : α} {s : Seq α} : a ∈ cons b s ↔ a = b ∨ a ∈ s :=
⟨eq_or_mem_of_mem_cons, by rintro (rfl | m) <;> [apply mem_cons; exact mem_cons_of_mem _ m]⟩
@[simp]
theorem get?_mem {s : Seq α} {n : ℕ} {x : α} (h : s.get? n = .some x) : x ∈ s := ⟨n, h.symm⟩
/-- Destructor for a sequence, resulting in either `none` (for `nil`) or
`some (a, s)` (for `cons a s`). -/
def destruct (s : Seq α) : Option (Seq1 α) :=
(fun a' => (a', s.tail)) <$> get? s 0
theorem destruct_eq_none {s : Seq α} : destruct s = none → s = nil := by
dsimp [destruct]
induction' f0 : get? s 0 <;> intro h
· apply Subtype.eq
funext n
induction' n with n IH
exacts [f0, s.2 IH]
· contradiction
theorem destruct_eq_cons {s : Seq α} {a s'} : destruct s = some (a, s') → s = cons a s' := by
dsimp [destruct]
induction' f0 : get? s 0 with a' <;> intro h
· contradiction
· obtain ⟨f, al⟩ := s
injections _ h1 h2
rw [← h2]
apply Subtype.eq
dsimp [tail, cons]
rw [h1] at f0
rw [← f0]
exact (Stream'.eta f).symm
@[simp]
theorem destruct_nil : destruct (nil : Seq α) = none :=
rfl
@[simp]
theorem destruct_cons (a : α) : ∀ s, destruct (cons a s) = some (a, s)
| ⟨f, al⟩ => by
unfold cons destruct Functor.map
apply congr_arg fun s => some (a, s)
apply Subtype.eq; dsimp [tail]
-- Porting note: needed universe annotation to avoid universe issues
theorem head_eq_destruct (s : Seq α) : head.{u} s = Prod.fst.{u} <$> destruct.{u} s := by
unfold destruct head; cases get? s 0 <;> rfl
@[simp]
theorem head_nil : head (nil : Seq α) = none :=
rfl
@[simp]
theorem head_cons (a : α) (s) : head (cons a s) = some a := by
rw [head_eq_destruct, destruct_cons, Option.map_eq_map, Option.map_some']
@[simp]
theorem tail_nil : tail (nil : Seq α) = nil :=
rfl
@[simp]
theorem tail_cons (a : α) (s) : tail (cons a s) = s := by
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [tail, cons]
@[simp]
theorem get?_tail (s : Seq α) (n) : get? (tail s) n = get? s (n + 1) :=
rfl
/-- Recursion principle for sequences, compare with `List.recOn`. -/
@[cases_eliminator]
def recOn {motive : Seq α → Sort v} (s : Seq α) (nil : motive nil)
(cons : ∀ x s, motive (cons x s)) :
motive s := by
rcases H : destruct s with - | v
· rw [destruct_eq_none H]
apply nil
· obtain ⟨a, s'⟩ := v
rw [destruct_eq_cons H]
apply cons
@[simp]
theorem cons_ne_nil {x : α} {s : Seq α} : (cons x s) ≠ .nil := by
intro h
apply_fun head at h
simp at h
@[simp]
theorem nil_ne_cons {x : α} {s : Seq α} : .nil ≠ (cons x s) := cons_ne_nil.symm
theorem cons_eq_cons {x x' : α} {s s' : Seq α} :
(cons x s = cons x' s') ↔ (x = x' ∧ s = s') := by
constructor
· intro h
constructor
· apply_fun head at h
simpa using h
· apply_fun tail at h
simpa using h
· intro ⟨_, _⟩
congr
theorem head_eq_some {s : Seq α} {x : α} (h : s.head = some x) :
s = cons x s.tail := by
cases s <;> simp at h
simpa [cons_eq_cons]
theorem head_eq_none {s : Seq α} (h : s.head = none) : s = nil := by
cases s
· rfl
· simp at h
@[simp]
theorem head_eq_none_iff {s : Seq α} : s.head = none ↔ s = nil := by
constructor
· apply head_eq_none
· intro h
simp [h]
theorem mem_rec_on {C : Seq α → Prop} {a s} (M : a ∈ s)
(h1 : ∀ b s', a = b ∨ C s' → C (cons b s')) : C s := by
obtain ⟨k, e⟩ := M; unfold Stream'.get at e
induction' k with k IH generalizing s
· have TH : s = cons a (tail s) := by
apply destruct_eq_cons
unfold destruct get? Functor.map
rw [← e]
rfl
rw [TH]
apply h1 _ _ (Or.inl rfl)
cases s with
| nil => injection e
| cons b s' =>
have h_eq : (cons b s').val (Nat.succ k) = s'.val k := by cases s' using Subtype.recOn; rfl
rw [h_eq] at e
apply h1 _ _ (Or.inr (IH e))
/-- Corecursor over pairs of `Option` values -/
def Corec.f (f : β → Option (α × β)) : Option β → Option α × Option β
| none => (none, none)
| some b =>
match f b with
| none => (none, none)
| some (a, b') => (some a, some b')
/-- Corecursor for `Seq α` as a coinductive type. Iterates `f` to produce new elements
of the sequence until `none` is obtained. -/
def corec (f : β → Option (α × β)) (b : β) : Seq α := by
refine ⟨Stream'.corec' (Corec.f f) (some b), fun {n} h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (some b)).2 n = none
revert h; generalize some b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = none → (Corec.f f (Corec.f f o).2).1 = none
rcases o with - | b <;> intro h
· rfl
dsimp [Corec.f] at h
dsimp [Corec.f]
revert h; rcases h₁ : f b with - | s <;> intro h
· rfl
· obtain ⟨a, b'⟩ := s
contradiction
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
@[simp]
theorem corec_eq (f : β → Option (α × β)) (b : β) :
destruct (corec f b) = omap (corec f) (f b) := by
dsimp [corec, destruct, get]
rw [show Stream'.corec' (Corec.f f) (some b) 0 = (Corec.f f (some b)).1 from rfl]
dsimp [Corec.f]
induction' h : f b with s; · rfl
obtain ⟨a, b'⟩ := s; dsimp [Corec.f]
apply congr_arg fun b' => some (a, b')
apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
theorem corec_nil (f : β → Option (α × β)) (b : β)
(h : f b = .none) : corec f b = nil := by
apply destruct_eq_none
simp [h]
theorem corec_cons {f : β → Option (α × β)} {b : β} {x : α} {s : β}
(h : f b = .some (x, s)) : corec f b = cons x (corec f s) := by
apply destruct_eq_cons
simp [h]
section Bisim
variable (R : Seq α → Seq α → Prop)
local infixl:50 " ~ " => R
/-- Bisimilarity relation over `Option` of `Seq1 α` -/
def BisimO : Option (Seq1 α) → Option (Seq1 α) → Prop
| none, none => True
| some (a, s), some (a', s') => a = a' ∧ R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- a relation is bisimilar if it meets the `BisimO` test -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Seq α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
exact
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ => by
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s using Subtype.recOn; rfl,
by cases s' using Subtype.recOn; rfl, r⟩) this
have := bisim r; revert r this
cases s <;> cases s'
· intro r _
constructor
· rfl
· assumption
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_nil, destruct_cons] at this
exact False.elim this
· intro _ this
rw [destruct_cons, destruct_cons] at this
rw [head_cons, head_cons, tail_cons, tail_cons]
obtain ⟨h1, h2⟩ := this
constructor
· rw [h1]
· exact h2
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
theorem coinduction :
∀ {s₁ s₂ : Seq α},
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Seq α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂
| _, _, hh, ht =>
Subtype.eq (Stream'.coinduction hh fun β fr => ht β fun s => fr s.1)
theorem coinduction2 (s) (f g : Seq α → Seq β)
(H :
∀ s,
BisimO (fun s1 s2 : Seq β => ∃ s : Seq α, s1 = f s ∧ s2 = g s) (destruct (f s))
(destruct (g s))) :
f s = g s := by
refine eq_of_bisim (fun s1 s2 => ∃ s, s1 = f s ∧ s2 = g s) ?_ ⟨s, rfl, rfl⟩
intro s1 s2 h; rcases h with ⟨s, h1, h2⟩
rw [h1, h2]; apply H
/-- Embed a list as a sequence -/
@[coe]
def ofList (l : List α) : Seq α :=
⟨(l[·]?), fun {n} h => by
rw [List.getElem?_eq_none_iff] at h ⊢
exact h.trans (Nat.le_succ n)⟩
instance coeList : Coe (List α) (Seq α) :=
⟨ofList⟩
@[simp]
theorem ofList_nil : ofList [] = (nil : Seq α) :=
rfl
@[simp]
theorem ofList_get? (l : List α) (n : ℕ) : (ofList l).get? n = l[n]? :=
rfl
@[deprecated (since := "2025-02-21")]
alias ofList_get := ofList_get?
@[simp]
theorem ofList_cons (a : α) (l : List α) : ofList (a::l) = cons a (ofList l) := by
ext1 (_ | n) <;> simp
theorem ofList_injective : Function.Injective (ofList : List α → _) :=
fun _ _ h => List.ext_getElem? fun _ => congr_fun (Subtype.ext_iff.1 h) _
/-- Embed an infinite stream as a sequence -/
@[coe]
def ofStream (s : Stream' α) : Seq α :=
⟨s.map some, fun {n} h => by contradiction⟩
instance coeStream : Coe (Stream' α) (Seq α) :=
⟨ofStream⟩
section MLList
/-- Embed a `MLList α` as a sequence. Note that even though this
is non-meta, it will produce infinite sequences if used with
cyclic `MLList`s created by meta constructions. -/
def ofMLList : MLList Id α → Seq α :=
corec fun l =>
match l.uncons with
| .none => none
| .some (a, l') => some (a, l')
instance coeMLList : Coe (MLList Id α) (Seq α) :=
⟨ofMLList⟩
/-- Translate a sequence into a `MLList`. -/
unsafe def toMLList : Seq α → MLList Id α
| s =>
match destruct s with
| none => .nil
| some (a, s') => .cons a (toMLList s')
end MLList
/-- Translate a sequence to a list. This function will run forever if
run on an infinite sequence. -/
unsafe def forceToList (s : Seq α) : List α :=
(toMLList s).force
/-- The sequence of natural numbers some 0, some 1, ... -/
def nats : Seq ℕ :=
Stream'.nats
@[simp]
theorem nats_get? (n : ℕ) : nats.get? n = some n :=
rfl
/-- Append two sequences. If `s₁` is infinite, then `s₁ ++ s₂ = s₁`,
otherwise it puts `s₂` at the location of the `nil` in `s₁`. -/
def append (s₁ s₂ : Seq α) : Seq α :=
@corec α (Seq α × Seq α)
(fun ⟨s₁, s₂⟩ =>
match destruct s₁ with
| none => omap (fun s₂ => (nil, s₂)) (destruct s₂)
| some (a, s₁') => some (a, s₁', s₂))
(s₁, s₂)
/-- Map a function over a sequence. -/
def map (f : α → β) : Seq α → Seq β
| ⟨s, al⟩ =>
⟨s.map (Option.map f), fun {n} => by
dsimp [Stream'.map, Stream'.get]
induction' e : s n with e <;> intro
· rw [al e]
assumption
· contradiction⟩
/-- Flatten a sequence of sequences. (It is required that the
sequences be nonempty to ensure productivity; in the case
of an infinite sequence of `nil`, the first element is never
generated.) -/
def join : Seq (Seq1 α) → Seq α :=
corec fun S =>
match destruct S with
| none => none
| some ((a, s), S') =>
some
(a,
match destruct s with
| none => S'
| some s' => cons s' S')
/-- Remove the first `n` elements from the sequence. -/
def drop (s : Seq α) : ℕ → Seq α
| 0 => s
| n + 1 => tail (drop s n)
/-- Take the first `n` elements of the sequence (producing a list) -/
def take : ℕ → Seq α → List α
| 0, _ => []
| n + 1, s =>
match destruct s with
| none => []
| some (x, r) => List.cons x (take n r)
/-- Split a sequence at `n`, producing a finite initial segment
and an infinite tail. -/
def splitAt : ℕ → Seq α → List α × Seq α
| 0, s => ([], s)
| n + 1, s =>
match destruct s with
| none => ([], nil)
| some (x, s') =>
let (l, r) := splitAt n s'
(List.cons x l, r)
/-- Folds a sequence using `f`, producing a sequence of intermediate values, i.e.
`[init, f init s.head, f (f init s.head) s.tail.head, ...]`. -/
def fold (s : Seq α) (init : β) (f : β → α → β) : Seq β :=
let f : β × Seq α → Option (β × (β × Seq α)) := fun (acc, x) =>
match destruct x with
| none => .none
| some (x, s) => .some (f acc x, f acc x, s)
cons init <| corec f (init, s)
section ZipWith
/-- Combine two sequences with a function -/
def zipWith (f : α → β → γ) (s₁ : Seq α) (s₂ : Seq β) : Seq γ :=
⟨fun n => Option.map₂ f (s₁.get? n) (s₂.get? n), fun {_} hn =>
Option.map₂_eq_none_iff.2 <| (Option.map₂_eq_none_iff.1 hn).imp s₁.2 s₂.2⟩
@[simp]
theorem get?_zipWith (f : α → β → γ) (s s' n) :
(zipWith f s s').get? n = Option.map₂ f (s.get? n) (s'.get? n) :=
rfl
end ZipWith
/-- Pair two sequences into a sequence of pairs -/
def zip : Seq α → Seq β → Seq (α × β) :=
zipWith Prod.mk
@[simp]
theorem get?_zip (s : Seq α) (t : Seq β) (n : ℕ) :
get? (zip s t) n = Option.map₂ Prod.mk (get? s n) (get? t n) :=
get?_zipWith _ _ _ _
/-- Separate a sequence of pairs into two sequences -/
def unzip (s : Seq (α × β)) : Seq α × Seq β :=
(map Prod.fst s, map Prod.snd s)
/-- Enumerate a sequence by tagging each element with its index. -/
def enum (s : Seq α) : Seq (ℕ × α) :=
Seq.zip nats s
@[simp]
theorem get?_enum (s : Seq α) (n : ℕ) : get? (enum s) n = Option.map (Prod.mk n) (get? s n) :=
get?_zip _ _ _
@[simp]
theorem enum_nil : enum (nil : Seq α) = nil :=
rfl
/-- The length of a terminating sequence. -/
def length (s : Seq α) (h : s.Terminates) : ℕ :=
Nat.find h
/-- Convert a sequence which is known to terminate into a list -/
def toList (s : Seq α) (h : s.Terminates) : List α :=
take (length s h) s
/-- Convert a sequence which is known not to terminate into a stream -/
def toStream (s : Seq α) (h : ¬s.Terminates) : Stream' α := fun n =>
Option.get _ <| not_terminates_iff.1 h n
/-- Convert a sequence into either a list or a stream depending on whether
it is finite or infinite. (Without decidability of the infiniteness predicate,
this is not constructively possible.) -/
def toListOrStream (s : Seq α) [Decidable s.Terminates] : List α ⊕ Stream' α :=
if h : s.Terminates then Sum.inl (toList s h) else Sum.inr (toStream s h)
@[simp]
theorem nil_append (s : Seq α) : append nil s = s := by
apply coinduction2; intro s
dsimp [append]; rw [corec_eq]
dsimp [append]
cases s
· trivial
· rw [destruct_cons]
dsimp
exact ⟨rfl, _, rfl, rfl⟩
@[simp]
theorem take_nil {n : ℕ} : (nil (α := α)).take n = List.nil := by
cases n <;> rfl
@[simp]
theorem take_zero {s : Seq α} : s.take 0 = [] := by
cases s <;> rfl
@[simp]
theorem take_succ_cons {n : ℕ} {x : α} {s : Seq α} :
(cons x s).take (n + 1) = x :: s.take n := by
rfl
@[simp]
theorem getElem?_take : ∀ (n k : ℕ) (s : Seq α),
(s.take k)[n]? = if n < k then s.get? n else none
| n, 0, s => by simp [take]
| n, k+1, s => by
rw [take]
cases h : destruct s with
| none =>
simp [destruct_eq_none h]
| some a =>
match a with
| (x, r) =>
rw [destruct_eq_cons h]
match n with
| 0 => simp
| n+1 =>
simp [List.getElem?_cons_succ, Nat.add_lt_add_iff_right, getElem?_take]
theorem get?_mem_take {s : Seq α} {m n : ℕ} (h_mn : m < n) {x : α}
(h_get : s.get? m = .some x) : x ∈ s.take n := by
induction m generalizing n s with
| zero =>
obtain ⟨l, hl⟩ := Nat.exists_add_one_eq.mpr h_mn
rw [← hl, take, head_eq_some h_get]
simp
| succ k ih =>
obtain ⟨l, hl⟩ := Nat.exists_eq_add_of_lt h_mn
subst hl
have : ∃ y, s.get? 0 = .some y := by
apply ge_stable _ _ h_get
simp
obtain ⟨y, hy⟩ := this
rw [take, head_eq_some hy]
simp
right
apply ih (by omega)
rwa [get?_tail]
theorem terminatedAt_ofList (l : List α) :
(ofList l).TerminatedAt l.length := by
simp [ofList, TerminatedAt]
theorem terminates_ofList (l : List α) : (ofList l).Terminates :=
⟨_, terminatedAt_ofList l⟩
@[simp]
theorem terminatedAt_nil {n : ℕ} : TerminatedAt (nil : Seq α) n := rfl
@[simp]
theorem cons_not_terminatedAt_zero {x : α} {s : Seq α} :
¬(cons x s).TerminatedAt 0 := by
simp [TerminatedAt]
@[simp]
theorem cons_terminatedAt_succ_iff {x : α} {s : Seq α} {n : ℕ} :
(cons x s).TerminatedAt (n + 1) ↔ s.TerminatedAt n := by
simp [TerminatedAt]
@[simp]
theorem terminates_nil : Terminates (nil : Seq α) := ⟨0, rfl⟩
@[simp]
theorem terminates_cons_iff {x : α} {s : Seq α} :
(cons x s).Terminates ↔ s.Terminates := by
constructor <;> intro ⟨n, h⟩
· exact ⟨n, cons_terminatedAt_succ_iff.mp (terminated_stable _ (Nat.le_succ _) h)⟩
· exact ⟨n + 1, cons_terminatedAt_succ_iff.mpr h⟩
@[simp]
theorem length_nil : length (nil : Seq α) terminates_nil = 0 := rfl
@[simp]
theorem get?_zero_eq_none {s : Seq α} : s.get? 0 = none ↔ s = nil := by
refine ⟨fun h => ?_, fun h => h ▸ rfl⟩
ext1 n
exact le_stable s (Nat.zero_le _) h
@[simp] theorem length_eq_zero {s : Seq α} {h : s.Terminates} :
s.length h = 0 ↔ s = nil := by
simp [length, TerminatedAt]
theorem terminatedAt_zero_iff {s : Seq α} : s.TerminatedAt 0 ↔ s = nil := by
refine ⟨?_, ?_⟩
· intro h
ext n
rw [le_stable _ (Nat.zero_le _) h]
simp
· rintro rfl
simp [TerminatedAt]
/-- The statement of `length_le_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `length_le_iff` -/
theorem length_le_iff' {s : Seq α} {n : ℕ} :
(∃ h, s.length h ≤ n) ↔ s.TerminatedAt n := by
simp only [length, Nat.find_le_iff, TerminatedAt, Terminates, exists_prop]
refine ⟨?_, ?_⟩
· rintro ⟨_, k, hkn, hk⟩
exact le_stable s hkn hk
· intro hn
exact ⟨⟨n, hn⟩, ⟨n, le_rfl, hn⟩⟩
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem length_le_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
s.length h ≤ n ↔ s.TerminatedAt n := by
rw [← length_le_iff']; simp [h]
/-- The statement of `lt_length_iff'` does not assume that the sequence terminates. For a
simpler statement of the theorem where the sequence is known to terminate see `lt_length_iff` -/
theorem lt_length_iff' {s : Seq α} {n : ℕ} :
(∀ h : s.Terminates, n < s.length h) ↔ ∃ a, a ∈ s.get? n := by
simp only [Terminates, TerminatedAt, length, Nat.lt_find_iff, forall_exists_index, Option.mem_def,
← Option.ne_none_iff_exists', ne_eq]
refine ⟨?_, ?_⟩
· intro h hn
exact h n hn n le_rfl hn
· intro hn _ _ k hkn hk
exact hn <| le_stable s hkn hk
/-- The statement of `length_le_iff` assumes that the sequence terminates. For a
statement of the where the sequence is not known to terminate see `length_le_iff'` -/
theorem lt_length_iff {s : Seq α} {n : ℕ} {h : s.Terminates} :
n < s.length h ↔ ∃ a, a ∈ s.get? n := by
rw [← lt_length_iff']; simp [h]
theorem length_take_le {s : Seq α} {n : ℕ} : (s.take n).length ≤ n := by
induction n generalizing s with
| zero => simp
| succ m ih =>
rw [take]
cases s.destruct with
| none => simp
| some v =>
obtain ⟨x, r⟩ := v
simpa using ih
theorem length_take_of_le_length {s : Seq α} {n : ℕ}
(hle : ∀ h : s.Terminates, n ≤ s.length h) : (s.take n).length = n := by
induction n generalizing s with
| zero => simp [take]
| succ n ih =>
rw [take, destruct]
let ⟨a, ha⟩ := lt_length_iff'.1 (fun ht => lt_of_lt_of_le (Nat.succ_pos _) (hle ht))
simp [Option.mem_def.1 ha]
rw [ih]
intro h
simp only [length, tail, Nat.le_find_iff, TerminatedAt, get?_mk, Stream'.tail]
intro m hmn hs
have := lt_length_iff'.1 (fun ht => (Nat.lt_of_succ_le (hle ht)))
rw [le_stable s (Nat.succ_le_of_lt hmn) hs] at this
simp at this
@[simp]
theorem length_toList (s : Seq α) (h : s.Terminates) : (toList s h).length = length s h := by
rw [toList, length_take_of_le_length]
intro _
exact le_rfl
@[simp]
theorem getElem?_toList (s : Seq α) (h : s.Terminates) (n : ℕ) : (toList s h)[n]? = s.get? n := by
ext k
simp only [ofList, toList, get?_mk, Option.mem_def, getElem?_take, Nat.lt_find_iff, length,
Option.ite_none_right_eq_some, and_iff_right_iff_imp, TerminatedAt]
| intro h m hmn
let ⟨a, ha⟩ := ge_stable s hmn h
simp [ha]
| Mathlib/Data/Seq/Seq.lean | 816 | 818 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.SetTheory.Ordinal.Exponential
import Mathlib.SetTheory.Ordinal.Family
/-!
# Cantor Normal Form
The Cantor normal form of an ordinal is generally defined as its base `ω` expansion, with its
non-zero exponents in decreasing order. Here, we more generally define a base `b` expansion
`Ordinal.CNF` in this manner, which is well-behaved for any `b ≥ 2`.
# Implementation notes
We implement `Ordinal.CNF` as an association list, where keys are exponents and values are
coefficients. This is because this structure intrinsically reflects two key properties of the Cantor
normal form:
- It is ordered.
- It has finitely many entries.
# Todo
- Add API for the coefficients of the Cantor normal form.
- Prove the basic results relating the CNF to the arithmetic operations on ordinals.
-/
noncomputable section
universe u
open List
namespace Ordinal
/-- Inducts on the base `b` expansion of an ordinal. -/
@[elab_as_elim]
noncomputable def CNFRec (b : Ordinal) {C : Ordinal → Sort*} (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) (o : Ordinal) : C o :=
if h : o = 0 then h ▸ H0 else H o h (CNFRec b H0 H (o % b ^ log b o))
termination_by o
decreasing_by exact mod_opow_log_lt_self b h
@[simp]
theorem CNFRec_zero {C : Ordinal → Sort*} (b : Ordinal) (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) : CNFRec b H0 H 0 = H0 := by
rw [CNFRec, dif_pos rfl]
theorem CNFRec_pos (b : Ordinal) {o : Ordinal} {C : Ordinal → Sort*} (ho : o ≠ 0) (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) :
CNFRec b H0 H o = H o ho (@CNFRec b C H0 H _) := by
rw [CNFRec, dif_neg]
/-- The Cantor normal form of an ordinal `o` is the list of coefficients and exponents in the
base-`b` expansion of `o`.
We special-case `CNF 0 o = CNF 1 o = [(0, o)]` for `o ≠ 0`.
`CNF b (b ^ u₁ * v₁ + b ^ u₂ * v₂) = [(u₁, v₁), (u₂, v₂)]` -/
@[pp_nodot]
def CNF (b o : Ordinal) : List (Ordinal × Ordinal) :=
CNFRec b [] (fun o _ IH ↦ (log b o, o / b ^ log b o)::IH) o
@[simp]
theorem CNF_zero (b : Ordinal) : CNF b 0 = [] :=
CNFRec_zero b _ _
/-- Recursive definition for the Cantor normal form. -/
theorem CNF_ne_zero {b o : Ordinal} (ho : o ≠ 0) :
CNF b o = (log b o, o / b ^ log b o)::CNF b (o % b ^ log b o) :=
CNFRec_pos b ho _ _
theorem zero_CNF {o : Ordinal} (ho : o ≠ 0) : CNF 0 o = [(0, o)] := by simp [CNF_ne_zero ho]
theorem one_CNF {o : Ordinal} (ho : o ≠ 0) : CNF 1 o = [(0, o)] := by simp [CNF_ne_zero ho]
theorem CNF_of_le_one {b o : Ordinal} (hb : b ≤ 1) (ho : o ≠ 0) : CNF b o = [(0, o)] := by
rcases le_one_iff.1 hb with (rfl | rfl)
exacts [zero_CNF ho, one_CNF ho]
theorem CNF_of_lt {b o : Ordinal} (ho : o ≠ 0) (hb : o < b) : CNF b o = [(0, o)] := by
rw [CNF_ne_zero ho, log_eq_zero hb, opow_zero, div_one, mod_one, CNF_zero]
/-- Evaluating the Cantor normal form of an ordinal returns the ordinal. -/
theorem CNF_foldr (b o : Ordinal) : (CNF b o).foldr (fun p r ↦ b ^ p.1 * p.2 + r) 0 = o := by
refine CNFRec b ?_ ?_ o
· rw [CNF_zero, foldr_nil]
· intro o ho IH
rw [CNF_ne_zero ho, foldr_cons, IH, div_add_mod]
/-- Every exponent in the Cantor normal form `CNF b o` is less or equal to `log b o`. -/
theorem CNF_fst_le_log {b o : Ordinal.{u}} {x : Ordinal × Ordinal} :
x ∈ CNF b o → x.1 ≤ log b o := by
refine CNFRec b ?_ (fun o ho H ↦ ?_) o
· simp
· rw [CNF_ne_zero ho, mem_cons]
| rintro (rfl | h)
· rfl
· exact (H h).trans (log_mono_right _ (mod_opow_log_lt_self b ho).le)
| Mathlib/SetTheory/Ordinal/CantorNormalForm.lean | 101 | 104 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.Module.End
import Mathlib.Algebra.Ring.Prod
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Tactic.FinCases
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `ZMod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
* A coercion `cast` is defined from `ZMod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
assert_not_exists Field Submodule TwoSidedIdeal
open Function ZMod
namespace ZMod
/-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/
def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n
| 0, h => (h.ne _ rfl).elim
| _ + 1, _ => .refl _
instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ)
/-- `val a` is a natural number defined as:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
See `ZMod.valMinAbs` for a variant that takes values in the integers.
-/
def val : ∀ {n : ℕ}, ZMod n → ℕ
| 0 => Int.natAbs
| n + 1 => ((↑) : Fin (n + 1) → ℕ)
theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by
cases n
· cases NeZero.ne 0 rfl
exact Fin.is_lt a
theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n :=
a.val_lt.le
@[simp]
theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0
| 0 => rfl
| _ + 1 => rfl
@[simp]
theorem val_one' : (1 : ZMod 0).val = 1 :=
rfl
@[simp]
theorem val_neg' {n : ZMod 0} : (-n).val = n.val :=
Int.natAbs_neg n
@[simp]
theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val :=
Int.natAbs_mul m n
@[simp]
theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by
cases n
· rw [Nat.mod_zero]
exact Int.natAbs_natCast a
· apply Fin.val_natCast
lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rwa [val_natCast, Nat.mod_eq_of_lt]
lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast ..
lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) :=
val_natCast_of_lt han
theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by
simp only [val]
rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one]
lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by
rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h]
instance charP (n : ℕ) : CharP (ZMod n) n where
cast_eq_zero_iff := by
intro k
rcases n with - | n
· simp [zero_dvd_iff, Int.natCast_eq_zero]
· exact Fin.natCast_eq_zero
@[simp]
theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n :=
CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n)
/-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `addOrderOf_coe'`. -/
@[simp]
theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rcases a with - | a
· simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right,
Nat.pos_of_ne_zero n0, Nat.div_self]
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one]
/-- This lemma works in the case in which `a ≠ 0`. The version where
`ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/
@[simp]
theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one]
/-- We have that `ringChar (ZMod n) = n`. -/
theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
rw [ringChar.eq_iff]
exact ZMod.charP n
theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
CharP.cast_eq_zero (ZMod n) n
@[simp]
theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by
rw [← Nat.cast_add_one, natCast_self (n + 1)]
section UniversalProperty
variable {n : ℕ} {R : Type*}
section
variable [AddGroupWithOne R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `ZMod.castHom` for a bundled version. -/
def cast : ∀ {n : ℕ}, ZMod n → R
| 0 => Int.cast
| _ + 1 => fun i => i.val
@[simp]
theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by
delta ZMod.cast
cases n
· exact Int.cast_zero
· simp
theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by
cases n
· cases NeZero.ne 0 rfl
rfl
variable {S : Type*} [AddGroupWithOne S]
@[simp]
theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by
cases n
· rfl
· simp [ZMod.cast]
@[simp]
theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by
cases n
· rfl
· simp [ZMod.cast]
end
/-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring,
see `ZMod.natCast_val`. -/
theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.cast_val_eq_self
theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) :=
natCast_zmod_val
theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) :=
natCast_rightInverse.surjective
/-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary
ring, see `ZMod.intCast_cast`. -/
@[norm_cast]
theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by
cases n
· simp [ZMod.cast, ZMod]
· dsimp [ZMod.cast]
rw [Int.cast_natCast, natCast_zmod_val]
theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) :=
intCast_zmod_cast
theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) :=
intCast_rightInverse.surjective
lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall
lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists
theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i
| 0, _ => Int.cast_id
| _ + 1, i => natCast_zmod_val i
@[simp]
theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id :=
funext (cast_id n)
variable (R) [Ring R]
/-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/
@[simp]
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n
· cases NeZero.ne 0 rfl
rfl
/-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/
@[simp]
theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by
cases n
· exact congr_arg (Int.cast ∘ ·) ZMod.cast_id'
· ext
simp [ZMod, ZMod.cast]
variable {R}
@[simp]
theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i :=
congr_fun (natCast_comp_val R) i
@[simp]
theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i :=
congr_fun (intCast_comp_cast R) i
theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) :
(cast (a + b) : ℤ) =
if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by
rcases n with - | n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· rw [Nat.cast_sub h]
congr
· rfl
section CharDvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variable {m : ℕ} [CharP R m]
@[simp]
theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by
rcases n with - | n
· exact Int.cast_one
show ((1 % (n + 1) : ℕ) : R) = 1
cases n
· rw [Nat.dvd_one] at h
subst m
subsingleton [CharP.CharOne.subsingleton]
rw [Nat.mod_eq_of_lt]
· exact Nat.cast_one
exact Nat.lt_of_sub_eq_succ rfl
theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by
cases n
· apply Int.cast_add
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by
cases n
· apply Int.cast_mul
symm
dsimp [ZMod, ZMod.cast, ZMod.val]
rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
/-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`.
See also `ZMod.lift` for a generalized version working in `AddGroup`s.
-/
def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where
toFun := cast
map_zero' := cast_zero
map_one' := cast_one h
map_add' := cast_add h
map_mul' := cast_mul h
@[simp]
theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i :=
rfl
@[simp]
theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
(castHom h R).map_sub a b
@[simp]
theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) :=
(castHom h R).map_neg a
@[simp]
theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k :=
(castHom h R).map_pow a k
@[simp, norm_cast]
theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
map_natCast (castHom h R) k
@[simp, norm_cast]
theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
map_intCast (castHom h R) k
end CharDvd
section CharEq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [CharP R n]
@[simp]
theorem cast_one' : (cast (1 : ZMod n) : R) = 1 :=
cast_one dvd_rfl
@[simp]
theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b :=
cast_add dvd_rfl a b
@[simp]
theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b :=
cast_mul dvd_rfl a b
@[simp]
theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
cast_sub dvd_rfl a b
@[simp]
theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k :=
cast_natCast dvd_rfl k
@[simp, norm_cast]
theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k :=
cast_intCast dvd_rfl k
variable (R)
theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by
rw [injective_iff_map_eq_zero]
intro x
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x
rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n]
exact id
theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) :
Function.Bijective (ZMod.castHom (dvd_refl n) R) := by
haveI : NeZero n :=
⟨by
intro hn
rw [hn] at h
exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩
rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true]
apply ZMod.castHom_injective
/-- The unique ring isomorphism between `ZMod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R :=
RingEquiv.ofBijective _ (ZMod.castHom_bijective R h)
/-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`.
If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv`
below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/
noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) :
ZMod p ≃+* R :=
have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt)
-- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`.
have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R)
ZMod.ringEquiv R hR
@[simp]
lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime)
(hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl
/-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/
def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by
rcases m with - | m <;> rcases n with - | n
· exact RingEquiv.refl _
· exfalso
exact n.succ_ne_zero h.symm
· exfalso
exact m.succ_ne_zero h
· exact
{ finCongr h with
map_mul' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h]
map_add' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] }
@[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by
cases a <;> rfl
lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by
rw [ringEquivCongr_refl]
rfl
lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) :
(ringEquivCongr hab).symm = ringEquivCongr hab.symm := by
subst hab
cases a <;> rfl
lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) :
(ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by
subst hab hbc
cases a <;> rfl
lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) :
ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by
rw [← ringEquivCongr_trans hab hbc]
rfl
lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) :
ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by
subst h
cases a <;> rfl
lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) :
ZMod.ringEquivCongr h z = z := by
subst h
cases a <;> rfl
end CharEq
end UniversalProperty
variable {m n : ℕ}
@[simp]
theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0
| 0, _ => Int.natAbs_eq_zero
| n + 1, a => by
rw [Fin.ext_iff]
exact Iff.rfl
theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] :=
CharP.intCast_eq_intCast (ZMod c) c
theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.intCast_eq_intCast_iff a b c
theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by
have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _
have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a)
refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_
rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id]
theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by
simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c
theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.natCast_eq_natCast_iff a b c
theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by
rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd]
theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by
rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd]
theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by
rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd]
theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by
cases n
· rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl
· rw [← val_intCast, val]; rfl
lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by
rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by
rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast]
@[simp]
theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by
dsimp [val, Fin.coe_neg]
cases n
· simp [Nat.mod_one]
· dsimp [ZMod, ZMod.cast]
rw [Fin.coe_neg_one]
/-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by
rcases n with - | n
· dsimp [ZMod, ZMod.cast]; simp
· rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right]
theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) :
(cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by
split_ifs with hk
· rw [hk, zero_sub, ZMod.cast_neg_one]
· cases n
· dsimp [ZMod, ZMod.cast]
rw [Int.cast_sub, Int.cast_one]
· dsimp [ZMod, ZMod.cast, ZMod.val]
rw [Fin.coe_sub_one, if_neg]
· rw [Nat.cast_sub, Nat.cast_one]
rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk
· exact hk
theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_natCast, Nat.mod_add_div]
· rintro ⟨k, rfl⟩
rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul,
add_zero]
theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_intCast, Int.emod_add_ediv]
· rintro ⟨k, rfl⟩
rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val,
ZMod.natCast_self, zero_mul, add_zero, cast_id]
@[push_cast, simp]
theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by
rw [ZMod.intCast_eq_intCast_iff]
apply Int.mod_modEq
theorem ker_intCastAddHom (n : ℕ) :
(Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by
ext
rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom,
intCast_zmod_eq_zero_iff_dvd]
theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) :
Function.Injective (@cast (ZMod n) _ m) := by
cases m with
| zero => cases nzm; simp_all
| succ m =>
rintro ⟨x, hx⟩ ⟨y, hy⟩ f
simp only [cast, val, natCast_eq_natCast_iff',
Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f
apply Fin.ext
exact f
theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast a : ZMod n) = 0 ↔ a = 0 := by
rw [← ZMod.cast_zero (n := m)]
exact Injective.eq_iff' (cast_injective_of_le h) rfl
@[simp]
theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z
| (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast]
| Int.negSucc n, h => by simp at h
theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by
cases n
· cases NeZero.ne 0 rfl
intro a b h
dsimp [ZMod]
ext
exact h
theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by
rw [← Nat.cast_one, val_natCast]
theorem val_two_eq_two_mod (n : ℕ) : (2 : ZMod n).val = 2 % n := by
rw [← Nat.cast_two, val_natCast]
theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by
rw [val_one_eq_one_mod]
exact Nat.mod_eq_of_lt Fact.out
lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1
| 0, _ => rfl
| 1, hn => by cases hn rfl
| n + 2, _ =>
haveI : Fact (1 < n + 2) := ⟨by simp⟩
ZMod.val_one _
theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.val_add
theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
have : NeZero n := by constructor; rintro rfl; simp at h
rw [ZMod.val_add, Nat.mod_eq_of_lt h]
theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
a.val + b.val = (a + b).val + n := by
rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _),
Nat.mod_eq_of_lt (val_lt _)]
rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)]
theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
(a + b).val = a.val + b.val - n := by
rw [val_add_val_of_le h]
exact eq_tsub_of_add_eq rfl
theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by
cases n
· simpa [ZMod.val] using Int.natAbs_add_le _ _
· simpa [ZMod.val_add] using Nat.mod_le _ _
theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by
cases n
· rw [Nat.mod_zero]
apply Int.natAbs_mul
· apply Fin.val_mul
theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by
rw [val_mul]
apply Nat.mod_le
theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) :
(a * b).val = a.val * b.val := by
rw [val_mul]
apply Nat.mod_eq_of_lt h
theorem val_mul_iff_lt {n : ℕ} [NeZero n] (a b : ZMod n) :
(a * b).val = a.val * b.val ↔ a.val * b.val < n := by
constructor <;> intro h
· rw [← h]; apply ZMod.val_lt
· apply ZMod.val_mul_of_lt h
instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) :=
⟨⟨0, 1, fun h =>
zero_ne_one <|
calc
0 = (0 : ZMod n).val := by rw [val_zero]
_ = (1 : ZMod n).val := congr_arg ZMod.val h
_ = 1 := val_one n
⟩⟩
instance nontrivial' : Nontrivial (ZMod 0) := by
delta ZMod; infer_instance
lemma one_eq_zero_iff {n : ℕ} : (1 : ZMod n) = 0 ↔ n = 1 := by
rw [← Nat.cast_one, natCast_zmod_eq_zero_iff_dvd, Nat.dvd_one]
/-- The inversion on `ZMod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : ∀ n : ℕ, ZMod n → ZMod n
| 0, i => Int.sign i
| n + 1, i => Nat.gcdA i.val (n + 1)
instance (n : ℕ) : Inv (ZMod n) :=
⟨inv n⟩
theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0
| 0 => Int.sign_zero
| n + 1 =>
show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by
rw [val_zero]
unfold Nat.gcdA Nat.xgcd Nat.xgcdAux
rfl
theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by
rcases n with - | n
· dsimp [ZMod] at a ⊢
calc
_ = a * Int.sign a := rfl
_ = a.natAbs := by rw [Int.mul_sign_self]
_ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right]
· calc
a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by
rw [natCast_self, zero_mul, add_zero]
_ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by
push_cast
rw [natCast_zmod_val]
rfl
_ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl
@[simp] protected lemma inv_one (n : ℕ) : (1⁻¹ : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 1
· exact Subsingleton.elim _ _
· simpa [ZMod.val_one'' hn] using mul_inv_eq_gcd (1 : ZMod n)
@[simp]
theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by
conv =>
rhs
rw [← Nat.mod_add_div a n]
simp
theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by
cases n
· simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero]
· rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast]
exact Iff.rfl
theorem eq_zero_iff_even {n : ℕ} : (n : ZMod 2) = 0 ↔ Even n :=
(CharP.cast_eq_zero_iff (ZMod 2) 2 n).trans even_iff_two_dvd.symm
theorem eq_one_iff_odd {n : ℕ} : (n : ZMod 2) = 1 ↔ Odd n := by
rw [← @Nat.cast_one (ZMod 2), ZMod.eq_iff_modEq_nat, Nat.odd_iff, Nat.ModEq]
theorem ne_zero_iff_odd {n : ℕ} : (n : ZMod 2) ≠ 0 ↔ Odd n := by
constructor <;>
· contrapose
simp [eq_zero_iff_even]
|
theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by
| Mathlib/Data/ZMod/Basic.lean | 750 | 752 |
/-
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, Yaël Dillies
-/
import Mathlib.Data.Set.Image
/-!
# Directed indexed families and sets
This file defines directed indexed families and directed sets. An indexed family/set is
directed iff each pair of elements has a shared upper bound.
## Main declarations
* `Directed r f`: Predicate stating that the indexed family `f` is `r`-directed.
* `DirectedOn r s`: Predicate stating that the set `s` is `r`-directed.
* `IsDirected α r`: Prop-valued mixin stating that `α` is `r`-directed. Follows the style of the
unbundled relation classes such as `IsTotal`.
## TODO
Define connected orders (the transitive symmetric closure of `≤` is everything) and show that
(co)directed orders are connected.
## References
* [Gierz et al, *A Compendium of Continuous Lattices*][GierzEtAl1980]
-/
open Function
universe u v w
variable {α : Type u} {β : Type v} {ι : Sort w} (r r' s : α → α → Prop)
/-- Local notation for a relation -/
local infixl:50 " ≼ " => r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def Directed (f : ι → α) :=
∀ x y, ∃ z, f x ≼ f z ∧ f y ≼ f z
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def DirectedOn (s : Set α) :=
∀ x ∈ s, ∀ y ∈ s, ∃ z ∈ s, x ≼ z ∧ y ≼ z
variable {r r'}
theorem directedOn_iff_directed {s} : @DirectedOn α r s ↔ Directed r (Subtype.val : s → α) := by
simp only [DirectedOn, Directed, Subtype.exists, exists_and_left, exists_prop, Subtype.forall]
exact forall₂_congr fun x _ => by simp [And.comm, and_assoc]
alias ⟨DirectedOn.directed_val, _⟩ := directedOn_iff_directed
theorem directedOn_range {f : ι → α} : Directed r f ↔ DirectedOn r (Set.range f) := by
simp_rw [Directed, DirectedOn, Set.forall_mem_range, Set.exists_range_iff]
protected alias ⟨Directed.directedOn_range, _⟩ := directedOn_range
theorem directedOn_image {s : Set β} {f : β → α} :
DirectedOn r (f '' s) ↔ DirectedOn (f ⁻¹'o r) s := by
simp only [DirectedOn, Set.mem_image, exists_exists_and_eq_and, forall_exists_index, and_imp,
| forall_apply_eq_imp_iff₂, Order.Preimage]
| Mathlib/Order/Directed.lean | 66 | 67 |
/-
Copyright (c) 2019 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.Ring.Finset
import Mathlib.Algebra.Order.AbsoluteValue.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.BigOperators.Ring.Multiset
import Mathlib.Tactic.Ring
/-!
# Big operators on a finset in ordered rings
This file contains the results concerning the interaction of finset big operators with ordered
rings.
In particular, this file contains the standard form of the Cauchy-Schwarz inequality, as well as
some of its immediate consequences.
-/
variable {ι R S : Type*}
namespace Finset
section CommMonoidWithZero
variable [CommMonoidWithZero R] [PartialOrder R] [ZeroLEOneClass R]
section PosMulMono
variable [PosMulMono R] {f g : ι → R} {s t : Finset ι}
lemma prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i ∈ s, f i :=
| prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0
/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the
product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for
the case of an ordered commutative multiplicative monoid. -/
@[gcongr]
lemma prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :
∏ i ∈ s, f i ≤ ∏ i ∈ s, g i := by
induction s using Finset.cons_induction with
| empty => simp
| cons a s has ih =>
simp only [prod_cons, forall_mem_cons] at h0 h1 ⊢
have := posMulMono_iff_mulPosMono.1 ‹PosMulMono R›
gcongr
| Mathlib/Algebra/Order/BigOperators/Ring/Finset.lean | 33 | 46 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.