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 Sebastian Monnet. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Monnet
-/
import Mathlib.FieldTheory.Galois.Basic
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.OpenSubgroup
import Mathlib.Tactic.ByContra
/-!
# Krull topology
We define the Krull topology on `L ≃ₐ[K] L` for an arbitrary field extension `L/K`. In order to do
this, we first define a `GroupFilterBasis` on `L ≃ₐ[K] L`, whose sets are `E.fixingSubgroup` for
all intermediate fields `E` with `E/K` finite dimensional.
## Main Definitions
- `finiteExts K L`. Given a field extension `L/K`, this is the set of intermediate fields that are
finite-dimensional over `K`.
- `fixedByFinite K L`. Given a field extension `L/K`, `fixedByFinite K L` is the set of
subsets `Gal(L/E)` of `Gal(L/K)`, where `E/K` is finite
- `galBasis K L`. Given a field extension `L/K`, this is the filter basis on `L ≃ₐ[K] L` whose
sets are `Gal(L/E)` for intermediate fields `E` with `E/K` finite.
- `galGroupBasis K L`. This is the same as `galBasis K L`, but with the added structure
that it is a group filter basis on `L ≃ₐ[K] L`, rather than just a filter basis.
- `krullTopology K L`. Given a field extension `L/K`, this is the topology on `L ≃ₐ[K] L`, induced
by the group filter basis `galGroupBasis K L`.
## Main Results
- `krullTopology_t2 K L`. For an integral field extension `L/K`, the topology `krullTopology K L`
is Hausdorff.
- `krullTopology_totallyDisconnected K L`. For an integral field extension `L/K`, the topology
`krullTopology K L` is totally disconnected.
- `IntermediateField.finrank_eq_fixingSubgroup_index`: given a Galois extension `K/k` and an
intermediate field `L`, the `[L : k]` as a natural number is equal to the index of the
fixing subgroup of `L`.
## Notations
- In docstrings, we will write `Gal(L/E)` to denote the fixing subgroup of an intermediate field
`E`. That is, `Gal(L/E)` is the subgroup of `L ≃ₐ[K] L` consisting of automorphisms that fix
every element of `E`. In particular, we distinguish between `L ≃ₐ[E] L` and `Gal(L/E)`, since the
former is defined to be a subgroup of `L ≃ₐ[K] L`, while the latter is a group in its own right.
## Implementation Notes
- `krullTopology K L` is defined as an instance for type class inference.
-/
open scoped Pointwise
/-- Mapping intermediate fields along the identity does not change them -/
theorem IntermediateField.map_id {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) : E.map (AlgHom.id K L) = E :=
SetLike.coe_injective <| Set.image_id _
/-- Mapping a finite dimensional intermediate field along an algebra equivalence gives
a finite-dimensional intermediate field. -/
instance im_finiteDimensional {K L : Type*} [Field K] [Field L] [Algebra K L]
{E : IntermediateField K L} (σ : L ≃ₐ[K] L) [FiniteDimensional K E] :
FiniteDimensional K (E.map σ.toAlgHom) :=
LinearEquiv.finiteDimensional (IntermediateField.intermediateFieldMap σ E).toLinearEquiv
/-- Given a field extension `L/K`, `finiteExts K L` is the set of
intermediate field extensions `L/E/K` such that `E/K` is finite -/
def finiteExts (K : Type*) [Field K] (L : Type*) [Field L] [Algebra K L] :
Set (IntermediateField K L) :=
{E | FiniteDimensional K E}
/-- Given a field extension `L/K`, `fixedByFinite K L` is the set of
subsets `Gal(L/E)` of `L ≃ₐ[K] L`, where `E/K` is finite -/
def fixedByFinite (K L : Type*) [Field K] [Field L] [Algebra K L] : Set (Subgroup (L ≃ₐ[K] L)) :=
IntermediateField.fixingSubgroup '' finiteExts K L
/-- For a field extension `L/K`, the intermediate field `K` is finite-dimensional over `K` -/
theorem IntermediateField.finiteDimensional_bot (K L : Type*) [Field K] [Field L] [Algebra K L] :
FiniteDimensional K (⊥ : IntermediateField K L) :=
.of_rank_eq_one IntermediateField.rank_bot
/-- This lemma says that `Gal(L/K) = L ≃ₐ[K] L` -/
theorem IntermediateField.fixingSubgroup.bot {K L : Type*} [Field K] [Field L] [Algebra K L] :
IntermediateField.fixingSubgroup (⊥ : IntermediateField K L) = ⊤ := by
ext f
refine ⟨fun _ => Subgroup.mem_top _, fun _ => ?_⟩
rintro ⟨x, hx : x ∈ (⊥ : IntermediateField K L)⟩
rw [IntermediateField.mem_bot] at hx
rcases hx with ⟨y, rfl⟩
exact f.commutes y
/-- If `L/K` is a field extension, then we have `Gal(L/K) ∈ fixedByFinite K L` -/
theorem top_fixedByFinite {K L : Type*} [Field K] [Field L] [Algebra K L] :
⊤ ∈ fixedByFinite K L :=
⟨⊥, IntermediateField.finiteDimensional_bot K L, IntermediateField.fixingSubgroup.bot⟩
/-- If `E1` and `E2` are finite-dimensional intermediate fields, then so is their compositum.
This rephrases a result already in mathlib so that it is compatible with our type classes -/
theorem finiteDimensional_sup {K L : Type*} [Field K] [Field L] [Algebra K L]
(E1 E2 : IntermediateField K L) (_ : FiniteDimensional K E1) (_ : FiniteDimensional K E2) :
FiniteDimensional K (↥(E1 ⊔ E2)) :=
IntermediateField.finiteDimensional_sup E1 E2
/-- An element of `L ≃ₐ[K] L` is in `Gal(L/E)` if and only if it fixes every element of `E`. -/
theorem IntermediateField.mem_fixingSubgroup_iff {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) (σ : L ≃ₐ[K] L) : σ ∈ E.fixingSubgroup ↔ ∀ x : L, x ∈ E → σ x = x :=
⟨fun hσ x hx => hσ ⟨x, hx⟩, fun h ⟨x, hx⟩ => h x hx⟩
/-- The map `E ↦ Gal(L/E)` is inclusion-reversing -/
theorem IntermediateField.fixingSubgroup.antimono {K L : Type*} [Field K] [Field L] [Algebra K L]
{E1 E2 : IntermediateField K L} (h12 : E1 ≤ E2) : E2.fixingSubgroup ≤ E1.fixingSubgroup := by
rintro σ hσ ⟨x, hx⟩
exact hσ ⟨x, h12 hx⟩
/-- Given a field extension `L/K`, `galBasis K L` is the filter basis on `L ≃ₐ[K] L` whose sets
are `Gal(L/E)` for intermediate fields `E` with `E/K` finite dimensional -/
def galBasis (K L : Type*) [Field K] [Field L] [Algebra K L] : FilterBasis (L ≃ₐ[K] L) where
sets := (fun g => g.carrier) '' fixedByFinite K L
nonempty := ⟨⊤, ⊤, top_fixedByFinite, rfl⟩
inter_sets := by
rintro X Y ⟨H1, ⟨E1, h_E1, rfl⟩, rfl⟩ ⟨H2, ⟨E2, h_E2, rfl⟩, rfl⟩
use (IntermediateField.fixingSubgroup (E1 ⊔ E2)).carrier
refine ⟨⟨_, ⟨_, finiteDimensional_sup E1 E2 h_E1 h_E2, rfl⟩, rfl⟩, ?_⟩
rw [Set.subset_inter_iff]
exact
⟨IntermediateField.fixingSubgroup.antimono le_sup_left,
IntermediateField.fixingSubgroup.antimono le_sup_right⟩
/-- A subset of `L ≃ₐ[K] L` is a member of `galBasis K L` if and only if it is the underlying set
of `Gal(L/E)` for some finite subextension `E/K`. -/
theorem mem_galBasis_iff (K L : Type*) [Field K] [Field L] [Algebra K L] (U : Set (L ≃ₐ[K] L)) :
U ∈ galBasis K L ↔ U ∈ (fun g => g.carrier) '' fixedByFinite K L :=
Iff.rfl
/-- For a field extension `L/K`, `galGroupBasis K L` is the group filter basis on `L ≃ₐ[K] L`
whose sets are `Gal(L/E)` for finite subextensions `E/K` -/
def galGroupBasis (K L : Type*) [Field K] [Field L] [Algebra K L] :
GroupFilterBasis (L ≃ₐ[K] L) where
toFilterBasis := galBasis K L
one' := fun ⟨H, _, h2⟩ => h2 ▸ H.one_mem
mul' {U} hU :=
⟨U, hU, by
rcases hU with ⟨H, _, rfl⟩
rintro x ⟨a, haH, b, hbH, rfl⟩
exact H.mul_mem haH hbH⟩
inv' {U} hU :=
⟨U, hU, by
rcases hU with ⟨H, _, rfl⟩
exact fun _ => H.inv_mem'⟩
conj' := by
rintro σ U ⟨H, ⟨E, hE, rfl⟩, rfl⟩
let F : IntermediateField K L := E.map σ.symm.toAlgHom
refine ⟨F.fixingSubgroup.carrier, ⟨⟨F.fixingSubgroup, ⟨F, ?_, rfl⟩, rfl⟩, fun g hg => ?_⟩⟩
· have : FiniteDimensional K E := hE
apply im_finiteDimensional σ.symm
change σ * g * σ⁻¹ ∈ E.fixingSubgroup
rw [IntermediateField.mem_fixingSubgroup_iff]
intro x hx
change σ (g (σ⁻¹ x)) = x
have h_in_F : σ⁻¹ x ∈ F := ⟨x, hx, by dsimp; rw [← AlgEquiv.invFun_eq_symm]; rfl⟩
have h_g_fix : g (σ⁻¹ x) = σ⁻¹ x := by
rw [Subgroup.mem_carrier, IntermediateField.mem_fixingSubgroup_iff F g] at hg
exact hg (σ⁻¹ x) h_in_F
rw [h_g_fix]
change σ (σ⁻¹ x) = x
exact AlgEquiv.apply_symm_apply σ x
/-- For a field extension `L/K`, `krullTopology K L` is the topological space structure on
`L ≃ₐ[K] L` induced by the group filter basis `galGroupBasis K L` -/
instance krullTopology (K L : Type*) [Field K] [Field L] [Algebra K L] :
TopologicalSpace (L ≃ₐ[K] L) :=
GroupFilterBasis.topology (galGroupBasis K L)
/-- For a field extension `L/K`, the Krull topology on `L ≃ₐ[K] L` makes it a topological group. -/
@[stacks 0BMJ "We define Krull topology directly without proving the universal property"]
instance (K L : Type*) [Field K] [Field L] [Algebra K L] : IsTopologicalGroup (L ≃ₐ[K] L) :=
GroupFilterBasis.isTopologicalGroup (galGroupBasis K L)
open scoped Topology in
lemma krullTopology_mem_nhds_one_iff (K L : Type*) [Field K] [Field L] [Algebra K L]
(s : Set (L ≃ₐ[K] L)) : s ∈ 𝓝 1 ↔ ∃ E : IntermediateField K L,
FiniteDimensional K E ∧ (E.fixingSubgroup : Set (L ≃ₐ[K] L)) ⊆ s := by
rw [GroupFilterBasis.nhds_one_eq]
constructor
· rintro ⟨-, ⟨-, ⟨E, fin, rfl⟩, rfl⟩, hE⟩
exact ⟨E, fin, hE⟩
· rintro ⟨E, fin, hE⟩
exact ⟨E.fixingSubgroup, ⟨E.fixingSubgroup, ⟨E, fin, rfl⟩, rfl⟩, hE⟩
open scoped Topology in
lemma krullTopology_mem_nhds_one_iff_of_normal (K L : Type*) [Field K] [Field L] [Algebra K L]
[Normal K L] (s : Set (L ≃ₐ[K] L)) : s ∈ 𝓝 1 ↔ ∃ E : IntermediateField K L,
FiniteDimensional K E ∧ Normal K E ∧ (E.fixingSubgroup : Set (L ≃ₐ[K] L)) ⊆ s := by
rw [krullTopology_mem_nhds_one_iff]
refine ⟨fun ⟨E, _, hE⟩ ↦ ?_, fun ⟨E, hE⟩ ↦ ⟨E, hE.1, hE.2.2⟩⟩
use (IntermediateField.normalClosure K E L)
simp only [normalClosure.is_finiteDimensional K E L, normalClosure.normal K E L, true_and]
exact le_trans (E.fixingSubgroup_anti E.le_normalClosure) hE
section KrullT2
open scoped Topology Filter
/-- Let `L/E/K` be a tower of fields with `E/K` finite. Then `Gal(L/E)` is an open subgroup of
`L ≃ₐ[K] L`. -/
theorem IntermediateField.fixingSubgroup_isOpen {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) [FiniteDimensional K E] :
IsOpen (E.fixingSubgroup : Set (L ≃ₐ[K] L)) := by
have h_basis : E.fixingSubgroup.carrier ∈ galGroupBasis K L :=
⟨E.fixingSubgroup, ⟨E, ‹_›, rfl⟩, rfl⟩
have h_nhd := GroupFilterBasis.mem_nhds_one (galGroupBasis K L) h_basis
exact Subgroup.isOpen_of_mem_nhds _ h_nhd
/-- Given a tower of fields `L/E/K`, with `E/K` finite, the subgroup `Gal(L/E) ≤ L ≃ₐ[K] L` is
closed. -/
theorem IntermediateField.fixingSubgroup_isClosed {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) [FiniteDimensional K E] :
IsClosed (E.fixingSubgroup : Set (L ≃ₐ[K] L)) :=
OpenSubgroup.isClosed ⟨E.fixingSubgroup, E.fixingSubgroup_isOpen⟩
/-- If `L/K` is an algebraic extension, then the Krull topology on `L ≃ₐ[K] L` is Hausdorff. -/
theorem krullTopology_t2 {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsIntegral K L] : T2Space (L ≃ₐ[K] L) :=
{ t2 := fun f g hfg => by
let φ := f⁻¹ * g
obtain ⟨x, hx⟩ := DFunLike.exists_ne hfg
have hφx : φ x ≠ x := by
apply ne_of_apply_ne f
change f (f.symm (g x)) ≠ f x
rw [AlgEquiv.apply_symm_apply f (g x), ne_comm]
exact hx
let E : IntermediateField K L := IntermediateField.adjoin K {x}
let h_findim : FiniteDimensional K E := IntermediateField.adjoin.finiteDimensional
(Algebra.IsIntegral.isIntegral x)
let H := E.fixingSubgroup
have h_basis : (H : Set (L ≃ₐ[K] L)) ∈ galGroupBasis K L := ⟨H, ⟨E, ⟨h_findim, rfl⟩⟩, rfl⟩
have h_nhd := GroupFilterBasis.mem_nhds_one (galGroupBasis K L) h_basis
rw [mem_nhds_iff] at h_nhd
rcases h_nhd with ⟨W, hWH, hW_open, hW_1⟩
refine ⟨f • W, g • W,
⟨hW_open.leftCoset f, hW_open.leftCoset g, ⟨1, hW_1, mul_one _⟩, ⟨1, hW_1, mul_one _⟩, ?_⟩⟩
rw [Set.disjoint_left]
rintro σ ⟨w1, hw1, h⟩ ⟨w2, hw2, rfl⟩
dsimp at h
rw [eq_inv_mul_iff_mul_eq.symm, ← mul_assoc, mul_inv_eq_iff_eq_mul.symm] at h
have h_in_H : w1 * w2⁻¹ ∈ H := H.mul_mem (hWH hw1) (H.inv_mem (hWH hw2))
rw [h] at h_in_H
change φ ∈ E.fixingSubgroup at h_in_H
rw [IntermediateField.mem_fixingSubgroup_iff] at h_in_H
specialize h_in_H x
have hxE : x ∈ E := by
apply IntermediateField.subset_adjoin
apply Set.mem_singleton
exact hφx (h_in_H hxE) }
|
end KrullT2
section TotallySeparated
instance {K L : Type*} [Field K] [Field L] [Algebra K L] [Algebra.IsIntegral K L] :
TotallySeparatedSpace (L ≃ₐ[K] L) := by
rw [totallySeparatedSpace_iff_exists_isClopen]
intro σ τ h_diff
have hστ : σ⁻¹ * τ ≠ 1 := by rwa [Ne, inv_mul_eq_one]
rcases DFunLike.exists_ne hστ with ⟨x, hx : (σ⁻¹ * τ) x ≠ x⟩
let E := IntermediateField.adjoin K ({x} : Set L)
haveI := IntermediateField.adjoin.finiteDimensional
(Algebra.IsIntegral.isIntegral (R := K) x)
refine ⟨σ • E.fixingSubgroup,
| Mathlib/FieldTheory/KrullTopology.lean | 262 | 276 |
/-
Copyright (c) 2023 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll, Ralf Stephan
-/
import Mathlib.Data.Nat.Factorization.Defs
import Mathlib.Data.Nat.Squarefree
/-!
# Smooth numbers
For `s : Finset ℕ` we define the set `Nat.factoredNumbers s` of "`s`-factored numbers"
consisting of the positive natural numbers all of whose prime factors are in `s`, and
we provide some API for this.
We then define the set `Nat.smoothNumbers n` consisting of the positive natural numbers all of
whose prime factors are strictly less than `n`. This is the special case `s = Finset.range n`
of the set of `s`-factored numbers.
We also define the finite set `Nat.primesBelow n` to be the set of prime numbers less than `n`.
The main definition `Nat.equivProdNatSmoothNumbers` establishes the bijection between
`ℕ × (smoothNumbers p)` and `smoothNumbers (p+1)` given by sending `(e, n)` to `p^e * n`.
Here `p` is a prime number. It is obtained from the more general bijection between
`ℕ × (factoredNumbers s)` and `factoredNumbers (s ∪ {p})`; see `Nat.equivProdNatFactoredNumbers`.
Additionally, we define `Nat.smoothNumbersUpTo N n` as the `Finset` of `n`-smooth numbers
up to and including `N`, and similarly `Nat.roughNumbersUpTo` for its complement in `{1, ..., N}`,
and we provide some API, in particular bounds for their cardinalities; see
`Nat.smoothNumbersUpTo_card_le` and `Nat.roughNumbersUpTo_card_le`.
-/
open scoped Finset
namespace Nat
/-- `primesBelow n` is the set of primes less than `n` as a `Finset`. -/
def primesBelow (n : ℕ) : Finset ℕ := {p ∈ Finset.range n | p.Prime}
@[simp]
lemma primesBelow_zero : primesBelow 0 = ∅ := by
rw [primesBelow, Finset.range_zero, Finset.filter_empty]
lemma mem_primesBelow {k n : ℕ} :
n ∈ primesBelow k ↔ n < k ∧ n.Prime := by simp [primesBelow]
lemma prime_of_mem_primesBelow {p n : ℕ} (h : p ∈ n.primesBelow) : p.Prime :=
(Finset.mem_filter.mp h).2
lemma lt_of_mem_primesBelow {p n : ℕ} (h : p ∈ n.primesBelow) : p < n :=
Finset.mem_range.mp <| Finset.mem_of_mem_filter p h
lemma primesBelow_succ (n : ℕ) :
primesBelow (n + 1) = if n.Prime then insert n (primesBelow n) else primesBelow n := by
rw [primesBelow, primesBelow, Finset.range_succ, Finset.filter_insert]
lemma not_mem_primesBelow (n : ℕ) : n ∉ primesBelow n :=
fun hn ↦ (lt_of_mem_primesBelow hn).false
/-!
### `s`-factored numbers
-/
/-- `factoredNumbers s`, for a finite set `s` of natural numbers, is the set of positive natural
numbers all of whose prime factors are in `s`. -/
def factoredNumbers (s : Finset ℕ) : Set ℕ := {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s}
lemma mem_factoredNumbers {s : Finset ℕ} {m : ℕ} :
m ∈ factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s :=
Iff.rfl
/-- Membership in `Nat.factoredNumbers n` is decidable. -/
instance (s : Finset ℕ) : DecidablePred (· ∈ factoredNumbers s) :=
inferInstanceAs <| DecidablePred fun x ↦ x ∈ {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s}
/-- A number that divides an `s`-factored number is itself `s`-factored. -/
lemma mem_factoredNumbers_of_dvd {s : Finset ℕ} {m k : ℕ} (h : m ∈ factoredNumbers s)
(h' : k ∣ m) :
k ∈ factoredNumbers s := by
obtain ⟨h₁, h₂⟩ := h
have hk := ne_zero_of_dvd_ne_zero h₁ h'
refine ⟨hk, fun p hp ↦ h₂ p ?_⟩
rw [mem_primeFactorsList <| by assumption] at hp ⊢
exact ⟨hp.1, hp.2.trans h'⟩
/-- `m` is `s`-factored if and only if `m` is nonzero and all prime divisors `≤ m` of `m`
are in `s`. -/
lemma mem_factoredNumbers_iff_forall_le {s : Finset ℕ} {m : ℕ} :
m ∈ factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ≤ m, p.Prime → p ∣ m → p ∈ s := by
simp_rw [mem_factoredNumbers, mem_primeFactorsList']
exact ⟨fun ⟨H₀, H₁⟩ ↦ ⟨H₀, fun p _ hp₂ hp₃ ↦ H₁ p ⟨hp₂, hp₃, H₀⟩⟩,
fun ⟨H₀, H₁⟩ ↦
⟨H₀, fun p ⟨hp₁, hp₂, hp₃⟩ ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero hp₃) hp₂) hp₁ hp₂⟩⟩
/-- `m` is `s`-factored if and only if all prime divisors of `m` are in `s`. -/
lemma mem_factoredNumbers' {s : Finset ℕ} {m : ℕ} :
m ∈ factoredNumbers s ↔ ∀ p, p.Prime → p ∣ m → p ∈ s := by
obtain ⟨p, hp₁, hp₂⟩ := exists_infinite_primes (1 + Finset.sup s id)
rw [mem_factoredNumbers_iff_forall_le]
refine ⟨fun ⟨H₀, H₁⟩ ↦ fun p hp₁ hp₂ ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero H₀) hp₂) hp₁ hp₂,
fun H ↦ ⟨fun h ↦ lt_irrefl p ?_, fun p _ ↦ H p⟩⟩
calc
p ≤ s.sup id := Finset.le_sup (f := @id ℕ) <| H p hp₂ <| h.symm ▸ dvd_zero p
_ < 1 + s.sup id := lt_one_add _
_ ≤ p := hp₁
lemma ne_zero_of_mem_factoredNumbers {s : Finset ℕ} {m : ℕ} (h : m ∈ factoredNumbers s) : m ≠ 0 :=
h.1
/-- The `Finset` of prime factors of an `s`-factored number is contained in `s`. -/
lemma primeFactors_subset_of_mem_factoredNumbers {s : Finset ℕ} {m : ℕ}
(hm : m ∈ factoredNumbers s) :
m.primeFactors ⊆ s := by
rw [mem_factoredNumbers] at hm
exact fun n hn ↦ hm.2 n (mem_primeFactors_iff_mem_primeFactorsList.mp hn)
/-- If `m ≠ 0` and the `Finset` of prime factors of `m` is contained in `s`, then `m`
is `s`-factored. -/
lemma mem_factoredNumbers_of_primeFactors_subset {s : Finset ℕ} {m : ℕ} (hm : m ≠ 0)
(hp : m.primeFactors ⊆ s) :
m ∈ factoredNumbers s := by
rw [mem_factoredNumbers]
exact ⟨hm, fun p hp' ↦ hp <| mem_primeFactors_iff_mem_primeFactorsList.mpr hp'⟩
/-- `m` is `s`-factored if and only if `m ≠ 0` and its `Finset` of prime factors
is contained in `s`. -/
lemma mem_factoredNumbers_iff_primeFactors_subset {s : Finset ℕ} {m : ℕ} :
m ∈ factoredNumbers s ↔ m ≠ 0 ∧ m.primeFactors ⊆ s :=
⟨fun h ↦ ⟨ne_zero_of_mem_factoredNumbers h, primeFactors_subset_of_mem_factoredNumbers h⟩,
fun ⟨h₁, h₂⟩ ↦ mem_factoredNumbers_of_primeFactors_subset h₁ h₂⟩
@[simp]
lemma factoredNumbers_empty : factoredNumbers ∅ = {1} := by
ext m
simp only [mem_factoredNumbers, Finset.not_mem_empty, ← List.eq_nil_iff_forall_not_mem,
primeFactorsList_eq_nil, and_or_left, not_and_self_iff, ne_and_eq_iff_right zero_ne_one,
false_or, Set.mem_singleton_iff]
/-- The product of two `s`-factored numbers is again `s`-factored. -/
lemma mul_mem_factoredNumbers {s : Finset ℕ} {m n : ℕ} (hm : m ∈ factoredNumbers s)
(hn : n ∈ factoredNumbers s) :
m * n ∈ factoredNumbers s := by
have hm' := primeFactors_subset_of_mem_factoredNumbers hm
have hn' := primeFactors_subset_of_mem_factoredNumbers hn
exact mem_factoredNumbers_of_primeFactors_subset (mul_ne_zero hm.1 hn.1)
<| primeFactors_mul hm.1 hn.1 ▸ Finset.union_subset hm' hn'
/-- The product of the prime factors of `n` that are in `s` is an `s`-factored number. -/
lemma prod_mem_factoredNumbers (s : Finset ℕ) (n : ℕ) :
(n.primeFactorsList.filter (· ∈ s)).prod ∈ factoredNumbers s := by
have h₀ : (n.primeFactorsList.filter (· ∈ s)).prod ≠ 0 :=
List.prod_ne_zero fun h ↦ (pos_of_mem_primeFactorsList (List.mem_of_mem_filter h)).false
refine ⟨h₀, fun p hp ↦ ?_⟩
obtain ⟨H₁, H₂⟩ := (mem_primeFactorsList h₀).mp hp
simpa only [decide_eq_true_eq] using List.of_mem_filter <| mem_list_primes_of_dvd_prod H₁.prime
(fun _ hq ↦ (prime_of_mem_primeFactorsList (List.mem_of_mem_filter hq)).prime) H₂
/-- The sets of `s`-factored and of `s ∪ {N}`-factored numbers are the same when `N` is not prime.
See `Nat.equivProdNatFactoredNumbers` for when `N` is prime. -/
lemma factoredNumbers_insert (s : Finset ℕ) {N : ℕ} (hN : ¬ N.Prime) :
factoredNumbers (insert N s) = factoredNumbers s := by
ext m
refine ⟨fun hm ↦ ⟨hm.1, fun p hp ↦ ?_⟩,
fun hm ↦ ⟨hm.1, fun p hp ↦ Finset.mem_insert_of_mem <| hm.2 p hp⟩⟩
exact Finset.mem_of_mem_insert_of_ne (hm.2 p hp)
fun h ↦ hN <| h ▸ prime_of_mem_primeFactorsList hp
@[gcongr] lemma factoredNumbers_mono {s t : Finset ℕ} (hst : s ≤ t) :
factoredNumbers s ⊆ factoredNumbers t :=
fun _ hx ↦ ⟨hx.1, fun p hp ↦ hst <| hx.2 p hp⟩
/-- The non-zero non-`s`-factored numbers are `≥ N` when `s` contains all primes less than `N`. -/
lemma factoredNumbers_compl {N : ℕ} {s : Finset ℕ} (h : primesBelow N ≤ s) :
(factoredNumbers s)ᶜ \ {0} ⊆ {n | N ≤ n} := by
intro n hn
simp only [Set.mem_compl_iff, mem_factoredNumbers, Set.mem_diff, ne_eq, not_and, not_forall,
not_lt, exists_prop, Set.mem_singleton_iff] at hn
simp only [Set.mem_setOf_eq]
obtain ⟨p, hp₁, hp₂⟩ := hn.1 hn.2
have : N ≤ p := by
contrapose! hp₂
exact h <| mem_primesBelow.mpr ⟨hp₂, prime_of_mem_primeFactorsList hp₁⟩
exact this.trans <| le_of_mem_primeFactorsList hp₁
/-- If `p` is a prime and `n` is `s`-factored, then every product `p^e * n`
is `s ∪ {p}`-factored. -/
lemma pow_mul_mem_factoredNumbers {s : Finset ℕ} {p n : ℕ} (hp : p.Prime) (e : ℕ)
(hn : n ∈ factoredNumbers s) :
p ^ e * n ∈ factoredNumbers (insert p s) := by
have hp' := pow_ne_zero e hp.ne_zero
refine ⟨mul_ne_zero hp' hn.1, fun q hq ↦ ?_⟩
rcases (mem_primeFactorsList_mul hp' hn.1).mp hq with H | H
· rw [mem_primeFactorsList hp'] at H
rw [(prime_dvd_prime_iff_eq H.1 hp).mp <| H.1.dvd_of_dvd_pow H.2]
exact Finset.mem_insert_self p s
· exact Finset.mem_insert_of_mem <| hn.2 _ H
/-- If `p ∉ s` is a prime and `n` is `s`-factored, then `p` and `n` are coprime. -/
lemma Prime.factoredNumbers_coprime {s : Finset ℕ} {p n : ℕ} (hp : p.Prime) (hs : p ∉ s)
(hn : n ∈ factoredNumbers s) :
Nat.Coprime p n := by
rw [hp.coprime_iff_not_dvd, ← mem_primeFactorsList_iff_dvd hn.1 hp]
exact fun H ↦ hs <| hn.2 p H
/-- If `f : ℕ → F` is multiplicative on coprime arguments, `p ∉ s` is a prime and `m`
is `s`-factored, then `f (p^e * m) = f (p^e) * f m`. -/
lemma factoredNumbers.map_prime_pow_mul {F : Type*} [Mul F] {f : ℕ → F}
(hmul : ∀ {m n}, Coprime m n → f (m * n) = f m * f n) {s : Finset ℕ} {p : ℕ}
(hp : p.Prime) (hs : p ∉ s) (e : ℕ) {m : factoredNumbers s} :
f (p ^ e * m) = f (p ^ e) * f m :=
hmul <| Coprime.pow_left _ <| hp.factoredNumbers_coprime hs <| Subtype.mem m
open List Perm in
/-- We establish the bijection from `ℕ × factoredNumbers s` to `factoredNumbers (s ∪ {p})`
given by `(e, n) ↦ p^e * n` when `p ∉ s` is a prime. See `Nat.factoredNumbers_insert` for
when `p` is not prime. -/
def equivProdNatFactoredNumbers {s : Finset ℕ} {p : ℕ} (hp : p.Prime) (hs : p ∉ s) :
ℕ × factoredNumbers s ≃ factoredNumbers (insert p s) where
toFun := fun ⟨e, n⟩ ↦ ⟨p ^ e * n, pow_mul_mem_factoredNumbers hp e n.2⟩
invFun := fun ⟨m, _⟩ ↦ (m.factorization p,
⟨(m.primeFactorsList.filter (· ∈ s)).prod, prod_mem_factoredNumbers ..⟩)
left_inv := by
rintro ⟨e, m, hm₀, hm⟩
simp (config := { etaStruct := .all }) only
[Set.coe_setOf, Set.mem_setOf_eq, Prod.mk.injEq, Subtype.mk.injEq]
constructor
· rw [factorization_mul (pos_iff_ne_zero.mp <| Nat.pow_pos hp.pos) hm₀]
simp only [factorization_pow, Finsupp.coe_add, Finsupp.coe_smul, nsmul_eq_mul,
Pi.natCast_def, cast_id, Pi.add_apply, Pi.mul_apply, hp.factorization_self,
mul_one, add_eq_left]
rw [← primeFactorsList_count_eq, count_eq_zero]
exact fun H ↦ hs (hm p H)
· nth_rewrite 2 [← prod_primeFactorsList hm₀]
refine prod_eq <|
(filter _ <| perm_primeFactorsList_mul (pow_ne_zero e hp.ne_zero) hm₀).trans ?_
rw [filter_append, hp.primeFactorsList_pow,
filter_eq_nil_iff.mpr fun q hq ↦ by rw [mem_replicate] at hq; simp [hq.2, hs],
nil_append, filter_eq_self.mpr fun q hq ↦ by simp only [hm q hq, decide_true]]
right_inv := by
rintro ⟨m, hm₀, hm⟩
simp only [Set.coe_setOf, Set.mem_setOf_eq, Subtype.mk.injEq]
rw [← primeFactorsList_count_eq, ← prod_replicate, ← prod_append]
nth_rewrite 3 [← prod_primeFactorsList hm₀]
have : m.primeFactorsList.filter (· = p) = m.primeFactorsList.filter (¬ · ∈ s) := by
refine (filter_congr fun q hq ↦ ?_).symm
simp only [decide_not, Bool.not_eq_true', decide_eq_false_iff_not, decide_eq_true_eq]
rcases Finset.mem_insert.mp <| hm _ hq with h | h
· simp only [h, hs, decide_false, Bool.not_false, decide_true]
· simp only [h, decide_true, Bool.not_true, false_eq_decide_iff]
exact fun H ↦ hs <| H ▸ h
refine prod_eq <| (filter_eq p).symm ▸ this ▸ perm_append_comm.trans ?_
simp only [decide_not]
exact filter_append_perm (· ∈ s) (primeFactorsList m)
@[simp]
lemma equivProdNatFactoredNumbers_apply {s : Finset ℕ} {p e m : ℕ} (hp : p.Prime) (hs : p ∉ s)
(hm : m ∈ factoredNumbers s) :
equivProdNatFactoredNumbers hp hs (e, ⟨m, hm⟩) = p ^ e * m := rfl
@[simp]
lemma equivProdNatFactoredNumbers_apply' {s : Finset ℕ} {p : ℕ} (hp : p.Prime) (hs : p ∉ s)
(x : ℕ × factoredNumbers s) :
equivProdNatFactoredNumbers hp hs x = p ^ x.1 * x.2 := rfl
/-!
### `n`-smooth numbers
-/
/-- `smoothNumbers n` is the set of *`n`-smooth positive natural numbers*, i.e., the
positive natural numbers all of whose prime factors are less than `n`. -/
def smoothNumbers (n : ℕ) : Set ℕ := {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p < n}
lemma mem_smoothNumbers {n m : ℕ} : m ∈ smoothNumbers n ↔ m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p < n :=
Iff.rfl
/-- The `n`-smooth numbers agree with the `Finset.range n`-factored numbers. -/
lemma smoothNumbers_eq_factoredNumbers (n : ℕ) :
smoothNumbers n = factoredNumbers (Finset.range n) := by
simp only [smoothNumbers, ne_eq, mem_primeFactorsList', and_imp, factoredNumbers,
Finset.mem_range]
/-- The `n`-smooth numbers agree with the `primesBelow n`-factored numbers. -/
lemma smmoothNumbers_eq_factoredNumbers_primesBelow (n : ℕ) :
smoothNumbers n = factoredNumbers n.primesBelow := by
rw [smoothNumbers_eq_factoredNumbers]
refine Set.Subset.antisymm (fun m hm ↦ ?_) <| factoredNumbers_mono Finset.mem_of_mem_filter
simp_rw [mem_factoredNumbers'] at hm ⊢
exact fun p hp hp' ↦ mem_primesBelow.mpr ⟨Finset.mem_range.mp <| hm p hp hp', hp⟩
/-- Membership in `Nat.smoothNumbers n` is decidable. -/
instance (n : ℕ) : DecidablePred (· ∈ smoothNumbers n) :=
inferInstanceAs <| DecidablePred fun x ↦ x ∈ {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p < n}
/-- A number that divides an `n`-smooth number is itself `n`-smooth. -/
lemma mem_smoothNumbers_of_dvd {n m k : ℕ} (h : m ∈ smoothNumbers n) (h' : k ∣ m) :
k ∈ smoothNumbers n := by
simp only [smoothNumbers_eq_factoredNumbers] at h ⊢
exact mem_factoredNumbers_of_dvd h h'
/-- `m` is `n`-smooth if and only if `m` is nonzero and all prime divisors `≤ m` of `m`
are less than `n`. -/
lemma mem_smoothNumbers_iff_forall_le {n m : ℕ} :
m ∈ smoothNumbers n ↔ m ≠ 0 ∧ ∀ p ≤ m, p.Prime → p ∣ m → p < n := by
simp only [smoothNumbers_eq_factoredNumbers, mem_factoredNumbers_iff_forall_le, Finset.mem_range]
/-- `m` is `n`-smooth if and only if all prime divisors of `m` are less than `n`. -/
lemma mem_smoothNumbers' {n m : ℕ} : m ∈ smoothNumbers n ↔ ∀ p, p.Prime → p ∣ m → p < n := by
simp only [smoothNumbers_eq_factoredNumbers, mem_factoredNumbers', Finset.mem_range]
/-- The `Finset` of prime factors of an `n`-smooth number is contained in the `Finset`
of primes below `n`. -/
lemma primeFactors_subset_of_mem_smoothNumbers {m n : ℕ} (hms : m ∈ n.smoothNumbers) :
m.primeFactors ⊆ n.primesBelow :=
primeFactors_subset_of_mem_factoredNumbers <|
smmoothNumbers_eq_factoredNumbers_primesBelow n ▸ hms
/-- `m` is an `n`-smooth number if the `Finset` of its prime factors consists of numbers `< n`. -/
lemma mem_smoothNumbers_of_primeFactors_subset {m n : ℕ} (hm : m ≠ 0)
(hp : m.primeFactors ⊆ Finset.range n) : m ∈ n.smoothNumbers :=
smoothNumbers_eq_factoredNumbers n ▸ mem_factoredNumbers_of_primeFactors_subset hm hp
/-- `m` is an `n`-smooth number if and only if `m ≠ 0` and the `Finset` of its prime factors
is contained in the `Finset` of primes below `n` -/
lemma mem_smoothNumbers_iff_primeFactors_subset {m n : ℕ} :
m ∈ n.smoothNumbers ↔ m ≠ 0 ∧ m.primeFactors ⊆ n.primesBelow :=
⟨fun h ↦ ⟨h.1, primeFactors_subset_of_mem_smoothNumbers h⟩,
fun h ↦ mem_smoothNumbers_of_primeFactors_subset h.1 <| h.2.trans <| Finset.filter_subset ..⟩
/-- Zero is never a smooth number -/
lemma ne_zero_of_mem_smoothNumbers {n m : ℕ} (h : m ∈ smoothNumbers n) : m ≠ 0 := h.1
@[simp]
lemma smoothNumbers_zero : smoothNumbers 0 = {1} := by
simp only [smoothNumbers_eq_factoredNumbers, Finset.range_zero, factoredNumbers_empty]
/-- The product of two `n`-smooth numbers is an `n`-smooth number. -/
theorem mul_mem_smoothNumbers {m₁ m₂ n : ℕ}
(hm1 : m₁ ∈ n.smoothNumbers) (hm2 : m₂ ∈ n.smoothNumbers) : m₁ * m₂ ∈ n.smoothNumbers := by
rw [smoothNumbers_eq_factoredNumbers] at hm1 hm2 ⊢
exact mul_mem_factoredNumbers hm1 hm2
/-- The product of the prime factors of `n` that are less than `N` is an `N`-smooth number. -/
lemma prod_mem_smoothNumbers (n N : ℕ) :
(n.primeFactorsList.filter (· < N)).prod ∈ smoothNumbers N := by
simp only [smoothNumbers_eq_factoredNumbers, ← Finset.mem_range, prod_mem_factoredNumbers]
/-- The sets of `N`-smooth and of `(N+1)`-smooth numbers are the same when `N` is not prime.
See `Nat.equivProdNatSmoothNumbers` for when `N` is prime. -/
lemma smoothNumbers_succ {N : ℕ} (hN : ¬ N.Prime) : (N + 1).smoothNumbers = N.smoothNumbers := by
simp only [smoothNumbers_eq_factoredNumbers, Finset.range_succ, factoredNumbers_insert _ hN]
@[simp] lemma smoothNumbers_one : smoothNumbers 1 = {1} := by
simp +decide only [not_false_eq_true, smoothNumbers_succ, smoothNumbers_zero]
@[gcongr] lemma smoothNumbers_mono {N M : ℕ} (hNM : N ≤ M) : N.smoothNumbers ⊆ M.smoothNumbers :=
fun _ hx ↦ ⟨hx.1, fun p hp => (hx.2 p hp).trans_le hNM⟩
/-- All `m`, `0 < m < n` are `n`-smooth numbers -/
lemma mem_smoothNumbers_of_lt {m n : ℕ} (hm : 0 < m) (hmn : m < n) : m ∈ n.smoothNumbers :=
smoothNumbers_eq_factoredNumbers _ ▸ ⟨ne_zero_of_lt hm,
fun _ h => Finset.mem_range.mpr <| lt_of_le_of_lt (le_of_mem_primeFactorsList h) hmn⟩
/-- The non-zero non-`N`-smooth numbers are `≥ N`. -/
| lemma smoothNumbers_compl (N : ℕ) : (N.smoothNumbers)ᶜ \ {0} ⊆ {n | N ≤ n} := by
simpa only [smoothNumbers_eq_factoredNumbers]
using factoredNumbers_compl <| Finset.filter_subset _ (Finset.range N)
/-- If `p` is positive and `n` is `p`-smooth, then every product `p^e * n` is `(p+1)`-smooth. -/
lemma pow_mul_mem_smoothNumbers {p n : ℕ} (hp : p ≠ 0) (e : ℕ) (hn : n ∈ smoothNumbers p) :
p ^ e * n ∈ smoothNumbers (succ p) := by
-- This cannot be easily reduced to `pow_mul_mem_factoredNumbers`, as there `p.Prime` is needed.
have : NoZeroDivisors ℕ := inferInstance -- this is needed twice --> speed-up
have hp' := pow_ne_zero e hp
refine ⟨mul_ne_zero hp' hn.1, fun q hq ↦ ?_⟩
| Mathlib/NumberTheory/SmoothNumbers.lean | 365 | 375 |
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Johan Commelin
-/
import Mathlib.Algebra.GCDMonoid.IntegrallyClosed
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed
import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots
import Mathlib.RingTheory.UniqueFactorizationDomain.Nat
/-!
# Minimal polynomial of roots of unity
We gather several results about minimal polynomial of root of unity.
## Main results
* `IsPrimitiveRoot.totient_le_degree_minpoly`: The degree of the minimal polynomial of an `n`-th
primitive root of unity is at least `totient n`.
-/
open minpoly Polynomial
open scoped Polynomial
namespace IsPrimitiveRoot
section CommRing
variable {n : ℕ} {K : Type*} [CommRing K] {μ : K} (h : IsPrimitiveRoot μ n)
include h
/-- `μ` is integral over `ℤ`. -/
-- Porting note: `hpos` was in the `variable` line, with an `omit` in mathlib3 just after this
-- declaration. For some reason, in Lean4, `hpos` gets included also in the declarations below,
-- even if it is not used in the proof.
theorem isIntegral (hpos : 0 < n) : IsIntegral ℤ μ := by
use X ^ n - 1
constructor
· exact monic_X_pow_sub_C 1 (ne_of_lt hpos).symm
· simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, eval₂_one, eval₂_X_pow, eval₂_sub,
sub_self]
section IsDomain
variable [IsDomain K] [CharZero K]
/-- The minimal polynomial of a root of unity `μ` divides `X ^ n - 1`. -/
theorem minpoly_dvd_x_pow_sub_one : minpoly ℤ μ ∣ X ^ n - 1 := by
rcases n.eq_zero_or_pos with (rfl | h0)
· simp
apply minpoly.isIntegrallyClosed_dvd (isIntegral h h0)
simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, aeval_X_pow, eq_intCast, Int.cast_one,
aeval_one, map_sub, sub_self]
/-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is separable. -/
theorem separable_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
Separable (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) := by
have hdvd : map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣ X ^ n - 1 := by
convert RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p)))
(minpoly_dvd_x_pow_sub_one h)
simp only [map_sub, map_pow, coe_mapRingHom, map_X, map_one]
refine Separable.of_dvd (separable_X_pow_sub_C 1 ?_ one_ne_zero) hdvd
by_contra hzero
exact hdiv ((ZMod.natCast_zmod_eq_zero_iff_dvd n p).1 hzero)
/-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is squarefree. -/
theorem squarefree_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
Squarefree (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) :=
(separable_minpoly_mod h hdiv).squarefree
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a natural number that does not divide `n`. Then `P` divides `expand ℤ p Q`. -/
theorem minpoly_dvd_expand {p : ℕ} (hdiv : ¬p ∣ n) :
minpoly ℤ μ ∣ expand ℤ p (minpoly ℤ (μ ^ p)) := by
rcases n.eq_zero_or_pos with (rfl | hpos)
· simp_all
letI : IsIntegrallyClosed ℤ := GCDMonoid.toIsIntegrallyClosed
refine minpoly.isIntegrallyClosed_dvd (h.isIntegral hpos) ?_
rw [aeval_def, coe_expand, ← comp, eval₂_eq_eval_map, map_comp, Polynomial.map_pow, map_X,
eval_comp, eval_pow, eval_X, ← eval₂_eq_eval_map, ← aeval_def]
exact minpoly.aeval _ _
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q ^ p` modulo `p`. -/
theorem minpoly_dvd_pow_mod {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) :
map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣
map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) ^ p := by
set Q := minpoly ℤ (μ ^ p)
have hfrob :
map (Int.castRingHom (ZMod p)) Q ^ p = map (Int.castRingHom (ZMod p)) (expand ℤ p Q) := by
rw [← ZMod.expand_card, map_expand]
rw [hfrob]
apply RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p)))
exact minpoly_dvd_expand h hdiv
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q` modulo `p`. -/
theorem minpoly_dvd_mod_p {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣
map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) :=
(squarefree_minpoly_mod h hdiv).isRadical _ _ (minpoly_dvd_pow_mod h hdiv)
/-- If `p` is a prime that does not divide `n`,
then the minimal polynomials of a primitive `n`-th root of unity `μ`
and of `μ ^ p` are the same. -/
theorem minpoly_eq_pow {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) :
minpoly ℤ μ = minpoly ℤ (μ ^ p) := by
classical
by_cases hn : n = 0
· simp_all
have hpos := Nat.pos_of_ne_zero hn
by_contra hdiff
set P := minpoly ℤ μ
set Q := minpoly ℤ (μ ^ p)
have Pmonic : P.Monic := minpoly.monic (h.isIntegral hpos)
have Qmonic : Q.Monic := minpoly.monic ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos)
have Pirr : Irreducible P := minpoly.irreducible (h.isIntegral hpos)
have Qirr : Irreducible Q := minpoly.irreducible ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos)
have PQprim : IsPrimitive (P * Q) := Pmonic.isPrimitive.mul Qmonic.isPrimitive
have prod : P * Q ∣ X ^ n - 1 := by
rw [IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast (P * Q) (X ^ n - 1) PQprim
(monic_X_pow_sub_C (1 : ℤ) (ne_of_gt hpos)).isPrimitive,
Polynomial.map_mul]
refine IsCoprime.mul_dvd ?_ ?_ ?_
· have aux := IsPrimitive.Int.irreducible_iff_irreducible_map_cast Pmonic.isPrimitive
refine (dvd_or_isCoprime _ _ (aux.1 Pirr)).resolve_left ?_
rw [map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic]
intro hdiv
refine hdiff (eq_of_monic_of_associated Pmonic Qmonic ?_)
exact associated_of_dvd_dvd hdiv (Pirr.dvd_symm Qirr hdiv)
· apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic).2
exact minpoly_dvd_x_pow_sub_one h
· apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Qmonic).2
exact minpoly_dvd_x_pow_sub_one (pow_of_prime h hprime.1 hdiv)
replace prod := RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p))) prod
rw [coe_mapRingHom, Polynomial.map_mul, Polynomial.map_sub, Polynomial.map_one,
Polynomial.map_pow, map_X] at prod
obtain ⟨R, hR⟩ := minpoly_dvd_mod_p h hdiv
rw [hR, ← mul_assoc, ← Polynomial.map_mul, ← sq, Polynomial.map_pow] at prod
have habs : map (Int.castRingHom (ZMod p)) P ^ 2 ∣ map (Int.castRingHom (ZMod p)) P ^ 2 * R := by
use R
replace habs :=
lt_of_lt_of_le (Nat.cast_lt.2 one_lt_two)
(le_emultiplicity_of_pow_dvd (dvd_trans habs prod))
have hfree : Squarefree (X ^ n - 1 : (ZMod p)[X]) :=
(separable_X_pow_sub_C 1 (fun h => hdiv <| (ZMod.natCast_zmod_eq_zero_iff_dvd n p).1 h)
one_ne_zero).squarefree
rcases (squarefree_iff_emultiplicity_le_one (X ^ n - 1)).1 hfree
(map (Int.castRingHom (ZMod p)) P) with hle | hunit
· rw [Nat.cast_one] at habs; exact hle.not_lt habs
· replace hunit := degree_eq_zero_of_isUnit hunit
rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom (ZMod p)) _] at hunit
· exact (minpoly.degree_pos (isIntegral h hpos)).ne' hunit
simp only [Pmonic, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff,
one_ne_zero]
/-- If `m : ℕ` is coprime with `n`,
then the minimal polynomials of a primitive `n`-th root of unity `μ`
and of `μ ^ m` are the same. -/
theorem minpoly_eq_pow_coprime {m : ℕ} (hcop : Nat.Coprime m n) :
minpoly ℤ μ = minpoly ℤ (μ ^ m) := by
revert n hcop
refine UniqueFactorizationMonoid.induction_on_prime m ?_ ?_ ?_
· intro h hn
congr
simpa [(Nat.coprime_zero_left _).mp hn] using h
· intro u hunit _ _
congr
simp [Nat.isUnit_iff.mp hunit]
· intro a p _ hprime
intro hind h hcop
rw [hind h (Nat.Coprime.coprime_mul_left hcop)]; clear hind
replace hprime := hprime.nat_prime
have hdiv := (Nat.Prime.coprime_iff_not_dvd hprime).1 (Nat.Coprime.coprime_mul_right hcop)
haveI := Fact.mk hprime
rw [minpoly_eq_pow (h.pow_of_coprime a (Nat.Coprime.coprime_mul_left hcop)) hdiv]
congr 1
ring
/-- If `m : ℕ` is coprime with `n`,
then the minimal polynomial of a primitive `n`-th root of unity `μ`
has `μ ^ m` as root. -/
theorem pow_isRoot_minpoly {m : ℕ} (hcop : Nat.Coprime m n) :
IsRoot (map (Int.castRingHom K) (minpoly ℤ μ)) (μ ^ m) := by
simp only [minpoly_eq_pow_coprime h hcop, IsRoot.def, eval_map]
exact minpoly.aeval ℤ (μ ^ m)
/-- `primitiveRoots n K` is a subset of the roots of the minimal polynomial of a primitive
`n`-th root of unity `μ`. -/
theorem is_roots_of_minpoly [DecidableEq K] :
primitiveRoots n K ⊆ (map (Int.castRingHom K) (minpoly ℤ μ)).roots.toFinset := by
by_cases hn : n = 0; · simp_all
have : NeZero n := ⟨hn⟩
have hpos := Nat.pos_of_ne_zero hn
intro x hx
obtain ⟨m, _, hcop, rfl⟩ := (isPrimitiveRoot_iff h).1 ((mem_primitiveRoots hpos).1 hx)
simp only [Multiset.mem_toFinset, mem_roots]
convert pow_isRoot_minpoly h hcop using 0
rw [← mem_roots]
exact map_monic_ne_zero <| minpoly.monic <| isIntegral h hpos
/-- The degree of the minimal polynomial of `μ` is at least `totient n`. -/
theorem totient_le_degree_minpoly : Nat.totient n ≤ (minpoly ℤ μ).natDegree := by
classical
let P : ℤ[X] := minpoly ℤ μ
-- minimal polynomial of `μ`
let P_K : K[X] := map (Int.castRingHom K) P
-- minimal polynomial of `μ` sent to `K[X]`
calc
n.totient = (primitiveRoots n K).card := h.card_primitiveRoots.symm
_ ≤ P_K.roots.toFinset.card := Finset.card_le_card (is_roots_of_minpoly h)
_ ≤ Multiset.card P_K.roots := Multiset.toFinset_card_le _
_ ≤ P_K.natDegree := card_roots' _
_ ≤ P.natDegree := natDegree_map_le
| end IsDomain
end CommRing
end IsPrimitiveRoot
| Mathlib/RingTheory/RootsOfUnity/Minpoly.lean | 220 | 231 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Action.Prod
import Mathlib.Algebra.Group.Subgroup.Map
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
import Mathlib.Data.Finite.Sigma
import Mathlib.Data.Set.Finite.Range
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Defs
/-!
# Basic properties of group actions
This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of
actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation
of `•` belong elsewhere.
## Main definitions
* `MulAction.orbit`
* `MulAction.fixedPoints`
* `MulAction.fixedBy`
* `MulAction.stabilizer`
-/
universe u v
open Pointwise
open Function
namespace MulAction
variable (M : Type u) [Monoid M] (α : Type v) [MulAction M α] {β : Type*} [MulAction M β]
section Orbit
variable {α M}
@[to_additive]
lemma fst_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) :
x.1 ∈ MulAction.orbit M y.1 := by
rcases h with ⟨g, rfl⟩
exact mem_orbit _ _
@[to_additive]
lemma snd_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) :
x.2 ∈ MulAction.orbit M y.2 := by
rcases h with ⟨g, rfl⟩
exact mem_orbit _ _
@[to_additive]
lemma _root_.Finite.finite_mulAction_orbit [Finite M] (a : α) : Set.Finite (orbit M a) :=
Set.finite_range _
variable (M)
@[to_additive]
theorem orbit_eq_univ [IsPretransitive M α] (a : α) : orbit M a = Set.univ :=
(surjective_smul M a).range_eq
end Orbit
section FixedPoints
variable {M α}
@[to_additive (attr := simp)]
theorem subsingleton_orbit_iff_mem_fixedPoints {a : α} :
(orbit M a).Subsingleton ↔ a ∈ fixedPoints M α := by
rw [mem_fixedPoints]
constructor
· exact fun h m ↦ h (mem_orbit a m) (mem_orbit_self a)
· rintro h _ ⟨m, rfl⟩ y ⟨p, rfl⟩
simp only [h]
@[to_additive mem_fixedPoints_iff_card_orbit_eq_one]
theorem mem_fixedPoints_iff_card_orbit_eq_one {a : α} [Fintype (orbit M a)] :
a ∈ fixedPoints M α ↔ Fintype.card (orbit M a) = 1 := by
simp only [← subsingleton_orbit_iff_mem_fixedPoints, le_antisymm_iff,
Fintype.card_le_one_iff_subsingleton, Nat.add_one_le_iff, Fintype.card_pos_iff,
Set.subsingleton_coe, iff_self_and, Set.nonempty_coe_sort, orbit_nonempty, implies_true]
@[to_additive instDecidablePredMemSetFixedByAddOfDecidableEq]
instance (m : M) [DecidableEq β] :
DecidablePred fun b : β => b ∈ MulAction.fixedBy β m := fun b ↦ by
simp only [MulAction.mem_fixedBy, Equiv.Perm.smul_def]
infer_instance
end FixedPoints
end MulAction
/-- `smul` by a `k : M` over a group is injective, if `k` is not a zero divisor.
The general theory of such `k` is elaborated by `IsSMulRegular`.
The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/
theorem smul_cancel_of_non_zero_divisor {M G : Type*} [Monoid M] [AddGroup G]
[DistribMulAction M G] (k : M) (h : ∀ x : G, k • x = 0 → x = 0) {a b : G} (h' : k • a = k • b) :
a = b := by
rw [← sub_eq_zero]
refine h _ ?_
rw [smul_sub, h', sub_self]
namespace MulAction
variable {G α β : Type*} [Group G] [MulAction G α] [MulAction G β]
@[to_additive] theorem fixedPoints_of_subsingleton [Subsingleton α] :
fixedPoints G α = .univ := by
apply Set.eq_univ_of_forall
simp only [mem_fixedPoints]
intro x hx
apply Subsingleton.elim ..
/-- If a group acts nontrivially, then the type is nontrivial -/
@[to_additive "If a subgroup acts nontrivially, then the type is nontrivial."]
theorem nontrivial_of_fixedPoints_ne_univ (h : fixedPoints G α ≠ .univ) :
Nontrivial α :=
(subsingleton_or_nontrivial α).resolve_left fun _ ↦ h fixedPoints_of_subsingleton
section Orbit
-- TODO: This proof is redoing a special case of `MulAction.IsInvariantBlock.isBlock`. Can we move
-- this lemma earlier to golf?
@[to_additive (attr := simp)]
theorem smul_orbit (g : G) (a : α) : g • orbit G a = orbit G a :=
(smul_orbit_subset g a).antisymm <|
calc
orbit G a = g • g⁻¹ • orbit G a := (smul_inv_smul _ _).symm
_ ⊆ g • orbit G a := Set.image_subset _ (smul_orbit_subset _ _)
/-- The action of a group on an orbit is transitive. -/
@[to_additive "The action of an additive group on an orbit is transitive."]
instance (a : α) : IsPretransitive G (orbit G a) :=
⟨by
rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩
use h * g⁻¹
ext1
simp [mul_smul]⟩
@[to_additive]
lemma orbitRel_subgroup_le (H : Subgroup G) : orbitRel H α ≤ orbitRel G α :=
Setoid.le_def.2 mem_orbit_of_mem_orbit_subgroup
@[to_additive]
lemma orbitRel_subgroupOf (H K : Subgroup G) :
orbitRel (H.subgroupOf K) α = orbitRel (H ⊓ K : Subgroup G) α := by
rw [← Subgroup.subgroupOf_map_subtype]
ext x
simp_rw [orbitRel_apply]
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases h with ⟨⟨gv, gp⟩, rfl⟩
simp only [Submonoid.mk_smul]
refine mem_orbit _ (⟨gv, ?_⟩ : Subgroup.map K.subtype (H.subgroupOf K))
simpa using gp
· rcases h with ⟨⟨gv, gp⟩, rfl⟩
simp only [Submonoid.mk_smul]
simp only [Subgroup.subgroupOf_map_subtype, Subgroup.mem_inf] at gp
refine mem_orbit _ (⟨⟨gv, ?_⟩, ?_⟩ : H.subgroupOf K)
· exact gp.2
· simp only [Subgroup.mem_subgroupOf]
exact gp.1
variable (G α)
/-- An action is pretransitive if and only if the quotient by `MulAction.orbitRel` is a
subsingleton. -/
@[to_additive "An additive action is pretransitive if and only if the quotient by
`AddAction.orbitRel` is a subsingleton."]
theorem pretransitive_iff_subsingleton_quotient :
IsPretransitive G α ↔ Subsingleton (orbitRel.Quotient G α) := by
refine ⟨fun _ ↦ ⟨fun a b ↦ ?_⟩, fun _ ↦ ⟨fun a b ↦ ?_⟩⟩
· refine Quot.inductionOn a (fun x ↦ ?_)
exact Quot.inductionOn b (fun y ↦ Quot.sound <| exists_smul_eq G y x)
· have h : Quotient.mk (orbitRel G α) b = ⟦a⟧ := Subsingleton.elim _ _
exact Quotient.eq''.mp h
/-- If `α` is non-empty, an action is pretransitive if and only if the quotient has exactly one
element. -/
@[to_additive "If `α` is non-empty, an additive action is pretransitive if and only if the
quotient has exactly one element."]
theorem pretransitive_iff_unique_quotient_of_nonempty [Nonempty α] :
IsPretransitive G α ↔ Nonempty (Unique <| orbitRel.Quotient G α) := by
rw [unique_iff_subsingleton_and_nonempty, pretransitive_iff_subsingleton_quotient, iff_self_and]
exact fun _ ↦ (nonempty_quotient_iff _).mpr inferInstance
variable {G α}
@[to_additive]
instance (x : orbitRel.Quotient G α) : IsPretransitive G x.orbit where
exists_smul_eq := by
induction x using Quotient.inductionOn'
rintro ⟨y, yh⟩ ⟨z, zh⟩
rw [orbitRel.Quotient.mem_orbit, Quotient.eq''] at yh zh
rcases yh with ⟨g, rfl⟩
rcases zh with ⟨h, rfl⟩
refine ⟨h * g⁻¹, ?_⟩
ext
simp [mul_smul]
variable (G) (α)
local notation "Ω" => orbitRel.Quotient G α
@[to_additive]
lemma _root_.Finite.of_finite_mulAction_orbitRel_quotient [Finite G] [Finite Ω] : Finite α := by
rw [(selfEquivSigmaOrbits' G _).finite_iff]
have : ∀ g : Ω, Finite g.orbit := by
intro g
induction g using Quotient.inductionOn'
simpa [Set.finite_coe_iff] using Finite.finite_mulAction_orbit _
exact Finite.instSigma
variable (β)
@[to_additive]
lemma orbitRel_le_fst :
orbitRel G (α × β) ≤ (orbitRel G α).comap Prod.fst :=
Setoid.le_def.2 fst_mem_orbit_of_mem_orbit
@[to_additive]
lemma orbitRel_le_snd :
orbitRel G (α × β) ≤ (orbitRel G β).comap Prod.snd :=
Setoid.le_def.2 snd_mem_orbit_of_mem_orbit
end Orbit
section Stabilizer
variable (G)
variable {G}
/-- If the stabilizer of `a` is `S`, then the stabilizer of `g • a` is `gSg⁻¹`. -/
theorem stabilizer_smul_eq_stabilizer_map_conj (g : G) (a : α) :
stabilizer G (g • a) = (stabilizer G a).map (MulAut.conj g).toMonoidHom := by
ext h
rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul,
inv_mul_cancel, one_smul, ← mem_stabilizer_iff, Subgroup.mem_map_equiv, MulAut.conj_symm_apply]
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) :
stabilizer G a ≃* stabilizer G b :=
let g : G := Classical.choose h
have hg : g • b = a := Classical.choose_spec h
have this : stabilizer G a = (stabilizer G b).map (MulAut.conj g).toMonoidHom := by
rw [← hg, stabilizer_smul_eq_stabilizer_map_conj]
(MulEquiv.subgroupCongr this).trans ((MulAut.conj g).subgroupMap <| stabilizer G b).symm
end Stabilizer
end MulAction
namespace AddAction
variable {G α : Type*} [AddGroup G] [AddAction G α]
/-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/
theorem stabilizer_vadd_eq_stabilizer_map_conj (g : G) (a : α) :
stabilizer G (g +ᵥ a) = (stabilizer G a).map (AddAut.conj g).toMul.toAddMonoidHom := by
ext h
rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g), vadd_vadd, vadd_vadd, vadd_vadd,
neg_add_cancel, zero_vadd, ← mem_stabilizer_iff, AddSubgroup.mem_map_equiv,
AddAut.conj_symm_apply]
/-- A bijection between the stabilizers of two elements in the same orbit. -/
noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) :
stabilizer G a ≃+ stabilizer G b :=
let g : G := Classical.choose h
have hg : g +ᵥ b = a := Classical.choose_spec h
have this : stabilizer G a = (stabilizer G b).map (AddAut.conj g).toMul.toAddMonoidHom := by
rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj]
(AddEquiv.addSubgroupCongr this).trans ((AddAut.conj g).addSubgroupMap <| stabilizer G b).symm
end AddAction
attribute [to_additive existing] MulAction.stabilizer_smul_eq_stabilizer_map_conj
attribute [to_additive existing] MulAction.stabilizerEquivStabilizerOfOrbitRel
theorem Equiv.swap_mem_stabilizer {α : Type*} [DecidableEq α] {S : Set α} {a b : α} :
Equiv.swap a b ∈ MulAction.stabilizer (Equiv.Perm α) S ↔ (a ∈ S ↔ b ∈ S) := by
rw [MulAction.mem_stabilizer_iff, Set.ext_iff, ← swap_inv]
simp_rw [Set.mem_inv_smul_set_iff, Perm.smul_def, swap_apply_def]
exact ⟨fun h ↦ by simpa [Iff.comm] using h a, by intros; split_ifs <;> simp [*]⟩
namespace MulAction
variable {G : Type*} [Group G] {α : Type*} [MulAction G α]
/-- To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions. -/
@[to_additive
"To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions."]
theorem le_stabilizer_iff_smul_le (s : Set α) (H : Subgroup G) :
H ≤ stabilizer G s ↔ ∀ g ∈ H, g • s ⊆ s := by
constructor
· intro hyp g hg
apply Eq.subset
rw [← mem_stabilizer_iff]
exact hyp hg
· intro hyp g hg
rw [mem_stabilizer_iff]
apply subset_antisymm (hyp g hg)
intro x hx
use g⁻¹ • x
constructor
· apply hyp g⁻¹ (inv_mem hg)
simp only [Set.smul_mem_smul_set_iff, hx]
· simp only [smul_inv_smul]
end MulAction
section
variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]
variable {M} in
lemma Module.stabilizer_units_eq_bot_of_ne_zero {x : M} (hx : x ≠ 0) :
MulAction.stabilizer Rˣ x = ⊥ := by
rw [eq_bot_iff]
intro g (hg : g.val • x = x)
ext
rw [← sub_eq_zero, ← smul_eq_zero_iff_left hx, Units.val_one, sub_smul, hg, one_smul, sub_self]
end
| Mathlib/GroupTheory/GroupAction/Basic.lean | 733 | 737 | |
/-
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, Sophie Morel, Yury Kudryashov
-/
import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace
import Mathlib.Logic.Embedding.Basic
import Mathlib.Data.Fintype.CardEmbedding
import Mathlib.Topology.Algebra.Module.Multilinear.Topology
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `‖f‖` as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `‖f m‖ ≤ C * ∏ i, ‖m i‖` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mkContinuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `‖f‖` is its norm, i.e., the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for
all `m`.
* `le_opNorm f m` asserts the fundamental inequality `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖`.
* `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of
`‖f‖` and `‖m₁ - m₂‖`.
## Implementation notes
We mostly follow the API (and the proofs) of `OperatorNorm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `Fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
suppress_compilation
noncomputable section
open scoped NNReal Topology Uniformity
open Finset Metric Function Filter
/-!
### Type variables
We use the following type variables in this file:
* `𝕜` : a `NontriviallyNormedField`;
* `ι`, `ι'` : finite index types with decidable equality;
* `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`;
* `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`;
* `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : Fin (Nat.succ n)`;
* `G`, `G'` : normed vector spaces over `𝕜`.
-/
universe u v v' wE wE₁ wE' wG wG'
section continuous_eval
variable {𝕜 ι : Type*} {E : ι → Type*} {F : Type*}
[NormedField 𝕜] [Finite ι] [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
[TopologicalSpace F] [AddCommGroup F] [IsTopologicalAddGroup F] [Module 𝕜 F]
instance ContinuousMultilinearMap.instContinuousEval :
ContinuousEval (ContinuousMultilinearMap 𝕜 E F) (Π i, E i) F where
continuous_eval := by
cases nonempty_fintype ι
let _ := IsTopologicalAddGroup.toUniformSpace F
have := isUniformAddGroup_of_addCommGroup (G := F)
refine (UniformOnFun.continuousOn_eval₂ fun m ↦ ?_).comp_continuous
(isEmbedding_toUniformOnFun.continuous.prodMap continuous_id) fun (f, x) ↦ f.cont.continuousAt
exact ⟨ball m 1, NormedSpace.isVonNBounded_of_isBounded _ isBounded_ball,
ball_mem_nhds _ one_pos⟩
namespace ContinuousLinearMap
variable {G : Type*} [AddCommGroup G] [TopologicalSpace G] [Module 𝕜 G] [ContinuousConstSMul 𝕜 F]
lemma continuous_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) :
Continuous (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) := by
fun_prop
lemma continuousOn_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {s} :
ContinuousOn (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) s :=
f.continuous_uncurry_of_multilinear.continuousOn
lemma continuousAt_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {x} :
ContinuousAt (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) x :=
f.continuous_uncurry_of_multilinear.continuousAt
lemma continuousWithinAt_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {s x} :
ContinuousWithinAt (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) s x :=
f.continuous_uncurry_of_multilinear.continuousWithinAt
end ContinuousLinearMap
end continuous_eval
section Seminorm
variable {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {E : ι → Type wE} {E₁ : ι → Type wE₁}
{E' : ι' → Type wE'} {G : Type wG} {G' : Type wG'}
[Fintype ι'] [NontriviallyNormedField 𝕜] [∀ i, SeminormedAddCommGroup (E i)]
[∀ i, NormedSpace 𝕜 (E i)] [∀ i, SeminormedAddCommGroup (E₁ i)] [∀ i, NormedSpace 𝕜 (E₁ i)]
[SeminormedAddCommGroup G] [NormedSpace 𝕜 G] [SeminormedAddCommGroup G'] [NormedSpace 𝕜 G']
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, in
both directions. Along the way, we prove useful bounds on the difference `‖f m₁ - f m₂‖`.
-/
namespace MultilinearMap
/-- If `f` is a continuous multilinear map on `E`
and `m` is an element of `∀ i, E i` such that one of the `m i` has norm `0`,
then `f m` has norm `0`.
Note that we cannot drop the continuity assumption because `f (m : Unit → E) = f (m ())`,
where the domain has zero norm and the codomain has a nonzero norm
does not satisfy this condition. -/
lemma norm_map_coord_zero (f : MultilinearMap 𝕜 E G) (hf : Continuous f)
{m : ∀ i, E i} {i : ι} (hi : ‖m i‖ = 0) : ‖f m‖ = 0 := by
classical
rw [← inseparable_zero_iff_norm] at hi ⊢
have : Inseparable (update m i 0) m := inseparable_pi.2 <|
(forall_update_iff m fun i a ↦ Inseparable a (m i)).2 ⟨hi.symm, fun _ _ ↦ rfl⟩
simpa only [map_update_zero] using this.symm.map hf
variable [Fintype ι]
/-- If a multilinear map in finitely many variables on seminormed spaces
sends vectors with a component of norm zero to vectors of norm zero
and satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i`
for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`,
then it satisfies this inequality for all `m`.
The first assumption is automatically satisfied on normed spaces, see `bound_of_shell` below.
For seminormed spaces, it follows from continuity of `f`, see next lemma,
see `bound_of_shell_of_continuous` below. -/
theorem bound_of_shell_of_norm_map_coord_zero (f : MultilinearMap 𝕜 E G)
(hf₀ : ∀ {m i}, ‖m i‖ = 0 → ‖f m‖ = 0)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
rcases em (∃ i, ‖m i‖ = 0) with (⟨i, hi⟩ | hm)
· rw [hf₀ hi, prod_eq_zero (mem_univ i) hi, mul_zero]
push_neg at hm
choose δ hδ0 hδm_lt hle_δm _ using fun i => rescale_to_shell_semi_normed (hc i) (hε i) (hm i)
have hδ0 : 0 < ∏ i, ‖δ i‖ := prod_pos fun i _ => norm_pos_iff.2 (hδ0 i)
simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hδ0] using
hf (fun i => δ i • m i) hle_δm hδm_lt
/-- If a continuous multilinear map in finitely many variables on normed spaces satisfies
the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive
numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. -/
theorem bound_of_shell_of_continuous (f : MultilinearMap 𝕜 E G) (hfc : Continuous f)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
bound_of_shell_of_norm_map_coord_zero f (norm_map_coord_zero f hfc) hε hc hf m
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (f : MultilinearMap 𝕜 E G) (hf : Continuous f) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
cases isEmpty_or_nonempty ι
· refine ⟨‖f 0‖ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, fun m => ?_⟩
obtain rfl : m = 0 := funext (IsEmpty.elim ‹_›)
simp [univ_eq_empty, zero_le_one]
obtain ⟨ε : ℝ, ε0 : 0 < ε, hε : ∀ m : ∀ i, E i, ‖m - 0‖ < ε → ‖f m - f 0‖ < 1⟩ :=
NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one
simp only [sub_zero, f.map_zero] at hε
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
have : 0 < (‖c‖ / ε) ^ Fintype.card ι := pow_pos (div_pos (zero_lt_one.trans hc) ε0) _
refine ⟨_, this, ?_⟩
refine f.bound_of_shell_of_continuous hf (fun _ => ε0) (fun _ => hc) fun m hcm hm => ?_
refine (hε m ((pi_norm_lt_iff ε0).2 hm)).le.trans ?_
rw [← div_le_iff₀' this, one_div, ← inv_pow, inv_div, Fintype.card, ← prod_const]
exact prod_le_prod (fun _ _ => div_nonneg ε0.le (norm_nonneg _)) fun i _ => hcm i
/-- If a multilinear map `f` satisfies a boundedness property around `0`,
one can deduce a bound on `f m₁ - f m₂` using the multilinearity.
Here, we give a precise but hard to use version.
See `norm_image_sub_le_of_bound` for a less precise but more usable version.
The bound reads
`‖f m - f m'‖ ≤
C * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le_of_bound' [DecidableEq ι] (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A :
∀ s : Finset ι,
‖f m₁ - f (s.piecewise m₂ m₁)‖ ≤
C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
intro s
induction' s using Finset.induction with i s his Hrec
· simp
have I :
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ ≤
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A : (insert i s).piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₂ i) :=
s.piecewise_insert _ _ _
have B : s.piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₁ i) := by
simp [eq_update_iff, his]
rw [B, A, ← f.map_update_sub]
apply le_trans (H _)
gcongr with j
by_cases h : j = i
· rw [h]
simp
· by_cases h' : j ∈ s <;> simp [h', h, le_refl]
calc
‖f m₁ - f ((insert i s).piecewise m₂ m₁)‖ ≤
‖f m₁ - f (s.piecewise m₂ m₁)‖ +
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ := by
rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm]
exact dist_triangle _ _ _
_ ≤ (C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) +
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
(add_le_add Hrec I)
_ = C * ∑ i ∈ insert i s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
simp [his, add_comm, left_distrib]
convert A univ
simp
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`‖f m - f m'‖ ≤ C * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le_of_bound (f : MultilinearMap 𝕜 E G)
{C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
classical
have A :
∀ i : ι,
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
intro i
calc
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
∏ j : ι, Function.update (fun _ => max ‖m₁‖ ‖m₂‖) i ‖m₁ - m₂‖ j := by
apply Finset.prod_le_prod
· intro j _
by_cases h : j = i <;> simp [h, norm_nonneg]
· intro j _
by_cases h : j = i
· rw [h]
simp only [ite_true, Function.update_self]
exact norm_le_pi_norm (m₁ - m₂) i
· simp [h, - le_sup_iff, - sup_le_iff, sup_le_sup, norm_le_pi_norm]
_ = ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
rw [prod_update_of_mem (Finset.mem_univ _)]
simp [card_univ_diff]
calc
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.norm_image_sub_le_of_bound' hC H m₁ m₂
_ ≤ C * ∑ _i, ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by gcongr; apply A
_ = C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
rw [sum_const, card_univ, nsmul_eq_mul]
ring
/-- If a multilinear map satisfies an inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, then it is
continuous. -/
theorem continuous_of_bound (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
Continuous f := by
let D := max C 1
have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _)
replace H (m) : ‖f m‖ ≤ D * ∏ i, ‖m i‖ :=
(H m).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity)
refine continuous_iff_continuousAt.2 fun m => ?_
refine
continuousAt_of_locally_lipschitz zero_lt_one
(D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1)) fun m' h' => ?_
rw [dist_eq_norm, dist_eq_norm]
have : max ‖m'‖ ‖m‖ ≤ ‖m‖ + 1 := by
simp [zero_le_one, norm_le_of_mem_closedBall (le_of_lt h')]
calc
‖f m' - f m‖ ≤ D * Fintype.card ι * max ‖m'‖ ‖m‖ ^ (Fintype.card ι - 1) * ‖m' - m‖ :=
f.norm_image_sub_le_of_bound D_pos H m' m
_ ≤ D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1) * ‖m' - m‖ := by gcongr
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mkContinuous (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
ContinuousMultilinearMap 𝕜 E G :=
{ f with cont := f.continuous_of_bound C H }
@[simp]
theorem coe_mkContinuous (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
⇑(f.mkContinuous C H) = f :=
rfl
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`‖f.restr v‖ ≤ C * ‖z‖^(n-k) * Π ‖v i‖` if the original function satisfies `‖f v‖ ≤ C * Π ‖v i‖`. -/
theorem restr_norm_le {k n : ℕ} (f : MultilinearMap 𝕜 (fun _ : Fin n => G) G')
(s : Finset (Fin n)) (hk : #s = k) (z : G) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(v : Fin k → G) : ‖f.restr s hk z v‖ ≤ C * ‖z‖ ^ (n - k) * ∏ i, ‖v i‖ := by
rw [mul_right_comm, mul_assoc]
convert H _ using 2
simp only [apply_dite norm, Fintype.prod_dite, prod_const ‖z‖, Finset.card_univ,
Fintype.card_of_subtype sᶜ fun _ => mem_compl, card_compl, Fintype.card_fin, hk, mk_coe, ←
(s.orderIsoOfFin hk).symm.bijective.prod_comp fun x => ‖v x‖]
convert rfl
end MultilinearMap
/-!
### Continuous multilinear maps
We define the norm `‖f‖` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that this
defines a normed space structure on `ContinuousMultilinearMap 𝕜 E G`.
-/
namespace ContinuousMultilinearMap
variable [Fintype ι]
theorem bound (f : ContinuousMultilinearMap 𝕜 E G) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
f.toMultilinearMap.exists_bound_of_continuous f.2
open Real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def opNorm (f : ContinuousMultilinearMap 𝕜 E G) : ℝ :=
sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ }
instance hasOpNorm : Norm (ContinuousMultilinearMap 𝕜 E G) :=
⟨opNorm⟩
/-- An alias of `ContinuousMultilinearMap.hasOpNorm` with non-dependent types to help typeclass
search. -/
instance hasOpNorm' : Norm (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.hasOpNorm
theorem norm_def (f : ContinuousMultilinearMap 𝕜 E G) :
‖f‖ = sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
rfl
-- So that invocations of `le_csInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty {f : ContinuousMultilinearMap 𝕜 E G} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
theorem bounds_bddBelow {f : ContinuousMultilinearMap 𝕜 E G} :
BddBelow { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
theorem isLeast_opNorm (f : ContinuousMultilinearMap 𝕜 E G) :
IsLeast {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} ‖f‖ := by
refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow
simp only [Set.setOf_and, Set.setOf_forall]
exact isClosed_Ici.inter (isClosed_iInter fun m ↦
isClosed_le continuous_const (continuous_id.mul continuous_const))
theorem opNorm_nonneg (f : ContinuousMultilinearMap 𝕜 E G) : 0 ≤ ‖f‖ :=
Real.sInf_nonneg fun _ ⟨hx, _⟩ => hx
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`. -/
theorem le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖ :=
f.isLeast_opNorm.1.2 m
theorem le_mul_prod_of_opNorm_le_of_le {f : ContinuousMultilinearMap 𝕜 E G}
{m : ∀ i, E i} {C : ℝ} {b : ι → ℝ} (hC : ‖f‖ ≤ C) (hm : ∀ i, ‖m i‖ ≤ b i) :
‖f m‖ ≤ C * ∏ i, b i :=
(f.le_opNorm m).trans <| by gcongr; exacts [f.opNorm_nonneg.trans hC, hm _]
@[deprecated (since := "2024-11-27")]
alias le_mul_prod_of_le_opNorm_of_le := le_mul_prod_of_opNorm_le_of_le
theorem le_opNorm_mul_prod_of_le (f : ContinuousMultilinearMap 𝕜 E G)
{m : ∀ i, E i} {b : ι → ℝ} (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ ‖f‖ * ∏ i, b i :=
le_mul_prod_of_opNorm_le_of_le le_rfl hm
theorem le_opNorm_mul_pow_card_of_le (f : ContinuousMultilinearMap 𝕜 E G) {m b} (hm : ‖m‖ ≤ b) :
‖f m‖ ≤ ‖f‖ * b ^ Fintype.card ι := by
simpa only [prod_const] using f.le_opNorm_mul_prod_of_le fun i => (norm_le_pi_norm m i).trans hm
theorem le_opNorm_mul_pow_of_le {n : ℕ} {Ei : Fin n → Type*} [∀ i, SeminormedAddCommGroup (Ei i)]
[∀ i, NormedSpace 𝕜 (Ei i)] (f : ContinuousMultilinearMap 𝕜 Ei G) {m : ∀ i, Ei i} {b : ℝ}
(hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ n := by
simpa only [Fintype.card_fin] using f.le_opNorm_mul_pow_card_of_le hm
theorem le_of_opNorm_le {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ} (h : ‖f‖ ≤ C) (m : ∀ i, E i) :
‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
le_mul_prod_of_opNorm_le_of_le h fun _ ↦ le_rfl
theorem ratio_le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
(‖f m‖ / ∏ i, ‖m i‖) ≤ ‖f‖ :=
div_le_of_le_mul₀ (by positivity) (opNorm_nonneg _) (f.le_opNorm m)
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
theorem unit_le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) {m : ∀ i, E i} (h : ‖m‖ ≤ 1) :
‖f m‖ ≤ ‖f‖ :=
(le_opNorm_mul_pow_card_of_le f h).trans <| by simp
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
theorem opNorm_le_bound {f : ContinuousMultilinearMap 𝕜 E G}
{M : ℝ} (hMp : 0 ≤ M) (hM : ∀ m, ‖f m‖ ≤ M * ∏ i, ‖m i‖) : ‖f‖ ≤ M :=
csInf_le bounds_bddBelow ⟨hMp, hM⟩
theorem opNorm_le_iff {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ} (hC : 0 ≤ C) :
‖f‖ ≤ C ↔ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
⟨fun h _ ↦ le_of_opNorm_le h _, opNorm_le_bound hC⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem opNorm_add_le (f g : ContinuousMultilinearMap 𝕜 E G) : ‖f + g‖ ≤ ‖f‖ + ‖g‖ :=
opNorm_le_bound (add_nonneg (opNorm_nonneg f) (opNorm_nonneg g)) fun x => by
rw [add_mul]
exact norm_add_le_of_le (le_opNorm _ _) (le_opNorm _ _)
theorem opNorm_zero : ‖(0 : ContinuousMultilinearMap 𝕜 E G)‖ = 0 :=
(opNorm_nonneg _).antisymm' <| opNorm_le_bound le_rfl fun m => by simp
section
variable {𝕜' : Type*} [NormedField 𝕜'] [NormedSpace 𝕜' G] [SMulCommClass 𝕜 𝕜' G]
theorem opNorm_smul_le (c : 𝕜') (f : ContinuousMultilinearMap 𝕜 E G) : ‖c • f‖ ≤ ‖c‖ * ‖f‖ :=
(c • f).opNorm_le_bound (mul_nonneg (norm_nonneg _) (opNorm_nonneg _)) fun m ↦ by
rw [smul_apply, norm_smul, mul_assoc]
exact mul_le_mul_of_nonneg_left (le_opNorm _ _) (norm_nonneg _)
variable (𝕜 E G) in
/-- Operator seminorm on the space of continuous multilinear maps, as `Seminorm`.
We use this seminorm
to define a `SeminormedAddCommGroup` structure on `ContinuousMultilinearMap 𝕜 E G`,
but we have to override the projection `UniformSpace`
so that it is definitionally equal to the one coming from the topologies on `E` and `G`. -/
protected def seminorm : Seminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G) :=
.ofSMulLE norm opNorm_zero opNorm_add_le fun c f ↦ f.opNorm_smul_le c
private lemma uniformity_eq_seminorm :
𝓤 (ContinuousMultilinearMap 𝕜 E G) = ⨅ r > 0, 𝓟 {f | ‖f.1 - f.2‖ < r} := by
refine (ContinuousMultilinearMap.seminorm 𝕜 E G).uniformity_eq_of_hasBasis
(ContinuousMultilinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall)
?_ fun (s, r) ⟨hs, hr⟩ ↦ ?_
· rcases NormedField.exists_lt_norm 𝕜 1 with ⟨c, hc⟩
have hc₀ : 0 < ‖c‖ := one_pos.trans hc
simp only [hasBasis_nhds_zero.mem_iff, Prod.exists]
use 1, closedBall 0 ‖c‖, closedBall 0 1
suffices ∀ f : ContinuousMultilinearMap 𝕜 E G, (∀ x, ‖x‖ ≤ ‖c‖ → ‖f x‖ ≤ 1) → ‖f‖ ≤ 1 by
simpa [NormedSpace.isVonNBounded_closedBall, closedBall_mem_nhds, Set.subset_def, Set.MapsTo]
intro f hf
refine opNorm_le_bound (by positivity) <|
f.1.bound_of_shell_of_continuous f.2 (fun _ ↦ hc₀) (fun _ ↦ hc) fun x hcx hx ↦ ?_
calc
‖f x‖ ≤ 1 := hf _ <| (pi_norm_le_iff_of_nonneg (norm_nonneg c)).2 fun i ↦ (hx i).le
_ = ∏ i : ι, 1 := by simp
_ ≤ ∏ i, ‖x i‖ := Finset.prod_le_prod (fun _ _ ↦ zero_le_one) fun i _ ↦ by
simpa only [div_self hc₀.ne'] using hcx i
_ = 1 * ∏ i, ‖x i‖ := (one_mul _).symm
· rcases (NormedSpace.isVonNBounded_iff' _).1 hs with ⟨ε, hε⟩
rcases exists_pos_mul_lt hr (ε ^ Fintype.card ι) with ⟨δ, hδ₀, hδ⟩
refine ⟨δ, hδ₀, fun f hf x hx ↦ ?_⟩
simp only [Seminorm.mem_ball_zero, mem_closedBall_zero_iff] at hf ⊢
replace hf : ‖f‖ ≤ δ := hf.le
replace hx : ‖x‖ ≤ ε := hε x hx
calc
‖f x‖ ≤ ‖f‖ * ε ^ Fintype.card ι := le_opNorm_mul_pow_card_of_le f hx
_ ≤ δ * ε ^ Fintype.card ι := by have := (norm_nonneg x).trans hx; gcongr
_ ≤ r := (mul_comm _ _).trans_le hδ.le
instance instPseudoMetricSpace : PseudoMetricSpace (ContinuousMultilinearMap 𝕜 E G) :=
.replaceUniformity
(ContinuousMultilinearMap.seminorm 𝕜 E G).toSeminormedAddCommGroup.toPseudoMetricSpace
uniformity_eq_seminorm
/-- Continuous multilinear maps themselves form a seminormed space with respect to
the operator norm. -/
instance seminormedAddCommGroup :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 E G) := ⟨fun _ _ ↦ rfl⟩
/-- An alias of `ContinuousMultilinearMap.seminormedAddCommGroup` with non-dependent types to help
typeclass search. -/
instance seminormedAddCommGroup' :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.seminormedAddCommGroup
instance normedSpace : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 E G) :=
⟨fun c f => f.opNorm_smul_le c⟩
/-- An alias of `ContinuousMultilinearMap.normedSpace` with non-dependent types to help typeclass
search. -/
instance normedSpace' : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 (fun _ : ι => G') G) :=
ContinuousMultilinearMap.normedSpace
@[deprecated norm_neg (since := "2024-11-24")]
theorem opNorm_neg (f : ContinuousMultilinearMap 𝕜 E G) : ‖-f‖ = ‖f‖ := norm_neg f
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`, `nnnorm` version. -/
theorem le_opNNNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
‖f m‖₊ ≤ ‖f‖₊ * ∏ i, ‖m i‖₊ :=
NNReal.coe_le_coe.1 <| by
push_cast
exact f.le_opNorm m
theorem le_of_opNNNorm_le (f : ContinuousMultilinearMap 𝕜 E G)
{C : ℝ≥0} (h : ‖f‖₊ ≤ C) (m : ∀ i, E i) : ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ :=
(f.le_opNNNorm m).trans <| mul_le_mul' h le_rfl
theorem opNNNorm_le_iff {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ≥0} :
‖f‖₊ ≤ C ↔ ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := by
simp only [← NNReal.coe_le_coe]; simp [opNorm_le_iff C.coe_nonneg, NNReal.coe_prod]
theorem isLeast_opNNNorm (f : ContinuousMultilinearMap 𝕜 E G) :
IsLeast {C : ℝ≥0 | ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊} ‖f‖₊ := by
simpa only [← opNNNorm_le_iff] using isLeast_Ici
theorem opNNNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖₊ = max ‖f‖₊ ‖g‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by
simp only [opNNNorm_le_iff, prod_apply, Prod.nnnorm_def, max_le_iff, forall_and]
theorem opNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖ = max ‖f‖ ‖g‖ :=
congr_arg NNReal.toReal (opNNNorm_prod f g)
theorem opNNNorm_pi
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) : ‖pi f‖₊ = ‖f‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by simpa [opNNNorm_le_iff, pi_nnnorm_le_iff] using forall_swap
theorem opNorm_pi {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'}
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) :
‖pi f‖ = ‖f‖ :=
| congr_arg NNReal.toReal (opNNNorm_pi f)
| Mathlib/Analysis/NormedSpace/Multilinear/Basic.lean | 550 | 551 |
/-
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
| Mathlib/GroupTheory/FreeGroup/Basic.lean | 672 | 674 |
/-
Copyright (c) 2021 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson, Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Finset.Order
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Data.Set.Finite.Range
import Mathlib.Order.Atoms
import Mathlib.Order.Minimal
/-!
# Order structures on finite types
This file provides order instances on fintypes.
## Computable instances
On a `Fintype`, we can construct
* an `OrderBot` from `SemilatticeInf`.
* an `OrderTop` from `SemilatticeSup`.
* a `BoundedOrder` from `Lattice`.
Those are marked as `def` to avoid defeqness issues.
## Completion instances
Those instances are noncomputable because the definitions of `sSup` and `sInf` use `Set.toFinset`
and set membership is undecidable in general.
On a `Fintype`, we can promote:
* a `Lattice` to a `CompleteLattice`.
* a `DistribLattice` to a `CompleteDistribLattice`.
* a `LinearOrder` to a `CompleteLinearOrder`.
* a `BooleanAlgebra` to a `CompleteAtomicBooleanAlgebra`.
Those are marked as `def` to avoid typeclass loops.
## Concrete instances
We provide a few instances for concrete types:
* `Fin.completeLinearOrder`
* `Bool.completeLinearOrder`
* `Bool.completeBooleanAlgebra`
-/
open Finset
namespace Fintype
variable {ι α : Type*} [Fintype ι] [Fintype α]
section Nonempty
variable (α) [Nonempty α]
-- See note [reducible non-instances]
/-- Constructs the `⊥` of a finite nonempty `SemilatticeInf`. -/
abbrev toOrderBot [SemilatticeInf α] : OrderBot α where
bot := univ.inf' univ_nonempty id
bot_le a := inf'_le _ <| mem_univ a
-- See note [reducible non-instances]
/-- Constructs the `⊤` of a finite nonempty `SemilatticeSup` -/
abbrev toOrderTop [SemilatticeSup α] : OrderTop α where
top := univ.sup' univ_nonempty id
le_top a := le_sup' id <| mem_univ a
-- See note [reducible non-instances]
/-- Constructs the `⊤` and `⊥` of a finite nonempty `Lattice`. -/
abbrev toBoundedOrder [Lattice α] : BoundedOrder α :=
{ toOrderBot α, toOrderTop α with }
end Nonempty
section BoundedOrder
variable (α)
open scoped Classical in
-- See note [reducible non-instances]
/-- A finite bounded lattice is complete. -/
noncomputable abbrev toCompleteLattice [Lattice α] [BoundedOrder α] : CompleteLattice α where
__ := ‹Lattice α›
__ := ‹BoundedOrder α›
sSup := fun s => s.toFinset.sup id
sInf := fun s => s.toFinset.inf id
le_sSup := fun _ _ ha => Finset.le_sup (f := id) (Set.mem_toFinset.mpr ha)
sSup_le := fun _ _ ha => Finset.sup_le fun _ hb => ha _ <| Set.mem_toFinset.mp hb
sInf_le := fun _ _ ha => Finset.inf_le (Set.mem_toFinset.mpr ha)
le_sInf := fun _ _ ha => Finset.le_inf fun _ hb => ha _ <| Set.mem_toFinset.mp hb
-- See note [reducible non-instances]
/-- A finite bounded distributive lattice is completely distributive. -/
noncomputable abbrev toCompleteDistribLatticeMinimalAxioms [DistribLattice α] [BoundedOrder α] :
CompleteDistribLattice.MinimalAxioms α where
__ := toCompleteLattice α
iInf_sup_le_sup_sInf := fun a s => by
convert (Finset.inf_sup_distrib_left s.toFinset id a).ge using 1
rw [Finset.inf_eq_iInf]
simp_rw [Set.mem_toFinset]
rfl
inf_sSup_le_iSup_inf := fun a s => by
convert (Finset.sup_inf_distrib_left s.toFinset id a).le using 1
rw [Finset.sup_eq_iSup]
simp_rw [Set.mem_toFinset]
rfl
-- See note [reducible non-instances]
/-- A finite bounded distributive lattice is completely distributive. -/
noncomputable abbrev toCompleteDistribLattice [DistribLattice α] [BoundedOrder α] :
CompleteDistribLattice α := .ofMinimalAxioms (toCompleteDistribLatticeMinimalAxioms _)
-- See note [reducible non-instances]
/-- A finite bounded linear order is complete.
If the `α` is already a `BiheytingAlgebra`, then prefer to construct this instance manually using
`Fintype.toCompleteLattice` instead, to avoid creating a diamond with
`LinearOrder.toBiheytingAlgebra`. -/
noncomputable abbrev toCompleteLinearOrder
[LinearOrder α] [BoundedOrder α] : CompleteLinearOrder α :=
{ toCompleteLattice α, ‹LinearOrder α›, LinearOrder.toBiheytingAlgebra with }
-- See note [reducible non-instances]
/-- A finite boolean algebra is complete. -/
noncomputable abbrev toCompleteBooleanAlgebra [BooleanAlgebra α] : CompleteBooleanAlgebra α where
__ := ‹BooleanAlgebra α›
__ := Fintype.toCompleteDistribLattice α
inf_sSup_le_iSup_inf _ _ := inf_sSup_eq.le
iInf_sup_le_sup_sInf _ _ := sup_sInf_eq.ge
-- See note [reducible non-instances]
/-- A finite boolean algebra is complete and atomic. -/
noncomputable abbrev toCompleteAtomicBooleanAlgebra [BooleanAlgebra α] :
CompleteAtomicBooleanAlgebra α :=
(toCompleteBooleanAlgebra α).toCompleteAtomicBooleanAlgebra
end BoundedOrder
section Nonempty
variable (α) [Nonempty α]
-- See note [reducible non-instances]
/-- A nonempty finite lattice is complete. If the lattice is already a `BoundedOrder`, then use
`Fintype.toCompleteLattice` instead, as this gives definitional equality for `⊥` and `⊤`. -/
noncomputable abbrev toCompleteLatticeOfNonempty [Lattice α] : CompleteLattice α :=
@toCompleteLattice _ _ _ <| @toBoundedOrder α _ ⟨Classical.arbitrary α⟩ _
-- See note [reducible non-instances]
/-- A nonempty finite linear order is complete. If the linear order is already a `BoundedOrder`,
then use `Fintype.toCompleteLinearOrder` instead, as this gives definitional equality for `⊥` and
`⊤`. -/
noncomputable abbrev toCompleteLinearOrderOfNonempty [LinearOrder α] : CompleteLinearOrder α := by
let _ := toBoundedOrder α
exact { toCompleteLatticeOfNonempty α, ‹LinearOrder α›, LinearOrder.toBiheytingAlgebra with }
end Nonempty
end Fintype
/-! ### Properties for PartialOrders -/
section PartialOrder
variable {α : Type*} [PartialOrder α] {a : α} {p : α → Prop}
lemma Finite.exists_minimal_le [Finite α] (h : p a) : ∃ b, b ≤ a ∧ Minimal p b := by
obtain ⟨b, ⟨hba, hb⟩, hbmin⟩ :=
Set.Finite.exists_minimal_wrt id {x | x ≤ a ∧ p x} (Set.toFinite _) ⟨a, rfl.le, h⟩
exact ⟨b, hba, hb, fun x hx hxb ↦ (hbmin x ⟨hxb.trans hba, hx⟩ hxb).le⟩
lemma Finite.exists_le_maximal [Finite α] (h : p a) : ∃ b, a ≤ b ∧ Maximal p b :=
Finite.exists_minimal_le (α := αᵒᵈ) h
lemma Finset.exists_minimal_le (s : Finset α) (h : a ∈ s) : ∃ b, b ≤ a ∧ Minimal (· ∈ s) b := by
obtain ⟨⟨b, _⟩, lb, minb⟩ := @Finite.exists_minimal_le s _ ⟨a, h⟩ (·.1 ∈ s) _ h
use b, lb; rwa [minimal_subtype, inf_idem] at minb
lemma Finset.exists_le_maximal (s : Finset α) (h : a ∈ s) : ∃ b, a ≤ b ∧ Maximal (· ∈ s) b :=
s.exists_minimal_le (α := αᵒᵈ) h
|
lemma Set.Finite.exists_minimal_le {s : Set α} (hs : s.Finite) (h : a ∈ s) :
| Mathlib/Data/Fintype/Order.lean | 184 | 185 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.ComposableArrows
/-!
# Exact sequences
A sequence of `n` composable arrows `S : ComposableArrows C` (i.e. a functor
`S : Fin (n + 1) ⥤ C`) is said to be exact (`S.Exact`) if the composition
of two consecutive arrows are zero (`S.IsComplex`) and the diagram is
exact at each `i` for `1 ≤ i < n`.
Together with the inductive construction of composable arrows
`ComposableArrows.precomp`, this is useful in order to state that certain
finite sequences of morphisms are exact (e.g the snake lemma), even though
in the applications it would usually be more convenient to use individual
lemmas expressing the exactness at a particular object.
This implementation is a refactor of `exact_seq` with appeared in the
Liquid Tensor Experiment as a property of lists in `Arrow C`.
-/
namespace CategoryTheory
open Limits
variable {C : Type*} [Category C] [HasZeroMorphisms C]
/-- The composable arrows associated to a short complex. -/
@[simps!]
def ShortComplex.toComposableArrows (S : ShortComplex C) : ComposableArrows C 2 :=
ComposableArrows.mk₂ S.f S.g
/-- A map of short complexes induces a map of composable arrows with the same data. -/
def ShortComplex.mapToComposableArrows {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
S₁.toComposableArrows ⟶ S₂.toComposableArrows :=
ComposableArrows.homMk₂ φ.τ₁ φ.τ₂ φ.τ₃ φ.comm₁₂.symm φ.comm₂₃.symm
@[simp]
theorem ShortComplex.mapToComposableArrows_app_0 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
(ShortComplex.mapToComposableArrows φ).app 0 = φ.τ₁ := rfl
@[simp]
theorem ShortComplex.mapToComposableArrows_app_1 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
(ShortComplex.mapToComposableArrows φ).app 1 = φ.τ₂ := rfl
@[simp]
theorem ShortComplex.mapToComposableArrows_app_2 {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) :
(ShortComplex.mapToComposableArrows φ).app 2 = φ.τ₃ := rfl
@[simp]
theorem ShortComplex.mapToComposableArrows_id {S₁ : ShortComplex C} :
(ShortComplex.mapToComposableArrows (𝟙 S₁)) = 𝟙 S₁.toComposableArrows := by
aesop_cat
@[simp]
theorem ShortComplex.mapToComposableArrows_comp {S₁ S₂ S₃ : ShortComplex C} (φ : S₁ ⟶ S₂)
(ψ : S₂ ⟶ S₃) : ShortComplex.mapToComposableArrows (φ ≫ ψ) =
ShortComplex.mapToComposableArrows φ ≫ ShortComplex.mapToComposableArrows ψ := by
aesop_cat
namespace ComposableArrows
variable {n : ℕ} (S : ComposableArrows C n)
/-- `F : ComposableArrows C n` is a complex if all compositions of
two consecutive arrows are zero. -/
structure IsComplex : Prop where
/-- the composition of two consecutive arrows is zero -/
zero (i : ℕ) (hi : i + 2 ≤ n := by omega) :
S.map' i (i + 1) ≫ S.map' (i + 1) (i + 2) = 0
attribute [reassoc] IsComplex.zero
variable {S}
@[reassoc]
lemma IsComplex.zero' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega)
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
S.map' i j ≫ S.map' j k = 0 := by
subst hij hjk
exact hS.zero i hk
lemma isComplex_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.IsComplex) :
S₂.IsComplex where
zero i hi := by
rw [← cancel_epi (ComposableArrows.app' e.hom i), comp_zero,
← NatTrans.naturality_assoc, ← NatTrans.naturality,
reassoc_of% (h₁.zero i hi), zero_comp]
lemma isComplex_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) :
S₁.IsComplex ↔ S₂.IsComplex :=
⟨isComplex_of_iso e, isComplex_of_iso e.symm⟩
lemma isComplex₀ (S : ComposableArrows C 0) : S.IsComplex where
-- See https://github.com/leanprover/lean4/issues/2862
-- Without `decide := true`, simp gets stuck at `hi : autoParam False _auto✝`
zero i hi := by simp +decide at hi
lemma isComplex₁ (S : ComposableArrows C 1) : S.IsComplex where
zero i hi := by omega
variable (S)
/-- The short complex consisting of maps `S.map' i j` and `S.map' j k` when we know
that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/
abbrev sc' (hS : S.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega)
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
ShortComplex C :=
ShortComplex.mk (S.map' i j) (S.map' j k) (hS.zero' i j k)
/-- The short complex consisting of maps `S.map' i (i + 1)` and `S.map' (i + 1) (i + 2)`
when we know that `S : ComposableArrows C n` satisfies `S.IsComplex`. -/
abbrev sc (hS : S.IsComplex) (i : ℕ) (hi : i + 2 ≤ n := by omega) :
ShortComplex C :=
S.sc' hS i (i + 1) (i + 2)
/-- `F : ComposableArrows C n` is exact if it is a complex and that all short
complexes consisting of two consecutive arrows are exact. -/
structure Exact : Prop extends S.IsComplex where
exact (i : ℕ) (hi : i + 2 ≤ n := by omega) : (S.sc toIsComplex i).Exact
variable {S}
lemma Exact.exact' (hS : S.Exact) (i j k : ℕ) (hij : i + 1 = j := by omega)
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
(S.sc' hS.toIsComplex i j k).Exact := by
subst hij hjk
exact hS.exact i hk
/-- Functoriality maps for `ComposableArrows.sc'`. -/
@[simps]
def sc'Map {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex)
(i j k : ℕ) (hij : i + 1 = j := by omega)
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
S₁.sc' h₁ i j k ⟶ S₂.sc' h₂ i j k where
τ₁ := φ.app _
τ₂ := φ.app _
τ₃ := φ.app _
/-- Functoriality maps for `ComposableArrows.sc`. -/
@[simps!]
def scMap {S₁ S₂ : ComposableArrows C n} (φ : S₁ ⟶ S₂) (h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex)
(i : ℕ) (hi : i + 2 ≤ n := by omega) :
S₁.sc h₁ i ⟶ S₂.sc h₂ i :=
sc'Map φ h₁ h₂ i (i + 1) (i + 2)
/-- The isomorphism `S₁.sc' _ i j k ≅ S₂.sc' _ i j k` induced by an isomorphism `S₁ ≅ S₂`
in `ComposableArrows C n`. -/
@[simps]
def sc'MapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂)
(h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex) (i j k : ℕ) (hij : i + 1 = j := by omega)
(hjk : j + 1 = k := by omega) (hk : k ≤ n := by omega) :
S₁.sc' h₁ i j k ≅ S₂.sc' h₂ i j k where
hom := sc'Map e.hom h₁ h₂ i j k
inv := sc'Map e.inv h₂ h₁ i j k
hom_inv_id := by ext <;> dsimp <;> simp
inv_hom_id := by ext <;> dsimp <;> simp
/-- The isomorphism `S₁.sc _ i ≅ S₂.sc _ i` induced by an isomorphism `S₁ ≅ S₂`
in `ComposableArrows C n`. -/
@[simps]
def scMapIso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂)
(h₁ : S₁.IsComplex) (h₂ : S₂.IsComplex)
(i : ℕ) (hi : i + 2 ≤ n := by omega) :
S₁.sc h₁ i ≅ S₂.sc h₂ i where
hom := scMap e.hom h₁ h₂ i
inv := scMap e.inv h₂ h₁ i
hom_inv_id := by ext <;> dsimp <;> simp
inv_hom_id := by ext <;> dsimp <;> simp
lemma exact_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) (h₁ : S₁.Exact) :
S₂.Exact where
toIsComplex := isComplex_of_iso e h₁.toIsComplex
exact i hi := ShortComplex.exact_of_iso (scMapIso e h₁.toIsComplex
(isComplex_of_iso e h₁.toIsComplex) i) (h₁.exact i hi)
lemma exact_iff_of_iso {S₁ S₂ : ComposableArrows C n} (e : S₁ ≅ S₂) :
S₁.Exact ↔ S₂.Exact :=
⟨exact_of_iso e, exact_of_iso e.symm⟩
lemma exact₀ (S : ComposableArrows C 0) : S.Exact where
toIsComplex := S.isComplex₀
-- See https://github.com/leanprover/lean4/issues/2862
exact i hi := by simp at hi
lemma exact₁ (S : ComposableArrows C 1) : S.Exact where
toIsComplex := S.isComplex₁
exact i hi := by exfalso; omega
lemma isComplex₂_iff (S : ComposableArrows C 2) :
S.IsComplex ↔ S.map' 0 1 ≫ S.map' 1 2 = 0 := by
constructor
· intro h
exact h.zero 0 (by omega)
· intro h
refine IsComplex.mk (fun i hi => ?_)
obtain rfl : i = 0 := by omega
exact h
lemma isComplex₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0) :
S.IsComplex :=
S.isComplex₂_iff.2 w
#adaptation_note /-- nightly-2024-03-11
We turn off simprocs here.
Ideally someone will investigate whether `simp` lemmas can be rearranged
so that this works without the `set_option`,
*or* come up with a proposal regarding finer control of disabling simprocs. -/
set_option simprocs false in
lemma _root_.CategoryTheory.ShortComplex.isComplex_toComposableArrows (S : ShortComplex C) :
S.toComposableArrows.IsComplex :=
isComplex₂_mk _ (by simp)
lemma exact₂_iff (S : ComposableArrows C 2) (hS : S.IsComplex) :
S.Exact ↔ (S.sc' hS 0 1 2).Exact := by
constructor
· intro h
exact h.exact 0 (by omega)
· intro h
refine Exact.mk hS (fun i hi => ?_)
obtain rfl : i = 0 := by omega
exact h
lemma exact₂_mk (S : ComposableArrows C 2) (w : S.map' 0 1 ≫ S.map' 1 2 = 0)
(h : (ShortComplex.mk _ _ w).Exact) : S.Exact :=
(S.exact₂_iff (S.isComplex₂_mk w)).2 h
lemma _root_.CategoryTheory.ShortComplex.Exact.exact_toComposableArrows
{S : ShortComplex C} (hS : S.Exact) :
S.toComposableArrows.Exact :=
exact₂_mk _ _ hS
lemma _root_.CategoryTheory.ShortComplex.exact_iff_exact_toComposableArrows
(S : ShortComplex C) :
S.Exact ↔ S.toComposableArrows.Exact :=
(S.toComposableArrows.exact₂_iff S.isComplex_toComposableArrows).symm
lemma exact_iff_δ₀ (S : ComposableArrows C (n + 2)) :
S.Exact ↔ (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact ∧ S.δ₀.Exact := by
constructor
· intro h
constructor
· rw [exact₂_iff]; swap
· rw [isComplex₂_iff]
exact h.toIsComplex.zero 0
exact h.exact 0 (by omega)
· exact Exact.mk (IsComplex.mk (fun i hi => h.toIsComplex.zero (i + 1)))
(fun i hi => h.exact (i + 1))
· rintro ⟨h, h₀⟩
refine Exact.mk (IsComplex.mk (fun i hi => ?_)) (fun i hi => ?_)
· obtain _ | i := i
· exact h.toIsComplex.zero 0
· exact h₀.toIsComplex.zero i
· obtain _ | i := i
· exact h.exact 0
· exact h₀.exact i
lemma Exact.δ₀ {S : ComposableArrows C (n + 2)} (hS : S.Exact) :
S.δ₀.Exact := by
rw [exact_iff_δ₀] at hS
exact hS.2
/-- If `S : ComposableArrows C (n + 2)` is such that the first two arrows form
an exact sequence and that the tail `S.δ₀` is exact, then `S` is also exact.
See `ShortComplex.SnakeInput.snake_lemma` in `Algebra.Homology.ShortComplex.SnakeLemma`
| for a use of this lemma. -/
lemma exact_of_δ₀ {S : ComposableArrows C (n + 2)}
(h : (mk₂ (S.map' 0 1) (S.map' 1 2)).Exact) (h₀ : S.δ₀.Exact) : S.Exact := by
rw [exact_iff_δ₀]
| Mathlib/Algebra/Homology/ExactSequence.lean | 272 | 275 |
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SetFamily.Shadow
/-!
# UV-compressions
This file defines UV-compression. It is an operation on a set family that reduces its shadow.
UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are
disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`.
UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that
compressing a set family might decrease the size of its shadow, so iterated compressions hopefully
minimise the shadow.
## Main declarations
* `UV.compress`: `compress u v a` is `a` compressed along `u` and `v`.
* `UV.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`.
It is the compressions of the elements of `s` whose compression is not already in `s` along with
the element whose compression is already in `s`. This way of splitting into what moves and what
does not ensures the compression doesn't squash the set family, which is proved by
`UV.card_compression`.
* `UV.card_shadow_compression_le`: Compressing reduces the size of the shadow. This is a key fact in
the proof of Kruskal-Katona.
## Notation
`𝓒` (typed with `\MCC`) is notation for `UV.compression` in locale `FinsetFamily`.
## Notes
Even though our emphasis is on `Finset α`, we define UV-compressions more generally in a generalized
boolean algebra, so that one can use it for `Set α`.
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
## Tags
compression, UV-compression, shadow
-/
open Finset
variable {α : Type*}
/-- UV-compression is injective on the elements it moves. See `UV.compress`. -/
theorem sup_sdiff_injOn [GeneralizedBooleanAlgebra α] (u v : α) :
{ x | Disjoint u x ∧ v ≤ x }.InjOn fun x => (x ⊔ u) \ v := by
rintro a ha b hb hab
have h : ((a ⊔ u) \ v) \ u ⊔ v = ((b ⊔ u) \ v) \ u ⊔ v := by
dsimp at hab
rw [hab]
rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm,
hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h
-- The namespace is here to distinguish from other compressions.
namespace UV
/-! ### UV-compression in generalized boolean algebras -/
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra α] [DecidableRel (@Disjoint α _ _)]
[DecidableLE α] {s : Finset α} {u v a : α}
/-- UV-compressing `a` means removing `v` from it and adding `u` if `a` and `u` are disjoint and
`v ≤ a` (it replaces the `v` part of `a` by the `u` part). Else, UV-compressing `a` doesn't do
anything. This is most useful when `u` and `v` are disjoint finsets of the same size. -/
def compress (u v a : α) : α :=
if Disjoint u a ∧ v ≤ a then (a ⊔ u) \ v else a
theorem compress_of_disjoint_of_le (hua : Disjoint u a) (hva : v ≤ a) :
compress u v a = (a ⊔ u) \ v :=
if_pos ⟨hua, hva⟩
theorem compress_of_disjoint_of_le' (hva : Disjoint v a) (hua : u ≤ a) :
compress u v ((a ⊔ v) \ u) = a := by
rw [compress_of_disjoint_of_le disjoint_sdiff_self_right
(le_sdiff.2 ⟨(le_sup_right : v ≤ a ⊔ v), hva.mono_right hua⟩),
sdiff_sup_cancel (le_sup_of_le_left hua), hva.symm.sup_sdiff_cancel_right]
@[simp]
theorem compress_self (u a : α) : compress u u a = a := by
unfold compress
split_ifs with h
· exact h.1.symm.sup_sdiff_cancel_right
· rfl
/-- An element can be compressed to any other element by removing/adding the differences. -/
@[simp]
theorem compress_sdiff_sdiff (a b : α) : compress (a \ b) (b \ a) b = a := by
refine (compress_of_disjoint_of_le disjoint_sdiff_self_left sdiff_le).trans ?_
rw [sup_sdiff_self_right, sup_sdiff, disjoint_sdiff_self_right.sdiff_eq_left, sup_eq_right]
exact sdiff_sdiff_le
/-- Compressing an element is idempotent. -/
@[simp]
theorem compress_idem (u v a : α) : compress u v (compress u v a) = compress u v a := by
unfold compress
split_ifs with h h'
· rw [le_sdiff_right.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem]
· rfl
· rfl
variable [DecidableEq α]
/-- To UV-compress a set family, we compress each of its elements, except that we don't want to
reduce the cardinality, so we keep all elements whose compression is already present. -/
def compression (u v : α) (s : Finset α) :=
{a ∈ s | compress u v a ∈ s} ∪ {a ∈ s.image <| compress u v | a ∉ s}
@[inherit_doc]
scoped[FinsetFamily] notation "𝓒 " => UV.compression
open scoped FinsetFamily
/-- `IsCompressed u v s` expresses that `s` is UV-compressed. -/
def IsCompressed (u v : α) (s : Finset α) :=
𝓒 u v s = s
/-- UV-compression is injective on the sets that are not UV-compressed. -/
theorem compress_injOn : Set.InjOn (compress u v) ↑{a ∈ s | compress u v a ∉ s} := by
intro a ha b hb hab
rw [mem_coe, mem_filter] at ha hb
rw [compress] at ha hab
split_ifs at ha hab with has
· rw [compress] at hb hab
split_ifs at hb hab with hbs
· exact sup_sdiff_injOn u v has hbs hab
· exact (hb.2 hb.1).elim
· exact (ha.2 ha.1).elim
/-- `a` is in the UV-compressed family iff it's in the original and its compression is in the
original, or it's not in the original but it's the compression of something in the original. -/
theorem mem_compression :
a ∈ 𝓒 u v s ↔ a ∈ s ∧ compress u v a ∈ s ∨ a ∉ s ∧ ∃ b ∈ s, compress u v b = a := by
simp_rw [compression, mem_union, mem_filter, mem_image, and_comm]
protected theorem IsCompressed.eq (h : IsCompressed u v s) : 𝓒 u v s = s := h
@[simp]
theorem compression_self (u : α) (s : Finset α) : 𝓒 u u s = s := by
unfold compression
convert union_empty s
· ext a
rw [mem_filter, compress_self, and_self_iff]
· refine eq_empty_of_forall_not_mem fun a ha ↦ ?_
simp_rw [mem_filter, mem_image, compress_self] at ha
obtain ⟨⟨b, hb, rfl⟩, hb'⟩ := ha
exact hb' hb
/-- Any family is compressed along two identical elements. -/
theorem isCompressed_self (u : α) (s : Finset α) : IsCompressed u u s := compression_self u s
theorem compress_disjoint :
Disjoint {a ∈ s | compress u v a ∈ s} {a ∈ s.image <| compress u v | a ∉ s} :=
disjoint_left.2 fun _a ha₁ ha₂ ↦ (mem_filter.1 ha₂).2 (mem_filter.1 ha₁).1
theorem compress_mem_compression (ha : a ∈ s) : compress u v a ∈ 𝓒 u v s := by
rw [mem_compression]
by_cases h : compress u v a ∈ s
· rw [compress_idem]
exact Or.inl ⟨h, h⟩
· exact Or.inr ⟨h, a, ha, rfl⟩
-- This is a special case of `compress_mem_compression` once we have `compression_idem`.
theorem compress_mem_compression_of_mem_compression (ha : a ∈ 𝓒 u v s) :
compress u v a ∈ 𝓒 u v s := by
rw [mem_compression] at ha ⊢
simp only [compress_idem, exists_prop]
obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha
· exact Or.inl ⟨ha, ha⟩
· exact Or.inr ⟨by rwa [compress_idem], b, hb, (compress_idem _ _ _).symm⟩
/-- Compressing a family is idempotent. -/
@[simp]
theorem compression_idem (u v : α) (s : Finset α) : 𝓒 u v (𝓒 u v s) = 𝓒 u v s := by
have h : {a ∈ 𝓒 u v s | compress u v a ∉ 𝓒 u v s} = ∅ :=
filter_false_of_mem fun a ha h ↦ h <| compress_mem_compression_of_mem_compression ha
rw [compression, filter_image, h, image_empty, ← h]
exact filter_union_filter_neg_eq _ (compression u v s)
/-- Compressing a family doesn't change its size. -/
@[simp]
theorem card_compression (u v : α) (s : Finset α) : #(𝓒 u v s) = #s := by
rw [compression, card_union_of_disjoint compress_disjoint, filter_image,
card_image_of_injOn compress_injOn, ← card_union_of_disjoint (disjoint_filter_filter_neg s _ _),
filter_union_filter_neg_eq]
theorem le_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) : u ≤ a := by
rw [mem_compression] at h
obtain h | ⟨-, b, hb, hba⟩ := h
· cases ha h.1
unfold compress at hba
split_ifs at hba with h
· rw [← hba, le_sdiff]
exact ⟨le_sup_right, h.1.mono_right h.2⟩
· cases ne_of_mem_of_not_mem hb ha hba
theorem disjoint_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) : Disjoint v a := by
rw [mem_compression] at h
obtain h | ⟨-, b, hb, hba⟩ := h
· cases ha h.1
unfold compress at hba
split_ifs at hba
· rw [← hba]
exact disjoint_sdiff_self_right
· cases ne_of_mem_of_not_mem hb ha hba
theorem sup_sdiff_mem_of_mem_compression_of_not_mem (h : a ∈ 𝓒 u v s) (ha : a ∉ s) :
(a ⊔ v) \ u ∈ s := by
rw [mem_compression] at h
obtain h | ⟨-, b, hb, hba⟩ := h
· cases ha h.1
unfold compress at hba
split_ifs at hba with h
· rwa [← hba, sdiff_sup_cancel (le_sup_of_le_left h.2), sup_sdiff_right_self,
h.1.symm.sdiff_eq_left]
· cases ne_of_mem_of_not_mem hb ha hba
/-- If `a` is in the family compression and can be compressed, then its compression is in the
original family. -/
theorem sup_sdiff_mem_of_mem_compression (ha : a ∈ 𝓒 u v s) (hva : v ≤ a) (hua : Disjoint u a) :
(a ⊔ u) \ v ∈ s := by
rw [mem_compression, compress_of_disjoint_of_le hua hva] at ha
obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha
· exact ha
have hu : u = ⊥ := by
suffices Disjoint u (u \ v) by rwa [(hua.mono_right hva).sdiff_eq_left, disjoint_self] at this
refine hua.mono_right ?_
rw [← compress_idem, compress_of_disjoint_of_le hua hva]
exact sdiff_le_sdiff_right le_sup_right
have hv : v = ⊥ := by
rw [← disjoint_self]
apply Disjoint.mono_right hva
rw [← compress_idem, compress_of_disjoint_of_le hua hva]
exact disjoint_sdiff_self_right
rwa [hu, hv, compress_self, sup_bot_eq, sdiff_bot]
/-- If `a` is in the `u, v`-compression but `v ≤ a`, then `a` must have been in the original
family. -/
theorem mem_of_mem_compression (ha : a ∈ 𝓒 u v s) (hva : v ≤ a) (hvu : v = ⊥ → u = ⊥) :
a ∈ s := by
rw [mem_compression] at ha
obtain ha | ⟨_, b, hb, h⟩ := ha
· exact ha.1
unfold compress at h
split_ifs at h
· rw [← h, le_sdiff_right] at hva
rwa [← h, hvu hva, hva, sup_bot_eq, sdiff_bot]
· rwa [← h]
end GeneralizedBooleanAlgebra
/-! ### UV-compression on finsets -/
open FinsetFamily
variable [DecidableEq α] {𝒜 : Finset (Finset α)} {u v : Finset α} {r : ℕ}
/-- Compressing a finset doesn't change its size. -/
theorem card_compress (huv : #u = #v) (a : Finset α) : #(compress u v a) = #a := by
unfold compress
split_ifs with h
· rw [card_sdiff (h.2.trans le_sup_left), sup_eq_union, card_union_of_disjoint h.1.symm, huv,
add_tsub_cancel_right]
· rfl
lemma _root_.Set.Sized.uvCompression (huv : #u = #v) (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
(𝓒 u v 𝒜 : Set (Finset α)).Sized r := by
simp_rw [Set.Sized, mem_coe, mem_compression]
rintro s (hs | ⟨huvt, t, ht, rfl⟩)
· exact h𝒜 hs.1
· rw [card_compress huv, h𝒜 ht]
private theorem aux (huv : ∀ x ∈ u, ∃ y ∈ v, IsCompressed (u.erase x) (v.erase y) 𝒜) :
v = ∅ → u = ∅ := by
rintro rfl; refine eq_empty_of_forall_not_mem fun a ha ↦ ?_; obtain ⟨_, ⟨⟩, -⟩ := huv a ha
/-- UV-compression reduces the size of the shadow of `𝒜` if, for all `x ∈ u` there is `y ∈ v` such
that `𝒜` is `(u.erase x, v.erase y)`-compressed. This is the key fact about compression for
Kruskal-Katona. -/
theorem shadow_compression_subset_compression_shadow (u v : Finset α)
(huv : ∀ x ∈ u, ∃ y ∈ v, IsCompressed (u.erase x) (v.erase y) 𝒜) :
∂ (𝓒 u v 𝒜) ⊆ 𝓒 u v (∂ 𝒜) := by
set 𝒜' := 𝓒 u v 𝒜
suffices H : ∀ s ∈ ∂ 𝒜',
s ∉ ∂ 𝒜 → u ⊆ s ∧ Disjoint v s ∧ (s ∪ v) \ u ∈ ∂ 𝒜 ∧ (s ∪ v) \ u ∉ ∂ 𝒜' by
rintro s hs'
rw [mem_compression]
by_cases hs : s ∈ 𝒜.shadow
swap
· obtain ⟨hus, hvs, h, _⟩ := H _ hs' hs
exact Or.inr ⟨hs, _, h, compress_of_disjoint_of_le' hvs hus⟩
refine Or.inl ⟨hs, ?_⟩
rw [compress]
split_ifs with huvs
swap
· exact hs
rw [mem_shadow_iff] at hs'
obtain ⟨t, Ht, a, hat, rfl⟩ := hs'
have hav : a ∉ v := not_mem_mono huvs.2 (not_mem_erase a t)
have hvt : v ≤ t := huvs.2.trans (erase_subset _ t)
have ht : t ∈ 𝒜 := mem_of_mem_compression Ht hvt (aux huv)
by_cases hau : a ∈ u
· obtain ⟨b, hbv, Hcomp⟩ := huv a hau
refine mem_shadow_iff_insert_mem.2 ⟨b, not_mem_sdiff_of_mem_right hbv, ?_⟩
rw [← Hcomp.eq] at ht
have hsb :=
| sup_sdiff_mem_of_mem_compression ht ((erase_subset _ _).trans hvt)
(disjoint_erase_comm.2 huvs.1)
rwa [sup_eq_union, sdiff_erase (mem_union_left _ <| hvt hbv), union_erase_of_mem hat, ←
erase_union_of_mem hau] at hsb
· refine mem_shadow_iff.2
⟨(t ⊔ u) \ v,
sup_sdiff_mem_of_mem_compression Ht hvt <| disjoint_of_erase_right hau huvs.1, a, ?_, ?_⟩
· rw [sup_eq_union, mem_sdiff, mem_union]
exact ⟨Or.inl hat, hav⟩
· rw [← erase_sdiff_comm, sup_eq_union, erase_union_distrib, erase_eq_of_not_mem hau]
intro s hs𝒜' hs𝒜
-- This is going to be useful a couple of times so let's name it.
have m : ∀ y, y ∉ s → insert y s ∉ 𝒜 := fun y h a => hs𝒜 (mem_shadow_iff_insert_mem.2 ⟨y, h, a⟩)
obtain ⟨x, _, _⟩ := mem_shadow_iff_insert_mem.1 hs𝒜'
have hus : u ⊆ insert x s := le_of_mem_compression_of_not_mem ‹_ ∈ 𝒜'› (m _ ‹x ∉ s›)
have hvs : Disjoint v (insert x s) := disjoint_of_mem_compression_of_not_mem ‹_› (m _ ‹x ∉ s›)
have : (insert x s ∪ v) \ u ∈ 𝒜 := sup_sdiff_mem_of_mem_compression_of_not_mem ‹_› (m _ ‹x ∉ s›)
have hsv : Disjoint s v := hvs.symm.mono_left (subset_insert _ _)
have hvu : Disjoint v u := disjoint_of_subset_right hus hvs
have hxv : x ∉ v := disjoint_right.1 hvs (mem_insert_self _ _)
have : v \ u = v := ‹Disjoint v u›.sdiff_eq_left
-- The first key part is that `x ∉ u`
have : x ∉ u := by
intro hxu
obtain ⟨y, hyv, hxy⟩ := huv x hxu
-- If `x ∈ u`, we can get `y ∈ v` so that `𝒜` is `(u.erase x, v.erase y)`-compressed
apply m y (disjoint_right.1 hsv hyv)
-- and we will use this `y` to contradict `m`, so we would like to show `insert y s ∈ 𝒜`.
-- We do this by showing the below
have : ((insert x s ∪ v) \ u ∪ erase u x) \ erase v y ∈ 𝒜 := by
refine
sup_sdiff_mem_of_mem_compression (by rwa [hxy.eq]) ?_
(disjoint_of_subset_left (erase_subset _ _) disjoint_sdiff)
rw [union_sdiff_distrib, ‹v \ u = v›]
exact (erase_subset _ _).trans subset_union_right
-- and then arguing that it's the same
convert this using 1
rw [sdiff_union_erase_cancel (hus.trans subset_union_left) ‹x ∈ u›, erase_union_distrib,
erase_insert ‹x ∉ s›, erase_eq_of_not_mem ‹x ∉ v›, sdiff_erase (mem_union_right _ hyv),
union_sdiff_cancel_right hsv]
-- Now that this is done, it's immediate that `u ⊆ s`
have hus : u ⊆ s := by rwa [← erase_eq_of_not_mem ‹x ∉ u›, ← subset_insert_iff]
-- and we already had that `v` and `s` are disjoint,
-- so it only remains to get `(s ∪ v) \ u ∈ ∂ 𝒜 \ ∂ 𝒜'`
simp_rw [mem_shadow_iff_insert_mem]
refine ⟨hus, hsv.symm, ⟨x, ?_, ?_⟩, ?_⟩
-- `(s ∪ v) \ u ∈ ∂ 𝒜` is pretty direct:
· exact not_mem_sdiff_of_not_mem_left (not_mem_union.2 ⟨‹x ∉ s›, ‹x ∉ v›⟩)
· rwa [← insert_sdiff_of_not_mem _ ‹x ∉ u›, ← insert_union]
-- For (s ∪ v) \ u ∉ ∂ 𝒜', we split up based on w ∈ u
rintro ⟨w, hwB, hw𝒜'⟩
have : v ⊆ insert w ((s ∪ v) \ u) :=
(subset_sdiff.2 ⟨subset_union_right, hvu⟩).trans (subset_insert _ _)
by_cases hwu : w ∈ u
-- If `w ∈ u`, we find `z ∈ v`, and contradict `m` again
· obtain ⟨z, hz, hxy⟩ := huv w hwu
apply m z (disjoint_right.1 hsv hz)
have : insert w ((s ∪ v) \ u) ∈ 𝒜 := mem_of_mem_compression hw𝒜' ‹_› (aux huv)
have : (insert w ((s ∪ v) \ u) ∪ erase u w) \ erase v z ∈ 𝒜 := by
refine sup_sdiff_mem_of_mem_compression (by rwa [hxy.eq]) ((erase_subset _ _).trans ‹_›) ?_
rw [← sdiff_erase (mem_union_left _ <| hus hwu)]
exact disjoint_sdiff
convert this using 1
rw [insert_union_comm, insert_erase ‹w ∈ u›,
sdiff_union_of_subset (hus.trans subset_union_left),
sdiff_erase (mem_union_right _ ‹z ∈ v›), union_sdiff_cancel_right hsv]
-- If `w ∉ u`, we contradict `m` again
rw [mem_sdiff, ← Classical.not_imp, Classical.not_not] at hwB
apply m w (hwu ∘ hwB ∘ mem_union_left _)
have : (insert w ((s ∪ v) \ u) ∪ u) \ v ∈ 𝒜 :=
sup_sdiff_mem_of_mem_compression ‹insert w ((s ∪ v) \ u) ∈ 𝒜'› ‹_›
(disjoint_insert_right.2 ⟨‹_›, disjoint_sdiff⟩)
convert this using 1
rw [insert_union, sdiff_union_of_subset (hus.trans subset_union_left),
insert_sdiff_of_not_mem _ (hwu ∘ hwB ∘ mem_union_right _), union_sdiff_cancel_right hsv]
/-- UV-compression reduces the size of the shadow of `𝒜` if, for all `x ∈ u` there is `y ∈ v`
such that `𝒜` is `(u.erase x, v.erase y)`-compressed. This is the key UV-compression fact needed for
Kruskal-Katona. -/
theorem card_shadow_compression_le (u v : Finset α)
(huv : ∀ x ∈ u, ∃ y ∈ v, IsCompressed (u.erase x) (v.erase y) 𝒜) :
#(∂ (𝓒 u v 𝒜)) ≤ #(∂ 𝒜) :=
(card_le_card <| shadow_compression_subset_compression_shadow _ _ huv).trans
(card_compression _ _ _).le
end UV
| Mathlib/Combinatorics/SetFamily/Compression/UV.lean | 319 | 420 |
/-
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 | 394 | 394 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.Order.Ring.WithTop
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.Data.Nat.SuccPred
import Mathlib.Order.SuccPred.WithBot
/-!
# Degree of univariate polynomials
## Main definitions
* `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥`
* `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0`
* `Polynomial.leadingCoeff`: the leading coefficient of a polynomial
* `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0
* `Polynomial.nextCoeff`: the next coefficient after the leading coefficient
## Main results
* `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials
-/
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : R[X]) : WithBot ℕ :=
p.support.max
/-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/
def natDegree (p : R[X]) : ℕ :=
(degree p).unbotD 0
/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/
def leadingCoeff (p : R[X]) : R :=
coeff p (natDegree p)
/-- a polynomial is `Monic` if its leading coefficient is 1 -/
def Monic (p : R[X]) :=
leadingCoeff p = (1 : R)
theorem Monic.def : Monic p ↔ leadingCoeff p = 1 :=
Iff.rfl
instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance
@[simp]
theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=
hp
theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=
hp
@[simp]
theorem degree_zero : degree (0 : R[X]) = ⊥ :=
rfl
@[simp]
theorem natDegree_zero : natDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=
rfl
@[simp]
theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩
theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not
theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by
let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))
have hn : degree p = some n := Classical.not_not.1 hn
rw [natDegree, hn]; rfl
theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe
theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) :
p.degree = n ↔ p.natDegree = n := by
obtain rfl|h := eq_or_ne p 0
· simp [hn.ne]
· exact degree_eq_iff_natDegree_eq h
theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by
rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe]
theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n :=
mt natDegree_eq_of_degree_eq_some
@[simp]
theorem degree_le_natDegree : degree p ≤ natDegree p :=
WithBot.giUnbotDBot.gc.le_u_l _
theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) :
natDegree p = natDegree q := by unfold natDegree; rw [h]
theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by
rw [Nat.cast_withBot]
exact Finset.le_sup (mem_support_iff.2 h)
theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) :
f.degree ≤ g.degree :=
Finset.sup_mono h
theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by
by_cases hp : p = 0
· rw [hp, degree_zero]
exact bot_le
· rw [degree_eq_natDegree hp]
exact le_degree_of_ne_zero h
theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n :=
WithBot.unbotD_le_iff (fun _ ↦ bot_le)
theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n :=
WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp))
alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le
theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) :
p.natDegree ≤ q.natDegree :=
WithBot.giUnbotDBot.gc.monotone_l hpq
@[simp]
theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by
rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton,
WithBot.coe_zero]
theorem degree_C_le : degree (C a) ≤ 0 := by
by_cases h : a = 0
· rw [h, C_0]
exact bot_le
· rw [degree_C h]
theorem degree_C_lt : degree (C a) < 1 :=
degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one
theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le
@[simp]
theorem natDegree_C (a : R) : natDegree (C a) = 0 := by
by_cases ha : a = 0
· have : C a = 0 := by rw [ha, C_0]
rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot]
· rw [natDegree, degree_C ha, WithBot.unbotD_zero]
@[simp]
theorem natDegree_one : natDegree (1 : R[X]) = 0 :=
natDegree_C 1
@[simp]
theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by
simp only [← C_eq_natCast, natDegree_C]
@[simp]
theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] :
natDegree (ofNat(n) : R[X]) = 0 :=
natDegree_natCast _
theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by
rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot]
@[simp]
theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by
rw [C_mul_X_pow_eq_monomial, degree_monomial n ha]
theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by
simpa only [pow_one] using degree_C_mul_X_pow 1 ha
theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n :=
letI := Classical.decEq R
if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le
else le_of_eq (degree_monomial n h)
theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by
rw [C_mul_X_pow_eq_monomial]
apply degree_monomial_le
theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by
simpa only [pow_one] using degree_C_mul_X_pow_le 1 a
@[simp]
theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha)
@[simp]
theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by
simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha
@[simp]
theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) :
natDegree (monomial i r) = if r = 0 then 0 else i := by
split_ifs with hr
· simp [hr]
· rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr]
theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by
classical
rw [Polynomial.natDegree_monomial]
split_ifs
exacts [Nat.zero_le _, le_rfl]
theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i :=
letI := Classical.decEq R
Eq.trans (natDegree_monomial _ _) (if_neg r0)
theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h =>
mem_support_iff.mp (mem_of_max hn) h
theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by
simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R)
theorem degree_X_le : degree (X : R[X]) ≤ 1 :=
degree_monomial_le _ _
theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 :=
natDegree_le_of_degree_le degree_X_le
theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by
rw [degree_eq_natDegree h]
exact WithBot.succ_coe p.natDegree
end Semiring
section NonzeroSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]}
@[simp]
theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) :=
degree_C one_ne_zero
@[simp]
theorem degree_X : degree (X : R[X]) = 1 :=
degree_monomial _ one_ne_zero
@[simp]
theorem natDegree_X : (X : R[X]).natDegree = 1 :=
natDegree_eq_of_degree_eq_some degree_X
end NonzeroSemiring
section Ring
variable [Ring R]
@[simp]
theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg]
theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a :=
p.degree_neg.le.trans hp
@[simp]
theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree]
theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m :=
(natDegree_neg p).le.trans hp
@[simp]
theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by
rw [← C_eq_intCast, natDegree_C]
theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp)
@[simp]
theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by
rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg]
end Ring
section Semiring
variable [Semiring R] {p : R[X]}
/-- The second-highest coefficient, or 0 for constants -/
def nextCoeff (p : R[X]) : R :=
if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1)
lemma nextCoeff_eq_zero :
p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by
simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop
lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by
simp [nextCoeff]
@[simp]
theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by
rw [nextCoeff]
simp
theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) :
nextCoeff p = p.coeff (p.natDegree - 1) := by
rw [nextCoeff, if_neg]
contrapose! hp
simpa
variable {p q : R[X]} {ι : Type*}
theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by
simpa only [degree, ← support_toFinsupp, toFinsupp_add]
using AddMonoidAlgebra.sup_support_add_le _ _ _
theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) :
degree (p + q) ≤ n :=
(degree_add_le p q).trans <| max_le hp hq
theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p + q) ≤ max a b :=
(p.degree_add_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by
rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h]
theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n)
(hq : natDegree q ≤ n) : natDegree (p + q) ≤ n :=
(natDegree_add_le p q).trans <| max_le hp hq
theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p + q) ≤ max m n :=
(p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_›
@[simp]
theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 :=
⟨fun h =>
Classical.by_contradiction fun hp =>
mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)),
fun h => h.symm ▸ leadingCoeff_zero⟩
theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero]
theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by
rw [leadingCoeff_eq_zero, degree_eq_bot]
theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n :=
natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _
theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by
rcases p with ⟨p⟩
simp only [erase_def, degree, coeff, support]
apply sup_mono
rw [Finsupp.support_erase]
apply Finset.erase_subset
theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by
apply lt_of_le_of_ne (degree_erase_le _ _)
rw [degree_eq_natDegree hp, degree, support_erase]
exact fun h => not_mem_erase _ _ (mem_of_max h)
theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by
classical
rw [degree, support_update]
split_ifs
· exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _)
· rw [max_insert, max_comm]
exact le_rfl
theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) :
degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) :=
Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl])
fun a s has ih =>
calc
degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by
rw [Finset.sum_cons]; exact degree_add_le _ _
_ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih
theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by
simpa only [degree, ← support_toFinsupp, toFinsupp_mul]
using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _
theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p * q) ≤ a + b :=
(p.degree_mul_le _).trans <| add_le_add ‹_› ‹_›
theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p
| 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le
| n + 1 =>
calc
degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by
rw [pow_succ]; exact degree_mul_le _ _
_ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _
theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) :
degree (p ^ b) ≤ b * a := by
induction b with
| zero => simp [degree_one_le]
| succ n hn =>
rw [Nat.cast_succ, add_mul, one_mul, pow_succ]
exact degree_mul_le_of_le hn hp
@[simp]
theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by
classical
by_cases ha : a = 0
· simp only [ha, (monomial n).map_zero, leadingCoeff_zero]
· rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial]
simp
theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by
rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial]
theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by
simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1
@[simp]
theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a :=
leadingCoeff_monomial a 0
theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by
simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n
theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by
simpa only [pow_one] using @leadingCoeff_X_pow R _ 1
@[simp]
theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) :=
leadingCoeff_X_pow n
@[simp]
theorem monic_X : Monic (X : R[X]) :=
leadingCoeff_X
theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 :=
leadingCoeff_C 1
@[simp]
theorem monic_one : Monic (1 : R[X]) :=
leadingCoeff_C _
theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) :
p ≠ 0 := by
rintro rfl
simp [Monic] at hp
theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by
nontriviality R
exact hp.ne_zero
theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 :=
haveI := Nontrivial.of_polynomial_ne hne
hp.ne_zero
theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by
apply natDegree_le_of_degree_le
apply le_trans (degree_mul_le p q)
rw [Nat.cast_add]
apply add_le_add <;> apply degree_le_natDegree
theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) :
natDegree (p * q) ≤ m + n :=
natDegree_mul_le.trans <| add_le_add ‹_› ‹_›
theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by
induction n with
| zero => simp
| succ i hi =>
rw [pow_succ, Nat.succ_mul]
apply le_trans natDegree_mul_le (add_le_add_right hi _)
theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) :
natDegree (p ^ n) ≤ n * m :=
natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›)
theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by
rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero]
theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl
theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) :
degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by
simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le,
not_imp_comm, Nat.cast_withBot]
theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) :
degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by
simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff,
WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not]
theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p :=
lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le
end Semiring
section NontrivialSemiring
variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ)
@[simp]
theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by
rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)]
@[simp]
theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n :=
natDegree_eq_of_degree_eq_some (degree_X_pow n)
end NontrivialSemiring
section Ring
variable [Ring R] {p q : R[X]}
theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by
simpa only [degree_neg q] using degree_add_le p (-q)
theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) :
degree (p - q) ≤ max a b :=
(p.degree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by
simpa only [← natDegree_neg q] using natDegree_add_le p (-q)
theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) :
natDegree (p - q) ≤ max m n :=
(p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_›
theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0)
(hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p :=
have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p :=
monomial_add_erase _ _
have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q :=
monomial_add_erase _ _
have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd]
have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0)
calc
degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by
conv =>
lhs
rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg]
_ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) :=
(degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _)
_ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩
theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 :=
(degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one))
theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 :=
natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r
end Ring
end Polynomial
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 749 | 755 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.MeasurableSpace.MeasurablyGenerated
import Mathlib.MeasureTheory.Measure.NullMeasurable
import Mathlib.Order.Interval.Set.Monotone
/-!
# Measure spaces
The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to
be available in `MeasureSpace` (through `MeasurableSpace`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure.
## Implementation notes
Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generateFrom_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using
`C ∪ {univ}`, but is easier to work with.
A `MeasureSpace` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable section
open Set
open Filter hiding map
open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory
open scoped symmDiff
variable {α β γ δ ι R R' : Type*}
namespace MeasureTheory
section
variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α}
instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) :=
⟨fun _s hs =>
let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
/-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/
theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by
simp only [uIoc_eq_union, mem_union, or_imp, eventually_and]
theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀ h.nullMeasurableSet hd.aedisjoint
theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀' h.nullMeasurableSet hd.aedisjoint
theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s :=
measure_inter_add_diff₀ _ ht.nullMeasurableSet
theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s :=
(add_comm _ _).trans (measure_inter_add_diff s ht)
theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by
contrapose! hs
exact ((measure_mono (subset_diff_union s t)).trans_lt
((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne
theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ←
measure_inter_add_diff s ht]
ac_rfl
theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm]
lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by
simpa only [symmDiff_def, sup_eq_union]
using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint
lemma measure_symmDiff_le (s t u : Set α) :
μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) :=
le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u))
theorem measure_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ :=
measure_mono_top subset_union_right (measure_diff_eq_top ht hs)
theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ :=
measure_add_measure_compl₀ h.nullMeasurableSet
theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable)
(hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by
haveI := hs.toEncodable
rw [biUnion_eq_iUnion]
exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2
theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f)
(h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=
measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet
theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ))
(h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h]
theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint)
(h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion hs hd h]
theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α}
(hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by
rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype]
exact measure_biUnion₀ s.countable_toSet hd hm
theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f)
(hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) :=
measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet
/-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least
the sum of the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by
rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff]
intro s
simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i]
gcongr
exact iUnion_subset fun _ ↦ Subset.rfl
/-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of
the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) :=
tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet)
(fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by
rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf]
lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) :
μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by
rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs]
/-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by
simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf,
Finset.set_biUnion_preimage_singleton]
@[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] :
∑ x ∈ s, μ {x} = μ s := by
trans ∑ x ∈ s, μ (id ⁻¹' {x})
· simp
rw [sum_measure_preimage_singleton]
· simp
· simp
theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_congr <| diff_ae_eq_self.2 h
theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) :
μ s + μ (t \ s) = μ (s ∪ t) := by
rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self]
theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) :
μ (s \ t) = μ (s ∪ t) - μ t :=
ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm]
theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) :
μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h]
theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) :=
tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by
gcongr; apply inter_subset_right
/-- If the measure of the symmetric difference of two sets is finite,
then one has infinite measure if and only if the other one does. -/
theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by
suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞
from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩
intro u v hμuv hμu
by_contra! hμv
apply hμuv
rw [Set.symmDiff_def, eq_top_iff]
calc
∞ = μ u - μ v := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩]
_ ≤ μ (u \ v) := le_measure_diff
_ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left
/-- If the measure of the symmetric difference of two sets is finite,
then one has finite measure if and only if the other one does. -/
theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ :=
(measure_eq_top_iff_of_symmDiff hμst).ne
theorem measure_diff_lt_of_lt_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞)
{ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by
rw [measure_diff hst hs hs']; rw [add_comm] at h
exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h
theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞)
{ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by
rw [measure_diff hst hs hs', tsub_le_iff_left]
theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) :
μ s = μ t := measure_congr <|
EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff)
theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃)
(h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by
have le12 : μ s₁ ≤ μ s₂ := measure_mono h12
have le23 : μ s₂ ≤ μ s₃ := measure_mono h23
have key : μ s₃ ≤ μ s₁ :=
calc
μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)]
_ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _
_ = μ s₁ := by simp only [h_nulldiff, zero_add]
exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩
theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1
theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2
lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) :
μ sᶜ = μ Set.univ - μ s := by
rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs]
theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s :=
measure_compl₀ h₁.nullMeasurableSet h_fin
lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null']; rwa [← diff_eq]
lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null ht]
@[simp]
theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by
rw [ae_le_set]
refine
⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h =>
eventuallyLE_antisymm_iff.mpr
⟨by rwa [ae_le_set, union_diff_left],
HasSubset.Subset.eventuallyLE subset_union_left⟩⟩
@[simp]
theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by
rw [union_comm, union_ae_eq_left_iff_ae_subset]
theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s)
(hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by
refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩
replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁)
replace ht : μ s ≠ ∞ := h₂ ▸ ht
rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self]
/-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/
theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ)
(ht : μ t ≠ ∞) : s =ᵐ[μ] t :=
ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht
theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α}
(hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by
refine le_antisymm (by gcongr; apply hsub) ?_
rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop)
· calc
μ (⋃ i, t i) ≤ ∞ := le_top
_ ≤ μ (s i) := hi ▸ h_le i
_ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _
push_neg at htop
set M := toMeasurable μ
have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by
refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_
· calc
μ (M (t b)) = μ (t b) := measure_toMeasurable _
_ ≤ μ (s b) := h_le b
_ ≤ μ (M (t b) ∩ M (⋃ b, s b)) :=
measure_mono <|
subset_inter ((hsub b).trans <| subset_toMeasurable _ _)
((subset_iUnion _ _).trans <| subset_toMeasurable _ _)
· measurability
· rw [measure_toMeasurable]
exact htop b
calc
μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _)
_ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm
_ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right)
_ = μ (⋃ b, s b) := measure_toMeasurable _
theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁)
(ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by
rw [union_eq_iUnion, union_eq_iUnion]
exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩)
@[simp]
theorem measure_iUnion_toMeasurable {ι : Sort*} [Countable ι] (s : ι → Set α) :
μ (⋃ i, toMeasurable μ (s i)) = μ (⋃ i, s i) :=
Eq.symm <| measure_iUnion_congr_of_subset (fun _i => subset_toMeasurable _ _) fun _i ↦
(measure_toMeasurable _).le
theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) :
μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable]
@[simp]
theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl
le_rfl
@[simp]
theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _)
(measure_toMeasurable _).le
theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α}
(h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) :
(∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by
rw [← measure_biUnion_finset₀ H h]
exact measure_mono (subset_univ _)
theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : Pairwise (AEDisjoint μ on s)) : ∑' i, μ (s i) ≤ μ (univ : Set α) := by
rw [ENNReal.tsum_eq_iSup_sum]
exact iSup_le fun s =>
sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α}
(μ : Measure α) {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by
contrapose! H
apply tsum_measure_le_measure_univ hs
intro i j hij
exact (disjoint_iff_inter_eq_empty.mpr (H i j hij)).aedisjoint
/-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and
`∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α)
{s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ)
(H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) :
∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by
contrapose! H
apply sum_measure_le_measure_univ h
intro i hi j hj hij
exact (disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)).aedisjoint
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `t` is measurable. -/
theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [← Set.not_disjoint_iff_nonempty_inter]
contrapose! h
calc
μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm
_ ≤ μ u := measure_mono (union_subset h's h't)
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `s` is measurable. -/
theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [add_comm] at h
rw [inter_comm]
exact nonempty_inter_of_measure_lt_add μ hs h't h's h
/-- Continuity from below:
the measure of the union of a directed sequence of (not necessarily measurable) sets
is the supremum of the measures. -/
theorem _root_.Directed.measure_iUnion [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
-- WLOG, `ι = ℕ`
rcases Countable.exists_injective_nat ι with ⟨e, he⟩
generalize ht : Function.extend e s ⊥ = t
replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot he
suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by
simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot he,
Function.comp_def, Pi.bot_apply, bot_eq_empty, measure_empty] at this
exact this.trans (iSup_extend_bot he _)
clear! ι
-- The `≥` inequality is trivial
refine le_antisymm ?_ (iSup_le fun i ↦ measure_mono <| subset_iUnion _ _)
-- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T`
set T : ℕ → Set α := fun n => toMeasurable μ (t n)
set Td : ℕ → Set α := disjointed T
have hm : ∀ n, MeasurableSet (Td n) := .disjointed fun n ↦ measurableSet_toMeasurable _ _
calc
μ (⋃ n, t n) = μ (⋃ n, Td n) := by rw [iUnion_disjointed, measure_iUnion_toMeasurable]
_ ≤ ∑' n, μ (Td n) := measure_iUnion_le _
_ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum
_ ≤ ⨆ n, μ (t n) := iSup_le fun I => by
rcases hd.finset_le I with ⟨N, hN⟩
calc
(∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) :=
(measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm
_ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _)
_ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _
_ ≤ μ (t N) := measure_mono (iUnion₂_subset hN)
_ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N
/-- Continuity from below:
the measure of the union of a monotone family of sets is equal to the supremum of their measures.
The theorem assumes that the `atTop` filter on the index set is countably generated,
so it works for a family indexed by a countable type, as well as `ℝ`. -/
theorem _root_.Monotone.measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
cases isEmpty_or_nonempty ι with
| inl _ => simp
| inr _ =>
rcases exists_seq_monotone_tendsto_atTop_atTop ι with ⟨x, hxm, hx⟩
rw [← hs.iUnion_comp_tendsto_atTop hx, ← Monotone.iSup_comp_tendsto_atTop _ hx]
exacts [(hs.comp hxm).directed_le.measure_iUnion, fun _ _ h ↦ measure_mono (hs h)]
theorem _root_.Antitone.measure_iUnion [Preorder ι] [IsDirected ι (· ≥ ·)]
[(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) :=
hs.dual_left.measure_iUnion
/-- Continuity from below: the measure of the union of a sequence of
(not necessarily measurable) sets is the supremum of the measures of the partial unions. -/
theorem measure_iUnion_eq_iSup_accumulate [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {f : ι → Set α} :
μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by
rw [← iUnion_accumulate]
exact monotone_accumulate.measure_iUnion
theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable)
(hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, hd.directed_val.measure_iUnion, ← iSup_subtype'']
/-- **Continuity from above**:
the measure of the intersection of a directed downwards countable family of measurable sets
is the infimum of the measures. -/
theorem _root_.Directed.measure_iInter [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) := by
rcases hfin with ⟨k, hk⟩
have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht)
rw [← ENNReal.sub_sub_cancel hk (iInf_le (fun i => μ (s i)) k), ENNReal.sub_iInf, ←
ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ←
measure_diff (iInter_subset _ k) (.iInter h) (this _ (iInter_subset _ k)),
diff_iInter, Directed.measure_iUnion]
· congr 1
refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => le_measure_diff)
rcases hd i k with ⟨j, hji, hjk⟩
use j
rw [← measure_diff hjk (h _) (this _ hjk)]
gcongr
· exact hd.mono_comp _ fun _ _ => diff_subset_diff_right
/-- **Continuity from above**:
the measure of the intersection of a monotone family of measurable sets
indexed by a type with countably generated `atBot` filter
is equal to the infimum of the measures. -/
theorem _root_.Monotone.measure_iInter [Preorder ι] [IsDirected ι (· ≥ ·)]
[(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s)
(hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) := by
refine le_antisymm (le_iInf fun i ↦ measure_mono <| iInter_subset _ _) ?_
have := hfin.nonempty
rcases exists_seq_antitone_tendsto_atTop_atBot ι with ⟨x, hxm, hx⟩
calc
⨅ i, μ (s i) ≤ ⨅ n, μ (s (x n)) := le_iInf_comp (μ ∘ s) x
_ = μ (⋂ n, s (x n)) := by
refine .symm <| (hs.comp_antitone hxm).directed_ge.measure_iInter (fun n ↦ hsm _) ?_
rcases hfin with ⟨k, hk⟩
rcases (hx.eventually_le_atBot k).exists with ⟨n, hn⟩
exact ⟨n, ne_top_of_le_ne_top hk <| measure_mono <| hs hn⟩
_ ≤ μ (⋂ i, s i) := by
refine measure_mono <| iInter_mono' fun i ↦ ?_
rcases (hx.eventually_le_atBot i).exists with ⟨n, hn⟩
exact ⟨n, hs hn⟩
/-- **Continuity from above**:
the measure of the intersection of an antitone family of measurable sets
indexed by a type with countably generated `atTop` filter
is equal to the infimum of the measures. -/
theorem _root_.Antitone.measure_iInter [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s)
(hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) :=
hs.dual_left.measure_iInter hsm hfin
/-- Continuity from above: the measure of the intersection of a sequence of
measurable sets is the infimum of the measures of the partial intersections. -/
theorem measure_iInter_eq_iInf_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α}
{μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)]
{f : ι → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (hfin : ∃ i, μ (f i) ≠ ∞) :
μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by
rw [← Antitone.measure_iInter]
· rw [iInter_comm]
exact congrArg μ <| iInter_congr fun i ↦ (biInf_const nonempty_Ici).symm
· exact fun i j h ↦ biInter_mono (Iic_subset_Iic.2 h) fun _ _ ↦ Set.Subset.rfl
· exact fun i ↦ .biInter (to_countable _) fun _ _ ↦ h _
· refine hfin.imp fun k hk ↦ ne_top_of_le_ne_top hk <| measure_mono <| iInter₂_subset k ?_
rfl
/-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily
measurable) sets is the limit of the measures. -/
theorem tendsto_measure_iUnion_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)]
{s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [hm.measure_iUnion]
exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm
theorem tendsto_measure_iUnion_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)]
{s : ι → Set α} (hm : Antitone s) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋃ n, s n))) :=
tendsto_measure_iUnion_atTop (ι := ιᵒᵈ) hm.dual_left
/-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable)
sets is the limit of the measures of the partial unions. -/
theorem tendsto_measure_iUnion_accumulate {α ι : Type*}
[Preorder ι] [IsCountablyGenerated (atTop : Filter ι)]
{_ : MeasurableSpace α} {μ : Measure α} {f : ι → Set α} :
Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [measure_iUnion_eq_iSup_accumulate]
exact tendsto_atTop_iSup fun i j hij ↦ by gcongr
/-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable
sets is the limit of the measures. -/
theorem tendsto_measure_iInter_atTop [Preorder ι]
[IsCountablyGenerated (atTop : Filter ι)] {s : ι → Set α}
(hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) :
Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [hm.measure_iInter hs hf]
exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm
/-- Continuity from above: the measure of the intersection of an increasing sequence of measurable
sets is the limit of the measures. -/
theorem tendsto_measure_iInter_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)]
{s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Monotone s)
(hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋂ n, s n))) :=
tendsto_measure_iInter_atTop (ι := ιᵒᵈ) hs hm.dual_left hf
/-- Continuity from above: the measure of the intersection of a sequence of measurable
sets such that one has finite measure is the limit of the measures of the partial intersections. -/
theorem tendsto_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[Countable ι] [Preorder ι] {f : ι → Set α} (hm : ∀ i, NullMeasurableSet (f i) μ)
(hf : ∃ i, μ (f i) ≠ ∞) :
Tendsto (fun i ↦ μ (⋂ j ≤ i, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by
refine .of_neBot_imp fun hne ↦ ?_
cases atTop_neBot_iff.mp hne
rw [measure_iInter_eq_iInf_measure_iInter_le hm hf]
exact tendsto_atTop_iInf
fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij
/-- Some version of continuity of a measure in the empty set using the intersection along a set of
sets. -/
theorem exists_measure_iInter_lt {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α}
[SemilatticeSup ι] [Countable ι] {f : ι → Set α}
(hm : ∀ i, NullMeasurableSet (f i) μ) {ε : ℝ≥0∞} (hε : 0 < ε) (hfin : ∃ i, μ (f i) ≠ ∞)
(hfem : ⋂ n, f n = ∅) : ∃ m, μ (⋂ n ≤ m, f n) < ε := by
let F m := μ (⋂ n ≤ m, f n)
have hFAnti : Antitone F :=
fun i j hij => measure_mono (biInter_subset_biInter_left fun k hki => le_trans hki hij)
suffices Filter.Tendsto F Filter.atTop (𝓝 0) by
rw [@ENNReal.tendsto_atTop_zero_iff_lt_of_antitone
_ (nonempty_of_exists hfin) _ _ hFAnti] at this
exact this ε hε
have hzero : μ (⋂ n, f n) = 0 := by
simp only [hfem, measure_empty]
rw [← hzero]
exact tendsto_measure_iInter_le hm hfin
/-- The measure of the intersection of a decreasing sequence of measurable
sets indexed by a linear order with first countable topology is the limit of the measures. -/
theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι]
[OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α}
{a : ι} (hs : ∀ r > a, NullMeasurableSet (s r) μ) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j)
(hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by
have : (atBot : Filter (Ioi a)).IsCountablyGenerated := by
rw [← comap_coe_Ioi_nhdsGT]
infer_instance
simp_rw [← map_coe_Ioi_atBot, tendsto_map'_iff, ← mem_Ioi, biInter_eq_iInter]
apply tendsto_measure_iInter_atBot
· rwa [Subtype.forall]
· exact fun i j h ↦ hm i j i.2 h
· simpa only [Subtype.exists, exists_prop]
theorem measure_if {x : β} {t : Set β} {s : Set α} [Decidable (x ∈ t)] :
μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h]
end
section OuterMeasure
variable [ms : MeasurableSpace α] {s t : Set α}
/-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are
Carathéodory measurable. -/
def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α :=
Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd =>
m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd
theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory :=
fun _s hs _t => (measure_inter_add_diff _ hs).symm
@[simp]
theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) :
(m.toMeasure h).toOuterMeasure = m.trim :=
rfl
@[simp]
theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α}
(hs : MeasurableSet s) : m.toMeasure h s = m s :=
m.trim_eq hs
theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) :
m s ≤ m.toMeasure h s :=
m.le_trim s
theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α}
(hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by
refine le_antisymm ?_ (le_toMeasure_apply _ _ _)
rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩
calc
m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm
_ = m t := toMeasure_apply m h htm
_ ≤ m s := m.mono hts
@[simp]
theorem toOuterMeasure_toMeasure {μ : Measure α} :
μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ :=
Measure.ext fun _s => μ.toOuterMeasure.trim_eq
@[simp]
theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure :=
μ.toOuterMeasure.boundedBy_eq_self
end OuterMeasure
section
variable {m0 : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable),
then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/
theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u)
(htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by
rw [h] at ht_ne_top
refine le_antisymm (by gcongr) ?_
have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) :=
calc
μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs
_ = μ t := h.symm
_ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm
_ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr
have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne
exact ENNReal.le_of_add_le_add_right B A
/-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`)
satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`.
Here, we require that the measure of `t` is finite. The conclusion holds without this assumption
when the measure is s-finite (for example when it is σ-finite),
see `measure_toMeasurable_inter_of_sFinite`. -/
theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) :
μ (toMeasurable μ t ∩ s) = μ (t ∩ s) :=
(measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t)
ht).symm
/-! ### The `ℝ≥0∞`-module of measures -/
instance instZero {_ : MeasurableSpace α} : Zero (Measure α) :=
⟨{ toOuterMeasure := 0
m_iUnion := fun _f _hf _hd => tsum_zero.symm
trim_le := OuterMeasure.trim_zero.le }⟩
@[simp]
theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 :=
rfl
@[simp, norm_cast]
theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 :=
rfl
@[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_zero
[ms : MeasurableSpace α] (h : ms ≤ (0 : OuterMeasure α).caratheodory) :
(0 : OuterMeasure α).toMeasure h = 0 := by
ext s hs
simp [hs]
@[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_eq_zero {ms : MeasurableSpace α}
{μ : OuterMeasure α} (h : ms ≤ μ.caratheodory) : μ.toMeasure h = 0 ↔ μ = 0 where
mp hμ := by ext s; exact le_bot_iff.1 <| (le_toMeasure_apply _ _ _).trans_eq congr($hμ s)
mpr := by rintro rfl; simp
@[nontriviality]
lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) :
μ s = 0 := by
rw [eq_empty_of_isEmpty s, measure_empty]
instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) :=
⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩
theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 :=
Subsingleton.elim μ 0
instance instInhabited {_ : MeasurableSpace α} : Inhabited (Measure α) :=
⟨0⟩
instance instAdd {_ : MeasurableSpace α} : Add (Measure α) :=
⟨fun μ₁ μ₂ =>
{ toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure
m_iUnion := fun s hs hd =>
show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by
rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs]
trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩
@[simp]
theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) :
(μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure :=
rfl
@[simp, norm_cast]
theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ :=
rfl
theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) :
(μ₁ + μ₂) s = μ₁ s + μ₂ s :=
rfl
section SMul
variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞]
instance instSMul {_ : MeasurableSpace α} : SMul R (Measure α) :=
⟨fun c μ =>
{ toOuterMeasure := c • μ.toOuterMeasure
m_iUnion := fun s hs hd => by
simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul,
measure_iUnion hd hs]
trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩
@[simp]
theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) :
(c • μ).toOuterMeasure = c • μ.toOuterMeasure :=
rfl
@[simp, norm_cast]
theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ :=
rfl
@[simp]
theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) :
(c • μ) s = c • μ s :=
rfl
instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] {_ : MeasurableSpace α} :
SMulCommClass R R' (Measure α) :=
⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩
instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] {_ : MeasurableSpace α} :
IsScalarTower R R' (Measure α) :=
⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩
instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] {_ : MeasurableSpace α} :
IsCentralScalar R (Measure α) :=
⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩
end SMul
instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where
eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h
instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{_ : MeasurableSpace α} : MulAction R (Measure α) :=
Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure
instance instAddCommMonoid {_ : MeasurableSpace α} : AddCommMonoid (Measure α) :=
toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure
fun _ _ => smul_toOuterMeasure _ _
/-- Coercion to function as an additive monoid homomorphism. -/
def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where
toFun := (⇑)
map_zero' := coe_zero
map_add' := coe_add
@[simp]
theorem coeAddHom_apply {_ : MeasurableSpace α} (μ : Measure α) : coeAddHom μ = ⇑μ := rfl
@[simp]
theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) :
⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I
theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) :
(∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply]
instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{_ : MeasurableSpace α} : DistribMulAction R (Measure α) :=
Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩
toOuterMeasure_injective smul_toOuterMeasure
instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
{_ : MeasurableSpace α} : Module R (Measure α) :=
Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩
toOuterMeasure_injective smul_toOuterMeasure
@[simp]
theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) :
(c • μ) s = c * μ s :=
rfl
@[simp]
theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) :
c • μ s = c * μ s := by
rfl
theorem ae_smul_measure {p : α → Prop} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : ∀ᵐ x ∂μ, p x) (c : R) : ∀ᵐ x ∂c • μ, p x :=
ae_iff.2 <| by rw [smul_apply, ae_iff.1 h, ← smul_one_smul ℝ≥0∞, smul_zero]
theorem ae_smul_measure_le [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) :
ae (c • μ) ≤ ae μ := fun _ h ↦ ae_smul_measure h c
section SMulWithZero
variable {R : Type*} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
[NoZeroSMulDivisors R ℝ≥0∞] {c : R} {p : α → Prop}
lemma ae_smul_measure_iff (hc : c ≠ 0) {μ : Measure α} : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by
simp [ae_iff, hc]
@[simp] lemma ae_smul_measure_eq (hc : c ≠ 0) (μ : Measure α) : ae (c • μ) = ae μ := by
ext; exact ae_smul_measure_iff hc
end SMulWithZero
theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t)
(h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by
refine le_antisymm (measure_mono h') ?_
have : μ t + ν t ≤ μ s + ν t :=
calc
μ t + ν t = μ s + ν s := h''.symm
_ ≤ μ s + ν t := by gcongr
apply ENNReal.le_of_add_le_add_right _ this
exact ne_top_of_le_ne_top h (le_add_left le_rfl)
theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t)
(h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by
rw [add_comm] at h'' h
exact measure_eq_left_of_subset_of_measure_add_eq h h' h''
theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s)
(ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by
refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm
· refine
measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _)
(measure_toMeasurable t).symm
rwa [measure_toMeasurable t]
· simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht
exact ht.1
theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s)
(ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by
rw [add_comm] at ht ⊢
exact measure_toMeasurable_add_inter_left hs ht
/-! ### The complete lattice of measures -/
/-- Measures are partially ordered. -/
instance instPartialOrder {_ : MeasurableSpace α} : PartialOrder (Measure α) where
le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s
le_refl _ _ := le_rfl
le_trans _ _ _ h₁ h₂ s := le_trans (h₁ s) (h₂ s)
le_antisymm _ _ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s)
theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl
theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff
theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ :=
le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs)
theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl
theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s :=
lt_iff_le_not_le.trans <|
and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop]
theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s :=
lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le]
instance instAddLeftMono {_ : MeasurableSpace α} : AddLeftMono (Measure α) :=
⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩
protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s)
protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s)
section sInf
variable {m : Set (Measure α)}
theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) :
MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by
rw [OuterMeasure.sInf_eq_boundedBy_sInfGen]
refine OuterMeasure.boundedBy_caratheodory fun t => ?_
simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t,
coe_toOuterMeasure]
intro μ hμ u htu _hu
have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by
intro s t hst
rw [OuterMeasure.sInfGen_def, iInf_image]
exact iInf₂_le_of_le μ hμ <| measure_mono hst
rw [← measure_inter_add_diff u hs]
exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu)
instance {_ : MeasurableSpace α} : InfSet (Measure α) :=
⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩
theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s :=
toMeasure_apply _ _ hs
private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ :=
have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h)
le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s
private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m :=
have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) :=
le_sInf <| forall_mem_image.2 fun _ hμ ↦ toOuterMeasure_le.2 <| h _ hμ
le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s
instance instCompleteSemilatticeInf {_ : MeasurableSpace α} : CompleteSemilatticeInf (Measure α) :=
{ (by infer_instance : PartialOrder (Measure α)),
(by infer_instance : InfSet (Measure α)) with
sInf_le := fun _s _a => measure_sInf_le
le_sInf := fun _s _a => measure_le_sInf }
instance instCompleteLattice {_ : MeasurableSpace α} : CompleteLattice (Measure α) :=
{ completeLatticeOfCompleteSemilatticeInf (Measure α) with
top :=
{ toOuterMeasure := ⊤,
m_iUnion := by
intro f _ _
refine (measure_iUnion_le _).antisymm ?_
if hne : (⋃ i, f i).Nonempty then
rw [OuterMeasure.top_apply hne]
exact le_top
else
simp_all [Set.not_nonempty_iff_eq_empty]
trim_le := le_top },
le_top := fun _ => toOuterMeasure_le.mp le_top
bot := 0
bot_le := fun _a _s => bot_le }
end sInf
lemma inf_apply {s : Set α} (hs : MeasurableSet s) :
(μ ⊓ ν) s = sInf {m | ∃ t, m = μ (t ∩ s) + ν (tᶜ ∩ s)} := by
-- `(μ ⊓ ν) s` is defined as `⊓ (t : ℕ → Set α) (ht : s ⊆ ⋃ n, t n), ∑' n, μ (t n) ⊓ ν (t n)`
rw [← sInf_pair, Measure.sInf_apply hs, OuterMeasure.sInf_apply
(image_nonempty.2 <| insert_nonempty μ {ν})]
refine le_antisymm (le_sInf fun m ⟨t, ht₁⟩ ↦ ?_) (le_iInf₂ fun t' ht' ↦ ?_)
· subst ht₁
-- We first show `(μ ⊓ ν) s ≤ μ (t ∩ s) + ν (tᶜ ∩ s)` for any `t : Set α`
-- For this, define the sequence `t' : ℕ → Set α` where `t' 0 = t ∩ s`, `t' 1 = tᶜ ∩ s` and
-- `∅` otherwise. Then, we have by construction
-- `(μ ⊓ ν) s ≤ ∑' n, μ (t' n) ⊓ ν (t' n) ≤ μ (t' 0) + ν (t' 1) = μ (t ∩ s) + ν (tᶜ ∩ s)`.
set t' : ℕ → Set α := fun n ↦ if n = 0 then t ∩ s else if n = 1 then tᶜ ∩ s else ∅ with ht'
refine (iInf₂_le t' fun x hx ↦ ?_).trans ?_
· by_cases hxt : x ∈ t
· refine mem_iUnion.2 ⟨0, ?_⟩
simp [hx, hxt]
· refine mem_iUnion.2 ⟨1, ?_⟩
simp [hx, hxt]
· simp only [iInf_image, coe_toOuterMeasure, iInf_pair]
rw [tsum_eq_add_tsum_ite 0, tsum_eq_add_tsum_ite 1, if_neg zero_ne_one.symm,
ENNReal.summable.tsum_eq_zero_iff.2 _, add_zero]
· exact add_le_add (inf_le_left.trans <| by simp [ht']) (inf_le_right.trans <| by simp [ht'])
· simp only [ite_eq_left_iff]
intro n hn₁ hn₀
simp only [ht', if_neg hn₀, if_neg hn₁, measure_empty, iInf_pair, le_refl, inf_of_le_left]
· simp only [iInf_image, coe_toOuterMeasure, iInf_pair]
-- Conversely, fixing `t' : ℕ → Set α` such that `s ⊆ ⋃ n, t' n`, we construct `t : Set α`
-- for which `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n)`.
-- Denoting `I := {n | μ (t' n) ≤ ν (t' n)}`, we set `t = ⋃ n ∈ I, t' n`.
-- Clearly `μ (t ∩ s) ≤ ∑' n ∈ I, μ (t' n)` and `ν (tᶜ ∩ s) ≤ ∑' n ∉ I, ν (t' n)`, so
-- `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n ∈ I, μ (t' n) + ∑' n ∉ I, ν (t' n)`
-- where the RHS equals `∑' n, μ (t' n) ⊓ ν (t' n)` by the choice of `I`.
set t := ⋃ n ∈ {k : ℕ | μ (t' k) ≤ ν (t' k)}, t' n with ht
suffices hadd : μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n) by
exact le_trans (sInf_le ⟨t, rfl⟩) hadd
have hle₁ : μ (t ∩ s) ≤ ∑' (n : {k | μ (t' k) ≤ ν (t' k)}), μ (t' n) :=
(measure_mono inter_subset_left).trans <| measure_biUnion_le _ (to_countable _) _
have hcap : tᶜ ∩ s ⊆ ⋃ n ∈ {k | ν (t' k) < μ (t' k)}, t' n := by
simp_rw [ht, compl_iUnion]
refine fun x ⟨hx₁, hx₂⟩ ↦ mem_iUnion₂.2 ?_
obtain ⟨i, hi⟩ := mem_iUnion.1 <| ht' hx₂
refine ⟨i, ?_, hi⟩
by_contra h
simp only [mem_setOf_eq, not_lt] at h
exact mem_iInter₂.1 hx₁ i h hi
have hle₂ : ν (tᶜ ∩ s) ≤ ∑' (n : {k | ν (t' k) < μ (t' k)}), ν (t' n) :=
(measure_mono hcap).trans (measure_biUnion_le ν (to_countable {k | ν (t' k) < μ (t' k)}) _)
refine (add_le_add hle₁ hle₂).trans ?_
have heq : {k | μ (t' k) ≤ ν (t' k)} ∪ {k | ν (t' k) < μ (t' k)} = univ := by
ext k; simp [le_or_lt]
conv in ∑' (n : ℕ), μ (t' n) ⊓ ν (t' n) => rw [← tsum_univ, ← heq]
rw [ENNReal.summable.tsum_union_disjoint (f := fun n ↦ μ (t' n) ⊓ ν (t' n)) ?_ ENNReal.summable]
· refine add_le_add (tsum_congr ?_).le (tsum_congr ?_).le
· rw [Subtype.forall]
intro n hn; simpa
· rw [Subtype.forall]
intro n hn
rw [mem_setOf_eq] at hn
simp [le_of_lt hn]
· rw [Set.disjoint_iff]
rintro k ⟨hk₁, hk₂⟩
rw [mem_setOf_eq] at hk₁ hk₂
exact False.elim <| hk₂.not_le hk₁
@[simp]
theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top :
(⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) =
(⊤ : Measure α) :=
toOuterMeasure_toMeasure (μ := ⊤)
@[simp]
theorem toOuterMeasure_top {_ : MeasurableSpace α} :
(⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) :=
rfl
@[simp]
theorem top_add : ⊤ + μ = ⊤ :=
top_unique <| Measure.le_add_right le_rfl
@[simp]
theorem add_top : μ + ⊤ = ⊤ :=
top_unique <| Measure.le_add_left le_rfl
protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ :=
bot_le
theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 :=
μ.zero_le.le_iff_eq
@[simp]
theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 :=
⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h =>
h.symm ▸ rfl⟩
theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 :=
measure_univ_eq_zero.not
instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩
@[simp]
theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 :=
pos_iff_ne_zero.trans measure_univ_ne_zero
lemma nonempty_of_neZero (μ : Measure α) [NeZero μ] : Nonempty α :=
(isEmpty_or_nonempty α).resolve_left fun h ↦ by
simpa [eq_empty_of_isEmpty] using NeZero.ne (μ univ)
section Sum
variable {f : ι → Measure α}
/-- Sum of an indexed family of measures. -/
noncomputable def sum (f : ι → Measure α) : Measure α :=
(OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <|
le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _)
(OuterMeasure.le_sum_caratheodory _)
theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s :=
le_toMeasure_apply _ _ _
@[simp]
theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
sum f s = ∑' i, f i s :=
toMeasure_apply _ _ hs
theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) :
sum f s = ∑' i, f i s := by
apply le_antisymm ?_ (le_sum_apply _ _)
rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩
calc
sum f s = sum f t := measure_congr ht.symm
_ = ∑' i, f i t := sum_apply _ t_meas
_ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts
/-! For the next theorem, the countability assumption is necessary. For a counterexample, consider
an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets
not containing `x₀`, and their complements. All points but `x₀` are measurable.
Consider the sum of the Dirac masses at points different from `x₀`, and `s = {x₀}`. For any Dirac
mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure
`sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any
measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one gets
`sum δ_x {x₀} = ∞`.
-/
theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) :
sum f s = ∑' i, f i s := by
apply le_antisymm ?_ (le_sum_apply _ _)
rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩
calc
sum f s ≤ sum f t := measure_mono hst
_ = ∑' i, f i t := sum_apply _ htm
_ = ∑' i, f i s := by simp [ht]
theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ :=
le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i
@[simp]
theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} :
sum μ s = 0 ↔ ∀ i, μ i s = 0 := by
simp [sum_apply_of_countable]
theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) :
sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs]
@[simp] lemma sum_eq_zero : sum f = 0 ↔ ∀ i, f i = 0 := by
simp +contextual [Measure.ext_iff, forall_swap (α := ι)]
@[simp]
lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by
ext s hs
simp [Measure.sum_apply _ hs]
theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) :
(sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by
ext1 s hs
simp [sum_apply _ hs, ENNReal.tsum_prod']
theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) :
(sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by
ext1 s hs
simp_rw [sum_apply _ hs]
rw [ENNReal.tsum_comm]
theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} :
(∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x :=
sum_apply_eq_zero
theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) :
(∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x :=
sum_apply_eq_zero' h.compl
@[simp]
theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by
ext1 s hs
simp only [sum_apply, finset_sum_apply, hs, tsum_fintype]
theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) :
(sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ]
@[simp]
theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) :=
Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm
theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by
rw [sum_fintype, Fintype.sum_bool]
theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν :=
sum_bool _
@[simp]
theorem sum_of_isEmpty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by
rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty]
theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) :
((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by
ext1 t ht
simp only [add_apply, sum_apply _ ht]
exact ENNReal.summable.tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable
theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν :=
congr_arg sum (funext h)
theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by
ext1 s hs
simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add,
ENNReal.summable.tsum_add ENNReal.summable]
@[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) :
sum (m ∘ e) = sum m := by
ext s hs
simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s)
@[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) :
sum (Function.extend f m 0) = sum m := by
ext s hs
simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)]
end Sum
/-! ### The `cofinite` filter -/
/-- The filter of sets `s` such that `sᶜ` has finite measure. -/
def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α :=
comk (μ · < ∞) (by simp) (fun _ ht _ hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦
(measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩
theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ :=
Iff.rfl
theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ :=
Iff.rfl
instance cofinite.instIsMeasurablyGenerated : IsMeasurablyGenerated μ.cofinite where
exists_measurable_subset s hs := by
refine ⟨(toMeasurable μ sᶜ)ᶜ, ?_, (measurableSet_toMeasurable _ _).compl, ?_⟩
· rwa [compl_mem_cofinite, measure_toMeasurable]
· rw [compl_subset_comm]
apply subset_toMeasurable
end Measure
open Measure
open MeasureTheory
protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) :
NullMeasurable f μ :=
let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm
lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β}
(hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ :=
hf.nullMeasurable hs
@[simp]
theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by
rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero]
@[simp]
theorem ae_neBot : (ae μ).NeBot ↔ μ ≠ 0 :=
neBot_iff.trans (not_congr ae_eq_bot)
instance Measure.ae.neBot [NeZero μ] : (ae μ).NeBot := ae_neBot.2 <| NeZero.ne μ
@[simp]
theorem ae_zero {_m0 : MeasurableSpace α} : ae (0 : Measure α) = ⊥ :=
ae_eq_bot.2 rfl
section Intervals
theorem biSup_measure_Iic [Preorder α] {s : Set α} (hsc : s.Countable)
(hst : ∀ x : α, ∃ y ∈ s, x ≤ y) (hdir : DirectedOn (· ≤ ·) s) :
⨆ x ∈ s, μ (Iic x) = μ univ := by
| rw [← measure_biUnion_eq_iSup hsc]
· congr
simp only [← bex_def] at hst
| Mathlib/MeasureTheory/Measure/MeasureSpace.lean | 1,323 | 1,325 |
/-
Copyright (c) 2019 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Normed.Group.AddCircle
import Mathlib.Algebra.CharZero.Quotient
import Mathlib.Topology.Instances.Sign
/-!
# The type of angles
In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas
about trigonometric functions and angles.
-/
open Real
noncomputable section
namespace Real
/-- The type of angles -/
def Angle : Type :=
AddCircle (2 * π)
-- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
namespace Angle
instance : NormedAddCommGroup Angle :=
inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π)))
instance : Inhabited Angle :=
inferInstanceAs (Inhabited (AddCircle (2 * π)))
/-- The canonical map from `ℝ` to the quotient `Angle`. -/
@[coe]
protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r
instance : Coe ℝ Angle := ⟨Angle.coe⟩
instance : CircularOrder Real.Angle :=
QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩)
@[continuity]
theorem continuous_coe : Continuous ((↑) : ℝ → Angle) :=
continuous_quotient_mk'
/-- Coercion `ℝ → Angle` as an additive homomorphism. -/
def coeHom : ℝ →+ Angle :=
QuotientAddGroup.mk' _
@[simp]
theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) :=
rfl
/-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with
`induction θ using Real.Angle.induction_on`. -/
@[elab_as_elim]
protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ :=
Quotient.inductionOn' θ h
@[simp]
theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) :=
rfl
@[simp]
theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) :=
rfl
@[simp]
theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) :=
rfl
@[simp]
theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) :=
rfl
theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) :=
rfl
theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) :=
rfl
theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x :=
AddCircle.coe_eq_zero_iff (2 * π)
@[simp, norm_cast]
theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by
simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n
@[simp, norm_cast]
theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by
simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n
theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by
simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
rw [Angle.coe, Angle.coe, QuotientAddGroup.eq]
simp only [AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
@[simp]
theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) :=
angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩
@[simp]
theorem neg_coe_pi : -(π : Angle) = π := by
rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub]
use -1
simp [two_mul, sub_eq_add_neg]
@[simp]
theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_nsmul, two_nsmul, add_halves]
@[simp]
theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_zsmul, two_zsmul, add_halves]
theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by
rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi]
theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by
rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two]
theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by
rw [sub_eq_add_neg, neg_coe_pi]
@[simp]
theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul]
@[simp]
theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul]
@[simp]
theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi]
theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) :=
QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz
theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) :=
QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz
theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
have : Int.natAbs 2 = 2 := rfl
rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero,
Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two,
mul_div_cancel_left₀ (_ : ℝ) two_ne_zero]
theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff]
theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
convert two_nsmul_eq_iff <;> simp
theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_nsmul_eq_zero_iff]
theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff]
theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_zsmul_eq_zero_iff]
theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by
rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff]
theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← eq_neg_self_iff.not]
theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff]
theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← neg_eq_self_iff.not]
theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves]
nth_rw 1 [h]
rw [coe_nsmul, two_nsmul_eq_iff]
-- Porting note: `congr` didn't simplify the goal of iff of `Or`s
convert Iff.rfl
rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc,
add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero]
theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff]
theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} :
cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by
constructor
· intro Hcos
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos
rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩)
· right
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul,
mul_comm, coe_two_pi, zsmul_zero]
· left
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn
rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero,
zero_add]
· rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero]
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul]
theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by
constructor
· intro Hsin
rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin
rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h
· left
rw [coe_sub, coe_sub] at h
exact sub_right_inj.1 h
right
rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add,
add_halves, sub_sub, sub_eq_zero] at h
exact h.symm
· rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul]
have H' : θ + ψ = 2 * k * π + π := by
rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←
mul_assoc] at H
rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero]
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by
rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; · exact hc
rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; · exact hs
rw [eq_neg_iff_add_eq_zero, hs] at hc
obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc)
rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero,
eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one,
← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn
have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn
rw [add_comm, Int.add_mul_emod_self_right] at this
exact absurd this one_ne_zero
/-- The sine of a `Real.Angle`. -/
def sin (θ : Angle) : ℝ :=
sin_periodic.lift θ
@[simp]
theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x :=
rfl
@[continuity]
theorem continuous_sin : Continuous sin :=
Real.continuous_sin.quotient_liftOn' _
/-- The cosine of a `Real.Angle`. -/
def cos (θ : Angle) : ℝ :=
cos_periodic.lift θ
@[simp]
theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x :=
rfl
@[continuity]
theorem continuous_cos : Continuous cos :=
Real.continuous_cos.quotient_liftOn' _
theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} :
cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction θ using Real.Angle.induction_on
exact cos_eq_iff_coe_eq_or_eq_neg
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction ψ using Real.Angle.induction_on
exact cos_eq_real_cos_iff_eq_or_eq_neg
theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} :
sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction θ using Real.Angle.induction_on
exact sin_eq_iff_coe_eq_or_add_eq_pi
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction ψ using Real.Angle.induction_on
exact sin_eq_real_sin_iff_eq_or_add_eq_pi
@[simp]
theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero]
theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi]
theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by
nth_rw 1 [← sin_zero]
rw [sin_eq_iff_eq_or_add_eq_pi]
simp
theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← sin_eq_zero_iff]
@[simp]
theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_neg _
theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.sin_antiperiodic _
@[simp]
theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ :=
sin_antiperiodic θ
@[simp]
theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ :=
sin_antiperiodic.sub_eq θ
@[simp]
theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero]
theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi]
@[simp]
theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_neg _
theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.cos_antiperiodic _
@[simp]
theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ :=
cos_antiperiodic θ
@[simp]
theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ :=
cos_antiperiodic.sub_eq θ
theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div]
theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by
induction θ₁ using Real.Angle.induction_on
induction θ₂ using Real.Angle.induction_on
exact Real.sin_add _ _
theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by
induction θ₂ using Real.Angle.induction_on
induction θ₁ using Real.Angle.induction_on
exact Real.cos_add _ _
@[simp]
theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by
induction θ using Real.Angle.induction_on
exact Real.cos_sq_add_sin_sq _
theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_add_pi_div_two _
theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_sub_pi_div_two _
theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_pi_div_two_sub _
theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_add_pi_div_two _
theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_sub_pi_div_two _
theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_pi_div_two_sub _
theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) :
|sin θ| = |sin ψ| := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· rw [sin_add_pi, abs_neg]
theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) :
|sin θ| = |sin ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_sin_eq_of_two_nsmul_eq h
theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) :
|cos θ| = |cos ψ| := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· rw [cos_add_pi, abs_neg]
theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) :
|cos θ| = |cos ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_cos_eq_of_two_nsmul_eq h
@[simp]
theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub]
refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩
rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm]
@[simp]
theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub]
refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩
rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm]
/-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/
def toReal (θ : Angle) : ℝ :=
(toIocMod_periodic two_pi_pos (-π)).lift θ
theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ :=
rfl
theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by
rw [toReal_coe, toIocMod_eq_self two_pi_pos]
ring_nf
rfl
theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by
rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc]
theorem toReal_injective : Function.Injective toReal := by
intro θ ψ h
induction θ using Real.Angle.induction_on
induction ψ using Real.Angle.induction_on
simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ←
angle_eq_iff_two_pi_dvd_sub, eq_comm] using h
@[simp]
theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ :=
toReal_injective.eq_iff
| @[simp]
theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by
induction θ using Real.Angle.induction_on
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean | 454 | 456 |
/-
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, Mitchell Lee
-/
import Mathlib.Algebra.BigOperators.Finprod
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Algebra.Group.ULift
import Mathlib.Order.Filter.Pointwise
import Mathlib.Topology.Algebra.MulAction
import Mathlib.Topology.ContinuousMap.Defs
import Mathlib.Topology.Algebra.Monoid.Defs
/-!
# Theory of topological monoids
In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many
applications the underlying type is a monoid (multiplicative or additive), we do not require this in
the definitions.
-/
universe u v
open Set Filter TopologicalSpace Topology
open scoped Topology Pointwise
variable {ι α M N X : Type*} [TopologicalSpace X]
@[to_additive (attr := continuity, fun_prop)]
theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X → M) :=
@continuous_const _ _ _ _ 1
section ContinuousMul
variable [TopologicalSpace M] [Mul M] [ContinuousMul M]
@[to_additive]
instance : ContinuousMul Mᵒᵈ :=
‹ContinuousMul M›
@[to_additive]
instance : ContinuousMul (ULift.{u} M) := by
constructor
apply continuous_uliftUp.comp
exact continuous_mul.comp₂ (continuous_uliftDown.comp continuous_fst)
(continuous_uliftDown.comp continuous_snd)
@[to_additive]
instance ContinuousMul.to_continuousSMul : ContinuousSMul M M :=
⟨continuous_mul⟩
@[to_additive]
instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mᵐᵒᵖ M :=
⟨show Continuous ((fun p : M × M => p.1 * p.2) ∘ Prod.swap ∘ Prod.map MulOpposite.unop id) from
continuous_mul.comp <|
continuous_swap.comp <| Continuous.prodMap MulOpposite.continuous_unop continuous_id⟩
@[to_additive]
theorem ContinuousMul.induced {α : Type*} {β : Type*} {F : Type*} [FunLike F α β] [Mul α]
[Mul β] [MulHomClass F α β] [tβ : TopologicalSpace β] [ContinuousMul β] (f : F) :
@ContinuousMul α (tβ.induced f) _ := by
let tα := tβ.induced f
refine ⟨continuous_induced_rng.2 ?_⟩
simp only [Function.comp_def, map_mul]
fun_prop
@[to_additive (attr := continuity)]
theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b :=
continuous_const.mul continuous_id
@[to_additive (attr := continuity)]
theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a :=
continuous_id.mul continuous_const
@[to_additive]
theorem tendsto_mul {a b : M} : Tendsto (fun p : M × M => p.fst * p.snd) (𝓝 (a, b)) (𝓝 (a * b)) :=
continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b)
@[to_additive]
theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : α → M} {l : Filter α}
(h : Tendsto (fun k : α => f k) l (𝓝 c)) : Tendsto (fun k : α => b * f k) l (𝓝 (b * c)) :=
tendsto_const_nhds.mul h
@[to_additive]
theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : α → M} {l : Filter α}
(h : Tendsto (fun k : α => f k) l (𝓝 c)) : Tendsto (fun k : α => f k * b) l (𝓝 (c * b)) :=
h.mul tendsto_const_nhds
@[to_additive]
theorem le_nhds_mul (a b : M) : 𝓝 a * 𝓝 b ≤ 𝓝 (a * b) := by
rw [← map₂_mul, ← map_uncurry_prod, ← nhds_prod_eq]
exact continuous_mul.tendsto _
@[to_additive (attr := simp)]
theorem nhds_one_mul_nhds {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) :
𝓝 (1 : M) * 𝓝 a = 𝓝 a :=
((le_nhds_mul _ _).trans_eq <| congr_arg _ (one_mul a)).antisymm <|
le_mul_of_one_le_left' <| pure_le_nhds 1
@[to_additive (attr := simp)]
theorem nhds_mul_nhds_one {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) :
𝓝 a * 𝓝 1 = 𝓝 a :=
((le_nhds_mul _ _).trans_eq <| congr_arg _ (mul_one a)).antisymm <|
le_mul_of_one_le_right' <| pure_le_nhds 1
section tendsto_nhds
variable {𝕜 : Type*} [Preorder 𝕜] [Zero 𝕜] [Mul 𝕜] [TopologicalSpace 𝕜] [ContinuousMul 𝕜]
{l : Filter α} {f : α → 𝕜} {b c : 𝕜} (hb : 0 < b)
include hb
theorem Filter.TendstoNhdsWithinIoi.const_mul [PosMulStrictMono 𝕜] [PosMulReflectLT 𝕜]
(h : Tendsto f l (𝓝[>] c)) : Tendsto (fun a => b * f a) l (𝓝[>] (b * c)) :=
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _
((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <|
(tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr
theorem Filter.TendstoNhdsWithinIio.const_mul [PosMulStrictMono 𝕜] [PosMulReflectLT 𝕜]
(h : Tendsto f l (𝓝[<] c)) : Tendsto (fun a => b * f a) l (𝓝[<] (b * c)) :=
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _
((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <|
(tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr
theorem Filter.TendstoNhdsWithinIoi.mul_const [MulPosStrictMono 𝕜] [MulPosReflectLT 𝕜]
(h : Tendsto f l (𝓝[>] c)) : Tendsto (fun a => f a * b) l (𝓝[>] (c * b)) :=
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _
((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <|
(tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr
theorem Filter.TendstoNhdsWithinIio.mul_const [MulPosStrictMono 𝕜] [MulPosReflectLT 𝕜]
(h : Tendsto f l (𝓝[<] c)) : Tendsto (fun a => f a * b) l (𝓝[<] (c * b)) :=
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _
((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <|
(tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr
end tendsto_nhds
@[to_additive]
protected theorem Specializes.mul {a b c d : M} (hab : a ⤳ b) (hcd : c ⤳ d) : (a * c) ⤳ (b * d) :=
hab.smul hcd
@[to_additive]
protected theorem Inseparable.mul {a b c d : M} (hab : Inseparable a b) (hcd : Inseparable c d) :
Inseparable (a * c) (b * d) :=
hab.smul hcd
@[to_additive]
protected theorem Specializes.pow {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M]
| {a b : M} (h : a ⤳ b) (n : ℕ) : (a ^ n) ⤳ (b ^ n) :=
Nat.recOn n (by simp only [pow_zero, specializes_rfl]) fun _ ihn ↦ by
simpa only [pow_succ] using ihn.mul h
| Mathlib/Topology/Algebra/Monoid.lean | 150 | 152 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Data.Subtype
import Mathlib.Order.Defs.LinearOrder
import Mathlib.Order.Notation
import Mathlib.Tactic.GCongr.Core
import Mathlib.Tactic.Spread
import Mathlib.Tactic.Convert
import Mathlib.Tactic.Inhabit
import Mathlib.Tactic.SimpRw
/-!
# Basic definitions about `≤` and `<`
This file proves basic results about orders, provides extensive dot notation, defines useful order
classes and allows to transfer order instances.
## Type synonyms
* `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`.
* `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using
`IsTotal α (≤)`.
### Transferring orders
- `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a
partial (resp., linear) order on `α` using an injective function `f`.
### Extra class
* `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such
that `a < c < b`.
## Notes
`≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all
lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares
us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.
Dot notation is particularly useful on `≤` (`LE.le`) and `<` (`LT.lt`). To that end, we
provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with
`LE.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`,
`hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct
`hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## Tags
preorder, order, partial order, poset, linear order, chain
-/
open Function
variable {ι α β : Type*} {π : ι → Type*}
/-! ### Bare relations -/
attribute [ext] LE
protected lemma LE.le.ge [LE α] {x y : α} (h : x ≤ y) : y ≥ x := h
protected lemma GE.ge.le [LE α] {x y : α} (h : x ≥ y) : y ≤ x := h
protected lemma LT.lt.gt [LT α] {x y : α} (h : x < y) : y > x := h
protected lemma GT.gt.lt [LT α] {x y : α} (h : x > y) : y < x := h
/-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined
by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f`
is injective). -/
@[simp]
def Order.Preimage (f : α → β) (s : β → β → Prop) (x y : α) : Prop := s (f x) (f y)
@[inherit_doc] infixl:80 " ⁻¹'o " => Order.Preimage
/-- The preimage of a decidable order is decidable. -/
instance Order.Preimage.decidable (f : α → β) (s : β → β → Prop) [H : DecidableRel s] :
DecidableRel (f ⁻¹'o s) := fun _ _ ↦ H _ _
/-! ### Preorders -/
section Preorder
variable [Preorder α] {a b c d : α}
theorem le_trans' : b ≤ c → a ≤ b → a ≤ c :=
flip le_trans
theorem lt_trans' : b < c → a < b → a < c :=
flip lt_trans
theorem lt_of_le_of_lt' : b ≤ c → a < b → a < c :=
flip lt_of_lt_of_le
theorem lt_of_lt_of_le' : b < c → a ≤ b → a < c :=
flip lt_of_le_of_lt
theorem le_of_le_of_eq' : b ≤ c → a = b → a ≤ c :=
flip le_of_eq_of_le
theorem le_of_eq_of_le' : b = c → a ≤ b → a ≤ c :=
flip le_of_le_of_eq
theorem lt_of_lt_of_eq' : b < c → a = b → a < c :=
flip lt_of_eq_of_lt
theorem lt_of_eq_of_lt' : b = c → a < b → a < c :=
flip lt_of_lt_of_eq
theorem not_lt_iff_not_le_or_ge : ¬a < b ↔ ¬a ≤ b ∨ b ≤ a := by
rw [lt_iff_le_not_le, Classical.not_and_iff_not_or_not, Classical.not_not]
-- Unnecessary brackets are here for readability
lemma not_lt_iff_le_imp_le : ¬ a < b ↔ (a ≤ b → b ≤ a) := by
simp [not_lt_iff_not_le_or_ge, or_iff_not_imp_left]
/-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used
almost exclusively in mathlib. -/
lemma ge_of_eq (h : a = b) : b ≤ a := le_of_eq h.symm
@[simp] lemma lt_self_iff_false (x : α) : x < x ↔ False := ⟨lt_irrefl x, False.elim⟩
alias LE.le.trans := le_trans
alias LE.le.trans' := le_trans'
alias LT.lt.trans := lt_trans
alias LT.lt.trans' := lt_trans'
alias LE.le.trans_lt := lt_of_le_of_lt
alias LE.le.trans_lt' := lt_of_le_of_lt'
alias LT.lt.trans_le := lt_of_lt_of_le
alias LT.lt.trans_le' := lt_of_lt_of_le'
alias LE.le.trans_eq := le_of_le_of_eq
alias LE.le.trans_eq' := le_of_le_of_eq'
alias LT.lt.trans_eq := lt_of_lt_of_eq
alias LT.lt.trans_eq' := lt_of_lt_of_eq'
alias Eq.trans_le := le_of_eq_of_le
alias Eq.trans_ge := le_of_eq_of_le'
alias Eq.trans_lt := lt_of_eq_of_lt
alias Eq.trans_gt := lt_of_eq_of_lt'
alias LE.le.lt_of_not_le := lt_of_le_not_le
alias LE.le.lt_or_eq_dec := Decidable.lt_or_eq_of_le
alias LT.lt.le := le_of_lt
alias LT.lt.ne := ne_of_lt
alias Eq.le := le_of_eq
@[inherit_doc ge_of_eq] alias Eq.ge := ge_of_eq
alias LT.lt.asymm := lt_asymm
alias LT.lt.not_lt := lt_asymm
theorem ne_of_not_le (h : ¬a ≤ b) : a ≠ b := fun hab ↦ h (le_of_eq hab)
protected lemma Eq.not_lt (hab : a = b) : ¬a < b := fun h' ↦ h'.ne hab
protected lemma Eq.not_gt (hab : a = b) : ¬b < a := hab.symm.not_lt
@[simp] lemma le_of_subsingleton [Subsingleton α] : a ≤ b := (Subsingleton.elim a b).le
-- Making this a @[simp] lemma causes confluence problems downstream.
lemma not_lt_of_subsingleton [Subsingleton α] : ¬a < b := (Subsingleton.elim a b).not_lt
namespace LT.lt
protected theorem false : a < a → False := lt_irrefl a
theorem ne' (h : a < b) : b ≠ a := h.ne.symm
end LT.lt
theorem le_of_forall_le (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b := H _ le_rfl
theorem le_of_forall_ge (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a := H _ le_rfl
@[deprecated (since := "2025-01-30")] alias le_of_forall_le' := le_of_forall_ge
theorem forall_le_iff_le : (∀ ⦃c⦄, c ≤ a → c ≤ b) ↔ a ≤ b :=
⟨le_of_forall_le, fun h _ hca ↦ le_trans hca h⟩
theorem forall_le_iff_ge : (∀ ⦃c⦄, a ≤ c → b ≤ c) ↔ b ≤ a :=
⟨le_of_forall_ge, fun h _ hca ↦ le_trans h hca⟩
/-- monotonicity of `≤` with respect to `→` -/
theorem le_implies_le_of_le_of_le (hca : c ≤ a) (hbd : b ≤ d) : a ≤ b → c ≤ d :=
fun hab ↦ (hca.trans hab).trans hbd
end Preorder
/-! ### Partial order -/
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem ge_antisymm : a ≤ b → b ≤ a → b = a :=
flip le_antisymm
theorem lt_of_le_of_ne' : a ≤ b → b ≠ a → a < b := fun h₁ h₂ ↦ lt_of_le_of_ne h₁ h₂.symm
theorem Ne.lt_of_le : a ≠ b → a ≤ b → a < b :=
flip lt_of_le_of_ne
theorem Ne.lt_of_le' : b ≠ a → a ≤ b → a < b :=
flip lt_of_le_of_ne'
alias LE.le.antisymm := le_antisymm
alias LE.le.antisymm' := ge_antisymm
alias LE.le.lt_of_ne := lt_of_le_of_ne
alias LE.le.lt_of_ne' := lt_of_le_of_ne'
alias LE.le.lt_or_eq := lt_or_eq_of_le
-- Unnecessary brackets are here for readability
lemma le_imp_eq_iff_le_imp_le : (a ≤ b → b = a) ↔ (a ≤ b → b ≤ a) where
mp h hab := (h hab).le
mpr h hab := (h hab).antisymm hab
-- Unnecessary brackets are here for readability
lemma ge_imp_eq_iff_le_imp_le : (a ≤ b → a = b) ↔ (a ≤ b → b ≤ a) where
mp h hab := (h hab).ge
mpr h hab := hab.antisymm (h hab)
namespace LE.le
theorem lt_iff_ne (h : a ≤ b) : a < b ↔ a ≠ b :=
⟨fun h ↦ h.ne, h.lt_of_ne⟩
theorem gt_iff_ne (h : a ≤ b) : a < b ↔ b ≠ a :=
⟨fun h ↦ h.ne.symm, h.lt_of_ne'⟩
theorem not_lt_iff_eq (h : a ≤ b) : ¬a < b ↔ a = b :=
h.lt_iff_ne.not_left
theorem not_gt_iff_eq (h : a ≤ b) : ¬a < b ↔ b = a :=
h.gt_iff_ne.not_left
theorem le_iff_eq (h : a ≤ b) : b ≤ a ↔ b = a :=
⟨fun h' ↦ h'.antisymm h, Eq.le⟩
theorem ge_iff_eq (h : a ≤ b) : b ≤ a ↔ a = b :=
⟨h.antisymm, Eq.ge⟩
end LE.le
-- See Note [decidable namespace]
protected theorem Decidable.le_iff_eq_or_lt [DecidableLE α] : a ≤ b ↔ a = b ∨ a < b :=
Decidable.le_iff_lt_or_eq.trans or_comm
theorem le_iff_eq_or_lt : a ≤ b ↔ a = b ∨ a < b := le_iff_lt_or_eq.trans or_comm
theorem lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b :=
⟨fun h ↦ ⟨le_of_lt h, ne_of_lt h⟩, fun ⟨h1, h2⟩ ↦ h1.lt_of_ne h2⟩
lemma eq_iff_not_lt_of_le (hab : a ≤ b) : a = b ↔ ¬ a < b := by simp [hab, lt_iff_le_and_ne]
alias LE.le.eq_iff_not_lt := eq_iff_not_lt_of_le
-- See Note [decidable namespace]
protected theorem Decidable.eq_iff_le_not_lt [DecidableLE α] : a = b ↔ a ≤ b ∧ ¬a < b :=
⟨fun h ↦ ⟨h.le, h ▸ lt_irrefl _⟩, fun ⟨h₁, h₂⟩ ↦
h₁.antisymm <| Decidable.byContradiction fun h₃ ↦ h₂ (h₁.lt_of_not_le h₃)⟩
theorem eq_iff_le_not_lt : a = b ↔ a ≤ b ∧ ¬a < b :=
haveI := Classical.dec
Decidable.eq_iff_le_not_lt
theorem eq_or_lt_of_le (h : a ≤ b) : a = b ∨ a < b := h.lt_or_eq.symm
theorem eq_or_gt_of_le (h : a ≤ b) : b = a ∨ a < b := h.lt_or_eq.symm.imp Eq.symm id
theorem gt_or_eq_of_le (h : a ≤ b) : a < b ∨ b = a := (eq_or_gt_of_le h).symm
alias LE.le.eq_or_lt_dec := Decidable.eq_or_lt_of_le
alias LE.le.eq_or_lt := eq_or_lt_of_le
alias LE.le.eq_or_gt := eq_or_gt_of_le
alias LE.le.gt_or_eq := gt_or_eq_of_le
theorem eq_of_le_of_not_lt (hab : a ≤ b) (hba : ¬a < b) : a = b := hab.eq_or_lt.resolve_right hba
theorem eq_of_ge_of_not_gt (hab : a ≤ b) (hba : ¬a < b) : b = a := (eq_of_le_of_not_lt hab hba).symm
alias LE.le.eq_of_not_lt := eq_of_le_of_not_lt
alias LE.le.eq_of_not_gt := eq_of_ge_of_not_gt
theorem Ne.le_iff_lt (h : a ≠ b) : a ≤ b ↔ a < b := ⟨fun h' ↦ lt_of_le_of_ne h' h, fun h ↦ h.le⟩
theorem Ne.not_le_or_not_le (h : a ≠ b) : ¬a ≤ b ∨ ¬b ≤ a := not_and_or.1 <| le_antisymm_iff.not.1 h
-- See Note [decidable namespace]
protected theorem Decidable.ne_iff_lt_iff_le [DecidableEq α] : (a ≠ b ↔ a < b) ↔ a ≤ b :=
⟨fun h ↦ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↦ ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩
@[simp]
theorem ne_iff_lt_iff_le : (a ≠ b ↔ a < b) ↔ a ≤ b :=
haveI := Classical.dec
Decidable.ne_iff_lt_iff_le
lemma eq_of_forall_le_iff (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b :=
((H _).1 le_rfl).antisymm ((H _).2 le_rfl)
lemma eq_of_forall_ge_iff (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b :=
((H _).2 le_rfl).antisymm ((H _).1 le_rfl)
/-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≤ b ○ a` for all `a`,
`b`. -/
lemma commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≤ f b a) : ∀ a b, f a b = f b a :=
fun _ _ ↦ (comm _ _).antisymm <| comm _ _
/-- To prove associativity of a commutative binary operation `○`, we only to check
`(a ○ b) ○ c ≤ a ○ (b ○ c)` for all `a`, `b`, `c`. -/
lemma associative_of_commutative_of_le {f : α → α → α} (comm : Std.Commutative f)
(assoc : ∀ a b c, f (f a b) c ≤ f a (f b c)) : Std.Associative f where
assoc a b c :=
le_antisymm (assoc _ _ _) <| by
rw [comm.comm, comm.comm b, comm.comm _ c, comm.comm a]
exact assoc ..
end PartialOrder
section LinearOrder
variable [LinearOrder α] {a b : α}
namespace LE.le
lemma lt_or_le (h : a ≤ b) (c : α) : a < c ∨ c ≤ b := (lt_or_ge a c).imp id h.trans'
lemma le_or_lt (h : a ≤ b) (c : α) : a ≤ c ∨ c < b := (le_or_gt a c).imp id h.trans_lt'
lemma le_or_le (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b := (h.lt_or_le c).imp le_of_lt id
end LE.le
namespace LT.lt
lemma lt_or_lt (h : a < b) (c : α) : a < c ∨ c < b := (le_or_gt b c).imp h.trans_le id
end LT.lt
-- Variant of `min_def` with the branches reversed.
theorem min_def' (a b : α) : min a b = if b ≤ a then b else a := by
rw [min_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
-- Variant of `min_def` with the branches reversed.
-- This is sometimes useful as it used to be the default.
theorem max_def' (a b : α) : max a b = if b ≤ a then a else b := by
rw [max_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
theorem lt_of_not_le (h : ¬b ≤ a) : a < b :=
((le_total _ _).resolve_right h).lt_of_not_le h
theorem lt_iff_not_le : a < b ↔ ¬b ≤ a :=
⟨not_le_of_lt, lt_of_not_le⟩
theorem Ne.lt_or_lt (h : a ≠ b) : a < b ∨ b < a :=
lt_or_gt_of_ne h
/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/
@[simp]
theorem lt_or_lt_iff_ne : a < b ∨ b < a ↔ a ≠ b :=
ne_iff_lt_or_gt.symm
theorem not_lt_iff_eq_or_lt : ¬a < b ↔ a = b ∨ b < a :=
not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl
theorem exists_ge_of_linear (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
match le_total a b with
| Or.inl h => ⟨_, h, le_rfl⟩
| Or.inr h => ⟨_, le_rfl, h⟩
lemma exists_forall_ge_and {p q : α → Prop} :
(∃ i, ∀ j ≥ i, p j) → (∃ i, ∀ j ≥ i, q j) → ∃ i, ∀ j ≥ i, p j ∧ q j
| ⟨a, ha⟩, ⟨b, hb⟩ =>
let ⟨c, hac, hbc⟩ := exists_ge_of_linear a b
⟨c, fun _d hcd ↦ ⟨ha _ <| hac.trans hcd, hb _ <| hbc.trans hcd⟩⟩
theorem le_of_forall_lt (H : ∀ c, c < a → c < b) : a ≤ b :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
theorem forall_lt_iff_le : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b :=
⟨le_of_forall_lt, fun h _ hca ↦ lt_of_lt_of_le hca h⟩
theorem le_of_forall_lt' (H : ∀ c, a < c → b < c) : b ≤ a :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
theorem forall_lt_iff_le' : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a :=
⟨le_of_forall_lt', fun h _ hac ↦ lt_of_le_of_lt h hac⟩
theorem eq_of_forall_lt_iff (h : ∀ c, c < a ↔ c < b) : a = b :=
(le_of_forall_lt fun _ ↦ (h _).1).antisymm <| le_of_forall_lt fun _ ↦ (h _).2
theorem eq_of_forall_gt_iff (h : ∀ c, a < c ↔ b < c) : a = b :=
(le_of_forall_lt' fun _ ↦ (h _).2).antisymm <| le_of_forall_lt' fun _ ↦ (h _).1
section ltByCases
variable {P : Sort*} {x y : α}
@[simp]
lemma ltByCases_lt (h : x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₁ h := dif_pos h
@[simp]
lemma ltByCases_gt (h : y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₃ h := (dif_neg h.not_lt).trans (dif_pos h)
@[simp]
lemma ltByCases_eq (h : x = y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} :
ltByCases x y h₁ h₂ h₃ = h₂ h := (dif_neg h.not_lt).trans (dif_neg h.not_gt)
lemma ltByCases_not_lt (h : ¬ x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ y < x → x = y := fun h' => (le_antisymm (le_of_not_gt h') (le_of_not_gt h))) :
ltByCases x y h₁ h₂ h₃ = if h' : y < x then h₃ h' else h₂ (p h') := dif_neg h
lemma ltByCases_not_gt (h : ¬ y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → x = y := fun h' => (le_antisymm (le_of_not_gt h) (le_of_not_gt h'))) :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₂ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_neg h)
lemma ltByCases_ne (h : x ≠ y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : ¬ x < y → y < x := fun h' => h.lt_or_lt.resolve_left h') :
ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₃ (p h') :=
dite_congr rfl (fun _ => rfl) (fun _ => dif_pos _)
lemma ltByCases_comm {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
(p : y = x → x = y := fun h' => h'.symm) :
ltByCases x y h₁ h₂ h₃ = ltByCases y x h₃ (h₂ ∘ p) h₁ := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt h, ltByCases_gt h]
· rw [ltByCases_eq h, ltByCases_eq h.symm, comp_apply]
· rw [ltByCases_lt h, ltByCases_gt h]
lemma eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt {x' y' : α}
(ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) :
x = y ↔ x' = y' := by simp_rw [eq_iff_le_not_lt, ← not_lt, ltc, gtc]
lemma ltByCases_rec {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : P)
(hlt : (h : x < y) → h₁ h = p) (heq : (h : x = y) → h₂ h = p)
(hgt : (h : y < x) → h₃ h = p) :
ltByCases x y h₁ h₂ h₃ = p :=
ltByCases x y
(fun h => ltByCases_lt h ▸ hlt h)
(fun h => ltByCases_eq h ▸ heq h)
(fun h => ltByCases_gt h ▸ hgt h)
lemma ltByCases_eq_iff {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {p : P} :
ltByCases x y h₁ h₂ h₃ = p ↔ (∃ h, h₁ h = p) ∨ (∃ h, h₂ h = p) ∨ (∃ h, h₃ h = p) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltByCases_lt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, or_false, h.ne]
· simp only [h, lt_self_iff_false, ltByCases_eq, not_false_eq_true,
exists_prop_of_false, exists_prop_of_true, or_false, false_or]
· simp only [ltByCases_gt, exists_prop_of_true, h, h.not_lt, not_false_eq_true,
exists_prop_of_false, false_or, h.ne']
lemma ltByCases_congr {x' y' : α} {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P}
{h₁' : x' < y' → P} {h₂' : x' = y' → P} {h₃' : y' < x' → P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : ∀ (h : x' < y'), h₁ (ltc.mpr h) = h₁' h)
(hh'₂ : ∀ (h : x' = y'), h₂ ((eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc).mpr h) = h₂' h)
(hh'₃ : ∀ (h : y' < x'), h₃ (gtc.mpr h) = h₃' h) :
ltByCases x y h₁ h₂ h₃ = ltByCases x' y' h₁' h₂' h₃' := by
refine ltByCases_rec _ (fun h => ?_) (fun h => ?_) (fun h => ?_)
· rw [ltByCases_lt (ltc.mp h), hh'₁]
· rw [eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc] at h
rw [ltByCases_eq h, hh'₂]
· rw [ltByCases_gt (gtc.mp h), hh'₃]
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order,
non-dependently. -/
abbrev ltTrichotomy (x y : α) (p q r : P) := ltByCases x y (fun _ => p) (fun _ => q) (fun _ => r)
variable {p q r s : P}
@[simp]
lemma ltTrichotomy_lt (h : x < y) : ltTrichotomy x y p q r = p := ltByCases_lt h
@[simp]
lemma ltTrichotomy_gt (h : y < x) : ltTrichotomy x y p q r = r := ltByCases_gt h
@[simp]
lemma ltTrichotomy_eq (h : x = y) : ltTrichotomy x y p q r = q := ltByCases_eq h
lemma ltTrichotomy_not_lt (h : ¬ x < y) :
ltTrichotomy x y p q r = if y < x then r else q := ltByCases_not_lt h
lemma ltTrichotomy_not_gt (h : ¬ y < x) :
ltTrichotomy x y p q r = if x < y then p else q := ltByCases_not_gt h
lemma ltTrichotomy_ne (h : x ≠ y) :
ltTrichotomy x y p q r = if x < y then p else r := ltByCases_ne h
lemma ltTrichotomy_comm : ltTrichotomy x y p q r = ltTrichotomy y x r q p := ltByCases_comm
lemma ltTrichotomy_self {p : P} : ltTrichotomy x y p p p = p :=
ltByCases_rec p (fun _ => rfl) (fun _ => rfl) (fun _ => rfl)
lemma ltTrichotomy_eq_iff : ltTrichotomy x y p q r = s ↔
(x < y ∧ p = s) ∨ (x = y ∧ q = s) ∨ (y < x ∧ r = s) := by
refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_)
· simp only [ltTrichotomy_lt, false_and, true_and, or_false, h, h.not_lt, h.ne]
· simp only [ltTrichotomy_eq, false_and, true_and, or_false, false_or, h, lt_irrefl]
· simp only [ltTrichotomy_gt, false_and, true_and, false_or, h, h.not_lt, h.ne']
lemma ltTrichotomy_congr {x' y' : α} {p' q' r' : P} (ltc : (x < y) ↔ (x' < y'))
(gtc : (y < x) ↔ (y' < x')) (hh'₁ : x' < y' → p = p')
(hh'₂ : x' = y' → q = q') (hh'₃ : y' < x' → r = r') :
ltTrichotomy x y p q r = ltTrichotomy x' y' p' q' r' :=
ltByCases_congr ltc gtc hh'₁ hh'₂ hh'₃
end ltByCases
/-! #### `min`/`max` recursors -/
section MinMaxRec
variable {p : α → Prop}
lemma min_rec (ha : a ≤ b → p a) (hb : b ≤ a → p b) : p (min a b) := by
obtain hab | hba := le_total a b <;> simp [min_eq_left, min_eq_right, *]
lemma max_rec (ha : b ≤ a → p a) (hb : a ≤ b → p b) : p (max a b) := by
obtain hab | hba := le_total a b <;> simp [max_eq_left, max_eq_right, *]
lemma min_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (min a b) :=
min_rec (fun _ ↦ ha) fun _ ↦ hb
lemma max_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (max a b) :=
max_rec (fun _ ↦ ha) fun _ ↦ hb
lemma min_def_lt (a b : α) : min a b = if a < b then a else b := by
rw [min_comm, min_def, ← ite_not]; simp only [not_le]
lemma max_def_lt (a b : α) : max a b = if a < b then b else a := by
rw [max_comm, max_def, ← ite_not]; simp only [not_le]
end MinMaxRec
end LinearOrder
/-! ### Implications -/
lemma lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b → c ≤ d) (h : d < c) : b < a :=
lt_of_not_le fun h' ↦ (H h').not_lt h
lemma le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
a ≤ b → c ≤ d ↔ d < c → b < a :=
⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩
lemma lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c :=
lt_iff_le_not_le.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm
lemma lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c := not_le.symm.trans <| (not_congr H).trans <| not_le
lemma le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
(a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) :=
⟨lt_iff_lt_of_le_iff_le, fun H ↦ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩
/-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/
lemma rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β}
(h : ∀ a b, r a b → f a ≤ f b) {a b : α} : r a b → f a = f b := fun hab ↦
le_antisymm (h a b hab) (h b a <| symm hab)
/-! ### Extensionality lemmas -/
@[ext]
lemma Preorder.toLE_injective : Function.Injective (@Preorder.toLE α) :=
fun
| { lt := A_lt, lt_iff_le_not_le := A_iff, .. },
{ lt := B_lt, lt_iff_le_not_le := B_iff, .. } => by
rintro ⟨⟩
have : A_lt = B_lt := by
funext a b
rw [A_iff, B_iff]
cases this
congr
@[ext]
lemma PartialOrder.toPreorder_injective : Function.Injective (@PartialOrder.toPreorder α) := by
rintro ⟨⟩ ⟨⟩ ⟨⟩; congr
@[ext]
lemma LinearOrder.toPartialOrder_injective : Function.Injective (@LinearOrder.toPartialOrder α) :=
fun
| { le := A_le, lt := A_lt,
toDecidableLE := A_decidableLE, toDecidableEq := A_decidableEq, toDecidableLT := A_decidableLT
min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def,
compare := A_compare, compare_eq_compareOfLessAndEq := A_compare_canonical, .. },
{ le := B_le, lt := B_lt,
toDecidableLE := B_decidableLE, toDecidableEq := B_decidableEq, toDecidableLT := B_decidableLT
min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def,
compare := B_compare, compare_eq_compareOfLessAndEq := B_compare_canonical, .. } => by
rintro ⟨⟩
obtain rfl : A_decidableLE = B_decidableLE := Subsingleton.elim _ _
obtain rfl : A_decidableEq = B_decidableEq := Subsingleton.elim _ _
obtain rfl : A_decidableLT = B_decidableLT := Subsingleton.elim _ _
have : A_min = B_min := by
funext a b
exact (A_min_def _ _).trans (B_min_def _ _).symm
cases this
have : A_max = B_max := by
funext a b
exact (A_max_def _ _).trans (B_max_def _ _).symm
cases this
have : A_compare = B_compare := by
funext a b
exact (A_compare_canonical _ _).trans (B_compare_canonical _ _).symm
congr
lemma Preorder.ext {A B : Preorder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y; exact H x y
lemma PartialOrder.ext {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by ext x y; exact H x y
lemma PartialOrder.ext_lt {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) :
A = B := by ext x y; rw [le_iff_lt_or_eq, @le_iff_lt_or_eq _ A, H]
lemma LinearOrder.ext {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) :
A = B := by ext x y; exact H x y
lemma LinearOrder.ext_lt {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) :
A = B := LinearOrder.toPartialOrder_injective (PartialOrder.ext_lt H)
/-! ### Order dual -/
/-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. `αᵒᵈ` is
notation for `OrderDual α`. -/
def OrderDual (α : Type*) : Type _ :=
α
@[inherit_doc]
notation:max α "ᵒᵈ" => OrderDual α
namespace OrderDual
instance (α : Type*) [h : Nonempty α] : Nonempty αᵒᵈ :=
h
instance (α : Type*) [h : Subsingleton α] : Subsingleton αᵒᵈ :=
h
instance (α : Type*) [LE α] : LE αᵒᵈ :=
⟨fun x y : α ↦ y ≤ x⟩
instance (α : Type*) [LT α] : LT αᵒᵈ :=
⟨fun x y : α ↦ y < x⟩
instance instOrd (α : Type*) [Ord α] : Ord αᵒᵈ where
compare := fun (a b : α) ↦ compare b a
instance instSup (α : Type*) [Min α] : Max αᵒᵈ :=
⟨((· ⊓ ·) : α → α → α)⟩
instance instInf (α : Type*) [Max α] : Min αᵒᵈ :=
⟨((· ⊔ ·) : α → α → α)⟩
instance instPreorder (α : Type*) [Preorder α] : Preorder αᵒᵈ where
le_refl := fun _ ↦ le_refl _
le_trans := fun _ _ _ hab hbc ↦ hbc.trans hab
lt_iff_le_not_le := fun _ _ ↦ lt_iff_le_not_le
instance instPartialOrder (α : Type*) [PartialOrder α] : PartialOrder αᵒᵈ where
__ := inferInstanceAs (Preorder αᵒᵈ)
le_antisymm := fun a b hab hba ↦ @le_antisymm α _ a b hba hab
instance instLinearOrder (α : Type*) [LinearOrder α] : LinearOrder αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
__ := inferInstanceAs (Ord αᵒᵈ)
le_total := fun a b : α ↦ le_total b a
max := fun a b ↦ (min a b : α)
min := fun a b ↦ (max a b : α)
min_def := fun a b ↦ show (max .. : α) = _ by rw [max_comm, max_def]; rfl
max_def := fun a b ↦ show (min .. : α) = _ by rw [min_comm, min_def]; rfl
toDecidableLE := (inferInstance : DecidableRel (fun a b : α ↦ b ≤ a))
toDecidableLT := (inferInstance : DecidableRel (fun a b : α ↦ b < a))
toDecidableEq := (inferInstance : DecidableEq α)
compare_eq_compareOfLessAndEq a b := by
simp only [compare, LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq, eq_comm]
rfl
/-- The opposite linear order to a given linear order -/
def _root_.LinearOrder.swap (α : Type*) (_ : LinearOrder α) : LinearOrder α :=
inferInstanceAs <| LinearOrder (OrderDual α)
instance : ∀ [Inhabited α], Inhabited αᵒᵈ := fun [x : Inhabited α] => x
theorem Ord.dual_dual (α : Type*) [H : Ord α] : OrderDual.instOrd αᵒᵈ = H :=
rfl
theorem Preorder.dual_dual (α : Type*) [H : Preorder α] : OrderDual.instPreorder αᵒᵈ = H :=
rfl
theorem instPartialOrder.dual_dual (α : Type*) [H : PartialOrder α] :
OrderDual.instPartialOrder αᵒᵈ = H :=
rfl
theorem instLinearOrder.dual_dual (α : Type*) [H : LinearOrder α] :
OrderDual.instLinearOrder αᵒᵈ = H :=
rfl
end OrderDual
/-! ### `HasCompl` -/
instance Prop.hasCompl : HasCompl Prop :=
⟨Not⟩
instance Pi.hasCompl [∀ i, HasCompl (π i)] : HasCompl (∀ i, π i) :=
⟨fun x i ↦ (x i)ᶜ⟩
theorem Pi.compl_def [∀ i, HasCompl (π i)] (x : ∀ i, π i) :
xᶜ = fun i ↦ (x i)ᶜ :=
rfl
@[simp]
theorem Pi.compl_apply [∀ i, HasCompl (π i)] (x : ∀ i, π i) (i : ι) :
xᶜ i = (x i)ᶜ :=
rfl
instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α rᶜ :=
⟨@irrefl α r _⟩
instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α rᶜ :=
⟨fun a ↦ not_not_intro (refl a)⟩
theorem compl_lt [LinearOrder α] : (· < · : α → α → _)ᶜ = (· ≥ ·) := by ext; simp [compl]
theorem compl_le [LinearOrder α] : (· ≤ · : α → α → _)ᶜ = (· > ·) := by ext; simp [compl]
theorem compl_gt [LinearOrder α] : (· > · : α → α → _)ᶜ = (· ≤ ·) := by ext; simp [compl]
theorem compl_ge [LinearOrder α] : (· ≥ · : α → α → _)ᶜ = (· < ·) := by ext; simp [compl]
instance Ne.instIsEquiv_compl : IsEquiv α (· ≠ ·)ᶜ := by
convert eq_isEquiv α
simp [compl]
/-! ### Order instances on the function space -/
instance Pi.hasLe [∀ i, LE (π i)] :
LE (∀ i, π i) where le x y := ∀ i, x i ≤ y i
theorem Pi.le_def [∀ i, LE (π i)] {x y : ∀ i, π i} :
x ≤ y ↔ ∀ i, x i ≤ y i :=
Iff.rfl
instance Pi.preorder [∀ i, Preorder (π i)] : Preorder (∀ i, π i) where
__ := inferInstanceAs (LE (∀ i, π i))
le_refl := fun a i ↦ le_refl (a i)
le_trans := fun _ _ _ h₁ h₂ i ↦ le_trans (h₁ i) (h₂ i)
theorem Pi.lt_def [∀ i, Preorder (π i)] {x y : ∀ i, π i} :
x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by
simp +contextual [lt_iff_le_not_le, Pi.le_def]
instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where
__ := Pi.preorder
le_antisymm := fun _ _ h1 h2 ↦ funext fun b ↦ (h1 b).antisymm (h2 b)
namespace Sum
variable {α₁ α₂ : Type*} [LE β]
@[simp]
lemma elim_le_elim_iff {u₁ v₁ : α₁ → β} {u₂ v₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Sum.elim v₁ v₂ ↔ u₁ ≤ v₁ ∧ u₂ ≤ v₂ :=
Sum.forall
lemma const_le_elim_iff {b : β} {v₁ : α₁ → β} {v₂ : α₂ → β} :
Function.const _ b ≤ Sum.elim v₁ v₂ ↔ Function.const _ b ≤ v₁ ∧ Function.const _ b ≤ v₂ :=
elim_const_const b ▸ elim_le_elim_iff ..
lemma elim_le_const_iff {b : β} {u₁ : α₁ → β} {u₂ : α₂ → β} :
Sum.elim u₁ u₂ ≤ Function.const _ b ↔ u₁ ≤ Function.const _ b ∧ u₂ ≤ Function.const _ b :=
elim_const_const b ▸ elim_le_elim_iff ..
end Sum
section Pi
/-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/
def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop :=
∀ i, a i < b i
@[inherit_doc]
local infixl:50 " ≺ " => StrongLT
variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i}
theorem le_of_strongLT (h : a ≺ b) : a ≤ b := fun _ ↦ (h _).le
theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by
inhabit ι
exact Pi.lt_def.2 ⟨le_of_strongLT h, default, h _⟩
theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≤ c) : a ≺ c := fun _ ↦
(hab _).trans_le <| hbc _
theorem strongLT_of_le_of_strongLT (hab : a ≤ b) (hbc : b ≺ c) : a ≺ c := fun _ ↦
(hab _).trans_lt <| hbc _
alias StrongLT.le := le_of_strongLT
alias StrongLT.lt := lt_of_strongLT
alias StrongLT.trans_le := strongLT_of_strongLT_of_le
alias LE.le.trans_strongLT := strongLT_of_le_of_strongLT
end Pi
section Function
variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i}
theorem le_update_iff : x ≤ Function.update y i a ↔ x i ≤ a ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ x j ≤ z
theorem update_le_iff : Function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ z ≤ y j
theorem update_le_update_iff :
Function.update x i a ≤ Function.update y i b ↔ a ≤ b ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := by
simp +contextual [update_le_iff]
@[simp]
theorem update_le_update_iff' : update x i a ≤ update x i b ↔ a ≤ b := by
simp [update_le_update_iff]
@[simp]
theorem update_lt_update_iff : update x i a < update x i b ↔ a < b :=
lt_iff_lt_of_le_iff_le' update_le_update_iff' update_le_update_iff'
@[simp]
theorem le_update_self_iff : x ≤ update x i a ↔ x i ≤ a := by simp [le_update_iff]
@[simp]
theorem update_le_self_iff : update x i a ≤ x ↔ a ≤ x i := by simp [update_le_iff]
@[simp]
theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_le]
@[simp]
theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_le]
end Function
instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) :=
⟨fun x y i ↦ x i \ y i⟩
theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) :
x \ y = fun i ↦ x i \ y i :=
rfl
@[simp]
theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) :
(x \ y) i = x i \ y i :=
rfl
namespace Function
variable [Preorder α] [Nonempty β] {a b : α}
@[simp]
theorem const_le_const : const β a ≤ const β b ↔ a ≤ b := by simp [Pi.le_def]
@[simp]
theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt
end Function
/-! ### Lifts of order instances -/
/-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`.
See note [reducible non-instances]. -/
abbrev Preorder.lift [Preorder β] (f : α → β) : Preorder α where
le x y := f x ≤ f y
le_refl _ := le_rfl
le_trans _ _ _ := _root_.le_trans
lt x y := f x < f y
lt_iff_le_not_le _ _ := _root_.lt_iff_le_not_le
/-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
abbrev PartialOrder.lift [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α :=
{ Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↦ inj (h₁.antisymm h₂) }
theorem compare_of_injective_eq_compareOfLessAndEq (a b : α) [LinearOrder β]
[DecidableEq α] (f : α → β) (inj : Injective f)
[Decidable (LT.lt (self := PartialOrder.lift f inj |>.toLT) a b)] :
compare (f a) (f b) =
@compareOfLessAndEq _ a b (PartialOrder.lift f inj |>.toLT) _ _ := by
have h := LinearOrder.compare_eq_compareOfLessAndEq (f a) (f b)
simp only [h, compareOfLessAndEq]
split_ifs <;> try (first | rfl | contradiction)
· have : ¬ f a = f b := by rename_i h; exact inj.ne h
contradiction
· have : f a = f b := by rename_i h; exact congrArg f h
contradiction
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses
them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and
`max` fields, and `LinearOrder.liftWithOrd` for one that does not auto-generate `compare`
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.lift [LinearOrder β] [Max α] [Min α] (f : α → β) (inj : Injective f)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrder α :=
letI instOrdα : Ord α := ⟨fun a b ↦ compare (f a) (f b)⟩
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj, instOrdα with
le_total := fun x y ↦ le_total (f x) (f y)
toDecidableLE := decidableLE
toDecidableLT := decidableLT
toDecidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version autogenerates `min` and `max` fields. See `LinearOrder.lift`
for a version that takes `[Max α]` and `[Min α]`, then uses them as `max` and `min`. See
`LinearOrder.liftWithOrd'` for a version which does not auto-generate `compare` fields.
See note [reducible non-instances]. -/
abbrev LinearOrder.lift' [LinearOrder β] (f : α → β) (inj : Injective f) : LinearOrder α :=
@LinearOrder.lift α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm) fun _ _ ↦
(apply_ite f _ _ _).trans (min_def _ _).symm
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses
them for `max` and `min` fields. It also takes `[Ord α]` as an argument and uses them for `compare`
fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and
`LinearOrder.liftWithOrd'` for one that auto-generates `min` and `max` fields.
fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd [LinearOrder β] [Max α] [Min α] [Ord α] (f : α → β)
(inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y))
(hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y))
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y))
letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
{ PartialOrder.lift f inj with
le_total := fun x y ↦ le_total (f x) (f y)
toDecidableLE := decidableLE
toDecidableLT := decidableLT
toDecidableEq := decidableEq
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hsup _ _).trans (max_def _ _)
compare_eq_compareOfLessAndEq := fun a b ↦
(compare_f a b).trans <| compare_of_injective_eq_compareOfLessAndEq a b f inj }
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version auto-generates `min` and `max` fields. It also takes `[Ord α]`
as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that
autogenerates `compare` fields, and `LinearOrder.liftWithOrd` for one that doesn't auto-generate
`min` and `max` fields. fields. See note [reducible non-instances]. -/
abbrev LinearOrder.liftWithOrd' [LinearOrder β] [Ord α] (f : α → β)
(inj : Injective f)
(compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α :=
@LinearOrder.liftWithOrd α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩
⟨fun x y ↦ if f x ≤ f y then x else y⟩ _ f inj
(fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm)
(fun _ _ ↦ (apply_ite f _ _ _).trans (min_def _ _).symm)
compare_f
/-! ### Subtype of an order -/
namespace Subtype
instance le [LE α] {p : α → Prop} : LE (Subtype p) :=
⟨fun x y ↦ (x : α) ≤ y⟩
instance lt [LT α] {p : α → Prop} : LT (Subtype p) :=
| ⟨fun x y ↦ (x : α) < y⟩
| Mathlib/Order/Basic.lean | 1,001 | 1,001 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad
-/
import Mathlib.Order.Filter.Germ.OrderedMonoid
import Mathlib.Algebra.Order.Ring.Defs
/-!
# Lemmas about filters and ordered rings.
-/
namespace Filter
open Function Filter
universe u v
variable {α : Type u} {β : Type v}
theorem EventuallyLE.mul_le_mul [MulZeroClass β] [Preorder β] [PosMulMono β] [MulPosMono β]
{l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) (hg₀ : 0 ≤ᶠ[l] g₁)
(hf₀ : 0 ≤ᶠ[l] f₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by
filter_upwards [hf, hg, hg₀, hf₀] with x using _root_.mul_le_mul
@[to_additive EventuallyLE.add_le_add]
theorem EventuallyLE.mul_le_mul' [Mul β] [Preorder β] [MulLeftMono β]
| [MulRightMono β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β}
(hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ * g₁ ≤ᶠ[l] f₂ * g₂ := by
filter_upwards [hf, hg] with x hfx hgx using _root_.mul_le_mul' hfx hgx
| Mathlib/Order/Filter/Ring.lean | 27 | 30 |
/-
Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.GroupWithZero.Finset
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Group.FiniteSupport
import Mathlib.Algebra.NoZeroSMulDivisors.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Data.Set.Finite.Lattice
import Mathlib.Data.Set.Subsingleton
/-!
# Finite products and sums over types and sets
We define products and sums over types and subsets of types, with no finiteness hypotheses.
All infinite products and sums are defined to be junk values (i.e. one or zero).
This approach is sometimes easier to use than `Finset.sum`,
when issues arise with `Finset` and `Fintype` being data.
## Main definitions
We use the following variables:
* `α`, `β` - types with no structure;
* `s`, `t` - sets
* `M`, `N` - additive or multiplicative commutative monoids
* `f`, `g` - functions
Definitions in this file:
* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.
Zero otherwise.
* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if
it's finite. One otherwise.
## Notation
* `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f`
* `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f`
This notation works for functions `f : p → M`, where `p : Prop`, so the following works:
* `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : Set α` : sum over the set `s`;
* `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;
* `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.
## Implementation notes
`finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However
experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings
where the user is not interested in computability and wants to do reasoning without running into
typeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and
`Fintype`. By sticking solely to `Set.Finite` we avoid these problems. We are aware that there are
other solutions but for beginner mathematicians this approach is easier in practice.
Another application is the construction of a partition of unity from a collection of “bump”
function. In this case the finite set depends on the point and it's convenient to have a definition
that does not mention the set explicitly.
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
We did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`.
## Tags
finsum, finprod, finite sum, finite product
-/
open Function Set
/-!
### Definition and relation to `Finset.sum` and `Finset.prod`
-/
-- Porting note: Used to be section Sort
section sort
variable {G M N : Type*} {α β ι : Sort*} [CommMonoid M] [CommMonoid N]
section
/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas
with `Classical.dec` in their statement. -/
open Classical in
/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero
otherwise. -/
noncomputable irreducible_def finsum (lemma := finsum_def') [AddCommMonoid M] (f : α → M) : M :=
if h : (support (f ∘ PLift.down)).Finite then ∑ i ∈ h.toFinset, f i.down else 0
open Classical in
/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's
finite. One otherwise. -/
@[to_additive existing]
noncomputable irreducible_def finprod (lemma := finprod_def') (f : α → M) : M :=
if h : (mulSupport (f ∘ PLift.down)).Finite then ∏ i ∈ h.toFinset, f i.down else 1
attribute [to_additive existing] finprod_def'
end
open Batteries.ExtendedBinder
/-- `∑ᶠ x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the
support of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or
conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/
notation3"∑ᶠ "(...)", "r:67:(scoped f => finsum f) => r
/-- `∏ᶠ x, f x` is notation for `finprod f`. It is the product of `f x`, where `x` ranges over the
multiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple
arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/
notation3"∏ᶠ "(...)", "r:67:(scoped f => finprod f) => r
-- Porting note: The following ports the lean3 notation for this file, but is currently very fickle.
-- syntax (name := bigfinsum) "∑ᶠ" extBinders ", " term:67 : term
-- macro_rules (kind := bigfinsum)
-- | `(∑ᶠ $x:ident, $p) => `(finsum (fun $x:ident ↦ $p))
-- | `(∑ᶠ $x:ident : $t, $p) => `(finsum (fun $x:ident : $t ↦ $p))
-- | `(∑ᶠ $x:ident $b:binderPred, $p) =>
-- `(finsum fun $x => (finsum (α := satisfies_binder_pred% $x $b) (fun _ => $p)))
-- | `(∑ᶠ ($x:ident) ($h:ident : $t), $p) =>
-- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p))
-- | `(∑ᶠ ($x:ident : $_) ($h:ident : $t), $p) =>
-- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p))
-- | `(∑ᶠ ($x:ident) ($y:ident), $p) =>
-- `(finsum fun $x => (finsum fun $y => $p))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum (α := $t) fun $h => $p)))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p)))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (α := $t) fun $h => $p))))
--
--
-- syntax (name := bigfinprod) "∏ᶠ " extBinders ", " term:67 : term
-- macro_rules (kind := bigfinprod)
-- | `(∏ᶠ $x:ident, $p) => `(finprod (fun $x:ident ↦ $p))
-- | `(∏ᶠ $x:ident : $t, $p) => `(finprod (fun $x:ident : $t ↦ $p))
-- | `(∏ᶠ $x:ident $b:binderPred, $p) =>
-- `(finprod fun $x => (finprod (α := satisfies_binder_pred% $x $b) (fun _ => $p)))
-- | `(∏ᶠ ($x:ident) ($h:ident : $t), $p) =>
-- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p))
-- | `(∏ᶠ ($x:ident : $_) ($h:ident : $t), $p) =>
-- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p))
-- | `(∏ᶠ ($x:ident) ($y:ident), $p) =>
-- `(finprod fun $x => (finprod fun $y => $p))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod (α := $t) fun $h => $p)))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p)))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod fun $z =>
-- (finprod (α := $t) fun $h => $p))))
@[to_additive]
theorem finprod_eq_prod_plift_of_mulSupport_toFinset_subset {f : α → M}
(hf : (mulSupport (f ∘ PLift.down)).Finite) {s : Finset (PLift α)} (hs : hf.toFinset ⊆ s) :
∏ᶠ i, f i = ∏ i ∈ s, f i.down := by
rw [finprod, dif_pos]
refine Finset.prod_subset hs fun x _ hxf => ?_
rwa [hf.mem_toFinset, nmem_mulSupport] at hxf
@[to_additive]
theorem finprod_eq_prod_plift_of_mulSupport_subset {f : α → M} {s : Finset (PLift α)}
(hs : mulSupport (f ∘ PLift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down :=
finprod_eq_prod_plift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx => by
rw [Finite.mem_toFinset] at hx
exact hs hx
@[to_additive (attr := simp)]
theorem finprod_one : (∏ᶠ _ : α, (1 : M)) = 1 := by
have : (mulSupport fun x : PLift α => (fun _ => 1 : α → M) x.down) ⊆ (∅ : Finset (PLift α)) :=
fun x h => by simp at h
rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_empty]
@[to_additive]
theorem finprod_of_isEmpty [IsEmpty α] (f : α → M) : ∏ᶠ i, f i = 1 := by
rw [← finprod_one]
congr
simp [eq_iff_true_of_subsingleton]
@[to_additive (attr := simp)]
theorem finprod_false (f : False → M) : ∏ᶠ i, f i = 1 :=
finprod_of_isEmpty _
@[to_additive]
theorem finprod_eq_single (f : α → M) (a : α) (ha : ∀ x, x ≠ a → f x = 1) :
∏ᶠ x, f x = f a := by
have : mulSupport (f ∘ PLift.down) ⊆ ({PLift.up a} : Finset (PLift α)) := by
intro x
contrapose
simpa [PLift.eq_up_iff_down_eq] using ha x.down
rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_singleton]
@[to_additive]
theorem finprod_unique [Unique α] (f : α → M) : ∏ᶠ i, f i = f default :=
finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim
@[to_additive (attr := simp)]
theorem finprod_true (f : True → M) : ∏ᶠ i, f i = f trivial :=
@finprod_unique M True _ ⟨⟨trivial⟩, fun _ => rfl⟩ f
@[to_additive]
theorem finprod_eq_dif {p : Prop} [Decidable p] (f : p → M) :
∏ᶠ i, f i = if h : p then f h else 1 := by
split_ifs with h
· haveI : Unique p := ⟨⟨h⟩, fun _ => rfl⟩
exact finprod_unique f
· haveI : IsEmpty p := ⟨h⟩
exact finprod_of_isEmpty f
@[to_additive]
theorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : ∏ᶠ _ : p, x = if p then x else 1 :=
finprod_eq_dif fun _ => x
@[to_additive]
theorem finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g :=
congr_arg _ <| funext h
@[to_additive (attr := congr)]
theorem finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q)
(hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by
subst q
exact finprod_congr hfg
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on the factors. -/
@[to_additive
"To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on the summands."]
theorem finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := by
rw [finprod]
split_ifs
exacts [Finset.prod_induction _ _ hp₁ hp₀ fun i _ => hp₂ _, hp₀]
theorem finprod_nonneg {R : Type*} [CommSemiring R] [PartialOrder R] [IsOrderedRing R]
{f : α → R} (hf : ∀ x, 0 ≤ f x) :
0 ≤ ∏ᶠ x, f x :=
finprod_induction (fun x => 0 ≤ x) zero_le_one (fun _ _ => mul_nonneg) hf
@[to_additive finsum_nonneg]
theorem one_le_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M]
{f : α → M} (hf : ∀ i, 1 ≤ f i) :
1 ≤ ∏ᶠ i, f i :=
finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf
@[to_additive]
theorem MonoidHom.map_finprod_plift (f : M →* N) (g : α → M)
(h : (mulSupport <| g ∘ PLift.down).Finite) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := by
rw [finprod_eq_prod_plift_of_mulSupport_subset h.coe_toFinset.ge,
finprod_eq_prod_plift_of_mulSupport_subset, map_prod]
rw [h.coe_toFinset]
exact mulSupport_comp_subset f.map_one (g ∘ PLift.down)
@[to_additive]
theorem MonoidHom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
f.map_finprod_plift g (Set.toFinite _)
@[to_additive]
theorem MonoidHom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) :
f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := by
by_cases hg : (mulSupport <| g ∘ PLift.down).Finite; · exact f.map_finprod_plift g hg
rw [finprod, dif_neg, f.map_one, finprod, dif_neg]
exacts [Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg]
@[to_additive]
theorem MonoidHom.map_finprod_of_injective (g : M →* N) (hg : Injective g) (f : α → M) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f
@[to_additive]
theorem MulEquiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f
@[to_additive]
theorem MulEquivClass.map_finprod {F : Type*} [EquivLike F M N] [MulEquivClass F M N] (g : F)
(f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
MulEquiv.map_finprod (MulEquivClass.toMulEquiv g) f
/-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is
infinite. For a more usual version assuming `(support f).Finite` instead, see `finsum_smul'`. -/
theorem finsum_smul {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]
(f : ι → R) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _
/-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is
infinite. For a more usual version assuming `(support f).Finite` instead, see `smul_finsum'`. -/
theorem smul_finsum {R M : Type*} [Semiring R] [AddCommGroup M] [Module R M]
[NoZeroSMulDivisors R M] (c : R) (f : ι → M) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := by
rcases eq_or_ne c 0 with (rfl | hc)
· simp
· exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _
@[to_additive]
theorem finprod_inv_distrib [DivisionCommMonoid G] (f : α → G) : (∏ᶠ x, (f x)⁻¹) = (∏ᶠ x, f x)⁻¹ :=
((MulEquiv.inv G).map_finprod f).symm
end sort
-- Porting note: Used to be section Type
section type
variable {α β ι G M N : Type*} [CommMonoid M] [CommMonoid N]
@[to_additive]
theorem finprod_eq_mulIndicator_apply (s : Set α) (f : α → M) (a : α) :
∏ᶠ _ : a ∈ s, f a = mulIndicator s f a := by
classical convert finprod_eq_if (M := M) (p := a ∈ s) (x := f a)
@[to_additive (attr := simp)]
theorem finprod_apply_ne_one (f : α → M) (a : α) : ∏ᶠ _ : f a ≠ 1, f a = f a := by
rw [← mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport]
@[to_additive]
theorem finprod_mem_def (s : Set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mulIndicator s f a :=
finprod_congr <| finprod_eq_mulIndicator_apply s f
@[to_additive]
lemma finprod_mem_mulSupport (f : α → M) : ∏ᶠ a ∈ mulSupport f, f a = ∏ᶠ a, f a := by
rw [finprod_mem_def, mulIndicator_mulSupport]
@[to_additive]
theorem finprod_eq_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ s) :
∏ᶠ i, f i = ∏ i ∈ s, f i := by
have A : mulSupport (f ∘ PLift.down) = Equiv.plift.symm '' mulSupport f := by
rw [mulSupport_comp_eq_preimage]
exact (Equiv.plift.symm.image_eq_preimage _).symm
have : mulSupport (f ∘ PLift.down) ⊆ s.map Equiv.plift.symm.toEmbedding := by
rw [A, Finset.coe_map]
exact image_subset _ h
rw [finprod_eq_prod_plift_of_mulSupport_subset this]
simp only [Finset.prod_map, Equiv.coe_toEmbedding]
congr
@[to_additive]
theorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : α → M) (hf : (mulSupport f).Finite)
{s : Finset α} (h : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i :=
finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx
@[to_additive]
theorem finprod_eq_finset_prod_of_mulSupport_subset (f : α → M) {s : Finset α}
(h : mulSupport f ⊆ (s : Set α)) : ∏ᶠ i, f i = ∏ i ∈ s, f i :=
haveI h' : (s.finite_toSet.subset h).toFinset ⊆ s := by
simpa [← Finset.coe_subset, Set.coe_toFinset]
finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h'
@[to_additive]
theorem finprod_def (f : α → M) [Decidable (mulSupport f).Finite] :
∏ᶠ i : α, f i = if h : (mulSupport f).Finite then ∏ i ∈ h.toFinset, f i else 1 := by
split_ifs with h
· exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _)
· rw [finprod, dif_neg]
rw [mulSupport_comp_eq_preimage]
exact mt (fun hf => hf.of_preimage Equiv.plift.surjective) h
@[to_additive]
theorem finprod_of_infinite_mulSupport {f : α → M} (hf : (mulSupport f).Infinite) :
∏ᶠ i, f i = 1 := by classical rw [finprod_def, dif_neg hf]
@[to_additive]
theorem finprod_eq_prod (f : α → M) (hf : (mulSupport f).Finite) :
∏ᶠ i : α, f i = ∏ i ∈ hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf]
@[to_additive]
theorem finprod_eq_prod_of_fintype [Fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i :=
finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _
@[to_additive]
theorem map_finset_prod {α F : Type*} [Fintype α] [EquivLike F M N] [MulEquivClass F M N] (f : F)
(g : α → M) : f (∏ i : α, g i) = ∏ i : α, f (g i) := by
simp [← finprod_eq_prod_of_fintype, MulEquivClass.map_finprod]
@[to_additive]
theorem finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : Finset α}
(h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : (∏ᶠ (i) (_ : p i), f i) = ∏ i ∈ t, f i := by
set s := { x | p x }
change ∏ᶠ (i : α) (_ : i ∈ s), f i = ∏ i ∈ t, f i
have : mulSupport (s.mulIndicator f) ⊆ t := by
rw [Set.mulSupport_mulIndicator]
intro x hx
exact (h hx.2).1 hx.1
rw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this]
refine Finset.prod_congr rfl fun x hx => mulIndicator_apply_eq_self.2 fun hxs => ?_
contrapose! hxs
exact (h hxs).2 hx
@[to_additive]
theorem finprod_cond_ne (f : α → M) (a : α) [DecidableEq α] (hf : (mulSupport f).Finite) :
(∏ᶠ (i) (_ : i ≠ a), f i) = ∏ i ∈ hf.toFinset.erase a, f i := by
apply finprod_cond_eq_prod_of_cond_iff
intro x hx
rw [Finset.mem_erase, Finite.mem_toFinset, mem_mulSupport]
exact ⟨fun h => And.intro h hx, fun h => h.1⟩
@[to_additive]
theorem finprod_mem_eq_prod_of_inter_mulSupport_eq (f : α → M) {s : Set α} {t : Finset α}
(h : s ∩ mulSupport f = t.toSet ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i :=
finprod_cond_eq_prod_of_cond_iff _ <| by
intro x hxf
rw [← mem_mulSupport] at hxf
refine ⟨fun hx => ?_, fun hx => ?_⟩
· refine ((mem_inter_iff x t (mulSupport f)).mp ?_).1
rw [← Set.ext_iff.mp h x, mem_inter_iff]
exact ⟨hx, hxf⟩
· refine ((mem_inter_iff x s (mulSupport f)).mp ?_).1
rw [Set.ext_iff.mp h x, mem_inter_iff]
exact ⟨hx, hxf⟩
@[to_additive]
theorem finprod_mem_eq_prod_of_subset (f : α → M) {s : Set α} {t : Finset α}
(h₁ : s ∩ mulSupport f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i :=
finprod_cond_eq_prod_of_cond_iff _ fun hx => ⟨fun h => h₁ ⟨h, hx⟩, fun h => h₂ h⟩
@[to_additive]
theorem finprod_mem_eq_prod (f : α → M) {s : Set α} (hf : (s ∩ mulSupport f).Finite) :
∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_assoc]
@[to_additive]
theorem finprod_mem_eq_prod_filter (f : α → M) (s : Set α) [DecidablePred (· ∈ s)]
(hf : (mulSupport f).Finite) :
∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset with i ∈ s, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by
ext x
simp [and_comm]
@[to_additive]
theorem finprod_mem_eq_toFinset_prod (f : α → M) (s : Set α) [Fintype s] :
∏ᶠ i ∈ s, f i = ∏ i ∈ s.toFinset, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp_rw [coe_toFinset s]
@[to_additive]
theorem finprod_mem_eq_finite_toFinset_prod (f : α → M) {s : Set α} (hs : s.Finite) :
∏ᶠ i ∈ s, f i = ∏ i ∈ hs.toFinset, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [hs.coe_toFinset]
@[to_additive]
theorem finprod_mem_finset_eq_prod (f : α → M) (s : Finset α) : ∏ᶠ i ∈ s, f i = ∏ i ∈ s, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl
@[to_additive]
theorem finprod_mem_coe_finset (f : α → M) (s : Finset α) :
(∏ᶠ i ∈ (s : Set α), f i) = ∏ i ∈ s, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl
@[to_additive]
theorem finprod_mem_eq_one_of_infinite {f : α → M} {s : Set α} (hs : (s ∩ mulSupport f).Infinite) :
∏ᶠ i ∈ s, f i = 1 := by
rw [finprod_mem_def]
apply finprod_of_infinite_mulSupport
rwa [← mulSupport_mulIndicator] at hs
@[to_additive]
theorem finprod_mem_eq_one_of_forall_eq_one {f : α → M} {s : Set α} (h : ∀ x ∈ s, f x = 1) :
∏ᶠ i ∈ s, f i = 1 := by simp +contextual [h]
@[to_additive]
theorem finprod_mem_inter_mulSupport (f : α → M) (s : Set α) :
∏ᶠ i ∈ s ∩ mulSupport f, f i = ∏ᶠ i ∈ s, f i := by
rw [finprod_mem_def, finprod_mem_def, mulIndicator_inter_mulSupport]
@[to_additive]
theorem finprod_mem_inter_mulSupport_eq (f : α → M) (s t : Set α)
(h : s ∩ mulSupport f = t ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by
rw [← finprod_mem_inter_mulSupport, h, finprod_mem_inter_mulSupport]
@[to_additive]
theorem finprod_mem_inter_mulSupport_eq' (f : α → M) (s t : Set α)
(h : ∀ x ∈ mulSupport f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by
apply finprod_mem_inter_mulSupport_eq
ext x
exact and_congr_left (h x)
@[to_additive]
theorem finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @Set.univ α, f i = ∏ᶠ i : α, f i :=
finprod_congr fun _ => finprod_true _
variable {f g : α → M} {a b : α} {s t : Set α}
@[to_additive]
theorem finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i :=
h₀.symm ▸ finprod_congr fun i => finprod_congr_Prop rfl (h₁ i)
@[to_additive]
theorem finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) : ∏ᶠ i, f i = 1 := by
simp +contextual [h]
@[to_additive finsum_pos']
theorem one_lt_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M]
{f : ι → M}
(h : ∀ i, 1 ≤ f i) (h' : ∃ i, 1 < f i) (hf : (mulSupport f).Finite) : 1 < ∏ᶠ i, f i := by
rcases h' with ⟨i, hi⟩
rw [finprod_eq_prod _ hf]
refine Finset.one_lt_prod' (fun i _ ↦ h i) ⟨i, ?_, hi⟩
simpa only [Finite.mem_toFinset, mem_mulSupport] using ne_of_gt hi
/-!
### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication
-/
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals
the product of `f i` multiplied by the product of `g i`. -/
@[to_additive
"If the additive supports of `f` and `g` are finite, then the sum of `f i + g i`
equals the sum of `f i` plus the sum of `g i`."]
theorem finprod_mul_distrib (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) :
∏ᶠ i, f i * g i = (∏ᶠ i, f i) * ∏ᶠ i, g i := by
classical
rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf Finset.subset_union_left,
finprod_eq_prod_of_mulSupport_toFinset_subset g hg Finset.subset_union_right, ←
Finset.prod_mul_distrib]
refine finprod_eq_prod_of_mulSupport_subset _ ?_
simp only [Finset.coe_union, Finite.coe_toFinset, mulSupport_subset_iff,
mem_union, mem_mulSupport]
intro x
contrapose!
rintro ⟨hf, hg⟩
simp [hf, hg]
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i`
equals the product of `f i` divided by the product of `g i`. -/
@[to_additive
"If the additive supports of `f` and `g` are finite, then the sum of `f i - g i`
equals the sum of `f i` minus the sum of `g i`."]
theorem finprod_div_distrib [DivisionCommMonoid G] {f g : α → G} (hf : (mulSupport f).Finite)
| (hg : (mulSupport g).Finite) : ∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i := by
simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mulSupport_inv g).symm.rec hg),
finprod_inv_distrib]
| Mathlib/Algebra/BigOperators/Finprod.lean | 547 | 549 |
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.ModelTheory.Ultraproducts
import Mathlib.ModelTheory.Bundled
import Mathlib.ModelTheory.Skolem
import Mathlib.Order.Filter.AtTopBot.Basic
/-!
# First-Order Satisfiability
This file deals with the satisfiability of first-order theories, as well as equivalence over them.
## Main Definitions
- `FirstOrder.Language.Theory.IsSatisfiable`: `T.IsSatisfiable` indicates that `T` has a nonempty
model.
- `FirstOrder.Language.Theory.IsFinitelySatisfiable`: `T.IsFinitelySatisfiable` indicates that
every finite subset of `T` is satisfiable.
- `FirstOrder.Language.Theory.IsComplete`: `T.IsComplete` indicates that `T` is satisfiable and
models each sentence or its negation.
- `Cardinal.Categorical`: A theory is `κ`-categorical if all models of size `κ` are isomorphic.
## Main Results
- The Compactness Theorem, `FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable`,
shows that a theory is satisfiable iff it is finitely satisfiable.
- `FirstOrder.Language.completeTheory.isComplete`: The complete theory of a structure is
complete.
- `FirstOrder.Language.Theory.exists_large_model_of_infinite_model` shows that any theory with an
infinite model has arbitrarily large models.
- `FirstOrder.Language.Theory.exists_elementaryEmbedding_card_eq`: The Upward Löwenheim–Skolem
Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure
`M`, then `M` has an elementary extension of cardinality `κ`.
## Implementation Details
- Satisfiability of an `L.Theory` `T` is defined in the minimal universe containing all the symbols
of `L`. By Löwenheim-Skolem, this is equivalent to satisfiability in any universe.
-/
universe u v w w'
open Cardinal CategoryTheory
open Cardinal FirstOrder
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ}
namespace Theory
variable (T)
/-- A theory is satisfiable if a structure models it. -/
def IsSatisfiable : Prop :=
Nonempty (ModelType.{u, v, max u v} T)
/-- A theory is finitely satisfiable if all of its finite subtheories are satisfiable. -/
def IsFinitelySatisfiable : Prop :=
∀ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T → IsSatisfiable (T0 : L.Theory)
variable {T} {T' : L.Theory}
theorem Model.isSatisfiable (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] :
T.IsSatisfiable :=
⟨((⊥ : Substructure _ (ModelType.of T M)).elementarySkolem₁Reduct.toModel T).shrink⟩
theorem IsSatisfiable.mono (h : T'.IsSatisfiable) (hs : T ⊆ T') : T.IsSatisfiable :=
⟨(Theory.Model.mono (ModelType.is_model h.some) hs).bundled⟩
theorem isSatisfiable_empty (L : Language.{u, v}) : IsSatisfiable (∅ : L.Theory) :=
⟨default⟩
theorem isSatisfiable_of_isSatisfiable_onTheory {L' : Language.{w, w'}} (φ : L →ᴸ L')
(h : (φ.onTheory T).IsSatisfiable) : T.IsSatisfiable :=
Model.isSatisfiable (h.some.reduct φ)
theorem isSatisfiable_onTheory_iff {L' : Language.{w, w'}} {φ : L →ᴸ L'} (h : φ.Injective) :
(φ.onTheory T).IsSatisfiable ↔ T.IsSatisfiable := by
classical
refine ⟨isSatisfiable_of_isSatisfiable_onTheory φ, fun h' => ?_⟩
haveI : Inhabited h'.some := Classical.inhabited_of_nonempty'
exact Model.isSatisfiable (h'.some.defaultExpansion h)
theorem IsSatisfiable.isFinitelySatisfiable (h : T.IsSatisfiable) : T.IsFinitelySatisfiable :=
fun _ => h.mono
/-- The **Compactness Theorem of first-order logic**: A theory is satisfiable if and only if it is
finitely satisfiable. -/
theorem isSatisfiable_iff_isFinitelySatisfiable {T : L.Theory} :
T.IsSatisfiable ↔ T.IsFinitelySatisfiable :=
⟨Theory.IsSatisfiable.isFinitelySatisfiable, fun h => by
classical
set M : Finset T → Type max u v := fun T0 : Finset T =>
(h (T0.map (Function.Embedding.subtype fun x => x ∈ T)) T0.map_subtype_subset).some.Carrier
let M' := Filter.Product (Ultrafilter.of (Filter.atTop : Filter (Finset T))) M
have h' : M' ⊨ T := by
refine ⟨fun φ hφ => ?_⟩
rw [Ultraproduct.sentence_realize]
refine
Filter.Eventually.filter_mono (Ultrafilter.of_le _)
(Filter.eventually_atTop.2
⟨{⟨φ, hφ⟩}, fun s h' =>
Theory.realize_sentence_of_mem (s.map (Function.Embedding.subtype fun x => x ∈ T))
?_⟩)
simp only [Finset.coe_map, Function.Embedding.coe_subtype, Set.mem_image, Finset.mem_coe,
Subtype.exists, Subtype.coe_mk, exists_and_right, exists_eq_right]
exact ⟨hφ, h' (Finset.mem_singleton_self _)⟩
exact ⟨ModelType.of T M'⟩⟩
theorem isSatisfiable_directed_union_iff {ι : Type*} [Nonempty ι] {T : ι → L.Theory}
(h : Directed (· ⊆ ·) T) : Theory.IsSatisfiable (⋃ i, T i) ↔ ∀ i, (T i).IsSatisfiable := by
refine ⟨fun h' i => h'.mono (Set.subset_iUnion _ _), fun h' => ?_⟩
rw [isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable]
intro T0 hT0
obtain ⟨i, hi⟩ := h.exists_mem_subset_of_finset_subset_biUnion hT0
exact (h' i).mono hi
theorem isSatisfiable_union_distinctConstantsTheory_of_card_le (T : L.Theory) (s : Set α)
(M : Type w') [Nonempty M] [L.Structure M] [M ⊨ T]
(h : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} #M) :
((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by
haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance
rw [Cardinal.lift_mk_le'] at h
letI : (constantsOn α).Structure M := constantsOn.structure (Function.extend (↑) h.some default)
have : M ⊨ (L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s := by
refine ((LHom.onTheory_model _ _).2 inferInstance).union ?_
rw [model_distinctConstantsTheory]
refine fun a as b bs ab => ?_
rw [← Subtype.coe_mk a as, ← Subtype.coe_mk b bs, ← Subtype.ext_iff]
exact
h.some.injective
((Subtype.coe_injective.extend_apply h.some default ⟨a, as⟩).symm.trans
(ab.trans (Subtype.coe_injective.extend_apply h.some default ⟨b, bs⟩)))
exact Model.isSatisfiable M
theorem isSatisfiable_union_distinctConstantsTheory_of_infinite (T : L.Theory) (s : Set α)
(M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] :
((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by
classical
rw [distinctConstantsTheory_eq_iUnion, Set.union_iUnion, isSatisfiable_directed_union_iff]
· exact fun t =>
isSatisfiable_union_distinctConstantsTheory_of_card_le T _ M
((lift_le_aleph0.2 (finset_card_lt_aleph0 _).le).trans
(aleph0_le_lift.2 (aleph0_le_mk M)))
· apply Monotone.directed_le
refine monotone_const.union (monotone_distinctConstantsTheory.comp ?_)
simp only [Finset.coe_map, Function.Embedding.coe_subtype]
exact Monotone.comp (g := Set.image ((↑) : s → α)) (f := ((↑) : Finset s → Set s))
Set.monotone_image fun _ _ => Finset.coe_subset.2
/-- Any theory with an infinite model has arbitrarily large models. -/
theorem exists_large_model_of_infinite_model (T : L.Theory) (κ : Cardinal.{w}) (M : Type w')
[L.Structure M] [M ⊨ T] [Infinite M] :
∃ N : ModelType.{_, _, max u v w} T, Cardinal.lift.{max u v w} κ ≤ #N := by
obtain ⟨N⟩ :=
isSatisfiable_union_distinctConstantsTheory_of_infinite T (Set.univ : Set κ.out) M
refine ⟨(N.is_model.mono Set.subset_union_left).bundled.reduct _, ?_⟩
haveI : N ⊨ distinctConstantsTheory _ _ := N.is_model.mono Set.subset_union_right
rw [ModelType.reduct_Carrier, coe_of]
refine _root_.trans (lift_le.2 (le_of_eq (Cardinal.mk_out κ).symm)) ?_
rw [← mk_univ]
refine
(card_le_of_model_distinctConstantsTheory L Set.univ N).trans (lift_le.{max u v w}.1 ?_)
rw [lift_lift]
theorem isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset {ι : Type*} (T : ι → L.Theory) :
IsSatisfiable (⋃ i, T i) ↔ ∀ s : Finset ι, IsSatisfiable (⋃ i ∈ s, T i) := by
classical
refine
⟨fun h s => h.mono (Set.iUnion_mono fun _ => Set.iUnion_subset_iff.2 fun _ => refl _),
fun h => ?_⟩
rw [isSatisfiable_iff_isFinitelySatisfiable]
intro s hs
rw [Set.iUnion_eq_iUnion_finset] at hs
obtain ⟨t, ht⟩ := Directed.exists_mem_subset_of_finset_subset_biUnion (by
exact Monotone.directed_le fun t1 t2 (h : ∀ ⦃x⦄, x ∈ t1 → x ∈ t2) =>
Set.iUnion_mono fun _ => Set.iUnion_mono' fun h1 => ⟨h h1, refl _⟩) hs
exact (h t).mono ht
end Theory
variable (L)
/-- A version of The Downward Löwenheim–Skolem theorem where the structure `N` elementarily embeds
into `M`, but is not by type a substructure of `M`, and thus can be chosen to belong to the universe
of the cardinal `κ`.
-/
theorem exists_elementaryEmbedding_card_eq_of_le (M : Type w') [L.Structure M] [Nonempty M]
(κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ)
(h3 : lift.{w'} κ ≤ Cardinal.lift.{w} #M) :
∃ N : Bundled L.Structure, Nonempty (N ↪ₑ[L] M) ∧ #N = κ := by
obtain ⟨S, _, hS⟩ := exists_elementarySubstructure_card_eq L ∅ κ h1 (by simp) h2 h3
have : Small.{w} S := by
rw [← lift_inj.{_, w + 1}, lift_lift, lift_lift] at hS
exact small_iff_lift_mk_lt_univ.2 (lt_of_eq_of_lt hS κ.lift_lt_univ')
refine
⟨(equivShrink S).bundledInduced L,
⟨S.subtype.comp (Equiv.bundledInducedEquiv L _).symm.toElementaryEmbedding⟩,
lift_inj.1 (_root_.trans ?_ hS)⟩
simp only [Equiv.bundledInduced_α, lift_mk_shrink']
section
/-- The **Upward Löwenheim–Skolem Theorem**: If `κ` is a cardinal greater than the cardinalities of
`L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. -/
theorem exists_elementaryEmbedding_card_eq_of_ge (M : Type w') [L.Structure M] [iM : Infinite M]
(κ : Cardinal.{w}) (h1 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ)
(h2 : Cardinal.lift.{w} #M ≤ Cardinal.lift.{w'} κ) :
∃ N : Bundled L.Structure, Nonempty (M ↪ₑ[L] N) ∧ #N = κ := by
obtain ⟨N0, hN0⟩ := (L.elementaryDiagram M).exists_large_model_of_infinite_model κ M
rw [← lift_le.{max u v}, lift_lift, lift_lift] at h2
obtain ⟨N, ⟨NN0⟩, hN⟩ :=
exists_elementaryEmbedding_card_eq_of_le (L[[M]]) N0 κ
(aleph0_le_lift.1 ((aleph0_le_lift.2 (aleph0_le_mk M)).trans h2))
(by
simp only [card_withConstants, lift_add, lift_lift]
rw [add_comm, add_eq_max (aleph0_le_lift.2 (infinite_iff.1 iM)), max_le_iff]
rw [← lift_le.{w'}, lift_lift, lift_lift] at h1
exact ⟨h2, h1⟩)
(hN0.trans (by rw [← lift_umax, lift_id]))
letI := (lhomWithConstants L M).reduct N
haveI h : N ⊨ L.elementaryDiagram M :=
(NN0.theory_model_iff (L.elementaryDiagram M)).2 inferInstance
refine ⟨Bundled.of N, ⟨?_⟩, hN⟩
apply ElementaryEmbedding.ofModelsElementaryDiagram L M N
end
/-- The Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L`
and an infinite `L`-structure `M`, then there is an elementary embedding in the appropriate
direction between then `M` and a structure of cardinality `κ`. -/
theorem exists_elementaryEmbedding_card_eq (M : Type w') [L.Structure M] [iM : Infinite M]
(κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : Bundled L.Structure, (Nonempty (N ↪ₑ[L] M) ∨ Nonempty (M ↪ₑ[L] N)) ∧ #N = κ := by
cases le_or_gt (lift.{w'} κ) (Cardinal.lift.{w} #M) with
| inl h =>
obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_le L M κ h1 h2 h
exact ⟨N, Or.inl hN1, hN2⟩
| inr h =>
obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_ge L M κ h2 (le_of_lt h)
exact ⟨N, Or.inr hN1, hN2⟩
/-- A consequence of the Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the
cardinalities of `L` and an infinite `L`-structure `M`, then there is a structure of cardinality `κ`
elementarily equivalent to `M`. -/
theorem exists_elementarilyEquivalent_card_eq (M : Type w') [L.Structure M] [Infinite M]
(κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : CategoryTheory.Bundled L.Structure, (M ≅[L] N) ∧ #N = κ := by
obtain ⟨N, NM | MN, hNκ⟩ := exists_elementaryEmbedding_card_eq L M κ h1 h2
· exact ⟨N, NM.some.elementarilyEquivalent.symm, hNκ⟩
· exact ⟨N, MN.some.elementarilyEquivalent, hNκ⟩
variable {L}
namespace Theory
theorem exists_model_card_eq (h : ∃ M : ModelType.{u, v, max u v} T, Infinite M) (κ : Cardinal.{w})
(h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : ModelType.{u, v, w} T, #N = κ := by
cases h with
| intro M MI =>
haveI := MI
obtain ⟨N, hN, rfl⟩ := exists_elementarilyEquivalent_card_eq L M κ h1 h2
haveI : Nonempty N := hN.nonempty
exact ⟨hN.theory_model.bundled, rfl⟩
|
variable (T)
/-- A theory models a (bounded) formula when any of its nonempty models realizes that formula on all
inputs. -/
def ModelsBoundedFormula (φ : L.BoundedFormula α n) : Prop :=
| Mathlib/ModelTheory/Satisfiability.lean | 275 | 280 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel, Heather Macbeth
-/
import Mathlib.Analysis.Convex.Slope
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Tactic.LinearCombination
/-!
# Collection of convex functions
In this file we prove that the following functions are convex or strictly convex:
* `strictConvexOn_exp` : The exponential function is strictly convex.
* `strictConcaveOn_log_Ioi`, `strictConcaveOn_log_Iio`: `Real.log` is strictly concave on
$(0, +∞)$ and $(-∞, 0)$ respectively.
* `convexOn_rpow`, `strictConvexOn_rpow` : For `p : ℝ`, `fun x ↦ x ^ p` is convex on $[0, +∞)$ when
`1 ≤ p` and strictly convex when `1 < p`.
The proofs in this file are deliberately elementary, *not* by appealing to the sign of the second
derivative. This is in order to keep this file early in the import hierarchy, since it is on the
path to Hölder's and Minkowski's inequalities and after that to Lp spaces and most of measure
theory.
(Strict) concavity of `fun x ↦ x ^ p` for `0 < p < 1` (`0 ≤ p ≤ 1`) can be found in
`Mathlib.Analysis.Convex.SpecificFunctions.Pow`.
## See also
`Mathlib.Analysis.Convex.Mul` for convexity of `x ↦ x ^ n`
-/
open Real Set NNReal
/-- `Real.exp` is strictly convex on the whole real line. -/
theorem strictConvexOn_exp : StrictConvexOn ℝ univ exp := by
apply strictConvexOn_of_slope_strict_mono_adjacent convex_univ
rintro x y z - - hxy hyz
trans exp y
· have h1 : 0 < y - x := by linarith
have h2 : x - y < 0 := by linarith
rw [div_lt_iff₀ h1]
calc
exp y - exp x = exp y - exp y * exp (x - y) := by rw [← exp_add]; ring_nf
_ = exp y * (1 - exp (x - y)) := by ring
_ < exp y * -(x - y) := by gcongr; linarith [add_one_lt_exp h2.ne]
_ = exp y * (y - x) := by ring
· have h1 : 0 < z - y := by linarith
rw [lt_div_iff₀ h1]
calc
exp y * (z - y) < exp y * (exp (z - y) - 1) := by
gcongr _ * ?_
linarith [add_one_lt_exp h1.ne']
_ = exp (z - y) * exp y - exp y := by ring
_ ≤ exp z - exp y := by rw [← exp_add]; ring_nf; rfl
/-- `Real.exp` is convex on the whole real line. -/
theorem convexOn_exp : ConvexOn ℝ univ exp :=
strictConvexOn_exp.convexOn
/-- `Real.log` is strictly concave on `(0, +∞)`. -/
theorem strictConcaveOn_log_Ioi : StrictConcaveOn ℝ (Ioi 0) log := by
apply strictConcaveOn_of_slope_strict_anti_adjacent (convex_Ioi (0 : ℝ))
intro x y z (hx : 0 < x) (hz : 0 < z) hxy hyz
have hy : 0 < y := hx.trans hxy
trans y⁻¹
· have h : 0 < z - y := by linarith
rw [div_lt_iff₀ h]
have hyz' : 0 < z / y := by positivity
have hyz'' : z / y ≠ 1 := by
contrapose! h
rw [div_eq_one_iff_eq hy.ne'] at h
simp [h]
calc
log z - log y = log (z / y) := by rw [← log_div hz.ne' hy.ne']
_ < z / y - 1 := log_lt_sub_one_of_pos hyz' hyz''
_ = y⁻¹ * (z - y) := by field_simp
· have h : 0 < y - x := by linarith
rw [lt_div_iff₀ h]
have hxy' : 0 < x / y := by positivity
have hxy'' : x / y ≠ 1 := by
contrapose! h
rw [div_eq_one_iff_eq hy.ne'] at h
simp [h]
calc
y⁻¹ * (y - x) = 1 - x / y := by field_simp
_ < -log (x / y) := by linarith [log_lt_sub_one_of_pos hxy' hxy'']
_ = -(log x - log y) := by rw [log_div hx.ne' hy.ne']
_ = log y - log x := by ring
/-- **Bernoulli's inequality** for real exponents, strict version: for `1 < p` and `-1 ≤ s`, with
`s ≠ 0`, we have `1 + p * s < (1 + s) ^ p`. -/
theorem one_add_mul_self_lt_rpow_one_add {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp : 1 < p) :
1 + p * s < (1 + s) ^ p := by
have hp' : 0 < p := zero_lt_one.trans hp
rcases eq_or_lt_of_le hs with rfl | hs
· rwa [add_neg_cancel, zero_rpow hp'.ne', mul_neg_one, add_neg_lt_iff_lt_add, zero_add]
have hs1 : 0 < 1 + s := neg_lt_iff_pos_add'.mp hs
rcases le_or_lt (1 + p * s) 0 with hs2 | hs2
· exact hs2.trans_lt (rpow_pos_of_pos hs1 _)
have hs3 : 1 + s ≠ 1 := hs' ∘ add_eq_left.mp
have hs4 : 1 + p * s ≠ 1 := by
contrapose! hs'; rwa [add_eq_left, mul_eq_zero, eq_false_intro hp'.ne', false_or] at hs'
rw [rpow_def_of_pos hs1, ← exp_log hs2]
apply exp_strictMono
rcases lt_or_gt_of_ne hs' with hs' | hs'
· rw [← div_lt_iff₀ hp', ← div_lt_div_right_of_neg hs']
convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs2 hs1 hs4 hs3 _ using 1
· rw [add_sub_cancel_left, log_one, sub_zero]
· rw [add_sub_cancel_left, div_div, log_one, sub_zero]
· apply add_lt_add_left (mul_lt_of_one_lt_left hs' hp)
· rw [← div_lt_iff₀ hp', ← div_lt_div_iff_of_pos_right hs']
convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs1 hs2 hs3 hs4 _ using 1
· rw [add_sub_cancel_left, div_div, log_one, sub_zero]
· rw [add_sub_cancel_left, log_one, sub_zero]
· apply add_lt_add_left (lt_mul_of_one_lt_left hs' hp)
/-- **Bernoulli's inequality** for real exponents, non-strict version: for `1 ≤ p` and `-1 ≤ s`
we have `1 + p * s ≤ (1 + s) ^ p`. -/
theorem one_add_mul_self_le_rpow_one_add {s : ℝ} (hs : -1 ≤ s) {p : ℝ} (hp : 1 ≤ p) :
1 + p * s ≤ (1 + s) ^ p := by
rcases eq_or_lt_of_le hp with (rfl | hp)
· simp
by_cases hs' : s = 0
· simp [hs']
exact (one_add_mul_self_lt_rpow_one_add hs hs' hp).le
/-- **Bernoulli's inequality** for real exponents, strict version: for `0 < p < 1` and `-1 ≤ s`,
with `s ≠ 0`, we have `(1 + s) ^ p < 1 + p * s`. -/
theorem rpow_one_add_lt_one_add_mul_self {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp1 : 0 < p)
(hp2 : p < 1) : (1 + s) ^ p < 1 + p * s := by
rcases eq_or_lt_of_le hs with rfl | hs
· rwa [add_neg_cancel, zero_rpow hp1.ne', mul_neg_one, lt_add_neg_iff_add_lt, zero_add]
have hs1 : 0 < 1 + s := neg_lt_iff_pos_add'.mp hs
have hs2 : 0 < 1 + p * s := by
rw [← neg_lt_iff_pos_add']
rcases lt_or_gt_of_ne hs' with h | h
· exact hs.trans (lt_mul_of_lt_one_left h hp2)
· exact neg_one_lt_zero.trans (mul_pos hp1 h)
have hs3 : 1 + s ≠ 1 := hs' ∘ add_eq_left.mp
have hs4 : 1 + p * s ≠ 1 := by
contrapose! hs'; rwa [add_eq_left, mul_eq_zero, eq_false_intro hp1.ne', false_or] at hs'
rw [rpow_def_of_pos hs1, ← exp_log hs2]
apply exp_strictMono
rcases lt_or_gt_of_ne hs' with hs' | hs'
· rw [← lt_div_iff₀ hp1, ← div_lt_div_right_of_neg hs']
convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs1 hs2 hs3 hs4 _ using 1
· rw [add_sub_cancel_left, div_div, log_one, sub_zero]
· rw [add_sub_cancel_left, log_one, sub_zero]
· apply add_lt_add_left (lt_mul_of_lt_one_left hs' hp2)
· rw [← lt_div_iff₀ hp1, ← div_lt_div_iff_of_pos_right hs']
convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs2 hs1 hs4 hs3 _ using 1
· rw [add_sub_cancel_left, log_one, sub_zero]
· rw [add_sub_cancel_left, div_div, log_one, sub_zero]
· apply add_lt_add_left (mul_lt_of_lt_one_left hs' hp2)
/-- **Bernoulli's inequality** for real exponents, non-strict version: for `0 ≤ p ≤ 1` and `-1 ≤ s`
we have `(1 + s) ^ p ≤ 1 + p * s`. -/
theorem rpow_one_add_le_one_add_mul_self {s : ℝ} (hs : -1 ≤ s) {p : ℝ} (hp1 : 0 ≤ p) (hp2 : p ≤ 1) :
(1 + s) ^ p ≤ 1 + p * s := by
rcases eq_or_lt_of_le hp1 with (rfl | hp1)
· simp
rcases eq_or_lt_of_le hp2 with (rfl | hp2)
· simp
by_cases hs' : s = 0
· simp [hs']
exact (rpow_one_add_lt_one_add_mul_self hs hs' hp1 hp2).le
/-- For `p : ℝ` with `1 < p`, `fun x ↦ x ^ p` is strictly convex on $[0, +∞)$. -/
theorem strictConvexOn_rpow {p : ℝ} (hp : 1 < p) : StrictConvexOn ℝ (Ici 0) fun x : ℝ ↦ x ^ p := by
apply strictConvexOn_of_slope_strict_mono_adjacent (convex_Ici (0 : ℝ))
intro x y z (hx : 0 ≤ x) (hz : 0 ≤ z) hxy hyz
have hy : 0 < y := hx.trans_lt hxy
have hy' : 0 < y ^ p := rpow_pos_of_pos hy _
trans p * y ^ (p - 1)
· have q : 0 < y - x := by rwa [sub_pos]
rw [div_lt_iff₀ q, ← div_lt_div_iff_of_pos_right hy', _root_.sub_div, div_self hy'.ne',
← div_rpow hx hy.le, sub_lt_comm, ← add_sub_cancel_right (x / y) 1, add_comm, add_sub_assoc,
← div_mul_eq_mul_div, mul_div_assoc, ← rpow_sub hy, sub_sub_cancel_left, rpow_neg_one,
mul_assoc, ← div_eq_inv_mul, sub_eq_add_neg, ← mul_neg, ← neg_div, neg_sub, _root_.sub_div,
div_self hy.ne']
apply one_add_mul_self_lt_rpow_one_add _ _ hp
· rw [le_sub_iff_add_le, neg_add_cancel, div_nonneg_iff]
exact Or.inl ⟨hx, hy.le⟩
· rw [sub_ne_zero]
exact ((div_lt_one hy).mpr hxy).ne
· have q : 0 < z - y := by rwa [sub_pos]
rw [lt_div_iff₀ q, ← div_lt_div_iff_of_pos_right hy', _root_.sub_div, div_self hy'.ne',
← div_rpow hz hy.le, lt_sub_iff_add_lt', ← add_sub_cancel_right (z / y) 1, add_comm _ 1,
add_sub_assoc, ← div_mul_eq_mul_div, mul_div_assoc, ← rpow_sub hy, sub_sub_cancel_left,
rpow_neg_one, mul_assoc, ← div_eq_inv_mul, _root_.sub_div, div_self hy.ne']
apply one_add_mul_self_lt_rpow_one_add _ _ hp
· rw [le_sub_iff_add_le, neg_add_cancel, div_nonneg_iff]
exact Or.inl ⟨hz, hy.le⟩
· rw [sub_ne_zero]
exact ((one_lt_div hy).mpr hyz).ne'
theorem convexOn_rpow {p : ℝ} (hp : 1 ≤ p) : ConvexOn ℝ (Ici 0) fun x : ℝ ↦ x ^ p := by
rcases eq_or_lt_of_le hp with (rfl | hp)
· simpa using convexOn_id (convex_Ici _)
exact (strictConvexOn_rpow hp).convexOn
theorem strictConcaveOn_log_Iio : StrictConcaveOn ℝ (Iio 0) log := by
refine ⟨convex_Iio _, ?_⟩
| intro x (hx : x < 0) y (hy : y < 0) hxy a b ha hb hab
have hx' : 0 < -x := by linarith
have hy' : 0 < -y := by linarith
have hxy' : -x ≠ -y := by contrapose! hxy; linarith
| Mathlib/Analysis/Convex/SpecificFunctions/Basic.lean | 206 | 209 |
/-
Copyright (c) 2022 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov, Kevin H. Wilson, Heather Macbeth
-/
import Mathlib.Order.Filter.Tendsto
/-!
# Product and coproduct filters
In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product
of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and
`Filter.Tendsto Prod.snd l g`.
## Implementation details
The product filter cannot be defined using the monad structure on filters. For example:
```lean
F := do {x ← seq, y ← top, return (x, y)}
G := do {y ← top, x ← seq, return (x, y)}
```
hence:
```lean
s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s
s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s
```
Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`.
As product filter we want to have `F` as result.
## Notations
* `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`.
-/
open Set
open Filter
namespace Filter
variable {α β γ δ : Type*} {ι : Sort*}
section Prod
variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β}
theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g :=
inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht)
theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} :
s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by
constructor
· rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩
exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩
· rintro ⟨t₁, ht₁, t₂, ht₂, h⟩
exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h
@[simp]
theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by
simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint]
@[simp]
theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g :=
⟨fun h =>
let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h
(prod_subset_prod_iff.1 H).elim
(fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h =>
h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e =>
absurd ht'e (nonempty_of_mem ht').ne_empty,
fun h => prod_mem_prod h.1 h.2⟩
theorem mem_prod_principal {s : Set (α × β)} :
s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by
rw [← @exists_mem_subset_iff _ f, mem_prod_iff]
refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩
· rintro ⟨v, v_in, hv⟩ a a_in b b_in
exact hv (mk_mem_prod a_in <| v_in b_in)
· rintro ⟨x, y⟩ ⟨hx, hy⟩
exact h hx y hy
theorem mem_prod_top {s : Set (α × β)} :
s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by
rw [← principal_univ, mem_prod_principal]
simp only [mem_univ, forall_true_left]
theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} :
(∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by
rw [eventually_iff, eventually_iff, mem_prod_principal]
simp only [mem_setOf_eq]
theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) :
comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by
rw [prod_eq_inf, comap_inf, Filter.comap_comap, Filter.comap_comap]
theorem comap_prodMap_prod (f : α → β) (g : γ → δ) (lb : Filter β) (ld : Filter δ) :
comap (Prod.map f g) (lb ×ˢ ld) = comap f lb ×ˢ comap g ld := by
simp [prod_eq_inf, comap_comap, Function.comp_def]
theorem prod_top : f ×ˢ (⊤ : Filter β) = f.comap Prod.fst := by
rw [prod_eq_inf, comap_top, inf_top_eq]
theorem top_prod : (⊤ : Filter α) ×ˢ g = g.comap Prod.snd := by
rw [prod_eq_inf, comap_top, top_inf_eq]
theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by
simp only [prod_eq_inf, comap_sup, inf_sup_right]
theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by
simp only [prod_eq_inf, comap_sup, inf_sup_left]
theorem eventually_prod_iff {p : α × β → Prop} :
(∀ᶠ x in f ×ˢ g, p x) ↔
∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧
∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by
simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g
theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f :=
tendsto_inf_left tendsto_comap
theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g :=
tendsto_inf_right tendsto_comap
/-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to
`g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a
product of two topological spaces. -/
theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) :
Tendsto (fun a ↦ (m a).1) f g :=
tendsto_fst.comp H
/-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to
`h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a
product of two topological spaces. -/
theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) :
Tendsto (fun a ↦ (m a).2) f h :=
tendsto_snd.comp H
theorem Tendsto.prodMk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ}
(h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) :=
tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩
@[deprecated (since := "2025-03-10")]
alias Tendsto.prod_mk := Tendsto.prodMk
theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) :=
tendsto_snd.prodMk tendsto_fst
theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) :
∀ᶠ x in la ×ˢ lb, p (x : α × β).1 :=
tendsto_fst.eventually h
theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) :
∀ᶠ x in la ×ˢ lb, p (x : α × β).2 :=
tendsto_snd.eventually h
theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β}
{pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 :=
(ha.prod_inl lb).and (hb.prod_inr la)
theorem EventuallyEq.prodMap {δ} {la : Filter α} {fa ga : α → γ} (ha : fa =ᶠ[la] ga)
{lb : Filter β} {fb gb : β → δ} (hb : fb =ᶠ[lb] gb) :
Prod.map fa fb =ᶠ[la ×ˢ lb] Prod.map ga gb :=
(Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2
@[deprecated (since := "2025-03-10")]
alias EventuallyEq.prod_map := EventuallyEq.prodMap
theorem EventuallyLE.prodMap {δ} [LE γ] [LE δ] {la : Filter α} {fa ga : α → γ} (ha : fa ≤ᶠ[la] ga)
{lb : Filter β} {fb gb : β → δ} (hb : fb ≤ᶠ[lb] gb) :
Prod.map fa fb ≤ᶠ[la ×ˢ lb] Prod.map ga gb :=
Eventually.prod_mk ha hb
@[deprecated (since := "2025-03-10")]
alias EventuallyLE.prod_map := EventuallyLE.prodMap
theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop}
(h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by
rcases eventually_prod_iff.1 h with ⟨pa, ha, pb, hb, h⟩
exact ha.mono fun a ha => hb.mono fun b hb => h ha hb
protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop}
(h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 :=
mt (fun h ↦ by simpa only [not_frequently] using h.curry) h
lemma Frequently.of_curry {la : Filter α} {lb : Filter β} {p : α × β → Prop}
(h : ∃ᶠ x in la, ∃ᶠ y in lb, p (x, y)) : ∃ᶠ xy in la ×ˢ lb, p xy :=
h.uncurry
/-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about
all diagonal pairs `(i, i)` -/
theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) :
∀ᶠ i in f, p (i, i) := by
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
apply (ht.and hs).mono fun x hx => hst hx.1 hx.2
theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} :
(∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by
intro h
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2]
theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} :
(∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by
intro h
obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h
exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2]
theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) :=
tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod
theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} :
(⨅ i, f i) ×ˢ g = ⨅ i, f i ×ˢ g := by
simp only [prod_eq_inf, comap_iInf, iInf_inf]
theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} :
(f ×ˢ ⨅ i, g i) = ⨅ i, f ×ˢ g i := by
simp only [prod_eq_inf, comap_iInf, inf_iInf]
@[mono, gcongr]
theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) :
f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ :=
inf_le_inf (comap_mono hf) (comap_mono hg)
@[gcongr]
theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≤ f₂) : f₁ ×ˢ g ≤ f₂ ×ˢ g :=
Filter.prod_mono hf rfl.le
@[gcongr]
theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≤ g₂) : f ×ˢ g₁ ≤ f ×ˢ g₂ :=
Filter.prod_mono rfl.le hf
theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
{f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} :
comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by
simp only [prod_eq_inf, comap_comap, comap_inf, Function.comp_def]
theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by
simp only [prod_eq_inf, comap_comap, Function.comp_def, inf_comm, Prod.swap, comap_inf]
theorem prod_comm : f ×ˢ g = map (fun p : β × α => (p.2, p.1)) (g ×ˢ f) := by
rw [prod_comm', ← map_swap_eq_comap_swap]
rfl
theorem mem_prod_iff_left {s : Set (α × β)} :
s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by
simp only [mem_prod_iff, prod_subset_iff]
refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff
exact exists_congr fun _ => Iff.rfl.and forall₂_swap
theorem mem_prod_iff_right {s : Set (α × β)} :
s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by
rw [prod_comm, mem_map, mem_prod_iff_left]; rfl
@[simp]
theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by
ext s
simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def,
exists_mem_subset_iff]
@[simp]
theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by
rw [prod_comm, map_map]; apply map_fst_prod
@[simp]
theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] :
f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ ↔ f₁ ≤ f₂ ∧ g₁ ≤ g₂ :=
⟨fun h =>
⟨map_fst_prod f₁ g₁ ▸ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▸ tendsto_snd.mono_left h⟩,
fun h => prod_mono h.1 h.2⟩
@[simp]
theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] :
f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by
refine ⟨fun h => ?_, fun h => h.1 ▸ h.2 ▸ rfl⟩
have hle : f₁ ≤ f₂ ∧ g₁ ≤ g₂ := prod_le_prod.1 h.le
haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2
exact ⟨hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩
theorem eventually_swap_iff {p : α × β → Prop} :
(∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by
rw [prod_comm]; rfl
theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) :
map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by
simp_rw [← comap_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc,
Function.comp_def, Equiv.prodAssoc_symm_apply]
theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) :
map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by
simp_rw [map_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc,
Function.comp_def, Equiv.prodAssoc_apply]
theorem tendsto_prodAssoc {h : Filter γ} :
Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) :=
(prod_assoc f g h).le
theorem tendsto_prodAssoc_symm {h : Filter γ} :
Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) :=
(prod_assoc_symm f g h).le
/-- A useful lemma when dealing with uniformities. -/
theorem map_swap4_prod {h : Filter γ} {k : Filter δ} :
map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) =
(f ×ˢ h) ×ˢ (g ×ˢ k) := by
simp_rw [map_swap4_eq_comap, prod_eq_inf, comap_inf, comap_comap]; ac_rfl
| theorem tendsto_swap4_prod {h : Filter γ} {k : Filter δ} :
Tendsto (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k))
((f ×ˢ h) ×ˢ (g ×ˢ k)) :=
map_swap4_prod.le
theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x}
| Mathlib/Order/Filter/Prod.lean | 308 | 313 |
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.Basic
import Mathlib.Algebra.GroupWithZero.Basic
/-!
# Basic Translation Lemmas Between Functions Defined for Continued Fractions
## Summary
Some simple translation lemmas between the different definitions of functions defined in
`Algebra.ContinuedFractions.Basic`.
-/
namespace GenContFract
section General
/-!
### Translations Between General Access Functions
Here we give some basic translations that hold by definition between the various methods that allow
us to access the numerators and denominators of a continued fraction.
-/
variable {α : Type*} {g : GenContFract α} {n : ℕ}
theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl
theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl
theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq]
theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by
rw [terminatedAt_iff_s_none, partNum_none_iff_s_none]
theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by
cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq]
theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by
rw [terminatedAt_iff_s_none, partDen_none_iff_s_none]
theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq]
theorem partDen_eq_s_b {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) :
g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq]
theorem exists_s_a_of_partNum {a : α} (nth_partNum_eq : g.partNums.get? n = some a) :
∃ gp, g.s.get? n = some gp ∧ gp.a = a := by
simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq
theorem exists_s_b_of_partDen {b : α}
(nth_partDen_eq : g.partDens.get? n = some b) :
∃ gp, g.s.get? n = some gp ∧ gp.b = b := by
simpa [partDens, Stream'.Seq.map_get?] using nth_partDen_eq
end General
section WithDivisionRing
/-!
### Translations Between Computational Functions
Here we give some basic translations that hold by definition for the computational methods of a
continued fraction.
-/
variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K]
theorem nth_cont_eq_succ_nth_contAux : g.conts n = g.contsAux (n + 1) :=
rfl
theorem num_eq_conts_a : g.nums n = (g.conts n).a :=
rfl
theorem den_eq_conts_b : g.dens n = (g.conts n).b :=
rfl
theorem conv_eq_num_div_den : g.convs n = g.nums n / g.dens n :=
rfl
theorem conv_eq_conts_a_div_conts_b :
g.convs n = (g.conts n).a / (g.conts n).b :=
rfl
theorem exists_conts_a_of_num {A : K} (nth_num_eq : g.nums n = A) :
∃ conts, g.conts n = conts ∧ conts.a = A := by simpa
theorem exists_conts_b_of_den {B : K} (nth_denom_eq : g.dens n = B) :
∃ conts, g.conts n = conts ∧ conts.b = B := by simpa
@[simp]
theorem zeroth_contAux_eq_one_zero : g.contsAux 0 = ⟨1, 0⟩ :=
rfl
@[simp]
theorem first_contAux_eq_h_one : g.contsAux 1 = ⟨g.h, 1⟩ :=
rfl
@[simp]
theorem zeroth_cont_eq_h_one : g.conts 0 = ⟨g.h, 1⟩ :=
rfl
@[simp]
theorem zeroth_num_eq_h : g.nums 0 = g.h :=
rfl
| @[simp]
theorem zeroth_den_eq_one : g.dens 0 = 1 :=
| Mathlib/Algebra/ContinuedFractions/Translations.lean | 116 | 117 |
/-
Copyright (c) 2020 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.GroupTheory.Complement
/-!
# Semidirect product
This file defines semidirect products of groups, and the canonical maps in and out of the
semidirect product. The semidirect product of `N` and `G` given a hom `φ` from
`G` to the automorphism group of `N` is the product of sets with the group
`⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩`
## Key definitions
There are two homs into the semidirect product `inl : N →* N ⋊[φ] G` and
`inr : G →* N ⋊[φ] G`, and `lift` can be used to define maps `N ⋊[φ] G →* H`
out of the semidirect product given maps `fn : N →* H` and `fg : G →* H` that satisfy the
condition `∀ n g, fn (φ g n) = fg g * fn n * fg g⁻¹`
## Notation
This file introduces the global notation `N ⋊[φ] G` for `SemidirectProduct N G φ`
## Tags
group, semidirect product
-/
open Subgroup
variable (N : Type*) (G : Type*) {H : Type*} [Group N] [Group G] [Group H]
-- Don't generate sizeOf and injectivity lemmas, which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
set_option genInjectivity false in
/-- The semidirect product of groups `N` and `G`, given a map `φ` from `G` to the automorphism
group of `N`. It the product of sets with the group operation
`⟨n₁, g₁⟩ * ⟨n₂, g₂⟩ = ⟨n₁ * φ g₁ n₂, g₁ * g₂⟩` -/
@[ext]
structure SemidirectProduct (φ : G →* MulAut N) where
/-- The element of N -/
left : N
/-- The element of G -/
right : G
deriving DecidableEq
-- Porting note: unknown attribute
-- attribute [pp_using_anonymous_constructor] SemidirectProduct
@[inherit_doc]
notation:35 N " ⋊[" φ:35 "] " G:35 => SemidirectProduct N G φ
namespace SemidirectProduct
variable {N G}
variable {φ : G →* MulAut N}
instance : Mul (SemidirectProduct N G φ) where
mul a b := ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩
lemma mul_def (a b : SemidirectProduct N G φ) : a * b = ⟨a.1 * φ a.2 b.1, a.2 * b.2⟩ := rfl
@[simp]
theorem mul_left (a b : N ⋊[φ] G) : (a * b).left = a.left * φ a.right b.left := rfl
@[simp]
theorem mul_right (a b : N ⋊[φ] G) : (a * b).right = a.right * b.right := rfl
instance : One (SemidirectProduct N G φ) where one := ⟨1, 1⟩
@[simp]
theorem one_left : (1 : N ⋊[φ] G).left = 1 := rfl
@[simp]
theorem one_right : (1 : N ⋊[φ] G).right = 1 := rfl
instance : Inv (SemidirectProduct N G φ) where
inv x := ⟨φ x.2⁻¹ x.1⁻¹, x.2⁻¹⟩
@[simp]
theorem inv_left (a : N ⋊[φ] G) : a⁻¹.left = φ a.right⁻¹ a.left⁻¹ := rfl
@[simp]
theorem inv_right (a : N ⋊[φ] G) : a⁻¹.right = a.right⁻¹ := rfl
instance : Group (N ⋊[φ] G) where
mul_assoc a b c := SemidirectProduct.ext (by simp [mul_assoc]) (by simp [mul_assoc])
one_mul a := SemidirectProduct.ext (by simp) (one_mul a.2)
mul_one a := SemidirectProduct.ext (by simp) (mul_one _)
inv_mul_cancel a := SemidirectProduct.ext (by simp) (by simp)
instance : Inhabited (N ⋊[φ] G) := ⟨1⟩
/-- The canonical map `N →* N ⋊[φ] G` sending `n` to `⟨n, 1⟩` -/
def inl : N →* N ⋊[φ] G where
toFun n := ⟨n, 1⟩
map_one' := rfl
map_mul' := by intros; ext <;>
simp only [mul_left, map_one, MulAut.one_apply, mul_right, mul_one]
@[simp]
theorem left_inl (n : N) : (inl n : N ⋊[φ] G).left = n := rfl
@[simp]
theorem right_inl (n : N) : (inl n : N ⋊[φ] G).right = 1 := rfl
theorem inl_injective : Function.Injective (inl : N → N ⋊[φ] G) :=
Function.injective_iff_hasLeftInverse.2 ⟨left, left_inl⟩
@[simp]
theorem inl_inj {n₁ n₂ : N} : (inl n₁ : N ⋊[φ] G) = inl n₂ ↔ n₁ = n₂ :=
inl_injective.eq_iff
/-- The canonical map `G →* N ⋊[φ] G` sending `g` to `⟨1, g⟩` -/
def inr : G →* N ⋊[φ] G where
toFun g := ⟨1, g⟩
map_one' := rfl
map_mul' := by intros; ext <;> simp
@[simp]
theorem left_inr (g : G) : (inr g : N ⋊[φ] G).left = 1 := rfl
@[simp]
theorem right_inr (g : G) : (inr g : N ⋊[φ] G).right = g := rfl
theorem inr_injective : Function.Injective (inr : G → N ⋊[φ] G) :=
Function.injective_iff_hasLeftInverse.2 ⟨right, right_inr⟩
@[simp]
theorem inr_inj {g₁ g₂ : G} : (inr g₁ : N ⋊[φ] G) = inr g₂ ↔ g₁ = g₂ :=
inr_injective.eq_iff
theorem inl_aut (g : G) (n : N) : (inl (φ g n) : N ⋊[φ] G) = inr g * inl n * inr g⁻¹ := by
ext <;> simp
theorem inl_aut_inv (g : G) (n : N) : (inl ((φ g)⁻¹ n) : N ⋊[φ] G) = inr g⁻¹ * inl n * inr g := by
rw [← MonoidHom.map_inv, inl_aut, inv_inv]
@[simp]
theorem mk_eq_inl_mul_inr (g : G) (n : N) : (⟨n, g⟩ : N ⋊[φ] G) = inl n * inr g := by ext <;> simp
@[simp]
theorem inl_left_mul_inr_right (x : N ⋊[φ] G) : inl x.left * inr x.right = x := by ext <;> simp
/-- The canonical projection map `N ⋊[φ] G →* G`, as a group hom. -/
def rightHom : N ⋊[φ] G →* G where
toFun := SemidirectProduct.right
map_one' := rfl
map_mul' _ _ := rfl
@[simp]
theorem rightHom_eq_right : (rightHom : N ⋊[φ] G → G) = right := rfl
@[simp]
theorem rightHom_comp_inl : (rightHom : N ⋊[φ] G →* G).comp inl = 1 := by ext; simp [rightHom]
@[simp]
theorem rightHom_comp_inr : (rightHom : N ⋊[φ] G →* G).comp inr = MonoidHom.id _ := by
ext; simp [rightHom]
@[simp]
theorem rightHom_inl (n : N) : rightHom (inl n : N ⋊[φ] G) = 1 := by simp [rightHom]
@[simp]
theorem rightHom_inr (g : G) : rightHom (inr g : N ⋊[φ] G) = g := by simp [rightHom]
theorem rightHom_surjective : Function.Surjective (rightHom : N ⋊[φ] G → G) :=
Function.surjective_iff_hasRightInverse.2 ⟨inr, rightHom_inr⟩
theorem range_inl_eq_ker_rightHom : (inl : N →* N ⋊[φ] G).range = rightHom.ker :=
le_antisymm (fun _ ↦ by simp +contextual [MonoidHom.mem_ker, eq_comm])
fun x hx ↦ ⟨x.left, by ext <;> simp_all [MonoidHom.mem_ker]⟩
/-- The bijection between the semidirect product and the product. -/
@[simps]
def equivProd : N ⋊[φ] G ≃ N × G where
toFun x := ⟨x.1, x.2⟩
invFun x := ⟨x.1, x.2⟩
left_inv _ := rfl
right_inv _ := rfl
/-- The group isomorphism between a semidirect product with respect to the trivial map
and the product. -/
@[simps (config := { rhsMd := .default })]
def mulEquivProd : N ⋊[1] G ≃* N × G :=
{ equivProd with map_mul' _ _ := rfl }
section lift
variable (fn : N →* H) (fg : G →* H)
(h : ∀ g, fn.comp (φ g).toMonoidHom = (MulAut.conj (fg g)).toMonoidHom.comp fn)
/-- Define a group hom `N ⋊[φ] G →* H`, by defining maps `N →* H` and `G →* H` -/
def lift : N ⋊[φ] G →* H where
toFun a := fn a.1 * fg a.2
map_one' := by simp
map_mul' a b := by
have := fun n g ↦ DFunLike.ext_iff.1 (h n) g
simp only [MulAut.conj_apply, MonoidHom.comp_apply, MulEquiv.coe_toMonoidHom] at this
simp only [mul_left, mul_right, map_mul, this, mul_assoc, inv_mul_cancel_left]
@[simp]
theorem lift_inl (n : N) : lift fn fg h (inl n) = fn n := by simp [lift]
@[simp]
theorem lift_comp_inl : (lift fn fg h).comp inl = fn := by ext; simp
@[simp]
theorem lift_inr (g : G) : lift fn fg h (inr g) = fg g := by simp [lift]
@[simp]
theorem lift_comp_inr : (lift fn fg h).comp inr = fg := by ext; simp
theorem lift_unique (F : N ⋊[φ] G →* H) :
F = lift (F.comp inl) (F.comp inr) fun _ ↦ by ext; simp [inl_aut] := by
rw [DFunLike.ext_iff]
simp only [lift, MonoidHom.comp_apply, MonoidHom.coe_mk, OneHom.coe_mk, ← map_mul,
inl_left_mul_inr_right, forall_const]
/-- Two maps out of the semidirect product are equal if they're equal after composition
with both `inl` and `inr` -/
theorem hom_ext {f g : N ⋊[φ] G →* H} (hl : f.comp inl = g.comp inl)
(hr : f.comp inr = g.comp inr) : f = g := by
rw [lift_unique f, lift_unique g]
simp only [*]
| Mathlib/GroupTheory/SemidirectProduct.lean | 228 | 228 | |
/-
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, Sophie Morel, Yury Kudryashov
-/
import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace
import Mathlib.Logic.Embedding.Basic
import Mathlib.Data.Fintype.CardEmbedding
import Mathlib.Topology.Algebra.Module.Multilinear.Topology
/-!
# Operator norm on the space of continuous multilinear maps
When `f` is a continuous multilinear map in finitely many variables, we define its norm `‖f‖` as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`.
We show that it is indeed a norm, and prove its basic properties.
## Main results
Let `f` be a multilinear map in finitely many variables.
* `exists_bound_of_continuous` asserts that, if `f` is continuous, then there exists `C > 0`
with `‖f m‖ ≤ C * ∏ i, ‖m i‖` for all `m`.
* `continuous_of_bound`, conversely, asserts that this bound implies continuity.
* `mkContinuous` constructs the associated continuous multilinear map.
Let `f` be a continuous multilinear map in finitely many variables.
* `‖f‖` is its norm, i.e., the smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for
all `m`.
* `le_opNorm f m` asserts the fundamental inequality `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖`.
* `norm_image_sub_le f m₁ m₂` gives a control of the difference `f m₁ - f m₂` in terms of
`‖f‖` and `‖m₁ - m₂‖`.
## Implementation notes
We mostly follow the API (and the proofs) of `OperatorNorm.lean`, with the additional complexity
that we should deal with multilinear maps in several variables.
From the mathematical point of view, all the results follow from the results on operator norm in
one variable, by applying them to one variable after the other through currying. However, this
is only well defined when there is an order on the variables (for instance on `Fin n`) although
the final result is independent of the order. While everything could be done following this
approach, it turns out that direct proofs are easier and more efficient.
-/
suppress_compilation
noncomputable section
open scoped NNReal Topology Uniformity
open Finset Metric Function Filter
/-!
### Type variables
We use the following type variables in this file:
* `𝕜` : a `NontriviallyNormedField`;
* `ι`, `ι'` : finite index types with decidable equality;
* `E`, `E₁` : families of normed vector spaces over `𝕜` indexed by `i : ι`;
* `E'` : a family of normed vector spaces over `𝕜` indexed by `i' : ι'`;
* `Ei` : a family of normed vector spaces over `𝕜` indexed by `i : Fin (Nat.succ n)`;
* `G`, `G'` : normed vector spaces over `𝕜`.
-/
universe u v v' wE wE₁ wE' wG wG'
section continuous_eval
variable {𝕜 ι : Type*} {E : ι → Type*} {F : Type*}
[NormedField 𝕜] [Finite ι] [∀ i, SeminormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)]
[TopologicalSpace F] [AddCommGroup F] [IsTopologicalAddGroup F] [Module 𝕜 F]
instance ContinuousMultilinearMap.instContinuousEval :
ContinuousEval (ContinuousMultilinearMap 𝕜 E F) (Π i, E i) F where
continuous_eval := by
cases nonempty_fintype ι
let _ := IsTopologicalAddGroup.toUniformSpace F
have := isUniformAddGroup_of_addCommGroup (G := F)
refine (UniformOnFun.continuousOn_eval₂ fun m ↦ ?_).comp_continuous
(isEmbedding_toUniformOnFun.continuous.prodMap continuous_id) fun (f, x) ↦ f.cont.continuousAt
exact ⟨ball m 1, NormedSpace.isVonNBounded_of_isBounded _ isBounded_ball,
ball_mem_nhds _ one_pos⟩
namespace ContinuousLinearMap
variable {G : Type*} [AddCommGroup G] [TopologicalSpace G] [Module 𝕜 G] [ContinuousConstSMul 𝕜 F]
lemma continuous_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) :
Continuous (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) := by
fun_prop
lemma continuousOn_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {s} :
ContinuousOn (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) s :=
f.continuous_uncurry_of_multilinear.continuousOn
lemma continuousAt_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {x} :
ContinuousAt (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) x :=
f.continuous_uncurry_of_multilinear.continuousAt
lemma continuousWithinAt_uncurry_of_multilinear (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 E F) {s x} :
ContinuousWithinAt (fun (p : G × (Π i, E i)) ↦ f p.1 p.2) s x :=
f.continuous_uncurry_of_multilinear.continuousWithinAt
end ContinuousLinearMap
end continuous_eval
section Seminorm
variable {𝕜 : Type u} {ι : Type v} {ι' : Type v'} {E : ι → Type wE} {E₁ : ι → Type wE₁}
{E' : ι' → Type wE'} {G : Type wG} {G' : Type wG'}
[Fintype ι'] [NontriviallyNormedField 𝕜] [∀ i, SeminormedAddCommGroup (E i)]
[∀ i, NormedSpace 𝕜 (E i)] [∀ i, SeminormedAddCommGroup (E₁ i)] [∀ i, NormedSpace 𝕜 (E₁ i)]
[SeminormedAddCommGroup G] [NormedSpace 𝕜 G] [SeminormedAddCommGroup G'] [NormedSpace 𝕜 G']
/-!
### Continuity properties of multilinear maps
We relate continuity of multilinear maps to the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, in
both directions. Along the way, we prove useful bounds on the difference `‖f m₁ - f m₂‖`.
-/
namespace MultilinearMap
/-- If `f` is a continuous multilinear map on `E`
and `m` is an element of `∀ i, E i` such that one of the `m i` has norm `0`,
then `f m` has norm `0`.
Note that we cannot drop the continuity assumption because `f (m : Unit → E) = f (m ())`,
where the domain has zero norm and the codomain has a nonzero norm
does not satisfy this condition. -/
lemma norm_map_coord_zero (f : MultilinearMap 𝕜 E G) (hf : Continuous f)
{m : ∀ i, E i} {i : ι} (hi : ‖m i‖ = 0) : ‖f m‖ = 0 := by
classical
rw [← inseparable_zero_iff_norm] at hi ⊢
have : Inseparable (update m i 0) m := inseparable_pi.2 <|
(forall_update_iff m fun i a ↦ Inseparable a (m i)).2 ⟨hi.symm, fun _ _ ↦ rfl⟩
simpa only [map_update_zero] using this.symm.map hf
variable [Fintype ι]
/-- If a multilinear map in finitely many variables on seminormed spaces
sends vectors with a component of norm zero to vectors of norm zero
and satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i`
for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`,
then it satisfies this inequality for all `m`.
The first assumption is automatically satisfied on normed spaces, see `bound_of_shell` below.
For seminormed spaces, it follows from continuity of `f`, see next lemma,
see `bound_of_shell_of_continuous` below. -/
theorem bound_of_shell_of_norm_map_coord_zero (f : MultilinearMap 𝕜 E G)
(hf₀ : ∀ {m i}, ‖m i‖ = 0 → ‖f m‖ = 0)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
rcases em (∃ i, ‖m i‖ = 0) with (⟨i, hi⟩ | hm)
· rw [hf₀ hi, prod_eq_zero (mem_univ i) hi, mul_zero]
push_neg at hm
choose δ hδ0 hδm_lt hle_δm _ using fun i => rescale_to_shell_semi_normed (hc i) (hε i) (hm i)
have hδ0 : 0 < ∏ i, ‖δ i‖ := prod_pos fun i _ => norm_pos_iff.2 (hδ0 i)
simpa [map_smul_univ, norm_smul, prod_mul_distrib, mul_left_comm C, mul_le_mul_left hδ0] using
hf (fun i => δ i • m i) hle_δm hδm_lt
/-- If a continuous multilinear map in finitely many variables on normed spaces satisfies
the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive
numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. -/
theorem bound_of_shell_of_continuous (f : MultilinearMap 𝕜 E G) (hfc : Continuous f)
{ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖)
(hf : ∀ m : ∀ i, E i, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(m : ∀ i, E i) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
bound_of_shell_of_norm_map_coord_zero f (norm_map_coord_zero f hfc) hε hc hf m
/-- If a multilinear map in finitely many variables on normed spaces is continuous, then it
satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, for some `C` which can be chosen to be
positive. -/
theorem exists_bound_of_continuous (f : MultilinearMap 𝕜 E G) (hf : Continuous f) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := by
cases isEmpty_or_nonempty ι
· refine ⟨‖f 0‖ + 1, add_pos_of_nonneg_of_pos (norm_nonneg _) zero_lt_one, fun m => ?_⟩
obtain rfl : m = 0 := funext (IsEmpty.elim ‹_›)
simp [univ_eq_empty, zero_le_one]
obtain ⟨ε : ℝ, ε0 : 0 < ε, hε : ∀ m : ∀ i, E i, ‖m - 0‖ < ε → ‖f m - f 0‖ < 1⟩ :=
NormedAddCommGroup.tendsto_nhds_nhds.1 (hf.tendsto 0) 1 zero_lt_one
simp only [sub_zero, f.map_zero] at hε
rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩
have : 0 < (‖c‖ / ε) ^ Fintype.card ι := pow_pos (div_pos (zero_lt_one.trans hc) ε0) _
refine ⟨_, this, ?_⟩
refine f.bound_of_shell_of_continuous hf (fun _ => ε0) (fun _ => hc) fun m hcm hm => ?_
refine (hε m ((pi_norm_lt_iff ε0).2 hm)).le.trans ?_
rw [← div_le_iff₀' this, one_div, ← inv_pow, inv_div, Fintype.card, ← prod_const]
exact prod_le_prod (fun _ _ => div_nonneg ε0.le (norm_nonneg _)) fun i _ => hcm i
/-- If a multilinear map `f` satisfies a boundedness property around `0`,
one can deduce a bound on `f m₁ - f m₂` using the multilinearity.
Here, we give a precise but hard to use version.
See `norm_image_sub_le_of_bound` for a less precise but more usable version.
The bound reads
`‖f m - f m'‖ ≤
C * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le_of_bound' [DecidableEq ι] (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A :
∀ s : Finset ι,
‖f m₁ - f (s.piecewise m₂ m₁)‖ ≤
C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
intro s
induction' s using Finset.induction with i s his Hrec
· simp
have I :
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ ≤
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
have A : (insert i s).piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₂ i) :=
s.piecewise_insert _ _ _
have B : s.piecewise m₂ m₁ = Function.update (s.piecewise m₂ m₁) i (m₁ i) := by
simp [eq_update_iff, his]
rw [B, A, ← f.map_update_sub]
apply le_trans (H _)
gcongr with j
by_cases h : j = i
· rw [h]
simp
· by_cases h' : j ∈ s <;> simp [h', h, le_refl]
calc
‖f m₁ - f ((insert i s).piecewise m₂ m₁)‖ ≤
‖f m₁ - f (s.piecewise m₂ m₁)‖ +
‖f (s.piecewise m₂ m₁) - f ((insert i s).piecewise m₂ m₁)‖ := by
rw [← dist_eq_norm, ← dist_eq_norm, ← dist_eq_norm]
exact dist_triangle _ _ _
_ ≤ (C * ∑ i ∈ s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) +
C * ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
(add_le_add Hrec I)
_ = C * ∑ i ∈ insert i s, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := by
simp [his, add_comm, left_distrib]
convert A univ
simp
/-- If `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂`
using the multilinearity. Here, we give a usable but not very precise version. See
`norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is
`‖f m - f m'‖ ≤ C * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le_of_bound (f : MultilinearMap 𝕜 E G)
{C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
classical
have A :
∀ i : ι,
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
intro i
calc
∏ j, (if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖) ≤
∏ j : ι, Function.update (fun _ => max ‖m₁‖ ‖m₂‖) i ‖m₁ - m₂‖ j := by
apply Finset.prod_le_prod
· intro j _
by_cases h : j = i <;> simp [h, norm_nonneg]
· intro j _
by_cases h : j = i
· rw [h]
simp only [ite_true, Function.update_self]
exact norm_le_pi_norm (m₁ - m₂) i
· simp [h, - le_sup_iff, - sup_le_iff, sup_le_sup, norm_le_pi_norm]
_ = ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by
rw [prod_update_of_mem (Finset.mem_univ _)]
simp [card_univ_diff]
calc
‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.norm_image_sub_le_of_bound' hC H m₁ m₂
_ ≤ C * ∑ _i, ‖m₁ - m₂‖ * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) := by gcongr; apply A
_ = C * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := by
rw [sum_const, card_univ, nsmul_eq_mul]
ring
/-- If a multilinear map satisfies an inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, then it is
continuous. -/
theorem continuous_of_bound (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
Continuous f := by
let D := max C 1
have D_pos : 0 ≤ D := le_trans zero_le_one (le_max_right _ _)
replace H (m) : ‖f m‖ ≤ D * ∏ i, ‖m i‖ :=
(H m).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity)
refine continuous_iff_continuousAt.2 fun m => ?_
refine
continuousAt_of_locally_lipschitz zero_lt_one
(D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1)) fun m' h' => ?_
rw [dist_eq_norm, dist_eq_norm]
have : max ‖m'‖ ‖m‖ ≤ ‖m‖ + 1 := by
simp [zero_le_one, norm_le_of_mem_closedBall (le_of_lt h')]
calc
‖f m' - f m‖ ≤ D * Fintype.card ι * max ‖m'‖ ‖m‖ ^ (Fintype.card ι - 1) * ‖m' - m‖ :=
f.norm_image_sub_le_of_bound D_pos H m' m
_ ≤ D * Fintype.card ι * (‖m‖ + 1) ^ (Fintype.card ι - 1) * ‖m' - m‖ := by gcongr
/-- Constructing a continuous multilinear map from a multilinear map satisfying a boundedness
condition. -/
def mkContinuous (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
ContinuousMultilinearMap 𝕜 E G :=
{ f with cont := f.continuous_of_bound C H }
@[simp]
theorem coe_mkContinuous (f : MultilinearMap 𝕜 E G) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) :
⇑(f.mkContinuous C H) = f :=
rfl
/-- Given a multilinear map in `n` variables, if one restricts it to `k` variables putting `z` on
the other coordinates, then the resulting restricted function satisfies an inequality
`‖f.restr v‖ ≤ C * ‖z‖^(n-k) * Π ‖v i‖` if the original function satisfies `‖f v‖ ≤ C * Π ‖v i‖`. -/
theorem restr_norm_le {k n : ℕ} (f : MultilinearMap 𝕜 (fun _ : Fin n => G) G')
(s : Finset (Fin n)) (hk : #s = k) (z : G) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖)
(v : Fin k → G) : ‖f.restr s hk z v‖ ≤ C * ‖z‖ ^ (n - k) * ∏ i, ‖v i‖ := by
rw [mul_right_comm, mul_assoc]
convert H _ using 2
simp only [apply_dite norm, Fintype.prod_dite, prod_const ‖z‖, Finset.card_univ,
Fintype.card_of_subtype sᶜ fun _ => mem_compl, card_compl, Fintype.card_fin, hk, mk_coe, ←
(s.orderIsoOfFin hk).symm.bijective.prod_comp fun x => ‖v x‖]
convert rfl
end MultilinearMap
/-!
### Continuous multilinear maps
We define the norm `‖f‖` of a continuous multilinear map `f` in finitely many variables as the
smallest number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that this
defines a normed space structure on `ContinuousMultilinearMap 𝕜 E G`.
-/
namespace ContinuousMultilinearMap
variable [Fintype ι]
theorem bound (f : ContinuousMultilinearMap 𝕜 E G) :
∃ C : ℝ, 0 < C ∧ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
f.toMultilinearMap.exists_bound_of_continuous f.2
open Real
/-- The operator norm of a continuous multilinear map is the inf of all its bounds. -/
def opNorm (f : ContinuousMultilinearMap 𝕜 E G) : ℝ :=
sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ }
instance hasOpNorm : Norm (ContinuousMultilinearMap 𝕜 E G) :=
⟨opNorm⟩
/-- An alias of `ContinuousMultilinearMap.hasOpNorm` with non-dependent types to help typeclass
search. -/
instance hasOpNorm' : Norm (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.hasOpNorm
theorem norm_def (f : ContinuousMultilinearMap 𝕜 E G) :
‖f‖ = sInf { c | 0 ≤ (c : ℝ) ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
rfl
-- So that invocations of `le_csInf` make sense: we show that the set of
-- bounds is nonempty and bounded below.
theorem bounds_nonempty {f : ContinuousMultilinearMap 𝕜 E G} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
let ⟨M, hMp, hMb⟩ := f.bound
⟨M, le_of_lt hMp, hMb⟩
theorem bounds_bddBelow {f : ContinuousMultilinearMap 𝕜 E G} :
BddBelow { c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖ } :=
⟨0, fun _ ⟨hn, _⟩ => hn⟩
theorem isLeast_opNorm (f : ContinuousMultilinearMap 𝕜 E G) :
IsLeast {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} ‖f‖ := by
refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow
simp only [Set.setOf_and, Set.setOf_forall]
exact isClosed_Ici.inter (isClosed_iInter fun m ↦
isClosed_le continuous_const (continuous_id.mul continuous_const))
theorem opNorm_nonneg (f : ContinuousMultilinearMap 𝕜 E G) : 0 ≤ ‖f‖ :=
Real.sInf_nonneg fun _ ⟨hx, _⟩ => hx
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`. -/
theorem le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖ :=
f.isLeast_opNorm.1.2 m
theorem le_mul_prod_of_opNorm_le_of_le {f : ContinuousMultilinearMap 𝕜 E G}
{m : ∀ i, E i} {C : ℝ} {b : ι → ℝ} (hC : ‖f‖ ≤ C) (hm : ∀ i, ‖m i‖ ≤ b i) :
‖f m‖ ≤ C * ∏ i, b i :=
(f.le_opNorm m).trans <| by gcongr; exacts [f.opNorm_nonneg.trans hC, hm _]
@[deprecated (since := "2024-11-27")]
alias le_mul_prod_of_le_opNorm_of_le := le_mul_prod_of_opNorm_le_of_le
theorem le_opNorm_mul_prod_of_le (f : ContinuousMultilinearMap 𝕜 E G)
{m : ∀ i, E i} {b : ι → ℝ} (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ ‖f‖ * ∏ i, b i :=
le_mul_prod_of_opNorm_le_of_le le_rfl hm
theorem le_opNorm_mul_pow_card_of_le (f : ContinuousMultilinearMap 𝕜 E G) {m b} (hm : ‖m‖ ≤ b) :
‖f m‖ ≤ ‖f‖ * b ^ Fintype.card ι := by
simpa only [prod_const] using f.le_opNorm_mul_prod_of_le fun i => (norm_le_pi_norm m i).trans hm
theorem le_opNorm_mul_pow_of_le {n : ℕ} {Ei : Fin n → Type*} [∀ i, SeminormedAddCommGroup (Ei i)]
[∀ i, NormedSpace 𝕜 (Ei i)] (f : ContinuousMultilinearMap 𝕜 Ei G) {m : ∀ i, Ei i} {b : ℝ}
(hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ n := by
simpa only [Fintype.card_fin] using f.le_opNorm_mul_pow_card_of_le hm
theorem le_of_opNorm_le {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ} (h : ‖f‖ ≤ C) (m : ∀ i, E i) :
‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
le_mul_prod_of_opNorm_le_of_le h fun _ ↦ le_rfl
theorem ratio_le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
(‖f m‖ / ∏ i, ‖m i‖) ≤ ‖f‖ :=
div_le_of_le_mul₀ (by positivity) (opNorm_nonneg _) (f.le_opNorm m)
/-- The image of the unit ball under a continuous multilinear map is bounded. -/
theorem unit_le_opNorm (f : ContinuousMultilinearMap 𝕜 E G) {m : ∀ i, E i} (h : ‖m‖ ≤ 1) :
‖f m‖ ≤ ‖f‖ :=
(le_opNorm_mul_pow_card_of_le f h).trans <| by simp
/-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/
theorem opNorm_le_bound {f : ContinuousMultilinearMap 𝕜 E G}
{M : ℝ} (hMp : 0 ≤ M) (hM : ∀ m, ‖f m‖ ≤ M * ∏ i, ‖m i‖) : ‖f‖ ≤ M :=
csInf_le bounds_bddBelow ⟨hMp, hM⟩
theorem opNorm_le_iff {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ} (hC : 0 ≤ C) :
‖f‖ ≤ C ↔ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ :=
⟨fun h _ ↦ le_of_opNorm_le h _, opNorm_le_bound hC⟩
/-- The operator norm satisfies the triangle inequality. -/
theorem opNorm_add_le (f g : ContinuousMultilinearMap 𝕜 E G) : ‖f + g‖ ≤ ‖f‖ + ‖g‖ :=
opNorm_le_bound (add_nonneg (opNorm_nonneg f) (opNorm_nonneg g)) fun x => by
rw [add_mul]
exact norm_add_le_of_le (le_opNorm _ _) (le_opNorm _ _)
theorem opNorm_zero : ‖(0 : ContinuousMultilinearMap 𝕜 E G)‖ = 0 :=
(opNorm_nonneg _).antisymm' <| opNorm_le_bound le_rfl fun m => by simp
section
variable {𝕜' : Type*} [NormedField 𝕜'] [NormedSpace 𝕜' G] [SMulCommClass 𝕜 𝕜' G]
theorem opNorm_smul_le (c : 𝕜') (f : ContinuousMultilinearMap 𝕜 E G) : ‖c • f‖ ≤ ‖c‖ * ‖f‖ :=
(c • f).opNorm_le_bound (mul_nonneg (norm_nonneg _) (opNorm_nonneg _)) fun m ↦ by
rw [smul_apply, norm_smul, mul_assoc]
exact mul_le_mul_of_nonneg_left (le_opNorm _ _) (norm_nonneg _)
variable (𝕜 E G) in
/-- Operator seminorm on the space of continuous multilinear maps, as `Seminorm`.
We use this seminorm
to define a `SeminormedAddCommGroup` structure on `ContinuousMultilinearMap 𝕜 E G`,
but we have to override the projection `UniformSpace`
so that it is definitionally equal to the one coming from the topologies on `E` and `G`. -/
protected def seminorm : Seminorm 𝕜 (ContinuousMultilinearMap 𝕜 E G) :=
.ofSMulLE norm opNorm_zero opNorm_add_le fun c f ↦ f.opNorm_smul_le c
private lemma uniformity_eq_seminorm :
𝓤 (ContinuousMultilinearMap 𝕜 E G) = ⨅ r > 0, 𝓟 {f | ‖f.1 - f.2‖ < r} := by
refine (ContinuousMultilinearMap.seminorm 𝕜 E G).uniformity_eq_of_hasBasis
(ContinuousMultilinearMap.hasBasis_nhds_zero_of_basis Metric.nhds_basis_closedBall)
?_ fun (s, r) ⟨hs, hr⟩ ↦ ?_
· rcases NormedField.exists_lt_norm 𝕜 1 with ⟨c, hc⟩
have hc₀ : 0 < ‖c‖ := one_pos.trans hc
simp only [hasBasis_nhds_zero.mem_iff, Prod.exists]
use 1, closedBall 0 ‖c‖, closedBall 0 1
suffices ∀ f : ContinuousMultilinearMap 𝕜 E G, (∀ x, ‖x‖ ≤ ‖c‖ → ‖f x‖ ≤ 1) → ‖f‖ ≤ 1 by
simpa [NormedSpace.isVonNBounded_closedBall, closedBall_mem_nhds, Set.subset_def, Set.MapsTo]
intro f hf
refine opNorm_le_bound (by positivity) <|
f.1.bound_of_shell_of_continuous f.2 (fun _ ↦ hc₀) (fun _ ↦ hc) fun x hcx hx ↦ ?_
calc
‖f x‖ ≤ 1 := hf _ <| (pi_norm_le_iff_of_nonneg (norm_nonneg c)).2 fun i ↦ (hx i).le
_ = ∏ i : ι, 1 := by simp
_ ≤ ∏ i, ‖x i‖ := Finset.prod_le_prod (fun _ _ ↦ zero_le_one) fun i _ ↦ by
simpa only [div_self hc₀.ne'] using hcx i
_ = 1 * ∏ i, ‖x i‖ := (one_mul _).symm
· rcases (NormedSpace.isVonNBounded_iff' _).1 hs with ⟨ε, hε⟩
rcases exists_pos_mul_lt hr (ε ^ Fintype.card ι) with ⟨δ, hδ₀, hδ⟩
refine ⟨δ, hδ₀, fun f hf x hx ↦ ?_⟩
simp only [Seminorm.mem_ball_zero, mem_closedBall_zero_iff] at hf ⊢
replace hf : ‖f‖ ≤ δ := hf.le
replace hx : ‖x‖ ≤ ε := hε x hx
calc
‖f x‖ ≤ ‖f‖ * ε ^ Fintype.card ι := le_opNorm_mul_pow_card_of_le f hx
_ ≤ δ * ε ^ Fintype.card ι := by have := (norm_nonneg x).trans hx; gcongr
_ ≤ r := (mul_comm _ _).trans_le hδ.le
instance instPseudoMetricSpace : PseudoMetricSpace (ContinuousMultilinearMap 𝕜 E G) :=
.replaceUniformity
(ContinuousMultilinearMap.seminorm 𝕜 E G).toSeminormedAddCommGroup.toPseudoMetricSpace
uniformity_eq_seminorm
/-- Continuous multilinear maps themselves form a seminormed space with respect to
the operator norm. -/
instance seminormedAddCommGroup :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 E G) := ⟨fun _ _ ↦ rfl⟩
/-- An alias of `ContinuousMultilinearMap.seminormedAddCommGroup` with non-dependent types to help
typeclass search. -/
instance seminormedAddCommGroup' :
SeminormedAddCommGroup (ContinuousMultilinearMap 𝕜 (fun _ : ι => G) G') :=
ContinuousMultilinearMap.seminormedAddCommGroup
instance normedSpace : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 E G) :=
⟨fun c f => f.opNorm_smul_le c⟩
/-- An alias of `ContinuousMultilinearMap.normedSpace` with non-dependent types to help typeclass
search. -/
instance normedSpace' : NormedSpace 𝕜' (ContinuousMultilinearMap 𝕜 (fun _ : ι => G') G) :=
ContinuousMultilinearMap.normedSpace
@[deprecated norm_neg (since := "2024-11-24")]
theorem opNorm_neg (f : ContinuousMultilinearMap 𝕜 E G) : ‖-f‖ = ‖f‖ := norm_neg f
/-- The fundamental property of the operator norm of a continuous multilinear map:
`‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`, `nnnorm` version. -/
theorem le_opNNNorm (f : ContinuousMultilinearMap 𝕜 E G) (m : ∀ i, E i) :
‖f m‖₊ ≤ ‖f‖₊ * ∏ i, ‖m i‖₊ :=
NNReal.coe_le_coe.1 <| by
push_cast
exact f.le_opNorm m
theorem le_of_opNNNorm_le (f : ContinuousMultilinearMap 𝕜 E G)
{C : ℝ≥0} (h : ‖f‖₊ ≤ C) (m : ∀ i, E i) : ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ :=
(f.le_opNNNorm m).trans <| mul_le_mul' h le_rfl
theorem opNNNorm_le_iff {f : ContinuousMultilinearMap 𝕜 E G} {C : ℝ≥0} :
‖f‖₊ ≤ C ↔ ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := by
simp only [← NNReal.coe_le_coe]; simp [opNorm_le_iff C.coe_nonneg, NNReal.coe_prod]
theorem isLeast_opNNNorm (f : ContinuousMultilinearMap 𝕜 E G) :
IsLeast {C : ℝ≥0 | ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊} ‖f‖₊ := by
simpa only [← opNNNorm_le_iff] using isLeast_Ici
theorem opNNNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖₊ = max ‖f‖₊ ‖g‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by
simp only [opNNNorm_le_iff, prod_apply, Prod.nnnorm_def, max_le_iff, forall_and]
theorem opNorm_prod (f : ContinuousMultilinearMap 𝕜 E G) (g : ContinuousMultilinearMap 𝕜 E G') :
‖f.prod g‖ = max ‖f‖ ‖g‖ :=
congr_arg NNReal.toReal (opNNNorm_prod f g)
theorem opNNNorm_pi
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) : ‖pi f‖₊ = ‖f‖₊ :=
eq_of_forall_ge_iff fun _ ↦ by simpa [opNNNorm_le_iff, pi_nnnorm_le_iff] using forall_swap
theorem opNorm_pi {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'}
[∀ i', SeminormedAddCommGroup (E' i')] [∀ i', NormedSpace 𝕜 (E' i')]
(f : ∀ i', ContinuousMultilinearMap 𝕜 E (E' i')) :
‖pi f‖ = ‖f‖ :=
congr_arg NNReal.toReal (opNNNorm_pi f)
section
@[simp]
theorem norm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') :
‖ofSubsingleton 𝕜 G G' i f‖ = ‖f‖ := by
letI : Unique ι := uniqueOfSubsingleton i
simp [norm_def, ContinuousLinearMap.norm_def, (Equiv.funUnique _ _).symm.surjective.forall]
@[simp]
theorem nnnorm_ofSubsingleton [Subsingleton ι] (i : ι) (f : G →L[𝕜] G') :
‖ofSubsingleton 𝕜 G G' i f‖₊ = ‖f‖₊ :=
NNReal.eq <| norm_ofSubsingleton i f
variable (𝕜 G)
/-- Linear isometry between continuous linear maps from `G` to `G'`
and continuous `1`-multilinear maps from `G` to `G'`. -/
@[simps apply symm_apply]
def ofSubsingletonₗᵢ [Subsingleton ι] (i : ι) :
(G →L[𝕜] G') ≃ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ G) G' :=
{ ofSubsingleton 𝕜 G G' i with
map_add' := fun _ _ ↦ rfl
map_smul' := fun _ _ ↦ rfl
norm_map' := norm_ofSubsingleton i }
theorem norm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖ ≤ 1 := by
rw [norm_ofSubsingleton]
apply ContinuousLinearMap.norm_id_le
theorem nnnorm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) :
‖ofSubsingleton 𝕜 G G i (.id _ _)‖₊ ≤ 1 :=
norm_ofSubsingleton_id_le _ _ _
variable {G} (E)
@[simp]
theorem norm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖ = ‖x‖ := by
apply le_antisymm
· refine opNorm_le_bound (norm_nonneg _) fun x => ?_
rw [Fintype.prod_empty, mul_one, constOfIsEmpty_apply]
· simpa using (constOfIsEmpty 𝕜 E x).le_opNorm 0
@[simp]
theorem nnnorm_constOfIsEmpty [IsEmpty ι] (x : G) : ‖constOfIsEmpty 𝕜 E x‖₊ = ‖x‖₊ :=
NNReal.eq <| norm_constOfIsEmpty _ _ _
end
section
variable (𝕜 E E' G G')
/-- `ContinuousMultilinearMap.prod` as a `LinearIsometryEquiv`. -/
@[simps]
def prodL :
ContinuousMultilinearMap 𝕜 E G × ContinuousMultilinearMap 𝕜 E G' ≃ₗᵢ[𝕜]
ContinuousMultilinearMap 𝕜 E (G × G') where
__ := prodEquiv
map_add' _ _ := rfl
map_smul' _ _ := rfl
norm_map' f := opNorm_prod f.1 f.2
/-- `ContinuousMultilinearMap.pi` as a `LinearIsometryEquiv`. -/
@[simps! apply symm_apply]
def piₗᵢ {ι' : Type v'} [Fintype ι'] {E' : ι' → Type wE'} [∀ i', NormedAddCommGroup (E' i')]
[∀ i', NormedSpace 𝕜 (E' i')] :
(Π i', ContinuousMultilinearMap 𝕜 E (E' i'))
≃ₗᵢ[𝕜] (ContinuousMultilinearMap 𝕜 E (Π i, E' i)) where
toLinearEquiv := piLinearEquiv
norm_map' := opNorm_pi
end
end
section RestrictScalars
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜]
variable [NormedSpace 𝕜' G] [IsScalarTower 𝕜' 𝕜 G]
variable [∀ i, NormedSpace 𝕜' (E i)] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)]
@[simp]
theorem norm_restrictScalars (f : ContinuousMultilinearMap 𝕜 E G) :
‖f.restrictScalars 𝕜'‖ = ‖f‖ :=
rfl
variable (𝕜')
/-- `ContinuousMultilinearMap.restrictScalars` as a `LinearIsometry`. -/
def restrictScalarsₗᵢ : ContinuousMultilinearMap 𝕜 E G →ₗᵢ[𝕜'] ContinuousMultilinearMap 𝕜' E G where
toFun := restrictScalars 𝕜'
map_add' _ _ := rfl
map_smul' _ _ := rfl
norm_map' _ := rfl
end RestrictScalars
/-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, precise version.
For a less precise but more usable version, see `norm_image_sub_le`. The bound reads
`‖f m - f m'‖ ≤
‖f‖ * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`,
where the other terms in the sum are the same products where `1` is replaced by any `i`. -/
theorem norm_image_sub_le' [DecidableEq ι] (f : ContinuousMultilinearMap 𝕜 E G) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ ‖f‖ * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ :=
f.toMultilinearMap.norm_image_sub_le_of_bound' (norm_nonneg _) f.le_opNorm _ _
/-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, less precise
version. For a more precise but less usable version, see `norm_image_sub_le'`.
The bound is `‖f m - f m'‖ ≤ ‖f‖ * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/
theorem norm_image_sub_le (f : ContinuousMultilinearMap 𝕜 E G) (m₁ m₂ : ∀ i, E i) :
‖f m₁ - f m₂‖ ≤ ‖f‖ * Fintype.card ι * max ‖m₁‖ ‖m₂‖ ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ :=
f.toMultilinearMap.norm_image_sub_le_of_bound (norm_nonneg _) f.le_opNorm _ _
end ContinuousMultilinearMap
variable [Fintype ι]
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mkContinuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
theorem MultilinearMap.mkContinuous_norm_le (f : MultilinearMap 𝕜 E G) {C : ℝ} (hC : 0 ≤ C)
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ C :=
ContinuousMultilinearMap.opNorm_le_bound hC fun m => H m
/-- If a continuous multilinear map is constructed from a multilinear map via the constructor
`mkContinuous`, then its norm is bounded by the bound given to the constructor if it is
nonnegative. -/
theorem MultilinearMap.mkContinuous_norm_le' (f : MultilinearMap 𝕜 E G) {C : ℝ}
(H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ max C 0 :=
ContinuousMultilinearMap.opNorm_le_bound (le_max_right _ _) fun m ↦ (H m).trans <|
mul_le_mul_of_nonneg_right (le_max_left _ _) <| by positivity
namespace ContinuousMultilinearMap
/-- Given a continuous multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset
`s` of `k` of these variables, one gets a new continuous multilinear map on `Fin k` by varying
these variables, and fixing the other ones equal to a given value `z`. It is denoted by
`f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit
identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/
def restr {k n : ℕ} (f : (G [×n]→L[𝕜] G' :)) (s : Finset (Fin n)) (hk : #s = k) (z : G) :
G [×k]→L[𝕜] G' :=
(f.toMultilinearMap.restr s hk z).mkContinuous (‖f‖ * ‖z‖ ^ (n - k)) fun _ =>
MultilinearMap.restr_norm_le _ _ _ _ f.le_opNorm _
theorem norm_restr {k n : ℕ} (f : G [×n]→L[𝕜] G') (s : Finset (Fin n)) (hk : #s = k) (z : G) :
‖f.restr s hk z‖ ≤ ‖f‖ * ‖z‖ ^ (n - k) := by
apply MultilinearMap.mkContinuous_norm_le
exact mul_nonneg (norm_nonneg _) (pow_nonneg (norm_nonneg _) _)
section
variable {A : Type*} [NormedCommRing A] [NormedAlgebra 𝕜 A]
@[simp]
theorem norm_mkPiAlgebra_le [Nonempty ι] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ ≤ 1 := by
refine opNorm_le_bound zero_le_one fun m => ?_
simp only [ContinuousMultilinearMap.mkPiAlgebra_apply, one_mul]
exact norm_prod_le' _ univ_nonempty _
theorem norm_mkPiAlgebra_of_empty [IsEmpty ι] :
‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = ‖(1 : A)‖ := by
apply le_antisymm
· apply opNorm_le_bound <;> simp
· convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => 1
simp [eq_empty_of_isEmpty univ]
@[simp]
theorem norm_mkPiAlgebra [NormOneClass A] : ‖ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A‖ = 1 := by
cases isEmpty_or_nonempty ι
· simp [norm_mkPiAlgebra_of_empty]
· refine le_antisymm norm_mkPiAlgebra_le ?_
| convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebra 𝕜 ι A) fun _ => 1
simp
end
section
variable {n : ℕ} {A : Type*} [SeminormedRing A] [NormedAlgebra 𝕜 A]
theorem norm_mkPiAlgebraFin_succ_le : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n.succ A‖ ≤ 1 := by
refine opNorm_le_bound zero_le_one fun m => ?_
simp only [ContinuousMultilinearMap.mkPiAlgebraFin_apply, one_mul, List.ofFn_eq_map,
Fin.prod_univ_def, Multiset.map_coe, Multiset.prod_coe]
refine (List.norm_prod_le' ?_).trans_eq ?_
· rw [Ne, List.map_eq_nil_iff, List.finRange_eq_nil]
exact Nat.succ_ne_zero _
rw [List.map_map, Function.comp_def]
theorem norm_mkPiAlgebraFin_le_of_pos (hn : 0 < n) :
‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 n A‖ ≤ 1 := by
obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn.ne'
exact norm_mkPiAlgebraFin_succ_le
theorem norm_mkPiAlgebraFin_zero : ‖ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 0 A‖ = ‖(1 : A)‖ := by
refine le_antisymm ?_ ?_
· refine opNorm_le_bound (norm_nonneg (1 : A)) ?_
simp
· convert ratio_le_opNorm (ContinuousMultilinearMap.mkPiAlgebraFin 𝕜 0 A) fun _ => (1 : A)
| Mathlib/Analysis/NormedSpace/Multilinear/Basic.lean | 724 | 751 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Data.Set.BooleanAlgebra
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.Interval.Set.UnorderedInterval
/-!
# Intervals in `pi`-space
In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`,
`Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals
usually include the corresponding products as proper subsets.
-/
-- Porting note: Added, since dot notation no longer works on `Function.update`
open Function
variable {ι : Type*} {α : ι → Type*}
namespace Set
section PiPreorder
variable [∀ i, Preorder (α i)] (x y : ∀ i, α i)
@[simp]
theorem pi_univ_Ici : (pi univ fun i ↦ Ici (x i)) = Ici x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Iic : (pi univ fun i ↦ Iic (x i)) = Iic x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Icc : (pi univ fun i ↦ Icc (x i) (y i)) = Icc x y :=
ext fun y ↦ by simp [Pi.le_def, forall_and]
theorem piecewise_mem_Icc {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : ∀ i ∈ s, f₁ i ∈ Icc (g₁ i) (g₂ i)) (h₂ : ∀ i ∉ s, f₂ i ∈ Icc (g₁ i) (g₂ i)) :
s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
⟨le_piecewise (fun i hi ↦ (h₁ i hi).1) fun i hi ↦ (h₂ i hi).1,
piecewise_le (fun i hi ↦ (h₁ i hi).2) fun i hi ↦ (h₂ i hi).2⟩
theorem piecewise_mem_Icc' {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : f₁ ∈ Icc g₁ g₂) (h₂ : f₂ ∈ Icc g₁ g₂) : s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
piecewise_mem_Icc (fun _ _ ↦ ⟨h₁.1 _, h₁.2 _⟩) fun _ _ ↦ ⟨h₂.1 _, h₂.2 _⟩
section Nonempty
theorem pi_univ_Ioi_subset [Nonempty ι]: (pi univ fun i ↦ Ioi (x i)) ⊆ Ioi x := fun _ hz ↦
⟨fun i ↦ le_of_lt <| hz i trivial, fun h ↦
(‹Nonempty ι›.elim) fun i ↦ not_lt_of_le (h i) (hz i trivial)⟩
theorem pi_univ_Iio_subset [Nonempty ι]: (pi univ fun i ↦ Iio (x i)) ⊆ Iio x :=
pi_univ_Ioi_subset (α := fun i ↦ (α i)ᵒᵈ) x
theorem pi_univ_Ioo_subset [Nonempty ι]: (pi univ fun i ↦ Ioo (x i) (y i)) ⊆ Ioo x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
theorem pi_univ_Ioc_subset [Nonempty ι]: (pi univ fun i ↦ Ioc (x i) (y i)) ⊆ Ioc x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, fun i ↦ (hx i trivial).2⟩
theorem pi_univ_Ico_subset [Nonempty ι]: (pi univ fun i ↦ Ico (x i) (y i)) ⊆ Ico x y := fun _ hx ↦
⟨fun i ↦ (hx i trivial).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
end Nonempty
variable [DecidableEq ι]
open Function (update)
theorem pi_univ_Ioc_update_left {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) :
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) =
{ z | m < z i₀ } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc m (y i₀) = Ioi m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, ← inter_assoc,
inter_eq_self_of_subset_left (Ioi_subset_Ioi hm)]
simp_rw [univ_pi_update i₀ _ _ fun i z ↦ Ioc z (y i), ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem pi_univ_Ioc_update_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) :
(pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) =
{ z | z i₀ ≤ m } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc (x i₀) m = Iic m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_left_comm,
inter_eq_self_of_subset_left (Iic_subset_Iic.2 hm)]
simp_rw [univ_pi_update i₀ y m fun i z ↦ Ioc (x i) z, ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem disjoint_pi_univ_Ioc_update_left_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} :
Disjoint (pi univ fun i ↦ Ioc (x i) (update y i₀ m i))
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) := by
rw [disjoint_left]
rintro z h₁ h₂
refine (h₁ i₀ (mem_univ _)).2.not_lt ?_
simpa only [Function.update_self] using (h₂ i₀ (mem_univ _)).1
end PiPreorder
section PiPartialOrder
variable [DecidableEq ι] [∀ i, PartialOrder (α i)]
-- Porting note: Dot notation on `Function.update` broke
theorem image_update_Icc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Icc a b = Icc (update f i a) (update f i b) := by
ext x
rw [← Set.pi_univ_Icc]
refine ⟨?_, fun h => ⟨x i, ?_, ?_⟩⟩
· rintro ⟨c, hc, rfl⟩
simpa [update_le_update_iff]
· simpa only [Function.update_self] using h i (mem_univ i)
· ext j
obtain rfl | hij := eq_or_ne i j
· exact Function.update_self ..
· simpa only [Function.update_of_ne hij.symm, le_antisymm_iff] using h j (mem_univ j)
theorem image_update_Ico (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ico a b = Ico (update f i a) (update f i b) := by
rw [← Icc_diff_right, ← Icc_diff_right, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioc a b = Ioc (update f i a) (update f i b) := by
rw [← Icc_diff_left, ← Icc_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioo (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioo a b = Ioo (update f i a) (update f i b) := by
rw [← Ico_diff_left, ← Ico_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Ico]
theorem image_update_Icc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Icc a (f i) = Icc (update f i a) f := by simpa using image_update_Icc f i a (f i)
theorem image_update_Ico_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ico a (f i) = Ico (update f i a) f := by simpa using image_update_Ico f i a (f i)
theorem image_update_Ioc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioc a (f i) = Ioc (update f i a) f := by simpa using image_update_Ioc f i a (f i)
theorem image_update_Ioo_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioo a (f i) = Ioo (update f i a) f := by simpa using image_update_Ioo f i a (f i)
theorem image_update_Icc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Icc (f i) b = Icc f (update f i b) := by simpa using image_update_Icc f i (f i) b
theorem image_update_Ico_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ico (f i) b = Ico f (update f i b) := by simpa using image_update_Ico f i (f i) b
theorem image_update_Ioc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioc (f i) b = Ioc f (update f i b) := by simpa using image_update_Ioc f i (f i) b
|
theorem image_update_Ioo_right (f : ∀ i, α i) (i : ι) (b : α i) :
| Mathlib/Order/Interval/Set/Pi.lean | 160 | 161 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) :
Real.exp x < 1 / (1 - x) := by
have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc
0 < x ^ 3 := by positivity
_ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring
calc
exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three
_ ≤ 1 + x + x ^ 2 := by
-- Porting note: was `norm_num [Finset.sum] <;> nlinarith`
-- This proof should be restored after the norm_num plugin for big operators is ported.
-- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.)
rw [show 3 = 1 + 1 + 1 from rfl]
repeat rw [Finset.sum_range_succ]
norm_num [Nat.factorial]
nlinarith
_ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith
theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) :
Real.exp x ≤ 1 / (1 - x) := by
rcases eq_or_lt_of_le h1 with (rfl | h1)
· simp
· exact (exp_bound_div_one_sub_of_interval' h1 h2).le
theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by
obtain hx | hx := hx.symm.lt_or_lt
· exact add_one_lt_exp_of_pos hx
obtain h' | h' := le_or_lt 1 (-x)
· linarith [x.exp_pos]
have hx' : 0 < x + 1 := by linarith
simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx']
using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h'
theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by
obtain rfl | hx := eq_or_ne x 0
· simp
· exact (add_one_lt_exp hx).le
lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) :=
(sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx
lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) :=
(sub_eq_neg_add _ _).trans_le <| add_one_le_exp _
theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rwa [Nat.cast_zero] at ht'
calc
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
gcongr
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
· exact one_sub_le_exp_neg _
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by
rw [le_inv_mul_iff₀ hc]
calc c * x
_ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one
_ ≤ _ := Real.add_one_le_exp (c * x)
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.exp $a) =>
assertInstancesCommute
pure (.positive q(Real.exp_pos $a))
| _, _, _ => throwError "not Real.exp"
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by
rw [← ofReal_exp]
exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _))
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal
end Complex
| Mathlib/Data/Complex/Exponential.lean | 701 | 702 | |
/-
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.Group.Action.Pi
import Mathlib.Data.Finset.Prod
import Mathlib.Data.SetLike.Basic
import Mathlib.Data.Sym.Basic
import Mathlib.Data.Sym.Sym2.Init
/-!
# The symmetric square
This file defines the symmetric square, which is `α × α` modulo
swapping. This is also known as the type of unordered pairs.
More generally, the symmetric square is the second symmetric power
(see `Data.Sym.Basic`). The equivalence is `Sym2.equivSym`.
From the point of view that an unordered pair is equivalent to a
multiset of cardinality two (see `Sym2.equivMultiset`), there is a
`Mem` instance `Sym2.Mem`, which is a `Prop`-valued membership
test. Given `h : a ∈ z` for `z : Sym2 α`, then `Mem.other h` is the other
element of the pair, defined using `Classical.choice`. If `α` has
decidable equality, then `h.other'` computably gives the other element.
The universal property of `Sym2` is provided as `Sym2.lift`, which
states that functions from `Sym2 α` are equivalent to symmetric
two-argument functions from `α`.
Recall that an undirected graph (allowing self loops, but no multiple
edges) is equivalent to a symmetric relation on the vertex type `α`.
Given a symmetric relation on `α`, the corresponding edge set is
constructed by `Sym2.fromRel` which is a special case of `Sym2.lift`.
## Notation
The element `Sym2.mk (a, b)` can be written as `s(a, b)` for short.
## Tags
symmetric square, unordered pairs, symmetric powers
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Finset Function Sym
universe u
variable {α β γ : Type*}
namespace Sym2
/-- This is the relation capturing the notion of pairs equivalent up to permutations. -/
@[aesop (rule_sets := [Sym2]) [safe [constructors, cases], norm]]
inductive Rel (α : Type u) : α × α → α × α → Prop
| refl (x y : α) : Rel _ (x, y) (x, y)
| swap (x y : α) : Rel _ (x, y) (y, x)
attribute [refl] Rel.refl
@[symm]
theorem Rel.symm {x y : α × α} : Rel α x y → Rel α y x := by aesop (rule_sets := [Sym2])
@[trans]
theorem Rel.trans {x y z : α × α} (a : Rel α x y) (b : Rel α y z) : Rel α x z := by
aesop (rule_sets := [Sym2])
theorem Rel.is_equivalence : Equivalence (Rel α) :=
{ refl := fun (x, y) ↦ Rel.refl x y, symm := Rel.symm, trans := Rel.trans }
/-- One can use `attribute [local instance] Sym2.Rel.setoid` to temporarily
make `Quotient` functionality work for `α × α`. -/
def Rel.setoid (α : Type u) : Setoid (α × α) :=
⟨Rel α, Rel.is_equivalence⟩
@[simp]
theorem rel_iff' {p q : α × α} : Rel α p q ↔ p = q ∨ p = q.swap := by
aesop (rule_sets := [Sym2])
theorem rel_iff {x y z w : α} : Rel α (x, y) (z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by
simp
end Sym2
/-- `Sym2 α` is the symmetric square of `α`, which, in other words, is the
type of unordered pairs.
It is equivalent in a natural way to multisets of cardinality 2 (see
`Sym2.equivMultiset`).
-/
abbrev Sym2 (α : Type u) := Quot (Sym2.Rel α)
/-- Constructor for `Sym2`. This is the quotient map `α × α → Sym2 α`. -/
protected abbrev Sym2.mk {α : Type*} (p : α × α) : Sym2 α := Quot.mk (Sym2.Rel α) p
/-- `s(x, y)` is an unordered pair,
which is to say a pair modulo the action of the symmetric group.
It is equal to `Sym2.mk (x, y)`. -/
notation3 "s(" x ", " y ")" => Sym2.mk (x, y)
namespace Sym2
protected theorem sound {p p' : α × α} (h : Sym2.Rel α p p') : Sym2.mk p = Sym2.mk p' :=
Quot.sound h
protected theorem exact {p p' : α × α} (h : Sym2.mk p = Sym2.mk p') : Sym2.Rel α p p' :=
Quotient.exact (s := Sym2.Rel.setoid α) h
@[simp]
protected theorem eq {p p' : α × α} : Sym2.mk p = Sym2.mk p' ↔ Sym2.Rel α p p' :=
Quotient.eq' (s₁ := Sym2.Rel.setoid α)
@[elab_as_elim, cases_eliminator, induction_eliminator]
protected theorem ind {f : Sym2 α → Prop} (h : ∀ x y, f s(x, y)) : ∀ i, f i :=
Quot.ind <| Prod.rec <| h
@[elab_as_elim]
protected theorem inductionOn {f : Sym2 α → Prop} (i : Sym2 α) (hf : ∀ x y, f s(x, y)) : f i :=
i.ind hf
@[elab_as_elim]
protected theorem inductionOn₂ {f : Sym2 α → Sym2 β → Prop} (i : Sym2 α) (j : Sym2 β)
(hf : ∀ a₁ a₂ b₁ b₂, f s(a₁, a₂) s(b₁, b₂)) : f i j :=
Quot.induction_on₂ i j <| by
intro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩
exact hf _ _ _ _
/-- Dependent recursion principal for `Sym2`. See `Quot.rec`. -/
@[elab_as_elim]
protected def rec {motive : Sym2 α → Sort*}
(f : (p : α × α) → motive (Sym2.mk p))
(h : (p q : α × α) → (h : Sym2.Rel α p q) → Eq.ndrec (f p) (Sym2.sound h) = f q)
| (z : Sym2 α) : motive z :=
Quot.rec f h z
/-- Dependent recursion principal for `Sym2` when the target is a `Subsingleton` type.
See `Quot.recOnSubsingleton`. -/
| Mathlib/Data/Sym/Sym2.lean | 138 | 142 |
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Group.Action.Pointwise.Finset
import Mathlib.GroupTheory.QuotientGroup.Defs
import Mathlib.Order.ConditionallyCompleteLattice.Basic
/-!
# Stabilizer of a set under a pointwise action
This file characterises the stabilizer of a set/finset under the pointwise action of a group.
-/
open Function MulOpposite Set
open scoped Pointwise
namespace MulAction
variable {G H α : Type*}
/-! ### Stabilizer of a set -/
section Set
section Group
variable [Group G] [Group H] [MulAction G α] {a : G} {s t : Set α}
@[to_additive (attr := simp)]
| lemma stabilizer_empty : stabilizer G (∅ : Set α) = ⊤ :=
Subgroup.coe_eq_univ.1 <| eq_univ_of_forall fun _a ↦ smul_set_empty
@[to_additive (attr := simp)]
| Mathlib/Algebra/Pointwise/Stabilizer.lean | 29 | 32 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Set.Lattice.Image
import Mathlib.Order.Hom.BoundedLattice
/-!
# Complete lattice homomorphisms
This file defines frame homomorphisms and complete lattice homomorphisms.
We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to
be satisfied by itself and all stricter types.
## Types of morphisms
* `sSupHom`: Maps which preserve `⨆`.
* `sInfHom`: Maps which preserve `⨅`.
* `FrameHom`: Frame homomorphisms. Maps which preserve `⨆`, `⊓` and `⊤`.
* `CompleteLatticeHom`: Complete lattice homomorphisms. Maps which preserve `⨆` and `⨅`.
## Typeclasses
* `sSupHomClass`
* `sInfHomClass`
* `FrameHomClass`
* `CompleteLatticeHomClass`
## Concrete homs
* `CompleteLatticeHom.setPreimage`: `Set.preimage` as a complete lattice homomorphism.
## TODO
Frame homs are Heyting homs.
-/
assert_not_exists Monoid
open Function OrderDual Set
variable {F α β γ δ : Type*} {ι : Sort*} {κ : ι → Sort*}
/-- The type of `⨆`-preserving functions from `α` to `β`. -/
structure sSupHom (α β : Type*) [SupSet α] [SupSet β] where
/-- The underlying function of a sSupHom. -/
toFun : α → β
/-- The proposition that a `sSupHom` commutes with arbitrary suprema/joins. -/
map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s)
/-- The type of `⨅`-preserving functions from `α` to `β`. -/
structure sInfHom (α β : Type*) [InfSet α] [InfSet β] where
/-- The underlying function of an `sInfHom`. -/
toFun : α → β
/-- The proposition that a `sInfHom` commutes with arbitrary infima/meets -/
map_sInf' (s : Set α) : toFun (sInf s) = sInf (toFun '' s)
/-- The type of frame homomorphisms from `α` to `β`. They preserve finite meets and arbitrary joins.
-/
structure FrameHom (α β : Type*) [CompleteLattice α] [CompleteLattice β] extends
InfTopHom α β where
/-- The proposition that frame homomorphisms commute with arbitrary suprema/joins. -/
map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s)
/-- The type of complete lattice homomorphisms from `α` to `β`. -/
structure CompleteLatticeHom (α β : Type*) [CompleteLattice α] [CompleteLattice β] extends
sInfHom α β where
/-- The proposition that complete lattice homomorphism commutes with arbitrary suprema/joins. -/
map_sSup' (s : Set α) : toFun (sSup s) = sSup (toFun '' s)
section
/-- `sSupHomClass F α β` states that `F` is a type of `⨆`-preserving morphisms.
You should extend this class when you extend `sSupHom`. -/
class sSupHomClass (F α β : Type*) [SupSet α] [SupSet β] [FunLike F α β] : Prop where
/-- The proposition that members of `sSupHomClass`s commute with arbitrary suprema/joins. -/
map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s)
/-- `sInfHomClass F α β` states that `F` is a type of `⨅`-preserving morphisms.
You should extend this class when you extend `sInfHom`. -/
class sInfHomClass (F α β : Type*) [InfSet α] [InfSet β] [FunLike F α β] : Prop where
/-- The proposition that members of `sInfHomClass`s commute with arbitrary infima/meets. -/
map_sInf (f : F) (s : Set α) : f (sInf s) = sInf (f '' s)
/-- `FrameHomClass F α β` states that `F` is a type of frame morphisms. They preserve `⊓` and `⨆`.
You should extend this class when you extend `FrameHom`. -/
class FrameHomClass (F α β : Type*) [CompleteLattice α] [CompleteLattice β] [FunLike F α β] : Prop
extends InfTopHomClass F α β where
/-- The proposition that members of `FrameHomClass` commute with arbitrary suprema/joins. -/
map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s)
/-- `CompleteLatticeHomClass F α β` states that `F` is a type of complete lattice morphisms.
You should extend this class when you extend `CompleteLatticeHom`. -/
class CompleteLatticeHomClass (F α β : Type*) [CompleteLattice α] [CompleteLattice β]
[FunLike F α β] : Prop
extends sInfHomClass F α β where
/-- The proposition that members of `CompleteLatticeHomClass` commute with arbitrary
suprema/joins. -/
map_sSup (f : F) (s : Set α) : f (sSup s) = sSup (f '' s)
end
export sSupHomClass (map_sSup)
export sInfHomClass (map_sInf)
attribute [simp] map_sSup map_sInf
section Hom
variable [FunLike F α β]
@[simp] theorem map_iSup [SupSet α] [SupSet β] [sSupHomClass F α β] (f : F) (g : ι → α) :
f (⨆ i, g i) = ⨆ i, f (g i) := by simp [iSup, ← Set.range_comp, Function.comp_def]
theorem map_iSup₂ [SupSet α] [SupSet β] [sSupHomClass F α β] (f : F) (g : ∀ i, κ i → α) :
f (⨆ (i) (j), g i j) = ⨆ (i) (j), f (g i j) := by simp_rw [map_iSup]
@[simp] theorem map_iInf [InfSet α] [InfSet β] [sInfHomClass F α β] (f : F) (g : ι → α) :
f (⨅ i, g i) = ⨅ i, f (g i) := by simp [iInf, ← Set.range_comp, Function.comp_def]
theorem map_iInf₂ [InfSet α] [InfSet β] [sInfHomClass F α β] (f : F) (g : ∀ i, κ i → α) :
f (⨅ (i) (j), g i j) = ⨅ (i) (j), f (g i j) := by simp_rw [map_iInf]
-- See note [lower instance priority]
instance (priority := 100) sSupHomClass.toSupBotHomClass [CompleteLattice α]
[CompleteLattice β] [sSupHomClass F α β] : SupBotHomClass F α β :=
{ ‹sSupHomClass F α β› with
map_sup := fun f a b => by
rw [← sSup_pair, map_sSup]
simp only [Set.image_pair, sSup_insert, sSup_singleton]
| map_bot := fun f => by
rw [← sSup_empty, map_sSup, Set.image_empty, sSup_empty] }
| Mathlib/Order/Hom/CompleteLattice.lean | 138 | 139 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau, Kim Morrison
-/
import Mathlib.Data.List.Chain
/-!
# Ranges of naturals as lists
This file shows basic results about `List.iota`, `List.range`, `List.range'`
and defines `List.finRange`.
`finRange n` is the list of elements of `Fin n`.
`iota n = [n, n - 1, ..., 1]` and `range n = [0, ..., n - 1]` are basic list constructions used for
tactics. `range' a b = [a, ..., a + b - 1]` is there to help prove properties about them.
Actual maths should use `List.Ico` instead.
-/
universe u
open Nat
namespace List
variable {α : Type u}
theorem getElem_range'_1 {n m} (i) (H : i < (range' n m).length) :
(range' n m)[i] = n + i := by simp
theorem chain'_range_succ (r : ℕ → ℕ → Prop) (n : ℕ) :
Chain' r (range n.succ) ↔ ∀ m < n, r m m.succ := by
rw [range_succ]
induction' n with n hn
· simp
· rw [range_succ]
simp only [append_assoc, singleton_append, chain'_append_cons_cons, chain'_singleton, and_true]
rw [hn, forall_lt_succ]
theorem chain_range_succ (r : ℕ → ℕ → Prop) (n a : ℕ) :
Chain r a (range n.succ) ↔ r a 0 ∧ ∀ m < n, r m m.succ := by
rw [range_succ_eq_map, chain_cons, and_congr_right_iff, ← chain'_range_succ, range_succ_eq_map]
exact fun _ => Iff.rfl
section Ranges
/-- From `l : List ℕ`, construct `l.ranges : List (List ℕ)` such that
`l.ranges.map List.length = l` and `l.ranges.join = range l.sum`
* Example: `[1,2,3].ranges = [[0],[1,2],[3,4,5]]` -/
def ranges : List ℕ → List (List ℕ)
| [] => nil
| a::l => range a::(ranges l).map (map (a + ·))
/-- The members of `l.ranges` are pairwise disjoint -/
theorem ranges_disjoint (l : List ℕ) :
Pairwise Disjoint (ranges l) := by
induction l with
| nil => exact Pairwise.nil
| cons a l hl =>
simp only [ranges, pairwise_cons]
constructor
· intro s hs
obtain ⟨s', _, rfl⟩ := mem_map.mp hs
intro u hu
rw [mem_map]
rintro ⟨v, _, rfl⟩
| rw [mem_range] at hu
omega
| Mathlib/Data/List/Range.lean | 66 | 67 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Order.Monotone.Odd
import Mathlib.Analysis.Calculus.LogDeriv
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Calculus.Deriv.MeanValue
/-!
# Differentiability of trigonometric functions
## Main statements
The differentiability of the usual trigonometric functions is proved, and their derivatives are
computed.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open scoped Topology Filter
open Set
namespace Complex
/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/
theorem hasStrictDerivAt_sin (x : ℂ) : HasStrictDerivAt sin (cos x) x := by
simp only [cos, div_eq_mul_inv]
convert ((((hasStrictDerivAt_id x).neg.mul_const I).cexp.sub
((hasStrictDerivAt_id x).mul_const I).cexp).mul_const I).mul_const (2 : ℂ)⁻¹ using 1
simp only [Function.comp, id]
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
theorem hasDerivAt_sin (x : ℂ) : HasDerivAt sin (cos x) x :=
(hasStrictDerivAt_sin x).hasDerivAt
theorem contDiff_sin {n} : ContDiff ℂ n sin :=
(((contDiff_neg.mul contDiff_const).cexp.sub (contDiff_id.mul contDiff_const).cexp).mul
contDiff_const).div_const _
@[simp]
theorem differentiable_sin : Differentiable ℂ sin := fun x => (hasDerivAt_sin x).differentiableAt
@[simp]
theorem differentiableAt_sin {x : ℂ} : DifferentiableAt ℂ sin x :=
differentiable_sin x
@[simp]
theorem deriv_sin : deriv sin = cos :=
funext fun x => (hasDerivAt_sin x).deriv
/-- The complex cosine function is everywhere strictly differentiable, with the derivative
`-sin x`. -/
theorem hasStrictDerivAt_cos (x : ℂ) : HasStrictDerivAt cos (-sin x) x := by
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul]
convert (((hasStrictDerivAt_id x).mul_const I).cexp.add
((hasStrictDerivAt_id x).neg.mul_const I).cexp).mul_const (2 : ℂ)⁻¹ using 1
simp only [Function.comp, id]
ring
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
theorem hasDerivAt_cos (x : ℂ) : HasDerivAt cos (-sin x) x :=
(hasStrictDerivAt_cos x).hasDerivAt
theorem contDiff_cos {n} : ContDiff ℂ n cos :=
((contDiff_id.mul contDiff_const).cexp.add (contDiff_neg.mul contDiff_const).cexp).div_const _
@[simp]
theorem differentiable_cos : Differentiable ℂ cos := fun x => (hasDerivAt_cos x).differentiableAt
@[simp]
theorem differentiableAt_cos {x : ℂ} : DifferentiableAt ℂ cos x :=
differentiable_cos x
theorem deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(hasDerivAt_cos x).deriv
@[simp]
theorem deriv_cos' : deriv cos = fun x => -sin x :=
funext fun _ => deriv_cos
/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative
`cosh x`. -/
theorem hasStrictDerivAt_sinh (x : ℂ) : HasStrictDerivAt sinh (cosh x) x := by
simp only [cosh, div_eq_mul_inv]
convert ((hasStrictDerivAt_exp x).sub (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹
using 1
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
theorem hasDerivAt_sinh (x : ℂ) : HasDerivAt sinh (cosh x) x :=
(hasStrictDerivAt_sinh x).hasDerivAt
theorem contDiff_sinh {n} : ContDiff ℂ n sinh :=
(contDiff_exp.sub contDiff_neg.cexp).div_const _
@[simp]
theorem differentiable_sinh : Differentiable ℂ sinh := fun x => (hasDerivAt_sinh x).differentiableAt
@[simp]
theorem differentiableAt_sinh {x : ℂ} : DifferentiableAt ℂ sinh x :=
differentiable_sinh x
@[simp]
theorem deriv_sinh : deriv sinh = cosh :=
funext fun x => (hasDerivAt_sinh x).deriv
/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the
derivative `sinh x`. -/
theorem hasStrictDerivAt_cosh (x : ℂ) : HasStrictDerivAt cosh (sinh x) x := by
simp only [sinh, div_eq_mul_inv]
convert ((hasStrictDerivAt_exp x).add (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹
using 1
rw [id, mul_neg_one, sub_eq_add_neg]
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative
`sinh x`. -/
theorem hasDerivAt_cosh (x : ℂ) : HasDerivAt cosh (sinh x) x :=
(hasStrictDerivAt_cosh x).hasDerivAt
theorem contDiff_cosh {n} : ContDiff ℂ n cosh :=
(contDiff_exp.add contDiff_neg.cexp).div_const _
@[simp]
theorem differentiable_cosh : Differentiable ℂ cosh := fun x => (hasDerivAt_cosh x).differentiableAt
@[simp]
theorem differentiableAt_cosh {x : ℂ} : DifferentiableAt ℂ cosh x :=
differentiable_cosh x
@[simp]
theorem deriv_cosh : deriv cosh = sinh :=
funext fun x => (hasDerivAt_cosh x).deriv
end Complex
section
/-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : ℂ → ℂ` -/
variable {f : ℂ → ℂ} {f' x : ℂ} {s : Set ℂ}
/-! #### `Complex.cos` -/
theorem HasStrictDerivAt.ccos (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x :=
(Complex.hasStrictDerivAt_cos (f x)).comp x hf
theorem HasDerivAt.ccos (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x :=
(Complex.hasDerivAt_cos (f x)).comp x hf
theorem HasDerivWithinAt.ccos (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') s x :=
(Complex.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.ccos.derivWithin hxs
@[simp]
theorem deriv_ccos (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.cos (f x)) x = -Complex.sin (f x) * deriv f x :=
hc.hasDerivAt.ccos.deriv
/-! #### `Complex.sin` -/
theorem HasStrictDerivAt.csin (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x :=
(Complex.hasStrictDerivAt_sin (f x)).comp x hf
theorem HasDerivAt.csin (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x :=
(Complex.hasDerivAt_sin (f x)).comp x hf
theorem HasDerivWithinAt.csin (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') s x :=
(Complex.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.sin (f x)) s x = Complex.cos (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.csin.derivWithin hxs
@[simp]
theorem deriv_csin (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.sin (f x)) x = Complex.cos (f x) * deriv f x :=
hc.hasDerivAt.csin.deriv
/-! #### `Complex.cosh` -/
theorem HasStrictDerivAt.ccosh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x :=
(Complex.hasStrictDerivAt_cosh (f x)).comp x hf
theorem HasDerivAt.ccosh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x :=
(Complex.hasDerivAt_cosh (f x)).comp x hf
theorem HasDerivWithinAt.ccosh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') s x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.ccosh.derivWithin hxs
@[simp]
theorem deriv_ccosh (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) * deriv f x :=
hc.hasDerivAt.ccosh.deriv
/-! #### `Complex.sinh` -/
theorem HasStrictDerivAt.csinh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x :=
(Complex.hasStrictDerivAt_sinh (f x)).comp x hf
theorem HasDerivAt.csinh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x :=
(Complex.hasDerivAt_sinh (f x)).comp x hf
theorem HasDerivWithinAt.csinh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') s x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.csinh.derivWithin hxs
@[simp]
theorem deriv_csinh (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) * deriv f x :=
hc.hasDerivAt.csinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : E → ℂ` -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
{s : Set E}
/-! #### `Complex.cos` -/
theorem HasStrictFDerivAt.ccos (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x :=
(Complex.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.ccos (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x :=
(Complex.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.ccos (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') s x :=
(Complex.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.ccos (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.cos (f x)) s x :=
hf.hasFDerivWithinAt.ccos.differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.ccos (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.cos (f x)) x :=
hc.hasFDerivAt.ccos.differentiableAt
theorem DifferentiableOn.ccos (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.cos (f x)) s := fun x h => (hc x h).ccos
@[simp, fun_prop]
theorem Differentiable.ccos (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.cos (f x) := fun x => (hc x).ccos
theorem fderivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.ccos.fderivWithin hxs
@[simp]
theorem fderiv_ccos (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.cos (f x)) x = -Complex.sin (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.ccos.fderiv
theorem ContDiff.ccos {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cos (f x) :=
Complex.contDiff_cos.comp h
theorem ContDiffAt.ccos {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.cos (f x)) x :=
Complex.contDiff_cos.contDiffAt.comp x hf
theorem ContDiffOn.ccos {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.cos (f x)) s :=
Complex.contDiff_cos.comp_contDiffOn hf
theorem ContDiffWithinAt.ccos {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.cos (f x)) s x :=
Complex.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Complex.sin` -/
theorem HasStrictFDerivAt.csin (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x :=
(Complex.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.csin (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x :=
(Complex.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.csin (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') s x :=
(Complex.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.csin (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.sin (f x)) s x :=
hf.hasFDerivWithinAt.csin.differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.csin (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.sin (f x)) x :=
hc.hasFDerivAt.csin.differentiableAt
theorem DifferentiableOn.csin (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.sin (f x)) s := fun x h => (hc x h).csin
@[simp, fun_prop]
theorem Differentiable.csin (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.sin (f x) := fun x => (hc x).csin
theorem fderivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.sin (f x)) s x = Complex.cos (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.csin.fderivWithin hxs
@[simp]
theorem fderiv_csin (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.sin (f x)) x = Complex.cos (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.csin.fderiv
theorem ContDiff.csin {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sin (f x) :=
Complex.contDiff_sin.comp h
theorem ContDiffAt.csin {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.sin (f x)) x :=
Complex.contDiff_sin.contDiffAt.comp x hf
theorem ContDiffOn.csin {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.sin (f x)) s :=
Complex.contDiff_sin.comp_contDiffOn hf
theorem ContDiffWithinAt.csin {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.sin (f x)) s x :=
Complex.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Complex.cosh` -/
theorem HasStrictFDerivAt.ccosh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x :=
(Complex.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.ccosh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.ccosh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') s x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.ccosh (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.cosh (f x)) s x :=
hf.hasFDerivWithinAt.ccosh.differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.ccosh (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.cosh (f x)) x :=
hc.hasFDerivAt.ccosh.differentiableAt
theorem DifferentiableOn.ccosh (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.cosh (f x)) s := fun x h => (hc x h).ccosh
@[simp, fun_prop]
theorem Differentiable.ccosh (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.cosh (f x) := fun x => (hc x).ccosh
theorem fderivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.ccosh.fderivWithin hxs
@[simp]
theorem fderiv_ccosh (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.ccosh.fderiv
theorem ContDiff.ccosh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cosh (f x) :=
Complex.contDiff_cosh.comp h
theorem ContDiffAt.ccosh {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.cosh (f x)) x :=
Complex.contDiff_cosh.contDiffAt.comp x hf
theorem ContDiffOn.ccosh {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.cosh (f x)) s :=
Complex.contDiff_cosh.comp_contDiffOn hf
theorem ContDiffWithinAt.ccosh {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.cosh (f x)) s x :=
Complex.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Complex.sinh` -/
theorem HasStrictFDerivAt.csinh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x :=
(Complex.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.csinh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.csinh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') s x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.csinh (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.sinh (f x)) s x :=
hf.hasFDerivWithinAt.csinh.differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.csinh (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.sinh (f x)) x :=
hc.hasFDerivAt.csinh.differentiableAt
theorem DifferentiableOn.csinh (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.sinh (f x)) s := fun x h => (hc x h).csinh
@[simp, fun_prop]
theorem Differentiable.csinh (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.sinh (f x) := fun x => (hc x).csinh
theorem fderivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.csinh.fderivWithin hxs
@[simp]
theorem fderiv_csinh (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.csinh.fderiv
theorem ContDiff.csinh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sinh (f x) :=
Complex.contDiff_sinh.comp h
theorem ContDiffAt.csinh {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.sinh (f x)) x :=
Complex.contDiff_sinh.contDiffAt.comp x hf
theorem ContDiffOn.csinh {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.sinh (f x)) s :=
Complex.contDiff_sinh.comp_contDiffOn hf
theorem ContDiffWithinAt.csinh {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.sinh (f x)) s x :=
Complex.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf
end
namespace Real
variable {x y z : ℝ}
theorem hasStrictDerivAt_sin (x : ℝ) : HasStrictDerivAt sin (cos x) x :=
(Complex.hasStrictDerivAt_sin x).real_of_complex
theorem hasDerivAt_sin (x : ℝ) : HasDerivAt sin (cos x) x :=
(hasStrictDerivAt_sin x).hasDerivAt
theorem contDiff_sin {n} : ContDiff ℝ n sin :=
Complex.contDiff_sin.real_of_complex
@[simp]
theorem differentiable_sin : Differentiable ℝ sin := fun x => (hasDerivAt_sin x).differentiableAt
@[simp]
theorem differentiableAt_sin : DifferentiableAt ℝ sin x :=
differentiable_sin x
@[simp]
theorem deriv_sin : deriv sin = cos :=
funext fun x => (hasDerivAt_sin x).deriv
theorem hasStrictDerivAt_cos (x : ℝ) : HasStrictDerivAt cos (-sin x) x :=
(Complex.hasStrictDerivAt_cos x).real_of_complex
theorem hasDerivAt_cos (x : ℝ) : HasDerivAt cos (-sin x) x :=
(Complex.hasDerivAt_cos x).real_of_complex
theorem contDiff_cos {n} : ContDiff ℝ n cos :=
Complex.contDiff_cos.real_of_complex
@[simp]
theorem differentiable_cos : Differentiable ℝ cos := fun x => (hasDerivAt_cos x).differentiableAt
@[simp]
theorem differentiableAt_cos : DifferentiableAt ℝ cos x :=
differentiable_cos x
theorem deriv_cos : deriv cos x = -sin x :=
(hasDerivAt_cos x).deriv
@[simp]
theorem deriv_cos' : deriv cos = fun x => -sin x :=
funext fun _ => deriv_cos
theorem hasStrictDerivAt_sinh (x : ℝ) : HasStrictDerivAt sinh (cosh x) x :=
(Complex.hasStrictDerivAt_sinh x).real_of_complex
theorem hasDerivAt_sinh (x : ℝ) : HasDerivAt sinh (cosh x) x :=
(Complex.hasDerivAt_sinh x).real_of_complex
theorem contDiff_sinh {n} : ContDiff ℝ n sinh :=
Complex.contDiff_sinh.real_of_complex
@[simp]
theorem differentiable_sinh : Differentiable ℝ sinh := fun x => (hasDerivAt_sinh x).differentiableAt
@[simp]
theorem differentiableAt_sinh : DifferentiableAt ℝ sinh x :=
differentiable_sinh x
@[simp]
theorem deriv_sinh : deriv sinh = cosh :=
funext fun x => (hasDerivAt_sinh x).deriv
theorem hasStrictDerivAt_cosh (x : ℝ) : HasStrictDerivAt cosh (sinh x) x :=
(Complex.hasStrictDerivAt_cosh x).real_of_complex
theorem hasDerivAt_cosh (x : ℝ) : HasDerivAt cosh (sinh x) x :=
(Complex.hasDerivAt_cosh x).real_of_complex
theorem contDiff_cosh {n} : ContDiff ℝ n cosh :=
Complex.contDiff_cosh.real_of_complex
@[simp]
theorem differentiable_cosh : Differentiable ℝ cosh := fun x => (hasDerivAt_cosh x).differentiableAt
@[simp]
theorem differentiableAt_cosh : DifferentiableAt ℝ cosh x :=
differentiable_cosh x
@[simp]
theorem deriv_cosh : deriv cosh = sinh :=
funext fun x => (hasDerivAt_cosh x).deriv
/-- `sinh` is strictly monotone. -/
theorem sinh_strictMono : StrictMono sinh :=
strictMono_of_deriv_pos <| by rw [Real.deriv_sinh]; exact cosh_pos
/-- `sinh` is injective, `∀ a b, sinh a = sinh b → a = b`. -/
theorem sinh_injective : Function.Injective sinh :=
sinh_strictMono.injective
@[simp]
theorem sinh_inj : sinh x = sinh y ↔ x = y :=
sinh_injective.eq_iff
@[simp]
theorem sinh_le_sinh : sinh x ≤ sinh y ↔ x ≤ y :=
sinh_strictMono.le_iff_le
@[simp]
theorem sinh_lt_sinh : sinh x < sinh y ↔ x < y :=
sinh_strictMono.lt_iff_lt
@[simp] lemma sinh_eq_zero : sinh x = 0 ↔ x = 0 := by rw [← @sinh_inj x, sinh_zero]
lemma sinh_ne_zero : sinh x ≠ 0 ↔ x ≠ 0 := sinh_eq_zero.not
@[simp]
theorem sinh_pos_iff : 0 < sinh x ↔ 0 < x := by simpa only [sinh_zero] using @sinh_lt_sinh 0 x
@[simp]
theorem sinh_nonpos_iff : sinh x ≤ 0 ↔ x ≤ 0 := by simpa only [sinh_zero] using @sinh_le_sinh x 0
@[simp]
theorem sinh_neg_iff : sinh x < 0 ↔ x < 0 := by simpa only [sinh_zero] using @sinh_lt_sinh x 0
@[simp]
theorem sinh_nonneg_iff : 0 ≤ sinh x ↔ 0 ≤ x := by simpa only [sinh_zero] using @sinh_le_sinh 0 x
theorem abs_sinh (x : ℝ) : |sinh x| = sinh |x| := by
cases le_total x 0 <;> simp [abs_of_nonneg, abs_of_nonpos, *]
theorem cosh_strictMonoOn : StrictMonoOn cosh (Ici 0) :=
strictMonoOn_of_deriv_pos (convex_Ici _) continuous_cosh.continuousOn fun x hx => by
rw [interior_Ici, mem_Ioi] at hx; rwa [deriv_cosh, sinh_pos_iff]
@[simp]
theorem cosh_le_cosh : cosh x ≤ cosh y ↔ |x| ≤ |y| :=
cosh_abs x ▸ cosh_abs y ▸ cosh_strictMonoOn.le_iff_le (abs_nonneg x) (abs_nonneg y)
@[simp]
theorem cosh_lt_cosh : cosh x < cosh y ↔ |x| < |y| :=
lt_iff_lt_of_le_iff_le cosh_le_cosh
@[simp]
theorem one_le_cosh (x : ℝ) : 1 ≤ cosh x :=
cosh_zero ▸ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg])
@[simp]
theorem one_lt_cosh : 1 < cosh x ↔ x ≠ 0 :=
cosh_zero ▸ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos])
theorem sinh_sub_id_strictMono : StrictMono fun x => sinh x - x := by
refine strictMono_of_odd_strictMonoOn_nonneg (fun x => by simp; abel) ?_
refine strictMonoOn_of_deriv_pos (convex_Ici _) ?_ fun x hx => ?_
· exact (continuous_sinh.sub continuous_id).continuousOn
· rw [interior_Ici, mem_Ioi] at hx
rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh]
exacts [hx.ne', differentiableAt_sinh, differentiableAt_id]
@[simp]
theorem self_le_sinh_iff : x ≤ sinh x ↔ 0 ≤ x :=
calc
x ≤ sinh x ↔ sinh 0 - 0 ≤ sinh x - x := by simp
_ ↔ 0 ≤ x := sinh_sub_id_strictMono.le_iff_le
@[simp]
theorem sinh_le_self_iff : sinh x ≤ x ↔ x ≤ 0 :=
calc
sinh x ≤ x ↔ sinh x - x ≤ sinh 0 - 0 := by simp
_ ↔ x ≤ 0 := sinh_sub_id_strictMono.le_iff_le
@[simp]
theorem self_lt_sinh_iff : x < sinh x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le sinh_le_self_iff
@[simp]
theorem sinh_lt_self_iff : sinh x < x ↔ x < 0 :=
lt_iff_lt_of_le_iff_le self_le_sinh_iff
end Real
section
/-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : ℝ → ℝ` -/
variable {f : ℝ → ℝ} {f' x : ℝ} {s : Set ℝ}
/-! #### `Real.cos` -/
theorem HasStrictDerivAt.cos (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x :=
(Real.hasStrictDerivAt_cos (f x)).comp x hf
theorem HasDerivAt.cos (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x :=
(Real.hasDerivAt_cos (f x)).comp x hf
theorem HasDerivWithinAt.cos (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') s x :=
(Real.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.cos (f x)) s x = -Real.sin (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.cos.derivWithin hxs
@[simp]
theorem deriv_cos (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.cos (f x)) x = -Real.sin (f x) * deriv f x :=
hc.hasDerivAt.cos.deriv
/-! #### `Real.sin` -/
theorem HasStrictDerivAt.sin (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x :=
(Real.hasStrictDerivAt_sin (f x)).comp x hf
theorem HasDerivAt.sin (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x :=
(Real.hasDerivAt_sin (f x)).comp x hf
theorem HasDerivWithinAt.sin (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') s x :=
(Real.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_sin (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.sin (f x)) s x = Real.cos (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.sin.derivWithin hxs
@[simp]
theorem deriv_sin (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.sin (f x)) x = Real.cos (f x) * deriv f x :=
hc.hasDerivAt.sin.deriv
/-! #### `Real.cosh` -/
theorem HasStrictDerivAt.cosh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x :=
(Real.hasStrictDerivAt_cosh (f x)).comp x hf
theorem HasDerivAt.cosh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x :=
(Real.hasDerivAt_cosh (f x)).comp x hf
theorem HasDerivWithinAt.cosh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') s x :=
(Real.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_cosh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.cosh (f x)) s x = Real.sinh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.cosh.derivWithin hxs
@[simp]
theorem deriv_cosh (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.cosh (f x)) x = Real.sinh (f x) * deriv f x :=
hc.hasDerivAt.cosh.deriv
/-! #### `Real.sinh` -/
theorem HasStrictDerivAt.sinh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x :=
(Real.hasStrictDerivAt_sinh (f x)).comp x hf
theorem HasDerivAt.sinh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x :=
(Real.hasDerivAt_sinh (f x)).comp x hf
theorem HasDerivWithinAt.sinh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') s x :=
(Real.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_sinh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.sinh (f x)) s x = Real.cosh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.sinh.derivWithin hxs
@[simp]
theorem deriv_sinh (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.sinh (f x)) x = Real.cosh (f x) * deriv f x :=
hc.hasDerivAt.sinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : E → ℝ` -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E}
{s : Set E}
| /-! #### `Real.cos` -/
theorem HasStrictFDerivAt.cos (hf : HasStrictFDerivAt f f' x) :
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Deriv.lean | 770 | 773 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.Continuous
import Mathlib.Topology.Defs.Induced
/-!
# Ordering on topologies and (co)induced topologies
Topologies on a fixed type `α` are ordered, by reverse inclusion. That is, for topologies `t₁` and
`t₂` on `α`, we write `t₁ ≤ t₂` if every set open in `t₂` is also open in `t₁`. (One also calls
`t₁` *finer* than `t₂`, and `t₂` *coarser* than `t₁`.)
Any function `f : α → β` induces
* `TopologicalSpace.induced f : TopologicalSpace β → TopologicalSpace α`;
* `TopologicalSpace.coinduced f : TopologicalSpace α → TopologicalSpace β`.
Continuity, the ordering on topologies and (co)induced topologies are related as follows:
* The identity map `(α, t₁) → (α, t₂)` is continuous iff `t₁ ≤ t₂`.
* A map `f : (α, t) → (β, u)` is continuous
* iff `t ≤ TopologicalSpace.induced f u` (`continuous_iff_le_induced`)
* iff `TopologicalSpace.coinduced f t ≤ u` (`continuous_iff_coinduced_le`).
Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete
topology.
For a function `f : α → β`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois
connection between topologies on `α` and topologies on `β`.
## Implementation notes
There is a Galois insertion between topologies on `α` (with the inclusion ordering) and all
collections of sets in `α`. The complete lattice structure on topologies on `α` is defined as the
reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding
Galois coinsertion between topologies on `α` (with the reversed inclusion ordering) and collections
of sets in `α` (with the reversed inclusion ordering).
## Tags
finer, coarser, induced topology, coinduced topology
-/
open Function Set Filter Topology
universe u v w
namespace TopologicalSpace
variable {α : Type u}
/-- The open sets of the least topology containing a collection of basic sets. -/
inductive GenerateOpen (g : Set (Set α)) : Set α → Prop
| basic : ∀ s ∈ g, GenerateOpen g s
| univ : GenerateOpen g univ
| inter : ∀ s t, GenerateOpen g s → GenerateOpen g t → GenerateOpen g (s ∩ t)
| sUnion : ∀ S : Set (Set α), (∀ s ∈ S, GenerateOpen g s) → GenerateOpen g (⋃₀ S)
/-- The smallest topological space containing the collection `g` of basic sets -/
def generateFrom (g : Set (Set α)) : TopologicalSpace α where
IsOpen := GenerateOpen g
isOpen_univ := GenerateOpen.univ
isOpen_inter := GenerateOpen.inter
isOpen_sUnion := GenerateOpen.sUnion
theorem isOpen_generateFrom_of_mem {g : Set (Set α)} {s : Set α} (hs : s ∈ g) :
IsOpen[generateFrom g] s :=
GenerateOpen.basic s hs
theorem nhds_generateFrom {g : Set (Set α)} {a : α} :
@nhds α (generateFrom g) a = ⨅ s ∈ { s | a ∈ s ∧ s ∈ g }, 𝓟 s := by
letI := generateFrom g
rw [nhds_def]
refine le_antisymm (biInf_mono fun s ⟨as, sg⟩ => ⟨as, .basic _ sg⟩) <| le_iInf₂ ?_
rintro s ⟨ha, hs⟩
induction hs with
| basic _ hs => exact iInf₂_le _ ⟨ha, hs⟩
| univ => exact le_top.trans_eq principal_univ.symm
| inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal
| sUnion _ _ hS =>
let ⟨t, htS, hat⟩ := ha
exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS)
lemma tendsto_nhds_generateFrom_iff {β : Type*} {m : α → β} {f : Filter α} {g : Set (Set β)}
{b : β} : Tendsto m f (@nhds β (generateFrom g) b) ↔ ∀ s ∈ g, b ∈ s → m ⁻¹' s ∈ f := by
simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp,
tendsto_principal]; rfl
/-- Construct a topology on α given the filter of neighborhoods of each point of α. -/
protected def mkOfNhds (n : α → Filter α) : TopologicalSpace α where
IsOpen s := ∀ a ∈ s, s ∈ n a
isOpen_univ _ _ := univ_mem
isOpen_inter := fun _s _t hs ht x ⟨hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt)
isOpen_sUnion := fun _s hs _a ⟨x, hx, hxa⟩ =>
mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx)
theorem nhds_mkOfNhds_of_hasBasis {n : α → Filter α} {ι : α → Sort*} {p : ∀ a, ι a → Prop}
{s : ∀ a, ι a → Set α} (hb : ∀ a, (n a).HasBasis (p a) (s a))
(hpure : ∀ a i, p a i → a ∈ s a i) (hopen : ∀ a i, p a i → ∀ᶠ x in n a, s a i ∈ n x) (a : α) :
@nhds α (.mkOfNhds n) a = n a := by
let t : TopologicalSpace α := .mkOfNhds n
apply le_antisymm
· intro U hU
replace hpure : pure ≤ n := fun x ↦ (hb x).ge_iff.2 (hpure x)
refine mem_nhds_iff.2 ⟨{x | U ∈ n x}, fun x hx ↦ hpure x hx, fun x hx ↦ ?_, hU⟩
rcases (hb x).mem_iff.1 hx with ⟨i, hpi, hi⟩
exact (hopen x i hpi).mono fun y hy ↦ mem_of_superset hy hi
· exact (nhds_basis_opens a).ge_iff.2 fun U ⟨haU, hUo⟩ ↦ hUo a haU
theorem nhds_mkOfNhds (n : α → Filter α) (a : α) (h₀ : pure ≤ n)
(h₁ : ∀ a, ∀ s ∈ n a, ∀ᶠ y in n a, s ∈ n y) :
@nhds α (TopologicalSpace.mkOfNhds n) a = n a :=
nhds_mkOfNhds_of_hasBasis (fun a ↦ (n a).basis_sets) h₀ h₁ _
theorem nhds_mkOfNhds_single [DecidableEq α] {a₀ : α} {l : Filter α} (h : pure a₀ ≤ l) (b : α) :
@nhds α (TopologicalSpace.mkOfNhds (update pure a₀ l)) b =
(update pure a₀ l : α → Filter α) b := by
refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟨h, fun _ _ => le_rfl⟩) fun a s hs => ?_
rcases eq_or_ne a a₀ with (rfl | ha)
· filter_upwards [hs] with b hb
rcases eq_or_ne b a with (rfl | hb)
· exact hs
· rwa [update_of_ne hb]
· simpa only [update_of_ne ha, mem_pure, eventually_pure] using hs
theorem nhds_mkOfNhds_filterBasis (B : α → FilterBasis α) (a : α) (h₀ : ∀ x, ∀ n ∈ B x, x ∈ n)
(h₁ : ∀ x, ∀ n ∈ B x, ∃ n₁ ∈ B x, ∀ x' ∈ n₁, ∃ n₂ ∈ B x', n₂ ⊆ n) :
@nhds α (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter :=
nhds_mkOfNhds_of_hasBasis (fun a ↦ (B a).hasBasis) h₀ h₁ a
section Lattice
variable {α : Type u} {β : Type v}
/-- The ordering on topologies on the type `α`. `t ≤ s` if every set open in `s` is also open in `t`
(`t` is finer than `s`). -/
instance : PartialOrder (TopologicalSpace α) :=
{ PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with
le := fun s t => ∀ U, IsOpen[t] U → IsOpen[s] U }
protected theorem le_def {α} {t s : TopologicalSpace α} : t ≤ s ↔ IsOpen[s] ≤ IsOpen[t] :=
Iff.rfl
theorem le_generateFrom_iff_subset_isOpen {g : Set (Set α)} {t : TopologicalSpace α} :
t ≤ generateFrom g ↔ g ⊆ { s | IsOpen[t] s } :=
⟨fun ht s hs => ht _ <| .basic s hs, fun hg _s hs =>
hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩
/-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a
topology. -/
protected def mkOfClosure (s : Set (Set α)) (hs : { u | GenerateOpen s u } = s) :
TopologicalSpace α where
IsOpen u := u ∈ s
isOpen_univ := hs ▸ TopologicalSpace.GenerateOpen.univ
isOpen_inter := hs ▸ TopologicalSpace.GenerateOpen.inter
isOpen_sUnion := hs ▸ TopologicalSpace.GenerateOpen.sUnion
theorem mkOfClosure_sets {s : Set (Set α)} {hs : { u | GenerateOpen s u } = s} :
TopologicalSpace.mkOfClosure s hs = generateFrom s :=
TopologicalSpace.ext hs.symm
theorem gc_generateFrom (α) :
GaloisConnection (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s })
(generateFrom ∘ OrderDual.ofDual) := fun _ _ =>
le_generateFrom_iff_subset_isOpen.symm
/-- The Galois coinsertion between `TopologicalSpace α` and `(Set (Set α))ᵒᵈ` whose lower part sends
a topology to its collection of open subsets, and whose upper part sends a collection of subsets
of `α` to the topology they generate. -/
def gciGenerateFrom (α : Type*) :
GaloisCoinsertion (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s })
(generateFrom ∘ OrderDual.ofDual) where
gc := gc_generateFrom α
u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs
choice g hg := TopologicalSpace.mkOfClosure g
(Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl)
choice_eq _ _ := mkOfClosure_sets
/-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology
and `⊤` the indiscrete topology. The infimum of a collection of topologies
is the topology generated by all their open sets, while the supremum is the
topology whose open sets are those sets open in every member of the collection. -/
instance : CompleteLattice (TopologicalSpace α) := (gciGenerateFrom α).liftCompleteLattice
@[mono, gcongr]
theorem generateFrom_anti {α} {g₁ g₂ : Set (Set α)} (h : g₁ ⊆ g₂) :
generateFrom g₂ ≤ generateFrom g₁ :=
(gc_generateFrom _).monotone_u h
theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) :
generateFrom { s | IsOpen[t] s } = t :=
(gciGenerateFrom α).u_l_eq t
theorem leftInverse_generateFrom :
LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } :=
(gciGenerateFrom α).u_l_leftInverse
theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) :=
(gciGenerateFrom α).u_surjective
theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace α => { s | IsOpen[t] s } :=
(gciGenerateFrom α).l_injective
end Lattice
end TopologicalSpace
section Lattice
variable {α : Type*} {t t₁ t₂ : TopologicalSpace α} {s : Set α}
theorem IsOpen.mono (hs : IsOpen[t₂] s) (h : t₁ ≤ t₂) : IsOpen[t₁] s := h s hs
theorem IsClosed.mono (hs : IsClosed[t₂] s) (h : t₁ ≤ t₂) : IsClosed[t₁] s :=
(@isOpen_compl_iff α s t₁).mp <| hs.isOpen_compl.mono h
theorem closure.mono (h : t₁ ≤ t₂) : closure[t₁] s ⊆ closure[t₂] s :=
@closure_minimal _ t₁ s (@closure _ t₂ s) subset_closure (IsClosed.mono isClosed_closure h)
theorem isOpen_implies_isOpen_iff : (∀ s, IsOpen[t₁] s → IsOpen[t₂] s) ↔ t₂ ≤ t₁ :=
Iff.rfl
/-- The only open sets in the indiscrete topology are the empty set and the whole space. -/
theorem TopologicalSpace.isOpen_top_iff {α} (U : Set α) : IsOpen[⊤] U ↔ U = ∅ ∨ U = univ :=
⟨fun h => by
induction h with
| basic _ h => exact False.elim h
| univ => exact .inr rfl
| inter _ _ _ _ h₁ h₂ =>
rcases h₁ with (rfl | rfl) <;> rcases h₂ with (rfl | rfl) <;> simp
| sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by
rintro (rfl | rfl)
exacts [@isOpen_empty _ ⊤, @isOpen_univ _ ⊤]⟩
/-- A topological space is discrete if every set is open, that is,
its topology equals the discrete topology `⊥`. -/
class DiscreteTopology (α : Type*) [t : TopologicalSpace α] : Prop where
/-- The `TopologicalSpace` structure on a type with discrete topology is equal to `⊥`. -/
eq_bot : t = ⊥
theorem discreteTopology_bot (α : Type*) : @DiscreteTopology α ⊥ :=
@DiscreteTopology.mk α ⊥ rfl
section DiscreteTopology
variable [TopologicalSpace α] [DiscreteTopology α] {β : Type*}
@[simp]
theorem isOpen_discrete (s : Set α) : IsOpen s := (@DiscreteTopology.eq_bot α _).symm ▸ trivial
@[simp] theorem isClosed_discrete (s : Set α) : IsClosed s := ⟨isOpen_discrete _⟩
theorem closure_discrete (s : Set α) : closure s = s := (isClosed_discrete _).closure_eq
@[simp] theorem dense_discrete {s : Set α} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq]
@[simp]
theorem denseRange_discrete {ι : Type*} {f : ι → α} : DenseRange f ↔ Surjective f := by
rw [DenseRange, dense_discrete, range_eq_univ]
@[nontriviality, continuity, fun_prop]
theorem continuous_of_discreteTopology [TopologicalSpace β] {f : α → β} : Continuous f :=
continuous_def.2 fun _ _ => isOpen_discrete _
/-- A function to a discrete topological space is continuous if and only if the preimage of every
singleton is open. -/
theorem continuous_discrete_rng {α} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β]
{f : α → β} : Continuous f ↔ ∀ b : β, IsOpen (f ⁻¹' {b}) :=
⟨fun h _ => (isOpen_discrete _).preimage h, fun h => ⟨fun s _ => by
rw [← biUnion_of_singleton s, preimage_iUnion₂]
exact isOpen_biUnion fun _ _ => h _⟩⟩
@[simp]
theorem nhds_discrete (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : @nhds α _ = pure :=
le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds
theorem mem_nhds_discrete {x : α} {s : Set α} :
s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure]
end DiscreteTopology
theorem le_of_nhds_le_nhds (h : ∀ x, @nhds α t₁ x ≤ @nhds α t₂ x) : t₁ ≤ t₂ := fun s => by
rw [@isOpen_iff_mem_nhds _ t₁, @isOpen_iff_mem_nhds _ t₂]
exact fun hs a ha => h _ (hs _ ha)
theorem eq_bot_of_singletons_open {t : TopologicalSpace α} (h : ∀ x, IsOpen[t] {x}) : t = ⊥ :=
bot_unique fun s _ => biUnion_of_singleton s ▸ isOpen_biUnion fun x _ => h x
theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] :
(∀ s : Set X, IsOpen s) ↔ DiscreteTopology X :=
⟨fun h => ⟨eq_bot_of_singletons_open fun _ => h _⟩, @isOpen_discrete _ _⟩
theorem discreteTopology_iff_forall_isClosed [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ s : Set α, IsClosed s :=
forall_open_iff_discrete.symm.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↦
isOpen_compl_iff
theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] :
(∀ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X :=
⟨fun h => ⟨eq_bot_of_singletons_open h⟩, fun a _ => @isOpen_discrete _ _ a _⟩
theorem DiscreteTopology.of_finite_of_isClosed_singleton [TopologicalSpace α] [Finite α]
(h : ∀ a : α, IsClosed {a}) : DiscreteTopology α :=
discreteTopology_iff_forall_isClosed.mpr fun s ↦
s.iUnion_of_singleton_coe ▸ isClosed_iUnion_of_finite fun _ ↦ h _
theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ x : α, {x} ∈ 𝓝 x := by
simp only [← singletons_open_iff_discrete, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq]
/-- This lemma characterizes discrete topological spaces as those whose singletons are
neighbourhoods. -/
theorem discreteTopology_iff_nhds [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ x : α, 𝓝 x = pure x := by
simp [discreteTopology_iff_singleton_mem_nhds, le_pure_iff]
apply forall_congr' (fun x ↦ ?_)
simp [le_antisymm_iff, pure_le_nhds x]
theorem discreteTopology_iff_nhds_ne [TopologicalSpace α] :
DiscreteTopology α ↔ ∀ x : α, 𝓝[≠] x = ⊥ := by
simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl]
/-- If the codomain of a continuous injective function has discrete topology,
then so does the domain.
See also `Embedding.discreteTopology` for an important special case. -/
theorem DiscreteTopology.of_continuous_injective
{β : Type*} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β}
(hc : Continuous f) (hinj : Injective f) : DiscreteTopology α :=
forall_open_iff_discrete.1 fun s ↦ hinj.preimage_image s ▸ (isOpen_discrete _).preimage hc
end Lattice
section GaloisConnection
variable {α β γ : Type*}
theorem isOpen_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} :
IsOpen[t.induced f] s ↔ ∃ t, IsOpen t ∧ f ⁻¹' t = s :=
Iff.rfl
theorem isClosed_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} :
IsClosed[t.induced f] s ↔ ∃ t, IsClosed t ∧ f ⁻¹' t = s := by
letI := t.induced f
simp only [← isOpen_compl_iff, isOpen_induced_iff]
exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff])
theorem isOpen_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} :
IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) :=
Iff.rfl
theorem isClosed_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} :
IsClosed[t.coinduced f] s ↔ IsClosed (f ⁻¹' s) := by
simp only [← isOpen_compl_iff, isOpen_coinduced (f := f), preimage_compl]
theorem preimage_nhds_coinduced [TopologicalSpace α] {π : α → β} {s : Set β} {a : α}
(hs : s ∈ @nhds β (TopologicalSpace.coinduced π ‹_›) (π a)) : π ⁻¹' s ∈ 𝓝 a := by
letI := TopologicalSpace.coinduced π ‹_›
rcases mem_nhds_iff.mp hs with ⟨V, hVs, V_op, mem_V⟩
exact mem_nhds_iff.mpr ⟨π ⁻¹' V, Set.preimage_mono hVs, V_op, mem_V⟩
variable {t t₁ t₂ : TopologicalSpace α} {t' : TopologicalSpace β} {f : α → β} {g : β → α}
theorem Continuous.coinduced_le (h : Continuous[t, t'] f) : t.coinduced f ≤ t' :=
(@continuous_def α β t t').1 h
theorem coinduced_le_iff_le_induced {f : α → β} {tα : TopologicalSpace α}
{tβ : TopologicalSpace β} : tα.coinduced f ≤ tβ ↔ tα ≤ tβ.induced f :=
⟨fun h _s ⟨_t, ht, hst⟩ => hst ▸ h _ ht, fun h s hs => h _ ⟨s, hs, rfl⟩⟩
theorem Continuous.le_induced (h : Continuous[t, t'] f) : t ≤ t'.induced f :=
coinduced_le_iff_le_induced.1 h.coinduced_le
theorem gc_coinduced_induced (f : α → β) :
GaloisConnection (TopologicalSpace.coinduced f) (TopologicalSpace.induced f) := fun _ _ =>
coinduced_le_iff_le_induced
theorem induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g :=
(gc_coinduced_induced g).monotone_u h
theorem coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f :=
(gc_coinduced_induced f).monotone_l h
@[simp]
theorem induced_top : (⊤ : TopologicalSpace α).induced g = ⊤ :=
(gc_coinduced_induced g).u_top
@[simp]
theorem induced_inf : (t₁ ⊓ t₂).induced g = t₁.induced g ⊓ t₂.induced g :=
(gc_coinduced_induced g).u_inf
@[simp]
theorem induced_iInf {ι : Sort w} {t : ι → TopologicalSpace α} :
(⨅ i, t i).induced g = ⨅ i, (t i).induced g :=
(gc_coinduced_induced g).u_iInf
@[simp]
theorem induced_sInf {s : Set (TopologicalSpace α)} :
TopologicalSpace.induced g (sInf s) = sInf (TopologicalSpace.induced g '' s) := by
rw [sInf_eq_iInf', sInf_image', induced_iInf]
@[simp]
theorem coinduced_bot : (⊥ : TopologicalSpace α).coinduced f = ⊥ :=
(gc_coinduced_induced f).l_bot
@[simp]
theorem coinduced_sup : (t₁ ⊔ t₂).coinduced f = t₁.coinduced f ⊔ t₂.coinduced f :=
(gc_coinduced_induced f).l_sup
@[simp]
theorem coinduced_iSup {ι : Sort w} {t : ι → TopologicalSpace α} :
(⨆ i, t i).coinduced f = ⨆ i, (t i).coinduced f :=
(gc_coinduced_induced f).l_iSup
@[simp]
theorem coinduced_sSup {s : Set (TopologicalSpace α)} :
TopologicalSpace.coinduced f (sSup s) = sSup ((TopologicalSpace.coinduced f) '' s) := by
rw [sSup_eq_iSup', sSup_image', coinduced_iSup]
theorem induced_id [t : TopologicalSpace α] : t.induced id = t :=
TopologicalSpace.ext <|
funext fun s => propext <| ⟨fun ⟨_, hs, h⟩ => h ▸ hs, fun hs => ⟨s, hs, rfl⟩⟩
theorem induced_compose {tγ : TopologicalSpace γ} {f : α → β} {g : β → γ} :
(tγ.induced g).induced f = tγ.induced (g ∘ f) :=
TopologicalSpace.ext <|
funext fun _ => propext
⟨fun ⟨_, ⟨s, hs, h₂⟩, h₁⟩ => h₁ ▸ h₂ ▸ ⟨s, hs, rfl⟩,
fun ⟨s, hs, h⟩ => ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩
theorem induced_const [t : TopologicalSpace α] {x : α} : (t.induced fun _ : β => x) = ⊤ :=
le_antisymm le_top (@continuous_const β α ⊤ t x).le_induced
theorem coinduced_id [t : TopologicalSpace α] : t.coinduced id = t :=
TopologicalSpace.ext rfl
theorem coinduced_compose [tα : TopologicalSpace α] {f : α → β} {g : β → γ} :
(tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) :=
TopologicalSpace.ext rfl
theorem Equiv.induced_symm {α β : Type*} (e : α ≃ β) :
TopologicalSpace.induced e.symm = TopologicalSpace.coinduced e := by
ext t U
rw [isOpen_induced_iff, isOpen_coinduced]
simp only [e.symm.preimage_eq_iff_eq_image, exists_eq_right, ← preimage_equiv_eq_image_symm]
theorem Equiv.coinduced_symm {α β : Type*} (e : α ≃ β) :
TopologicalSpace.coinduced e.symm = TopologicalSpace.induced e :=
e.symm.induced_symm.symm
end GaloisConnection
-- constructions using the complete lattice structure
section Constructions
open TopologicalSpace
variable {α : Type u} {β : Type v}
instance inhabitedTopologicalSpace {α : Type u} : Inhabited (TopologicalSpace α) :=
⟨⊥⟩
instance (priority := 100) Subsingleton.uniqueTopologicalSpace [Subsingleton α] :
Unique (TopologicalSpace α) where
default := ⊥
uniq t :=
eq_bot_of_singletons_open fun x =>
Subsingleton.set_cases (@isOpen_empty _ t) (@isOpen_univ _ t) ({x} : Set α)
instance (priority := 100) Subsingleton.discreteTopology [t : TopologicalSpace α] [Subsingleton α] :
DiscreteTopology α :=
⟨Unique.eq_default t⟩
instance : TopologicalSpace Empty := ⊥
instance : DiscreteTopology Empty := ⟨rfl⟩
instance : TopologicalSpace PEmpty := ⊥
instance : DiscreteTopology PEmpty := ⟨rfl⟩
instance : TopologicalSpace PUnit := ⊥
instance : DiscreteTopology PUnit := ⟨rfl⟩
instance : TopologicalSpace Bool := ⊥
instance : DiscreteTopology Bool := ⟨rfl⟩
instance : TopologicalSpace ℕ := ⊥
instance : DiscreteTopology ℕ := ⟨rfl⟩
instance : TopologicalSpace ℤ := ⊥
instance : DiscreteTopology ℤ := ⟨rfl⟩
instance {n} : TopologicalSpace (Fin n) := ⊥
instance {n} : DiscreteTopology (Fin n) := ⟨rfl⟩
instance sierpinskiSpace : TopologicalSpace Prop :=
generateFrom {{True}}
/-- See also `continuous_of_discreteTopology`, which works for `IsEmpty α`. -/
theorem continuous_empty_function [TopologicalSpace α] [TopologicalSpace β] [IsEmpty β]
(f : α → β) : Continuous f :=
letI := Function.isEmpty f
continuous_of_discreteTopology
theorem le_generateFrom {t : TopologicalSpace α} {g : Set (Set α)} (h : ∀ s ∈ g, IsOpen s) :
t ≤ generateFrom g :=
le_generateFrom_iff_subset_isOpen.2 h
theorem induced_generateFrom_eq {α β} {b : Set (Set β)} {f : α → β} :
(generateFrom b).induced f = generateFrom (preimage f '' b) :=
le_antisymm (le_generateFrom <| forall_mem_image.2 fun s hs => ⟨s, GenerateOpen.basic _ hs, rfl⟩)
(coinduced_le_iff_le_induced.1 <| le_generateFrom fun _s hs => .basic _ (mem_image_of_mem _ hs))
theorem le_induced_generateFrom {α β} [t : TopologicalSpace α] {b : Set (Set β)} {f : α → β}
(h : ∀ a : Set β, a ∈ b → IsOpen (f ⁻¹' a)) : t ≤ induced f (generateFrom b) := by
rw [induced_generateFrom_eq]
apply le_generateFrom
simp only [mem_image, and_imp, forall_apply_eq_imp_iff₂, exists_imp]
exact h
lemma generateFrom_insert_of_generateOpen {α : Type*} {s : Set (Set α)} {t : Set α}
(ht : GenerateOpen s t) : generateFrom (insert t s) = generateFrom s := by
refine le_antisymm (generateFrom_anti <| subset_insert t s) (le_generateFrom ?_)
rintro t (rfl | h)
· exact ht
· exact isOpen_generateFrom_of_mem h
@[simp]
lemma generateFrom_insert_univ {α : Type*} {s : Set (Set α)} :
generateFrom (insert univ s) = generateFrom s :=
generateFrom_insert_of_generateOpen .univ
@[simp]
lemma generateFrom_insert_empty {α : Type*} {s : Set (Set α)} :
generateFrom (insert ∅ s) = generateFrom s := by
rw [← sUnion_empty]
exact generateFrom_insert_of_generateOpen (.sUnion ∅ (fun s_1 a ↦ False.elim a))
/-- This construction is left adjoint to the operation sending a topology on `α`
to its neighborhood filter at a fixed point `a : α`. -/
def nhdsAdjoint (a : α) (f : Filter α) : TopologicalSpace α where
IsOpen s := a ∈ s → s ∈ f
isOpen_univ _ := univ_mem
isOpen_inter := fun _s _t hs ht ⟨has, hat⟩ => inter_mem (hs has) (ht hat)
isOpen_sUnion := fun _k hk ⟨u, hu, hau⟩ => mem_of_superset (hk u hu hau) (subset_sUnion_of_mem hu)
theorem gc_nhds (a : α) : GaloisConnection (nhdsAdjoint a) fun t => @nhds α t a := fun f t => by
rw [le_nhds_iff]
exact ⟨fun H s hs has => H _ has hs, fun H s has hs => H _ hs has⟩
theorem nhds_mono {t₁ t₂ : TopologicalSpace α} {a : α} (h : t₁ ≤ t₂) :
@nhds α t₁ a ≤ @nhds α t₂ a :=
(gc_nhds a).monotone_u h
theorem le_iff_nhds {α : Type*} (t t' : TopologicalSpace α) :
t ≤ t' ↔ ∀ x, @nhds α t x ≤ @nhds α t' x :=
⟨fun h _ => nhds_mono h, le_of_nhds_le_nhds⟩
theorem isOpen_singleton_nhdsAdjoint {α : Type*} {a b : α} (f : Filter α) (hb : b ≠ a) :
IsOpen[nhdsAdjoint a f] {b} := fun h ↦
absurd h hb.symm
theorem nhds_nhdsAdjoint_same (a : α) (f : Filter α) :
@nhds α (nhdsAdjoint a f) a = pure a ⊔ f := by
let _ := nhdsAdjoint a f
apply le_antisymm
· rintro t ⟨hat : a ∈ t, htf : t ∈ f⟩
exact IsOpen.mem_nhds (fun _ ↦ htf) hat
· exact sup_le (pure_le_nhds _) ((gc_nhds a).le_u_l f)
theorem nhds_nhdsAdjoint_of_ne {a b : α} (f : Filter α) (h : b ≠ a) :
@nhds α (nhdsAdjoint a f) b = pure b :=
let _ := nhdsAdjoint a f
(isOpen_singleton_iff_nhds_eq_pure _).1 <| isOpen_singleton_nhdsAdjoint f h
theorem nhds_nhdsAdjoint [DecidableEq α] (a : α) (f : Filter α) :
@nhds α (nhdsAdjoint a f) = update pure a (pure a ⊔ f) :=
eq_update_iff.2 ⟨nhds_nhdsAdjoint_same .., fun _ ↦ nhds_nhdsAdjoint_of_ne _⟩
theorem le_nhdsAdjoint_iff' {a : α} {f : Filter α} {t : TopologicalSpace α} :
t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, @nhds α t b = pure b := by
classical
simp_rw [le_iff_nhds, nhds_nhdsAdjoint, forall_update_iff, (pure_le_nhds _).le_iff_eq]
theorem le_nhdsAdjoint_iff {α : Type*} (a : α) (f : Filter α) (t : TopologicalSpace α) :
t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, IsOpen[t] {b} := by
simp only [le_nhdsAdjoint_iff', @isOpen_singleton_iff_nhds_eq_pure α t]
theorem nhds_iInf {ι : Sort*} {t : ι → TopologicalSpace α} {a : α} :
@nhds α (iInf t) a = ⨅ i, @nhds α (t i) a :=
(gc_nhds a).u_iInf
theorem nhds_sInf {s : Set (TopologicalSpace α)} {a : α} :
@nhds α (sInf s) a = ⨅ t ∈ s, @nhds α t a :=
(gc_nhds a).u_sInf
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: timeouts without `b₁ := t₁`
theorem nhds_inf {t₁ t₂ : TopologicalSpace α} {a : α} :
@nhds α (t₁ ⊓ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a :=
(gc_nhds a).u_inf (b₁ := t₁)
theorem nhds_top {a : α} : @nhds α ⊤ a = ⊤ :=
(gc_nhds a).u_top
theorem isOpen_sup {t₁ t₂ : TopologicalSpace α} {s : Set α} :
IsOpen[t₁ ⊔ t₂] s ↔ IsOpen[t₁] s ∧ IsOpen[t₂] s :=
Iff.rfl
open TopologicalSpace
variable {γ : Type*} {f : α → β} {ι : Sort*}
theorem continuous_iff_coinduced_le {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} :
Continuous[t₁, t₂] f ↔ coinduced f t₁ ≤ t₂ :=
continuous_def
theorem continuous_iff_le_induced {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} :
Continuous[t₁, t₂] f ↔ t₁ ≤ induced f t₂ :=
Iff.trans continuous_iff_coinduced_le (gc_coinduced_induced f _ _)
lemma continuous_generateFrom_iff {t : TopologicalSpace α} {b : Set (Set β)} :
Continuous[t, generateFrom b] f ↔ ∀ s ∈ b, IsOpen (f ⁻¹' s) := by
rw [continuous_iff_coinduced_le, le_generateFrom_iff_subset_isOpen]
simp only [isOpen_coinduced, preimage_id', subset_def, mem_setOf]
@[continuity, fun_prop]
theorem continuous_induced_dom {t : TopologicalSpace β} : Continuous[induced f t, t] f :=
continuous_iff_le_induced.2 le_rfl
theorem continuous_induced_rng {g : γ → α} {t₂ : TopologicalSpace β} {t₁ : TopologicalSpace γ} :
Continuous[t₁, induced f t₂] g ↔ Continuous[t₁, t₂] (f ∘ g) := by
simp only [continuous_iff_le_induced, induced_compose]
theorem continuous_coinduced_rng {t : TopologicalSpace α} :
Continuous[t, coinduced f t] f :=
continuous_iff_coinduced_le.2 le_rfl
theorem continuous_coinduced_dom {g : β → γ} {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace γ} :
Continuous[coinduced f t₁, t₂] g ↔ Continuous[t₁, t₂] (g ∘ f) := by
simp only [continuous_iff_coinduced_le, coinduced_compose]
theorem continuous_le_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁)
(h₂ : Continuous[t₁, t₃] f) : Continuous[t₂, t₃] f := by
rw [continuous_iff_le_induced] at h₂ ⊢
exact le_trans h₁ h₂
theorem continuous_le_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃)
(h₂ : Continuous[t₁, t₂] f) : Continuous[t₁, t₃] f := by
rw [continuous_iff_coinduced_le] at h₂ ⊢
exact le_trans h₂ h₁
theorem continuous_sup_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} :
Continuous[t₁ ⊔ t₂, t₃] f ↔ Continuous[t₁, t₃] f ∧ Continuous[t₂, t₃] f := by
simp only [continuous_iff_le_induced, sup_le_iff]
theorem continuous_sup_rng_left {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} :
Continuous[t₁, t₂] f → Continuous[t₁, t₂ ⊔ t₃] f :=
continuous_le_rng le_sup_left
theorem continuous_sup_rng_right {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} :
Continuous[t₁, t₃] f → Continuous[t₁, t₂ ⊔ t₃] f :=
continuous_le_rng le_sup_right
theorem continuous_sSup_dom {T : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β} :
Continuous[sSup T, t₂] f ↔ ∀ t ∈ T, Continuous[t, t₂] f := by
simp only [continuous_iff_le_induced, sSup_le_iff]
theorem continuous_sSup_rng {t₁ : TopologicalSpace α} {t₂ : Set (TopologicalSpace β)}
{t : TopologicalSpace β} (h₁ : t ∈ t₂) (hf : Continuous[t₁, t] f) :
Continuous[t₁, sSup t₂] f :=
continuous_iff_coinduced_le.2 <| le_sSup_of_le h₁ <| continuous_iff_coinduced_le.1 hf
theorem continuous_iSup_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} :
Continuous[iSup t₁, t₂] f ↔ ∀ i, Continuous[t₁ i, t₂] f := by
simp only [continuous_iff_le_induced, iSup_le_iff]
theorem continuous_iSup_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} {i : ι}
(h : Continuous[t₁, t₂ i] f) : Continuous[t₁, iSup t₂] f :=
continuous_sSup_rng ⟨i, rfl⟩ h
theorem continuous_inf_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} :
Continuous[t₁, t₂ ⊓ t₃] f ↔ Continuous[t₁, t₂] f ∧ Continuous[t₁, t₃] f := by
simp only [continuous_iff_coinduced_le, le_inf_iff]
theorem continuous_inf_dom_left {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} :
Continuous[t₁, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f :=
continuous_le_dom inf_le_left
theorem continuous_inf_dom_right {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} :
Continuous[t₂, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f :=
continuous_le_dom inf_le_right
theorem continuous_sInf_dom {t₁ : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β}
{t : TopologicalSpace α} (h₁ : t ∈ t₁) :
Continuous[t, t₂] f → Continuous[sInf t₁, t₂] f :=
continuous_le_dom <| sInf_le h₁
theorem continuous_sInf_rng {t₁ : TopologicalSpace α} {T : Set (TopologicalSpace β)} :
Continuous[t₁, sInf T] f ↔ ∀ t ∈ T, Continuous[t₁, t] f := by
simp only [continuous_iff_coinduced_le, le_sInf_iff]
theorem continuous_iInf_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} {i : ι} :
Continuous[t₁ i, t₂] f → Continuous[iInf t₁, t₂] f :=
continuous_le_dom <| iInf_le _ _
theorem continuous_iInf_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} :
Continuous[t₁, iInf t₂] f ↔ ∀ i, Continuous[t₁, t₂ i] f := by
simp only [continuous_iff_coinduced_le, le_iInf_iff]
@[continuity, fun_prop]
theorem continuous_bot {t : TopologicalSpace β} : Continuous[⊥, t] f :=
continuous_iff_le_induced.2 bot_le
@[continuity, fun_prop]
theorem continuous_top {t : TopologicalSpace α} : Continuous[t, ⊤] f :=
continuous_iff_coinduced_le.2 le_top
theorem continuous_id_iff_le {t t' : TopologicalSpace α} : Continuous[t, t'] id ↔ t ≤ t' :=
@continuous_def _ _ t t' id
theorem continuous_id_of_le {t t' : TopologicalSpace α} (h : t ≤ t') : Continuous[t, t'] id :=
continuous_id_iff_le.2 h
-- 𝓝 in the induced topology
theorem mem_nhds_induced [T : TopologicalSpace α] (f : β → α) (a : β) (s : Set β) :
s ∈ @nhds β (TopologicalSpace.induced f T) a ↔ ∃ u ∈ 𝓝 (f a), f ⁻¹' u ⊆ s := by
letI := T.induced f
simp_rw [mem_nhds_iff, isOpen_induced_iff]
constructor
· rintro ⟨u, usub, ⟨v, openv, rfl⟩, au⟩
exact ⟨v, ⟨v, Subset.rfl, openv, au⟩, usub⟩
· rintro ⟨u, ⟨v, vsubu, openv, amem⟩, finvsub⟩
exact ⟨f ⁻¹' v, (Set.preimage_mono vsubu).trans finvsub, ⟨⟨v, openv, rfl⟩, amem⟩⟩
theorem nhds_induced [T : TopologicalSpace α] (f : β → α) (a : β) :
@nhds β (TopologicalSpace.induced f T) a = comap f (𝓝 (f a)) := by
ext s
rw [mem_nhds_induced, mem_comap]
theorem induced_iff_nhds_eq [tα : TopologicalSpace α] [tβ : TopologicalSpace β] (f : β → α) :
tβ = tα.induced f ↔ ∀ b, 𝓝 b = comap f (𝓝 <| f b) := by
simp only [ext_iff_nhds, nhds_induced]
theorem map_nhds_induced_of_surjective [T : TopologicalSpace α] {f : β → α} (hf : Surjective f)
(a : β) : map f (@nhds β (TopologicalSpace.induced f T) a) = 𝓝 (f a) := by
rw [nhds_induced, map_comap_of_surjective hf]
theorem continuous_nhdsAdjoint_dom [TopologicalSpace β] {f : α → β} {a : α} {l : Filter α} :
Continuous[nhdsAdjoint a l, _] f ↔ Tendsto f l (𝓝 (f a)) := by
simp_rw [continuous_iff_le_induced, gc_nhds _ _, nhds_induced, tendsto_iff_comap]
theorem coinduced_nhdsAdjoint (f : α → β) (a : α) (l : Filter α) :
coinduced f (nhdsAdjoint a l) = nhdsAdjoint (f a) (map f l) :=
eq_of_forall_ge_iff fun _ ↦ by
rw [gc_nhds, ← continuous_iff_coinduced_le, continuous_nhdsAdjoint_dom, Tendsto]
end Constructions
section Induced
open TopologicalSpace
variable {α : Type*} {β : Type*}
variable [t : TopologicalSpace β] {f : α → β}
theorem isOpen_induced_eq {s : Set α} :
IsOpen[induced f t] s ↔ s ∈ preimage f '' { s | IsOpen s } :=
Iff.rfl
theorem isOpen_induced {s : Set β} (h : IsOpen s) : IsOpen[induced f t] (f ⁻¹' s) :=
⟨s, h, rfl⟩
theorem map_nhds_induced_eq (a : α) : map f (@nhds α (induced f t) a) = 𝓝[range f] f a := by
rw [nhds_induced, Filter.map_comap, nhdsWithin]
theorem map_nhds_induced_of_mem {a : α} (h : range f ∈ 𝓝 (f a)) :
map f (@nhds α (induced f t) a) = 𝓝 (f a) := by rw [nhds_induced, Filter.map_comap_of_mem h]
theorem closure_induced {f : α → β} {a : α} {s : Set α} :
a ∈ @closure α (t.induced f) s ↔ f a ∈ closure (f '' s) := by
letI := t.induced f
simp only [mem_closure_iff_frequently, nhds_induced, frequently_comap, mem_image, and_comm]
theorem isClosed_induced_iff' {f : α → β} {s : Set α} :
IsClosed[t.induced f] s ↔ ∀ a, f a ∈ closure (f '' s) → a ∈ s := by
letI := t.induced f
simp only [← closure_subset_iff_isClosed, subset_def, closure_induced]
end Induced
section Sierpinski
variable {α : Type*}
@[simp]
theorem isOpen_singleton_true : IsOpen ({True} : Set Prop) :=
TopologicalSpace.GenerateOpen.basic _ (mem_singleton _)
@[simp]
theorem nhds_true : 𝓝 True = pure True :=
le_antisymm (le_pure_iff.2 <| isOpen_singleton_true.mem_nhds <| mem_singleton _) (pure_le_nhds _)
@[simp]
theorem nhds_false : 𝓝 False = ⊤ :=
TopologicalSpace.nhds_generateFrom.trans <| by simp [@and_comm (_ ∈ _), iInter_and]
theorem tendsto_nhds_true {l : Filter α} {p : α → Prop} :
Tendsto p l (𝓝 True) ↔ ∀ᶠ x in l, p x := by simp
theorem tendsto_nhds_Prop {l : Filter α} {p : α → Prop} {q : Prop} :
Tendsto p l (𝓝 q) ↔ (q → ∀ᶠ x in l, p x) := by
by_cases q <;> simp [*]
variable [TopologicalSpace α]
theorem continuous_Prop {p : α → Prop} : Continuous p ↔ IsOpen { x | p x } := by
simp only [continuous_iff_continuousAt, ContinuousAt, tendsto_nhds_Prop, isOpen_iff_mem_nhds]; rfl
theorem isOpen_iff_continuous_mem {s : Set α} : IsOpen s ↔ Continuous (· ∈ s) :=
continuous_Prop.symm
end Sierpinski
section iInf
open TopologicalSpace
variable {α : Type u} {ι : Sort v}
theorem generateFrom_union (a₁ a₂ : Set (Set α)) :
generateFrom (a₁ ∪ a₂) = generateFrom a₁ ⊓ generateFrom a₂ :=
(gc_generateFrom α).u_inf
theorem setOf_isOpen_sup (t₁ t₂ : TopologicalSpace α) :
{ s | IsOpen[t₁ ⊔ t₂] s } = { s | IsOpen[t₁] s } ∩ { s | IsOpen[t₂] s } :=
rfl
theorem generateFrom_iUnion {f : ι → Set (Set α)} :
generateFrom (⋃ i, f i) = ⨅ i, generateFrom (f i) :=
(gc_generateFrom α).u_iInf
theorem setOf_isOpen_iSup {t : ι → TopologicalSpace α} :
{ s | IsOpen[⨆ i, t i] s } = ⋂ i, { s | IsOpen[t i] s } :=
(gc_generateFrom α).l_iSup
theorem generateFrom_sUnion {S : Set (Set (Set α))} :
generateFrom (⋃₀ S) = ⨅ s ∈ S, generateFrom s :=
(gc_generateFrom α).u_sInf
theorem setOf_isOpen_sSup {T : Set (TopologicalSpace α)} :
{ s | IsOpen[sSup T] s } = ⋂ t ∈ T, { s | IsOpen[t] s } :=
(gc_generateFrom α).l_sSup
theorem generateFrom_union_isOpen (a b : TopologicalSpace α) :
generateFrom ({ s | IsOpen[a] s } ∪ { s | IsOpen[b] s }) = a ⊓ b :=
(gciGenerateFrom α).u_inf_l _ _
theorem generateFrom_iUnion_isOpen (f : ι → TopologicalSpace α) :
generateFrom (⋃ i, { s | IsOpen[f i] s }) = ⨅ i, f i :=
(gciGenerateFrom α).u_iInf_l _
theorem generateFrom_inter (a b : TopologicalSpace α) :
generateFrom ({ s | IsOpen[a] s } ∩ { s | IsOpen[b] s }) = a ⊔ b :=
(gciGenerateFrom α).u_sup_l _ _
theorem generateFrom_iInter (f : ι → TopologicalSpace α) :
generateFrom (⋂ i, { s | IsOpen[f i] s }) = ⨆ i, f i :=
(gciGenerateFrom α).u_iSup_l _
theorem generateFrom_iInter_of_generateFrom_eq_self (f : ι → Set (Set α))
(hf : ∀ i, { s | IsOpen[generateFrom (f i)] s } = f i) :
generateFrom (⋂ i, f i) = ⨆ i, generateFrom (f i) :=
(gciGenerateFrom α).u_iSup_of_lu_eq_self f hf
variable {t : ι → TopologicalSpace α}
theorem isOpen_iSup_iff {s : Set α} : IsOpen[⨆ i, t i] s ↔ ∀ i, IsOpen[t i] s :=
show s ∈ {s | IsOpen[iSup t] s} ↔ s ∈ { x : Set α | ∀ i : ι, IsOpen[t i] x } by
simp [setOf_isOpen_iSup]
theorem isOpen_sSup_iff {s : Set α} {T : Set (TopologicalSpace α)} :
IsOpen[sSup T] s ↔ ∀ t ∈ T, IsOpen[t] s := by
simp only [sSup_eq_iSup, isOpen_iSup_iff]
theorem isClosed_iSup_iff {s : Set α} : IsClosed[⨆ i, t i] s ↔ ∀ i, IsClosed[t i] s := by
simp only [← @isOpen_compl_iff _ _ (⨆ i, t i), ← @isOpen_compl_iff _ _ (t _), isOpen_iSup_iff]
theorem isClosed_sSup_iff {s : Set α} {T : Set (TopologicalSpace α)} :
IsClosed[sSup T] s ↔ ∀ t ∈ T, IsClosed[t] s := by
simp only [sSup_eq_iSup, isClosed_iSup_iff]
end iInf
| Mathlib/Topology/Order.lean | 906 | 907 | |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Logic.Relator
import Mathlib.Tactic.Use
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.SimpRw
import Mathlib.Logic.Basic
import Mathlib.Order.Defs.Unbundled
/-!
# Relation closures
This file defines the reflexive, transitive, reflexive transitive and equivalence closures
of relations and proves some basic results on them.
Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For
the bundled version, see `Rel`.
## Definitions
* `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all
`a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`.
* `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related
transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`.
* `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything
`r` related transitively, plus for all `a` it relates `a` with itself. So
`ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as
the reflexive closure of the transitive closure, or the transitive closure of the reflexive
closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of
rewrites.
* `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates,
plus for all related pairs it relates them in the opposite order.
* `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and
`s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to
both.
* `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`,
`g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b`
related by `r`.
* `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In
terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term.
-/
open Function
variable {α β γ δ ε ζ : Type*}
section NeImp
variable {r : α → α → Prop}
theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x
/-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`,
it suffices to show it holds when `x ≠ y`. -/
theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by
by_cases hxy : x = y
· exact hxy ▸ h x
· exact hr hxy
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. -/
theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y :=
⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/
theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y :=
IsRefl.reflexive.ne_imp_iff
protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x :=
⟨fun h ↦ H h, fun h ↦ H h⟩
theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r :=
funext₂ fun _ _ ↦ propext <| h.iff _ _
theorem Symmetric.swap_eq : Symmetric r → swap r = r :=
Symmetric.flip_eq
theorem flip_eq_iff : flip r = r ↔ Symmetric r :=
⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩
theorem swap_eq_iff : swap r = r ↔ Symmetric r :=
flip_eq_iff
end NeImp
section Comap
variable {r : β → β → Prop}
theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a)
theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab
theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) :=
fun _ _ _ hab hbc ↦ h hab hbc
theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) :=
⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩
end Comap
namespace Relation
section Comp
variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop}
/-- The composition of two relations, yielding a new relation. The result
relates a term of `α` and a term of `γ` if there is an intermediate
term of `β` related to both.
-/
def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop :=
∃ b, r a b ∧ p b c
@[inherit_doc]
local infixr:80 " ∘r " => Relation.Comp
@[simp]
theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun ..
@[simp]
theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp ..
@[simp]
theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, eq_comp]
@[simp]
theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, comp_eq]
theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by
funext a d
apply propext
constructor
· exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩
· exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩
theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by
funext c a
apply propext
constructor
· exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩
· exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩
end Comp
section Fibration
variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β)
/-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all
`a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image
of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/
def Fibration :=
∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b
variable {rα rβ}
/-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is
accessible under `rα`, then `f a` is accessible under `rβ`. -/
theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by
induction ha with | intro a _ ih => ?_
refine Acc.intro (f a) fun b hr ↦ ?_
obtain ⟨a', hr', rfl⟩ := fib hr
exact ih a' hr'
theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α)
(ha : Acc (InvImage rβ f) a) : Acc rβ (f a) :=
ha.of_fibration f fun a _ h ↦
let ⟨a', he⟩ := dc h
⟨a', by simp_all [InvImage], he⟩
end Fibration
section Map
variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ}
/-- The map of a relation `r` through a pair of functions pushes the
relation to the codomains of the functions. The resulting relation is
defined by having pairs of terms related if they have preimages
related by `r`.
-/
protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦
∃ a b, r a b ∧ f a = c ∧ g b = d
lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl
@[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) :
Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by
ext a b
simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ]
refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩
rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩
exact ⟨hab, h⟩
@[simp]
lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) :
Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff]
@[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map]
instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) :=
‹Decidable _›
lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) :
Reflexive (Relation.Map r f f) := by
intro x
obtain ⟨y, rfl⟩ := hf x
exact ⟨y, y, hr y, rfl, rfl⟩
lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) :
Symmetric (Relation.Map r f f) := by
rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩
lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β}
(hf : ∀ x y, f x = f y → r x y) :
Transitive (Relation.Map r f f) := by
rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩
exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩
lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β)
(hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) :
Equivalence (Relation.Map r f f) where
refl := map_reflexive hr.reflexive hf
symm := @(map_symmetric hr.symmetric _)
trans := @(map_transitive hr.transitive hf_ker)
-- TODO: state this using `≤`, after adjusting imports.
lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) :
∀ x y, Relation.Map r f g x y → Relation.Map s f g x y :=
fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩
end Map
variable {r : α → α → Prop} {a b c : α}
/-- `ReflTransGen r`: reflexive transitive closure of `r` -/
@[mk_iff ReflTransGen.cases_tail_iff]
inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflTransGen r a a
| tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c
attribute [refl] ReflTransGen.refl
/-- `ReflGen r`: reflexive closure of `r` -/
@[mk_iff]
inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflGen r a a
| single {b} : r a b → ReflGen r a b
variable (r) in
/-- `EqvGen r`: equivalence closure of `r`. -/
@[mk_iff]
inductive EqvGen : α → α → Prop
| rel x y : r x y → EqvGen x y
| refl x : EqvGen x x
| symm x y : EqvGen x y → EqvGen y x
| trans x y z : EqvGen x y → EqvGen y z → EqvGen x z
attribute [mk_iff] TransGen
attribute [refl] ReflGen.refl
namespace ReflGen
theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b
| a, _, refl => by rfl
| _, _, single h => ReflTransGen.tail ReflTransGen.refl h
theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b
| a, _, ReflGen.refl => by rfl
| a, b, single h => single (hp a b h)
instance : IsRefl α (ReflGen r) :=
⟨@refl α r⟩
end ReflGen
namespace ReflTransGen
@[trans]
theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
theorem single (hab : r a b) : ReflTransGen r a b :=
| refl.tail hab
theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| Mathlib/Logic/Relation.lean | 306 | 309 |
/-
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
-/
import Mathlib.Data.Finset.Basic
import Mathlib.Data.Finset.Image
/-!
# Cardinality of a finite set
This defines the cardinality of a `Finset` and provides induction principles for finsets.
## Main declarations
* `Finset.card`: `#s : ℕ` returns the cardinality of `s : Finset α`.
### Induction principles
* `Finset.strongInduction`: Strong induction
* `Finset.strongInductionOn`
* `Finset.strongDownwardInduction`
* `Finset.strongDownwardInductionOn`
* `Finset.case_strong_induction_on`
* `Finset.Nonempty.strong_induction`
-/
assert_not_exists Monoid
open Function Multiset Nat
variable {α β R : Type*}
namespace Finset
variable {s t : Finset α} {a b : α}
/-- `s.card` is the number of elements of `s`, aka its cardinality.
The notation `#s` can be accessed in the `Finset` locale. -/
def card (s : Finset α) : ℕ :=
Multiset.card s.1
@[inherit_doc] scoped prefix:arg "#" => Finset.card
theorem card_def (s : Finset α) : #s = Multiset.card s.1 :=
rfl
@[simp] lemma card_val (s : Finset α) : Multiset.card s.1 = #s := rfl
@[simp]
theorem card_mk {m nodup} : #(⟨m, nodup⟩ : Finset α) = Multiset.card m :=
rfl
@[simp]
theorem card_empty : #(∅ : Finset α) = 0 :=
rfl
@[gcongr]
theorem card_le_card : s ⊆ t → #s ≤ #t :=
Multiset.card_le_card ∘ val_le_iff.mpr
@[mono]
theorem card_mono : Monotone (@card α) := by apply card_le_card
@[simp] lemma card_eq_zero : #s = 0 ↔ s = ∅ := Multiset.card_eq_zero.trans val_eq_zero
lemma card_ne_zero : #s ≠ 0 ↔ s.Nonempty := card_eq_zero.ne.trans nonempty_iff_ne_empty.symm
@[simp] lemma card_pos : 0 < #s ↔ s.Nonempty := Nat.pos_iff_ne_zero.trans card_ne_zero
@[simp] lemma one_le_card : 1 ≤ #s ↔ s.Nonempty := card_pos
alias ⟨_, Nonempty.card_pos⟩ := card_pos
alias ⟨_, Nonempty.card_ne_zero⟩ := card_ne_zero
theorem card_ne_zero_of_mem (h : a ∈ s) : #s ≠ 0 :=
(not_congr card_eq_zero).2 <| ne_empty_of_mem h
@[simp]
theorem card_singleton (a : α) : #{a} = 1 :=
Multiset.card_singleton _
theorem card_singleton_inter [DecidableEq α] : #({a} ∩ s) ≤ 1 := by
obtain h | h := Finset.decidableMem a s
· simp [Finset.singleton_inter_of_not_mem h]
· simp [Finset.singleton_inter_of_mem h]
@[simp]
theorem card_cons (h : a ∉ s) : #(s.cons a h) = #s + 1 :=
Multiset.card_cons _ _
section InsertErase
variable [DecidableEq α]
@[simp]
theorem card_insert_of_not_mem (h : a ∉ s) : #(insert a s) = #s + 1 := by
rw [← cons_eq_insert _ _ h, card_cons]
theorem card_insert_of_mem (h : a ∈ s) : #(insert a s) = #s := by rw [insert_eq_of_mem h]
theorem card_insert_le (a : α) (s : Finset α) : #(insert a s) ≤ #s + 1 := by
by_cases h : a ∈ s
· rw [insert_eq_of_mem h]
exact Nat.le_succ _
· rw [card_insert_of_not_mem h]
section
variable {a b c d e f : α}
theorem card_le_two : #{a, b} ≤ 2 := card_insert_le _ _
| theorem card_le_three : #{a, b, c} ≤ 3 :=
| Mathlib/Data/Finset/Card.lean | 112 | 112 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Order.Filter.Tendsto
import Mathlib.Data.Set.Accumulate
import Mathlib.Topology.Bornology.Basic
import Mathlib.Topology.ContinuousOn
import Mathlib.Topology.Ultrafilter
import Mathlib.Topology.Defs.Ultrafilter
/-!
# Compact sets and compact spaces
## Main results
* `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets
is compact.
-/
open Set Filter Topology TopologicalSpace Function
universe u v
variable {X : Type u} {Y : Type v} {ι : Type*}
variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} {f : X → Y}
-- compact sets
section Compact
lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) :
∃ x ∈ s, ClusterPt x f := hs hf
lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f]
{u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) :
∃ x ∈ s, MapClusterPt x f u := hs hf
lemma IsCompact.exists_clusterPt_of_frequently {l : Filter X} (hs : IsCompact s)
(hl : ∃ᶠ x in l, x ∈ s) : ∃ a ∈ s, ClusterPt a l :=
let ⟨a, has, ha⟩ := @hs _ (frequently_mem_iff_neBot.mp hl) inf_le_right
⟨a, has, ha.mono inf_le_left⟩
lemma IsCompact.exists_mapClusterPt_of_frequently {l : Filter ι} {f : ι → X} (hs : IsCompact s)
(hf : ∃ᶠ x in l, f x ∈ s) : ∃ a ∈ s, MapClusterPt a l f :=
hs.exists_clusterPt_of_frequently hf
/-- The complement to a compact set belongs to a filter `f` if it belongs to each filter
`𝓝 x ⊓ f`, `x ∈ s`. -/
theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) :
sᶜ ∈ f := by
contrapose! hf
simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢
exact @hs _ hf inf_le_right
/-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t`
within `s` such that `tᶜ` belongs to `f`. -/
theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X}
(hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by
refine hs.compl_mem_sets fun x hx => ?_
rcases hf x hx with ⟨t, ht, hst⟩
replace ht := mem_inf_principal.1 ht
apply mem_inf_of_inter ht hst
rintro x ⟨h₁, h₂⟩ hs
exact h₂ (h₁ hs)
/-- If `p : Set X → Prop` is stable under restriction and union, and each point `x`
of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
@[elab_as_elim]
theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅)
(hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t))
(hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by
let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht)
have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds)
rwa [← compl_compl s]
/-- The intersection of a compact set and a closed set is a compact set. -/
theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by
intro f hnf hstf
obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f :=
hs (le_trans hstf (le_principal_iff.2 inter_subset_left))
have : x ∈ t := ht.mem_of_nhdsWithin_neBot <|
hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right)
exact ⟨x, ⟨hsx, this⟩, hx⟩
/-- The intersection of a closed set and a compact set is a compact set. -/
theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
/-- The set difference of a compact set and an open set is a compact set. -/
theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) :=
hs.inter_right (isClosed_compl_iff.mpr ht)
/-- A closed subset of a compact set is a compact set. -/
theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) :
IsCompact t :=
inter_eq_self_of_subset_right h ▸ hs.inter_right ht
theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) :
IsCompact (f '' s) := by
intro l lne ls
have : NeBot (l.comap f ⊓ 𝓟 s) :=
comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls)
obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this inf_le_right
haveI := hx.neBot
use f x, mem_image_of_mem f hxs
have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by
convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1
rw [nhdsWithin]
ac_rfl
exact this.neBot
theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) :=
hs.image_of_continuousOn hf.continuousOn
theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s)
(ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f :=
Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) =>
let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂
have : x ∈ t := ht₂ x hx hfx.of_inf_left
have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ this)
have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this
have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne
absurd A this
theorem isCompact_iff_ultrafilter_le_nhds :
IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by
refine (forall_neBot_le_iff ?_).trans ?_
· rintro f g hle ⟨x, hxs, hxf⟩
exact ⟨x, hxs, hxf.mono hle⟩
· simp only [Ultrafilter.clusterPt_iff]
alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds
theorem isCompact_iff_ultrafilter_le_nhds' :
IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by
simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe]
alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds'
/-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set,
then the filter is less than or equal to `𝓝 y`. -/
lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X}
(hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by
refine le_iff_ultrafilter.2 fun f hf ↦ ?_
rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩
convert ← hx
exact h x hxs (.mono (.of_le_nhds hx) hf)
/-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l`
and `y` is a unique `MapClusterPt` for `f` along `l` in `s`,
then `f` tends to `𝓝 y` along `l`. -/
lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {Y} {l : Filter Y} {y : X} {f : Y → X}
(hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) :
Tendsto f l (𝓝 y) :=
hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h
/-- For every open directed cover of a compact set, there exists a single element of the
cover which itself includes the set. -/
theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s)
(U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) :
∃ i, s ⊆ U i :=
hι.elim fun i₀ =>
IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩)
(fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ =>
let ⟨k, hki, hkj⟩ := hdU i j
⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩)
fun _x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx)
⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X)
(hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i :=
hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i)
(iUnion_eq_iUnion_finset U ▸ hsU)
(directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h)
lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by
rcases hs.elim_finite_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior)
fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ with ⟨t, hst⟩
refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩
rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩
refine mem_of_superset ?_ (subset_biUnion_of_mem hyt)
exact mem_interior_iff_mem_nhds.1 hy
lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X}
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := by
let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU
classical
exact ⟨t.image (↑), fun x hx =>
let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx
hyx ▸ y.2,
by rwa [Finset.set_biUnion_finset_image]⟩
theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 :=
(hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet
theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x :=
(hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet
theorem IsCompact.elim_nhdsWithin_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X)
(hU : ∀ x (hx : x ∈ s), U x hx ∈ 𝓝[s] x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U x x.2 := by
choose V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx)
refine (hs.elim_nhds_subcover' V V_nhds).imp fun t ht =>
subset_trans ?_ (iUnion₂_mono fun x _ => hV x x.2)
simpa [← iUnion_inter, ← iUnion_coe_set]
theorem IsCompact.elim_nhdsWithin_subcover (hs : IsCompact s) (U : X → Set X)
(hU : ∀ x ∈ s, U x ∈ 𝓝[s] x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by
choose! V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx)
refine (hs.elim_nhds_subcover V V_nhds).imp fun t ⟨t_sub_s, ht⟩ =>
⟨t_sub_s, subset_trans ?_ (iUnion₂_mono fun x hx => hV x (t_sub_s x hx))⟩
simpa [← iUnion_inter]
/-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the
neighborhood filter of each point of this set is disjoint with `l`. -/
theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact s) :
Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by
refine ⟨fun h x hx => h.mono_left <| nhds_le_nhdsSet hx, fun H => ?_⟩
choose! U hxU hUl using fun x hx => (nhds_basis_opens x).disjoint_iff_left.1 (H x hx)
choose hxU hUo using hxU
rcases hs.elim_nhds_subcover U fun x hx => (hUo x hx).mem_nhds (hxU x hx) with ⟨t, hts, hst⟩
refine (hasBasis_nhdsSet _).disjoint_iff_left.2
⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx => hUo x (hts x hx), hst⟩, ?_⟩
rw [compl_iUnion₂, biInter_finset_mem]
exact fun x hx => hUl x (hts x hx)
/-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is
disjoint with the neighborhood filter of each point of this set. -/
theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) :
Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by
simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left
-- TODO: reformulate using `Disjoint`
/-- For every directed family of closed sets whose intersection avoids a compact set,
there exists a single element of the family which itself avoids this compact set. -/
theorem IsCompact.elim_directed_family_closed {ι : Type v} [Nonempty ι] (hs : IsCompact s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅)
(hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ :=
let ⟨t, ht⟩ :=
hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl)
(by
simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop,
mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using hst)
(hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr)
⟨t, by
simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop,
mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using ht⟩
-- TODO: reformulate using `Disjoint`
/-- For every family of closed sets whose intersection avoids a compact set,
there exists a finite subfamily whose intersection avoids this compact set. -/
theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s)
(t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) :
∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ :=
hs.elim_directed_family_closed _ (fun _ ↦ isClosed_biInter fun _ _ ↦ htc _)
(by rwa [← iInter_eq_iInter_finset])
(directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h)
/-- To show that a compact set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every finite subfamily. -/
theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X)
(htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) :
(s ∩ ⋂ i, t i).Nonempty := by
contrapose! hst
exact hs.elim_finite_subfamily_closed t htc hst
/-- Cantor's intersection theorem for `iInter`:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
{ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t)
(htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) :
(⋂ i, t i).Nonempty := by
let i₀ := hι.some
suffices (t i₀ ∩ ⋂ i, t i).Nonempty by
rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this
simp only [nonempty_iff_ne_empty] at htn ⊢
apply mt ((htc i₀).elim_directed_family_closed t htcl)
push_neg
simp only [← nonempty_iff_ne_empty] at htn ⊢
refine ⟨htd, fun i => ?_⟩
rcases htd i₀ i with ⟨j, hji₀, hji⟩
exact (htn j).mono (subset_inter hji₀ hji)
/-- Cantor's intersection theorem for `sInter`:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed
{S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty)
(hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by
rw [sInter_eq_iInter]
exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _
(DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2)
/-- Cantor's intersection theorem for sequences indexed by `ℕ`:
the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/
theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X)
(htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0))
(htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty :=
have tmono : Antitone t := antitone_nat_of_succ_le htd
have htd : Directed (· ⊇ ·) t := tmono.directed_ge
have : ∀ i, t i ⊆ t 0 := fun i => tmono <| Nat.zero_le i
have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i)
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s)
(hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) :
∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by
simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂
rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩
refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩
· simp
· rwa [biUnion_image]
/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/
theorem isCompact_of_finite_subcover
(h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) →
∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) :
IsCompact s := fun f hf hfs => by
contrapose! h
simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall',
(nhds_basis_opens _).disjoint_iff_left] at h
choose U hU hUf using h
refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩
refine compl_not_mem (le_principal_iff.1 hfs) ?_
refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_
rw [subset_compl_comm, compl_iInter₂]
simpa only [compl_compl]
-- TODO: reformulate using `Disjoint`
/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem isCompact_of_finite_subfamily_closed
(h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ →
∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) :
IsCompact s :=
isCompact_of_finite_subcover fun U hUo hsU => by
rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU
rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩
refine ⟨t, ?_⟩
rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff]
/-- A set `s` is compact if and only if
for every open cover of `s`, there exists a finite subcover. -/
theorem isCompact_iff_finite_subcover :
IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X),
(∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i :=
⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩
/-- A set `s` is compact if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem isCompact_iff_finite_subfamily_closed :
IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X),
(∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ :=
⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩
/-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`,
then it belongs to `(𝓝ˢ K) ×ˢ l`,
i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/
theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {Y} {l : Filter Y} {s : Set (X × Y)}
(hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by
refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_
· exact prod_mono (nhdsSet_mono ht) le_rfl hs
· simp [sup_prod, *]
· rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx)
with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩
refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩
exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv
theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) {Y} (l : Filter Y) :
(𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l :=
le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs)
(iSup₂_le fun _ hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl)
theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) {X} (l : Filter X) :
l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by
simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup]
/-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`,
then it belongs to `l ×ˢ (𝓝ˢ K)`,
i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/
theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {X} {l : Filter X} {s : Set (X × Y)}
(hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K :=
(hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs
-- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ?
-- That would seem a bit more natural.
theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) :
(𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by
have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by
simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm
simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup]
theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) :
l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by
simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup]
/-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`,
then it belongs to `(𝓝ˢ K) ⊓ l`,
i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/
theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X}
(hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l :=
(hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs
/-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`,
then it belongs to `l ⊓ (𝓝ˢ K)`,
i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/
theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X}
(hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K :=
(hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs
/-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact,
it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough
to `(x₀, y₀)`.
Provided for backwards compatibility,
see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement.
-/
theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K)
{P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) :
∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by
simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP
exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet
theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf =>
Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf
theorem isCompact_singleton {x : X} : IsCompact ({x} : Set X) := fun _ hf hfa =>
⟨x, rfl, ClusterPt.of_le_nhds'
(hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩
theorem Set.Subsingleton.isCompact (hs : s.Subsingleton) : IsCompact s :=
Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton
theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite)
(hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) :=
isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by
rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl
rcases hl with ⟨i, his, hi⟩
rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩
exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩
theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) :
IsCompact (⋃ i ∈ s, f i) :=
s.finite_toSet.isCompact_biUnion hf
theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) :
IsCompact (Accumulate K n) :=
(finite_le_nat n).isCompact_biUnion fun k _ => hK k
theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) :
IsCompact (⋃₀ S) := by
rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc
theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) :
IsCompact (⋃ i, f i) :=
(finite_range f).isCompact_sUnion <| forall_mem_range.2 h
@[simp] theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s :=
biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton
theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := by
have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete]
rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, _, hst⟩
simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst
exact t.finite_toSet.subset hst
theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite :=
⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩
theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by
rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption
protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) :=
isCompact_singleton.union hs
-- TODO: reformulate using `𝓝ˢ`
/-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of
`⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is
not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/
theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X}
(hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i))
{U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by
obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU
suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU
by_contra! H
replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i)
have : (⋂ i, V i ∩ Wᶜ).Nonempty := by
refine
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H
(fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i =>
(hV_closed i).inter W_op.isClosed_compl
rcases hV i j with ⟨k, hki, hkj⟩
refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;>
tauto
have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff]
contradiction
namespace Filter
theorem hasBasis_cocompact : (cocompact X).HasBasis IsCompact compl :=
hasBasis_biInf_principal'
(fun s hs t ht =>
⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩)
⟨∅, isCompact_empty⟩
theorem mem_cocompact : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ tᶜ ⊆ s :=
hasBasis_cocompact.mem_iff
theorem mem_cocompact' : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ sᶜ ⊆ t :=
mem_cocompact.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm
theorem _root_.IsCompact.compl_mem_cocompact (hs : IsCompact s) : sᶜ ∈ Filter.cocompact X :=
hasBasis_cocompact.mem_of_mem hs
theorem cocompact_le_cofinite : cocompact X ≤ cofinite := fun s hs =>
compl_compl s ▸ hs.isCompact.compl_mem_cocompact
theorem cocompact_eq_cofinite (X : Type*) [TopologicalSpace X] [DiscreteTopology X] :
cocompact X = cofinite := by
simp only [cocompact, hasBasis_cofinite.eq_biInf, isCompact_iff_finite]
/-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/
theorem disjoint_cocompact_left (f : Filter X) :
Disjoint (Filter.cocompact X) f ↔ ∃ K ∈ f, IsCompact K := by
simp_rw [hasBasis_cocompact.disjoint_iff_left, compl_compl]
tauto
/-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/
theorem disjoint_cocompact_right (f : Filter X) :
Disjoint f (Filter.cocompact X) ↔ ∃ K ∈ f, IsCompact K := by
simp_rw [hasBasis_cocompact.disjoint_iff_right, compl_compl]
tauto
theorem Tendsto.isCompact_insert_range_of_cocompact {f : X → Y} {y}
(hf : Tendsto f (cocompact X) (𝓝 y)) (hfc : Continuous f) : IsCompact (insert y (range f)) := by
intro l hne hle
by_cases hy : ClusterPt y l
· exact ⟨y, Or.inl rfl, hy⟩
simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy
rcases hy with ⟨s, hsy, t, htl, hd⟩
rcases mem_cocompact.1 (hf hsy) with ⟨K, hKc, hKs⟩
have : f '' K ∈ l := by
filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf
rcases hyf with (rfl | ⟨x, rfl⟩)
exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim,
mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)]
rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩
exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩
theorem Tendsto.isCompact_insert_range_of_cofinite {f : ι → X} {x} (hf : Tendsto f cofinite (𝓝 x)) :
IsCompact (insert x (range f)) := by
letI : TopologicalSpace ι := ⊥; haveI h : DiscreteTopology ι := ⟨rfl⟩
rw [← cocompact_eq_cofinite ι] at hf
exact hf.isCompact_insert_range_of_cocompact continuous_of_discreteTopology
theorem Tendsto.isCompact_insert_range {f : ℕ → X} {x} (hf : Tendsto f atTop (𝓝 x)) :
IsCompact (insert x (range f)) :=
Filter.Tendsto.isCompact_insert_range_of_cofinite <| Nat.cofinite_eq_atTop.symm ▸ hf
theorem hasBasis_coclosedCompact :
(Filter.coclosedCompact X).HasBasis (fun s => IsClosed s ∧ IsCompact s) compl := by
simp only [Filter.coclosedCompact, iInf_and']
refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isCompact_empty⟩
rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩
exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left,
compl_subset_compl.2 subset_union_right⟩⟩
/-- A set belongs to `coclosedCompact` if and only if the closure of its complement is compact. -/
theorem mem_coclosedCompact_iff :
s ∈ coclosedCompact X ↔ IsCompact (closure sᶜ) := by
refine hasBasis_coclosedCompact.mem_iff.trans ⟨?_, fun h ↦ ?_⟩
· rintro ⟨t, ⟨htcl, htco⟩, hst⟩
exact htco.of_isClosed_subset isClosed_closure <|
closure_minimal (compl_subset_comm.2 hst) htcl
· exact ⟨closure sᶜ, ⟨isClosed_closure, h⟩, compl_subset_comm.2 subset_closure⟩
/-- Complement of a set belongs to `coclosedCompact` if and only if its closure is compact. -/
theorem compl_mem_coclosedCompact : sᶜ ∈ coclosedCompact X ↔ IsCompact (closure s) := by
rw [mem_coclosedCompact_iff, compl_compl]
theorem cocompact_le_coclosedCompact : cocompact X ≤ coclosedCompact X :=
iInf_mono fun _ => le_iInf fun _ => le_rfl
end Filter
theorem IsCompact.compl_mem_coclosedCompact_of_isClosed (hs : IsCompact s) (hs' : IsClosed s) :
sᶜ ∈ Filter.coclosedCompact X :=
hasBasis_coclosedCompact.mem_of_mem ⟨hs', hs⟩
namespace Bornology
variable (X) in
/-- Sets that are contained in a compact set form a bornology. Its `cobounded` filter is
`Filter.cocompact`. See also `Bornology.relativelyCompact` the bornology of sets with compact
closure. -/
def inCompact : Bornology X where
cobounded' := Filter.cocompact X
le_cofinite' := Filter.cocompact_le_cofinite
theorem inCompact.isBounded_iff : @IsBounded _ (inCompact X) s ↔ ∃ t, IsCompact t ∧ s ⊆ t := by
change sᶜ ∈ Filter.cocompact X ↔ _
rw [Filter.mem_cocompact]
simp
end Bornology
/-- If `s` and `t` are compact sets, then the set neighborhoods filter of `s ×ˢ t`
is the product of set neighborhoods filters for `s` and `t`.
For general sets, only the `≤` inequality holds, see `nhdsSet_prod_le`. -/
theorem IsCompact.nhdsSet_prod_eq {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) :
𝓝ˢ (s ×ˢ t) = 𝓝ˢ s ×ˢ 𝓝ˢ t := by
simp_rw [hs.nhdsSet_prod_eq_biSup, ht.prod_nhdsSet_eq_biSup, nhdsSet, sSup_image, biSup_prod,
nhds_prod_eq]
theorem nhdsSet_prod_le_of_disjoint_cocompact {f : Filter Y} (hs : IsCompact s)
(hf : Disjoint f (Filter.cocompact Y)) :
𝓝ˢ s ×ˢ f ≤ 𝓝ˢ (s ×ˢ Set.univ) := by
obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf
calc
𝓝ˢ s ×ˢ f
_ ≤ 𝓝ˢ s ×ˢ 𝓟 K := Filter.prod_mono_right _ (Filter.le_principal_iff.mpr hKf)
_ ≤ 𝓝ˢ s ×ˢ 𝓝ˢ K := Filter.prod_mono_right _ principal_le_nhdsSet
_ = 𝓝ˢ (s ×ˢ K) := (hs.nhdsSet_prod_eq hK).symm
_ ≤ 𝓝ˢ (s ×ˢ Set.univ) := nhdsSet_mono (prod_mono_right le_top)
theorem prod_nhdsSet_le_of_disjoint_cocompact {t : Set Y} {f : Filter X} (ht : IsCompact t)
(hf : Disjoint f (Filter.cocompact X)) :
f ×ˢ 𝓝ˢ t ≤ 𝓝ˢ (Set.univ ×ˢ t) := by
obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf
calc
f ×ˢ 𝓝ˢ t
_ ≤ (𝓟 K) ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ (Filter.le_principal_iff.mpr hKf)
_ ≤ 𝓝ˢ K ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ principal_le_nhdsSet
_ = 𝓝ˢ (K ×ˢ t) := (hK.nhdsSet_prod_eq ht).symm
_ ≤ 𝓝ˢ (Set.univ ×ˢ t) := nhdsSet_mono (prod_mono_left le_top)
theorem nhds_prod_le_of_disjoint_cocompact {f : Filter Y} (x : X)
(hf : Disjoint f (Filter.cocompact Y)) :
𝓝 x ×ˢ f ≤ 𝓝ˢ ({x} ×ˢ Set.univ) := by
simpa using nhdsSet_prod_le_of_disjoint_cocompact isCompact_singleton hf
theorem prod_nhds_le_of_disjoint_cocompact {f : Filter X} (y : Y)
(hf : Disjoint f (Filter.cocompact X)) :
f ×ˢ 𝓝 y ≤ 𝓝ˢ (Set.univ ×ˢ {y}) := by
simpa using prod_nhdsSet_le_of_disjoint_cocompact isCompact_singleton hf
/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist
open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`.
See also `IsCompact.nhdsSet_prod_eq`. -/
theorem generalized_tube_lemma (hs : IsCompact s) {t : Set Y} (ht : IsCompact t)
{n : Set (X × Y)} (hn : IsOpen n) (hp : s ×ˢ t ⊆ n) :
∃ (u : Set X) (v : Set Y), IsOpen u ∧ IsOpen v ∧ s ⊆ u ∧ t ⊆ v ∧ u ×ˢ v ⊆ n := by
rw [← hn.mem_nhdsSet, hs.nhdsSet_prod_eq ht,
((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).mem_iff] at hp
rcases hp with ⟨⟨u, v⟩, ⟨⟨huo, hsu⟩, hvo, htv⟩, hn⟩
exact ⟨u, v, huo, hvo, hsu, htv, hn⟩
-- see Note [lower instance priority]
instance (priority := 10) Subsingleton.compactSpace [Subsingleton X] : CompactSpace X :=
⟨subsingleton_univ.isCompact⟩
theorem isCompact_univ_iff : IsCompact (univ : Set X) ↔ CompactSpace X :=
⟨fun h => ⟨h⟩, fun h => h.1⟩
theorem isCompact_univ [h : CompactSpace X] : IsCompact (univ : Set X) :=
h.isCompact_univ
theorem exists_clusterPt_of_compactSpace [CompactSpace X] (f : Filter X) [NeBot f] :
∃ x, ClusterPt x f := by
simpa using isCompact_univ (show f ≤ 𝓟 univ by simp)
nonrec theorem Ultrafilter.le_nhds_lim [CompactSpace X] (F : Ultrafilter X) : ↑F ≤ 𝓝 F.lim := by
rcases isCompact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩
exact le_nhds_lim ⟨x, h⟩
theorem CompactSpace.elim_nhds_subcover [CompactSpace X] (U : X → Set X) (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Finset X, ⋃ x ∈ t, U x = ⊤ := by
obtain ⟨t, -, s⟩ := IsCompact.elim_nhds_subcover isCompact_univ U fun x _ => hU x
exact ⟨t, top_unique s⟩
theorem compactSpace_of_finite_subfamily_closed
(h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → ⋂ i, t i = ∅ →
∃ u : Finset ι, ⋂ i ∈ u, t i = ∅) :
CompactSpace X where
isCompact_univ := isCompact_of_finite_subfamily_closed fun t => by simpa using h t
theorem IsClosed.isCompact [CompactSpace X] (h : IsClosed s) : IsCompact s :=
isCompact_univ.of_isClosed_subset h (subset_univ _)
/-- If a filter has a unique cluster point `y` in a compact topological space,
then the filter is less than or equal to `𝓝 y`. -/
lemma le_nhds_of_unique_clusterPt [CompactSpace X] {l : Filter X} {y : X}
(h : ∀ x, ClusterPt x l → x = y) : l ≤ 𝓝 y :=
isCompact_univ.le_nhds_of_unique_clusterPt univ_mem fun x _ ↦ h x
/-- If `y` is a unique `MapClusterPt` for `f` along `l`
and the codomain of `f` is a compact space,
then `f` tends to `𝓝 y` along `l`. -/
lemma tendsto_nhds_of_unique_mapClusterPt [CompactSpace X] {Y} {l : Filter Y} {y : X} {f : Y → X}
(h : ∀ x, MapClusterPt x l f → x = y) :
Tendsto f l (𝓝 y) :=
le_nhds_of_unique_clusterPt h
lemma noncompact_univ (X : Type*) [TopologicalSpace X] [NoncompactSpace X] :
¬IsCompact (univ : Set X) :=
NoncompactSpace.noncompact_univ
theorem IsCompact.ne_univ [NoncompactSpace X] (hs : IsCompact s) : s ≠ univ := fun h =>
noncompact_univ X (h ▸ hs)
instance [NoncompactSpace X] : NeBot (Filter.cocompact X) := by
refine Filter.hasBasis_cocompact.neBot_iff.2 fun hs => ?_
contrapose hs; rw [not_nonempty_iff_eq_empty, compl_empty_iff] at hs
rw [hs]; exact noncompact_univ X
@[simp]
theorem Filter.cocompact_eq_bot [CompactSpace X] : Filter.cocompact X = ⊥ :=
Filter.hasBasis_cocompact.eq_bot_iff.mpr ⟨Set.univ, isCompact_univ, Set.compl_univ⟩
instance [NoncompactSpace X] : NeBot (Filter.coclosedCompact X) :=
neBot_of_le Filter.cocompact_le_coclosedCompact
theorem noncompactSpace_of_neBot (_ : NeBot (Filter.cocompact X)) : NoncompactSpace X :=
⟨fun h' => (Filter.nonempty_of_mem h'.compl_mem_cocompact).ne_empty compl_univ⟩
theorem Filter.cocompact_neBot_iff : NeBot (Filter.cocompact X) ↔ NoncompactSpace X :=
⟨noncompactSpace_of_neBot, fun _ => inferInstance⟩
theorem not_compactSpace_iff : ¬CompactSpace X ↔ NoncompactSpace X :=
⟨fun h₁ => ⟨fun h₂ => h₁ ⟨h₂⟩⟩, fun ⟨h₁⟩ ⟨h₂⟩ => h₁ h₂⟩
instance : NoncompactSpace ℤ :=
noncompactSpace_of_neBot <| by simp only [Filter.cocompact_eq_cofinite, Filter.cofinite_neBot]
-- Note: We can't make this into an instance because it loops with `Finite.compactSpace`.
/-- A compact discrete space is finite. -/
theorem finite_of_compact_of_discrete [CompactSpace X] [DiscreteTopology X] : Finite X :=
Finite.of_finite_univ <| isCompact_univ.finite_of_discrete
lemma Set.Infinite.exists_accPt_cofinite_inf_principal_of_subset_isCompact
{K : Set X} (hs : s.Infinite) (hK : IsCompact K) (hsub : s ⊆ K) :
∃ x ∈ K, AccPt x (cofinite ⊓ 𝓟 s) :=
(@hK _ hs.cofinite_inf_principal_neBot (inf_le_right.trans <| principal_mono.2 hsub)).imp
fun x hx ↦ by rwa [accPt_iff_clusterPt, inf_comm, inf_right_comm,
(finite_singleton _).cofinite_inf_principal_compl]
lemma Set.Infinite.exists_accPt_of_subset_isCompact {K : Set X} (hs : s.Infinite)
(hK : IsCompact K) (hsub : s ⊆ K) : ∃ x ∈ K, AccPt x (𝓟 s) :=
let ⟨x, hxK, hx⟩ := hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact hK hsub
⟨x, hxK, hx.mono inf_le_right⟩
lemma Set.Infinite.exists_accPt_cofinite_inf_principal [CompactSpace X] (hs : s.Infinite) :
∃ x, AccPt x (cofinite ⊓ 𝓟 s) := by
simpa only [mem_univ, true_and]
using hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact isCompact_univ s.subset_univ
lemma Set.Infinite.exists_accPt_principal [CompactSpace X] (hs : s.Infinite) : ∃ x, AccPt x (𝓟 s) :=
hs.exists_accPt_cofinite_inf_principal.imp fun _x hx ↦ hx.mono inf_le_right
theorem exists_nhds_ne_neBot (X : Type*) [TopologicalSpace X] [CompactSpace X] [Infinite X] :
∃ z : X, (𝓝[≠] z).NeBot := by
simpa [AccPt] using (@infinite_univ X _).exists_accPt_principal
theorem finite_cover_nhds_interior [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Finset X, ⋃ x ∈ t, interior (U x) = univ :=
let ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover (fun x => interior (U x))
(fun _ => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩
⟨t, univ_subset_iff.1 ht⟩
theorem finite_cover_nhds [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) :
∃ t : Finset X, ⋃ x ∈ t, U x = univ :=
let ⟨t, ht⟩ := finite_cover_nhds_interior hU
⟨t, univ_subset_iff.1 <| ht.symm.subset.trans <| iUnion₂_mono fun _ _ => interior_subset⟩
/-- The comap of the cocompact filter on `Y` by a continuous function `f : X → Y` is less than or
equal to the cocompact filter on `X`.
This is a reformulation of the fact that images of compact sets are compact. -/
theorem Filter.comap_cocompact_le {f : X → Y} (hf : Continuous f) :
(Filter.cocompact Y).comap f ≤ Filter.cocompact X := by
rw [(Filter.hasBasis_cocompact.comap f).le_basis_iff Filter.hasBasis_cocompact]
intro t ht
refine ⟨f '' t, ht.image hf, ?_⟩
simpa using t.subset_preimage_image f
/-- If a filter is disjoint from the cocompact filter, so is its image under any continuous
function. -/
theorem disjoint_map_cocompact {g : X → Y} {f : Filter X} (hg : Continuous g)
(hf : Disjoint f (Filter.cocompact X)) : Disjoint (map g f) (Filter.cocompact Y) := by
rw [← Filter.disjoint_comap_iff_map, disjoint_iff_inf_le]
calc
f ⊓ (comap g (cocompact Y))
_ ≤ f ⊓ Filter.cocompact X := inf_le_inf_left f (Filter.comap_cocompact_le hg)
_ = ⊥ := disjoint_iff.mp hf
theorem isCompact_range [CompactSpace X] {f : X → Y} (hf : Continuous f) : IsCompact (range f) := by
rw [← image_univ]; exact isCompact_univ.image hf
theorem isCompact_diagonal [CompactSpace X] : IsCompact (diagonal X) :=
@range_diag X ▸ isCompact_range (continuous_id.prodMk continuous_id)
/-- If `X` is a compact topological space, then `Prod.snd : X × Y → Y` is a closed map. -/
theorem isClosedMap_snd_of_compactSpace [CompactSpace X] :
IsClosedMap (Prod.snd : X × Y → Y) := fun s hs => by
rw [← isOpen_compl_iff, isOpen_iff_mem_nhds]
intro y hy
have : univ ×ˢ {y} ⊆ sᶜ := by
exact fun (x, y') ⟨_, rfl⟩ hs => hy ⟨(x, y'), hs, rfl⟩
rcases generalized_tube_lemma isCompact_univ isCompact_singleton hs.isOpen_compl this
with ⟨U, V, -, hVo, hU, hV, hs⟩
refine mem_nhds_iff.2 ⟨V, ?_, hVo, hV rfl⟩
rintro _ hzV ⟨z, hzs, rfl⟩
exact hs ⟨hU trivial, hzV⟩ hzs
/-- If `Y` is a compact topological space, then `Prod.fst : X × Y → X` is a closed map. -/
theorem isClosedMap_fst_of_compactSpace [CompactSpace Y] : IsClosedMap (Prod.fst : X × Y → X) :=
isClosedMap_snd_of_compactSpace.comp isClosedMap_swap
theorem exists_subset_nhds_of_compactSpace [CompactSpace X] [Nonempty ι]
{V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X}
(hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U :=
exists_subset_nhds_of_isCompact' hV (fun i => (hV_closed i).isCompact) hV_closed hU
/-- If `f : X → Y` is an inducing map, the image `f '' s` of a set `s` is compact
if and only if `s` is compact. -/
theorem Topology.IsInducing.isCompact_iff {f : X → Y} (hf : IsInducing f) :
IsCompact s ↔ IsCompact (f '' s) := by
refine ⟨fun hs => hs.image hf.continuous, fun hs F F_ne_bot F_le => ?_⟩
obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : ClusterPt (f x) (map f F)⟩ :=
hs ((map_mono F_le).trans_eq map_principal)
exact ⟨x, x_in, hf.mapClusterPt_iff.1 hx⟩
@[deprecated (since := "2024-10-28")] alias Inducing.isCompact_iff := IsInducing.isCompact_iff
/-- If `f : X → Y` is an embedding, the image `f '' s` of a set `s` is compact
if and only if `s` is compact. -/
theorem Topology.IsEmbedding.isCompact_iff {f : X → Y} (hf : IsEmbedding f) :
IsCompact s ↔ IsCompact (f '' s) := hf.isInducing.isCompact_iff
@[deprecated (since := "2024-10-26")]
alias Embedding.isCompact_iff := IsEmbedding.isCompact_iff
/-- The preimage of a compact set under an inducing map is a compact set. -/
theorem Topology.IsInducing.isCompact_preimage (hf : IsInducing f) (hf' : IsClosed (range f))
{K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) := by
replace hK := hK.inter_right hf'
rwa [hf.isCompact_iff, image_preimage_eq_inter_range]
@[deprecated (since := "2024-10-28")]
alias Inducing.isCompact_preimage := IsInducing.isCompact_preimage
lemma Topology.IsInducing.isCompact_preimage_iff {f : X → Y} (hf : IsInducing f) {K : Set Y}
(Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) ↔ IsCompact K := by
rw [hf.isCompact_iff, image_preimage_eq_of_subset Kf]
@[deprecated (since := "2024-10-28")]
alias Inducing.isCompact_preimage_iff := IsInducing.isCompact_preimage_iff
/-- The preimage of a compact set in the image of an inducing map is compact. -/
lemma Topology.IsInducing.isCompact_preimage' (hf : IsInducing f) {K : Set Y}
(hK : IsCompact K) (Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) :=
(hf.isCompact_preimage_iff Kf).2 hK
@[deprecated (since := "2024-10-28")]
alias Inducing.isCompact_preimage' := IsInducing.isCompact_preimage'
/-- The preimage of a compact set under a closed embedding is a compact set. -/
theorem Topology.IsClosedEmbedding.isCompact_preimage (hf : IsClosedEmbedding f)
{K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) :=
hf.isInducing.isCompact_preimage (hf.isClosed_range) hK
/-- A closed embedding is proper, ie, inverse images of compact sets are contained in compacts.
Moreover, the preimage of a compact set is compact, see `IsClosedEmbedding.isCompact_preimage`. -/
theorem Topology.IsClosedEmbedding.tendsto_cocompact (hf : IsClosedEmbedding f) :
Tendsto f (Filter.cocompact X) (Filter.cocompact Y) :=
Filter.hasBasis_cocompact.tendsto_right_iff.mpr fun _K hK =>
(hf.isCompact_preimage hK).compl_mem_cocompact
/-- Sets of subtype are compact iff the image under a coercion is. -/
theorem Subtype.isCompact_iff {p : X → Prop} {s : Set { x // p x }} :
IsCompact s ↔ IsCompact ((↑) '' s : Set X) :=
IsEmbedding.subtypeVal.isCompact_iff
theorem isCompact_iff_isCompact_univ : IsCompact s ↔ IsCompact (univ : Set s) := by
rw [Subtype.isCompact_iff, image_univ, Subtype.range_coe]
theorem isCompact_iff_compactSpace : IsCompact s ↔ CompactSpace s :=
isCompact_iff_isCompact_univ.trans isCompact_univ_iff
theorem IsCompact.finite (hs : IsCompact s) (hs' : DiscreteTopology s) : s.Finite :=
finite_coe_iff.mp (@finite_of_compact_of_discrete _ _ (isCompact_iff_compactSpace.mp hs) hs')
theorem exists_nhds_ne_inf_principal_neBot (hs : IsCompact s) (hs' : s.Infinite) :
∃ z ∈ s, (𝓝[≠] z ⊓ 𝓟 s).NeBot :=
hs'.exists_accPt_of_subset_isCompact hs Subset.rfl
protected theorem Topology.IsClosedEmbedding.noncompactSpace [NoncompactSpace X] {f : X → Y}
(hf : IsClosedEmbedding f) : NoncompactSpace Y :=
noncompactSpace_of_neBot hf.tendsto_cocompact.neBot
protected theorem Topology.IsClosedEmbedding.compactSpace [h : CompactSpace Y] {f : X → Y}
(hf : IsClosedEmbedding f) : CompactSpace X :=
⟨by rw [hf.isInducing.isCompact_iff, image_univ]; exact hf.isClosed_range.isCompact⟩
theorem IsCompact.prod {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) :
IsCompact (s ×ˢ t) := by
rw [isCompact_iff_ultrafilter_le_nhds'] at hs ht ⊢
intro f hfs
obtain ⟨x : X, sx : x ∈ s, hx : map Prod.fst f.1 ≤ 𝓝 x⟩ :=
hs (f.map Prod.fst) (mem_map.2 <| mem_of_superset hfs fun x => And.left)
obtain ⟨y : Y, ty : y ∈ t, hy : map Prod.snd f.1 ≤ 𝓝 y⟩ :=
ht (f.map Prod.snd) (mem_map.2 <| mem_of_superset hfs fun x => And.right)
rw [map_le_iff_le_comap] at hx hy
refine ⟨⟨x, y⟩, ⟨sx, ty⟩, ?_⟩
rw [nhds_prod_eq]; exact le_inf hx hy
/-- Finite topological spaces are compact. -/
instance (priority := 100) Finite.compactSpace [Finite X] : CompactSpace X where
isCompact_univ := finite_univ.isCompact
instance ULift.compactSpace [CompactSpace X] : CompactSpace (ULift.{v} X) :=
IsClosedEmbedding.uliftDown.compactSpace
/-- The product of two compact spaces is compact. -/
instance [CompactSpace X] [CompactSpace Y] : CompactSpace (X × Y) :=
⟨by rw [← univ_prod_univ]; exact isCompact_univ.prod isCompact_univ⟩
/-- The disjoint union of two compact spaces is compact. -/
instance [CompactSpace X] [CompactSpace Y] : CompactSpace (X ⊕ Y) :=
⟨by
rw [← range_inl_union_range_inr]
exact (isCompact_range continuous_inl).union (isCompact_range continuous_inr)⟩
instance {X : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (X i)] [∀ i, CompactSpace (X i)] :
CompactSpace (Σi, X i) := by
refine ⟨?_⟩
rw [Sigma.univ]
exact isCompact_iUnion fun i => isCompact_range continuous_sigmaMk
/-- The coproduct of the cocompact filters on two topological spaces is the cocompact filter on
their product. -/
theorem Filter.coprod_cocompact :
(Filter.cocompact X).coprod (Filter.cocompact Y) = Filter.cocompact (X × Y) := by
apply le_antisymm
· exact sup_le (comap_cocompact_le continuous_fst) (comap_cocompact_le continuous_snd)
· refine (hasBasis_cocompact.coprod hasBasis_cocompact).ge_iff.2 fun K hK ↦ ?_
rw [← univ_prod, ← prod_univ, ← compl_prod_eq_union]
exact (hK.1.prod hK.2).compl_mem_cocompact
theorem Prod.noncompactSpace_iff :
NoncompactSpace (X × Y) ↔ NoncompactSpace X ∧ Nonempty Y ∨ Nonempty X ∧ NoncompactSpace Y := by
simp [← Filter.cocompact_neBot_iff, ← Filter.coprod_cocompact, Filter.coprod_neBot_iff]
-- See Note [lower instance priority]
instance (priority := 100) Prod.noncompactSpace_left [NoncompactSpace X] [Nonempty Y] :
NoncompactSpace (X × Y) :=
Prod.noncompactSpace_iff.2 (Or.inl ⟨‹_›, ‹_›⟩)
-- See Note [lower instance priority]
instance (priority := 100) Prod.noncompactSpace_right [Nonempty X] [NoncompactSpace Y] :
NoncompactSpace (X × Y) :=
Prod.noncompactSpace_iff.2 (Or.inr ⟨‹_›, ‹_›⟩)
section Tychonoff
variable {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
/-- **Tychonoff's theorem**: product of compact sets is compact. -/
theorem isCompact_pi_infinite {s : ∀ i, Set (X i)} :
(∀ i, IsCompact (s i)) → IsCompact { x : ∀ i, X i | ∀ i, x i ∈ s i } := by
simp only [isCompact_iff_ultrafilter_le_nhds, nhds_pi, le_pi, le_principal_iff]
intro h f hfs
have : ∀ i : ι, ∃ x, x ∈ s i ∧ Tendsto (Function.eval i) f (𝓝 x) := by
refine fun i => h i (f.map _) (mem_map.2 ?_)
exact mem_of_superset hfs fun x hx => hx i
choose x hx using this
exact ⟨x, fun i => (hx i).left, fun i => (hx i).right⟩
/-- **Tychonoff's theorem** formulated using `Set.pi`: product of compact sets is compact. -/
theorem isCompact_univ_pi {s : ∀ i, Set (X i)} (h : ∀ i, IsCompact (s i)) :
IsCompact (pi univ s) := by
convert isCompact_pi_infinite h
simp only [← mem_univ_pi, setOf_mem_eq]
instance Pi.compactSpace [∀ i, CompactSpace (X i)] : CompactSpace (∀ i, X i) :=
⟨by rw [← pi_univ univ]; exact isCompact_univ_pi fun i => isCompact_univ⟩
instance Function.compactSpace [CompactSpace Y] : CompactSpace (ι → Y) :=
Pi.compactSpace
lemma Pi.isCompact_iff_of_isClosed {s : Set (Π i, X i)} (hs : IsClosed s) :
IsCompact s ↔ ∀ i, IsCompact (eval i '' s) := by
constructor <;> intro H
· exact fun i ↦ H.image <| continuous_apply i
· exact IsCompact.of_isClosed_subset (isCompact_univ_pi H) hs (subset_pi_eval_image univ s)
protected lemma Pi.exists_compact_superset_iff {s : Set (Π i, X i)} :
(∃ K, IsCompact K ∧ s ⊆ K) ↔ ∀ i, ∃ Ki, IsCompact Ki ∧ s ⊆ eval i ⁻¹' Ki := by
constructor
· intro ⟨K, hK, hsK⟩ i
exact ⟨eval i '' K, hK.image <| continuous_apply i, hsK.trans <| K.subset_preimage_image _⟩
· intro H
choose K hK hsK using H
exact ⟨pi univ K, isCompact_univ_pi hK, fun _ hx i _ ↦ hsK i hx⟩
/-- **Tychonoff's theorem** formulated in terms of filters: `Filter.cocompact` on an indexed product
type `Π d, X d` the `Filter.coprodᵢ` of filters `Filter.cocompact` on `X d`. -/
theorem Filter.coprodᵢ_cocompact {X : ι → Type*} [∀ d, TopologicalSpace (X d)] :
(Filter.coprodᵢ fun d => Filter.cocompact (X d)) = Filter.cocompact (∀ d, X d) := by
refine le_antisymm (iSup_le fun i => Filter.comap_cocompact_le (continuous_apply i)) ?_
refine compl_surjective.forall.2 fun s H => ?_
simp only [compl_mem_coprodᵢ, Filter.mem_cocompact, compl_subset_compl, image_subset_iff] at H ⊢
choose K hKc htK using H
exact ⟨Set.pi univ K, isCompact_univ_pi hKc, fun f hf i _ => htK i hf⟩
end Tychonoff
instance Quot.compactSpace {r : X → X → Prop} [CompactSpace X] : CompactSpace (Quot r) :=
⟨by
rw [← range_quot_mk]
exact isCompact_range continuous_quot_mk⟩
instance Quotient.compactSpace {s : Setoid X} [CompactSpace X] : CompactSpace (Quotient s) :=
Quot.compactSpace
theorem IsClosed.exists_minimal_nonempty_closed_subset [CompactSpace X] {S : Set X}
(hS : IsClosed S) (hne : S.Nonempty) :
∃ V : Set X, V ⊆ S ∧ V.Nonempty ∧ IsClosed V ∧
∀ V' : Set X, V' ⊆ V → V'.Nonempty → IsClosed V' → V' = V := by
let opens := { U : Set X | Sᶜ ⊆ U ∧ IsOpen U ∧ Uᶜ.Nonempty }
obtain ⟨U, h⟩ :=
zorn_subset opens fun c hc hz => by
by_cases hcne : c.Nonempty
· obtain ⟨U₀, hU₀⟩ := hcne
haveI : Nonempty { U // U ∈ c } := ⟨⟨U₀, hU₀⟩⟩
obtain ⟨U₀compl, -, -⟩ := hc hU₀
use ⋃₀ c
refine ⟨⟨?_, ?_, ?_⟩, fun U hU _ hx => ⟨U, hU, hx⟩⟩
· exact fun _ hx => ⟨U₀, hU₀, U₀compl hx⟩
· exact isOpen_sUnion fun _ h => (hc h).2.1
· convert_to (⋂ U : { U // U ∈ c }, U.1ᶜ).Nonempty
· ext
simp only [not_exists, exists_prop, not_and, Set.mem_iInter, Subtype.forall,
mem_setOf_eq, mem_compl_iff, mem_sUnion]
apply IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
· rintro ⟨U, hU⟩ ⟨U', hU'⟩
obtain ⟨V, hVc, hVU, hVU'⟩ := hz.directedOn U hU U' hU'
exact ⟨⟨V, hVc⟩, Set.compl_subset_compl.mpr hVU, Set.compl_subset_compl.mpr hVU'⟩
· exact fun U => (hc U.2).2.2
· exact fun U => (hc U.2).2.1.isClosed_compl.isCompact
· exact fun U => (hc U.2).2.1.isClosed_compl
· use Sᶜ
refine ⟨⟨Set.Subset.refl _, isOpen_compl_iff.mpr hS, ?_⟩, fun U Uc => (hcne ⟨U, Uc⟩).elim⟩
rw [compl_compl]
exact hne
obtain ⟨Uc, Uo, Ucne⟩ := h.prop
refine ⟨Uᶜ, Set.compl_subset_comm.mp Uc, Ucne, Uo.isClosed_compl, ?_⟩
intro V' V'sub V'ne V'cls
have : V'ᶜ = U := by
refine h.eq_of_ge ⟨?_, isOpen_compl_iff.mpr V'cls, ?_⟩ (subset_compl_comm.2 V'sub)
· exact Set.Subset.trans Uc (Set.subset_compl_comm.mp V'sub)
· simp only [compl_compl, V'ne]
rw [← this, compl_compl]
end Compact
| Mathlib/Topology/Compactness/Compact.lean | 1,180 | 1,186 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
| /-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 191 | 193 |
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Fintype.Card
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Multiset coercion to type
This module defines a `CoeSort` instance for multisets and gives it a `Fintype` instance.
It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of
a multiset. These coercions and definitions make it easier to sum over multisets using existing
`Finset` theory.
## Main definitions
* A coercion from `m : Multiset α` to a `Type*`. Each `x : m` has two components.
The first, `x.1`, can be obtained via the coercion `↑x : α`,
and it yields the underlying element of the multiset.
The second, `x.2`, is a term of `Fin (m.count x)`,
and its function is to ensure each term appears with the correct multiplicity.
Note that this coercion requires `DecidableEq α` due to the definition using `Multiset.count`.
* `Multiset.toEnumFinset` is a `Finset` version of this.
* `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion
and whose second component enumerates elements with multiplicity.
* `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`.
## Tags
multiset enumeration
-/
variable {α β : Type*} [DecidableEq α] [DecidableEq β] {m : Multiset α}
namespace Multiset
/-- Auxiliary definition for the `CoeSort` instance. This prevents the `CoeOut m α`
instance from inadvertently applying to other sigma types. -/
def ToType (m : Multiset α) : Type _ := (x : α) × Fin (m.count x)
/-- Create a type that has the same number of elements as the multiset.
Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`.
This way repeated elements of a multiset appear multiple times from different values of `i`. -/
instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩
example : DecidableEq m := inferInstanceAs <| DecidableEq ((x : α) × Fin (m.count x))
/-- Constructor for terms of the coercion of `m` to a type.
This helps Lean pick up the correct instances. -/
@[reducible, match_pattern]
def mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m :=
⟨x, i⟩
/-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first
component. -/
instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α :=
⟨fun x ↦ x.1⟩
theorem coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x :=
rfl
@[simp] lemma coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (by have := x.2.2; omega)
@[simp]
protected theorem forall_coe (p : m → Prop) :
(∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ :=
Sigma.forall
@[simp]
protected theorem exists_coe (p : m → Prop) :
(∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ :=
Sigma.exists
instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } :=
Fintype.ofFinset
(m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨_, Prod.mk_right_injective x⟩)
(by
rintro ⟨x, i⟩
simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range,
Function.Embedding.coeFn_mk, Prod.mk_inj, Set.mem_setOf_eq]
simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp]
exact fun h ↦ Multiset.count_pos.mp (by omega))
/-- Construct a finset whose elements enumerate the elements of the multiset `m`.
The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times
then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/
def toEnumFinset (m : Multiset α) : Finset (α × ℕ) :=
{ p : α × ℕ | p.2 < m.count p.1 }.toFinset
@[simp]
theorem mem_toEnumFinset (m : Multiset α) (p : α × ℕ) :
p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 :=
Set.mem_toFinset
theorem mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m :=
have := (m.mem_toEnumFinset p).mp h; Multiset.count_pos.mp (by omega)
@[simp] lemma toEnumFinset_filter_eq (m : Multiset α) (a : α) :
{x ∈ m.toEnumFinset | x.1 = a} = {a} ×ˢ Finset.range (m.count a) := by aesop
@[simp] lemma map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by
ext a; simp [count_map, ← Finset.filter_val, eq_comm (a := a)]
@[simp] lemma image_toEnumFinset_fst (m : Multiset α) :
m.toEnumFinset.image Prod.fst = m.toFinset := by
rw [Finset.image, Multiset.map_toEnumFinset_fst]
@[simp] lemma map_fst_le_of_subset_toEnumFinset {s : Finset (α × ℕ)} (hsm : s ⊆ m.toEnumFinset) :
s.1.map Prod.fst ≤ m := by
simp_rw [le_iff_count, count_map]
rintro a
obtain ha | ha := (s.1.filter fun x ↦ a = x.1).card.eq_zero_or_pos
· rw [ha]
exact Nat.zero_le _
obtain ⟨n, han, hn⟩ : ∃ n ≥ card (s.1.filter fun x ↦ a = x.1) - 1, (a, n) ∈ s := by
by_contra! h
replace h : {x ∈ s | x.1 = a} ⊆ {a} ×ˢ .range (card (s.1.filter fun x ↦ a = x.1) - 1) := by
simpa +contextual [forall_swap (β := _ = a), Finset.subset_iff,
imp_not_comm, not_le, Nat.lt_sub_iff_add_lt] using h
have : card (s.1.filter fun x ↦ a = x.1) ≤ card (s.1.filter fun x ↦ a = x.1) - 1 := by
simpa [Finset.card, eq_comm] using Finset.card_mono h
omega
exact Nat.le_of_pred_lt (han.trans_lt <| by simpa using hsm hn)
@[mono]
theorem toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) :
m₁.toEnumFinset ⊆ m₂.toEnumFinset := by
intro p
simp only [Multiset.mem_toEnumFinset]
exact gt_of_ge_of_gt (Multiset.le_iff_count.mp h p.1)
@[simp]
theorem toEnumFinset_subset_iff {m₁ m₂ : Multiset α} :
m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ :=
⟨fun h ↦ by simpa using map_fst_le_of_subset_toEnumFinset h, Multiset.toEnumFinset_mono⟩
/-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats.
If you are looking for the function `m → α`, that would be plain `(↑)`. -/
@[simps]
def coeEmbedding (m : Multiset α) : m ↪ α × ℕ where
toFun x := (x, x.2)
inj' := by
intro ⟨x, i, hi⟩ ⟨y, j, hj⟩
rintro ⟨⟩
rfl
/-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce
that `Finset` to a type. -/
@[simps]
def coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where
toFun x :=
⟨m.coeEmbedding x, by
rw [Multiset.mem_toEnumFinset]
exact x.2.2⟩
invFun x :=
⟨x.1.1, x.1.2, by
rw [← Multiset.mem_toEnumFinset]
exact x.2⟩
left_inv := by
rintro ⟨x, i, h⟩
rfl
right_inv := by
rintro ⟨⟨x, i⟩, h⟩
rfl
@[simp]
theorem toEmbedding_coeEquiv_trans (m : Multiset α) :
m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl
@[irreducible]
instance fintypeCoe : Fintype m :=
Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm
theorem map_univ_coeEmbedding (m : Multiset α) :
(Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by
ext ⟨x, i⟩
simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply,
Prod.mk_inj, exists_true_left, Multiset.exists_coe, Multiset.coe_mk, Fin.val_mk,
exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, true_and]
@[simp]
theorem map_univ_coe (m : Multiset α) :
(Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by
have := m.map_toEnumFinset_fst
rw [← m.map_univ_coeEmbedding] at this
simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map,
Function.comp_apply] using this
theorem map_univ_comp_coe {β : Type*} (m : Multiset α) (f : α → β) :
((Finset.univ : Finset m).val.map (f ∘ (fun x : m ↦ (x : α)))) = m.map f := by
rw [← Multiset.map_map, Multiset.map_univ_coe]
@[simp]
theorem map_univ {β : Type*} (m : Multiset α) (f : α → β) :
((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by
simp_rw [← Function.comp_apply (f := f)]
exact map_univ_comp_coe m f
@[simp]
theorem card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by
rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val]
congr
exact m.map_toEnumFinset_fst
@[simp]
theorem card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by
rw [Fintype.card_congr m.coeEquiv]
simp only [Fintype.card_coe, card_toEnumFinset]
@[to_additive]
theorem prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by
congr
simp
@[to_additive]
theorem prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) :
m.prod = ∏ x ∈ m.toEnumFinset, x.1 := by
congr
simp
@[to_additive]
theorem prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) :
∏ x ∈ m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by
rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2]
· rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2]
· intro x
rfl
/--
If `s = t` then there's an equivalence between the appropriate types.
-/
@[simps]
def cast {s t : Multiset α} (h : s = t) : s ≃ t where
toFun x := ⟨x.1, x.2.cast (by simp [h])⟩
invFun x := ⟨x.1, x.2.cast (by simp [h])⟩
left_inv x := rfl
right_inv x := rfl
instance : IsEmpty (0 : Multiset α) := Fintype.card_eq_zero_iff.mp (by simp)
instance : IsEmpty (∅ : Multiset α) := Fintype.card_eq_zero_iff.mp (by simp)
/--
`v ::ₘ m` is equivalent to `Option m` by mapping one `v` to `none` and everything else to `m`.
-/
def consEquiv {v : α} : v ::ₘ m ≃ Option m where
toFun x := if h : x.1 = v ∧ x.2.val = m.count v then none else some ⟨x.1, ⟨x.2, by
by_cases hv : x.1 = v
· simp only [hv, true_and] at h ⊢
apply lt_of_le_of_ne (Nat.le_of_lt_add_one _) h
convert x.2.2 using 1
| simp [hv]
· convert x.2.2 using 1
exact (count_cons_of_ne hv _).symm
⟩⟩
| Mathlib/Data/Multiset/Fintype.lean | 255 | 258 |
/-
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, Floris van Doorn
-/
import Mathlib.Data.Countable.Small
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Powerset
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Set.Countable
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Logic.Small.Set
import Mathlib.Logic.UnivLE
import Mathlib.SetTheory.Cardinal.Order
/-!
# Basic results on cardinal numbers
We provide a collection of basic results on cardinal numbers, in particular focussing on
finite/countable/small types and sets.
## Main definitions
* `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, aleph,
Cantor's theorem, König's theorem, Konig's theorem
-/
assert_not_exists Field
open List (Vector)
open Function Order Set
noncomputable section
universe u v w v' w'
variable {α β : Type u}
namespace Cardinal
/-! ### Lifting cardinals to a higher universe -/
@[simp]
lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by
rw [← mk_uLift, Cardinal.eq]
constructor
let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x)
have : Function.Bijective f :=
ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective))
exact Equiv.ofBijective f this
-- `simp` can't figure out universe levels: normal form is `lift_mk_shrink'`.
theorem lift_mk_shrink (α : Type u) [Small.{v} α] :
Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α :=
lift_mk_eq.2 ⟨(equivShrink α).symm⟩
@[simp]
theorem lift_mk_shrink' (α : Type u) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α :=
lift_mk_shrink.{u, v, 0} α
@[simp]
theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = #α := by
rw [← lift_umax, lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id]
theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) :
prod f = Cardinal.lift.{u} (∏ i, f i) := by
revert f
refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h)
· intro α β hβ e h f
letI := Fintype.ofEquiv β e.symm
rw [← e.prod_comp f, ← h]
exact mk_congr (e.piCongrLeft _).symm
· intro f
rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one]
· intro α hα h f
rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax.{v, u}, mk_out, ←
Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)]
simp only [lift_id]
/-! ### Basic cardinals -/
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α :=
⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ =>
⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩
@[simp]
theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
alias ⟨_, _root_.Set.Subsingleton.cardinalMk_le_one⟩ := mk_le_one_iff_set_subsingleton
@[deprecated (since := "2024-11-10")]
alias _root_.Set.Subsingleton.cardinal_mk_le_one := Set.Subsingleton.cardinalMk_le_one
private theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by
change #(ULift.{u} _) = #(ULift.{u} _) + 1
rw [← mk_option]
simp
/-! ### Order properties -/
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases s.eq_empty_or_nonempty with rfl | hne
· exact Or.inl rfl
· exact Or.inr ⟨sInf s, csInf_mem hne, h⟩
· rcases h with rfl | ⟨a, ha, rfl⟩
· exact Cardinal.sInf_empty
· exact eq_bot_iff.2 (csInf_le' ha)
lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} :
(⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by
simp [iInf, sInf_eq_zero_iff]
/-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/
protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 :=
ciSup_of_empty f
@[simp]
theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp
· exact lift_monotone.map_csInf hs
@[simp]
theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u, v} (iInf f) = ⨅ i, lift.{u, v} (f i) := by
unfold iInf
convert lift_sInf (range f)
simp_rw [← comp_apply (f := lift), range_comp]
end Cardinal
/-! ### Small sets of cardinals -/
namespace Cardinal
instance small_Iic (a : Cardinal.{u}) : Small.{u} (Iic a) := by
rw [← mk_out a]
apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩
rintro ⟨x, hx⟩
simpa using le_mk_iff_exists_set.1 hx
instance small_Iio (a : Cardinal.{u}) : Small.{u} (Iio a) := small_subset Iio_subset_Iic_self
instance small_Icc (a b : Cardinal.{u}) : Small.{u} (Icc a b) := small_subset Icc_subset_Iic_self
instance small_Ico (a b : Cardinal.{u}) : Small.{u} (Ico a b) := small_subset Ico_subset_Iio_self
instance small_Ioc (a b : Cardinal.{u}) : Small.{u} (Ioc a b) := small_subset Ioc_subset_Iic_self
instance small_Ioo (a b : Cardinal.{u}) : Small.{u} (Ioo a b) := small_subset Ioo_subset_Iio_self
/-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/
theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun _ h => ha h) _, by
rintro ⟨ι, ⟨e⟩⟩
use sum.{u, u} fun x ↦ e.symm x
intro a ha
simpa using le_sum (fun x ↦ e.symm x) (e ⟨a, ha⟩)⟩
theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
theorem bddAbove_range {ι : Type*} [Small.{u} ι] (f : ι → Cardinal.{u}) : BddAbove (Set.range f) :=
bddAbove_of_small _
theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}}
(hs : BddAbove s) : BddAbove (f '' s) := by
rw [bddAbove_iff_small] at hs ⊢
exact small_lift _
theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f))
(g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by
rw [range_comp]
exact bddAbove_image g hf
/-- The type of cardinals in universe `u` is not `Small.{u}`. This is a version of the Burali-Forti
paradox. -/
theorem _root_.not_small_cardinal : ¬ Small.{u} Cardinal.{max u v} := by
intro h
have := small_lift.{_, v} Cardinal.{max u v}
rw [← small_univ_iff, ← bddAbove_iff_small] at this
exact not_bddAbove_univ this
instance uncountable : Uncountable Cardinal.{u} :=
Uncountable.of_not_small not_small_cardinal.{u}
/-! ### Bounds on suprema -/
theorem sum_le_iSup_lift {ι : Type u}
(f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift #ι * iSup f := by
rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const]
exact sum_le_sum _ _ (le_ciSup <| bddAbove_of_small _)
theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by
rw [← lift_id #ι]
exact sum_le_iSup_lift f
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) :
lift.{u} (sSup s) = sSup (lift.{u} '' s) := by
apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _)
· intro c hc
by_contra h
obtain ⟨d, rfl⟩ := Cardinal.mem_range_lift_of_le (not_le.1 h).le
simp_rw [lift_le] at h hc
rw [csSup_le_iff' hs] at h
exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha)
· rintro i ⟨j, hj, rfl⟩
exact lift_le.2 (le_csSup hs hj)
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) :
lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by
rw [iSup, iSup, lift_sSup hf, ← range_comp]
simp [Function.comp_def]
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f))
(w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le' w
@[simp]
theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f))
{t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _)
/-- To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}}
{f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'}
(h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by
rw [lift_iSup hf, lift_iSup hf']
exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩
/-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}}
{f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι')
(h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') :=
lift_iSup_le_lift_iSup hf hf' h
/-! ### Properties about the cast from `ℕ` -/
theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by
simp [Pow.pow]
@[norm_cast]
theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by
rw [Nat.cast_succ]
refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_)
rw [← Nat.cast_succ]
exact Nat.cast_lt.2 (Nat.lt_succ_self _)
lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by
rw [← Cardinal.nat_succ]
norm_cast
lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by
rw [← Order.succ_le_iff, Cardinal.succ_natCast]
lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by
convert natCast_add_one_le_iff
norm_cast
@[simp]
theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast
-- This works generally to prove inequalities between numeric cardinals.
theorem one_lt_two : (1 : Cardinal) < 2 := by norm_cast
theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) :
∃ s : Finset α, n ≤ s.card := by
obtain hα|hα := finite_or_infinite α
· let hα := Fintype.ofFinite α
use Finset.univ
simpa only [mk_fintype, Nat.cast_le] using h
· obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n
exact ⟨s, hs.ge⟩
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by
contrapose! H
apply exists_finset_le_card α (n+1)
simpa only [nat_succ, succ_le_iff] using H
theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by
rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb
exact (cantor a).trans_le (power_le_power_right hb)
theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by
rw [← succ_zero, succ_le_iff]
theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by
rw [one_le_iff_pos, pos_iff_ne_zero]
@[simp]
theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by
simpa using lt_succ_bot_iff (a := c)
/-! ### Properties about `aleph0` -/
theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ :=
succ_le_iff.1
(by
rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}]
exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩)
@[simp]
theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1
@[simp]
theorem one_le_aleph0 : 1 ≤ ℵ₀ :=
one_lt_aleph0.le
theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n :=
⟨fun h => by
rcases lt_lift_iff.1 h with ⟨c, h', rfl⟩
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩
suffices S.Finite by
lift S to Finset ℕ using this
simp
contrapose! h'
haveI := Infinite.to_subtype h'
exact ⟨Infinite.natEmbedding S⟩, fun ⟨_, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩
lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by
obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h
rw [hn, succ_natCast]
theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c :=
⟨fun h _ => (nat_lt_aleph0 _).le.trans h, fun h =>
le_of_not_lt fun hn => by
rcases lt_aleph0.1 hn with ⟨n, rfl⟩
exact (Nat.lt_succ_self _).not_le (Nat.cast_le.1 (h (n + 1)))⟩
theorem isSuccPrelimit_aleph0 : IsSuccPrelimit ℵ₀ :=
isSuccPrelimit_of_succ_lt fun a ha => by
rcases lt_aleph0.1 ha with ⟨n, rfl⟩
rw [← nat_succ]
apply nat_lt_aleph0
theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := by
rw [Cardinal.isSuccLimit_iff]
exact ⟨aleph0_ne_zero, isSuccPrelimit_aleph0⟩
lemma not_isSuccLimit_natCast : (n : ℕ) → ¬ IsSuccLimit (n : Cardinal.{u})
| 0, e => e.1 isMin_bot
| Nat.succ n, e => Order.not_isSuccPrelimit_succ _ (nat_succ n ▸ e.2)
theorem not_isSuccLimit_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ¬ IsSuccLimit c := by
obtain ⟨n, rfl⟩ := lt_aleph0.1 h
exact not_isSuccLimit_natCast n
theorem aleph0_le_of_isSuccLimit {c : Cardinal} (h : IsSuccLimit c) : ℵ₀ ≤ c := by
contrapose! h
exact not_isSuccLimit_of_lt_aleph0 h
theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ := by
refine ⟨aleph0_ne_zero, fun x hx ↦ ?_⟩
obtain ⟨n, rfl⟩ := lt_aleph0.1 hx
exact_mod_cast nat_lt_aleph0 _
theorem IsStrongLimit.aleph0_le {c} (H : IsStrongLimit c) : ℵ₀ ≤ c :=
aleph0_le_of_isSuccLimit H.isSuccLimit
lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v})
(hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n :=
exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f hf (not_isSuccLimit_natCast n) h
@[simp]
theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ :=
ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0]
theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by
rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq']
theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by
simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin]
theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) :=
lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _)
theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ :=
lt_aleph0_iff_finite.2 ‹_›
theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite :=
lt_aleph0_iff_finite.trans finite_coe_iff
alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite
@[simp]
theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite :=
lt_aleph0_iff_set_finite
theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by
rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le']
@[simp]
theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ :=
mk_le_aleph0_iff.mpr ‹_›
theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff
alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable
@[simp]
theorem le_aleph0_iff_subtype_countable {p : α → Prop} :
#{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable :=
le_aleph0_iff_set_countable
theorem aleph0_lt_mk_iff : ℵ₀ < #α ↔ Uncountable α := by
rw [← not_le, ← not_countable_iff, not_iff_not, mk_le_aleph0_iff]
@[simp]
theorem aleph0_lt_mk [Uncountable α] : ℵ₀ < #α :=
aleph0_lt_mk_iff.mpr ‹_›
instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ :=
⟨fun _ hx =>
let ⟨n, hn⟩ := lt_aleph0.mp hx
⟨n, hn.symm⟩⟩
theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0
theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ :=
⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩,
fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩
theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by
simp only [← not_lt, add_lt_aleph0_iff, not_and_or]
/-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/
theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by
cases n with
| zero => simpa using nat_lt_aleph0 0
| succ n =>
simp only [Nat.succ_ne_zero, false_or]
induction' n with n ih
· simp
rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff]
/-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/
theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ :=
nsmul_lt_aleph0_iff.trans <| or_iff_right h
theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0
theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by
refine ⟨fun h => ?_, ?_⟩
· by_cases ha : a = 0
· exact Or.inl ha
right
by_cases hb : b = 0
· exact Or.inl hb
right
rw [← Ne, ← one_le_iff_ne_zero] at ha hb
constructor
· rw [← mul_one a]
exact (mul_le_mul' le_rfl hb).trans_lt h
· rw [← one_mul b]
exact (mul_le_mul' ha le_rfl).trans_lt h
rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero]
/-- See also `Cardinal.aleph0_le_mul_iff`. -/
theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by
let h := (@mul_lt_aleph0_iff a b).not
rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h
/-- See also `Cardinal.aleph0_le_mul_iff'`. -/
theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by
have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a
simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)]
simp only [and_comm, or_comm]
theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb]
theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [power_natCast, ← Nat.cast_pow]; apply nat_lt_aleph0
theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α :=
calc
#α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff
_ ↔ Subsingleton α ∧ Nonempty α :=
le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff)
theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by
rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite]
lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm
lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff]
@[simp] lemma mk_lt_aleph0 [Finite α] : #α < ℵ₀ := mk_lt_aleph0_iff.2 ‹_›
@[simp]
theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α :=
infinite_iff.1 ‹_›
@[simp]
theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ :=
mk_le_aleph0.antisymm <| aleph0_le_mk _
theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ :=
⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by
obtain ⟨f⟩ := Quotient.exact h
exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩
theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ :=
denumerable_iff.1 ⟨‹_›⟩
theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} :
s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by
rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff]
@[simp]
theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ :=
mk_denumerable _
theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ :=
mk_denumerable _
@[simp]
theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ :=
le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <|
le_mul_of_one_le_left (zero_le _) <| by
rwa [← Nat.cast_one, Nat.cast_le, Nat.one_le_iff_ne_zero]
@[simp]
theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn]
@[simp]
theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) * ℵ₀ = ℵ₀ :=
nat_mul_aleph0 (NeZero.ne n)
@[simp]
theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * ofNat(n) = ℵ₀ :=
aleph0_mul_nat (NeZero.ne n)
@[simp]
theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ :=
⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h =>
aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩
@[simp]
theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ :=
(add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add
@[simp]
theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat]
@[simp]
theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) + ℵ₀ = ℵ₀ :=
nat_add_aleph0 n
@[simp]
theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + ofNat(n) = ℵ₀ :=
aleph0_add_nat n
theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by
lift c to ℕ using h.trans_lt (nat_lt_aleph0 _)
exact ⟨c, mod_cast h, rfl⟩
theorem mk_int : #ℤ = ℵ₀ :=
mk_denumerable ℤ
theorem mk_pnat : #ℕ+ = ℵ₀ :=
mk_denumerable ℕ+
@[deprecated (since := "2025-04-27")]
alias mk_pNat := mk_pnat
/-! ### Cardinalities of basic sets and types -/
@[simp] theorem mk_additive : #(Additive α) = #α := rfl
@[simp] theorem mk_multiplicative : #(Multiplicative α) = #α := rfl
@[to_additive (attr := simp)] theorem mk_mulOpposite : #(MulOpposite α) = #α :=
mk_congr MulOpposite.opEquiv.symm
theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 :=
mk_eq_one _
@[simp]
theorem mk_vector (α : Type u) (n : ℕ) : #(List.Vector α n) = #α ^ n :=
(mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp
theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n :=
calc
#(List α) = #(Σn, List.Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm
_ = sum fun n : ℕ => #α ^ n := by simp
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α :=
mk_le_of_surjective Quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α :=
mk_quot_le
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
#(Subtype p) ≤ #(Subtype q) :=
⟨Embedding.subtypeMap (Embedding.refl α) h⟩
theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 :=
mk_eq_zero _
theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by
constructor
· intro h
rw [mk_eq_zero_iff] at h
exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩
· rintro rfl
exact mk_emptyCollection _
@[simp]
theorem mk_univ {α : Type u} : #(@univ α) = #α :=
mk_congr (Equiv.Set.univ α)
@[simp] lemma mk_setProd {α β : Type u} (s : Set α) (t : Set β) : #(s ×ˢ t) = #s * #t := by
rw [mul_def, mk_congr (Equiv.Set.prod ..)]
theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s :=
mk_le_of_surjective surjective_onto_image
lemma mk_image2_le {α β γ : Type u} {f : α → β → γ} {s : Set α} {t : Set β} :
#(image2 f s t) ≤ #s * #t := by
rw [← image_uncurry_prod, ← mk_setProd]
exact mk_image_le
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} :
lift.{u} #(f '' s) ≤ lift.{v} #s :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α :=
mk_le_of_surjective surjective_onto_range
theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} :
lift.{u} #(range f) ≤ lift.{v} #α :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩
theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α :=
mk_congr (Equiv.ofInjective f h).symm
theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{max u w} #(range f) = lift.{max v w} #α :=
lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩
theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{u} #(range f) = lift.{v} #α :=
lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩
lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by
rw [← Cardinal.mk_range_eq_of_injective hf]
exact Cardinal.lift_le.2 (Cardinal.mk_set_le _)
lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) :
Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) :=
lift_mk_le_lift_mk_of_injective (injective_surjInv hf)
theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) :
#(f '' s) = #s :=
mk_congr (Equiv.Set.imageOfInjOn f s h).symm
theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α)
(h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s :=
lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s :=
mk_image_eq_of_injOn _ _ hf.injOn
theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_of_injOn_lift _ _ h.injOn
@[simp]
theorem mk_image_embedding_lift {β : Type v} (f : α ↪ β) (s : Set α) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_lift _ _ f.injective
@[simp]
theorem mk_image_embedding (f : α ↪ β) (s : Set α) : #(f '' s) = #s := by
simpa using mk_image_embedding_lift f s
theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
#(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} :
lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) :=
mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α}
(h : Pairwise (Disjoint on f)) : #(⋃ i, f i) = sum fun i => #(f i) :=
calc
#(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α}
(h : Pairwise (Disjoint on f)) :
lift.{v} #(⋃ i, f i) = sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) = #(Σi, f i) :=
mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) :=
mk_iUnion_le_sum_mk.trans (sum_le_iSup _)
theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) :
lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by
refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _)
rw [← lift_sum, lift_id'.{_,u}]
theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by
rw [sUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) :
#(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) :
lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le_lift
theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ :=
lt_aleph0_of_finite _
theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} :
#s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by
constructor
· intro h
lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n)
simpa using h
· rintro ⟨t, rfl, rfl⟩
exact mk_coe_finset
theorem mk_eq_nat_iff_finset {n : ℕ} :
#α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by
rw [← mk_univ, mk_set_eq_nat_iff_finset]
theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by
rw [mk_eq_nat_iff_finset]
constructor
· rintro ⟨t, ht, hn⟩
exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩
· rintro ⟨⟨t, ht⟩, hn⟩
exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩
theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} :
#(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T := by
classical
exact Quot.sound ⟨Equiv.Set.unionSumInter S T⟩
/-- The cardinality of a union is at most the sum of the cardinalities
of the two sets. -/
theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T :=
@mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α)
theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) :
#(S ∪ T : Set α) = #S + #T := by
classical
exact Quot.sound ⟨Equiv.Set.union H⟩
theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) :
#(insert a s : Set α) = #s + 1 := by
rw [← union_singleton, mk_union_of_disjoint, mk_singleton]
simpa
theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by
by_cases h : a ∈ s
· simp only [insert_eq_of_mem h, self_le_add_right]
· rw [mk_insert h]
theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α := by
classical
exact mk_congr (Equiv.Set.sumCompl s)
theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t :=
⟨Set.embeddingOfSubset s t h⟩
theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} :
#t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by
refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩
apply card_le_of (fun s ↦ ?_)
classical
let u : Finset α := s.image Subtype.val
have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn
rw [← this]
apply H
simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ]
theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) :
#{ x // p x } ≤ #{ x // q x } :=
⟨embeddingOfSubset _ _ h⟩
theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T :=
(mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _
theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by
refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h]
exact disjoint_sdiff_self_left
theorem mk_union_le_aleph0 {α} {P Q : Set α} :
#(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by
simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def,
← countable_union]
theorem mk_sep (s : Set α) (t : α → Prop) : #({ x ∈ s | t x } : Set α) = #{ x : s | t x.1 } :=
mk_congr (Equiv.Set.sep s t)
theorem mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) : lift.{v} #(f ⁻¹' s) ≤ lift.{u} #s := by
rw [lift_mk_le.{0}]
-- Porting note: Needed to insert `mem_preimage.mp` below
use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2
apply Subtype.coind_injective; exact h.comp Subtype.val_injective
theorem mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : s ⊆ range f) : lift.{u} #s ≤ lift.{v} #(f ⁻¹' s) := by
rw [← image_preimage_eq_iff] at h
nth_rewrite 1 [← h]
apply mk_image_le_lift
theorem mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) (h2 : s ⊆ range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
theorem mk_preimage_of_injective_of_subset_range (f : α → β) (s : Set β) (h : Injective f)
(h2 : s ⊆ range f) : #(f ⁻¹' s) = #s := by
convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id]
@[simp]
theorem mk_preimage_equiv_lift {β : Type v} (f : α ≃ β) (s : Set β) :
lift.{v} #(f ⁻¹' s) = lift.{u} #s := by
apply mk_preimage_of_injective_of_subset_range_lift _ _ f.injective
rw [f.range_eq_univ]
exact fun _ _ ↦ ⟨⟩
@[simp]
theorem mk_preimage_equiv (f : α ≃ β) (s : Set β) : #(f ⁻¹' s) = #s := by
simpa using mk_preimage_equiv_lift f s
theorem mk_preimage_of_injective (f : α → β) (s : Set β) (h : Injective f) :
#(f ⁻¹' s) ≤ #s := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_injective_lift f s h
theorem mk_preimage_of_subset_range (f : α → β) (s : Set β) (h : s ⊆ range f) :
#s ≤ #(f ⁻¹' s) := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_subset_range_lift f s h
theorem mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : Set α}
{t : Set β} (h : t ⊆ f '' s) : lift.{u} #t ≤ lift.{v} #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range_lift _ _ h using 1
rw [mk_sep]
rfl
theorem mk_subset_ge_of_subset_image (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) :
#t ≤ #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range _ _ h using 1
rw [mk_sep]
rfl
theorem le_mk_iff_exists_subset {c : Cardinal} {α : Type u} {s : Set α} :
c ≤ #s ↔ ∃ p : Set α, p ⊆ s ∧ #p = c := by
rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype]
apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective
@[simp]
theorem mk_range_inl {α : Type u} {β : Type v} : #(range (@Sum.inl α β)) = lift.{v} #α := by
rw [← lift_id'.{u, v} #_, (Equiv.Set.rangeInl α β).lift_cardinal_eq, lift_umax.{u, v}]
@[simp]
theorem mk_range_inr {α : Type u} {β : Type v} : #(range (@Sum.inr α β)) = lift.{u} #β := by
rw [← lift_id'.{v, u} #_, (Equiv.Set.rangeInr α β).lift_cardinal_eq, lift_umax.{v, u}]
theorem two_le_iff : (2 : Cardinal) ≤ #α ↔ ∃ x y : α, x ≠ y := by
rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff]
theorem two_le_iff' (x : α) : (2 : Cardinal) ≤ #α ↔ ∃ y : α, y ≠ x := by
rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x]
theorem mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : Set α) = univ := by
classical
simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two]
constructor
· rintro ⟨t, ht, x, y, hne, rfl⟩
exact ⟨x, y, hne, by simpa using ht⟩
· rintro ⟨x, y, hne, h⟩
exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩
theorem mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x := by
rw [mk_eq_two_iff]; constructor
· rintro ⟨a, b, hne, h⟩
simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h
rcases h x with (rfl | rfl)
exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩]
· rintro ⟨y, hne, hy⟩
exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩
theorem exists_not_mem_of_length_lt {α : Type*} (l : List α) (h : ↑l.length < #α) :
∃ z : α, z ∉ l := by
classical
contrapose! h
calc
#α = #(Set.univ : Set α) := mk_univ.symm
_ ≤ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x)
_ = l.toFinset.card := Cardinal.mk_coe_finset
_ ≤ l.length := Nat.cast_le.mpr (List.toFinset_card_le l)
theorem three_le {α : Type*} (h : 3 ≤ #α) (x : α) (y : α) : ∃ z : α, z ≠ x ∧ z ≠ y := by
have : ↑(3 : ℕ) ≤ #α := by simpa using h
have : ↑(2 : ℕ) < #α := by rwa [← succ_le_iff, ← Cardinal.nat_succ]
have := exists_not_mem_of_length_lt [x, y] this
simpa [not_or] using this
/-! ### `powerlt` operation -/
/-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/
def powerlt (a b : Cardinal.{u}) : Cardinal.{u} :=
⨆ c : Iio b, a ^ (c : Cardinal)
@[inherit_doc]
infixl:80 " ^< " => powerlt
theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by
refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩
rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by
rw [powerlt, ciSup_le_iff']
· simp
· rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h
theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left
theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b :=
(powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <|
le_powerlt a (lt_succ b)
theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_min
theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_max
theorem zero_powerlt {a : Cardinal} (h : a ≠ 0) : 0 ^< a = 1 := by
apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm
rw [← power_zero]
exact le_powerlt 0 (pos_iff_ne_zero.2 h)
@[simp]
theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by
convert Cardinal.iSup_of_empty _
exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt
end Cardinal
| Mathlib/SetTheory/Cardinal/Basic.lean | 1,101 | 1,101 | |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.Algebra.Group.Pointwise.Set.Scalar
import Mathlib.Algebra.Ring.Subsemiring.Basic
import Mathlib.RingTheory.Localization.Defs
/-!
# Integer elements of a localization
## Main definitions
* `IsLocalization.IsInteger` is a predicate stating that `x : S` is in the image of `R`
## Implementation notes
See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
variable {R : Type*} [CommSemiring R] {M : Submonoid R} {S : Type*} [CommSemiring S]
variable [Algebra R S] {P : Type*} [CommSemiring P]
open Function
namespace IsLocalization
section
variable (R)
-- TODO: define a subalgebra of `IsInteger`s
/-- Given `a : S`, `S` a localization of `R`, `IsInteger R a` iff `a` is in the image of
the localization map from `R` to `S`. -/
def IsInteger (a : S) : Prop :=
a ∈ (algebraMap R S).rangeS
end
theorem isInteger_zero : IsInteger R (0 : S) :=
Subsemiring.zero_mem _
theorem isInteger_one : IsInteger R (1 : S) :=
Subsemiring.one_mem _
theorem isInteger_add {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a + b) :=
Subsemiring.add_mem _ ha hb
theorem isInteger_mul {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a * b) :=
Subsemiring.mul_mem _ ha hb
theorem isInteger_smul {a : R} {b : S} (hb : IsInteger R b) : IsInteger R (a • b) := by
rcases hb with ⟨b', hb⟩
use a * b'
rw [← hb, (algebraMap R S).map_mul, Algebra.smul_def]
variable (M)
variable [IsLocalization M S]
/-- Each element `a : S` has an `M`-multiple which is an integer.
This version multiplies `a` on the right, matching the argument order in `LocalizationMap.surj`.
-/
theorem exists_integer_multiple' (a : S) : ∃ b : M, IsInteger R (a * algebraMap R S b) :=
let ⟨⟨Num, denom⟩, h⟩ := IsLocalization.surj _ a
⟨denom, Set.mem_range.mpr ⟨Num, h.symm⟩⟩
/-- Each element `a : S` has an `M`-multiple which is an integer.
This version multiplies `a` on the left, matching the argument order in the `SMul` instance.
-/
theorem exists_integer_multiple (a : S) : ∃ b : M, IsInteger R ((b : R) • a) := by
simp_rw [Algebra.smul_def, mul_comm _ a]
apply exists_integer_multiple'
/-- We can clear the denominators of a `Finset`-indexed family of fractions. -/
theorem exist_integer_multiples {ι : Type*} (s : Finset ι) (f : ι → S) :
∃ b : M, ∀ i ∈ s, IsLocalization.IsInteger R ((b : R) • f i) := by
haveI := Classical.propDecidable
refine ⟨∏ i ∈ s, (sec M (f i)).2, fun i hi => ⟨?_, ?_⟩⟩
· exact (∏ j ∈ s.erase i, (sec M (f j)).2) * (sec M (f i)).1
rw [RingHom.map_mul, sec_spec', ← mul_assoc, ← (algebraMap R S).map_mul, ← Algebra.smul_def]
congr 2
refine _root_.trans ?_ (map_prod (Submonoid.subtype M) _ _).symm
rw [mul_comm,Submonoid.coe_finset_prod,
-- Porting note: explicitly supplied `f`
← Finset.prod_insert (f := fun i => ((sec M (f i)).snd : R)) (s.not_mem_erase i),
Finset.insert_erase hi]
rfl
/-- We can clear the denominators of a finite indexed family of fractions. -/
theorem exist_integer_multiples_of_finite {ι : Type*} [Finite ι] (f : ι → S) :
∃ b : M, ∀ i, IsLocalization.IsInteger R ((b : R) • f i) := by
cases nonempty_fintype ι
obtain ⟨b, hb⟩ := exist_integer_multiples M Finset.univ f
exact ⟨b, fun i => hb i (Finset.mem_univ _)⟩
/-- We can clear the denominators of a finite set of fractions. -/
theorem exist_integer_multiples_of_finset (s : Finset S) :
∃ b : M, ∀ a ∈ s, IsInteger R ((b : R) • a) :=
| exist_integer_multiples M s id
/-- A choice of a common multiple of the denominators of a `Finset`-indexed family of fractions. -/
noncomputable def commonDenom {ι : Type*} (s : Finset ι) (f : ι → S) : M :=
(exist_integer_multiples M s f).choose
| Mathlib/RingTheory/Localization/Integer.lean | 107 | 111 |
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Group.NatPowAssoc
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Ring.Opposite
import Mathlib.Tactic.Abel
import Mathlib.Algebra.Ring.Regular
/-!
# Partial sums of geometric series
This file determines the values of the geometric series $\sum_{i=0}^{n-1} x^i$ and
$\sum_{i=0}^{n-1} x^i y^{n-1-i}$ and variants thereof. We also provide some bounds on the
"geometric" sum of `a/b^i` where `a b : ℕ`.
## Main statements
* `geom_sum_Ico` proves that $\sum_{i=m}^{n-1} x^i=\frac{x^n-x^m}{x-1}$ in a division ring.
* `geom_sum₂_Ico` proves that $\sum_{i=m}^{n-1} x^iy^{n - 1 - i}=\frac{x^n-y^{n-m}x^m}{x-y}$
in a field.
Several variants are recorded, generalising in particular to the case of a noncommutative ring in
which `x` and `y` commute. Even versions not using division or subtraction, valid in each semiring,
are recorded.
-/
variable {R K : Type*}
open Finset MulOpposite
section Semiring
variable [Semiring R]
theorem geom_sum_succ {x : R} {n : ℕ} :
∑ i ∈ range (n + 1), x ^ i = (x * ∑ i ∈ range n, x ^ i) + 1 := by
simp only [mul_sum, ← pow_succ', sum_range_succ', pow_zero]
theorem geom_sum_succ' {x : R} {n : ℕ} :
∑ i ∈ range (n + 1), x ^ i = x ^ n + ∑ i ∈ range n, x ^ i :=
(sum_range_succ _ _).trans (add_comm _ _)
theorem geom_sum_zero (x : R) : ∑ i ∈ range 0, x ^ i = 0 :=
rfl
theorem geom_sum_one (x : R) : ∑ i ∈ range 1, x ^ i = 1 := by simp [geom_sum_succ']
@[simp]
theorem geom_sum_two {x : R} : ∑ i ∈ range 2, x ^ i = x + 1 := by simp [geom_sum_succ']
@[simp]
theorem zero_geom_sum : ∀ {n}, ∑ i ∈ range n, (0 : R) ^ i = if n = 0 then 0 else 1
| 0 => by simp
| 1 => by simp
| n + 2 => by
rw [geom_sum_succ']
simp [zero_geom_sum]
theorem one_geom_sum (n : ℕ) : ∑ i ∈ range n, (1 : R) ^ i = n := by simp
| Mathlib/Algebra/GeomSum.lean | 65 | 65 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mitchell Lee
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Indicator
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Topology.Algebra.InfiniteSum.Defs
import Mathlib.Topology.Algebra.Monoid.Defs
/-!
# Lemmas on infinite sums and products in topological monoids
This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to
keep the basic file of definitions as short as possible.
Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`.
-/
noncomputable section
open Filter Finset Function Topology
variable {α β γ : Type*}
section HasProd
variable [CommMonoid α] [TopologicalSpace α]
variable {f g : β → α} {a b : α}
/-- Constant one function has product `1` -/
@[to_additive "Constant zero function has sum `0`"]
theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds]
@[to_additive]
theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by
convert @hasProd_one α β _ _
@[to_additive]
theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) :=
hasProd_one.multipliable
@[to_additive]
theorem multipliable_empty [IsEmpty β] : Multipliable f :=
hasProd_empty.multipliable
/-- See `multipliable_congr_cofinite` for a version allowing the functions to
disagree on a finite set. -/
@[to_additive "See `summable_congr_cofinite` for a version allowing the functions to
disagree on a finite set."]
theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g :=
iff_of_eq (congr_arg Multipliable <| funext hfg)
/-- See `Multipliable.congr_cofinite` for a version allowing the functions to
disagree on a finite set. -/
@[to_additive "See `Summable.congr_cofinite` for a version allowing the functions to
disagree on a finite set."]
theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g :=
(multipliable_congr hfg).mp hf
@[to_additive]
lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a :=
(funext h : g = f) ▸ hf
@[to_additive]
theorem HasProd.hasProd_of_prod_eq {g : γ → α}
(h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' →
∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b)
(hf : HasProd g a) : HasProd f a :=
le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf
@[to_additive]
theorem hasProd_iff_hasProd {g : γ → α}
(h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' →
∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b)
(h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' →
∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) :
HasProd f a ↔ HasProd g a :=
⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩
@[to_additive]
theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g)
(hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f :=
exists_congr fun _ ↦ hg.hasProd_iff hf
@[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) :
HasProd (extend g f 1) a ↔ HasProd f a := by
rw [← hg.hasProd_iff, extend_comp hg]
exact extend_apply' _ _
@[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) :
Multipliable (extend g f 1) ↔ Multipliable f :=
exists_congr fun _ ↦ hasProd_extend_one hg
@[to_additive]
theorem hasProd_subtype_iff_mulIndicator {s : Set β} :
HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by
rw [← Set.mulIndicator_range_comp, Subtype.range_coe,
hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset]
@[to_additive]
theorem multipliable_subtype_iff_mulIndicator {s : Set β} :
Multipliable (f ∘ (↑) : s → α) ↔ Multipliable (s.mulIndicator f) :=
exists_congr fun _ ↦ hasProd_subtype_iff_mulIndicator
@[to_additive (attr := simp)]
theorem hasProd_subtype_mulSupport : HasProd (f ∘ (↑) : mulSupport f → α) a ↔ HasProd f a :=
hasProd_subtype_iff_of_mulSupport_subset <| Set.Subset.refl _
@[to_additive]
protected theorem Finset.multipliable (s : Finset β) (f : β → α) :
Multipliable (f ∘ (↑) : (↑s : Set β) → α) :=
(s.hasProd f).multipliable
@[to_additive]
protected theorem Set.Finite.multipliable {s : Set β} (hs : s.Finite) (f : β → α) :
Multipliable (f ∘ (↑) : s → α) := by
have := hs.toFinset.multipliable f
rwa [hs.coe_toFinset] at this
@[to_additive]
theorem multipliable_of_finite_mulSupport (h : (mulSupport f).Finite) : Multipliable f := by
apply multipliable_of_ne_finset_one (s := h.toFinset); simp
@[to_additive]
lemma Multipliable.of_finite [Finite β] {f : β → α} : Multipliable f :=
multipliable_of_finite_mulSupport <| Set.finite_univ.subset (Set.subset_univ _)
@[to_additive]
theorem hasProd_single {f : β → α} (b : β) (hf : ∀ (b') (_ : b' ≠ b), f b' = 1) : HasProd f (f b) :=
suffices HasProd f (∏ b' ∈ {b}, f b') by simpa using this
hasProd_prod_of_ne_finset_one <| by simpa [hf]
@[to_additive (attr := simp)] lemma hasProd_unique [Unique β] (f : β → α) : HasProd f (f default) :=
hasProd_single default (fun _ hb ↦ False.elim <| hb <| Unique.uniq ..)
@[to_additive (attr := simp)]
lemma hasProd_singleton (m : β) (f : β → α) : HasProd (({m} : Set β).restrict f) (f m) :=
hasProd_unique (Set.restrict {m} f)
@[to_additive]
theorem hasProd_ite_eq (b : β) [DecidablePred (· = b)] (a : α) :
HasProd (fun b' ↦ if b' = b then a else 1) a := by
convert @hasProd_single _ _ _ _ (fun b' ↦ if b' = b then a else 1) b (fun b' hb' ↦ if_neg hb')
exact (if_pos rfl).symm
@[to_additive]
theorem Equiv.hasProd_iff (e : γ ≃ β) : HasProd (f ∘ e) a ↔ HasProd f a :=
e.injective.hasProd_iff <| by simp
@[to_additive]
theorem Function.Injective.hasProd_range_iff {g : γ → β} (hg : Injective g) :
HasProd (fun x : Set.range g ↦ f x) a ↔ HasProd (f ∘ g) a :=
(Equiv.ofInjective g hg).hasProd_iff.symm
@[to_additive]
theorem Equiv.multipliable_iff (e : γ ≃ β) : Multipliable (f ∘ e) ↔ Multipliable f :=
exists_congr fun _ ↦ e.hasProd_iff
@[to_additive]
theorem Equiv.hasProd_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g)
(he : ∀ x : mulSupport f, g (e x) = f x) : HasProd f a ↔ HasProd g a := by
have : (g ∘ (↑)) ∘ e = f ∘ (↑) := funext he
rw [← hasProd_subtype_mulSupport, ← this, e.hasProd_iff, hasProd_subtype_mulSupport]
@[to_additive]
theorem hasProd_iff_hasProd_of_ne_one_bij {g : γ → α} (i : mulSupport g → β)
(hi : Injective i) (hf : mulSupport f ⊆ Set.range i)
(hfg : ∀ x, f (i x) = g x) : HasProd f a ↔ HasProd g a :=
Iff.symm <|
Equiv.hasProd_iff_of_mulSupport
(Equiv.ofBijective (fun x ↦ ⟨i x, fun hx ↦ x.coe_prop <| hfg x ▸ hx⟩)
⟨fun _ _ h ↦ hi <| Subtype.ext_iff.1 h, fun y ↦
(hf y.coe_prop).imp fun _ hx ↦ Subtype.ext hx⟩)
hfg
@[to_additive]
theorem Equiv.multipliable_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g)
(he : ∀ x : mulSupport f, g (e x) = f x) : Multipliable f ↔ Multipliable g :=
exists_congr fun _ ↦ e.hasProd_iff_of_mulSupport he
@[to_additive]
protected theorem HasProd.map [CommMonoid γ] [TopologicalSpace γ] (hf : HasProd f a) {G}
[FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) :
HasProd (g ∘ f) (g a) := by
have : (g ∘ fun s : Finset β ↦ ∏ b ∈ s, f b) = fun s : Finset β ↦ ∏ b ∈ s, (g ∘ f) b :=
funext <| map_prod g _
unfold HasProd
rw [← this]
exact (hg.tendsto a).comp hf
@[to_additive]
protected theorem Topology.IsInducing.hasProd_iff [CommMonoid γ] [TopologicalSpace γ] {G}
[FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : IsInducing g) (f : β → α) (a : α) :
HasProd (g ∘ f) (g a) ↔ HasProd f a := by
simp_rw [HasProd, comp_apply, ← map_prod]
exact hg.tendsto_nhds_iff.symm
@[deprecated (since := "2024-10-28")] alias Inducing.hasProd_iff := IsInducing.hasProd_iff
@[to_additive]
protected theorem Multipliable.map [CommMonoid γ] [TopologicalSpace γ] (hf : Multipliable f) {G}
[FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : Multipliable (g ∘ f) :=
(hf.hasProd.map g hg).multipliable
@[to_additive]
protected theorem Multipliable.map_iff_of_leftInverse [CommMonoid γ] [TopologicalSpace γ] {G G'}
[FunLike G α γ] [MonoidHomClass G α γ] [FunLike G' γ α] [MonoidHomClass G' γ α]
(g : G) (g' : G') (hg : Continuous g) (hg' : Continuous g') (hinv : Function.LeftInverse g' g) :
Multipliable (g ∘ f) ↔ Multipliable f :=
⟨fun h ↦ by
have := h.map _ hg'
rwa [← Function.comp_assoc, hinv.id] at this, fun h ↦ h.map _ hg⟩
@[to_additive]
theorem Multipliable.map_tprod [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] (hf : Multipliable f)
{G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) :
g (∏' i, f i) = ∏' i, g (f i) := (HasProd.tprod_eq (HasProd.map hf.hasProd g hg)).symm
@[to_additive]
lemma Topology.IsInducing.multipliable_iff_tprod_comp_mem_range [CommMonoid γ] [TopologicalSpace γ]
[T2Space γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : IsInducing g) (f : β → α) :
Multipliable f ↔ Multipliable (g ∘ f) ∧ ∏' i, g (f i) ∈ Set.range g := by
constructor
· intro hf
constructor
· exact hf.map g hg.continuous
· use ∏' i, f i
exact hf.map_tprod g hg.continuous
· rintro ⟨hgf, a, ha⟩
use a
have := hgf.hasProd
simp_rw [comp_apply, ← ha] at this
exact (hg.hasProd_iff f a).mp this
@[deprecated (since := "2024-10-28")]
alias Inducing.multipliable_iff_tprod_comp_mem_range :=
IsInducing.multipliable_iff_tprod_comp_mem_range
/-- "A special case of `Multipliable.map_iff_of_leftInverse` for convenience" -/
@[to_additive "A special case of `Summable.map_iff_of_leftInverse` for convenience"]
protected theorem Multipliable.map_iff_of_equiv [CommMonoid γ] [TopologicalSpace γ] {G}
[EquivLike G α γ] [MulEquivClass G α γ] (g : G) (hg : Continuous g)
(hg' : Continuous (EquivLike.inv g : γ → α)) : Multipliable (g ∘ f) ↔ Multipliable f :=
Multipliable.map_iff_of_leftInverse g (g : α ≃* γ).symm hg hg' (EquivLike.left_inv g)
@[to_additive]
theorem Function.Surjective.multipliable_iff_of_hasProd_iff {α' : Type*} [CommMonoid α']
[TopologicalSpace α'] {e : α' → α} (hes : Function.Surjective e) {f : β → α} {g : γ → α'}
(he : ∀ {a}, HasProd f (e a) ↔ HasProd g a) : Multipliable f ↔ Multipliable g :=
hes.exists.trans <| exists_congr <| @he
variable [ContinuousMul α]
@[to_additive]
theorem HasProd.mul (hf : HasProd f a) (hg : HasProd g b) :
HasProd (fun b ↦ f b * g b) (a * b) := by
dsimp only [HasProd] at hf hg ⊢
simp_rw [prod_mul_distrib]
exact hf.mul hg
@[to_additive]
theorem Multipliable.mul (hf : Multipliable f) (hg : Multipliable g) :
Multipliable fun b ↦ f b * g b :=
(hf.hasProd.mul hg.hasProd).multipliable
@[to_additive]
theorem hasProd_prod {f : γ → β → α} {a : γ → α} {s : Finset γ} :
(∀ i ∈ s, HasProd (f i) (a i)) → HasProd (fun b ↦ ∏ i ∈ s, f i b) (∏ i ∈ s, a i) := by
classical
exact Finset.induction_on s (by simp only [hasProd_one, prod_empty, forall_true_iff]) <| by
simp +contextual only [mem_insert, forall_eq_or_imp, not_false_iff,
prod_insert, and_imp]
exact fun x s _ IH hx h ↦ hx.mul (IH h)
@[to_additive]
theorem multipliable_prod {f : γ → β → α} {s : Finset γ} (hf : ∀ i ∈ s, Multipliable (f i)) :
Multipliable fun b ↦ ∏ i ∈ s, f i b :=
(hasProd_prod fun i hi ↦ (hf i hi).hasProd).multipliable
@[to_additive]
theorem HasProd.mul_disjoint {s t : Set β} (hs : Disjoint s t) (ha : HasProd (f ∘ (↑) : s → α) a)
(hb : HasProd (f ∘ (↑) : t → α) b) : HasProd (f ∘ (↑) : (s ∪ t : Set β) → α) (a * b) := by
rw [hasProd_subtype_iff_mulIndicator] at *
rw [Set.mulIndicator_union_of_disjoint hs]
exact ha.mul hb
@[to_additive]
theorem hasProd_prod_disjoint {ι} (s : Finset ι) {t : ι → Set β} {a : ι → α}
(hs : (s : Set ι).Pairwise (Disjoint on t)) (hf : ∀ i ∈ s, HasProd (f ∘ (↑) : t i → α) (a i)) :
HasProd (f ∘ (↑) : (⋃ i ∈ s, t i) → α) (∏ i ∈ s, a i) := by
simp_rw [hasProd_subtype_iff_mulIndicator] at *
rw [Finset.mulIndicator_biUnion _ _ hs]
exact hasProd_prod hf
@[to_additive]
theorem HasProd.mul_isCompl {s t : Set β} (hs : IsCompl s t) (ha : HasProd (f ∘ (↑) : s → α) a)
(hb : HasProd (f ∘ (↑) : t → α) b) : HasProd f (a * b) := by
simpa [← hs.compl_eq] using
(hasProd_subtype_iff_mulIndicator.1 ha).mul (hasProd_subtype_iff_mulIndicator.1 hb)
@[to_additive]
theorem HasProd.mul_compl {s : Set β} (ha : HasProd (f ∘ (↑) : s → α) a)
(hb : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) b) : HasProd f (a * b) :=
ha.mul_isCompl isCompl_compl hb
@[to_additive]
theorem Multipliable.mul_compl {s : Set β} (hs : Multipliable (f ∘ (↑) : s → α))
(hsc : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) : Multipliable f :=
(hs.hasProd.mul_compl hsc.hasProd).multipliable
@[to_additive]
theorem HasProd.compl_mul {s : Set β} (ha : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) a)
(hb : HasProd (f ∘ (↑) : s → α) b) : HasProd f (a * b) :=
ha.mul_isCompl isCompl_compl.symm hb
@[to_additive]
theorem Multipliable.compl_add {s : Set β} (hs : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α))
(hsc : Multipliable (f ∘ (↑) : s → α)) : Multipliable f :=
(hs.hasProd.compl_mul hsc.hasProd).multipliable
/-- Version of `HasProd.update` for `CommMonoid` rather than `CommGroup`.
Rather than showing that `f.update` has a specific product in terms of `HasProd`,
it gives a relationship between the products of `f` and `f.update` given that both exist. -/
@[to_additive "Version of `HasSum.update` for `AddCommMonoid` rather than `AddCommGroup`.
Rather than showing that `f.update` has a specific sum in terms of `HasSum`,
it gives a relationship between the sums of `f` and `f.update` given that both exist."]
theorem HasProd.update' {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α]
[ContinuousMul α] [DecidableEq β] {f : β → α} {a a' : α} (hf : HasProd f a) (b : β) (x : α)
(hf' : HasProd (update f b x) a') : a * x = a' * f b := by
have : ∀ b', f b' * ite (b' = b) x 1 = update f b x b' * ite (b' = b) (f b) 1 := by
intro b'
split_ifs with hb'
· simpa only [Function.update_apply, hb', eq_self_iff_true] using mul_comm (f b) x
· simp only [Function.update_apply, hb', if_false]
have h := hf.mul (hasProd_ite_eq b x)
simp_rw [this] at h
exact HasProd.unique h (hf'.mul (hasProd_ite_eq b (f b)))
/-- Version of `hasProd_ite_div_hasProd` for `CommMonoid` rather than `CommGroup`.
Rather than showing that the `ite` expression has a specific product in terms of `HasProd`, it gives
a relationship between the products of `f` and `ite (n = b) 0 (f n)` given that both exist. -/
@[to_additive "Version of `hasSum_ite_sub_hasSum` for `AddCommMonoid` rather than `AddCommGroup`.
Rather than showing that the `ite` expression has a specific sum in terms of `HasSum`,
it gives a relationship between the sums of `f` and `ite (n = b) 0 (f n)` given that both exist."]
theorem eq_mul_of_hasProd_ite {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α]
[ContinuousMul α] [DecidableEq β] {f : β → α} {a : α} (hf : HasProd f a) (b : β) (a' : α)
(hf' : HasProd (fun n ↦ ite (n = b) 1 (f n)) a') : a = a' * f b := by
refine (mul_one a).symm.trans (hf.update' b 1 ?_)
convert hf'
apply update_apply
end HasProd
section tprod
variable [CommMonoid α] [TopologicalSpace α] {f g : β → α}
@[to_additive]
theorem tprod_congr_set_coe (f : β → α) {s t : Set β} (h : s = t) :
∏' x : s, f x = ∏' x : t, f x := by rw [h]
@[to_additive]
theorem tprod_congr_subtype (f : β → α) {P Q : β → Prop} (h : ∀ x, P x ↔ Q x) :
∏' x : {x // P x}, f x = ∏' x : {x // Q x}, f x :=
tprod_congr_set_coe f <| Set.ext h
@[to_additive]
theorem tprod_eq_finprod (hf : (mulSupport f).Finite) :
∏' b, f b = ∏ᶠ b, f b := by simp [tprod_def, multipliable_of_finite_mulSupport hf, hf]
@[to_additive]
theorem tprod_eq_prod' {s : Finset β} (hf : mulSupport f ⊆ s) :
∏' b, f b = ∏ b ∈ s, f b := by
rw [tprod_eq_finprod (s.finite_toSet.subset hf), finprod_eq_prod_of_mulSupport_subset _ hf]
@[to_additive]
theorem tprod_eq_prod {s : Finset β} (hf : ∀ b ∉ s, f b = 1) :
∏' b, f b = ∏ b ∈ s, f b :=
tprod_eq_prod' <| mulSupport_subset_iff'.2 hf
@[to_additive (attr := simp)]
theorem tprod_one : ∏' _ : β, (1 : α) = 1 := by rw [tprod_eq_finprod] <;> simp
@[to_additive (attr := simp)]
theorem tprod_empty [IsEmpty β] : ∏' b, f b = 1 := by
rw [tprod_eq_prod (s := (∅ : Finset β))] <;> simp
@[to_additive]
theorem tprod_congr {f g : β → α}
(hfg : ∀ b, f b = g b) : ∏' b, f b = ∏' b, g b :=
congr_arg tprod (funext hfg)
@[to_additive]
theorem tprod_fintype [Fintype β] (f : β → α) : ∏' b, f b = ∏ b, f b := by
apply tprod_eq_prod; simp
@[to_additive]
theorem prod_eq_tprod_mulIndicator (f : β → α) (s : Finset β) :
| ∏ x ∈ s, f x = ∏' x, Set.mulIndicator (↑s) f x := by
rw [tprod_eq_prod' (Set.mulSupport_mulIndicator_subset),
| Mathlib/Topology/Algebra/InfiniteSum/Basic.lean | 401 | 402 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Tape
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.PFun
import Mathlib.Computability.PostTuringMachine
/-!
# Turing machines
The files `PostTuringMachine.lean` and `TuringMachine.lean` define
a sequence of simple machine languages, starting with Turing machines and working
up to more complex languages based on Wang B-machines.
`PostTuringMachine.lean` covers the TM0 model and TM1 model;
`TuringMachine.lean` adds the TM2 model.
## Naming conventions
Each model of computation in this file shares a naming convention for the elements of a model of
computation. These are the parameters for the language:
* `Γ` is the alphabet on the tape.
* `Λ` is the set of labels, or internal machine states.
* `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and
later models achieve this by mixing it into `Λ`.
* `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks.
All of these variables denote "essentially finite" types, but for technical reasons it is
convenient to allow them to be infinite anyway. When using an infinite type, we will be interested
to prove that only finitely many values of the type are ever interacted with.
Given these parameters, there are a few common structures for the model that arise:
* `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is
finite, and for later models it is an infinite inductive type representing "possible program
texts".
* `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with
its environment.
* `Machine` is the set of all machines in the model. Usually this is approximately a function
`Λ → Stmt`, although different models have different ways of halting and other actions.
* `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step.
If `step c = none`, then `c` is a terminal state, and the result of the computation is read off
from `c`. Because of the type of `step`, these models are all deterministic by construction.
* `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model;
in most cases it is `List Γ`.
* `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from
`init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to
the final state to obtain the result. The type `Output` depends on the model.
* `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and
can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input
cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when
convenient, and prove that only finitely many of these states are actually accessible. This
formalizes "essentially finite" mentioned above.
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Relation
open Nat (iterate)
open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply'
iterate_zero_apply)
namespace Turing
/-!
## The TM2 model
The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite)
collection of stacks, each with elements of different types (the alphabet of stack `k : K` is
`Γ k`). The statements are:
* `push k (f : σ → Γ k) q` puts `f a` on the `k`-th stack, then does `q`.
* `pop k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, and removes this element from the stack, then does `q`.
* `peek k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, then does `q`.
* `load (f : σ → σ) q` reads nothing but applies `f` to the internal state, then does `q`.
* `branch (f : σ → Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`.
* `goto (f : σ → Λ)` jumps to label `f a`.
* `halt` halts on the next step.
The configuration is a tuple `(l, var, stk)` where `l : Option Λ` is the current label to run or
`none` for the halting state, `var : σ` is the (finite) internal state, and `stk : ∀ k, List (Γ k)`
is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not
`ListBlank`s, they have definite ends that can be detected by the `pop` command.)
Given a designated stack `k` and a value `L : List (Γ k)`, the initial configuration has all the
stacks empty except the designated "input" stack; in `eval` this designated stack also functions
as the output stack.
-/
namespace TM2
variable {K : Type*}
-- Index type of stacks
variable (Γ : K → Type*)
-- Type of stack elements
variable (Λ : Type*)
-- Type of function labels
variable (σ : Type*)
-- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive Stmt
| push : ∀ k, (σ → Γ k) → Stmt → Stmt
| peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| load : (σ → σ) → Stmt → Stmt
| branch : (σ → Bool) → Stmt → Stmt → Stmt
| goto : (σ → Λ) → Stmt
| halt : Stmt
open Stmt
instance Stmt.inhabited : Inhabited (Stmt Γ Λ σ) :=
⟨halt⟩
/-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) -/
structure Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Λ
/-- The internal state -/
var : σ
/-- The (finite) collection of internal stacks -/
stk : ∀ k, List (Γ k)
instance Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) :=
⟨⟨default, default, default⟩⟩
variable {Γ Λ σ}
section
variable [DecidableEq K]
/-- The step function for the TM2 model. -/
def stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S)
| goto f, v, S => ⟨some (f v), v, S⟩
| halt, v, S => ⟨none, v, S⟩
/-- The step function for the TM2 model. -/
def step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ)
| ⟨none, _, _⟩ => none
| ⟨some l, v, S⟩ => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2
/-- The (reflexive) reachability relation for the TM2 model. -/
def Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop :=
ReflTransGen fun a b ↦ b ∈ step M a
end
/-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/
def SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂
| goto l => ∀ v, l v ∈ S
| halt => True
section
open scoped Classical in
/-- The set of subtree statements in a statement. -/
noncomputable def stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ)
| Q@(push _ _ q) => insert Q (stmts₁ q)
| Q@(peek _ _ q) => insert Q (stmts₁ q)
| Q@(pop _ _ q) => insert Q (stmts₁ q)
| Q@(load _ q) => insert Q (stmts₁ q)
| Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q@(goto _) => {Q}
| Q@halt => {Q}
theorem stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁]
theorem stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by
classical
intro h₁₂ q₀ h₀₁
induction q₂ with (
simp only [stmts₁] at h₁₂ ⊢
simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂)
| branch f q₁ q₂ IH₁ IH₂ =>
rcases h₁₂ with (rfl | h₁₂ | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂))
· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂))
| goto l => subst h₁₂; exact h₀₁
| halt => subst h₁₂; exact h₀₁
| load _ q IH | _ _ _ q IH =>
rcases h₁₂ with (rfl | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (IH h₁₂)
theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂)
(hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by
induction q₂ with
simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton]
at h hs
| branch f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in
/-- The set of statements accessible from initial set `S` of labels. -/
noncomputable def stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) :=
Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q))
theorem stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) :
some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩
end
variable [Inhabited Λ]
/-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states in `S`. -/
def Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) :=
default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q)
theorem stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ}
(ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls)
variable [DecidableEq K]
theorem step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) :
∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S
| ⟨some l₁, v, T⟩, c', h₁, h₂ => by
replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂)
simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c'
revert h₂; induction M l₁ generalizing v T with intro hs
| branch p q₁' q₂' IH₁ IH₂ =>
unfold stepAux; cases p v
· exact IH₂ _ _ hs.2
· exact IH₁ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited σ]
/-- The initial state of the TM2 model. The input is provided on a designated stack. -/
def init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ :=
⟨some default, default, update (fun _ ↦ []) k L⟩
/-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/
def eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) :=
(Turing.eval (step M) (init k L)).map fun c ↦ c.stk k
end TM2
/-!
## TM2 emulator in TM1
To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a
TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of
stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack
1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this:
```
bottom: ... | _ | T | _ | _ | _ | _ | ...
stack 1: ... | _ | b | a | _ | _ | _ | ...
stack 2: ... | _ | f | e | d | c | _ | ...
```
where a tape element is a vertical slice through the diagram. Here the alphabet is
`Γ' := Bool × ∀ k, Option (Γ k)`, where:
* `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the
tail of all stacks. It is never modified.
* `stk k : Option (Γ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is
the blank value). Note that the head of the stack is at the far end; this is so that push and pop
don't have to do any shifting.
In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions,
it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the
end of the appropriate stack, make its changes, and then return to the bottom. So the states are:
* `normal (l : Λ)`: waiting at `bottom` to execute function `l`
* `go k (s : StAct k) (q : Stmt₂)`: travelling to the right to get to the end of stack `k` in
order to perform stack action `s`, and later continue with executing `q`
* `ret (q : Stmt₂)`: travelling to the left after having performed a stack action, and executing
`q` once we arrive
Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the
length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)`
steps to run when emulated in TM1, where `m` is the length of the input.
-/
namespace TM2to1
-- A displaced lemma proved in unnecessary generality
theorem stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Γ : K → Type*)
variable {Λ σ : Type*}
/-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/
def Γ' :=
Bool × ∀ k, Option (Γ k)
variable {K Γ}
instance Γ'.inhabited : Inhabited (Γ' K Γ) :=
⟨⟨false, fun _ ↦ none⟩⟩
instance Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) :=
instFintypeProd _ _
/-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function
to express the program state in terms of a tape with only the stacks themselves. -/
def addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) :=
ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩)
theorem addBottom_map (L : ListBlank (∀ k, Option (Γ k))) :
(addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by
simp only [addBottom, ListBlank.map_cons]
convert ListBlank.cons_head_tail L
generalize ListBlank.tail L = L'
refine L'.induction_on fun l ↦ ?_; simp
theorem addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k))
(L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
(addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by
cases n <;>
simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons]
congr; symm; apply ListBlank.map_modifyNth; intro; rfl
theorem addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth n).2 = L.nth n := by
conv => rhs; rw [← addBottom_map L, ListBlank.nth_map]
theorem addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth (n + 1)).1 = false := by
rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map]
theorem addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by
rw [addBottom, ListBlank.head_cons]
variable (K Γ σ) in
/-- A stack action is a command that interacts with the top of a stack. Our default position
is at the bottom of all the stacks, so we have to hold on to this action while going to the end
to modify the stack. -/
inductive StAct (k : K)
| push : (σ → Γ k) → StAct k
| peek : (σ → Option (Γ k) → σ) → StAct k
| pop : (σ → Option (Γ k) → σ) → StAct k
instance StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) :=
⟨StAct.peek fun s _ ↦ s⟩
section
open StAct
/-- The TM2 statement corresponding to a stack action. -/
def stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ
| push f => TM2.Stmt.push k f
| peek f => TM2.Stmt.peek k f
| pop f => TM2.Stmt.pop k f
/-- The effect of a stack action on the local variables, given the value of the stack. -/
def stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ
| push _ => v
| peek f => f v l.head?
| pop f => f v l.head?
/-- The effect of a stack action on the stack. -/
def stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k)
| push f => f v :: l
| peek _ => l
| pop _ => l.tail
/-- We have partitioned the TM2 statements into "stack actions", which require going to the end
of the stack, and all other actions, which do not. This is a modified recursor which lumps the
stack actions into one. -/
@[elab_as_elim]
def stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l}
(run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q))
(load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q))
(branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂))
(goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n
| TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.branch _ q₁ q₂ =>
branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂)
| TM2.Stmt.goto _ => goto _
| TM2.Stmt.halt => halt
theorem supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by
cases s <;> rfl
end
variable (K Γ Λ σ)
/-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the
next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and
return to the bottom, respectively. -/
inductive Λ'
| normal : Λ → Λ'
| go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ'
| ret : TM2.Stmt Γ Λ σ → Λ'
variable {K Γ Λ σ}
open Λ'
instance Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) :=
⟨normal default⟩
open TM1.Stmt
section
variable [DecidableEq K]
/-- The program corresponding to state transitions at the end of a stack. Here we start out just
after the top of the stack, and should end just after the new top of the stack. -/
def trStAct {k : K} (q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ) :
StAct K Γ σ k → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q
| StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q
| StAct.pop f =>
branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q)
(move Dir.left <|
(load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q)
/-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty
except for the input stack, and the stack bottom mark is set at the head. -/
def trInit (k : K) (L : List (Γ k)) : List (Γ' K Γ) :=
let L' : List (Γ' K Γ) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a))
(true, L'.headI.2) :: L'.tail
theorem step_run {k : K} (q : TM2.Stmt Γ Λ σ) (v : σ) (S : ∀ k, List (Γ k)) : ∀ s : StAct K Γ σ k,
TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s))
| StAct.push _ => rfl
| StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl
| StAct.pop _ => rfl
end
/-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents,
but stack actions are deferred by going to the corresponding `go` state, so that we can find the
appropriate stack top. -/
def trNormal : TM2.Stmt Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q
| TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q
| TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q
| TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q)
| TM2.Stmt.branch f q₁ q₂ => branch (fun _ ↦ f) (trNormal q₁) (trNormal q₂)
| TM2.Stmt.goto l => goto fun _ s ↦ normal (l s)
| TM2.Stmt.halt => halt
theorem trNormal_run {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by
cases s <;> rfl
section
open scoped Classical in
/-- The set of machine states accessible from an initial TM2 statement. -/
noncomputable def trStmts₁ : TM2.Stmt Γ Λ σ → Finset (Λ' K Γ Λ σ)
| TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.load _ q => trStmts₁ q
| TM2.Stmt.branch _ q₁ q₂ => trStmts₁ q₁ ∪ trStmts₁ q₂
| _ => ∅
theorem trStmts₁_run {k : K} {s : StAct K Γ σ k} {q : TM2.Stmt Γ Λ σ} :
open scoped Classical in
trStmts₁ (stRun s q) = {go k s q, ret q} ∪ trStmts₁ q := by
cases s <;> simp only [trStmts₁, stRun]
theorem tr_respects_aux₂ [DecidableEq K] {k : K} {q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ} {v : σ}
{S : ∀ k, List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : ∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) :
let v' := stVar v (S k) o
let Sk' := stWrite v (S k) o
let S' := update S k Sk'
∃ L' : ListBlank (∀ k, Option (Γ k)),
(∀ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧
TM1.stepAux (trStAct q o) v
((Tape.move Dir.right)^[(S k).length] (Tape.mk' ∅ (addBottom L))) =
TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' ∅ (addBottom L'))) := by
simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux]
| push f =>
have := Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k (some (f v)))
refine
⟨_, fun k' ↦ ?_, by
-- Porting note: `rw [...]` to `erw [...]; rfl`.
-- https://github.com/leanprover-community/mathlib4/issues/5164
rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this]
erw [addBottom_modifyNth fun a ↦ update a k (some (f v))]
rw [Nat.add_one, iterate_succ']
rfl⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h
<;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map]
· rw [List.getI_eq_getElem _, List.getElem_append_right] <;>
simp only [List.length_append, List.length_reverse, List.length_map, ← h,
Nat.sub_self, List.length_singleton, List.getElem_singleton,
le_refl, Nat.lt_succ_self]
rw [← proj_map_nth, hL, ListBlank.nth_mk]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
| peek f =>
rw [Function.update_eq_self]
use L, hL; rw [Tape.move_left_right]; congr
cases e : S k; · rfl
rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left,
Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e,
List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length]
rfl
| pop f =>
rcases e : S k with - | ⟨hd, tl⟩
· simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length,
Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil]
rw [← e, Function.update_eq_self]
exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩
· refine
⟨_, fun k' ↦ ?_, by
erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst,
cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head,
Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k none),
addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd,
stk_nth_val _ (hL k), e,
show (List.cons hd tl).reverse[tl.length]? = some hd by
rw [List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length],
List.head?, List.tail]⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail]
· rw [List.getI_eq_default]
· rfl
rw [h, List.length_reverse, List.length_map]
rw [← proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
end
variable [DecidableEq K]
variable (M : Λ → TM2.Stmt Γ Λ σ)
/-- The TM2 emulator machine states written as a TM1 program.
This handles the `go` and `ret` states, which shuttle to and from a stack top. -/
def tr : Λ' K Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| normal q => trNormal (M q)
| go k s q =>
branch (fun a _ ↦ (a.2 k).isNone) (trStAct (goto fun _ _ ↦ ret q) s)
(move Dir.right <| goto fun _ _ ↦ go k s q)
| ret q => branch (fun a _ ↦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ ↦ ret q)
/-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/
inductive TrCfg : TM2.Cfg Γ Λ σ → TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ → Prop
| mk {q : Option Λ} {v : σ} {S : ∀ k, List (Γ k)} (L : ListBlank (∀ k, Option (Γ k))) :
(∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) →
TrCfg ⟨q, v, S⟩ ⟨q.map normal, v, Tape.mk' ∅ (addBottom L)⟩
theorem tr_respects_aux₁ {k} (o q v) {S : List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n ≤ S.length) :
Reaches₀ (TM1.step (tr M)) ⟨some (go k o q), v, Tape.mk' ∅ (addBottom L)⟩
⟨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ := by
induction' n with n IH; · rfl
apply (IH (le_of_lt H)).tail
rw [iterate_succ_apply']
simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head,
addBottom_nth_snd, Option.mem_def]
rw [stk_nth_val _ hL, List.getElem?_eq_getElem]
· rfl
· rwa [List.length_reverse]
theorem tr_respects_aux₃ {q v} {L : ListBlank (∀ k, Option (Γ k))} (n) : Reaches₀ (TM1.step (tr M))
⟨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩
⟨some (ret q), v, Tape.mk' ∅ (addBottom L)⟩ := by
induction' n with n IH; · rfl
refine Reaches₀.head ?_ IH
simp only [Option.mem_def, TM1.step]
rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat,
addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left]
rfl
theorem tr_respects_aux {q v T k} {S : ∀ k, List (Γ k)}
(hT : ∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse)
(o : StAct K Γ σ k)
(IH : ∀ {v : σ} {S : ∀ k : K, List (Γ k)} {T : ListBlank (∀ k, Option (Γ k))},
(∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) →
∃ b, TrCfg (TM2.stepAux q v S) b ∧
Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' ∅ (addBottom T))) b) :
∃ b, TrCfg (TM2.stepAux (stRun o q) v S) b ∧ Reaches (TM1.step (tr M))
(TM1.stepAux (trNormal (stRun o q)) v (Tape.mk' ∅ (addBottom T))) b := by
simp only [trNormal_run, step_run]
have hgo := tr_respects_aux₁ M o q v (hT k) _ le_rfl
obtain ⟨T', hT', hrun⟩ := tr_respects_aux₂ (Λ := Λ) hT o
have := hgo.tail' rfl
rw [tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd,
stk_nth_val _ (hT k), List.getElem?_eq_none (le_of_eq List.length_reverse),
Option.isNone, cond, hrun, TM1.stepAux] at this
obtain ⟨c, gc, rc⟩ := IH hT'
refine ⟨c, gc, (this.to₀.trans (tr_respects_aux₃ M _) c (TransGen.head' rfl ?_)).to_reflTransGen⟩
rw [tr, TM1.stepAux, Tape.mk'_head, addBottom_head_fst]
exact rc
attribute [local simp] Respects TM2.step TM2.stepAux trNormal
theorem tr_respects : Respects (TM2.step M) (TM1.step (tr M)) TrCfg := by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
intro c₁ c₂ h
obtain @⟨- | l, v, S, L, hT⟩ := h; · constructor
rsuffices ⟨b, c, r⟩ : ∃ b, _ ∧ Reaches (TM1.step (tr M)) _ _
· exact ⟨b, c, TransGen.head' rfl r⟩
simp only [tr]
generalize M l = N
induction N using stmtStRec generalizing v S L hT with
| run k s q IH => exact tr_respects_aux M hT s @IH
| load a _ IH => exact IH _ hT
| branch p q₁ q₂ IH₁ IH₂ =>
unfold TM2.stepAux trNormal TM1.stepAux
beta_reduce
cases p v <;> [exact IH₂ _ hT; exact IH₁ _ hT]
| goto => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩
| halt => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩
section
variable [Inhabited Λ] [Inhabited σ]
theorem trCfg_init (k) (L : List (Γ k)) : TrCfg (TM2.init k L)
(TM1.init (trInit k L) : TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ) := by
rw [(_ : TM1.init _ = _)]
· refine ⟨ListBlank.mk (L.reverse.map fun a ↦ update default k (some a)), fun k' ↦ ?_⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map_map]
have : ((proj k').f ∘ fun a => update (β := fun k => Option (Γ k)) default k (some a))
= fun a => (proj k').f (update (β := fun k => Option (Γ k)) default k (some a)) := rfl
rw [this, List.getElem?_map, proj, PointedMap.mk_val]
simp only []
by_cases h : k' = k
· subst k'
simp only [Function.update_self]
rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, ← List.map_reverse, List.getElem?_map]
· simp only [Function.update_of_ne h]
rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map, List.reverse_nil]
cases L.reverse[i]? <;> rfl
· rw [trInit, TM1.init]
congr <;> cases L.reverse <;> try rfl
simp only [List.map_map, List.tail_cons, List.map]
rfl
theorem tr_eval_dom (k) (L : List (Γ k)) :
(TM1.eval (tr M) (trInit k L)).Dom ↔ (TM2.eval M k L).Dom :=
Turing.tr_eval_dom (tr_respects M) (trCfg_init k L)
theorem tr_eval (k) (L : List (Γ k)) {L₁ L₂} (H₁ : L₁ ∈ TM1.eval (tr M) (trInit k L))
(H₂ : L₂ ∈ TM2.eval M k L) :
∃ (S : ∀ k, List (Γ k)) (L' : ListBlank (∀ k, Option (Γ k))),
addBottom L' = L₁ ∧
(∀ k, L'.map (proj k) = ListBlank.mk ((S k).map some).reverse) ∧ S k = L₂ := by
obtain ⟨c₁, h₁, rfl⟩ := (Part.mem_map_iff _).1 H₁
obtain ⟨c₂, h₂, rfl⟩ := (Part.mem_map_iff _).1 H₂
obtain ⟨_, ⟨L', hT⟩, h₃⟩ := Turing.tr_eval (tr_respects M) (trCfg_init k L) h₂
cases Part.mem_unique h₁ h₃
exact ⟨_, L', by simp only [Tape.mk'_right₀], hT, rfl⟩
end
section
variable [Inhabited Λ]
open scoped Classical in
/-- The support of a set of TM2 states in the TM2 emulator. -/
noncomputable def trSupp (S : Finset Λ) : Finset (Λ' K Γ Λ σ) :=
S.biUnion fun l ↦ insert (normal l) (trStmts₁ (M l))
open scoped Classical in
theorem tr_supports {S} (ss : TM2.Supports M S) : TM1.Supports (tr M) (trSupp M S) :=
⟨Finset.mem_biUnion.2 ⟨_, ss.1, Finset.mem_insert.2 <| Or.inl rfl⟩, fun l' h ↦ by
suffices ∀ (q) (_ : TM2.SupportsStmt S q) (_ : ∀ x ∈ trStmts₁ q, x ∈ trSupp M S),
TM1.SupportsStmt (trSupp M S) (trNormal q) ∧
∀ l' ∈ trStmts₁ q, TM1.SupportsStmt (trSupp M S) (tr M l') by
rcases Finset.mem_biUnion.1 h with ⟨l, lS, h⟩
have :=
this _ (ss.2 l lS) fun x hx ↦ Finset.mem_biUnion.2 ⟨_, lS, Finset.mem_insert_of_mem hx⟩
rcases Finset.mem_insert.1 h with (rfl | h) <;> [exact this.1; exact this.2 _ h]
clear h l'
refine stmtStRec ?_ ?_ ?_ ?_ ?_
· intro _ s _ IH ss' sub -- stack op
rw [TM2to1.supports_run] at ss'
simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton]
at sub
have hgo := sub _ (Or.inl <| Or.inl rfl)
have hret := sub _ (Or.inl <| Or.inr rfl)
obtain ⟨IH₁, IH₂⟩ := IH ss' fun x hx ↦ sub x <| Or.inr hx
refine ⟨by simp only [trNormal_run, TM1.SupportsStmt]; intros; exact hgo, fun l h ↦ ?_⟩
rw [trStmts₁_run] at h
simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton]
at h
rcases h with (⟨rfl | rfl⟩ | h)
· cases s
· exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩
· exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩
· exact ⟨⟨fun _ _ ↦ hret, fun _ _ ↦ hret⟩, fun _ _ ↦ hgo⟩
· unfold TM1.SupportsStmt TM2to1.tr
exact ⟨IH₁, fun _ _ ↦ hret⟩
· exact IH₂ _ h
· intro _ _ IH ss' sub -- load
unfold TM2to1.trStmts₁ at sub ⊢
exact IH ss' sub
· intro _ _ _ IH₁ IH₂ ss' sub -- branch
unfold TM2to1.trStmts₁ at sub
obtain ⟨IH₁₁, IH₁₂⟩ := IH₁ ss'.1 fun x hx ↦ sub x <| Finset.mem_union_left _ hx
obtain ⟨IH₂₁, IH₂₂⟩ := IH₂ ss'.2 fun x hx ↦ sub x <| Finset.mem_union_right _ hx
refine ⟨⟨IH₁₁, IH₂₁⟩, fun l h ↦ ?_⟩
rw [trStmts₁] at h
rcases Finset.mem_union.1 h with (h | h) <;> [exact IH₁₂ _ h; exact IH₂₂ _ h]
· intro _ ss' _ -- goto
simp only [trStmts₁, Finset.not_mem_empty]; refine ⟨?_, fun _ ↦ False.elim⟩
exact fun _ v ↦ Finset.mem_biUnion.2 ⟨_, ss' v, Finset.mem_insert_self _ _⟩
· intro _ _ -- halt
simp only [trStmts₁, Finset.not_mem_empty]
exact ⟨trivial, fun _ ↦ False.elim⟩⟩
end
end TM2to1
end Turing
| Mathlib/Computability/TuringMachine.lean | 2,219 | 2,227 | |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Localization.Opposite
/-!
# Calculus of fractions
Following the definitions by [Gabriel and Zisman][gabriel-zisman-1967],
given a morphism property `W : MorphismProperty C` on a category `C`,
we introduce the class `W.HasLeftCalculusOfFractions`. The main
result `Localization.exists_leftFraction` is that if `L : C ⥤ D`
is a localization functor for `W`, then for any morphism `L.obj X ⟶ L.obj Y` in `D`,
there exists an auxiliary object `Y' : C` and morphisms `g : X ⟶ Y'` and `s : Y ⟶ Y'`,
with `W s`, such that the given morphism is a sort of fraction `g / s`,
or more precisely of the form `L.map g ≫ (Localization.isoOfHom L W s hs).inv`.
We also show that the functor `L.mapArrow : Arrow C ⥤ Arrow D` is essentially surjective.
Similar results are obtained when `W` has a right calculus of fractions.
## References
* [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967]
-/
namespace CategoryTheory
variable {C D : Type*} [Category C] [Category D]
open Category
namespace MorphismProperty
/-- A left fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the
datum of an object `Y' : C` and maps `f : X ⟶ Y'` and `s : Y ⟶ Y'` such that `W s`. -/
structure LeftFraction (W : MorphismProperty C) (X Y : C) where
/-- the auxiliary object of a left fraction -/
{Y' : C}
/-- the numerator of a left fraction -/
f : X ⟶ Y'
/-- the denominator of a left fraction -/
s : Y ⟶ Y'
/-- the condition that the denominator belongs to the given morphism property -/
hs : W s
namespace LeftFraction
variable (W : MorphismProperty C) {X Y : C}
/-- The left fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/
@[simps]
def ofHom (f : X ⟶ Y) [W.ContainsIdentities] :
W.LeftFraction X Y := mk f (𝟙 Y) (W.id_mem Y)
variable {W}
/-- The left fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/
@[simps]
def ofInv (s : Y ⟶ X) (hs : W s) :
W.LeftFraction X Y := mk (𝟙 X) s hs
/-- If `φ : W.LeftFraction X Y` and `L` is a functor which inverts `W`, this is the
induced morphism `L.obj X ⟶ L.obj Y` -/
noncomputable def map (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.obj X ⟶ L.obj Y :=
have := hL _ φ.hs
L.map φ.f ≫ inv (L.map φ.s)
@[reassoc (attr := simp)]
lemma map_comp_map_s (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
φ.map L hL ≫ L.map φ.s = L.map φ.f := by
letI := hL _ φ.hs
simp [map]
variable (W)
lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] :
(ofHom W f).map L hL = L.map f := by
simp [map]
@[reassoc (attr := simp)]
lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by
letI := hL _ hs
simp [map]
@[reassoc (attr := simp)]
lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by
letI := hL _ hs
simp [map]
variable {W}
lemma cases (α : W.LeftFraction X Y) :
∃ (Y' : C) (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s), α = LeftFraction.mk f s hs :=
⟨_, _, _, _, rfl⟩
end LeftFraction
/-- A right fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the
datum of an object `X' : C` and maps `s : X' ⟶ X` and `f : X' ⟶ Y` such that `W s`. -/
structure RightFraction (W : MorphismProperty C) (X Y : C) where
/-- the auxiliary object of a right fraction -/
{X' : C}
/-- the denominator of a right fraction -/
s : X' ⟶ X
/-- the condition that the denominator belongs to the given morphism property -/
hs : W s
/-- the numerator of a right fraction -/
f : X' ⟶ Y
namespace RightFraction
variable (W : MorphismProperty C)
variable {X Y : C}
/-- The right fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/
@[simps]
def ofHom (f : X ⟶ Y) [W.ContainsIdentities] :
W.RightFraction X Y := mk (𝟙 X) (W.id_mem X) f
variable {W}
/-- The right fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/
@[simps]
def ofInv (s : Y ⟶ X) (hs : W s) :
W.RightFraction X Y := mk s hs (𝟙 Y)
/-- If `φ : W.RightFraction X Y` and `L` is a functor which inverts `W`, this is the
induced morphism `L.obj X ⟶ L.obj Y` -/
noncomputable def map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.obj X ⟶ L.obj Y :=
have := hL _ φ.hs
inv (L.map φ.s) ≫ L.map φ.f
@[reassoc (attr := simp)]
lemma map_s_comp_map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map φ.s ≫ φ.map L hL = L.map φ.f := by
letI := hL _ φ.hs
simp [map]
variable (W)
@[simp]
lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] :
(ofHom W f).map L hL = L.map f := by
simp [map]
@[reassoc (attr := simp)]
lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by
letI := hL _ hs
simp [map]
@[reassoc (attr := simp)]
lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by
letI := hL _ hs
simp [map]
variable {W}
lemma cases (α : W.RightFraction X Y) :
∃ (X' : C) (s : X' ⟶ X) (hs : W s) (f : X' ⟶ Y) , α = RightFraction.mk s hs f :=
⟨_, _, _, _, rfl⟩
end RightFraction
variable (W : MorphismProperty C)
/-- A multiplicative morphism property `W` has left calculus of fractions if
any right fraction can be turned into a left fraction and that two morphisms
that can be equalized by precomposition with a morphism in `W` can also
be equalized by postcomposition with a morphism in `W`. -/
class HasLeftCalculusOfFractions : Prop extends W.IsMultiplicative where
exists_leftFraction ⦃X Y : C⦄ (φ : W.RightFraction X Y) :
∃ (ψ : W.LeftFraction X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f
ext : ∀ ⦃X' X Y : C⦄ (f₁ f₂ : X ⟶ Y) (s : X' ⟶ X) (_ : W s)
(_ : s ≫ f₁ = s ≫ f₂), ∃ (Y' : C) (t : Y ⟶ Y') (_ : W t), f₁ ≫ t = f₂ ≫ t
/-- A multiplicative morphism property `W` has right calculus of fractions if
any left fraction can be turned into a right fraction and that two morphisms
that can be equalized by postcomposition with a morphism in `W` can also
be equalized by precomposition with a morphism in `W`. -/
class HasRightCalculusOfFractions : Prop extends W.IsMultiplicative where
exists_rightFraction ⦃X Y : C⦄ (φ : W.LeftFraction X Y) :
∃ (ψ : W.RightFraction X Y), ψ.s ≫ φ.f = ψ.f ≫ φ.s
ext : ∀ ⦃X Y Y' : C⦄ (f₁ f₂ : X ⟶ Y) (s : Y ⟶ Y') (_ : W s)
(_ : f₁ ≫ s = f₂ ≫ s), ∃ (X' : C) (t : X' ⟶ X) (_ : W t), t ≫ f₁ = t ≫ f₂
variable {W}
lemma RightFraction.exists_leftFraction [W.HasLeftCalculusOfFractions] {X Y : C}
(φ : W.RightFraction X Y) : ∃ (ψ : W.LeftFraction X Y), φ.f ≫ ψ.s = φ.s ≫ ψ.f :=
HasLeftCalculusOfFractions.exists_leftFraction φ
/-- A choice of a left fraction deduced from a right fraction for a morphism property `W`
when `W` has left calculus of fractions. -/
noncomputable def RightFraction.leftFraction [W.HasLeftCalculusOfFractions] {X Y : C}
(φ : W.RightFraction X Y) : W.LeftFraction X Y :=
φ.exists_leftFraction.choose
@[reassoc]
lemma RightFraction.leftFraction_fac [W.HasLeftCalculusOfFractions] {X Y : C}
(φ : W.RightFraction X Y) : φ.f ≫ φ.leftFraction.s = φ.s ≫ φ.leftFraction.f :=
φ.exists_leftFraction.choose_spec
lemma LeftFraction.exists_rightFraction [W.HasRightCalculusOfFractions] {X Y : C}
(φ : W.LeftFraction X Y) : ∃ (ψ : W.RightFraction X Y), ψ.s ≫ φ.f = ψ.f ≫ φ.s :=
HasRightCalculusOfFractions.exists_rightFraction φ
/-- A choice of a right fraction deduced from a left fraction for a morphism property `W`
when `W` has right calculus of fractions. -/
noncomputable def LeftFraction.rightFraction [W.HasRightCalculusOfFractions] {X Y : C}
(φ : W.LeftFraction X Y) : W.RightFraction X Y :=
φ.exists_rightFraction.choose
@[reassoc]
lemma LeftFraction.rightFraction_fac [W.HasRightCalculusOfFractions] {X Y : C}
(φ : W.LeftFraction X Y) : φ.rightFraction.s ≫ φ.f = φ.rightFraction.f ≫ φ.s :=
φ.exists_rightFraction.choose_spec
/-- The equivalence relation on left fractions for a morphism property `W`. -/
def LeftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) : Prop :=
∃ (Z : C) (t₁ : z₁.Y' ⟶ Z) (t₂ : z₂.Y' ⟶ Z) (_ : z₁.s ≫ t₁ = z₂.s ≫ t₂)
(_ : z₁.f ≫ t₁ = z₂.f ≫ t₂), W (z₁.s ≫ t₁)
namespace LeftFractionRel
lemma refl {X Y : C} (z : W.LeftFraction X Y) : LeftFractionRel z z :=
⟨z.Y', 𝟙 _, 𝟙 _, rfl, rfl, by simpa only [Category.comp_id] using z.hs⟩
lemma symm {X Y : C} {z₁ z₂ : W.LeftFraction X Y} (h : LeftFractionRel z₁ z₂) :
LeftFractionRel z₂ z₁ := by
obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h
exact ⟨Z, t₂, t₁, hst.symm, hft.symm, by simpa only [← hst] using ht⟩
lemma trans {X Y : C} {z₁ z₂ z₃ : W.LeftFraction X Y}
[HasLeftCalculusOfFractions W]
(h₁₂ : LeftFractionRel z₁ z₂) (h₂₃ : LeftFractionRel z₂ z₃) :
LeftFractionRel z₁ z₃ := by
obtain ⟨Z₄, t₁, t₂, hst, hft, ht⟩ := h₁₂
obtain ⟨Z₅, u₂, u₃, hsu, hfu, hu⟩ := h₂₃
obtain ⟨⟨v₄, v₅, hv₅⟩, fac⟩ := HasLeftCalculusOfFractions.exists_leftFraction
(RightFraction.mk (z₁.s ≫ t₁) ht (z₃.s ≫ u₃))
simp only [Category.assoc] at fac
have eq : z₂.s ≫ u₂ ≫ v₅ = z₂.s ≫ t₂ ≫ v₄ := by
simpa only [← reassoc_of% hsu, reassoc_of% hst] using fac
obtain ⟨Z₇, w, hw, fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ z₂.hs eq
simp only [Category.assoc] at fac'
refine ⟨Z₇, t₁ ≫ v₄ ≫ w, u₃ ≫ v₅ ≫ w, ?_, ?_, ?_⟩
· rw [reassoc_of% fac]
· rw [reassoc_of% hft, ← fac', reassoc_of% hfu]
· rw [← reassoc_of% fac, ← reassoc_of% hsu, ← Category.assoc]
exact W.comp_mem _ _ hu (W.comp_mem _ _ hv₅ hw)
end LeftFractionRel
section
variable (W)
lemma equivalenceLeftFractionRel [W.HasLeftCalculusOfFractions] (X Y : C) :
@_root_.Equivalence (W.LeftFraction X Y) LeftFractionRel where
refl := LeftFractionRel.refl
symm := LeftFractionRel.symm
trans := LeftFractionRel.trans
variable {W}
namespace LeftFraction
open HasLeftCalculusOfFractions
/-- Auxiliary definition for the composition of left fractions. -/
@[simp]
def comp₀ [W.HasLeftCalculusOfFractions] {X Y Z : C}
(z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) (z₃ : W.LeftFraction z₁.Y' z₂.Y') :
W.LeftFraction X Z :=
mk (z₁.f ≫ z₃.f) (z₂.s ≫ z₃.s) (W.comp_mem _ _ z₂.hs z₃.hs)
/-- The equivalence class of `z₁.comp₀ z₂ z₃` does not depend on the choice of `z₃` provided
they satisfy the compatibility `z₂.f ≫ z₃.s = z₁.s ≫ z₃.f`. -/
lemma comp₀_rel [W.HasLeftCalculusOfFractions]
{X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ z₃' : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f)
(h₃' : z₂.f ≫ z₃'.s = z₁.s ≫ z₃'.f) :
LeftFractionRel (z₁.comp₀ z₂ z₃) (z₁.comp₀ z₂ z₃') := by
obtain ⟨z₄, fac⟩ := exists_leftFraction (RightFraction.mk z₃.s z₃.hs z₃'.s)
dsimp at fac
have eq : z₁.s ≫ z₃.f ≫ z₄.f = z₁.s ≫ z₃'.f ≫ z₄.s := by
rw [← reassoc_of% h₃, ← reassoc_of% h₃', fac]
obtain ⟨Y, t, ht, fac'⟩ := HasLeftCalculusOfFractions.ext _ _ _ z₁.hs eq
simp only [assoc] at fac'
refine ⟨Y, z₄.f ≫ t, z₄.s ≫ t, ?_, ?_, ?_⟩
· simp only [comp₀, assoc, reassoc_of% fac]
· simp only [comp₀, assoc, fac']
· simp only [comp₀, assoc, ← reassoc_of% fac]
exact W.comp_mem _ _ z₂.hs (W.comp_mem _ _ z₃'.hs (W.comp_mem _ _ z₄.hs ht))
variable (W) in
/-- The morphisms in the constructed localized category for a morphism property `W`
that has left calculus of fractions are equivalence classes of left fractions. -/
def Localization.Hom (X Y : C) :=
Quot (LeftFractionRel : W.LeftFraction X Y → W.LeftFraction X Y → Prop)
/-- The morphism in the constructed localized category that is induced by a left fraction. -/
def Localization.Hom.mk {X Y : C} (z : W.LeftFraction X Y) : Localization.Hom W X Y :=
Quot.mk _ z
lemma Localization.Hom.mk_surjective {X Y : C} (f : Localization.Hom W X Y) :
∃ (z : W.LeftFraction X Y), f = mk z := by
obtain ⟨z⟩ := f
exact ⟨z, rfl⟩
variable [W.HasLeftCalculusOfFractions]
/-- Auxiliary definition towards the definition of the composition of morphisms
in the constructed localized category for a morphism property that has
left calculus of fractions. -/
noncomputable def comp
{X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) :
Localization.Hom W X Z :=
Localization.Hom.mk (z₁.comp₀ z₂ (RightFraction.mk z₁.s z₁.hs z₂.f).leftFraction)
lemma comp_eq {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) :
z₁.comp z₂ = Localization.Hom.mk (z₁.comp₀ z₂ z₃) :=
Quot.sound (LeftFraction.comp₀_rel _ _ _ _
(RightFraction.leftFraction_fac (RightFraction.mk z₁.s z₁.hs z₂.f)) h₃)
namespace Localization
/-- Composition of morphisms in the constructed localized category
for a morphism property that has left calculus of fractions. -/
noncomputable def Hom.comp {X Y Z : C} (z₁ : Hom W X Y) (z₂ : Hom W Y Z) : Hom W X Z := by
refine Quot.lift₂ (fun a b => a.comp b) ?_ ?_ z₁ z₂
· rintro a b₁ b₂ ⟨U, t₁, t₂, hst, hft, ht⟩
obtain ⟨z₁, fac₁⟩ := exists_leftFraction (RightFraction.mk a.s a.hs b₁.f)
obtain ⟨z₂, fac₂⟩ := exists_leftFraction (RightFraction.mk a.s a.hs b₂.f)
obtain ⟨w₁, fac₁'⟩ := exists_leftFraction (RightFraction.mk z₁.s z₁.hs t₁)
obtain ⟨w₂, fac₂'⟩ := exists_leftFraction (RightFraction.mk z₂.s z₂.hs t₂)
obtain ⟨u, fac₃⟩ := exists_leftFraction (RightFraction.mk w₁.s w₁.hs w₂.s)
dsimp at fac₁ fac₂ fac₁' fac₂' fac₃ ⊢
have eq : a.s ≫ z₁.f ≫ w₁.f ≫ u.f = a.s ≫ z₂.f ≫ w₂.f ≫ u.s := by
rw [← reassoc_of% fac₁, ← reassoc_of% fac₂, ← reassoc_of% fac₁', ← reassoc_of% fac₂',
reassoc_of% hft, fac₃]
obtain ⟨Z, p, hp, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a.hs eq
simp only [assoc] at fac₄
rw [comp_eq _ _ z₁ fac₁, comp_eq _ _ z₂ fac₂]
apply Quot.sound
refine ⟨Z, w₁.f ≫ u.f ≫ p, w₂.f ≫ u.s ≫ p, ?_, ?_, ?_⟩
· dsimp
simp only [assoc, ← reassoc_of% fac₁', ← reassoc_of% fac₂',
reassoc_of% hst, reassoc_of% fac₃]
· dsimp
simp only [assoc, fac₄]
· dsimp
simp only [assoc]
rw [← reassoc_of% fac₁', ← reassoc_of% fac₃, ← assoc]
exact W.comp_mem _ _ ht (W.comp_mem _ _ w₂.hs (W.comp_mem _ _ u.hs hp))
· rintro a₁ a₂ b ⟨U, t₁, t₂, hst, hft, ht⟩
obtain ⟨z₁, fac₁⟩ := exists_leftFraction (RightFraction.mk a₁.s a₁.hs b.f)
obtain ⟨z₂, fac₂⟩ := exists_leftFraction (RightFraction.mk a₂.s a₂.hs b.f)
obtain ⟨w₁, fac₁'⟩ := exists_leftFraction (RightFraction.mk (a₁.s ≫ t₁) ht (b.f ≫ z₁.s))
obtain ⟨w₂, fac₂'⟩ := exists_leftFraction (RightFraction.mk (a₂.s ≫ t₂)
(show W _ by rw [← hst]; exact ht) (b.f ≫ z₂.s))
let p₁ : W.LeftFraction X Z := LeftFraction.mk (a₁.f ≫ t₁ ≫ w₁.f) (b.s ≫ z₁.s ≫ w₁.s)
(W.comp_mem _ _ b.hs (W.comp_mem _ _ z₁.hs w₁.hs))
let p₂ : W.LeftFraction X Z := LeftFraction.mk (a₂.f ≫ t₂ ≫ w₂.f) (b.s ≫ z₂.s ≫ w₂.s)
(W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs w₂.hs))
dsimp at fac₁ fac₂ fac₁' fac₂' ⊢
simp only [assoc] at fac₁' fac₂'
rw [comp_eq _ _ z₁ fac₁, comp_eq _ _ z₂ fac₂]
apply Quot.sound
refine LeftFractionRel.trans ?_ ((?_ : LeftFractionRel p₁ p₂).trans ?_)
· have eq : a₁.s ≫ z₁.f ≫ w₁.s = a₁.s ≫ t₁ ≫ w₁.f := by rw [← fac₁', reassoc_of% fac₁]
obtain ⟨Z, u, hu, fac₃⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₁.hs eq
simp only [assoc] at fac₃
refine ⟨Z, w₁.s ≫ u, u, ?_, ?_, ?_⟩
· dsimp [p₁]
simp only [assoc]
· dsimp [p₁]
simp only [assoc, fac₃]
· dsimp
simp only [assoc]
exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₁.hs (W.comp_mem _ _ w₁.hs hu))
· obtain ⟨q, fac₃⟩ := exists_leftFraction (RightFraction.mk (z₁.s ≫ w₁.s)
(W.comp_mem _ _ z₁.hs w₁.hs) (z₂.s ≫ w₂.s))
dsimp at fac₃
simp only [assoc] at fac₃
have eq : a₁.s ≫ t₁ ≫ w₁.f ≫ q.f = a₁.s ≫ t₁ ≫ w₂.f ≫ q.s := by
rw [← reassoc_of% fac₁', ← fac₃, reassoc_of% hst, reassoc_of% fac₂']
obtain ⟨Z, u, hu, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₁.hs eq
simp only [assoc] at fac₄
refine ⟨Z, q.f ≫ u, q.s ≫ u, ?_, ?_, ?_⟩
· simp only [p₁, p₂, assoc, reassoc_of% fac₃]
· rw [assoc, assoc, assoc, assoc, fac₄, reassoc_of% hft]
· simp only [p₁, p₂, assoc, ← reassoc_of% fac₃]
exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs
(W.comp_mem _ _ w₂.hs (W.comp_mem _ _ q.hs hu)))
· have eq : a₂.s ≫ z₂.f ≫ w₂.s = a₂.s ≫ t₂ ≫ w₂.f := by
rw [← fac₂', reassoc_of% fac₂]
obtain ⟨Z, u, hu, fac₄⟩ := HasLeftCalculusOfFractions.ext _ _ _ a₂.hs eq
simp only [assoc] at fac₄
refine ⟨Z, u, w₂.s ≫ u, ?_, ?_, ?_⟩
· dsimp [p₁, p₂]
simp only [assoc]
· dsimp [p₁, p₂]
simp only [assoc, fac₄]
· dsimp [p₁, p₂]
simp only [assoc]
exact W.comp_mem _ _ b.hs (W.comp_mem _ _ z₂.hs (W.comp_mem _ _ w₂.hs hu))
lemma Hom.comp_eq {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z) :
Hom.comp (mk z₁) (mk z₂) = z₁.comp z₂ := rfl
end Localization
/-- The constructed localized category for a morphism property
that has left calculus of fractions. -/
@[nolint unusedArguments]
def Localization (_ : MorphismProperty C) := C
namespace Localization
noncomputable instance : Category (Localization W) where
Hom X Y := Localization.Hom W X Y
id _ := Localization.Hom.mk (ofHom W (𝟙 _))
comp f g := f.comp g
comp_id := by
rintro (X Y : C) f
obtain ⟨z, rfl⟩ := Hom.mk_surjective f
change (Hom.mk z).comp (Hom.mk (ofHom W (𝟙 Y))) = Hom.mk z
rw [Hom.comp_eq, comp_eq z (ofHom W (𝟙 Y)) (ofInv z.s z.hs) (by simp)]
dsimp [comp₀]
simp only [comp_id, id_comp]
id_comp := by
rintro (X Y : C) f
obtain ⟨z, rfl⟩ := Hom.mk_surjective f
change (Hom.mk (ofHom W (𝟙 X))).comp (Hom.mk z) = Hom.mk z
rw [Hom.comp_eq, comp_eq (ofHom W (𝟙 X)) z (ofHom W z.f) (by simp)]
dsimp
simp only [comp₀, id_comp, comp_id]
assoc := by
rintro (X₁ X₂ X₃ X₄ : C) f₁ f₂ f₃
obtain ⟨z₁, rfl⟩ := Hom.mk_surjective f₁
obtain ⟨z₂, rfl⟩ := Hom.mk_surjective f₂
obtain ⟨z₃, rfl⟩ := Hom.mk_surjective f₃
change ((Hom.mk z₁).comp (Hom.mk z₂)).comp (Hom.mk z₃) =
(Hom.mk z₁).comp ((Hom.mk z₂).comp (Hom.mk z₃))
rw [Hom.comp_eq z₁ z₂, Hom.comp_eq z₂ z₃]
obtain ⟨z₁₂, fac₁₂⟩ := exists_leftFraction (RightFraction.mk z₁.s z₁.hs z₂.f)
obtain ⟨z₂₃, fac₂₃⟩ := exists_leftFraction (RightFraction.mk z₂.s z₂.hs z₃.f)
obtain ⟨z', fac⟩ := exists_leftFraction (RightFraction.mk z₁₂.s z₁₂.hs z₂₃.f)
dsimp at fac₁₂ fac₂₃ fac
rw [comp_eq z₁ z₂ z₁₂ fac₁₂, comp_eq z₂ z₃ z₂₃ fac₂₃, comp₀, comp₀,
Hom.comp_eq, Hom.comp_eq,
comp_eq _ z₃ (mk z'.f (z₂₃.s ≫ z'.s) (W.comp_mem _ _ z₂₃.hs z'.hs))
(by dsimp; rw [assoc, reassoc_of% fac₂₃, fac]),
comp_eq z₁ _ (mk (z₁₂.f ≫ z'.f) z'.s z'.hs)
(by dsimp; rw [assoc, ← reassoc_of% fac₁₂, fac])]
simp
variable (W) in
/-- The localization functor to the constructed localized category for a morphism property
that has left calculus of fractions. -/
@[simps obj]
def Q : C ⥤ Localization W where
obj X := X
map f := Hom.mk (ofHom W f)
map_id _ := rfl
map_comp {X Y Z} f g := by
change _ = Hom.comp _ _
rw [Hom.comp_eq, comp_eq (ofHom W f) (ofHom W g) (ofHom W g) (by simp)]
simp only [ofHom, comp₀, comp_id]
/-- The morphism on `Localization W` that is induced by a left fraction. -/
abbrev homMk {X Y : C} (f : W.LeftFraction X Y) : (Q W).obj X ⟶ (Q W).obj Y := Hom.mk f
lemma homMk_eq_hom_mk {X Y : C} (f : W.LeftFraction X Y) : homMk f = Hom.mk f := rfl
variable (W)
lemma Q_map {X Y : C} (f : X ⟶ Y) : (Q W).map f = homMk (ofHom W f) := rfl
variable {W}
lemma homMk_comp_homMk {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f) :
homMk z₁ ≫ homMk z₂ = homMk (z₁.comp₀ z₂ z₃) := by
change Hom.comp _ _ = _
rw [Hom.comp_eq, comp_eq z₁ z₂ z₃ h₃]
lemma homMk_eq_of_leftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y)
(h : LeftFractionRel z₁ z₂) :
homMk z₁ = homMk z₂ :=
Quot.sound h
lemma homMk_eq_iff_leftFractionRel {X Y : C} (z₁ z₂ : W.LeftFraction X Y) :
homMk z₁ = homMk z₂ ↔ LeftFractionRel z₁ z₂ :=
@Equivalence.quot_mk_eq_iff _ _ (equivalenceLeftFractionRel W X Y) _ _
/-- The morphism in `Localization W` that is the formal inverse of a morphism
which belongs to `W`. -/
def Qinv {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).obj Y ⟶ (Q W).obj X := homMk (ofInv s hs)
lemma Q_map_comp_Qinv {X Y Y' : C} (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s) :
(Q W).map f ≫ Qinv s hs = homMk (mk f s hs) := by
dsimp only [Q_map, Qinv]
rw [homMk_comp_homMk (ofHom W f) (ofInv s hs) (ofHom W (𝟙 _)) (by simp)]
simp
/-- The isomorphism in `Localization W` that is induced by a morphism in `W`. -/
@[simps]
def Qiso {X Y : C} (s : X ⟶ Y) (hs : W s) : (Q W).obj X ≅ (Q W).obj Y where
hom := (Q W).map s
inv := Qinv s hs
hom_inv_id := by
rw [Q_map_comp_Qinv]
apply homMk_eq_of_leftFractionRel
exact ⟨_, 𝟙 Y, s, by simp, by simp, by simpa using hs⟩
inv_hom_id := by
dsimp only [Qinv, Q_map]
rw [homMk_comp_homMk (ofInv s hs) (ofHom W s) (ofHom W (𝟙 Y)) (by simp)]
apply homMk_eq_of_leftFractionRel
exact ⟨_, 𝟙 Y, 𝟙 Y, by simp, by simp, by simpa using W.id_mem Y⟩
@[reassoc (attr := simp)]
lemma Qiso_hom_inv_id {X Y : C} (s : X ⟶ Y) (hs : W s) :
(Q W).map s ≫ Qinv s hs = 𝟙 _ := (Qiso s hs).hom_inv_id
@[reassoc (attr := simp)]
lemma Qiso_inv_hom_id {X Y : C} (s : X ⟶ Y) (hs : W s) :
Qinv s hs ≫ (Q W).map s = 𝟙 _ := (Qiso s hs).inv_hom_id
instance {X Y : C} (s : X ⟶ Y) (hs : W s) : IsIso (Qinv s hs) :=
(inferInstance : IsIso (Qiso s hs).inv)
section
variable {E : Type*} [Category E]
/-- The image by a functor which inverts `W` of an equivalence class of left fractions. -/
noncomputable def Hom.map {X Y : C} (f : Hom W X Y) (F : C ⥤ E) (hF : W.IsInvertedBy F) :
F.obj X ⟶ F.obj Y :=
Quot.lift (fun f => f.map F hF) (by
intro a₁ a₂ ⟨Z, t₁, t₂, hst, hft, h⟩
dsimp
have := hF _ h
rw [← cancel_mono (F.map (a₁.s ≫ t₁)), F.map_comp, map_comp_map_s_assoc,
← F.map_comp, ← F.map_comp, hst, hft, F.map_comp,
F.map_comp, map_comp_map_s_assoc]) f
@[simp]
lemma Hom.map_mk {W} {X Y : C} (f : LeftFraction W X Y)
(F : C ⥤ E) (hF : W.IsInvertedBy F) :
Hom.map (Hom.mk f) F hF = f.map F hF := rfl
namespace StrictUniversalPropertyFixedTarget
variable (W)
lemma inverts : W.IsInvertedBy (Q W) := fun _ _ s hs =>
(inferInstance : IsIso (Qiso s hs).hom)
variable {W}
/-- The functor `Localization W ⥤ E` that is induced by a functor `C ⥤ E` which inverts `W`,
when `W` has a left calculus of fractions. -/
noncomputable def lift (F : C ⥤ E) (hF : W.IsInvertedBy F) :
Localization W ⥤ E where
obj X := F.obj X
map {_ _ : C} f := f.map F hF
map_id := by
intro (X : C)
change (Hom.mk (ofHom W (𝟙 X))).map F hF = _
rw [Hom.map_mk, map_ofHom, F.map_id]
map_comp := by
rintro (X Y Z : C) f g
obtain ⟨f, rfl⟩ := Hom.mk_surjective f
obtain ⟨g, rfl⟩ := Hom.mk_surjective g
dsimp
obtain ⟨z, fac⟩ := HasLeftCalculusOfFractions.exists_leftFraction
(RightFraction.mk f.s f.hs g.f)
rw [homMk_comp_homMk f g z fac, Hom.map_mk]
dsimp at fac ⊢
have := hF _ g.hs
have := hF _ z.hs
rw [← cancel_mono (F.map g.s), assoc, map_comp_map_s,
← cancel_mono (F.map z.s), assoc, assoc, ← F.map_comp,
← F.map_comp, map_comp_map_s, fac]
dsimp
rw [F.map_comp, F.map_comp, map_comp_map_s_assoc]
lemma fac (F : C ⥤ E) (hF : W.IsInvertedBy F) : Q W ⋙ lift F hF = F :=
Functor.ext (fun _ => rfl) (fun X Y f => by
dsimp [lift]
rw [Q_map, Hom.map_mk, id_comp, comp_id, map_ofHom])
lemma uniq (F₁ F₂ : Localization W ⥤ E) (h : Q W ⋙ F₁ = Q W ⋙ F₂) : F₁ = F₂ :=
Functor.ext (fun X => Functor.congr_obj h X) (by
rintro (X Y : C) f
obtain ⟨f, rfl⟩ := Hom.mk_surjective f
rw [show Hom.mk f = homMk (mk f.f f.s f.hs) by rfl,
← Q_map_comp_Qinv f.f f.s f.hs, F₁.map_comp, F₂.map_comp, assoc]
erw [Functor.congr_hom h f.f]
rw [assoc, assoc]
congr 2
have := inverts W _ f.hs
rw [← cancel_epi (F₂.map ((Q W).map f.s)), ← F₂.map_comp_assoc,
Qiso_hom_inv_id, Functor.map_id, id_comp]
erw [Functor.congr_hom h.symm f.s]
dsimp
rw [assoc, assoc, eqToHom_trans_assoc, eqToHom_refl, id_comp, ← F₁.map_comp,
Qiso_hom_inv_id]
dsimp
rw [F₁.map_id, comp_id])
end StrictUniversalPropertyFixedTarget
variable (W)
open StrictUniversalPropertyFixedTarget in
/-- The universal property of the localization for the constructed localized category
when there is a left calculus of fractions. -/
noncomputable def strictUniversalPropertyFixedTarget (E : Type*) [Category E] :
Localization.StrictUniversalPropertyFixedTarget (Q W) W E where
inverts := inverts W
lift := lift
fac := fac
uniq := uniq
instance : (Q W).IsLocalization W :=
Functor.IsLocalization.mk' _ _
(strictUniversalPropertyFixedTarget W _)
(strictUniversalPropertyFixedTarget W _)
end
lemma homMk_eq {X Y : C} (f : LeftFraction W X Y) :
homMk f = f.map (Q W) (Localization.inverts _ W) := by
have := Localization.inverts (Q W) W f.s f.hs
rw [← Q_map_comp_Qinv f.f f.s f.hs, ← cancel_mono ((Q W).map f.s),
assoc, Qiso_inv_hom_id, comp_id, map_comp_map_s]
lemma map_eq_iff {X Y : C} (f g : LeftFraction W X Y) :
f.map (LeftFraction.Localization.Q W) (Localization.inverts _ _) =
g.map (LeftFraction.Localization.Q W) (Localization.inverts _ _) ↔
LeftFractionRel f g := by
simp only [← Hom.map_mk _ (Q W)]
constructor
· intro h
rw [← homMk_eq_iff_leftFractionRel, homMk_eq, homMk_eq]
exact h
· intro h
congr 1
exact Quot.sound h
end Localization
section
lemma map_eq {W} {X Y : C} (φ : W.LeftFraction X Y) (L : C ⥤ D) [L.IsLocalization W] :
φ.map L (Localization.inverts L W) =
L.map φ.f ≫ (Localization.isoOfHom L W φ.s φ.hs).inv := rfl
lemma map_compatibility {W} {X Y : C}
(φ : W.LeftFraction X Y) {E : Type*} [Category E]
(L₁ : C ⥤ D) (L₂ : C ⥤ E) [L₁.IsLocalization W] [L₂.IsLocalization W] :
(Localization.uniq L₁ L₂ W).functor.map (φ.map L₁ (Localization.inverts L₁ W)) =
(Localization.compUniqFunctor L₁ L₂ W).hom.app X ≫
φ.map L₂ (Localization.inverts L₂ W) ≫
(Localization.compUniqFunctor L₁ L₂ W).inv.app Y := by
let e := Localization.compUniqFunctor L₁ L₂ W
have := Localization.inverts L₂ W φ.s φ.hs
rw [← cancel_mono (e.hom.app Y), assoc, assoc, e.inv_hom_id_app, comp_id,
← cancel_mono (L₂.map φ.s), assoc, assoc, map_comp_map_s, ← e.hom.naturality]
simpa [← Functor.map_comp_assoc, map_comp_map_s] using e.hom.naturality φ.f
lemma map_eq_of_map_eq {W} {X Y : C}
(φ₁ φ₂ : W.LeftFraction X Y) {E : Type*} [Category E]
(L₁ : C ⥤ D) (L₂ : C ⥤ E) [L₁.IsLocalization W] [L₂.IsLocalization W]
(h : φ₁.map L₁ (Localization.inverts L₁ W) = φ₂.map L₁ (Localization.inverts L₁ W)) :
φ₁.map L₂ (Localization.inverts L₂ W) = φ₂.map L₂ (Localization.inverts L₂ W) := by
apply (Localization.uniq L₂ L₁ W).functor.map_injective
rw [map_compatibility φ₁ L₂ L₁, map_compatibility φ₂ L₂ L₁, h]
lemma map_comp_map_eq_map {X Y Z : C} (z₁ : W.LeftFraction X Y) (z₂ : W.LeftFraction Y Z)
(z₃ : W.LeftFraction z₁.Y' z₂.Y') (h₃ : z₂.f ≫ z₃.s = z₁.s ≫ z₃.f)
(L : C ⥤ D) [L.IsLocalization W] :
z₁.map L (Localization.inverts L W) ≫ z₂.map L (Localization.inverts L W) =
(z₁.comp₀ z₂ z₃).map L (Localization.inverts L W) := by
have := Localization.inverts L W _ z₂.hs
have := Localization.inverts L W _ z₃.hs
have : IsIso (L.map (z₂.s ≫ z₃.s)) := by
rw [L.map_comp]
infer_instance
dsimp [LeftFraction.comp₀]
rw [← cancel_mono (L.map (z₂.s ≫ z₃.s)), map_comp_map_s,
L.map_comp, assoc, map_comp_map_s_assoc, ← L.map_comp, h₃,
L.map_comp, map_comp_map_s_assoc, L.map_comp]
end
end LeftFraction
end
end MorphismProperty
variable (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W]
section
variable [W.HasLeftCalculusOfFractions]
lemma Localization.exists_leftFraction {X Y : C} (f : L.obj X ⟶ L.obj Y) :
∃ (φ : W.LeftFraction X Y), f = φ.map L (Localization.inverts L W) := by
let E := Localization.uniq (MorphismProperty.LeftFraction.Localization.Q W) L W
let e : _ ⋙ E.functor ≅ L := Localization.compUniqFunctor _ _ _
obtain ⟨f', rfl⟩ : ∃ (f' : E.functor.obj X ⟶ E.functor.obj Y),
f = e.inv.app _ ≫ f' ≫ e.hom.app _ := ⟨e.hom.app _ ≫ f ≫ e.inv.app _, by simp⟩
obtain ⟨g, rfl⟩ := E.functor.map_surjective f'
obtain ⟨g, rfl⟩ := MorphismProperty.LeftFraction.Localization.Hom.mk_surjective g
refine ⟨g, ?_⟩
rw [← MorphismProperty.LeftFraction.Localization.homMk_eq_hom_mk,
MorphismProperty.LeftFraction.Localization.homMk_eq g,
g.map_compatibility (MorphismProperty.LeftFraction.Localization.Q W) L,
assoc, assoc, Iso.inv_hom_id_app, comp_id, Iso.inv_hom_id_app_assoc]
lemma MorphismProperty.LeftFraction.map_eq_iff
{X Y : C} (φ ψ : W.LeftFraction X Y) :
φ.map L (Localization.inverts _ _) = ψ.map L (Localization.inverts _ _) ↔
LeftFractionRel φ ψ := by
constructor
· intro h
rw [← MorphismProperty.LeftFraction.Localization.map_eq_iff]
apply map_eq_of_map_eq _ _ _ _ h
· intro h
simp only [← Localization.Hom.map_mk _ L (Localization.inverts _ _)]
congr 1
exact Quot.sound h
lemma MorphismProperty.map_eq_iff_postcomp {X Y : C} (f₁ f₂ : X ⟶ Y) :
L.map f₁ = L.map f₂ ↔ ∃ (Z : C) (s : Y ⟶ Z) (_ : W s), f₁ ≫ s = f₂ ≫ s := by
constructor
· intro h
rw [← LeftFraction.map_ofHom W _ L (Localization.inverts _ _),
← LeftFraction.map_ofHom W _ L (Localization.inverts _ _),
LeftFraction.map_eq_iff] at h
obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h
dsimp at t₁ t₂ hst hft ht
simp only [id_comp] at hst
exact ⟨Z, t₁, by simpa using ht, by rw [hft, hst]⟩
· rintro ⟨Z, s, hs, fac⟩
simp only [← cancel_mono (Localization.isoOfHom L W s hs).hom,
Localization.isoOfHom_hom, ← L.map_comp, fac]
include W in
lemma Localization.essSurj_mapArrow :
L.mapArrow.EssSurj where
mem_essImage f := by
have := Localization.essSurj L W
obtain ⟨X, ⟨eX⟩⟩ : ∃ (X : C), Nonempty (L.obj X ≅ f.left) :=
⟨_, ⟨L.objObjPreimageIso f.left⟩⟩
obtain ⟨Y, ⟨eY⟩⟩ : ∃ (Y : C), Nonempty (L.obj Y ≅ f.right) :=
⟨_, ⟨L.objObjPreimageIso f.right⟩⟩
obtain ⟨φ, hφ⟩ := Localization.exists_leftFraction L W (eX.hom ≫ f.hom ≫ eY.inv)
refine ⟨Arrow.mk φ.f, ⟨Iso.symm ?_⟩⟩
refine Arrow.isoMk eX.symm (eY.symm ≪≫ Localization.isoOfHom L W φ.s φ.hs) ?_
dsimp
simp only [← cancel_epi eX.hom, Iso.hom_inv_id_assoc, reassoc_of% hφ,
MorphismProperty.LeftFraction.map_comp_map_s]
end
namespace MorphismProperty
variable {W}
/-- The right fraction in the opposite category corresponding to a left fraction. -/
@[simps]
def LeftFraction.op {X Y : C} (φ : W.LeftFraction X Y) :
W.op.RightFraction (Opposite.op Y) (Opposite.op X) where
X' := Opposite.op φ.Y'
s := φ.s.op
hs := φ.hs
f := φ.f.op
/-- The left fraction in the opposite category corresponding to a right fraction. -/
@[simps]
def RightFraction.op {X Y : C} (φ : W.RightFraction X Y) :
W.op.LeftFraction (Opposite.op Y) (Opposite.op X) where
Y' := Opposite.op φ.X'
s := φ.s.op
hs := φ.hs
f := φ.f.op
/-- The right fraction corresponding to a left fraction in the opposite category. -/
@[simps]
def LeftFraction.unop {W : MorphismProperty Cᵒᵖ}
{X Y : Cᵒᵖ} (φ : W.LeftFraction X Y) :
W.unop.RightFraction (Opposite.unop Y) (Opposite.unop X) where
X' := Opposite.unop φ.Y'
s := φ.s.unop
hs := φ.hs
f := φ.f.unop
/-- The left fraction corresponding to a right fraction in the opposite category. -/
@[simps]
def RightFraction.unop {W : MorphismProperty Cᵒᵖ}
{X Y : Cᵒᵖ} (φ : W.RightFraction X Y) :
W.unop.LeftFraction (Opposite.unop Y) (Opposite.unop X) where
Y' := Opposite.unop φ.X'
s := φ.s.unop
hs := φ.hs
f := φ.f.unop
lemma RightFraction.op_map
{X Y : C} (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(φ.map L hL).op = φ.op.map L.op hL.op := by
dsimp [map, LeftFraction.map]
rw [op_inv]
lemma LeftFraction.op_map
{X Y : C} (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) :
(φ.map L hL).op = φ.op.map L.op hL.op := by
dsimp [map, RightFraction.map]
rw [op_inv]
instance [h : W.HasLeftCalculusOfFractions] : W.op.HasRightCalculusOfFractions where
exists_rightFraction X Y φ := by
obtain ⟨ψ, eq⟩ := h.exists_leftFraction φ.unop
exact ⟨ψ.op, Quiver.Hom.unop_inj eq⟩
ext X Y Y' f₁ f₂ s hs eq := by
obtain ⟨X', t, ht, fac⟩ := h.ext f₁.unop f₂.unop s.unop hs (Quiver.Hom.op_inj eq)
exact ⟨Opposite.op X', t.op, ht, Quiver.Hom.unop_inj fac⟩
instance [h : W.HasRightCalculusOfFractions] : W.op.HasLeftCalculusOfFractions where
exists_leftFraction X Y φ := by
obtain ⟨ψ, eq⟩ := h.exists_rightFraction φ.unop
exact ⟨ψ.op, Quiver.Hom.unop_inj eq⟩
ext X' X Y f₁ f₂ s hs eq := by
obtain ⟨Y', t, ht, fac⟩ := h.ext f₁.unop f₂.unop s.unop hs (Quiver.Hom.op_inj eq)
exact ⟨Opposite.op Y', t.op, ht, Quiver.Hom.unop_inj fac⟩
instance (W : MorphismProperty Cᵒᵖ) [h : W.HasLeftCalculusOfFractions] :
W.unop.HasRightCalculusOfFractions where
exists_rightFraction X Y φ := by
obtain ⟨ψ, eq⟩ := h.exists_leftFraction φ.op
exact ⟨ψ.unop, Quiver.Hom.op_inj eq⟩
ext X Y Y' f₁ f₂ s hs eq := by
obtain ⟨X', t, ht, fac⟩ := h.ext f₁.op f₂.op s.op hs (Quiver.Hom.unop_inj eq)
exact ⟨Opposite.unop X', t.unop, ht, Quiver.Hom.op_inj fac⟩
instance (W : MorphismProperty Cᵒᵖ) [h : W.HasRightCalculusOfFractions] :
W.unop.HasLeftCalculusOfFractions where
exists_leftFraction X Y φ := by
obtain ⟨ψ, eq⟩ := h.exists_rightFraction φ.op
exact ⟨ψ.unop, Quiver.Hom.op_inj eq⟩
ext X' X Y f₁ f₂ s hs eq := by
obtain ⟨Y', t, ht, fac⟩ := h.ext f₁.op f₂.op s.op hs (Quiver.Hom.unop_inj eq)
exact ⟨Opposite.unop Y', t.unop, ht, Quiver.Hom.op_inj fac⟩
/-- The equivalence relation on right fractions for a morphism property `W`. -/
def RightFractionRel {X Y : C} (z₁ z₂ : W.RightFraction X Y) : Prop :=
∃ (Z : C) (t₁ : Z ⟶ z₁.X') (t₂ : Z ⟶ z₂.X') (_ : t₁ ≫ z₁.s = t₂ ≫ z₂.s)
(_ : t₁ ≫ z₁.f = t₂ ≫ z₂.f), W (t₁ ≫ z₁.s)
lemma RightFractionRel.op {X Y : C} {z₁ z₂ : W.RightFraction X Y}
(h : RightFractionRel z₁ z₂) : LeftFractionRel z₁.op z₂.op := by
obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h
exact ⟨Opposite.op Z, t₁.op, t₂.op, Quiver.Hom.unop_inj hs,
Quiver.Hom.unop_inj hf, ht⟩
lemma RightFractionRel.unop {W : MorphismProperty Cᵒᵖ} {X Y : Cᵒᵖ}
{z₁ z₂ : W.RightFraction X Y}
(h : RightFractionRel z₁ z₂) : LeftFractionRel z₁.unop z₂.unop := by
obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h
exact ⟨Opposite.unop Z, t₁.unop, t₂.unop, Quiver.Hom.op_inj hs,
Quiver.Hom.op_inj hf, ht⟩
lemma LeftFractionRel.op {X Y : C} {z₁ z₂ : W.LeftFraction X Y}
(h : LeftFractionRel z₁ z₂) : RightFractionRel z₁.op z₂.op := by
obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h
exact ⟨Opposite.op Z, t₁.op, t₂.op, Quiver.Hom.unop_inj hs,
Quiver.Hom.unop_inj hf, ht⟩
lemma LeftFractionRel.unop {W : MorphismProperty Cᵒᵖ} {X Y : Cᵒᵖ}
{z₁ z₂ : W.LeftFraction X Y}
(h : LeftFractionRel z₁ z₂) : RightFractionRel z₁.unop z₂.unop := by
obtain ⟨Z, t₁, t₂, hs, hf, ht⟩ := h
exact ⟨Opposite.unop Z, t₁.unop, t₂.unop, Quiver.Hom.op_inj hs,
Quiver.Hom.op_inj hf, ht⟩
lemma leftFractionRel_op_iff
{X Y : C} (z₁ z₂ : W.RightFraction X Y) :
LeftFractionRel z₁.op z₂.op ↔ RightFractionRel z₁ z₂ :=
⟨fun h => h.unop, fun h => h.op⟩
lemma rightFractionRel_op_iff
{X Y : C} (z₁ z₂ : W.LeftFraction X Y) :
RightFractionRel z₁.op z₂.op ↔ LeftFractionRel z₁ z₂ :=
⟨fun h => h.unop, fun h => h.op⟩
namespace RightFractionRel
lemma refl {X Y : C} (z : W.RightFraction X Y) : RightFractionRel z z :=
(LeftFractionRel.refl z.op).unop
lemma symm {X Y : C} {z₁ z₂ : W.RightFraction X Y} (h : RightFractionRel z₁ z₂) :
RightFractionRel z₂ z₁ :=
h.op.symm.unop
lemma trans {X Y : C} {z₁ z₂ z₃ : W.RightFraction X Y}
[HasRightCalculusOfFractions W]
(h₁₂ : RightFractionRel z₁ z₂) (h₂₃ : RightFractionRel z₂ z₃) :
RightFractionRel z₁ z₃ :=
(h₁₂.op.trans h₂₃.op).unop
end RightFractionRel
lemma equivalenceRightFractionRel (X Y : C) [HasRightCalculusOfFractions W] :
@_root_.Equivalence (W.RightFraction X Y) RightFractionRel where
refl := RightFractionRel.refl
symm := RightFractionRel.symm
trans := RightFractionRel.trans
end MorphismProperty
section
variable [W.HasRightCalculusOfFractions]
lemma Localization.exists_rightFraction {X Y : C} (f : L.obj X ⟶ L.obj Y) :
∃ (φ : W.RightFraction X Y), f = φ.map L (Localization.inverts L W) := by
obtain ⟨φ, eq⟩ := Localization.exists_leftFraction L.op W.op f.op
refine ⟨φ.unop, Quiver.Hom.op_inj ?_⟩
rw [eq, MorphismProperty.RightFraction.op_map]
rfl
lemma MorphismProperty.RightFraction.map_eq_iff
{X Y : C} (φ ψ : W.RightFraction X Y) :
φ.map L (Localization.inverts _ _) = ψ.map L (Localization.inverts _ _) ↔
RightFractionRel φ ψ := by
rw [← leftFractionRel_op_iff, ← LeftFraction.map_eq_iff L.op W.op φ.op ψ.op,
← φ.op_map L (Localization.inverts _ _), ← ψ.op_map L (Localization.inverts _ _)]
constructor
· apply Quiver.Hom.unop_inj
· apply Quiver.Hom.op_inj
lemma MorphismProperty.map_eq_iff_precomp {Y Z : C} (f₁ f₂ : Y ⟶ Z) :
L.map f₁ = L.map f₂ ↔ ∃ (X : C) (s : X ⟶ Y) (_ : W s), s ≫ f₁ = s ≫ f₂ := by
constructor
· intro h
rw [← RightFraction.map_ofHom W _ L (Localization.inverts _ _),
← RightFraction.map_ofHom W _ L (Localization.inverts _ _),
RightFraction.map_eq_iff] at h
obtain ⟨Z, t₁, t₂, hst, hft, ht⟩ := h
dsimp at t₁ t₂ hst hft ht
simp only [comp_id] at hst
exact ⟨Z, t₁, by simpa using ht, by rw [hft, hst]⟩
· rintro ⟨Z, s, hs, fac⟩
simp only [← cancel_epi (Localization.isoOfHom L W s hs).hom,
Localization.isoOfHom_hom, ← L.map_comp, fac]
include W in
lemma Localization.essSurj_mapArrow_of_hasRightCalculusOfFractions :
| L.mapArrow.EssSurj where
mem_essImage f := by
have := Localization.essSurj_mapArrow L.op W.op
obtain ⟨g, ⟨e⟩⟩ : ∃ (g : _), Nonempty (L.op.mapArrow.obj g ≅ Arrow.mk f.hom.op) :=
⟨_, ⟨Functor.objObjPreimageIso _ _⟩⟩
exact ⟨Arrow.mk g.hom.unop, ⟨Arrow.isoMk (Arrow.rightFunc.mapIso e.symm).unop
(Arrow.leftFunc.mapIso e.symm).unop (Quiver.Hom.op_inj e.inv.w.symm)⟩⟩
| Mathlib/CategoryTheory/Localization/CalculusOfFractions.lean | 975 | 982 |
/-
Copyright (c) 2020 Kenji Nakagawa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio, Yongle Hu
-/
import Mathlib.RingTheory.DiscreteValuationRing.TFAE
import Mathlib.RingTheory.LocalProperties.IntegrallyClosed
/-!
# Dedekind domains
This file defines an equivalent notion of a Dedekind domain (or Dedekind ring),
namely a Noetherian integral domain where the localization at all nonzero prime ideals is a DVR.
## Main definitions
- `IsDedekindDomainDvr` alternatively defines a Dedekind domain as an integral domain that
is Noetherian, and the localization at every nonzero prime ideal is a DVR.
## Main results
- `IsLocalization.AtPrime.discreteValuationRing_of_dedekind_domain` shows that
`IsDedekindDomain` implies the localization at each nonzero prime ideal is a DVR.
- `IsDedekindDomain.isDedekindDomainDvr` is one direction of the equivalence of definitions
of a Dedekind domain
## Implementation notes
The definitions that involve a field of fractions choose a canonical field of fractions,
but are independent of that choice. The `..._iff` lemmas express this independence.
Often, definitions assume that Dedekind domains are not fields. We found it more practical
to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic]
* [J. Neukirch, *Algebraic Number Theory*][Neukirch1992]
## Tags
dedekind domain, dedekind ring
-/
variable (A : Type*) [CommRing A] [IsDomain A]
open scoped nonZeroDivisors Polynomial
/-- A Dedekind domain is an integral domain that is Noetherian, and the
localization at every nonzero prime is a discrete valuation ring.
This is equivalent to `IsDedekindDomain`.
-/
class IsDedekindDomainDvr : Prop extends IsNoetherian A A where
is_dvr_at_nonzero_prime : ∀ P ≠ (⊥ : Ideal A), ∀ _ : P.IsPrime,
IsDiscreteValuationRing (Localization.AtPrime P)
/-- Localizing a domain of Krull dimension `≤ 1` gives another ring of Krull dimension `≤ 1`.
Note that the same proof can/should be generalized to preserving any Krull dimension,
once we have a suitable definition.
-/
theorem Ring.DimensionLEOne.localization {R : Type*} (Rₘ : Type*) [CommRing R] [IsDomain R]
[CommRing Rₘ] [Algebra R Rₘ] {M : Submonoid R} [IsLocalization M Rₘ] (hM : M ≤ R⁰)
[h : Ring.DimensionLEOne R] : Ring.DimensionLEOne Rₘ := ⟨by
intro p hp0 hpp
refine Ideal.isMaximal_def.mpr ⟨hpp.ne_top, Ideal.maximal_of_no_maximal fun P hpP hPm => ?_⟩
have hpP' : (⟨p, hpp⟩ : { p : Ideal Rₘ // p.IsPrime }) < ⟨P, hPm.isPrime⟩ := hpP
rw [← (IsLocalization.orderIsoOfPrime M Rₘ).lt_iff_lt] at hpP'
haveI : Ideal.IsPrime (Ideal.comap (algebraMap R Rₘ) p) :=
((IsLocalization.orderIsoOfPrime M Rₘ) ⟨p, hpp⟩).2.1
haveI : Ideal.IsPrime (Ideal.comap (algebraMap R Rₘ) P) :=
((IsLocalization.orderIsoOfPrime M Rₘ) ⟨P, hPm.isPrime⟩).2.1
have hlt : Ideal.comap (algebraMap R Rₘ) p < Ideal.comap (algebraMap R Rₘ) P := hpP'
refine h.not_lt_lt ⊥ (Ideal.comap _ _) (Ideal.comap _ _) ⟨?_, hlt⟩
exact IsLocalization.bot_lt_comap_prime _ _ hM _ hp0⟩
/-- The localization of a Dedekind domain is a Dedekind domain. -/
theorem IsLocalization.isDedekindDomain [IsDedekindDomain A] {M : Submonoid A} (hM : M ≤ A⁰)
(Aₘ : Type*) [CommRing Aₘ] [IsDomain Aₘ] [Algebra A Aₘ] [IsLocalization M Aₘ] :
IsDedekindDomain Aₘ := by
have h : ∀ y : M, IsUnit (algebraMap A (FractionRing A) y) := by
rintro ⟨y, hy⟩
exact IsUnit.mk0 _ (mt IsFractionRing.to_map_eq_zero_iff.mp (nonZeroDivisors.ne_zero (hM hy)))
letI : Algebra Aₘ (FractionRing A) := RingHom.toAlgebra (IsLocalization.lift h)
haveI : IsScalarTower A Aₘ (FractionRing A) :=
| IsScalarTower.of_algebraMap_eq fun x => (IsLocalization.lift_eq h x).symm
haveI : IsFractionRing Aₘ (FractionRing A) :=
IsFractionRing.isFractionRing_of_isDomain_of_isLocalization M _ _
refine (isDedekindDomain_iff _ (FractionRing A)).mpr ⟨?_, ?_, ?_, ?_⟩
· infer_instance
· exact IsLocalization.isNoetherianRing M _ inferInstance
· exact Ring.DimensionLEOne.localization Aₘ hM
· intro x hx
obtain ⟨⟨y, y_mem⟩, hy⟩ := hx.exists_multiple_integral_of_isLocalization M _
obtain ⟨z, hz⟩ := (isIntegrallyClosed_iff _).mp IsDedekindRing.toIsIntegralClosure hy
refine ⟨IsLocalization.mk' Aₘ z ⟨y, y_mem⟩, (IsLocalization.lift_mk'_spec _ _ _ _).mpr ?_⟩
rw [hz, ← Algebra.smul_def]
rfl
/-- The localization of a Dedekind domain at every nonzero prime ideal is a Dedekind domain. -/
theorem IsLocalization.AtPrime.isDedekindDomain [IsDedekindDomain A] (P : Ideal A) [P.IsPrime]
(Aₘ : Type*) [CommRing Aₘ] [IsDomain Aₘ] [Algebra A Aₘ] [IsLocalization.AtPrime Aₘ P] :
IsDedekindDomain Aₘ :=
IsLocalization.isDedekindDomain A P.primeCompl_le_nonZeroDivisors Aₘ
instance Localization.AtPrime.isDedekindDomain [IsDedekindDomain A] (P : Ideal A) [P.IsPrime] :
| Mathlib/RingTheory/DedekindDomain/Dvr.lean | 88 | 108 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Kappelmann
-/
import Mathlib.Algebra.Order.Floor.Defs
import Mathlib.Algebra.Order.Floor.Ring
import Mathlib.Algebra.Order.Floor.Semiring
deprecated_module (since := "2025-04-13")
| Mathlib/Algebra/Order/Floor.lean | 1,399 | 1,401 | |
/-
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.Analytic.Linear
import Mathlib.Analysis.Analytic.Composition
import Mathlib.Analysis.Analytic.Constructions
import Mathlib.Analysis.Normed.Module.Completion
import Mathlib.Analysis.Analytic.ChangeOrigin
/-!
# Uniqueness principle for analytic functions
We show that two analytic functions which coincide around a point coincide on whole connected sets,
in `AnalyticOnNhd.eqOn_of_preconnected_of_eventuallyEq`.
-/
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
open Set
open scoped Topology ENNReal NNReal
/-!
### Uniqueness of power series
If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding
to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is,
for any `n : ℕ` and `y : E`, `p₁ n (fun i ↦ y) = p₂ n (fun i ↦ y)`. In the one-dimensional case,
when `f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by
`ContinuousMultilinearMap.mkPiRing`, and hence are determined completely by the value of
`p₁ n (fun i ↦ 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be
transferred to the other.
-/
section Uniqueness
open ContinuousMultilinearMap
theorem Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero {n : ℕ} {p : E [×n]→L[𝕜] F}
(h : (fun y => p fun _ => y) =O[𝓝 0] fun y => ‖y‖ ^ (n + 1)) (y : E) : (p fun _ => y) = 0 := by
obtain ⟨c, c_pos, hc⟩ := h.exists_pos
obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (isBigOWith_iff.mp hc)
obtain ⟨δ, δ_pos, δε⟩ := (Metric.isOpen_iff.mp t_open) 0 z_mem
clear h hc z_mem
rcases n with - | n
· exact norm_eq_zero.mp (by
simpa only [fin0_apply_norm, norm_eq_zero, norm_zero, zero_add, pow_one,
mul_zero, norm_le_zero_iff] using ht 0 (δε (Metric.mem_ball_self δ_pos)))
· refine Or.elim (Classical.em (y = 0))
(fun hy => by simpa only [hy] using p.map_zero) fun hy => ?_
replace hy := norm_pos_iff.mpr hy
refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add fun ε ε_pos => ?_) (norm_nonneg _))
have h₀ := _root_.mul_pos c_pos (pow_pos hy (n.succ + 1))
obtain ⟨k, k_pos, k_norm⟩ := NormedField.exists_norm_lt 𝕜
(lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀)))
have h₁ : ‖k • y‖ < δ := by
rw [norm_smul]
exact inv_mul_cancel_right₀ hy.ne.symm δ ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_left _ _)) hy
have h₂ :=
calc
‖p fun _ => k • y‖ ≤ c * ‖k • y‖ ^ (n.succ + 1) := by
-- Porting note: now Lean wants `_root_.`
simpa only [norm_pow, _root_.norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
--simpa only [norm_pow, norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
_ = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by
simp only [norm_smul, mul_pow]
ring
have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε :=
inv_mul_cancel_right₀ h₀.ne.symm ε ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀
calc
‖p fun _ => y‖ = ‖k⁻¹ ^ n.succ‖ * ‖p fun _ => k • y‖ := by
simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos), norm_smul, Finset.prod_const,
Finset.card_fin] using
congr_arg norm (p.map_smul_univ (fun _ : Fin n.succ => k⁻¹) fun _ : Fin n.succ => k • y)
_ ≤ ‖k⁻¹ ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))) := by gcongr
_ = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by
rw [← mul_assoc]
simp [norm_mul, mul_pow]
_ ≤ 0 + ε := by
rw [inv_mul_cancel₀ (norm_pos_iff.mp k_pos)]
simpa using h₃.le
/-- If a formal multilinear series `p` represents the zero function at `x : E`, then the
terms `p n (fun i ↦ y)` appearing in the sum are zero for any `n : ℕ`, `y : E`. -/
theorem HasFPowerSeriesAt.apply_eq_zero {p : FormalMultilinearSeries 𝕜 E F} {x : E}
(h : HasFPowerSeriesAt 0 p x) (n : ℕ) : ∀ y : E, (p n fun _ => y) = 0 := by
refine Nat.strong_induction_on n fun k hk => ?_
have psum_eq : p.partialSum (k + 1) = fun y => p k fun _ => y := by
funext z
refine Finset.sum_eq_single _ (fun b hb hnb => ?_) fun hn => ?_
| · have := Finset.mem_range_succ_iff.mp hb
simp only [hk b (this.lt_of_ne hnb), Pi.zero_apply]
· exact False.elim (hn (Finset.mem_range.mpr (lt_add_one k)))
replace h := h.isBigO_sub_partialSum_pow k.succ
simp only [psum_eq, zero_sub, Pi.zero_apply, Asymptotics.isBigO_neg_left] at h
exact h.continuousMultilinearMap_apply_eq_zero
| Mathlib/Analysis/Analytic/Uniqueness.lean | 96 | 101 |
/-
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)⟩
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 334 | 336 |
/-
Copyright (c) 2023 Sophie Morel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sophie Morel
-/
import Mathlib.Analysis.Analytic.Constructions
import Mathlib.Analysis.Analytic.CPolynomialDef
/-! # Properties of continuously polynomial functions
We expand the API around continuously polynomial functions. Notably, we show that this class is
stable under the usual operations (addition, subtraction, negation).
We also prove that continuous multilinear maps are continuously polynomial, and so
are continuous linear maps into continuous multilinear maps. In particular, such maps are
analytic.
-/
variable {𝕜 E F G : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E]
[NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G]
open scoped Topology
open Set Filter Asymptotics NNReal ENNReal
variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞} {n m : ℕ}
theorem hasFiniteFPowerSeriesOnBall_const {c : F} {e : E} :
HasFiniteFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e 1 ⊤ :=
⟨hasFPowerSeriesOnBall_const, fun n hn ↦ constFormalMultilinearSeries_apply (id hn : 0 < n).ne'⟩
theorem hasFiniteFPowerSeriesAt_const {c : F} {e : E} :
HasFiniteFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e 1 :=
⟨⊤, hasFiniteFPowerSeriesOnBall_const⟩
theorem CPolynomialAt_const {v : F} : CPolynomialAt 𝕜 (fun _ => v) x :=
⟨constFormalMultilinearSeries 𝕜 E v, 1, hasFiniteFPowerSeriesAt_const⟩
theorem CPolynomialOn_const {v : F} {s : Set E} : CPolynomialOn 𝕜 (fun _ => v) s :=
fun _ _ => CPolynomialAt_const
theorem HasFiniteFPowerSeriesOnBall.add (hf : HasFiniteFPowerSeriesOnBall f pf x n r)
(hg : HasFiniteFPowerSeriesOnBall g pg x m r) :
HasFiniteFPowerSeriesOnBall (f + g) (pf + pg) x (max n m) r :=
⟨hf.1.add hg.1, fun N hN ↦ by
rw [Pi.add_apply, hf.finite _ ((le_max_left n m).trans hN),
hg.finite _ ((le_max_right n m).trans hN), zero_add]⟩
theorem HasFiniteFPowerSeriesAt.add (hf : HasFiniteFPowerSeriesAt f pf x n)
(hg : HasFiniteFPowerSeriesAt g pg x m) :
HasFiniteFPowerSeriesAt (f + g) (pf + pg) x (max n m) := by
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
exact ⟨r, hr.1.add hr.2⟩
theorem CPolynomialAt.add (hf : CPolynomialAt 𝕜 f x) (hg : CPolynomialAt 𝕜 g x) :
CPolynomialAt 𝕜 (f + g) x :=
let ⟨_, _, hpf⟩ := hf
let ⟨_, _, hqf⟩ := hg
(hpf.add hqf).cpolynomialAt
theorem HasFiniteFPowerSeriesOnBall.neg (hf : HasFiniteFPowerSeriesOnBall f pf x n r) :
HasFiniteFPowerSeriesOnBall (-f) (-pf) x n r :=
⟨hf.1.neg, fun m hm ↦ by rw [Pi.neg_apply, hf.finite m hm, neg_zero]⟩
theorem HasFiniteFPowerSeriesAt.neg (hf : HasFiniteFPowerSeriesAt f pf x n) :
HasFiniteFPowerSeriesAt (-f) (-pf) x n :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFiniteFPowerSeriesAt
theorem CPolynomialAt.neg (hf : CPolynomialAt 𝕜 f x) : CPolynomialAt 𝕜 (-f) x :=
let ⟨_, _, hpf⟩ := hf
hpf.neg.cpolynomialAt
theorem HasFiniteFPowerSeriesOnBall.sub (hf : HasFiniteFPowerSeriesOnBall f pf x n r)
(hg : HasFiniteFPowerSeriesOnBall g pg x m r) :
HasFiniteFPowerSeriesOnBall (f - g) (pf - pg) x (max n m) r := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFiniteFPowerSeriesAt.sub (hf : HasFiniteFPowerSeriesAt f pf x n)
(hg : HasFiniteFPowerSeriesAt g pg x m) :
HasFiniteFPowerSeriesAt (f - g) (pf - pg) x (max n m) := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem CPolynomialAt.sub (hf : CPolynomialAt 𝕜 f x) (hg : CPolynomialAt 𝕜 g x) :
CPolynomialAt 𝕜 (f - g) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem CPolynomialOn.add {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : CPolynomialOn 𝕜 g s) :
CPolynomialOn 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
theorem CPolynomialOn.sub {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : CPolynomialOn 𝕜 g s) :
CPolynomialOn 𝕜 (f - g) s :=
fun z hz => (hf z hz).sub (hg z hz)
/-!
### Continuous multilinear maps
We show that continuous multilinear maps are continuously polynomial, and therefore analytic.
-/
namespace ContinuousMultilinearMap
variable {ι : Type*} {Em : ι → Type*} [∀ i, NormedAddCommGroup (Em i)] [∀ i, NormedSpace 𝕜 (Em i)]
[Fintype ι] (f : ContinuousMultilinearMap 𝕜 Em F) {x : Π i, Em i} {s : Set (Π i, Em i)}
open FormalMultilinearSeries
protected theorem hasFiniteFPowerSeriesOnBall :
HasFiniteFPowerSeriesOnBall f f.toFormalMultilinearSeries 0 (Fintype.card ι + 1) ⊤ :=
.mk' (fun _ hm ↦ dif_neg (Nat.succ_le_iff.mp hm).ne) ENNReal.zero_lt_top fun y _ ↦ by
rw [Finset.sum_eq_single_of_mem _ (Finset.self_mem_range_succ _), zero_add]
· rw [toFormalMultilinearSeries, dif_pos rfl]; rfl
· intro m _ ne; rw [toFormalMultilinearSeries, dif_neg ne.symm]; rfl
lemma cpolynomialAt : CPolynomialAt 𝕜 f x :=
f.hasFiniteFPowerSeriesOnBall.cpolynomialAt_of_mem
(by simp only [Metric.emetric_ball_top, Set.mem_univ])
lemma cpolynomialOn : CPolynomialOn 𝕜 f s := fun _ _ ↦ f.cpolynomialAt
@[deprecated (since := "2025-02-15")] alias cpolyomialOn := cpolynomialOn
lemma analyticOnNhd : AnalyticOnNhd 𝕜 f s := f.cpolynomialOn.analyticOnNhd
lemma analyticOn : AnalyticOn 𝕜 f s := f.analyticOnNhd.analyticOn
lemma analyticAt : AnalyticAt 𝕜 f x := f.cpolynomialAt.analyticAt
lemma analyticWithinAt : AnalyticWithinAt 𝕜 f s x := f.analyticAt.analyticWithinAt
end ContinuousMultilinearMap
/-!
### Continuous linear maps into continuous multilinear maps
We show that a continuous linear map into continuous multilinear maps is continuously polynomial
(as a function of two variables, i.e., uncurried). Therefore, it is also analytic.
-/
namespace ContinuousLinearMap
variable {ι : Type*} {Em : ι → Type*} [∀ i, NormedAddCommGroup (Em i)] [∀ i, NormedSpace 𝕜 (Em i)]
[Fintype ι] (f : G →L[𝕜] ContinuousMultilinearMap 𝕜 Em F)
{s : Set (G × (Π i, Em i))} {x : G × (Π i, Em i)}
/-- Formal multilinear series associated to a linear map into multilinear maps. -/
noncomputable def toFormalMultilinearSeriesOfMultilinear :
FormalMultilinearSeries 𝕜 (G × (Π i, Em i)) F :=
fun n ↦ if h : Fintype.card (Option ι) = n then
(f.continuousMultilinearMapOption).domDomCongr (Fintype.equivFinOfCardEq h)
else 0
| protected theorem hasFiniteFPowerSeriesOnBall_uncurry_of_multilinear :
HasFiniteFPowerSeriesOnBall (fun (p : G × (Π i, Em i)) ↦ f p.1 p.2)
f.toFormalMultilinearSeriesOfMultilinear 0 (Fintype.card (Option ι) + 1) ⊤ := by
apply HasFiniteFPowerSeriesOnBall.mk' ?_ ENNReal.zero_lt_top ?_
· intro m hm
apply dif_neg
| Mathlib/Analysis/Analytic/CPolynomial.lean | 155 | 160 |
/-
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 | 1,064 | 1,066 | |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.Order.Interval.Set.Group
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.Convex.Segment
import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional
import Mathlib.Tactic.FieldSimp
/-!
# Betweenness in affine spaces
This file defines notions of a point in an affine space being between two given points.
## Main definitions
* `affineSegment R x y`: The segment of points weakly between `x` and `y`.
* `Wbtw R x y z`: The point `y` is weakly between `x` and `z`.
* `Sbtw R x y z`: The point `y` is strictly between `x` and `z`.
-/
variable (R : Type*) {V V' P P' : Type*}
open AffineEquiv AffineMap
section OrderedRing
/-- The segment of points weakly between `x` and `y`. When convexity is refactored to support
abstract affine combination spaces, this will no longer need to be a separate definition from
`segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a
refactoring, as distinct from versions involving `+` or `-` in a module. -/
def affineSegment [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V]
[AddTorsor V P] (x y : P) :=
lineMap x y '' Set.Icc (0 : R) 1
variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P]
variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
variable {R} in
@[simp]
theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) :
f '' affineSegment R x y = affineSegment R (f x) (f y) := by
rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap]
rfl
@[simp]
theorem affineSegment_const_vadd_image (x y : P) (v : V) :
(v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) :=
affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y
@[simp]
theorem affineSegment_vadd_const_image (x y : V) (p : P) :
(· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) :=
affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y
@[simp]
theorem affineSegment_const_vsub_image (x y p : P) :
(p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) :=
affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y
@[simp]
theorem affineSegment_vsub_const_image (x y p : P) :
(· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) :=
affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y
variable {R}
@[simp]
theorem mem_const_vadd_affineSegment {x y z : P} (v : V) :
v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image]
@[simp]
theorem mem_vadd_const_affineSegment {x y z : V} (p : P) :
z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image]
@[simp]
theorem mem_const_vsub_affineSegment {x y z : P} (p : P) :
p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image]
@[simp]
theorem mem_vsub_const_affineSegment {x y z : P} (p : P) :
z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by
rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image]
variable (R)
section OrderedRing
variable [IsOrderedRing R]
theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by
rw [segment_eq_image_lineMap, affineSegment]
theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by
refine Set.ext fun z => ?_
constructor <;>
· rintro ⟨t, ht, hxy⟩
refine ⟨1 - t, ?_, ?_⟩
· rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero]
· rwa [lineMap_apply_one_sub]
theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y :=
⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩
theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y :=
⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩
@[simp]
theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by
simp_rw [affineSegment, lineMap_same, AffineMap.coe_const, Function.const,
(Set.nonempty_Icc.mpr zero_le_one).image_const]
end OrderedRing
/-- The point `y` is weakly between `x` and `z`. -/
def Wbtw (x y z : P) : Prop :=
y ∈ affineSegment R x z
/-- The point `y` is strictly between `x` and `z`. -/
def Sbtw (x y z : P) : Prop :=
Wbtw R x y z ∧ y ≠ x ∧ y ≠ z
variable {R}
section OrderedRing
variable [IsOrderedRing R]
lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by
rw [Wbtw, affineSegment_eq_segment]
alias ⟨_, Wbtw.mem_segment⟩ := mem_segment_iff_wbtw
lemma Convex.mem_of_wbtw {p₀ p₁ p₂ : V} {s : Set V} (hs : Convex R s) (h₀₁₂ : Wbtw R p₀ p₁ p₂)
(h₀ : p₀ ∈ s) (h₂ : p₂ ∈ s) : p₁ ∈ s := hs.segment_subset h₀ h₂ h₀₁₂.mem_segment
theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by
rw [Wbtw, Wbtw, affineSegment_comm]
alias ⟨Wbtw.symm, _⟩ := wbtw_comm
theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by
rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm]
alias ⟨Sbtw.symm, _⟩ := sbtw_comm
end OrderedRing
lemma AffineSubspace.mem_of_wbtw {s : AffineSubspace R P} {x y z : P} (hxyz : Wbtw R x y z)
(hx : x ∈ s) (hz : z ∈ s) : y ∈ s := by obtain ⟨ε, -, rfl⟩ := hxyz; exact lineMap_mem _ hx hz
theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by
rw [Wbtw, ← affineSegment_image]
exact Set.mem_image_of_mem _ h
theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) :
Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h
theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) :
Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by
simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff]
@[simp]
theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') :
Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by
have : Function.Injective f.toAffineMap := f.injective
-- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing.
apply this.wbtw_map_iff
@[simp]
theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') :
Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by
have : Function.Injective f.toAffineMap := f.injective
-- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing.
apply this.sbtw_map_iff
@[simp]
theorem wbtw_const_vadd_iff {x y z : P} (v : V) :
Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z :=
mem_const_vadd_affineSegment _
@[simp]
theorem wbtw_vadd_const_iff {x y z : V} (p : P) :
Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z :=
mem_vadd_const_affineSegment _
@[simp]
theorem wbtw_const_vsub_iff {x y z : P} (p : P) :
Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z :=
mem_const_vsub_affineSegment _
@[simp]
theorem wbtw_vsub_const_iff {x y z : P} (p : P) :
Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z :=
mem_vsub_const_affineSegment _
@[simp]
theorem sbtw_const_vadd_iff {x y z : P} (v : V) :
Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff,
(AddAction.injective v).ne_iff]
@[simp]
theorem sbtw_vadd_const_iff {x y z : V} (p : P) :
Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff,
(vadd_right_injective p).ne_iff]
@[simp]
theorem sbtw_const_vsub_iff {x y z : P} (p : P) :
Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff,
(vsub_right_injective p).ne_iff]
@[simp]
theorem sbtw_vsub_const_iff {x y z : P} (p : P) :
Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by
rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff,
(vsub_left_injective p).ne_iff]
theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z :=
h.1
theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x :=
h.2.1
theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y :=
h.2.1.symm
theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z :=
h.2.2
theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y :=
h.2.2.symm
theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) :
y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by
rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩
rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho)
· exfalso
exact hyx (lineMap_apply_zero _ _)
· exfalso
exact hyz (lineMap_apply_one _ _)
· exact ⟨t, ho, rfl⟩
theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by
rcases h with ⟨r, ⟨-, rfl⟩⟩
exact lineMap_mem_affineSpan_pair _ _ _
variable (R)
section OrderedRing
variable [IsOrderedRing R]
@[simp]
theorem wbtw_self_left (x y : P) : Wbtw R x x y :=
left_mem_affineSegment _ _ _
@[simp]
theorem wbtw_self_right (x y : P) : Wbtw R x y y :=
right_mem_affineSegment _ _ _
@[simp]
theorem wbtw_self_iff {x y : P} : Wbtw R x y x ↔ y = x := by
refine ⟨fun h => ?_, fun h => ?_⟩
· simpa [Wbtw, affineSegment] using h
· rw [h]
exact wbtw_self_left R x x
end OrderedRing
@[simp]
theorem not_sbtw_self_left (x y : P) : ¬Sbtw R x x y :=
fun h => h.ne_left rfl
@[simp]
theorem not_sbtw_self_right (x y : P) : ¬Sbtw R x y y :=
fun h => h.ne_right rfl
variable {R}
variable [IsOrderedRing R]
theorem Wbtw.left_ne_right_of_ne_left {x y z : P} (h : Wbtw R x y z) (hne : y ≠ x) : x ≠ z := by
rintro rfl
rw [wbtw_self_iff] at h
exact hne h
theorem Wbtw.left_ne_right_of_ne_right {x y z : P} (h : Wbtw R x y z) (hne : y ≠ z) : x ≠ z := by
rintro rfl
rw [wbtw_self_iff] at h
exact hne h
theorem Sbtw.left_ne_right {x y z : P} (h : Sbtw R x y z) : x ≠ z :=
h.wbtw.left_ne_right_of_ne_left h.2.1
theorem sbtw_iff_mem_image_Ioo_and_ne [NoZeroSMulDivisors R V] {x y z : P} :
Sbtw R x y z ↔ y ∈ lineMap x z '' Set.Ioo (0 : R) 1 ∧ x ≠ z := by
refine ⟨fun h => ⟨h.mem_image_Ioo, h.left_ne_right⟩, fun h => ?_⟩
rcases h with ⟨⟨t, ht, rfl⟩, hxz⟩
refine ⟨⟨t, Set.mem_Icc_of_Ioo ht, rfl⟩, ?_⟩
rw [lineMap_apply, ← @vsub_ne_zero V, ← @vsub_ne_zero V _ _ _ _ z, vadd_vsub_assoc, vsub_self,
vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z x, ← @neg_one_smul R, ← add_smul, ← sub_eq_add_neg]
simp [smul_ne_zero, sub_eq_zero, ht.1.ne.symm, ht.2.ne, hxz.symm]
variable (R)
@[simp]
theorem not_sbtw_self (x y : P) : ¬Sbtw R x y x :=
fun h => h.left_ne_right rfl
theorem wbtw_swap_left_iff [NoZeroSMulDivisors R V] {x y : P} (z : P) :
Wbtw R x y z ∧ Wbtw R y x z ↔ x = y := by
constructor
· rintro ⟨hxyz, hyxz⟩
rcases hxyz with ⟨ty, hty, rfl⟩
rcases hyxz with ⟨tx, htx, hx⟩
rw [lineMap_apply, lineMap_apply, ← add_vadd] at hx
rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, vsub_vadd_eq_vsub_sub, smul_sub, smul_smul, ← sub_smul,
← add_smul, smul_eq_zero] at hx
rcases hx with (h | h)
· nth_rw 1 [← mul_one tx] at h
rw [← mul_sub, add_eq_zero_iff_neg_eq] at h
have h' : ty = 0 := by
refine le_antisymm ?_ hty.1
rw [← h, Left.neg_nonpos_iff]
exact mul_nonneg htx.1 (sub_nonneg.2 hty.2)
simp [h']
· rw [vsub_eq_zero_iff_eq] at h
rw [h, lineMap_same_apply]
· rintro rfl
exact ⟨wbtw_self_left _ _ _, wbtw_self_left _ _ _⟩
theorem wbtw_swap_right_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} :
Wbtw R x y z ∧ Wbtw R x z y ↔ y = z := by
rw [wbtw_comm, wbtw_comm (z := y), eq_comm]
exact wbtw_swap_left_iff R x
theorem wbtw_rotate_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} :
Wbtw R x y z ∧ Wbtw R z x y ↔ x = y := by rw [wbtw_comm, wbtw_swap_right_iff, eq_comm]
variable {R}
theorem Wbtw.swap_left_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R y x z ↔ x = y := by rw [← wbtw_swap_left_iff R z, and_iff_right h]
theorem Wbtw.swap_right_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R x z y ↔ y = z := by rw [← wbtw_swap_right_iff R x, and_iff_right h]
theorem Wbtw.rotate_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) :
Wbtw R z x y ↔ x = y := by rw [← wbtw_rotate_iff R x, and_iff_right h]
theorem Sbtw.not_swap_left [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) :
¬Wbtw R y x z := fun hs => h.left_ne (h.wbtw.swap_left_iff.1 hs)
theorem Sbtw.not_swap_right [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) :
¬Wbtw R x z y := fun hs => h.ne_right (h.wbtw.swap_right_iff.1 hs)
theorem Sbtw.not_rotate [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R z x y :=
fun hs => h.left_ne (h.wbtw.rotate_iff.1 hs)
@[simp]
theorem wbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} :
Wbtw R x (lineMap x y r) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := by
by_cases hxy : x = y
· rw [hxy, lineMap_same_apply]
simp
rw [or_iff_right hxy, Wbtw, affineSegment, (lineMap_injective R hxy).mem_set_image]
@[simp]
theorem sbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} :
Sbtw R x (lineMap x y r) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := by
rw [sbtw_iff_mem_image_Ioo_and_ne, and_comm, and_congr_right]
intro hxy
rw [(lineMap_injective R hxy).mem_set_image]
@[simp]
theorem wbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} :
Wbtw R x (r * (y - x) + x) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 :=
wbtw_lineMap_iff
@[simp]
theorem sbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} :
Sbtw R x (r * (y - x) + x) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 :=
sbtw_lineMap_iff
omit [IsOrderedRing R] in
@[simp]
theorem wbtw_zero_one_iff {x : R} : Wbtw R 0 x 1 ↔ x ∈ Set.Icc (0 : R) 1 := by
rw [Wbtw, affineSegment, Set.mem_image]
simp_rw [lineMap_apply_ring]
simp
@[simp]
theorem wbtw_one_zero_iff {x : R} : Wbtw R 1 x 0 ↔ x ∈ Set.Icc (0 : R) 1 := by
rw [wbtw_comm, wbtw_zero_one_iff]
omit [IsOrderedRing R] in
@[simp]
theorem sbtw_zero_one_iff {x : R} : Sbtw R 0 x 1 ↔ x ∈ Set.Ioo (0 : R) 1 := by
rw [Sbtw, wbtw_zero_one_iff, Set.mem_Icc, Set.mem_Ioo]
exact
⟨fun h => ⟨h.1.1.lt_of_ne (Ne.symm h.2.1), h.1.2.lt_of_ne h.2.2⟩, fun h =>
⟨⟨h.1.le, h.2.le⟩, h.1.ne', h.2.ne⟩⟩
@[simp]
theorem sbtw_one_zero_iff {x : R} : Sbtw R 1 x 0 ↔ x ∈ Set.Ioo (0 : R) 1 := by
rw [sbtw_comm, sbtw_zero_one_iff]
theorem Wbtw.trans_left {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R w x z := by
rcases h₁ with ⟨t₁, ht₁, rfl⟩
rcases h₂ with ⟨t₂, ht₂, rfl⟩
refine ⟨t₂ * t₁, ⟨mul_nonneg ht₂.1 ht₁.1, mul_le_one₀ ht₂.2 ht₁.1 ht₁.2⟩, ?_⟩
rw [lineMap_apply, lineMap_apply, lineMap_vsub_left, smul_smul]
theorem Wbtw.trans_right {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w y z := by
rw [wbtw_comm] at *
exact h₁.trans_left h₂
theorem Wbtw.trans_sbtw_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Sbtw R w x y) : Sbtw R w x z := by
refine ⟨h₁.trans_left h₂.wbtw, h₂.ne_left, ?_⟩
rintro rfl
exact h₂.right_ne ((wbtw_swap_right_iff R w).1 ⟨h₁, h₂.wbtw⟩)
theorem Wbtw.trans_sbtw_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
(h₂ : Sbtw R x y z) : Sbtw R w y z := by
rw [wbtw_comm] at *
rw [sbtw_comm] at *
exact h₁.trans_sbtw_left h₂
theorem Sbtw.trans_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z)
(h₂ : Sbtw R w x y) : Sbtw R w x z :=
h₁.wbtw.trans_sbtw_left h₂
theorem Sbtw.trans_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z)
(h₂ : Sbtw R x y z) : Sbtw R w y z :=
h₁.wbtw.trans_sbtw_right h₂
theorem Wbtw.trans_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z)
(h₂ : Wbtw R w x y) (h : y ≠ z) : x ≠ z := by
rintro rfl
exact h (h₁.swap_right_iff.1 h₂)
theorem Wbtw.trans_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z)
(h₂ : Wbtw R x y z) (h : w ≠ x) : w ≠ y := by
rintro rfl
exact h (h₁.swap_left_iff.1 h₂)
theorem Sbtw.trans_wbtw_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z)
(h₂ : Wbtw R w x y) : x ≠ z :=
h₁.wbtw.trans_left_ne h₂ h₁.ne_right
theorem Sbtw.trans_wbtw_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z)
(h₂ : Wbtw R x y z) : w ≠ y :=
h₁.wbtw.trans_right_ne h₂ h₁.left_ne
theorem Sbtw.affineCombination_of_mem_affineSpan_pair [NoZeroDivisors R] [NoZeroSMulDivisors R V]
{ι : Type*} {p : ι → P} (ha : AffineIndependent R p) {w w₁ w₂ : ι → R} {s : Finset ι}
(hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1)
(h : s.affineCombination R p w ∈
line[R, s.affineCombination R p w₁, s.affineCombination R p w₂])
{i : ι} (his : i ∈ s) (hs : Sbtw R (w₁ i) (w i) (w₂ i)) :
Sbtw R (s.affineCombination R p w₁) (s.affineCombination R p w)
(s.affineCombination R p w₂) := by
rw [affineCombination_mem_affineSpan_pair ha hw hw₁ hw₂] at h
rcases h with ⟨r, hr⟩
rw [hr i his, sbtw_mul_sub_add_iff] at hs
change ∀ i ∈ s, w i = (r • (w₂ - w₁) + w₁) i at hr
rw [s.affineCombination_congr hr fun _ _ => rfl]
rw [← s.weightedVSub_vadd_affineCombination, s.weightedVSub_const_smul,
← s.affineCombination_vsub, ← lineMap_apply, sbtw_lineMap_iff, and_iff_left hs.2,
← @vsub_ne_zero V, s.affineCombination_vsub]
intro hz
have hw₁w₂ : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by
simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, hw₁, hw₂, sub_self]
refine hs.1 ?_
have ha' := ha s (w₁ - w₂) hw₁w₂ hz i his
rwa [Pi.sub_apply, sub_eq_zero] at ha'
end OrderedRing
section StrictOrderedCommRing
variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P]
variable {R}
theorem Wbtw.sameRay_vsub {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ y) := by
rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩
simp_rw [lineMap_apply]
rcases ht0.lt_or_eq with (ht0' | rfl); swap; · simp
rcases ht1.lt_or_eq with (ht1' | rfl); swap; · simp
refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩)
simp only [vadd_vsub, smul_smul, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul]
ring_nf
theorem Wbtw.sameRay_vsub_left {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ x) := by
rcases h with ⟨t, ⟨ht0, _⟩, rfl⟩
simpa [lineMap_apply] using SameRay.sameRay_nonneg_smul_left (z -ᵥ x) ht0
theorem Wbtw.sameRay_vsub_right {x y z : P} (h : Wbtw R x y z) : SameRay R (z -ᵥ x) (z -ᵥ y) := by
rcases h with ⟨t, ⟨_, ht1⟩, rfl⟩
simpa [lineMap_apply, vsub_vadd_eq_vsub_sub, sub_smul] using
SameRay.sameRay_nonneg_smul_right (z -ᵥ x) (sub_nonneg.2 ht1)
end StrictOrderedCommRing
section LinearOrderedRing
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P]
variable {R}
/-- Suppose lines from two vertices of a triangle to interior points of the opposite side meet at
`p`. Then `p` lies in the interior of the first (and by symmetry the other) segment from a
vertex to the point on the opposite side. -/
theorem sbtw_of_sbtw_of_sbtw_of_mem_affineSpan_pair [NoZeroSMulDivisors R V]
{t : Affine.Triangle R P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) {p₁ p₂ p : P}
(h₁ : Sbtw R (t.points i₂) p₁ (t.points i₃)) (h₂ : Sbtw R (t.points i₁) p₂ (t.points i₃))
(h₁' : p ∈ line[R, t.points i₁, p₁]) (h₂' : p ∈ line[R, t.points i₂, p₂]) :
Sbtw R (t.points i₁) p p₁ := by
have h₁₃ : i₁ ≠ i₃ := by
rintro rfl
simp at h₂
have h₂₃ : i₂ ≠ i₃ := by
rintro rfl
simp at h₁
have h3 : ∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃ := by omega
have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by
clear h₁ h₂ h₁' h₂'
decide +revert
have hp : p ∈ affineSpan R (Set.range t.points) := by
have hle : line[R, t.points i₁, p₁] ≤ affineSpan R (Set.range t.points) := by
refine affineSpan_pair_le_of_mem_of_mem (mem_affineSpan R (Set.mem_range_self _)) ?_
have hle : line[R, t.points i₂, t.points i₃] ≤ affineSpan R (Set.range t.points) := by
refine affineSpan_mono R ?_
simp [Set.insert_subset_iff]
rw [AffineSubspace.le_def'] at hle
exact hle _ h₁.wbtw.mem_affineSpan
rw [AffineSubspace.le_def'] at hle
exact hle _ h₁'
have h₁i := h₁.mem_image_Ioo
have h₂i := h₂.mem_image_Ioo
rw [Set.mem_image] at h₁i h₂i
rcases h₁i with ⟨r₁, ⟨hr₁0, hr₁1⟩, rfl⟩
rcases h₂i with ⟨r₂, ⟨hr₂0, hr₂1⟩, rfl⟩
rcases eq_affineCombination_of_mem_affineSpan_of_fintype hp with ⟨w, hw, rfl⟩
have h₁s :=
sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _)
(Finset.mem_univ _) (Finset.mem_univ _) h₁₂ h₁₃ h₂₃ hr₁0 hr₁1 h₁'
have h₂s :=
sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _)
(Finset.mem_univ _) (Finset.mem_univ _) h₁₂.symm h₂₃ h₁₃ hr₂0 hr₂1 h₂'
rw [← Finset.univ.affineCombination_affineCombinationSingleWeights R t.points
(Finset.mem_univ i₁),
← Finset.univ.affineCombination_affineCombinationLineMapWeights t.points (Finset.mem_univ _)
(Finset.mem_univ _)] at h₁' ⊢
refine
Sbtw.affineCombination_of_mem_affineSpan_pair t.independent hw
(Finset.univ.sum_affineCombinationSingleWeights R (Finset.mem_univ _))
(Finset.univ.sum_affineCombinationLineMapWeights (Finset.mem_univ _) (Finset.mem_univ _) _)
h₁' (Finset.mem_univ i₁) ?_
rw [Finset.affineCombinationSingleWeights_apply_self,
Finset.affineCombinationLineMapWeights_apply_of_ne h₁₂ h₁₃, sbtw_one_zero_iff]
have hs : ∀ i : Fin 3, SignType.sign (w i) = SignType.sign (w i₃) := by
intro i
rcases h3 i with (rfl | rfl | rfl)
· exact h₂s
· exact h₁s
· rfl
have hss : SignType.sign (∑ i, w i) = 1 := by simp [hw]
have hs' := sign_sum Finset.univ_nonempty (SignType.sign (w i₃)) fun i _ => hs i
rw [hs'] at hss
simp_rw [hss, sign_eq_one_iff] at hs
refine ⟨hs i₁, ?_⟩
rw [hu] at hw
rw [Finset.sum_insert, Finset.sum_insert, Finset.sum_singleton] at hw
· by_contra hle
rw [not_lt] at hle
exact (hle.trans_lt (lt_add_of_pos_right _ (Left.add_pos (hs i₂) (hs i₃)))).ne' hw
· simpa using h₂₃
· simpa [not_or] using ⟨h₁₂, h₁₃⟩
end LinearOrderedRing
section LinearOrderedField
variable [Field R] [LinearOrder R] [IsStrictOrderedRing R]
[AddCommGroup V] [Module R V] [AddTorsor V P] {x y z : P}
variable {R}
lemma wbtw_iff_of_le {x y z : R} (hxz : x ≤ z) : Wbtw R x y z ↔ x ≤ y ∧ y ≤ z := by
cases hxz.eq_or_lt with
| inl hxz =>
subst hxz
rw [← le_antisymm_iff, wbtw_self_iff, eq_comm]
| inr hxz =>
have hxz' : 0 < z - x := sub_pos.mpr hxz
let r := (y - x) / (z - x)
have hy : y = r * (z - x) + x := by simp [r, hxz'.ne']
simp [hy, wbtw_mul_sub_add_iff, mul_nonneg_iff_of_pos_right hxz', ← le_sub_iff_add_le,
mul_le_iff_le_one_left hxz', hxz.ne]
lemma Wbtw.of_le_of_le {x y z : R} (hxy : x ≤ y) (hyz : y ≤ z) : Wbtw R x y z :=
(wbtw_iff_of_le (hxy.trans hyz)).mpr ⟨hxy, hyz⟩
lemma Sbtw.of_lt_of_lt {x y z : R} (hxy : x < y) (hyz : y < z) : Sbtw R x y z :=
⟨.of_le_of_le hxy.le hyz.le, hxy.ne', hyz.ne⟩
theorem wbtw_iff_left_eq_or_right_mem_image_Ici {x y z : P} :
Wbtw R x y z ↔ x = y ∨ z ∈ lineMap x y '' Set.Ici (1 : R) := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩
rcases hr0.lt_or_eq with (hr0' | rfl)
· rw [Set.mem_image]
refine .inr ⟨r⁻¹, (one_le_inv₀ hr0').2 hr1, ?_⟩
simp only [lineMap_apply, smul_smul, vadd_vsub]
rw [inv_mul_cancel₀ hr0'.ne', one_smul, vsub_vadd]
· simp
· rcases h with (rfl | ⟨r, ⟨hr, rfl⟩⟩)
· exact wbtw_self_left _ _ _
· rw [Set.mem_Ici] at hr
refine ⟨r⁻¹, ⟨inv_nonneg.2 (zero_le_one.trans hr), inv_le_one_of_one_le₀ hr⟩, ?_⟩
simp only [lineMap_apply, smul_smul, vadd_vsub]
rw [inv_mul_cancel₀ (one_pos.trans_le hr).ne', one_smul, vsub_vadd]
theorem Wbtw.right_mem_image_Ici_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) :
z ∈ lineMap x y '' Set.Ici (1 : R) :=
(wbtw_iff_left_eq_or_right_mem_image_Ici.1 h).resolve_left hne
theorem Wbtw.right_mem_affineSpan_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) :
z ∈ line[R, x, y] := by
rcases h.right_mem_image_Ici_of_left_ne hne with ⟨r, ⟨-, rfl⟩⟩
exact lineMap_mem_affineSpan_pair _ _ _
theorem sbtw_iff_left_ne_and_right_mem_image_Ioi {x y z : P} :
Sbtw R x y z ↔ x ≠ y ∧ z ∈ lineMap x y '' Set.Ioi (1 : R) := by
refine ⟨fun h => ⟨h.left_ne, ?_⟩, fun h => ?_⟩
· obtain ⟨r, ⟨hr, rfl⟩⟩ := h.wbtw.right_mem_image_Ici_of_left_ne h.left_ne
rw [Set.mem_Ici] at hr
rcases hr.lt_or_eq with (hrlt | rfl)
· exact Set.mem_image_of_mem _ hrlt
· exfalso
simp at h
· rcases h with ⟨hne, r, hr, rfl⟩
rw [Set.mem_Ioi] at hr
refine
⟨wbtw_iff_left_eq_or_right_mem_image_Ici.2
(Or.inr (Set.mem_image_of_mem _ (Set.mem_of_mem_of_subset hr Set.Ioi_subset_Ici_self))),
hne.symm, ?_⟩
rw [lineMap_apply, ← @vsub_ne_zero V, vsub_vadd_eq_vsub_sub]
nth_rw 1 [← one_smul R (y -ᵥ x)]
rw [← sub_smul, smul_ne_zero_iff, vsub_ne_zero, sub_ne_zero]
exact ⟨hr.ne, hne.symm⟩
theorem Sbtw.right_mem_image_Ioi {x y z : P} (h : Sbtw R x y z) :
z ∈ lineMap x y '' Set.Ioi (1 : R) :=
(sbtw_iff_left_ne_and_right_mem_image_Ioi.1 h).2
theorem Sbtw.right_mem_affineSpan {x y z : P} (h : Sbtw R x y z) : z ∈ line[R, x, y] :=
h.wbtw.right_mem_affineSpan_of_left_ne h.left_ne
theorem wbtw_iff_right_eq_or_left_mem_image_Ici {x y z : P} :
Wbtw R x y z ↔ z = y ∨ x ∈ lineMap z y '' Set.Ici (1 : R) := by
rw [wbtw_comm, wbtw_iff_left_eq_or_right_mem_image_Ici]
theorem Wbtw.left_mem_image_Ici_of_right_ne {x y z : P} (h : Wbtw R x y z) (hne : z ≠ y) :
x ∈ lineMap z y '' Set.Ici (1 : R) :=
h.symm.right_mem_image_Ici_of_left_ne hne
theorem Wbtw.left_mem_affineSpan_of_right_ne {x y z : P} (h : Wbtw R x y z) (hne : z ≠ y) :
x ∈ line[R, z, y] :=
h.symm.right_mem_affineSpan_of_left_ne hne
theorem sbtw_iff_right_ne_and_left_mem_image_Ioi {x y z : P} :
Sbtw R x y z ↔ z ≠ y ∧ x ∈ lineMap z y '' Set.Ioi (1 : R) := by
rw [sbtw_comm, sbtw_iff_left_ne_and_right_mem_image_Ioi]
theorem Sbtw.left_mem_image_Ioi {x y z : P} (h : Sbtw R x y z) :
x ∈ lineMap z y '' Set.Ioi (1 : R) :=
h.symm.right_mem_image_Ioi
theorem Sbtw.left_mem_affineSpan {x y z : P} (h : Sbtw R x y z) : x ∈ line[R, z, y] :=
h.symm.right_mem_affineSpan
omit [IsStrictOrderedRing R] in
lemma AffineSubspace.right_mem_of_wbtw {s : AffineSubspace R P} (hxyz : Wbtw R x y z) (hx : x ∈ s)
(hy : y ∈ s) (hxy : x ≠ y) : z ∈ s := by
obtain ⟨ε, -, rfl⟩ := hxyz
have hε : ε ≠ 0 := by rintro rfl; simp at hxy
simpa [hε] using lineMap_mem ε⁻¹ hx hy
theorem wbtw_smul_vadd_smul_vadd_of_nonneg_of_le (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁)
(hr₂ : r₁ ≤ r₂) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) := by
refine ⟨r₁ / r₂, ⟨div_nonneg hr₁ (hr₁.trans hr₂), div_le_one_of_le₀ hr₂ (hr₁.trans hr₂)⟩, ?_⟩
by_cases h : r₁ = 0; · simp [h]
simp [lineMap_apply, smul_smul, ((hr₁.lt_of_ne' h).trans_le hr₂).ne.symm]
theorem wbtw_or_wbtw_smul_vadd_of_nonneg (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) :
Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) ∨ Wbtw R x (r₂ • v +ᵥ x) (r₁ • v +ᵥ x) := by
rcases le_total r₁ r₂ with (h | h)
· exact Or.inl (wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x v hr₁ h)
· exact Or.inr (wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x v hr₂ h)
theorem wbtw_smul_vadd_smul_vadd_of_nonpos_of_le (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0)
(hr₂ : r₂ ≤ r₁) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) := by
convert wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x (-v) (Left.nonneg_neg_iff.2 hr₁)
(neg_le_neg_iff.2 hr₂) using 1 <;>
rw [neg_smul_neg]
theorem wbtw_or_wbtw_smul_vadd_of_nonpos (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0) (hr₂ : r₂ ≤ 0) :
Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) ∨ Wbtw R x (r₂ • v +ᵥ x) (r₁ • v +ᵥ x) := by
rcases le_total r₁ r₂ with (h | h)
· exact Or.inr (wbtw_smul_vadd_smul_vadd_of_nonpos_of_le x v hr₂ h)
· exact Or.inl (wbtw_smul_vadd_smul_vadd_of_nonpos_of_le x v hr₁ h)
theorem wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0)
(hr₂ : 0 ≤ r₂) : Wbtw R (r₁ • v +ᵥ x) x (r₂ • v +ᵥ x) := by
convert wbtw_smul_vadd_smul_vadd_of_nonneg_of_le (r₁ • v +ᵥ x) v (Left.nonneg_neg_iff.2 hr₁)
(neg_le_sub_iff_le_add.2 ((le_add_iff_nonneg_left r₁).2 hr₂)) using 1 <;>
simp [sub_smul, ← add_vadd]
theorem wbtw_smul_vadd_smul_vadd_of_nonneg_of_nonpos (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁)
(hr₂ : r₂ ≤ 0) : Wbtw R (r₁ • v +ᵥ x) x (r₂ • v +ᵥ x) := by
rw [wbtw_comm]
exact wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg x v hr₂ hr₁
theorem Wbtw.trans_left_right {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) :
Wbtw R x y z := by
rcases h₁ with ⟨t₁, ht₁, rfl⟩
rcases h₂ with ⟨t₂, ht₂, rfl⟩
refine
⟨(t₁ - t₂ * t₁) / (1 - t₂ * t₁),
⟨div_nonneg (sub_nonneg.2 (mul_le_of_le_one_left ht₁.1 ht₂.2))
(sub_nonneg.2 (mul_le_one₀ ht₂.2 ht₁.1 ht₁.2)), div_le_one_of_le₀
(sub_le_sub_right ht₁.2 _) (sub_nonneg.2 (mul_le_one₀ ht₂.2 ht₁.1 ht₁.2))⟩,
?_⟩
simp only [lineMap_apply, smul_smul, ← add_vadd, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul,
← add_smul, vadd_vsub, vadd_right_cancel_iff, div_mul_eq_mul_div, div_sub_div_same]
nth_rw 1 [← mul_one (t₁ - t₂ * t₁)]
rw [← mul_sub, mul_div_assoc]
by_cases h : 1 - t₂ * t₁ = 0
· rw [sub_eq_zero, eq_comm] at h
rw [h]
suffices t₁ = 1 by simp [this]
exact
eq_of_le_of_not_lt ht₁.2 fun ht₁lt =>
(mul_lt_one_of_nonneg_of_lt_one_right ht₂.2 ht₁.1 ht₁lt).ne h
· rw [div_self h]
ring_nf
theorem Wbtw.trans_right_left {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) :
Wbtw R w x y := by
rw [wbtw_comm] at *
exact h₁.trans_left_right h₂
theorem Sbtw.trans_left_right {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Sbtw R w x y) :
Sbtw R x y z :=
⟨h₁.wbtw.trans_left_right h₂.wbtw, h₂.right_ne, h₁.ne_right⟩
theorem Sbtw.trans_right_left {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Sbtw R x y z) :
Sbtw R w x y :=
⟨h₁.wbtw.trans_right_left h₂.wbtw, h₁.ne_left, h₂.left_ne⟩
omit [IsStrictOrderedRing R] in
theorem Wbtw.collinear {x y z : P} (h : Wbtw R x y z) : Collinear R ({x, y, z} : Set P) := by
rw [collinear_iff_exists_forall_eq_smul_vadd]
refine ⟨x, z -ᵥ x, ?_⟩
intro p hp
simp_rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hp
rcases hp with (rfl | rfl | rfl)
· refine ⟨0, ?_⟩
simp
· rcases h with ⟨t, -, rfl⟩
exact ⟨t, rfl⟩
· refine ⟨1, ?_⟩
simp
theorem Collinear.wbtw_or_wbtw_or_wbtw {x y z : P} (h : Collinear R ({x, y, z} : Set P)) :
Wbtw R x y z ∨ Wbtw R y z x ∨ Wbtw R z x y := by
rw [collinear_iff_of_mem (Set.mem_insert _ _)] at h
rcases h with ⟨v, h⟩
simp_rw [Set.mem_insert_iff, Set.mem_singleton_iff] at h
have hy := h y (Or.inr (Or.inl rfl))
have hz := h z (Or.inr (Or.inr rfl))
rcases hy with ⟨ty, rfl⟩
rcases hz with ⟨tz, rfl⟩
rcases lt_trichotomy ty 0 with (hy0 | rfl | hy0)
· rcases lt_trichotomy tz 0 with (hz0 | rfl | hz0)
· rw [wbtw_comm (z := x)]
rw [← or_assoc]
exact Or.inl (wbtw_or_wbtw_smul_vadd_of_nonpos _ _ hy0.le hz0.le)
· simp
· exact Or.inr (Or.inr (wbtw_smul_vadd_smul_vadd_of_nonneg_of_nonpos _ _ hz0.le hy0.le))
· simp
· rcases lt_trichotomy tz 0 with (hz0 | rfl | hz0)
· refine Or.inr (Or.inr (wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg _ _ hz0.le hy0.le))
· simp
· rw [wbtw_comm (z := x)]
rw [← or_assoc]
exact Or.inl (wbtw_or_wbtw_smul_vadd_of_nonneg _ _ hy0.le hz0.le)
theorem wbtw_iff_sameRay_vsub {x y z : P} : Wbtw R x y z ↔ SameRay R (y -ᵥ x) (z -ᵥ y) := by
refine ⟨Wbtw.sameRay_vsub, fun h => ?_⟩
rcases h with (h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩)
· rw [vsub_eq_zero_iff_eq] at h
simp [h]
· rw [vsub_eq_zero_iff_eq] at h
simp [h]
· refine
⟨r₂ / (r₁ + r₂),
⟨div_nonneg hr₂.le (add_nonneg hr₁.le hr₂.le),
div_le_one_of_le₀ (le_add_of_nonneg_left hr₁.le) (add_nonneg hr₁.le hr₂.le)⟩,
?_⟩
have h' : z = r₂⁻¹ • r₁ • (y -ᵥ x) +ᵥ y := by simp [h, hr₂.ne']
rw [eq_comm]
simp only [lineMap_apply, h', vadd_vsub_assoc, smul_smul, ← add_smul, eq_vadd_iff_vsub_eq,
smul_add]
convert (one_smul R (y -ᵥ x)).symm
field_simp [(add_pos hr₁ hr₂).ne', hr₂.ne']
ring
/-- If `T` is an affine independent family of points,
then any 3 distinct points form a triangle. -/
theorem AffineIndependent.not_wbtw_of_injective {ι} (i j k : ι)
(h : Function.Injective ![i, j, k]) {T : ι → P} (hT : AffineIndependent R T) :
¬ Wbtw R (T i) (T j) (T k) := by
replace hT := hT.comp_embedding ⟨_, h⟩
rw [affineIndependent_iff_not_collinear] at hT
contrapose! hT
simp [Set.range_comp, Set.image_insert_eq, hT.symm.collinear]
variable (R)
theorem wbtw_pointReflection (x y : P) : Wbtw R y x (pointReflection R x y) := by
refine ⟨2⁻¹, ⟨by norm_num, by norm_num⟩, ?_⟩
rw [lineMap_apply, pointReflection_apply, vadd_vsub_assoc, ← two_smul R (x -ᵥ y)]
simp
theorem sbtw_pointReflection_of_ne {x y : P} (h : x ≠ y) : Sbtw R y x (pointReflection R x y) := by
| refine ⟨wbtw_pointReflection _ _ _, h, ?_⟩
nth_rw 1 [← pointReflection_self R x]
exact (pointReflection_involutive R x).injective.ne h
theorem wbtw_midpoint (x y : P) : Wbtw R x (midpoint R x y) y := by
convert wbtw_pointReflection R (midpoint R x y) x
rw [pointReflection_midpoint_left]
theorem sbtw_midpoint_of_ne {x y : P} (h : x ≠ y) : Sbtw R x (midpoint R x y) y := by
have h : midpoint R x y ≠ x := by simp [h]
convert sbtw_pointReflection_of_ne R h
rw [pointReflection_midpoint_left]
end LinearOrderedField
| Mathlib/Analysis/Convex/Between.lean | 851 | 873 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Shing Tak Lam, Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.List
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Log
import Mathlib.Data.List.Palindrome
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
/-!
# Digits of a natural number
This provides a basic API for extracting the digits of a natural number in a given base,
and reconstructing numbers from their digits.
We also prove some divisibility tests based on digits, in particular completing
Theorem #85 from https://www.cs.ru.nl/~freek/100/.
Also included is a bound on the length of `Nat.toDigits` from core.
## TODO
A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b`
are numerals is not yet ported.
-/
namespace Nat
variable {n : ℕ}
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux0 : ℕ → List ℕ
| 0 => []
| n + 1 => [n + 1]
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux1 (n : ℕ) : List ℕ :=
List.replicate n 1
/-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/
def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ
| 0 => []
| n + 1 =>
((n + 1) % b) :: digitsAux b h ((n + 1) / b)
decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h
@[simp]
theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux]
theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) :
digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by
cases n
· cases w
· rw [digitsAux]
/-- `digits b n` gives the digits, in little-endian order,
of a natural number `n` in a specified base `b`.
In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`.
* For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`,
and the last digit is not zero.
This uniquely specifies the behaviour of `digits b`.
* For `b = 1`, we define `digits 1 n = List.replicate n 1`.
* For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`.
Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals.
In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`.
-/
def digits : ℕ → ℕ → List ℕ
| 0 => digitsAux0
| 1 => digitsAux1
| b + 2 => digitsAux (b + 2) (by norm_num)
@[simp]
theorem digits_zero (b : ℕ) : digits b 0 = [] := by
rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1]
theorem digits_zero_zero : digits 0 0 = [] :=
rfl
@[simp]
theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] :=
rfl
theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n]
| 0, h => (h rfl).elim
| _ + 1, _ => rfl
@[simp]
theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 :=
rfl
-- no `@[simp]`: dsimp can prove this
theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n :=
rfl
theorem digits_add_two_add_one (b n : ℕ) :
digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by
simp [digits, digitsAux_def]
@[simp]
lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) :
Nat.digits b n = n % b :: Nat.digits b (n / b) := by
rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one]
theorem digits_def' :
∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b)
| 0, h => absurd h (by decide)
| 1, h => absurd h (by decide)
| b + 2, _ => digitsAux_def _ (by simp) _
@[simp]
theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by
rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩
rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩
rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb]
theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) :
digits b (x + b * y) = x :: digits b y := by
rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩
cases y
· simp [hxb, hxy.resolve_right (absurd rfl)]
dsimp [digits]
rw [digitsAux_def]
· congr
· simp [Nat.add_mod, mod_eq_of_lt hxb]
· simp [add_mul_div_left, div_eq_of_lt hxb]
· apply Nat.succ_pos
-- If we had a function converting a list into a polynomial,
-- and appropriate lemmas about that function,
-- we could rewrite this in terms of that.
/-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them
as a number in semiring, as the little-endian digits in base `b`.
-/
def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α
| [] => 0
| h :: t => h + b * ofDigits b t
theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) :
ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by
induction' L with d L ih
· rfl
· dsimp [ofDigits]
rw [ih]
theorem ofDigits_eq_sum_mapIdx_aux (b : ℕ) (l : List ℕ) :
(l.zipWith ((fun a i : ℕ => a * b ^ (i + 1))) (List.range l.length)).sum =
b * (l.zipWith (fun a i => a * b ^ i) (List.range l.length)).sum := by
suffices
l.zipWith (fun a i : ℕ => a * b ^ (i + 1)) (List.range l.length) =
l.zipWith (fun a i=> b * (a * b ^ i)) (List.range l.length)
by simp [this]
congr; ext; simp [pow_succ]; ring
theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) :
ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by
rw [List.mapIdx_eq_zipIdx_map, List.zipIdx_eq_zip_range', List.map_zip_eq_zipWith,
ofDigits_eq_foldr, ← List.range_eq_range']
induction' L with hd tl hl
· simp
· simpa [List.range_succ_eq_map, List.zipWith_map_right, ofDigits_eq_sum_mapIdx_aux] using
Or.inl hl
@[simp]
theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl
@[simp]
theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits]
@[simp]
theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) :
ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits]
theorem ofDigits_cons {b hd} {tl : List ℕ} :
ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl
theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} :
ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by
induction' l1 with hd tl IH
· simp [ofDigits]
· rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ']
ring
@[norm_cast]
theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) :
((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by
induction' L with d L ih
· simp [ofDigits]
· dsimp [ofDigits]; push_cast; rw [ih]
@[norm_cast]
theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by
induction' L with d L _
· rfl
· dsimp [ofDigits]; push_cast; simp only
theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) :
∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0
| _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0
| _ :: _, h0, _, List.Mem.tail _ hL =>
digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL
theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b)
(w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by
induction' L with d L ih
· dsimp [ofDigits]
simp
· dsimp [ofDigits]
replace w₂ := w₂ (by simp)
rw [digits_add b h]
· rw [ih]
· intro l m
apply w₁
exact List.mem_cons_of_mem _ m
· intro h
rw [List.getLast_cons h] at w₂
convert w₂
· exact w₁ d List.mem_cons_self
· by_cases h' : L = []
· rcases h' with rfl
left
simpa using w₂
· right
contrapose! w₂
refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_
rw [List.getLast_cons h']
exact List.getLast_mem h'
theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by
rcases b with - | b
· rcases n with - | n
· rfl
· simp
· rcases b with - | b
· induction' n with n ih
· rfl
· rw [Nat.zero_add] at ih ⊢
simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ]
· induction n using Nat.strongRecOn with | ind n h => ?_
cases n
· rw [digits_zero]
rfl
· simp only [Nat.succ_eq_add_one, digits_add_two_add_one]
dsimp [ofDigits]
rw [h _ (Nat.div_lt_self' _ b)]
rw [Nat.mod_add_div]
theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by
induction L with
| nil => rfl
| cons _ _ ih => simp [ofDigits, List.sum_cons, ih]
/-!
### Properties
This section contains various lemmas of properties relating to `digits` and `ofDigits`.
-/
theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by
constructor
· intro h
have : ofDigits b (digits b n) = ofDigits b [] := by rw [h]
convert this
rw [ofDigits_digits]
· rintro rfl
simp
theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 :=
not_congr digits_eq_nil_iff_eq_zero
theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) :
digits b n = (n % b) :: digits b (n / b) := by
rcases b with (_ | _ | b)
· rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero]
· norm_num at h
rcases n with (_ | n)
· norm_num at w
· simp only [digits_add_two_add_one, ne_eq]
theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) :
(digits b m).getLast p = (digits b (m / b)).getLast q := by
by_cases hm : m = 0
· simp [hm]
simp only [digits_eq_cons_digits_div h hm]
rw [List.getLast_cons]
theorem digits.injective (b : ℕ) : Function.Injective b.digits :=
Function.LeftInverse.injective (ofDigits_digits b)
@[simp]
theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m :=
(digits.injective b).eq_iff
theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by
induction' n using Nat.strong_induction_on with n IH
rw [digits_eq_cons_digits_div hb hn, List.length]
by_cases h : n / b = 0
· simp [IH, h]
aesop
· have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb
rw [IH _ this h, log_div_base, tsub_add_cancel_of_le]
refine Nat.succ_le_of_lt (log_pos hb ?_)
contrapose! h
exact div_eq_of_lt h
theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) :
(digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by
rcases b with (_ | _ | b)
· cases m
· cases hm rfl
· simp
· cases m
· cases hm rfl
rename ℕ => m
simp only [zero_add, digits_one, List.getLast_replicate_succ m 1]
exact Nat.one_ne_zero
revert hm
induction m using Nat.strongRecOn with | ind n IH => ?_
intro hn
by_cases hnb : n < b + 2
· simpa only [digits_of_lt (b + 2) n hn hnb]
· rw [digits_getLast n (le_add_left 2 b)]
refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_
rw [← pos_iff_ne_zero]
exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b))
theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} :
n * ofDigits b l = ofDigits b (l.map (n * ·)) := by
induction l with
| nil => rfl
| cons hd tl ih =>
rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih]
ring
lemma ofDigits_inj_of_len_eq {b : ℕ} (hb : 1 < b) {L1 L2 : List ℕ}
(len : L1.length = L2.length) (w1 : ∀ l ∈ L1, l < b) (w2 : ∀ l ∈ L2, l < b)
(h : ofDigits b L1 = ofDigits b L2) : L1 = L2 := by
induction' L1 with D L ih generalizing L2
· simp only [List.length_nil] at len
exact (List.length_eq_zero_iff.mp len.symm).symm
obtain ⟨d, l, rfl⟩ := List.exists_cons_of_length_eq_add_one len.symm
simp only [List.length_cons, add_left_inj] at len
simp only [ofDigits_cons] at h
have eqd : D = d := by
have H : (D + b * ofDigits b L) % b = (d + b * ofDigits b l) % b := by rw [h]
simpa [mod_eq_of_lt (w2 d List.mem_cons_self),
mod_eq_of_lt (w1 D List.mem_cons_self)] using H
simp only [eqd, add_right_inj, mul_left_cancel_iff_of_pos (zero_lt_of_lt hb)] at h
have := ih len (fun a ha ↦ w1 a <| List.mem_cons_of_mem D ha)
(fun a ha ↦ w2 a <| List.mem_cons_of_mem d ha) h
rw [eqd, this]
/-- The addition of ofDigits of two lists is equal to ofDigits of digit-wise addition of them -/
theorem ofDigits_add_ofDigits_eq_ofDigits_zipWith_of_length_eq {b : ℕ} {l1 l2 : List ℕ}
(h : l1.length = l2.length) :
ofDigits b l1 + ofDigits b l2 = ofDigits b (l1.zipWith (· + ·) l2) := by
induction l1 generalizing l2 with
| nil => simp_all [eq_comm, List.length_eq_zero_iff, ofDigits]
| cons hd₁ tl₁ ih₁ =>
induction l2 generalizing tl₁ with
| nil => simp_all
| cons hd₂ tl₂ ih₂ =>
simp_all only [List.length_cons, succ_eq_add_one, ofDigits_cons, add_left_inj,
eq_comm, List.zipWith_cons_cons, add_eq]
rw [← ih₁ h.symm, mul_add]
ac_rfl
/-- The digits in the base b+2 expansion of n are all less than b+2 -/
theorem digits_lt_base' {b m : ℕ} : ∀ {d}, d ∈ digits (b + 2) m → d < b + 2 := by
induction m using Nat.strongRecOn with | ind n IH => ?_
intro d hd
rcases n with - | n
· rw [digits_zero] at hd
cases hd
-- base b+2 expansion of 0 has no digits
rw [digits_add_two_add_one] at hd
cases hd
· exact n.succ.mod_lt (by linarith)
· apply IH ((n + 1) / (b + 2))
· apply Nat.div_lt_self <;> omega
· assumption
/-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/
theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by
rcases b with (_ | _ | b) <;> try simp_all
exact digits_lt_base' hd
/-- an n-digit number in base b + 2 is less than (b + 2)^n -/
theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) :
ofDigits (b + 2) l < (b + 2) ^ l.length := by
induction' l with hd tl IH
· simp [ofDigits]
· rw [ofDigits, List.length_cons, pow_succ]
have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) :=
mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le])
(Nat.zero_le _)
suffices ↑hd < b + 2 by linarith
exact hl hd List.mem_cons_self
/-- an n-digit number in base b is less than b^n if b > 1 -/
theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) :
ofDigits b l < b ^ l.length := by
rcases b with (_ | _ | b) <;> try simp_all
exact ofDigits_lt_base_pow_length' hl
/-- Any number m is less than (b+2)^(number of digits in the base b + 2 representation of m) -/
theorem lt_base_pow_length_digits' {b m : ℕ} : m < (b + 2) ^ (digits (b + 2) m).length := by
convert @ofDigits_lt_base_pow_length' b (digits (b + 2) m) fun _ => digits_lt_base'
rw [ofDigits_digits (b + 2) m]
/-- Any number m is less than b^(number of digits in the base b representation of m) -/
theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by
rcases b with (_ | _ | b) <;> try simp_all
exact lt_base_pow_length_digits'
theorem digits_base_pow_mul {b k m : ℕ} (hb : 1 < b) (hm : 0 < m) :
digits b (b ^ k * m) = List.replicate k 0 ++ digits b m := by
induction k generalizing m with
| zero => simp
| succ k ih =>
have hmb : 0 < m * b := lt_mul_of_lt_of_one_lt' hm hb
let h1 := digits_def' hb hmb
have h2 : m = m * b / b :=
Nat.eq_div_of_mul_eq_left (ne_zero_of_lt hb) rfl
simp only [mul_mod_left, ← h2] at h1
rw [List.replicate_succ', List.append_assoc, List.singleton_append, ← h1, ← ih hmb]
ring_nf
theorem ofDigits_digits_append_digits {b m n : ℕ} :
ofDigits b (digits b n ++ digits b m) = n + b ^ (digits b n).length * m := by
rw [ofDigits_append, ofDigits_digits, ofDigits_digits]
theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) :
digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by
rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb)
· simp
rw [← ofDigits_digits_append_digits]
refine (digits_ofDigits b hb _ (fun l hl => ?_) (fun h_append => ?_)).symm
· rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h
· by_cases h : digits b m = []
· simp only [h, List.append_nil] at h_append ⊢
exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append
· exact (List.getLast_append_of_right_ne_nil _ _ h) ▸
(getLast_digit_ne_zero _ <| digits_ne_nil_iff_ne_zero.mp h)
theorem digits_append_zeroes_append_digits {b k m n : ℕ} (hb : 1 < b) (hm : 0 < m) :
digits b n ++ List.replicate k 0 ++ digits b m =
digits b (n + b ^ ((digits b n).length + k) * m) := by
rw [List.append_assoc, ← digits_base_pow_mul hb hm]
simp only [digits_append_digits (zero_lt_of_lt hb), digits_inj_iff, add_right_inj]
ring
theorem digits_len_le_digits_len_succ (b n : ℕ) :
(digits b n).length ≤ (digits b (n + 1)).length := by
| rcases Decidable.eq_or_ne n 0 with (rfl | hn)
· simp
rcases le_or_lt b 1 with hb | hb
· interval_cases b <;> simp +arith [digits_zero_succ', hn]
simpa [digits_len, hb, hn] using log_mono_right (le_succ _)
theorem le_digits_len_le (b n m : ℕ) (h : n ≤ m) : (digits b n).length ≤ (digits b m).length :=
monotone_nat_of_le_succ (digits_len_le_digits_len_succ b) h
@[mono]
theorem ofDigits_monotone {p q : ℕ} (L : List ℕ) (h : p ≤ q) : ofDigits p L ≤ ofDigits q L := by
induction L with
| Mathlib/Data/Nat/Digits.lean | 463 | 474 |
/-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.Baire.Lemmas
import Mathlib.Topology.Algebra.Group.Pointwise
/-! # Open mapping theorem for morphisms of topological groups
We prove that a continuous surjective group morphism from a sigma-compact group to a locally compact
group is automatically open, in `MonoidHom.isOpenMap_of_sigmaCompact`.
We deduce this from a similar statement for the orbits of continuous actions of sigma-compact groups
on Baire spaces, given in `isOpenMap_smul_of_sigmaCompact`.
Note that a sigma-compactness assumption is necessary. Indeed, let `G` be the real line with
the discrete topology, and `H` the real line with the usual topology. Both are locally compact
groups, and the identity from `G` to `H` is continuous but not open.
-/
open scoped Topology Pointwise
open MulAction Set Function
variable {G X : Type*} [TopologicalSpace G] [TopologicalSpace X]
[Group G] [IsTopologicalGroup G] [MulAction G X]
[SigmaCompactSpace G] [BaireSpace X] [T2Space X]
[ContinuousSMul G X] [IsPretransitive G X]
/-- Consider a sigma-compact group acting continuously and transitively on a Baire space. Then
the orbit map is open around the identity. It follows in `isOpenMap_smul_of_sigmaCompact` that it
is open around any point. -/
@[to_additive "Consider a sigma-compact additive group acting continuously and transitively on a
Baire space. Then the orbit map is open around zero. It follows in
`isOpenMap_vadd_of_sigmaCompact` that it is open around any point."]
theorem smul_singleton_mem_nhds_of_sigmaCompact
{U : Set G} (hU : U ∈ 𝓝 1) (x : X) : U • {x} ∈ 𝓝 x := by
/- Consider a small closed neighborhood `V` of the identity. Then the group is covered by
countably many translates of `V`, say `gᵢ V`. Let also `Kₙ` be a sequence of compact sets covering
the space. Then the image of `Kₙ ∩ gᵢ V` in the orbit is compact, and their unions covers the
space. By Baire, one of them has nonempty interior. Then `gᵢ V • x` has nonempty interior, and
so does `V • x`. Its interior contains a point `g' x` with `g' ∈ V`. Then `g'⁻¹ • V • x` contains
a neighborhood of `x`, and it is included in `V⁻¹ • V • x`, which is itself contained in `U • x`
if `V` is small enough. -/
obtain ⟨V, V_mem, V_closed, V_symm, VU⟩ : ∃ V ∈ 𝓝 (1 : G), IsClosed V ∧ V⁻¹ = V ∧ V * V ⊆ U :=
exists_closed_nhds_one_inv_eq_mul_subset hU
obtain ⟨s, s_count, hs⟩ : ∃ (s : Set G), s.Countable ∧ ⋃ g ∈ s, g • V = univ :=
countable_cover_nhds_of_sigmaCompact fun _ ↦ by simpa
let K : ℕ → Set G := compactCovering G
let F : ℕ × s → Set X := fun p ↦ (K p.1 ∩ (p.2 : G) • V) • ({x} : Set X)
obtain ⟨⟨n, ⟨g, hg⟩⟩, hi⟩ : ∃ i, (interior (F i)).Nonempty := by
have : Nonempty X := ⟨x⟩
have : Encodable s := Countable.toEncodable s_count
apply nonempty_interior_of_iUnion_of_closed
· rintro ⟨n, ⟨g, hg⟩⟩
apply IsCompact.isClosed
suffices H : IsCompact ((fun (g : G) ↦ g • x) '' (K n ∩ g • V)) by
simpa only [F, smul_singleton] using H
apply IsCompact.image
· exact (isCompact_compactCovering G n).inter_right (V_closed.smul g)
· exact continuous_id.smul continuous_const
· apply eq_univ_iff_forall.2 (fun y ↦ ?_)
obtain ⟨h, rfl⟩ : ∃ h, h • x = y := exists_smul_eq G x y
obtain ⟨n, hn⟩ : ∃ n, h ∈ K n := exists_mem_compactCovering h
obtain ⟨g, gs, hg⟩ : ∃ g ∈ s, h ∈ g • V := exists_set_mem_of_union_eq_top s _ hs _
simp only [F, smul_singleton, mem_iUnion, mem_image, mem_inter_iff, Prod.exists,
Subtype.exists, exists_prop]
exact ⟨n, g, gs, h, ⟨hn, hg⟩, rfl⟩
have I : (interior ((g • V) • {x})).Nonempty := by
apply hi.mono
apply interior_mono
exact smul_subset_smul_right inter_subset_right
obtain ⟨y, hy⟩ : (interior (V • ({x} : Set X))).Nonempty := by
rw [smul_assoc, interior_smul] at I
exact smul_set_nonempty.1 I
obtain ⟨g', hg', rfl⟩ : ∃ g' ∈ V, g' • x = y := by simpa using interior_subset hy
have J : (g' ⁻¹ • V) • {x} ∈ 𝓝 x := by
apply mem_interior_iff_mem_nhds.1
rwa [smul_assoc, interior_smul, mem_inv_smul_set_iff]
have : (g'⁻¹ • V) • {x} ⊆ U • ({x} : Set X) := by
apply smul_subset_smul_right
apply Subset.trans (smul_set_subset_smul (inv_mem_inv.2 hg')) ?_
rw [V_symm]
exact VU
exact Filter.mem_of_superset J this
/-- Consider a sigma-compact group acting continuously and transitively on a Baire space. Then
the orbit map is open. This is a version of the open mapping theorem, valid notably for the
action of a sigma-compact locally compact group on a locally compact space. -/
@[to_additive "Consider a sigma-compact additive group acting continuously and transitively on a
Baire space. Then the orbit map is open. This is a version of the open mapping theorem, valid
notably for the action of a sigma-compact locally compact group on a locally compact space."]
theorem isOpenMap_smul_of_sigmaCompact (x : X) : IsOpenMap (fun (g : G) ↦ g • x) := by
/- We have already proved the theorem around the basepoint of the orbit, in
`smul_singleton_mem_nhds_of_sigmaCompact`. The general statement follows around an arbitrary
point by changing basepoints. -/
simp_rw [isOpenMap_iff_nhds_le, Filter.le_map_iff]
intro g U hU
have : (· • x) = (· • (g • x)) ∘ (· * g⁻¹) := by
ext g
simp [smul_smul]
rw [this, image_comp, ← smul_singleton]
apply smul_singleton_mem_nhds_of_sigmaCompact
simpa using isOpenMap_mul_right g⁻¹ |>.image_mem_nhds hU
/-- A surjective morphism of topological groups is open when the source group is sigma-compact and
the target group is a Baire space (for instance a locally compact group). -/
@[to_additive]
theorem MonoidHom.isOpenMap_of_sigmaCompact
{H : Type*} [Group H] [TopologicalSpace H] [BaireSpace H] [T2Space H] [ContinuousMul H]
| (f : G →* H) (hf : Function.Surjective f) (h'f : Continuous f) :
IsOpenMap f := by
let A : MulAction G H := MulAction.compHom _ f
have : ContinuousSMul G H := continuousSMul_compHom h'f
have : IsPretransitive G H := isPretransitive_compHom hf
have : f = (fun (g : G) ↦ g • (1 : H)) := by simp [A, MulAction.compHom_smul_def]
rw [this]
exact isOpenMap_smul_of_sigmaCompact _
| Mathlib/Topology/Algebra/Group/OpenMapping.lean | 112 | 121 |
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.HasLimits
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
/-!
# Wide equalizers and wide coequalizers
This file defines wide (co)equalizers as special cases of (co)limits.
A wide equalizer for the family of morphisms `X ⟶ Y` indexed by `J` is the categorical
generalization of the subobject `{a ∈ A | ∀ j₁ j₂, f(j₁, a) = f(j₂, a)}`. Note that if `J` has
fewer than two morphisms this condition is trivial, so some lemmas and definitions assume `J` is
nonempty.
## Main definitions
* `WalkingParallelFamily` is the indexing category used for wide (co)equalizer diagrams
* `parallelFamily` is a functor from `WalkingParallelFamily` to our category `C`.
* a `Trident` is a cone over a parallel family.
* there is really only one interesting morphism in a trident: the arrow from the vertex of the
trident to the domain of f and g. It is called `Trident.ι`.
* a `wideEqualizer` is now just a `limit (parallelFamily f)`
Each of these has a dual.
## Main statements
* `wideEqualizer.ι_mono` states that every wideEqualizer map is a monomorphism
## Implementation notes
As with the other special shapes in the limits library, all the definitions here are given as
`abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about
general limits can be used.
## References
* [F. Borceux, *Handbook of Categorical Algebra 1*][borceux-vol1]
-/
noncomputable section
namespace CategoryTheory.Limits
open CategoryTheory
universe w v u u₂
variable {J : Type w}
/-- The type of objects for the diagram indexing a wide (co)equalizer. -/
inductive WalkingParallelFamily (J : Type w) : Type w
| zero : WalkingParallelFamily J
| one : WalkingParallelFamily J
open WalkingParallelFamily
instance : DecidableEq (WalkingParallelFamily J)
| zero, zero => isTrue rfl
| zero, one => isFalse fun t => WalkingParallelFamily.noConfusion t
| one, zero => isFalse fun t => WalkingParallelFamily.noConfusion t
| one, one => isTrue rfl
instance : Inhabited (WalkingParallelFamily J) :=
⟨zero⟩
-- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- The type family of morphisms for the diagram indexing a wide (co)equalizer. -/
inductive WalkingParallelFamily.Hom (J : Type w) :
WalkingParallelFamily J → WalkingParallelFamily J → Type w
| id : ∀ X : WalkingParallelFamily.{w} J, WalkingParallelFamily.Hom J X X
| line : J → WalkingParallelFamily.Hom J zero one
deriving DecidableEq
/-- Satisfying the inhabited linter -/
instance (J : Type v) : Inhabited (WalkingParallelFamily.Hom J zero zero) where default := Hom.id _
open WalkingParallelFamily.Hom
/-- Composition of morphisms in the indexing diagram for wide (co)equalizers. -/
def WalkingParallelFamily.Hom.comp :
∀ {X Y Z : WalkingParallelFamily J} (_ : WalkingParallelFamily.Hom J X Y)
(_ : WalkingParallelFamily.Hom J Y Z), WalkingParallelFamily.Hom J X Z
| _, _, _, id _, h => h
| _, _, _, line j, id one => line j
-- attribute [local tidy] tactic.case_bash Porting note: no tidy, no local
instance WalkingParallelFamily.category : SmallCategory (WalkingParallelFamily J) where
Hom := WalkingParallelFamily.Hom J
id := WalkingParallelFamily.Hom.id
comp := WalkingParallelFamily.Hom.comp
assoc f g h := by cases f <;> cases g <;> cases h <;> aesop_cat
comp_id f := by cases f <;> aesop_cat
@[simp]
theorem WalkingParallelFamily.hom_id (X : WalkingParallelFamily J) :
WalkingParallelFamily.Hom.id X = 𝟙 X :=
rfl
variable (J) in
/-- `Arrow (WalkingParallelFamily J)` identifies to the type obtained
by adding two elements to `T`. -/
def WalkingParallelFamily.arrowEquiv :
Arrow (WalkingParallelFamily J) ≃ Option (Option J) where
toFun f := match f.left, f.right, f.hom with
| zero, _, .id _ => none
| one, _, .id _ => some none
| zero, one, .line t => some (some t)
invFun x := match x with
| none => Arrow.mk (𝟙 zero)
| some none => Arrow.mk (𝟙 one)
| some (some t) => Arrow.mk (.line t)
left_inv := by rintro ⟨(_ | _), _, (_ | _)⟩ <;> rfl
right_inv := by rintro (_ | (_ | _)) <;> rfl
variable {C : Type u} [Category.{v} C]
variable {X Y : C} (f : J → (X ⟶ Y))
/-- `parallelFamily f` is the diagram in `C` consisting of the given family of morphisms, each with
common domain and codomain.
-/
def parallelFamily : WalkingParallelFamily J ⥤ C where
obj x := WalkingParallelFamily.casesOn x X Y
map {x y} h :=
match x, y, h with
| _, _, Hom.id _ => 𝟙 _
| _, _, line j => f j
map_comp := by
rintro _ _ _ ⟨⟩ ⟨⟩ <;>
· aesop_cat
@[simp]
theorem parallelFamily_obj_zero : (parallelFamily f).obj zero = X :=
rfl
@[simp]
theorem parallelFamily_obj_one : (parallelFamily f).obj one = Y :=
rfl
@[simp]
theorem parallelFamily_map_left {j : J} : (parallelFamily f).map (line j) = f j :=
rfl
/-- Every functor indexing a wide (co)equalizer is naturally isomorphic (actually, equal) to a
`parallelFamily` -/
@[simps!]
def diagramIsoParallelFamily (F : WalkingParallelFamily J ⥤ C) :
F ≅ parallelFamily fun j => F.map (line j) :=
NatIso.ofComponents (fun j => eqToIso <| by cases j <;> aesop_cat) <| by
rintro _ _ (_|_) <;> aesop_cat
/-- `WalkingParallelPair` as a category is equivalent to a special case of
`WalkingParallelFamily`. -/
@[simps!]
def walkingParallelFamilyEquivWalkingParallelPair :
WalkingParallelFamily.{w} (ULift Bool) ≌ WalkingParallelPair where
functor :=
parallelFamily fun p => cond p.down WalkingParallelPairHom.left WalkingParallelPairHom.right
inverse := parallelPair (line (ULift.up true)) (line (ULift.up false))
unitIso := NatIso.ofComponents (fun X => eqToIso (by cases X <;> rfl)) (by
rintro _ _ (_|⟨_|_⟩) <;> aesop_cat)
counitIso := NatIso.ofComponents (fun X => eqToIso (by cases X <;> rfl)) (by
rintro _ _ (_|_|_) <;> aesop_cat)
functor_unitIso_comp := by rintro (_|_) <;> aesop_cat
/-- A trident on `f` is just a `Cone (parallelFamily f)`. -/
abbrev Trident :=
Cone (parallelFamily f)
/-- A cotrident on `f` and `g` is just a `Cocone (parallelFamily f)`. -/
abbrev Cotrident :=
Cocone (parallelFamily f)
variable {f}
/-- A trident `t` on the parallel family `f : J → (X ⟶ Y)` consists of two morphisms
`t.π.app zero : t.X ⟶ X` and `t.π.app one : t.X ⟶ Y`. Of these, only the first one is
interesting, and we give it the shorter name `Trident.ι t`. -/
abbrev Trident.ι (t : Trident f) :=
t.π.app zero
/-- A cotrident `t` on the parallel family `f : J → (X ⟶ Y)` consists of two morphisms
`t.ι.app zero : X ⟶ t.X` and `t.ι.app one : Y ⟶ t.X`. Of these, only the second one is
interesting, and we give it the shorter name `Cotrident.π t`. -/
abbrev Cotrident.π (t : Cotrident f) :=
t.ι.app one
@[simp]
theorem Trident.ι_eq_app_zero (t : Trident f) : t.ι = t.π.app zero :=
rfl
@[simp]
theorem Cotrident.π_eq_app_one (t : Cotrident f) : t.π = t.ι.app one :=
rfl
@[reassoc (attr := simp)]
theorem Trident.app_zero (s : Trident f) (j : J) : s.π.app zero ≫ f j = s.π.app one := by
rw [← s.w (line j), parallelFamily_map_left]
@[reassoc (attr := simp)]
theorem Cotrident.app_one (s : Cotrident f) (j : J) : f j ≫ s.ι.app one = s.ι.app zero := by
rw [← s.w (line j), parallelFamily_map_left]
/-- A trident on `f : J → (X ⟶ Y)` is determined by the morphism `ι : P ⟶ X` satisfying
`∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂`.
-/
@[simps]
def Trident.ofι [Nonempty J] {P : C} (ι : P ⟶ X) (w : ∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂) :
Trident f where
pt := P
π :=
{ app := fun X => WalkingParallelFamily.casesOn X ι (ι ≫ f (Classical.arbitrary J))
naturality := fun i j f => by
dsimp
obtain - | k := f
· simp
· simp [w (Classical.arbitrary J) k] }
/-- A cotrident on `f : J → (X ⟶ Y)` is determined by the morphism `π : Y ⟶ P` satisfying
`∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π`.
-/
@[simps]
def Cotrident.ofπ [Nonempty J] {P : C} (π : Y ⟶ P) (w : ∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π) :
Cotrident f where
pt := P
ι :=
{ app := fun X => WalkingParallelFamily.casesOn X (f (Classical.arbitrary J) ≫ π) π
naturality := fun i j f => by
dsimp
obtain - | k := f
· simp
· simp [w (Classical.arbitrary J) k] }
-- See note [dsimp, simp]
theorem Trident.ι_ofι [Nonempty J] {P : C} (ι : P ⟶ X) (w : ∀ j₁ j₂, ι ≫ f j₁ = ι ≫ f j₂) :
(Trident.ofι ι w).ι = ι :=
rfl
theorem Cotrident.π_ofπ [Nonempty J] {P : C} (π : Y ⟶ P) (w : ∀ j₁ j₂, f j₁ ≫ π = f j₂ ≫ π) :
(Cotrident.ofπ π w).π = π :=
rfl
@[reassoc]
theorem Trident.condition (j₁ j₂ : J) (t : Trident f) : t.ι ≫ f j₁ = t.ι ≫ f j₂ := by
rw [t.app_zero, t.app_zero]
@[reassoc]
theorem Cotrident.condition (j₁ j₂ : J) (t : Cotrident f) : f j₁ ≫ t.π = f j₂ ≫ t.π := by
rw [t.app_one, t.app_one]
/-- To check whether two maps are equalized by both maps of a trident, it suffices to check it for
the first map -/
theorem Trident.equalizer_ext [Nonempty J] (s : Trident f) {W : C} {k l : W ⟶ s.pt}
(h : k ≫ s.ι = l ≫ s.ι) : ∀ j : WalkingParallelFamily J, k ≫ s.π.app j = l ≫ s.π.app j
| zero => h
| one => by rw [← s.app_zero (Classical.arbitrary J), reassoc_of% h]
/-- To check whether two maps are coequalized by both maps of a cotrident, it suffices to check it
for the second map -/
theorem Cotrident.coequalizer_ext [Nonempty J] (s : Cotrident f) {W : C} {k l : s.pt ⟶ W}
(h : s.π ≫ k = s.π ≫ l) : ∀ j : WalkingParallelFamily J, s.ι.app j ≫ k = s.ι.app j ≫ l
| zero => by rw [← s.app_one (Classical.arbitrary J), Category.assoc, Category.assoc, h]
| one => h
theorem Trident.IsLimit.hom_ext [Nonempty J] {s : Trident f} (hs : IsLimit s) {W : C}
{k l : W ⟶ s.pt} (h : k ≫ s.ι = l ≫ s.ι) : k = l :=
hs.hom_ext <| Trident.equalizer_ext _ h
theorem Cotrident.IsColimit.hom_ext [Nonempty J] {s : Cotrident f} (hs : IsColimit s) {W : C}
{k l : s.pt ⟶ W} (h : s.π ≫ k = s.π ≫ l) : k = l :=
hs.hom_ext <| Cotrident.coequalizer_ext _ h
/-- If `s` is a limit trident over `f`, then a morphism `k : W ⟶ X` satisfying
`∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂` induces a morphism `l : W ⟶ s.X` such that
`l ≫ Trident.ι s = k`. -/
def Trident.IsLimit.lift' [Nonempty J] {s : Trident f} (hs : IsLimit s) {W : C} (k : W ⟶ X)
(h : ∀ j₁ j₂, k ≫ f j₁ = k ≫ f j₂) : { l : W ⟶ s.pt // l ≫ Trident.ι s = k } :=
⟨hs.lift <| Trident.ofι _ h, hs.fac _ _⟩
/-- If `s` is a colimit cotrident over `f`, then a morphism `k : Y ⟶ W` satisfying
`∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k` induces a morphism `l : s.X ⟶ W` such that
`Cotrident.π s ≫ l = k`. -/
def Cotrident.IsColimit.desc' [Nonempty J] {s : Cotrident f} (hs : IsColimit s) {W : C} (k : Y ⟶ W)
(h : ∀ j₁ j₂, f j₁ ≫ k = f j₂ ≫ k) : { l : s.pt ⟶ W // Cotrident.π s ≫ l = k } :=
⟨hs.desc <| Cotrident.ofπ _ h, hs.fac _ _⟩
/-- This is a slightly more convenient method to verify that a trident is a limit cone. It
only asks for a proof of facts that carry any mathematical content -/
def Trident.IsLimit.mk [Nonempty J] (t : Trident f) (lift : ∀ s : Trident f, s.pt ⟶ t.pt)
(fac : ∀ s : Trident f, lift s ≫ t.ι = s.ι)
(uniq :
∀ (s : Trident f) (m : s.pt ⟶ t.pt)
(_ : ∀ j : WalkingParallelFamily J, m ≫ t.π.app j = s.π.app j), m = lift s) :
IsLimit t :=
{ lift
fac := fun s j =>
WalkingParallelFamily.casesOn j (fac s)
(by rw [← t.w (line (Classical.arbitrary J)), reassoc_of% fac, s.w])
uniq := uniq }
/-- This is another convenient method to verify that a trident is a limit cone. It
only asks for a proof of facts that carry any mathematical content, and allows access to the
same `s` for all parts. -/
def Trident.IsLimit.mk' [Nonempty J] (t : Trident f)
(create : ∀ s : Trident f, { l // l ≫ t.ι = s.ι ∧ ∀ {m}, m ≫ t.ι = s.ι → m = l }) :
IsLimit t :=
Trident.IsLimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w =>
(create s).2.2 (w zero)
/-- This is a slightly more convenient method to verify that a cotrident is a colimit cocone. It
only asks for a proof of facts that carry any mathematical content -/
def Cotrident.IsColimit.mk [Nonempty J] (t : Cotrident f) (desc : ∀ s : Cotrident f, t.pt ⟶ s.pt)
(fac : ∀ s : Cotrident f, t.π ≫ desc s = s.π)
(uniq :
∀ (s : Cotrident f) (m : t.pt ⟶ s.pt)
(_ : ∀ j : WalkingParallelFamily J, t.ι.app j ≫ m = s.ι.app j), m = desc s) :
IsColimit t :=
{ desc
fac := fun s j =>
WalkingParallelFamily.casesOn j (by rw [← t.w_assoc (line (Classical.arbitrary J)), fac, s.w])
(fac s)
uniq := uniq }
/-- This is another convenient method to verify that a cotrident is a colimit cocone. It
only asks for a proof of facts that carry any mathematical content, and allows access to the
same `s` for all parts. -/
def Cotrident.IsColimit.mk' [Nonempty J] (t : Cotrident f)
(create :
∀ s : Cotrident f, { l : t.pt ⟶ s.pt // t.π ≫ l = s.π ∧ ∀ {m}, t.π ≫ m = s.π → m = l }) :
IsColimit t :=
Cotrident.IsColimit.mk t (fun s => (create s).1) (fun s => (create s).2.1) fun s _ w =>
(create s).2.2 (w one)
/--
Given a limit cone for the family `f : J → (X ⟶ Y)`, for any `Z`, morphisms from `Z` to its point
are in bijection with morphisms `h : Z ⟶ X` such that `∀ j₁ j₂, h ≫ f j₁ = h ≫ f j₂`.
Further, this bijection is natural in `Z`: see `Trident.Limits.homIso_natural`.
-/
@[simps]
def Trident.IsLimit.homIso [Nonempty J] {t : Trident f} (ht : IsLimit t) (Z : C) :
(Z ⟶ t.pt) ≃ { h : Z ⟶ X // ∀ j₁ j₂, h ≫ f j₁ = h ≫ f j₂ } where
toFun k := ⟨k ≫ t.ι, by simp⟩
invFun h := (Trident.IsLimit.lift' ht _ h.prop).1
left_inv _ := Trident.IsLimit.hom_ext ht (Trident.IsLimit.lift' _ _ _).prop
right_inv _ := Subtype.ext (Trident.IsLimit.lift' ht _ _).prop
/-- The bijection of `Trident.IsLimit.homIso` is natural in `Z`. -/
theorem Trident.IsLimit.homIso_natural [Nonempty J] {t : Trident f} (ht : IsLimit t) {Z Z' : C}
(q : Z' ⟶ Z) (k : Z ⟶ t.pt) :
(Trident.IsLimit.homIso ht _ (q ≫ k) : Z' ⟶ X) =
q ≫ (Trident.IsLimit.homIso ht _ k : Z ⟶ X) :=
Category.assoc _ _ _
/-- Given a colimit cocone for the family `f : J → (X ⟶ Y)`, for any `Z`, morphisms from the cocone
point to `Z` are in bijection with morphisms `h : Z ⟶ X` such that
`∀ j₁ j₂, f j₁ ≫ h = f j₂ ≫ h`. Further, this bijection is natural in `Z`: see
`Cotrident.IsColimit.homIso_natural`.
-/
@[simps]
def Cotrident.IsColimit.homIso [Nonempty J] {t : Cotrident f} (ht : IsColimit t) (Z : C) :
(t.pt ⟶ Z) ≃ { h : Y ⟶ Z // ∀ j₁ j₂, f j₁ ≫ h = f j₂ ≫ h } where
toFun k := ⟨t.π ≫ k, by simp⟩
invFun h := (Cotrident.IsColimit.desc' ht _ h.prop).1
left_inv _ := Cotrident.IsColimit.hom_ext ht (Cotrident.IsColimit.desc' _ _ _).prop
right_inv _ := Subtype.ext (Cotrident.IsColimit.desc' ht _ _).prop
/-- The bijection of `Cotrident.IsColimit.homIso` is natural in `Z`. -/
theorem Cotrident.IsColimit.homIso_natural [Nonempty J] {t : Cotrident f} {Z Z' : C} (q : Z ⟶ Z')
(ht : IsColimit t) (k : t.pt ⟶ Z) :
(Cotrident.IsColimit.homIso ht _ (k ≫ q) : Y ⟶ Z') =
(Cotrident.IsColimit.homIso ht _ k : Y ⟶ Z) ≫ q :=
(Category.assoc _ _ _).symm
/-- This is a helper construction that can be useful when verifying that a category has certain wide
equalizers. Given `F : WalkingParallelFamily ⥤ C`, which is really the same as
`parallelFamily (fun j ↦ F.map (line j))`, and a trident on `fun j ↦ F.map (line j)`,
we get a cone on `F`.
If you're thinking about using this, have a look at
`hasWideEqualizers_of_hasLimit_parallelFamily`, which you may find to be an easier way of
achieving your goal. -/
def Cone.ofTrident {F : WalkingParallelFamily J ⥤ C} (t : Trident fun j => F.map (line j)) :
Cone F where
pt := t.pt
π :=
{ app := fun X => t.π.app X ≫ eqToHom (by cases X <;> aesop_cat)
naturality := fun j j' g => by cases g <;> aesop_cat }
/-- This is a helper construction that can be useful when verifying that a category has all
coequalizers. Given `F : WalkingParallelFamily ⥤ C`, which is really the same as
`parallelFamily (fun j ↦ F.map (line j))`, and a cotrident on `fun j ↦ F.map (line j)` we get a
cocone on `F`.
If you're thinking about using this, have a look at
`hasWideCoequalizers_of_hasColimit_parallelFamily`, which you may find to be an easier way
of achieving your goal. -/
def Cocone.ofCotrident {F : WalkingParallelFamily J ⥤ C} (t : Cotrident fun j => F.map (line j)) :
Cocone F where
pt := t.pt
ι :=
{ app := fun X => eqToHom (by cases X <;> aesop_cat) ≫ t.ι.app X
naturality := fun j j' g => by cases g <;> dsimp <;> simp [Cotrident.app_one t] }
@[simp]
theorem Cone.ofTrident_π {F : WalkingParallelFamily J ⥤ C} (t : Trident fun j => F.map (line j))
(j) : (Cone.ofTrident t).π.app j = t.π.app j ≫ eqToHom (by cases j <;> aesop_cat) :=
rfl
@[simp]
theorem Cocone.ofCotrident_ι {F : WalkingParallelFamily J ⥤ C}
(t : Cotrident fun j => F.map (line j)) (j) :
(Cocone.ofCotrident t).ι.app j = eqToHom (by cases j <;> aesop_cat) ≫ t.ι.app j :=
rfl
/-- Given `F : WalkingParallelFamily ⥤ C`, which is really the same as
`parallelFamily (fun j ↦ F.map (line j))` and a cone on `F`, we get a trident on
`fun j ↦ F.map (line j)`. -/
def Trident.ofCone {F : WalkingParallelFamily J ⥤ C} (t : Cone F) :
Trident fun j => F.map (line j) where
pt := t.pt
π :=
{ app := fun X => t.π.app X ≫ eqToHom (by cases X <;> aesop_cat)
naturality := by rintro _ _ (_|_) <;> aesop_cat }
/-- Given `F : WalkingParallelFamily ⥤ C`, which is really the same as
`parallelFamily (F.map left) (F.map right)` and a cocone on `F`, we get a cotrident on
`fun j ↦ F.map (line j)`. -/
def Cotrident.ofCocone {F : WalkingParallelFamily J ⥤ C} (t : Cocone F) :
Cotrident fun j => F.map (line j) where
| pt := t.pt
ι :=
{ app := fun X => eqToHom (by cases X <;> aesop_cat) ≫ t.ι.app X
| Mathlib/CategoryTheory/Limits/Shapes/WideEqualizers.lean | 436 | 438 |
/-
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.RingTheory.Ideal.AssociatedPrime.Basic
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-04-20")
| Mathlib/RingTheory/Ideal/AssociatedPrime.lean | 146 | 149 | |
/-
Copyright (c) 2023 Junyan Xu, Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu, Antoine Chambert-Loir
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Data.Fintype.Perm
import Mathlib.Data.Set.Card
import Mathlib.GroupTheory.GroupAction.Defs
import Mathlib.GroupTheory.GroupAction.DomAct.Basic
/-!
# Subgroup of `Equiv.Perm α` preserving a function
Let `α` and `ι` by types and let `f : α → ι`
* `DomMulAct.mem_stabilizer_iff` proves that the stabilizer of `f : α → ι`
in `(Equiv.Perm α)ᵈᵐᵃ` is the set of `g : (Equiv.Perm α)ᵈᵐᵃ` such that `f ∘ (mk.symm g) = f`.
The natural equivalence from `stabilizer (Perm α)ᵈᵐᵃ f` to `{ g : Perm α // p ∘ g = f }`
can be obtained as `subtypeEquiv mk.symm (fun _ => mem_stabilizer_iff)`
* `DomMulAct.stabilizerMulEquiv` is the `MulEquiv` from
the MulOpposite of this stabilizer to the product,
for `i : ι`, of `Equiv.Perm {a // f a = i}`.
* Under `Fintype α` and `Fintype ι`, `DomMulAct.stabilizer_card p` computes
the cardinality of the type of permutations preserving `p` :
`Fintype.card {g : Perm α // f ∘ g = f} = ∏ i, (Fintype.card {a // f a = i})!`.
* Without `Fintype ι`, `DomMulAct.stabilizer_card' p` gives an equivalent
formula, where the product is restricted to `Finset.univ.image f`.
-/
assert_not_exists Field
open Equiv MulAction
variable {α ι : Type*} {f : α → ι}
| namespace DomMulAct
lemma mem_stabilizer_iff {g : (Perm α)ᵈᵐᵃ} :
| Mathlib/GroupTheory/Perm/DomMulAct.lean | 41 | 43 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yakov Pechersky, Eric Wieser
-/
import Mathlib.Data.List.Basic
/-!
# Properties of `List.enum`
## Deprecation note
Many lemmas in this file have been replaced by theorems in Lean4,
in terms of `xs[i]?` and `xs[i]` rather than `get` and `get?`.
The deprecated results here are unused in Mathlib.
Any downstream users who can not easily adapt may remove the deprecations as needed.
-/
namespace List
variable {α : Type*}
theorem forall_mem_zipIdx {l : List α} {n : ℕ} {p : α × ℕ → Prop} :
(∀ x ∈ l.zipIdx n, p x) ↔ ∀ (i : ℕ) (_ : i < length l), p (l[i], n + i) := by
simp only [forall_mem_iff_getElem, getElem_zipIdx, length_zipIdx]
/-- Variant of `forall_mem_zipIdx` with the `zipIdx` argument specialized to `0`. -/
theorem forall_mem_zipIdx' {l : List α} {p : α × ℕ → Prop} :
(∀ x ∈ l.zipIdx, p x) ↔ ∀ (i : ℕ) (_ : i < length l), p (l[i], i) :=
forall_mem_zipIdx.trans <| by simp
theorem exists_mem_zipIdx {l : List α} {n : ℕ} {p : α × ℕ → Prop} :
(∃ x ∈ l.zipIdx n, p x) ↔ ∃ (i : ℕ) (_ : i < length l), p (l[i], n + i) := by
simp only [exists_mem_iff_getElem, getElem_zipIdx, length_zipIdx]
/-- Variant of `exists_mem_zipIdx` with the `zipIdx` argument specialized to `0`. -/
theorem exists_mem_zipIdx' {l : List α} {p : α × ℕ → Prop} :
| (∃ x ∈ l.zipIdx, p x) ↔ ∃ (i : ℕ) (_ : i < length l), p (l[i], i) :=
exists_mem_zipIdx.trans <| by simp
| Mathlib/Data/List/Enum.lean | 39 | 40 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Algebra.Group.TypeTags.Basic
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Finset.Piecewise
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.Filter.Curry
import Mathlib.Topology.Constructions.SumProd
import Mathlib.Topology.NhdsSet
/-!
# Constructions of new topological spaces from old ones
This file constructs pi types, subtypes and quotients of topological spaces
and sets up their basic theory, such as criteria for maps into or out of these
constructions to be continuous; descriptions of the open sets, neighborhood filters,
and generators of these constructions; and their behavior with respect to embeddings
and other specific classes of maps.
## Implementation note
The constructed topologies are defined using induced and coinduced topologies
along with the complete lattice structure on topologies. Their universal properties
(for example, a map `X → Y × Z` is continuous if and only if both projections
`X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of
continuity. With more work we can also extract descriptions of the open sets,
neighborhood filters and so on.
## Tags
product, subspace, quotient space
-/
noncomputable section
open Topology TopologicalSpace Set Filter Function
open scoped Set.Notation
universe u v u' v'
variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*}
section Constructions
instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) :=
coinduced (Quot.mk r) t
instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] :
TopologicalSpace (Quotient s) :=
coinduced Quotient.mk' t
instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] :
TopologicalSpace (Sigma X) :=
⨆ i, coinduced (Sigma.mk i) (t₂ i)
instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] :
TopologicalSpace ((i : ι) → Y i) :=
⨅ i, induced (fun f => f i) (t₂ i)
instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) :=
t.induced ULift.down
/-!
### `Additive`, `Multiplicative`
The topology on those type synonyms is inherited without change.
-/
section
variable [TopologicalSpace X]
open Additive Multiplicative
instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X›
instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X›
instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X›
instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X›
theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id
theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id
theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id
theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id
theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id
theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id
theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id
theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id
theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id
theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id
theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id
theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id
theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl
theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl
theorem nhds_toMul (x : Additive X) : 𝓝 x.toMul = map toMul (𝓝 x) := rfl
theorem nhds_toAdd (x : Multiplicative X) : 𝓝 x.toAdd = map toAdd (𝓝 x) := rfl
end
/-!
### Order dual
The topology on this type synonym is inherited without change.
-/
section
variable [TopologicalSpace X]
open OrderDual
instance OrderDual.instTopologicalSpace : TopologicalSpace Xᵒᵈ := ‹_›
instance OrderDual.instDiscreteTopology [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹_›
theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id
theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id
theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id
theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id
theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id
theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id
theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl
theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl
variable [Preorder X] {x : X}
instance OrderDual.instNeBotNhdsWithinIoi [(𝓝[<] x).NeBot] : (𝓝[>] toDual x).NeBot := ‹_›
instance OrderDual.instNeBotNhdsWithinIio [(𝓝[>] x).NeBot] : (𝓝[<] toDual x).NeBot := ‹_›
end
theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s}
{x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x :=
preimage_nhds_coinduced hs
/-- The image of a dense set under `Quotient.mk'` is a dense set. -/
theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) :
Dense (Quotient.mk' '' s) :=
Quotient.mk''_surjective.denseRange.dense_image continuous_coinduced_rng H
/-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/
theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) :
DenseRange (Quotient.mk' ∘ f) :=
Quotient.mk''_surjective.denseRange.comp hf continuous_coinduced_rng
theorem continuous_map_of_le {α : Type*} [TopologicalSpace α]
{s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) :=
continuous_coinduced_rng
theorem continuous_map_sInf {α : Type*} [TopologicalSpace α]
{S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) :=
continuous_coinduced_rng
instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) :=
⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩
instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X]
[hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) :=
⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩
instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)]
[h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) :=
⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩
@[simp] lemma comap_nhdsWithin_range {α β} [TopologicalSpace β] (f : α → β) (y : β) :
comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range
section Top
variable [TopologicalSpace X]
/-
The 𝓝 filter and the subspace topology.
-/
theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t :=
mem_nhds_induced _ x t
theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) :=
nhds_induced _ x
lemma nhds_subtype_eq_comap_nhdsWithin (s : Set X) (x : { x // x ∈ s }) :
𝓝 x = comap (↑) (𝓝[s] (x : X)) := by
rw [nhds_subtype, ← comap_nhdsWithin_range, Subtype.range_val]
theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} :
𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by
rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal,
nhds_induced]
theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} :
𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by
rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton,
Subtype.coe_injective.preimage_image]
theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} :
(𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by
rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff]
theorem discreteTopology_subtype_iff {S : Set X} :
DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by
simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff]
end Top
/-- A type synonym equipped with the topology whose open sets are the empty set and the sets with
finite complements. -/
def CofiniteTopology (X : Type*) := X
namespace CofiniteTopology
/-- The identity equivalence between `` and `CofiniteTopology `. -/
def of : X ≃ CofiniteTopology X :=
Equiv.refl X
instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default
instance : TopologicalSpace (CofiniteTopology X) where
IsOpen s := s.Nonempty → Set.Finite sᶜ
isOpen_univ := by simp
isOpen_inter s t := by
rintro hs ht ⟨x, hxs, hxt⟩
rw [compl_inter]
exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩)
isOpen_sUnion := by
rintro s h ⟨x, t, hts, hzt⟩
rw [compl_sUnion]
exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩)
theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite :=
Iff.rfl
theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by
simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left]
theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by
simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff]
theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by
ext U
rw [mem_nhds_iff]
constructor
· rintro ⟨V, hVU, V_op, haV⟩
exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩
· rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩
exact ⟨U, Subset.rfl, fun _ => hU', hU⟩
theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} :
s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq]
end CofiniteTopology
end Constructions
section Prod
variable [TopologicalSpace X] [TopologicalSpace Y]
theorem MapClusterPt.curry_prodMap {α β : Type*}
{f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y}
(hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) :
MapClusterPt (x, y) (la.curry lb) (.map f g) := by
rw [mapClusterPt_iff_frequently] at hf hg
rw [((𝓝 x).basis_sets.prod_nhds (𝓝 y).basis_sets).mapClusterPt_iff_frequently]
rintro ⟨s, t⟩ ⟨hs, ht⟩
rw [frequently_curry_iff]
exact (hf s hs).mono fun x hx ↦ (hg t ht).mono fun y hy ↦ ⟨hx, hy⟩
theorem MapClusterPt.prodMap {α β : Type*}
{f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y}
(hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) :
MapClusterPt (x, y) (la ×ˢ lb) (.map f g) :=
(hf.curry_prodMap hg).mono <| map_mono curry_le_prod
end Prod
section Bool
lemma continuous_bool_rng [TopologicalSpace X] {f : X → Bool} (b : Bool) :
Continuous f ↔ IsClopen (f ⁻¹' {b}) := by
rw [continuous_discrete_rng, Bool.forall_bool' b, IsClopen, ← isOpen_compl_iff, ← preimage_compl,
Bool.compl_singleton, and_comm]
end Bool
section Subtype
variable [TopologicalSpace X] [TopologicalSpace Y] {p : X → Prop}
lemma Topology.IsInducing.subtypeVal {t : Set Y} : IsInducing ((↑) : t → Y) := ⟨rfl⟩
@[deprecated (since := "2024-10-28")] alias inducing_subtype_val := IsInducing.subtypeVal
lemma Topology.IsInducing.of_codRestrict {f : X → Y} {t : Set Y} (ht : ∀ x, f x ∈ t)
(h : IsInducing (t.codRestrict f ht)) : IsInducing f := subtypeVal.comp h
@[deprecated (since := "2024-10-28")] alias Inducing.of_codRestrict := IsInducing.of_codRestrict
lemma Topology.IsEmbedding.subtypeVal : IsEmbedding ((↑) : Subtype p → X) :=
⟨.subtypeVal, Subtype.coe_injective⟩
@[deprecated (since := "2024-10-26")] alias embedding_subtype_val := IsEmbedding.subtypeVal
theorem Topology.IsClosedEmbedding.subtypeVal (h : IsClosed {a | p a}) :
IsClosedEmbedding ((↑) : Subtype p → X) :=
⟨.subtypeVal, by rwa [Subtype.range_coe_subtype]⟩
@[continuity, fun_prop]
theorem continuous_subtype_val : Continuous (@Subtype.val X p) :=
continuous_induced_dom
theorem Continuous.subtype_val {f : Y → Subtype p} (hf : Continuous f) :
Continuous fun x => (f x : X) :=
continuous_subtype_val.comp hf
theorem IsOpen.isOpenEmbedding_subtypeVal {s : Set X} (hs : IsOpen s) :
IsOpenEmbedding ((↑) : s → X) :=
⟨.subtypeVal, (@Subtype.range_coe _ s).symm ▸ hs⟩
theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s → X) :=
hs.isOpenEmbedding_subtypeVal.isOpenMap
theorem IsOpenMap.restrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} (hs : IsOpen s) :
IsOpenMap (s.restrict f) :=
hf.comp hs.isOpenMap_subtype_val
lemma IsClosed.isClosedEmbedding_subtypeVal {s : Set X} (hs : IsClosed s) :
IsClosedEmbedding ((↑) : s → X) := .subtypeVal hs
theorem IsClosed.isClosedMap_subtype_val {s : Set X} (hs : IsClosed s) :
IsClosedMap ((↑) : s → X) :=
hs.isClosedEmbedding_subtypeVal.isClosedMap
@[continuity, fun_prop]
theorem Continuous.subtype_mk {f : Y → X} (h : Continuous f) (hp : ∀ x, p (f x)) :
Continuous fun x => (⟨f x, hp x⟩ : Subtype p) :=
continuous_induced_rng.2 h
theorem Continuous.subtype_map {f : X → Y} (h : Continuous f) {q : Y → Prop}
(hpq : ∀ x, p x → q (f x)) : Continuous (Subtype.map f hpq) :=
(h.comp continuous_subtype_val).subtype_mk _
theorem continuous_inclusion {s t : Set X} (h : s ⊆ t) : Continuous (inclusion h) :=
continuous_id.subtype_map h
theorem continuousAt_subtype_val {p : X → Prop} {x : Subtype p} :
ContinuousAt ((↑) : Subtype p → X) x :=
continuous_subtype_val.continuousAt
theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s ⊆ closure ((↑) '' t) := by
rw [IsInducing.subtypeVal.dense_iff, SetCoe.forall]
rfl
theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s → X) (𝓝 x) = 𝓝[s] ↑x := by
rw [IsInducing.subtypeVal.map_nhds_eq, Subtype.range_val]
theorem map_nhds_subtype_coe_eq_nhds {x : X} (hx : p x) (h : ∀ᶠ x in 𝓝 x, p x) :
map ((↑) : Subtype p → X) (𝓝 ⟨x, hx⟩) = 𝓝 x :=
map_nhds_induced_of_mem <| by rw [Subtype.range_val]; exact h
theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) :=
nhds_induced _ _
theorem tendsto_subtype_rng {Y : Type*} {p : X → Prop} {l : Filter Y} {f : Y → Subtype p} :
∀ {x : Subtype p}, Tendsto f l (𝓝 x) ↔ Tendsto (fun x => (f x : X)) l (𝓝 (x : X))
| ⟨a, ha⟩ => by rw [nhds_subtype_eq_comap, tendsto_comap_iff]; rfl
theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} :
x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ → X) '' s) :=
closure_induced
@[simp]
theorem continuousAt_codRestrict_iff {f : X → Y} {t : Set Y} (h1 : ∀ x, f x ∈ t) {x : X} :
ContinuousAt (codRestrict f t h1) x ↔ ContinuousAt f x :=
IsInducing.subtypeVal.continuousAt_iff
alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff
theorem ContinuousAt.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) {x : s}
(h2 : ContinuousAt f x) : ContinuousAt (h1.restrict f s t) x :=
(h2.comp continuousAt_subtype_val).codRestrict _
theorem ContinuousAt.restrictPreimage {f : X → Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) :
ContinuousAt (s.restrictPreimage f) x :=
h.restrict _
@[continuity, fun_prop]
theorem Continuous.codRestrict {f : X → Y} {s : Set Y} (hf : Continuous f) (hs : ∀ a, f a ∈ s) :
Continuous (s.codRestrict f hs) :=
hf.subtype_mk hs
@[continuity, fun_prop]
theorem Continuous.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t)
(h2 : Continuous f) : Continuous (h1.restrict f s t) :=
(h2.comp continuous_subtype_val).codRestrict _
@[continuity, fun_prop]
theorem Continuous.restrictPreimage {f : X → Y} {s : Set Y} (h : Continuous f) :
Continuous (s.restrictPreimage f) :=
h.restrict _
lemma Topology.IsEmbedding.restrict {f : X → Y}
(hf : IsEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) :
IsEmbedding H.restrict :=
.of_comp (hf.continuous.restrict H) continuous_subtype_val (hf.comp .subtypeVal)
lemma Topology.IsOpenEmbedding.restrict {f : X → Y}
(hf : IsOpenEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) (hs : IsOpen s) :
IsOpenEmbedding H.restrict :=
⟨hf.isEmbedding.restrict H, (by
rw [MapsTo.range_restrict]
exact continuous_subtype_val.1 _ (hf.isOpenMap _ hs))⟩
theorem Topology.IsInducing.codRestrict {e : X → Y} (he : IsInducing e) {s : Set Y}
(hs : ∀ x, e x ∈ s) : IsInducing (codRestrict e s hs) :=
he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val
@[deprecated (since := "2024-10-28")] alias Inducing.codRestrict := IsInducing.codRestrict
protected lemma Topology.IsEmbedding.codRestrict {e : X → Y} (he : IsEmbedding e) (s : Set Y)
(hs : ∀ x, e x ∈ s) : IsEmbedding (codRestrict e s hs) :=
he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val
@[deprecated (since := "2024-10-26")]
alias Embedding.codRestrict := IsEmbedding.codRestrict
variable {s t : Set X}
protected lemma Topology.IsEmbedding.inclusion (h : s ⊆ t) :
IsEmbedding (inclusion h) := IsEmbedding.subtypeVal.codRestrict _ _
protected lemma Topology.IsOpenEmbedding.inclusion (hst : s ⊆ t) (hs : IsOpen (t ↓∩ s)) :
IsOpenEmbedding (inclusion hst) where
toIsEmbedding := .inclusion _
isOpen_range := by rwa [range_inclusion]
protected lemma Topology.IsClosedEmbedding.inclusion (hst : s ⊆ t) (hs : IsClosed (t ↓∩ s)) :
IsClosedEmbedding (inclusion hst) where
toIsEmbedding := .inclusion _
isClosed_range := by rwa [range_inclusion]
@[deprecated (since := "2024-10-26")]
alias embedding_inclusion := IsEmbedding.inclusion
/-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced
by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/
theorem DiscreteTopology.of_subset {X : Type*} [TopologicalSpace X] {s t : Set X}
(_ : DiscreteTopology s) (ts : t ⊆ s) : DiscreteTopology t :=
(IsEmbedding.inclusion ts).discreteTopology
/-- Let `s` be a discrete subset of a topological space. Then the preimage of `s` by
a continuous injective map is also discrete. -/
theorem DiscreteTopology.preimage_of_continuous_injective {X Y : Type*} [TopologicalSpace X]
[TopologicalSpace Y] (s : Set Y) [DiscreteTopology s] {f : X → Y} (hc : Continuous f)
(hinj : Function.Injective f) : DiscreteTopology (f ⁻¹' s) :=
DiscreteTopology.of_continuous_injective (β := s) (Continuous.restrict
(by exact fun _ x ↦ x) hc) ((MapsTo.restrict_inj _).mpr hinj.injOn)
/-- If `f : X → Y` is a quotient map,
then its restriction to the preimage of an open set is a quotient map too. -/
theorem Topology.IsQuotientMap.restrictPreimage_isOpen {f : X → Y} (hf : IsQuotientMap f)
{s : Set Y} (hs : IsOpen s) : IsQuotientMap (s.restrictPreimage f) := by
refine isQuotientMap_iff.2 ⟨hf.surjective.restrictPreimage _, fun U ↦ ?_⟩
rw [hs.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, ← hf.isOpen_preimage,
(hs.preimage hf.continuous).isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen,
image_val_preimage_restrictPreimage]
@[deprecated (since := "2024-10-22")]
alias QuotientMap.restrictPreimage_isOpen := IsQuotientMap.restrictPreimage_isOpen
open scoped Set.Notation in
lemma isClosed_preimage_val {s t : Set X} : IsClosed (s ↓∩ t) ↔ s ∩ closure (s ∩ t) ⊆ t := by
rw [← closure_eq_iff_isClosed, IsEmbedding.subtypeVal.closure_eq_preimage_closure_image,
← Subtype.val_injective.image_injective.eq_iff, Subtype.image_preimage_coe,
Subtype.image_preimage_coe, subset_antisymm_iff, and_iff_left, Set.subset_inter_iff,
and_iff_right]
exacts [Set.inter_subset_left, Set.subset_inter Set.inter_subset_left subset_closure]
theorem frontier_inter_open_inter {s t : Set X} (ht : IsOpen t) :
frontier (s ∩ t) ∩ t = frontier s ∩ t := by
simp only [Set.inter_comm _ t, ← Subtype.preimage_coe_eq_preimage_coe_iff,
ht.isOpenMap_subtype_val.preimage_frontier_eq_frontier_preimage continuous_subtype_val,
Subtype.preimage_coe_self_inter]
section SetNotation
open scoped Set.Notation
lemma IsOpen.preimage_val {s t : Set X} (ht : IsOpen t) : IsOpen (s ↓∩ t) :=
ht.preimage continuous_subtype_val
lemma IsClosed.preimage_val {s t : Set X} (ht : IsClosed t) : IsClosed (s ↓∩ t) :=
ht.preimage continuous_subtype_val
@[simp] lemma IsOpen.inter_preimage_val_iff {s t : Set X} (hs : IsOpen s) :
IsOpen (s ↓∩ t) ↔ IsOpen (s ∩ t) :=
⟨fun h ↦ by simpa using hs.isOpenMap_subtype_val _ h,
fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩
@[simp] lemma IsClosed.inter_preimage_val_iff {s t : Set X} (hs : IsClosed s) :
IsClosed (s ↓∩ t) ↔ IsClosed (s ∩ t) :=
⟨fun h ↦ by simpa using hs.isClosedMap_subtype_val _ h,
fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩
end SetNotation
end Subtype
section Quotient
variable [TopologicalSpace X] [TopologicalSpace Y]
variable {r : X → X → Prop} {s : Setoid X}
theorem isQuotientMap_quot_mk : IsQuotientMap (@Quot.mk X r) :=
⟨Quot.exists_rep, rfl⟩
@[deprecated (since := "2024-10-22")]
alias quotientMap_quot_mk := isQuotientMap_quot_mk
@[continuity, fun_prop]
theorem continuous_quot_mk : Continuous (@Quot.mk X r) :=
continuous_coinduced_rng
@[continuity, fun_prop]
theorem continuous_quot_lift {f : X → Y} (hr : ∀ a b, r a b → f a = f b) (h : Continuous f) :
Continuous (Quot.lift f hr : Quot r → Y) :=
continuous_coinduced_dom.2 h
theorem isQuotientMap_quotient_mk' : IsQuotientMap (@Quotient.mk' X s) :=
isQuotientMap_quot_mk
@[deprecated (since := "2024-10-22")]
alias quotientMap_quotient_mk' := isQuotientMap_quotient_mk'
theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) :=
continuous_coinduced_rng
theorem Continuous.quotient_lift {f : X → Y} (h : Continuous f) (hs : ∀ a b, a ≈ b → f a = f b) :
Continuous (Quotient.lift f hs : Quotient s → Y) :=
continuous_coinduced_dom.2 h
theorem Continuous.quotient_liftOn' {f : X → Y} (h : Continuous f)
(hs : ∀ a b, s a b → f a = f b) :
Continuous (fun x => Quotient.liftOn' x f hs : Quotient s → Y) :=
h.quotient_lift hs
open scoped Relator in
@[continuity, fun_prop]
theorem Continuous.quotient_map' {t : Setoid Y} {f : X → Y} (hf : Continuous f)
(H : (s.r ⇒ t.r) f f) : Continuous (Quotient.map' f H) :=
(continuous_quotient_mk'.comp hf).quotient_lift _
end Quotient
section Pi
variable {ι : Type*} {π : ι → Type*} {κ : Type*} [TopologicalSpace X]
[T : ∀ i, TopologicalSpace (π i)] {f : X → ∀ i : ι, π i}
theorem continuous_pi_iff : Continuous f ↔ ∀ i, Continuous fun a => f a i := by
simp only [continuous_iInf_rng, continuous_induced_rng, comp_def]
@[continuity, fun_prop]
theorem continuous_pi (h : ∀ i, Continuous fun a => f a i) : Continuous f :=
continuous_pi_iff.2 h
@[continuity, fun_prop]
theorem continuous_apply (i : ι) : Continuous fun p : ∀ i, π i => p i :=
continuous_iInf_dom continuous_induced_dom
@[continuity]
theorem continuous_apply_apply {ρ : κ → ι → Type*} [∀ j i, TopologicalSpace (ρ j i)] (j : κ)
(i : ι) : Continuous fun p : ∀ j, ∀ i, ρ j i => p j i :=
(continuous_apply i).comp (continuous_apply j)
theorem continuousAt_apply (i : ι) (x : ∀ i, π i) : ContinuousAt (fun p : ∀ i, π i => p i) x :=
(continuous_apply i).continuousAt
theorem Filter.Tendsto.apply_nhds {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i}
(h : Tendsto f l (𝓝 x)) (i : ι) : Tendsto (fun a => f a i) l (𝓝 <| x i) :=
(continuousAt_apply i _).tendsto.comp h
@[fun_prop]
protected theorem Continuous.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} (hf : ∀ i, Continuous (f i)) : Continuous (Pi.map f) :=
continuous_pi fun i ↦ (hf i).comp (continuous_apply i)
theorem nhds_pi {a : ∀ i, π i} : 𝓝 a = pi fun i => 𝓝 (a i) := by
simp only [nhds_iInf, nhds_induced, Filter.pi]
protected theorem IsOpenMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i}
(hfo : ∀ i, IsOpenMap (f i)) (hsurj : ∀ᶠ i in cofinite, Surjective (f i)) :
IsOpenMap (Pi.map f) := by
refine IsOpenMap.of_nhds_le fun x ↦ ?_
rw [nhds_pi, nhds_pi, map_piMap_pi hsurj]
exact Filter.pi_mono fun i ↦ (hfo i).nhds_le _
protected theorem IsOpenQuotientMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} (hf : ∀ i, IsOpenQuotientMap (f i)) : IsOpenQuotientMap (Pi.map f) :=
⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2, .piMap (fun i ↦ (hf i).3) <|
.of_forall fun i ↦ (hf i).1⟩
theorem tendsto_pi_nhds {f : Y → ∀ i, π i} {g : ∀ i, π i} {u : Filter Y} :
Tendsto f u (𝓝 g) ↔ ∀ x, Tendsto (fun i => f i x) u (𝓝 (g x)) := by
rw [nhds_pi, Filter.tendsto_pi]
theorem continuousAt_pi {f : X → ∀ i, π i} {x : X} :
ContinuousAt f x ↔ ∀ i, ContinuousAt (fun y => f y i) x :=
tendsto_pi_nhds
@[fun_prop]
theorem continuousAt_pi' {f : X → ∀ i, π i} {x : X} (hf : ∀ i, ContinuousAt (fun y => f y i) x) :
ContinuousAt f x :=
continuousAt_pi.2 hf
@[fun_prop]
protected theorem ContinuousAt.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)]
{f : ∀ i, π i → Y i} {x : ∀ i, π i} (hf : ∀ i, ContinuousAt (f i) (x i)) :
ContinuousAt (Pi.map f) x :=
continuousAt_pi.2 fun i ↦ (hf i).comp (continuousAt_apply i x)
theorem Pi.continuous_precomp' {ι' : Type*} (φ : ι' → ι) :
Continuous (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) :=
continuous_pi fun j ↦ continuous_apply (φ j)
theorem Pi.continuous_precomp {ι' : Type*} (φ : ι' → ι) :
Continuous (· ∘ φ : (ι → X) → (ι' → X)) :=
Pi.continuous_precomp' φ
theorem Pi.continuous_postcomp' {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
{g : ∀ i, π i → X i} (hg : ∀ i, Continuous (g i)) :
Continuous (fun (f : (∀ i, π i)) (i : ι) ↦ g i (f i)) :=
continuous_pi fun i ↦ (hg i).comp <| continuous_apply i
theorem Pi.continuous_postcomp [TopologicalSpace Y] {g : X → Y} (hg : Continuous g) :
Continuous (g ∘ · : (ι → X) → (ι → Y)) :=
Pi.continuous_postcomp' fun _ ↦ hg
lemma Pi.induced_precomp' {ι' : Type*} (φ : ι' → ι) :
induced (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) Pi.topologicalSpace =
⨅ i', induced (eval (φ i')) (T (φ i')) := by
simp [Pi.topologicalSpace, induced_iInf, induced_compose, comp_def]
lemma Pi.induced_precomp [TopologicalSpace Y] {ι' : Type*} (φ : ι' → ι) :
induced (· ∘ φ) Pi.topologicalSpace =
⨅ i', induced (eval (φ i')) ‹TopologicalSpace Y› :=
induced_precomp' φ
@[continuity, fun_prop]
lemma Pi.continuous_restrict (S : Set ι) :
Continuous (S.restrict : (∀ i : ι, π i) → (∀ i : S, π i)) :=
Pi.continuous_precomp' ((↑) : S → ι)
@[continuity, fun_prop]
lemma Pi.continuous_restrict₂ {s t : Set ι} (hst : s ⊆ t) : Continuous (restrict₂ (π := π) hst) :=
continuous_pi fun _ ↦ continuous_apply _
@[continuity, fun_prop]
theorem Finset.continuous_restrict (s : Finset ι) : Continuous (s.restrict (π := π)) :=
continuous_pi fun _ ↦ continuous_apply _
@[continuity, fun_prop]
theorem Finset.continuous_restrict₂ {s t : Finset ι} (hst : s ⊆ t) :
Continuous (Finset.restrict₂ (π := π) hst) :=
continuous_pi fun _ ↦ continuous_apply _
variable [TopologicalSpace Z]
@[continuity, fun_prop]
theorem Pi.continuous_restrict_apply (s : Set X) {f : X → Z} (hf : Continuous f) :
Continuous (s.restrict f) := hf.comp continuous_subtype_val
@[continuity, fun_prop]
theorem Pi.continuous_restrict₂_apply {s t : Set X} (hst : s ⊆ t)
{f : t → Z} (hf : Continuous f) :
Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst)
@[continuity, fun_prop]
theorem Finset.continuous_restrict_apply (s : Finset X) {f : X → Z} (hf : Continuous f) :
Continuous (s.restrict f) := hf.comp continuous_subtype_val
@[continuity, fun_prop]
theorem Finset.continuous_restrict₂_apply {s t : Finset X} (hst : s ⊆ t)
{f : t → Z} (hf : Continuous f) :
Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst)
lemma Pi.induced_restrict (S : Set ι) :
induced (S.restrict) Pi.topologicalSpace =
⨅ i ∈ S, induced (eval i) (T i) := by
simp +unfoldPartialApp [← iInf_subtype'', ← induced_precomp' ((↑) : S → ι),
restrict]
lemma Pi.induced_restrict_sUnion (𝔖 : Set (Set ι)) :
induced (⋃₀ 𝔖).restrict (Pi.topologicalSpace (Y := fun i : (⋃₀ 𝔖) ↦ π i)) =
⨅ S ∈ 𝔖, induced S.restrict Pi.topologicalSpace := by
simp_rw [Pi.induced_restrict, iInf_sUnion]
theorem Filter.Tendsto.update [DecidableEq ι] {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i}
(hf : Tendsto f l (𝓝 x)) (i : ι) {g : Y → π i} {xi : π i} (hg : Tendsto g l (𝓝 xi)) :
Tendsto (fun a => update (f a) i (g a)) l (𝓝 <| update x i xi) :=
tendsto_pi_nhds.2 fun j => by rcases eq_or_ne j i with (rfl | hj) <;> simp [*, hf.apply_nhds]
theorem ContinuousAt.update [DecidableEq ι] {x : X} (hf : ContinuousAt f x) (i : ι) {g : X → π i}
(hg : ContinuousAt g x) : ContinuousAt (fun a => update (f a) i (g a)) x :=
hf.tendsto.update i hg
theorem Continuous.update [DecidableEq ι] (hf : Continuous f) (i : ι) {g : X → π i}
(hg : Continuous g) : Continuous fun a => update (f a) i (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.update i hg.continuousAt
/-- `Function.update f i x` is continuous in `(f, x)`. -/
@[continuity, fun_prop]
theorem continuous_update [DecidableEq ι] (i : ι) :
Continuous fun f : (∀ j, π j) × π i => update f.1 i f.2 :=
continuous_fst.update i continuous_snd
/-- `Pi.mulSingle i x` is continuous in `x`. -/
@[to_additive (attr := continuity) "`Pi.single i x` is continuous in `x`."]
theorem continuous_mulSingle [∀ i, One (π i)] [DecidableEq ι] (i : ι) :
Continuous fun x => (Pi.mulSingle i x : ∀ i, π i) :=
continuous_const.update _ continuous_id
section Fin
variable {n : ℕ} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)]
theorem Filter.Tendsto.finCons
{f : Y → π 0} {g : Y → ∀ j : Fin n, π j.succ} {l : Filter Y} {x : π 0} {y : ∀ j, π (Fin.succ j)}
(hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => Fin.cons (f a) (g a)) l (𝓝 <| Fin.cons x y) :=
tendsto_pi_nhds.2 fun j => Fin.cases (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j
theorem ContinuousAt.finCons {f : X → π 0} {g : X → ∀ j : Fin n, π (Fin.succ j)} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => Fin.cons (f a) (g a)) x :=
hf.tendsto.finCons hg
theorem Continuous.finCons {f : X → π 0} {g : X → ∀ j : Fin n, π (Fin.succ j)}
(hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.cons (f a) (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finCons hg.continuousAt
theorem Filter.Tendsto.matrixVecCons
{f : Y → Z} {g : Y → Fin n → Z} {l : Filter Y} {x : Z} {y : Fin n → Z}
(hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => Matrix.vecCons (f a) (g a)) l (𝓝 <| Matrix.vecCons x y) :=
hf.finCons hg
theorem ContinuousAt.matrixVecCons
{f : X → Z} {g : X → Fin n → Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => Matrix.vecCons (f a) (g a)) x :=
hf.finCons hg
theorem Continuous.matrixVecCons
{f : X → Z} {g : X → Fin n → Z} (hf : Continuous f) (hg : Continuous g) :
Continuous fun a => Matrix.vecCons (f a) (g a) :=
hf.finCons hg
theorem Filter.Tendsto.finSnoc
{f : Y → ∀ j : Fin n, π j.castSucc} {g : Y → π (Fin.last _)}
{l : Filter Y} {x : ∀ j, π (Fin.castSucc j)} {y : π (Fin.last _)}
(hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => Fin.snoc (f a) (g a)) l (𝓝 <| Fin.snoc x y) :=
tendsto_pi_nhds.2 fun j => Fin.lastCases (by simpa) (by simpa using tendsto_pi_nhds.1 hf) j
theorem ContinuousAt.finSnoc {f : X → ∀ j : Fin n, π j.castSucc} {g : X → π (Fin.last _)} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => Fin.snoc (f a) (g a)) x :=
hf.tendsto.finSnoc hg
theorem Continuous.finSnoc {f : X → ∀ j : Fin n, π j.castSucc} {g : X → π (Fin.last _)}
(hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.snoc (f a) (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finSnoc hg.continuousAt
theorem Filter.Tendsto.finInsertNth
(i : Fin (n + 1)) {f : Y → π i} {g : Y → ∀ j : Fin n, π (i.succAbove j)} {l : Filter Y}
{x : π i} {y : ∀ j, π (i.succAbove j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) :
Tendsto (fun a => i.insertNth (f a) (g a)) l (𝓝 <| i.insertNth x y) :=
tendsto_pi_nhds.2 fun j => Fin.succAboveCases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j
@[deprecated (since := "2025-01-02")]
alias Filter.Tendsto.fin_insertNth := Filter.Tendsto.finInsertNth
theorem ContinuousAt.finInsertNth
(i : Fin (n + 1)) {f : X → π i} {g : X → ∀ j : Fin n, π (i.succAbove j)} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun a => i.insertNth (f a) (g a)) x :=
hf.tendsto.finInsertNth i hg
@[deprecated (since := "2025-01-02")]
alias ContinuousAt.fin_insertNth := ContinuousAt.finInsertNth
theorem Continuous.finInsertNth
(i : Fin (n + 1)) {f : X → π i} {g : X → ∀ j : Fin n, π (i.succAbove j)}
(hf : Continuous f) (hg : Continuous g) : Continuous fun a => i.insertNth (f a) (g a) :=
continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finInsertNth i hg.continuousAt
@[deprecated (since := "2025-01-02")]
alias Continuous.fin_insertNth := Continuous.finInsertNth
theorem Filter.Tendsto.finInit {f : Y → ∀ j : Fin (n + 1), π j} {l : Filter Y} {x : ∀ j, π j}
(hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.init (f a)) l (𝓝 <| Fin.init x) :=
tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.castSucc
@[fun_prop]
theorem ContinuousAt.finInit {f : X → ∀ j : Fin (n + 1), π j} {x : X}
(hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.init (f a)) x :=
hf.tendsto.finInit
@[fun_prop]
theorem Continuous.finInit {f : X → ∀ j : Fin (n + 1), π j} (hf : Continuous f) :
Continuous fun a ↦ Fin.init (f a) :=
continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finInit
theorem Filter.Tendsto.finTail {f : Y → ∀ j : Fin (n + 1), π j} {l : Filter Y} {x : ∀ j, π j}
(hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.tail (f a)) l (𝓝 <| Fin.tail x) :=
tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.succ
@[fun_prop]
theorem ContinuousAt.finTail {f : X → ∀ j : Fin (n + 1), π j} {x : X}
(hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.tail (f a)) x :=
hf.tendsto.finTail
@[fun_prop]
theorem Continuous.finTail {f : X → ∀ j : Fin (n + 1), π j} (hf : Continuous f) :
Continuous fun a ↦ Fin.tail (f a) :=
continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finTail
end Fin
theorem isOpen_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hi : i.Finite)
(hs : ∀ a ∈ i, IsOpen (s a)) : IsOpen (pi i s) := by
rw [pi_def]; exact hi.isOpen_biInter fun a ha => (hs _ ha).preimage (continuous_apply _)
theorem isOpen_pi_iff {s : Set (∀ a, π a)} :
IsOpen s ↔
∀ f, f ∈ s → ∃ (I : Finset ι) (u : ∀ a, Set (π a)),
(∀ a, a ∈ I → IsOpen (u a) ∧ f a ∈ u a) ∧ (I : Set ι).pi u ⊆ s := by
rw [isOpen_iff_nhds]
simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff]
refine forall₂_congr fun a _ => ⟨?_, ?_⟩
· rintro ⟨I, t, ⟨h1, h2⟩⟩
refine ⟨I, fun a => eval a '' (I : Set ι).pi fun a => (h1 a).choose, fun i hi => ?_, ?_⟩
· simp_rw [eval_image_pi (Finset.mem_coe.mpr hi)
(pi_nonempty_iff.mpr fun i => ⟨_, fun _ => (h1 i).choose_spec.2.2⟩)]
exact (h1 i).choose_spec.2
· exact Subset.trans
(pi_mono fun i hi => (eval_image_pi_subset hi).trans (h1 i).choose_spec.1) h2
· rintro ⟨I, t, ⟨h1, h2⟩⟩
classical
refine ⟨I, fun a => ite (a ∈ I) (t a) univ, fun i => ?_, ?_⟩
· by_cases hi : i ∈ I
· use t i
simp_rw [if_pos hi]
exact ⟨Subset.rfl, (h1 i) hi⟩
· use univ
simp_rw [if_neg hi]
exact ⟨Subset.rfl, isOpen_univ, mem_univ _⟩
· rw [← univ_pi_ite]
simp only [← ite_and, ← Finset.mem_coe, and_self_iff, univ_pi_ite, h2]
theorem isOpen_pi_iff' [Finite ι] {s : Set (∀ a, π a)} :
IsOpen s ↔
∀ f, f ∈ s → ∃ u : ∀ a, Set (π a), (∀ a, IsOpen (u a) ∧ f a ∈ u a) ∧ univ.pi u ⊆ s := by
cases nonempty_fintype ι
rw [isOpen_iff_nhds]
simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff]
refine forall₂_congr fun a _ => ⟨?_, ?_⟩
· rintro ⟨I, t, ⟨h1, h2⟩⟩
refine
⟨fun i => (h1 i).choose,
⟨fun i => (h1 i).choose_spec.2,
(pi_mono fun i _ => (h1 i).choose_spec.1).trans (Subset.trans ?_ h2)⟩⟩
rw [← pi_inter_compl (I : Set ι)]
exact inter_subset_left
· exact fun ⟨u, ⟨h1, _⟩⟩ =>
⟨Finset.univ, u, ⟨fun i => ⟨u i, ⟨rfl.subset, h1 i⟩⟩, by rwa [Finset.coe_univ]⟩⟩
theorem isClosed_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hs : ∀ a ∈ i, IsClosed (s a)) :
IsClosed (pi i s) := by
rw [pi_def]; exact isClosed_biInter fun a ha => (hs _ ha).preimage (continuous_apply _)
theorem mem_nhds_of_pi_mem_nhds {I : Set ι} {s : ∀ i, Set (π i)} (a : ∀ i, π i) (hs : I.pi s ∈ 𝓝 a)
{i : ι} (hi : i ∈ I) : s i ∈ 𝓝 (a i) := by
rw [nhds_pi] at hs; exact mem_of_pi_mem_pi hs hi
theorem set_pi_mem_nhds {i : Set ι} {s : ∀ a, Set (π a)} {x : ∀ a, π a} (hi : i.Finite)
(hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by
rw [pi_def, biInter_mem hi]
exact fun a ha => (continuous_apply a).continuousAt (hs a ha)
theorem set_pi_mem_nhds_iff {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} (a : ∀ i, π i) :
I.pi s ∈ 𝓝 a ↔ ∀ i : ι, i ∈ I → s i ∈ 𝓝 (a i) := by
rw [nhds_pi, pi_mem_pi_iff hI]
theorem interior_pi_set {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} :
interior (pi I s) = I.pi fun i => interior (s i) := by
ext a
simp only [Set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI]
theorem exists_finset_piecewise_mem_of_mem_nhds [DecidableEq ι] {s : Set (∀ a, π a)} {x : ∀ a, π a}
(hs : s ∈ 𝓝 x) (y : ∀ a, π a) : ∃ I : Finset ι, I.piecewise x y ∈ s := by
simp only [nhds_pi, Filter.mem_pi'] at hs
rcases hs with ⟨I, t, htx, hts⟩
refine ⟨I, hts fun i hi => ?_⟩
simpa [Finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i)
theorem pi_generateFrom_eq {π : ι → Type*} {g : ∀ a, Set (Set (π a))} :
(@Pi.topologicalSpace ι π fun a => generateFrom (g a)) =
generateFrom
{ t | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, s a ∈ g a) ∧ t = pi (↑i) s } := by
refine le_antisymm ?_ ?_
· apply le_generateFrom
rintro _ ⟨s, i, hi, rfl⟩
letI := fun a => generateFrom (g a)
exact isOpen_set_pi i.finite_toSet (fun a ha => GenerateOpen.basic _ (hi a ha))
· classical
refine le_iInf fun i => coinduced_le_iff_le_induced.1 <| le_generateFrom fun s hs => ?_
refine GenerateOpen.basic _ ⟨update (fun i => univ) i s, {i}, ?_⟩
simp [hs]
theorem pi_eq_generateFrom :
Pi.topologicalSpace =
generateFrom
{ g | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, IsOpen (s a)) ∧ g = pi (↑i) s } :=
calc Pi.topologicalSpace
_ = @Pi.topologicalSpace ι π fun _ => generateFrom { s | IsOpen s } := by
simp only [generateFrom_setOf_isOpen]
_ = _ := pi_generateFrom_eq
theorem pi_generateFrom_eq_finite {π : ι → Type*} {g : ∀ a, Set (Set (π a))} [Finite ι]
(hg : ∀ a, ⋃₀ g a = univ) :
(@Pi.topologicalSpace ι π fun a => generateFrom (g a)) =
generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s } := by
cases nonempty_fintype ι
rw [pi_generateFrom_eq]
refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_)
· exact fun s ⟨t, ht, Eq⟩ => ⟨t, Finset.univ, by simp [ht, Eq]⟩
· rintro s ⟨t, i, ht, rfl⟩
letI := generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s }
refine isOpen_iff_forall_mem_open.2 fun f hf => ?_
choose c hcg hfc using fun a => sUnion_eq_univ_iff.1 (hg a) (f a)
refine ⟨pi i t ∩ pi ((↑i)ᶜ : Set ι) c, inter_subset_left, ?_, ⟨hf, fun a _ => hfc a⟩⟩
classical
rw [← univ_pi_piecewise]
refine GenerateOpen.basic _ ⟨_, fun a => ?_, rfl⟩
by_cases a ∈ i <;> simp [*]
theorem induced_to_pi {X : Type*} (f : X → ∀ i, π i) :
induced f Pi.topologicalSpace = ⨅ i, induced (f · i) inferInstance := by
simp_rw [Pi.topologicalSpace, induced_iInf, induced_compose, Function.comp_def]
/-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type
endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a
map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by
the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i`
where `Π i, π i` is endowed with the usual product topology. -/
theorem inducing_iInf_to_pi {X : Type*} (f : ∀ i, X → π i) :
@IsInducing X (∀ i, π i) (⨅ i, induced (f i) inferInstance) _ fun x i => f i x :=
letI := ⨅ i, induced (f i) inferInstance; ⟨(induced_to_pi _).symm⟩
variable [Finite ι] [∀ i, DiscreteTopology (π i)]
/-- A finite product of discrete spaces is discrete. -/
instance Pi.discreteTopology : DiscreteTopology (∀ i, π i) :=
singletons_open_iff_discrete.mp fun x => by
rw [← univ_pi_singleton]
exact isOpen_set_pi finite_univ fun i _ => (isOpen_discrete {x i})
end Pi
section Sigma
variable {ι κ : Type*} {σ : ι → Type*} {τ : κ → Type*} [∀ i, TopologicalSpace (σ i)]
[∀ k, TopologicalSpace (τ k)] [TopologicalSpace X]
@[continuity, fun_prop]
theorem continuous_sigmaMk {i : ι} : Continuous (@Sigma.mk ι σ i) :=
continuous_iSup_rng continuous_coinduced_rng
theorem isOpen_sigma_iff {s : Set (Sigma σ)} : IsOpen s ↔ ∀ i, IsOpen (Sigma.mk i ⁻¹' s) := by
rw [isOpen_iSup_iff]
rfl
theorem isClosed_sigma_iff {s : Set (Sigma σ)} : IsClosed s ↔ ∀ i, IsClosed (Sigma.mk i ⁻¹' s) := by
simp only [← isOpen_compl_iff, isOpen_sigma_iff, preimage_compl]
theorem isOpenMap_sigmaMk {i : ι} : IsOpenMap (@Sigma.mk ι σ i) := by
intro s hs
rw [isOpen_sigma_iff]
intro j
rcases eq_or_ne j i with (rfl | hne)
· rwa [preimage_image_eq _ sigma_mk_injective]
· rw [preimage_image_sigmaMk_of_ne hne]
exact isOpen_empty
theorem isOpen_range_sigmaMk {i : ι} : IsOpen (range (@Sigma.mk ι σ i)) :=
isOpenMap_sigmaMk.isOpen_range
theorem isClosedMap_sigmaMk {i : ι} : IsClosedMap (@Sigma.mk ι σ i) := by
intro s hs
rw [isClosed_sigma_iff]
intro j
rcases eq_or_ne j i with (rfl | hne)
· rwa [preimage_image_eq _ sigma_mk_injective]
· rw [preimage_image_sigmaMk_of_ne hne]
exact isClosed_empty
theorem isClosed_range_sigmaMk {i : ι} : IsClosed (range (@Sigma.mk ι σ i)) :=
isClosedMap_sigmaMk.isClosed_range
lemma Topology.IsOpenEmbedding.sigmaMk {i : ι} : IsOpenEmbedding (@Sigma.mk ι σ i) :=
.of_continuous_injective_isOpenMap continuous_sigmaMk sigma_mk_injective isOpenMap_sigmaMk
@[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigmaMk := IsOpenEmbedding.sigmaMk
lemma Topology.IsClosedEmbedding.sigmaMk {i : ι} : IsClosedEmbedding (@Sigma.mk ι σ i) :=
.of_continuous_injective_isClosedMap continuous_sigmaMk sigma_mk_injective isClosedMap_sigmaMk
@[deprecated (since := "2024-10-30")] alias isClosedEmbedding_sigmaMk := IsClosedEmbedding.sigmaMk
lemma Topology.IsEmbedding.sigmaMk {i : ι} : IsEmbedding (@Sigma.mk ι σ i) :=
IsClosedEmbedding.sigmaMk.1
@[deprecated (since := "2024-10-26")]
alias embedding_sigmaMk := IsEmbedding.sigmaMk
theorem Sigma.nhds_mk (i : ι) (x : σ i) : 𝓝 (⟨i, x⟩ : Sigma σ) = Filter.map (Sigma.mk i) (𝓝 x) :=
(IsOpenEmbedding.sigmaMk.map_nhds_eq x).symm
theorem Sigma.nhds_eq (x : Sigma σ) : 𝓝 x = Filter.map (Sigma.mk x.1) (𝓝 x.2) := by
cases x
apply Sigma.nhds_mk
theorem comap_sigmaMk_nhds (i : ι) (x : σ i) : comap (Sigma.mk i) (𝓝 ⟨i, x⟩) = 𝓝 x :=
(IsEmbedding.sigmaMk.nhds_eq_comap _).symm
theorem isOpen_sigma_fst_preimage (s : Set ι) : IsOpen (Sigma.fst ⁻¹' s : Set (Σ a, σ a)) := by
rw [← biUnion_of_singleton s, preimage_iUnion₂]
simp only [← range_sigmaMk]
exact isOpen_biUnion fun _ _ => isOpen_range_sigmaMk
/-- A map out of a sum type is continuous iff its restriction to each summand is. -/
@[simp]
theorem continuous_sigma_iff {f : Sigma σ → X} :
Continuous f ↔ ∀ i, Continuous fun a => f ⟨i, a⟩ := by
delta instTopologicalSpaceSigma
rw [continuous_iSup_dom]
exact forall_congr' fun _ => continuous_coinduced_dom
/-- A map out of a sum type is continuous if its restriction to each summand is. -/
@[continuity, fun_prop]
theorem continuous_sigma {f : Sigma σ → X} (hf : ∀ i, Continuous fun a => f ⟨i, a⟩) :
Continuous f :=
continuous_sigma_iff.2 hf
/-- A map defined on a sigma type (a.k.a. the disjoint union of an indexed family of topological
spaces) is inducing iff its restriction to each component is inducing and each the image of each
component under `f` can be separated from the images of all other components by an open set. -/
theorem inducing_sigma {f : Sigma σ → X} :
IsInducing f ↔ (∀ i, IsInducing (f ∘ Sigma.mk i)) ∧
(∀ i, ∃ U, IsOpen U ∧ ∀ x, f x ∈ U ↔ x.1 = i) := by
refine ⟨fun h ↦ ⟨fun i ↦ h.comp IsEmbedding.sigmaMk.1, fun i ↦ ?_⟩, ?_⟩
· rcases h.isOpen_iff.1 (isOpen_range_sigmaMk (i := i)) with ⟨U, hUo, hU⟩
refine ⟨U, hUo, ?_⟩
simpa [Set.ext_iff] using hU
· refine fun ⟨h₁, h₂⟩ ↦ isInducing_iff_nhds.2 fun ⟨i, x⟩ ↦ ?_
rw [Sigma.nhds_mk, (h₁ i).nhds_eq_comap, comp_apply, ← comap_comap, map_comap_of_mem]
rcases h₂ i with ⟨U, hUo, hU⟩
filter_upwards [preimage_mem_comap <| hUo.mem_nhds <| (hU _).2 rfl] with y hy
simpa [hU] using hy
@[simp 1100]
theorem continuous_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} :
Continuous (Sigma.map f₁ f₂) ↔ ∀ i, Continuous (f₂ i) :=
continuous_sigma_iff.trans <| by
simp only [Sigma.map, IsEmbedding.sigmaMk.continuous_iff, comp_def]
@[continuity, fun_prop]
theorem Continuous.sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (hf : ∀ i, Continuous (f₂ i)) :
Continuous (Sigma.map f₁ f₂) :=
continuous_sigma_map.2 hf
theorem isOpenMap_sigma {f : Sigma σ → X} : IsOpenMap f ↔ ∀ i, IsOpenMap fun a => f ⟨i, a⟩ := by
simp only [isOpenMap_iff_nhds_le, Sigma.forall, Sigma.nhds_eq, map_map, comp_def]
theorem isOpenMap_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} :
IsOpenMap (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenMap (f₂ i) :=
isOpenMap_sigma.trans <|
forall_congr' fun i => (@IsOpenEmbedding.sigmaMk _ _ _ (f₁ i)).isOpenMap_iff.symm
lemma Topology.isInducing_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)}
(h₁ : Injective f₁) : IsInducing (Sigma.map f₁ f₂) ↔ ∀ i, IsInducing (f₂ i) := by
simp only [isInducing_iff_nhds, Sigma.forall, Sigma.nhds_mk, Sigma.map_mk,
← map_sigma_mk_comap h₁, map_inj sigma_mk_injective]
@[deprecated (since := "2024-10-28")] alias inducing_sigma_map := isInducing_sigmaMap
lemma Topology.isEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)}
(h : Injective f₁) : IsEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsEmbedding (f₂ i) := by
simp only [isEmbedding_iff, Injective.sigma_map, isInducing_sigmaMap h, forall_and,
h.sigma_map_iff]
@[deprecated (since := "2024-10-26")]
alias embedding_sigma_map := isEmbedding_sigmaMap
lemma Topology.isOpenEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) :
IsOpenEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenEmbedding (f₂ i) := by
simp only [isOpenEmbedding_iff_isEmbedding_isOpenMap, isOpenMap_sigma_map, isEmbedding_sigmaMap h,
forall_and]
@[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigma_map := isOpenEmbedding_sigmaMap
end Sigma
section ULift
theorem ULift.isOpen_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} :
IsOpen s ↔ IsOpen (ULift.up ⁻¹' s) := by
rw [ULift.topologicalSpace, ← Equiv.ulift_apply, ← Equiv.ulift.coinduced_symm, ← isOpen_coinduced]
theorem ULift.isClosed_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} :
IsClosed s ↔ IsClosed (ULift.up ⁻¹' s) := by
rw [← isOpen_compl_iff, ← isOpen_compl_iff, isOpen_iff, preimage_compl]
@[continuity, fun_prop]
theorem continuous_uliftDown [TopologicalSpace X] : Continuous (ULift.down : ULift.{v, u} X → X) :=
continuous_induced_dom
@[continuity, fun_prop]
theorem continuous_uliftUp [TopologicalSpace X] : Continuous (ULift.up : X → ULift.{v, u} X) :=
continuous_induced_rng.2 continuous_id
@[deprecated (since := "2025-02-10")] alias continuous_uLift_down := continuous_uliftDown
@[deprecated (since := "2025-02-10")] alias continuous_uLift_up := continuous_uliftUp
@[continuity, fun_prop]
theorem continuous_uliftMap [TopologicalSpace X] [TopologicalSpace Y]
(f : X → Y) (hf : Continuous f) :
Continuous (ULift.map f : ULift.{u'} X → ULift.{v'} Y) := by
change Continuous (ULift.up ∘ f ∘ ULift.down)
fun_prop
lemma Topology.IsEmbedding.uliftDown [TopologicalSpace X] :
IsEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨⟨rfl⟩, ULift.down_injective⟩
@[deprecated (since := "2024-10-26")]
alias embedding_uLift_down := IsEmbedding.uliftDown
lemma Topology.IsClosedEmbedding.uliftDown [TopologicalSpace X] :
IsClosedEmbedding (ULift.down : ULift.{v, u} X → X) :=
⟨.uliftDown, by simp only [ULift.down_surjective.range_eq, isClosed_univ]⟩
@[deprecated (since := "2024-10-30")]
alias ULift.isClosedEmbedding_down := IsClosedEmbedding.uliftDown
instance [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (ULift X) :=
IsEmbedding.uliftDown.discreteTopology
end ULift
section Monad
variable [TopologicalSpace X] {s : Set X} {t : Set s}
theorem IsOpen.trans (ht : IsOpen t) (hs : IsOpen s) : IsOpen (t : Set X) := by
rcases isOpen_induced_iff.mp ht with ⟨s', hs', rfl⟩
rw [Subtype.image_preimage_coe]
exact hs.inter hs'
theorem IsClosed.trans (ht : IsClosed t) (hs : IsClosed s) : IsClosed (t : Set X) := by
rcases isClosed_induced_iff.mp ht with ⟨s', hs', rfl⟩
rw [Subtype.image_preimage_coe]
exact hs.inter hs'
end Monad
section NhdsSet
variable [TopologicalSpace X] [TopologicalSpace Y]
{s : Set X} {t : Set Y}
/-- The product of a neighborhood of `s` and a neighborhood of `t` is a neighborhood of `s ×ˢ t`,
formulated in terms of a filter inequality. -/
theorem nhdsSet_prod_le (s : Set X) (t : Set Y) : 𝓝ˢ (s ×ˢ t) ≤ 𝓝ˢ s ×ˢ 𝓝ˢ t :=
((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).ge_iff.2 fun (_u, _v) ⟨⟨huo, hsu⟩, hvo, htv⟩ ↦
(huo.prod hvo).mem_nhdsSet.2 <| prod_mono hsu htv
theorem Filter.eventually_nhdsSet_prod_iff {p : X × Y → Prop} :
(∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q) ↔
∀ x ∈ s, ∀ y ∈ t,
∃ px : X → Prop, (∀ᶠ x' in 𝓝 x, px x') ∧ ∃ py : Y → Prop, (∀ᶠ y' in 𝓝 y, py y') ∧
∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y) := by
simp_rw [eventually_nhdsSet_iff_forall, forall_prod_set, nhds_prod_eq, eventually_prod_iff]
theorem Filter.Eventually.prod_nhdsSet {p : X × Y → Prop} {px : X → Prop} {py : Y → Prop}
(hp : ∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y)) (hs : ∀ᶠ x in 𝓝ˢ s, px x)
(ht : ∀ᶠ y in 𝓝ˢ t, py y) : ∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q :=
nhdsSet_prod_le _ _ (mem_of_superset (prod_mem_prod hs ht) fun _ ⟨hx, hy⟩ ↦ hp hx hy)
end NhdsSet
| Mathlib/Topology/Constructions.lean | 1,727 | 1,730 | |
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SimpleGraph.DegreeSum
import Mathlib.Combinatorics.SimpleGraph.Regularity.Lemma
import Mathlib.Combinatorics.SimpleGraph.Triangle.Basic
import Mathlib.Combinatorics.SimpleGraph.Triangle.Counting
import Mathlib.Data.Finset.CastCard
/-!
# Triangle removal lemma
In this file, we prove the triangle removal lemma.
## References
[Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp]
-/
open Finset Fintype Nat SzemerediRegularity
variable {α : Type*} [DecidableEq α] [Fintype α] {G : SimpleGraph α} [DecidableRel G.Adj]
{s t : Finset α} {P : Finpartition (univ : Finset α)} {ε : ℝ}
namespace SimpleGraph
/-- An explicit form for the constant in the triangle removal lemma.
Note that this depends on `SzemerediRegularity.bound`, which is a tower-type exponential. This means
`triangleRemovalBound` is in practice absolutely tiny. -/
noncomputable def triangleRemovalBound (ε : ℝ) : ℝ :=
min (2 * ⌈4/ε⌉₊^3)⁻¹ ((1 - ε/4) * (ε/(16 * bound (ε/8) ⌈4/ε⌉₊))^3)
|
lemma triangleRemovalBound_pos (hε : 0 < ε) (hε₁ : ε ≤ 1) : 0 < triangleRemovalBound ε := by
have : 0 < 1 - ε / 4 := by linarith
unfold triangleRemovalBound
| Mathlib/Combinatorics/SimpleGraph/Triangle/Removal.lean | 35 | 38 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Justus Springer
-/
import Mathlib.Topology.Category.TopCat.OpenNhds
import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing
/-!
# Stalks
For a presheaf `F` on a topological space `X`, valued in some category `C`, the *stalk* of `F`
at the point `x : X` is defined as the colimit of the composition of the inclusion of categories
`(OpenNhds x)ᵒᵖ ⥤ (Opens X)ᵒᵖ` and the functor `F : (Opens X)ᵒᵖ ⥤ C`.
For an open neighborhood `U` of `x`, we define the map `F.germ x : F.obj (op U) ⟶ F.stalk x` as the
canonical morphism into this colimit.
Taking stalks is functorial: For every point `x : X` we define a functor `stalkFunctor C x`,
sending presheaves on `X` to objects of `C`. Furthermore, for a map `f : X ⟶ Y` between
topological spaces, we define `stalkPushforward` as the induced map on the stalks
`(f _* ℱ).stalk (f x) ⟶ ℱ.stalk x`.
Some lemmas about stalks and germs only hold for certain classes of concrete categories. A basic
property of forgetful functors of categories of algebraic structures (like `MonCat`,
`CommRingCat`,...) is that they preserve filtered colimits. Since stalks are filtered colimits,
this ensures that the stalks of presheaves valued in these categories behave exactly as for
`Type`-valued presheaves. For example, in `germ_exist` we prove that in such a category, every
element of the stalk is the germ of a section.
Furthermore, if we require the forgetful functor to reflect isomorphisms and preserve limits (as
is the case for most algebraic structures), we have access to the unique gluing API and can prove
further properties. Most notably, in `is_iso_iff_stalk_functor_map_iso`, we prove that in such
a category, a morphism of sheaves is an isomorphism if and only if all of its stalk maps are
isomorphisms.
See also the definition of "algebraic structures" in the stacks project:
https://stacks.math.columbia.edu/tag/007L
-/
assert_not_exists OrderedCommMonoid
noncomputable section
universe v u v' u'
open CategoryTheory
open TopCat
open CategoryTheory.Limits
open TopologicalSpace Topology
open Opposite
open scoped AlgebraicGeometry
variable {C : Type u} [Category.{v} C]
variable [HasColimits.{v} C]
variable {X Y Z : TopCat.{v}}
namespace TopCat.Presheaf
variable (C) in
/-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/
def stalkFunctor (x : X) : X.Presheaf C ⥤ C :=
(whiskeringLeft _ _ C).obj (OpenNhds.inclusion x).op ⋙ colim
/-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor
nbhds x ⥤ opens F.X ⥤ C
-/
def stalk (ℱ : X.Presheaf C) (x : X) : C :=
(stalkFunctor C x).obj ℱ
-- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ)
@[simp]
theorem stalkFunctor_obj (ℱ : X.Presheaf C) (x : X) : (stalkFunctor C x).obj ℱ = ℱ.stalk x :=
rfl
/-- The germ of a section of a presheaf over an open at a point of that open.
-/
def germ (F : X.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) : F.obj (op U) ⟶ stalk F x :=
colimit.ι ((OpenNhds.inclusion x).op ⋙ F) (op ⟨U, hx⟩)
/-- The germ of a global section of a presheaf at a point. -/
def Γgerm (F : X.Presheaf C) (x : X) : F.obj (op ⊤) ⟶ stalk F x :=
F.germ ⊤ x True.intro
@[reassoc]
theorem germ_res (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : X) (hx : x ∈ U) :
F.map i.op ≫ F.germ U x hx = F.germ V x (i.le hx) :=
let i' : (⟨U, hx⟩ : OpenNhds x) ⟶ ⟨V, i.le hx⟩ := i
colimit.w ((OpenNhds.inclusion x).op ⋙ F) i'.op
/-- A variant of `germ_res` with `op V ⟶ op U`
so that the LHS is more general and simp fires more easier. -/
@[reassoc (attr := simp)]
theorem germ_res' (F : X.Presheaf C) {U V : Opens X} (i : op V ⟶ op U) (x : X) (hx : x ∈ U) :
F.map i ≫ F.germ U x hx = F.germ V x (i.unop.le hx) :=
let i' : (⟨U, hx⟩ : OpenNhds x) ⟶ ⟨V, i.unop.le hx⟩ := i.unop
colimit.w ((OpenNhds.inclusion x).op ⋙ F) i'.op
@[reassoc]
lemma map_germ_eq_Γgerm (F : X.Presheaf C) {U : Opens X} {i : U ⟶ ⊤} (x : X) (hx : x ∈ U) :
F.map i.op ≫ F.germ U x hx = F.Γgerm x :=
germ_res F i x hx
variable {FC : C → C → Type*} {CC : C → Type*} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)]
theorem germ_res_apply (F : X.Presheaf C)
{U V : Opens X} (i : U ⟶ V) (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) :
F.germ U x hx (F.map i.op s) = F.germ V x (i.le hx) s := by
rw [← ConcreteCategory.comp_apply, germ_res]
theorem germ_res_apply' (F : X.Presheaf C)
{U V : Opens X} (i : op V ⟶ op U) (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) :
F.germ U x hx (F.map i s) = F.germ V x (i.unop.le hx) s := by
rw [← ConcreteCategory.comp_apply, germ_res']
| lemma Γgerm_res_apply (F : X.Presheaf C)
{U : Opens X} {i : U ⟶ ⊤} (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) :
F.germ U x hx (F.map i.op s) = F.Γgerm x s := F.germ_res_apply i x hx s
| Mathlib/Topology/Sheaves/Stalks.lean | 122 | 125 |
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Johan Commelin
-/
import Mathlib.GroupTheory.FreeAbelianGroup
/-!
# Free rings
The theory of the free ring over a type.
## Main definitions
* `FreeRing α` : the free (not commutative in general) ring over a type.
* `lift (f : α → R)` : the ring hom `FreeRing α →+* R` induced by `f`.
* `map (f : α → β)` : the ring hom `FreeRing α →+* FreeRing β` induced by `f`.
## Implementation details
`FreeRing α` is implemented as the free abelian group over the free monoid on `α`.
## Tags
free ring
-/
universe u v
/--
If `α` is a type, then `FreeRing α` is the free ring generated by `α`.
This is a ring equipped with a function `FreeRing.of : α → FreeRing α` which has
the following universal property: if `R` is any ring, and `f : α → R` is any function,
then this function is the composite of `FreeRing.of` and a unique ring homomorphism
`FreeRing.lift f : FreeRing α →+* R`.
A typical element of `FreeRing α` is a `ℤ`-linear combination of
formal products of elements of `α`.
For example if `x` and `y` are terms of type `α` then `3 * x * y * x - 2 * y * x + 1` is a
"typical" element of `FreeRing α`. In particular if `α` is empty
then `FreeRing α` is isomorphic to `ℤ`, and if `α` has one term `t`
then `FreeRing α` is isomorphic to the polynomial ring `ℤ[t]`.
If `α` has two or more terms then `FreeRing α` is not commutative.
One can think of `FreeRing α` as the free non-commutative polynomial ring
with coefficients in the integers and variables indexed by `α`.
-/
def FreeRing (α : Type u) : Type u :=
FreeAbelianGroup <| FreeMonoid α
instance (α : Type u) : Ring (FreeRing α) :=
FreeAbelianGroup.ring _
instance (α : Type u) : Inhabited (FreeRing α) := by
dsimp only [FreeRing]
infer_instance
instance (α : Type u) : Nontrivial (FreeRing α) :=
| inferInstanceAs <| Nontrivial (FreeAbelianGroup _)
namespace FreeRing
variable {α : Type u}
/-- The canonical map from α to `FreeRing α`. -/
def of (x : α) : FreeRing α :=
FreeAbelianGroup.of (FreeMonoid.of x)
theorem of_injective : Function.Injective (of : α → FreeRing α) :=
FreeAbelianGroup.of_injective.comp FreeMonoid.of_injective
| Mathlib/RingTheory/FreeRing.lean | 60 | 71 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Tape
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.PFun
import Mathlib.Computability.PostTuringMachine
/-!
# Turing machines
The files `PostTuringMachine.lean` and `TuringMachine.lean` define
a sequence of simple machine languages, starting with Turing machines and working
up to more complex languages based on Wang B-machines.
`PostTuringMachine.lean` covers the TM0 model and TM1 model;
`TuringMachine.lean` adds the TM2 model.
## Naming conventions
Each model of computation in this file shares a naming convention for the elements of a model of
computation. These are the parameters for the language:
* `Γ` is the alphabet on the tape.
* `Λ` is the set of labels, or internal machine states.
* `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and
later models achieve this by mixing it into `Λ`.
* `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks.
All of these variables denote "essentially finite" types, but for technical reasons it is
convenient to allow them to be infinite anyway. When using an infinite type, we will be interested
to prove that only finitely many values of the type are ever interacted with.
Given these parameters, there are a few common structures for the model that arise:
* `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is
finite, and for later models it is an infinite inductive type representing "possible program
texts".
* `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with
its environment.
* `Machine` is the set of all machines in the model. Usually this is approximately a function
`Λ → Stmt`, although different models have different ways of halting and other actions.
* `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step.
If `step c = none`, then `c` is a terminal state, and the result of the computation is read off
from `c`. Because of the type of `step`, these models are all deterministic by construction.
* `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model;
in most cases it is `List Γ`.
* `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from
`init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to
the final state to obtain the result. The type `Output` depends on the model.
* `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and
can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input
cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when
convenient, and prove that only finitely many of these states are actually accessible. This
formalizes "essentially finite" mentioned above.
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Relation
open Nat (iterate)
open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply'
iterate_zero_apply)
namespace Turing
/-!
## The TM2 model
The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite)
collection of stacks, each with elements of different types (the alphabet of stack `k : K` is
`Γ k`). The statements are:
* `push k (f : σ → Γ k) q` puts `f a` on the `k`-th stack, then does `q`.
* `pop k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, and removes this element from the stack, then does `q`.
* `peek k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, then does `q`.
* `load (f : σ → σ) q` reads nothing but applies `f` to the internal state, then does `q`.
* `branch (f : σ → Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`.
* `goto (f : σ → Λ)` jumps to label `f a`.
* `halt` halts on the next step.
The configuration is a tuple `(l, var, stk)` where `l : Option Λ` is the current label to run or
`none` for the halting state, `var : σ` is the (finite) internal state, and `stk : ∀ k, List (Γ k)`
is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not
`ListBlank`s, they have definite ends that can be detected by the `pop` command.)
Given a designated stack `k` and a value `L : List (Γ k)`, the initial configuration has all the
stacks empty except the designated "input" stack; in `eval` this designated stack also functions
as the output stack.
-/
namespace TM2
variable {K : Type*}
-- Index type of stacks
variable (Γ : K → Type*)
-- Type of stack elements
variable (Λ : Type*)
-- Type of function labels
variable (σ : Type*)
-- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive Stmt
| push : ∀ k, (σ → Γ k) → Stmt → Stmt
| peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt
| load : (σ → σ) → Stmt → Stmt
| branch : (σ → Bool) → Stmt → Stmt → Stmt
| goto : (σ → Λ) → Stmt
| halt : Stmt
open Stmt
instance Stmt.inhabited : Inhabited (Stmt Γ Λ σ) :=
⟨halt⟩
/-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) -/
structure Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Λ
/-- The internal state -/
var : σ
/-- The (finite) collection of internal stacks -/
stk : ∀ k, List (Γ k)
instance Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) :=
⟨⟨default, default, default⟩⟩
variable {Γ Λ σ}
section
variable [DecidableEq K]
/-- The step function for the TM2 model. -/
def stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S)
| goto f, v, S => ⟨some (f v), v, S⟩
| halt, v, S => ⟨none, v, S⟩
/-- The step function for the TM2 model. -/
def step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ)
| ⟨none, _, _⟩ => none
| ⟨some l, v, S⟩ => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2
/-- The (reflexive) reachability relation for the TM2 model. -/
def Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop :=
ReflTransGen fun a b ↦ b ∈ step M a
end
/-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/
def SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂
| goto l => ∀ v, l v ∈ S
| halt => True
section
open scoped Classical in
/-- The set of subtree statements in a statement. -/
noncomputable def stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ)
| Q@(push _ _ q) => insert Q (stmts₁ q)
| Q@(peek _ _ q) => insert Q (stmts₁ q)
| Q@(pop _ _ q) => insert Q (stmts₁ q)
| Q@(load _ q) => insert Q (stmts₁ q)
| Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂)
| Q@(goto _) => {Q}
| Q@halt => {Q}
theorem stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁]
theorem stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by
classical
intro h₁₂ q₀ h₀₁
induction q₂ with (
simp only [stmts₁] at h₁₂ ⊢
simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂)
| branch f q₁ q₂ IH₁ IH₂ =>
rcases h₁₂ with (rfl | h₁₂ | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂))
· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂))
| goto l => subst h₁₂; exact h₀₁
| halt => subst h₁₂; exact h₀₁
| load _ q IH | _ _ _ q IH =>
rcases h₁₂ with (rfl | h₁₂)
· unfold stmts₁ at h₀₁
exact h₀₁
· exact Finset.mem_insert_of_mem (IH h₁₂)
theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂)
(hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by
induction q₂ with
simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton]
at h hs
| branch f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in
/-- The set of statements accessible from initial set `S` of labels. -/
noncomputable def stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) :=
Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q))
theorem stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) :
some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩
end
variable [Inhabited Λ]
/-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states in `S`. -/
def Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) :=
default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q)
theorem stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ}
(ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls)
variable [DecidableEq K]
theorem step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) :
∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S
| ⟨some l₁, v, T⟩, c', h₁, h₂ => by
replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂)
simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c'
revert h₂; induction M l₁ generalizing v T with intro hs
| branch p q₁' q₂' IH₁ IH₂ =>
unfold stepAux; cases p v
· exact IH₂ _ _ hs.2
· exact IH₁ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited σ]
/-- The initial state of the TM2 model. The input is provided on a designated stack. -/
def init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ :=
⟨some default, default, update (fun _ ↦ []) k L⟩
/-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/
def eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) :=
(Turing.eval (step M) (init k L)).map fun c ↦ c.stk k
end TM2
/-!
## TM2 emulator in TM1
To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a
TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of
stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack
1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this:
```
bottom: ... | _ | T | _ | _ | _ | _ | ...
stack 1: ... | _ | b | a | _ | _ | _ | ...
stack 2: ... | _ | f | e | d | c | _ | ...
```
where a tape element is a vertical slice through the diagram. Here the alphabet is
`Γ' := Bool × ∀ k, Option (Γ k)`, where:
* `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the
tail of all stacks. It is never modified.
* `stk k : Option (Γ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is
the blank value). Note that the head of the stack is at the far end; this is so that push and pop
don't have to do any shifting.
In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions,
it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the
end of the appropriate stack, make its changes, and then return to the bottom. So the states are:
* `normal (l : Λ)`: waiting at `bottom` to execute function `l`
* `go k (s : StAct k) (q : Stmt₂)`: travelling to the right to get to the end of stack `k` in
order to perform stack action `s`, and later continue with executing `q`
* `ret (q : Stmt₂)`: travelling to the left after having performed a stack action, and executing
`q` once we arrive
Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the
length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)`
steps to run when emulated in TM1, where `m` is the length of the input.
-/
namespace TM2to1
-- A displaced lemma proved in unnecessary generality
theorem stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Γ : K → Type*)
variable {Λ σ : Type*}
/-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/
def Γ' :=
Bool × ∀ k, Option (Γ k)
variable {K Γ}
instance Γ'.inhabited : Inhabited (Γ' K Γ) :=
⟨⟨false, fun _ ↦ none⟩⟩
instance Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) :=
instFintypeProd _ _
/-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function
to express the program state in terms of a tape with only the stacks themselves. -/
def addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) :=
ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩)
theorem addBottom_map (L : ListBlank (∀ k, Option (Γ k))) :
(addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by
simp only [addBottom, ListBlank.map_cons]
convert ListBlank.cons_head_tail L
generalize ListBlank.tail L = L'
refine L'.induction_on fun l ↦ ?_; simp
theorem addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k))
(L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
(addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by
cases n <;>
simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons]
congr; symm; apply ListBlank.map_modifyNth; intro; rfl
theorem addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth n).2 = L.nth n := by
conv => rhs; rw [← addBottom_map L, ListBlank.nth_map]
theorem addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) :
((addBottom L).nth (n + 1)).1 = false := by
rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map]
theorem addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by
rw [addBottom, ListBlank.head_cons]
variable (K Γ σ) in
/-- A stack action is a command that interacts with the top of a stack. Our default position
is at the bottom of all the stacks, so we have to hold on to this action while going to the end
to modify the stack. -/
inductive StAct (k : K)
| push : (σ → Γ k) → StAct k
| peek : (σ → Option (Γ k) → σ) → StAct k
| pop : (σ → Option (Γ k) → σ) → StAct k
instance StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) :=
⟨StAct.peek fun s _ ↦ s⟩
section
open StAct
/-- The TM2 statement corresponding to a stack action. -/
def stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ
| push f => TM2.Stmt.push k f
| peek f => TM2.Stmt.peek k f
| pop f => TM2.Stmt.pop k f
/-- The effect of a stack action on the local variables, given the value of the stack. -/
def stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ
| push _ => v
| peek f => f v l.head?
| pop f => f v l.head?
/-- The effect of a stack action on the stack. -/
def stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k)
| push f => f v :: l
| peek _ => l
| pop _ => l.tail
/-- We have partitioned the TM2 statements into "stack actions", which require going to the end
of the stack, and all other actions, which do not. This is a modified recursor which lumps the
stack actions into one. -/
@[elab_as_elim]
def stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l}
(run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q))
(load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q))
(branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂))
(goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n
| TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.branch _ q₁ q₂ =>
branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂)
| TM2.Stmt.goto _ => goto _
| TM2.Stmt.halt => halt
theorem supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by
cases s <;> rfl
end
variable (K Γ Λ σ)
/-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the
next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and
return to the bottom, respectively. -/
inductive Λ'
| normal : Λ → Λ'
| go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ'
| ret : TM2.Stmt Γ Λ σ → Λ'
variable {K Γ Λ σ}
open Λ'
instance Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) :=
⟨normal default⟩
open TM1.Stmt
section
variable [DecidableEq K]
/-- The program corresponding to state transitions at the end of a stack. Here we start out just
after the top of the stack, and should end just after the new top of the stack. -/
def trStAct {k : K} (q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ) :
StAct K Γ σ k → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q
| StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q
| StAct.pop f =>
branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q)
(move Dir.left <|
(load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q)
/-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty
except for the input stack, and the stack bottom mark is set at the head. -/
def trInit (k : K) (L : List (Γ k)) : List (Γ' K Γ) :=
let L' : List (Γ' K Γ) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a))
(true, L'.headI.2) :: L'.tail
theorem step_run {k : K} (q : TM2.Stmt Γ Λ σ) (v : σ) (S : ∀ k, List (Γ k)) : ∀ s : StAct K Γ σ k,
TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s))
| StAct.push _ => rfl
| StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl
| StAct.pop _ => rfl
end
/-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents,
but stack actions are deferred by going to the corresponding `go` state, so that we can find the
appropriate stack top. -/
def trNormal : TM2.Stmt Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q
| TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q
| TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q
| TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q)
| TM2.Stmt.branch f q₁ q₂ => branch (fun _ ↦ f) (trNormal q₁) (trNormal q₂)
| TM2.Stmt.goto l => goto fun _ s ↦ normal (l s)
| TM2.Stmt.halt => halt
theorem trNormal_run {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) :
trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by
cases s <;> rfl
section
open scoped Classical in
/-- The set of machine states accessible from an initial TM2 statement. -/
noncomputable def trStmts₁ : TM2.Stmt Γ Λ σ → Finset (Λ' K Γ Λ σ)
| TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} ∪ trStmts₁ q
| TM2.Stmt.load _ q => trStmts₁ q
| TM2.Stmt.branch _ q₁ q₂ => trStmts₁ q₁ ∪ trStmts₁ q₂
| _ => ∅
theorem trStmts₁_run {k : K} {s : StAct K Γ σ k} {q : TM2.Stmt Γ Λ σ} :
open scoped Classical in
trStmts₁ (stRun s q) = {go k s q, ret q} ∪ trStmts₁ q := by
cases s <;> simp only [trStmts₁, stRun]
theorem tr_respects_aux₂ [DecidableEq K] {k : K} {q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ} {v : σ}
{S : ∀ k, List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : ∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) :
let v' := stVar v (S k) o
let Sk' := stWrite v (S k) o
let S' := update S k Sk'
∃ L' : ListBlank (∀ k, Option (Γ k)),
(∀ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧
TM1.stepAux (trStAct q o) v
((Tape.move Dir.right)^[(S k).length] (Tape.mk' ∅ (addBottom L))) =
TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' ∅ (addBottom L'))) := by
simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux]
| push f =>
have := Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k (some (f v)))
refine
⟨_, fun k' ↦ ?_, by
-- Porting note: `rw [...]` to `erw [...]; rfl`.
-- https://github.com/leanprover-community/mathlib4/issues/5164
rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this]
erw [addBottom_modifyNth fun a ↦ update a k (some (f v))]
rw [Nat.add_one, iterate_succ']
rfl⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h
<;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map]
· rw [List.getI_eq_getElem _, List.getElem_append_right] <;>
simp only [List.length_append, List.length_reverse, List.length_map, ← h,
Nat.sub_self, List.length_singleton, List.getElem_singleton,
le_refl, Nat.lt_succ_self]
rw [← proj_map_nth, hL, ListBlank.nth_mk]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
| peek f =>
rw [Function.update_eq_self]
use L, hL; rw [Tape.move_left_right]; congr
cases e : S k; · rfl
rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left,
Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e,
List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length]
rfl
| pop f =>
rcases e : S k with - | ⟨hd, tl⟩
· simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length,
Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil]
rw [← e, Function.update_eq_self]
exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩
· refine
⟨_, fun k' ↦ ?_, by
erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst,
cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head,
Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k none),
addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd,
stk_nth_val _ (hL k), e,
show (List.cons hd tl).reverse[tl.length]? = some hd by
rw [List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length],
List.head?, List.tail]⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
· subst k'
split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail]
· rw [List.getI_eq_default]
· rfl
rw [h, List.length_reverse, List.length_map]
rw [← proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons]
rcases lt_or_gt_of_ne h with h | h
· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL]
rw [Function.update_of_ne h']
end
variable [DecidableEq K]
variable (M : Λ → TM2.Stmt Γ Λ σ)
/-- The TM2 emulator machine states written as a TM1 program.
This handles the `go` and `ret` states, which shuttle to and from a stack top. -/
def tr : Λ' K Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ
| normal q => trNormal (M q)
| go k s q =>
branch (fun a _ ↦ (a.2 k).isNone) (trStAct (goto fun _ _ ↦ ret q) s)
(move Dir.right <| goto fun _ _ ↦ go k s q)
| ret q => branch (fun a _ ↦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ ↦ ret q)
/-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/
inductive TrCfg : TM2.Cfg Γ Λ σ → TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ → Prop
| mk {q : Option Λ} {v : σ} {S : ∀ k, List (Γ k)} (L : ListBlank (∀ k, Option (Γ k))) :
(∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) →
TrCfg ⟨q, v, S⟩ ⟨q.map normal, v, Tape.mk' ∅ (addBottom L)⟩
theorem tr_respects_aux₁ {k} (o q v) {S : List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))}
(hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n ≤ S.length) :
Reaches₀ (TM1.step (tr M)) ⟨some (go k o q), v, Tape.mk' ∅ (addBottom L)⟩
⟨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ := by
induction' n with n IH; · rfl
apply (IH (le_of_lt H)).tail
rw [iterate_succ_apply']
simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head,
addBottom_nth_snd, Option.mem_def]
rw [stk_nth_val _ hL, List.getElem?_eq_getElem]
· rfl
· rwa [List.length_reverse]
theorem tr_respects_aux₃ {q v} {L : ListBlank (∀ k, Option (Γ k))} (n) : Reaches₀ (TM1.step (tr M))
⟨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩
⟨some (ret q), v, Tape.mk' ∅ (addBottom L)⟩ := by
induction' n with n IH; · rfl
refine Reaches₀.head ?_ IH
simp only [Option.mem_def, TM1.step]
rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat,
addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left]
rfl
theorem tr_respects_aux {q v T k} {S : ∀ k, List (Γ k)}
(hT : ∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse)
(o : StAct K Γ σ k)
(IH : ∀ {v : σ} {S : ∀ k : K, List (Γ k)} {T : ListBlank (∀ k, Option (Γ k))},
(∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) →
∃ b, TrCfg (TM2.stepAux q v S) b ∧
Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' ∅ (addBottom T))) b) :
∃ b, TrCfg (TM2.stepAux (stRun o q) v S) b ∧ Reaches (TM1.step (tr M))
(TM1.stepAux (trNormal (stRun o q)) v (Tape.mk' ∅ (addBottom T))) b := by
simp only [trNormal_run, step_run]
have hgo := tr_respects_aux₁ M o q v (hT k) _ le_rfl
obtain ⟨T', hT', hrun⟩ := tr_respects_aux₂ (Λ := Λ) hT o
have := hgo.tail' rfl
rw [tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd,
stk_nth_val _ (hT k), List.getElem?_eq_none (le_of_eq List.length_reverse),
Option.isNone, cond, hrun, TM1.stepAux] at this
obtain ⟨c, gc, rc⟩ := IH hT'
refine ⟨c, gc, (this.to₀.trans (tr_respects_aux₃ M _) c (TransGen.head' rfl ?_)).to_reflTransGen⟩
rw [tr, TM1.stepAux, Tape.mk'_head, addBottom_head_fst]
exact rc
attribute [local simp] Respects TM2.step TM2.stepAux trNormal
theorem tr_respects : Respects (TM2.step M) (TM1.step (tr M)) TrCfg := by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
intro c₁ c₂ h
obtain @⟨- | l, v, S, L, hT⟩ := h; · constructor
rsuffices ⟨b, c, r⟩ : ∃ b, _ ∧ Reaches (TM1.step (tr M)) _ _
· exact ⟨b, c, TransGen.head' rfl r⟩
simp only [tr]
generalize M l = N
induction N using stmtStRec generalizing v S L hT with
| run k s q IH => exact tr_respects_aux M hT s @IH
| load a _ IH => exact IH _ hT
| branch p q₁ q₂ IH₁ IH₂ =>
unfold TM2.stepAux trNormal TM1.stepAux
beta_reduce
cases p v <;> [exact IH₂ _ hT; exact IH₁ _ hT]
| goto => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩
| halt => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩
section
variable [Inhabited Λ] [Inhabited σ]
theorem trCfg_init (k) (L : List (Γ k)) : TrCfg (TM2.init k L)
(TM1.init (trInit k L) : TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ) := by
rw [(_ : TM1.init _ = _)]
· refine ⟨ListBlank.mk (L.reverse.map fun a ↦ update default k (some a)), fun k' ↦ ?_⟩
refine ListBlank.ext fun i ↦ ?_
rw [ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map_map]
have : ((proj k').f ∘ fun a => update (β := fun k => Option (Γ k)) default k (some a))
= fun a => (proj k').f (update (β := fun k => Option (Γ k)) default k (some a)) := rfl
rw [this, List.getElem?_map, proj, PointedMap.mk_val]
simp only []
by_cases h : k' = k
· subst k'
simp only [Function.update_self]
rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, ← List.map_reverse, List.getElem?_map]
· simp only [Function.update_of_ne h]
rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map, List.reverse_nil]
cases L.reverse[i]? <;> rfl
· rw [trInit, TM1.init]
congr <;> cases L.reverse <;> try rfl
simp only [List.map_map, List.tail_cons, List.map]
rfl
theorem tr_eval_dom (k) (L : List (Γ k)) :
(TM1.eval (tr M) (trInit k L)).Dom ↔ (TM2.eval M k L).Dom :=
Turing.tr_eval_dom (tr_respects M) (trCfg_init k L)
theorem tr_eval (k) (L : List (Γ k)) {L₁ L₂} (H₁ : L₁ ∈ TM1.eval (tr M) (trInit k L))
(H₂ : L₂ ∈ TM2.eval M k L) :
∃ (S : ∀ k, List (Γ k)) (L' : ListBlank (∀ k, Option (Γ k))),
addBottom L' = L₁ ∧
(∀ k, L'.map (proj k) = ListBlank.mk ((S k).map some).reverse) ∧ S k = L₂ := by
obtain ⟨c₁, h₁, rfl⟩ := (Part.mem_map_iff _).1 H₁
obtain ⟨c₂, h₂, rfl⟩ := (Part.mem_map_iff _).1 H₂
obtain ⟨_, ⟨L', hT⟩, h₃⟩ := Turing.tr_eval (tr_respects M) (trCfg_init k L) h₂
cases Part.mem_unique h₁ h₃
exact ⟨_, L', by simp only [Tape.mk'_right₀], hT, rfl⟩
end
section
variable [Inhabited Λ]
open scoped Classical in
/-- The support of a set of TM2 states in the TM2 emulator. -/
noncomputable def trSupp (S : Finset Λ) : Finset (Λ' K Γ Λ σ) :=
S.biUnion fun l ↦ insert (normal l) (trStmts₁ (M l))
open scoped Classical in
theorem tr_supports {S} (ss : TM2.Supports M S) : TM1.Supports (tr M) (trSupp M S) :=
⟨Finset.mem_biUnion.2 ⟨_, ss.1, Finset.mem_insert.2 <| Or.inl rfl⟩, fun l' h ↦ by
suffices ∀ (q) (_ : TM2.SupportsStmt S q) (_ : ∀ x ∈ trStmts₁ q, x ∈ trSupp M S),
TM1.SupportsStmt (trSupp M S) (trNormal q) ∧
∀ l' ∈ trStmts₁ q, TM1.SupportsStmt (trSupp M S) (tr M l') by
rcases Finset.mem_biUnion.1 h with ⟨l, lS, h⟩
have :=
this _ (ss.2 l lS) fun x hx ↦ Finset.mem_biUnion.2 ⟨_, lS, Finset.mem_insert_of_mem hx⟩
rcases Finset.mem_insert.1 h with (rfl | h) <;> [exact this.1; exact this.2 _ h]
clear h l'
refine stmtStRec ?_ ?_ ?_ ?_ ?_
· intro _ s _ IH ss' sub -- stack op
rw [TM2to1.supports_run] at ss'
simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton]
at sub
have hgo := sub _ (Or.inl <| Or.inl rfl)
have hret := sub _ (Or.inl <| Or.inr rfl)
obtain ⟨IH₁, IH₂⟩ := IH ss' fun x hx ↦ sub x <| Or.inr hx
refine ⟨by simp only [trNormal_run, TM1.SupportsStmt]; intros; exact hgo, fun l h ↦ ?_⟩
rw [trStmts₁_run] at h
simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton]
at h
rcases h with (⟨rfl | rfl⟩ | h)
· cases s
· exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩
· exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩
· exact ⟨⟨fun _ _ ↦ hret, fun _ _ ↦ hret⟩, fun _ _ ↦ hgo⟩
· unfold TM1.SupportsStmt TM2to1.tr
exact ⟨IH₁, fun _ _ ↦ hret⟩
· exact IH₂ _ h
· intro _ _ IH ss' sub -- load
unfold TM2to1.trStmts₁ at sub ⊢
exact IH ss' sub
· intro _ _ _ IH₁ IH₂ ss' sub -- branch
unfold TM2to1.trStmts₁ at sub
obtain ⟨IH₁₁, IH₁₂⟩ := IH₁ ss'.1 fun x hx ↦ sub x <| Finset.mem_union_left _ hx
obtain ⟨IH₂₁, IH₂₂⟩ := IH₂ ss'.2 fun x hx ↦ sub x <| Finset.mem_union_right _ hx
refine ⟨⟨IH₁₁, IH₂₁⟩, fun l h ↦ ?_⟩
rw [trStmts₁] at h
rcases Finset.mem_union.1 h with (h | h) <;> [exact IH₁₂ _ h; exact IH₂₂ _ h]
· intro _ ss' _ -- goto
simp only [trStmts₁, Finset.not_mem_empty]; refine ⟨?_, fun _ ↦ False.elim⟩
exact fun _ v ↦ Finset.mem_biUnion.2 ⟨_, ss' v, Finset.mem_insert_self _ _⟩
· intro _ _ -- halt
simp only [trStmts₁, Finset.not_mem_empty]
exact ⟨trivial, fun _ ↦ False.elim⟩⟩
end
end TM2to1
end Turing
| Mathlib/Computability/TuringMachine.lean | 2,250 | 2,254 | |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Topology.Algebra.GroupWithZero
import Mathlib.Topology.Order.OrderClosed
import Mathlib.Topology.Separation.Regular
/-!
# The topology on linearly ordered commutative groups with zero
Let `Γ₀` be a linearly ordered commutative group to which we have adjoined a zero element. Then
`Γ₀` may naturally be endowed with a topology that turns `Γ₀` into a topological monoid.
Neighborhoods of zero are sets containing `{ γ | γ < γ₀ }` for some invertible element `γ₀` and
every invertible element is open. In particular the topology is the following: "a subset `U ⊆ Γ₀`
is open if `0 ∉ U` or if there is an invertible `γ₀ ∈ Γ₀` such that `{ γ | γ < γ₀ } ⊆ U`", see
`WithZeroTopology.isOpen_iff`.
We prove this topology is ordered and T₅ (in addition to be compatible with the monoid
structure).
All this is useful to extend a valuation to a completion. This is an abstract version of how the
absolute value (resp. `p`-adic absolute value) on `ℚ` is extended to `ℝ` (resp. `ℚₚ`).
## Implementation notes
This topology is defined as a scoped instance since it may not be the desired topology on
a linearly ordered commutative group with zero. You can locally activate this topology using
`open WithZeroTopology`.
-/
open Topology Filter TopologicalSpace Filter Set Function
namespace WithZeroTopology
variable {α Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀] {γ γ₁ γ₂ : Γ₀} {l : Filter α}
{f : α → Γ₀}
/-- The topology on a linearly ordered commutative group with a zero element adjoined.
A subset U is open if 0 ∉ U or if there is an invertible element γ₀ such that {γ | γ < γ₀} ⊆ U. -/
scoped instance (priority := 100) topologicalSpace : TopologicalSpace Γ₀ :=
nhdsAdjoint 0 <| ⨅ γ ≠ 0, 𝓟 (Iio γ)
theorem nhds_eq_update : (𝓝 : Γ₀ → Filter Γ₀) = update pure 0 (⨅ γ ≠ 0, 𝓟 (Iio γ)) := by
rw [nhds_nhdsAdjoint, sup_of_le_right]
exact le_iInf₂ fun γ hγ ↦ le_principal_iff.2 <| zero_lt_iff.2 hγ
/-!
### Neighbourhoods of zero
-/
theorem nhds_zero : 𝓝 (0 : Γ₀) = ⨅ γ ≠ 0, 𝓟 (Iio γ) := by
rw [nhds_eq_update, update_self]
/-- In a linearly ordered group with zero element adjoined, `U` is a neighbourhood of `0` if and
only if there exists a nonzero element `γ₀` such that `Iio γ₀ ⊆ U`. -/
theorem hasBasis_nhds_zero : (𝓝 (0 : Γ₀)).HasBasis (fun γ : Γ₀ => γ ≠ 0) Iio := by
rw [nhds_zero]
refine hasBasis_biInf_principal ?_ ⟨1, one_ne_zero⟩
exact directedOn_iff_directed.2 (Monotone.directed_ge fun a b hab => Iio_subset_Iio hab)
theorem Iio_mem_nhds_zero (hγ : γ ≠ 0) : Iio γ ∈ 𝓝 (0 : Γ₀) :=
hasBasis_nhds_zero.mem_of_mem hγ
/-- If `γ` is an invertible element of a linearly ordered group with zero element adjoined, then
`Iio (γ : Γ₀)` is a neighbourhood of `0`. -/
theorem nhds_zero_of_units (γ : Γ₀ˣ) : Iio ↑γ ∈ 𝓝 (0 : Γ₀) :=
Iio_mem_nhds_zero γ.ne_zero
theorem tendsto_zero : Tendsto f l (𝓝 (0 : Γ₀)) ↔ ∀ (γ₀) (_ : γ₀ ≠ 0), ∀ᶠ x in l, f x < γ₀ := by
simp [nhds_zero]
/-!
### Neighbourhoods of non-zero elements
-/
/-- The neighbourhood filter of a nonzero element consists of all sets containing that
element. -/
@[simp]
theorem nhds_of_ne_zero {γ : Γ₀} (h₀ : γ ≠ 0) : 𝓝 γ = pure γ :=
nhds_nhdsAdjoint_of_ne _ h₀
/-- The neighbourhood filter of an invertible element consists of all sets containing that
element. -/
theorem nhds_coe_units (γ : Γ₀ˣ) : 𝓝 (γ : Γ₀) = pure (γ : Γ₀) :=
nhds_of_ne_zero γ.ne_zero
/-- If `γ` is an invertible element of a linearly ordered group with zero element adjoined, then
`{γ}` is a neighbourhood of `γ`. -/
theorem singleton_mem_nhds_of_units (γ : Γ₀ˣ) : ({↑γ} : Set Γ₀) ∈ 𝓝 (γ : Γ₀) := by simp
/-- If `γ` is a nonzero element of a linearly ordered group with zero element adjoined, then `{γ}`
is a neighbourhood of `γ`. -/
theorem singleton_mem_nhds_of_ne_zero (h : γ ≠ 0) : ({γ} : Set Γ₀) ∈ 𝓝 (γ : Γ₀) := by simp [h]
theorem hasBasis_nhds_of_ne_zero {x : Γ₀} (h : x ≠ 0) :
HasBasis (𝓝 x) (fun _ : Unit => True) fun _ => {x} := by
rw [nhds_of_ne_zero h]
exact hasBasis_pure _
theorem hasBasis_nhds_units (γ : Γ₀ˣ) :
HasBasis (𝓝 (γ : Γ₀)) (fun _ : Unit => True) fun _ => {↑γ} :=
hasBasis_nhds_of_ne_zero γ.ne_zero
theorem tendsto_of_ne_zero {γ : Γ₀} (h : γ ≠ 0) : Tendsto f l (𝓝 γ) ↔ ∀ᶠ x in l, f x = γ := by
rw [nhds_of_ne_zero h, tendsto_pure]
theorem tendsto_units {γ₀ : Γ₀ˣ} : Tendsto f l (𝓝 (γ₀ : Γ₀)) ↔ ∀ᶠ x in l, f x = γ₀ :=
tendsto_of_ne_zero γ₀.ne_zero
theorem Iio_mem_nhds (h : γ₁ < γ₂) : Iio γ₂ ∈ 𝓝 γ₁ := by
rcases eq_or_ne γ₁ 0 with (rfl | h₀) <;> simp [*, h.ne', Iio_mem_nhds_zero]
/-!
### Open/closed sets
-/
| theorem isOpen_iff {s : Set Γ₀} : IsOpen s ↔ (0 : Γ₀) ∉ s ∨ ∃ γ, γ ≠ 0 ∧ Iio γ ⊆ s := by
rw [isOpen_iff_mem_nhds, ← and_forall_ne (0 : Γ₀)]
| Mathlib/Topology/Algebra/WithZeroTopology.lean | 120 | 121 |
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Topology.Algebra.Module.Basic
/-!
# Group and ring filter bases
A `GroupFilterBasis` is a `FilterBasis` on a group with some properties relating
the basis to the group structure. The main theorem is that a `GroupFilterBasis`
on a group gives a topology on the group which makes it into a topological group
with neighborhoods of the neutral element generated by the given basis.
## Main definitions and results
Given a group `G` and a ring `R`:
* `GroupFilterBasis G`: the type of filter bases that will become neighborhood of `1`
for a topology on `G` compatible with the group structure
* `GroupFilterBasis.topology`: the associated topology
* `GroupFilterBasis.isTopologicalGroup`: the compatibility between the above topology
and the group structure
* `RingFilterBasis R`: the type of filter bases that will become neighborhood of `0`
for a topology on `R` compatible with the ring structure
* `RingFilterBasis.topology`: the associated topology
* `RingFilterBasis.isTopologicalRing`: the compatibility between the above topology
and the ring structure
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
-/
open Filter Set TopologicalSpace Function
open Topology Filter Pointwise
universe u
/-- A `GroupFilterBasis` on a group is a `FilterBasis` satisfying some additional axioms.
Example : if `G` is a topological group then the neighbourhoods of the identity are a
`GroupFilterBasis`. Conversely given a `GroupFilterBasis` one can define a topology
compatible with the group structure on `G`. -/
class GroupFilterBasis (G : Type u) [Group G] extends FilterBasis G where
one' : ∀ {U}, U ∈ sets → (1 : G) ∈ U
mul' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V * V ⊆ U
inv' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U
conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U
/-- An `AddGroupFilterBasis` on an additive group is a `FilterBasis` satisfying some additional
axioms. Example : if `G` is a topological group then the neighbourhoods of the identity are an
`AddGroupFilterBasis`. Conversely given an `AddGroupFilterBasis` one can define a topology
compatible with the group structure on `G`. -/
class AddGroupFilterBasis (A : Type u) [AddGroup A] extends FilterBasis A where
zero' : ∀ {U}, U ∈ sets → (0 : A) ∈ U
add' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V + V ⊆ U
neg' : ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ -x) ⁻¹' U
conj' : ∀ x₀, ∀ {U}, U ∈ sets → ∃ V ∈ sets, V ⊆ (fun x ↦ x₀ + x + -x₀) ⁻¹' U
attribute [to_additive existing] GroupFilterBasis GroupFilterBasis.conj'
GroupFilterBasis.toFilterBasis
/-- `GroupFilterBasis` constructor in the commutative group case. -/
@[to_additive "`AddGroupFilterBasis` constructor in the additive commutative group case."]
def groupFilterBasisOfComm {G : Type*} [CommGroup G] (sets : Set (Set G))
(nonempty : sets.Nonempty) (inter_sets : ∀ x y, x ∈ sets → y ∈ sets → ∃ z ∈ sets, z ⊆ x ∩ y)
(one : ∀ U ∈ sets, (1 : G) ∈ U) (mul : ∀ U ∈ sets, ∃ V ∈ sets, V * V ⊆ U)
(inv : ∀ U ∈ sets, ∃ V ∈ sets, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U) : GroupFilterBasis G :=
{ sets := sets
nonempty := nonempty
inter_sets := inter_sets _ _
one' := one _
mul' := mul _
inv' := inv _
conj' := fun x U U_in ↦ ⟨U, U_in, by simp only [mul_inv_cancel_comm, preimage_id']; rfl⟩ }
namespace GroupFilterBasis
variable {G : Type u} [Group G] {B : GroupFilterBasis G}
@[to_additive]
instance : Membership (Set G) (GroupFilterBasis G) :=
⟨fun f s ↦ s ∈ f.sets⟩
@[to_additive]
theorem one {U : Set G} : U ∈ B → (1 : G) ∈ U :=
GroupFilterBasis.one'
@[to_additive]
theorem mul {U : Set G} : U ∈ B → ∃ V ∈ B, V * V ⊆ U :=
GroupFilterBasis.mul'
@[to_additive]
theorem inv {U : Set G} : U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x⁻¹) ⁻¹' U :=
GroupFilterBasis.inv'
@[to_additive]
theorem conj : ∀ x₀, ∀ {U}, U ∈ B → ∃ V ∈ B, V ⊆ (fun x ↦ x₀ * x * x₀⁻¹) ⁻¹' U :=
GroupFilterBasis.conj'
/-- The trivial group filter basis consists of `{1}` only. The associated topology
is discrete. -/
@[to_additive "The trivial additive group filter basis consists of `{0}` only. The associated
topology is discrete."]
instance : Inhabited (GroupFilterBasis G) where
default := {
sets := {{1}}
nonempty := singleton_nonempty _
inter_sets := by simp
one' := by simp
mul' := by simp
inv' := by simp
conj' := by simp }
@[to_additive]
theorem subset_mul_self (B : GroupFilterBasis G) {U : Set G} (h : U ∈ B) : U ⊆ U * U :=
fun x x_in ↦ ⟨1, one h, x, x_in, one_mul x⟩
/-- The neighborhood function of a `GroupFilterBasis`. -/
@[to_additive "The neighborhood function of an `AddGroupFilterBasis`."]
def N (B : GroupFilterBasis G) : G → Filter G :=
fun x ↦ map (fun y ↦ x * y) B.toFilterBasis.filter
@[to_additive (attr := simp)]
theorem N_one (B : GroupFilterBasis G) : B.N 1 = B.toFilterBasis.filter := by
simp only [N, one_mul, map_id']
@[to_additive]
protected theorem hasBasis (B : GroupFilterBasis G) (x : G) :
HasBasis (B.N x) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x * y) '' V :=
HasBasis.map (fun y ↦ x * y) toFilterBasis.hasBasis
/-- The topological space structure coming from a group filter basis. -/
@[to_additive "The topological space structure coming from an additive group filter basis."]
def topology (B : GroupFilterBasis G) : TopologicalSpace G :=
TopologicalSpace.mkOfNhds B.N
@[to_additive]
theorem nhds_eq (B : GroupFilterBasis G) {x₀ : G} : @nhds G B.topology x₀ = B.N x₀ := by
apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun x ↦ (FilterBasis.hasBasis _).map _)
· intro a U U_in
exact ⟨1, B.one U_in, mul_one a⟩
· intro a U U_in
rcases GroupFilterBasis.mul U_in with ⟨V, V_in, hVU⟩
filter_upwards [image_mem_map (B.mem_filter_of_mem V_in)]
rintro _ ⟨x, hx, rfl⟩
calc
(a * x) • V ∈ (a * x) • B.filter := smul_set_mem_smul_filter <| B.mem_filter_of_mem V_in
_ = a • x • V := smul_smul .. |>.symm
_ ⊆ a • (V * V) := smul_set_mono <| smul_set_subset_smul hx
_ ⊆ a • U := smul_set_mono hVU
@[to_additive]
theorem nhds_one_eq (B : GroupFilterBasis G) :
@nhds G B.topology (1 : G) = B.toFilterBasis.filter := by
rw [B.nhds_eq]
simp only [N, one_mul]
exact map_id
@[to_additive]
theorem nhds_hasBasis (B : GroupFilterBasis G) (x₀ : G) :
HasBasis (@nhds G B.topology x₀) (fun V : Set G ↦ V ∈ B) fun V ↦ (fun y ↦ x₀ * y) '' V := by
rw [B.nhds_eq]
apply B.hasBasis
@[to_additive]
theorem nhds_one_hasBasis (B : GroupFilterBasis G) :
| HasBasis (@nhds G B.topology 1) (fun V : Set G ↦ V ∈ B) id := by
rw [B.nhds_one_eq]
exact B.toFilterBasis.hasBasis
@[to_additive]
theorem mem_nhds_one (B : GroupFilterBasis G) {U : Set G} (hU : U ∈ B) :
U ∈ @nhds G B.topology 1 := by
rw [B.nhds_one_hasBasis.mem_iff]
exact ⟨U, hU, rfl.subset⟩
-- See note [lower instance priority]
/-- If a group is endowed with a topological structure coming from a group filter basis then it's a
topological group. -/
| Mathlib/Topology/Algebra/FilterBasis.lean | 171 | 183 |
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Probability.Martingale.BorelCantelli
import Mathlib.Probability.ConditionalExpectation
import Mathlib.Probability.Independence.Basic
/-!
# The second Borel-Cantelli lemma
This file contains the *second Borel-Cantelli lemma* which states that, given a sequence of
independent sets `(sₙ)` in a probability space, if `∑ n, μ sₙ = ∞`, then the limsup of `sₙ` has
measure 1. We employ a proof using Lévy's generalized Borel-Cantelli by choosing an appropriate
filtration.
## Main result
- `ProbabilityTheory.measure_limsup_eq_one`: the second Borel-Cantelli lemma.
**Note**: for the *first Borel-Cantelli lemma*, which holds in general measure spaces (not only
in probability spaces), see `MeasureTheory.measure_limsup_atTop_eq_zero`.
-/
open scoped ENNReal Topology
open MeasureTheory
namespace ProbabilityTheory
variable {Ω : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω}
section BorelCantelli
variable {ι β : Type*} [LinearOrder ι] [mβ : MeasurableSpace β] [NormedAddCommGroup β]
[BorelSpace β] {f : ι → Ω → β} {i j : ι} {s : ι → Set Ω}
theorem iIndepFun.indep_comap_natural_of_lt (hf : ∀ i, StronglyMeasurable (f i))
(hfi : iIndepFun f μ) (hij : i < j) :
Indep (MeasurableSpace.comap (f j) mβ) (Filtration.natural f hf i) μ := by
suffices Indep (⨆ k ∈ ({j} : Set ι), MeasurableSpace.comap (f k) mβ)
| (⨆ k ∈ {k | k ≤ i}, MeasurableSpace.comap (f k) mβ) μ by rwa [iSup_singleton] at this
exact indep_iSup_of_disjoint (fun k => (hf k).measurable.comap_le) hfi (by simpa)
theorem iIndepFun.condExp_natural_ae_eq_of_lt [SecondCountableTopology β] [CompleteSpace β]
[NormedSpace ℝ β] (hf : ∀ i, StronglyMeasurable (f i)) (hfi : iIndepFun f μ)
(hij : i < j) : μ[f j|Filtration.natural f hf i] =ᵐ[μ] fun _ => μ[f j] := by
| Mathlib/Probability/BorelCantelli.lean | 43 | 48 |
/-
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, Floris van Doorn
-/
import Mathlib.Order.Hom.CompleteLattice
import Mathlib.Topology.Compactness.Bases
import Mathlib.Topology.ContinuousMap.Basic
import Mathlib.Order.CompactlyGenerated.Basic
import Mathlib.Order.Copy
/-!
# Open sets
## Summary
We define the subtype of open sets in a topological space.
## Main Definitions
### Bundled open sets
- `TopologicalSpace.Opens α` is the type of open subsets of a topological space `α`.
- `TopologicalSpace.Opens.IsBasis` is a predicate saying that a set of `Opens`s form a topological
basis.
- `TopologicalSpace.Opens.comap`: preimage of an open set under a continuous map as a `FrameHom`.
- `Homeomorph.opensCongr`: order-preserving equivalence between open sets in the domain and the
codomain of a homeomorphism.
### Bundled open neighborhoods
- `TopologicalSpace.OpenNhdsOf x` is the type of open subsets of a topological space `α` containing
`x : α`.
- `TopologicalSpace.OpenNhdsOf.comap f x U` is the preimage of open neighborhood `U` of `f x` under
`f : C(α, β)`.
## Main results
We define order structures on both `Opens α` (`CompleteLattice`, `Frame`) and `OpenNhdsOf x`
(`OrderTop`, `DistribLattice`).
## TODO
- Rename `TopologicalSpace.Opens` to `Open`?
- Port the `auto_cases` tactic version (as a plugin if the ported `auto_cases` will allow plugins).
-/
open Filter Function Order Set
open Topology
variable {ι α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ]
namespace TopologicalSpace
variable (α) in
/-- The type of open subsets of a topological space. -/
structure Opens where
/-- The underlying set of a bundled `TopologicalSpace.Opens` object. -/
carrier : Set α
/-- The `TopologicalSpace.Opens.carrier _` is an open set. -/
is_open' : IsOpen carrier
namespace Opens
instance : SetLike (Opens α) α where
coe := Opens.carrier
coe_injective' := fun ⟨_, _⟩ ⟨_, _⟩ _ => by congr
instance : CanLift (Set α) (Opens α) (↑) IsOpen :=
⟨fun s h => ⟨⟨s, h⟩, rfl⟩⟩
instance instSecondCountableOpens [SecondCountableTopology α] (U : Opens α) :
SecondCountableTopology U := inferInstanceAs (SecondCountableTopology U.1)
theorem «forall» {p : Opens α → Prop} : (∀ U, p U) ↔ ∀ (U : Set α) (hU : IsOpen U), p ⟨U, hU⟩ :=
⟨fun h _ _ => h _, fun h _ => h _ _⟩
@[simp] theorem carrier_eq_coe (U : Opens α) : U.1 = ↑U := rfl
/-- the coercion `Opens α → Set α` applied to a pair is the same as taking the first component -/
@[simp]
theorem coe_mk {U : Set α} {hU : IsOpen U} : ↑(⟨U, hU⟩ : Opens α) = U :=
rfl
@[simp]
theorem mem_mk {x : α} {U : Set α} {h : IsOpen U} : x ∈ mk U h ↔ x ∈ U := Iff.rfl
protected theorem nonempty_coeSort {U : Opens α} : Nonempty U ↔ (U : Set α).Nonempty :=
Set.nonempty_coe_sort
-- TODO: should this theorem be proved for a `SetLike`?
protected theorem nonempty_coe {U : Opens α} : (U : Set α).Nonempty ↔ ∃ x, x ∈ U :=
Iff.rfl
@[ext] -- TODO: replace with `∀ x, x ∈ U ↔ x ∈ V`?
theorem ext {U V : Opens α} (h : (U : Set α) = V) : U = V :=
SetLike.coe_injective h
theorem coe_inj {U V : Opens α} : (U : Set α) = V ↔ U = V :=
SetLike.ext'_iff.symm
/-- A version of `Set.inclusion` not requiring definitional abuse -/
abbrev inclusion {U V : Opens α} (h : U ≤ V) : U → V := Set.inclusion h
protected theorem isOpen (U : Opens α) : IsOpen (U : Set α) :=
U.is_open'
@[simp] theorem mk_coe (U : Opens α) : mk (↑U) U.isOpen = U := rfl
/-- See Note [custom simps projection]. -/
def Simps.coe (U : Opens α) : Set α := U
initialize_simps_projections Opens (carrier → coe, as_prefix coe)
/-- The interior of a set, as an element of `Opens`. -/
@[simps]
protected def interior (s : Set α) : Opens α :=
⟨interior s, isOpen_interior⟩
@[simp]
theorem mem_interior {s : Set α} {x : α} : x ∈ Opens.interior s ↔ x ∈ _root_.interior s := .rfl
theorem gc : GaloisConnection ((↑) : Opens α → Set α) Opens.interior := fun U _ =>
⟨fun h => interior_maximal h U.isOpen, fun h => le_trans h interior_subset⟩
/-- The galois coinsertion between sets and opens. -/
def gi : GaloisCoinsertion (↑) (@Opens.interior α _) where
choice s hs := ⟨s, interior_eq_iff_isOpen.mp <| le_antisymm interior_subset hs⟩
gc := gc
u_l_le _ := interior_subset
choice_eq _s hs := le_antisymm hs interior_subset
instance : CompleteLattice (Opens α) :=
CompleteLattice.copy (GaloisCoinsertion.liftCompleteLattice gi)
-- le
(fun U V => (U : Set α) ⊆ V) rfl
-- top
⟨univ, isOpen_univ⟩ (ext interior_univ.symm)
-- bot
⟨∅, isOpen_empty⟩ rfl
-- sup
(fun U V => ⟨↑U ∪ ↑V, U.2.union V.2⟩) rfl
-- inf
(fun U V => ⟨↑U ∩ ↑V, U.2.inter V.2⟩)
(funext₂ fun U V => ext (U.2.inter V.2).interior_eq.symm)
-- sSup
(fun S => ⟨⋃ s ∈ S, ↑s, isOpen_biUnion fun s _ => s.2⟩)
(funext fun _ => ext sSup_image.symm)
-- sInf
_ rfl
@[simp]
theorem mk_inf_mk {U V : Set α} {hU : IsOpen U} {hV : IsOpen V} :
(⟨U, hU⟩ ⊓ ⟨V, hV⟩ : Opens α) = ⟨U ⊓ V, IsOpen.inter hU hV⟩ :=
rfl
@[simp, norm_cast]
theorem coe_inf (s t : Opens α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t :=
rfl
@[simp]
lemma mem_inf {s t : Opens α} {x : α} : x ∈ s ⊓ t ↔ x ∈ s ∧ x ∈ t := Iff.rfl
@[simp, norm_cast]
theorem coe_sup (s t : Opens α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t :=
rfl
@[simp, norm_cast]
theorem coe_bot : ((⊥ : Opens α) : Set α) = ∅ :=
rfl
@[simp]
lemma mem_bot {x : α} : x ∈ (⊥ : Opens α) ↔ False := Iff.rfl
@[simp] theorem mk_empty : (⟨∅, isOpen_empty⟩ : Opens α) = ⊥ := rfl
@[simp, norm_cast]
theorem coe_eq_empty {U : Opens α} : (U : Set α) = ∅ ↔ U = ⊥ :=
SetLike.coe_injective.eq_iff' rfl
@[simp]
lemma mem_top (x : α) : x ∈ (⊤ : Opens α) := trivial
@[simp, norm_cast]
theorem coe_top : ((⊤ : Opens α) : Set α) = Set.univ :=
rfl
@[simp] theorem mk_univ : (⟨univ, isOpen_univ⟩ : Opens α) = ⊤ := rfl
@[simp, norm_cast]
theorem coe_eq_univ {U : Opens α} : (U : Set α) = univ ↔ U = ⊤ :=
SetLike.coe_injective.eq_iff' rfl
@[simp, norm_cast]
theorem coe_sSup {S : Set (Opens α)} : (↑(sSup S) : Set α) = ⋃ i ∈ S, ↑i :=
rfl
@[simp, norm_cast]
theorem coe_finset_sup (f : ι → Opens α) (s : Finset ι) : (↑(s.sup f) : Set α) = s.sup ((↑) ∘ f) :=
map_finset_sup (⟨⟨(↑), coe_sup⟩, coe_bot⟩ : SupBotHom (Opens α) (Set α)) _ _
@[simp, norm_cast]
theorem coe_finset_inf (f : ι → Opens α) (s : Finset ι) : (↑(s.inf f) : Set α) = s.inf ((↑) ∘ f) :=
map_finset_inf (⟨⟨(↑), coe_inf⟩, coe_top⟩ : InfTopHom (Opens α) (Set α)) _ _
instance : Inhabited (Opens α) := ⟨⊥⟩
instance [IsEmpty α] : Unique (Opens α) where
uniq _ := ext <| Subsingleton.elim _ _
instance [Nonempty α] : Nontrivial (Opens α) where
exists_pair_ne := ⟨⊥, ⊤, mt coe_inj.2 empty_ne_univ⟩
@[simp, norm_cast]
theorem coe_iSup {ι} (s : ι → Opens α) : ((⨆ i, s i : Opens α) : Set α) = ⋃ i, s i := by
simp [iSup]
theorem iSup_def {ι} (s : ι → Opens α) : ⨆ i, s i = ⟨⋃ i, s i, isOpen_iUnion fun i => (s i).2⟩ :=
ext <| coe_iSup s
@[simp]
theorem iSup_mk {ι} (s : ι → Set α) (h : ∀ i, IsOpen (s i)) :
(⨆ i, ⟨s i, h i⟩ : Opens α) = ⟨⋃ i, s i, isOpen_iUnion h⟩ :=
iSup_def _
@[simp]
theorem mem_iSup {ι} {x : α} {s : ι → Opens α} : x ∈ iSup s ↔ ∃ i, x ∈ s i := by
rw [← SetLike.mem_coe]
simp
@[simp]
theorem mem_sSup {Us : Set (Opens α)} {x : α} : x ∈ sSup Us ↔ ∃ u ∈ Us, x ∈ u := by
simp_rw [sSup_eq_iSup, mem_iSup, exists_prop]
/-- Open sets in a topological space form a frame. -/
def frameMinimalAxioms : Frame.MinimalAxioms (Opens α) where
inf_sSup_le_iSup_inf a s :=
(ext <| by simp only [coe_inf, coe_iSup, coe_sSup, Set.inter_iUnion₂]).le
instance instFrame : Frame (Opens α) := .ofMinimalAxioms frameMinimalAxioms
theorem isOpenEmbedding' (U : Opens α) : IsOpenEmbedding (Subtype.val : U → α) :=
U.isOpen.isOpenEmbedding_subtypeVal
theorem isOpenEmbedding_of_le {U V : Opens α} (i : U ≤ V) :
IsOpenEmbedding (Set.inclusion <| SetLike.coe_subset_coe.2 i) where
toIsEmbedding := .inclusion i
isOpen_range := by
| rw [Set.range_inclusion i]
exact U.isOpen.preimage continuous_subtype_val
| Mathlib/Topology/Sets/Opens.lean | 251 | 252 |
/-
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`. -/
| Mathlib/Data/Seq/Seq.lean | 237 | 241 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Ordmap.Invariants
/-!
# Verification of `Ordnode`
This file uses the invariants defined in `Mathlib.Data.Ordmap.Invariants` to construct `Ordset α`,
a wrapper around `Ordnode α` which includes the correctness invariant of the type. It exposes
parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the
correctness proofs.
The advantage is that it is possible to, for example, prove that the result of `find` on `insert`
will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not
satisfy the type invariants.
## Main definitions
* `Ordnode.Valid`: The validity predicate for an `Ordnode` subtree.
* `Ordset α`: A well formed set of values of type `α`.
## Implementation notes
Because the `Ordnode` file was ported from Haskell, the correctness invariants of some
of the functions have not been spelled out, and some theorems like
`Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes,
which may need to be revised if it turns out some operations violate these assumptions,
because there is a decent amount of slop in the actual data structure invariants, so the
theorem will go through with multiple choices of assumption.
-/
variable {α : Type*}
namespace Ordnode
section Valid
variable [Preorder α]
/-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are
correct, the tree is balanced, and the elements of the tree are organized according to the
ordering. This version of `Valid` also puts all elements in the tree in the interval `(lo, hi)`. -/
structure Valid' (lo : WithBot α) (t : Ordnode α) (hi : WithTop α) : Prop where
ord : t.Bounded lo hi
sz : t.Sized
bal : t.Balanced
/-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are
correct, the tree is balanced, and the elements of the tree are organized according to the
ordering. -/
def Valid (t : Ordnode α) : Prop :=
Valid' ⊥ t ⊤
theorem Valid'.mono_left {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' y t o) :
Valid' x t o :=
⟨h.1.mono_left xy, h.2, h.3⟩
theorem Valid'.mono_right {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' o t x) :
Valid' o t y :=
⟨h.1.mono_right xy, h.2, h.3⟩
theorem Valid'.trans_left {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (h : Bounded t₁ o₁ x)
(H : Valid' x t₂ o₂) : Valid' o₁ t₂ o₂ :=
⟨h.trans_left H.1, H.2, H.3⟩
theorem Valid'.trans_right {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t₁ x)
(h : Bounded t₂ x o₂) : Valid' o₁ t₁ o₂ :=
⟨H.1.trans_right h, H.2, H.3⟩
theorem Valid'.of_lt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil o₁ x)
(h₂ : All (· < x) t) : Valid' o₁ t x :=
⟨H.1.of_lt h₁ h₂, H.2, H.3⟩
theorem Valid'.of_gt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil x o₂)
(h₂ : All (· > x) t) : Valid' x t o₂ :=
⟨H.1.of_gt h₁ h₂, H.2, H.3⟩
theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t :=
⟨h.1.weak, h.2, h.3⟩
theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ :=
⟨h, ⟨⟩, ⟨⟩⟩
theorem valid_nil : Valid (@nil α) :=
valid'_nil ⟨⟩
theorem Valid'.node {s l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : BalancedSz (size l) (size r)) (hs : s = size l + size r + 1) :
Valid' o₁ (@node α s l x r) o₂ :=
⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩
theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁
| .nil, _, _, h => valid'_nil h.1.dual
| .node _ l _ r, _, _, ⟨⟨ol, Or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ =>
let ⟨ol', sl', bl'⟩ := Valid'.dual ⟨ol, sl, bl⟩
let ⟨or', sr', br'⟩ := Valid'.dual ⟨Or, sr, br⟩
⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩,
⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩
theorem Valid'.dual_iff {t : Ordnode α} {o₁ o₂} : Valid' o₁ t o₂ ↔ @Valid' αᵒᵈ _ o₂ (.dual t) o₁ :=
⟨Valid'.dual, fun h => by
have := Valid'.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩
theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual
theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) :=
Valid'.dual_iff
theorem Valid'.left {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' o₁ l x :=
⟨H.1.1, H.2.2.1, H.3.2.1⟩
theorem Valid'.right {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' x r o₂ :=
⟨H.1.2, H.2.2.2, H.3.2.2⟩
nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l :=
H.left.valid
nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r :=
H.right.valid
theorem Valid.size_eq {s l x r} (H : Valid (@node α s l x r)) :
size (@node α s l x r) = size l + size r + 1 :=
H.2.1
theorem Valid'.node' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : BalancedSz (size l) (size r)) : Valid' o₁ (@node' α l x r) o₂ :=
hl.node hr H rfl
theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : Bounded nil o₁ x) (h₂ : Bounded nil x o₂) :
Valid' o₁ (singleton x : Ordnode α) o₂ :=
(valid'_nil h₁).node (valid'_nil h₂) (Or.inl zero_le_one) rfl
theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) :=
valid'_singleton ⟨⟩ ⟨⟩
theorem Valid'.node3L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m))
(H2 : BalancedSz (size l + size m + 1) (size r)) : Valid' o₁ (@node3L α l x m y r) o₂ :=
(hl.node' hm H1).node' hr H2
theorem Valid'.node3R {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m + size r + 1))
(H2 : BalancedSz (size m) (size r)) : Valid' o₁ (@node3R α l x m y r) o₂ :=
hl.node' (hm.node' hr H2) H1
theorem Valid'.node4L_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9)
(mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by omega
theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega
theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) :
d ≤ 3 * c := by omega
theorem Valid'.node4L_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d)
(mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by omega
theorem Valid'.node4L_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9)
(mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by omega
theorem Valid'.node4L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y)
(hr : Valid' (↑y) r o₂) (Hm : 0 < size m)
(H : size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨
0 < size l ∧
ratio * size r ≤ size m ∧
delta * size l ≤ size m + size r ∧
3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r) :
Valid' o₁ (@node4L α l x m y r) o₂ := by
obtain - | ⟨s, ml, z, mr⟩ := m; · cases Hm
suffices
BalancedSz (size l) (size ml) ∧
BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1) from
Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2
rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩)
· rw [hm.2.size_eq, Nat.succ_inj, add_eq_zero] at m1
rw [l0, m1.1, m1.2]; revert r0; rcases size r with (_ | _ | _) <;>
[decide; decide; (intro r0; unfold BalancedSz delta; omega)]
· rcases Nat.eq_zero_or_pos (size r) with r0 | r0
· rw [r0] at mr₂; cases not_le_of_lt Hm mr₂
rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂
by_cases mm : size ml + size mr ≤ 1
· have r1 :=
le_antisymm
((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0
rw [r1, add_assoc] at lr₁
have l1 :=
le_antisymm
((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1))
l0
rw [l1, r1]
revert mm; cases size ml <;> cases size mr <;> intro mm
· decide
· rw [zero_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩)
decide
· rcases mm with (_ | ⟨⟨⟩⟩); decide
· rw [Nat.succ_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩)
rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩
rcases Nat.eq_zero_or_pos (size ml) with ml0 | ml0
· rw [ml0, mul_zero, Nat.le_zero] at mm₂
rw [ml0, mm₂] at mm; cases mm (by decide)
have : 2 * size l ≤ size ml + size mr + 1 := by
have := Nat.mul_le_mul_left ratio lr₁
rw [mul_left_comm, mul_add] at this
have := le_trans this (add_le_add_left mr₁ _)
rw [← Nat.succ_mul] at this
exact (mul_le_mul_left (by decide)).1 this
refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩
· refine (mul_le_mul_left (by decide)).1 (le_trans this ?_)
rw [two_mul, Nat.succ_le_iff]
refine add_lt_add_of_lt_of_le ?_ mm₂
simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3)
· exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁)
· exact Valid'.node4L_lemma₂ mr₂
· exact Valid'.node4L_lemma₃ mr₁ mm₁
· exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁
· exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂
theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by
omega
theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) :
b < 3 * a + 1 := by omega
theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by
omega
theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by
omega
theorem Valid'.rotateL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H1 : ¬size l + size r ≤ 1) (H2 : delta * size l < size r)
(H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@rotateL α l x r) o₂ := by
obtain - | ⟨rs, rl, rx, rr⟩ := r; · cases H2
rw [hr.2.size_eq, Nat.lt_succ_iff] at H2
rw [hr.2.size_eq] at H3
replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 :=
H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ
have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by
intro l0; rw [l0] at H3
exact
(or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3
have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l =>
(or_iff_left_of_imp <| by omega).1 H3
have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by omega
have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb =>
absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide)
rw [Ordnode.rotateL_node]; split_ifs with h
· have rr0 : size rr > 0 :=
(mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _)
suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by
exact hl.node3L hr.left hr.right this.1 this.2
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· rw [l0]; replace H3 := H3_0 l0
have := hr.3.1
rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0
· rw [rl0] at this ⊢
rw [le_antisymm (balancedSz_zero.1 this.symm) rr0]
decide
have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0
rw [add_comm] at H3
rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0]
decide
replace H3 := H3p l0
rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩
refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩
· exact Valid'.rotateL_lemma₁ H2 hb₂
· exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h)
· exact Valid'.rotateL_lemma₃ H2 h
· exact
le_trans hb₂
(Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _))
· rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0
· rw [rl0, not_lt, Nat.le_zero, Nat.mul_eq_zero] at h
replace h := h.resolve_left (by decide)
rw [rl0, h, Nat.le_zero, Nat.mul_eq_zero] at H2
rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1
cases H1 (by decide)
refine hl.node4L hr.left hr.right rl0 ?_
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· replace H3 := H3_0 l0
rcases Nat.eq_zero_or_pos (size rr) with rr0 | rr0
· have := hr.3.1
rw [rr0] at this
exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩
exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩
exact
Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩
theorem Valid'.rotateR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H1 : ¬size l + size r ≤ 1) (H2 : delta * size r < size l)
(H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@rotateR α l x r) o₂ := by
refine Valid'.dual_iff.2 ?_
rw [dual_rotateR]
refine hr.dual.rotateL hl.dual ?_ ?_ ?_
· rwa [size_dual, size_dual, add_comm]
· rwa [size_dual, size_dual]
· rwa [size_dual, size_dual]
theorem Valid'.balance'_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3)
(H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balance' α l x r) o₂ := by
rw [balance']; split_ifs with h h_1 h_2
· exact hl.node' hr (Or.inl h)
· exact hl.rotateL hr h h_1 H₁
· exact hl.rotateR hr h h_2 H₂
· exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩)
theorem Valid'.balance'_lemma {α l l' r r'} (H1 : BalancedSz l' r')
(H2 : Nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l') :
2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := by
suffices @size α r ≤ 3 * (size l + 1) by omega
rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩) <;> rcases H1 with (h | ⟨_, h₂⟩)
· exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _))
· exact
le_trans h₂
(Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _))
· exact
le_trans (Nat.dist_tri_left' _ _)
(le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by omega))
· rw [Nat.mul_succ]
exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide)))
theorem Valid'.balance' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : ∃ l' r', BalancedSz l' r' ∧
(Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) :
Valid' o₁ (@balance' α l x r) o₂ :=
let ⟨_, _, H1, H2⟩ := H
Valid'.balance'_aux hl hr (Valid'.balance'_lemma H1 H2) (Valid'.balance'_lemma H1.symm H2.symm)
theorem Valid'.balance {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : ∃ l' r', BalancedSz l' r' ∧
(Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) :
Valid' o₁ (@balance α l x r) o₂ := by
rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]; exact hl.balance' hr H
theorem Valid'.balanceL_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l)
(H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balanceL α l x r) o₂ := by
rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2]
refine hl.balance'_aux hr (Or.inl ?_) H₃
rcases Nat.eq_zero_or_pos (size r) with r0 | r0
· rw [r0]; exact Nat.zero_le _
rcases Nat.eq_zero_or_pos (size l) with l0 | l0
· rw [l0]; exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide)
replace H₂ : _ ≤ 3 * _ := H₂ l0 r0; omega
theorem Valid'.balanceL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨
∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') :
Valid' o₁ (@balanceL α l x r) o₂ := by
rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H]
refine hl.balance' hr ?_
rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩)
· exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩
· exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩
theorem Valid'.balanceR_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r)
(H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@balanceR α l x r) o₂ := by
rw [Valid'.dual_iff, dual_balanceR]
have := hr.dual.balanceL_aux hl.dual
rw [size_dual, size_dual] at this
exact this H₁ H₂ H₃
theorem Valid'.balanceR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂)
(H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨
∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') :
Valid' o₁ (@balanceR α l x r) o₂ := by
rw [Valid'.dual_iff, dual_balanceR]; exact hr.dual.balanceL hl.dual (balance_sz_dual H)
theorem Valid'.eraseMax_aux {s l x r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) :
Valid' o₁ (@eraseMax α (.node' l x r)) ↑(findMax' x r) ∧
size (.node' l x r) = size (eraseMax (.node' l x r)) + 1 := by
have := H.2.eq_node'; rw [this] at H; clear this
induction r generalizing l x o₁ with
| nil => exact ⟨H.left, rfl⟩
| node rs rl rx rr _ IHrr =>
have := H.2.2.2.eq_node'; rw [this] at H ⊢
rcases IHrr H.right with ⟨h, e⟩
refine ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), ?_⟩
rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)]
rw [size_node, e]; rfl
theorem Valid'.eraseMin_aux {s l} {x : α} {r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) :
Valid' ↑(findMin' l x) (@eraseMin α (.node' l x r)) o₂ ∧
size (.node' l x r) = size (eraseMin (.node' l x r)) + 1 := by
have := H.dual.eraseMax_aux
rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual]
at this
theorem eraseMin.valid : ∀ {t}, @Valid α _ t → Valid (eraseMin t)
| nil, _ => valid_nil
| node _ l x r, h => by rw [h.2.eq_node']; exact h.eraseMin_aux.1.valid
theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by
rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual
theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
(sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) :
Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by
obtain - | ⟨ls, ll, lx, lr⟩ := l; · exact ⟨hr, (zero_add _).symm⟩
obtain - | ⟨rs, rl, rx, rr⟩ := r; · exact ⟨hl, rfl⟩
dsimp [glue]; split_ifs
· rw [splitMax_eq]
· obtain ⟨v, e⟩ := Valid'.eraseMax_aux hl
suffices H : _ by
refine ⟨Valid'.balanceR v (hr.of_gt ?_ ?_) H, ?_⟩
· refine findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂)
lx lr hl.1.2.to_nil (sep.2.2.imp ?_)
exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1)
· exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2
· rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl
refine Or.inl ⟨_, Or.inr e, ?_⟩
rwa [hl.2.eq_node'] at bal
· rw [splitMin_eq]
· obtain ⟨v, e⟩ := Valid'.eraseMin_aux hr
suffices H : _ by
refine ⟨Valid'.balanceL (hl.of_lt ?_ ?_) v H, ?_⟩
· refine @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α))
_ rl rx (sep.2.1.1.imp ?_) hr.1.1.to_nil
exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h)
· exact
@findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx
(all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx)
(sep.imp fun y hy => hy.2.1)
· rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl
refine Or.inr ⟨_, Or.inr e, ?_⟩
rwa [hr.2.eq_node'] at bal
theorem Valid'.glue {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) :
BalancedSz (size l) (size r) →
Valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r :=
Valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1)
theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) :
2 * (a + b) ≤ 9 * c + 5 := by omega
theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t}
(hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂)
(h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) :
Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by
rw [hl.2.1] at e
rw [hl.2.1, hr.2.1, delta] at h
rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · omega
suffices H₂ : _ by
suffices H₁ : _ by
refine ⟨Valid'.balanceL_aux v hr.right H₁ H₂ ?_, ?_⟩
· rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁)
· rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2,
size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1]
abel
· rw [e, add_right_comm]; rintro ⟨⟩
intro _ _; rw [e]; unfold delta at hr₂ ⊢; omega
theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂)
(sep : l.All fun x => r.All fun y => x < y) :
Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by
induction l generalizing o₁ o₂ r with
| nil => exact ⟨hr, (zero_add _).symm⟩
| node ls ll lx lr _ IHlr => ?_
induction r generalizing o₁ o₂ with
| nil => exact ⟨hl, rfl⟩
| node rs rl rx rr IHrl _ => ?_
rw [merge_node]; split_ifs with h h_1
· obtain ⟨v, e⟩ := IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left
(sep.imp fun x h => h.1)
exact Valid'.merge_aux₁ hl hr h v e
· obtain ⟨v, e⟩ := IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2
have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual
rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual,
add_comm rs] at this
exact this e
· refine Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩)
theorem Valid.merge {l r} (hl : Valid l) (hr : Valid r)
(sep : l.All fun x => r.All fun y => x < y) : Valid (@merge α l r) :=
(Valid'.merge_aux hl hr sep).1
theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α)
(hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) :
∀ {t o₁ o₂},
Valid' o₁ t o₂ →
Bounded nil o₁ x →
Bounded nil x o₂ →
Valid' o₁ (insertWith f x t) o₂ ∧ Raised (size t) (size (insertWith f x t))
| nil, _, _, _, bl, br => ⟨valid'_singleton bl br, Or.inr rfl⟩
| node sz l y r, o₁, o₂, h, bl, br => by
rw [insertWith, cmpLE]
split_ifs with h_1 h_2 <;> dsimp only
· rcases h with ⟨⟨lx, xr⟩, hs, hb⟩
rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩
refine
⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩
· rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩
suffices H : _ by
refine ⟨vl.balanceL h.right H, ?_⟩
rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq]
exact (e.add_right _).add_right _
exact Or.inl ⟨_, e, h.3.1⟩
· have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1
rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩
suffices H : _ by
refine ⟨h.left.balanceR vr H, ?_⟩
rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq]
exact (e.add_left _).add_right _
exact Or.inr ⟨_, e, h.3.1⟩
theorem insertWith.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α)
(hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : Valid t) : Valid (insertWith f x t) :=
(insertWith.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1
theorem insert_eq_insertWith [DecidableLE α] (x : α) :
∀ t, Ordnode.insert x t = insertWith (fun _ => x) x t
| nil => rfl
| node _ l y r => by
unfold Ordnode.insert insertWith; cases cmpLE x y <;> simp [insert_eq_insertWith]
theorem insert.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) :
Valid (Ordnode.insert x t) := by
rw [insert_eq_insertWith]; exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h
theorem insert'_eq_insertWith [DecidableLE α] (x : α) :
∀ t, insert' x t = insertWith id x t
| nil => rfl
| node _ l y r => by
unfold insert' insertWith; cases cmpLE x y <;> simp [insert'_eq_insertWith]
theorem insert'.valid [IsTotal α (· ≤ ·)] [DecidableLE α]
(x : α) {t} (h : Valid t) : Valid (insert' x t) := by
rw [insert'_eq_insertWith]; exact insertWith.valid _ _ (fun _ => id) h
theorem Valid'.map_aux {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t a₁ a₂}
(h : Valid' a₁ t a₂) :
Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ (map f t).size = t.size := by
induction t generalizing a₁ a₂ with
| nil =>
simp only [map, size_nil, and_true]; apply valid'_nil
cases a₁; · trivial
cases a₂; · trivial
simp only [Option.map, Bounded]
exact f_strict_mono h.ord
| node _ _ _ _ t_ih_l t_ih_r =>
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l'
obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r'
simp only [map, size_node, and_true]
constructor
· exact And.intro t_l_valid.ord t_r_valid.ord
· constructor
· rw [t_l_size, t_r_size]; exact h.sz.1
· constructor
· exact t_l_valid.sz
· exact t_r_valid.sz
· constructor
· rw [t_l_size, t_r_size]; exact h.bal.1
· constructor
· exact t_l_valid.bal
· exact t_r_valid.bal
theorem map.valid {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t} (h : Valid t) :
Valid (map f t) :=
(Valid'.map_aux f_strict_mono h).1
theorem Valid'.erase_aux [DecidableLE α] (x : α) {t a₁ a₂} (h : Valid' a₁ t a₂) :
Valid' a₁ (erase x t) a₂ ∧ Raised (erase x t).size t.size := by
induction t generalizing a₁ a₂ with
| nil =>
simpa [erase, Raised]
| node _ t_l t_x t_r t_ih_l t_ih_r =>
simp only [erase, size_node]
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l'
obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r'
cases cmpLE x t_x <;> rw [h.sz.1]
· suffices h_balanceable : _ by
constructor
· exact Valid'.balanceR t_l_valid h.right h_balanceable
· rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable]
repeat apply Raised.add_right
exact t_l_size
left; exists t_l.size; exact And.intro t_l_size h.bal.1
· have h_glue := Valid'.glue h.left h.right h.bal.1
obtain ⟨h_glue_valid, h_glue_sized⟩ := h_glue
constructor
· exact h_glue_valid
· right; rw [h_glue_sized]
· suffices h_balanceable : _ by
constructor
· exact Valid'.balanceL h.left t_r_valid h_balanceable
· rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable]
apply Raised.add_right
apply Raised.add_left
exact t_r_size
right; exists t_r.size; exact And.intro t_r_size h.bal.1
theorem erase.valid [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (erase x t) :=
(Valid'.erase_aux x h).1
theorem size_erase_of_mem [DecidableLE α] {x : α} {t a₁ a₂} (h : Valid' a₁ t a₂)
(h_mem : x ∈ t) : size (erase x t) = size t - 1 := by
induction t generalizing a₁ a₂ with
| nil =>
contradiction
| node _ t_l t_x t_r t_ih_l t_ih_r =>
have t_ih_l' := t_ih_l h.left
have t_ih_r' := t_ih_r h.right
clear t_ih_l t_ih_r
dsimp only [Membership.mem, mem] at h_mem
unfold erase
revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢
· have t_ih_l := t_ih_l' h_mem
clear t_ih_l' t_ih_r'
have t_l_h := Valid'.erase_aux x h.left
obtain ⟨t_l_valid, t_l_size⟩ := t_l_h
rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz
(Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))]
rw [t_ih_l, h.sz.1]
have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem
revert h_pos_t_l_size; rcases t_l.size with - | t_l_size <;> intro h_pos_t_l_size
· cases h_pos_t_l_size
· simp [Nat.add_right_comm]
· rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl
· have t_ih_r := t_ih_r' h_mem
clear t_ih_l' t_ih_r'
have t_r_h := Valid'.erase_aux x h.right
obtain ⟨t_r_valid, t_r_size⟩ := t_r_h
rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz
(Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))]
rw [t_ih_r, h.sz.1]
have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem
revert h_pos_t_r_size; rcases t_r.size with - | t_r_size <;> intro h_pos_t_r_size
· cases h_pos_t_r_size
· simp [Nat.add_assoc]
end Valid
end Ordnode
/-- An `Ordset α` is a finite set of values, represented as a tree. The operations on this type
maintain that the tree is balanced and correctly stores subtree sizes at each level. The
correctness property of the tree is baked into the type, so all operations on this type are correct
by construction. -/
def Ordset (α : Type*) [Preorder α] :=
{ t : Ordnode α // t.Valid }
namespace Ordset
open Ordnode
variable [Preorder α]
/-- O(1). The empty set. -/
nonrec def nil : Ordset α :=
⟨nil, ⟨⟩, ⟨⟩, ⟨⟩⟩
/-- O(1). Get the size of the set. -/
def size (s : Ordset α) : ℕ :=
s.1.size
/-- O(1). Construct a singleton set containing value `a`. -/
protected def singleton (a : α) : Ordset α :=
⟨singleton a, valid_singleton⟩
instance instEmptyCollection : EmptyCollection (Ordset α) :=
⟨nil⟩
instance instInhabited : Inhabited (Ordset α) :=
⟨nil⟩
instance instSingleton : Singleton α (Ordset α) :=
⟨Ordset.singleton⟩
/-- O(1). Is the set empty? -/
def Empty (s : Ordset α) : Prop :=
s = ∅
theorem empty_iff {s : Ordset α} : s = ∅ ↔ s.1.empty :=
⟨fun h => by cases h; exact rfl,
fun h => by cases s with | mk s_val _ => cases s_val <;> [rfl; cases h]⟩
instance Empty.instDecidablePred : DecidablePred (@Empty α _) :=
fun _ => decidable_of_iff' _ empty_iff
/-- O(log n). Insert an element into the set, preserving balance and the BST property.
If an equivalent element is already in the set, this replaces it. -/
protected def insert [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) :
Ordset α :=
⟨Ordnode.insert x s.1, insert.valid _ s.2⟩
instance instInsert [IsTotal α (· ≤ ·)] [DecidableLE α] : Insert α (Ordset α) :=
⟨Ordset.insert⟩
/-- O(log n). Insert an element into the set, preserving balance and the BST property.
If an equivalent element is already in the set, the set is returned as is. -/
nonrec def insert' [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) :
Ordset α :=
⟨insert' x s.1, insert'.valid _ s.2⟩
section
variable [DecidableLE α]
/-- O(log n). Does the set contain the element `x`? That is,
is there an element that is equivalent to `x` in the order? -/
def mem (x : α) (s : Ordset α) : Bool :=
x ∈ s.val
/-- O(log n). Retrieve an element in the set that is equivalent to `x` in the order,
if it exists. -/
def find (x : α) (s : Ordset α) : Option α :=
Ordnode.find x s.val
instance instMembership : Membership α (Ordset α) :=
⟨fun s x => mem x s⟩
instance mem.decidable (x : α) (s : Ordset α) : Decidable (x ∈ s) :=
instDecidableEqBool _ _
theorem pos_size_of_mem {x : α} {t : Ordset α} (h_mem : x ∈ t) : 0 < size t := by
simp? [Membership.mem, mem] at h_mem says
simp only [Membership.mem, mem, Bool.decide_eq_true] at h_mem
apply Ordnode.pos_size_of_mem t.property.sz h_mem
end
/-- O(log n). Remove an element from the set equivalent to `x`. Does nothing if there
is no such element. -/
def erase [DecidableLE α] (x : α) (s : Ordset α) : Ordset α :=
⟨Ordnode.erase x s.val, Ordnode.erase.valid x s.property⟩
/-- O(n). Map a function across a tree, without changing the structure. -/
def map {β} [Preorder β] (f : α → β) (f_strict_mono : StrictMono f) (s : Ordset α) : Ordset β :=
⟨Ordnode.map f s.val, Ordnode.map.valid f_strict_mono s.property⟩
end Ordset
| Mathlib/Data/Ordmap/Ordset.lean | 1,554 | 1,558 | |
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Interval.Finset.Basic
/-!
# Intervals as multisets
This file defines intervals as multisets.
## Main declarations
In a `LocallyFiniteOrder`,
* `Multiset.Icc`: Closed-closed interval as a multiset.
* `Multiset.Ico`: Closed-open interval as a multiset.
* `Multiset.Ioc`: Open-closed interval as a multiset.
* `Multiset.Ioo`: Open-open interval as a multiset.
In a `LocallyFiniteOrderTop`,
* `Multiset.Ici`: Closed-infinite interval as a multiset.
* `Multiset.Ioi`: Open-infinite interval as a multiset.
In a `LocallyFiniteOrderBot`,
* `Multiset.Iic`: Infinite-open interval as a multiset.
* `Multiset.Iio`: Infinite-closed interval as a multiset.
## TODO
Do we really need this file at all? (March 2024)
-/
variable {α : Type*}
namespace Multiset
section LocallyFiniteOrder
variable [Preorder α] [LocallyFiniteOrder α] {a b x : α}
/-- The multiset of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a
multiset. -/
def Icc (a b : α) : Multiset α := (Finset.Icc a b).val
/-- The multiset of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a
multiset. -/
def Ico (a b : α) : Multiset α := (Finset.Ico a b).val
/-- The multiset of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a
multiset. -/
def Ioc (a b : α) : Multiset α := (Finset.Ioc a b).val
/-- The multiset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a
multiset. -/
def Ioo (a b : α) : Multiset α := (Finset.Ioo a b).val
@[simp] lemma mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := by rw [Icc, ← Finset.mem_def, Finset.mem_Icc]
@[simp] lemma mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := by rw [Ico, ← Finset.mem_def, Finset.mem_Ico]
@[simp] lemma mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := by rw [Ioc, ← Finset.mem_def, Finset.mem_Ioc]
@[simp] lemma mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := by rw [Ioo, ← Finset.mem_def, Finset.mem_Ioo]
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [Preorder α] [LocallyFiniteOrderTop α] {a x : α}
/-- The multiset of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a multiset. -/
def Ici (a : α) : Multiset α := (Finset.Ici a).val
/-- The multiset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a multiset. -/
def Ioi (a : α) : Multiset α := (Finset.Ioi a).val
@[simp] lemma mem_Ici : x ∈ Ici a ↔ a ≤ x := by rw [Ici, ← Finset.mem_def, Finset.mem_Ici]
@[simp] lemma mem_Ioi : x ∈ Ioi a ↔ a < x := by rw [Ioi, ← Finset.mem_def, Finset.mem_Ioi]
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [Preorder α] [LocallyFiniteOrderBot α] {b x : α}
/-- The multiset of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a multiset. -/
def Iic (b : α) : Multiset α := (Finset.Iic b).val
/-- The multiset of elements `x` such that `x < b`. Basically `Set.Iio b` as a multiset. -/
def Iio (b : α) : Multiset α := (Finset.Iio b).val
@[simp] lemma mem_Iic : x ∈ Iic b ↔ x ≤ b := by rw [Iic, ← Finset.mem_def, Finset.mem_Iic]
@[simp] lemma mem_Iio : x ∈ Iio b ↔ x < b := by rw [Iio, ← Finset.mem_def, Finset.mem_Iio]
end LocallyFiniteOrderBot
section Preorder
variable [Preorder α] [LocallyFiniteOrder α] {a b c : α}
theorem nodup_Icc : (Icc a b).Nodup :=
Finset.nodup _
theorem nodup_Ico : (Ico a b).Nodup :=
Finset.nodup _
theorem nodup_Ioc : (Ioc a b).Nodup :=
Finset.nodup _
theorem nodup_Ioo : (Ioo a b).Nodup :=
Finset.nodup _
@[simp]
theorem Icc_eq_zero_iff : Icc a b = 0 ↔ ¬a ≤ b := by
rw [Icc, Finset.val_eq_zero, Finset.Icc_eq_empty_iff]
@[simp]
theorem Ico_eq_zero_iff : Ico a b = 0 ↔ ¬a < b := by
rw [Ico, Finset.val_eq_zero, Finset.Ico_eq_empty_iff]
@[simp]
theorem Ioc_eq_zero_iff : Ioc a b = 0 ↔ ¬a < b := by
rw [Ioc, Finset.val_eq_zero, Finset.Ioc_eq_empty_iff]
@[simp]
theorem Ioo_eq_zero_iff [DenselyOrdered α] : Ioo a b = 0 ↔ ¬a < b := by
rw [Ioo, Finset.val_eq_zero, Finset.Ioo_eq_empty_iff]
alias ⟨_, Icc_eq_zero⟩ := Icc_eq_zero_iff
alias ⟨_, Ico_eq_zero⟩ := Ico_eq_zero_iff
alias ⟨_, Ioc_eq_zero⟩ := Ioc_eq_zero_iff
@[simp]
theorem Ioo_eq_zero (h : ¬a < b) : Ioo a b = 0 :=
eq_zero_iff_forall_not_mem.2 fun _x hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
@[simp]
theorem Icc_eq_zero_of_lt (h : b < a) : Icc a b = 0 :=
Icc_eq_zero h.not_le
@[simp]
theorem Ico_eq_zero_of_le (h : b ≤ a) : Ico a b = 0 :=
Ico_eq_zero h.not_lt
@[simp]
theorem Ioc_eq_zero_of_le (h : b ≤ a) : Ioc a b = 0 :=
Ioc_eq_zero h.not_lt
@[simp]
theorem Ioo_eq_zero_of_le (h : b ≤ a) : Ioo a b = 0 :=
Ioo_eq_zero h.not_lt
variable (a)
theorem Ico_self : Ico a a = 0 := by rw [Ico, Finset.Ico_self, Finset.empty_val]
theorem Ioc_self : Ioc a a = 0 := by rw [Ioc, Finset.Ioc_self, Finset.empty_val]
theorem Ioo_self : Ioo a a = 0 := by rw [Ioo, Finset.Ioo_self, Finset.empty_val]
variable {a}
theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b :=
Finset.left_mem_Icc
theorem left_mem_Ico : a ∈ Ico a b ↔ a < b :=
Finset.left_mem_Ico
theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b :=
Finset.right_mem_Icc
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b :=
Finset.right_mem_Ioc
theorem left_not_mem_Ioc : a ∉ Ioc a b :=
Finset.left_not_mem_Ioc
theorem left_not_mem_Ioo : a ∉ Ioo a b :=
Finset.left_not_mem_Ioo
theorem right_not_mem_Ico : b ∉ Ico a b :=
Finset.right_not_mem_Ico
theorem right_not_mem_Ioo : b ∉ Ioo a b :=
Finset.right_not_mem_Ioo
theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) :
((Ico a b).filter fun x => x < c) = ∅ := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_left hca]
rfl
theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) :
((Ico a b).filter fun x => x < c) = Ico a b := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_right_le hbc]
theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) :
((Ico a b).filter fun x => x < c) = Ico a c := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_right hcb]
rfl
theorem Ico_filter_le_of_le_left [DecidablePred (c ≤ ·)] (hca : c ≤ a) :
((Ico a b).filter fun x => c ≤ x) = Ico a b := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_le_left hca]
theorem Ico_filter_le_of_right_le [DecidablePred (b ≤ ·)] :
((Ico a b).filter fun x => b ≤ x) = ∅ := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_right_le]
rfl
theorem Ico_filter_le_of_left_le [DecidablePred (c ≤ ·)] (hac : a ≤ c) :
((Ico a b).filter fun x => c ≤ x) = Ico c b := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_left_le hac]
rfl
end Preorder
section PartialOrder
variable [PartialOrder α] [LocallyFiniteOrder α] {a b : α}
@[simp]
theorem Icc_self (a : α) : Icc a a = {a} := by rw [Icc, Finset.Icc_self, Finset.singleton_val]
theorem Ico_cons_right (h : a ≤ b) : b ::ₘ Ico a b = Icc a b := by
classical
rw [Ico, ← Finset.insert_val_of_not_mem right_not_mem_Ico, Finset.Ico_insert_right h]
rfl
theorem Ioo_cons_left (h : a < b) : a ::ₘ Ioo a b = Ico a b := by
classical
rw [Ioo, ← Finset.insert_val_of_not_mem left_not_mem_Ioo, Finset.Ioo_insert_left h]
rfl
theorem Ico_disjoint_Ico {a b c d : α} (h : b ≤ c) : Disjoint (Ico a b) (Ico c d) :=
disjoint_left.mpr fun hab hbc => by
rw [mem_Ico] at hab hbc
exact hab.2.not_le (h.trans hbc.1)
@[simp]
theorem Ico_inter_Ico_of_le [DecidableEq α] {a b c d : α} (h : b ≤ c) : Ico a b ∩ Ico c d = 0 :=
Multiset.inter_eq_zero_iff_disjoint.2 <| Ico_disjoint_Ico h
theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) :
((Ico a b).filter fun x => x ≤ a) = {a} := by
rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_left hab]
rfl
theorem card_Ico_eq_card_Icc_sub_one (a b : α) : card (Ico a b) = card (Icc a b) - 1 :=
Finset.card_Ico_eq_card_Icc_sub_one _ _
theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : card (Ioc a b) = card (Icc a b) - 1 :=
Finset.card_Ioc_eq_card_Icc_sub_one _ _
theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : card (Ioo a b) = card (Ico a b) - 1 :=
Finset.card_Ioo_eq_card_Ico_sub_one _ _
theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : card (Ioo a b) = card (Icc a b) - 2 :=
Finset.card_Ioo_eq_card_Icc_sub_two _ _
end PartialOrder
section LinearOrder
variable [LinearOrder α] [LocallyFiniteOrder α] {a b c d : α}
theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) :
Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
Finset.Ico_subset_Ico_iff h
theorem Ico_add_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) :
Ico a b + Ico b c = Ico a c := by
rw [add_eq_union_iff_disjoint.2 (Ico_disjoint_Ico le_rfl), Ico, Ico, Ico, ← Finset.union_val,
Finset.Ico_union_Ico_eq_Ico hab hbc]
theorem Ico_inter_Ico : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by
rw [Ico, Ico, Ico, ← Finset.inter_val, Finset.Ico_inter_Ico]
@[simp]
theorem Ico_filter_lt (a b c : α) : ((Ico a b).filter fun x => x < c) = Ico a (min b c) := by
rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_lt]
@[simp]
theorem Ico_filter_le (a b c : α) : ((Ico a b).filter fun x => c ≤ x) = Ico (max a c) b := by
rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_le]
@[simp]
theorem Ico_sub_Ico_left (a b c : α) : Ico a b - Ico a c = Ico (max a c) b := by
rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_left]
|
@[simp]
theorem Ico_sub_Ico_right (a b c : α) : Ico a b - Ico c b = Ico a (min b c) := by
rw [Ico, Ico, Ico, ← Finset.sdiff_val, Finset.Ico_diff_Ico_right]
| Mathlib/Order/Interval/Multiset.lean | 293 | 296 |
/-
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.Algebra.NeZero
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
/-! # Image and map operations on finite sets
This file provides the finite analog of `Set.image`, along with some other similar functions.
Note there are two ways to take the image over a finset; via `Finset.image` which applies the
function then removes duplicates (requiring `DecidableEq`), or via `Finset.map` which exploits
injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to
choosing between `insert` and `Finset.cons`, or between `Finset.union` and `Finset.disjUnion`.
## Main definitions
* `Finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`.
* `Finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`.
* `Finset.filterMap` Given a function `f : α → Option β`, `s.filterMap f` is the
image finset in `β`, filtering out `none`s.
* `Finset.subtype`: `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`.
* `Finset.fin`:`s.fin n` is the finset of all elements of `s` less than `n`.
-/
assert_not_exists Monoid OrderedCommMonoid
variable {α β γ : Type*}
open Multiset
open Function
namespace Finset
/-! ### map -/
section Map
open Function
/-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image
finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/
def map (f : α ↪ β) (s : Finset α) : Finset β :=
⟨s.1.map f, s.2.map f.2⟩
@[simp]
theorem map_val (f : α ↪ β) (s : Finset α) : (map f s).1 = s.1.map f :=
rfl
@[simp]
theorem map_empty (f : α ↪ β) : (∅ : Finset α).map f = ∅ :=
rfl
variable {f : α ↪ β} {s : Finset α}
@[simp]
theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b :=
Multiset.mem_map
-- Higher priority to apply before `mem_map`.
@[simp 1100]
theorem mem_map_equiv {f : α ≃ β} {b : β} : b ∈ s.map f.toEmbedding ↔ f.symm b ∈ s := by
rw [mem_map]
exact
⟨by
rintro ⟨a, H, rfl⟩
simpa, fun h => ⟨_, h, by simp⟩⟩
@[simp 1100]
theorem mem_map' (f : α ↪ β) {a} {s : Finset α} : f a ∈ s.map f ↔ a ∈ s :=
mem_map_of_injective f.2
theorem mem_map_of_mem (f : α ↪ β) {a} {s : Finset α} : a ∈ s → f a ∈ s.map f :=
(mem_map' _).2
theorem forall_mem_map {f : α ↪ β} {s : Finset α} {p : ∀ a, a ∈ s.map f → Prop} :
(∀ y (H : y ∈ s.map f), p y H) ↔ ∀ x (H : x ∈ s), p (f x) (mem_map_of_mem _ H) :=
⟨fun h y hy => h (f y) (mem_map_of_mem _ hy),
fun h x hx => by
obtain ⟨y, hy, rfl⟩ := mem_map.1 hx
exact h _ hy⟩
theorem apply_coe_mem_map (f : α ↪ β) (s : Finset α) (x : s) : f x ∈ s.map f :=
mem_map_of_mem f x.prop
@[simp, norm_cast]
theorem coe_map (f : α ↪ β) (s : Finset α) : (s.map f : Set β) = f '' s :=
Set.ext (by simp only [mem_coe, mem_map, Set.mem_image, implies_true])
theorem coe_map_subset_range (f : α ↪ β) (s : Finset α) : (s.map f : Set β) ⊆ Set.range f :=
calc
↑(s.map f) = f '' s := coe_map f s
_ ⊆ Set.range f := Set.image_subset_range f ↑s
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem map_perm {σ : Equiv.Perm α} (hs : { a | σ a ≠ a } ⊆ s) : s.map (σ : α ↪ α) = s :=
coe_injective <| (coe_map _ _).trans <| Set.image_perm hs
theorem map_toFinset [DecidableEq α] [DecidableEq β] {s : Multiset α} :
s.toFinset.map f = (s.map f).toFinset :=
ext fun _ => by simp only [mem_map, Multiset.mem_map, exists_prop, Multiset.mem_toFinset]
@[simp]
theorem map_refl : s.map (Embedding.refl _) = s :=
ext fun _ => by simpa only [mem_map, exists_prop] using exists_eq_right
@[simp]
theorem map_cast_heq {α β} (h : α = β) (s : Finset α) :
HEq (s.map (Equiv.cast h).toEmbedding) s := by
subst h
simp
theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : Finset α) : (s.map f).map g = s.map (f.trans g) :=
eq_of_veq <| by simp only [map_val, Multiset.map_map]; rfl
theorem map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.map g).map f = (s.map f').map g' := by
simp_rw [map_map, Embedding.trans, Function.comp_def, h_comm]
theorem _root_.Function.Semiconj.finset_map {f : α ↪ β} {ga : α ↪ α} {gb : β ↪ β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := fun _ =>
map_comm h
theorem _root_.Function.Commute.finset_map {f g : α ↪ α} (h : Function.Commute f g) :
Function.Commute (map f) (map g) :=
Function.Semiconj.finset_map h
@[simp]
theorem map_subset_map {s₁ s₂ : Finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ :=
⟨fun h _ xs => (mem_map' _).1 <| h <| (mem_map' f).2 xs,
fun h => by simp [subset_def, Multiset.map_subset_map h]⟩
@[gcongr] alias ⟨_, _root_.GCongr.finsetMap_subset⟩ := map_subset_map
/-- The `Finset` version of `Equiv.subset_symm_image`. -/
theorem subset_map_symm {t : Finset β} {f : α ≃ β} : s ⊆ t.map f.symm ↔ s.map f ⊆ t := by
constructor <;> intro h x hx
· simp only [mem_map_equiv, Equiv.symm_symm] at hx
simpa using h hx
· simp only [mem_map_equiv]
exact h (by simp [hx])
/-- The `Finset` version of `Equiv.symm_image_subset`. -/
theorem map_symm_subset {t : Finset β} {f : α ≃ β} : t.map f.symm ⊆ s ↔ t ⊆ s.map f := by
simp only [← subset_map_symm, Equiv.symm_symm]
/-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a finset to its
image under `f`. -/
def mapEmbedding (f : α ↪ β) : Finset α ↪o Finset β :=
OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_subset_map
@[simp]
theorem map_inj {s₁ s₂ : Finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ :=
(mapEmbedding f).injective.eq_iff
theorem map_injective (f : α ↪ β) : Injective (map f) :=
(mapEmbedding f).injective
@[simp]
theorem map_ssubset_map {s t : Finset α} : s.map f ⊂ t.map f ↔ s ⊂ t := (mapEmbedding f).lt_iff_lt
@[gcongr] alias ⟨_, _root_.GCongr.finsetMap_ssubset⟩ := map_ssubset_map
@[simp]
theorem mapEmbedding_apply : mapEmbedding f s = map f s :=
rfl
theorem filter_map {p : β → Prop} [DecidablePred p] :
(s.map f).filter p = (s.filter (p ∘ f)).map f :=
eq_of_veq (Multiset.filter_map _ _ _)
lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α)
[DecidablePred (∃ a, p a ∧ f a = ·)] :
(s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [Function.comp_def, filter_map, f.injective.eq_iff]
lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] :
s.attach.filter p =
(s.filter fun x => ∃ h, p ⟨x, h⟩).attach.map
⟨Subtype.map id <| filter_subset _ _, Subtype.map_injective _ injective_id⟩ :=
eq_of_veq <| Multiset.filter_attach' _ _
lemma filter_attach (p : α → Prop) [DecidablePred p] (s : Finset α) :
s.attach.filter (fun a : s ↦ p a) =
(s.filter p).attach.map ((Embedding.refl _).subtypeMap mem_of_mem_filter) :=
eq_of_veq <| Multiset.filter_attach _ _
theorem map_filter {f : α ≃ β} {p : α → Prop} [DecidablePred p] :
(s.filter p).map f.toEmbedding = (s.map f.toEmbedding).filter (p ∘ f.symm) := by
simp only [filter_map, Function.comp_def, Equiv.toEmbedding_apply, Equiv.symm_apply_apply]
@[simp]
theorem disjoint_map {s t : Finset α} (f : α ↪ β) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
mod_cast Set.disjoint_image_iff f.injective (s := s) (t := t)
theorem map_disjUnion {f : α ↪ β} (s₁ s₂ : Finset α) (h) (h' := (disjoint_map _).mpr h) :
(s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' :=
eq_of_veq <| Multiset.map_add _ _ _
/-- A version of `Finset.map_disjUnion` for writing in the other direction. -/
theorem map_disjUnion' {f : α ↪ β} (s₁ s₂ : Finset α) (h') (h := (disjoint_map _).mp h') :
(s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' :=
map_disjUnion _ _ _
theorem map_union [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) :
(s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f :=
mod_cast Set.image_union f s₁ s₂
theorem map_inter [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) :
(s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f :=
mod_cast Set.image_inter f.injective (s := s₁) (t := s₂)
@[simp]
theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} :=
coe_injective <| by simp only [coe_map, coe_singleton, Set.image_singleton]
@[simp]
theorem map_insert [DecidableEq α] [DecidableEq β] (f : α ↪ β) (a : α) (s : Finset α) :
(insert a s).map f = insert (f a) (s.map f) := by
simp only [insert_eq, map_union, map_singleton]
@[simp]
theorem map_cons (f : α ↪ β) (a : α) (s : Finset α) (ha : a ∉ s) :
(cons a s ha).map f = cons (f a) (s.map f) (by simpa using ha) :=
eq_of_veq <| Multiset.map_cons f a s.val
@[simp]
theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := (map_injective f).eq_iff' (map_empty f)
@[simp]
theorem map_nonempty : (s.map f).Nonempty ↔ s.Nonempty :=
mod_cast Set.image_nonempty (f := f) (s := s)
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Nonempty.map⟩ := map_nonempty
@[simp]
theorem map_nontrivial : (s.map f).Nontrivial ↔ s.Nontrivial :=
mod_cast Set.image_nontrivial f.injective (s := s)
theorem attach_map_val {s : Finset α} : s.attach.map (Embedding.subtype _) = s :=
eq_of_veq <| by rw [map_val, attach_val]; exact Multiset.attach_map_val _
end Map
theorem range_add_one' (n : ℕ) :
range (n + 1) = insert 0 ((range n).map ⟨fun i => i + 1, fun i j => by simp⟩) := by
ext (⟨⟩ | ⟨n⟩) <;> simp [Nat.zero_lt_succ n]
/-! ### image -/
section Image
variable [DecidableEq β]
/-- `image f s` is the forward image of `s` under `f`. -/
| def image (f : α → β) (s : Finset α) : Finset β :=
(s.1.map f).toFinset
| Mathlib/Data/Finset/Image.lean | 268 | 269 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Comap
import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono, gcongr]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
@[gcongr]
theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) :
μ.restrict s ≤ ν.restrict s :=
restrict_mono subset_rfl h
@[gcongr]
theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) :
μ.restrict s ≤ μ.restrict t :=
restrict_mono h le_rfl
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s := by
simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
@[simp]
theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by
rw [← measure_univ_eq_zero, restrict_apply_univ]
/-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) :=
⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩
theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 :=
restrict_eq_zero.2 h
@[simp]
theorem restrict_empty : μ.restrict ∅ = 0 :=
restrict_zero_set measure_empty
@[simp]
theorem restrict_univ : μ.restrict univ = μ :=
ext fun s hs => by simp [hs]
theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq]
exact measure_inter_add_diff₀ (u ∩ s) ht
theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s :=
restrict_inter_add_diff₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ←
restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm]
theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t :=
restrict_union_add_inter₀ s ht.nullMeasurableSet
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h]
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t :=
restrict_union₀ h.aedisjoint ht.nullMeasurableSet
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
μ.restrict s + μ.restrict sᶜ = μ := by
rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self,
restrict_univ]
@[simp]
theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by
rw [add_comm, restrict_add_restrict_compl hs]
theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' :=
le_iff.2 fun t ht ↦ by
simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s')
theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by
simp only [restrict_apply, ht, inter_iUnion]
exact
measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right)
fun i => ht.nullMeasurableSet.inter (hm i)
theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) :
μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t :=
restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht
theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s)
{t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion]
rw [Directed.measure_iUnion]
exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _]
/-- The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/
theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) :
(μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
ext fun t ht => by simp [*, hf ht]
theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h,
inter_comm]
theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄
(hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ :=
calc
μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs)
_ = μ := restrict_univ
theorem restrict_congr_meas (hs : MeasurableSet s) :
μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t :=
⟨fun H t hts ht => by
rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H =>
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩
theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) :
μ.restrict s = ν.restrict s := by
rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s ∪ t`. -/
theorem restrict_union_congr :
μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔
μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by
refine ⟨fun h ↦ ⟨restrict_congr_mono subset_union_left h,
restrict_congr_mono subset_union_right h⟩, ?_⟩
rintro ⟨hs, ht⟩
ext1 u hu
simp only [restrict_apply hu, inter_union_distrib_left]
rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩
calc
μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) :=
measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl
_ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm.nullMeasurableSet _).symm
_ = restrict μ s u + restrict μ t (u \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc]
_ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht]
_ = ν US + ν ((u ∩ t) \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc]
_ = ν (US ∪ u ∩ t) := measure_add_diff hm.nullMeasurableSet _
_ = ν (u ∩ s ∪ u ∩ t) := .symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl
theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
classical
induction' s using Finset.induction_on with i s _ hs; · simp
simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert]
rw [restrict_union_congr, ← hs]
theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩
ext1 t ht
have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i :=
Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht
rw [iUnion_eq_iUnion_finset]
simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i]
theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) :
μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔
∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr]
theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) :
μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by
rw [sUnion_eq_biUnion, restrict_biUnion_congr hc]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)}
(hm : m.Nonempty) (ht : MeasurableSet t) :
(sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by
ext1 s hs
simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht),
Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ←
Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _),
OuterMeasure.restrict_apply]
theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop}
(hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by
rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs
exact (hs.and_eventually hp).exists
/-- If a quasi measure preserving map `f` maps a set `s` to a set `t`,
then it is quasi measure preserving with respect to the restrictions of the measures. -/
theorem QuasiMeasurePreserving.restrict {ν : Measure β} {f : α → β}
(hf : QuasiMeasurePreserving f μ ν) {t : Set β} (hmaps : MapsTo f s t) :
QuasiMeasurePreserving f (μ.restrict s) (ν.restrict t) where
measurable := hf.measurable
absolutelyContinuous := by
refine AbsolutelyContinuous.mk fun u hum ↦ ?_
suffices ν (u ∩ t) = 0 → μ (f ⁻¹' u ∩ s) = 0 by simpa [hum, hf.measurable, hf.measurable hum]
refine fun hu ↦ measure_mono_null ?_ (hf.preimage_null hu)
rw [preimage_inter]
gcongr
assumption
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) :
μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `biUnion`). -/
theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable)
(hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by
rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ]
alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) :
μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s :=
ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion]
alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ
theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞)
(ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by
refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_
ext1 u hu
simp only [restrict_apply hu]
induction u, hu using induction_on_inter h_gen h_inter with
| empty => simp only [Set.empty_inter, measure_empty]
| basic u hu => exact ST_eq _ ht _ hu
| compl u hu ihu =>
have := T_eq t ht
rw [Set.inter_comm] at ihu ⊢
rwa [← measure_inter_add_diff t hu, ← measure_inter_add_diff t hu, ← ihu,
ENNReal.add_right_inj] at this
exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left)
| iUnion f hfd hfm ihf =>
simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at ihf ⊢
simp only [measure_iUnion hfd hfm, ihf]
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`. -/
theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S)
(h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ)
(htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht)
intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H
· simp only [H, measure_empty]
· exact h_eq _ (h_inter _ hs _ (h_sub ht) H)
/-- Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on an increasing spanning sequence of sets in the π-system.
This lemma is formulated using `iUnion`.
`FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/
theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C)
(hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞)
(h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by
refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq
· rintro _ ⟨i, rfl⟩
apply h2B
· rintro _ ⟨i, rfl⟩
apply hμB
@[simp]
theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) :
(sum μ).restrict s = sum fun i => (μ i).restrict s :=
ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs]
@[simp]
theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) :
(sum μ).restrict s = sum fun i => (μ i).restrict s := by
ext t ht
simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable]
lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by
refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_)
rw [restrict_apply ht] at htν ⊢
exact h htν
theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s))
(hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht]
theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s))
(hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) :=
restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet
theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} :
μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) :=
le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·)
end Measure
@[simp]
theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) :
ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) :=
le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <|
iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl
@[simp]
theorem ae_restrict_union_eq (s t : Set α) :
ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by
simp [union_eq_iUnion, iSup_bool_eq]
theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype'']
theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) :
ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) :=
ae_restrict_biUnion_eq s t.countable_toSet
theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp
theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp
theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup]
@[simp]
theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) :
(∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by
simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup]
theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup]
theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by
simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup]
theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) :
f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g :=
ae_eq_restrict_biUnion_iff s t.countable_toSet f g
open scoped Interval in
theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) :
ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by
simp only [uIoc_eq_union, ae_restrict_union_eq]
open scoped Interval in
/-- See also `MeasureTheory.ae_uIoc_iff`. -/
theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔
(∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by
rw [ae_restrict_uIoc_eq, eventually_sup]
theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff₀ hp.nullMeasurableSet
theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) :
∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff] at h ⊢
simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h
theorem ae_restrict_iff'₀ {p : α → Prop} (hs : NullMeasurableSet s μ) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by
simp only [ae_iff, ← compl_setOf, restrict_apply₀' hs]
rw [iff_iff_eq]; congr with x; simp [and_comm]
theorem ae_restrict_iff' {p : α → Prop} (hs : MeasurableSet s) :
(∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x :=
ae_restrict_iff'₀ hs.nullMeasurableSet
theorem _root_.Filter.EventuallyEq.restrict {f g : α → δ} {s : Set α} (hfg : f =ᵐ[μ] g) :
f =ᵐ[μ.restrict s] g := by
-- note that we cannot use `ae_restrict_iff` since we do not require measurability
refine hfg.filter_mono ?_
rw [Measure.ae_le_iff_absolutelyContinuous]
exact Measure.absolutelyContinuous_of_le Measure.restrict_le_self
theorem ae_restrict_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
(ae_restrict_iff'₀ hs).2 (Filter.Eventually.of_forall fun _ => id)
theorem ae_restrict_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ.restrict s, x ∈ s :=
ae_restrict_mem₀ hs.nullMeasurableSet
theorem ae_restrict_of_forall_mem {μ : Measure α} {s : Set α}
(hs : MeasurableSet s) {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᵐ (x : α) ∂μ.restrict s, p x :=
(ae_restrict_mem hs).mono h
theorem ae_restrict_of_ae {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono Measure.restrict_le_self)
theorem ae_restrict_of_ae_restrict_of_subset {s t : Set α} {p : α → Prop} (hst : s ⊆ t)
(h : ∀ᵐ x ∂μ.restrict t, p x) : ∀ᵐ x ∂μ.restrict s, p x :=
h.filter_mono (ae_mono <| Measure.restrict_mono hst (le_refl μ))
theorem ae_of_ae_restrict_of_ae_restrict_compl (t : Set α) {p : α → Prop}
(ht : ∀ᵐ x ∂μ.restrict t, p x) (htc : ∀ᵐ x ∂μ.restrict tᶜ, p x) : ∀ᵐ x ∂μ, p x :=
nonpos_iff_eq_zero.1 <|
calc
μ { x | ¬p x } ≤ μ ({ x | ¬p x } ∩ t) + μ ({ x | ¬p x } ∩ tᶜ) :=
measure_le_inter_add_diff _ _ _
_ ≤ μ.restrict t { x | ¬p x } + μ.restrict tᶜ { x | ¬p x } :=
| add_le_add (le_restrict_apply _ _) (le_restrict_apply _ _)
_ = 0 := by rw [ae_iff.1 ht, ae_iff.1 htc, zero_add]
theorem mem_map_restrict_ae_iff {β} {s : Set α} {t : Set β} {f : α → β} (hs : MeasurableSet s) :
| Mathlib/MeasureTheory/Measure/Restrict.lean | 608 | 611 |
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.Unitization
import Mathlib.Algebra.Star.Subalgebra
import Mathlib.GroupTheory.GroupAction.Ring
/-!
# Relating unital and non-unital substructures
This file relates various algebraic structures and provides maps (generally algebra homomorphisms),
from the unitization of a non-unital subobject into the full structure. The range of this map is
the unital closure of the non-unital subobject (e.g., `Algebra.adjoin`, `Subring.closure`,
`Subsemiring.closure` or `StarAlgebra.adjoin`). When the underlying scalar ring is a field, for
this map to be injective it suffices that the range omits `1`. In this setting we provide suitable
`AlgEquiv` (or `StarAlgEquiv`) onto the range.
## Main declarations
* `NonUnitalSubalgebra.unitization s : Unitization R s →ₐ[R] A`:
where `s` is a non-unital subalgebra of a unital `R`-algebra `A`, this is the natural algebra
homomorphism sending `(r, a)` to `r • 1 + a`. The range of this map is
`Algebra.adjoin R (s : Set A)`.
* `NonUnitalSubalgebra.unitizationAlgEquiv s : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A)`
when `R` is a field and `1 ∉ s`. This is `NonUnitalSubalgebra.unitization` upgraded to an
`AlgEquiv` onto its range.
* `NonUnitalSubsemiring.unitization : Unitization ℕ s →ₐ[ℕ] R`: the natural `ℕ`-algebra homomorphism
from the unitization of a non-unital subsemiring `s` into the ring containing it. The range of
this map is `subalgebraOfSubsemiring (Subsemiring.closure s)`.
This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because
there is an instance Lean can't find on its own due to `outParam`.
* `NonUnitalSubring.unitization : Unitization ℤ s →ₐ[ℤ] R`:
the natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring `s` into the
ring containing it. The range of this map is `subalgebraOfSubring (Subring.closure s)`.
This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because
there is an instance Lean can't find on its own due to `outParam`.
* `NonUnitalStarSubalgebra s : Unitization R s →⋆ₐ[R] A`: a version of
`NonUnitalSubalgebra.unitization` for star algebras.
* `NonUnitalStarSubalgebra.unitizationStarAlgEquiv s :`
`Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A)`:
a version of `NonUnitalSubalgebra.unitizationAlgEquiv` for star algebras.
-/
/-! ## Subalgebras -/
namespace Unitization
variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A]
variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Semiring C] [Algebra R C]
theorem lift_range_le {f : A →ₙₐ[R] C} {S : Subalgebra R C} :
(lift f).range ≤ S ↔ NonUnitalAlgHom.range f ≤ S.toNonUnitalSubalgebra := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rintro - ⟨x, rfl⟩
exact @h (f x) ⟨x, by simp⟩
· rintro - ⟨x, rfl⟩
induction x with
| _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩)
theorem lift_range (f : A →ₙₐ[R] C) :
(lift f).range = Algebra.adjoin R (NonUnitalAlgHom.range f : Set C) :=
eq_of_forall_ge_iff fun c ↦ by rw [lift_range_le, Algebra.adjoin_le_iff]; rfl
end Unitization
namespace NonUnitalSubalgebra
section Semiring
variable {R S A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A]
[hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] (s : S)
/-- The natural `R`-algebra homomorphism from the unitization of a non-unital subalgebra into
the algebra containing it. -/
def unitization : Unitization R s →ₐ[R] A :=
Unitization.lift (NonUnitalSubalgebraClass.subtype s)
@[simp]
theorem unitization_apply (x : Unitization R s) :
unitization s x = algebraMap R A x.fst + x.snd :=
rfl
theorem unitization_range : (unitization s).range = Algebra.adjoin R (s : Set A) := by
rw [unitization, Unitization.lift_range]
simp only [NonUnitalAlgHom.coe_range, NonUnitalSubalgebraClass.coe_subtype,
Subtype.range_coe_subtype, SetLike.mem_coe]
rfl
end Semiring
/-- A sufficient condition for injectivity of `NonUnitalSubalgebra.unitization` when the scalars
are a commutative ring. When the scalars are a field, one should use the more natural
`NonUnitalStarSubalgebra.unitization_injective` whose hypothesis is easier to verify. -/
theorem _root_.AlgHomClass.unitization_injective' {F R S A : Type*} [CommRing R] [Ring A]
[Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
(s : S) (h : ∀ r, r ≠ 0 → algebraMap R A r ∉ s)
[FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A]
(f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by
refine (injective_iff_map_eq_zero f).mpr fun x hx => ?_
induction x with
| inl_add_inr r a =>
simp_rw [map_add, hf, ← Unitization.algebraMap_eq_inl, AlgHomClass.commutes] at hx
rw [add_eq_zero_iff_eq_neg] at hx ⊢
by_cases hr : r = 0
· ext
· simp [hr]
· simpa [hr] using hx
· exact (h r hr <| hx ▸ (neg_mem a.property)).elim
/-- This is a generic version which allows us to prove both
`NonUnitalSubalgebra.unitization_injective` and `NonUnitalStarSubalgebra.unitization_injective`. -/
theorem _root_.AlgHomClass.unitization_injective {F R S A : Type*} [Field R] [Ring A]
[Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
(s : S) (h1 : 1 ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A]
(f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by
refine AlgHomClass.unitization_injective' s (fun r hr hr' ↦ ?_) f hf
rw [Algebra.algebraMap_eq_smul_one] at hr'
exact h1 <| inv_smul_smul₀ hr (1 : A) ▸ SMulMemClass.smul_mem r⁻¹ hr'
section Field
variable {R S A : Type*} [Field R] [Ring A] [Algebra R A]
[SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S)
theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) :=
AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp
/-- If a `NonUnitalSubalgebra` over a field does not contain `1`, then its unitization is
isomorphic to its `Algebra.adjoin`. -/
@[simps! apply_coe]
noncomputable def unitizationAlgEquiv (h1 : (1 : A) ∉ s) :
Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A) :=
let algHom : Unitization R s →ₐ[R] Algebra.adjoin R (s : Set A) :=
((unitization s).codRestrict _
fun x ↦ (unitization_range s).le <| AlgHom.mem_range_self _ x)
AlgEquiv.ofBijective algHom <| by
refine ⟨?_, fun x ↦ ?_⟩
· have := AlgHomClass.unitization_injective s h1
((Subalgebra.val _).comp algHom) fun _ ↦ by simp [algHom]
rw [AlgHom.coe_comp] at this
exact this.of_comp
· obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) :=
(unitization_range s).ge x.property
exact ⟨a, Subtype.ext ha⟩
end Field
end NonUnitalSubalgebra
/-! ## Subsemirings -/
namespace NonUnitalSubsemiring
variable {R S : Type*} [Semiring R] [SetLike S R] [hSR : NonUnitalSubsemiringClass S R] (s : S)
/-- The natural `ℕ`-algebra homomorphism from the unitization of a non-unital subsemiring to
its `Subsemiring.closure`. -/
def unitization : Unitization ℕ s →ₐ[ℕ] R :=
NonUnitalSubalgebra.unitization (hSRA := AddSubmonoidClass.nsmulMemClass) s
@[simp]
theorem unitization_apply (x : Unitization ℕ s) : unitization s x = x.fst + x.snd :=
rfl
theorem unitization_range :
(unitization s).range = subalgebraOfSubsemiring (.closure s) := by
have := AddSubmonoidClass.nsmulMemClass (S := S)
rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_nat]
end NonUnitalSubsemiring
/-! ## Subrings -/
namespace NonUnitalSubring
variable {R S : Type*} [Ring R] [SetLike S R] [hSR : NonUnitalSubringClass S R] (s : S)
/-- The natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring to
its `Subring.closure`. -/
def unitization : Unitization ℤ s →ₐ[ℤ] R :=
NonUnitalSubalgebra.unitization (hSRA := AddSubgroupClass.zsmulMemClass) s
@[simp]
theorem unitization_apply (x : Unitization ℤ s) : unitization s x = x.fst + x.snd :=
rfl
theorem unitization_range :
(unitization s).range = subalgebraOfSubring (.closure s) := by
have := AddSubgroupClass.zsmulMemClass (S := S)
rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_int]
end NonUnitalSubring
/-! ## Star subalgebras -/
namespace Unitization
variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A] [StarRing R] [StarRing A]
variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [StarModule R A]
variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C]
theorem starLift_range_le
{f : A →⋆ₙₐ[R] C} {S : StarSubalgebra R C} :
(starLift f).range ≤ S ↔ NonUnitalStarAlgHom.range f ≤ S.toNonUnitalStarSubalgebra := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rintro - ⟨x, rfl⟩
exact @h (f x) ⟨x, by simp⟩
· rintro - ⟨x, rfl⟩
induction x with
| _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩)
theorem starLift_range (f : A →⋆ₙₐ[R] C) :
(starLift f).range = StarAlgebra.adjoin R (NonUnitalStarAlgHom.range f : Set C) :=
eq_of_forall_ge_iff fun c ↦ by
rw [starLift_range_le, StarAlgebra.adjoin_le_iff]
rfl
end Unitization
namespace NonUnitalStarSubalgebra
section Semiring
variable {R S A : Type*} [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A]
[StarModule R A] [SetLike S A] [hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A]
[StarMemClass S A] (s : S)
/-- The natural star `R`-algebra homomorphism from the unitization of a non-unital star subalgebra
to its `StarAlgebra.adjoin`. -/
def unitization : Unitization R s →⋆ₐ[R] A :=
Unitization.starLift <| NonUnitalStarSubalgebraClass.subtype s
@[simp]
theorem unitization_apply (x : Unitization R s) : unitization s x = algebraMap R A x.fst + x.snd :=
rfl
theorem unitization_range : (unitization s).range = StarAlgebra.adjoin R s := by
rw [unitization, Unitization.starLift_range]
simp only [NonUnitalStarAlgHom.coe_range, NonUnitalStarSubalgebraClass.coe_subtype,
Subtype.range_coe_subtype]
rfl
end Semiring
section Field
variable {R S A : Type*} [Field R] [StarRing R] [Ring A] [StarRing A] [Algebra R A]
[StarModule R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A]
[StarMemClass S A] (s : S)
theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) :=
AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp
/-- If a `NonUnitalStarSubalgebra` over a field does not contain `1`, then its unitization is
isomorphic to its `StarAlgebra.adjoin`. -/
@[simps! apply_coe]
noncomputable def unitizationStarAlgEquiv (h1 : (1 : A) ∉ s) :
Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A) :=
let starAlgHom : Unitization R s →⋆ₐ[R] StarAlgebra.adjoin R (s : Set A) :=
((unitization s).codRestrict _
fun x ↦ (unitization_range s).le <| Set.mem_range_self x)
StarAlgEquiv.ofBijective starAlgHom <| by
refine ⟨?_, fun x ↦ ?_⟩
· have := AlgHomClass.unitization_injective s h1 ((StarSubalgebra.subtype _).comp starAlgHom)
fun _ ↦ by simp [starAlgHom]
rw [StarAlgHom.coe_comp] at this
exact this.of_comp
· obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) :=
(unitization_range s).ge x.property
exact ⟨a, Subtype.ext ha⟩
end Field
end NonUnitalStarSubalgebra
| Mathlib/Algebra/Algebra/Subalgebra/Unitization.lean | 390 | 394 | |
/-
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.LinearAlgebra.QuadraticForm.IsometryEquiv
/-! # Quadratic form on product and pi types
## Main definitions
* `QuadraticForm.prod Q₁ Q₂`: the quadratic form constructed elementwise on a product
* `QuadraticForm.pi Q`: the quadratic form constructed elementwise on a pi type
## Main results
* `QuadraticForm.Equivalent.prod`, `QuadraticForm.Equivalent.pi`: quadratic forms are equivalent
if their components are equivalent
* `QuadraticForm.nonneg_prod_iff`, `QuadraticForm.nonneg_pi_iff`: quadratic forms are positive-
semidefinite if and only if their components are positive-semidefinite.
* `QuadraticForm.posDef_prod_iff`, `QuadraticForm.posDef_pi_iff`: quadratic forms are positive-
definite if and only if their components are positive-definite.
## Implementation notes
Many of the lemmas in this file could be generalized into results about sums of positive and
non-negative elements, and would generalize to any map `Q` where `Q 0 = 0`, not just quadratic
forms specifically.
-/
universe u v w
variable {ι : Type*} {R : Type*} {M₁ M₂ N₁ N₂ P : Type*} {Mᵢ Nᵢ : ι → Type*}
namespace QuadraticMap
section Prod
section Semiring
variable [CommSemiring R]
variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid N₁] [AddCommMonoid N₂]
variable [AddCommMonoid P]
variable [Module R M₁] [Module R M₂] [Module R N₁] [Module R N₂] [Module R P]
/-- Construct a quadratic form on a product of two modules from the quadratic form on each module.
-/
@[simps!]
def prod (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) : QuadraticMap R (M₁ × M₂) P :=
Q₁.comp (LinearMap.fst _ _ _) + Q₂.comp (LinearMap.snd _ _ _)
/-- An isometry between quadratic forms generated by `QuadraticForm.prod` can be constructed
from a pair of isometries between the left and right parts. -/
@[simps toLinearEquiv]
def IsometryEquiv.prod
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
{Q₁' : QuadraticMap R N₁ P} {Q₂' : QuadraticMap R N₂ P}
(e₁ : Q₁.IsometryEquiv Q₁') (e₂ : Q₂.IsometryEquiv Q₂') :
(Q₁.prod Q₂).IsometryEquiv (Q₁'.prod Q₂') where
map_app' x := congr_arg₂ (· + ·) (e₁.map_app x.1) (e₂.map_app x.2)
toLinearEquiv := LinearEquiv.prodCongr e₁.toLinearEquiv e₂.toLinearEquiv
/-- `LinearMap.inl` as an isometry. -/
@[simps!]
def Isometry.inl (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) : Q₁ →qᵢ (Q₁.prod Q₂) where
toLinearMap := LinearMap.inl R _ _
map_app' m₁ := by simp
/-- `LinearMap.inr` as an isometry. -/
@[simps!]
def Isometry.inr (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) : Q₂ →qᵢ (Q₁.prod Q₂) where
toLinearMap := LinearMap.inr R _ _
map_app' m₁ := by simp
variable (M₂) in
/-- `LinearMap.fst` as an isometry, when the second space has the zero quadratic form. -/
@[simps!]
def Isometry.fst (Q₁ : QuadraticMap R M₁ P) : (Q₁.prod (0 : QuadraticMap R M₂ P)) →qᵢ Q₁ where
toLinearMap := LinearMap.fst R _ _
map_app' m₁ := by simp
variable (M₁) in
/-- `LinearMap.snd` as an isometry, when the first space has the zero quadratic form. -/
@[simps!]
def Isometry.snd (Q₂ : QuadraticMap R M₂ P) : ((0 : QuadraticMap R M₁ P).prod Q₂) →qᵢ Q₂ where
toLinearMap := LinearMap.snd R _ _
map_app' m₁ := by simp
@[simp]
lemma Isometry.fst_comp_inl (Q₁ : QuadraticMap R M₁ P) :
(fst M₂ Q₁).comp (inl Q₁ (0 : QuadraticMap R M₂ P)) = .id _ :=
ext fun _ => rfl
@[simp]
lemma Isometry.snd_comp_inr (Q₂ : QuadraticMap R M₂ P) :
(snd M₁ Q₂).comp (inr (0 : QuadraticMap R M₁ P) Q₂) = .id _ :=
ext fun _ => rfl
@[simp]
lemma Isometry.snd_comp_inl (Q₂ : QuadraticMap R M₂ P) :
(snd M₁ Q₂).comp (inl (0 : QuadraticMap R M₁ P) Q₂) = 0 :=
ext fun _ => rfl
@[simp]
lemma Isometry.fst_comp_inr (Q₁ : QuadraticMap R M₁ P) :
(fst M₂ Q₁).comp (inr Q₁ (0 : QuadraticMap R M₂ P)) = 0 :=
ext fun _ => rfl
theorem Equivalent.prod {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
{Q₁' : QuadraticMap R N₁ P} {Q₂' : QuadraticMap R N₂ P} (e₁ : Q₁.Equivalent Q₁')
(e₂ : Q₂.Equivalent Q₂') : (Q₁.prod Q₂).Equivalent (Q₁'.prod Q₂') :=
Nonempty.map2 IsometryEquiv.prod e₁ e₂
/-- `LinearEquiv.prodComm` is isometric. -/
@[simps!]
def IsometryEquiv.prodComm (Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P) :
(Q₁.prod Q₂).IsometryEquiv (Q₂.prod Q₁) where
toLinearEquiv := LinearEquiv.prodComm _ _ _
map_app' _ := add_comm _ _
/-- `LinearEquiv.prodProdProdComm` is isometric. -/
@[simps!]
def IsometryEquiv.prodProdProdComm
(Q₁ : QuadraticMap R M₁ P) (Q₂ : QuadraticMap R M₂ P)
(Q₃ : QuadraticMap R N₁ P) (Q₄ : QuadraticMap R N₂ P) :
((Q₁.prod Q₂).prod (Q₃.prod Q₄)).IsometryEquiv ((Q₁.prod Q₃).prod (Q₂.prod Q₄)) where
toLinearEquiv := LinearEquiv.prodProdProdComm _ _ _ _ _
map_app' _ := add_add_add_comm _ _ _ _
/-- If a product is anisotropic then its components must be. The converse is not true. -/
theorem anisotropic_of_prod
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} (h : (Q₁.prod Q₂).Anisotropic) :
Q₁.Anisotropic ∧ Q₂.Anisotropic := by
simp_rw [Anisotropic, prod_apply, Prod.forall, Prod.mk_eq_zero] at h
constructor
· intro x hx
refine (h x 0 ?_).1
rw [hx, zero_add, map_zero]
· intro x hx
refine (h 0 x ?_).2
rw [hx, add_zero, map_zero]
theorem nonneg_prod_iff [Preorder P] [AddLeftMono P]
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} :
(∀ x, 0 ≤ (Q₁.prod Q₂) x) ↔ (∀ x, 0 ≤ Q₁ x) ∧ ∀ x, 0 ≤ Q₂ x := by
simp_rw [Prod.forall, prod_apply]
constructor
· intro h
constructor
· intro x; simpa only [add_zero, map_zero] using h x 0
· intro x; simpa only [zero_add, map_zero] using h 0 x
· rintro ⟨h₁, h₂⟩ x₁ x₂
exact add_nonneg (h₁ x₁) (h₂ x₂)
theorem posDef_prod_iff [PartialOrder P] [AddLeftMono P]
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} :
(Q₁.prod Q₂).PosDef ↔ Q₁.PosDef ∧ Q₂.PosDef := by
simp_rw [posDef_iff_nonneg, nonneg_prod_iff]
constructor
· rintro ⟨⟨hle₁, hle₂⟩, ha⟩
obtain ⟨ha₁, ha₂⟩ := anisotropic_of_prod ha
exact ⟨⟨hle₁, ha₁⟩, ⟨hle₂, ha₂⟩⟩
· rintro ⟨⟨hle₁, ha₁⟩, ⟨hle₂, ha₂⟩⟩
refine ⟨⟨hle₁, hle₂⟩, ?_⟩
rintro ⟨x₁, x₂⟩ (hx : Q₁ x₁ + Q₂ x₂ = 0)
rw [add_eq_zero_iff_of_nonneg (hle₁ x₁) (hle₂ x₂), ha₁.eq_zero_iff, ha₂.eq_zero_iff] at hx
rwa [Prod.mk_eq_zero]
theorem PosDef.prod [PartialOrder P] [AddLeftMono P]
{Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P} (h₁ : Q₁.PosDef) (h₂ : Q₂.PosDef) :
(Q₁.prod Q₂).PosDef :=
posDef_prod_iff.mpr ⟨h₁, h₂⟩
theorem IsOrtho.prod {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
{v w : M₁ × M₂} (h₁ : Q₁.IsOrtho v.1 w.1) (h₂ : Q₂.IsOrtho v.2 w.2) :
(Q₁.prod Q₂).IsOrtho v w :=
(congr_arg₂ HAdd.hAdd h₁ h₂).trans <| add_add_add_comm _ _ _ _
@[simp] theorem IsOrtho.inl_inr {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₁ : M₁) (m₂ : M₂) :
(Q₁.prod Q₂).IsOrtho (m₁, 0) (0, m₂) :=
QuadraticMap.IsOrtho.prod (.zero_right _) (.zero_left _)
@[simp] theorem IsOrtho.inr_inl {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₁ : M₁) (m₂ : M₂) :
(Q₁.prod Q₂).IsOrtho (0, m₂) (m₁, 0) := (IsOrtho.inl_inr _ _).symm
@[simp] theorem isOrtho_inl_inl_iff {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₁ m₁' : M₁) :
(Q₁.prod Q₂).IsOrtho (m₁, 0) (m₁', 0) ↔ Q₁.IsOrtho m₁ m₁' := by
simp [isOrtho_def]
@[simp] theorem isOrtho_inr_inr_iff {Q₁ : QuadraticMap R M₁ P} {Q₂ : QuadraticMap R M₂ P}
(m₂ m₂' : M₂) :
| (Q₁.prod Q₂).IsOrtho (0, m₂) (0, m₂') ↔ Q₂.IsOrtho m₂ m₂' := by
simp [isOrtho_def]
end Semiring
| Mathlib/LinearAlgebra/QuadraticForm/Prod.lean | 197 | 200 |
/-
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.Finset.Card
import Mathlib.Data.Finset.Lattice.Union
import Mathlib.Data.Multiset.Powerset
import Mathlib.Data.Set.Pairwise.Lattice
/-!
# The powerset of a finset
-/
namespace Finset
open Function Multiset
variable {α : Type*} {s t : Finset α}
/-! ### powerset -/
section Powerset
/-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/
def powerset (s : Finset α) : Finset (Finset α) :=
⟨(s.1.powerset.pmap Finset.mk) fun _t h => nodup_of_le (mem_powerset.1 h) s.nodup,
s.nodup.powerset.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩
@[simp]
theorem mem_powerset {s t : Finset α} : s ∈ powerset t ↔ s ⊆ t := by
cases s
simp [powerset, mem_mk, mem_pmap, mk.injEq, mem_powerset, exists_prop, exists_eq_right,
← val_le_iff]
@[simp, norm_cast]
theorem coe_powerset (s : Finset α) :
(s.powerset : Set (Finset α)) = ((↑) : Finset α → Set α) ⁻¹' (s : Set α).powerset := by
ext
simp
theorem empty_mem_powerset (s : Finset α) : ∅ ∈ powerset s := by simp
theorem mem_powerset_self (s : Finset α) : s ∈ powerset s := by simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem powerset_nonempty (s : Finset α) : s.powerset.Nonempty :=
⟨∅, empty_mem_powerset _⟩
@[simp]
theorem powerset_mono {s t : Finset α} : powerset s ⊆ powerset t ↔ s ⊆ t :=
⟨fun h => mem_powerset.1 <| h <| mem_powerset_self _, fun st _u h =>
mem_powerset.2 <| Subset.trans (mem_powerset.1 h) st⟩
theorem powerset_injective : Injective (powerset : Finset α → Finset (Finset α)) :=
(injective_of_le_imp_le _) powerset_mono.1
@[simp]
theorem powerset_inj : powerset s = powerset t ↔ s = t :=
powerset_injective.eq_iff
@[simp]
theorem powerset_empty : (∅ : Finset α).powerset = {∅} :=
rfl
@[simp]
theorem powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ := by
rw [← powerset_empty, powerset_inj]
/-- **Number of Subsets of a Set** -/
@[simp]
theorem card_powerset (s : Finset α) : card (powerset s) = 2 ^ card s :=
(card_pmap _ _ _).trans (Multiset.card_powerset s.1)
theorem not_mem_of_mem_powerset_of_not_mem {s t : Finset α} {a : α} (ht : t ∈ s.powerset)
(h : a ∉ s) : a ∉ t := by
apply mt _ h
apply mem_powerset.1 ht
theorem powerset_insert [DecidableEq α] (s : Finset α) (a : α) :
powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) := by
ext t
simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff]
by_cases h : a ∈ t
· constructor
· exact fun H => Or.inr ⟨_, H, insert_erase h⟩
· intro H
rcases H with H | H
· exact Subset.trans (erase_subset a t) H
· rcases H with ⟨u, hu⟩
rw [← hu.2]
exact Subset.trans (erase_insert_subset a u) hu.1
· have : ¬∃ u : Finset α, u ⊆ s ∧ insert a u = t := by simp [Ne.symm (ne_insert_of_not_mem _ _ h)]
simp [Finset.erase_eq_of_not_mem h, this]
lemma pairwiseDisjoint_pair_insert [DecidableEq α] {a : α} (ha : a ∉ s) :
(s.powerset : Set (Finset α)).PairwiseDisjoint fun t ↦ ({t, insert a t} : Set (Finset α)) := by
simp_rw [Set.pairwiseDisjoint_iff, mem_coe, mem_powerset]
rintro i hi j hj
simp only [Set.Nonempty, Set.mem_inter_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
exists_eq_or_imp, exists_eq_left, or_imp, imp_self, true_and]
refine ⟨?_, ?_, insert_erase_invOn.2.injOn (not_mem_mono hi ha) (not_mem_mono hj ha)⟩ <;>
rintro rfl <;>
cases Finset.not_mem_mono ‹_› ha (Finset.mem_insert_self _ _)
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidableExistsOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop}
[∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∃ (t : _) (h : t ⊆ s), p t h) :=
decidable_of_iff (∃ (t : _) (hs : t ∈ s.powerset), p t (mem_powerset.1 hs))
⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_powerset.2 hs, hp⟩⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidableForallOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop}
[∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∀ (t) (h : t ⊆ s), p t h) :=
decidable_of_iff (∀ (t) (h : t ∈ s.powerset), p t (mem_powerset.1 h))
⟨fun h t hs => h t (mem_powerset.2 hs), fun h _ _ => h _ _⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidableExistsOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop}
[∀ t, Decidable (p t)] : Decidable (∃ t ⊆ s, p t) :=
decidable_of_iff (∃ (t : _) (_h : t ⊆ s), p t) <| by simp
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidableForallOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop}
[∀ t, Decidable (p t)] : Decidable (∀ t ⊆ s, p t) :=
decidable_of_iff (∀ (t : _) (_h : t ⊆ s), p t) <| by simp
end Powerset
section SSubsets
variable [DecidableEq α]
/-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/
def ssubsets (s : Finset α) : Finset (Finset α) :=
erase (powerset s) s
@[simp]
theorem mem_ssubsets {s t : Finset α} : t ∈ s.ssubsets ↔ t ⊂ s := by
rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and_comm]
theorem empty_mem_ssubsets {s : Finset α} (h : s.Nonempty) : ∅ ∈ s.ssubsets := by
rw [mem_ssubsets, ssubset_iff_subset_ne]
exact ⟨empty_subset s, h.ne_empty.symm⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/
def decidableExistsOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop}
[∀ t h, Decidable (p t h)] : Decidable (∃ t h, p t h) :=
decidable_of_iff (∃ (t : _) (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs))
⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_ssubsets.2 hs, hp⟩⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/
def decidableForallOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop}
[∀ t h, Decidable (p t h)] : Decidable (∀ t h, p t h) :=
decidable_of_iff (∀ (t) (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h))
⟨fun h t hs => h t (mem_ssubsets.2 hs), fun h _ _ => h _ _⟩
/-- A version of `Finset.decidableExistsOfDecidableSSubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidableExistsOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop}
(hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∃ (t : _) (_h : t ⊂ s), p t) :=
@Finset.decidableExistsOfDecidableSSubsets _ _ _ _ hu
/-- A version of `Finset.decidableForallOfDecidableSSubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidableForallOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop}
(hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∀ t ⊂ s, p t) :=
@Finset.decidableForallOfDecidableSSubsets _ _ _ _ hu
end SSubsets
section powersetCard
variable {n} {s t : Finset α}
/-- Given an integer `n` and a finset `s`, then `powersetCard n s` is the finset of subsets of `s`
of cardinality `n`. -/
def powersetCard (n : ℕ) (s : Finset α) : Finset (Finset α) :=
⟨((s.1.powersetCard n).pmap Finset.mk) fun _t h => nodup_of_le (mem_powersetCard.1 h).1 s.2,
s.2.powersetCard.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩
@[simp] lemma mem_powersetCard : s ∈ powersetCard n t ↔ s ⊆ t ∧ card s = n := by
cases s; simp [powersetCard, val_le_iff.symm]
@[simp]
theorem powersetCard_mono {n} {s t : Finset α} (h : s ⊆ t) : powersetCard n s ⊆ powersetCard n t :=
fun _u h' => mem_powersetCard.2 <|
And.imp (fun h₂ => Subset.trans h₂ h) id (mem_powersetCard.1 h')
/-- **Formula for the Number of Combinations** -/
@[simp]
theorem card_powersetCard (n : ℕ) (s : Finset α) :
card (powersetCard n s) = Nat.choose (card s) n :=
(card_pmap _ _ _).trans (Multiset.card_powersetCard n s.1)
@[simp]
theorem powersetCard_zero (s : Finset α) : s.powersetCard 0 = {∅} := by
ext; rw [mem_powersetCard, mem_singleton, card_eq_zero]
refine
⟨fun h => h.2, fun h => by
rw [h]
exact ⟨empty_subset s, rfl⟩⟩
lemma powersetCard_empty_subsingleton (n : ℕ) :
(powersetCard n (∅ : Finset α) : Set <| Finset α).Subsingleton := by
simp [Set.Subsingleton, subset_empty]
@[simp]
theorem map_val_val_powersetCard (s : Finset α) (i : ℕ) :
(s.powersetCard i).val.map Finset.val = s.1.powersetCard i := by
simp [Finset.powersetCard, map_pmap, pmap_eq_map, map_id']
theorem powersetCard_one (s : Finset α) :
s.powersetCard 1 = s.map ⟨_, Finset.singleton_injective⟩ :=
eq_of_veq <| Multiset.map_injective val_injective <| by simp [Multiset.powersetCard_one]
@[simp]
lemma powersetCard_eq_empty : powersetCard n s = ∅ ↔ s.card < n := by
refine ⟨?_, fun h ↦ card_eq_zero.1 <| by rw [card_powersetCard, Nat.choose_eq_zero_of_lt h]⟩
contrapose!
exact fun h ↦ nonempty_iff_ne_empty.1 <| (exists_subset_card_eq h).imp <| by simp
@[simp] lemma powersetCard_card_add (s : Finset α) (hn : 0 < n) :
s.powersetCard (s.card + n) = ∅ := by simpa
theorem powersetCard_eq_filter {n} {s : Finset α} :
powersetCard n s = (powerset s).filter fun x => x.card = n := by
| ext
simp [mem_powersetCard]
| Mathlib/Data/Finset/Powerset.lean | 229 | 231 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine
import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle
/-!
# Oriented angles in right-angled triangles.
This file proves basic geometrical results about distances and oriented angles in (possibly
degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces.
-/
noncomputable section
open scoped EuclideanGeometry
open scoped Real
open scoped RealInnerProductSpace
namespace Orientation
open Module
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side. -/
theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse. -/
theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse. -/
theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side. -/
theorem norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle x (x + y)) = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side. -/
theorem norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle (x + y) y) = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arccos (‖y‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arccos (‖x‖ / ‖x - y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arcsin (‖x‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arcsin_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arcsin (‖y‖ / ‖x - y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arcsin_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/
theorem oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle y (y - x) = Real.arctan (‖x‖ / ‖y‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_sub_eq_arctan_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h) (o.right_ne_zero_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/
theorem oangle_sub_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x - y) x = Real.arctan (‖y‖ / ‖x‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).oangle_sub_right_eq_arctan_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle y (y - x)) = ‖y‖ / ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x - y) x) = ‖x‖ / ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).cos_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle y (y - x)) = ‖x‖ / ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The sine of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x - y) x) = ‖y‖ / ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).sin_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle y (y - x)) = ‖x‖ / ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The tangent of an angle in a right-angled triangle as a ratio of sides, version subtracting
vectors. -/
theorem tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x - y) x) = ‖y‖ / ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).tan_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side, version subtracting vectors. -/
theorem cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle y (y - x)) * ‖y - x‖ = ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side, version subtracting vectors. -/
theorem cos_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x - y) x) * ‖x - y‖ = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).cos_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side, version subtracting vectors. -/
theorem sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle y (y - x)) * ‖y - x‖ = ‖x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side, version subtracting vectors. -/
theorem sin_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x - y) x) * ‖x - y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).sin_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side, version subtracting vectors. -/
theorem tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle y (y - x)) * ‖y‖ = ‖x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_sub_mul_norm_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals
the opposite side, version subtracting vectors. -/
theorem tan_oangle_sub_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x - y) x) * ‖x‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).tan_oangle_sub_right_mul_norm_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle y (y - x)) = ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.norm_div_cos_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.right_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_cos_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle (x - y) x) = ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_cos_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle y (y - x)) = ‖y - x‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.norm_div_sin_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the sine of the opposite angle equals the
hypotenuse, version subtracting vectors. -/
theorem norm_div_sin_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle (x - y) x) = ‖x - y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_sin_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side, version subtracting vectors. -/
theorem norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle y (y - x)) = ‖y‖ := by
have hs : (o.oangle y (y - x)).sign = 1 := by
rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.norm_div_tan_angle_sub_of_inner_eq_zero
(o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inr (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
/-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the
adjacent side, version subtracting vectors. -/
theorem norm_div_tan_oangle_sub_left_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle (x - y) x) = ‖x‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
exact (-o).norm_div_tan_oangle_sub_right_of_oangle_eq_pi_div_two h
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`. -/
theorem oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle x (x + r • o.rotation (π / 2 : ℝ) x) = Real.arctan r := by
rcases lt_trichotomy r 0 with (hr | rfl | hr)
· have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = -(π / 2 : ℝ) := by
rw [o.oangle_smul_right_of_neg _ _ hr, o.oangle_neg_right h, o.oangle_rotation_self_right h, ←
sub_eq_zero, add_comm, sub_neg_eq_add, ← Real.Angle.coe_add, ← Real.Angle.coe_add,
add_assoc, add_halves, ← two_mul, Real.Angle.coe_two_pi]
simpa using h
-- Porting note: if the type is not given in `neg_neg` then Lean "forgets" about the instance
-- `Neg (Orientation ℝ V (Fin 2))`
rw [← neg_inj, ← oangle_neg_orientation_eq_neg, @neg_neg Real.Angle] at ha
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, oangle_rev,
(-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul,
LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one,
Real.norm_eq_abs, abs_of_neg hr, Real.arctan_neg, Real.Angle.coe_neg, neg_neg]
· rw [zero_smul, add_zero, oangle_self, Real.arctan_zero, Real.Angle.coe_zero]
· have ha : o.oangle x (r • o.rotation (π / 2 : ℝ) x) = (π / 2 : ℝ) := by
rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right h]
rw [o.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two ha, norm_smul,
LinearIsometryEquiv.norm_map, mul_div_assoc, div_self (norm_ne_zero_iff.2 h), mul_one,
Real.norm_eq_abs, abs_of_pos hr]
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`. -/
theorem oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)
= Real.arctan r⁻¹ := by
by_cases hr : r = 0; · simp [hr]
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj, ←
neg_neg ((π / 2 : ℝ) : Real.Angle), ← rotation_neg_orientation_eq_neg, add_comm]
have hx : x = r⁻¹ • (-o).rotation (π / 2 : ℝ) (r • (-o).rotation (-(π / 2 : ℝ)) x) := by simp [hr]
nth_rw 3 [hx]
refine (-o).oangle_add_right_smul_rotation_pi_div_two ?_ _
simp [hr, h]
/-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a
rotation of another by `π / 2`. -/
theorem tan_oangle_add_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
Real.Angle.tan (o.oangle x (x + r • o.rotation (π / 2 : ℝ) x)) = r := by
rw [o.oangle_add_right_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan]
/-- The tangent of an angle in a right-angled triangle, where one side is a multiple of a
rotation of another by `π / 2`. -/
theorem tan_oangle_add_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
Real.Angle.tan (o.oangle (x + r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x)) =
r⁻¹ := by
rw [o.oangle_add_left_smul_rotation_pi_div_two h, Real.Angle.tan_coe, Real.tan_arctan]
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`, version subtracting vectors. -/
theorem oangle_sub_right_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (r • o.rotation (π / 2 : ℝ) x) (r • o.rotation (π / 2 : ℝ) x - x)
= Real.arctan r⁻¹ := by
by_cases hr : r = 0; · simp [hr]
have hx : -x = r⁻¹ • o.rotation (π / 2 : ℝ) (r • o.rotation (π / 2 : ℝ) x) := by
simp [hr, ← Real.Angle.coe_add]
rw [sub_eq_add_neg, hx, o.oangle_add_right_smul_rotation_pi_div_two]
simpa [hr] using h
/-- An angle in a right-angled triangle expressed using `arctan`, where one side is a multiple
of a rotation of another by `π / 2`, version subtracting vectors. -/
theorem oangle_sub_left_smul_rotation_pi_div_two {x : V} (h : x ≠ 0) (r : ℝ) :
o.oangle (x - r • o.rotation (π / 2 : ℝ) x) x = Real.arctan r := by
by_cases hr : r = 0; · simp [hr]
have hx : x = r⁻¹ • o.rotation (π / 2 : ℝ) (-(r • o.rotation (π / 2 : ℝ) x)) := by
simp [hr, ← Real.Angle.coe_add]
rw [sub_eq_add_neg, add_comm]
nth_rw 3 [hx]
nth_rw 2 [hx]
rw [o.oangle_add_left_smul_rotation_pi_div_two, inv_inv]
simpa [hr] using h
end Orientation
namespace EuclideanGeometry
open Module
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_right_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₂ p₃ p₁ = Real.arccos (dist p₃ p₂ / dist p₁ p₃) := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs,
angle_eq_arccos_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)]
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_left_eq_arccos_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₃ p₁ p₂ = Real.arccos (dist p₁ p₂ / dist p₁ p₃) := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm,
angle_eq_arccos_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h),
dist_comm p₁ p₃]
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_right_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₂ p₃ p₁ = Real.arcsin (dist p₁ p₂ / dist p₁ p₃) := by
have hs : (∡ p₂ p₃ p₁).sign = 1 := by rw [oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs,
angle_eq_arcsin_of_angle_eq_pi_div_two (angle_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inl (left_ne_of_oangle_eq_pi_div_two h))]
| /-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_left_eq_arcsin_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∡ p₃ p₁ p₂ = Real.arcsin (dist p₃ p₂ / dist p₁ p₃) := by
have hs : (∡ p₃ p₁ p₂).sign = 1 := by rw [← oangle_rotate_sign, h, Real.Angle.sign_coe_pi_div_two]
rw [oangle_eq_angle_of_sign_eq_one hs, angle_comm,
angle_eq_arcsin_of_angle_eq_pi_div_two (angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two h)
(Or.inr (left_ne_of_oangle_eq_pi_div_two h)),
dist_comm p₁ p₃]
| Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean | 550 | 557 |
/-
Copyright (c) 2024 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Heather Macbeth
-/
import Mathlib.Analysis.Calculus.Deriv.Pi
import Mathlib.Analysis.InnerProductSpace.EuclideanDist
import Mathlib.Analysis.InnerProductSpace.NormPow
import Mathlib.Data.Finset.Interval
import Mathlib.MeasureTheory.Integral.IntegralEqImproper
/-!
# Gagliardo-Nirenberg-Sobolev inequality
In this file we prove the Gagliardo-Nirenberg-Sobolev inequality.
This states that for compactly supported `C¹`-functions between finite dimensional vector spaces,
we can bound the `L^p`-norm of `u` by the `L^q` norm of the derivative of `u`.
The bound is up to a constant that is independent of the function `u`.
Let `n` be the dimension of the domain.
The main step in the proof, which we dubbed the "grid-lines lemma" below, is a complicated
inductive argument that involves manipulating an `n+1`-fold iterated integral and a product of
`n+2` factors. In each step, one pushes one of the integral inside (all but one of)
the factors of the product using Hölder's inequality. The precise formulation of the induction
hypothesis (`MeasureTheory.GridLines.T_insert_le_T_lmarginal_singleton`) is tricky,
and none of the 5 sources we referenced stated it.
In the formalization we use the operation `MeasureTheory.lmarginal` to work with the iterated
integrals, and use `MeasureTheory.lmarginal_insert'` to conveniently push one of the integrals
inside. The Hölder's inequality step is done using `ENNReal.lintegral_mul_prod_norm_pow_le`.
The conclusions of the main results below are an estimation up to a constant multiple.
We don't really care about this constant, other than that it only depends on some pieces of data,
typically `E`, `μ`, `p` and sometimes also the codomain of `u` or the support of `u`.
We state these constants as separate definitions.
## Main results
* `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_of_eq`:
The bound holds for `1 ≤ p`, `0 < n` and `q⁻¹ = p⁻¹ - n⁻¹`
* `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_of_le`:
The bound holds when `1 ≤ p < n`, `0 ≤ q` and `p⁻¹ - n⁻¹ ≤ q⁻¹`.
Note that in this case the constant depends on the support of `u`.
Potentially also useful:
* `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_one`: this is the inequality for `q = 1`.
In this version, the codomain can be an arbitrary Banach space.
* `MeasureTheory.eLpNorm_le_eLpNorm_fderiv_of_eq_inner`: in this version,
the codomain is assumed to be a Hilbert space, without restrictions on its dimension.
-/
open scoped ENNReal NNReal
open Set Function Finset MeasureTheory Measure Filter
noncomputable section
variable {ι : Type*}
local prefix:max "#" => Fintype.card
/-! ## The grid-lines lemma -/
variable {A : ι → Type*} [∀ i, MeasurableSpace (A i)]
(μ : ∀ i, Measure (A i))
namespace MeasureTheory
section DecidableEq
variable [DecidableEq ι]
namespace GridLines
/-- The "grid-lines operation" (not a standard name) which is central in the inductive proof of the
Sobolev inequality.
For a finite dependent product `Π i : ι, A i` of sigma-finite measure spaces, a finite set `s` of
indices from `ι`, and a (later assumed nonnegative) real number `p`, this operation acts on a
function `f` from `Π i, A i` into the extended nonnegative reals. The operation is to partially
integrate, in the `s` co-ordinates, the function whose value at `x : Π i, A i` is obtained by
multiplying a certain power of `f` with the product, for each co-ordinate `i` in `s`, of a certain
power of the integral of `f` along the "grid line" in the `i` direction through `x`.
We are most interested in this operation when the set `s` is the universe in `ι`, but as a proxy for
"induction on dimension" we define it for a general set `s` of co-ordinates: the `s`-grid-lines
operation on a function `f` which is constant along the co-ordinates in `sᶜ` is morally (that is, up
to type-theoretic nonsense) the same thing as the universe-grid-lines operation on the associated
function on the "lower-dimensional" space `Π i : s, A i`. -/
def T (p : ℝ) (f : (∀ i, A i) → ℝ≥0∞) (s : Finset ι) : (∀ i, A i) → ℝ≥0∞ :=
∫⋯∫⁻_s, f ^ (1 - (s.card - 1 : ℝ) * p) * ∏ i ∈ s, (∫⋯∫⁻_{i}, f ∂μ) ^ p ∂μ
variable {p : ℝ}
@[simp] lemma T_univ [Fintype ι] [∀ i, SigmaFinite (μ i)] (f : (∀ i, A i) → ℝ≥0∞) (x : ∀ i, A i) :
T μ p f univ x =
∫⁻ (x : ∀ i, A i), (f x ^ (1 - (#ι - 1 : ℝ) * p)
* ∏ i : ι, (∫⁻ t : A i, f (update x i t) ∂(μ i)) ^ p) ∂(.pi μ) := by
simp [T, lmarginal_singleton]
@[simp] lemma T_empty (f : (∀ i, A i) → ℝ≥0∞) (x : ∀ i, A i) :
T μ p f ∅ x = f x ^ (1 + p) := by
simp [T]
/-- The main inductive step in the grid-lines lemma for the Gagliardo-Nirenberg-Sobolev inequality.
The grid-lines operation `GridLines.T` on a nonnegative function on a finitary product type is
less than or equal to the grid-lines operation of its partial integral in one co-ordinate
(the latter intuitively considered as a function on a space "one dimension down"). -/
theorem T_insert_le_T_lmarginal_singleton [∀ i, SigmaFinite (μ i)] (hp₀ : 0 ≤ p) (s : Finset ι)
(hp : (s.card : ℝ) * p ≤ 1)
(i : ι) (hi : i ∉ s) {f : (∀ i, A i) → ℝ≥0∞} (hf : Measurable f) :
T μ p f (insert i s) ≤ T μ p (∫⋯∫⁻_{i}, f ∂μ) s := by
/- The proof is a tricky computation that relies on Hölder's inequality at its heart.
The left-hand-side is an `|s|+1`-times iterated integral. Let `xᵢ` denote the `i`-th variable.
We first push the integral over the `i`-th variable as the
innermost integral. This is done in a single step with `MeasureTheory.lmarginal_insert'`,
but in fact hides a repeated application of Fubini's theorem.
The integrand is a product of `|s|+2` factors, in `|s|+1` of them we integrate over one
additional variable. We split of the factor that integrates over `xᵢ`,
and apply Hölder's inequality to the remaining factors (whose powers sum exactly to 1).
After reordering factors, and combining two factors into one we obtain the right-hand side. -/
calc T μ p f (insert i s)
= ∫⋯∫⁻_insert i s,
f ^ (1 - (s.card : ℝ) * p) * ∏ j ∈ insert i s, (∫⋯∫⁻_{j}, f ∂μ) ^ p ∂μ := by
-- unfold `T` and reformulate the exponents
simp_rw [T, card_insert_of_not_mem hi]
congr!
push_cast
ring
_ = ∫⋯∫⁻_s, (fun x ↦ ∫⁻ (t : A i),
(f (update x i t) ^ (1 - (s.card : ℝ) * p)
* ∏ j ∈ insert i s, (∫⋯∫⁻_{j}, f ∂μ) (update x i t) ^ p) ∂ (μ i)) ∂μ := by
-- pull out the integral over `xᵢ`
rw [lmarginal_insert' _ _ hi]
· congr! with x t
simp only [Pi.mul_apply, Pi.pow_apply, Finset.prod_apply]
· change Measurable (fun x ↦ _)
simp only [Pi.mul_apply, Pi.pow_apply, Finset.prod_apply]
refine (hf.pow_const _).mul <| Finset.measurable_prod _ ?_
exact fun _ _ ↦ hf.lmarginal μ |>.pow_const _
_ ≤ T μ p (∫⋯∫⁻_{i}, f ∂μ) s := lmarginal_mono (s := s) (fun x ↦ ?_)
-- The remainder of the computation happens within an `|s|`-fold iterated integral
simp only [Pi.mul_apply, Pi.pow_apply, Finset.prod_apply]
set X := update x i
have hF₁ : ∀ {j : ι}, Measurable fun t ↦ (∫⋯∫⁻_{j}, f ∂μ) (X t) :=
fun {_} ↦ hf.lmarginal μ |>.comp <| measurable_update _
have hF₀ : Measurable fun t ↦ f (X t) := hf.comp <| measurable_update _
let k : ℝ := s.card
have hk' : 0 ≤ 1 - k * p := by linarith only [hp]
calc ∫⁻ t, f (X t) ^ (1 - k * p)
* ∏ j ∈ insert i s, (∫⋯∫⁻_{j}, f ∂μ) (X t) ^ p ∂ (μ i)
= ∫⁻ t, (∫⋯∫⁻_{i}, f ∂μ) (X t) ^ p * (f (X t) ^ (1 - k * p)
* ∏ j ∈ s, ((∫⋯∫⁻_{j}, f ∂μ) (X t) ^ p)) ∂(μ i) := by
-- rewrite integrand so that `(∫⋯∫⁻_insert i s, f ∂μ) ^ p` comes first
clear_value X
congr! 2 with t
simp_rw [prod_insert hi]
ring_nf
_ = (∫⋯∫⁻_{i}, f ∂μ) x ^ p *
∫⁻ t, f (X t) ^ (1 - k * p) * ∏ j ∈ s, ((∫⋯∫⁻_{j}, f ∂μ) (X t)) ^ p ∂(μ i) := by
-- pull out this constant factor
have : ∀ t, (∫⋯∫⁻_{i}, f ∂μ) (X t) = (∫⋯∫⁻_{i}, f ∂μ) x := by
intro t
rw [lmarginal_update_of_mem]
exact Iff.mpr Finset.mem_singleton rfl
simp_rw [this]
rw [lintegral_const_mul]
exact (hF₀.pow_const _).mul <| Finset.measurable_prod _ fun _ _ ↦ hF₁.pow_const _
_ ≤ (∫⋯∫⁻_{i}, f ∂μ) x ^ p *
((∫⁻ t, f (X t) ∂μ i) ^ (1 - k * p)
* ∏ j ∈ s, (∫⁻ t, (∫⋯∫⁻_{j}, f ∂μ) (X t) ∂μ i) ^ p) := by
-- apply Hölder's inequality
gcongr
apply ENNReal.lintegral_mul_prod_norm_pow_le
· exact hF₀.aemeasurable
· intros
exact hF₁.aemeasurable
· simp only [sum_const, nsmul_eq_mul]
ring
· exact hk'
· exact fun _ _ ↦ hp₀
_ = (∫⋯∫⁻_{i}, f ∂μ) x ^ p *
((∫⋯∫⁻_{i}, f ∂μ) x ^ (1 - k * p) * ∏ j ∈ s, (∫⋯∫⁻_{i, j}, f ∂μ) x ^ p) := by
-- absorb the newly-created integrals into `∫⋯∫`
congr! 2
· rw [lmarginal_singleton]
refine prod_congr rfl fun j hj => ?_
have hi' : i ∉ ({j} : Finset ι) := by
simp only [Finset.mem_singleton, Finset.mem_insert, Finset.mem_compl] at hj ⊢
exact fun h ↦ hi (h ▸ hj)
rw [lmarginal_insert _ hf hi']
_ = (∫⋯∫⁻_{i}, f ∂μ) x ^ (p + (1 - k * p)) * ∏ j ∈ s, (∫⋯∫⁻_{i, j}, f ∂μ) x ^ p := by
-- combine two `(∫⋯∫⁻_insert i s, f ∂μ) x` terms
rw [ENNReal.rpow_add_of_nonneg]
· ring
· exact hp₀
· exact hk'
_ ≤ (∫⋯∫⁻_{i}, f ∂μ) x ^ (1 - (s.card - 1 : ℝ) * p) *
∏ j ∈ s, (∫⋯∫⁻_{j}, (∫⋯∫⁻_{i}, f ∂μ) ∂μ) x ^ p := by
-- identify the result with the RHS integrand
congr! 2 with j hj
· ring
· congr! 1
rw [← lmarginal_union μ f hf]
· congr
rw [Finset.union_comm]
rfl
· rw [Finset.disjoint_singleton]
simp only [Finset.mem_insert, Finset.mem_compl] at hj
exact fun h ↦ hi (h ▸ hj)
/-- Auxiliary result for the grid-lines lemma. Given a nonnegative function on a finitary product
type indexed by `ι`, and a set `s` in `ι`, consider partially integrating over the variables in
`sᶜ` and performing the "grid-lines operation" (see `GridLines.T`) to the resulting function in the
variables `s`. This theorem states that this operation decreases as the number of grid-lines taken
increases. -/
theorem T_lmarginal_antitone [Fintype ι] [∀ i, SigmaFinite (μ i)]
(hp₀ : 0 ≤ p) (hp : (#ι - 1 : ℝ) * p ≤ 1) {f : (∀ i, A i) → ℝ≥0∞} (hf : Measurable f) :
Antitone (fun s ↦ T μ p (∫⋯∫⁻_sᶜ, f ∂μ) s) := by
-- Reformulate (by induction): a function is decreasing on `Finset ι` if it decreases under the
-- insertion of any element to any set.
rw [Finset.antitone_iff_forall_insert_le]
intro s i hi
-- apply the lemma designed to encapsulate the inductive step
convert T_insert_le_T_lmarginal_singleton μ hp₀ s ?_ i hi (hf.lmarginal μ) using 2
· rw [← lmarginal_union μ f hf]
· rw [← insert_compl_insert hi]
rfl
rw [Finset.disjoint_singleton_left, not_mem_compl]
exact mem_insert_self i s
· -- the main nontrivial point is to check that an exponent `p` satisfying `0 ≤ p` and
-- `(#ι - 1) * p ≤ 1` is in the valid range for the inductive-step lemma
refine le_trans ?_ hp
gcongr
suffices (s.card : ℝ) + 1 ≤ #ι by linarith
rw [← card_add_card_compl s]
norm_cast
gcongr
have hi' : sᶜ.Nonempty := ⟨i, by rwa [Finset.mem_compl]⟩
rwa [← card_pos] at hi'
end GridLines
/-- The "grid-lines lemma" (not a standard name), stated with a general parameter `p` as the
exponent. Compare with `lintegral_prod_lintegral_pow_le`.
For any finite dependent product `Π i : ι, A i` of sigma-finite measure spaces, for any
nonnegative real number `p` such that `(#ι - 1) * p ≤ 1`, for any function `f` from `Π i, A i` into
the extended nonnegative reals, we consider an associated "grid-lines quantity", the integral of an
associated function from `Π i, A i` into the extended nonnegative reals. The value of this function
at `x : Π i, A i` is obtained by multiplying a certain power of `f` with the product, for each
co-ordinate `i`, of a certain power of the integral of `f` along the "grid line" in the `i`
direction through `x`.
This lemma bounds the Lebesgue integral of the grid-lines quantity by a power of the Lebesgue
integral of `f`. -/
theorem lintegral_mul_prod_lintegral_pow_le
[Fintype ι] [∀ i, SigmaFinite (μ i)] {p : ℝ} (hp₀ : 0 ≤ p)
(hp : (#ι - 1 : ℝ) * p ≤ 1) {f : (∀ i : ι, A i) → ℝ≥0∞} (hf : Measurable f) :
∫⁻ x, f x ^ (1 - (#ι - 1 : ℝ) * p) * ∏ i, (∫⁻ xᵢ, f (update x i xᵢ) ∂μ i) ^ p ∂.pi μ
≤ (∫⁻ x, f x ∂.pi μ) ^ (1 + p) := by
cases isEmpty_or_nonempty (∀ i, A i)
· simp_rw [lintegral_of_isEmpty]; refine zero_le _
inhabit ∀ i, A i
have H : (∅ : Finset ι) ≤ Finset.univ := Finset.empty_subset _
simpa [lmarginal_univ] using GridLines.T_lmarginal_antitone μ hp₀ hp hf H default
/-- Special case of the grid-lines lemma `lintegral_mul_prod_lintegral_pow_le`, taking the extremal
exponent `p = (#ι - 1)⁻¹`. -/
theorem lintegral_prod_lintegral_pow_le [Fintype ι] [∀ i, SigmaFinite (μ i)]
{p : ℝ} (hp : Real.HolderConjugate #ι p)
{f} (hf : Measurable f) :
∫⁻ x, ∏ i, (∫⁻ xᵢ, f (update x i xᵢ) ∂μ i) ^ ((1 : ℝ) / (#ι - 1 : ℝ)) ∂.pi μ
≤ (∫⁻ x, f x ∂.pi μ) ^ p := by
have : Nontrivial ι :=
Fintype.one_lt_card_iff_nontrivial.mp (by exact_mod_cast hp.lt)
have h0 : (1 : ℝ) < #ι := by norm_cast; exact Fintype.one_lt_card
have h1 : (0 : ℝ) < #ι - 1 := by linarith
have h2 : 0 ≤ ((1 : ℝ) / (#ι - 1 : ℝ)) := by positivity
have h3 : (#ι - 1 : ℝ) * ((1 : ℝ) / (#ι - 1 : ℝ)) ≤ 1 := by field_simp
have h4 : p = 1 + 1 / (↑#ι - 1) := by field_simp; rw [mul_comm, hp.sub_one_mul_conj]
rw [h4]
convert lintegral_mul_prod_lintegral_pow_le μ h2 h3 hf using 2
field_simp
end DecidableEq
/-! ## The Gagliardo-Nirenberg-Sobolev inequality -/
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
/-- The **Gagliardo-Nirenberg-Sobolev inequality**. Let `u` be a continuously differentiable
compactly-supported function `u` on `ℝⁿ`, for `n ≥ 2`. (More literally we encode `ℝⁿ` as
`ι → ℝ` where `n := #ι` is finite and at least 2.) Then the Lebesgue integral of the pointwise
expression `|u x| ^ (n / (n - 1))` is bounded above by the `n / (n - 1)`-th power of the Lebesgue
integral of the Fréchet derivative of `u`.
For a basis-free version, see `lintegral_pow_le_pow_lintegral_fderiv`. -/
theorem lintegral_pow_le_pow_lintegral_fderiv_aux [Fintype ι]
{p : ℝ} (hp : Real.HolderConjugate #ι p)
{u : (ι → ℝ) → F} (hu : ContDiff ℝ 1 u)
(h2u : HasCompactSupport u) :
∫⁻ x, ‖u x‖ₑ ^ p ≤ (∫⁻ x, ‖fderiv ℝ u x‖ₑ) ^ p := by
classical
/- For a function `f` in one variable and `t ∈ ℝ` we have
`|f(t)| = `|∫_{-∞}^t Df(s)∂s| ≤ ∫_ℝ |Df(s)| ∂s` where we use the fundamental theorem of calculus.
For each `x ∈ ℝⁿ` we let `u` vary in one of the `n` coordinates and apply the inequality above.
By taking the product over these `n` factors, raising them to the power `(n-1)⁻¹` and integrating,
we get the inequality `∫ |u| ^ (n/(n-1)) ≤ ∫ x, ∏ i, (∫ xᵢ, |Du(update x i xᵢ)|)^(n-1)⁻¹`.
The result then follows from the grid-lines lemma. -/
have : (1 : ℝ) ≤ ↑#ι - 1 := by
have hι : (2 : ℝ) ≤ #ι := by exact_mod_cast hp.lt
linarith
calc ∫⁻ x, ‖u x‖ₑ ^ p
= ∫⁻ x, (‖u x‖ₑ ^ (1 / (#ι - 1 : ℝ))) ^ (#ι : ℝ) := by
-- a little algebraic manipulation of the exponent
congr! 2 with x
rw [← ENNReal.rpow_mul, hp.conjugate_eq]
field_simp
_ = ∫⁻ x, ∏ _i : ι, ‖u x‖ₑ ^ (1 / (#ι - 1 : ℝ)) := by
-- express the left-hand integrand as a product of identical factors
congr! 2 with x
simp_rw [prod_const]
norm_cast
_ ≤ ∫⁻ x, ∏ i, (∫⁻ xᵢ, ‖fderiv ℝ u (update x i xᵢ)‖ₑ) ^ ((1 : ℝ) / (#ι - 1 : ℝ)) := ?_
_ ≤ (∫⁻ x, ‖fderiv ℝ u x‖ₑ) ^ p := by
-- apply the grid-lines lemma
apply lintegral_prod_lintegral_pow_le _ hp
have : Continuous (fderiv ℝ u) := hu.continuous_fderiv le_rfl
fun_prop
-- we estimate |u x| using the fundamental theorem of calculus.
gcongr with x i
calc ‖u x‖ₑ
_ ≤ ∫⁻ xᵢ in Iic (x i), ‖deriv (u ∘ update x i) xᵢ‖ₑ := by
apply le_trans (by simp) (HasCompactSupport.enorm_le_lintegral_Ici_deriv _ _ _)
· exact hu.comp (by convert contDiff_update 1 x i)
· exact h2u.comp_isClosedEmbedding (isClosedEmbedding_update x i)
_ ≤ ∫⁻ xᵢ, ‖fderiv ℝ u (update x i xᵢ)‖ₑ := ?_
gcongr
· exact Measure.restrict_le_self
intro y
dsimp
-- bound the derivative which appears
calc ‖deriv (u ∘ update x i) y‖ₑ = ‖fderiv ℝ u (update x i y) (deriv (update x i) y)‖ₑ := by
rw [fderiv_comp_deriv _ (hu.differentiable le_rfl).differentiableAt
(hasDerivAt_update x i y).differentiableAt]
_ ≤ ‖fderiv ℝ u (update x i y)‖ₑ * ‖deriv (update x i) y‖ₑ := ContinuousLinearMap.le_opENorm _ _
_ ≤ ‖fderiv ℝ u (update x i y)‖ₑ := by simp [deriv_update, Pi.enorm_single]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
open Module
/-- The constant factor occurring in the conclusion of `lintegral_pow_le_pow_lintegral_fderiv`.
It only depends on `E`, `μ` and `p`.
It is determined by the ratio of the measures on `E` and `ℝⁿ` and
the operator norm of a chosen equivalence `E ≃ ℝⁿ` (raised to suitable powers involving `p`). -/
irreducible_def lintegralPowLePowLIntegralFDerivConst (p : ℝ) : ℝ≥0 := by
let ι := Fin (finrank ℝ E)
have : finrank ℝ E = finrank ℝ (ι → ℝ) := by
| rw [finrank_fintype_fun_eq_card, Fintype.card_fin (finrank ℝ E)]
let e : E ≃L[ℝ] ι → ℝ := ContinuousLinearEquiv.ofFinrankEq this
let c := addHaarScalarFactor μ ((volume : Measure (ι → ℝ)).map e.symm)
exact (c * ‖(e.symm : (ι → ℝ) →L[ℝ] E)‖₊ ^ p) * (c ^ p)⁻¹
/-- The **Gagliardo-Nirenberg-Sobolev inequality**. Let `u` be a continuously differentiable
compactly-supported function `u` on a normed space `E` of finite dimension `n ≥ 2`, equipped
with Haar measure. Then the Lebesgue integral of the pointwise expression
`|u x| ^ (n / (n - 1))` is bounded above by a constant times the `n / (n - 1)`-th power of the
Lebesgue integral of the Fréchet derivative of `u`. -/
theorem lintegral_pow_le_pow_lintegral_fderiv {u : E → F}
(hu : ContDiff ℝ 1 u) (h2u : HasCompactSupport u)
{p : ℝ} (hp : Real.HolderConjugate (finrank ℝ E) p) :
∫⁻ x, ‖u x‖ₑ ^ p ∂μ ≤
lintegralPowLePowLIntegralFDerivConst μ p * (∫⁻ x, ‖fderiv ℝ u x‖ₑ ∂μ) ^ p := by
/- We reduce to the case where `E` is `ℝⁿ`, for which we have already proved the result using
an explicit basis in `MeasureTheory.lintegral_pow_le_pow_lintegral_fderiv_aux`.
This proof is not too hard, but takes quite some steps, reasoning about the equivalence
`e : E ≃ ℝⁿ`, relating the measures on each sides of the equivalence,
and estimating the derivative using the chain rule. -/
set C := lintegralPowLePowLIntegralFDerivConst μ p
let ι := Fin (finrank ℝ E)
have hιcard : #ι = finrank ℝ E := Fintype.card_fin (finrank ℝ E)
have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [hιcard]
let e : E ≃L[ℝ] ι → ℝ := ContinuousLinearEquiv.ofFinrankEq this
have : IsAddHaarMeasure ((volume : Measure (ι → ℝ)).map e.symm) :=
(e.symm : (ι → ℝ) ≃+ E).isAddHaarMeasure_map _ e.symm.continuous e.symm.symm.continuous
have hp : Real.HolderConjugate #ι p := by rwa [hιcard]
have h0p : 0 ≤ p := hp.symm.nonneg
let c := addHaarScalarFactor μ ((volume : Measure (ι → ℝ)).map e.symm)
have hc : 0 < c := addHaarScalarFactor_pos_of_isAddHaarMeasure ..
have h2c : μ = c • ((volume : Measure (ι → ℝ)).map e.symm) := isAddLeftInvariant_eq_smul ..
have h3c : (c : ℝ≥0∞) ≠ 0 := by simp_rw [ne_eq, ENNReal.coe_eq_zero, hc.ne', not_false_eq_true]
have h0C : C = (c * ‖(e.symm : (ι → ℝ) →L[ℝ] E)‖₊ ^ p) * (c ^ p)⁻¹ := by
simp_rw [c, ι, C, e, lintegralPowLePowLIntegralFDerivConst]
have hC : C * c ^ p = c * ‖(e.symm : (ι → ℝ) →L[ℝ] E)‖₊ ^ p := by
rw [h0C, inv_mul_cancel_right₀ (NNReal.rpow_pos hc).ne']
simp only [h2c, ENNReal.smul_def, lintegral_smul_measure, smul_eq_mul]
let v : (ι → ℝ) → F := u ∘ e.symm
have hv : ContDiff ℝ 1 v := hu.comp e.symm.contDiff
have h2v : HasCompactSupport v := h2u.comp_homeomorph e.symm.toHomeomorph
have :=
calc ∫⁻ x, ‖u x‖ₑ ^ p ∂(volume : Measure (ι → ℝ)).map e.symm
= ∫⁻ y, ‖v y‖ₑ ^ p := by
refine lintegral_map ?_ e.symm.continuous.measurable
borelize F
exact hu.continuous.measurable.nnnorm.coe_nnreal_ennreal.pow_const _
_ ≤ (∫⁻ y, ‖fderiv ℝ v y‖ₑ) ^ p := lintegral_pow_le_pow_lintegral_fderiv_aux hp hv h2v
_ = (∫⁻ y, ‖(fderiv ℝ u (e.symm y)).comp (fderiv ℝ e.symm y)‖ₑ) ^ p := by
congr! with y
apply fderiv_comp _ (hu.differentiable le_rfl _)
exact e.symm.differentiableAt
_ ≤ (∫⁻ y, ‖fderiv ℝ u (e.symm y)‖ₑ * ‖(e.symm : (ι → ℝ) →L[ℝ] E)‖ₑ) ^ p := by
gcongr with y
rw [e.symm.fderiv]
apply ContinuousLinearMap.opENorm_comp_le
_ = (‖(e.symm : (ι → ℝ) →L[ℝ] E)‖ₑ * ∫⁻ y, ‖fderiv ℝ u (e.symm y)‖ₑ) ^ p := by
rw [lintegral_mul_const, mul_comm]
refine (Continuous.nnnorm ?_).measurable.coe_nnreal_ennreal
exact (hu.continuous_fderiv le_rfl).comp e.symm.continuous
_ = (‖(e.symm : (ι → ℝ) →L[ℝ] E)‖₊ ^ p : ℝ≥0) * (∫⁻ y, ‖fderiv ℝ u (e.symm y)‖ₑ) ^ p := by
rw [ENNReal.mul_rpow_of_nonneg _ _ h0p, enorm_eq_nnnorm, ← ENNReal.coe_rpow_of_nonneg _ h0p]
_ = (‖(e.symm : (ι → ℝ) →L[ℝ] E)‖₊ ^ p : ℝ≥0)
* (∫⁻ x, ‖fderiv ℝ u x‖ₑ ∂(volume : Measure (ι → ℝ)).map e.symm) ^ p := by
| Mathlib/Analysis/FunctionalSpaces/SobolevInequality.lean | 362 | 425 |
/-
Copyright (c) 2022 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Int.Log
/-!
# Real logarithm base `b`
In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We
define this as the division of the natural logarithms of the argument and the base, so that we have
a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and
`logb (-b) x = logb b x`.
We prove some basic properties of this function and its relation to `rpow`.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {b x y : ℝ}
/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to
be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/
@[pp_nodot]
noncomputable def logb (b x : ℝ) : ℝ :=
log x / log b
theorem log_div_log : log x / log b = logb b x :=
rfl
@[simp]
theorem logb_zero : logb b 0 = 0 := by simp [logb]
@[simp]
theorem logb_one : logb b 1 = 0 := by simp [logb]
theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero]
@[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply]
theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero]
@[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply]
@[simp]
lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 :=
div_self (log_pos hb).ne'
lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 :=
| Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 64 | 64 |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Set.Image
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.WithBot
/-!
# Intervals in `WithTop α` and `WithBot α`
In this file we prove various lemmas about `Set.image`s and `Set.preimage`s of intervals under
`some : α → WithTop α` and `some : α → WithBot α`.
-/
open Set
variable {α : Type*}
/-! ### `WithTop` -/
namespace WithTop
@[simp]
theorem preimage_coe_top : (some : α → WithTop α) ⁻¹' {⊤} = (∅ : Set α) :=
eq_empty_of_subset_empty fun _ => coe_ne_top
variable [Preorder α] {a b : α}
theorem range_coe : range (some : α → WithTop α) = Iio ⊤ := by
ext x
rw [mem_Iio, WithTop.lt_top_iff_ne_top, mem_range, ne_top_iff_exists]
@[simp]
theorem preimage_coe_Ioi : (some : α → WithTop α) ⁻¹' Ioi a = Ioi a :=
ext fun _ => coe_lt_coe
@[simp]
theorem preimage_coe_Ici : (some : α → WithTop α) ⁻¹' Ici a = Ici a :=
ext fun _ => coe_le_coe
@[simp]
theorem preimage_coe_Iio : (some : α → WithTop α) ⁻¹' Iio a = Iio a :=
ext fun _ => coe_lt_coe
@[simp]
theorem preimage_coe_Iic : (some : α → WithTop α) ⁻¹' Iic a = Iic a :=
ext fun _ => coe_le_coe
@[simp]
theorem preimage_coe_Icc : (some : α → WithTop α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic]
@[simp]
theorem preimage_coe_Ico : (some : α → WithTop α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio]
@[simp]
theorem preimage_coe_Ioc : (some : α → WithTop α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic]
@[simp]
theorem preimage_coe_Ioo : (some : α → WithTop α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio]
@[simp]
theorem preimage_coe_Iio_top : (some : α → WithTop α) ⁻¹' Iio ⊤ = univ := by
rw [← range_coe, preimage_range]
@[simp]
theorem preimage_coe_Ico_top : (some : α → WithTop α) ⁻¹' Ico a ⊤ = Ici a := by
simp [← Ici_inter_Iio]
@[simp]
theorem preimage_coe_Ioo_top : (some : α → WithTop α) ⁻¹' Ioo a ⊤ = Ioi a := by
simp [← Ioi_inter_Iio]
| theorem image_coe_Ioi : (some : α → WithTop α) '' Ioi a = Ioo (a : WithTop α) ⊤ := by
rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, Ioi_inter_Iio]
| Mathlib/Order/Interval/Set/WithBotTop.lean | 75 | 76 |
/-
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, Yury Kudryashov, Sébastien Gouëzel, Chris Hughes
-/
import Mathlib.Data.Fin.Rev
import Mathlib.Data.Nat.Find
/-!
# Operation on tuples
We interpret maps `∀ i : Fin n, α i` as `n`-tuples of elements of possibly varying type `α i`,
`(α 0, …, α (n-1))`. A particular case is `Fin n → α` of elements with all the same type.
In this case when `α i` is a constant map, then tuples are isomorphic (but not definitionally equal)
to `Vector`s.
## Main declarations
There are three (main) ways to consider `Fin n` as a subtype of `Fin (n + 1)`, hence three (main)
ways to move between tuples of length `n` and of length `n + 1` by adding/removing an entry.
### Adding at the start
* `Fin.succ`: Send `i : Fin n` to `i + 1 : Fin (n + 1)`. This is defined in Core.
* `Fin.cases`: Induction/recursion principle for `Fin`: To prove a property/define a function for
all `Fin (n + 1)`, it is enough to prove/define it for `0` and for `i.succ` for all `i : Fin n`.
This is defined in Core.
* `Fin.cons`: Turn a tuple `f : Fin n → α` and an entry `a : α` into a tuple
`Fin.cons a f : Fin (n + 1) → α` by adding `a` at the start. In general, tuples can be dependent
functions, in which case `f : ∀ i : Fin n, α i.succ` and `a : α 0`. This is a special case of
`Fin.cases`.
* `Fin.tail`: Turn a tuple `f : Fin (n + 1) → α` into a tuple `Fin.tail f : Fin n → α` by forgetting
the start. In general, tuples can be dependent functions,
in which case `Fin.tail f : ∀ i : Fin n, α i.succ`.
### Adding at the end
* `Fin.castSucc`: Send `i : Fin n` to `i : Fin (n + 1)`. This is defined in Core.
* `Fin.lastCases`: Induction/recursion principle for `Fin`: To prove a property/define a function
for all `Fin (n + 1)`, it is enough to prove/define it for `last n` and for `i.castSucc` for all
`i : Fin n`. This is defined in Core.
* `Fin.snoc`: Turn a tuple `f : Fin n → α` and an entry `a : α` into a tuple
`Fin.snoc f a : Fin (n + 1) → α` by adding `a` at the end. In general, tuples can be dependent
functions, in which case `f : ∀ i : Fin n, α i.castSucc` and `a : α (last n)`. This is a
special case of `Fin.lastCases`.
* `Fin.init`: Turn a tuple `f : Fin (n + 1) → α` into a tuple `Fin.init f : Fin n → α` by forgetting
the start. In general, tuples can be dependent functions,
in which case `Fin.init f : ∀ i : Fin n, α i.castSucc`.
### Adding in the middle
For a **pivot** `p : Fin (n + 1)`,
* `Fin.succAbove`: Send `i : Fin n` to
* `i : Fin (n + 1)` if `i < p`,
* `i + 1 : Fin (n + 1)` if `p ≤ i`.
* `Fin.succAboveCases`: Induction/recursion principle for `Fin`: To prove a property/define a
function for all `Fin (n + 1)`, it is enough to prove/define it for `p` and for `p.succAbove i`
for all `i : Fin n`.
* `Fin.insertNth`: Turn a tuple `f : Fin n → α` and an entry `a : α` into a tuple
`Fin.insertNth f a : Fin (n + 1) → α` by adding `a` in position `p`. In general, tuples can be
dependent functions, in which case `f : ∀ i : Fin n, α (p.succAbove i)` and `a : α p`. This is a
special case of `Fin.succAboveCases`.
* `Fin.removeNth`: Turn a tuple `f : Fin (n + 1) → α` into a tuple `Fin.removeNth p f : Fin n → α`
by forgetting the `p`-th value. In general, tuples can be dependent functions,
in which case `Fin.removeNth f : ∀ i : Fin n, α (succAbove p i)`.
`p = 0` means we add at the start. `p = last n` means we add at the end.
### Miscellaneous
* `Fin.find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied.
* `Fin.append a b` : append two tuples.
* `Fin.repeat n a` : repeat a tuple `n` times.
-/
assert_not_exists Monoid
universe u v
namespace Fin
variable {m n : ℕ}
open Function
section Tuple
/-- There is exactly one tuple of size zero. -/
example (α : Fin 0 → Sort u) : Unique (∀ i : Fin 0, α i) := by infer_instance
theorem tuple0_le {α : Fin 0 → Type*} [∀ i, Preorder (α i)] (f g : ∀ i, α i) : f ≤ g :=
finZeroElim
variable {α : Fin (n + 1) → Sort u} (x : α 0) (q : ∀ i, α i) (p : ∀ i : Fin n, α i.succ) (i : Fin n)
(y : α i.succ) (z : α 0)
/-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/
def tail (q : ∀ i, α i) : ∀ i : Fin n, α i.succ := fun i ↦ q i.succ
theorem tail_def {n : ℕ} {α : Fin (n + 1) → Sort*} {q : ∀ i, α i} :
(tail fun k : Fin (n + 1) ↦ q k) = fun k : Fin n ↦ q k.succ :=
rfl
/-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/
def cons (x : α 0) (p : ∀ i : Fin n, α i.succ) : ∀ i, α i := fun j ↦ Fin.cases x p j
@[simp]
theorem tail_cons : tail (cons x p) = p := by
simp +unfoldPartialApp [tail, cons]
@[simp]
theorem cons_succ : cons x p i.succ = p i := by simp [cons]
@[simp]
theorem cons_zero : cons x p 0 = x := by simp [cons]
@[simp]
theorem cons_one {α : Fin (n + 2) → Sort*} (x : α 0) (p : ∀ i : Fin n.succ, α i.succ) :
cons x p 1 = p 0 := by
rw [← cons_succ x p]; rfl
/-- Updating a tuple and adding an element at the beginning commute. -/
@[simp]
theorem cons_update : cons x (update p i y) = update (cons x p) i.succ y := by
ext j
by_cases h : j = 0
· rw [h]
simp [Ne.symm (succ_ne_zero i)]
· let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [← this, cons_succ]
by_cases h' : j' = i
· rw [h']
simp
· have : j'.succ ≠ i.succ := by rwa [Ne, succ_inj]
rw [update_of_ne h', update_of_ne this, cons_succ]
/-- As a binary function, `Fin.cons` is injective. -/
theorem cons_injective2 : Function.Injective2 (@cons n α) := fun x₀ y₀ x y h ↦
⟨congr_fun h 0, funext fun i ↦ by simpa using congr_fun h (Fin.succ i)⟩
@[simp]
theorem cons_inj {x₀ y₀ : α 0} {x y : ∀ i : Fin n, α i.succ} :
cons x₀ x = cons y₀ y ↔ x₀ = y₀ ∧ x = y :=
cons_injective2.eq_iff
theorem cons_left_injective (x : ∀ i : Fin n, α i.succ) : Function.Injective fun x₀ ↦ cons x₀ x :=
cons_injective2.left _
theorem cons_right_injective (x₀ : α 0) : Function.Injective (cons x₀) :=
cons_injective2.right _
/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it
directly. -/
theorem update_cons_zero : update (cons x p) 0 z = cons z p := by
ext j
by_cases h : j = 0
· rw [h]
simp
· simp only [h, update_of_ne, Ne, not_false_iff]
let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [← this, cons_succ, cons_succ]
/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/
@[simp]
theorem cons_self_tail : cons (q 0) (tail q) = q := by
ext j
by_cases h : j = 0
· rw [h]
simp
· let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [← this]
unfold tail
rw [cons_succ]
/-- Equivalence between tuples of length `n + 1` and pairs of an element and a tuple of length `n`
given by separating out the first element of the tuple.
This is `Fin.cons` as an `Equiv`. -/
@[simps]
def consEquiv (α : Fin (n + 1) → Type*) : α 0 × (∀ i, α (succ i)) ≃ ∀ i, α i where
toFun f := cons f.1 f.2
invFun f := (f 0, tail f)
left_inv f := by simp
right_inv f := by simp
/-- Recurse on an `n+1`-tuple by splitting it into a single element and an `n`-tuple. -/
@[elab_as_elim]
def consCases {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀ x, P (Fin.cons x₀ x))
(x : ∀ i : Fin n.succ, α i) : P x :=
_root_.cast (by rw [cons_self_tail]) <| h (x 0) (tail x)
@[simp]
theorem consCases_cons {P : (∀ i : Fin n.succ, α i) → Sort v} (h : ∀ x₀ x, P (Fin.cons x₀ x))
(x₀ : α 0) (x : ∀ i : Fin n, α i.succ) : @consCases _ _ _ h (cons x₀ x) = h x₀ x := by
rw [consCases, cast_eq]
congr
/-- Recurse on a tuple by splitting into `Fin.elim0` and `Fin.cons`. -/
@[elab_as_elim]
def consInduction {α : Sort*} {P : ∀ {n : ℕ}, (Fin n → α) → Sort v} (h0 : P Fin.elim0)
(h : ∀ {n} (x₀) (x : Fin n → α), P x → P (Fin.cons x₀ x)) : ∀ {n : ℕ} (x : Fin n → α), P x
| 0, x => by convert h0
| _ + 1, x => consCases (fun _ _ ↦ h _ _ <| consInduction h0 h _) x
theorem cons_injective_of_injective {α} {x₀ : α} {x : Fin n → α} (hx₀ : x₀ ∉ Set.range x)
(hx : Function.Injective x) : Function.Injective (cons x₀ x : Fin n.succ → α) := by
refine Fin.cases ?_ ?_
· refine Fin.cases ?_ ?_
· intro
rfl
· intro j h
rw [cons_zero, cons_succ] at h
exact hx₀.elim ⟨_, h.symm⟩
· intro i
refine Fin.cases ?_ ?_
· intro h
rw [cons_zero, cons_succ] at h
exact hx₀.elim ⟨_, h⟩
· intro j h
rw [cons_succ, cons_succ] at h
exact congr_arg _ (hx h)
theorem cons_injective_iff {α} {x₀ : α} {x : Fin n → α} :
Function.Injective (cons x₀ x : Fin n.succ → α) ↔ x₀ ∉ Set.range x ∧ Function.Injective x := by
refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ cons_injective_of_injective h.1 h.2⟩
· rintro ⟨i, hi⟩
replace h := @h i.succ 0
simp [hi] at h
· simpa [Function.comp] using h.comp (Fin.succ_injective _)
@[simp]
theorem forall_fin_zero_pi {α : Fin 0 → Sort*} {P : (∀ i, α i) → Prop} :
(∀ x, P x) ↔ P finZeroElim :=
⟨fun h ↦ h _, fun h x ↦ Subsingleton.elim finZeroElim x ▸ h⟩
@[simp]
theorem exists_fin_zero_pi {α : Fin 0 → Sort*} {P : (∀ i, α i) → Prop} :
(∃ x, P x) ↔ P finZeroElim :=
⟨fun ⟨x, h⟩ ↦ Subsingleton.elim x finZeroElim ▸ h, fun h ↦ ⟨_, h⟩⟩
theorem forall_fin_succ_pi {P : (∀ i, α i) → Prop} : (∀ x, P x) ↔ ∀ a v, P (Fin.cons a v) :=
⟨fun h a v ↦ h (Fin.cons a v), consCases⟩
theorem exists_fin_succ_pi {P : (∀ i, α i) → Prop} : (∃ x, P x) ↔ ∃ a v, P (Fin.cons a v) :=
⟨fun ⟨x, h⟩ ↦ ⟨x 0, tail x, (cons_self_tail x).symm ▸ h⟩, fun ⟨_, _, h⟩ ↦ ⟨_, h⟩⟩
/-- Updating the first element of a tuple does not change the tail. -/
@[simp]
theorem tail_update_zero : tail (update q 0 z) = tail q := by
ext j
simp [tail]
/-- Updating a nonzero element and taking the tail commute. -/
@[simp]
theorem tail_update_succ : tail (update q i.succ y) = update (tail q) i y := by
ext j
by_cases h : j = i
· rw [h]
simp [tail]
· simp [tail, (Fin.succ_injective n).ne h, h]
theorem comp_cons {α : Sort*} {β : Sort*} (g : α → β) (y : α) (q : Fin n → α) :
g ∘ cons y q = cons (g y) (g ∘ q) := by
ext j
by_cases h : j = 0
· rw [h]
rfl
· let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [← this, cons_succ, comp_apply, comp_apply, cons_succ]
|
theorem comp_tail {α : Sort*} {β : Sort*} (g : α → β) (q : Fin n.succ → α) :
g ∘ tail q = tail (g ∘ q) := by
ext j
simp [tail]
| Mathlib/Data/Fin/Tuple/Basic.lean | 277 | 282 |
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.Topology.Instances.NNReal.Lemmas
import Mathlib.Topology.Order.MonotoneContinuity
/-!
# Square root of a real number
In this file we define
* `NNReal.sqrt` to be the square root of a nonnegative real number.
* `Real.sqrt` to be the square root of a real number, defined to be zero on negative numbers.
Then we prove some basic properties of these functions.
## Implementation notes
We define `NNReal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general
theory of inverses of strictly monotone functions to prove that `NNReal.sqrt x` exists. As a side
effect, `NNReal.sqrt` is a bundled `OrderIso`, so for `NNReal` numbers we get continuity as well as
theorems like `NNReal.sqrt x ≤ y ↔ x ≤ y * y` for free.
Then we define `Real.sqrt x` to be `NNReal.sqrt (Real.toNNReal x)`.
## Tags
square root
-/
open Set Filter
open scoped Filter NNReal Topology
namespace NNReal
variable {x y : ℝ≥0}
/-- Square root of a nonnegative real number. -/
-- Porting note (kmill): `pp_nodot` has no effect here
-- unless RFC https://github.com/leanprover/lean4/issues/6178 leads to dot notation pp for CoeFun
@[pp_nodot]
noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 :=
OrderIso.symm <| powOrderIso 2 two_ne_zero
@[simp] lemma sq_sqrt (x : ℝ≥0) : sqrt x ^ 2 = x := sqrt.symm_apply_apply _
@[simp] lemma sqrt_sq (x : ℝ≥0) : sqrt (x ^ 2) = x := sqrt.apply_symm_apply _
@[simp] lemma mul_self_sqrt (x : ℝ≥0) : sqrt x * sqrt x = x := by rw [← sq, sq_sqrt]
@[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := by rw [← sq, sqrt_sq]
lemma sqrt_le_sqrt : sqrt x ≤ sqrt y ↔ x ≤ y := sqrt.le_iff_le
lemma sqrt_lt_sqrt : sqrt x < sqrt y ↔ x < y := sqrt.lt_iff_lt
lemma sqrt_eq_iff_eq_sq : sqrt x = y ↔ x = y ^ 2 := sqrt.toEquiv.apply_eq_iff_eq_symm_apply
lemma sqrt_le_iff_le_sq : sqrt x ≤ y ↔ x ≤ y ^ 2 := sqrt.to_galoisConnection _ _
lemma le_sqrt_iff_sq_le : x ≤ sqrt y ↔ x ^ 2 ≤ y := (sqrt.symm.to_galoisConnection _ _).symm
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 := by simp [sqrt_eq_iff_eq_sq]
@[simp] lemma sqrt_eq_one : sqrt x = 1 ↔ x = 1 := by simp [sqrt_eq_iff_eq_sq]
@[simp] lemma sqrt_zero : sqrt 0 = 0 := by simp
@[simp] lemma sqrt_one : sqrt 1 = 1 := by simp
@[simp] lemma sqrt_le_one : sqrt x ≤ 1 ↔ x ≤ 1 := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
@[simp] lemma one_le_sqrt : 1 ≤ sqrt x ↔ 1 ≤ x := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
theorem sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y := by
rw [sqrt_eq_iff_eq_sq, mul_pow, sq_sqrt, sq_sqrt]
/-- `NNReal.sqrt` as a `MonoidWithZeroHom`. -/
noncomputable def sqrtHom : ℝ≥0 →*₀ ℝ≥0 :=
⟨⟨sqrt, sqrt_zero⟩, sqrt_one, sqrt_mul⟩
theorem sqrt_inv (x : ℝ≥0) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
map_inv₀ sqrtHom x
theorem sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y :=
map_div₀ sqrtHom x y
@[continuity, fun_prop]
theorem continuous_sqrt : Continuous sqrt := sqrt.continuous
@[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x := by simp [pos_iff_ne_zero]
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
attribute [bound] sqrt_pos_of_pos
end NNReal
namespace Real
/-- The square root of a real number. This returns 0 for negative inputs.
This has notation `√x`. Note that `√x⁻¹` is parsed as `√(x⁻¹)`. -/
noncomputable def sqrt (x : ℝ) : ℝ :=
NNReal.sqrt (Real.toNNReal x)
-- TODO: replace this with a typeclass
@[inherit_doc]
prefix:max "√" => Real.sqrt
variable {x y : ℝ}
@[simp, norm_cast]
theorem coe_sqrt {x : ℝ≥0} : (NNReal.sqrt x : ℝ) = √(x : ℝ) := by
rw [Real.sqrt, Real.toNNReal_coe]
@[continuity]
theorem continuous_sqrt : Continuous (√· : ℝ → ℝ) :=
NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal
theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 := by simp [sqrt, Real.toNNReal_eq_zero.2 h]
@[simp] theorem sqrt_nonneg (x : ℝ) : 0 ≤ √x := NNReal.coe_nonneg _
@[simp]
theorem mul_self_sqrt (h : 0 ≤ x) : √x * √x = x := by
rw [Real.sqrt, ← NNReal.coe_mul, NNReal.mul_self_sqrt, Real.coe_toNNReal _ h]
@[simp]
theorem sqrt_mul_self (h : 0 ≤ x) : √(x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
theorem sqrt_eq_cases : √x = y ↔ y * y = x ∧ 0 ≤ y ∨ x < 0 ∧ y = 0 := by
constructor
· rintro rfl
rcases le_or_lt 0 x with hle | hlt
· exact Or.inl ⟨mul_self_sqrt hle, sqrt_nonneg x⟩
· exact Or.inr ⟨hlt, sqrt_eq_zero_of_nonpos hlt.le⟩
· rintro (⟨rfl, hy⟩ | ⟨hx, rfl⟩)
exacts [sqrt_mul_self hy, sqrt_eq_zero_of_nonpos hx.le]
theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ x = y * y :=
⟨fun h => by rw [← h, mul_self_sqrt hx], fun h => by rw [h, sqrt_mul_self hy]⟩
theorem sqrt_eq_iff_mul_self_eq_of_pos (h : 0 < y) : √x = y ↔ y * y = x := by
simp [sqrt_eq_cases, h.ne', h.le]
@[simp]
theorem sqrt_eq_one : √x = 1 ↔ x = 1 :=
calc
√x = 1 ↔ 1 * 1 = x := sqrt_eq_iff_mul_self_eq_of_pos zero_lt_one
_ ↔ x = 1 := by rw [eq_comm, mul_one]
@[simp]
theorem sq_sqrt (h : 0 ≤ x) : √x ^ 2 = x := by rw [sq, mul_self_sqrt h]
@[simp]
theorem sqrt_sq (h : 0 ≤ x) : √(x ^ 2) = x := by rw [sq, sqrt_mul_self h]
theorem sqrt_eq_iff_eq_sq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ x = y ^ 2 := by
rw [sq, sqrt_eq_iff_mul_self_eq hx hy]
theorem sqrt_mul_self_eq_abs (x : ℝ) : √(x * x) = |x| := by
rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)]
theorem sqrt_sq_eq_abs (x : ℝ) : √(x ^ 2) = |x| := by rw [sq, sqrt_mul_self_eq_abs]
@[simp]
theorem sqrt_zero : √0 = 0 := by simp [Real.sqrt]
@[simp]
theorem sqrt_one : √1 = 1 := by simp [Real.sqrt]
@[simp]
theorem sqrt_le_sqrt_iff (hy : 0 ≤ y) : √x ≤ √y ↔ x ≤ y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt, toNNReal_le_toNNReal_iff hy]
@[simp]
theorem sqrt_lt_sqrt_iff (hx : 0 ≤ x) : √x < √y ↔ x < y :=
lt_iff_lt_of_le_iff_le (sqrt_le_sqrt_iff hx)
theorem sqrt_lt_sqrt_iff_of_pos (hy : 0 < y) : √x < √y ↔ x < y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_lt_coe, NNReal.sqrt_lt_sqrt, toNNReal_lt_toNNReal_iff hy]
@[gcongr, bound]
theorem sqrt_le_sqrt (h : x ≤ y) : √x ≤ √y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt]
exact toNNReal_le_toNNReal h
@[gcongr, bound]
theorem sqrt_lt_sqrt (hx : 0 ≤ x) (h : x < y) : √x < √y :=
(sqrt_lt_sqrt_iff hx).2 h
theorem sqrt_le_left (hy : 0 ≤ y) : √x ≤ y ↔ x ≤ y ^ 2 := by
rw [sqrt, ← Real.le_toNNReal_iff_coe_le hy, NNReal.sqrt_le_iff_le_sq, sq, ← Real.toNNReal_mul hy,
Real.toNNReal_le_toNNReal_iff (mul_self_nonneg y), sq]
theorem sqrt_le_iff : √x ≤ y ↔ 0 ≤ y ∧ x ≤ y ^ 2 := by
rw [← and_iff_right_of_imp fun h => (sqrt_nonneg x).trans h, and_congr_right_iff]
exact sqrt_le_left
theorem sqrt_lt (hx : 0 ≤ x) (hy : 0 ≤ y) : √x < y ↔ x < y ^ 2 := by
rw [← sqrt_lt_sqrt_iff hx, sqrt_sq hy]
theorem sqrt_lt' (hy : 0 < y) : √x < y ↔ x < y ^ 2 := by
rw [← sqrt_lt_sqrt_iff_of_pos (pow_pos hy _), sqrt_sq hy.le]
/-- Note: if you want to conclude `x ≤ √y`, then use `Real.le_sqrt_of_sq_le`.
If you have `x > 0`, consider using `Real.le_sqrt'` -/
theorem le_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x ≤ √y ↔ x ^ 2 ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| sqrt_lt hy hx
theorem le_sqrt' (hx : 0 < x) : x ≤ √y ↔ x ^ 2 ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| sqrt_lt' hx
theorem abs_le_sqrt (h : x ^ 2 ≤ y) : |x| ≤ √y := by
rw [← sqrt_sq_eq_abs]; exact sqrt_le_sqrt h
theorem sq_le (h : 0 ≤ y) : x ^ 2 ≤ y ↔ -√y ≤ x ∧ x ≤ √y := by
constructor
· simpa only [abs_le] using abs_le_sqrt
· rw [← abs_le, ← sq_abs]
exact (le_sqrt (abs_nonneg x) h).mp
theorem neg_sqrt_le_of_sq_le (h : x ^ 2 ≤ y) : -√y ≤ x :=
((sq_le ((sq_nonneg x).trans h)).mp h).1
theorem le_sqrt_of_sq_le (h : x ^ 2 ≤ y) : x ≤ √y :=
((sq_le ((sq_nonneg x).trans h)).mp h).2
@[simp]
theorem sqrt_inj (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = √y ↔ x = y := by
simp [le_antisymm_iff, hx, hy]
@[simp]
theorem sqrt_eq_zero (h : 0 ≤ x) : √x = 0 ↔ x = 0 := by simpa using sqrt_inj h le_rfl
theorem sqrt_eq_zero' : √x = 0 ↔ x ≤ 0 := by
rw [sqrt, NNReal.coe_eq_zero, NNReal.sqrt_eq_zero, Real.toNNReal_eq_zero]
theorem sqrt_ne_zero (h : 0 ≤ x) : √x ≠ 0 ↔ x ≠ 0 := by rw [not_iff_not, sqrt_eq_zero h]
theorem sqrt_ne_zero' : √x ≠ 0 ↔ 0 < x := by rw [← not_le, not_iff_not, sqrt_eq_zero']
@[simp]
theorem sqrt_pos : 0 < √x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le (Iff.trans (by simp [le_antisymm_iff, sqrt_nonneg]) sqrt_eq_zero')
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
lemma sqrt_le_sqrt_iff' (hx : 0 < x) : √x ≤ √y ↔ x ≤ y := by
obtain hy | hy := le_total y 0
· exact iff_of_false ((sqrt_eq_zero_of_nonpos hy).trans_lt <| sqrt_pos.2 hx).not_le
(hy.trans_lt hx).not_le
· exact sqrt_le_sqrt_iff hy
@[simp] lemma one_le_sqrt : 1 ≤ √x ↔ 1 ≤ x := by
rw [← sqrt_one, sqrt_le_sqrt_iff' zero_lt_one, sqrt_one]
@[simp] lemma sqrt_le_one : √x ≤ 1 ↔ x ≤ 1 := by
rw [← sqrt_one, sqrt_le_sqrt_iff zero_le_one, sqrt_one]
end Real
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
/-- Extension for the `positivity` tactic: a square root of a strictly positive nonnegative real is
positive. -/
@[positivity NNReal.sqrt _]
def evalNNRealSqrt : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(NNReal), ~q(NNReal.sqrt $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(NNReal.sqrt_pos_of_pos $pa))
| _ => failure -- this case is dealt with by generic nonnegativity of nnreals
| _, _, _ => throwError "not NNReal.sqrt"
/-- Extension for the `positivity` tactic: a square root is nonnegative, and is strictly positive if
its input is. -/
@[positivity √_]
def evalSqrt : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(√$a) =>
let ra ← catchNone <| core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(Real.sqrt_pos_of_pos $pa))
| _ => pure (.nonnegative q(Real.sqrt_nonneg $a))
| _, _, _ => throwError "not Real.sqrt"
end Mathlib.Meta.Positivity
namespace Real
@[simp]
theorem sqrt_mul {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : √(x * y) = √x * √y := by
simp_rw [Real.sqrt, ← NNReal.coe_mul, NNReal.coe_inj, Real.toNNReal_mul hx, NNReal.sqrt_mul]
@[simp]
theorem sqrt_mul' (x) {y : ℝ} (hy : 0 ≤ y) : √(x * y) = √x * √y := by
rw [mul_comm, sqrt_mul hy, mul_comm]
@[simp]
theorem sqrt_inv (x : ℝ) : √x⁻¹ = (√x)⁻¹ := by
rw [Real.sqrt, Real.toNNReal_inv, NNReal.sqrt_inv, NNReal.coe_inv, Real.sqrt]
@[simp]
theorem sqrt_div {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : √(x / y) = √x / √y := by
rw [division_def, sqrt_mul hx, sqrt_inv, division_def]
@[simp]
theorem sqrt_div' (x) {y : ℝ} (hy : 0 ≤ y) : √(x / y) = √x / √y := by
rw [division_def, sqrt_mul' x (inv_nonneg.2 hy), sqrt_inv, division_def]
variable {x y : ℝ}
@[simp]
theorem div_sqrt : x / √x = √x := by
rcases le_or_lt x 0 with h | h
· rw [sqrt_eq_zero'.mpr h, div_zero]
· rw [div_eq_iff (sqrt_ne_zero'.mpr h), mul_self_sqrt h.le]
theorem sqrt_div_self' : √x / x = 1 / √x := by rw [← div_sqrt, one_div_div, div_sqrt]
theorem sqrt_div_self : √x / x = (√x)⁻¹ := by rw [sqrt_div_self', one_div]
theorem lt_sqrt (hx : 0 ≤ x) : x < √y ↔ x ^ 2 < y := by
rw [← sqrt_lt_sqrt_iff (sq_nonneg _), sqrt_sq hx]
theorem sq_lt : x ^ 2 < y ↔ -√y < x ∧ x < √y := by
rw [← abs_lt, ← sq_abs, lt_sqrt (abs_nonneg _)]
theorem neg_sqrt_lt_of_sq_lt (h : x ^ 2 < y) : -√y < x :=
(sq_lt.mp h).1
theorem lt_sqrt_of_sq_lt (h : x ^ 2 < y) : x < √y :=
(sq_lt.mp h).2
theorem lt_sq_of_sqrt_lt (h : √x < y) : x < y ^ 2 := by
have hy := x.sqrt_nonneg.trans_lt h
rwa [← sqrt_lt_sqrt_iff_of_pos (sq_pos_of_pos hy), sqrt_sq hy.le]
/-- The natural square root is at most the real square root -/
theorem nat_sqrt_le_real_sqrt {a : ℕ} : ↑(Nat.sqrt a) ≤ √(a : ℝ) := by
rw [Real.le_sqrt (Nat.cast_nonneg _) (Nat.cast_nonneg _)]
norm_cast
exact Nat.sqrt_le' a
/-- The real square root is less than the natural square root plus one -/
theorem real_sqrt_lt_nat_sqrt_succ {a : ℕ} : √(a : ℝ) < Nat.sqrt a + 1 := by
rw [sqrt_lt (by simp)] <;> norm_cast
· exact Nat.lt_succ_sqrt' a
· exact Nat.le_add_left 0 (Nat.sqrt a + 1)
/-- The real square root is at most the natural square root plus one -/
theorem real_sqrt_le_nat_sqrt_succ {a : ℕ} : √(a : ℝ) ≤ Nat.sqrt a + 1 :=
real_sqrt_lt_nat_sqrt_succ.le
/-- The floor of the real square root is the same as the natural square root. -/
@[simp]
theorem floor_real_sqrt_eq_nat_sqrt {a : ℕ} : ⌊√(a : ℝ)⌋ = Nat.sqrt a := by
rw [Int.floor_eq_iff]
exact ⟨nat_sqrt_le_real_sqrt, real_sqrt_lt_nat_sqrt_succ⟩
/-- The natural floor of the real square root is the same as the natural square root. -/
@[simp]
theorem nat_floor_real_sqrt_eq_nat_sqrt {a : ℕ} : ⌊√(a : ℝ)⌋₊ = Nat.sqrt a := by
rw [Nat.floor_eq_iff (sqrt_nonneg a)]
exact ⟨nat_sqrt_le_real_sqrt, real_sqrt_lt_nat_sqrt_succ⟩
/-- Bernoulli's inequality for exponent `1 / 2`, stated using `sqrt`. -/
theorem sqrt_one_add_le (h : -1 ≤ x) : √(1 + x) ≤ 1 + x / 2 := by
refine sqrt_le_iff.mpr ⟨by linarith, ?_⟩
calc 1 + x
_ ≤ 1 + x + (x / 2) ^ 2 := le_add_of_nonneg_right <| sq_nonneg _
_ = _ := by ring
end Real
open Real
variable {α : Type*}
theorem Filter.Tendsto.sqrt {f : α → ℝ} {l : Filter α} {x : ℝ} (h : Tendsto f l (𝓝 x)) :
Tendsto (fun x => √(f x)) l (𝓝 (√x)) :=
(continuous_sqrt.tendsto _).comp h
variable [TopologicalSpace α] {f : α → ℝ} {s : Set α} {x : α}
nonrec theorem ContinuousWithinAt.sqrt (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (fun x => √(f x)) s x :=
h.sqrt
@[fun_prop]
nonrec theorem ContinuousAt.sqrt (h : ContinuousAt f x) : ContinuousAt (fun x => √(f x)) x :=
h.sqrt
@[fun_prop]
theorem ContinuousOn.sqrt (h : ContinuousOn f s) : ContinuousOn (fun x => √(f x)) s :=
fun x hx => (h x hx).sqrt
@[continuity, fun_prop]
theorem Continuous.sqrt (h : Continuous f) : Continuous fun x => √(f x) :=
continuous_sqrt.comp h
namespace NNReal
| variable {ι : Type*}
| Mathlib/Data/Real/Sqrt.lean | 413 | 413 |
/-
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 :=
| Mathlib/Topology/Order/DenselyOrdered.lean | 75 | 79 |
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, François Dupuis
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Order.Filter.Extr
import Mathlib.Tactic.NormNum
/-!
# Convex and concave functions
This file defines convex and concave functions in vector spaces and proves the finite Jensen
inequality. The integral version can be found in `Analysis.Convex.Integral`.
A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two
points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`.
Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is
a convex set.
## Main declarations
* `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`.
* `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`.
* `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`.
* `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`.
-/
open LinearMap Set Convex Pointwise
variable {𝕜 E F α β ι : Type*}
section OrderedSemiring
variable [Semiring 𝕜] [PartialOrder 𝕜]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section OrderedAddCommMonoid
variable [AddCommMonoid α] [PartialOrder α] [AddCommMonoid β] [PartialOrder β]
section SMul
variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α}
/-- Convexity of functions -/
def ConvexOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
f (a • x + b • y) ≤ a • f x + b • f y
/-- Concavity of functions -/
def ConcaveOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
a • f x + b • f y ≤ f (a • x + b • y)
/-- Strict convexity of functions -/
def StrictConvexOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
f (a • x + b • y) < a • f x + b • f y
/-- Strict concavity of functions -/
def StrictConcaveOn : Prop :=
Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 →
a • f x + b • f y < f (a • x + b • y)
variable {𝕜 s f}
open OrderDual (toDual ofDual)
theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf
theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf
theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf
theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf
theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id :=
⟨hs, by
intros
rfl⟩
theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id :=
⟨hs, by
intros
rfl⟩
section congr
variable {g : E → β}
theorem ConvexOn.congr (hf : ConvexOn 𝕜 s f) (hfg : EqOn f g s) : ConvexOn 𝕜 s g :=
⟨hf.1, fun x hx y hy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩
theorem ConcaveOn.congr (hf : ConcaveOn 𝕜 s f) (hfg : EqOn f g s) : ConcaveOn 𝕜 s g :=
⟨hf.1, fun x hx y hy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩
theorem StrictConvexOn.congr (hf : StrictConvexOn 𝕜 s f) (hfg : EqOn f g s) :
StrictConvexOn 𝕜 s g :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using
hf.2 hx hy hxy ha hb hab⟩
theorem StrictConcaveOn.congr (hf : StrictConcaveOn 𝕜 s f) (hfg : EqOn f g s) :
StrictConcaveOn 𝕜 s g :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using
hf.2 hx hy hxy ha hb hab⟩
end congr
theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) :
ConvexOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) :
ConcaveOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t)
(hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t)
(hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f :=
⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩
theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f)
(hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy _ _ ha hb hab =>
(hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab)
(hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <|
hf.2 hx hy ha hb hab).trans <|
hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩
theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f)
(hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy _ _ ha hb hab =>
(hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <|
hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab)
(mem_image_of_mem f <| hf.1 hx hy ha hb hab) <|
hf.2 hx hy ha hb hab⟩
theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f)
(hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg'
theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f)
(hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg'
theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f)
(hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab =>
(hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab)
(hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <|
hf.2 hx hy hxy ha hb hab).trans <|
hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩
theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f)
(hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) :=
⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab =>
(hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <|
hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab)
(mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <|
hf.2 hx hy hxy ha hb hab⟩
theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g)
(hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) :
StrictConvexOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg' hf'
theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g)
(hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) :
StrictConcaveOn 𝕜 s (g ∘ f) :=
hg.dual.comp hf hg' hf'
end SMul
section DistribMulAction
variable [IsOrderedAddMonoid β] [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β}
| theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) :=
⟨hf.1, fun x hx y hy a b ha hb hab =>
calc
f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) :=
add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
_ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]
⟩
| Mathlib/Analysis/Convex/Function.lean | 189 | 195 |
/-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# Left Homology of short complexes
Given a short complex `S : ShortComplex C`, which consists of two composable
maps `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`, we shall define
here the "left homology" `S.leftHomology` of `S`. For this, we introduce the
notion of "left homology data". Such an `h : S.LeftHomologyData` consists of the
data of morphisms `i : K ⟶ X₂` and `π : K ⟶ H` such that `i` identifies
`K` with the kernel of `g : X₂ ⟶ X₃`, and that `π` identifies `H` with the cokernel
of the induced map `f' : X₁ ⟶ K`.
When such a `S.LeftHomologyData` exists, we shall say that `[S.HasLeftHomology]`
and we define `S.leftHomology` to be the `H` field of a chosen left homology data.
Similarly, we define `S.cycles` to be the `K` field.
The dual notion is defined in `RightHomologyData.lean`. In `Homology.lean`,
when `S` has two compatible left and right homology data (i.e. they give
the same `H` up to a canonical isomorphism), we shall define `[S.HasHomology]`
and `S.homology`.
-/
namespace CategoryTheory
open Category Limits
namespace ShortComplex
variable {C : Type*} [Category C] [HasZeroMorphisms C] (S : ShortComplex C)
{S₁ S₂ S₃ : ShortComplex C}
/-- A left homology data for a short complex `S` consists of morphisms `i : K ⟶ S.X₂` and
`π : K ⟶ H` such that `i` identifies `K` to the kernel of `g : S.X₂ ⟶ S.X₃`,
and that `π` identifies `H` to the cokernel of the induced map `f' : S.X₁ ⟶ K` -/
structure LeftHomologyData where
/-- a choice of kernel of `S.g : S.X₂ ⟶ S.X₃` -/
K : C
/-- a choice of cokernel of the induced morphism `S.f' : S.X₁ ⟶ K` -/
H : C
/-- the inclusion of cycles in `S.X₂` -/
i : K ⟶ S.X₂
/-- the projection from cycles to the (left) homology -/
π : K ⟶ H
/-- the kernel condition for `i` -/
wi : i ≫ S.g = 0
/-- `i : K ⟶ S.X₂` is a kernel of `g : S.X₂ ⟶ S.X₃` -/
hi : IsLimit (KernelFork.ofι i wi)
/-- the cokernel condition for `π` -/
wπ : hi.lift (KernelFork.ofι _ S.zero) ≫ π = 0
/-- `π : K ⟶ H` is a cokernel of the induced morphism `S.f' : S.X₁ ⟶ K` -/
hπ : IsColimit (CokernelCofork.ofπ π wπ)
initialize_simps_projections LeftHomologyData (-hi, -hπ)
namespace LeftHomologyData
/-- The chosen kernels and cokernels of the limits API give a `LeftHomologyData` -/
@[simps]
noncomputable def ofHasKernelOfHasCokernel
[HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] :
S.LeftHomologyData where
K := kernel S.g
H := cokernel (kernel.lift S.g S.f S.zero)
i := kernel.ι _
π := cokernel.π _
wi := kernel.condition _
hi := kernelIsKernel _
wπ := cokernel.condition _
hπ := cokernelIsCokernel _
attribute [reassoc (attr := simp)] wi wπ
variable {S}
variable (h : S.LeftHomologyData) {A : C}
instance : Mono h.i := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hi⟩
instance : Epi h.π := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hπ⟩
/-- Any morphism `k : A ⟶ S.X₂` that is a cycle (i.e. `k ≫ S.g = 0`) lifts
to a morphism `A ⟶ K` -/
def liftK (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) : A ⟶ h.K := h.hi.lift (KernelFork.ofι k hk)
@[reassoc (attr := simp)]
lemma liftK_i (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) : h.liftK k hk ≫ h.i = k :=
h.hi.fac _ WalkingParallelPair.zero
/-- The (left) homology class `A ⟶ H` attached to a cycle `k : A ⟶ S.X₂` -/
@[simp]
def liftH (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0) : A ⟶ h.H := h.liftK k hk ≫ h.π
/-- Given `h : LeftHomologyData S`, this is morphism `S.X₁ ⟶ h.K` induced
by `S.f : S.X₁ ⟶ S.X₂` and the fact that `h.K` is a kernel of `S.g : S.X₂ ⟶ S.X₃`. -/
def f' : S.X₁ ⟶ h.K := h.liftK S.f S.zero
@[reassoc (attr := simp)] lemma f'_i : h.f' ≫ h.i = S.f := liftK_i _ _ _
@[reassoc (attr := simp)] lemma f'_π : h.f' ≫ h.π = 0 := h.wπ
@[reassoc]
lemma liftK_π_eq_zero_of_boundary (k : A ⟶ S.X₂) (x : A ⟶ S.X₁) (hx : k = x ≫ S.f) :
h.liftK k (by rw [hx, assoc, S.zero, comp_zero]) ≫ h.π = 0 := by
rw [show 0 = (x ≫ h.f') ≫ h.π by simp]
congr 1
simp only [← cancel_mono h.i, hx, liftK_i, assoc, f'_i]
/-- For `h : S.LeftHomologyData`, this is a restatement of `h.hπ`, saying that
`π : h.K ⟶ h.H` is a cokernel of `h.f' : S.X₁ ⟶ h.K`. -/
def hπ' : IsColimit (CokernelCofork.ofπ h.π h.f'_π) := h.hπ
/-- The morphism `H ⟶ A` induced by a morphism `k : K ⟶ A` such that `f' ≫ k = 0` -/
def descH (k : h.K ⟶ A) (hk : h.f' ≫ k = 0) : h.H ⟶ A :=
h.hπ.desc (CokernelCofork.ofπ k hk)
@[reassoc (attr := simp)]
lemma π_descH (k : h.K ⟶ A) (hk : h.f' ≫ k = 0) : h.π ≫ h.descH k hk = k :=
h.hπ.fac (CokernelCofork.ofπ k hk) WalkingParallelPair.one
lemma isIso_i (hg : S.g = 0) : IsIso h.i :=
⟨h.liftK (𝟙 S.X₂) (by rw [hg, id_comp]),
by simp only [← cancel_mono h.i, id_comp, assoc, liftK_i, comp_id], liftK_i _ _ _⟩
lemma isIso_π (hf : S.f = 0) : IsIso h.π := by
have ⟨φ, hφ⟩ := CokernelCofork.IsColimit.desc' h.hπ' (𝟙 _)
(by rw [← cancel_mono h.i, comp_id, f'_i, zero_comp, hf])
dsimp at hφ
exact ⟨φ, hφ, by rw [← cancel_epi h.π, reassoc_of% hφ, comp_id]⟩
variable (S)
/-- When the second map `S.g` is zero, this is the left homology data on `S` given
by any colimit cokernel cofork of `S.f` -/
@[simps]
def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) :
S.LeftHomologyData where
K := S.X₂
H := c.pt
i := 𝟙 _
π := c.π
wi := by rw [id_comp, hg]
hi := KernelFork.IsLimit.ofId _ hg
wπ := CokernelCofork.condition _
hπ := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _))
@[simp] lemma ofIsColimitCokernelCofork_f' (hg : S.g = 0) (c : CokernelCofork S.f)
(hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).f' = S.f := by
rw [← cancel_mono (ofIsColimitCokernelCofork S hg c hc).i, f'_i,
ofIsColimitCokernelCofork_i]
dsimp
rw [comp_id]
/-- When the second map `S.g` is zero, this is the left homology data on `S` given by
the chosen `cokernel S.f` -/
@[simps!]
noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.LeftHomologyData :=
ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _)
/-- When the first map `S.f` is zero, this is the left homology data on `S` given
by any limit kernel fork of `S.g` -/
@[simps]
def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) :
S.LeftHomologyData where
K := c.pt
H := c.pt
i := c.ι
π := 𝟙 _
wi := KernelFork.condition _
hi := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _))
wπ := Fork.IsLimit.hom_ext hc (by
dsimp
simp only [comp_id, zero_comp, Fork.IsLimit.lift_ι, Fork.ι_ofι, hf])
hπ := CokernelCofork.IsColimit.ofId _ (Fork.IsLimit.hom_ext hc (by
dsimp
simp only [comp_id, zero_comp, Fork.IsLimit.lift_ι, Fork.ι_ofι, hf]))
@[simp] lemma ofIsLimitKernelFork_f' (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) :
(ofIsLimitKernelFork S hf c hc).f' = 0 := by
rw [← cancel_mono (ofIsLimitKernelFork S hf c hc).i, f'_i, hf, zero_comp]
/-- When the first map `S.f` is zero, this is the left homology data on `S` given
by the chosen `kernel S.g` -/
@[simp]
noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.LeftHomologyData :=
ofIsLimitKernelFork S hf _ (kernelIsKernel _)
/-- When both `S.f` and `S.g` are zero, the middle object `S.X₂` gives a left homology data on S -/
@[simps]
def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.LeftHomologyData where
K := S.X₂
H := S.X₂
i := 𝟙 _
π := 𝟙 _
wi := by rw [id_comp, hg]
hi := KernelFork.IsLimit.ofId _ hg
wπ := by
change S.f ≫ 𝟙 _ = 0
simp only [hf, zero_comp]
hπ := CokernelCofork.IsColimit.ofId _ hf
@[simp] lemma ofZeros_f' (hf : S.f = 0) (hg : S.g = 0) :
(ofZeros S hf hg).f' = 0 := by
rw [← cancel_mono ((ofZeros S hf hg).i), zero_comp, f'_i, hf]
end LeftHomologyData
/-- A short complex `S` has left homology when there exists a `S.LeftHomologyData` -/
class HasLeftHomology : Prop where
condition : Nonempty S.LeftHomologyData
/-- A chosen `S.LeftHomologyData` for a short complex `S` that has left homology -/
noncomputable def leftHomologyData [S.HasLeftHomology] :
S.LeftHomologyData := HasLeftHomology.condition.some
variable {S}
namespace HasLeftHomology
lemma mk' (h : S.LeftHomologyData) : HasLeftHomology S := ⟨Nonempty.intro h⟩
instance of_hasKernel_of_hasCokernel [HasKernel S.g] [HasCokernel (kernel.lift S.g S.f S.zero)] :
S.HasLeftHomology := HasLeftHomology.mk' (LeftHomologyData.ofHasKernelOfHasCokernel S)
instance of_hasCokernel {X Y : C} (f : X ⟶ Y) (Z : C) [HasCokernel f] :
(ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).HasLeftHomology :=
HasLeftHomology.mk' (LeftHomologyData.ofHasCokernel _ rfl)
instance of_hasKernel {Y Z : C} (g : Y ⟶ Z) (X : C) [HasKernel g] :
(ShortComplex.mk (0 : X ⟶ Y) g zero_comp).HasLeftHomology :=
HasLeftHomology.mk' (LeftHomologyData.ofHasKernel _ rfl)
instance of_zeros (X Y Z : C) :
(ShortComplex.mk (0 : X ⟶ Y) (0 : Y ⟶ Z) zero_comp).HasLeftHomology :=
HasLeftHomology.mk' (LeftHomologyData.ofZeros _ rfl rfl)
end HasLeftHomology
section
variable (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData)
/-- Given left homology data `h₁` and `h₂` for two short complexes `S₁` and `S₂`,
a `LeftHomologyMapData` for a morphism `φ : S₁ ⟶ S₂`
consists of a description of the induced morphisms on the `K` (cycles)
and `H` (left homology) fields of `h₁` and `h₂`. -/
structure LeftHomologyMapData where
/-- the induced map on cycles -/
φK : h₁.K ⟶ h₂.K
/-- the induced map on left homology -/
φH : h₁.H ⟶ h₂.H
/-- commutation with `i` -/
commi : φK ≫ h₂.i = h₁.i ≫ φ.τ₂ := by aesop_cat
/-- commutation with `f'` -/
commf' : h₁.f' ≫ φK = φ.τ₁ ≫ h₂.f' := by aesop_cat
/-- commutation with `π` -/
commπ : h₁.π ≫ φH = φK ≫ h₂.π := by aesop_cat
namespace LeftHomologyMapData
attribute [reassoc (attr := simp)] commi commf' commπ
/-- The left homology map data associated to the zero morphism between two short complexes. -/
@[simps]
def zero (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) :
LeftHomologyMapData 0 h₁ h₂ where
φK := 0
φH := 0
/-- The left homology map data associated to the identity morphism of a short complex. -/
@[simps]
def id (h : S.LeftHomologyData) : LeftHomologyMapData (𝟙 S) h h where
φK := 𝟙 _
φH := 𝟙 _
/-- The composition of left homology map data. -/
@[simps]
def comp {φ : S₁ ⟶ S₂} {φ' : S₂ ⟶ S₃}
{h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData} {h₃ : S₃.LeftHomologyData}
(ψ : LeftHomologyMapData φ h₁ h₂) (ψ' : LeftHomologyMapData φ' h₂ h₃) :
LeftHomologyMapData (φ ≫ φ') h₁ h₃ where
φK := ψ.φK ≫ ψ'.φK
φH := ψ.φH ≫ ψ'.φH
instance : Subsingleton (LeftHomologyMapData φ h₁ h₂) :=
⟨fun ψ₁ ψ₂ => by
have hK : ψ₁.φK = ψ₂.φK := by rw [← cancel_mono h₂.i, commi, commi]
have hH : ψ₁.φH = ψ₂.φH := by rw [← cancel_epi h₁.π, commπ, commπ, hK]
cases ψ₁
cases ψ₂
congr⟩
instance : Inhabited (LeftHomologyMapData φ h₁ h₂) := ⟨by
let φK : h₁.K ⟶ h₂.K := h₂.liftK (h₁.i ≫ φ.τ₂)
(by rw [assoc, φ.comm₂₃, h₁.wi_assoc, zero_comp])
have commf' : h₁.f' ≫ φK = φ.τ₁ ≫ h₂.f' := by
rw [← cancel_mono h₂.i, assoc, assoc, LeftHomologyData.liftK_i,
LeftHomologyData.f'_i_assoc, LeftHomologyData.f'_i, φ.comm₁₂]
let φH : h₁.H ⟶ h₂.H := h₁.descH (φK ≫ h₂.π)
(by rw [reassoc_of% commf', h₂.f'_π, comp_zero])
exact ⟨φK, φH, by simp [φK], commf', by simp [φH]⟩⟩
instance : Unique (LeftHomologyMapData φ h₁ h₂) := Unique.mk' _
variable {φ h₁ h₂}
lemma congr_φH {γ₁ γ₂ : LeftHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φH = γ₂.φH := by rw [eq]
lemma congr_φK {γ₁ γ₂ : LeftHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φK = γ₂.φK := by rw [eq]
/-- When `S₁.f`, `S₁.g`, `S₂.f` and `S₂.g` are all zero, the action on left homology of a
morphism `φ : S₁ ⟶ S₂` is given by the action `φ.τ₂` on the middle objects. -/
@[simps]
def ofZeros (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) :
LeftHomologyMapData φ (LeftHomologyData.ofZeros S₁ hf₁ hg₁)
(LeftHomologyData.ofZeros S₂ hf₂ hg₂) where
φK := φ.τ₂
φH := φ.τ₂
/-- When `S₁.g` and `S₂.g` are zero and we have chosen colimit cokernel coforks `c₁` and `c₂`
for `S₁.f` and `S₂.f` respectively, the action on left homology of a morphism `φ : S₁ ⟶ S₂` of
short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that
`φ.τ₂ ≫ c₂.π = c₁.π ≫ f`. -/
@[simps]
def ofIsColimitCokernelCofork (φ : S₁ ⟶ S₂)
(hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁)
(hg₂ : S₂.g = 0) (c₂ : CokernelCofork S₂.f) (hc₂ : IsColimit c₂) (f : c₁.pt ⟶ c₂.pt)
(comm : φ.τ₂ ≫ c₂.π = c₁.π ≫ f) :
LeftHomologyMapData φ (LeftHomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁)
(LeftHomologyData.ofIsColimitCokernelCofork S₂ hg₂ c₂ hc₂) where
φK := φ.τ₂
φH := f
commπ := comm.symm
commf' := by simp only [LeftHomologyData.ofIsColimitCokernelCofork_f', φ.comm₁₂]
/-- When `S₁.f` and `S₂.f` are zero and we have chosen limit kernel forks `c₁` and `c₂`
for `S₁.g` and `S₂.g` respectively, the action on left homology of a morphism `φ : S₁ ⟶ S₂` of
short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that
`c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι`. -/
@[simps]
def ofIsLimitKernelFork (φ : S₁ ⟶ S₂)
(hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁)
(hf₂ : S₂.f = 0) (c₂ : KernelFork S₂.g) (hc₂ : IsLimit c₂) (f : c₁.pt ⟶ c₂.pt)
(comm : c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι) :
LeftHomologyMapData φ (LeftHomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁)
(LeftHomologyData.ofIsLimitKernelFork S₂ hf₂ c₂ hc₂) where
φK := f
φH := f
commi := comm.symm
variable (S)
/-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the left homology map
data (for the identity of `S`) which relates the left homology data `ofZeros` and
`ofIsColimitCokernelCofork`. -/
@[simps]
def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0)
(c : CokernelCofork S.f) (hc : IsColimit c) :
LeftHomologyMapData (𝟙 S) (LeftHomologyData.ofZeros S hf hg)
(LeftHomologyData.ofIsColimitCokernelCofork S hg c hc) where
φK := 𝟙 _
φH := c.π
/-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the left homology map
data (for the identity of `S`) which relates the left homology data
`LeftHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/
@[simps]
def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0)
(c : KernelFork S.g) (hc : IsLimit c) :
LeftHomologyMapData (𝟙 S) (LeftHomologyData.ofIsLimitKernelFork S hf c hc)
(LeftHomologyData.ofZeros S hf hg) where
φK := c.ι
φH := c.ι
end LeftHomologyMapData
end
section
variable (S)
variable [S.HasLeftHomology]
/-- The left homology of a short complex, given by the `H` field of a chosen left homology data. -/
noncomputable def leftHomology : C := S.leftHomologyData.H
-- `S.leftHomology` is the simp normal form.
@[simp] lemma leftHomologyData_H : S.leftHomologyData.H = S.leftHomology := rfl
/-- The cycles of a short complex, given by the `K` field of a chosen left homology data. -/
noncomputable def cycles : C := S.leftHomologyData.K
/-- The "homology class" map `S.cycles ⟶ S.leftHomology`. -/
noncomputable def leftHomologyπ : S.cycles ⟶ S.leftHomology := S.leftHomologyData.π
/-- The inclusion `S.cycles ⟶ S.X₂`. -/
noncomputable def iCycles : S.cycles ⟶ S.X₂ := S.leftHomologyData.i
/-- The "boundaries" map `S.X₁ ⟶ S.cycles`. (Note that in this homology API, we make no use
of the "image" of this morphism, which under some categorical assumptions would be a subobject
of `S.X₂` contained in `S.cycles`.) -/
noncomputable def toCycles : S.X₁ ⟶ S.cycles := S.leftHomologyData.f'
@[reassoc (attr := simp)]
lemma iCycles_g : S.iCycles ≫ S.g = 0 := S.leftHomologyData.wi
@[reassoc (attr := simp)]
lemma toCycles_i : S.toCycles ≫ S.iCycles = S.f := S.leftHomologyData.f'_i
instance : Mono S.iCycles := by
dsimp only [iCycles]
infer_instance
instance : Epi S.leftHomologyπ := by
dsimp only [leftHomologyπ]
infer_instance
lemma leftHomology_ext_iff {A : C} (f₁ f₂ : S.leftHomology ⟶ A) :
f₁ = f₂ ↔ S.leftHomologyπ ≫ f₁ = S.leftHomologyπ ≫ f₂ := by
rw [cancel_epi]
@[ext]
lemma leftHomology_ext {A : C} (f₁ f₂ : S.leftHomology ⟶ A)
(h : S.leftHomologyπ ≫ f₁ = S.leftHomologyπ ≫ f₂) : f₁ = f₂ := by
simpa only [leftHomology_ext_iff] using h
lemma cycles_ext_iff {A : C} (f₁ f₂ : A ⟶ S.cycles) :
f₁ = f₂ ↔ f₁ ≫ S.iCycles = f₂ ≫ S.iCycles := by
rw [cancel_mono]
@[ext]
lemma cycles_ext {A : C} (f₁ f₂ : A ⟶ S.cycles) (h : f₁ ≫ S.iCycles = f₂ ≫ S.iCycles) :
f₁ = f₂ := by
simpa only [cycles_ext_iff] using h
lemma isIso_iCycles (hg : S.g = 0) : IsIso S.iCycles :=
LeftHomologyData.isIso_i _ hg
/-- When `S.g = 0`, this is the canonical isomorphism `S.cycles ≅ S.X₂` induced by `S.iCycles`. -/
@[simps! hom]
noncomputable def cyclesIsoX₂ (hg : S.g = 0) : S.cycles ≅ S.X₂ := by
have := S.isIso_iCycles hg
exact asIso S.iCycles
@[reassoc (attr := simp)]
lemma cyclesIsoX₂_hom_inv_id (hg : S.g = 0) :
S.iCycles ≫ (S.cyclesIsoX₂ hg).inv = 𝟙 _ := (S.cyclesIsoX₂ hg).hom_inv_id
@[reassoc (attr := simp)]
lemma cyclesIsoX₂_inv_hom_id (hg : S.g = 0) :
(S.cyclesIsoX₂ hg).inv ≫ S.iCycles = 𝟙 _ := (S.cyclesIsoX₂ hg).inv_hom_id
lemma isIso_leftHomologyπ (hf : S.f = 0) : IsIso S.leftHomologyπ :=
LeftHomologyData.isIso_π _ hf
/-- When `S.f = 0`, this is the canonical isomorphism `S.cycles ≅ S.leftHomology` induced
by `S.leftHomologyπ`. -/
@[simps! hom]
noncomputable def cyclesIsoLeftHomology (hf : S.f = 0) : S.cycles ≅ S.leftHomology := by
have := S.isIso_leftHomologyπ hf
exact asIso S.leftHomologyπ
@[reassoc (attr := simp)]
lemma cyclesIsoLeftHomology_hom_inv_id (hf : S.f = 0) :
S.leftHomologyπ ≫ (S.cyclesIsoLeftHomology hf).inv = 𝟙 _ :=
(S.cyclesIsoLeftHomology hf).hom_inv_id
@[reassoc (attr := simp)]
lemma cyclesIsoLeftHomology_inv_hom_id (hf : S.f = 0) :
(S.cyclesIsoLeftHomology hf).inv ≫ S.leftHomologyπ = 𝟙 _ :=
(S.cyclesIsoLeftHomology hf).inv_hom_id
end
section
variable (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData)
/-- The (unique) left homology map data associated to a morphism of short complexes that
are both equipped with left homology data. -/
def leftHomologyMapData : LeftHomologyMapData φ h₁ h₂ := default
/-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and left homology data `h₁` and `h₂`
for `S₁` and `S₂` respectively, this is the induced left homology map `h₁.H ⟶ h₁.H`. -/
def leftHomologyMap' : h₁.H ⟶ h₂.H := (leftHomologyMapData φ _ _).φH
/-- Given a morphism `φ : S₁ ⟶ S₂` of short complexes and left homology data `h₁` and `h₂`
for `S₁` and `S₂` respectively, this is the induced morphism `h₁.K ⟶ h₁.K` on cycles. -/
def cyclesMap' : h₁.K ⟶ h₂.K := (leftHomologyMapData φ _ _).φK
@[reassoc (attr := simp)]
lemma cyclesMap'_i : cyclesMap' φ h₁ h₂ ≫ h₂.i = h₁.i ≫ φ.τ₂ :=
LeftHomologyMapData.commi _
@[reassoc (attr := simp)]
lemma f'_cyclesMap' : h₁.f' ≫ cyclesMap' φ h₁ h₂ = φ.τ₁ ≫ h₂.f' := by
simp only [← cancel_mono h₂.i, assoc, φ.comm₁₂, cyclesMap'_i,
LeftHomologyData.f'_i_assoc, LeftHomologyData.f'_i]
@[reassoc (attr := simp)]
lemma leftHomologyπ_naturality' :
h₁.π ≫ leftHomologyMap' φ h₁ h₂ = cyclesMap' φ h₁ h₂ ≫ h₂.π :=
LeftHomologyMapData.commπ _
end
section
variable [HasLeftHomology S₁] [HasLeftHomology S₂] (φ : S₁ ⟶ S₂)
/-- The (left) homology map `S₁.leftHomology ⟶ S₂.leftHomology` induced by a morphism
`S₁ ⟶ S₂` of short complexes. -/
noncomputable def leftHomologyMap : S₁.leftHomology ⟶ S₂.leftHomology :=
leftHomologyMap' φ _ _
/-- The morphism `S₁.cycles ⟶ S₂.cycles` induced by a morphism `S₁ ⟶ S₂` of short complexes. -/
noncomputable def cyclesMap : S₁.cycles ⟶ S₂.cycles := cyclesMap' φ _ _
@[reassoc (attr := simp)]
lemma cyclesMap_i : cyclesMap φ ≫ S₂.iCycles = S₁.iCycles ≫ φ.τ₂ :=
cyclesMap'_i _ _ _
@[reassoc (attr := simp)]
lemma toCycles_naturality : S₁.toCycles ≫ cyclesMap φ = φ.τ₁ ≫ S₂.toCycles :=
f'_cyclesMap' _ _ _
@[reassoc (attr := simp)]
lemma leftHomologyπ_naturality :
S₁.leftHomologyπ ≫ leftHomologyMap φ = cyclesMap φ ≫ S₂.leftHomologyπ :=
leftHomologyπ_naturality' _ _ _
end
namespace LeftHomologyMapData
variable {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData}
(γ : LeftHomologyMapData φ h₁ h₂)
lemma leftHomologyMap'_eq : leftHomologyMap' φ h₁ h₂ = γ.φH :=
LeftHomologyMapData.congr_φH (Subsingleton.elim _ _)
lemma cyclesMap'_eq : cyclesMap' φ h₁ h₂ = γ.φK :=
LeftHomologyMapData.congr_φK (Subsingleton.elim _ _)
end LeftHomologyMapData
@[simp]
lemma leftHomologyMap'_id (h : S.LeftHomologyData) :
leftHomologyMap' (𝟙 S) h h = 𝟙 _ :=
(LeftHomologyMapData.id h).leftHomologyMap'_eq
@[simp]
lemma cyclesMap'_id (h : S.LeftHomologyData) :
cyclesMap' (𝟙 S) h h = 𝟙 _ :=
(LeftHomologyMapData.id h).cyclesMap'_eq
variable (S)
@[simp]
lemma leftHomologyMap_id [HasLeftHomology S] :
leftHomologyMap (𝟙 S) = 𝟙 _ :=
leftHomologyMap'_id _
@[simp]
lemma cyclesMap_id [HasLeftHomology S] :
cyclesMap (𝟙 S) = 𝟙 _ :=
cyclesMap'_id _
@[simp]
lemma leftHomologyMap'_zero (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) :
leftHomologyMap' 0 h₁ h₂ = 0 :=
(LeftHomologyMapData.zero h₁ h₂).leftHomologyMap'_eq
@[simp]
lemma cyclesMap'_zero (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) :
cyclesMap' 0 h₁ h₂ = 0 :=
(LeftHomologyMapData.zero h₁ h₂).cyclesMap'_eq
variable (S₁ S₂)
@[simp]
lemma leftHomologyMap_zero [HasLeftHomology S₁] [HasLeftHomology S₂] :
leftHomologyMap (0 : S₁ ⟶ S₂) = 0 :=
leftHomologyMap'_zero _ _
@[simp]
lemma cyclesMap_zero [HasLeftHomology S₁] [HasLeftHomology S₂] :
cyclesMap (0 : S₁ ⟶ S₂) = 0 :=
cyclesMap'_zero _ _
variable {S₁ S₂}
@[reassoc]
lemma leftHomologyMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃)
(h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) (h₃ : S₃.LeftHomologyData) :
leftHomologyMap' (φ₁ ≫ φ₂) h₁ h₃ = leftHomologyMap' φ₁ h₁ h₂ ≫
leftHomologyMap' φ₂ h₂ h₃ := by
let γ₁ := leftHomologyMapData φ₁ h₁ h₂
let γ₂ := leftHomologyMapData φ₂ h₂ h₃
rw [γ₁.leftHomologyMap'_eq, γ₂.leftHomologyMap'_eq, (γ₁.comp γ₂).leftHomologyMap'_eq,
LeftHomologyMapData.comp_φH]
@[reassoc]
lemma cyclesMap'_comp (φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃)
(h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) (h₃ : S₃.LeftHomologyData) :
cyclesMap' (φ₁ ≫ φ₂) h₁ h₃ = cyclesMap' φ₁ h₁ h₂ ≫ cyclesMap' φ₂ h₂ h₃ := by
let γ₁ := leftHomologyMapData φ₁ h₁ h₂
let γ₂ := leftHomologyMapData φ₂ h₂ h₃
rw [γ₁.cyclesMap'_eq, γ₂.cyclesMap'_eq, (γ₁.comp γ₂).cyclesMap'_eq,
LeftHomologyMapData.comp_φK]
@[reassoc]
lemma leftHomologyMap_comp [HasLeftHomology S₁] [HasLeftHomology S₂] [HasLeftHomology S₃]
(φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) :
leftHomologyMap (φ₁ ≫ φ₂) = leftHomologyMap φ₁ ≫ leftHomologyMap φ₂ :=
leftHomologyMap'_comp _ _ _ _ _
@[reassoc]
lemma cyclesMap_comp [HasLeftHomology S₁] [HasLeftHomology S₂] [HasLeftHomology S₃]
(φ₁ : S₁ ⟶ S₂) (φ₂ : S₂ ⟶ S₃) :
cyclesMap (φ₁ ≫ φ₂) = cyclesMap φ₁ ≫ cyclesMap φ₂ :=
cyclesMap'_comp _ _ _ _ _
attribute [simp] leftHomologyMap_comp cyclesMap_comp
/-- An isomorphism of short complexes `S₁ ≅ S₂` induces an isomorphism on the `H` fields
of left homology data of `S₁` and `S₂`. -/
@[simps]
def leftHomologyMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.LeftHomologyData)
(h₂ : S₂.LeftHomologyData) : h₁.H ≅ h₂.H where
hom := leftHomologyMap' e.hom h₁ h₂
inv := leftHomologyMap' e.inv h₂ h₁
hom_inv_id := by rw [← leftHomologyMap'_comp, e.hom_inv_id, leftHomologyMap'_id]
inv_hom_id := by rw [← leftHomologyMap'_comp, e.inv_hom_id, leftHomologyMap'_id]
instance isIso_leftHomologyMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ]
(h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) :
IsIso (leftHomologyMap' φ h₁ h₂) :=
(inferInstance : IsIso (leftHomologyMapIso' (asIso φ) h₁ h₂).hom)
/-- An isomorphism of short complexes `S₁ ≅ S₂` induces an isomorphism on the `K` fields
of left homology data of `S₁` and `S₂`. -/
@[simps]
def cyclesMapIso' (e : S₁ ≅ S₂) (h₁ : S₁.LeftHomologyData)
(h₂ : S₂.LeftHomologyData) : h₁.K ≅ h₂.K where
hom := cyclesMap' e.hom h₁ h₂
inv := cyclesMap' e.inv h₂ h₁
hom_inv_id := by rw [← cyclesMap'_comp, e.hom_inv_id, cyclesMap'_id]
inv_hom_id := by rw [← cyclesMap'_comp, e.inv_hom_id, cyclesMap'_id]
instance isIso_cyclesMap'_of_isIso (φ : S₁ ⟶ S₂) [IsIso φ]
(h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData) :
IsIso (cyclesMap' φ h₁ h₂) :=
(inferInstance : IsIso (cyclesMapIso' (asIso φ) h₁ h₂).hom)
/-- The isomorphism `S₁.leftHomology ≅ S₂.leftHomology` induced by an isomorphism of
short complexes `S₁ ≅ S₂`. -/
@[simps]
noncomputable def leftHomologyMapIso (e : S₁ ≅ S₂) [S₁.HasLeftHomology]
[S₂.HasLeftHomology] : S₁.leftHomology ≅ S₂.leftHomology where
hom := leftHomologyMap e.hom
inv := leftHomologyMap e.inv
hom_inv_id := by rw [← leftHomologyMap_comp, e.hom_inv_id, leftHomologyMap_id]
inv_hom_id := by rw [← leftHomologyMap_comp, e.inv_hom_id, leftHomologyMap_id]
instance isIso_leftHomologyMap_of_iso (φ : S₁ ⟶ S₂)
[IsIso φ] [S₁.HasLeftHomology] [S₂.HasLeftHomology] :
IsIso (leftHomologyMap φ) :=
(inferInstance : IsIso (leftHomologyMapIso (asIso φ)).hom)
/-- The isomorphism `S₁.cycles ≅ S₂.cycles` induced by an isomorphism
of short complexes `S₁ ≅ S₂`. -/
@[simps]
noncomputable def cyclesMapIso (e : S₁ ≅ S₂) [S₁.HasLeftHomology]
[S₂.HasLeftHomology] : S₁.cycles ≅ S₂.cycles where
hom := cyclesMap e.hom
inv := cyclesMap e.inv
hom_inv_id := by rw [← cyclesMap_comp, e.hom_inv_id, cyclesMap_id]
inv_hom_id := by rw [← cyclesMap_comp, e.inv_hom_id, cyclesMap_id]
instance isIso_cyclesMap_of_iso (φ : S₁ ⟶ S₂) [IsIso φ] [S₁.HasLeftHomology]
[S₂.HasLeftHomology] : IsIso (cyclesMap φ) :=
(inferInstance : IsIso (cyclesMapIso (asIso φ)).hom)
variable {S}
namespace LeftHomologyData
variable (h : S.LeftHomologyData) [S.HasLeftHomology]
/-- The isomorphism `S.leftHomology ≅ h.H` induced by a left homology data `h` for a
short complex `S`. -/
noncomputable def leftHomologyIso : S.leftHomology ≅ h.H :=
leftHomologyMapIso' (Iso.refl _) _ _
/-- The isomorphism `S.cycles ≅ h.K` induced by a left homology data `h` for a
short complex `S`. -/
noncomputable def cyclesIso : S.cycles ≅ h.K :=
cyclesMapIso' (Iso.refl _) _ _
@[reassoc (attr := simp)]
lemma cyclesIso_hom_comp_i : h.cyclesIso.hom ≫ h.i = S.iCycles := by
dsimp [iCycles, LeftHomologyData.cyclesIso]
simp only [cyclesMap'_i, id_τ₂, comp_id]
@[reassoc (attr := simp)]
lemma cyclesIso_inv_comp_iCycles : h.cyclesIso.inv ≫ S.iCycles = h.i := by
simp only [← h.cyclesIso_hom_comp_i, Iso.inv_hom_id_assoc]
@[reassoc (attr := simp)]
lemma leftHomologyπ_comp_leftHomologyIso_hom :
S.leftHomologyπ ≫ h.leftHomologyIso.hom = h.cyclesIso.hom ≫ h.π := by
dsimp only [leftHomologyπ, leftHomologyIso, cyclesIso, leftHomologyMapIso',
cyclesMapIso', Iso.refl]
rw [← leftHomologyπ_naturality']
@[reassoc (attr := simp)]
lemma π_comp_leftHomologyIso_inv :
h.π ≫ h.leftHomologyIso.inv = h.cyclesIso.inv ≫ S.leftHomologyπ := by
simp only [← cancel_epi h.cyclesIso.hom, ← cancel_mono h.leftHomologyIso.hom, assoc,
Iso.inv_hom_id, comp_id, Iso.hom_inv_id_assoc,
LeftHomologyData.leftHomologyπ_comp_leftHomologyIso_hom]
end LeftHomologyData
namespace LeftHomologyMapData
variable {φ : S₁ ⟶ S₂} {h₁ : S₁.LeftHomologyData} {h₂ : S₂.LeftHomologyData}
(γ : LeftHomologyMapData φ h₁ h₂)
lemma leftHomologyMap_eq [S₁.HasLeftHomology] [S₂.HasLeftHomology] :
leftHomologyMap φ = h₁.leftHomologyIso.hom ≫ γ.φH ≫ h₂.leftHomologyIso.inv := by
dsimp [LeftHomologyData.leftHomologyIso, leftHomologyMapIso']
rw [← γ.leftHomologyMap'_eq, ← leftHomologyMap'_comp,
← leftHomologyMap'_comp, id_comp, comp_id]
rfl
lemma cyclesMap_eq [S₁.HasLeftHomology] [S₂.HasLeftHomology] :
cyclesMap φ = h₁.cyclesIso.hom ≫ γ.φK ≫ h₂.cyclesIso.inv := by
dsimp [LeftHomologyData.cyclesIso, cyclesMapIso']
rw [← γ.cyclesMap'_eq, ← cyclesMap'_comp, ← cyclesMap'_comp, id_comp, comp_id]
rfl
lemma leftHomologyMap_comm [S₁.HasLeftHomology] [S₂.HasLeftHomology] :
leftHomologyMap φ ≫ h₂.leftHomologyIso.hom = h₁.leftHomologyIso.hom ≫ γ.φH := by
simp only [γ.leftHomologyMap_eq, assoc, Iso.inv_hom_id, comp_id]
lemma cyclesMap_comm [S₁.HasLeftHomology] [S₂.HasLeftHomology] :
cyclesMap φ ≫ h₂.cyclesIso.hom = h₁.cyclesIso.hom ≫ γ.φK := by
simp only [γ.cyclesMap_eq, assoc, Iso.inv_hom_id, comp_id]
end LeftHomologyMapData
section
variable (C)
variable [HasKernels C] [HasCokernels C]
/-- The left homology functor `ShortComplex C ⥤ C`, where the left homology of a
short complex `S` is understood as a cokernel of the obvious map `S.toCycles : S.X₁ ⟶ S.cycles`
where `S.cycles` is a kernel of `S.g : S.X₂ ⟶ S.X₃`. -/
@[simps]
noncomputable def leftHomologyFunctor : ShortComplex C ⥤ C where
obj S := S.leftHomology
map := leftHomologyMap
/-- The cycles functor `ShortComplex C ⥤ C` which sends a short complex `S` to `S.cycles`
which is a kernel of `S.g : S.X₂ ⟶ S.X₃`. -/
@[simps]
noncomputable def cyclesFunctor : ShortComplex C ⥤ C where
obj S := S.cycles
map := cyclesMap
/-- The natural transformation `S.cycles ⟶ S.leftHomology` for all short complexes `S`. -/
@[simps]
noncomputable def leftHomologyπNatTrans : cyclesFunctor C ⟶ leftHomologyFunctor C where
app S := leftHomologyπ S
naturality := fun _ _ φ => (leftHomologyπ_naturality φ).symm
/-- The natural transformation `S.cycles ⟶ S.X₂` for all short complexes `S`. -/
@[simps]
noncomputable def iCyclesNatTrans : cyclesFunctor C ⟶ ShortComplex.π₂ where
app S := S.iCycles
/-- The natural transformation `S.X₁ ⟶ S.cycles` for all short complexes `S`. -/
@[simps]
noncomputable def toCyclesNatTrans :
π₁ ⟶ cyclesFunctor C where
app S := S.toCycles
naturality := fun _ _ φ => (toCycles_naturality φ).symm
end
namespace LeftHomologyData
/-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso
and `φ.τ₃` is mono, then a left homology data for `S₁` induces a left homology data for `S₂` with
the same `K` and `H` fields. The inverse construction is `ofEpiOfIsIsoOfMono'`. -/
@[simps]
noncomputable def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₁)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : LeftHomologyData S₂ := by
let i : h.K ⟶ S₂.X₂ := h.i ≫ φ.τ₂
have wi : i ≫ S₂.g = 0 := by simp only [i, assoc, φ.comm₂₃, h.wi_assoc, zero_comp]
have hi : IsLimit (KernelFork.ofι i wi) := KernelFork.IsLimit.ofι _ _
(fun x hx => h.liftK (x ≫ inv φ.τ₂) (by rw [assoc, ← cancel_mono φ.τ₃, assoc,
assoc, ← φ.comm₂₃, IsIso.inv_hom_id_assoc, hx, zero_comp]))
(fun x hx => by simp [i]) (fun x hx b hb => by
dsimp
rw [← cancel_mono h.i, ← cancel_mono φ.τ₂, assoc, assoc, liftK_i_assoc,
assoc, IsIso.inv_hom_id, comp_id, hb])
let f' := hi.lift (KernelFork.ofι S₂.f S₂.zero)
have hf' : φ.τ₁ ≫ f' = h.f' := by
have eq := @Fork.IsLimit.lift_ι _ _ _ _ _ _ _ ((KernelFork.ofι S₂.f S₂.zero)) hi
simp only [Fork.ι_ofι] at eq
rw [← cancel_mono h.i, ← cancel_mono φ.τ₂, assoc, assoc, eq, f'_i, φ.comm₁₂]
have wπ : f' ≫ h.π = 0 := by
rw [← cancel_epi φ.τ₁, comp_zero, reassoc_of% hf', h.f'_π]
have hπ : IsColimit (CokernelCofork.ofπ h.π wπ) := CokernelCofork.IsColimit.ofπ _ _
(fun x hx => h.descH x (by rw [← hf', assoc, hx, comp_zero]))
(fun x hx => by simp) (fun x hx b hb => by rw [← cancel_epi h.π, π_descH, hb])
exact ⟨h.K, h.H, i, h.π, wi, hi, wπ, hπ⟩
@[simp]
lemma τ₁_ofEpiOfIsIsoOfMono_f' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₁)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : φ.τ₁ ≫ (ofEpiOfIsIsoOfMono φ h).f' = h.f' := by
rw [← cancel_mono (ofEpiOfIsIsoOfMono φ h).i, assoc, f'_i,
ofEpiOfIsIsoOfMono_i, f'_i_assoc, φ.comm₁₂]
/-- If `φ : S₁ ⟶ S₂` is a morphism of short complexes such that `φ.τ₁` is epi, `φ.τ₂` is an iso
and `φ.τ₃` is mono, then a left homology data for `S₂` induces a left homology data for `S₁` with
the same `K` and `H` fields. The inverse construction is `ofEpiOfIsIsoOfMono`. -/
@[simps]
noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₂)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : LeftHomologyData S₁ := by
let i : h.K ⟶ S₁.X₂ := h.i ≫ inv φ.τ₂
have wi : i ≫ S₁.g = 0 := by
rw [assoc, ← cancel_mono φ.τ₃, zero_comp, assoc, assoc, ← φ.comm₂₃,
IsIso.inv_hom_id_assoc, h.wi]
have hi : IsLimit (KernelFork.ofι i wi) := KernelFork.IsLimit.ofι _ _
(fun x hx => h.liftK (x ≫ φ.τ₂)
(by rw [assoc, φ.comm₂₃, reassoc_of% hx, zero_comp]))
(fun x hx => by simp [i])
(fun x hx b hb => by rw [← cancel_mono h.i, ← cancel_mono (inv φ.τ₂), assoc, assoc,
hb, liftK_i_assoc, assoc, IsIso.hom_inv_id, comp_id])
let f' := hi.lift (KernelFork.ofι S₁.f S₁.zero)
have hf' : f' ≫ i = S₁.f := Fork.IsLimit.lift_ι _
have hf'' : f' = φ.τ₁ ≫ h.f' := by
rw [← cancel_mono h.i, ← cancel_mono (inv φ.τ₂), assoc, assoc, assoc, hf', f'_i_assoc,
φ.comm₁₂_assoc, IsIso.hom_inv_id, comp_id]
have wπ : f' ≫ h.π = 0 := by simp only [hf'', assoc, f'_π, comp_zero]
have hπ : IsColimit (CokernelCofork.ofπ h.π wπ) := CokernelCofork.IsColimit.ofπ _ _
(fun x hx => h.descH x (by rw [← cancel_epi φ.τ₁, ← reassoc_of% hf'', hx, comp_zero]))
(fun x hx => π_descH _ _ _)
(fun x hx b hx => by rw [← cancel_epi h.π, π_descH, hx])
exact ⟨h.K, h.H, i, h.π, wi, hi, wπ, hπ⟩
@[simp]
lemma ofEpiOfIsIsoOfMono'_f' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₂)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : (ofEpiOfIsIsoOfMono' φ h).f' = φ.τ₁ ≫ h.f' := by
rw [← cancel_mono (ofEpiOfIsIsoOfMono' φ h).i, f'_i, ofEpiOfIsIsoOfMono'_i,
assoc, f'_i_assoc, φ.comm₁₂_assoc, IsIso.hom_inv_id, comp_id]
/-- If `e : S₁ ≅ S₂` is an isomorphism of short complexes and `h₁ : LeftHomologyData S₁`,
this is the left homology data for `S₂` deduced from the isomorphism. -/
noncomputable def ofIso (e : S₁ ≅ S₂) (h₁ : LeftHomologyData S₁) : LeftHomologyData S₂ :=
h₁.ofEpiOfIsIsoOfMono e.hom
end LeftHomologyData
lemma hasLeftHomology_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [HasLeftHomology S₁]
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasLeftHomology S₂ :=
HasLeftHomology.mk' (LeftHomologyData.ofEpiOfIsIsoOfMono φ S₁.leftHomologyData)
lemma hasLeftHomology_of_epi_of_isIso_of_mono' (φ : S₁ ⟶ S₂) [HasLeftHomology S₂]
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : HasLeftHomology S₁ :=
HasLeftHomology.mk' (LeftHomologyData.ofEpiOfIsIsoOfMono' φ S₂.leftHomologyData)
lemma hasLeftHomology_of_iso {S₁ S₂ : ShortComplex C} (e : S₁ ≅ S₂) [HasLeftHomology S₁] :
HasLeftHomology S₂ :=
hasLeftHomology_of_epi_of_isIso_of_mono e.hom
namespace LeftHomologyMapData
/-- This left homology map data expresses compatibilities of the left homology data
constructed by `LeftHomologyData.ofEpiOfIsIsoOfMono` -/
@[simps]
def ofEpiOfIsIsoOfMono (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₁)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] :
LeftHomologyMapData φ h (LeftHomologyData.ofEpiOfIsIsoOfMono φ h) where
φK := 𝟙 _
φH := 𝟙 _
/-- This left homology map data expresses compatibilities of the left homology data
constructed by `LeftHomologyData.ofEpiOfIsIsoOfMono'` -/
@[simps]
noncomputable def ofEpiOfIsIsoOfMono' (φ : S₁ ⟶ S₂) (h : LeftHomologyData S₂)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] :
LeftHomologyMapData φ (LeftHomologyData.ofEpiOfIsIsoOfMono' φ h) h where
φK := 𝟙 _
φH := 𝟙 _
end LeftHomologyMapData
instance (φ : S₁ ⟶ S₂) (h₁ : S₁.LeftHomologyData) (h₂ : S₂.LeftHomologyData)
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] :
IsIso (leftHomologyMap' φ h₁ h₂) := by
let h₂' := LeftHomologyData.ofEpiOfIsIsoOfMono φ h₁
have : IsIso (leftHomologyMap' φ h₁ h₂') := by
rw [(LeftHomologyMapData.ofEpiOfIsIsoOfMono φ h₁).leftHomologyMap'_eq]
dsimp
infer_instance
have eq := leftHomologyMap'_comp φ (𝟙 S₂) h₁ h₂' h₂
rw [comp_id] at eq
rw [eq]
infer_instance
/-- If a morphism of short complexes `φ : S₁ ⟶ S₂` is such that `φ.τ₁` is epi, `φ.τ₂` is an iso,
and `φ.τ₃` is mono, then the induced morphism on left homology is an isomorphism. -/
instance (φ : S₁ ⟶ S₂) [S₁.HasLeftHomology] [S₂.HasLeftHomology]
[Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] :
IsIso (leftHomologyMap φ) := by
dsimp only [leftHomologyMap]
infer_instance
section
variable (S) (h : LeftHomologyData S) {A : C} (k : A ⟶ S.X₂) (hk : k ≫ S.g = 0)
[HasLeftHomology S]
/-- A morphism `k : A ⟶ S.X₂` such that `k ≫ S.g = 0` lifts to a morphism `A ⟶ S.cycles`. -/
noncomputable def liftCycles : A ⟶ S.cycles :=
S.leftHomologyData.liftK k hk
@[reassoc (attr := simp)]
lemma liftCycles_i : S.liftCycles k hk ≫ S.iCycles = k :=
LeftHomologyData.liftK_i _ k hk
@[reassoc]
lemma comp_liftCycles {A' : C} (α : A' ⟶ A) :
α ≫ S.liftCycles k hk = S.liftCycles (α ≫ k) (by rw [assoc, hk, comp_zero]) := by aesop_cat
/-- Via `S.iCycles : S.cycles ⟶ S.X₂`, the object `S.cycles` identifies to the
kernel of `S.g : S.X₂ ⟶ S.X₃`. -/
noncomputable def cyclesIsKernel : IsLimit (KernelFork.ofι S.iCycles S.iCycles_g) :=
S.leftHomologyData.hi
/-- The canonical isomorphism `S.cycles ≅ kernel S.g`. -/
@[simps]
noncomputable def cyclesIsoKernel [HasKernel S.g] : S.cycles ≅ kernel S.g where
hom := kernel.lift S.g S.iCycles (by simp)
inv := S.liftCycles (kernel.ι S.g) (by simp)
/-- The morphism `A ⟶ S.leftHomology` obtained from a morphism `k : A ⟶ S.X₂`
such that `k ≫ S.g = 0.` -/
@[simp]
noncomputable def liftLeftHomology : A ⟶ S.leftHomology :=
S.liftCycles k hk ≫ S.leftHomologyπ
@[reassoc]
lemma liftCycles_leftHomologyπ_eq_zero_of_boundary (x : A ⟶ S.X₁) (hx : k = x ≫ S.f) :
S.liftCycles k (by rw [hx, assoc, S.zero, comp_zero]) ≫ S.leftHomologyπ = 0 :=
| LeftHomologyData.liftK_π_eq_zero_of_boundary _ k x hx
@[reassoc (attr := simp)]
| Mathlib/Algebra/Homology/ShortComplex/LeftHomology.lean | 968 | 970 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Analysis.InnerProductSpace.LinearMap
import Mathlib.MeasureTheory.Function.LpSpace.ContinuousFunctions
import Mathlib.MeasureTheory.Function.StronglyMeasurable.Inner
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-! # `L^2` space
If `E` is an inner product space over `𝕜` (`ℝ` or `ℂ`), then `Lp E 2 μ`
(defined in `Mathlib.MeasureTheory.Function.LpSpace`)
is also an inner product space, with inner product defined as `inner f g = ∫ a, ⟪f a, g a⟫ ∂μ`.
### Main results
* `mem_L1_inner` : for `f` and `g` in `Lp E 2 μ`, the pointwise inner product `fun x ↦ ⟪f x, g x⟫`
belongs to `Lp 𝕜 1 μ`.
* `integrable_inner` : for `f` and `g` in `Lp E 2 μ`, the pointwise inner product
`fun x ↦ ⟪f x, g x⟫` is integrable.
* `L2.innerProductSpace` : `Lp E 2 μ` is an inner product space.
-/
noncomputable section
open TopologicalSpace MeasureTheory MeasureTheory.Lp Filter
open scoped NNReal ENNReal MeasureTheory
namespace MeasureTheory
section
variable {α F : Type*} {m : MeasurableSpace α} {μ : Measure α} [NormedAddCommGroup F]
theorem MemLp.integrable_sq {f : α → ℝ} (h : MemLp f 2 μ) : Integrable (fun x => f x ^ 2) μ := by
simpa [← memLp_one_iff_integrable] using h.norm_rpow two_ne_zero ENNReal.ofNat_ne_top
@[deprecated (since := "2025-02-21")]
alias Memℒp.integrable_sq := MemLp.integrable_sq
theorem memLp_two_iff_integrable_sq_norm {f : α → F} (hf : AEStronglyMeasurable f μ) :
MemLp f 2 μ ↔ Integrable (fun x => ‖f x‖ ^ 2) μ := by
rw [← memLp_one_iff_integrable]
convert (memLp_norm_rpow_iff hf two_ne_zero ENNReal.ofNat_ne_top).symm
· simp
· rw [div_eq_mul_inv, ENNReal.mul_inv_cancel two_ne_zero ENNReal.ofNat_ne_top]
@[deprecated (since := "2025-02-21")]
alias memℒp_two_iff_integrable_sq_norm := memLp_two_iff_integrable_sq_norm
theorem memLp_two_iff_integrable_sq {f : α → ℝ} (hf : AEStronglyMeasurable f μ) :
MemLp f 2 μ ↔ Integrable (fun x => f x ^ 2) μ := by
convert memLp_two_iff_integrable_sq_norm hf using 3
simp
@[deprecated (since := "2025-02-21")]
alias memℒp_two_iff_integrable_sq := memLp_two_iff_integrable_sq
end
section InnerProductSpace
variable {α : Type*} {m : MeasurableSpace α} {p : ℝ≥0∞} {μ : Measure α}
variable {E 𝕜 : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y
theorem MemLp.const_inner (c : E) {f : α → E} (hf : MemLp f p μ) : MemLp (fun a => ⟪c, f a⟫) p μ :=
hf.of_le_mul (AEStronglyMeasurable.inner aestronglyMeasurable_const hf.1)
(Eventually.of_forall fun _ => norm_inner_le_norm _ _)
@[deprecated (since := "2025-02-21")]
alias Memℒp.const_inner := MemLp.const_inner
theorem MemLp.inner_const {f : α → E} (hf : MemLp f p μ) (c : E) : MemLp (fun a => ⟪f a, c⟫) p μ :=
hf.of_le_mul (c := ‖c‖) (AEStronglyMeasurable.inner hf.1 aestronglyMeasurable_const)
(Eventually.of_forall fun x => by rw [mul_comm]; exact norm_inner_le_norm _ _)
|
@[deprecated (since := "2025-02-21")]
alias Memℒp.inner_const := MemLp.inner_const
| Mathlib/MeasureTheory/Function/L2Space.lean | 81 | 83 |
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.Prod.Lex
import Mathlib.Data.Sigma.Lex
import Mathlib.Order.RelIso.Set
import Mathlib.Order.WellQuasiOrder
import Mathlib.Tactic.TFAE
/-!
# Well-founded sets
This file introduces versions of `WellFounded` and `WellQuasiOrdered` for sets.
## Main Definitions
* `Set.WellFoundedOn s r` indicates that the relation `r` is
well-founded when restricted to the set `s`.
* `Set.IsWF s` indicates that `<` is well-founded when restricted to `s`.
* `Set.PartiallyWellOrderedOn s r` indicates that the relation `r` is
partially well-ordered (also known as well quasi-ordered) when restricted to the set `s`.
* `Set.IsPWO s` indicates that any infinite sequence of elements in `s` contains an infinite
monotone subsequence. Note that this is equivalent to containing only two comparable elements.
## Main Results
* Higman's Lemma, `Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂`,
shows that if `r` is partially well-ordered on `s`, then `List.SublistForall₂` is partially
well-ordered on the set of lists of elements of `s`. The result was originally published by
Higman, but this proof more closely follows Nash-Williams.
* `Set.wellFoundedOn_iff` relates `well_founded_on` to the well-foundedness of a relation on the
original type, to avoid dealing with subtypes.
* `Set.IsWF.mono` shows that a subset of a well-founded subset is well-founded.
* `Set.IsWF.union` shows that the union of two well-founded subsets is well-founded.
* `Finset.isWF` shows that all `Finset`s are well-founded.
## TODO
* Prove that `s` is partial well ordered iff it has no infinite descending chain or antichain.
* Rename `Set.PartiallyWellOrderedOn` to `Set.WellQuasiOrderedOn` and `Set.IsPWO` to `Set.IsWQO`.
## References
* [Higman, *Ordering by Divisibility in Abstract Algebras*][Higman52]
* [Nash-Williams, *On Well-Quasi-Ordering Finite Trees*][Nash-Williams63]
-/
assert_not_exists OrderedSemiring
open scoped Function -- required for scoped `on` notation
variable {ι α β γ : Type*} {π : ι → Type*}
namespace Set
/-! ### Relations well-founded on sets -/
/-- `s.WellFoundedOn r` indicates that the relation `r` is `WellFounded` when restricted to `s`. -/
def WellFoundedOn (s : Set α) (r : α → α → Prop) : Prop :=
WellFounded (Subrel r (· ∈ s))
@[simp]
theorem wellFoundedOn_empty (r : α → α → Prop) : WellFoundedOn ∅ r :=
wellFounded_of_isEmpty _
section WellFoundedOn
variable {r r' : α → α → Prop}
section AnyRel
variable {f : β → α} {s t : Set α} {x y : α}
theorem wellFoundedOn_iff :
s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := by
have f : RelEmbedding (Subrel r (· ∈ s)) fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s :=
⟨⟨(↑), Subtype.coe_injective⟩, by simp⟩
refine ⟨fun h => ?_, f.wellFounded⟩
rw [WellFounded.wellFounded_iff_has_min]
intro t ht
by_cases hst : (s ∩ t).Nonempty
· rw [← Subtype.preimage_coe_nonempty] at hst
rcases h.has_min (Subtype.val ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩
exact ⟨m, mt, fun x xt ⟨xm, xs, _⟩ => hm ⟨x, xs⟩ xt xm⟩
· rcases ht with ⟨m, mt⟩
exact ⟨m, mt, fun x _ ⟨_, _, ms⟩ => hst ⟨m, ⟨ms, mt⟩⟩⟩
@[simp]
theorem wellFoundedOn_univ : (univ : Set α).WellFoundedOn r ↔ WellFounded r := by
simp [wellFoundedOn_iff]
theorem _root_.WellFounded.wellFoundedOn : WellFounded r → s.WellFoundedOn r :=
InvImage.wf _
@[simp]
theorem wellFoundedOn_range : (range f).WellFoundedOn r ↔ WellFounded (r on f) := by
let f' : β → range f := fun c => ⟨f c, c, rfl⟩
refine ⟨fun h => (InvImage.wf f' h).mono fun c c' => id, fun h => ⟨?_⟩⟩
rintro ⟨_, c, rfl⟩
refine Acc.of_downward_closed f' ?_ _ ?_
· rintro _ ⟨_, c', rfl⟩ -
exact ⟨c', rfl⟩
· exact h.apply _
@[simp]
theorem wellFoundedOn_image {s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f) := by
rw [image_eq_range]; exact wellFoundedOn_range
namespace WellFoundedOn
protected theorem induction (hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop}
(hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x := by
let Q : s → Prop := fun y => P y
change Q ⟨x, hx⟩
refine WellFounded.induction hs ⟨x, hx⟩ ?_
simpa only [Subtype.forall]
protected theorem mono (h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) :
s.WellFoundedOn r := by
rw [wellFoundedOn_iff] at *
exact Subrelation.wf (fun xy => ⟨hle _ _ xy.1, hst xy.2.1, hst xy.2.2⟩) h
theorem mono' (h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) :
s.WellFoundedOn r → s.WellFoundedOn r' :=
Subrelation.wf @fun a b => h _ a.2 _ b.2
theorem subset (h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r :=
h.mono le_rfl hst
open Relation
open List in
/-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive
closure of `a` under `r` (including `a` or not). -/
theorem acc_iff_wellFoundedOn {α} {r : α → α → Prop} {a : α} :
TFAE [Acc r a,
WellFoundedOn { b | ReflTransGen r b a } r,
WellFoundedOn { b | TransGen r b a } r] := by
tfae_have 1 → 2 := by
refine fun h => ⟨fun b => InvImage.accessible Subtype.val ?_⟩
rw [← acc_transGen_iff] at h ⊢
obtain h' | h' := reflTransGen_iff_eq_or_transGen.1 b.2
· rwa [h'] at h
· exact h.inv h'
tfae_have 2 → 3 := fun h => h.subset fun _ => TransGen.to_reflTransGen
tfae_have 3 → 1 := by
refine fun h => Acc.intro _ (fun b hb => (h.apply ⟨b, .single hb⟩).of_fibration Subtype.val ?_)
exact fun ⟨c, hc⟩ d h => ⟨⟨d, .head h hc⟩, h, rfl⟩
tfae_finish
end WellFoundedOn
end AnyRel
section IsStrictOrder
variable [IsStrictOrder α r] {s t : Set α}
instance IsStrictOrder.subset : IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s where
toIsIrrefl := ⟨fun a con => irrefl_of r a con.1⟩
toIsTrans := ⟨fun _ _ _ ab bc => ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩⟩
theorem wellFoundedOn_iff_no_descending_seq :
s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s := by
simp only [wellFoundedOn_iff, RelEmbedding.wellFounded_iff_no_descending_seq, ← not_exists, ←
not_nonempty_iff, not_iff_not]
constructor
· rintro ⟨⟨f, hf⟩⟩
have H : ∀ n, f n ∈ s := fun n => (hf.2 n.lt_succ_self).2.2
refine ⟨⟨f, ?_⟩, H⟩
simpa only [H, and_true] using @hf
· rintro ⟨⟨f, hf⟩, hfs : ∀ n, f n ∈ s⟩
refine ⟨⟨f, ?_⟩⟩
simpa only [hfs, and_true] using @hf
theorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) :
(s ∪ t).WellFoundedOn r := by
rw [wellFoundedOn_iff_no_descending_seq] at *
rintro f hf
rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hg | hg⟩
exacts [hs (g.dual.ltEmbedding.trans f) hg, ht (g.dual.ltEmbedding.trans f) hg]
@[simp]
theorem wellFoundedOn_union : (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r :=
⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun h =>
h.1.union h.2⟩
end IsStrictOrder
end WellFoundedOn
/-! ### Sets well-founded w.r.t. the strict inequality -/
section LT
variable [LT α] {s t : Set α}
/-- `s.IsWF` indicates that `<` is well-founded when restricted to `s`. -/
def IsWF (s : Set α) : Prop :=
WellFoundedOn s (· < ·)
@[simp]
theorem isWF_empty : IsWF (∅ : Set α) :=
wellFounded_of_isEmpty _
theorem IsWF.mono (h : IsWF t) (st : s ⊆ t) : IsWF s := h.subset st
theorem isWF_univ_iff : IsWF (univ : Set α) ↔ WellFoundedLT α := by
simp [IsWF, wellFoundedOn_iff, isWellFounded_iff]
theorem IsWF.of_wellFoundedLT [h : WellFoundedLT α] (s : Set α) : s.IsWF :=
(Set.isWF_univ_iff.2 h).mono s.subset_univ
@[deprecated IsWF.of_wellFoundedLT (since := "2025-01-16")]
theorem _root_.WellFounded.isWF (h : WellFounded ((· < ·) : α → α → Prop)) (s : Set α) : s.IsWF :=
have : WellFoundedLT α := ⟨h⟩
.of_wellFoundedLT s
end LT
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
protected nonrec theorem IsWF.union (hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t) := hs.union ht
@[simp] theorem isWF_union : IsWF (s ∪ t) ↔ IsWF s ∧ IsWF t := wellFoundedOn_union
end Preorder
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
theorem isWF_iff_no_descending_seq :
IsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s :=
wellFoundedOn_iff_no_descending_seq.trans
⟨fun H f hf => H ⟨⟨f, hf.injective⟩, hf.lt_iff_lt⟩, fun H f => H f fun _ _ => f.map_rel_iff.2⟩
end Preorder
/-! ### Partially well-ordered sets -/
/-- `s.PartiallyWellOrderedOn r` indicates that the relation `r` is `WellQuasiOrdered` when
restricted to `s`.
A set is partially well-ordered by a relation `r` when any infinite sequence contains two elements
where the first is related to the second by `r`. Equivalently, any antichain (see `IsAntichain`) is
finite, see `Set.partiallyWellOrderedOn_iff_finite_antichains`.
TODO: rename this to `WellQuasiOrderedOn` to match `WellQuasiOrdered`. -/
def PartiallyWellOrderedOn (s : Set α) (r : α → α → Prop) : Prop :=
WellQuasiOrdered (Subrel r (· ∈ s))
section PartiallyWellOrderedOn
variable {r : α → α → Prop} {r' : β → β → Prop} {f : α → β} {s : Set α} {t : Set α} {a : α}
theorem PartiallyWellOrderedOn.exists_lt (hs : s.PartiallyWellOrderedOn r) {f : ℕ → α}
(hf : ∀ n, f n ∈ s) : ∃ m n, m < n ∧ r (f m) (f n) :=
hs fun n ↦ ⟨_, hf n⟩
theorem partiallyWellOrderedOn_iff_exists_lt : s.PartiallyWellOrderedOn r ↔
∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n, m < n ∧ r (f m) (f n) :=
⟨PartiallyWellOrderedOn.exists_lt, fun hf f ↦ hf _ fun n ↦ (f n).2⟩
theorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) :
s.PartiallyWellOrderedOn r :=
fun f ↦ ht (Set.inclusion h ∘ f)
@[simp]
theorem partiallyWellOrderedOn_empty (r : α → α → Prop) : PartiallyWellOrderedOn ∅ r :=
wellQuasiOrdered_of_isEmpty _
theorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r)
(ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r := by
intro f
obtain ⟨g, hgs | hgt⟩ := Nat.exists_subseq_of_forall_mem_union _ fun x ↦ (f x).2
· rcases hs.exists_lt hgs with ⟨m, n, hlt, hr⟩
exact ⟨g m, g n, g.strictMono hlt, hr⟩
· rcases ht.exists_lt hgt with ⟨m, n, hlt, hr⟩
exact ⟨g m, g n, g.strictMono hlt, hr⟩
@[simp]
theorem partiallyWellOrderedOn_union :
(s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r :=
⟨fun h ↦ ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h ↦ h.1.union h.2⟩
theorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r)
(hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r' := by
rw [partiallyWellOrderedOn_iff_exists_lt] at *
intro g' hg'
choose g hgs heq using hg'
obtain rfl : f ∘ g = g' := funext heq
obtain ⟨m, n, hlt, hmn⟩ := hs g hgs
exact ⟨m, n, hlt, hf _ (hgs m) _ (hgs n) hmn⟩
-- TODO: prove this in terms of `IsAntichain.finite_of_wellQuasiOrdered`
theorem _root_.IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s)
(hp : s.PartiallyWellOrderedOn r) : s.Finite := by
refine not_infinite.1 fun hi => ?_
obtain ⟨m, n, hmn, h⟩ := hp (hi.natEmbedding _)
exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <|
ha.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h)
section IsRefl
variable [IsRefl α r]
protected theorem Finite.partiallyWellOrderedOn (hs : s.Finite) : s.PartiallyWellOrderedOn r :=
hs.to_subtype.wellQuasiOrdered _
theorem _root_.IsAntichain.partiallyWellOrderedOn_iff (hs : IsAntichain r s) :
s.PartiallyWellOrderedOn r ↔ s.Finite :=
⟨hs.finite_of_partiallyWellOrderedOn, Finite.partiallyWellOrderedOn⟩
@[simp]
theorem partiallyWellOrderedOn_singleton (a : α) : PartiallyWellOrderedOn {a} r :=
(finite_singleton a).partiallyWellOrderedOn
@[nontriviality]
theorem Subsingleton.partiallyWellOrderedOn (hs : s.Subsingleton) : PartiallyWellOrderedOn s r :=
hs.finite.partiallyWellOrderedOn
@[simp]
theorem partiallyWellOrderedOn_insert :
PartiallyWellOrderedOn (insert a s) r ↔ PartiallyWellOrderedOn s r := by
simp only [← singleton_union, partiallyWellOrderedOn_union,
partiallyWellOrderedOn_singleton, true_and]
protected theorem PartiallyWellOrderedOn.insert (h : PartiallyWellOrderedOn s r) (a : α) :
PartiallyWellOrderedOn (insert a s) r :=
partiallyWellOrderedOn_insert.2 h
theorem partiallyWellOrderedOn_iff_finite_antichains [IsSymm α r] :
s.PartiallyWellOrderedOn r ↔ ∀ t, t ⊆ s → IsAntichain r t → t.Finite := by
refine ⟨fun h t ht hrt => hrt.finite_of_partiallyWellOrderedOn (h.mono ht), ?_⟩
rw [partiallyWellOrderedOn_iff_exists_lt]
intro hs f hf
by_contra! H
refine infinite_range_of_injective (fun m n hmn => ?_) (hs _ (range_subset_iff.2 hf) ?_)
· obtain h | h | h := lt_trichotomy m n
· refine (H _ _ h ?_).elim
rw [hmn]
exact refl _
· exact h
· refine (H _ _ h ?_).elim
rw [hmn]
exact refl _
rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩ hmn
obtain h | h := (ne_of_apply_ne _ hmn).lt_or_lt
· exact H _ _ h
· exact mt symm (H _ _ h)
end IsRefl
section IsPreorder
variable [IsPreorder α r]
theorem PartiallyWellOrderedOn.exists_monotone_subseq (h : s.PartiallyWellOrderedOn r) {f : ℕ → α}
(hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) :=
WellQuasiOrdered.exists_monotone_subseq h fun n ↦ ⟨_, hf n⟩
theorem partiallyWellOrderedOn_iff_exists_monotone_subseq :
s.PartiallyWellOrderedOn r ↔
∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
use PartiallyWellOrderedOn.exists_monotone_subseq
rw [PartiallyWellOrderedOn, wellQuasiOrdered_iff_exists_monotone_subseq]
exact fun H f ↦ H _ fun n ↦ (f n).2
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
(ht : PartiallyWellOrderedOn t r') :
PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
rw [partiallyWellOrderedOn_iff_exists_lt]
intro f hf
obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq fun n => (hf n).1
obtain ⟨m, n, hlt, hle⟩ := ht.exists_lt fun n => (hf _).2
exact ⟨g₁ m, g₁ n, g₁.strictMono hlt, h₁ _ _ hlt.le, hle⟩
theorem PartiallyWellOrderedOn.wellFoundedOn (h : s.PartiallyWellOrderedOn r) :
s.WellFoundedOn fun a b => r a b ∧ ¬ r b a :=
h.wellFounded
end IsPreorder
end PartiallyWellOrderedOn
section IsPWO
variable [Preorder α] [Preorder β] {s t : Set α}
/-- A subset of a preorder is partially well-ordered when any infinite sequence contains
a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/
def IsPWO (s : Set α) : Prop :=
PartiallyWellOrderedOn s (· ≤ ·)
nonrec theorem IsPWO.mono (ht : t.IsPWO) : s ⊆ t → s.IsPWO := ht.mono
nonrec theorem IsPWO.exists_monotone_subseq (h : s.IsPWO) {f : ℕ → α} (hf : ∀ n, f n ∈ s) :
∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
h.exists_monotone_subseq hf
theorem isPWO_iff_exists_monotone_subseq :
s.IsPWO ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
partiallyWellOrderedOn_iff_exists_monotone_subseq
protected theorem IsPWO.isWF (h : s.IsPWO) : s.IsWF := by
simpa only [← lt_iff_le_not_le] using h.wellFoundedOn
nonrec theorem IsPWO.prod {t : Set β} (hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s ×ˢ t) :=
hs.prod ht
theorem IsPWO.image_of_monotoneOn (hs : s.IsPWO) {f : α → β} (hf : MonotoneOn f s) :
IsPWO (f '' s) :=
hs.image_of_monotone_on hf
theorem IsPWO.image_of_monotone (hs : s.IsPWO) {f : α → β} (hf : Monotone f) : IsPWO (f '' s) :=
hs.image_of_monotone_on (hf.monotoneOn _)
protected nonrec theorem IsPWO.union (hs : IsPWO s) (ht : IsPWO t) : IsPWO (s ∪ t) :=
hs.union ht
@[simp]
theorem isPWO_union : IsPWO (s ∪ t) ↔ IsPWO s ∧ IsPWO t :=
partiallyWellOrderedOn_union
protected theorem Finite.isPWO (hs : s.Finite) : IsPWO s := hs.partiallyWellOrderedOn
@[simp] theorem isPWO_of_finite [Finite α] : s.IsPWO := s.toFinite.isPWO
@[simp] theorem isPWO_singleton (a : α) : IsPWO ({a} : Set α) := (finite_singleton a).isPWO
@[simp] theorem isPWO_empty : IsPWO (∅ : Set α) := finite_empty.isPWO
protected theorem Subsingleton.isPWO (hs : s.Subsingleton) : IsPWO s := hs.finite.isPWO
@[simp]
theorem isPWO_insert {a} : IsPWO (insert a s) ↔ IsPWO s := by
simp only [← singleton_union, isPWO_union, isPWO_singleton, true_and]
protected theorem IsPWO.insert (h : IsPWO s) (a : α) : IsPWO (insert a s) :=
isPWO_insert.2 h
protected theorem Finite.isWF (hs : s.Finite) : IsWF s := hs.isPWO.isWF
@[simp] theorem isWF_singleton {a : α} : IsWF ({a} : Set α) := (finite_singleton a).isWF
protected theorem Subsingleton.isWF (hs : s.Subsingleton) : IsWF s := hs.isPWO.isWF
@[simp]
theorem isWF_insert {a} : IsWF (insert a s) ↔ IsWF s := by
simp only [← singleton_union, isWF_union, isWF_singleton, true_and]
protected theorem IsWF.insert (h : IsWF s) (a : α) : IsWF (insert a s) :=
isWF_insert.2 h
end IsPWO
section WellFoundedOn
variable {r : α → α → Prop} [IsStrictOrder α r] {s : Set α} {a : α}
protected theorem Finite.wellFoundedOn (hs : s.Finite) : s.WellFoundedOn r :=
letI := partialOrderOfSO r
hs.isWF
@[simp]
theorem wellFoundedOn_singleton : WellFoundedOn ({a} : Set α) r :=
(finite_singleton a).wellFoundedOn
protected theorem Subsingleton.wellFoundedOn (hs : s.Subsingleton) : s.WellFoundedOn r :=
hs.finite.wellFoundedOn
@[simp]
theorem wellFoundedOn_insert : WellFoundedOn (insert a s) r ↔ WellFoundedOn s r := by
simp only [← singleton_union, wellFoundedOn_union, wellFoundedOn_singleton, true_and]
@[simp]
theorem wellFoundedOn_sdiff_singleton : WellFoundedOn (s \ {a}) r ↔ WellFoundedOn s r := by
simp only [← wellFoundedOn_insert (a := a), insert_diff_singleton, mem_insert_iff, true_or,
insert_eq_of_mem]
protected theorem WellFoundedOn.insert (h : WellFoundedOn s r) (a : α) :
WellFoundedOn (insert a s) r :=
wellFoundedOn_insert.2 h
protected theorem WellFoundedOn.sdiff_singleton (h : WellFoundedOn s r) (a : α) :
WellFoundedOn (s \ {a}) r :=
wellFoundedOn_sdiff_singleton.2 h
lemma WellFoundedOn.mapsTo {α β : Type*} {r : α → α → Prop} (f : β → α)
{s : Set α} {t : Set β} (h : MapsTo f t s) (hw : s.WellFoundedOn r) :
t.WellFoundedOn (r on f) := by
exact InvImage.wf (fun x : t ↦ ⟨f x, h x.prop⟩) hw
end WellFoundedOn
section LinearOrder
variable [LinearOrder α] {s : Set α}
/-- In a linear order, the predicates `Set.IsPWO` and `Set.IsWF` are equivalent. -/
theorem isPWO_iff_isWF : s.IsPWO ↔ s.IsWF := by
change WellQuasiOrdered (· ≤ ·) ↔ WellFounded (· < ·)
rw [← wellQuasiOrderedLE_def, ← isWellFounded_iff, wellQuasiOrderedLE_iff_wellFoundedLT]
alias ⟨_, IsWF.isPWO⟩ := isPWO_iff_isWF
@[deprecated isPWO_iff_isWF (since := "2025-01-21")]
theorem isWF_iff_isPWO : s.IsWF ↔ s.IsPWO :=
isPWO_iff_isWF.symm
/--
If `α` is a linear order with well-founded `<`, then any set in it is a partially well-ordered set.
Note this does not hold without the linearity assumption.
-/
lemma IsPWO.of_linearOrder [WellFoundedLT α] (s : Set α) : s.IsPWO :=
(IsWF.of_wellFoundedLT s).isPWO
end LinearOrder
end Set
namespace Finset
variable {r : α → α → Prop}
@[simp]
protected theorem partiallyWellOrderedOn [IsRefl α r] (s : Finset α) :
(s : Set α).PartiallyWellOrderedOn r :=
s.finite_toSet.partiallyWellOrderedOn
@[simp]
protected theorem isPWO [Preorder α] (s : Finset α) : Set.IsPWO (↑s : Set α) :=
s.partiallyWellOrderedOn
@[simp]
protected theorem isWF [Preorder α] (s : Finset α) : Set.IsWF (↑s : Set α) :=
s.finite_toSet.isWF
@[simp]
protected theorem wellFoundedOn [IsStrictOrder α r] (s : Finset α) :
Set.WellFoundedOn (↑s : Set α) r :=
letI := partialOrderOfSO r
s.isWF
theorem wellFoundedOn_sup [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
(s.sup f).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r :=
Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_biUnion, hs]
theorem partiallyWellOrderedOn_sup (s : Finset ι) {f : ι → Set α} :
(s.sup f).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r :=
Finset.cons_induction_on s (by simp) fun a s ha hs => by simp [-sup_set_eq_biUnion, hs]
theorem isWF_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
(s.sup f).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
s.wellFoundedOn_sup
theorem isPWO_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
(s.sup f).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
s.partiallyWellOrderedOn_sup
@[simp]
theorem wellFoundedOn_bUnion [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r := by
simpa only [Finset.sup_eq_iSup] using s.wellFoundedOn_sup
@[simp]
theorem partiallyWellOrderedOn_bUnion (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r := by
simpa only [Finset.sup_eq_iSup] using s.partiallyWellOrderedOn_sup
@[simp]
theorem isWF_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
s.wellFoundedOn_bUnion
@[simp]
theorem isPWO_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
(⋃ i ∈ s, f i).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
s.partiallyWellOrderedOn_bUnion
end Finset
namespace Set
section Preorder
variable [Preorder α] {s t : Set α} {a : α}
/-- `Set.IsWF.min` returns a minimal element of a nonempty well-founded set. -/
noncomputable nonrec def IsWF.min (hs : IsWF s) (hn : s.Nonempty) : α :=
hs.min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)
theorem IsWF.min_mem (hs : IsWF s) (hn : s.Nonempty) : hs.min hn ∈ s :=
(WellFounded.min hs univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)).2
nonrec theorem IsWF.not_lt_min (hs : IsWF s) (hn : s.Nonempty) (ha : a ∈ s) : ¬a < hs.min hn :=
hs.not_lt_min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype) (mem_univ (⟨a, ha⟩ : s))
theorem IsWF.min_of_subset_not_lt_min {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF}
{htn : t.Nonempty} (hst : s ⊆ t) : ¬hs.min hsn < ht.min htn :=
ht.not_lt_min htn (hst (min_mem hs hsn))
@[simp]
theorem isWF_min_singleton (a) {hs : IsWF ({a} : Set α)} {hn : ({a} : Set α).Nonempty} :
hs.min hn = a :=
eq_of_mem_singleton (IsWF.min_mem hs hn)
theorem IsWF.min_eq_of_lt (hs : s.IsWF) (ha : a ∈ s) (hlt : ∀ b ∈ s, b ≠ a → a < b) :
hs.min (nonempty_of_mem ha) = a := by
by_contra h
exact (hs.not_lt_min (nonempty_of_mem ha) ha) (hlt (hs.min (nonempty_of_mem ha))
(hs.min_mem (nonempty_of_mem ha)) h)
end Preorder
| section PartialOrder
variable [PartialOrder α] {s : Set α} {a : α}
| Mathlib/Order/WellFoundedSet.lean | 618 | 620 |
/-
Copyright (c) 2023 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.RingTheory.Localization.Module
import Mathlib.RingTheory.Norm.Basic
import Mathlib.RingTheory.Discriminant
/-!
# Field/algebra norm / trace and localization
This file contains results on the combination of `IsLocalization` and `Algebra.norm`,
`Algebra.trace` and `Algebra.discr`.
## Main results
* `Algebra.norm_localization`: let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M`
of `R S` respectively. Then the norm of `a : Sₘ` over `Rₘ` is the norm of `a : S` over `R`
if `S` is free as `R`-module.
* `Algebra.trace_localization`: let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M`
of `R S` respectively. Then the trace of `a : Sₘ` over `Rₘ` is the trace of `a : S` over `R`
if `S` is free as `R`-module.
* `Algebra.discr_localizationLocalization`: let `S` be an extension of `R` and `Rₘ Sₘ` be
localizations at `M` of `R S` respectively. Let `b` be a `R`-basis of `S`. Then discriminant of
the `Rₘ`-basis of `Sₘ` induced by `b` is the discriminant of `b`.
## Tags
field norm, algebra norm, localization
-/
open scoped nonZeroDivisors
variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S]
variable {Rₘ Sₘ : Type*} [CommRing Rₘ] [Algebra R Rₘ] [CommRing Sₘ] [Algebra S Sₘ]
variable (M : Submonoid R)
variable [IsLocalization M Rₘ] [IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ]
variable [Algebra Rₘ Sₘ] [Algebra R Sₘ] [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ]
include M
open Algebra
theorem Algebra.map_leftMulMatrix_localization {ι : Type*} [Fintype ι] [DecidableEq ι]
(b : Basis ι R S) (a : S) :
(algebraMap R Rₘ).mapMatrix (leftMulMatrix b a) =
leftMulMatrix (b.localizationLocalization Rₘ M Sₘ) (algebraMap S Sₘ a) := by
ext i j
simp only [Matrix.map_apply, RingHom.mapMatrix_apply, leftMulMatrix_eq_repr_mul, ← map_mul,
Basis.localizationLocalization_apply, Basis.localizationLocalization_repr_algebraMap]
/-- Let `S` be an extension of `R` and `Rₘ Sₘ` be localizations at `M` of `R S` respectively.
Then the norm of `a : Sₘ` over `Rₘ` is the norm of `a : S` over `R` if `S` is free as `R`-module.
-/
theorem Algebra.norm_localization [Module.Free R S] [Module.Finite R S] (a : S) :
Algebra.norm Rₘ (algebraMap S Sₘ a) = algebraMap R Rₘ (Algebra.norm R a) := by
| cases subsingleton_or_nontrivial R
· haveI : Subsingleton Rₘ := Module.subsingleton R Rₘ
simp [eq_iff_true_of_subsingleton]
let b := Module.Free.chooseBasis R S
letI := Classical.decEq (Module.Free.ChooseBasisIndex R S)
rw [Algebra.norm_eq_matrix_det (b.localizationLocalization Rₘ M Sₘ),
Algebra.norm_eq_matrix_det b, RingHom.map_det, ← Algebra.map_leftMulMatrix_localization]
variable {M} in
| Mathlib/RingTheory/Localization/NormTrace.lean | 61 | 69 |
/-
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, Yourong Zang
-/
import Mathlib.Analysis.Calculus.ContDiff.Operations
import Mathlib.Analysis.Calculus.Deriv.Linear
import Mathlib.Analysis.Complex.Basic
/-! # Real differentiability of complex-differentiable functions
`HasDerivAt.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`),
then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the
complex derivative.
-/
assert_not_exists IsConformalMap Conformal
section RealDerivOfComplex
/-! ### Differentiability of the restriction to `ℝ` of complex functions -/
open Complex
variable {e : ℂ → ℂ} {e' : ℂ} {z : ℝ}
/-- If a complex function is differentiable at a real point, then the induced real function is also
differentiable at this point, with a derivative equal to the real part of the complex derivative. -/
theorem HasStrictDerivAt.real_of_complex (h : HasStrictDerivAt e e' z) :
HasStrictDerivAt (fun x : ℝ => (e x).re) e'.re z := by
have A : HasStrictFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasStrictFDerivAt
have B :
HasStrictFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ)
(ofRealCLM z) :=
h.hasStrictFDerivAt.restrictScalars ℝ
have C : HasStrictFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasStrictFDerivAt
simpa using (C.comp z (B.comp z A)).hasStrictDerivAt
/-- If a complex function `e` is differentiable at a real point, then the function `ℝ → ℝ` given by
the real part of `e` is also differentiable at this point, with a derivative equal to the real part
of the complex derivative. -/
theorem HasDerivAt.real_of_complex (h : HasDerivAt e e' z) :
HasDerivAt (fun x : ℝ => (e x).re) e'.re z := by
have A : HasFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasFDerivAt
have B :
HasFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ)
(ofRealCLM z) :=
h.hasFDerivAt.restrictScalars ℝ
have C : HasFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasFDerivAt
simpa using (C.comp z (B.comp z A)).hasDerivAt
theorem ContDiffAt.real_of_complex {n : WithTop ℕ∞} (h : ContDiffAt ℂ n e z) :
ContDiffAt ℝ n (fun x : ℝ => (e x).re) z := by
have A : ContDiffAt ℝ n ((↑) : ℝ → ℂ) z := ofRealCLM.contDiff.contDiffAt
have B : ContDiffAt ℝ n e z := h.restrict_scalars ℝ
have C : ContDiffAt ℝ n re (e z) := reCLM.contDiff.contDiffAt
exact C.comp z (B.comp z A)
theorem ContDiff.real_of_complex {n : WithTop ℕ∞} (h : ContDiff ℂ n e) :
ContDiff ℝ n fun x : ℝ => (e x).re :=
contDiff_iff_contDiffAt.2 fun _ => h.contDiffAt.real_of_complex
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E]
theorem HasStrictDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E}
(h : HasStrictDerivAt f f' x) :
HasStrictFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by
simpa only [Complex.restrictScalars_one_smulRight'] using
h.hasStrictFDerivAt.restrictScalars ℝ
theorem HasDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasDerivAt f f' x) :
HasFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by
simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivAt.restrictScalars ℝ
theorem HasDerivWithinAt.complexToReal_fderiv' {f : ℂ → E} {s : Set ℂ} {x : ℂ} {f' : E}
(h : HasDerivWithinAt f f' s x) :
HasFDerivWithinAt f (reCLM.smulRight f' + I • imCLM.smulRight f') s x := by
simpa only [Complex.restrictScalars_one_smulRight'] using
h.hasFDerivWithinAt.restrictScalars ℝ
theorem HasStrictDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasStrictDerivAt f f' x) :
HasStrictFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by
simpa only [Complex.restrictScalars_one_smulRight] using h.hasStrictFDerivAt.restrictScalars ℝ
theorem HasDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasDerivAt f f' x) :
HasFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by
simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivAt.restrictScalars ℝ
theorem HasDerivWithinAt.complexToReal_fderiv {f : ℂ → ℂ} {s : Set ℂ} {f' x : ℂ}
(h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (f' • (1 : ℂ →L[ℝ] ℂ)) s x := by
simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivWithinAt.restrictScalars ℝ
/-- If a complex function `e` is differentiable at a real point, then its restriction to `ℝ` is
differentiable there as a function `ℝ → ℂ`, with the same derivative. -/
theorem HasDerivAt.comp_ofReal (hf : HasDerivAt e e' ↑z) : HasDerivAt (fun y : ℝ => e ↑y) e' z := by
simpa only [ofRealCLM_apply, ofReal_one, mul_one] using hf.comp z ofRealCLM.hasDerivAt
/-- If a function `f : ℝ → ℝ` is differentiable at a (real) point `x`, then it is also
differentiable as a function `ℝ → ℂ`. -/
theorem HasDerivAt.ofReal_comp {f : ℝ → ℝ} {u : ℝ} (hf : HasDerivAt f u z) :
HasDerivAt (fun y : ℝ => ↑(f y) : ℝ → ℂ) u z := by
simpa only [ofRealCLM_apply, ofReal_one, real_smul, mul_one] using
ofRealCLM.hasDerivAt.scomp z hf
end RealDerivOfComplex
| Mathlib/Analysis/Complex/RealDeriv.lean | 135 | 136 | |
/-
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 | 261 | 262 | |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov
-/
import Mathlib.Data.Set.Prod
import Mathlib.Data.Set.Restrict
/-!
# Functions over sets
This file contains basic results on the following predicates of functions and sets:
* `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`;
* `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`;
* `Set.InjOn f s` : restriction of `f` to `s` is injective;
* `Set.SurjOn f s t` : every point in `s` has a preimage in `s`;
* `Set.BijOn f s t` : `f` is a bijection between `s` and `t`;
* `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`;
* `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`;
* `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e.
we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`.
-/
variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*}
open Equiv Equiv.Perm Function
namespace Set
/-! ### Equality on a set -/
section equality
variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α}
/-- This lemma exists for use by `aesop` as a forward rule. -/
@[aesop safe forward]
lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a :=
h ha
@[simp]
theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim
@[simp]
theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by
simp [Set.EqOn]
@[simp]
theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by
simp [EqOn, funext_iff]
@[symm]
theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm
theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s :=
⟨EqOn.symm, EqOn.symm⟩
-- This can not be tagged as `@[refl]` with the current argument order.
-- See note below at `EqOn.trans`.
theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl
-- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it
-- the `trans` tactic could not use it.
-- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute.
-- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`.
-- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581).
theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx =>
(h₁ hx).trans (h₂ hx)
theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s :=
image_congr heq
/-- Variant of `EqOn.image_eq`, for one function being the identity. -/
theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by
rw [h.image_eq, image_id]
theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t :=
ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx]
theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx)
@[simp]
theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ :=
forall₂_or_left
theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) :=
eqOn_union.2 ⟨h₁, h₂⟩
theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha =>
congr_arg _ <| h ha
@[simp]
theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} :
EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f :=
forall_mem_range.trans <| funext_iff.symm
alias ⟨EqOn.comp_eq, _⟩ := eqOn_range
end equality
variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ}
{f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β}
section MapsTo
theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t :=
image_subset_iff.symm
theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) :=
diagonal_subset_iff.2 fun _ => rfl
@[deprecated (since := "2025-04-18")]
alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal
theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf
theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl
@[simp]
theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t :=
singleton_subset_iff
theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t :=
empty_subset _
@[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by
simp [mapsTo', subset_empty_iff]
/-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/
theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty :=
(hs.image f).mono (mapsTo'.mp h)
theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t :=
mapsTo'.1 h
theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx =>
h hx ▸ h₁ hx
theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) :=
fun _ ha => hg <| hf ha
theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h =>
h₁ (h₂ h)
theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id
theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s
| 0 => fun _ => id
| n + 1 => (MapsTo.iterate h n).comp h
theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) :
(h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by
funext x
rw [Subtype.ext_iff, MapsTo.val_restrict_apply]
induction n generalizing x with
| zero => rfl
| succ n ihn => simp [Nat.iterate, ihn]
lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) :
MapsTo f s t :=
fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩
lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s :=
mapsTo_of_subsingleton' _ id
theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ :=
fun _ hx => ht (hf <| hs hx)
theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx =>
hf (hs hx)
theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx =>
ht (hf hx)
theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx
theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t :=
union_self t ▸ h₁.union_union h₂
@[simp]
theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t :=
⟨fun h =>
⟨h.mono subset_union_left (Subset.refl t),
h.mono subset_union_right (Subset.refl t)⟩,
fun h => h.1.union h.2⟩
theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx =>
⟨h₁ hx, h₂ hx⟩
lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by
simpa [← singleton_union] using h.mono_right subset_union_right
theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) :
MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩
@[simp]
theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ :=
⟨fun h =>
⟨h.mono (Subset.refl s) inter_subset_left,
h.mono (Subset.refl s) inter_subset_right⟩,
fun h => h.1.inter h.2⟩
theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial
theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) :=
(mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _)
@[simp]
theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} :
MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t :=
⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩
lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) :=
fun x hx ↦ ⟨f x, hf hx, rfl⟩
lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) :
MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx
@[simp]
lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t :=
⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩
@[simp]
lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t :=
forall_mem_range
theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s :=
⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩
end MapsTo
/-! ### Injectivity on a set -/
section injOn
theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ =>
hs hx hy
@[simp]
theorem injOn_empty (f : α → β) : InjOn f ∅ :=
subsingleton_empty.injOn f
@[simp]
theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} :=
subsingleton_singleton.injOn f
@[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop
theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y :=
⟨h hx hy, fun h => h ▸ rfl⟩
theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y :=
(h.eq_iff hx hy).not
alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff
theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy =>
h hx ▸ h hy ▸ h₁ hx hy
theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H =>
ht (h hx) (h hy) H
theorem injOn_union (h : Disjoint s₁ s₂) :
InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by
refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩
· intro x hx y hy hxy
obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy
exact h.le_bot ⟨hx, hy⟩
· rintro ⟨h₁, h₂, h₁₂⟩
rintro x (hx | hx) y (hy | hy) hxy
exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy]
theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) :
Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by
rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)]
simp
theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ :=
⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩
theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy
alias _root_.Function.Injective.injOn := injOn_of_injective
-- A specialization of `injOn_of_injective` for `Subtype.val`.
theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s :=
Subtype.coe_injective.injOn
lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn
theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s :=
fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq
lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s :=
fun _ hx _ hy heq ↦ h hx hy (by simp [heq])
lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) :=
forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq
lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) :=
⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩
lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) :
∀ n, InjOn f^[n] s
| 0 => injOn_id _
| (n + 1) => (h.iterate hf n).comp h hf
lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s :=
(injective_of_subsingleton _).injOn
theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by
rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H
exact congr_arg f (h H)
theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) :
Injective (g ∘ f) ↔ Injective f :=
⟨(·.of_comp), fun h _ ↦ by aesop⟩
theorem exists_injOn_iff_injective [Nonempty β] :
(∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f :=
⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩,
fun ⟨f, hf⟩ => by
lift f to α → β using trivial
exact ⟨f, injOn_iff_injective.2 hf⟩⟩
theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B :=
fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst
theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) :
x ∈ s₁ :=
let ⟨_, h', Eq⟩ := h₁
hf (hs h') h Eq ▸ h'
theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) :
f x ∈ f '' s₁ ↔ x ∈ s₁ :=
⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩
theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ :=
ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩
theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t)
(hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha)
theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) :
s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ :=
⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩
lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) :
f '' (s ∩ t) = f '' s ∩ f '' t := by
apply Subset.antisymm (image_inter_subset _ _ _)
intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩
have : y = z := by
apply hf (hs ys) (ht zt)
rwa [← hz] at hy
rw [← this] at zt
exact ⟨y, ⟨ys, zt⟩, hy⟩
lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) :=
fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂]
theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ = f '' s₂ ↔ s₁ = s₂ :=
h.image.eq_iff h₁ h₂
lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by
refine ⟨fun h' ↦ ?_, image_subset _⟩
rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂]
exact inter_subset_inter_left _ (preimage_mono h')
lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) :
f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by
simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁]
-- TODO: can this move to a better place?
theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f)
(hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by
rw [disjoint_iff_inter_eq_empty] at h ⊢
rw [← hf.image_inter hs ht, h, image_empty]
lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by
refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩)
(diff_subset_iff.2 (by rw [← image_union, inter_union_diff]))
exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left
lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) :
f '' (s \ t) = f '' s \ f '' t := by
rw [h.image_diff, inter_eq_self_of_subset_right hst]
alias image_diff_of_injOn := InjOn.image_diff_subset
theorem InjOn.imageFactorization_injective (h : InjOn f s) :
Injective (s.imageFactorization f) :=
fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h'
@[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s :=
⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]),
InjOn.imageFactorization_injective⟩
end injOn
section graphOn
variable {x : α × β}
lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp
lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) :=
fun _f _g ↦ graphOn_univ_inj.1
lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} :
(∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by
refine ⟨?_, fun h ↦ ?_⟩
· rintro ⟨f, hf⟩
rw [hf]
exact InjOn.image_of_comp <| injOn_id _
· have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩
choose! f hf using this
rw [forall_mem_image] at hf
use f
rw [graphOn, image_image, EqOn.image_eq_self]
exact fun x hx ↦ h (hf hx) hx rfl
lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} :
(∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s :=
.trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩
exists_eq_graphOn_image_fst
end graphOn
/-! ### Surjectivity on a set -/
section surjOn
theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f :=
Subset.trans h <| image_subset_range f s
theorem surjOn_iff_exists_map_subtype :
SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x :=
⟨fun h =>
⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩,
fun ⟨t', g, htt', hg, hfg⟩ y hy =>
let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩
⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩
theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ :=
empty_subset _
@[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by
simp [SurjOn, subset_empty_iff]
@[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff
theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) :=
Subset.rfl
theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty :=
(ht.mono h).of_image
theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by
rwa [SurjOn, ← H.image_eq]
theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t :=
⟨fun H => H.congr h, fun H => H.congr h.symm⟩
theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ :=
Subset.trans ht <| Subset.trans hf <| image_subset _ hs
theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx =>
hx.elim (fun hx => h₁ hx) fun hx => h₂ hx
theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) :
SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) :=
(h₁.mono subset_union_left (Subset.refl _)).union
(h₂.mono subset_union_right (Subset.refl _))
theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by
intro y hy
rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩
rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩
obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm
exact mem_image_of_mem f ⟨hx₁, hx₂⟩
theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) :
SurjOn f (s₁ ∩ s₂) t :=
inter_self t ▸ h₁.inter_inter h₂ h
lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn]
theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p :=
Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _
lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by
intro z hz
obtain ⟨x, hx, rfl⟩ := h hz
exact ⟨f x, hr hx, rfl⟩
lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p :=
⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩
lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s
| 0 => surjOn_id _
| (n + 1) => (h.iterate n).comp h
lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by
rw [SurjOn, image_comp g f]; exact image_subset _ hf
lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) :
SurjOn (g ∘ f) (f ⁻¹' s) t := by
rwa [SurjOn, image_comp g f, image_preimage_eq _ hf]
lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) :
SurjOn f s t :=
fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _
lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s :=
surjOn_of_subsingleton' _ id
theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by
simp [Surjective, SurjOn, subset_def]
theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t :=
eq_of_subset_of_subset h₂.image_subset h₁
theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by
refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩
rintro rfl
exact ⟨s.surjOn_image f, s.mapsTo_image f⟩
lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ :=
image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx
theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ :=
fun _ hs ht =>
let ⟨_, hx', HEq⟩ := h ht
hs <| h' HEq ▸ hx'
theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ :=
h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs)
theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by
intro b hb
obtain ⟨a, ha, rfl⟩ := hf' hb
exact hf ha
theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) :
s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ :=
⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩
theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ :=
(s.surjOn_image f).cancel_right <| s.mapsTo_image f
theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) :
(∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) :=
⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩
end surjOn
/-! ### Bijectivity -/
section bijOn
theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t :=
h.left
theorem BijOn.injOn (h : BijOn f s t) : InjOn f s :=
h.right.left
theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t :=
h.right.right
theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t :=
⟨h₁, h₂, h₃⟩
theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ :=
⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩
@[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ :=
⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩
@[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ :=
⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩
@[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm]
theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy =>
let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1
⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩
theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃
theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) :=
⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left,
h₁.surjOn.inter_inter h₂.surjOn h⟩
theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) :
BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) :=
⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩
theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f :=
h.surjOn.subset_range
theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) :=
BijOn.mk (mapsTo_image f s) h (Subset.refl _)
theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t :=
BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h)
theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t :=
⟨fun h => h.congr H, fun h => h.congr H.symm⟩
theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t :=
h.surjOn.image_eq_of_mapsTo h.mapsTo
lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where
mp h _ ha := h _ <| hf.mapsTo ha
mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha
lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where
mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩
mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩
lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t :=
⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩,
BijOn.image_eq⟩
lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩
theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p :=
BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn)
/-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection
on `s` iff `g` is a bijection on `f '' s`. -/
theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by
simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf]
/--
If we have a commutative square
```
α --f--> β
| |
p₁ p₂
| |
\/ \/
γ --g--> δ
```
and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g`
induces a bijection from the image of `s` to the image of `t`, as long as `g` is
is injective on the image of `s`.
-/
theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a))
(hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by
obtain ⟨h1, h2, h3⟩ := hbij
refine ⟨?_, hinj, ?_⟩
· rintro _ ⟨a, ha, rfl⟩
exact ⟨f a, h1 ha, by rw [comm a]⟩
· rintro _ ⟨b, hb, rfl⟩
obtain ⟨a, ha, rfl⟩ := h3 hb
rw [← image_comp, comm]
exact ⟨a, ha, rfl⟩
lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s
| 0 => s.bijOn_id
| (n + 1) => (h.iterate n).comp h
lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β)
(h : s.Nonempty ↔ t.Nonempty) : BijOn f s t :=
⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩
lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s :=
bijOn_of_subsingleton' _ Iff.rfl
theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) :=
⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ =>
let ⟨x, hx, hxy⟩ := h.surjOn hy
⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩
theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ :=
Iff.intro
(fun h =>
let ⟨inj, surj⟩ := h
⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩)
fun h =>
let ⟨_map, inj, surj⟩ := h
⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩
alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ
theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ :=
⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩
theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) :
BijOn f (s ∩ f ⁻¹' r) r := by
refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩
obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx)
exact ⟨y, ⟨hy, hx⟩, rfl⟩
theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) :
BijOn f r (f '' r) :=
(hf.injOn.mono hrs).bijOn_image
theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) :
BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where
mp h := by
have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq)
simp only [mem_singleton_iff, insert_diff_of_mem] at this
rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this
· exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..),
by simp [← this, surjOn_image]⟩
simp only [mem_image, not_exists, not_and]
intro x hx
rw [h.injOn.eq_iff (by simp [hx]) (by simp)]
exact ha ∘ (· ▸ hx)
mpr h := by
repeat rw [insert_eq]
refine (bijOn_singleton.mpr rfl).union h ?_
simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image,
not_exists, not_and, true_and]
exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx)
theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) :
BijOn f (insert a s) (insert (f a) t) :=
(insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁
theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) :
BijOn f (s \ {a}) (t \ {f a}) := by
convert h₁.subset_left diff_subset
simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right]
end bijOn
/-! ### left inverse -/
namespace LeftInvOn
theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s :=
h
theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x :=
h hx
theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t)
(heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx
theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s :=
fun _ hx => heq hx ▸ h₁ hx
theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq =>
calc
x₁ = f₁' (f x₁) := Eq.symm <| h h₁
_ = f₁' (f x₂) := congr_arg f₁' heq
_ = x₂ := h h₂
theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx =>
⟨f x, hf hx, h hx⟩
theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) :
MapsTo f' t s := fun y hy => by
let ⟨x, hs, hx⟩ := hf hy
rwa [← hx, h hs]
lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl
theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) :
LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h =>
calc
(f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h))
_ = x := hf' h
theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx =>
hf (ht hx)
theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by
apply Subset.antisymm
· rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩
exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩
· rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩
exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩
theorem image_inter (hf : LeftInvOn f' f s) :
f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by
rw [hf.image_inter']
refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left))
rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩
theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by
rw [Set.image_image, image_congr hf, image_id']
theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ :=
(hf.mono hs).image_image
end LeftInvOn
/-! ### Right inverse -/
section RightInvOn
namespace RightInvOn
theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t :=
h
theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y :=
h hy
theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) :=
fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx)
theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) :
RightInvOn f₂' f t :=
h₁.congr_right heq
theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) :
RightInvOn f' f₂ t :=
LeftInvOn.congr_left h₁ hg heq
theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t :=
LeftInvOn.surjOn hf hf'
theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t :=
LeftInvOn.mapsTo h hf
lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl
theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) :
RightInvOn (f' ∘ g') (g ∘ f) p :=
LeftInvOn.comp hg hf g'pt
theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ :=
LeftInvOn.mono hf ht
end RightInvOn
theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t)
(h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h =>
hf (h₂ <| h₁ h) h (hf' (h₁ h))
theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t)
(h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy =>
calc
f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm
_ = f₂' y := h₁ (h hy)
theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) :
LeftInvOn f f' t := fun y hy => by
let ⟨x, hx, heq⟩ := hf hy
rw [← heq, hf' hx]
end RightInvOn
/-! ### Two-side inverses -/
namespace InvOn
lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩
lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t)
(g'pt : MapsTo g' p t) :
InvOn (f' ∘ g') (g ∘ f) s p :=
⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩
@[symm]
theorem symm (h : InvOn f' f s t) : InvOn f f' t s :=
⟨h.right, h.left⟩
theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ :=
⟨h.1.mono hs, h.2.mono ht⟩
/-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t`
into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from
`surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/
theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t :=
⟨hf, h.left.injOn, h.right.surjOn hf'⟩
end InvOn
end Set
/-! ### `invFunOn` is a left/right inverse -/
namespace Function
variable {s : Set α} {f : α → β} {a : α} {b : β}
/-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f`
on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/
noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α :=
open scoped Classical in
if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α›
variable [Nonempty α]
theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by
rw [invFunOn, dif_pos h]
exact Classical.choose_spec h
theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s :=
(invFunOn_pos h).left
theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b :=
(invFunOn_pos h).right
theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by
rw [invFunOn, dif_neg h]
@[simp]
theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s :=
invFunOn_mem ⟨a, h, rfl⟩
theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a :=
invFunOn_eq ⟨a, h, rfl⟩
end Function
open Function
namespace Set
variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β}
theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s :=
fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha)
theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) :
invFunOn f s₂ '' (f '' s₁) = s₁ :=
h.leftInvOn_invFunOn.image_image' ht
theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α]
(h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s :=
fun x hx ↦ by
obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx
rw [invFunOn_apply_eq (f := f) hx']
theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] :
InjOn f s ↔ (invFunOn f s) '' (f '' s) = s :=
⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦
(Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩
theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) :
Set.InjOn (invFunOn f s) (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he
rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx']
theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) :
(invFunOn f s) '' (f '' s) ⊆ s := by
rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx
theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy
theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t :=
⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩
theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) :
InvOn (invFunOn f s) f (invFunOn f s '' t) t := by
refine ⟨?_, h.rightInvOn_invFunOn⟩
rintro _ ⟨y, hy, rfl⟩
rw [h.rightInvOn_invFunOn hy]
theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s :=
fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy
/-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense
to use the other lemma directly in an application. -/
theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t)
(hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r :=
hf.rightInvOn_invFunOn.image_image' hrt
/-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense
to use the other lemma directly in an application. -/
theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) :
f '' (f.invFunOn s '' t) = t :=
hf.rightInvOn_invFunOn.image_image
theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by
refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _)
rintro _ ⟨y, hy, rfl⟩
rwa [h.rightInvOn_invFunOn hy]
theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by
constructor
· rcases eq_empty_or_nonempty t with (rfl | ht)
· exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩
· intro h
haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩
exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩
· rintro ⟨s', hs', hfs'⟩
exact hfs'.surjOn.mono hs' (Subset.refl _)
alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset
variable (f s)
lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) :=
surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s)
lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u :=
let ⟨u, _, hfu⟩ := exists_subset_bijOn s f
⟨u, hfu.image_eq, hfu.injOn⟩
variable {f s}
lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) :
∃ s, f '' s = t ∧ InjOn f s :=
image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _
/-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`,
then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/
theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t')
(ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by
obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f
rw [image_diff_preimage, image_inter_preimage] at hbij
refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩
· exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left
· rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff]
exact ⟨htt', diff_subset.trans inter_subset_right⟩
· rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn]
· refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_
rw [← h.image_eq]
exact ⟨x, hxs, hxy⟩
exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo
rw [image_union, h.image_eq, hbij.image_eq, union_diff_self]
exact .inr ⟨ht' hyt', hyt'⟩
/-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`,
then `f` maps some superset of `s` bijectively to `t'`. -/
theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) :
∃ s', s ⊆ s' ∧ BijOn f s' t' := by
simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn])
theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) :
∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by
obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs
(image_subset f hrs) Subset.rfl
exact ⟨u, hru, hus, h.image_eq, h.injOn⟩
theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α}
(h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by
ext x
rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx)
· simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false,
leftInverse_invFun hf _, hf.mem_set_image]
· simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true]
theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α}
(h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by
ext x
rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx)
· rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image]
· have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h')
simp only [mem_preimage, invFun_neg hx, h, this]
lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s :=
⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩
lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s :=
⟨BijOn.symm h, BijOn.symm h.symm⟩
end Set
namespace Function
open Set
variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α}
theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) :=
hg.injOn.comp hf (mapsTo_univ _ _)
theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s :=
(surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _)
theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s :=
fun x _ => h x
theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) :
RightInvOn f g s := fun x _ => h x
theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) :
RightInvOn f g (range g) :=
forall_mem_range.2 fun i => congr_arg g (h i)
namespace Semiconj
theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) :=
fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩
theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) :
MapsTo f (fa '' s) (fb '' t) :=
mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩
theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ =>
hy ▸ ⟨fa x, h x⟩
theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by
rintro y ⟨x, hxt, rfl⟩
rcases ha hxt with ⟨x, hxs, rfl⟩
rw [h x]
exact mem_image_of_mem _ (mem_image_of_mem _ hxs)
theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) :
SurjOn fb (range f) (range f) := by
rw [← image_univ]
exact h.surjOn_image (ha.surjOn univ)
theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) :
InjOn fb (f '' s) := by
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H
simp only [← h.eq] at H
exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H)
theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) :
InjOn fb (range f) := by
rw [← image_univ] at *
exact h.injOn_image ha.injOn hf
theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) :
BijOn fb (f '' s) (f '' t) :=
⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf),
h.surjOn_image ha.surjOn⟩
theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) :
BijOn fb (range f) (range f) := by
rw [← image_univ]
exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn
theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) :
MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx]
theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s)
(hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by
intro x hx y hy H
have := congr_arg f H
rw [h.eq, h.eq] at this
exact hf hx hy (hb hx hy this)
end Semiconj
theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β]
(g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) :
(fun j => update g i a (f j)) = fun j => g (f j) :=
(update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩
/-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/
theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β]
(g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f :=
update_comp_eq_of_not_mem_range' g a h
theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ =>
(insert_inj ha).1
lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) :
f a = b := by
simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a
end Function
/-! ### Equivalences, permutations -/
namespace Set
variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α}
protected lemma MapsTo.extendDomain (h : MapsTo g s t) :
MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩
protected lemma SurjOn.extendDomain (h : SurjOn g s t) :
SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩
obtain ⟨b, hb, rfl⟩ := h ha
exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩
protected lemma BijOn.extendDomain (h : BijOn g s t) :
BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) :=
⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩
protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) :
LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by
rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha]
protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) :
RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by
rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha]
protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) :
InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) :=
⟨h.1.extendDomain, h.2.extendDomain⟩
end Set
namespace Set
variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂}
{f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂}
lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) :
(s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) :=
fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2)
lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) :
SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by
rintro x hx
obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1
obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2
exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩
lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) :
MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩
lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) :
BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩
lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) :
LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) :=
fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2)
lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) :
RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) :=
fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2)
lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) :
InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) :=
⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩
end Set
namespace Equiv
open Set
variable (e : α ≃ β) {s : Set α} {t : Set β}
lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t :=
⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩
protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t :=
e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply]
lemma invOn : InvOn e e.symm t s :=
⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩
lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image
lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn
variable {e}
@[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn
alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm
variable [DecidableEq α] {a b : α}
lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s :=
(swap a b).bijOn fun x ↦ by
obtain rfl | hxa := eq_or_ne x a <;>
obtain rfl | hxb := eq_or_ne x b <;>
simp [*, swap_apply_of_ne_of_ne]
end Equiv
| Mathlib/Data/Set/Function.lean | 1,408 | 1,410 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Chris Hughes
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.Data.Fintype.Inv
import Mathlib.GroupTheory.SpecificGroups.Cyclic
import Mathlib.Tactic.FieldSimp
/-!
# Integral domains
Assorted theorems about integral domains.
## Main theorems
* `isCyclic_of_subgroup_isDomain`: A finite subgroup of the units of an integral domain is cyclic.
* `Fintype.fieldOfDomain`: A finite integral domain is a field.
## Notes
Wedderburn's little theorem, which shows that all finite division rings are actually fields,
is in `Mathlib.RingTheory.LittleWedderburn`.
## Tags
integral domain, finite integral domain, finite field
-/
section
open Finset Polynomial Function Nat
section CancelMonoidWithZero
-- There doesn't seem to be a better home for these right now
variable {M : Type*} [CancelMonoidWithZero M] [Finite M]
theorem mul_right_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => a * b :=
Finite.injective_iff_bijective.1 <| mul_right_injective₀ ha
theorem mul_left_bijective_of_finite₀ {a : M} (ha : a ≠ 0) : Bijective fun b => b * a :=
Finite.injective_iff_bijective.1 <| mul_left_injective₀ ha
/-- Every finite nontrivial cancel_monoid_with_zero is a group_with_zero. -/
def Fintype.groupWithZeroOfCancel (M : Type*) [CancelMonoidWithZero M] [DecidableEq M] [Fintype M]
[Nontrivial M] : GroupWithZero M :=
{ ‹Nontrivial M›,
‹CancelMonoidWithZero M› with
inv := fun a => if h : a = 0 then 0 else Fintype.bijInv (mul_right_bijective_of_finite₀ h) 1
mul_inv_cancel := fun a ha => by
simp only [Inv.inv, dif_neg ha]
exact Fintype.rightInverse_bijInv _ _
inv_zero := by simp [Inv.inv, dif_pos rfl] }
theorem exists_eq_pow_of_mul_eq_pow_of_coprime {R : Type*} [CommSemiring R] [IsDomain R]
[GCDMonoid R] [Subsingleton Rˣ] {a b c : R} {n : ℕ} (cp : IsCoprime a b) (h : a * b = c ^ n) :
∃ d : R, a = d ^ n := by
refine exists_eq_pow_of_mul_eq_pow (isUnit_of_dvd_one ?_) h
obtain ⟨x, y, hxy⟩ := cp
rw [← hxy]
exact -- Porting note: added `GCDMonoid.` twice
dvd_add (dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_left _ _) _)
(dvd_mul_of_dvd_right (GCDMonoid.gcd_dvd_right _ _) _)
nonrec
theorem Finset.exists_eq_pow_of_mul_eq_pow_of_coprime {ι R : Type*} [CommSemiring R] [IsDomain R]
[GCDMonoid R] [Subsingleton Rˣ] {n : ℕ} {c : R} {s : Finset ι} {f : ι → R}
(h : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → IsCoprime (f i) (f j))
(hprod : ∏ i ∈ s, f i = c ^ n) : ∀ i ∈ s, ∃ d : R, f i = d ^ n := by
classical
intro i hi
rw [← insert_erase hi, prod_insert (not_mem_erase i s)] at hprod
refine
exists_eq_pow_of_mul_eq_pow_of_coprime
(IsCoprime.prod_right fun j hj => h i hi j (erase_subset i s hj) fun hij => ?_) hprod
rw [hij] at hj
exact (s.not_mem_erase _) hj
end CancelMonoidWithZero
variable {R : Type*} {G : Type*}
section Ring
variable [Ring R] [IsDomain R] [Fintype R]
/-- Every finite domain is a division ring. More generally, they are fields; this can be found in
`Mathlib.RingTheory.LittleWedderburn`. -/
def Fintype.divisionRingOfIsDomain (R : Type*) [Ring R] [IsDomain R] [DecidableEq R] [Fintype R] :
DivisionRing R where
__ := (‹Ring R›:) -- this also works without the `( :)`, but it's slightly slow
__ := Fintype.groupWithZeroOfCancel R
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
/-- Every finite commutative domain is a field. More generally, commutativity is not required: this
can be found in `Mathlib.RingTheory.LittleWedderburn`. -/
def Fintype.fieldOfDomain (R) [CommRing R] [IsDomain R] [DecidableEq R] [Fintype R] : Field R :=
{ Fintype.divisionRingOfIsDomain R, ‹CommRing R› with }
theorem Finite.isField_of_domain (R) [CommRing R] [IsDomain R] [Finite R] : IsField R := by
cases nonempty_fintype R
exact @Field.toIsField R (@Fintype.fieldOfDomain R _ _ (Classical.decEq R) _)
end Ring
|
variable [CommRing R] [IsDomain R] [Group G]
| Mathlib/RingTheory/IntegralDomain.lean | 111 | 113 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov, Kexing Ying
-/
import Mathlib.Topology.Semicontinuous
import Mathlib.MeasureTheory.Function.AEMeasurableSequence
import Mathlib.MeasureTheory.Order.Lattice
import Mathlib.Topology.Order.Lattice
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
/-!
# Borel sigma algebras on spaces with orders
## Main statements
* `borel_eq_generateFrom_Ixx` (where Ixx is one of {Iio, Ioi, Iic, Ici, Ico, Ioc}):
The Borel sigma algebra of a linear order topology is generated by intervals of the given kind.
* `Dense.borel_eq_generateFrom_Ico_mem`, `Dense.borel_eq_generateFrom_Ioc_mem`:
The Borel sigma algebra of a dense linear order topology is generated by intervals of a given
kind, with endpoints from dense subsets.
* `ext_of_Ico`, `ext_of_Ioc`:
A locally finite Borel measure on a second countable conditionally complete linear order is
characterized by the measures of intervals of the given kind.
* `ext_of_Iic`, `ext_of_Ici`:
A finite Borel measure on a second countable linear order is characterized by the measures of
intervals of the given kind.
* `UpperSemicontinuous.measurable`, `LowerSemicontinuous.measurable`:
Semicontinuous functions are measurable.
* `Measurable.iSup`, `Measurable.iInf`, `Measurable.sSup`, `Measurable.sInf`:
Countable supremums and infimums of measurable functions to conditionally complete linear orders
are measurable.
* `Measurable.liminf`, `Measurable.limsup`:
Countable liminfs and limsups of measurable functions to conditionally complete linear orders
are measurable.
-/
open Set Filter MeasureTheory MeasurableSpace TopologicalSpace
open scoped Topology NNReal ENNReal MeasureTheory
universe u v w x y
variable {α β γ δ : Type*} {ι : Sort y} {s t u : Set α}
section OrderTopology
variable (α)
variable [TopologicalSpace α] [SecondCountableTopology α] [LinearOrder α] [OrderTopology α]
theorem borel_eq_generateFrom_Iio : borel α = .generateFrom (range Iio) := by
refine le_antisymm ?_ (generateFrom_le ?_)
· rw [borel_eq_generateFrom_of_subbasis (@OrderTopology.topology_eq_generate_intervals α _ _ _)]
letI : MeasurableSpace α := MeasurableSpace.generateFrom (range Iio)
have H : ∀ a : α, MeasurableSet (Iio a) := fun a => GenerateMeasurable.basic _ ⟨_, rfl⟩
refine generateFrom_le ?_
rintro _ ⟨a, rfl | rfl⟩
· rcases em (∃ b, a ⋖ b) with ⟨b, hb⟩ | hcovBy
· rw [hb.Ioi_eq, ← compl_Iio]
exact (H _).compl
· rcases isOpen_biUnion_countable (Ioi a) Ioi fun _ _ ↦ isOpen_Ioi with ⟨t, hat, htc, htU⟩
have : Ioi a = ⋃ b ∈ t, Ici b := by
refine Subset.antisymm ?_ <| iUnion₂_subset fun b hb ↦ Ici_subset_Ioi.2 (hat hb)
refine Subset.trans ?_ <| iUnion₂_mono fun _ _ ↦ Ioi_subset_Ici_self
simpa [CovBy, htU, subset_def] using hcovBy
simp only [this, ← compl_Iio]
exact .biUnion htc <| fun _ _ ↦ (H _).compl
· apply H
· rw [forall_mem_range]
intro a
exact GenerateMeasurable.basic _ isOpen_Iio
theorem borel_eq_generateFrom_Ioi : borel α = .generateFrom (range Ioi) :=
@borel_eq_generateFrom_Iio αᵒᵈ _ (by infer_instance : SecondCountableTopology α) _ _
theorem borel_eq_generateFrom_Iic :
borel α = MeasurableSpace.generateFrom (range Iic) := by
rw [borel_eq_generateFrom_Ioi]
refine le_antisymm ?_ ?_
· refine MeasurableSpace.generateFrom_le fun t ht => ?_
obtain ⟨u, rfl⟩ := ht
rw [← compl_Iic]
exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl
· refine MeasurableSpace.generateFrom_le fun t ht => ?_
obtain ⟨u, rfl⟩ := ht
rw [← compl_Ioi]
exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl
theorem borel_eq_generateFrom_Ici : borel α = MeasurableSpace.generateFrom (range Ici) :=
@borel_eq_generateFrom_Iic αᵒᵈ _ _ _ _
end OrderTopology
section Orders
variable [TopologicalSpace α] {mα : MeasurableSpace α} [OpensMeasurableSpace α]
variable {mδ : MeasurableSpace δ}
section Preorder
variable [Preorder α] [OrderClosedTopology α] {a b x : α} {μ : Measure α}
@[simp, measurability]
theorem measurableSet_Ici : MeasurableSet (Ici a) :=
isClosed_Ici.measurableSet
theorem nullMeasurableSet_Ici : NullMeasurableSet (Ici a) μ :=
measurableSet_Ici.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Iic : MeasurableSet (Iic a) :=
isClosed_Iic.measurableSet
theorem nullMeasurableSet_Iic : NullMeasurableSet (Iic a) μ :=
measurableSet_Iic.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Icc : MeasurableSet (Icc a b) :=
isClosed_Icc.measurableSet
theorem nullMeasurableSet_Icc : NullMeasurableSet (Icc a b) μ :=
measurableSet_Icc.nullMeasurableSet
instance nhdsWithin_Ici_isMeasurablyGenerated : (𝓝[Ici b] a).IsMeasurablyGenerated :=
measurableSet_Ici.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_Iic_isMeasurablyGenerated : (𝓝[Iic b] a).IsMeasurablyGenerated :=
measurableSet_Iic.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_Icc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[Icc a b] x) := by
rw [← Ici_inter_Iic, nhdsWithin_inter]
infer_instance
instance atTop_isMeasurablyGenerated : (Filter.atTop : Filter α).IsMeasurablyGenerated :=
@Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a =>
(measurableSet_Ici : MeasurableSet (Ici a)).principal_isMeasurablyGenerated
instance atBot_isMeasurablyGenerated : (Filter.atBot : Filter α).IsMeasurablyGenerated :=
@Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a =>
(measurableSet_Iic : MeasurableSet (Iic a)).principal_isMeasurablyGenerated
instance [R1Space α] : IsMeasurablyGenerated (cocompact α) where
exists_measurable_subset := by
intro _ hs
obtain ⟨t, ht, hts⟩ := mem_cocompact.mp hs
exact ⟨(closure t)ᶜ, ht.closure.compl_mem_cocompact, isClosed_closure.measurableSet.compl,
(compl_subset_compl.2 subset_closure).trans hts⟩
end Preorder
section PartialOrder
variable [PartialOrder α] [OrderClosedTopology α] [SecondCountableTopology α] {a b : α}
@[measurability]
theorem measurableSet_le' : MeasurableSet { p : α × α | p.1 ≤ p.2 } :=
OrderClosedTopology.isClosed_le'.measurableSet
@[measurability]
theorem measurableSet_le {f g : δ → α} (hf : Measurable f) (hg : Measurable g) :
MeasurableSet { a | f a ≤ g a } :=
hf.prodMk hg measurableSet_le'
end PartialOrder
section LinearOrder
variable [LinearOrder α] [OrderClosedTopology α] {a b x : α} {μ : Measure α}
-- we open this locale only here to avoid issues with list being treated as intervals above
open Interval
@[simp, measurability]
theorem measurableSet_Iio : MeasurableSet (Iio a) :=
isOpen_Iio.measurableSet
theorem nullMeasurableSet_Iio : NullMeasurableSet (Iio a) μ :=
measurableSet_Iio.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ioi : MeasurableSet (Ioi a) :=
isOpen_Ioi.measurableSet
theorem nullMeasurableSet_Ioi : NullMeasurableSet (Ioi a) μ :=
measurableSet_Ioi.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ioo : MeasurableSet (Ioo a b) :=
isOpen_Ioo.measurableSet
theorem nullMeasurableSet_Ioo : NullMeasurableSet (Ioo a b) μ :=
measurableSet_Ioo.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ioc : MeasurableSet (Ioc a b) :=
measurableSet_Ioi.inter measurableSet_Iic
theorem nullMeasurableSet_Ioc : NullMeasurableSet (Ioc a b) μ :=
measurableSet_Ioc.nullMeasurableSet
@[simp, measurability]
theorem measurableSet_Ico : MeasurableSet (Ico a b) :=
measurableSet_Ici.inter measurableSet_Iio
theorem nullMeasurableSet_Ico : NullMeasurableSet (Ico a b) μ :=
measurableSet_Ico.nullMeasurableSet
instance nhdsWithin_Ioi_isMeasurablyGenerated : (𝓝[Ioi b] a).IsMeasurablyGenerated :=
measurableSet_Ioi.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_Iio_isMeasurablyGenerated : (𝓝[Iio b] a).IsMeasurablyGenerated :=
measurableSet_Iio.nhdsWithin_isMeasurablyGenerated _
instance nhdsWithin_uIcc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[[[a, b]]] x) :=
nhdsWithin_Icc_isMeasurablyGenerated
@[measurability]
theorem measurableSet_lt' [SecondCountableTopology α] : MeasurableSet { p : α × α | p.1 < p.2 } :=
(isOpen_lt continuous_fst continuous_snd).measurableSet
@[measurability]
theorem measurableSet_lt [SecondCountableTopology α] {f g : δ → α} (hf : Measurable f)
(hg : Measurable g) : MeasurableSet { a | f a < g a } :=
hf.prodMk hg measurableSet_lt'
theorem nullMeasurableSet_lt [SecondCountableTopology α] {μ : Measure δ} {f g : δ → α}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { a | f a < g a } μ :=
(hf.prodMk hg).nullMeasurable measurableSet_lt'
theorem nullMeasurableSet_lt' [SecondCountableTopology α] {μ : Measure (α × α)} :
NullMeasurableSet { p : α × α | p.1 < p.2 } μ :=
measurableSet_lt'.nullMeasurableSet
theorem nullMeasurableSet_le [SecondCountableTopology α] {μ : Measure δ}
{f g : δ → α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
NullMeasurableSet { a | f a ≤ g a } μ :=
(hf.prodMk hg).nullMeasurable measurableSet_le'
theorem Set.OrdConnected.measurableSet (h : OrdConnected s) : MeasurableSet s := by
let u := ⋃ (x ∈ s) (y ∈ s), Ioo x y
have huopen : IsOpen u := isOpen_biUnion fun _ _ => isOpen_biUnion fun _ _ => isOpen_Ioo
have humeas : MeasurableSet u := huopen.measurableSet
have hfinite : (s \ u).Finite := s.finite_diff_iUnion_Ioo
have : u ⊆ s := iUnion₂_subset fun x hx => iUnion₂_subset fun y hy =>
Ioo_subset_Icc_self.trans (h.out hx hy)
rw [← union_diff_cancel this]
exact humeas.union hfinite.measurableSet
theorem IsPreconnected.measurableSet (h : IsPreconnected s) : MeasurableSet s :=
h.ordConnected.measurableSet
theorem generateFrom_Ico_mem_le_borel {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderClosedTopology α] (s t : Set α) :
MeasurableSpace.generateFrom { S | ∃ l ∈ s, ∃ u ∈ t, l < u ∧ Ico l u = S }
≤ borel α := by
apply generateFrom_le
borelize α
rintro _ ⟨a, -, b, -, -, rfl⟩
exact measurableSet_Ico
theorem Dense.borel_eq_generateFrom_Ico_mem_aux {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] [SecondCountableTopology α] {s : Set α} (hd : Dense s)
(hbot : ∀ x, IsBot x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → y ∈ s) :
borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } := by
set S : Set (Set α) := { S | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S }
refine le_antisymm ?_ (generateFrom_Ico_mem_le_borel _ _)
letI : MeasurableSpace α := generateFrom S
rw [borel_eq_generateFrom_Iio]
refine generateFrom_le (forall_mem_range.2 fun a => ?_)
rcases hd.exists_countable_dense_subset_bot_top with ⟨t, hts, hc, htd, htb, -⟩
by_cases ha : ∀ b < a, (Ioo b a).Nonempty
· convert_to MeasurableSet (⋃ (l ∈ t) (u ∈ t) (_ : l < u) (_ : u ≤ a), Ico l u)
· ext y
simp only [mem_iUnion, mem_Iio, mem_Ico]
constructor
· intro hy
rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) y with ⟨l, hlt, hly⟩
rcases htd.exists_mem_open isOpen_Ioo (ha y hy) with ⟨u, hut, hyu, hua⟩
exact ⟨l, hlt, u, hut, hly.trans_lt hyu, hua.le, hly, hyu⟩
· rintro ⟨l, -, u, -, -, hua, -, hyu⟩
exact hyu.trans_le hua
· refine MeasurableSet.biUnion hc fun a ha => MeasurableSet.biUnion hc fun b hb => ?_
refine MeasurableSet.iUnion fun hab => MeasurableSet.iUnion fun _ => ?_
exact .basic _ ⟨a, hts ha, b, hts hb, hab, mem_singleton _⟩
· simp only [not_forall, not_nonempty_iff_eq_empty] at ha
replace ha : a ∈ s := hIoo ha.choose a ha.choose_spec.fst ha.choose_spec.snd
convert_to MeasurableSet (⋃ (l ∈ t) (_ : l < a), Ico l a)
· symm
simp only [← Ici_inter_Iio, ← iUnion_inter, inter_eq_right, subset_def, mem_iUnion,
mem_Ici, mem_Iio]
intro x hx
rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) x with ⟨z, hzt, hzx⟩
exact ⟨z, hzt, hzx.trans_lt hx, hzx⟩
· refine .biUnion hc fun x hx => MeasurableSet.iUnion fun hlt => ?_
exact .basic _ ⟨x, hts hx, a, ha, hlt, mem_singleton _⟩
theorem Dense.borel_eq_generateFrom_Ico_mem {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] [SecondCountableTopology α] [DenselyOrdered α] [NoMinOrder α] {s : Set α}
(hd : Dense s) :
borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } :=
hd.borel_eq_generateFrom_Ico_mem_aux (by simp) fun _ _ hxy H =>
((nonempty_Ioo.2 hxy).ne_empty H).elim
theorem borel_eq_generateFrom_Ico (α : Type*) [TopologicalSpace α] [SecondCountableTopology α]
[LinearOrder α] [OrderTopology α] :
borel α = .generateFrom { S : Set α | ∃ (l u : α), l < u ∧ Ico l u = S } := by
simpa only [exists_prop, mem_univ, true_and] using
(@dense_univ α _).borel_eq_generateFrom_Ico_mem_aux (fun _ _ => mem_univ _) fun _ _ _ _ =>
mem_univ _
theorem Dense.borel_eq_generateFrom_Ioc_mem_aux {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] [SecondCountableTopology α] {s : Set α} (hd : Dense s)
(hbot : ∀ x, IsTop x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → x ∈ s) :
borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ioc l u = S } := by
convert hd.orderDual.borel_eq_generateFrom_Ico_mem_aux hbot fun x y hlt he => hIoo y x hlt _
using 2
· ext s
constructor <;> rintro ⟨l, hl, u, hu, hlt, rfl⟩
exacts [⟨u, hu, l, hl, hlt, Ico_toDual⟩, ⟨u, hu, l, hl, hlt, Ioc_toDual⟩]
· erw [Ioo_toDual]
exact he
theorem Dense.borel_eq_generateFrom_Ioc_mem {α : Type*} [TopologicalSpace α] [LinearOrder α]
[OrderTopology α] [SecondCountableTopology α] [DenselyOrdered α] [NoMaxOrder α] {s : Set α}
(hd : Dense s) :
borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ioc l u = S } :=
hd.borel_eq_generateFrom_Ioc_mem_aux (by simp) fun _ _ hxy H =>
((nonempty_Ioo.2 hxy).ne_empty H).elim
theorem borel_eq_generateFrom_Ioc (α : Type*) [TopologicalSpace α] [SecondCountableTopology α]
[LinearOrder α] [OrderTopology α] :
borel α = .generateFrom { S : Set α | ∃ l u, l < u ∧ Ioc l u = S } := by
simpa only [exists_prop, mem_univ, true_and] using
(@dense_univ α _).borel_eq_generateFrom_Ioc_mem_aux (fun _ _ => mem_univ _) fun _ _ _ _ =>
mem_univ _
namespace MeasureTheory.Measure
/-- Two finite measures on a Borel space are equal if they agree on all closed-open intervals. If
`α` is a conditionally complete linear order with no top element,
`MeasureTheory.Measure.ext_of_Ico` is an extensionality lemma with weaker assumptions on `μ` and
`ν`. -/
theorem ext_of_Ico_finite {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α}
[SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α)
[IsFiniteMeasure μ] (hμν : μ univ = ν univ) (h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) :
μ = ν := by
refine
ext_of_generate_finite _ (BorelSpace.measurable_eq.trans (borel_eq_generateFrom_Ico α))
(isPiSystem_Ico (id : α → α) id) ?_ hμν
rintro - ⟨a, b, hlt, rfl⟩
exact h hlt
/-- Two finite measures on a Borel space are equal if they agree on all open-closed intervals. If
`α` is a conditionally complete linear order with no top element,
`MeasureTheory.Measure.ext_of_Ioc` is an extensionality lemma with weaker assumptions on `μ` and
`ν`. -/
theorem ext_of_Ioc_finite {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α}
[SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α)
[IsFiniteMeasure μ] (hμν : μ univ = ν univ) (h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) :
μ = ν := by
refine @ext_of_Ico_finite αᵒᵈ _ _ _ _ _ ‹_› μ ν _ hμν fun a b hab => ?_
erw [Ico_toDual (α := α)]
exact h hab
/-- Two measures which are finite on closed-open intervals are equal if they agree on all
closed-open intervals. -/
theorem ext_of_Ico' {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α}
[SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] [NoMaxOrder α]
(μ ν : Measure α) (hμ : ∀ ⦃a b⦄, a < b → μ (Ico a b) ≠ ∞)
(h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν := by
rcases exists_countable_dense_bot_top α with ⟨s, hsc, hsd, hsb, _⟩
have : (⋃ (l ∈ s) (u ∈ s) (_ : l < u), {Ico l u} : Set (Set α)).Countable :=
hsc.biUnion fun l _ => hsc.biUnion fun u _ => countable_iUnion fun _ => countable_singleton _
simp only [← setOf_eq_eq_singleton, ← setOf_exists] at this
refine
Measure.ext_of_generateFrom_of_cover_subset
(BorelSpace.measurable_eq.trans (borel_eq_generateFrom_Ico α)) (isPiSystem_Ico id id) ?_ this
?_ ?_ ?_
· rintro _ ⟨l, -, u, -, h, rfl⟩
exact ⟨l, u, h, rfl⟩
· refine sUnion_eq_univ_iff.2 fun x => ?_
rcases hsd.exists_le' hsb x with ⟨l, hls, hlx⟩
rcases hsd.exists_gt x with ⟨u, hus, hxu⟩
exact ⟨_, ⟨l, hls, u, hus, hlx.trans_lt hxu, rfl⟩, hlx, hxu⟩
· rintro _ ⟨l, -, u, -, hlt, rfl⟩
exact hμ hlt
· rintro _ ⟨l, u, hlt, rfl⟩
exact h hlt
/-- Two measures which are finite on closed-open intervals are equal if they agree on all
open-closed intervals. -/
theorem ext_of_Ioc' {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α}
[SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] [NoMinOrder α]
(μ ν : Measure α) (hμ : ∀ ⦃a b⦄, a < b → μ (Ioc a b) ≠ ∞)
(h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν := by
refine @ext_of_Ico' αᵒᵈ _ _ _ _ _ ‹_› _ μ ν ?_ ?_ <;> intro a b hab <;> erw [Ico_toDual (α := α)]
exacts [hμ hab, h hab]
/-- Two measures which are finite on closed-open intervals are equal if they agree on all
closed-open intervals. -/
theorem ext_of_Ico {α : Type*} [TopologicalSpace α] {_m : MeasurableSpace α}
[SecondCountableTopology α] [ConditionallyCompleteLinearOrder α] [OrderTopology α]
[BorelSpace α] [NoMaxOrder α] (μ ν : Measure α) [IsLocallyFiniteMeasure μ]
(h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν :=
μ.ext_of_Ico' ν (fun _ _ _ => measure_Ico_lt_top.ne) h
/-- Two measures which are finite on closed-open intervals are equal if they agree on all
open-closed intervals. -/
theorem ext_of_Ioc {α : Type*} [TopologicalSpace α] {_m : MeasurableSpace α}
[SecondCountableTopology α] [ConditionallyCompleteLinearOrder α] [OrderTopology α]
[BorelSpace α] [NoMinOrder α] (μ ν : Measure α) [IsLocallyFiniteMeasure μ]
(h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν :=
μ.ext_of_Ioc' ν (fun _ _ _ => measure_Ioc_lt_top.ne) h
/-- Two finite measures on a Borel space are equal if they agree on all left-infinite right-closed
intervals. -/
theorem ext_of_Iic {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α}
[SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α)
[IsFiniteMeasure μ] (h : ∀ a, μ (Iic a) = ν (Iic a)) : μ = ν := by
refine ext_of_Ioc_finite μ ν ?_ fun a b hlt => ?_
· rcases exists_countable_dense_bot_top α with ⟨s, hsc, hsd, -, hst⟩
have : DirectedOn (· ≤ ·) s := directedOn_iff_directed.2 (Subtype.mono_coe _).directed_le
simp only [← biSup_measure_Iic hsc (hsd.exists_ge' hst) this, h]
rw [← Iic_diff_Iic, measure_diff (Iic_subset_Iic.2 hlt.le) nullMeasurableSet_Iic,
measure_diff (Iic_subset_Iic.2 hlt.le) nullMeasurableSet_Iic, h a, h b]
· rw [← h a]
exact measure_ne_top μ _
· exact measure_ne_top μ _
/-- Two finite measures on a Borel space are equal if they agree on all left-closed right-infinite
intervals. -/
theorem ext_of_Ici {α : Type*} [TopologicalSpace α] {_ : MeasurableSpace α}
[SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α)
[IsFiniteMeasure μ] (h : ∀ a, μ (Ici a) = ν (Ici a)) : μ = ν :=
| @ext_of_Iic αᵒᵈ _ _ _ _ _ ‹_› _ _ _ h
end MeasureTheory.Measure
@[measurability]
theorem measurableSet_uIcc : MeasurableSet (uIcc a b) :=
measurableSet_Icc
@[measurability]
theorem measurableSet_uIoc : MeasurableSet (uIoc a b) :=
measurableSet_Ioc
| Mathlib/MeasureTheory/Constructions/BorelSpace/Order.lean | 436 | 447 |
/-
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.Group.Defs
import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.Data.Int.Cast.Defs
import Mathlib.Tactic.Spread
import Mathlib.Util.AssertExists
import Mathlib.Tactic.StacksAttribute
/-!
# Semirings and rings
This file defines semirings, rings and domains. This is analogous to `Algebra.Group.Defs` and
`Algebra.Group.Basic`, the difference being that the former is about `+` and `*` separately, while
the present file is about their interaction.
## Main definitions
* `Distrib`: Typeclass for distributivity of multiplication over addition.
* `HasDistribNeg`: Typeclass for commutativity of negation and multiplication. This is useful when
dealing with multiplicative submonoids which are closed under negation without being closed under
addition, for example `Units`.
* `(NonUnital)(NonAssoc)(Semi)Ring`: Typeclasses for possibly non-unital or non-associative
rings and semirings. Some combinations are not defined yet because they haven't found use.
For Lie Rings, there is a type synonym `CommutatorRing` defined in
`Mathlib/Algebra/Algebra/NonUnitalHom.lean` turning the bracket into a multiplication so that the
instance `instNonUnitalNonAssocSemiringCommutatorRing` can be defined.
## Tags
`Semiring`, `CommSemiring`, `Ring`, `CommRing`, domain, `IsDomain`, nonzero, units
-/
/-!
Previously an import dependency on `Mathlib.Algebra.Group.Basic` had crept in.
In general, the `.Defs` files in the basic algebraic hierarchy should only depend on earlier `.Defs`
files, without importing `.Basic` theory development.
These `assert_not_exists` statements guard against this returning.
-/
assert_not_exists DivisionMonoid.toDivInvOneMonoid mul_rotate
universe u v
variable {α : Type u} {R : Type v}
open Function
/-!
### `Distrib` class
-/
/-- A typeclass stating that multiplication is left and right distributive
over addition. -/
class Distrib (R : Type*) extends Mul R, Add R where
/-- Multiplication is left distributive over addition -/
protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c
/-- Multiplication is right distributive over addition -/
protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c
/-- A typeclass stating that multiplication is left distributive over addition. -/
class LeftDistribClass (R : Type*) [Mul R] [Add R] : Prop where
/-- Multiplication is left distributive over addition -/
protected left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c
/-- A typeclass stating that multiplication is right distributive over addition. -/
class RightDistribClass (R : Type*) [Mul R] [Add R] : Prop where
/-- Multiplication is right distributive over addition -/
protected right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c
-- see Note [lower instance priority]
instance (priority := 100) Distrib.leftDistribClass (R : Type*) [Distrib R] : LeftDistribClass R :=
⟨Distrib.left_distrib⟩
-- see Note [lower instance priority]
instance (priority := 100) Distrib.rightDistribClass (R : Type*) [Distrib R] :
RightDistribClass R :=
⟨Distrib.right_distrib⟩
theorem left_distrib [Mul R] [Add R] [LeftDistribClass R] (a b c : R) :
a * (b + c) = a * b + a * c :=
LeftDistribClass.left_distrib a b c
alias mul_add := left_distrib
theorem right_distrib [Mul R] [Add R] [RightDistribClass R] (a b c : R) :
(a + b) * c = a * c + b * c :=
RightDistribClass.right_distrib a b c
alias add_mul := right_distrib
theorem distrib_three_right [Mul R] [Add R] [RightDistribClass R] (a b c d : R) :
(a + b + c) * d = a * d + b * d + c * d := by simp [right_distrib]
/-!
### Classes of semirings and rings
We make sure that the canonical path from `NonAssocSemiring` to `Ring` passes through `Semiring`,
as this is a path which is followed all the time in linear algebra where the defining semilinear map
`σ : R →+* S` depends on the `NonAssocSemiring` structure of `R` and `S` while the module
definition depends on the `Semiring` structure.
It is not currently possible to adjust priorities by hand (see https://github.com/leanprover/lean4/issues/2115). Instead, the last
declared instance is used, so we make sure that `Semiring` is declared after `NonAssocRing`, so
that `Semiring -> NonAssocSemiring` is tried before `NonAssocRing -> NonAssocSemiring`.
TODO: clean this once https://github.com/leanprover/lean4/issues/2115 is fixed
-/
/-- A not-necessarily-unital, not-necessarily-associative semiring. See `CommutatorRing` and the
documentation thereof in case you need a `NonUnitalNonAssocSemiring` instance on a Lie ring
or a Lie algebra. -/
class NonUnitalNonAssocSemiring (α : Type u) extends AddCommMonoid α, Distrib α, MulZeroClass α
/-- An associative but not-necessarily unital semiring. -/
class NonUnitalSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, SemigroupWithZero α
/-- A unital but not-necessarily-associative semiring. -/
class NonAssocSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, MulZeroOneClass α,
AddCommMonoidWithOne α
/-- A not-necessarily-unital, not-necessarily-associative ring. -/
class NonUnitalNonAssocRing (α : Type u) extends AddCommGroup α, NonUnitalNonAssocSemiring α
/-- An associative but not-necessarily unital ring. -/
class NonUnitalRing (α : Type*) extends NonUnitalNonAssocRing α, NonUnitalSemiring α
/-- A unital but not-necessarily-associative ring. -/
class NonAssocRing (α : Type*) extends NonUnitalNonAssocRing α, NonAssocSemiring α,
AddCommGroupWithOne α
/-- A `Semiring` is a type with addition, multiplication, a `0` and a `1` where addition is
commutative and associative, multiplication is associative and left and right distributive over
addition, and `0` and `1` are additive and multiplicative identities. -/
class Semiring (α : Type u) extends NonUnitalSemiring α, NonAssocSemiring α, MonoidWithZero α
/-- A `Ring` is a `Semiring` with negation making it an additive group. -/
class Ring (R : Type u) extends Semiring R, AddCommGroup R, AddGroupWithOne R
/-!
### Semirings
-/
section DistribMulOneClass
variable [Add α] [MulOneClass α]
theorem add_one_mul [RightDistribClass α] (a b : α) : (a + 1) * b = a * b + b := by
rw [add_mul, one_mul]
theorem mul_add_one [LeftDistribClass α] (a b : α) : a * (b + 1) = a * b + a := by
rw [mul_add, mul_one]
theorem one_add_mul [RightDistribClass α] (a b : α) : (1 + a) * b = b + a * b := by
rw [add_mul, one_mul]
theorem mul_one_add [LeftDistribClass α] (a b : α) : a * (1 + b) = a + a * b := by
rw [mul_add, mul_one]
end DistribMulOneClass
section NonAssocSemiring
variable [NonAssocSemiring α]
-- Porting note: was [has_add α] [mul_one_class α] [right_distrib_class α]
theorem two_mul (n : α) : 2 * n = n + n :=
(congrArg₂ _ one_add_one_eq_two.symm rfl).trans <| (right_distrib 1 1 n).trans (by rw [one_mul])
-- Porting note: was [has_add α] [mul_one_class α] [left_distrib_class α]
theorem mul_two (n : α) : n * 2 = n + n :=
(congrArg₂ _ rfl one_add_one_eq_two.symm).trans <| (left_distrib n 1 1).trans (by rw [mul_one])
end NonAssocSemiring
section MulZeroClass
variable [MulZeroClass α] (P Q : Prop) [Decidable P] [Decidable Q] (a b : α)
lemma ite_zero_mul : ite P a 0 * b = ite P (a * b) 0 := by simp
lemma mul_ite_zero : a * ite P b 0 = ite P (a * b) 0 := by simp
lemma ite_zero_mul_ite_zero : ite P a 0 * ite Q b 0 = ite (P ∧ Q) (a * b) 0 := by
simp only [← ite_and, ite_mul, mul_ite, mul_zero, zero_mul, and_comm]
end MulZeroClass
theorem mul_boole {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) :
(a * if P then 1 else 0) = if P then a else 0 := by simp
theorem boole_mul {α} [MulZeroOneClass α] (P : Prop) [Decidable P] (a : α) :
(if P then 1 else 0) * a = if P then a else 0 := by simp
/-- A not-necessarily-unital, not-necessarily-associative, but commutative semiring. -/
class NonUnitalNonAssocCommSemiring (α : Type u) extends NonUnitalNonAssocSemiring α, CommMagma α
/-- A non-unital commutative semiring is a `NonUnitalSemiring` with commutative multiplication.
In other words, it is a type with the following structures: additive commutative monoid
(`AddCommMonoid`), commutative semigroup (`CommSemigroup`), distributive laws (`Distrib`), and
multiplication by zero law (`MulZeroClass`). -/
class NonUnitalCommSemiring (α : Type u) extends NonUnitalSemiring α, CommSemigroup α
/-- A commutative semiring is a semiring with commutative multiplication. -/
class CommSemiring (R : Type u) extends Semiring R, CommMonoid R
-- see Note [lower instance priority]
instance (priority := 100) CommSemiring.toNonUnitalCommSemiring [CommSemiring α] :
NonUnitalCommSemiring α :=
{ inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with }
-- see Note [lower instance priority]
instance (priority := 100) CommSemiring.toCommMonoidWithZero [CommSemiring α] :
CommMonoidWithZero α :=
{ inferInstanceAs (CommMonoid α), inferInstanceAs (CommSemiring α) with }
section CommSemiring
variable [CommSemiring α]
theorem add_mul_self_eq (a b : α) : (a + b) * (a + b) = a * a + 2 * a * b + b * b := by
simp only [two_mul, add_mul, mul_add, add_assoc, mul_comm b]
lemma add_sq (a b : α) : (a + b) ^ 2 = a ^ 2 + 2 * a * b + b ^ 2 := by
simp only [sq, add_mul_self_eq]
lemma add_sq' (a b : α) : (a + b) ^ 2 = a ^ 2 + b ^ 2 + 2 * a * b := by
rw [add_sq, add_assoc, add_comm _ (b ^ 2), add_assoc]
alias add_pow_two := add_sq
end CommSemiring
section HasDistribNeg
/-- Typeclass for a negation operator that distributes across multiplication.
This is useful for dealing with submonoids of a ring that contain `-1` without having to duplicate
lemmas. -/
class HasDistribNeg (α : Type*) [Mul α] extends InvolutiveNeg α where
/-- Negation is left distributive over multiplication -/
neg_mul : ∀ x y : α, -x * y = -(x * y)
/-- Negation is right distributive over multiplication -/
mul_neg : ∀ x y : α, x * -y = -(x * y)
section Mul
variable [Mul α] [HasDistribNeg α]
@[simp]
theorem neg_mul (a b : α) : -a * b = -(a * b) :=
HasDistribNeg.neg_mul _ _
@[simp]
theorem mul_neg (a b : α) : a * -b = -(a * b) :=
HasDistribNeg.mul_neg _ _
theorem neg_mul_neg (a b : α) : -a * -b = a * b := by simp
theorem neg_mul_eq_neg_mul (a b : α) : -(a * b) = -a * b :=
(neg_mul _ _).symm
theorem neg_mul_eq_mul_neg (a b : α) : -(a * b) = a * -b :=
(mul_neg _ _).symm
theorem neg_mul_comm (a b : α) : -a * b = a * -b := by simp
end Mul
section MulOneClass
variable [MulOneClass α] [HasDistribNeg α]
theorem neg_eq_neg_one_mul (a : α) : -a = -1 * a := by simp
/-- An element of a ring multiplied by the additive inverse of one is the element's additive
inverse. -/
theorem mul_neg_one (a : α) : a * -1 = -a := by simp
/-- The additive inverse of one multiplied by an element of a ring is the element's additive
inverse. -/
theorem neg_one_mul (a : α) : -1 * a = -a := by simp
end MulOneClass
section MulZeroClass
variable [MulZeroClass α] [HasDistribNeg α]
instance (priority := 100) MulZeroClass.negZeroClass : NegZeroClass α where
__ := inferInstanceAs (Zero α); __ := inferInstanceAs (InvolutiveNeg α)
neg_zero := by rw [← zero_mul (0 : α), ← neg_mul, mul_zero, mul_zero]
end MulZeroClass
end HasDistribNeg
/-!
### Rings
-/
section NonUnitalNonAssocRing
variable [NonUnitalNonAssocRing α]
instance (priority := 100) NonUnitalNonAssocRing.toHasDistribNeg : HasDistribNeg α where
neg := Neg.neg
neg_neg := neg_neg
neg_mul a b := eq_neg_of_add_eq_zero_left <| by rw [← right_distrib, neg_add_cancel, zero_mul]
mul_neg a b := eq_neg_of_add_eq_zero_left <| by rw [← left_distrib, neg_add_cancel, mul_zero]
theorem mul_sub_left_distrib (a b c : α) : a * (b - c) = a * b - a * c := by
simpa only [sub_eq_add_neg, neg_mul_eq_mul_neg] using mul_add a b (-c)
alias mul_sub := mul_sub_left_distrib
theorem mul_sub_right_distrib (a b c : α) : (a - b) * c = a * c - b * c := by
simpa only [sub_eq_add_neg, neg_mul_eq_neg_mul] using add_mul a (-b) c
alias sub_mul := mul_sub_right_distrib
end NonUnitalNonAssocRing
section NonAssocRing
variable [NonAssocRing α]
theorem sub_one_mul (a b : α) : (a - 1) * b = a * b - b := by rw [sub_mul, one_mul]
theorem mul_sub_one (a b : α) : a * (b - 1) = a * b - a := by rw [mul_sub, mul_one]
theorem one_sub_mul (a b : α) : (1 - a) * b = b - a * b := by rw [sub_mul, one_mul]
theorem mul_one_sub (a b : α) : a * (1 - b) = a - a * b := by rw [mul_sub, mul_one]
end NonAssocRing
section Ring
variable [Ring α]
-- A (unital, associative) ring is a not-necessarily-unital ring
| -- see Note [lower instance priority]
| Mathlib/Algebra/Ring/Defs.lean | 347 | 347 |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.RingTheory.MvPowerSeries.Basic
import Mathlib.Tactic.MoveAdd
import Mathlib.Algebra.MvPolynomial.Equiv
import Mathlib.RingTheory.Ideal.Basic
/-!
# Formal power series (in one variable)
This file defines (univariate) formal power series
and develops the basic properties of these objects.
A formal power series is to a polynomial like an infinite sum is to a finite sum.
Formal power series in one variable are defined from multivariate
power series as `PowerSeries R := MvPowerSeries Unit R`.
The file sets up the (semi)ring structure on univariate power series.
We provide the natural inclusion from polynomials to formal power series.
Additional results can be found in:
* `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series;
* `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series,
and the fact that power series over a local ring form a local ring;
* `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0,
and application to the fact that power series over an integral domain
form an integral domain.
## Implementation notes
Because of its definition,
`PowerSeries R := MvPowerSeries Unit R`.
a lot of proofs and properties from the multivariate case
can be ported to the single variable case.
However, it means that formal power series are indexed by `Unit →₀ ℕ`,
which is of course canonically isomorphic to `ℕ`.
We then build some glue to treat formal power series as if they were indexed by `ℕ`.
Occasionally this leads to proofs that are uglier than expected.
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
/-- Formal power series over a coefficient type `R` -/
abbrev PowerSeries (R : Type*) :=
MvPowerSeries Unit R
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section
-- Porting note: not available in Lean 4
-- local reducible PowerSeries
/--
`R⟦X⟧` is notation for `PowerSeries R`,
the semiring of formal power series in one variable over a semiring `R`.
-/
scoped notation:9000 R "⟦X⟧" => PowerSeries R
instance [Inhabited R] : Inhabited R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Zero R] : Zero R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddMonoid R] : AddMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddGroup R] : AddGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Semiring R] : Semiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommSemiring R] : CommSemiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Ring R] : Ring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommRing R] : CommRing R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Nontrivial R] : Nontrivial R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S]
[IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ :=
Pi.isScalarTower
instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
end
section Semiring
variable (R) [Semiring R]
/-- The `n`th coefficient of a formal power series. -/
def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R :=
MvPowerSeries.coeff R (single () n)
/-- The `n`th monomial with coefficient `a` as formal power series. -/
def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ :=
MvPowerSeries.monomial R (single () n)
variable {R}
theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by
rw [coeff, ← h, ← Finsupp.unique_single s]
/-- Two formal power series are equal if all their coefficients are equal. -/
@[ext]
theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ :=
MvPowerSeries.ext fun n => by
rw [← coeff_def]
· apply h
rfl
@[simp]
theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff R n φ = 0) ↔ φ = 0 :=
⟨fun h => ext h, fun h => by simp [h]⟩
/-- Two formal power series are equal if all their coefficients are equal. -/
add_decl_doc PowerSeries.ext_iff
instance [Subsingleton R] : Subsingleton R⟦X⟧ := by
simp only [subsingleton_iff, PowerSeries.ext_iff]
subsingleton
/-- Constructor for formal power series. -/
def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ())
@[simp]
theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n :=
congr_arg f Finsupp.single_eq_same
theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 :=
calc
coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _
_ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff]
theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 :=
ext fun m => by rw [coeff_monomial, coeff_mk]
@[simp]
theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a :=
MvPowerSeries.coeff_monomial_same _ _
@[simp]
theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id :=
LinearMap.ext <| coeff_monomial_same n
variable (R)
/-- The constant coefficient of a formal power series. -/
def constantCoeff : R⟦X⟧ →+* R :=
MvPowerSeries.constantCoeff Unit R
/-- The constant formal power series. -/
def C : R →+* R⟦X⟧ :=
MvPowerSeries.C Unit R
@[simp] lemma algebraMap_eq {R : Type*} [CommSemiring R] : algebraMap R R⟦X⟧ = C R := rfl
variable {R}
/-- The variable of the formal power series ring. -/
def X : R⟦X⟧ :=
MvPowerSeries.X ()
theorem commute_X (φ : R⟦X⟧) : Commute φ X :=
MvPowerSeries.commute_X _ _
theorem X_mul {φ : R⟦X⟧} : X * φ = φ * X :=
MvPowerSeries.X_mul
theorem commute_X_pow (φ : R⟦X⟧) (n : ℕ) : Commute φ (X ^ n) :=
MvPowerSeries.commute_X_pow _ _ _
theorem X_pow_mul {φ : R⟦X⟧} {n : ℕ} : X ^ n * φ = φ * X ^ n :=
MvPowerSeries.X_pow_mul
@[simp]
theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by
rw [coeff, Finsupp.single_zero]
rfl
theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by
rw [coeff_zero_eq_constantCoeff]
@[simp]
theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by
-- This used to be `rw`, but we need `rw; rfl` after https://github.com/leanprover/lean4/pull/2644
rw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C]
rfl
theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp
theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by
rw [← monomial_zero_eq_C_apply, coeff_monomial]
@[simp]
theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by
rw [coeff_C, if_pos rfl]
theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by
rw [coeff_C, if_neg h]
@[simp]
theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 :=
coeff_ne_zero_C n.succ_ne_zero
theorem C_injective : Function.Injective (C R) := by
intro a b H
simp_rw [PowerSeries.ext_iff] at H
simpa only [coeff_zero_C] using H 0
protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
rw [subsingleton_iff] at h ⊢
exact fun a b ↦ C_injective (h (C R a) (C R b))
theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 :=
rfl
theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by
rw [X_eq, coeff_monomial]
@[simp]
theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by
rw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X]
@[simp]
theorem coeff_one_X : coeff R 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl]
@[simp]
theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by
simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H
theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial R n 1 :=
MvPowerSeries.X_pow_eq _ n
theorem coeff_X_pow (m n : ℕ) : coeff R m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by
rw [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_X_pow_self (n : ℕ) : coeff R n ((X : R⟦X⟧) ^ n) = 1 := by
rw [coeff_X_pow, if_pos rfl]
@[simp]
theorem coeff_one (n : ℕ) : coeff R n (1 : R⟦X⟧) = if n = 0 then 1 else 0 :=
coeff_C n 1
theorem coeff_zero_one : coeff R 0 (1 : R⟦X⟧) = 1 :=
coeff_zero_C 1
theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) :
coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
-- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans`
refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_
rw [Finsupp.antidiagonal_single, Finset.sum_map]
rfl
@[simp]
theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (φ * C R a) = coeff R n φ * a :=
MvPowerSeries.coeff_mul_C _ φ a
@[simp]
theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (C R a * φ) = a * coeff R n φ :=
MvPowerSeries.coeff_C_mul _ φ a
@[simp]
theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) :
coeff S n (a • φ) = a • coeff S n φ :=
rfl
@[simp]
theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) :
constantCoeff S (a • φ) = a • constantCoeff S φ :=
rfl
theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C R a * f := by
ext
simp
@[simp]
theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (φ * X) = coeff R n φ := by
simp only [coeff, Finsupp.single_add]
convert φ.coeff_add_mul_monomial (single () n) (single () 1) _
rw [mul_one]
@[simp]
theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (X * φ) = coeff R n φ := by
simp only [coeff, Finsupp.single_add, add_comm n 1]
convert φ.coeff_add_monomial_mul (single () 1) (single () n) _
rw [one_mul]
theorem mul_X_cancel {φ ψ : R⟦X⟧} (h : φ * X = ψ * X) : φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + 1)
theorem mul_X_injective : Function.Injective (· * X : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ mul_X_cancel
theorem mul_X_inj {φ ψ : R⟦X⟧} : φ * X = ψ * X ↔ φ = ψ :=
mul_X_injective.eq_iff
theorem X_mul_cancel {φ ψ : R⟦X⟧} (h : X * φ = X * ψ) : φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + 1)
theorem X_mul_injective : Function.Injective (X * · : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ X_mul_cancel
theorem X_mul_inj {φ ψ : R⟦X⟧} : X * φ = X * ψ ↔ φ = ψ :=
X_mul_injective.eq_iff
@[simp]
theorem constantCoeff_C (a : R) : constantCoeff R (C R a) = a :=
rfl
@[simp]
theorem constantCoeff_comp_C : (constantCoeff R).comp (C R) = RingHom.id R :=
rfl
@[simp]
theorem constantCoeff_zero : constantCoeff R 0 = 0 :=
rfl
@[simp]
theorem constantCoeff_one : constantCoeff R 1 = 1 :=
rfl
@[simp]
theorem constantCoeff_X : constantCoeff R X = 0 :=
MvPowerSeries.coeff_zero_X _
@[simp]
theorem constantCoeff_mk {f : ℕ → R} : constantCoeff R (mk f) = f 0 := rfl
theorem coeff_zero_mul_X (φ : R⟦X⟧) : coeff R 0 (φ * X) = 0 := by simp
theorem coeff_zero_X_mul (φ : R⟦X⟧) : coeff R 0 (X * φ) = 0 := by simp
theorem constantCoeff_surj : Function.Surjective (constantCoeff R) :=
fun r => ⟨(C R) r, constantCoeff_C r⟩
-- The following section duplicates the API of `Data.Polynomial.Coeff` and should attempt to keep
-- up to date with that
section
theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff R n (C R x * X ^ k : R⟦X⟧) = if n = k then x else 0 := by
simp [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_mul_X_pow (p : R⟦X⟧) (n d : ℕ) :
coeff R (d + n) (p * X ^ n) = coeff R d p := by
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, mul_zero]
rintro rfl
apply h2
rw [mem_antidiagonal, add_right_cancel_iff] at h1
subst h1
rfl
· exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
@[simp]
theorem coeff_X_pow_mul (p : R⟦X⟧) (n d : ℕ) :
coeff R (d + n) (X ^ n * p) = coeff R d p := by
rw [coeff_mul, Finset.sum_eq_single (n, d), coeff_X_pow, if_pos rfl, one_mul]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, zero_mul]
rintro rfl
apply h2
rw [mem_antidiagonal, add_comm, add_right_cancel_iff] at h1
subst h1
rfl
· rw [add_comm]
exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
theorem mul_X_pow_cancel {k : ℕ} {φ ψ : R⟦X⟧} (h : φ * X ^ k = ψ * X ^ k) :
φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + k)
theorem mul_X_pow_injective {k : ℕ} : Function.Injective (· * X ^ k : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ mul_X_pow_cancel
theorem mul_X_pow_inj {k : ℕ} {φ ψ : R⟦X⟧} :
φ * X ^ k = ψ * X ^ k ↔ φ = ψ :=
mul_X_pow_injective.eq_iff
theorem X_pow_mul_cancel {k : ℕ} {φ ψ : R⟦X⟧} (h : X ^ k * φ = X ^ k * ψ) :
φ = ψ := by
rw [PowerSeries.ext_iff] at h ⊢
intro n
simpa using h (n + k)
theorem X_pow_mul_injective {k : ℕ} : Function.Injective (X ^ k * · : R⟦X⟧ → R⟦X⟧) :=
fun _ _ ↦ X_pow_mul_cancel
theorem X_pow_mul_inj {k : ℕ} {φ ψ : R⟦X⟧} :
X ^ k * φ = X ^ k * ψ ↔ φ = ψ :=
X_pow_mul_injective.eq_iff
theorem coeff_mul_X_pow' (p : R⟦X⟧) (n d : ℕ) :
coeff R d (p * X ^ n) = ite (n ≤ d) (coeff R (d - n) p) 0 := by
split_ifs with h
· rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right]
· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, mul_zero]
exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne
theorem coeff_X_pow_mul' (p : R⟦X⟧) (n d : ℕ) :
coeff R d (X ^ n * p) = ite (n ≤ d) (coeff R (d - n) p) 0 := by
split_ifs with h
· rw [← tsub_add_cancel_of_le h, coeff_X_pow_mul]
simp
· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, zero_mul]
have := mem_antidiagonal.mp hx
rw [add_comm] at this
exact ((le_of_add_le_right this.le).trans_lt <| not_le.mp h).ne
end
/-- If a formal power series is invertible, then so is its constant coefficient. -/
theorem isUnit_constantCoeff (φ : R⟦X⟧) (h : IsUnit φ) : IsUnit (constantCoeff R φ) :=
MvPowerSeries.isUnit_constantCoeff φ h
/-- Split off the constant coefficient. -/
theorem eq_shift_mul_X_add_const (φ : R⟦X⟧) :
φ = (mk fun p => coeff R (p + 1) φ) * X + C R (constantCoeff R φ) := by
ext (_ | n)
· simp only [coeff_zero_eq_constantCoeff, map_add, map_mul, constantCoeff_X,
mul_zero, coeff_zero_C, zero_add]
· simp only [coeff_succ_mul_X, coeff_mk, LinearMap.map_add, coeff_C, n.succ_ne_zero, sub_zero,
if_false, add_zero]
/-- Split off the constant coefficient. -/
theorem eq_X_mul_shift_add_const (φ : R⟦X⟧) :
φ = (X * mk fun p => coeff R (p + 1) φ) + C R (constantCoeff R φ) := by
ext (_ | n)
· simp only [coeff_zero_eq_constantCoeff, map_add, map_mul, constantCoeff_X,
zero_mul, coeff_zero_C, zero_add]
· simp only [coeff_succ_X_mul, coeff_mk, LinearMap.map_add, coeff_C, n.succ_ne_zero, sub_zero,
if_false, add_zero]
section Map
variable {S : Type*} {T : Type*} [Semiring S] [Semiring T]
variable (f : R →+* S) (g : S →+* T)
/-- The map between formal power series induced by a map on the coefficients. -/
def map : R⟦X⟧ →+* S⟦X⟧ :=
MvPowerSeries.map _ f
@[simp]
theorem map_id : (map (RingHom.id R) : R⟦X⟧ → R⟦X⟧) = id :=
rfl
theorem map_comp : map (g.comp f) = (map g).comp (map f) :=
rfl
@[simp]
theorem coeff_map (n : ℕ) (φ : R⟦X⟧) : coeff S n (map f φ) = f (coeff R n φ) :=
rfl
@[simp]
theorem map_C (r : R) : map f (C _ r) = C _ (f r) := by
ext
simp [coeff_C, apply_ite f]
@[simp]
theorem map_X : map f X = X := by
ext
simp [coeff_X, apply_ite f]
theorem map_surjective (f : S →+* T) (hf : Function.Surjective f) :
Function.Surjective (PowerSeries.map f) := by
intro g
use PowerSeries.mk fun k ↦ Function.surjInv hf (PowerSeries.coeff _ k g)
ext k
simp only [Function.surjInv, coeff_map, coeff_mk]
exact Classical.choose_spec (hf ((coeff T k) g))
theorem map_injective (f : S →+* T) (hf : Function.Injective ⇑f) :
Function.Injective (PowerSeries.map f) := by
intro u v huv
ext k
apply hf
rw [← PowerSeries.coeff_map, ← PowerSeries.coeff_map, huv]
end Map
@[simp]
theorem map_eq_zero {R S : Type*} [DivisionSemiring R] [Semiring S] [Nontrivial S] (φ : R⟦X⟧)
(f : R →+* S) : φ.map f = 0 ↔ φ = 0 :=
MvPowerSeries.map_eq_zero _ _
theorem X_pow_dvd_iff {n : ℕ} {φ : R⟦X⟧} :
(X : R⟦X⟧) ^ n ∣ φ ↔ ∀ m, m < n → coeff R m φ = 0 := by
convert@MvPowerSeries.X_pow_dvd_iff Unit R _ () n φ
constructor <;> intro h m hm
· rw [Finsupp.unique_single m]
convert h _ hm
· apply h
simpa only [Finsupp.single_eq_same] using hm
theorem X_dvd_iff {φ : R⟦X⟧} : (X : R⟦X⟧) ∣ φ ↔ constantCoeff R φ = 0 := by
rw [← pow_one (X : R⟦X⟧), X_pow_dvd_iff, ← coeff_zero_eq_constantCoeff_apply]
constructor <;> intro h
· exact h 0 zero_lt_one
· intro m hm
rwa [Nat.eq_zero_of_le_zero (Nat.le_of_succ_le_succ hm)]
end Semiring
section CommSemiring
variable [CommSemiring R]
open Finset Nat
/-- The ring homomorphism taking a power series `f(X)` to `f(aX)`. -/
noncomputable def rescale (a : R) : R⟦X⟧ →+* R⟦X⟧ where
toFun f := PowerSeries.mk fun n => a ^ n * PowerSeries.coeff R n f
map_zero' := by
ext
simp only [LinearMap.map_zero, PowerSeries.coeff_mk, mul_zero]
map_one' := by
ext1
simp only [mul_boole, PowerSeries.coeff_mk, PowerSeries.coeff_one]
split_ifs with h
· rw [h, pow_zero a]
rfl
map_add' := by
intros
ext
dsimp only
exact mul_add _ _ _
map_mul' f g := by
ext
rw [PowerSeries.coeff_mul, PowerSeries.coeff_mk, PowerSeries.coeff_mul, Finset.mul_sum]
apply sum_congr rfl
simp only [coeff_mk, Prod.forall, mem_antidiagonal]
intro b c H
rw [← H, pow_add, mul_mul_mul_comm]
@[simp]
theorem coeff_rescale (f : R⟦X⟧) (a : R) (n : ℕ) :
coeff R n (rescale a f) = a ^ n * coeff R n f :=
coeff_mk n (fun n ↦ a ^ n * (coeff R n) f)
@[simp]
theorem rescale_zero : rescale 0 = (C R).comp (constantCoeff R) := by
ext x n
simp only [Function.comp_apply, RingHom.coe_comp, rescale, RingHom.coe_mk,
PowerSeries.coeff_mk _ _, coeff_C]
split_ifs with h <;> simp [h]
theorem rescale_zero_apply (f : R⟦X⟧) : rescale 0 f = C R (constantCoeff R f) := by simp
@[simp]
theorem rescale_one : rescale 1 = RingHom.id R⟦X⟧ := by
ext
simp [coeff_rescale]
theorem rescale_mk (f : ℕ → R) (a : R) : rescale a (mk f) = mk fun n : ℕ => a ^ n * f n := by
ext
rw [coeff_rescale, coeff_mk, coeff_mk]
theorem rescale_rescale (f : R⟦X⟧) (a b : R) :
rescale b (rescale a f) = rescale (a * b) f := by
ext n
simp_rw [coeff_rescale]
rw [mul_pow, mul_comm _ (b ^ n), mul_assoc]
theorem rescale_mul (a b : R) : rescale (a * b) = (rescale b).comp (rescale a) := by
ext
simp [← rescale_rescale]
end CommSemiring
section CommSemiring
open Finset.HasAntidiagonal Finset
variable {R : Type*} [CommSemiring R] {ι : Type*} [DecidableEq ι]
/-- Coefficients of a product of power series -/
theorem coeff_prod (f : ι → PowerSeries R) (d : ℕ) (s : Finset ι) :
coeff R d (∏ j ∈ s, f j) = ∑ l ∈ finsuppAntidiag s d, ∏ i ∈ s, coeff R (l i) (f i) := by
simp only [coeff]
rw [MvPowerSeries.coeff_prod, ← AddEquiv.finsuppUnique_symm d, ← mapRange_finsuppAntidiag_eq,
sum_map, sum_congr rfl]
intro x _
apply prod_congr rfl
intro i _
congr 2
simp only [AddEquiv.toEquiv_eq_coe, Finsupp.mapRange.addEquiv_toEquiv, AddEquiv.toEquiv_symm,
Equiv.coe_toEmbedding, Finsupp.mapRange.equiv_apply, AddEquiv.coe_toEquiv_symm,
Finsupp.mapRange_apply, AddEquiv.finsuppUnique_symm]
/-- The `n`-th coefficient of the `k`-th power of a power series. -/
lemma coeff_pow (k n : ℕ) (φ : R⟦X⟧) :
coeff R n (φ ^ k) = ∑ l ∈ finsuppAntidiag (range k) n, ∏ i ∈ range k, coeff R (l i) φ := by
have h₁ (i : ℕ) : Function.const ℕ φ i = φ := rfl
have h₂ (i : ℕ) : ∏ j ∈ range i, Function.const ℕ φ j = φ ^ i := by
apply prod_range_induction (fun _ => φ) (fun i => φ ^ i) rfl (congrFun rfl) i
rw [← h₂, ← h₁ k]
apply coeff_prod (f := Function.const ℕ φ) (d := n) (s := range k)
/-- First coefficient of the product of two power series. -/
lemma coeff_one_mul (φ ψ : R⟦X⟧) : coeff R 1 (φ * ψ) =
coeff R 1 φ * constantCoeff R ψ + coeff R 1 ψ * constantCoeff R φ := by
have : Finset.antidiagonal 1 = {(0, 1), (1, 0)} := by exact rfl
rw [coeff_mul, this, Finset.sum_insert, Finset.sum_singleton, coeff_zero_eq_constantCoeff,
mul_comm, add_comm]
norm_num
/-- First coefficient of the `n`-th power of a power series. -/
lemma coeff_one_pow (n : ℕ) (φ : R⟦X⟧) :
coeff R 1 (φ ^ n) = n * coeff R 1 φ * (constantCoeff R φ) ^ (n - 1) := by
rcases Nat.eq_zero_or_pos n with (rfl | hn)
· simp
induction n with
| zero => omega
| succ n' ih =>
have h₁ (m : ℕ) : φ ^ (m + 1) = φ ^ m * φ := by exact rfl
have h₂ : Finset.antidiagonal 1 = {(0, 1), (1, 0)} := by exact rfl
rw [h₁, coeff_mul, h₂, Finset.sum_insert, Finset.sum_singleton]
· simp only [coeff_zero_eq_constantCoeff, map_pow, Nat.cast_add, Nat.cast_one,
add_tsub_cancel_right]
have h₀ : n' = 0 ∨ 1 ≤ n' := by omega
rcases h₀ with h' | h'
· by_contra h''
rw [h'] at h''
simp only [pow_zero, one_mul, coeff_one, one_ne_zero, ↓reduceIte, zero_mul, add_zero,
CharP.cast_eq_zero, zero_add, mul_one, not_true_eq_false] at h''
norm_num at h''
· rw [ih]
· conv => lhs; arg 2; rw [mul_comm, ← mul_assoc]
move_mul [← (constantCoeff R) φ ^ (n' - 1)]
conv => enter [1, 2, 1, 1, 2]; rw [← pow_one (a := constantCoeff R φ)]
rw [← pow_add (a := constantCoeff R φ)]
conv => enter [1, 2, 1, 1]; rw [Nat.sub_add_cancel h']
conv => enter [1, 2, 1]; rw [mul_comm]
rw [mul_assoc, ← one_add_mul, add_comm, mul_assoc]
conv => enter [1, 2]; rw [mul_comm]
exact h'
· decide
end CommSemiring
section CommRing
variable {A : Type*} [CommRing A]
theorem not_isField : ¬IsField A⟦X⟧ := by
by_cases hA : Subsingleton A
· exact not_isField_of_subsingleton _
· nontriviality A
rw [Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top]
use Ideal.span {X}
constructor
· rw [bot_lt_iff_ne_bot, Ne, Ideal.span_singleton_eq_bot]
exact X_ne_zero
· rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, Ideal.mem_span_singleton,
X_dvd_iff, constantCoeff_one]
exact one_ne_zero
@[simp]
theorem rescale_X (a : A) : rescale a X = C A a * X := by
ext
simp only [coeff_rescale, coeff_C_mul, coeff_X]
split_ifs with h <;> simp [h]
theorem rescale_neg_one_X : rescale (-1 : A) X = -X := by
rw [rescale_X, map_neg, map_one, neg_one_mul]
/-- The ring homomorphism taking a power series `f(X)` to `f(-X)`. -/
noncomputable def evalNegHom : A⟦X⟧ →+* A⟦X⟧ :=
rescale (-1 : A)
@[simp]
theorem evalNegHom_X : evalNegHom (X : A⟦X⟧) = -X :=
rescale_neg_one_X
end CommRing
section Algebra
variable {A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
theorem C_eq_algebraMap {r : R} : C R r = (algebraMap R R⟦X⟧) r :=
rfl
theorem algebraMap_apply {r : R} : algebraMap R A⟦X⟧ r = C A (algebraMap R A r) :=
MvPowerSeries.algebraMap_apply
instance [Nontrivial R] : Nontrivial (Subalgebra R R⟦X⟧) :=
{ inferInstanceAs <| Nontrivial <| Subalgebra R <| MvPowerSeries Unit R with }
/-- Change of coefficients in power series, as an `AlgHom` -/
def mapAlgHom (φ : A →ₐ[R] B) :
PowerSeries A →ₐ[R] PowerSeries B :=
MvPowerSeries.mapAlgHom φ
theorem mapAlgHom_apply (φ : A →ₐ[R] B) (f : A⟦X⟧) :
mapAlgHom φ f = f.map φ :=
MvPowerSeries.mapAlgHom_apply φ f
end Algebra
end PowerSeries
namespace Polynomial
open Finsupp Polynomial
section Semiring
variable {R : Type*} [Semiring R] (φ ψ : R[X])
-- Porting note: added so we can add the `@[coe]` attribute
/-- The natural inclusion from polynomials into formal power series. -/
@[coe]
def toPowerSeries : R[X] → (PowerSeries R) := fun φ =>
PowerSeries.mk fun n => coeff φ n
@[deprecated (since := "2024-10-27")] alias ToPowerSeries := toPowerSeries
/-- The natural inclusion from polynomials into formal power series. -/
instance coeToPowerSeries : Coe R[X] (PowerSeries R) :=
⟨toPowerSeries⟩
theorem coe_def : (φ : PowerSeries R) = PowerSeries.mk (coeff φ) :=
rfl
@[simp, norm_cast]
theorem coeff_coe (n) : PowerSeries.coeff R n φ = coeff φ n :=
congr_arg (coeff φ) Finsupp.single_eq_same
@[simp, norm_cast]
theorem coe_monomial (n : ℕ) (a : R) :
(monomial n a : PowerSeries R) = PowerSeries.monomial R n a := by
ext
simp [coeff_coe, PowerSeries.coeff_monomial, Polynomial.coeff_monomial, eq_comm]
@[simp, norm_cast]
theorem coe_zero : ((0 : R[X]) : PowerSeries R) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : ((1 : R[X]) : PowerSeries R) = 1 := by
have := coe_monomial 0 (1 : R)
rwa [PowerSeries.monomial_zero_eq_C_apply] at this
@[simp, norm_cast]
theorem coe_add : ((φ + ψ : R[X]) : PowerSeries R) = φ + ψ := by
ext
simp
@[simp, norm_cast]
theorem coe_mul : ((φ * ψ : R[X]) : PowerSeries R) = φ * ψ :=
PowerSeries.ext fun n => by simp only [coeff_coe, PowerSeries.coeff_mul, coeff_mul]
@[simp, norm_cast]
theorem coe_C (a : R) : ((C a : R[X]) : PowerSeries R) = PowerSeries.C R a := by
have := coe_monomial 0 a
rwa [PowerSeries.monomial_zero_eq_C_apply] at this
@[simp, norm_cast]
theorem coe_X : ((X : R[X]) : PowerSeries R) = PowerSeries.X :=
coe_monomial _ _
@[simp]
lemma polynomial_map_coe {U V : Type*} [CommSemiring U] [CommSemiring V] {φ : U →+* V}
{f : Polynomial U} : Polynomial.map φ f = PowerSeries.map φ f := by
ext
simp
@[simp]
theorem constantCoeff_coe : PowerSeries.constantCoeff R φ = φ.coeff 0 :=
rfl
variable (R)
theorem coe_injective : Function.Injective (Coe.coe : R[X] → PowerSeries R) := fun x y h => by
ext
simp_rw [← coeff_coe]
congr
variable {R φ ψ}
@[simp, norm_cast]
theorem coe_inj : (φ : PowerSeries R) = ψ ↔ φ = ψ :=
(coe_injective R).eq_iff
@[simp]
theorem coe_eq_zero_iff : (φ : PowerSeries R) = 0 ↔ φ = 0 := by rw [← coe_zero, coe_inj]
@[simp]
theorem coe_eq_one_iff : (φ : PowerSeries R) = 1 ↔ φ = 1 := by rw [← coe_one, coe_inj]
/-- The coercion from polynomials to power series
as a ring homomorphism.
-/
def coeToPowerSeries.ringHom : R[X] →+* PowerSeries R where
toFun := (Coe.coe : R[X] → PowerSeries R)
map_zero' := coe_zero
map_one' := coe_one
map_add' := coe_add
map_mul' := coe_mul
@[simp]
theorem coeToPowerSeries.ringHom_apply : coeToPowerSeries.ringHom φ = φ :=
rfl
@[simp, norm_cast]
theorem coe_pow (n : ℕ) : ((φ ^ n : R[X]) : PowerSeries R) = (φ : PowerSeries R) ^ n :=
coeToPowerSeries.ringHom.map_pow _ _
theorem eval₂_C_X_eq_coe : φ.eval₂ (PowerSeries.C R) PowerSeries.X = ↑φ := by
nth_rw 2 [← eval₂_C_X (p := φ)]
rw [← coeToPowerSeries.ringHom_apply, eval₂_eq_sum_range, eval₂_eq_sum_range, map_sum]
apply Finset.sum_congr rfl
intros
rw [map_mul, map_pow, coeToPowerSeries.ringHom_apply,
coeToPowerSeries.ringHom_apply, coe_C, coe_X]
end Semiring
section CommSemiring
variable {R : Type*} [CommSemiring R] (φ ψ : R[X])
theorem _root_.MvPolynomial.toMvPowerSeries_pUnitAlgEquiv {f : MvPolynomial PUnit R} :
(f.toMvPowerSeries : PowerSeries R) = (f.pUnitAlgEquiv R).toPowerSeries := by
induction f using MvPolynomial.induction_on' with
| monomial d r =>
--Note: this `have` should be a generic `simp` lemma for a `Unique` type with `()` replaced
--by any element.
have : single () (d ()) = d := by ext; simp
simp only [MvPolynomial.coe_monomial, MvPolynomial.pUnitAlgEquiv_monomial,
Polynomial.coe_monomial, PowerSeries.monomial, this]
| add f g hf hg => simp [hf, hg]
theorem pUnitAlgEquiv_symm_toPowerSeries {f : Polynomial R} :
((f.toPowerSeries) : MvPowerSeries PUnit R)
= ((MvPolynomial.pUnitAlgEquiv R).symm f).toMvPowerSeries := by
set g := (MvPolynomial.pUnitAlgEquiv R).symm f
have : f = MvPolynomial.pUnitAlgEquiv R g := by simp only [g, AlgEquiv.apply_symm_apply]
rw [this, MvPolynomial.toMvPowerSeries_pUnitAlgEquiv]
variable (A : Type*) [Semiring A] [Algebra R A]
/-- The coercion from polynomials to power series
as an algebra homomorphism.
-/
def coeToPowerSeries.algHom : R[X] →ₐ[R] PowerSeries A :=
{ (PowerSeries.map (algebraMap R A)).comp coeToPowerSeries.ringHom with
commutes' := fun r => by simp [algebraMap_apply, PowerSeries.algebraMap_apply] }
@[simp]
theorem coeToPowerSeries.algHom_apply :
coeToPowerSeries.algHom A φ = PowerSeries.map (algebraMap R A) ↑φ :=
rfl
end CommSemiring
section CommRing
variable {R : Type*} [CommRing R]
@[simp, norm_cast]
lemma coe_neg (p : R[X]) : ((- p : R[X]) : PowerSeries R) = - p :=
coeToPowerSeries.ringHom.map_neg p
@[simp, norm_cast]
lemma coe_sub (p q : R[X]) : ((p - q : R[X]) : PowerSeries R) = p - q :=
coeToPowerSeries.ringHom.map_sub p q
end CommRing
end Polynomial
namespace PowerSeries
section Algebra
open Polynomial
variable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (f : R⟦X⟧)
| instance algebraPolynomial : Algebra R[X] A⟦X⟧ :=
| Mathlib/RingTheory/PowerSeries/Basic.lean | 940 | 940 |
/-
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
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.Order.Field.Canonical
import Mathlib.Algebra.Order.Nonneg.Ring
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Semifield structure on the type of nonnegative elements
This file defines instances and prove some properties about the nonnegative elements
`{x : α // 0 ≤ x}` of an arbitrary type `α`.
This is used to derive algebraic structures on `ℝ≥0` and `ℚ≥0` automatically.
## Main declarations
* `{x : α // 0 ≤ x}` is a `CanonicallyLinearOrderedSemifield` if `α` is a `LinearOrderedField`.
-/
assert_not_exists abs_inv
open Set
variable {α : Type*}
section NNRat
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a : α}
lemma NNRat.cast_nonneg (q : ℚ≥0) : 0 ≤ (q : α) := by
rw [cast_def]; exact div_nonneg q.num.cast_nonneg q.den.cast_nonneg
lemma nnqsmul_nonneg (q : ℚ≥0) (ha : 0 ≤ a) : 0 ≤ q • a := by
| rw [NNRat.smul_def]; exact mul_nonneg q.cast_nonneg ha
| Mathlib/Algebra/Order/Nonneg/Field.lean | 37 | 38 |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,
Amelia Livingston, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Action.Faithful
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.Prod
import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Algebra.Group.Submonoid.MulAction
import Mathlib.Algebra.Group.TypeTags.Basic
/-!
# Operations on `Submonoid`s
In this file we define various operations on `Submonoid`s and `MonoidHom`s.
## Main definitions
### Conversion between multiplicative and additive definitions
* `Submonoid.toAddSubmonoid`, `Submonoid.toAddSubmonoid'`, `AddSubmonoid.toSubmonoid`,
`AddSubmonoid.toSubmonoid'`: convert between multiplicative and additive submonoids of `M`,
`Multiplicative M`, and `Additive M`. These are stated as `OrderIso`s.
### (Commutative) monoid structure on a submonoid
* `Submonoid.toMonoid`, `Submonoid.toCommMonoid`: a submonoid inherits a (commutative) monoid
structure.
### Group actions by submonoids
* `Submonoid.MulAction`, `Submonoid.DistribMulAction`: a submonoid inherits (distributive)
multiplicative actions.
### Operations on submonoids
* `Submonoid.comap`: preimage of a submonoid under a monoid homomorphism as a submonoid of the
domain;
* `Submonoid.map`: image of a submonoid under a monoid homomorphism as a submonoid of the codomain;
* `Submonoid.prod`: product of two submonoids `s : Submonoid M` and `t : Submonoid N` as a submonoid
of `M × N`;
### Monoid homomorphisms between submonoid
* `Submonoid.subtype`: embedding of a submonoid into the ambient monoid.
* `Submonoid.inclusion`: given two submonoids `S`, `T` such that `S ≤ T`, `S.inclusion T` is the
inclusion of `S` into `T` as a monoid homomorphism;
* `MulEquiv.submonoidCongr`: converts a proof of `S = T` into a monoid isomorphism between `S`
and `T`.
* `Submonoid.prodEquiv`: monoid isomorphism between `s.prod t` and `s × t`;
### Operations on `MonoidHom`s
* `MonoidHom.mrange`: range of a monoid homomorphism as a submonoid of the codomain;
* `MonoidHom.mker`: kernel of a monoid homomorphism as a submonoid of the domain;
* `MonoidHom.restrict`: restrict a monoid homomorphism to a submonoid;
* `MonoidHom.codRestrict`: restrict the codomain of a monoid homomorphism to a submonoid;
* `MonoidHom.mrangeRestrict`: restrict a monoid homomorphism to its range;
## Tags
submonoid, range, product, map, comap
-/
assert_not_exists MonoidWithZero
open Function
variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass P] (S : Submonoid M)
/-!
### Conversion to/from `Additive`/`Multiplicative`
-/
section
/-- Submonoids of monoid `M` are isomorphic to additive submonoids of `Additive M`. -/
@[simps]
def Submonoid.toAddSubmonoid : Submonoid M ≃o AddSubmonoid (Additive M) where
toFun S :=
{ carrier := Additive.toMul ⁻¹' S
zero_mem' := S.one_mem'
add_mem' := fun ha hb => S.mul_mem' ha hb }
invFun S :=
{ carrier := Additive.ofMul ⁻¹' S
one_mem' := S.zero_mem'
mul_mem' := fun ha hb => S.add_mem' ha hb}
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
/-- Additive submonoids of an additive monoid `Additive M` are isomorphic to submonoids of `M`. -/
abbrev AddSubmonoid.toSubmonoid' : AddSubmonoid (Additive M) ≃o Submonoid M :=
Submonoid.toAddSubmonoid.symm
theorem Submonoid.toAddSubmonoid_closure (S : Set M) :
Submonoid.toAddSubmonoid (Submonoid.closure S)
= AddSubmonoid.closure (Additive.toMul ⁻¹' S) :=
le_antisymm
(Submonoid.toAddSubmonoid.le_symm_apply.1 <|
Submonoid.closure_le.2 (AddSubmonoid.subset_closure (M := Additive M)))
(AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := M))
theorem AddSubmonoid.toSubmonoid'_closure (S : Set (Additive M)) :
AddSubmonoid.toSubmonoid' (AddSubmonoid.closure S)
= Submonoid.closure (Additive.ofMul ⁻¹' S) :=
le_antisymm
(AddSubmonoid.toSubmonoid'.le_symm_apply.1 <|
AddSubmonoid.closure_le.2 (Submonoid.subset_closure (M := M)))
(Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := Additive M))
end
section
variable {A : Type*} [AddZeroClass A]
/-- Additive submonoids of an additive monoid `A` are isomorphic to
multiplicative submonoids of `Multiplicative A`. -/
@[simps]
def AddSubmonoid.toSubmonoid : AddSubmonoid A ≃o Submonoid (Multiplicative A) where
toFun S :=
{ carrier := Multiplicative.toAdd ⁻¹' S
one_mem' := S.zero_mem'
mul_mem' := fun ha hb => S.add_mem' ha hb }
invFun S :=
{ carrier := Multiplicative.ofAdd ⁻¹' S
zero_mem' := S.one_mem'
add_mem' := fun ha hb => S.mul_mem' ha hb}
left_inv x := by cases x; rfl
right_inv x := by cases x; rfl
map_rel_iff' := Iff.rfl
/-- Submonoids of a monoid `Multiplicative A` are isomorphic to additive submonoids of `A`. -/
abbrev Submonoid.toAddSubmonoid' : Submonoid (Multiplicative A) ≃o AddSubmonoid A :=
AddSubmonoid.toSubmonoid.symm
theorem AddSubmonoid.toSubmonoid_closure (S : Set A) :
(AddSubmonoid.toSubmonoid) (AddSubmonoid.closure S)
= Submonoid.closure (Multiplicative.toAdd ⁻¹' S) :=
le_antisymm
(AddSubmonoid.toSubmonoid.to_galoisConnection.l_le <|
AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A))
(Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A))
theorem Submonoid.toAddSubmonoid'_closure (S : Set (Multiplicative A)) :
Submonoid.toAddSubmonoid' (Submonoid.closure S)
= AddSubmonoid.closure (Multiplicative.ofAdd ⁻¹' S) :=
le_antisymm
(Submonoid.toAddSubmonoid'.to_galoisConnection.l_le <|
Submonoid.closure_le.2 <| AddSubmonoid.subset_closure (M := A))
(AddSubmonoid.closure_le.2 <| Submonoid.subset_closure (M := Multiplicative A))
end
namespace Submonoid
variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N]
open Set
/-!
### `comap` and `map`
-/
/-- The preimage of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive
"The preimage of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`."]
def comap (f : F) (S : Submonoid N) :
Submonoid M where
carrier := f ⁻¹' S
one_mem' := show f 1 ∈ S by rw [map_one]; exact S.one_mem
mul_mem' ha hb := show f (_ * _) ∈ S by rw [map_mul]; exact S.mul_mem ha hb
@[to_additive (attr := simp)]
theorem coe_comap (S : Submonoid N) (f : F) : (S.comap f : Set M) = f ⁻¹' S :=
rfl
@[to_additive (attr := simp)]
theorem mem_comap {S : Submonoid N} {f : F} {x : M} : x ∈ S.comap f ↔ f x ∈ S :=
Iff.rfl
@[to_additive]
theorem comap_comap (S : Submonoid P) (g : N →* P) (f : M →* N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[to_additive (attr := simp)]
theorem comap_id (S : Submonoid P) : S.comap (MonoidHom.id P) = S :=
ext (by simp)
/-- The image of a submonoid along a monoid homomorphism is a submonoid. -/
@[to_additive
"The image of an `AddSubmonoid` along an `AddMonoid` homomorphism is an `AddSubmonoid`."]
def map (f : F) (S : Submonoid M) :
Submonoid N where
carrier := f '' S
one_mem' := ⟨1, S.one_mem, map_one f⟩
mul_mem' := by
rintro _ _ ⟨x, hx, rfl⟩ ⟨y, hy, rfl⟩
exact ⟨x * y, S.mul_mem hx hy, by rw [map_mul]⟩
@[to_additive (attr := simp)]
theorem coe_map (f : F) (S : Submonoid M) : (S.map f : Set N) = f '' S :=
rfl
@[to_additive (attr := simp)]
theorem map_coe_toMonoidHom (f : F) (S : Submonoid M) : S.map (f : M →* N) = S.map f :=
rfl
@[to_additive (attr := simp)]
theorem map_coe_toMulEquiv {F} [EquivLike F M N] [MulEquivClass F M N] (f : F) (S : Submonoid M) :
S.map (f : M ≃* N) = S.map f :=
rfl
@[to_additive (attr := simp)]
theorem mem_map {f : F} {S : Submonoid M} {y : N} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl
@[to_additive]
theorem mem_map_of_mem (f : F) {S : Submonoid M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
@[to_additive]
theorem apply_coe_mem_map (f : F) (S : Submonoid M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.2
@[to_additive]
theorem map_map (g : N →* P) (f : M →* N) : (S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| image_image _ _ _
-- The simpNF linter says that the LHS can be simplified via `Submonoid.mem_map`.
-- However this is a higher priority lemma.
-- It seems the side condition `hf` is not applied by `simpNF`.
-- https://github.com/leanprover/std4/issues/207
@[to_additive (attr := simp 1100, nolint simpNF)]
theorem mem_map_iff_mem {f : F} (hf : Function.Injective f) {S : Submonoid M} {x : M} :
f x ∈ S.map f ↔ x ∈ S :=
hf.mem_set_image
@[to_additive]
theorem map_le_iff_le_comap {f : F} {S : Submonoid M} {T : Submonoid N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
@[to_additive]
theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap
@[to_additive]
theorem map_le_of_le_comap {T : Submonoid N} {f : F} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
@[to_additive]
theorem le_comap_of_map_le {T : Submonoid N} {f : F} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
@[to_additive]
theorem le_comap_map {f : F} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
@[to_additive]
theorem map_comap_le {S : Submonoid N} {f : F} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
@[to_additive]
theorem monotone_map {f : F} : Monotone (map f) :=
(gc_map_comap f).monotone_l
@[to_additive]
theorem monotone_comap {f : F} : Monotone (comap f) :=
(gc_map_comap f).monotone_u
@[to_additive (attr := simp)]
theorem map_comap_map {f : F} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[to_additive (attr := simp)]
theorem comap_map_comap {S : Submonoid N} {f : F} : ((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
@[to_additive]
theorem map_sup (S T : Submonoid M) (f : F) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
@[to_additive]
theorem map_iSup {ι : Sort*} (f : F) (s : ι → Submonoid M) : (iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
@[to_additive]
theorem map_inf (S T : Submonoid M) (f : F) (hf : Function.Injective f) :
(S ⊓ T).map f = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf)
@[to_additive]
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : F) (hf : Function.Injective f)
(s : ι → Submonoid M) : (iInf s).map f = ⨅ i, (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
@[to_additive]
theorem comap_inf (S T : Submonoid N) (f : F) : (S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_inf
@[to_additive]
theorem comap_iInf {ι : Sort*} (f : F) (s : ι → Submonoid N) :
(iInf s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
@[to_additive (attr := simp)]
theorem map_bot (f : F) : (⊥ : Submonoid M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[to_additive (attr := simp)]
theorem comap_top (f : F) : (⊤ : Submonoid N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[to_additive (attr := simp)]
theorem map_id (S : Submonoid M) : S.map (MonoidHom.id M) = S :=
ext fun _ => ⟨fun ⟨_, h, rfl⟩ => h, fun h => ⟨_, h, rfl⟩⟩
section GaloisCoinsertion
variable {ι : Type*} {f : F}
/-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/
@[to_additive "`map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective."]
def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff]
variable (hf : Function.Injective f)
include hf
@[to_additive]
theorem comap_map_eq_of_injective (S : Submonoid M) : (S.map f).comap f = S :=
(gciMapComap hf).u_l_eq _
@[to_additive]
theorem comap_surjective_of_injective : Function.Surjective (comap f) :=
(gciMapComap hf).u_surjective
@[to_additive]
theorem map_injective_of_injective : Function.Injective (map f) :=
(gciMapComap hf).l_injective
@[to_additive]
theorem comap_inf_map_of_injective (S T : Submonoid M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gciMapComap hf).u_inf_l _ _
@[to_additive]
theorem comap_iInf_map_of_injective (S : ι → Submonoid M) : (⨅ i, (S i).map f).comap f = iInf S :=
(gciMapComap hf).u_iInf_l _
@[to_additive]
theorem comap_sup_map_of_injective (S T : Submonoid M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gciMapComap hf).u_sup_l _ _
@[to_additive]
theorem comap_iSup_map_of_injective (S : ι → Submonoid M) : (⨆ i, (S i).map f).comap f = iSup S :=
(gciMapComap hf).u_iSup_l _
@[to_additive]
theorem map_le_map_iff_of_injective {S T : Submonoid M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gciMapComap hf).l_le_l_iff
@[to_additive]
theorem map_strictMono_of_injective : StrictMono (map f) :=
(gciMapComap hf).strictMono_l
end GaloisCoinsertion
section GaloisInsertion
variable {ι : Type*} {f : F}
/-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/
@[to_additive "`map f` and `comap f` form a `GaloisInsertion` when `f` is surjective."]
def giMapComap (hf : Function.Surjective f) : GaloisInsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisInsertion fun S x h =>
let ⟨y, hy⟩ := hf x
mem_map.2 ⟨y, by simp [hy, h]⟩
variable (hf : Function.Surjective f)
include hf
@[to_additive]
theorem map_comap_eq_of_surjective (S : Submonoid N) : (S.comap f).map f = S :=
(giMapComap hf).l_u_eq _
@[to_additive]
theorem map_surjective_of_surjective : Function.Surjective (map f) :=
(giMapComap hf).l_surjective
@[to_additive]
theorem comap_injective_of_surjective : Function.Injective (comap f) :=
(giMapComap hf).u_injective
@[to_additive]
theorem map_inf_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(giMapComap hf).l_inf_u _ _
@[to_additive]
theorem map_iInf_comap_of_surjective (S : ι → Submonoid N) : (⨅ i, (S i).comap f).map f = iInf S :=
(giMapComap hf).l_iInf_u _
@[to_additive]
theorem map_sup_comap_of_surjective (S T : Submonoid N) : (S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(giMapComap hf).l_sup_u _ _
@[to_additive]
theorem map_iSup_comap_of_surjective (S : ι → Submonoid N) : (⨆ i, (S i).comap f).map f = iSup S :=
(giMapComap hf).l_iSup_u _
@[to_additive]
theorem comap_le_comap_iff_of_surjective {S T : Submonoid N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(giMapComap hf).u_le_u_iff
@[to_additive]
theorem comap_strictMono_of_surjective : StrictMono (comap f) :=
(giMapComap hf).strictMono_u
end GaloisInsertion
variable {M : Type*} [MulOneClass M] (S : Submonoid M)
/-- The top submonoid is isomorphic to the monoid. -/
@[to_additive (attr := simps) "The top additive submonoid is isomorphic to the additive monoid."]
def topEquiv : (⊤ : Submonoid M) ≃* M where
toFun x := x
invFun x := ⟨x, mem_top x⟩
left_inv x := x.eta _
right_inv _ := rfl
map_mul' _ _ := rfl
@[to_additive (attr := simp)]
theorem topEquiv_toMonoidHom : ((topEquiv : _ ≃* M) : _ →* M) = (⊤ : Submonoid M).subtype :=
rfl
/-- A subgroup is isomorphic to its image under an injective function. If you have an isomorphism,
use `MulEquiv.submonoidMap` for better definitional equalities. -/
@[to_additive "An additive subgroup is isomorphic to its image under an injective function. If you
have an isomorphism, use `AddEquiv.addSubmonoidMap` for better definitional equalities."]
noncomputable def equivMapOfInjective (f : M →* N) (hf : Function.Injective f) : S ≃* S.map f :=
{ Equiv.Set.image f S hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) }
@[to_additive (attr := simp)]
theorem coe_equivMapOfInjective_apply (f : M →* N) (hf : Function.Injective f) (x : S) :
(equivMapOfInjective S f hf x : N) = f x :=
rfl
@[to_additive (attr := simp)]
theorem closure_closure_coe_preimage {s : Set M} : closure (((↑) : closure s → M) ⁻¹' s) = ⊤ :=
eq_top_iff.2 fun x _ ↦ Subtype.recOn x fun _ hx' ↦
closure_induction (fun _ h ↦ subset_closure h) (one_mem _) (fun _ _ _ _ ↦ mul_mem) hx'
/-- Given submonoids `s`, `t` of monoids `M`, `N` respectively, `s × t` as a submonoid
of `M × N`. -/
@[to_additive prod
"Given `AddSubmonoid`s `s`, `t` of `AddMonoid`s `A`, `B` respectively, `s × t`
as an `AddSubmonoid` of `A × B`."]
def prod (s : Submonoid M) (t : Submonoid N) :
Submonoid (M × N) where
carrier := s ×ˢ t
one_mem' := ⟨s.one_mem, t.one_mem⟩
mul_mem' hp hq := ⟨s.mul_mem hp.1 hq.1, t.mul_mem hp.2 hq.2⟩
@[to_additive coe_prod]
theorem coe_prod (s : Submonoid M) (t : Submonoid N) :
(s.prod t : Set (M × N)) = (s : Set M) ×ˢ (t : Set N) :=
rfl
@[to_additive mem_prod]
theorem mem_prod {s : Submonoid M} {t : Submonoid N} {p : M × N} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t :=
Iff.rfl
@[to_additive prod_mono]
theorem prod_mono {s₁ s₂ : Submonoid M} {t₁ t₂ : Submonoid N} (hs : s₁ ≤ s₂) (ht : t₁ ≤ t₂) :
s₁.prod t₁ ≤ s₂.prod t₂ :=
Set.prod_mono hs ht
@[to_additive prod_top]
theorem prod_top (s : Submonoid M) : s.prod (⊤ : Submonoid N) = s.comap (MonoidHom.fst M N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
@[to_additive top_prod]
theorem top_prod (s : Submonoid N) : (⊤ : Submonoid M).prod s = s.comap (MonoidHom.snd M N) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[to_additive (attr := simp) top_prod_top]
theorem top_prod_top : (⊤ : Submonoid M).prod (⊤ : Submonoid N) = ⊤ :=
(top_prod _).trans <| comap_top _
@[to_additive bot_prod_bot]
theorem bot_prod_bot : (⊥ : Submonoid M).prod (⊥ : Submonoid N) = ⊥ :=
SetLike.coe_injective <| by simp [coe_prod]
/-- The product of submonoids is isomorphic to their product as monoids. -/
@[to_additive prodEquiv
"The product of additive submonoids is isomorphic to their product as additive monoids"]
def prodEquiv (s : Submonoid M) (t : Submonoid N) : s.prod t ≃* s × t :=
{ (Equiv.Set.prod (s : Set M) (t : Set N)) with
map_mul' := fun _ _ => rfl }
open MonoidHom
@[to_additive]
theorem map_inl (s : Submonoid M) : s.map (inl M N) = s.prod ⊥ :=
ext fun p =>
⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨hx, Set.mem_singleton 1⟩, fun ⟨hps, hp1⟩ =>
⟨p.1, hps, Prod.ext rfl <| (Set.eq_of_mem_singleton hp1).symm⟩⟩
@[to_additive]
theorem map_inr (s : Submonoid N) : s.map (inr M N) = prod ⊥ s :=
ext fun p =>
⟨fun ⟨_, hx, hp⟩ => hp ▸ ⟨Set.mem_singleton 1, hx⟩, fun ⟨hp1, hps⟩ =>
⟨p.2, hps, Prod.ext (Set.eq_of_mem_singleton hp1).symm rfl⟩⟩
@[to_additive (attr := simp) prod_bot_sup_bot_prod]
theorem prod_bot_sup_bot_prod (s : Submonoid M) (t : Submonoid N) :
(prod s ⊥) ⊔ (prod ⊥ t) = prod s t :=
(le_antisymm (sup_le (prod_mono (le_refl s) bot_le) (prod_mono bot_le (le_refl t))))
fun p hp => Prod.fst_mul_snd p ▸ mul_mem
((le_sup_left : prod s ⊥ ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨hp.1, Set.mem_singleton 1⟩)
((le_sup_right : prod ⊥ t ≤ prod s ⊥ ⊔ prod ⊥ t) ⟨Set.mem_singleton 1, hp.2⟩)
@[to_additive]
theorem mem_map_equiv {f : M ≃* N} {K : Submonoid M} {x : N} :
x ∈ K.map f.toMonoidHom ↔ f.symm x ∈ K :=
Set.mem_image_equiv
@[to_additive]
theorem map_equiv_eq_comap_symm (f : M ≃* N) (K : Submonoid M) :
K.map f = K.comap f.symm :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage K)
@[to_additive]
theorem comap_equiv_eq_map_symm (f : N ≃* M) (K : Submonoid M) :
K.comap f = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
@[to_additive (attr := simp)]
theorem map_equiv_top (f : M ≃* N) : (⊤ : Submonoid M).map f = ⊤ :=
SetLike.coe_injective <| Set.image_univ.trans f.surjective.range_eq
@[to_additive le_prod_iff]
theorem le_prod_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} :
u ≤ s.prod t ↔ u.map (fst M N) ≤ s ∧ u.map (snd M N) ≤ t := by
constructor
· intro h
constructor
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).1
· rintro x ⟨⟨y1, y2⟩, ⟨hy1, rfl⟩⟩
exact (h hy1).2
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ h
exact ⟨hH ⟨_, h, rfl⟩, hK ⟨_, h, rfl⟩⟩
@[to_additive prod_le_iff]
theorem prod_le_iff {s : Submonoid M} {t : Submonoid N} {u : Submonoid (M × N)} :
s.prod t ≤ u ↔ s.map (inl M N) ≤ u ∧ t.map (inr M N) ≤ u := by
constructor
· intro h
constructor
· rintro _ ⟨x, hx, rfl⟩
apply h
exact ⟨hx, Submonoid.one_mem _⟩
· rintro _ ⟨x, hx, rfl⟩
apply h
exact ⟨Submonoid.one_mem _, hx⟩
· rintro ⟨hH, hK⟩ ⟨x1, x2⟩ ⟨h1, h2⟩
have h1' : inl M N x1 ∈ u := by
apply hH
simpa using h1
have h2' : inr M N x2 ∈ u := by
apply hK
simpa using h2
simpa using Submonoid.mul_mem _ h1' h2'
@[to_additive closure_prod]
theorem closure_prod {s : Set M} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) :
closure (s ×ˢ t) = (closure s).prod (closure t) :=
le_antisymm
(closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩)
(prod_le_iff.2 ⟨
map_le_of_le_comap _ <| closure_le.2 fun _x hx => subset_closure ⟨hx, ht⟩,
map_le_of_le_comap _ <| closure_le.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩)
@[to_additive (attr := simp) closure_prod_zero]
lemma closure_prod_one (s : Set M) : closure (s ×ˢ ({1} : Set N)) = (closure s).prod ⊥ :=
le_antisymm
(closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, .rfl⟩)
(prod_le_iff.2 ⟨
map_le_of_le_comap _ <| closure_le.2 fun _x hx => subset_closure ⟨hx, rfl⟩,
by simp⟩)
@[to_additive (attr := simp) closure_zero_prod]
lemma closure_one_prod (t : Set N) : closure (({1} : Set M) ×ˢ t) = .prod ⊥ (closure t) :=
le_antisymm
(closure_le.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨.rfl, subset_closure⟩)
(prod_le_iff.2 ⟨by simp,
map_le_of_le_comap _ <| closure_le.2 fun _y hy => subset_closure ⟨rfl, hy⟩⟩)
end Submonoid
namespace MonoidHom
variable {F : Type*} [FunLike F M N] [mc : MonoidHomClass F M N]
open Submonoid
library_note "range copy pattern"/--
For many categories (monoids, modules, rings, ...) the set-theoretic image of a morphism `f` is
a subobject of the codomain. When this is the case, it is useful to define the range of a morphism
in such a way that the underlying carrier set of the range subobject is definitionally
`Set.range f`. In particular this means that the types `↥(Set.range f)` and `↥f.range` are
interchangeable without proof obligations.
A convenient candidate definition for range which is mathematically correct is `map ⊤ f`, just as
`Set.range` could have been defined as `f '' Set.univ`. However, this lacks the desired definitional
convenience, in that it both does not match `Set.range`, and that it introduces a redundant `x ∈ ⊤`
term which clutters proofs. In such a case one may resort to the `copy`
pattern. A `copy` function converts the definitional problem for the carrier set of a subobject
into a one-off propositional proof obligation which one discharges while writing the definition of
the definitionally convenient range (the parameter `hs` in the example below).
A good example is the case of a morphism of monoids. A convenient definition for
`MonoidHom.mrange` would be `(⊤ : Submonoid M).map f`. However since this lacks the required
definitional convenience, we first define `Submonoid.copy` as follows:
```lean
protected def copy (S : Submonoid M) (s : Set M) (hs : s = S) : Submonoid M :=
{ carrier := s,
one_mem' := hs.symm ▸ S.one_mem',
mul_mem' := hs.symm ▸ S.mul_mem' }
```
and then finally define:
```lean
def mrange (f : M →* N) : Submonoid N :=
((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm
```
-/
/-- The range of a monoid homomorphism is a submonoid. See Note [range copy pattern]. -/
@[to_additive "The range of an `AddMonoidHom` is an `AddSubmonoid`."]
def mrange (f : F) : Submonoid N :=
((⊤ : Submonoid M).map f).copy (Set.range f) Set.image_univ.symm
@[to_additive (attr := simp)]
theorem coe_mrange (f : F) : (mrange f : Set N) = Set.range f :=
rfl
@[to_additive (attr := simp)]
theorem mem_mrange {f : F} {y : N} : y ∈ mrange f ↔ ∃ x, f x = y :=
Iff.rfl
@[to_additive]
lemma mrange_comp {O : Type*} [MulOneClass O] (f : N →* O) (g : M →* N) :
mrange (f.comp g) = (mrange g).map f := SetLike.coe_injective <| Set.range_comp f _
@[to_additive]
theorem mrange_eq_map (f : F) : mrange f = (⊤ : Submonoid M).map f :=
Submonoid.copy_eq _
@[to_additive (attr := simp)]
theorem mrange_id : mrange (MonoidHom.id M) = ⊤ := by
simp [mrange_eq_map]
@[to_additive]
theorem map_mrange (g : N →* P) (f : M →* N) : (mrange f).map g = mrange (comp g f) := by
simpa only [mrange_eq_map] using (⊤ : Submonoid M).map_map g f
@[to_additive]
theorem mrange_eq_top {f : F} : mrange f = (⊤ : Submonoid N) ↔ Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_mrange, coe_top]) Set.range_eq_univ
@[deprecated (since := "2024-11-11")]
alias mrange_top_iff_surjective := mrange_eq_top
/-- The range of a surjective monoid hom is the whole of the codomain. -/
@[to_additive (attr := simp)
"The range of a surjective `AddMonoid` hom is the whole of the codomain."]
theorem mrange_eq_top_of_surjective (f : F) (hf : Function.Surjective f) :
mrange f = (⊤ : Submonoid N) :=
mrange_eq_top.2 hf
@[deprecated (since := "2024-11-11")] alias mrange_top_of_surjective := mrange_eq_top_of_surjective
@[to_additive]
theorem mclosure_preimage_le (f : F) (s : Set N) : closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 fun _ hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated
by the image of the set. -/
@[to_additive
"The image under an `AddMonoid` hom of the `AddSubmonoid` generated by a set equals
the `AddSubmonoid` generated by the image of the set."]
theorem map_mclosure (f : F) (s : Set M) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (Submonoid.gi N).gc (Submonoid.gi M).gc
fun _ ↦ rfl
@[to_additive (attr := simp)]
theorem mclosure_range (f : F) : closure (Set.range f) = mrange f := by
rw [← Set.image_univ, ← map_mclosure, mrange_eq_map, closure_univ]
/-- Restriction of a monoid hom to a submonoid of the domain. -/
@[to_additive "Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the domain."]
def restrict {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M] (f : M →* N)
(s : S) : s →* N :=
f.comp (SubmonoidClass.subtype _)
@[to_additive (attr := simp)]
theorem restrict_apply {N S : Type*} [MulOneClass N] [SetLike S M] [SubmonoidClass S M]
(f : M →* N) (s : S) (x : s) : f.restrict s x = f x :=
rfl
@[to_additive (attr := simp)]
theorem restrict_mrange (f : M →* N) : mrange (f.restrict S) = S.map f := by
simp [SetLike.ext_iff]
/-- Restriction of a monoid hom to a submonoid of the codomain. -/
@[to_additive (attr := simps apply)
"Restriction of an `AddMonoid` hom to an `AddSubmonoid` of the codomain."]
def codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S) (h : ∀ x, f x ∈ s) :
M →* s where
toFun n := ⟨f n, h n⟩
map_one' := Subtype.eq f.map_one
map_mul' x y := Subtype.eq (f.map_mul x y)
@[to_additive (attr := simp)]
lemma injective_codRestrict {S} [SetLike S N] [SubmonoidClass S N] (f : M →* N) (s : S)
(h : ∀ x, f x ∈ s) : Function.Injective (f.codRestrict s h) ↔ Function.Injective f :=
⟨fun H _ _ hxy ↦ H <| Subtype.eq hxy, fun H _ _ hxy ↦ H (congr_arg Subtype.val hxy)⟩
/-- Restriction of a monoid hom to its range interpreted as a submonoid. -/
@[to_additive "Restriction of an `AddMonoid` hom to its range interpreted as a submonoid."]
def mrangeRestrict {N} [MulOneClass N] (f : M →* N) : M →* (mrange f) :=
(f.codRestrict (mrange f)) fun x => ⟨x, rfl⟩
@[to_additive (attr := simp)]
theorem coe_mrangeRestrict {N} [MulOneClass N] (f : M →* N) (x : M) :
(f.mrangeRestrict x : N) = f x :=
rfl
@[to_additive]
theorem mrangeRestrict_surjective (f : M →* N) : Function.Surjective f.mrangeRestrict :=
fun ⟨_, ⟨x, rfl⟩⟩ => ⟨x, rfl⟩
/-- The multiplicative kernel of a monoid hom is the submonoid of elements `x : G` such
that `f x = 1` -/
@[to_additive
"The additive kernel of an `AddMonoid` hom is the `AddSubmonoid` of
elements such that `f x = 0`"]
def mker (f : F) : Submonoid M :=
(⊥ : Submonoid N).comap f
@[to_additive (attr := simp)]
theorem mem_mker {f : F} {x : M} : x ∈ mker f ↔ f x = 1 :=
Iff.rfl
@[to_additive]
theorem coe_mker (f : F) : (mker f : Set M) = (f : M → N) ⁻¹' {1} :=
rfl
@[to_additive]
instance decidableMemMker [DecidableEq N] (f : F) : DecidablePred (· ∈ mker f) := fun x =>
decidable_of_iff (f x = 1) mem_mker
@[to_additive]
theorem comap_mker (g : N →* P) (f : M →* N) : (mker g).comap f = mker (comp g f) :=
rfl
@[to_additive (attr := simp)]
theorem comap_bot' (f : F) : (⊥ : Submonoid N).comap f = mker f :=
rfl
@[to_additive (attr := simp)]
theorem restrict_mker (f : M →* N) : mker (f.restrict S) = (MonoidHom.mker f).comap S.subtype :=
rfl
@[to_additive]
theorem mrangeRestrict_mker (f : M →* N) : mker (mrangeRestrict f) = mker f := by
ext x
change (⟨f x, _⟩ : mrange f) = ⟨1, _⟩ ↔ f x = 1
simp
@[to_additive (attr := simp)]
theorem mker_one : mker (1 : M →* N) = ⊤ := by
ext
simp [mem_mker]
@[to_additive prod_map_comap_prod']
theorem prod_map_comap_prod' {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N']
(f : M →* N) (g : M' →* N') (S : Submonoid N) (S' : Submonoid N') :
(S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) :=
SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _
@[to_additive mker_prod_map]
theorem mker_prod_map {M' : Type*} {N' : Type*} [MulOneClass M'] [MulOneClass N'] (f : M →* N)
(g : M' →* N') : mker (prodMap f g) = (mker f).prod (mker g) := by
| rw [← comap_bot', ← comap_bot', ← comap_bot', ← prod_map_comap_prod', bot_prod_bot]
| Mathlib/Algebra/Group/Submonoid/Operations.lean | 800 | 801 |
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Scott Carnahan
-/
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Finset.MulAntidiagonal
import Mathlib.Data.Finset.SMulAntidiagonal
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.RingTheory.HahnSeries.Addition
/-!
# Multiplicative properties of Hahn series
If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with
coefficients in `R`, whose supports are partially well-ordered. This module introduces
multiplication and scalar multiplication on Hahn series. If `Γ` is an ordered cancellative
commutative additive monoid and `R` is a semiring, then we get a semiring structure on
`HahnSeries Γ R`. If `Γ` has an ordered vector-addition on `Γ'` and `R` has a scalar multiplication
on `V`, we define `HahnModule Γ' R V` as a type alias for `HahnSeries Γ' V` that admits a scalar
multiplication from `HahnSeries Γ R`. The scalar action of `R` on `HahnSeries Γ R` is compatible
with the action of `HahnSeries Γ R` on `HahnModule Γ' R V`.
## Main Definitions
* `HahnModule` is a type alias for `HahnSeries`, which we use for defining scalar multiplication
of `HahnSeries Γ R` on `HahnModule Γ' R V` for an `R`-module `V`, where `Γ'` admits an ordered
cancellative vector addition operation from `Γ`. The type alias allows us to avoid a potential
instance diamond.
* `HahnModule.of` is the isomorphism from `HahnSeries Γ V` to `HahnModule Γ R V`.
* `HahnSeries.C` is the `constant term` ring homomorphism `R →+* HahnSeries Γ R`.
* `HahnSeries.embDomainRingHom` is the ring homomorphism `HahnSeries Γ R →+* HahnSeries Γ' R`
induced by an order embedding `Γ ↪o Γ'`.
## Main results
* If `R` is a (commutative) (semi-)ring, then so is `HahnSeries Γ R`.
* If `V` is an `R`-module, then `HahnModule Γ' R V` is a `HahnSeries Γ R`-module.
## TODO
The following may be useful for composing vertex operators, but they seem to take time.
* rightTensorMap: `HahnModule Γ' R U ⊗[R] V →ₗ[R] HahnModule Γ' R (U ⊗[R] V)`
* leftTensorMap: `U ⊗[R] HahnModule Γ' R V →ₗ[R] HahnModule Γ' R (U ⊗[R] V)`
## References
- [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven]
-/
open Finset Function Pointwise
noncomputable section
variable {Γ Γ' R S V : Type*}
namespace HahnSeries
variable [Zero Γ] [PartialOrder Γ]
instance [Zero R] [One R] : One (HahnSeries Γ R) :=
⟨single 0 1⟩
open Classical in
@[simp]
theorem coeff_one [Zero R] [One R] {a : Γ} :
(1 : HahnSeries Γ R).coeff a = if a = 0 then 1 else 0 :=
coeff_single
@[deprecated (since := "2025-01-31")] alias one_coeff := coeff_one
@[simp]
theorem single_zero_one [Zero R] [One R] : single (0 : Γ) (1 : R) = 1 :=
rfl
@[simp]
theorem support_one [MulZeroOneClass R] [Nontrivial R] : support (1 : HahnSeries Γ R) = {0} :=
support_single_of_ne one_ne_zero
@[simp]
theorem orderTop_one [MulZeroOneClass R] [Nontrivial R] : orderTop (1 : HahnSeries Γ R) = 0 := by
rw [← single_zero_one, orderTop_single one_ne_zero, WithTop.coe_eq_zero]
@[simp]
theorem order_one [MulZeroOneClass R] : order (1 : HahnSeries Γ R) = 0 := by
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim (1 : HahnSeries Γ R) 0, order_zero]
· exact order_single one_ne_zero
@[simp]
theorem leadingCoeff_one [MulZeroOneClass R] : (1 : HahnSeries Γ R).leadingCoeff = 1 := by
simp [leadingCoeff_eq]
@[simp]
protected lemma map_one [MonoidWithZero R] [MonoidWithZero S] (f : R →*₀ S) :
(1 : HahnSeries Γ R).map f = (1 : HahnSeries Γ S) := by
ext g
by_cases h : g = 0 <;> simp [h]
end HahnSeries
/-- We introduce a type alias for `HahnSeries` in order to work with scalar multiplication by
series. If we wrote a `SMul (HahnSeries Γ R) (HahnSeries Γ V)` instance, then when
`V = HahnSeries Γ R`, we would have two different actions of `HahnSeries Γ R` on `HahnSeries Γ V`.
See `Mathlib.Algebra.Polynomial.Module` for more discussion on this problem. -/
@[nolint unusedArguments]
def HahnModule (Γ R V : Type*) [PartialOrder Γ] [Zero V] [SMul R V] :=
HahnSeries Γ V
namespace HahnModule
section
variable [PartialOrder Γ] [Zero V] [SMul R V]
/-- The casting function to the type synonym. -/
def of (R : Type*) [SMul R V] : HahnSeries Γ V ≃ HahnModule Γ R V :=
Equiv.refl _
/-- Recursion principle to reduce a result about the synonym to the original type. -/
@[elab_as_elim]
def rec {motive : HahnModule Γ R V → Sort*} (h : ∀ x : HahnSeries Γ V, motive (of R x)) :
∀ x, motive x :=
fun x => h <| (of R).symm x
@[ext]
theorem ext (x y : HahnModule Γ R V) (h : ((of R).symm x).coeff = ((of R).symm y).coeff) : x = y :=
(of R).symm.injective <| HahnSeries.coeff_inj.1 h
end
section SMul
variable [PartialOrder Γ] [AddCommMonoid V] [SMul R V]
instance instAddCommMonoid : AddCommMonoid (HahnModule Γ R V) :=
inferInstanceAs <| AddCommMonoid (HahnSeries Γ V)
instance instBaseSMul {V} [Monoid R] [AddMonoid V] [DistribMulAction R V] :
SMul R (HahnModule Γ R V) :=
inferInstanceAs <| SMul R (HahnSeries Γ V)
@[simp] theorem of_zero : of R (0 : HahnSeries Γ V) = 0 := rfl
@[simp] theorem of_add (x y : HahnSeries Γ V) : of R (x + y) = of R x + of R y := rfl
@[simp] theorem of_symm_zero : (of R).symm (0 : HahnModule Γ R V) = 0 := rfl
@[simp] theorem of_symm_add (x y : HahnModule Γ R V) :
(of R).symm (x + y) = (of R).symm x + (of R).symm y := rfl
variable [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ']
instance instSMul [Zero R] : SMul (HahnSeries Γ R) (HahnModule Γ' R V) where
smul x y := (of R) {
coeff := fun a =>
∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd
isPWO_support' :=
haveI h :
{ a : Γ' |
(∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd) ≠ 0 } ⊆
{ a : Γ' | (VAddAntidiagonal x.isPWO_support
((of R).symm y).isPWO_support a).Nonempty } := by
intro a ha
contrapose! ha
simp [not_nonempty_iff_eq_empty.1 ha]
isPWO_support_vaddAntidiagonal.mono h }
theorem coeff_smul [Zero R] (x : HahnSeries Γ R) (y : HahnModule Γ' R V) (a : Γ') :
((of R).symm <| x • y).coeff a =
∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd :=
rfl
@[deprecated (since := "2025-01-31")] alias smul_coeff := coeff_smul
end SMul
section SMulZeroClass
variable [PartialOrder Γ] [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ']
[AddCommMonoid V]
instance instBaseSMulZeroClass [SMulZeroClass R V] :
SMulZeroClass R (HahnModule Γ R V) :=
inferInstanceAs <| SMulZeroClass R (HahnSeries Γ V)
@[simp] theorem of_smul [SMulZeroClass R V] (r : R) (x : HahnSeries Γ V) :
(of R) (r • x) = r • (of R) x := rfl
@[simp] theorem of_symm_smul [SMulZeroClass R V] (r : R) (x : HahnModule Γ R V) :
(of R).symm (r • x) = r • (of R).symm x := rfl
variable [Zero R]
instance instSMulZeroClass [SMulZeroClass R V] :
SMulZeroClass (HahnSeries Γ R) (HahnModule Γ' R V) where
smul_zero x := by
ext
simp [coeff_smul]
theorem coeff_smul_right [SMulZeroClass R V] {x : HahnSeries Γ R} {y : HahnModule Γ' R V} {a : Γ'}
{s : Set Γ'} (hs : s.IsPWO) (hys : ((of R).symm y).support ⊆ s) :
((of R).symm <| x • y).coeff a =
∑ ij ∈ VAddAntidiagonal x.isPWO_support hs a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd := by
classical
rw [coeff_smul]
apply sum_subset_zero_on_sdiff (vaddAntidiagonal_mono_right hys) _ fun _ _ => rfl
intro b hb
simp only [not_and, mem_sdiff, mem_vaddAntidiagonal, HahnSeries.mem_support, not_imp_not] at hb
rw [hb.2 hb.1.1 hb.1.2.2, smul_zero]
@[deprecated (since := "2025-01-31")] alias smul_coeff_right := coeff_smul_right
theorem coeff_smul_left [SMulWithZero R V] {x : HahnSeries Γ R}
{y : HahnModule Γ' R V} {a : Γ'} {s : Set Γ}
(hs : s.IsPWO) (hxs : x.support ⊆ s) :
((of R).symm <| x • y).coeff a =
∑ ij ∈ VAddAntidiagonal hs ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd := by
classical
rw [coeff_smul]
apply sum_subset_zero_on_sdiff (vaddAntidiagonal_mono_left hxs) _ fun _ _ => rfl
intro b hb
simp only [not_and', mem_sdiff, mem_vaddAntidiagonal, HahnSeries.mem_support, not_ne_iff] at hb
rw [hb.2 ⟨hb.1.2.1, hb.1.2.2⟩, zero_smul]
@[deprecated (since := "2025-01-31")] alias smul_coeff_left := coeff_smul_left
end SMulZeroClass
section DistribSMul
variable [PartialOrder Γ] [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [AddCommMonoid V]
theorem smul_add [Zero R] [DistribSMul R V] (x : HahnSeries Γ R) (y z : HahnModule Γ' R V) :
x • (y + z) = x • y + x • z := by
ext k
have hwf := ((of R).symm y).isPWO_support.union ((of R).symm z).isPWO_support
rw [coeff_smul_right hwf, of_symm_add]
· simp_all only [HahnSeries.coeff_add', Pi.add_apply, smul_add, of_symm_add]
rw [coeff_smul_right hwf Set.subset_union_right,
coeff_smul_right hwf Set.subset_union_left]
simp_all [sum_add_distrib]
· intro b
simp_all only [Set.isPWO_union, HahnSeries.isPWO_support, and_self, of_symm_add,
HahnSeries.coeff_add', Pi.add_apply, ne_eq, Set.mem_union, HahnSeries.mem_support]
contrapose!
intro h
rw [h.1, h.2, add_zero]
instance instDistribSMul [MonoidWithZero R] [DistribSMul R V] : DistribSMul (HahnSeries Γ R)
(HahnModule Γ' R V) where
smul_add := smul_add
theorem add_smul [AddCommMonoid R] [SMulWithZero R V] {x y : HahnSeries Γ R}
{z : HahnModule Γ' R V} (h : ∀ (r s : R) (u : V), (r + s) • u = r • u + s • u) :
(x + y) • z = x • z + y • z := by
ext a
have hwf := x.isPWO_support.union y.isPWO_support
rw [coeff_smul_left hwf, HahnSeries.coeff_add', of_symm_add]
· simp_all only [Pi.add_apply, HahnSeries.coeff_add']
rw [coeff_smul_left hwf Set.subset_union_right,
coeff_smul_left hwf Set.subset_union_left]
simp only [HahnSeries.coeff_add, h, sum_add_distrib]
· intro b
simp_all only [Set.isPWO_union, HahnSeries.isPWO_support, and_self, HahnSeries.mem_support,
HahnSeries.coeff_add, ne_eq, Set.mem_union, Set.mem_setOf_eq, mem_support]
contrapose!
intro h
rw [h.1, h.2, add_zero]
theorem coeff_single_smul_vadd [MulZeroClass R] [SMulWithZero R V] {r : R} {x : HahnModule Γ' R V}
{a : Γ'} {b : Γ} :
((of R).symm (HahnSeries.single b r • x)).coeff (b +ᵥ a) = r • ((of R).symm x).coeff a := by
by_cases hr : r = 0
· simp_all only [map_zero, zero_smul, coeff_smul, HahnSeries.support_zero, HahnSeries.coeff_zero,
sum_const_zero]
simp only [hr, coeff_smul, coeff_smul, HahnSeries.support_single_of_ne, ne_eq, not_false_iff,
smul_eq_mul]
by_cases hx : ((of R).symm x).coeff a = 0
· simp only [hx, smul_zero]
rw [sum_congr _ fun _ _ => rfl, sum_empty]
ext ⟨a1, a2⟩
simp only [not_mem_empty, not_and, Set.mem_singleton_iff, Classical.not_not,
mem_vaddAntidiagonal, Set.mem_setOf_eq, iff_false]
rintro rfl h2 h1
rw [IsCancelVAdd.left_cancel a1 a2 a h1] at h2
exact h2 hx
trans ∑ ij ∈ {(b, a)},
(HahnSeries.single b r).coeff ij.fst • ((of R).symm x).coeff ij.snd
· apply sum_congr _ fun _ _ => rfl
ext ⟨a1, a2⟩
simp only [Set.mem_singleton_iff, Prod.mk_inj, mem_vaddAntidiagonal, mem_singleton,
Set.mem_setOf_eq]
constructor
· rintro ⟨rfl, _, h1⟩
exact ⟨rfl, IsCancelVAdd.left_cancel a1 a2 a h1⟩
· rintro ⟨rfl, rfl⟩
exact ⟨rfl, by exact hx, rfl⟩
· simp
@[deprecated (since := "2025-01-31")] alias single_smul_coeff_add := coeff_single_smul_vadd
theorem coeff_single_zero_smul {Γ} [AddCommMonoid Γ] [PartialOrder Γ] [AddAction Γ Γ']
[IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {r : R}
{x : HahnModule Γ' R V} {a : Γ'} :
((of R).symm ((HahnSeries.single 0 r : HahnSeries Γ R) • x)).coeff a =
r • ((of R).symm x).coeff a := by
nth_rw 1 [← zero_vadd Γ a]
exact coeff_single_smul_vadd
@[deprecated (since := "2025-01-31")] alias single_zero_smul_coeff := coeff_single_zero_smul
@[simp]
theorem single_zero_smul_eq_smul (Γ) [AddCommMonoid Γ] [PartialOrder Γ] [AddAction Γ Γ']
[IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {r : R}
{x : HahnModule Γ' R V} :
(HahnSeries.single (0 : Γ) r) • x = r • x := by
ext
exact coeff_single_zero_smul
@[simp]
theorem zero_smul' [Zero R] [SMulWithZero R V] {x : HahnModule Γ' R V} :
(0 : HahnSeries Γ R) • x = 0 := by
ext
simp [coeff_smul]
@[simp]
theorem one_smul' {Γ} [AddCommMonoid Γ] [PartialOrder Γ] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ']
[MonoidWithZero R] [MulActionWithZero R V] {x : HahnModule Γ' R V} :
(1 : HahnSeries Γ R) • x = x := by
ext g
exact coeff_single_zero_smul.trans (one_smul R (x.coeff g))
theorem support_smul_subset_vadd_support' [MulZeroClass R] [SMulWithZero R V] {x : HahnSeries Γ R}
{y : HahnModule Γ' R V} :
((of R).symm (x • y)).support ⊆ x.support +ᵥ ((of R).symm y).support := by
apply Set.Subset.trans (fun x hx => _) support_vaddAntidiagonal_subset_vadd
· exact x.isPWO_support
· exact y.isPWO_support
intro x hx
contrapose! hx
simp only [Set.mem_setOf_eq, not_nonempty_iff_eq_empty] at hx
simp [hx, coeff_smul]
theorem support_smul_subset_vadd_support [MulZeroClass R] [SMulWithZero R V] {x : HahnSeries Γ R}
{y : HahnModule Γ' R V} :
((of R).symm (x • y)).support ⊆ x.support +ᵥ ((of R).symm y).support := by
exact support_smul_subset_vadd_support'
theorem orderTop_vAdd_le_orderTop_smul {Γ Γ'} [LinearOrder Γ] [LinearOrder Γ'] [VAdd Γ Γ']
[IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {x : HahnSeries Γ R}
[VAdd (WithTop Γ) (WithTop Γ')] {y : HahnModule Γ' R V}
(h : ∀ (γ : Γ) (γ' : Γ'), γ +ᵥ γ' = (γ : WithTop Γ) +ᵥ (γ' : WithTop Γ')) :
x.orderTop +ᵥ ((of R).symm y).orderTop ≤ ((of R).symm (x • y)).orderTop := by
by_cases hx : x = 0; · simp_all
by_cases hy : y = 0; · simp_all
have hhy : ((of R).symm y) ≠ 0 := hy
rw [HahnSeries.orderTop_of_ne hx, HahnSeries.orderTop_of_ne hhy, ← h,
← Set.IsWF.min_vadd]
by_cases hxy : (of R).symm (x • y) = 0
· rw [hxy, HahnSeries.orderTop_zero]
exact OrderTop.le_top (α := WithTop Γ') _
· rw [HahnSeries.orderTop_of_ne hxy, WithTop.coe_le_coe]
exact Set.IsWF.min_le_min_of_subset support_smul_subset_vadd_support
theorem coeff_smul_order_add_order {Γ}
[AddCommMonoid Γ] [LinearOrder Γ] [IsOrderedCancelAddMonoid Γ] [Zero R]
[SMulWithZero R V] (x : HahnSeries Γ R) (y : HahnModule Γ R V) :
((of R).symm (x • y)).coeff (x.order + ((of R).symm y).order) =
x.leadingCoeff • ((of R).symm y).leadingCoeff := by
by_cases hx : x = (0 : HahnSeries Γ R); · simp [HahnSeries.coeff_zero, hx]
by_cases hy : (of R).symm y = 0; · simp [hy, coeff_smul]
rw [HahnSeries.order_of_ne hx, HahnSeries.order_of_ne hy, coeff_smul,
HahnSeries.leadingCoeff_of_ne hx, HahnSeries.leadingCoeff_of_ne hy, ← vadd_eq_add,
Finset.vaddAntidiagonal_min_vadd_min, Finset.sum_singleton]
@[deprecated (since := "2025-01-31")] alias smul_coeff_order_add_order := coeff_smul_order_add_order
end DistribSMul
end HahnModule
variable [AddCommMonoid Γ] [PartialOrder Γ] [IsOrderedCancelAddMonoid Γ]
namespace HahnSeries
instance [NonUnitalNonAssocSemiring R] : Mul (HahnSeries Γ R) where
mul x y := (HahnModule.of R).symm (x • HahnModule.of R y)
theorem of_symm_smul_of_eq_mul [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} :
(HahnModule.of R).symm (x • HahnModule.of R y) = x * y := rfl
theorem coeff_mul [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} {a : Γ} :
(x * y).coeff a =
∑ ij ∈ addAntidiagonal x.isPWO_support y.isPWO_support a, x.coeff ij.fst * y.coeff ij.snd :=
rfl
@[deprecated (since := "2025-01-31")] alias mul_coeff := coeff_mul
protected lemma map_mul [NonUnitalNonAssocSemiring R] [NonUnitalNonAssocSemiring S] (f : R →ₙ+* S)
{x y : HahnSeries Γ R} : (x * y).map f = (x.map f : HahnSeries Γ S) * (y.map f) := by
ext
simp only [map_coeff, coeff_mul, ZeroHom.coe_coe, map_sum, map_mul]
refine Eq.symm (sum_subset (fun gh hgh => ?_) (fun gh hgh hz => ?_))
· simp_all only [mem_addAntidiagonal, mem_support, map_coeff, ZeroHom.coe_coe, ne_eq, and_true]
exact ⟨fun h => hgh.1 (map_zero f ▸ congrArg f h), fun h => hgh.2.1 (map_zero f ▸ congrArg f h)⟩
· simp_all only [mem_addAntidiagonal, mem_support, ne_eq, map_coeff, ZeroHom.coe_coe, and_true,
not_and, not_not]
by_cases h : f (x.coeff gh.1) = 0
· exact mul_eq_zero_of_left h (f (y.coeff gh.2))
· exact mul_eq_zero_of_right (f (x.coeff gh.1)) (hz h)
theorem coeff_mul_left' [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} {a : Γ} {s : Set Γ}
(hs : s.IsPWO) (hxs : x.support ⊆ s) :
(x * y).coeff a =
∑ ij ∈ addAntidiagonal hs y.isPWO_support a, x.coeff ij.fst * y.coeff ij.snd :=
HahnModule.coeff_smul_left hs hxs
@[deprecated (since := "2025-01-31")] alias mul_coeff_left' := coeff_mul_left'
theorem coeff_mul_right' [NonUnitalNonAssocSemiring R] {x y : HahnSeries Γ R} {a : Γ} {s : Set Γ}
(hs : s.IsPWO) (hys : y.support ⊆ s) :
(x * y).coeff a =
∑ ij ∈ addAntidiagonal x.isPWO_support hs a, x.coeff ij.fst * y.coeff ij.snd :=
HahnModule.coeff_smul_right hs hys
@[deprecated (since := "2025-01-31")] alias mul_coeff_right' := coeff_mul_right'
instance [NonUnitalNonAssocSemiring R] : Distrib (HahnSeries Γ R) :=
{ inferInstanceAs (Mul (HahnSeries Γ R)),
inferInstanceAs (Add (HahnSeries Γ R)) with
left_distrib := fun x y z => by
simp only [← of_symm_smul_of_eq_mul]
exact HahnModule.smul_add x y z
right_distrib := fun x y z => by
simp only [← of_symm_smul_of_eq_mul]
refine HahnModule.add_smul ?_
simp only [smul_eq_mul]
exact add_mul }
theorem coeff_single_mul_add [NonUnitalNonAssocSemiring R] {r : R} {x : HahnSeries Γ R} {a : Γ}
{b : Γ} : (single b r * x).coeff (a + b) = r * x.coeff a := by
rw [← of_symm_smul_of_eq_mul, add_comm, ← vadd_eq_add]
exact HahnModule.coeff_single_smul_vadd
@[deprecated (since := "2025-01-31")] alias single_mul_coeff_add := coeff_single_mul_add
|
theorem coeff_mul_single_add [NonUnitalNonAssocSemiring R] {r : R} {x : HahnSeries Γ R} {a : Γ}
{b : Γ} : (x * single b r).coeff (a + b) = x.coeff a * r := by
by_cases hr : r = 0
· simp [hr, coeff_mul]
simp only [hr, coeff_smul, coeff_mul, support_single_of_ne, Ne, not_false_iff, smul_eq_mul]
by_cases hx : x.coeff a = 0
· simp only [hx, zero_mul]
rw [sum_congr _ fun _ _ => rfl, sum_empty]
ext ⟨a1, a2⟩
simp only [not_mem_empty, not_and, Set.mem_singleton_iff, Classical.not_not,
| Mathlib/RingTheory/HahnSeries/Multiplication.lean | 444 | 454 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by
subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm)
(h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) :
|exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by
subst er
refine exp_approx_succ _ en _ _ ?_ h
field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega]
theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) :
|exp x - a| ≤ b := by simpa using h
theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) :
Real.exp x < 1 / (1 - x) := by
have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc
0 < x ^ 3 := by positivity
_ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring
calc
exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three
_ ≤ 1 + x + x ^ 2 := by
-- Porting note: was `norm_num [Finset.sum] <;> nlinarith`
-- This proof should be restored after the norm_num plugin for big operators is ported.
-- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.)
rw [show 3 = 1 + 1 + 1 from rfl]
repeat rw [Finset.sum_range_succ]
norm_num [Nat.factorial]
nlinarith
_ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith
theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) :
Real.exp x ≤ 1 / (1 - x) := by
rcases eq_or_lt_of_le h1 with (rfl | h1)
· simp
· exact (exp_bound_div_one_sub_of_interval' h1 h2).le
theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by
obtain hx | hx := hx.symm.lt_or_lt
· exact add_one_lt_exp_of_pos hx
obtain h' | h' := le_or_lt 1 (-x)
· linarith [x.exp_pos]
have hx' : 0 < x + 1 := by linarith
simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx']
using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h'
theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by
obtain rfl | hx := eq_or_ne x 0
· simp
· exact (add_one_lt_exp hx).le
lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) :=
(sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx
lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) :=
(sub_eq_neg_add _ _).trans_le <| add_one_le_exp _
theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rwa [Nat.cast_zero] at ht'
calc
(1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by
gcongr
· exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg
· exact one_sub_le_exp_neg _
_ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity
lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by
rw [le_inv_mul_iff₀ hc]
calc c * x
_ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one
_ ≤ _ := Real.add_one_le_exp (c * x)
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/
@[positivity Real.exp _]
def evalExp : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.exp $a) =>
assertInstancesCommute
pure (.positive q(Real.exp_pos $a))
| _, _, _ => throwError "not Real.exp"
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by
rw [← ofReal_exp]
exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _))
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal
end Complex
| Mathlib/Data/Complex/Exponential.lean | 1,118 | 1,120 | |
/-
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 | 817 | 819 | |
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Derivation.Killing
import Mathlib.Algebra.Lie.Killing
import Mathlib.Algebra.Lie.Sl2
import Mathlib.Algebra.Lie.Weights.Chain
import Mathlib.LinearAlgebra.Eigenspace.Semisimple
import Mathlib.LinearAlgebra.JordanChevalley
/-!
# Roots of Lie algebras with non-degenerate Killing forms
The file contains definitions and results about roots of Lie algebras with non-degenerate Killing
forms.
## Main definitions
* `LieAlgebra.IsKilling.ker_restrict_eq_bot_of_isCartanSubalgebra`: if the Killing form of
a Lie algebra is non-singular, it remains non-singular when restricted to a Cartan subalgebra.
* `LieAlgebra.IsKilling.instIsLieAbelianOfIsCartanSubalgebra`: if the Killing form of a Lie
algebra is non-singular, then its Cartan subalgebras are Abelian.
* `LieAlgebra.IsKilling.isSemisimple_ad_of_mem_isCartanSubalgebra`: over a perfect field, if a Lie
algebra has non-degenerate Killing form, Cartan subalgebras contain only semisimple elements.
* `LieAlgebra.IsKilling.span_weight_eq_top`: given a splitting Cartan subalgebra `H` of a
finite-dimensional Lie algebra with non-singular Killing form, the corresponding roots span the
dual space of `H`.
* `LieAlgebra.IsKilling.coroot`: the coroot corresponding to a root.
* `LieAlgebra.IsKilling.isCompl_ker_weight_span_coroot`: given a root `α` with respect to a Cartan
subalgebra `H`, we have a natural decomposition of `H` as the kernel of `α` and the span of the
coroot corresponding to `α`.
* `LieAlgebra.IsKilling.finrank_rootSpace_eq_one`: root spaces are one-dimensional.
-/
variable (R K L : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [Field K] [LieAlgebra K L]
namespace LieAlgebra
lemma restrict_killingForm (H : LieSubalgebra R L) :
(killingForm R L).restrict H = LieModule.traceForm R H L :=
rfl
namespace IsKilling
variable [IsKilling R L]
/-- If the Killing form of a Lie algebra is non-singular, it remains non-singular when restricted
to a Cartan subalgebra. -/
lemma ker_restrict_eq_bot_of_isCartanSubalgebra
[IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
LinearMap.ker ((killingForm R L).restrict H) = ⊥ := by
have h : Codisjoint (rootSpace H 0) (LieModule.posFittingComp R H L) :=
(LieModule.isCompl_genWeightSpace_zero_posFittingComp R H L).codisjoint
replace h : Codisjoint (H : Submodule R L) (LieModule.posFittingComp R H L : Submodule R L) := by
rwa [codisjoint_iff, ← LieSubmodule.toSubmodule_inj, LieSubmodule.sup_toSubmodule,
LieSubmodule.top_toSubmodule, rootSpace_zero_eq R L H, LieSubalgebra.coe_toLieSubmodule,
← codisjoint_iff] at h
suffices this : ∀ m₀ ∈ H, ∀ m₁ ∈ LieModule.posFittingComp R H L, killingForm R L m₀ m₁ = 0 by
simp [LinearMap.BilinForm.ker_restrict_eq_of_codisjoint h this]
intro m₀ h₀ m₁ h₁
exact killingForm_eq_zero_of_mem_zeroRoot_mem_posFitting R L H (le_zeroRootSubalgebra R L H h₀) h₁
@[simp] lemma ker_traceForm_eq_bot_of_isCartanSubalgebra
[IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
LinearMap.ker (LieModule.traceForm R H L) = ⊥ :=
ker_restrict_eq_bot_of_isCartanSubalgebra R L H
lemma traceForm_cartan_nondegenerate
[IsNoetherian R L] [IsArtinian R L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
(LieModule.traceForm R H L).Nondegenerate := by
simp [LinearMap.BilinForm.nondegenerate_iff_ker_eq_bot]
variable [Module.Free R L] [Module.Finite R L]
instance instIsLieAbelianOfIsCartanSubalgebra
[IsDomain R] [IsPrincipalIdealRing R] [IsArtinian R L]
(H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
IsLieAbelian H :=
LieModule.isLieAbelian_of_ker_traceForm_eq_bot R H L <|
ker_restrict_eq_bot_of_isCartanSubalgebra R L H
end IsKilling
section Field
open Module LieModule Set
open Submodule (span subset_span)
variable [FiniteDimensional K L] (H : LieSubalgebra K L) [H.IsCartanSubalgebra]
section
variable [IsTriangularizable K H L]
/-- For any `α` and `β`, the corresponding root spaces are orthogonal with respect to the Killing
form, provided `α + β ≠ 0`. -/
lemma killingForm_apply_eq_zero_of_mem_rootSpace_of_add_ne_zero {α β : H → K} {x y : L}
(hx : x ∈ rootSpace H α) (hy : y ∈ rootSpace H β) (hαβ : α + β ≠ 0) :
killingForm K L x y = 0 := by
/- If `ad R L z` is semisimple for all `z ∈ H` then writing `⟪x, y⟫ = killingForm K L x y`, there
is a slick proof of this lemma that requires only invariance of the Killing form as follows.
For any `z ∈ H`, we have:
`α z • ⟪x, y⟫ = ⟪α z • x, y⟫ = ⟪⁅z, x⁆, y⟫ = - ⟪x, ⁅z, y⁆⟫ = - ⟪x, β z • y⟫ = - β z • ⟪x, y⟫`.
Since this is true for any `z`, we thus have: `(α + β) • ⟪x, y⟫ = 0`, and hence the result.
However the semisimplicity of `ad R L z` is (a) non-trivial and (b) requires the assumption
that `K` is a perfect field and `L` has non-degenerate Killing form. -/
let σ : (H → K) → (H → K) := fun γ ↦ α + (β + γ)
have hσ : ∀ γ, σ γ ≠ γ := fun γ ↦ by simpa only [σ, ← add_assoc] using add_ne_right.mpr hαβ
let f : Module.End K L := (ad K L x) ∘ₗ (ad K L y)
have hf : ∀ γ, MapsTo f (rootSpace H γ) (rootSpace H (σ γ)) := fun γ ↦
(mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α (β + γ) hx).comp <|
mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L β γ hy
classical
have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top
(LieSubmodule.iSupIndep_toSubmodule.mpr <| iSupIndep_genWeightSpace K H L)
(LieSubmodule.iSup_toSubmodule_eq_top.mpr <| iSup_genWeightSpace_eq_top K H L)
exact LinearMap.trace_eq_zero_of_mapsTo_ne hds σ hσ hf
/-- Elements of the `α` root space which are Killing-orthogonal to the `-α` root space are
Killing-orthogonal to all of `L`. -/
lemma mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg
{α : H → K} {x : L} (hx : x ∈ rootSpace H α)
(hx' : ∀ y ∈ rootSpace H (-α), killingForm K L x y = 0) :
x ∈ LinearMap.ker (killingForm K L) := by
rw [LinearMap.mem_ker]
ext y
have hy : y ∈ ⨆ β, rootSpace H β := by simp [iSup_genWeightSpace_eq_top K H L]
induction hy using LieSubmodule.iSup_induction' with
| mem β y hy =>
by_cases hαβ : α + β = 0
· exact hx' _ (add_eq_zero_iff_neg_eq.mp hαβ ▸ hy)
· exact killingForm_apply_eq_zero_of_mem_rootSpace_of_add_ne_zero K L H hx hy hαβ
| zero => simp
| add => simp_all
end
namespace IsKilling
variable [IsKilling K L]
/-- If a Lie algebra `L` has non-degenerate Killing form, the only element of a Cartan subalgebra
whose adjoint action on `L` is nilpotent, is the zero element.
Over a perfect field a much stronger result is true, see
`LieAlgebra.IsKilling.isSemisimple_ad_of_mem_isCartanSubalgebra`. -/
lemma eq_zero_of_isNilpotent_ad_of_mem_isCartanSubalgebra {x : L} (hx : x ∈ H)
(hx' : _root_.IsNilpotent (ad K L x)) : x = 0 := by
suffices ⟨x, hx⟩ ∈ LinearMap.ker (traceForm K H L) by
simp at this
exact (AddSubmonoid.mk_eq_zero H.toAddSubmonoid).mp this
simp only [LinearMap.mem_ker]
ext y
have comm : Commute (toEnd K H L ⟨x, hx⟩) (toEnd K H L y) := by
rw [commute_iff_lie_eq, ← LieHom.map_lie, trivial_lie_zero, LieHom.map_zero]
rw [traceForm_apply_apply, ← Module.End.mul_eq_comp, LinearMap.zero_apply]
exact (LinearMap.isNilpotent_trace_of_isNilpotent (comm.isNilpotent_mul_left hx')).eq_zero
@[simp]
lemma corootSpace_zero_eq_bot :
corootSpace (0 : H → K) = ⊥ := by
refine eq_bot_iff.mpr fun x hx ↦ ?_
suffices {x | ∃ y ∈ H, ∃ z ∈ H, ⁅y, z⁆ = x} = {0} by simpa [mem_corootSpace, this] using hx
refine eq_singleton_iff_unique_mem.mpr ⟨⟨0, H.zero_mem, 0, H.zero_mem, zero_lie 0⟩, ?_⟩
rintro - ⟨y, hy, z, hz, rfl⟩
suffices ⁅(⟨y, hy⟩ : H), (⟨z, hz⟩ : H)⁆ = 0 by
simpa only [Subtype.ext_iff, LieSubalgebra.coe_bracket, ZeroMemClass.coe_zero] using this
simp
variable {K L} in
/-- The restriction of the Killing form to a Cartan subalgebra, as a linear equivalence to the
dual. -/
@[simps! apply_apply]
noncomputable def cartanEquivDual :
H ≃ₗ[K] Module.Dual K H :=
(traceForm K H L).toDual <| traceForm_cartan_nondegenerate K L H
variable {K L H}
/-- The coroot corresponding to a root. -/
noncomputable def coroot (α : Weight K H L) : H :=
2 • (α <| (cartanEquivDual H).symm α)⁻¹ • (cartanEquivDual H).symm α
lemma traceForm_coroot (α : Weight K H L) (x : H) :
traceForm K H L (coroot α) x = 2 • (α <| (cartanEquivDual H).symm α)⁻¹ • α x := by
have : cartanEquivDual H ((cartanEquivDual H).symm α) x = α x := by
rw [LinearEquiv.apply_symm_apply, Weight.toLinear_apply]
rw [coroot, map_nsmul, map_smul, LinearMap.smul_apply, LinearMap.smul_apply]
congr 2
variable [IsTriangularizable K H L]
lemma lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg_aux
{α : Weight K H L} {e f : L} (heα : e ∈ rootSpace H α) (hfα : f ∈ rootSpace H (-α))
(aux : ∀ (h : H), ⁅h, e⁆ = α h • e) :
⁅e, f⁆ = killingForm K L e f • (cartanEquivDual H).symm α := by
set α' := (cartanEquivDual H).symm α
rw [← sub_eq_zero, ← Submodule.mem_bot (R := K), ← ker_killingForm_eq_bot]
apply mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg (α := (0 : H → K))
· simp only [rootSpace_zero_eq, LieSubalgebra.mem_toLieSubmodule]
refine sub_mem ?_ (H.smul_mem _ α'.property)
simpa using mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α (-α) heα hfα
· intro z hz
replace hz : z ∈ H := by simpa using hz
have he : ⁅z, e⁆ = α ⟨z, hz⟩ • e := aux ⟨z, hz⟩
have hαz : killingForm K L α' (⟨z, hz⟩ : H) = α ⟨z, hz⟩ :=
LinearMap.BilinForm.apply_toDual_symm_apply (hB := traceForm_cartan_nondegenerate K L H) _ _
simp [traceForm_comm K L L ⁅e, f⁆, ← traceForm_apply_lie_apply, he, mul_comm _ (α ⟨z, hz⟩), hαz]
/-- This is Proposition 4.18 from [carter2005] except that we use
`LieModule.exists_forall_lie_eq_smul` instead of Lie's theorem (and so avoid
assuming `K` has characteristic zero). -/
lemma cartanEquivDual_symm_apply_mem_corootSpace (α : Weight K H L) :
(cartanEquivDual H).symm α ∈ corootSpace α := by
obtain ⟨e : L, he₀ : e ≠ 0, he : ∀ x, ⁅x, e⁆ = α x • e⟩ := exists_forall_lie_eq_smul K H L α
have heα : e ∈ rootSpace H α := (mem_genWeightSpace L α e).mpr fun x ↦ ⟨1, by simp [← he x]⟩
obtain ⟨f, hfα, hf⟩ : ∃ f ∈ rootSpace H (-α), killingForm K L e f ≠ 0 := by
contrapose! he₀
simpa using mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg K L H heα he₀
suffices ⁅e, f⁆ = killingForm K L e f • ((cartanEquivDual H).symm α : L) from
(mem_corootSpace α).mpr <| Submodule.subset_span ⟨(killingForm K L e f)⁻¹ • e,
Submodule.smul_mem _ _ heα, f, hfα, by simpa [inv_smul_eq_iff₀ hf]⟩
exact lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg_aux heα hfα he
/-- Given a splitting Cartan subalgebra `H` of a finite-dimensional Lie algebra with non-singular
Killing form, the corresponding roots span the dual space of `H`. -/
@[simp]
lemma span_weight_eq_top :
span K (range (Weight.toLinear K H L)) = ⊤ := by
refine eq_top_iff.mpr (le_trans ?_ (LieModule.range_traceForm_le_span_weight K H L))
rw [← traceForm_flip K H L, ← LinearMap.dualAnnihilator_ker_eq_range_flip,
ker_traceForm_eq_bot_of_isCartanSubalgebra, Submodule.dualAnnihilator_bot]
variable (K L H) in
@[simp]
lemma span_weight_isNonZero_eq_top :
span K ({α : Weight K H L | α.IsNonZero}.image (Weight.toLinear K H L)) = ⊤ := by
rw [← span_weight_eq_top]
refine le_antisymm (Submodule.span_mono <| by simp) ?_
suffices range (Weight.toLinear K H L) ⊆
insert 0 ({α : Weight K H L | α.IsNonZero}.image (Weight.toLinear K H L)) by
simpa only [Submodule.span_insert_zero] using Submodule.span_mono this
rintro - ⟨α, rfl⟩
simp only [mem_insert_iff, Weight.coe_toLinear_eq_zero_iff, mem_image, mem_setOf_eq]
tauto
@[simp]
lemma iInf_ker_weight_eq_bot :
⨅ α : Weight K H L, α.ker = ⊥ := by
rw [← Subspace.dualAnnihilator_inj, Subspace.dualAnnihilator_iInf_eq,
Submodule.dualAnnihilator_bot]
simp [← LinearMap.range_dualMap_eq_dualAnnihilator_ker, ← Submodule.span_range_eq_iSup]
section PerfectField
variable [PerfectField K]
open Module.End in
lemma isSemisimple_ad_of_mem_isCartanSubalgebra {x : L} (hx : x ∈ H) :
(ad K L x).IsSemisimple := by
/- Using Jordan-Chevalley, write `ad K L x` as a sum of its semisimple and nilpotent parts. -/
obtain ⟨N, -, S, hS₀, hN, hS, hSN⟩ := (ad K L x).exists_isNilpotent_isSemisimple
replace hS₀ : Commute (ad K L x) S := Algebra.commute_of_mem_adjoin_self hS₀
set x' : H := ⟨x, hx⟩
rw [eq_sub_of_add_eq hSN.symm] at hN
/- Note that the semisimple part `S` is just a scalar action on each root space. -/
have aux {α : H → K} {y : L} (hy : y ∈ rootSpace H α) : S y = α x' • y := by
replace hy : y ∈ (ad K L x).maxGenEigenspace (α x') :=
(genWeightSpace_le_genWeightSpaceOf L x' α) hy
rw [maxGenEigenspace_eq] at hy
set k := maxGenEigenspaceIndex (ad K L x) (α x')
rw [apply_eq_of_mem_of_comm_of_isFinitelySemisimple_of_isNil hy hS₀ hS.isFinitelySemisimple hN]
/- So `S` obeys the derivation axiom if we restrict to root spaces. -/
have h_der (y z : L) (α β : H → K) (hy : y ∈ rootSpace H α) (hz : z ∈ rootSpace H β) :
S ⁅y, z⁆ = ⁅S y, z⁆ + ⁅y, S z⁆ := by
have hyz : ⁅y, z⁆ ∈ rootSpace H (α + β) :=
mapsTo_toEnd_genWeightSpace_add_of_mem_rootSpace K L H L α β hy hz
rw [aux hy, aux hz, aux hyz, smul_lie, lie_smul, ← add_smul, ← Pi.add_apply]
/- Thus `S` is a derivation since root spaces span. -/
replace h_der (y z : L) : S ⁅y, z⁆ = ⁅S y, z⁆ + ⁅y, S z⁆ := by
have hy : y ∈ ⨆ α : H → K, rootSpace H α := by simp [iSup_genWeightSpace_eq_top]
have hz : z ∈ ⨆ α : H → K, rootSpace H α := by simp [iSup_genWeightSpace_eq_top]
induction hy using LieSubmodule.iSup_induction' with
| mem α y hy =>
induction hz using LieSubmodule.iSup_induction' with
| mem β z hz => exact h_der y z α β hy hz
| zero => simp
| add _ _ _ _ h h' => simp only [lie_add, map_add, h, h']; abel
| zero => simp
| add _ _ _ _ h h' => simp only [add_lie, map_add, h, h']; abel
/- An equivalent form of the derivation axiom used in `LieDerivation`. -/
replace h_der : ∀ y z : L, S ⁅y, z⁆ = ⁅y, S z⁆ - ⁅z, S y⁆ := by
simp_rw [← lie_skew (S _) _, add_comm, ← sub_eq_add_neg] at h_der; assumption
/- Bundle `S` as a `LieDerivation`. -/
let S' : LieDerivation K L L := ⟨S, h_der⟩
/- Since `L` has non-degenerate Killing form, `S` must be inner, corresponding to some `y : L`. -/
obtain ⟨y, hy⟩ := LieDerivation.IsKilling.exists_eq_ad S'
/- `y` commutes with all elements of `H` because `S` has eigenvalue 0 on `H`, `S = ad K L y`. -/
have hy' (z : L) (hz : z ∈ H) : ⁅y, z⁆ = 0 := by
rw [← LieSubalgebra.mem_toLieSubmodule, ← rootSpace_zero_eq] at hz
simp [S', ← ad_apply (R := K), ← LieDerivation.coe_ad_apply_eq_ad_apply, hy, aux hz]
/- Thus `y` belongs to `H` since `H` is self-normalizing. -/
replace hy' : y ∈ H := by
suffices y ∈ H.normalizer by rwa [LieSubalgebra.IsCartanSubalgebra.self_normalizing] at this
exact (H.mem_normalizer_iff y).mpr fun z hz ↦ hy' z hz ▸ LieSubalgebra.zero_mem H
/- It suffices to show `x = y` since `S = ad K L y` is semisimple. -/
suffices x = y by rwa [this, ← LieDerivation.coe_ad_apply_eq_ad_apply y, hy]
rw [← sub_eq_zero]
/- This will follow if we can show that `ad K L (x - y)` is nilpotent. -/
apply eq_zero_of_isNilpotent_ad_of_mem_isCartanSubalgebra K L H (H.sub_mem hx hy')
/- Which is true because `ad K L (x - y) = N`. -/
replace hy : S = ad K L y := by rw [← LieDerivation.coe_ad_apply_eq_ad_apply y, hy]
rwa [LieHom.map_sub, hSN, hy, add_sub_cancel_right, eq_sub_of_add_eq hSN.symm]
lemma lie_eq_smul_of_mem_rootSpace {α : H → K} {x : L} (hx : x ∈ rootSpace H α) (h : H) :
⁅h, x⁆ = α h • x := by
replace hx : x ∈ (ad K L h).maxGenEigenspace (α h) :=
genWeightSpace_le_genWeightSpaceOf L h α hx
rw [(isSemisimple_ad_of_mem_isCartanSubalgebra
h.property).isFinitelySemisimple.maxGenEigenspace_eq_eigenspace,
Module.End.mem_eigenspace_iff] at hx
simpa using hx
lemma lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg
{α : Weight K H L} {e f : L} (heα : e ∈ rootSpace H α) (hfα : f ∈ rootSpace H (-α)) :
⁅e, f⁆ = killingForm K L e f • (cartanEquivDual H).symm α := by
apply lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg_aux heα hfα
exact lie_eq_smul_of_mem_rootSpace heα
lemma coe_corootSpace_eq_span_singleton' (α : Weight K H L) :
(corootSpace α).toSubmodule = K ∙ (cartanEquivDual H).symm α := by
refine le_antisymm ?_ ?_
· intro ⟨x, hx⟩ hx'
have : {⁅y, z⁆ | (y ∈ rootSpace H α) (z ∈ rootSpace H (-α))} ⊆
K ∙ ((cartanEquivDual H).symm α : L) := by
rintro - ⟨e, heα, f, hfα, rfl⟩
rw [lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg heα hfα, SetLike.mem_coe,
Submodule.mem_span_singleton]
exact ⟨killingForm K L e f, rfl⟩
simp only [LieSubmodule.mem_toSubmodule, mem_corootSpace] at hx'
replace this := Submodule.span_mono this hx'
rw [Submodule.span_span] at this
rw [Submodule.mem_span_singleton] at this ⊢
obtain ⟨t, rfl⟩ := this
use t
simp only [Subtype.ext_iff]
rw [Submodule.coe_smul_of_tower]
· simp only [Submodule.span_singleton_le_iff_mem, LieSubmodule.mem_toSubmodule]
exact cartanEquivDual_symm_apply_mem_corootSpace α
end PerfectField
section CharZero
variable [CharZero K]
/-- The contrapositive of this result is very useful, taking `x` to be the element of `H`
corresponding to a root `α` under the identification between `H` and `H^*` provided by the Killing
form. -/
lemma eq_zero_of_apply_eq_zero_of_mem_corootSpace
(x : H) (α : H → K) (hαx : α x = 0) (hx : x ∈ corootSpace α) :
x = 0 := by
rcases eq_or_ne α 0 with rfl | hα; · simpa using hx
replace hx : x ∈ ⨅ β : Weight K H L, β.ker := by
refine (Submodule.mem_iInf _).mpr fun β ↦ ?_
obtain ⟨a, b, hb, hab⟩ :=
exists_forall_mem_corootSpace_smul_add_eq_zero L α β hα β.genWeightSpace_ne_bot
simpa [hαx, hb.ne'] using hab _ hx
simpa using hx
lemma disjoint_ker_weight_corootSpace (α : Weight K H L) :
Disjoint α.ker (corootSpace α) := by
rw [disjoint_iff]
refine (Submodule.eq_bot_iff _).mpr fun x ⟨hαx, hx⟩ ↦ ?_
replace hαx : α x = 0 := by simpa using hαx
exact eq_zero_of_apply_eq_zero_of_mem_corootSpace x α hαx hx
lemma root_apply_cartanEquivDual_symm_ne_zero {α : Weight K H L} (hα : α.IsNonZero) :
α ((cartanEquivDual H).symm α) ≠ 0 := by
contrapose! hα
suffices (cartanEquivDual H).symm α ∈ α.ker ⊓ corootSpace α by
rw [(disjoint_ker_weight_corootSpace α).eq_bot] at this
simpa using this
exact Submodule.mem_inf.mp ⟨hα, cartanEquivDual_symm_apply_mem_corootSpace α⟩
lemma root_apply_coroot {α : Weight K H L} (hα : α.IsNonZero) :
α (coroot α) = 2 := by
rw [← Weight.coe_coe]
simpa [coroot] using inv_mul_cancel₀ (root_apply_cartanEquivDual_symm_ne_zero hα)
@[simp] lemma coroot_eq_zero_iff {α : Weight K H L} :
coroot α = 0 ↔ α.IsZero := by
refine ⟨fun hα ↦ ?_, fun hα ↦ ?_⟩
· by_contra contra
simpa [hα, ← α.coe_coe, map_zero] using root_apply_coroot contra
· simp [coroot, Weight.coe_toLinear_eq_zero_iff.mpr hα]
@[simp]
lemma coroot_zero [Nontrivial L] : coroot (0 : Weight K H L) = 0 := by simp [Weight.isZero_zero]
lemma coe_corootSpace_eq_span_singleton (α : Weight K H L) :
(corootSpace α).toSubmodule = K ∙ coroot α := by
if hα : α.IsZero then
simp [hα.eq, coroot_eq_zero_iff.mpr hα]
else
set α' := (cartanEquivDual H).symm α
suffices (K ∙ coroot α) = K ∙ α' by rw [coe_corootSpace_eq_span_singleton']; exact this.symm
have : IsUnit (2 * (α α')⁻¹) := by simpa using root_apply_cartanEquivDual_symm_ne_zero hα
change (K ∙ (2 • (α α')⁻¹ • α')) = _
simpa [← Nat.cast_smul_eq_nsmul K, smul_smul] using Submodule.span_singleton_smul_eq this _
@[simp]
lemma corootSpace_eq_bot_iff {α : Weight K H L} :
corootSpace α = ⊥ ↔ α.IsZero := by
simp [← LieSubmodule.toSubmodule_eq_bot, coe_corootSpace_eq_span_singleton α]
lemma isCompl_ker_weight_span_coroot (α : Weight K H L) :
IsCompl α.ker (K ∙ coroot α) := by
if hα : α.IsZero then
simpa [Weight.coe_toLinear_eq_zero_iff.mpr hα, coroot_eq_zero_iff.mpr hα, Weight.ker]
using isCompl_top_bot
else
rw [← coe_corootSpace_eq_span_singleton]
apply Module.Dual.isCompl_ker_of_disjoint_of_ne_bot (by aesop)
(disjoint_ker_weight_corootSpace α)
replace hα : corootSpace α ≠ ⊥ := by simpa using hα
rwa [ne_eq, ← LieSubmodule.toSubmodule_inj] at hα
lemma traceForm_eq_zero_of_mem_ker_of_mem_span_coroot {α : Weight K H L} {x y : H}
(hx : x ∈ α.ker) (hy : y ∈ K ∙ coroot α) :
traceForm K H L x y = 0 := by
rw [← coe_corootSpace_eq_span_singleton, LieSubmodule.mem_toSubmodule, mem_corootSpace'] at hy
induction hy using Submodule.span_induction with
| mem z hz =>
obtain ⟨u, hu, v, -, huv⟩ := hz
change killingForm K L (x : L) (z : L) = 0
replace hx : α x = 0 := by simpa using hx
rw [← huv, ← traceForm_apply_lie_apply, ← LieSubalgebra.coe_bracket_of_module,
lie_eq_smul_of_mem_rootSpace hu, hx, zero_smul, map_zero, LinearMap.zero_apply]
| zero => simp
| add _ _ _ _ hx hy => simp [hx, hy]
| smul _ _ _ hz => simp [hz]
@[simp] lemma orthogonal_span_coroot_eq_ker (α : Weight K H L) :
(traceForm K H L).orthogonal (K ∙ coroot α) = α.ker := by
if hα : α.IsZero then
have hα' : coroot α = 0 := by simpa
replace hα : α.ker = ⊤ := by ext; simp [hα]
simp [hα, hα']
else
refine le_antisymm (fun x hx ↦ ?_) (fun x hx y hy ↦ ?_)
· simp only [LinearMap.BilinForm.mem_orthogonal_iff] at hx
specialize hx (coroot α) (Submodule.mem_span_singleton_self _)
simp only [LinearMap.BilinForm.isOrtho_def, traceForm_coroot, smul_eq_mul, nsmul_eq_mul,
Nat.cast_ofNat, mul_eq_zero, OfNat.ofNat_ne_zero, inv_eq_zero, false_or] at hx
simpa using hx.resolve_left (root_apply_cartanEquivDual_symm_ne_zero hα)
· have := traceForm_eq_zero_of_mem_ker_of_mem_span_coroot hx hy
rwa [traceForm_comm] at this
@[simp] lemma coroot_eq_iff (α β : Weight K H L) :
coroot α = coroot β ↔ α = β := by
refine ⟨fun hyp ↦ ?_, fun h ↦ by rw [h]⟩
if hα : α.IsZero then
have hβ : β.IsZero := by
rw [← coroot_eq_zero_iff] at hα ⊢
rwa [← hyp]
ext
simp [hα.eq, hβ.eq]
else
have hβ : β.IsNonZero := by
contrapose! hα
simp only [not_not, ← coroot_eq_zero_iff] at hα ⊢
rwa [hyp]
have : α.ker = β.ker := by
rw [← orthogonal_span_coroot_eq_ker α, hyp, orthogonal_span_coroot_eq_ker]
suffices (α : H →ₗ[K] K) = β by ext x; simpa using LinearMap.congr_fun this x
apply Module.Dual.eq_of_ker_eq_of_apply_eq (coroot α) this
· rw [Weight.toLinear_apply, root_apply_coroot hα, hyp, Weight.toLinear_apply,
root_apply_coroot hβ]
· simp [root_apply_coroot hα]
lemma exists_isSl2Triple_of_weight_isNonZero {α : Weight K H L} (hα : α.IsNonZero) :
∃ h e f : L, IsSl2Triple h e f ∧ e ∈ rootSpace H α ∧ f ∈ rootSpace H (- α) := by
obtain ⟨e, heα : e ∈ rootSpace H α, he₀ : e ≠ 0⟩ := α.exists_ne_zero
obtain ⟨f', hfα, hf⟩ : ∃ f ∈ rootSpace H (-α), killingForm K L e f ≠ 0 := by
contrapose! he₀
simpa using mem_ker_killingForm_of_mem_rootSpace_of_forall_rootSpace_neg K L H heα he₀
have hef := lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg heα hfα
let h : H := ⟨⁅e, f'⁆, hef ▸ Submodule.smul_mem _ _ (Submodule.coe_mem _)⟩
have hh : α h ≠ 0 := by
have : h = killingForm K L e f' • (cartanEquivDual H).symm α := by
simp only [h, Subtype.ext_iff, hef]
rw [Submodule.coe_smul_of_tower]
rw [this, map_smul, smul_eq_mul, ne_eq, mul_eq_zero, not_or]
exact ⟨hf, root_apply_cartanEquivDual_symm_ne_zero hα⟩
let f := (2 * (α h)⁻¹) • f'
replace hef : ⁅⁅e, f⁆, e⁆ = 2 • e := by
have : ⁅⁅e, f'⁆, e⁆ = α h • e := lie_eq_smul_of_mem_rootSpace heα h
rw [lie_smul, smul_lie, this, ← smul_assoc, smul_eq_mul, mul_assoc, inv_mul_cancel₀ hh,
mul_one, two_smul, two_smul]
refine ⟨⁅e, f⁆, e, f, ⟨fun contra ↦ ?_, rfl, hef, ?_⟩, heα, Submodule.smul_mem _ _ hfα⟩
· rw [contra] at hef
have _i : NoZeroSMulDivisors ℤ L := NoZeroSMulDivisors.int_of_charZero K L
simp only [zero_lie, eq_comm (a := (0 : L)), smul_eq_zero, OfNat.ofNat_ne_zero, false_or] at hef
contradiction
· have : ⁅⁅e, f'⁆, f'⁆ = - α h • f' := lie_eq_smul_of_mem_rootSpace hfα h
rw [lie_smul, lie_smul, smul_lie, this]
simp [← smul_assoc, f, hh, mul_comm _ (2 * (α h)⁻¹)]
lemma _root_.IsSl2Triple.h_eq_coroot {α : Weight K H L} (hα : α.IsNonZero)
{h e f : L} (ht : IsSl2Triple h e f) (heα : e ∈ rootSpace H α) (hfα : f ∈ rootSpace H (- α)) :
h = coroot α := by
have hef := lie_eq_killingForm_smul_of_mem_rootSpace_of_mem_rootSpace_neg heα hfα
lift h to H using by simpa only [← ht.lie_e_f, hef] using H.smul_mem _ (Submodule.coe_mem _)
congr 1
have key : α h = 2 := by
have := lie_eq_smul_of_mem_rootSpace heα h
rw [LieSubalgebra.coe_bracket_of_module, ht.lie_h_e_smul K] at this
exact smul_left_injective K ht.e_ne_zero this.symm
suffices ∃ s : K, s • h = coroot α by
obtain ⟨s, hs⟩ := this
| replace this : s = 1 := by simpa [root_apply_coroot hα, key] using congr_arg α hs
rwa [this, one_smul] at hs
set α' := (cartanEquivDual H).symm α with hα'
have h_eq : h = killingForm K L e f • α' := by
simp only [hα', Subtype.ext_iff, ← ht.lie_e_f, hef]
rw [Submodule.coe_smul_of_tower]
use (2 • (α α')⁻¹) * (killingForm K L e f)⁻¹
have hef₀ : killingForm K L e f ≠ 0 := by
have := ht.h_ne_zero
contrapose! this
simpa [this] using h_eq
rw [h_eq, smul_smul, mul_assoc, inv_mul_cancel₀ hef₀, mul_one, smul_assoc, coroot]
lemma finrank_rootSpace_eq_one (α : Weight K H L) (hα : α.IsNonZero) :
finrank K (rootSpace H α) = 1 := by
suffices ¬ 1 < finrank K (rootSpace H α) by
have h₀ : finrank K (rootSpace H α) ≠ 0 := by
convert_to finrank K (rootSpace H α).toSubmodule ≠ 0
simpa using α.genWeightSpace_ne_bot
omega
intro contra
obtain ⟨h, e, f, ht, heα, hfα⟩ := exists_isSl2Triple_of_weight_isNonZero hα
| Mathlib/Algebra/Lie/Weights/Killing.lean | 522 | 543 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by
by_cases hp0 : p = 0
· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots ≤ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by
classical
rw [← count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R}
(hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by
rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) :
#Z ≤ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [← sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by
rintro ⟨k, rfl⟩
exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩
|
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
| Mathlib/Algebra/Polynomial/Roots.lean | 154 | 158 |
/-
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.Squarefree.Basic
import Mathlib.Data.Nat.Factorization.PrimePow
import Mathlib.RingTheory.UniqueFactorizationDomain.Nat
/-!
# Lemmas about squarefreeness of natural numbers
A number is squarefree when it is not divisible by any squares except the squares of units.
## Main Results
- `Nat.squarefree_iff_nodup_primeFactorsList`: A positive natural number `x` is squarefree iff
the list `factors x` has no duplicate factors.
## Tags
squarefree, multiplicity
-/
open Finset
namespace Nat
theorem squarefree_iff_nodup_primeFactorsList {n : ℕ} (h0 : n ≠ 0) :
Squarefree n ↔ n.primeFactorsList.Nodup := by
rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0, Nat.factors_eq]
simp
end Nat
theorem Squarefree.nodup_primeFactorsList {n : ℕ} (hn : Squarefree n) : n.primeFactorsList.Nodup :=
(Nat.squarefree_iff_nodup_primeFactorsList hn.ne_zero).mp hn
namespace Nat
variable {s : Finset ℕ} {m n p : ℕ}
theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n :=
squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩
theorem _root_.Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) :
n.factorization p ≤ 1 := by
rcases eq_or_ne n 0 with (rfl | hn')
· simp
rw [squarefree_iff_emultiplicity_le_one] at hn
by_cases hp : p.Prime
· have := hn p
rw [← multiplicity_eq_factorization hp hn']
simp only [Nat.isUnit_iff, hp.ne_one, or_false] at this
exact multiplicity_le_of_emultiplicity_le this
· rw [factorization_eq_zero_of_non_prime _ hp]
exact zero_le_one
lemma factorization_eq_one_of_squarefree (hn : Squarefree n) (hp : p.Prime) (hpn : p ∣ n) :
factorization n p = 1 :=
(hn.natFactorization_le_one _).antisymm <| (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn
theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) :
Squarefree n := by
rw [squarefree_iff_nodup_primeFactorsList hn, List.nodup_iff_count_le_one]
intro a
rw [primeFactorsList_count_eq]
apply hn'
theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) :
Squarefree n ↔ ∀ p, n.factorization p ≤ 1 :=
⟨fun hn => hn.natFactorization_le_one, squarefree_of_factorization_le_one hn⟩
theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) :
n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) := by
refine ⟨by rintro rfl; simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => ?_⟩
by_cases hp : p.Prime
· have h₁ := h _ hp
rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff,
hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁
have h₂ := hn.natFactorization_le_one p
have h₃ := hm.natFactorization_le_one p
omega
rw [factorization_eq_zero_of_non_prime _ hp, factorization_eq_zero_of_non_prime _ hp]
theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) :
Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 := by
refine ⟨fun h => ?_, by rintro ⟨hn, rfl⟩; simpa⟩
rcases eq_or_ne n 0 with (rfl | -)
· simp [zero_pow hk] at h
refine ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => ?_⟩
have : 2 ≤ k := k.two_le_iff.mpr ⟨hk, h₁⟩
apply hn (Nat.isUnit_iff.1 (h _ _))
rw [← sq]
exact pow_dvd_pow _ this
theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n := by
refine ⟨?_, fun hn => ⟨hn.squarefree, hn.isPrimePow⟩⟩
rw [isPrimePow_nat_iff]
rintro ⟨h, p, k, hp, hk, rfl⟩
rw [squarefree_pow_iff hp.ne_one hk.ne'] at h
rwa [h.2, pow_one]
/-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that
`p^2 ∣ n`. -/
def minSqFacAux : ℕ → ℕ → Option ℕ
| n, k =>
if h : n < k * k then none
else
have : Nat.sqrt n - k < Nat.sqrt n + 2 - k := by
exact Nat.minFac_lemma n k h
if k ∣ n then
let n' := n / k
have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k :=
lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) k) this
if k ∣ n' then some k else minSqFacAux n' (k + 2)
else minSqFacAux n (k + 2)
termination_by n k => sqrt n + 2 - k
/-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no
such `p` (that is, `n` is squarefree). See also `Nat.squarefree_iff_minSqFac`. -/
def minSqFac (n : ℕ) : Option ℕ :=
if 2 ∣ n then
let n' := n / 2
if 2 ∣ n' then some 2 else minSqFacAux n' 3
else minSqFacAux n 3
/-- The correctness property of the return value of `minSqFac`.
* If `none`, then `n` is squarefree;
* If `some d`, then `d` is a minimal square factor of `n` -/
def MinSqFacProp (n : ℕ) : Option ℕ → Prop
| none => Squarefree n
| some d => Prime d ∧ d * d ∣ n ∧ ∀ p, Prime p → p * p ∣ n → d ≤ p
theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k ∣ n) {o}
(H : MinSqFacProp (n / k) o) : MinSqFacProp n o := by
have : ∀ p, Prime p → p * p ∣ n → k * (p * p) ∣ n := fun p pp dp =>
have :=
(coprime_primes pk pp).2 fun e => by
subst e
contradiction
(coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp
rcases o with - | d
· rw [MinSqFacProp, squarefree_iff_prime_squarefree] at H ⊢
exact fun p pp dp => H p pp ((dvd_div_iff_mul_dvd dk).2 (this _ pp dp))
· obtain ⟨H1, H2, H3⟩ := H
simp only [dvd_div_iff_mul_dvd dk] at H2 H3
exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩
theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3)
(ih : ∀ m, Prime m → m ∣ n → k ≤ m) : MinSqFacProp n (minSqFacAux n k) := by
rw [minSqFacAux]
by_cases h : n < k * k <;> simp only [h, ↓reduceDIte]
· refine squarefree_iff_prime_squarefree.2 fun p pp d => ?_
have := ih p pp (dvd_trans ⟨_, rfl⟩ d)
have := Nat.mul_le_mul this this
exact not_le_of_lt h (le_trans this (le_of_dvd n0 d))
have k2 : 2 ≤ k := by omega
have k0 : 0 < k := lt_of_lt_of_le (by decide) k2
have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by
intro n' nd' nk
have hn' := le_of_dvd n0 nd'
refine
have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k :=
lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h)
@minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1)
| (by simp [e, left_distrib]) fun m m2 d => ?_
rcases Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me | ml
· subst me
contradiction
apply (Nat.eq_or_lt_of_le ml).resolve_left
intro me
rw [← me, e] at d
change 2 * (i + 2) ∣ n' at d
have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd')
rw [e] at this
exact absurd this (by omega)
have pk : k ∣ n → Prime k := by
refine fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) ?_⟩
exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk)
split_ifs with dk dkk
· exact ⟨pk dk, (Nat.dvd_div_iff_mul_dvd dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩
· specialize IH (n / k) (div_dvd_of_dvd dk) dkk
exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff_mul_dvd dk).2 dkk) IH
· exact IH n (dvd_refl _) dk
termination_by n.sqrt + 2 - k
theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by
dsimp only [minSqFac]; split_ifs with d2 d4
· exact ⟨prime_two, (dvd_div_iff_mul_dvd d2).1 d4, fun p pp _ => pp.two_le⟩
· rcases Nat.eq_zero_or_pos n with n0 | n0
· subst n0
cases d4 (by decide)
refine minSqFacProp_div _ prime_two d2 (mt (dvd_div_iff_mul_dvd d2).2 d4) ?_
refine minSqFacAux_has_prop 3 (Nat.div_pos (le_of_dvd n0 d2) (by decide)) 0 rfl ?_
refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_)
rintro rfl
contradiction
· rcases Nat.eq_zero_or_pos n with n0 | n0
· subst n0
cases d2 (by decide)
refine minSqFacAux_has_prop _ n0 0 rfl ?_
refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_)
| Mathlib/Data/Nat/Squarefree.lean | 164 | 200 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Control.Combinators
import Mathlib.Logic.Function.Defs
import Mathlib.Tactic.CasesM
import Mathlib.Tactic.Attr.Core
/-!
Extends the theory on functors, applicatives and monads.
-/
universe u v w
variable {α β γ : Type u}
section Functor
attribute [functor_norm] Functor.map_map
end Functor
section Applicative
variable {F : Type u → Type v} [Applicative F]
/-- A generalization of `List.zipWith` which combines list elements with an `Applicative`. -/
def zipWithM {α₁ α₂ φ : Type u} (f : α₁ → α₂ → F φ) : ∀ (_ : List α₁) (_ : List α₂), F (List φ)
| x :: xs, y :: ys => (· :: ·) <$> f x y <*> zipWithM f xs ys
| _, _ => pure []
/-- Like `zipWithM` but evaluates the result as it traverses the lists using `*>`. -/
def zipWithM' (f : α → β → F γ) : List α → List β → F PUnit
| x :: xs, y :: ys => f x y *> zipWithM' f xs ys
| [], _ => pure PUnit.unit
| _, [] => pure PUnit.unit
variable [LawfulApplicative F]
@[simp]
theorem pure_id'_seq (x : F α) : (pure fun x => x) <*> x = x :=
pure_id_seq x
@[functor_norm]
theorem seq_map_assoc (x : F (α → β)) (f : γ → α) (y : F γ) :
x <*> f <$> y = (· ∘ f) <$> x <*> y := by
simp only [← pure_seq]
simp only [seq_assoc, Function.comp, seq_pure, ← comp_map]
simp [pure_seq]
rfl
@[functor_norm]
theorem map_seq (f : β → γ) (x : F (α → β)) (y : F α) :
f <$> (x <*> y) = (f ∘ ·) <$> x <*> y := by
simp only [← pure_seq]; simp [seq_assoc]
end Applicative
section Monad
variable {m : Type u → Type v} [Monad m] [LawfulMonad m]
theorem seq_bind_eq (x : m α) {g : β → m γ} {f : α → β} :
f <$> x >>= g = x >>= g ∘ f :=
show bind (f <$> x) g = bind x (g ∘ f) by
rw [← bind_pure_comp, bind_assoc]
simp [pure_bind, Function.comp_def]
-- order of implicits and `Seq.seq` has a lazily evaluated second argument using `Unit`
@[functor_norm]
theorem fish_pure {α β} (f : α → m β) : f >=> pure = f := by
simp +unfoldPartialApp only [(· >=> ·), functor_norm]
@[functor_norm]
theorem fish_pipe {α β} (f : α → m β) : pure >=> f = f := by
simp +unfoldPartialApp only [(· >=> ·), functor_norm]
-- note: in Lean 3 `>=>` is left-associative, but in Lean 4 it is right-associative.
@[functor_norm]
theorem fish_assoc {α β γ φ} (f : α → m β) (g : β → m γ) (h : γ → m φ) :
(f >=> g) >=> h = f >=> g >=> h := by
simp +unfoldPartialApp only [(· >=> ·), functor_norm]
variable {β' γ' : Type v}
variable {m' : Type v → Type w} [Monad m']
/-- Takes a value `β` and `List α` and accumulates pairs according to a monadic function `f`.
Accumulation occurs from the right (i.e., starting from the tail of the list). -/
def List.mapAccumRM (f : α → β' → m' (β' × γ')) : β' → List α → m' (β' × List γ')
| a, [] => pure (a, [])
| a, x :: xs => do
let (a', ys) ← List.mapAccumRM f a xs
let (a'', y) ← f x a'
pure (a'', y :: ys)
/-- Takes a value `β` and `List α` and accumulates pairs according to a monadic function `f`.
Accumulation occurs from the left (i.e., starting from the head of the list). -/
def List.mapAccumLM (f : β' → α → m' (β' × γ')) : β' → List α → m' (β' × List γ')
| a, [] => pure (a, [])
| a, x :: xs => do
let (a', y) ← f a x
let (a'', ys) ← List.mapAccumLM f a' xs
pure (a'', y :: ys)
end Monad
section
variable {m : Type u → Type u} [Monad m] [LawfulMonad m]
theorem joinM_map_map {α β : Type u} (f : α → β) (a : m (m α)) :
joinM (Functor.map f <$> a) = f <$> joinM a := by
simp only [joinM, (· ∘ ·), id, ← bind_pure_comp, bind_assoc, map_bind, pure_bind]
theorem joinM_map_joinM {α : Type u} (a : m (m (m α))) : joinM (joinM <$> a) = joinM (joinM a) := by
simp only [joinM, (· ∘ ·), id, map_bind, ← bind_pure_comp, bind_assoc, pure_bind]
@[simp]
theorem joinM_map_pure {α : Type u} (a : m α) : joinM (pure <$> a) = a := by
simp only [joinM, (· ∘ ·), id, map_bind, ← bind_pure_comp, bind_assoc, pure_bind, bind_pure]
@[simp]
theorem joinM_pure {α : Type u} (a : m α) : joinM (pure a) = a :=
LawfulMonad.pure_bind a id
end
section Alternative
variable {F : Type → Type v} [Alternative F]
-- [todo] add notation for `Functor.mapConst` and port `Functor.mapConstRev`
/-- Returns `pure true` if the computation succeeds and `pure false` otherwise. -/
def succeeds {α} (x : F α) : F Bool :=
Functor.mapConst true x <|> pure false
/-- Attempts to perform the computation, but fails silently if it doesn't succeed. -/
def tryM {α} (x : F α) : F Unit :=
Functor.mapConst () x <|> pure ()
/-- Attempts to perform the computation, and returns `none` if it doesn't succeed. -/
def try? {α} (x : F α) : F (Option α) :=
some <$> x <|> pure none
@[simp]
theorem guard_true {h : Decidable True} : @guard F _ True h = pure () := by simp [guard, if_pos]
@[simp]
theorem guard_false {h : Decidable False} : @guard F _ False h = failure := by
simp [guard, if_neg not_false]
end Alternative
namespace Sum
variable {e : Type v}
/-- The monadic `bind` operation for `Sum`. -/
protected def bind {α β} : e ⊕ α → (α → e ⊕ β) → e ⊕ β
| inl x, _ => inl x
| inr x, f => f x
-- incorrectly marked as a bad translation by mathport, so we do not mark with `ₓ`.
instance : Monad (Sum.{v, u} e) where
pure := @Sum.inr e
bind := @Sum.bind e
instance : LawfulFunctor (Sum.{v, u} e) := by
constructor <;> intros <;> (try casesm Sum _ _) <;> rfl
instance : LawfulMonad (Sum.{v, u} e) where
seqRight_eq := by
intros
casesm Sum _ _ <;> casesm Sum _ _ <;> rfl
seqLeft_eq := by
intros
casesm Sum _ _ <;> rfl
pure_seq := by
intros
rfl
| bind_assoc := by
| Mathlib/Control/Basic.lean | 183 | 183 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.